Commit 85f1503a authored by Benjamin Herrenschmidt's avatar Benjamin Herrenschmidt Committed by Linus Torvalds

[PATCH] nvidiafb: Fix mode setting & PPC support

This patch fixes nvifiafb mode setting code to be closer to what the X
driver does, which actually makes it work on the 5200FX I have access to.
It also fix the routine that gets the EDID from Open Firmware on PPC, it
was broken in various ways and would crash at boot.  Compared to the patch
I posted to linux-fbdev last week, this one just changes a printk to be
closer to the other ones in the driver.
Signed-off-by: default avatarBenjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: "Antonino A. Daplas" <adaplas@hotpop.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent ecc41d5e
...@@ -703,7 +703,7 @@ config FB_NVIDIA ...@@ -703,7 +703,7 @@ config FB_NVIDIA
config FB_NVIDIA_I2C config FB_NVIDIA_I2C
bool "Enable DDC Support" bool "Enable DDC Support"
depends on FB_NVIDIA && !PPC_OF depends on FB_NVIDIA
help help
This enables I2C support for nVidia Chipsets. This is used This enables I2C support for nVidia Chipsets. This is used
only for getting EDID information from the attached display only for getting EDID information from the attached display
......
...@@ -27,34 +27,60 @@ ...@@ -27,34 +27,60 @@
#include "nv_local.h" #include "nv_local.h"
#include "nv_proto.h" #include "nv_proto.h"
void nvidia_create_i2c_busses(struct nvidia_par *par) {} #include "../edid.h"
void nvidia_delete_i2c_busses(struct nvidia_par *par) {}
int nvidia_probe_i2c_connector(struct fb_info *info, int conn, u8 **out_edid) int nvidia_probe_of_connector(struct fb_info *info, int conn, u8 **out_edid)
{ {
struct nvidia_par *par = info->par; struct nvidia_par *par = info->par;
struct device_node *dp; struct device_node *parent, *dp;
unsigned char *pedid = NULL; unsigned char *pedid = NULL;
unsigned char *disptype = NULL;
static char *propnames[] = { static char *propnames[] = {
"DFP,EDID", "LCD,EDID", "EDID", "EDID1", "EDID,B", "EDID,A", NULL }; "DFP,EDID", "LCD,EDID", "EDID", "EDID1",
"EDID,B", "EDID,A", NULL };
int i; int i;
dp = pci_device_to_OF_node(par->pci_dev); parent = pci_device_to_OF_node(par->pci_dev);
for (; dp != NULL; dp = dp->child) { if (parent == NULL)
disptype = (unsigned char *)get_property(dp, "display-type", NULL); return -1;
if (disptype == NULL) if (par->twoHeads) {
continue; char *pname;
if (strncmp(disptype, "LCD", 3) != 0) int len;
continue;
for (dp = NULL;
(dp = of_get_next_child(parent, dp)) != NULL;) {
pname = (char *)get_property(dp, "name", NULL);
if (!pname)
continue;
len = strlen(pname);
if ((pname[len-1] == 'A' && conn == 1) ||
(pname[len-1] == 'B' && conn == 2)) {
for (i = 0; propnames[i] != NULL; ++i) {
pedid = (unsigned char *)
get_property(dp, propnames[i],
NULL);
if (pedid != NULL)
break;
}
of_node_put(dp);
break;
}
}
}
if (pedid == NULL) {
for (i = 0; propnames[i] != NULL; ++i) { for (i = 0; propnames[i] != NULL; ++i) {
pedid = (unsigned char *) pedid = (unsigned char *)
get_property(dp, propnames[i], NULL); get_property(parent, propnames[i], NULL);
if (pedid != NULL) { if (pedid != NULL)
*out_edid = pedid; break;
return 0;
}
} }
} }
return 1; if (pedid) {
*out_edid = kmalloc(EDID_LENGTH, GFP_KERNEL);
if (*out_edid == NULL)
return -1;
memcpy(*out_edid, pedid, EDID_LENGTH);
printk(KERN_DEBUG "nvidiafb: Found OF EDID for head %d\n", conn);
return 0;
}
return -1;
} }
...@@ -31,7 +31,7 @@ int NVShowHideCursor(struct nvidia_par *par, int); ...@@ -31,7 +31,7 @@ int NVShowHideCursor(struct nvidia_par *par, int);
void NVLockUnlock(struct nvidia_par *par, int); void NVLockUnlock(struct nvidia_par *par, int);
/* in nvidia-i2c.c */ /* in nvidia-i2c.c */
#if defined(CONFIG_FB_NVIDIA_I2C) || defined (CONFIG_PPC_OF) #ifdef CONFIG_FB_NVIDIA_I2C
void nvidia_create_i2c_busses(struct nvidia_par *par); void nvidia_create_i2c_busses(struct nvidia_par *par);
void nvidia_delete_i2c_busses(struct nvidia_par *par); void nvidia_delete_i2c_busses(struct nvidia_par *par);
int nvidia_probe_i2c_connector(struct fb_info *info, int conn, int nvidia_probe_i2c_connector(struct fb_info *info, int conn,
...@@ -39,10 +39,14 @@ int nvidia_probe_i2c_connector(struct fb_info *info, int conn, ...@@ -39,10 +39,14 @@ int nvidia_probe_i2c_connector(struct fb_info *info, int conn,
#else #else
#define nvidia_create_i2c_busses(...) #define nvidia_create_i2c_busses(...)
#define nvidia_delete_i2c_busses(...) #define nvidia_delete_i2c_busses(...)
#define nvidia_probe_i2c_connector(p, c, edid) \ #define nvidia_probe_i2c_connector(p, c, edid) (-1)
do { \ #endif
*(edid) = NULL; \
} while(0) #ifdef CONFIG_FB_OF
int nvidia_probe_of_connector(struct fb_info *info, int conn,
u8 ** out_edid);
#else
#define nvidia_probe_of_connector(p, c, edid) (-1)
#endif #endif
/* in nv_accel.c */ /* in nv_accel.c */
......
...@@ -190,9 +190,9 @@ static int NVIsConnected(struct nvidia_par *par, int output) ...@@ -190,9 +190,9 @@ static int NVIsConnected(struct nvidia_par *par, int output)
present = (NV_RD32(PRAMDAC, 0x0608) & (1 << 28)) ? 1 : 0; present = (NV_RD32(PRAMDAC, 0x0608) & (1 << 28)) ? 1 : 0;
if (present) if (present)
printk("nvidiafb: CRTC%i found\n", output); printk("nvidiafb: CRTC%i analog found\n", output);
else else
printk("nvidiafb: CRTC%i not found\n", output); printk("nvidiafb: CRTC%i analog not found\n", output);
NV_WR32(par->PRAMDAC0, 0x0608, NV_RD32(par->PRAMDAC0, 0x0608) & NV_WR32(par->PRAMDAC0, 0x0608, NV_RD32(par->PRAMDAC0, 0x0608) &
0x0000EFFF); 0x0000EFFF);
...@@ -305,6 +305,9 @@ void NVCommonSetup(struct fb_info *info) ...@@ -305,6 +305,9 @@ void NVCommonSetup(struct fb_info *info)
int FlatPanel = -1; /* really means the CRTC is slaved */ int FlatPanel = -1; /* really means the CRTC is slaved */
int Television = 0; int Television = 0;
memset(&monitorA, 0, sizeof(struct fb_monspecs));
memset(&monitorB, 0, sizeof(struct fb_monspecs));
par->PRAMIN = par->REGS + (0x00710000 / 4); par->PRAMIN = par->REGS + (0x00710000 / 4);
par->PCRTC0 = par->REGS + (0x00600000 / 4); par->PCRTC0 = par->REGS + (0x00600000 / 4);
par->PRAMDAC0 = par->REGS + (0x00680000 / 4); par->PRAMDAC0 = par->REGS + (0x00680000 / 4);
...@@ -401,7 +404,8 @@ void NVCommonSetup(struct fb_info *info) ...@@ -401,7 +404,8 @@ void NVCommonSetup(struct fb_info *info)
nvidia_create_i2c_busses(par); nvidia_create_i2c_busses(par);
if (!par->twoHeads) { if (!par->twoHeads) {
par->CRTCnumber = 0; par->CRTCnumber = 0;
nvidia_probe_i2c_connector(info, 1, &edidA); if (nvidia_probe_i2c_connector(info, 1, &edidA))
nvidia_probe_of_connector(info, 1, &edidA);
if (edidA && !fb_parse_edid(edidA, &var)) { if (edidA && !fb_parse_edid(edidA, &var)) {
printk("nvidiafb: EDID found from BUS1\n"); printk("nvidiafb: EDID found from BUS1\n");
monA = &monitorA; monA = &monitorA;
...@@ -488,14 +492,16 @@ void NVCommonSetup(struct fb_info *info) ...@@ -488,14 +492,16 @@ void NVCommonSetup(struct fb_info *info)
oldhead = NV_RD32(par->PCRTC0, 0x00000860); oldhead = NV_RD32(par->PCRTC0, 0x00000860);
NV_WR32(par->PCRTC0, 0x00000860, oldhead | 0x00000010); NV_WR32(par->PCRTC0, 0x00000860, oldhead | 0x00000010);
nvidia_probe_i2c_connector(info, 1, &edidA); if (nvidia_probe_i2c_connector(info, 1, &edidA))
nvidia_probe_of_connector(info, 1, &edidA);
if (edidA && !fb_parse_edid(edidA, &var)) { if (edidA && !fb_parse_edid(edidA, &var)) {
printk("nvidiafb: EDID found from BUS1\n"); printk("nvidiafb: EDID found from BUS1\n");
monA = &monitorA; monA = &monitorA;
fb_edid_to_monspecs(edidA, monA); fb_edid_to_monspecs(edidA, monA);
} }
nvidia_probe_i2c_connector(info, 2, &edidB); if (nvidia_probe_i2c_connector(info, 2, &edidB))
nvidia_probe_of_connector(info, 2, &edidB);
if (edidB && !fb_parse_edid(edidB, &var)) { if (edidB && !fb_parse_edid(edidB, &var)) {
printk("nvidiafb: EDID found from BUS2\n"); printk("nvidiafb: EDID found from BUS2\n");
monB = &monitorB; monB = &monitorB;
......
...@@ -627,41 +627,85 @@ static void nvidia_save_vga(struct nvidia_par *par, ...@@ -627,41 +627,85 @@ static void nvidia_save_vga(struct nvidia_par *par,
NVTRACE_LEAVE(); NVTRACE_LEAVE();
} }
#undef DUMP_REG
static void nvidia_write_regs(struct nvidia_par *par) static void nvidia_write_regs(struct nvidia_par *par)
{ {
struct _riva_hw_state *state = &par->ModeReg; struct _riva_hw_state *state = &par->ModeReg;
int i; int i;
NVTRACE_ENTER(); NVTRACE_ENTER();
NVWriteCrtc(par, 0x11, 0x00);
NVLockUnlock(par, 0);
NVLoadStateExt(par, state); NVLoadStateExt(par, state);
NVWriteMiscOut(par, state->misc_output); NVWriteMiscOut(par, state->misc_output);
for (i = 1; i < NUM_SEQ_REGS; i++) {
#ifdef DUMP_REG
printk(" SEQ[%02x] = %08x\n", i, state->seq[i]);
#endif
NVWriteSeq(par, i, state->seq[i]);
}
/* Ensure CRTC registers 0-7 are unlocked by clearing bit 7 of CRTC[17] */
NVWriteCrtc(par, 0x11, state->crtc[0x11] & ~0x80);
for (i = 0; i < NUM_CRT_REGS; i++) { for (i = 0; i < NUM_CRT_REGS; i++) {
switch (i) { switch (i) {
case 0x19: case 0x19:
case 0x20 ... 0x40: case 0x20 ... 0x40:
break; break;
default: default:
#ifdef DUMP_REG
printk("CRTC[%02x] = %08x\n", i, state->crtc[i]);
#endif
NVWriteCrtc(par, i, state->crtc[i]); NVWriteCrtc(par, i, state->crtc[i]);
} }
} }
for (i = 0; i < NUM_ATC_REGS; i++) for (i = 0; i < NUM_GRC_REGS; i++) {
NVWriteAttr(par, i, state->attr[i]); #ifdef DUMP_REG
printk(" GRA[%02x] = %08x\n", i, state->gra[i]);
for (i = 0; i < NUM_GRC_REGS; i++) #endif
NVWriteGr(par, i, state->gra[i]); NVWriteGr(par, i, state->gra[i]);
}
for (i = 0; i < NUM_ATC_REGS; i++) {
#ifdef DUMP_REG
printk("ATTR[%02x] = %08x\n", i, state->attr[i]);
#endif
NVWriteAttr(par, i, state->attr[i]);
}
for (i = 0; i < NUM_SEQ_REGS; i++)
NVWriteSeq(par, i, state->seq[i]);
NVTRACE_LEAVE(); NVTRACE_LEAVE();
} }
static void nvidia_vga_protect(struct nvidia_par *par, int on)
{
unsigned char tmp;
if (on) {
/*
* Turn off screen and disable sequencer.
*/
tmp = NVReadSeq(par, 0x01);
NVWriteSeq(par, 0x00, 0x01); /* Synchronous Reset */
NVWriteSeq(par, 0x01, tmp | 0x20); /* disable the display */
} else {
/*
* Reenable sequencer, then turn on screen.
*/
tmp = NVReadSeq(par, 0x01);
NVWriteSeq(par, 0x01, tmp & ~0x20); /* reenable display */
NVWriteSeq(par, 0x00, 0x03); /* End Reset */
}
}
static int nvidia_calc_regs(struct fb_info *info) static int nvidia_calc_regs(struct fb_info *info)
{ {
struct nvidia_par *par = info->par; struct nvidia_par *par = info->par;
...@@ -868,7 +912,7 @@ static void nvidia_init_vga(struct fb_info *info) ...@@ -868,7 +912,7 @@ static void nvidia_init_vga(struct fb_info *info)
for (i = 0; i < 0x10; i++) for (i = 0; i < 0x10; i++)
state->attr[i] = i; state->attr[i] = i;
state->attr[0x10] = 0x41; state->attr[0x10] = 0x41;
state->attr[0x11] = 0x01; state->attr[0x11] = 0xff;
state->attr[0x12] = 0x0f; state->attr[0x12] = 0x0f;
state->attr[0x13] = 0x00; state->attr[0x13] = 0x00;
state->attr[0x14] = 0x00; state->attr[0x14] = 0x00;
...@@ -991,7 +1035,6 @@ static int nvidiafb_set_par(struct fb_info *info) ...@@ -991,7 +1035,6 @@ static int nvidiafb_set_par(struct fb_info *info)
nvidia_init_vga(info); nvidia_init_vga(info);
nvidia_calc_regs(info); nvidia_calc_regs(info);
nvidia_write_regs(par);
NVLockUnlock(par, 0); NVLockUnlock(par, 0);
if (par->twoHeads) { if (par->twoHeads) {
...@@ -1000,7 +1043,22 @@ static int nvidiafb_set_par(struct fb_info *info) ...@@ -1000,7 +1043,22 @@ static int nvidiafb_set_par(struct fb_info *info)
NVLockUnlock(par, 0); NVLockUnlock(par, 0);
} }
NVWriteCrtc(par, 0x11, 0x00); nvidia_vga_protect(par, 1);
nvidia_write_regs(par);
#if defined (__BIG_ENDIAN)
/* turn on LFB swapping */
{
unsigned char tmp;
VGA_WR08(par->PCIO, 0x3d4, 0x46);
tmp = VGA_RD08(par->PCIO, 0x3d5);
tmp |= (1 << 7);
VGA_WR08(par->PCIO, 0x3d5, tmp);
}
#endif
info->fix.line_length = (info->var.xres_virtual * info->fix.line_length = (info->var.xres_virtual *
info->var.bits_per_pixel) >> 3; info->var.bits_per_pixel) >> 3;
if (info->var.accel_flags) { if (info->var.accel_flags) {
...@@ -1022,7 +1080,7 @@ static int nvidiafb_set_par(struct fb_info *info) ...@@ -1022,7 +1080,7 @@ static int nvidiafb_set_par(struct fb_info *info)
par->cursor_reset = 1; par->cursor_reset = 1;
NVWriteCrtc(par, 0x11, 0xff); nvidia_vga_protect(par, 0);
NVTRACE_LEAVE(); NVTRACE_LEAVE();
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment