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.c904
1 files changed, 216 insertions, 688 deletions
diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
index 5fc201b49d30..e5cbead85e50 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
@@ -27,6 +27,7 @@
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#include "nouveau_encoder.h"
30#include "nouveau_gpio.h"
30 31
31#include <linux/io-mapping.h> 32#include <linux/io-mapping.h>
32 33
@@ -34,9 +35,6 @@
34#define NV_CIO_CRE_44_HEADA 0x0 35#define NV_CIO_CRE_44_HEADA 0x0
35#define NV_CIO_CRE_44_HEADB 0x3 36#define NV_CIO_CRE_44_HEADB 0x3
36#define FEATURE_MOBILE 0x10 /* also FEATURE_QUADRO for BMP */ 37#define FEATURE_MOBILE 0x10 /* also FEATURE_QUADRO for BMP */
37#define LEGACY_I2C_CRT 0x80
38#define LEGACY_I2C_PANEL 0x81
39#define LEGACY_I2C_TV 0x82
40 38
41#define EDID1_LEN 128 39#define EDID1_LEN 128
42 40
@@ -723,115 +721,19 @@ static int dcb_entry_idx_from_crtchead(struct drm_device *dev)
723 return dcb_entry; 721 return dcb_entry;
724} 722}
725 723
726static int
727read_dcb_i2c_entry(struct drm_device *dev, int dcb_version, uint8_t *i2ctable, int index, struct dcb_i2c_entry *i2c)
728{
729 uint8_t dcb_i2c_ver = dcb_version, headerlen = 0, entry_len = 4;
730 int i2c_entries = DCB_MAX_NUM_I2C_ENTRIES;
731 int recordoffset = 0, rdofs = 1, wrofs = 0;
732 uint8_t port_type = 0;
733
734 if (!i2ctable)
735 return -EINVAL;
736
737 if (dcb_version >= 0x30) {
738 if (i2ctable[0] != dcb_version) /* necessary? */
739 NV_WARN(dev,
740 "DCB I2C table version mismatch (%02X vs %02X)\n",
741 i2ctable[0], dcb_version);
742 dcb_i2c_ver = i2ctable[0];
743 headerlen = i2ctable[1];
744 if (i2ctable[2] <= DCB_MAX_NUM_I2C_ENTRIES)
745 i2c_entries = i2ctable[2];
746 else
747 NV_WARN(dev,
748 "DCB I2C table has more entries than indexable "
749 "(%d entries, max %d)\n", i2ctable[2],
750 DCB_MAX_NUM_I2C_ENTRIES);
751 entry_len = i2ctable[3];
752 /* [4] is i2c_default_indices, read in parse_dcb_table() */
753 }
754 /*
755 * It's your own fault if you call this function on a DCB 1.1 BIOS --
756 * the test below is for DCB 1.2
757 */
758 if (dcb_version < 0x14) {
759 recordoffset = 2;
760 rdofs = 0;
761 wrofs = 1;
762 }
763
764 if (index == 0xf)
765 return 0;
766 if (index >= i2c_entries) {
767 NV_ERROR(dev, "DCB I2C index too big (%d >= %d)\n",
768 index, i2ctable[2]);
769 return -ENOENT;
770 }
771 if (i2ctable[headerlen + entry_len * index + 3] == 0xff) {
772 NV_ERROR(dev, "DCB I2C entry invalid\n");
773 return -EINVAL;
774 }
775
776 if (dcb_i2c_ver >= 0x30) {
777 port_type = i2ctable[headerlen + recordoffset + 3 + entry_len * index];
778
779 /*
780 * Fixup for chips using same address offset for read and
781 * write.
782 */
783 if (port_type == 4) /* seen on C51 */
784 rdofs = wrofs = 1;
785 if (port_type >= 5) /* G80+ */
786 rdofs = wrofs = 0;
787 }
788
789 if (dcb_i2c_ver >= 0x40) {
790 if (port_type != 5 && port_type != 6)
791 NV_WARN(dev, "DCB I2C table has port type %d\n", port_type);
792
793 i2c->entry = ROM32(i2ctable[headerlen + recordoffset + entry_len * index]);
794 }
795
796 i2c->port_type = port_type;
797 i2c->read = i2ctable[headerlen + recordoffset + rdofs + entry_len * index];
798 i2c->write = i2ctable[headerlen + recordoffset + wrofs + entry_len * index];
799
800 return 0;
801}
802
803static struct nouveau_i2c_chan * 724static struct nouveau_i2c_chan *
804init_i2c_device_find(struct drm_device *dev, int i2c_index) 725init_i2c_device_find(struct drm_device *dev, int i2c_index)
805{ 726{
806 struct drm_nouveau_private *dev_priv = dev->dev_private;
807 struct dcb_table *dcb = &dev_priv->vbios.dcb;
808
809 if (i2c_index == 0xff) { 727 if (i2c_index == 0xff) {
728 struct drm_nouveau_private *dev_priv = dev->dev_private;
729 struct dcb_table *dcb = &dev_priv->vbios.dcb;
810 /* note: dcb_entry_idx_from_crtchead needs pre-script set-up */ 730 /* note: dcb_entry_idx_from_crtchead needs pre-script set-up */
811 int idx = dcb_entry_idx_from_crtchead(dev), shift = 0; 731 int idx = dcb_entry_idx_from_crtchead(dev);
812 int default_indices = dcb->i2c_default_indices;
813 732
733 i2c_index = NV_I2C_DEFAULT(0);
814 if (idx != 0x7f && dcb->entry[idx].i2c_upper_default) 734 if (idx != 0x7f && dcb->entry[idx].i2c_upper_default)
815 shift = 4; 735 i2c_index = NV_I2C_DEFAULT(1);
816
817 i2c_index = (default_indices >> shift) & 0xf;
818 } 736 }
819 if (i2c_index == 0x80) /* g80+ */
820 i2c_index = dcb->i2c_default_indices & 0xf;
821 else
822 if (i2c_index == 0x81)
823 i2c_index = (dcb->i2c_default_indices & 0xf0) >> 4;
824
825 if (i2c_index >= DCB_MAX_NUM_I2C_ENTRIES) {
826 NV_ERROR(dev, "invalid i2c_index 0x%x\n", i2c_index);
827 return NULL;
828 }
829
830 /* Make sure i2c table entry has been parsed, it may not
831 * have been if this is a bus not referenced by a DCB encoder
832 */
833 read_dcb_i2c_entry(dev, dcb->version, dcb->i2c_table,
834 i2c_index, &dcb->i2c[i2c_index]);
835 737
836 return nouveau_i2c_find(dev, i2c_index); 738 return nouveau_i2c_find(dev, i2c_index);
837} 739}
@@ -1199,13 +1101,9 @@ init_dp_condition(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1199 1101
1200 switch (cond) { 1102 switch (cond) {
1201 case 0: 1103 case 0:
1202 { 1104 entry = dcb_conn(dev, dcb->connector);
1203 struct dcb_connector_table_entry *ent = 1105 if (!entry || entry[0] != DCB_CONNECTOR_eDP)
1204 &bios->dcb.connector.entry[dcb->connector];
1205
1206 if (ent->type != DCB_CONNECTOR_eDP)
1207 iexec->execute = false; 1106 iexec->execute = false;
1208 }
1209 break; 1107 break;
1210 case 1: 1108 case 1:
1211 case 2: 1109 case 2:
@@ -3227,49 +3125,6 @@ init_8d(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
3227 return 1; 3125 return 1;
3228} 3126}
3229 3127
3230static void
3231init_gpio_unknv50(struct nvbios *bios, struct dcb_gpio_entry *gpio)
3232{
3233 const uint32_t nv50_gpio_ctl[2] = { 0xe100, 0xe28c };
3234 u32 r, s, v;
3235
3236 /* Not a clue, needs de-magicing */
3237 r = nv50_gpio_ctl[gpio->line >> 4];
3238 s = (gpio->line & 0x0f);
3239 v = bios_rd32(bios, r) & ~(0x00010001 << s);
3240 switch ((gpio->entry & 0x06000000) >> 25) {
3241 case 1:
3242 v |= (0x00000001 << s);
3243 break;
3244 case 2:
3245 v |= (0x00010000 << s);
3246 break;
3247 default:
3248 break;
3249 }
3250
3251 bios_wr32(bios, r, v);
3252}
3253
3254static void
3255init_gpio_unknvd0(struct nvbios *bios, struct dcb_gpio_entry *gpio)
3256{
3257 u32 v, i;
3258
3259 v = bios_rd32(bios, 0x00d610 + (gpio->line * 4));
3260 v &= 0xffffff00;
3261 v |= (gpio->entry & 0x00ff0000) >> 16;
3262 bios_wr32(bios, 0x00d610 + (gpio->line * 4), v);
3263
3264 i = (gpio->entry & 0x1f000000) >> 24;
3265 if (i) {
3266 v = bios_rd32(bios, 0x00d640 + ((i - 1) * 4));
3267 v &= 0xffffff00;
3268 v |= gpio->line;
3269 bios_wr32(bios, 0x00d640 + ((i - 1) * 4), v);
3270 }
3271}
3272
3273static int 3128static int
3274init_gpio(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 3129init_gpio(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
3275{ 3130{
@@ -3282,35 +3137,8 @@ init_gpio(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
3282 * each GPIO according to various values listed in each entry 3137 * each GPIO according to various values listed in each entry
3283 */ 3138 */
3284 3139
3285 struct drm_nouveau_private *dev_priv = bios->dev->dev_private; 3140 if (iexec->execute && bios->execute)
3286 struct nouveau_gpio_engine *pgpio = &dev_priv->engine.gpio; 3141 nouveau_gpio_reset(bios->dev);
3287 int i;
3288
3289 if (dev_priv->card_type < NV_50) {
3290 NV_ERROR(bios->dev, "INIT_GPIO on unsupported chipset\n");
3291 return 1;
3292 }
3293
3294 if (!iexec->execute)
3295 return 1;
3296
3297 for (i = 0; i < bios->dcb.gpio.entries; i++) {
3298 struct dcb_gpio_entry *gpio = &bios->dcb.gpio.entry[i];
3299
3300 BIOSLOG(bios, "0x%04X: Entry: 0x%08X\n", offset, gpio->entry);
3301
3302 BIOSLOG(bios, "0x%04X: set gpio 0x%02x, state %d\n",
3303 offset, gpio->tag, gpio->state_default);
3304
3305 if (!bios->execute)
3306 continue;
3307
3308 pgpio->set(bios->dev, gpio->tag, gpio->state_default);
3309 if (dev_priv->card_type < NV_D0)
3310 init_gpio_unknv50(bios, gpio);
3311 else
3312 init_gpio_unknvd0(bios, gpio);
3313 }
3314 3142
3315 return 1; 3143 return 1;
3316} 3144}
@@ -4407,18 +4235,6 @@ int nouveau_bios_parse_lvds_table(struct drm_device *dev, int pxclk, bool *dl, b
4407 break; 4235 break;
4408 } 4236 }
4409 4237
4410 /* Dell Latitude D620 reports a too-high value for the dual-link
4411 * transition freq, causing us to program the panel incorrectly.
4412 *
4413 * It doesn't appear the VBIOS actually uses its transition freq
4414 * (90000kHz), instead it uses the "Number of LVDS channels" field
4415 * out of the panel ID structure (http://www.spwg.org/).
4416 *
4417 * For the moment, a quirk will do :)
4418 */
4419 if (nv_match_device(dev, 0x01d7, 0x1028, 0x01c2))
4420 bios->fp.duallink_transition_clk = 80000;
4421
4422 /* set dual_link flag for EDID case */ 4238 /* set dual_link flag for EDID case */
4423 if (pxclk && (chip_version < 0x25 || chip_version > 0x28)) 4239 if (pxclk && (chip_version < 0x25 || chip_version > 0x28))
4424 bios->fp.dual_link = (pxclk >= bios->fp.duallink_transition_clk); 4240 bios->fp.dual_link = (pxclk >= bios->fp.duallink_transition_clk);
@@ -4541,7 +4357,7 @@ nouveau_bios_run_display_table(struct drm_device *dev, u16 type, int pclk,
4541 NV_DEBUG_KMS(dev, "Searching for output entry for %d %d %d\n", 4357 NV_DEBUG_KMS(dev, "Searching for output entry for %d %d %d\n",
4542 dcbent->type, dcbent->location, dcbent->or); 4358 dcbent->type, dcbent->location, dcbent->or);
4543 for (i = 0; i < table[3]; i++) { 4359 for (i = 0; i < table[3]; i++) {
4544 otable = ROMPTR(bios, table[table[1] + (i * table[2])]); 4360 otable = ROMPTR(dev, table[table[1] + (i * table[2])]);
4545 if (otable && bios_encoder_match(dcbent, ROM32(otable[0]))) 4361 if (otable && bios_encoder_match(dcbent, ROM32(otable[0])))
4546 break; 4362 break;
4547 } 4363 }
@@ -4719,7 +4535,7 @@ static struct pll_mapping nv84_pll_mapping[] = {
4719 { PLL_CORE , 0x004028 }, 4535 { PLL_CORE , 0x004028 },
4720 { PLL_SHADER, 0x004020 }, 4536 { PLL_SHADER, 0x004020 },
4721 { PLL_MEMORY, 0x004008 }, 4537 { PLL_MEMORY, 0x004008 },
4722 { PLL_UNK05 , 0x004030 }, 4538 { PLL_VDEC , 0x004030 },
4723 { PLL_UNK41 , 0x00e818 }, 4539 { PLL_UNK41 , 0x00e818 },
4724 { PLL_VPLL0 , 0x614100 }, 4540 { PLL_VPLL0 , 0x614100 },
4725 { PLL_VPLL1 , 0x614900 }, 4541 { PLL_VPLL1 , 0x614900 },
@@ -5485,6 +5301,9 @@ bit_table(struct drm_device *dev, u8 id, struct bit_entry *bit)
5485 struct nvbios *bios = &dev_priv->vbios; 5301 struct nvbios *bios = &dev_priv->vbios;
5486 u8 entries, *entry; 5302 u8 entries, *entry;
5487 5303
5304 if (bios->type != NVBIOS_BIT)
5305 return -ENODEV;
5306
5488 entries = bios->data[bios->offset + 10]; 5307 entries = bios->data[bios->offset + 10];
5489 entry = &bios->data[bios->offset + 12]; 5308 entry = &bios->data[bios->offset + 12];
5490 while (entries--) { 5309 while (entries--) {
@@ -5493,7 +5312,7 @@ bit_table(struct drm_device *dev, u8 id, struct bit_entry *bit)
5493 bit->version = entry[1]; 5312 bit->version = entry[1];
5494 bit->length = ROM16(entry[2]); 5313 bit->length = ROM16(entry[2]);
5495 bit->offset = ROM16(entry[4]); 5314 bit->offset = ROM16(entry[4]);
5496 bit->data = ROMPTR(bios, entry[4]); 5315 bit->data = ROMPTR(dev, entry[4]);
5497 return 0; 5316 return 0;
5498 } 5317 }
5499 5318
@@ -5598,10 +5417,6 @@ static int parse_bmp_structure(struct drm_device *dev, struct nvbios *bios, unsi
5598 uint16_t legacy_scripts_offset, legacy_i2c_offset; 5417 uint16_t legacy_scripts_offset, legacy_i2c_offset;
5599 5418
5600 /* load needed defaults in case we can't parse this info */ 5419 /* load needed defaults in case we can't parse this info */
5601 bios->dcb.i2c[0].write = NV_CIO_CRE_DDC_WR__INDEX;
5602 bios->dcb.i2c[0].read = NV_CIO_CRE_DDC_STATUS__INDEX;
5603 bios->dcb.i2c[1].write = NV_CIO_CRE_DDC0_WR__INDEX;
5604 bios->dcb.i2c[1].read = NV_CIO_CRE_DDC0_STATUS__INDEX;
5605 bios->digital_min_front_porch = 0x4b; 5420 bios->digital_min_front_porch = 0x4b;
5606 bios->fmaxvco = 256000; 5421 bios->fmaxvco = 256000;
5607 bios->fminvco = 128000; 5422 bios->fminvco = 128000;
@@ -5709,14 +5524,6 @@ static int parse_bmp_structure(struct drm_device *dev, struct nvbios *bios, unsi
5709 bios->legacy.i2c_indices.crt = bios->data[legacy_i2c_offset]; 5524 bios->legacy.i2c_indices.crt = bios->data[legacy_i2c_offset];
5710 bios->legacy.i2c_indices.tv = bios->data[legacy_i2c_offset + 1]; 5525 bios->legacy.i2c_indices.tv = bios->data[legacy_i2c_offset + 1];
5711 bios->legacy.i2c_indices.panel = bios->data[legacy_i2c_offset + 2]; 5526 bios->legacy.i2c_indices.panel = bios->data[legacy_i2c_offset + 2];
5712 if (bios->data[legacy_i2c_offset + 4])
5713 bios->dcb.i2c[0].write = bios->data[legacy_i2c_offset + 4];
5714 if (bios->data[legacy_i2c_offset + 5])
5715 bios->dcb.i2c[0].read = bios->data[legacy_i2c_offset + 5];
5716 if (bios->data[legacy_i2c_offset + 6])
5717 bios->dcb.i2c[1].write = bios->data[legacy_i2c_offset + 6];
5718 if (bios->data[legacy_i2c_offset + 7])
5719 bios->dcb.i2c[1].read = bios->data[legacy_i2c_offset + 7];
5720 5527
5721 if (bmplength > 74) { 5528 if (bmplength > 74) {
5722 bios->fmaxvco = ROM32(bmp[67]); 5529 bios->fmaxvco = ROM32(bmp[67]);
@@ -5767,286 +5574,128 @@ static uint16_t findstr(uint8_t *data, int n, const uint8_t *str, int len)
5767 return 0; 5574 return 0;
5768} 5575}
5769 5576
5770static struct dcb_gpio_entry * 5577void *
5771new_gpio_entry(struct nvbios *bios) 5578dcb_table(struct drm_device *dev)
5772{
5773 struct drm_device *dev = bios->dev;
5774 struct dcb_gpio_table *gpio = &bios->dcb.gpio;
5775
5776 if (gpio->entries >= DCB_MAX_NUM_GPIO_ENTRIES) {
5777 NV_ERROR(dev, "exceeded maximum number of gpio entries!!\n");
5778 return NULL;
5779 }
5780
5781 return &gpio->entry[gpio->entries++];
5782}
5783
5784struct dcb_gpio_entry *
5785nouveau_bios_gpio_entry(struct drm_device *dev, enum dcb_gpio_tag tag)
5786{ 5579{
5787 struct drm_nouveau_private *dev_priv = dev->dev_private; 5580 struct drm_nouveau_private *dev_priv = dev->dev_private;
5788 struct nvbios *bios = &dev_priv->vbios; 5581 u8 *dcb = NULL;
5789 int i;
5790
5791 for (i = 0; i < bios->dcb.gpio.entries; i++) {
5792 if (bios->dcb.gpio.entry[i].tag != tag)
5793 continue;
5794 5582
5795 return &bios->dcb.gpio.entry[i]; 5583 if (dev_priv->card_type > NV_04)
5584 dcb = ROMPTR(dev, dev_priv->vbios.data[0x36]);
5585 if (!dcb) {
5586 NV_WARNONCE(dev, "No DCB data found in VBIOS\n");
5587 return NULL;
5796 } 5588 }
5797 5589
5798 return NULL; 5590 if (dcb[0] >= 0x41) {
5799} 5591 NV_WARNONCE(dev, "DCB version 0x%02x unknown\n", dcb[0]);
5800 5592 return NULL;
5801static void 5593 } else
5802parse_dcb_gpio_table(struct nvbios *bios)
5803{
5804 struct drm_device *dev = bios->dev;
5805 struct dcb_gpio_entry *e;
5806 u8 headerlen, entries, recordlen;
5807 u8 *dcb, *gpio = NULL, *entry;
5808 int i;
5809
5810 dcb = ROMPTR(bios, bios->data[0x36]);
5811 if (dcb[0] >= 0x30) { 5594 if (dcb[0] >= 0x30) {
5812 gpio = ROMPTR(bios, dcb[10]); 5595 if (ROM32(dcb[6]) == 0x4edcbdcb)
5813 if (!gpio) 5596 return dcb;
5814 goto no_table;
5815
5816 headerlen = gpio[1];
5817 entries = gpio[2];
5818 recordlen = gpio[3];
5819 } else 5597 } else
5820 if (dcb[0] >= 0x22 && dcb[-1] >= 0x13) { 5598 if (dcb[0] >= 0x20) {
5821 gpio = ROMPTR(bios, dcb[-15]); 5599 if (ROM32(dcb[4]) == 0x4edcbdcb)
5822 if (!gpio) 5600 return dcb;
5823 goto no_table;
5824
5825 headerlen = 3;
5826 entries = gpio[2];
5827 recordlen = gpio[1];
5828 } else 5601 } else
5829 if (dcb[0] >= 0x22) { 5602 if (dcb[0] >= 0x15) {
5830 /* No GPIO table present, parse the TVDAC GPIO data. */ 5603 if (!memcmp(&dcb[-7], "DEV_REC", 7))
5831 uint8_t *tvdac_gpio = &dcb[-5]; 5604 return dcb;
5832
5833 if (tvdac_gpio[0] & 1) {
5834 e = new_gpio_entry(bios);
5835 e->tag = DCB_GPIO_TVDAC0;
5836 e->line = tvdac_gpio[1] >> 4;
5837 e->invert = tvdac_gpio[0] & 2;
5838 }
5839
5840 goto no_table;
5841 } else { 5605 } else {
5842 NV_DEBUG(dev, "no/unknown gpio table on DCB 0x%02x\n", dcb[0]); 5606 /*
5843 goto no_table; 5607 * v1.4 (some NV15/16, NV11+) seems the same as v1.5, but
5844 } 5608 * always has the same single (crt) entry, even when tv-out
5845 5609 * present, so the conclusion is this version cannot really
5846 entry = gpio + headerlen; 5610 * be used.
5847 for (i = 0; i < entries; i++, entry += recordlen) { 5611 *
5848 e = new_gpio_entry(bios); 5612 * v1.2 tables (some NV6/10, and NV15+) normally have the
5849 if (!e) 5613 * same 5 entries, which are not specific to the card and so
5850 break; 5614 * no use.
5851 5615 *
5852 if (gpio[0] < 0x40) { 5616 * v1.2 does have an I2C table that read_dcb_i2c_table can
5853 e->entry = ROM16(entry[0]); 5617 * handle, but cards exist (nv11 in #14821) with a bad i2c
5854 e->tag = (e->entry & 0x07e0) >> 5; 5618 * table pointer, so use the indices parsed in
5855 if (e->tag == 0x3f) { 5619 * parse_bmp_structure.
5856 bios->dcb.gpio.entries--; 5620 *
5857 continue; 5621 * v1.1 (NV5+, maybe some NV4) is entirely unhelpful
5858 } 5622 */
5859 5623 NV_WARNONCE(dev, "No useful DCB data in VBIOS\n");
5860 e->line = (e->entry & 0x001f);
5861 e->invert = ((e->entry & 0xf800) >> 11) != 4;
5862 } else {
5863 e->entry = ROM32(entry[0]);
5864 e->tag = (e->entry & 0x0000ff00) >> 8;
5865 if (e->tag == 0xff) {
5866 bios->dcb.gpio.entries--;
5867 continue;
5868 }
5869
5870 e->line = (e->entry & 0x0000001f) >> 0;
5871 if (gpio[0] == 0x40) {
5872 e->state_default = (e->entry & 0x01000000) >> 24;
5873 e->state[0] = (e->entry & 0x18000000) >> 27;
5874 e->state[1] = (e->entry & 0x60000000) >> 29;
5875 } else {
5876 e->state_default = (e->entry & 0x00000080) >> 7;
5877 e->state[0] = (entry[4] >> 4) & 3;
5878 e->state[1] = (entry[4] >> 6) & 3;
5879 }
5880 }
5881 }
5882
5883no_table:
5884 /* Apple iMac G4 NV18 */
5885 if (nv_match_device(dev, 0x0189, 0x10de, 0x0010)) {
5886 e = new_gpio_entry(bios);
5887 if (e) {
5888 e->tag = DCB_GPIO_TVDAC0;
5889 e->line = 4;
5890 }
5891 }
5892}
5893
5894struct dcb_connector_table_entry *
5895nouveau_bios_connector_entry(struct drm_device *dev, int index)
5896{
5897 struct drm_nouveau_private *dev_priv = dev->dev_private;
5898 struct nvbios *bios = &dev_priv->vbios;
5899 struct dcb_connector_table_entry *cte;
5900
5901 if (index >= bios->dcb.connector.entries)
5902 return NULL;
5903
5904 cte = &bios->dcb.connector.entry[index];
5905 if (cte->type == 0xff)
5906 return NULL; 5624 return NULL;
5625 }
5907 5626
5908 return cte; 5627 NV_WARNONCE(dev, "DCB header validation failed\n");
5628 return NULL;
5909} 5629}
5910 5630
5911static enum dcb_connector_type 5631void *
5912divine_connector_type(struct nvbios *bios, int index) 5632dcb_outp(struct drm_device *dev, u8 idx)
5913{ 5633{
5914 struct dcb_table *dcb = &bios->dcb; 5634 u8 *dcb = dcb_table(dev);
5915 unsigned encoders = 0, type = DCB_CONNECTOR_NONE; 5635 if (dcb && dcb[0] >= 0x30) {
5916 int i; 5636 if (idx < dcb[2])
5917 5637 return dcb + dcb[1] + (idx * dcb[3]);
5918 for (i = 0; i < dcb->entries; i++) {
5919 if (dcb->entry[i].connector == index)
5920 encoders |= (1 << dcb->entry[i].type);
5921 }
5922
5923 if (encoders & (1 << OUTPUT_DP)) {
5924 if (encoders & (1 << OUTPUT_TMDS))
5925 type = DCB_CONNECTOR_DP;
5926 else
5927 type = DCB_CONNECTOR_eDP;
5928 } else
5929 if (encoders & (1 << OUTPUT_TMDS)) {
5930 if (encoders & (1 << OUTPUT_ANALOG))
5931 type = DCB_CONNECTOR_DVI_I;
5932 else
5933 type = DCB_CONNECTOR_DVI_D;
5934 } else
5935 if (encoders & (1 << OUTPUT_ANALOG)) {
5936 type = DCB_CONNECTOR_VGA;
5937 } else 5638 } else
5938 if (encoders & (1 << OUTPUT_LVDS)) { 5639 if (dcb && dcb[0] >= 0x20) {
5939 type = DCB_CONNECTOR_LVDS; 5640 u8 *i2c = ROMPTR(dev, dcb[2]);
5641 u8 *ent = dcb + 8 + (idx * 8);
5642 if (i2c && ent < i2c)
5643 return ent;
5940 } else 5644 } else
5941 if (encoders & (1 << OUTPUT_TV)) { 5645 if (dcb && dcb[0] >= 0x15) {
5942 type = DCB_CONNECTOR_TV_0; 5646 u8 *i2c = ROMPTR(dev, dcb[2]);
5647 u8 *ent = dcb + 4 + (idx * 10);
5648 if (i2c && ent < i2c)
5649 return ent;
5943 } 5650 }
5944 5651
5945 return type; 5652 return NULL;
5946} 5653}
5947 5654
5948static void 5655int
5949apply_dcb_connector_quirks(struct nvbios *bios, int idx) 5656dcb_outp_foreach(struct drm_device *dev, void *data,
5950{ 5657 int (*exec)(struct drm_device *, void *, int idx, u8 *outp))
5951 struct dcb_connector_table_entry *cte = &bios->dcb.connector.entry[idx]; 5658{
5952 struct drm_device *dev = bios->dev; 5659 int ret, idx = -1;
5660 u8 *outp = NULL;
5661 while ((outp = dcb_outp(dev, ++idx))) {
5662 if (ROM32(outp[0]) == 0x00000000)
5663 break; /* seen on an NV11 with DCB v1.5 */
5664 if (ROM32(outp[0]) == 0xffffffff)
5665 break; /* seen on an NV17 with DCB v2.0 */
5666
5667 if ((outp[0] & 0x0f) == OUTPUT_UNUSED)
5668 continue;
5669 if ((outp[0] & 0x0f) == OUTPUT_EOL)
5670 break;
5953 5671
5954 /* Gigabyte NX85T */ 5672 ret = exec(dev, data, idx, outp);
5955 if (nv_match_device(dev, 0x0421, 0x1458, 0x344c)) { 5673 if (ret)
5956 if (cte->type == DCB_CONNECTOR_HDMI_1) 5674 return ret;
5957 cte->type = DCB_CONNECTOR_DVI_I;
5958 } 5675 }
5959 5676
5960 /* Gigabyte GV-NX86T512H */ 5677 return 0;
5961 if (nv_match_device(dev, 0x0402, 0x1458, 0x3455)) {
5962 if (cte->type == DCB_CONNECTOR_HDMI_1)
5963 cte->type = DCB_CONNECTOR_DVI_I;
5964 }
5965} 5678}
5966 5679
5967static const u8 hpd_gpio[16] = { 5680u8 *
5968 0xff, 0x07, 0x08, 0xff, 0xff, 0x51, 0x52, 0xff, 5681dcb_conntab(struct drm_device *dev)
5969 0xff, 0xff, 0xff, 0xff, 0xff, 0x5e, 0x5f, 0x60,
5970};
5971
5972static void
5973parse_dcb_connector_table(struct nvbios *bios)
5974{ 5682{
5975 struct drm_device *dev = bios->dev; 5683 u8 *dcb = dcb_table(dev);
5976 struct dcb_connector_table *ct = &bios->dcb.connector; 5684 if (dcb && dcb[0] >= 0x30 && dcb[1] >= 0x16) {
5977 struct dcb_connector_table_entry *cte; 5685 u8 *conntab = ROMPTR(dev, dcb[0x14]);
5978 uint8_t *conntab = &bios->data[bios->dcb.connector_table_ptr]; 5686 if (conntab && conntab[0] >= 0x30 && conntab[0] <= 0x40)
5979 uint8_t *entry; 5687 return conntab;
5980 int i;
5981
5982 if (!bios->dcb.connector_table_ptr) {
5983 NV_DEBUG_KMS(dev, "No DCB connector table present\n");
5984 return;
5985 }
5986
5987 NV_INFO(dev, "DCB connector table: VHER 0x%02x %d %d %d\n",
5988 conntab[0], conntab[1], conntab[2], conntab[3]);
5989 if ((conntab[0] != 0x30 && conntab[0] != 0x40) ||
5990 (conntab[3] != 2 && conntab[3] != 4)) {
5991 NV_ERROR(dev, " Unknown! Please report.\n");
5992 return;
5993 } 5688 }
5689 return NULL;
5690}
5994 5691
5995 ct->entries = conntab[2]; 5692u8 *
5996 5693dcb_conn(struct drm_device *dev, u8 idx)
5997 entry = conntab + conntab[1]; 5694{
5998 cte = &ct->entry[0]; 5695 u8 *conntab = dcb_conntab(dev);
5999 for (i = 0; i < conntab[2]; i++, entry += conntab[3], cte++) { 5696 if (conntab && idx < conntab[2])
6000 cte->index = i; 5697 return conntab + conntab[1] + (idx * conntab[3]);
6001 if (conntab[3] == 2) 5698 return NULL;
6002 cte->entry = ROM16(entry[0]);
6003 else
6004 cte->entry = ROM32(entry[0]);
6005
6006 cte->type = (cte->entry & 0x000000ff) >> 0;
6007 cte->index2 = (cte->entry & 0x00000f00) >> 8;
6008
6009 cte->gpio_tag = ffs((cte->entry & 0x07033000) >> 12);
6010 cte->gpio_tag = hpd_gpio[cte->gpio_tag];
6011
6012 if (cte->type == 0xff)
6013 continue;
6014
6015 apply_dcb_connector_quirks(bios, i);
6016
6017 NV_INFO(dev, " %d: 0x%08x: type 0x%02x idx %d tag 0x%02x\n",
6018 i, cte->entry, cte->type, cte->index, cte->gpio_tag);
6019
6020 /* check for known types, fallback to guessing the type
6021 * from attached encoders if we hit an unknown.
6022 */
6023 switch (cte->type) {
6024 case DCB_CONNECTOR_VGA:
6025 case DCB_CONNECTOR_TV_0:
6026 case DCB_CONNECTOR_TV_1:
6027 case DCB_CONNECTOR_TV_3:
6028 case DCB_CONNECTOR_DVI_I:
6029 case DCB_CONNECTOR_DVI_D:
6030 case DCB_CONNECTOR_LVDS:
6031 case DCB_CONNECTOR_LVDS_SPWG:
6032 case DCB_CONNECTOR_DP:
6033 case DCB_CONNECTOR_eDP:
6034 case DCB_CONNECTOR_HDMI_0:
6035 case DCB_CONNECTOR_HDMI_1:
6036 break;
6037 default:
6038 cte->type = divine_connector_type(bios, cte->index);
6039 NV_WARN(dev, "unknown type, using 0x%02x\n", cte->type);
6040 break;
6041 }
6042
6043 if (nouveau_override_conntype) {
6044 int type = divine_connector_type(bios, cte->index);
6045 if (type != cte->type)
6046 NV_WARN(dev, " -> type 0x%02x\n", cte->type);
6047 }
6048
6049 }
6050} 5699}
6051 5700
6052static struct dcb_entry *new_dcb_entry(struct dcb_table *dcb) 5701static struct dcb_entry *new_dcb_entry(struct dcb_table *dcb)
@@ -6079,8 +5728,7 @@ parse_dcb20_entry(struct drm_device *dev, struct dcb_table *dcb,
6079 entry->type = conn & 0xf; 5728 entry->type = conn & 0xf;
6080 entry->i2c_index = (conn >> 4) & 0xf; 5729 entry->i2c_index = (conn >> 4) & 0xf;
6081 entry->heads = (conn >> 8) & 0xf; 5730 entry->heads = (conn >> 8) & 0xf;
6082 if (dcb->version >= 0x40) 5731 entry->connector = (conn >> 12) & 0xf;
6083 entry->connector = (conn >> 12) & 0xf;
6084 entry->bus = (conn >> 16) & 0xf; 5732 entry->bus = (conn >> 16) & 0xf;
6085 entry->location = (conn >> 20) & 0x3; 5733 entry->location = (conn >> 20) & 0x3;
6086 entry->or = (conn >> 24) & 0xf; 5734 entry->or = (conn >> 24) & 0xf;
@@ -6252,25 +5900,6 @@ parse_dcb15_entry(struct drm_device *dev, struct dcb_table *dcb,
6252 return true; 5900 return true;
6253} 5901}
6254 5902
6255static bool parse_dcb_entry(struct drm_device *dev, struct dcb_table *dcb,
6256 uint32_t conn, uint32_t conf)
6257{
6258 struct dcb_entry *entry = new_dcb_entry(dcb);
6259 bool ret;
6260
6261 if (dcb->version >= 0x20)
6262 ret = parse_dcb20_entry(dev, dcb, conn, conf, entry);
6263 else
6264 ret = parse_dcb15_entry(dev, dcb, conn, conf, entry);
6265 if (!ret)
6266 return ret;
6267
6268 read_dcb_i2c_entry(dev, dcb->version, dcb->i2c_table,
6269 entry->i2c_index, &dcb->i2c[entry->i2c_index]);
6270
6271 return true;
6272}
6273
6274static 5903static
6275void merge_like_dcb_entries(struct drm_device *dev, struct dcb_table *dcb) 5904void merge_like_dcb_entries(struct drm_device *dev, struct dcb_table *dcb)
6276{ 5905{
@@ -6431,154 +6060,118 @@ fabricate_dcb_encoder_table(struct drm_device *dev, struct nvbios *bios)
6431#endif 6060#endif
6432 6061
6433 /* Make up some sane defaults */ 6062 /* Make up some sane defaults */
6434 fabricate_dcb_output(dcb, OUTPUT_ANALOG, LEGACY_I2C_CRT, 1, 1); 6063 fabricate_dcb_output(dcb, OUTPUT_ANALOG,
6064 bios->legacy.i2c_indices.crt, 1, 1);
6435 6065
6436 if (nv04_tv_identify(dev, bios->legacy.i2c_indices.tv) >= 0) 6066 if (nv04_tv_identify(dev, bios->legacy.i2c_indices.tv) >= 0)
6437 fabricate_dcb_output(dcb, OUTPUT_TV, LEGACY_I2C_TV, 6067 fabricate_dcb_output(dcb, OUTPUT_TV,
6068 bios->legacy.i2c_indices.tv,
6438 all_heads, 0); 6069 all_heads, 0);
6439 6070
6440 else if (bios->tmds.output0_script_ptr || 6071 else if (bios->tmds.output0_script_ptr ||
6441 bios->tmds.output1_script_ptr) 6072 bios->tmds.output1_script_ptr)
6442 fabricate_dcb_output(dcb, OUTPUT_TMDS, LEGACY_I2C_PANEL, 6073 fabricate_dcb_output(dcb, OUTPUT_TMDS,
6074 bios->legacy.i2c_indices.panel,
6443 all_heads, 1); 6075 all_heads, 1);
6444} 6076}
6445 6077
6446static int 6078static int
6447parse_dcb_table(struct drm_device *dev, struct nvbios *bios) 6079parse_dcb_entry(struct drm_device *dev, void *data, int idx, u8 *outp)
6448{ 6080{
6449 struct drm_nouveau_private *dev_priv = dev->dev_private; 6081 struct drm_nouveau_private *dev_priv = dev->dev_private;
6450 struct dcb_table *dcb = &bios->dcb; 6082 struct dcb_table *dcb = &dev_priv->vbios.dcb;
6451 uint16_t dcbptr = 0, i2ctabptr = 0; 6083 u32 conf = (dcb->version >= 0x20) ? ROM32(outp[4]) : ROM32(outp[6]);
6452 uint8_t *dcbtable; 6084 u32 conn = ROM32(outp[0]);
6453 uint8_t headerlen = 0x4, entries = DCB_MAX_NUM_ENTRIES; 6085 bool ret;
6454 bool configblock = true;
6455 int recordlength = 8, confofs = 4;
6456 int i;
6457
6458 /* get the offset from 0x36 */
6459 if (dev_priv->card_type > NV_04) {
6460 dcbptr = ROM16(bios->data[0x36]);
6461 if (dcbptr == 0x0000)
6462 NV_WARN(dev, "No output data (DCB) found in BIOS\n");
6463 }
6464
6465 /* this situation likely means a really old card, pre DCB */
6466 if (dcbptr == 0x0) {
6467 fabricate_dcb_encoder_table(dev, bios);
6468 return 0;
6469 }
6470
6471 dcbtable = &bios->data[dcbptr];
6472
6473 /* get DCB version */
6474 dcb->version = dcbtable[0];
6475 NV_TRACE(dev, "Found Display Configuration Block version %d.%d\n",
6476 dcb->version >> 4, dcb->version & 0xf);
6477
6478 if (dcb->version >= 0x20) { /* NV17+ */
6479 uint32_t sig;
6480 6086
6481 if (dcb->version >= 0x30) { /* NV40+ */ 6087 if (apply_dcb_encoder_quirks(dev, idx, &conn, &conf)) {
6482 headerlen = dcbtable[1]; 6088 struct dcb_entry *entry = new_dcb_entry(dcb);
6483 entries = dcbtable[2];
6484 recordlength = dcbtable[3];
6485 i2ctabptr = ROM16(dcbtable[4]);
6486 sig = ROM32(dcbtable[6]);
6487 dcb->gpio_table_ptr = ROM16(dcbtable[10]);
6488 dcb->connector_table_ptr = ROM16(dcbtable[20]);
6489 } else {
6490 i2ctabptr = ROM16(dcbtable[2]);
6491 sig = ROM32(dcbtable[4]);
6492 headerlen = 8;
6493 }
6494 6089
6495 if (sig != 0x4edcbdcb) { 6090 NV_TRACEWARN(dev, "DCB outp %02d: %08x %08x\n", idx, conn, conf);
6496 NV_ERROR(dev, "Bad Display Configuration Block "
6497 "signature (%08X)\n", sig);
6498 return -EINVAL;
6499 }
6500 } else if (dcb->version >= 0x15) { /* some NV11 and NV20 */
6501 char sig[8] = { 0 };
6502 6091
6503 strncpy(sig, (char *)&dcbtable[-7], 7); 6092 if (dcb->version >= 0x20)
6504 i2ctabptr = ROM16(dcbtable[2]); 6093 ret = parse_dcb20_entry(dev, dcb, conn, conf, entry);
6505 recordlength = 10; 6094 else
6506 confofs = 6; 6095 ret = parse_dcb15_entry(dev, dcb, conn, conf, entry);
6096 if (!ret)
6097 return 1; /* stop parsing */
6507 6098
6508 if (strcmp(sig, "DEV_REC")) { 6099 /* Ignore the I2C index for on-chip TV-out, as there
6509 NV_ERROR(dev, "Bad Display Configuration Block " 6100 * are cards with bogus values (nv31m in bug 23212),
6510 "signature (%s)\n", sig); 6101 * and it's otherwise useless.
6511 return -EINVAL;
6512 }
6513 } else {
6514 /*
6515 * v1.4 (some NV15/16, NV11+) seems the same as v1.5, but always
6516 * has the same single (crt) entry, even when tv-out present, so
6517 * the conclusion is this version cannot really be used.
6518 * v1.2 tables (some NV6/10, and NV15+) normally have the same
6519 * 5 entries, which are not specific to the card and so no use.
6520 * v1.2 does have an I2C table that read_dcb_i2c_table can
6521 * handle, but cards exist (nv11 in #14821) with a bad i2c table
6522 * pointer, so use the indices parsed in parse_bmp_structure.
6523 * v1.1 (NV5+, maybe some NV4) is entirely unhelpful
6524 */ 6102 */
6525 NV_TRACEWARN(dev, "No useful information in BIOS output table; " 6103 if (entry->type == OUTPUT_TV &&
6526 "adding all possible outputs\n"); 6104 entry->location == DCB_LOC_ON_CHIP)
6527 fabricate_dcb_encoder_table(dev, bios); 6105 entry->i2c_index = 0x0f;
6528 return 0;
6529 } 6106 }
6530 6107
6531 if (!i2ctabptr) 6108 return 0;
6532 NV_WARN(dev, "No pointer to DCB I2C port table\n"); 6109}
6533 else {
6534 dcb->i2c_table = &bios->data[i2ctabptr];
6535 if (dcb->version >= 0x30)
6536 dcb->i2c_default_indices = dcb->i2c_table[4];
6537 6110
6538 /* 6111static void
6539 * Parse the "management" I2C bus, used for hardware 6112dcb_fake_connectors(struct nvbios *bios)
6540 * monitoring and some external TMDS transmitters. 6113{
6541 */ 6114 struct dcb_table *dcbt = &bios->dcb;
6542 if (dcb->version >= 0x22) { 6115 u8 map[16] = { };
6543 int idx = (dcb->version >= 0x40 ? 6116 int i, idx = 0;
6544 dcb->i2c_default_indices & 0xf :
6545 2);
6546 6117
6547 read_dcb_i2c_entry(dev, dcb->version, dcb->i2c_table, 6118 /* heuristic: if we ever get a non-zero connector field, assume
6548 idx, &dcb->i2c[idx]); 6119 * that all the indices are valid and we don't need fake them.
6549 } 6120 */
6121 for (i = 0; i < dcbt->entries; i++) {
6122 if (dcbt->entry[i].connector)
6123 return;
6550 } 6124 }
6551 6125
6552 if (entries > DCB_MAX_NUM_ENTRIES) 6126 /* no useful connector info available, we need to make it up
6553 entries = DCB_MAX_NUM_ENTRIES; 6127 * ourselves. the rule here is: anything on the same i2c bus
6554 6128 * is considered to be on the same connector. any output
6555 for (i = 0; i < entries; i++) { 6129 * without an associated i2c bus is assigned its own unique
6556 uint32_t connection, config = 0; 6130 * connector index.
6557 6131 */
6558 connection = ROM32(dcbtable[headerlen + recordlength * i]); 6132 for (i = 0; i < dcbt->entries; i++) {
6559 if (configblock) 6133 u8 i2c = dcbt->entry[i].i2c_index;
6560 config = ROM32(dcbtable[headerlen + confofs + recordlength * i]); 6134 if (i2c == 0x0f) {
6561 6135 dcbt->entry[i].connector = idx++;
6562 /* seen on an NV11 with DCB v1.5 */ 6136 } else {
6563 if (connection == 0x00000000) 6137 if (!map[i2c])
6564 break; 6138 map[i2c] = ++idx;
6139 dcbt->entry[i].connector = map[i2c] - 1;
6140 }
6141 }
6565 6142
6566 /* seen on an NV17 with DCB v2.0 */ 6143 /* if we created more than one connector, destroy the connector
6567 if (connection == 0xffffffff) 6144 * table - just in case it has random, rather than stub, entries.
6568 break; 6145 */
6146 if (i > 1) {
6147 u8 *conntab = dcb_conntab(bios->dev);
6148 if (conntab)
6149 conntab[0] = 0x00;
6150 }
6151}
6569 6152
6570 if ((connection & 0x0000000f) == 0x0000000f) 6153static int
6571 continue; 6154parse_dcb_table(struct drm_device *dev, struct nvbios *bios)
6155{
6156 struct dcb_table *dcb = &bios->dcb;
6157 u8 *dcbt, *conn;
6158 int idx;
6159
6160 dcbt = dcb_table(dev);
6161 if (!dcbt) {
6162 /* handle pre-DCB boards */
6163 if (bios->type == NVBIOS_BMP) {
6164 fabricate_dcb_encoder_table(dev, bios);
6165 return 0;
6166 }
6572 6167
6573 if (!apply_dcb_encoder_quirks(dev, i, &connection, &config)) 6168 return -EINVAL;
6574 continue; 6169 }
6575 6170
6576 NV_TRACEWARN(dev, "Raw DCB entry %d: %08x %08x\n", 6171 NV_TRACE(dev, "DCB version %d.%d\n", dcbt[0] >> 4, dcbt[0] & 0xf);
6577 dcb->entries, connection, config);
6578 6172
6579 if (!parse_dcb_entry(dev, dcb, connection, config)) 6173 dcb->version = dcbt[0];
6580 break; 6174 dcb_outp_foreach(dev, NULL, parse_dcb_entry);
6581 }
6582 6175
6583 /* 6176 /*
6584 * apart for v2.1+ not being known for requiring merging, this 6177 * apart for v2.1+ not being known for requiring merging, this
@@ -6590,77 +6183,19 @@ parse_dcb_table(struct drm_device *dev, struct nvbios *bios)
6590 if (!dcb->entries) 6183 if (!dcb->entries)
6591 return -ENXIO; 6184 return -ENXIO;
6592 6185
6593 parse_dcb_gpio_table(bios); 6186 /* dump connector table entries to log, if any exist */
6594 parse_dcb_connector_table(bios); 6187 idx = -1;
6595 return 0; 6188 while ((conn = dcb_conn(dev, ++idx))) {
6596} 6189 if (conn[0] != 0xff) {
6597 6190 NV_TRACE(dev, "DCB conn %02d: ", idx);
6598static void 6191 if (dcb_conntab(dev)[3] < 4)
6599fixup_legacy_connector(struct nvbios *bios) 6192 printk("%04x\n", ROM16(conn[0]));
6600{ 6193 else
6601 struct dcb_table *dcb = &bios->dcb; 6194 printk("%08x\n", ROM32(conn[0]));
6602 int i, i2c, i2c_conn[DCB_MAX_NUM_I2C_ENTRIES] = { };
6603
6604 /*
6605 * DCB 3.0 also has the table in most cases, but there are some cards
6606 * where the table is filled with stub entries, and the DCB entriy
6607 * indices are all 0. We don't need the connector indices on pre-G80
6608 * chips (yet?) so limit the use to DCB 4.0 and above.
6609 */
6610 if (dcb->version >= 0x40)
6611 return;
6612
6613 dcb->connector.entries = 0;
6614
6615 /*
6616 * No known connector info before v3.0, so make it up. the rule here
6617 * is: anything on the same i2c bus is considered to be on the same
6618 * connector. any output without an associated i2c bus is assigned
6619 * its own unique connector index.
6620 */
6621 for (i = 0; i < dcb->entries; i++) {
6622 /*
6623 * Ignore the I2C index for on-chip TV-out, as there
6624 * are cards with bogus values (nv31m in bug 23212),
6625 * and it's otherwise useless.
6626 */
6627 if (dcb->entry[i].type == OUTPUT_TV &&
6628 dcb->entry[i].location == DCB_LOC_ON_CHIP)
6629 dcb->entry[i].i2c_index = 0xf;
6630 i2c = dcb->entry[i].i2c_index;
6631
6632 if (i2c_conn[i2c]) {
6633 dcb->entry[i].connector = i2c_conn[i2c] - 1;
6634 continue;
6635 } 6195 }
6636
6637 dcb->entry[i].connector = dcb->connector.entries++;
6638 if (i2c != 0xf)
6639 i2c_conn[i2c] = dcb->connector.entries;
6640 }
6641
6642 /* Fake the connector table as well as just connector indices */
6643 for (i = 0; i < dcb->connector.entries; i++) {
6644 dcb->connector.entry[i].index = i;
6645 dcb->connector.entry[i].type = divine_connector_type(bios, i);
6646 dcb->connector.entry[i].gpio_tag = 0xff;
6647 }
6648}
6649
6650static void
6651fixup_legacy_i2c(struct nvbios *bios)
6652{
6653 struct dcb_table *dcb = &bios->dcb;
6654 int i;
6655
6656 for (i = 0; i < dcb->entries; i++) {
6657 if (dcb->entry[i].i2c_index == LEGACY_I2C_CRT)
6658 dcb->entry[i].i2c_index = bios->legacy.i2c_indices.crt;
6659 if (dcb->entry[i].i2c_index == LEGACY_I2C_PANEL)
6660 dcb->entry[i].i2c_index = bios->legacy.i2c_indices.panel;
6661 if (dcb->entry[i].i2c_index == LEGACY_I2C_TV)
6662 dcb->entry[i].i2c_index = bios->legacy.i2c_indices.tv;
6663 } 6196 }
6197 dcb_fake_connectors(bios);
6198 return 0;
6664} 6199}
6665 6200
6666static int load_nv17_hwsq_ucode_entry(struct drm_device *dev, struct nvbios *bios, uint16_t hwsq_offset, int entry) 6201static int load_nv17_hwsq_ucode_entry(struct drm_device *dev, struct nvbios *bios, uint16_t hwsq_offset, int entry)
@@ -6879,19 +6414,6 @@ nouveau_run_vbios_init(struct drm_device *dev)
6879 return ret; 6414 return ret;
6880} 6415}
6881 6416
6882static void
6883nouveau_bios_i2c_devices_takedown(struct drm_device *dev)
6884{
6885 struct drm_nouveau_private *dev_priv = dev->dev_private;
6886 struct nvbios *bios = &dev_priv->vbios;
6887 struct dcb_i2c_entry *entry;
6888 int i;
6889
6890 entry = &bios->dcb.i2c[0];
6891 for (i = 0; i < DCB_MAX_NUM_I2C_ENTRIES; i++, entry++)
6892 nouveau_i2c_fini(dev, entry);
6893}
6894
6895static bool 6417static bool
6896nouveau_bios_posted(struct drm_device *dev) 6418nouveau_bios_posted(struct drm_device *dev)
6897{ 6419{
@@ -6928,12 +6450,17 @@ nouveau_bios_init(struct drm_device *dev)
6928 if (ret) 6450 if (ret)
6929 return ret; 6451 return ret;
6930 6452
6931 ret = parse_dcb_table(dev, bios); 6453 ret = nouveau_i2c_init(dev);
6932 if (ret) 6454 if (ret)
6933 return ret; 6455 return ret;
6934 6456
6935 fixup_legacy_i2c(bios); 6457 ret = nouveau_mxm_init(dev);
6936 fixup_legacy_connector(bios); 6458 if (ret)
6459 return ret;
6460
6461 ret = parse_dcb_table(dev, bios);
6462 if (ret)
6463 return ret;
6937 6464
6938 if (!bios->major_version) /* we don't run version 0 bios */ 6465 if (!bios->major_version) /* we don't run version 0 bios */
6939 return 0; 6466 return 0;
@@ -6971,5 +6498,6 @@ nouveau_bios_init(struct drm_device *dev)
6971void 6498void
6972nouveau_bios_takedown(struct drm_device *dev) 6499nouveau_bios_takedown(struct drm_device *dev)
6973{ 6500{
6974 nouveau_bios_i2c_devices_takedown(dev); 6501 nouveau_mxm_fini(dev);
6502 nouveau_i2c_fini(dev);
6975} 6503}