aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/nouveau/nouveau_bios.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/drm/nouveau/nouveau_bios.c')
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_bios.c500
1 files changed, 327 insertions, 173 deletions
diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
index abc382a9918b..e7e69ccce5c9 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
@@ -26,6 +26,7 @@
26#define NV_DEBUG_NOTRACE 26#define NV_DEBUG_NOTRACE
27#include "nouveau_drv.h" 27#include "nouveau_drv.h"
28#include "nouveau_hw.h" 28#include "nouveau_hw.h"
29#include "nouveau_encoder.h"
29 30
30/* these defines are made up */ 31/* these defines are made up */
31#define NV_CIO_CRE_44_HEADA 0x0 32#define NV_CIO_CRE_44_HEADA 0x0
@@ -256,6 +257,11 @@ static bool NVShadowVBIOS(struct drm_device *dev, uint8_t *data)
256struct init_tbl_entry { 257struct init_tbl_entry {
257 char *name; 258 char *name;
258 uint8_t id; 259 uint8_t id;
260 /* Return:
261 * > 0: success, length of opcode
262 * 0: success, but abort further parsing of table (INIT_DONE etc)
263 * < 0: failure, table parsing will be aborted
264 */
259 int (*handler)(struct nvbios *, uint16_t, struct init_exec *); 265 int (*handler)(struct nvbios *, uint16_t, struct init_exec *);
260}; 266};
261 267
@@ -709,6 +715,83 @@ static int dcb_entry_idx_from_crtchead(struct drm_device *dev)
709 return dcb_entry; 715 return dcb_entry;
710} 716}
711 717
718static int
719read_dcb_i2c_entry(struct drm_device *dev, int dcb_version, uint8_t *i2ctable, int index, struct dcb_i2c_entry *i2c)
720{
721 uint8_t dcb_i2c_ver = dcb_version, headerlen = 0, entry_len = 4;
722 int i2c_entries = DCB_MAX_NUM_I2C_ENTRIES;
723 int recordoffset = 0, rdofs = 1, wrofs = 0;
724 uint8_t port_type = 0;
725
726 if (!i2ctable)
727 return -EINVAL;
728
729 if (dcb_version >= 0x30) {
730 if (i2ctable[0] != dcb_version) /* necessary? */
731 NV_WARN(dev,
732 "DCB I2C table version mismatch (%02X vs %02X)\n",
733 i2ctable[0], dcb_version);
734 dcb_i2c_ver = i2ctable[0];
735 headerlen = i2ctable[1];
736 if (i2ctable[2] <= DCB_MAX_NUM_I2C_ENTRIES)
737 i2c_entries = i2ctable[2];
738 else
739 NV_WARN(dev,
740 "DCB I2C table has more entries than indexable "
741 "(%d entries, max %d)\n", i2ctable[2],
742 DCB_MAX_NUM_I2C_ENTRIES);
743 entry_len = i2ctable[3];
744 /* [4] is i2c_default_indices, read in parse_dcb_table() */
745 }
746 /*
747 * It's your own fault if you call this function on a DCB 1.1 BIOS --
748 * the test below is for DCB 1.2
749 */
750 if (dcb_version < 0x14) {
751 recordoffset = 2;
752 rdofs = 0;
753 wrofs = 1;
754 }
755
756 if (index == 0xf)
757 return 0;
758 if (index >= i2c_entries) {
759 NV_ERROR(dev, "DCB I2C index too big (%d >= %d)\n",
760 index, i2ctable[2]);
761 return -ENOENT;
762 }
763 if (i2ctable[headerlen + entry_len * index + 3] == 0xff) {
764 NV_ERROR(dev, "DCB I2C entry invalid\n");
765 return -EINVAL;
766 }
767
768 if (dcb_i2c_ver >= 0x30) {
769 port_type = i2ctable[headerlen + recordoffset + 3 + entry_len * index];
770
771 /*
772 * Fixup for chips using same address offset for read and
773 * write.
774 */
775 if (port_type == 4) /* seen on C51 */
776 rdofs = wrofs = 1;
777 if (port_type >= 5) /* G80+ */
778 rdofs = wrofs = 0;
779 }
780
781 if (dcb_i2c_ver >= 0x40) {
782 if (port_type != 5 && port_type != 6)
783 NV_WARN(dev, "DCB I2C table has port type %d\n", port_type);
784
785 i2c->entry = ROM32(i2ctable[headerlen + recordoffset + entry_len * index]);
786 }
787
788 i2c->port_type = port_type;
789 i2c->read = i2ctable[headerlen + recordoffset + rdofs + entry_len * index];
790 i2c->write = i2ctable[headerlen + recordoffset + wrofs + entry_len * index];
791
792 return 0;
793}
794
712static struct nouveau_i2c_chan * 795static struct nouveau_i2c_chan *
713init_i2c_device_find(struct drm_device *dev, int i2c_index) 796init_i2c_device_find(struct drm_device *dev, int i2c_index)
714{ 797{
@@ -727,6 +810,20 @@ init_i2c_device_find(struct drm_device *dev, int i2c_index)
727 } 810 }
728 if (i2c_index == 0x80) /* g80+ */ 811 if (i2c_index == 0x80) /* g80+ */
729 i2c_index = dcb->i2c_default_indices & 0xf; 812 i2c_index = dcb->i2c_default_indices & 0xf;
813 else
814 if (i2c_index == 0x81)
815 i2c_index = (dcb->i2c_default_indices & 0xf0) >> 4;
816
817 if (i2c_index > DCB_MAX_NUM_I2C_ENTRIES) {
818 NV_ERROR(dev, "invalid i2c_index 0x%x\n", i2c_index);
819 return NULL;
820 }
821
822 /* Make sure i2c table entry has been parsed, it may not
823 * have been if this is a bus not referenced by a DCB encoder
824 */
825 read_dcb_i2c_entry(dev, dcb->version, dcb->i2c_table,
826 i2c_index, &dcb->i2c[i2c_index]);
730 827
731 return nouveau_i2c_find(dev, i2c_index); 828 return nouveau_i2c_find(dev, i2c_index);
732} 829}
@@ -818,7 +915,7 @@ init_io_restrict_prog(struct nvbios *bios, uint16_t offset,
818 NV_ERROR(bios->dev, 915 NV_ERROR(bios->dev,
819 "0x%04X: Config 0x%02X exceeds maximal bound 0x%02X\n", 916 "0x%04X: Config 0x%02X exceeds maximal bound 0x%02X\n",
820 offset, config, count); 917 offset, config, count);
821 return 0; 918 return -EINVAL;
822 } 919 }
823 920
824 configval = ROM32(bios->data[offset + 11 + config * 4]); 921 configval = ROM32(bios->data[offset + 11 + config * 4]);
@@ -920,7 +1017,7 @@ init_io_restrict_pll(struct nvbios *bios, uint16_t offset,
920 NV_ERROR(bios->dev, 1017 NV_ERROR(bios->dev,
921 "0x%04X: Config 0x%02X exceeds maximal bound 0x%02X\n", 1018 "0x%04X: Config 0x%02X exceeds maximal bound 0x%02X\n",
922 offset, config, count); 1019 offset, config, count);
923 return 0; 1020 return -EINVAL;
924 } 1021 }
925 1022
926 freq = ROM16(bios->data[offset + 12 + config * 2]); 1023 freq = ROM16(bios->data[offset + 12 + config * 2]);
@@ -1067,6 +1164,126 @@ init_io_flag_condition(struct nvbios *bios, uint16_t offset,
1067} 1164}
1068 1165
1069static int 1166static int
1167init_dp_condition(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1168{
1169 /*
1170 * INIT_DP_CONDITION opcode: 0x3A ('')
1171 *
1172 * offset (8 bit): opcode
1173 * offset + 1 (8 bit): "sub" opcode
1174 * offset + 2 (8 bit): unknown
1175 *
1176 */
1177
1178 struct bit_displayport_encoder_table *dpe = NULL;
1179 struct dcb_entry *dcb = bios->display.output;
1180 struct drm_device *dev = bios->dev;
1181 uint8_t cond = bios->data[offset + 1];
1182 int dummy;
1183
1184 BIOSLOG(bios, "0x%04X: subop 0x%02X\n", offset, cond);
1185
1186 if (!iexec->execute)
1187 return 3;
1188
1189 dpe = nouveau_bios_dp_table(dev, dcb, &dummy);
1190 if (!dpe) {
1191 NV_ERROR(dev, "0x%04X: INIT_3A: no encoder table!!\n", offset);
1192 return -EINVAL;
1193 }
1194
1195 switch (cond) {
1196 case 0:
1197 {
1198 struct dcb_connector_table_entry *ent =
1199 &bios->dcb.connector.entry[dcb->connector];
1200
1201 if (ent->type != DCB_CONNECTOR_eDP)
1202 iexec->execute = false;
1203 }
1204 break;
1205 case 1:
1206 case 2:
1207 if (!(dpe->unknown & cond))
1208 iexec->execute = false;
1209 break;
1210 case 5:
1211 {
1212 struct nouveau_i2c_chan *auxch;
1213 int ret;
1214
1215 auxch = nouveau_i2c_find(dev, bios->display.output->i2c_index);
1216 if (!auxch)
1217 return -ENODEV;
1218
1219 ret = nouveau_dp_auxch(auxch, 9, 0xd, &cond, 1);
1220 if (ret)
1221 return ret;
1222
1223 if (cond & 1)
1224 iexec->execute = false;
1225 }
1226 break;
1227 default:
1228 NV_WARN(dev, "0x%04X: unknown INIT_3A op: %d\n", offset, cond);
1229 break;
1230 }
1231
1232 if (iexec->execute)
1233 BIOSLOG(bios, "0x%04X: continuing to execute\n", offset);
1234 else
1235 BIOSLOG(bios, "0x%04X: skipping following commands\n", offset);
1236
1237 return 3;
1238}
1239
1240static int
1241init_op_3b(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1242{
1243 /*
1244 * INIT_3B opcode: 0x3B ('')
1245 *
1246 * offset (8 bit): opcode
1247 * offset + 1 (8 bit): crtc index
1248 *
1249 */
1250
1251 uint8_t or = ffs(bios->display.output->or) - 1;
1252 uint8_t index = bios->data[offset + 1];
1253 uint8_t data;
1254
1255 if (!iexec->execute)
1256 return 2;
1257
1258 data = bios_idxprt_rd(bios, 0x3d4, index);
1259 bios_idxprt_wr(bios, 0x3d4, index, data & ~(1 << or));
1260 return 2;
1261}
1262
1263static int
1264init_op_3c(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1265{
1266 /*
1267 * INIT_3C opcode: 0x3C ('')
1268 *
1269 * offset (8 bit): opcode
1270 * offset + 1 (8 bit): crtc index
1271 *
1272 */
1273
1274 uint8_t or = ffs(bios->display.output->or) - 1;
1275 uint8_t index = bios->data[offset + 1];
1276 uint8_t data;
1277
1278 if (!iexec->execute)
1279 return 2;
1280
1281 data = bios_idxprt_rd(bios, 0x3d4, index);
1282 bios_idxprt_wr(bios, 0x3d4, index, data | (1 << or));
1283 return 2;
1284}
1285
1286static int
1070init_idx_addr_latched(struct nvbios *bios, uint16_t offset, 1287init_idx_addr_latched(struct nvbios *bios, uint16_t offset,
1071 struct init_exec *iexec) 1288 struct init_exec *iexec)
1072{ 1289{
@@ -1170,7 +1387,7 @@ init_io_restrict_pll2(struct nvbios *bios, uint16_t offset,
1170 NV_ERROR(bios->dev, 1387 NV_ERROR(bios->dev,
1171 "0x%04X: Config 0x%02X exceeds maximal bound 0x%02X\n", 1388 "0x%04X: Config 0x%02X exceeds maximal bound 0x%02X\n",
1172 offset, config, count); 1389 offset, config, count);
1173 return 0; 1390 return -EINVAL;
1174 } 1391 }
1175 1392
1176 freq = ROM32(bios->data[offset + 11 + config * 4]); 1393 freq = ROM32(bios->data[offset + 11 + config * 4]);
@@ -1231,12 +1448,11 @@ init_i2c_byte(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1231 */ 1448 */
1232 1449
1233 uint8_t i2c_index = bios->data[offset + 1]; 1450 uint8_t i2c_index = bios->data[offset + 1];
1234 uint8_t i2c_address = bios->data[offset + 2]; 1451 uint8_t i2c_address = bios->data[offset + 2] >> 1;
1235 uint8_t count = bios->data[offset + 3]; 1452 uint8_t count = bios->data[offset + 3];
1236 int len = 4 + count * 3;
1237 struct nouveau_i2c_chan *chan; 1453 struct nouveau_i2c_chan *chan;
1238 struct i2c_msg msg; 1454 int len = 4 + count * 3;
1239 int i; 1455 int ret, i;
1240 1456
1241 if (!iexec->execute) 1457 if (!iexec->execute)
1242 return len; 1458 return len;
@@ -1247,35 +1463,34 @@ init_i2c_byte(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1247 1463
1248 chan = init_i2c_device_find(bios->dev, i2c_index); 1464 chan = init_i2c_device_find(bios->dev, i2c_index);
1249 if (!chan) 1465 if (!chan)
1250 return 0; 1466 return -ENODEV;
1251 1467
1252 for (i = 0; i < count; i++) { 1468 for (i = 0; i < count; i++) {
1253 uint8_t i2c_reg = bios->data[offset + 4 + i * 3]; 1469 uint8_t reg = bios->data[offset + 4 + i * 3];
1254 uint8_t mask = bios->data[offset + 5 + i * 3]; 1470 uint8_t mask = bios->data[offset + 5 + i * 3];
1255 uint8_t data = bios->data[offset + 6 + i * 3]; 1471 uint8_t data = bios->data[offset + 6 + i * 3];
1256 uint8_t value; 1472 union i2c_smbus_data val;
1257 1473
1258 msg.addr = i2c_address; 1474 ret = i2c_smbus_xfer(&chan->adapter, i2c_address, 0,
1259 msg.flags = I2C_M_RD; 1475 I2C_SMBUS_READ, reg,
1260 msg.len = 1; 1476 I2C_SMBUS_BYTE_DATA, &val);
1261 msg.buf = &value; 1477 if (ret < 0)
1262 if (i2c_transfer(&chan->adapter, &msg, 1) != 1) 1478 return ret;
1263 return 0;
1264 1479
1265 BIOSLOG(bios, "0x%04X: I2CReg: 0x%02X, Value: 0x%02X, " 1480 BIOSLOG(bios, "0x%04X: I2CReg: 0x%02X, Value: 0x%02X, "
1266 "Mask: 0x%02X, Data: 0x%02X\n", 1481 "Mask: 0x%02X, Data: 0x%02X\n",
1267 offset, i2c_reg, value, mask, data); 1482 offset, reg, val.byte, mask, data);
1268 1483
1269 value = (value & mask) | data; 1484 if (!bios->execute)
1485 continue;
1270 1486
1271 if (bios->execute) { 1487 val.byte &= mask;
1272 msg.addr = i2c_address; 1488 val.byte |= data;
1273 msg.flags = 0; 1489 ret = i2c_smbus_xfer(&chan->adapter, i2c_address, 0,
1274 msg.len = 1; 1490 I2C_SMBUS_WRITE, reg,
1275 msg.buf = &value; 1491 I2C_SMBUS_BYTE_DATA, &val);
1276 if (i2c_transfer(&chan->adapter, &msg, 1) != 1) 1492 if (ret < 0)
1277 return 0; 1493 return ret;
1278 }
1279 } 1494 }
1280 1495
1281 return len; 1496 return len;
@@ -1301,12 +1516,11 @@ init_zm_i2c_byte(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1301 */ 1516 */
1302 1517
1303 uint8_t i2c_index = bios->data[offset + 1]; 1518 uint8_t i2c_index = bios->data[offset + 1];
1304 uint8_t i2c_address = bios->data[offset + 2]; 1519 uint8_t i2c_address = bios->data[offset + 2] >> 1;
1305 uint8_t count = bios->data[offset + 3]; 1520 uint8_t count = bios->data[offset + 3];
1306 int len = 4 + count * 2;
1307 struct nouveau_i2c_chan *chan; 1521 struct nouveau_i2c_chan *chan;
1308 struct i2c_msg msg; 1522 int len = 4 + count * 2;
1309 int i; 1523 int ret, i;
1310 1524
1311 if (!iexec->execute) 1525 if (!iexec->execute)
1312 return len; 1526 return len;
@@ -1317,23 +1531,25 @@ init_zm_i2c_byte(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1317 1531
1318 chan = init_i2c_device_find(bios->dev, i2c_index); 1532 chan = init_i2c_device_find(bios->dev, i2c_index);
1319 if (!chan) 1533 if (!chan)
1320 return 0; 1534 return -ENODEV;
1321 1535
1322 for (i = 0; i < count; i++) { 1536 for (i = 0; i < count; i++) {
1323 uint8_t i2c_reg = bios->data[offset + 4 + i * 2]; 1537 uint8_t reg = bios->data[offset + 4 + i * 2];
1324 uint8_t data = bios->data[offset + 5 + i * 2]; 1538 union i2c_smbus_data val;
1539
1540 val.byte = bios->data[offset + 5 + i * 2];
1325 1541
1326 BIOSLOG(bios, "0x%04X: I2CReg: 0x%02X, Data: 0x%02X\n", 1542 BIOSLOG(bios, "0x%04X: I2CReg: 0x%02X, Data: 0x%02X\n",
1327 offset, i2c_reg, data); 1543 offset, reg, val.byte);
1328 1544
1329 if (bios->execute) { 1545 if (!bios->execute)
1330 msg.addr = i2c_address; 1546 continue;
1331 msg.flags = 0; 1547
1332 msg.len = 1; 1548 ret = i2c_smbus_xfer(&chan->adapter, i2c_address, 0,
1333 msg.buf = &data; 1549 I2C_SMBUS_WRITE, reg,
1334 if (i2c_transfer(&chan->adapter, &msg, 1) != 1) 1550 I2C_SMBUS_BYTE_DATA, &val);
1335 return 0; 1551 if (ret < 0)
1336 } 1552 return ret;
1337 } 1553 }
1338 1554
1339 return len; 1555 return len;
@@ -1357,7 +1573,7 @@ init_zm_i2c(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1357 */ 1573 */
1358 1574
1359 uint8_t i2c_index = bios->data[offset + 1]; 1575 uint8_t i2c_index = bios->data[offset + 1];
1360 uint8_t i2c_address = bios->data[offset + 2]; 1576 uint8_t i2c_address = bios->data[offset + 2] >> 1;
1361 uint8_t count = bios->data[offset + 3]; 1577 uint8_t count = bios->data[offset + 3];
1362 int len = 4 + count; 1578 int len = 4 + count;
1363 struct nouveau_i2c_chan *chan; 1579 struct nouveau_i2c_chan *chan;
@@ -1374,7 +1590,7 @@ init_zm_i2c(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1374 1590
1375 chan = init_i2c_device_find(bios->dev, i2c_index); 1591 chan = init_i2c_device_find(bios->dev, i2c_index);
1376 if (!chan) 1592 if (!chan)
1377 return 0; 1593 return -ENODEV;
1378 1594
1379 for (i = 0; i < count; i++) { 1595 for (i = 0; i < count; i++) {
1380 data[i] = bios->data[offset + 4 + i]; 1596 data[i] = bios->data[offset + 4 + i];
@@ -1388,7 +1604,7 @@ init_zm_i2c(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1388 msg.len = count; 1604 msg.len = count;
1389 msg.buf = data; 1605 msg.buf = data;
1390 if (i2c_transfer(&chan->adapter, &msg, 1) != 1) 1606 if (i2c_transfer(&chan->adapter, &msg, 1) != 1)
1391 return 0; 1607 return -EIO;
1392 } 1608 }
1393 1609
1394 return len; 1610 return len;
@@ -1427,7 +1643,7 @@ init_tmds(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1427 1643
1428 reg = get_tmds_index_reg(bios->dev, mlv); 1644 reg = get_tmds_index_reg(bios->dev, mlv);
1429 if (!reg) 1645 if (!reg)
1430 return 0; 1646 return -EINVAL;
1431 1647
1432 bios_wr32(bios, reg, 1648 bios_wr32(bios, reg,
1433 tmdsaddr | NV_PRAMDAC_FP_TMDS_CONTROL_WRITE_DISABLE); 1649 tmdsaddr | NV_PRAMDAC_FP_TMDS_CONTROL_WRITE_DISABLE);
@@ -1471,7 +1687,7 @@ init_zm_tmds_group(struct nvbios *bios, uint16_t offset,
1471 1687
1472 reg = get_tmds_index_reg(bios->dev, mlv); 1688 reg = get_tmds_index_reg(bios->dev, mlv);
1473 if (!reg) 1689 if (!reg)
1474 return 0; 1690 return -EINVAL;
1475 1691
1476 for (i = 0; i < count; i++) { 1692 for (i = 0; i < count; i++) {
1477 uint8_t tmdsaddr = bios->data[offset + 3 + i * 2]; 1693 uint8_t tmdsaddr = bios->data[offset + 3 + i * 2];
@@ -1946,7 +2162,7 @@ init_configure_mem(struct nvbios *bios, uint16_t offset,
1946 uint32_t reg, data; 2162 uint32_t reg, data;
1947 2163
1948 if (bios->major_version > 2) 2164 if (bios->major_version > 2)
1949 return 0; 2165 return -ENODEV;
1950 2166
1951 bios_idxprt_wr(bios, NV_VIO_SRX, NV_VIO_SR_CLOCK_INDEX, bios_idxprt_rd( 2167 bios_idxprt_wr(bios, NV_VIO_SRX, NV_VIO_SR_CLOCK_INDEX, bios_idxprt_rd(
1952 bios, NV_VIO_SRX, NV_VIO_SR_CLOCK_INDEX) | 0x20); 2168 bios, NV_VIO_SRX, NV_VIO_SR_CLOCK_INDEX) | 0x20);
@@ -2001,7 +2217,7 @@ init_configure_clk(struct nvbios *bios, uint16_t offset,
2001 int clock; 2217 int clock;
2002 2218
2003 if (bios->major_version > 2) 2219 if (bios->major_version > 2)
2004 return 0; 2220 return -ENODEV;
2005 2221
2006 clock = ROM16(bios->data[meminitoffs + 4]) * 10; 2222 clock = ROM16(bios->data[meminitoffs + 4]) * 10;
2007 setPLL(bios, NV_PRAMDAC_NVPLL_COEFF, clock); 2223 setPLL(bios, NV_PRAMDAC_NVPLL_COEFF, clock);
@@ -2034,7 +2250,7 @@ init_configure_preinit(struct nvbios *bios, uint16_t offset,
2034 uint8_t cr3c = ((straps << 2) & 0xf0) | (straps & (1 << 6)); 2250 uint8_t cr3c = ((straps << 2) & 0xf0) | (straps & (1 << 6));
2035 2251
2036 if (bios->major_version > 2) 2252 if (bios->major_version > 2)
2037 return 0; 2253 return -ENODEV;
2038 2254
2039 bios_idxprt_wr(bios, NV_CIO_CRX__COLOR, 2255 bios_idxprt_wr(bios, NV_CIO_CRX__COLOR,
2040 NV_CIO_CRE_SCRATCH4__INDEX, cr3c); 2256 NV_CIO_CRE_SCRATCH4__INDEX, cr3c);
@@ -2656,7 +2872,7 @@ init_ram_restrict_zm_reg_group(struct nvbios *bios, uint16_t offset,
2656 NV_ERROR(bios->dev, 2872 NV_ERROR(bios->dev,
2657 "0x%04X: Zero block length - has the M table " 2873 "0x%04X: Zero block length - has the M table "
2658 "been parsed?\n", offset); 2874 "been parsed?\n", offset);
2659 return 0; 2875 return -EINVAL;
2660 } 2876 }
2661 2877
2662 strap_ramcfg = (bios_rd32(bios, NV_PEXTDEV_BOOT_0) >> 2) & 0xf; 2878 strap_ramcfg = (bios_rd32(bios, NV_PEXTDEV_BOOT_0) >> 2) & 0xf;
@@ -2840,14 +3056,14 @@ init_auxch(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2840 3056
2841 if (!bios->display.output) { 3057 if (!bios->display.output) {
2842 NV_ERROR(dev, "INIT_AUXCH: no active output\n"); 3058 NV_ERROR(dev, "INIT_AUXCH: no active output\n");
2843 return 0; 3059 return -EINVAL;
2844 } 3060 }
2845 3061
2846 auxch = init_i2c_device_find(dev, bios->display.output->i2c_index); 3062 auxch = init_i2c_device_find(dev, bios->display.output->i2c_index);
2847 if (!auxch) { 3063 if (!auxch) {
2848 NV_ERROR(dev, "INIT_AUXCH: couldn't get auxch %d\n", 3064 NV_ERROR(dev, "INIT_AUXCH: couldn't get auxch %d\n",
2849 bios->display.output->i2c_index); 3065 bios->display.output->i2c_index);
2850 return 0; 3066 return -ENODEV;
2851 } 3067 }
2852 3068
2853 if (!iexec->execute) 3069 if (!iexec->execute)
@@ -2860,7 +3076,7 @@ init_auxch(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2860 ret = nouveau_dp_auxch(auxch, 9, addr, &data, 1); 3076 ret = nouveau_dp_auxch(auxch, 9, addr, &data, 1);
2861 if (ret) { 3077 if (ret) {
2862 NV_ERROR(dev, "INIT_AUXCH: rd auxch fail %d\n", ret); 3078 NV_ERROR(dev, "INIT_AUXCH: rd auxch fail %d\n", ret);
2863 return 0; 3079 return ret;
2864 } 3080 }
2865 3081
2866 data &= bios->data[offset + 0]; 3082 data &= bios->data[offset + 0];
@@ -2869,7 +3085,7 @@ init_auxch(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2869 ret = nouveau_dp_auxch(auxch, 8, addr, &data, 1); 3085 ret = nouveau_dp_auxch(auxch, 8, addr, &data, 1);
2870 if (ret) { 3086 if (ret) {
2871 NV_ERROR(dev, "INIT_AUXCH: wr auxch fail %d\n", ret); 3087 NV_ERROR(dev, "INIT_AUXCH: wr auxch fail %d\n", ret);
2872 return 0; 3088 return ret;
2873 } 3089 }
2874 } 3090 }
2875 3091
@@ -2899,14 +3115,14 @@ init_zm_auxch(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2899 3115
2900 if (!bios->display.output) { 3116 if (!bios->display.output) {
2901 NV_ERROR(dev, "INIT_ZM_AUXCH: no active output\n"); 3117 NV_ERROR(dev, "INIT_ZM_AUXCH: no active output\n");
2902 return 0; 3118 return -EINVAL;
2903 } 3119 }
2904 3120
2905 auxch = init_i2c_device_find(dev, bios->display.output->i2c_index); 3121 auxch = init_i2c_device_find(dev, bios->display.output->i2c_index);
2906 if (!auxch) { 3122 if (!auxch) {
2907 NV_ERROR(dev, "INIT_ZM_AUXCH: couldn't get auxch %d\n", 3123 NV_ERROR(dev, "INIT_ZM_AUXCH: couldn't get auxch %d\n",
2908 bios->display.output->i2c_index); 3124 bios->display.output->i2c_index);
2909 return 0; 3125 return -ENODEV;
2910 } 3126 }
2911 3127
2912 if (!iexec->execute) 3128 if (!iexec->execute)
@@ -2917,7 +3133,7 @@ init_zm_auxch(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2917 ret = nouveau_dp_auxch(auxch, 8, addr, &bios->data[offset], 1); 3133 ret = nouveau_dp_auxch(auxch, 8, addr, &bios->data[offset], 1);
2918 if (ret) { 3134 if (ret) {
2919 NV_ERROR(dev, "INIT_ZM_AUXCH: wr auxch fail %d\n", ret); 3135 NV_ERROR(dev, "INIT_ZM_AUXCH: wr auxch fail %d\n", ret);
2920 return 0; 3136 return ret;
2921 } 3137 }
2922 } 3138 }
2923 3139
@@ -2934,6 +3150,9 @@ static struct init_tbl_entry itbl_entry[] = {
2934 { "INIT_COPY" , 0x37, init_copy }, 3150 { "INIT_COPY" , 0x37, init_copy },
2935 { "INIT_NOT" , 0x38, init_not }, 3151 { "INIT_NOT" , 0x38, init_not },
2936 { "INIT_IO_FLAG_CONDITION" , 0x39, init_io_flag_condition }, 3152 { "INIT_IO_FLAG_CONDITION" , 0x39, init_io_flag_condition },
3153 { "INIT_DP_CONDITION" , 0x3A, init_dp_condition },
3154 { "INIT_OP_3B" , 0x3B, init_op_3b },
3155 { "INIT_OP_3C" , 0x3C, init_op_3c },
2937 { "INIT_INDEX_ADDRESS_LATCHED" , 0x49, init_idx_addr_latched }, 3156 { "INIT_INDEX_ADDRESS_LATCHED" , 0x49, init_idx_addr_latched },
2938 { "INIT_IO_RESTRICT_PLL2" , 0x4A, init_io_restrict_pll2 }, 3157 { "INIT_IO_RESTRICT_PLL2" , 0x4A, init_io_restrict_pll2 },
2939 { "INIT_PLL2" , 0x4B, init_pll2 }, 3158 { "INIT_PLL2" , 0x4B, init_pll2 },
@@ -3001,7 +3220,7 @@ parse_init_table(struct nvbios *bios, unsigned int offset,
3001 * is changed back to EXECUTE. 3220 * is changed back to EXECUTE.
3002 */ 3221 */
3003 3222
3004 int count = 0, i, res; 3223 int count = 0, i, ret;
3005 uint8_t id; 3224 uint8_t id;
3006 3225
3007 /* 3226 /*
@@ -3016,26 +3235,33 @@ parse_init_table(struct nvbios *bios, unsigned int offset,
3016 for (i = 0; itbl_entry[i].name && (itbl_entry[i].id != id); i++) 3235 for (i = 0; itbl_entry[i].name && (itbl_entry[i].id != id); i++)
3017 ; 3236 ;
3018 3237
3019 if (itbl_entry[i].name) { 3238 if (!itbl_entry[i].name) {
3020 BIOSLOG(bios, "0x%04X: [ (0x%02X) - %s ]\n",
3021 offset, itbl_entry[i].id, itbl_entry[i].name);
3022
3023 /* execute eventual command handler */
3024 res = (*itbl_entry[i].handler)(bios, offset, iexec);
3025 if (!res)
3026 break;
3027 /*
3028 * Add the offset of the current command including all data
3029 * of that command. The offset will then be pointing on the
3030 * next op code.
3031 */
3032 offset += res;
3033 } else {
3034 NV_ERROR(bios->dev, 3239 NV_ERROR(bios->dev,
3035 "0x%04X: Init table command not found: " 3240 "0x%04X: Init table command not found: "
3036 "0x%02X\n", offset, id); 3241 "0x%02X\n", offset, id);
3037 return -ENOENT; 3242 return -ENOENT;
3038 } 3243 }
3244
3245 BIOSLOG(bios, "0x%04X: [ (0x%02X) - %s ]\n", offset,
3246 itbl_entry[i].id, itbl_entry[i].name);
3247
3248 /* execute eventual command handler */
3249 ret = (*itbl_entry[i].handler)(bios, offset, iexec);
3250 if (ret < 0) {
3251 NV_ERROR(bios->dev, "0x%04X: Failed parsing init "
3252 "table opcode: %s %d\n", offset,
3253 itbl_entry[i].name, ret);
3254 }
3255
3256 if (ret <= 0)
3257 break;
3258
3259 /*
3260 * Add the offset of the current command including all data
3261 * of that command. The offset will then be pointing on the
3262 * next op code.
3263 */
3264 offset += ret;
3039 } 3265 }
3040 3266
3041 if (offset >= bios->length) 3267 if (offset >= bios->length)
@@ -4285,31 +4511,32 @@ int get_pll_limits(struct drm_device *dev, uint32_t limit_match, struct pll_lims
4285 break; 4511 break;
4286 } 4512 }
4287 4513
4288#if 0 /* for easy debugging */ 4514 NV_DEBUG(dev, "pll.vco1.minfreq: %d\n", pll_lim->vco1.minfreq);
4289 ErrorF("pll.vco1.minfreq: %d\n", pll_lim->vco1.minfreq); 4515 NV_DEBUG(dev, "pll.vco1.maxfreq: %d\n", pll_lim->vco1.maxfreq);
4290 ErrorF("pll.vco1.maxfreq: %d\n", pll_lim->vco1.maxfreq); 4516 NV_DEBUG(dev, "pll.vco1.min_inputfreq: %d\n", pll_lim->vco1.min_inputfreq);
4291 ErrorF("pll.vco2.minfreq: %d\n", pll_lim->vco2.minfreq); 4517 NV_DEBUG(dev, "pll.vco1.max_inputfreq: %d\n", pll_lim->vco1.max_inputfreq);
4292 ErrorF("pll.vco2.maxfreq: %d\n", pll_lim->vco2.maxfreq); 4518 NV_DEBUG(dev, "pll.vco1.min_n: %d\n", pll_lim->vco1.min_n);
4293 4519 NV_DEBUG(dev, "pll.vco1.max_n: %d\n", pll_lim->vco1.max_n);
4294 ErrorF("pll.vco1.min_inputfreq: %d\n", pll_lim->vco1.min_inputfreq); 4520 NV_DEBUG(dev, "pll.vco1.min_m: %d\n", pll_lim->vco1.min_m);
4295 ErrorF("pll.vco1.max_inputfreq: %d\n", pll_lim->vco1.max_inputfreq); 4521 NV_DEBUG(dev, "pll.vco1.max_m: %d\n", pll_lim->vco1.max_m);
4296 ErrorF("pll.vco2.min_inputfreq: %d\n", pll_lim->vco2.min_inputfreq); 4522 if (pll_lim->vco2.maxfreq) {
4297 ErrorF("pll.vco2.max_inputfreq: %d\n", pll_lim->vco2.max_inputfreq); 4523 NV_DEBUG(dev, "pll.vco2.minfreq: %d\n", pll_lim->vco2.minfreq);
4298 4524 NV_DEBUG(dev, "pll.vco2.maxfreq: %d\n", pll_lim->vco2.maxfreq);
4299 ErrorF("pll.vco1.min_n: %d\n", pll_lim->vco1.min_n); 4525 NV_DEBUG(dev, "pll.vco2.min_inputfreq: %d\n", pll_lim->vco2.min_inputfreq);
4300 ErrorF("pll.vco1.max_n: %d\n", pll_lim->vco1.max_n); 4526 NV_DEBUG(dev, "pll.vco2.max_inputfreq: %d\n", pll_lim->vco2.max_inputfreq);
4301 ErrorF("pll.vco1.min_m: %d\n", pll_lim->vco1.min_m); 4527 NV_DEBUG(dev, "pll.vco2.min_n: %d\n", pll_lim->vco2.min_n);
4302 ErrorF("pll.vco1.max_m: %d\n", pll_lim->vco1.max_m); 4528 NV_DEBUG(dev, "pll.vco2.max_n: %d\n", pll_lim->vco2.max_n);
4303 ErrorF("pll.vco2.min_n: %d\n", pll_lim->vco2.min_n); 4529 NV_DEBUG(dev, "pll.vco2.min_m: %d\n", pll_lim->vco2.min_m);
4304 ErrorF("pll.vco2.max_n: %d\n", pll_lim->vco2.max_n); 4530 NV_DEBUG(dev, "pll.vco2.max_m: %d\n", pll_lim->vco2.max_m);
4305 ErrorF("pll.vco2.min_m: %d\n", pll_lim->vco2.min_m); 4531 }
4306 ErrorF("pll.vco2.max_m: %d\n", pll_lim->vco2.max_m); 4532 if (!pll_lim->max_p) {
4307 4533 NV_DEBUG(dev, "pll.max_log2p: %d\n", pll_lim->max_log2p);
4308 ErrorF("pll.max_log2p: %d\n", pll_lim->max_log2p); 4534 NV_DEBUG(dev, "pll.log2p_bias: %d\n", pll_lim->log2p_bias);
4309 ErrorF("pll.log2p_bias: %d\n", pll_lim->log2p_bias); 4535 } else {
4310 4536 NV_DEBUG(dev, "pll.min_p: %d\n", pll_lim->min_p);
4311 ErrorF("pll.refclk: %d\n", pll_lim->refclk); 4537 NV_DEBUG(dev, "pll.max_p: %d\n", pll_lim->max_p);
4312#endif 4538 }
4539 NV_DEBUG(dev, "pll.refclk: %d\n", pll_lim->refclk);
4313 4540
4314 return 0; 4541 return 0;
4315} 4542}
@@ -4953,79 +5180,6 @@ static uint16_t findstr(uint8_t *data, int n, const uint8_t *str, int len)
4953 return 0; 5180 return 0;
4954} 5181}
4955 5182
4956static int
4957read_dcb_i2c_entry(struct drm_device *dev, int dcb_version, uint8_t *i2ctable, int index, struct dcb_i2c_entry *i2c)
4958{
4959 uint8_t dcb_i2c_ver = dcb_version, headerlen = 0, entry_len = 4;
4960 int i2c_entries = DCB_MAX_NUM_I2C_ENTRIES;
4961 int recordoffset = 0, rdofs = 1, wrofs = 0;
4962 uint8_t port_type = 0;
4963
4964 if (!i2ctable)
4965 return -EINVAL;
4966
4967 if (dcb_version >= 0x30) {
4968 if (i2ctable[0] != dcb_version) /* necessary? */
4969 NV_WARN(dev,
4970 "DCB I2C table version mismatch (%02X vs %02X)\n",
4971 i2ctable[0], dcb_version);
4972 dcb_i2c_ver = i2ctable[0];
4973 headerlen = i2ctable[1];
4974 if (i2ctable[2] <= DCB_MAX_NUM_I2C_ENTRIES)
4975 i2c_entries = i2ctable[2];
4976 else
4977 NV_WARN(dev,
4978 "DCB I2C table has more entries than indexable "
4979 "(%d entries, max %d)\n", i2ctable[2],
4980 DCB_MAX_NUM_I2C_ENTRIES);
4981 entry_len = i2ctable[3];
4982 /* [4] is i2c_default_indices, read in parse_dcb_table() */
4983 }
4984 /*
4985 * It's your own fault if you call this function on a DCB 1.1 BIOS --
4986 * the test below is for DCB 1.2
4987 */
4988 if (dcb_version < 0x14) {
4989 recordoffset = 2;
4990 rdofs = 0;
4991 wrofs = 1;
4992 }
4993
4994 if (index == 0xf)
4995 return 0;
4996 if (index >= i2c_entries) {
4997 NV_ERROR(dev, "DCB I2C index too big (%d >= %d)\n",
4998 index, i2ctable[2]);
4999 return -ENOENT;
5000 }
5001 if (i2ctable[headerlen + entry_len * index + 3] == 0xff) {
5002 NV_ERROR(dev, "DCB I2C entry invalid\n");
5003 return -EINVAL;
5004 }
5005
5006 if (dcb_i2c_ver >= 0x30) {
5007 port_type = i2ctable[headerlen + recordoffset + 3 + entry_len * index];
5008
5009 /*
5010 * Fixup for chips using same address offset for read and
5011 * write.
5012 */
5013 if (port_type == 4) /* seen on C51 */
5014 rdofs = wrofs = 1;
5015 if (port_type >= 5) /* G80+ */
5016 rdofs = wrofs = 0;
5017 }
5018
5019 if (dcb_i2c_ver >= 0x40 && port_type != 5 && port_type != 6)
5020 NV_WARN(dev, "DCB I2C table has port type %d\n", port_type);
5021
5022 i2c->port_type = port_type;
5023 i2c->read = i2ctable[headerlen + recordoffset + rdofs + entry_len * index];
5024 i2c->write = i2ctable[headerlen + recordoffset + wrofs + entry_len * index];
5025
5026 return 0;
5027}
5028
5029static struct dcb_gpio_entry * 5183static struct dcb_gpio_entry *
5030new_gpio_entry(struct nvbios *bios) 5184new_gpio_entry(struct nvbios *bios)
5031{ 5185{