Commit d2bcea68 authored by Ben Skeggs's avatar Ben Skeggs

drm/nouveau/bios: update gpio parsing apis to match current design

Signed-off-by: default avatarBen Skeggs <bskeggs@redhat.com>
parent caba5570
...@@ -25,9 +25,11 @@ struct dcb_gpio_func { ...@@ -25,9 +25,11 @@ struct dcb_gpio_func {
u8 param; u8 param;
}; };
u16 dcb_gpio_table(struct nouveau_bios *); u16 dcb_gpio_table(struct nouveau_bios *, u8 *ver, u8 *hdr, u8 *cnt, u8 *len);
u16 dcb_gpio_entry(struct nouveau_bios *, int idx, int ent, u8 *ver); u16 dcb_gpio_entry(struct nouveau_bios *, int idx, int ent, u8 *ver, u8 *len);
int dcb_gpio_parse(struct nouveau_bios *, int idx, u8 func, u8 line, u16 dcb_gpio_parse(struct nouveau_bios *, int idx, int ent, u8 *ver, u8 *len,
struct dcb_gpio_func *); struct dcb_gpio_func *);
u16 dcb_gpio_match(struct nouveau_bios *, int idx, u8 func, u8 line,
u8 *ver, u8 *len, struct dcb_gpio_func *);
#endif #endif
...@@ -27,84 +27,105 @@ ...@@ -27,84 +27,105 @@
#include <subdev/bios/gpio.h> #include <subdev/bios/gpio.h>
u16 u16
dcb_gpio_table(struct nouveau_bios *bios) dcb_gpio_table(struct nouveau_bios *bios, u8 *ver, u8 *hdr, u8 *cnt, u8 *len)
{ {
u8 ver, hdr, cnt, len; u16 data = 0x0000;
u16 dcb = dcb_table(bios, &ver, &hdr, &cnt, &len); u16 dcb = dcb_table(bios, ver, hdr, cnt, len);
if (dcb) { if (dcb) {
if (ver >= 0x30 && hdr >= 0x0c) if (*ver >= 0x30 && *hdr >= 0x0c)
return nv_ro16(bios, dcb + 0x0a); data = nv_ro16(bios, dcb + 0x0a);
if (ver >= 0x22 && nv_ro08(bios, dcb - 1) >= 0x13) else
return nv_ro16(bios, dcb - 0x0f); if (*ver >= 0x22 && nv_ro08(bios, dcb - 1) >= 0x13)
data = nv_ro16(bios, dcb - 0x0f);
if (data) {
*ver = nv_ro08(bios, data + 0x00);
if (*ver < 0x30) {
*hdr = 3;
*cnt = nv_ro08(bios, data + 0x02);
*len = nv_ro08(bios, data + 0x01);
} else
if (*ver <= 0x41) {
*hdr = nv_ro08(bios, data + 0x01);
*cnt = nv_ro08(bios, data + 0x02);
*len = nv_ro08(bios, data + 0x03);
} else {
data = 0x0000;
}
}
} }
return 0x0000; return data;
} }
u16 u16
dcb_gpio_entry(struct nouveau_bios *bios, int idx, int ent, u8 *ver) dcb_gpio_entry(struct nouveau_bios *bios, int idx, int ent, u8 *ver, u8 *len)
{ {
u16 gpio = dcb_gpio_table(bios); u8 hdr, cnt;
if (gpio) { u16 gpio = !idx ? dcb_gpio_table(bios, ver, &hdr, &cnt, len) : 0x0000;
*ver = nv_ro08(bios, gpio); if (gpio && ent < cnt)
if (*ver < 0x30 && ent < nv_ro08(bios, gpio + 2)) return gpio + hdr + (ent * *len);
return gpio + 3 + (ent * nv_ro08(bios, gpio + 1));
else if (ent < nv_ro08(bios, gpio + 2))
return gpio + nv_ro08(bios, gpio + 1) +
(ent * nv_ro08(bios, gpio + 3));
}
return 0x0000; return 0x0000;
} }
int u16
dcb_gpio_parse(struct nouveau_bios *bios, int idx, u8 func, u8 line, dcb_gpio_parse(struct nouveau_bios *bios, int idx, int ent, u8 *ver, u8 *len,
struct dcb_gpio_func *gpio) struct dcb_gpio_func *gpio)
{ {
u8 ver, hdr, cnt, len; u16 data = dcb_gpio_entry(bios, idx, ent, ver, len);
u16 entry; if (data) {
int i = -1; if (*ver < 0x40) {
u16 info = nv_ro16(bios, data);
while ((entry = dcb_gpio_entry(bios, idx, ++i, &ver))) {
if (ver < 0x40) {
u16 data = nv_ro16(bios, entry);
*gpio = (struct dcb_gpio_func) { *gpio = (struct dcb_gpio_func) {
.line = (data & 0x001f) >> 0, .line = (info & 0x001f) >> 0,
.func = (data & 0x07e0) >> 5, .func = (info & 0x07e0) >> 5,
.log[0] = (data & 0x1800) >> 11, .log[0] = (info & 0x1800) >> 11,
.log[1] = (data & 0x6000) >> 13, .log[1] = (info & 0x6000) >> 13,
.param = !!(data & 0x8000), .param = !!(info & 0x8000),
}; };
} else } else
if (ver < 0x41) { if (*ver < 0x41) {
u32 data = nv_ro32(bios, entry); u32 info = nv_ro32(bios, data);
*gpio = (struct dcb_gpio_func) { *gpio = (struct dcb_gpio_func) {
.line = (data & 0x0000001f) >> 0, .line = (info & 0x0000001f) >> 0,
.func = (data & 0x0000ff00) >> 8, .func = (info & 0x0000ff00) >> 8,
.log[0] = (data & 0x18000000) >> 27, .log[0] = (info & 0x18000000) >> 27,
.log[1] = (data & 0x60000000) >> 29, .log[1] = (info & 0x60000000) >> 29,
.param = !!(data & 0x80000000), .param = !!(info & 0x80000000),
}; };
} else { } else {
u32 data = nv_ro32(bios, entry + 0); u32 info = nv_ro32(bios, data + 0);
u8 data1 = nv_ro32(bios, entry + 4); u8 info1 = nv_ro32(bios, data + 4);
*gpio = (struct dcb_gpio_func) { *gpio = (struct dcb_gpio_func) {
.line = (data & 0x0000003f) >> 0, .line = (info & 0x0000003f) >> 0,
.func = (data & 0x0000ff00) >> 8, .func = (info & 0x0000ff00) >> 8,
.log[0] = (data1 & 0x30) >> 4, .log[0] = (info1 & 0x30) >> 4,
.log[1] = (data1 & 0xc0) >> 6, .log[1] = (info1 & 0xc0) >> 6,
.param = !!(data & 0x80000000), .param = !!(info & 0x80000000),
}; };
} }
}
return data;
}
u16
dcb_gpio_match(struct nouveau_bios *bios, int idx, u8 func, u8 line,
u8 *ver, u8 *len, struct dcb_gpio_func *gpio)
{
u8 hdr, cnt, i = 0;
u16 data;
while ((data = dcb_gpio_parse(bios, idx, i++, ver, len, gpio))) {
if ((line == 0xff || line == gpio->line) && if ((line == 0xff || line == gpio->line) &&
(func == 0xff || func == gpio->func)) (func == 0xff || func == gpio->func))
return 0; return data;
} }
/* DCB 2.2, fixed TVDAC GPIO data */ /* DCB 2.2, fixed TVDAC GPIO data */
if ((entry = dcb_table(bios, &ver, &hdr, &cnt, &len))) { if ((data = dcb_table(bios, ver, &hdr, &cnt, len))) {
if (ver >= 0x22 && ver < 0x30 && func == DCB_GPIO_TVDAC0) { if (*ver >= 0x22 && *ver < 0x30 && func == DCB_GPIO_TVDAC0) {
u8 conf = nv_ro08(bios, entry - 5); u8 conf = nv_ro08(bios, data - 5);
u8 addr = nv_ro08(bios, entry - 4); u8 addr = nv_ro08(bios, data - 4);
if (conf & 0x01) { if (conf & 0x01) {
*gpio = (struct dcb_gpio_func) { *gpio = (struct dcb_gpio_func) {
.func = DCB_GPIO_TVDAC0, .func = DCB_GPIO_TVDAC0,
...@@ -112,10 +133,11 @@ dcb_gpio_parse(struct nouveau_bios *bios, int idx, u8 func, u8 line, ...@@ -112,10 +133,11 @@ dcb_gpio_parse(struct nouveau_bios *bios, int idx, u8 func, u8 line,
.log[0] = !!(conf & 0x02), .log[0] = !!(conf & 0x02),
.log[1] = !(conf & 0x02), .log[1] = !(conf & 0x02),
}; };
return 0; *ver = 0x00;
return data;
} }
} }
} }
return -EINVAL; return 0x0000;
} }
...@@ -43,10 +43,15 @@ static int ...@@ -43,10 +43,15 @@ static int
nouveau_gpio_find(struct nouveau_gpio *gpio, int idx, u8 tag, u8 line, nouveau_gpio_find(struct nouveau_gpio *gpio, int idx, u8 tag, u8 line,
struct dcb_gpio_func *func) struct dcb_gpio_func *func)
{ {
struct nouveau_bios *bios = nouveau_bios(gpio);
u8 ver, len;
u16 data;
if (line == 0xff && tag == 0xff) if (line == 0xff && tag == 0xff)
return -EINVAL; return -EINVAL;
if (!dcb_gpio_parse(nouveau_bios(gpio), idx, tag, line, func)) data = dcb_gpio_match(bios, idx, tag, line, &ver, &len, func);
if (data)
return 0; return 0;
/* Apple iMac G4 NV18 */ /* Apple iMac G4 NV18 */
......
...@@ -33,11 +33,11 @@ nv50_gpio_reset(struct nouveau_gpio *gpio) ...@@ -33,11 +33,11 @@ nv50_gpio_reset(struct nouveau_gpio *gpio)
{ {
struct nouveau_bios *bios = nouveau_bios(gpio); struct nouveau_bios *bios = nouveau_bios(gpio);
struct nv50_gpio_priv *priv = (void *)gpio; struct nv50_gpio_priv *priv = (void *)gpio;
u8 ver, len;
u16 entry; u16 entry;
u8 ver;
int ent = -1; int ent = -1;
while ((entry = dcb_gpio_entry(bios, 0, ++ent, &ver))) { while ((entry = dcb_gpio_entry(bios, 0, ++ent, &ver, &len))) {
static const u32 regs[] = { 0xe100, 0xe28c }; static const u32 regs[] = { 0xe100, 0xe28c };
u32 data = nv_ro32(bios, entry); u32 data = nv_ro32(bios, entry);
u8 line = (data & 0x0000001f); u8 line = (data & 0x0000001f);
......
...@@ -33,11 +33,11 @@ nvd0_gpio_reset(struct nouveau_gpio *gpio) ...@@ -33,11 +33,11 @@ nvd0_gpio_reset(struct nouveau_gpio *gpio)
{ {
struct nouveau_bios *bios = nouveau_bios(gpio); struct nouveau_bios *bios = nouveau_bios(gpio);
struct nvd0_gpio_priv *priv = (void *)gpio; struct nvd0_gpio_priv *priv = (void *)gpio;
u8 ver, len;
u16 entry; u16 entry;
u8 ver;
int ent = -1; int ent = -1;
while ((entry = dcb_gpio_entry(bios, 0, ++ent, &ver))) { while ((entry = dcb_gpio_entry(bios, 0, ++ent, &ver, &len))) {
u32 data = nv_ro32(bios, entry); u32 data = nv_ro32(bios, entry);
u8 line = (data & 0x0000003f); u8 line = (data & 0x0000003f);
u8 defs = !!(data & 0x00000080); u8 defs = !!(data & 0x00000080);
......
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