aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Deucher <alexdeucher@gmail.com>2010-08-05 21:21:16 -0400
committerDave Airlie <airlied@redhat.com>2010-08-09 20:46:48 -0400
commitf376b94fbc0a313a606748206340cbef6c2adf6b (patch)
tree79687e8c214bf70251c242f8042bc46d6fc61020
parent1729dd33d20bddf1b3f371f3090f0cfd6be50b7a (diff)
drm/radeon/kms: unify i2c handling
Previously we added i2c buses as needed when enumerating connectors power management, etc. This only exposed the actual buses used and could have lead to the same buse getting created more than once if one buses was used for more than one purpose. This patch sets up all i2c buses on the card in one place and users of the buses just point back to the one instance. Signed-off-by: Alex Deucher <alexdeucher@gmail.com> Signed-off-by: Dave Airlie <airlied@redhat.com>
-rw-r--r--drivers/gpu/drm/radeon/radeon.h2
-rw-r--r--drivers/gpu/drm/radeon/radeon_atombios.c67
-rw-r--r--drivers/gpu/drm/radeon/radeon_combios.c77
-rw-r--r--drivers/gpu/drm/radeon/radeon_connectors.c31
-rw-r--r--drivers/gpu/drm/radeon/radeon_display.c5
-rw-r--r--drivers/gpu/drm/radeon/radeon_i2c.c53
-rw-r--r--drivers/gpu/drm/radeon/radeon_mode.h11
7 files changed, 214 insertions, 32 deletions
diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
index 3cd1c470b777..3dfcfa3ca425 100644
--- a/drivers/gpu/drm/radeon/radeon.h
+++ b/drivers/gpu/drm/radeon/radeon.h
@@ -1100,6 +1100,8 @@ struct radeon_device {
1100 struct notifier_block acpi_nb; 1100 struct notifier_block acpi_nb;
1101 /* only one userspace can use Hyperz features at a time */ 1101 /* only one userspace can use Hyperz features at a time */
1102 struct drm_file *hyperz_filp; 1102 struct drm_file *hyperz_filp;
1103 /* i2c buses */
1104 struct radeon_i2c_chan *i2c_bus[RADEON_MAX_I2C_BUS];
1103}; 1105};
1104 1106
1105int radeon_device_init(struct radeon_device *rdev, 1107int radeon_device_init(struct radeon_device *rdev,
diff --git a/drivers/gpu/drm/radeon/radeon_atombios.c b/drivers/gpu/drm/radeon/radeon_atombios.c
index 3bc2bcdf5308..a841adead1a1 100644
--- a/drivers/gpu/drm/radeon/radeon_atombios.c
+++ b/drivers/gpu/drm/radeon/radeon_atombios.c
@@ -114,7 +114,8 @@ static inline struct radeon_i2c_bus_rec radeon_lookup_i2c_gpio(struct radeon_dev
114 114
115 i2c.i2c_id = gpio->sucI2cId.ucAccess; 115 i2c.i2c_id = gpio->sucI2cId.ucAccess;
116 116
117 i2c.valid = true; 117 if (i2c.mask_clk_reg)
118 i2c.valid = true;
118 break; 119 break;
119 } 120 }
120 } 121 }
@@ -123,6 +124,66 @@ static inline struct radeon_i2c_bus_rec radeon_lookup_i2c_gpio(struct radeon_dev
123 return i2c; 124 return i2c;
124} 125}
125 126
127void radeon_atombios_i2c_init(struct radeon_device *rdev)
128{
129 struct atom_context *ctx = rdev->mode_info.atom_context;
130 ATOM_GPIO_I2C_ASSIGMENT *gpio;
131 struct radeon_i2c_bus_rec i2c;
132 int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
133 struct _ATOM_GPIO_I2C_INFO *i2c_info;
134 uint16_t data_offset, size;
135 int i, num_indices;
136 char stmp[32];
137
138 memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
139
140 if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
141 i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
142
143 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
144 sizeof(ATOM_GPIO_I2C_ASSIGMENT);
145
146 for (i = 0; i < num_indices; i++) {
147 gpio = &i2c_info->asGPIO_Info[i];
148 i2c.valid = false;
149 i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
150 i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
151 i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
152 i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex) * 4;
153 i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex) * 4;
154 i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex) * 4;
155 i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex) * 4;
156 i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex) * 4;
157 i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift);
158 i2c.mask_data_mask = (1 << gpio->ucDataMaskShift);
159 i2c.en_clk_mask = (1 << gpio->ucClkEnShift);
160 i2c.en_data_mask = (1 << gpio->ucDataEnShift);
161 i2c.y_clk_mask = (1 << gpio->ucClkY_Shift);
162 i2c.y_data_mask = (1 << gpio->ucDataY_Shift);
163 i2c.a_clk_mask = (1 << gpio->ucClkA_Shift);
164 i2c.a_data_mask = (1 << gpio->ucDataA_Shift);
165
166 if (gpio->sucI2cId.sbfAccess.bfHW_Capable)
167 i2c.hw_capable = true;
168 else
169 i2c.hw_capable = false;
170
171 if (gpio->sucI2cId.ucAccess == 0xa0)
172 i2c.mm_i2c = true;
173 else
174 i2c.mm_i2c = false;
175
176 i2c.i2c_id = gpio->sucI2cId.ucAccess;
177
178 if (i2c.mask_clk_reg) {
179 i2c.valid = true;
180 sprintf(stmp, "0x%x", i2c.i2c_id);
181 rdev->i2c_bus[i] = radeon_i2c_create(rdev->ddev, &i2c, stmp);
182 }
183 }
184 }
185}
186
126static inline struct radeon_gpio_rec radeon_lookup_gpio(struct radeon_device *rdev, 187static inline struct radeon_gpio_rec radeon_lookup_gpio(struct radeon_device *rdev,
127 u8 id) 188 u8 id)
128{ 189{
@@ -1521,7 +1582,7 @@ void radeon_atombios_get_power_modes(struct radeon_device *rdev)
1521 thermal_controller_names[power_info->info.ucOverdriveThermalController], 1582 thermal_controller_names[power_info->info.ucOverdriveThermalController],
1522 power_info->info.ucOverdriveControllerAddress >> 1); 1583 power_info->info.ucOverdriveControllerAddress >> 1);
1523 i2c_bus = radeon_lookup_i2c_gpio(rdev, power_info->info.ucOverdriveI2cLine); 1584 i2c_bus = radeon_lookup_i2c_gpio(rdev, power_info->info.ucOverdriveI2cLine);
1524 rdev->pm.i2c_bus = radeon_i2c_create(rdev->ddev, &i2c_bus, "Thermal"); 1585 rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
1525 if (rdev->pm.i2c_bus) { 1586 if (rdev->pm.i2c_bus) {
1526 struct i2c_board_info info = { }; 1587 struct i2c_board_info info = { };
1527 const char *name = thermal_controller_names[power_info->info. 1588 const char *name = thermal_controller_names[power_info->info.
@@ -1814,7 +1875,7 @@ void radeon_atombios_get_power_modes(struct radeon_device *rdev)
1814 (controller->ucFanParameters & 1875 (controller->ucFanParameters &
1815 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with"); 1876 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
1816 i2c_bus = radeon_lookup_i2c_gpio(rdev, controller->ucI2cLine); 1877 i2c_bus = radeon_lookup_i2c_gpio(rdev, controller->ucI2cLine);
1817 rdev->pm.i2c_bus = radeon_i2c_create(rdev->ddev, &i2c_bus, "Thermal"); 1878 rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
1818 if (rdev->pm.i2c_bus) { 1879 if (rdev->pm.i2c_bus) {
1819 struct i2c_board_info info = { }; 1880 struct i2c_board_info info = { };
1820 const char *name = pp_lib_thermal_controller_names[controller->ucType]; 1881 const char *name = pp_lib_thermal_controller_names[controller->ucType];
diff --git a/drivers/gpu/drm/radeon/radeon_combios.c b/drivers/gpu/drm/radeon/radeon_combios.c
index 5e1474cde4b4..18c84cf3eafa 100644
--- a/drivers/gpu/drm/radeon/radeon_combios.c
+++ b/drivers/gpu/drm/radeon/radeon_combios.c
@@ -479,6 +479,17 @@ radeon_combios_get_hardcoded_edid(struct radeon_device *rdev)
479 return NULL; 479 return NULL;
480} 480}
481 481
482/* standard i2c gpio lines */
483#define RADEON_I2C_MONID_ID 0
484#define RADEON_I2C_DVI_ID 1
485#define RADEON_I2C_VGA_ID 2
486#define RADEON_I2C_CRT2_ID 3
487#define RADEON_I2C_MM_ID 4
488/* custom defined gpio lines */
489#define RADEON_I2C_LCD_ID 5 /* ddc for laptop panels */
490#define RADEON_I2C_GPIO_ID 6 /* rs4xx gpio ddc */
491#define RADEON_I2C_DVO_ID 7 /* i2c bus for dvo */
492
482static struct radeon_i2c_bus_rec combios_setup_i2c_bus(struct radeon_device *rdev, 493static struct radeon_i2c_bus_rec combios_setup_i2c_bus(struct radeon_device *rdev,
483 int ddc_line) 494 int ddc_line)
484{ 495{
@@ -599,7 +610,24 @@ static struct radeon_i2c_bus_rec combios_setup_i2c_bus(struct radeon_device *rde
599 break; 610 break;
600 } 611 }
601 i2c.mm_i2c = false; 612 i2c.mm_i2c = false;
602 i2c.i2c_id = 0; 613
614 switch (ddc_line) {
615 case RADEON_GPIO_MONID:
616 i2c.i2c_id = RADEON_I2C_MONID_ID;
617 break;
618 case RADEON_GPIO_DVI_DDC:
619 i2c.i2c_id = RADEON_I2C_DVI_ID;
620 break;
621 case RADEON_GPIO_VGA_DDC:
622 i2c.i2c_id = RADEON_I2C_VGA_ID;
623 break;
624 case RADEON_GPIO_CRT2_DDC:
625 i2c.i2c_id = RADEON_I2C_CRT2_ID;
626 break;
627 default:
628 i2c.i2c_id = 0xff;
629 break;
630 }
603 i2c.hpd = RADEON_HPD_NONE; 631 i2c.hpd = RADEON_HPD_NONE;
604 632
605 if (ddc_line) 633 if (ddc_line)
@@ -610,6 +638,30 @@ static struct radeon_i2c_bus_rec combios_setup_i2c_bus(struct radeon_device *rde
610 return i2c; 638 return i2c;
611} 639}
612 640
641void radeon_combios_i2c_init(struct radeon_device *rdev)
642{
643 struct drm_device *dev = rdev->ddev;
644 struct radeon_i2c_bus_rec i2c;
645
646 i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_MONID);
647 rdev->i2c_bus[0] = radeon_i2c_create(dev, &i2c, "MONID");
648
649 i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC);
650 rdev->i2c_bus[1] = radeon_i2c_create(dev, &i2c, "DVI_DDC");
651
652 i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC);
653 rdev->i2c_bus[2] = radeon_i2c_create(dev, &i2c, "VGA_DDC");
654
655 i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_CRT2_DDC);
656 rdev->i2c_bus[3] = radeon_i2c_create(dev, &i2c, "CRT2_DDC");
657
658 i2c.valid = true;
659 i2c.hw_capable = true;
660 i2c.mm_i2c = true;
661 i2c.i2c_id = RADEON_I2C_MM_ID;
662 rdev->i2c_bus[4] = radeon_i2c_create(dev, &i2c, "MM_I2C");
663}
664
613bool radeon_combios_get_clock_info(struct drm_device *dev) 665bool radeon_combios_get_clock_info(struct drm_device *dev)
614{ 666{
615 struct radeon_device *rdev = dev->dev_private; 667 struct radeon_device *rdev = dev->dev_private;
@@ -1248,7 +1300,7 @@ bool radeon_legacy_get_ext_tmds_info_from_table(struct radeon_encoder *encoder,
1248 1300
1249 /* default for macs */ 1301 /* default for macs */
1250 i2c_bus = combios_setup_i2c_bus(rdev, RADEON_GPIO_MONID); 1302 i2c_bus = combios_setup_i2c_bus(rdev, RADEON_GPIO_MONID);
1251 tmds->i2c_bus = radeon_i2c_create(dev, &i2c_bus, "DVO"); 1303 tmds->i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
1252 1304
1253 /* XXX some macs have duallink chips */ 1305 /* XXX some macs have duallink chips */
1254 switch (rdev->mode_info.connector_table) { 1306 switch (rdev->mode_info.connector_table) {
@@ -1303,7 +1355,9 @@ bool radeon_legacy_get_ext_tmds_info_from_combios(struct radeon_encoder *encoder
1303 i2c_bus.en_data_reg = RADEON_GPIOPAD_EN; 1355 i2c_bus.en_data_reg = RADEON_GPIOPAD_EN;
1304 i2c_bus.y_clk_reg = RADEON_GPIOPAD_Y; 1356 i2c_bus.y_clk_reg = RADEON_GPIOPAD_Y;
1305 i2c_bus.y_data_reg = RADEON_GPIOPAD_Y; 1357 i2c_bus.y_data_reg = RADEON_GPIOPAD_Y;
1306 tmds->i2c_bus = radeon_i2c_create(dev, &i2c_bus, "DVO"); 1358 i2c_bus.i2c_id = RADEON_I2C_DVO_ID;
1359 radeon_i2c_add(rdev, &i2c_bus, "DVO");
1360 tmds->i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
1307 tmds->dvo_chip = DVO_SIL164; 1361 tmds->dvo_chip = DVO_SIL164;
1308 tmds->slave_addr = 0x70 >> 1; /* 7 bit addressing */ 1362 tmds->slave_addr = 0x70 >> 1; /* 7 bit addressing */
1309 break; 1363 break;
@@ -1321,15 +1375,15 @@ bool radeon_legacy_get_ext_tmds_info_from_combios(struct radeon_encoder *encoder
1321 switch (gpio) { 1375 switch (gpio) {
1322 case DDC_MONID: 1376 case DDC_MONID:
1323 i2c_bus = combios_setup_i2c_bus(rdev, RADEON_GPIO_MONID); 1377 i2c_bus = combios_setup_i2c_bus(rdev, RADEON_GPIO_MONID);
1324 tmds->i2c_bus = radeon_i2c_create(dev, &i2c_bus, "DVO"); 1378 tmds->i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
1325 break; 1379 break;
1326 case DDC_DVI: 1380 case DDC_DVI:
1327 i2c_bus = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC); 1381 i2c_bus = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC);
1328 tmds->i2c_bus = radeon_i2c_create(dev, &i2c_bus, "DVO"); 1382 tmds->i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
1329 break; 1383 break;
1330 case DDC_VGA: 1384 case DDC_VGA:
1331 i2c_bus = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC); 1385 i2c_bus = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC);
1332 tmds->i2c_bus = radeon_i2c_create(dev, &i2c_bus, "DVO"); 1386 tmds->i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
1333 break; 1387 break;
1334 case DDC_CRT2: 1388 case DDC_CRT2:
1335 /* R3xx+ chips don't have GPIO_CRT2_DDC gpio pad */ 1389 /* R3xx+ chips don't have GPIO_CRT2_DDC gpio pad */
@@ -1337,13 +1391,14 @@ bool radeon_legacy_get_ext_tmds_info_from_combios(struct radeon_encoder *encoder
1337 i2c_bus = combios_setup_i2c_bus(rdev, RADEON_GPIO_MONID); 1391 i2c_bus = combios_setup_i2c_bus(rdev, RADEON_GPIO_MONID);
1338 else 1392 else
1339 i2c_bus = combios_setup_i2c_bus(rdev, RADEON_GPIO_CRT2_DDC); 1393 i2c_bus = combios_setup_i2c_bus(rdev, RADEON_GPIO_CRT2_DDC);
1340 tmds->i2c_bus = radeon_i2c_create(dev, &i2c_bus, "DVO"); 1394 tmds->i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
1341 break; 1395 break;
1342 case DDC_LCD: /* MM i2c */ 1396 case DDC_LCD: /* MM i2c */
1343 i2c_bus.valid = true; 1397 i2c_bus.valid = true;
1344 i2c_bus.hw_capable = true; 1398 i2c_bus.hw_capable = true;
1345 i2c_bus.mm_i2c = true; 1399 i2c_bus.mm_i2c = true;
1346 tmds->i2c_bus = radeon_i2c_create(dev, &i2c_bus, "DVO"); 1400 i2c_bus.i2c_id = RADEON_I2C_MM_ID;
1401 tmds->i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
1347 break; 1402 break;
1348 default: 1403 default:
1349 DRM_ERROR("Unsupported gpio %d\n", gpio); 1404 DRM_ERROR("Unsupported gpio %d\n", gpio);
@@ -1926,6 +1981,8 @@ static bool radeon_apply_legacy_quirks(struct drm_device *dev,
1926 ddc_i2c->en_data_mask = 0x80; 1981 ddc_i2c->en_data_mask = 0x80;
1927 ddc_i2c->y_clk_mask = (0x20 << 8); 1982 ddc_i2c->y_clk_mask = (0x20 << 8);
1928 ddc_i2c->y_data_mask = 0x80; 1983 ddc_i2c->y_data_mask = 0x80;
1984 ddc_i2c->i2c_id = RADEON_I2C_GPIO_ID;
1985 radeon_i2c_add(rdev, ddc_i2c, "GPIO_DDC");
1929 } 1986 }
1930 1987
1931 /* R3xx+ chips don't have GPIO_CRT2_DDC gpio pad */ 1988 /* R3xx+ chips don't have GPIO_CRT2_DDC gpio pad */
@@ -2318,6 +2375,8 @@ bool radeon_get_legacy_connector_info_from_bios(struct drm_device *dev)
2318 RBIOS32(lcd_ddc_info + 3); 2375 RBIOS32(lcd_ddc_info + 3);
2319 ddc_i2c.y_data_mask = 2376 ddc_i2c.y_data_mask =
2320 RBIOS32(lcd_ddc_info + 7); 2377 RBIOS32(lcd_ddc_info + 7);
2378 ddc_i2c.i2c_id = RADEON_I2C_LCD_ID;
2379 radeon_i2c_add(rdev, &ddc_i2c, "LCD");
2321 break; 2380 break;
2322 case DDC_GPIO: 2381 case DDC_GPIO:
2323 ddc_i2c = 2382 ddc_i2c =
@@ -2339,6 +2398,8 @@ bool radeon_get_legacy_connector_info_from_bios(struct drm_device *dev)
2339 RBIOS32(lcd_ddc_info + 3); 2398 RBIOS32(lcd_ddc_info + 3);
2340 ddc_i2c.y_data_mask = 2399 ddc_i2c.y_data_mask =
2341 RBIOS32(lcd_ddc_info + 7); 2400 RBIOS32(lcd_ddc_info + 7);
2401 ddc_i2c.i2c_id = RADEON_I2C_LCD_ID;
2402 radeon_i2c_add(rdev, &ddc_i2c, "LCD");
2342 break; 2403 break;
2343 default: 2404 default:
2344 ddc_i2c.valid = false; 2405 ddc_i2c.valid = false;
diff --git a/drivers/gpu/drm/radeon/radeon_connectors.c b/drivers/gpu/drm/radeon/radeon_connectors.c
index 2395c8600cf4..185a6d962b72 100644
--- a/drivers/gpu/drm/radeon/radeon_connectors.c
+++ b/drivers/gpu/drm/radeon/radeon_connectors.c
@@ -518,8 +518,6 @@ static void radeon_connector_destroy(struct drm_connector *connector)
518{ 518{
519 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 519 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
520 520
521 if (radeon_connector->ddc_bus)
522 radeon_i2c_destroy(radeon_connector->ddc_bus);
523 if (radeon_connector->edid) 521 if (radeon_connector->edid)
524 kfree(radeon_connector->edid); 522 kfree(radeon_connector->edid);
525 kfree(radeon_connector->con_priv); 523 kfree(radeon_connector->con_priv);
@@ -955,8 +953,6 @@ static void radeon_dp_connector_destroy(struct drm_connector *connector)
955 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 953 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
956 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv; 954 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
957 955
958 if (radeon_connector->ddc_bus)
959 radeon_i2c_destroy(radeon_connector->ddc_bus);
960 if (radeon_connector->edid) 956 if (radeon_connector->edid)
961 kfree(radeon_connector->edid); 957 kfree(radeon_connector->edid);
962 if (radeon_dig_connector->dp_i2c_bus) 958 if (radeon_dig_connector->dp_i2c_bus)
@@ -1088,7 +1084,7 @@ radeon_add_atom_connector(struct drm_device *dev,
1088 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type); 1084 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1089 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs); 1085 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1090 if (i2c_bus->valid) { 1086 if (i2c_bus->valid) {
1091 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "VGA"); 1087 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1092 if (!radeon_connector->ddc_bus) 1088 if (!radeon_connector->ddc_bus)
1093 goto failed; 1089 goto failed;
1094 } 1090 }
@@ -1104,7 +1100,7 @@ radeon_add_atom_connector(struct drm_device *dev,
1104 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type); 1100 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1105 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs); 1101 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1106 if (i2c_bus->valid) { 1102 if (i2c_bus->valid) {
1107 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI"); 1103 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1108 if (!radeon_connector->ddc_bus) 1104 if (!radeon_connector->ddc_bus)
1109 goto failed; 1105 goto failed;
1110 } 1106 }
@@ -1126,7 +1122,7 @@ radeon_add_atom_connector(struct drm_device *dev,
1126 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type); 1122 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1127 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs); 1123 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1128 if (i2c_bus->valid) { 1124 if (i2c_bus->valid) {
1129 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI"); 1125 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1130 if (!radeon_connector->ddc_bus) 1126 if (!radeon_connector->ddc_bus)
1131 goto failed; 1127 goto failed;
1132 } 1128 }
@@ -1156,7 +1152,7 @@ radeon_add_atom_connector(struct drm_device *dev,
1156 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type); 1152 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1157 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs); 1153 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1158 if (i2c_bus->valid) { 1154 if (i2c_bus->valid) {
1159 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "HDMI"); 1155 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1160 if (!radeon_connector->ddc_bus) 1156 if (!radeon_connector->ddc_bus)
1161 goto failed; 1157 goto failed;
1162 } 1158 }
@@ -1187,10 +1183,7 @@ radeon_add_atom_connector(struct drm_device *dev,
1187 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "DP-auxch"); 1183 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "DP-auxch");
1188 if (!radeon_dig_connector->dp_i2c_bus) 1184 if (!radeon_dig_connector->dp_i2c_bus)
1189 goto failed; 1185 goto failed;
1190 if (connector_type == DRM_MODE_CONNECTOR_eDP) 1186 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1191 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "eDP");
1192 else
1193 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DP");
1194 if (!radeon_connector->ddc_bus) 1187 if (!radeon_connector->ddc_bus)
1195 goto failed; 1188 goto failed;
1196 } 1189 }
@@ -1230,7 +1223,7 @@ radeon_add_atom_connector(struct drm_device *dev,
1230 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type); 1223 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
1231 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs); 1224 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
1232 if (i2c_bus->valid) { 1225 if (i2c_bus->valid) {
1233 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "LVDS"); 1226 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1234 if (!radeon_connector->ddc_bus) 1227 if (!radeon_connector->ddc_bus)
1235 goto failed; 1228 goto failed;
1236 } 1229 }
@@ -1252,8 +1245,6 @@ radeon_add_atom_connector(struct drm_device *dev,
1252 return; 1245 return;
1253 1246
1254failed: 1247failed:
1255 if (radeon_connector->ddc_bus)
1256 radeon_i2c_destroy(radeon_connector->ddc_bus);
1257 drm_connector_cleanup(connector); 1248 drm_connector_cleanup(connector);
1258 kfree(connector); 1249 kfree(connector);
1259} 1250}
@@ -1300,7 +1291,7 @@ radeon_add_legacy_connector(struct drm_device *dev,
1300 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type); 1291 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1301 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs); 1292 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1302 if (i2c_bus->valid) { 1293 if (i2c_bus->valid) {
1303 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "VGA"); 1294 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1304 if (!radeon_connector->ddc_bus) 1295 if (!radeon_connector->ddc_bus)
1305 goto failed; 1296 goto failed;
1306 } 1297 }
@@ -1316,7 +1307,7 @@ radeon_add_legacy_connector(struct drm_device *dev,
1316 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type); 1307 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1317 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs); 1308 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1318 if (i2c_bus->valid) { 1309 if (i2c_bus->valid) {
1319 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI"); 1310 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1320 if (!radeon_connector->ddc_bus) 1311 if (!radeon_connector->ddc_bus)
1321 goto failed; 1312 goto failed;
1322 } 1313 }
@@ -1332,7 +1323,7 @@ radeon_add_legacy_connector(struct drm_device *dev,
1332 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type); 1323 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1333 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs); 1324 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1334 if (i2c_bus->valid) { 1325 if (i2c_bus->valid) {
1335 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI"); 1326 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1336 if (!radeon_connector->ddc_bus) 1327 if (!radeon_connector->ddc_bus)
1337 goto failed; 1328 goto failed;
1338 } 1329 }
@@ -1372,7 +1363,7 @@ radeon_add_legacy_connector(struct drm_device *dev,
1372 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type); 1363 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
1373 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs); 1364 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
1374 if (i2c_bus->valid) { 1365 if (i2c_bus->valid) {
1375 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "LVDS"); 1366 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1376 if (!radeon_connector->ddc_bus) 1367 if (!radeon_connector->ddc_bus)
1377 goto failed; 1368 goto failed;
1378 } 1369 }
@@ -1393,8 +1384,6 @@ radeon_add_legacy_connector(struct drm_device *dev,
1393 return; 1384 return;
1394 1385
1395failed: 1386failed:
1396 if (radeon_connector->ddc_bus)
1397 radeon_i2c_destroy(radeon_connector->ddc_bus);
1398 drm_connector_cleanup(connector); 1387 drm_connector_cleanup(connector);
1399 kfree(connector); 1388 kfree(connector);
1400} 1389}
diff --git a/drivers/gpu/drm/radeon/radeon_display.c b/drivers/gpu/drm/radeon/radeon_display.c
index 74dac9635d70..52ac08e9a045 100644
--- a/drivers/gpu/drm/radeon/radeon_display.c
+++ b/drivers/gpu/drm/radeon/radeon_display.c
@@ -1040,6 +1040,9 @@ int radeon_modeset_init(struct radeon_device *rdev)
1040 return ret; 1040 return ret;
1041 } 1041 }
1042 1042
1043 /* init i2c buses */
1044 radeon_i2c_init(rdev);
1045
1043 /* check combios for a valid hardcoded EDID - Sun servers */ 1046 /* check combios for a valid hardcoded EDID - Sun servers */
1044 if (!rdev->is_atom_bios) { 1047 if (!rdev->is_atom_bios) {
1045 /* check for hardcoded EDID in BIOS */ 1048 /* check for hardcoded EDID in BIOS */
@@ -1080,6 +1083,8 @@ void radeon_modeset_fini(struct radeon_device *rdev)
1080 drm_mode_config_cleanup(rdev->ddev); 1083 drm_mode_config_cleanup(rdev->ddev);
1081 rdev->mode_info.mode_config_initialized = false; 1084 rdev->mode_info.mode_config_initialized = false;
1082 } 1085 }
1086 /* free i2c buses */
1087 radeon_i2c_fini(rdev);
1083} 1088}
1084 1089
1085bool radeon_crtc_scaling_mode_fixup(struct drm_crtc *crtc, 1090bool radeon_crtc_scaling_mode_fixup(struct drm_crtc *crtc,
diff --git a/drivers/gpu/drm/radeon/radeon_i2c.c b/drivers/gpu/drm/radeon/radeon_i2c.c
index 5def6f5dff38..e71f2eb02ee2 100644
--- a/drivers/gpu/drm/radeon/radeon_i2c.c
+++ b/drivers/gpu/drm/radeon/radeon_i2c.c
@@ -960,6 +960,59 @@ void radeon_i2c_destroy(struct radeon_i2c_chan *i2c)
960 kfree(i2c); 960 kfree(i2c);
961} 961}
962 962
963/* Add the default buses */
964void radeon_i2c_init(struct radeon_device *rdev)
965{
966 if (rdev->is_atom_bios)
967 radeon_atombios_i2c_init(rdev);
968 else
969 radeon_combios_i2c_init(rdev);
970}
971
972/* remove all the buses */
973void radeon_i2c_fini(struct radeon_device *rdev)
974{
975 int i;
976
977 for (i = 0; i < RADEON_MAX_I2C_BUS; i++) {
978 if (rdev->i2c_bus[i]) {
979 radeon_i2c_destroy(rdev->i2c_bus[i]);
980 rdev->i2c_bus[i] = NULL;
981 }
982 }
983}
984
985/* Add additional buses */
986void radeon_i2c_add(struct radeon_device *rdev,
987 struct radeon_i2c_bus_rec *rec,
988 const char *name)
989{
990 struct drm_device *dev = rdev->ddev;
991 int i;
992
993 for (i = 0; i < RADEON_MAX_I2C_BUS; i++) {
994 if (!rdev->i2c_bus[i]) {
995 rdev->i2c_bus[i] = radeon_i2c_create(dev, rec, name);
996 return;
997 }
998 }
999}
1000
1001/* looks up bus based on id */
1002struct radeon_i2c_chan *radeon_i2c_lookup(struct radeon_device *rdev,
1003 struct radeon_i2c_bus_rec *i2c_bus)
1004{
1005 int i;
1006
1007 for (i = 0; i < RADEON_MAX_I2C_BUS; i++) {
1008 if (rdev->i2c_bus[i] &&
1009 (rdev->i2c_bus[i]->rec.i2c_id == i2c_bus->i2c_id)) {
1010 return rdev->i2c_bus[i];
1011 }
1012 }
1013 return NULL;
1014}
1015
963struct drm_encoder *radeon_best_encoder(struct drm_connector *connector) 1016struct drm_encoder *radeon_best_encoder(struct drm_connector *connector)
964{ 1017{
965 return NULL; 1018 return NULL;
diff --git a/drivers/gpu/drm/radeon/radeon_mode.h b/drivers/gpu/drm/radeon/radeon_mode.h
index 71aea4037e90..02d4e2af6180 100644
--- a/drivers/gpu/drm/radeon/radeon_mode.h
+++ b/drivers/gpu/drm/radeon/radeon_mode.h
@@ -82,6 +82,8 @@ enum radeon_hpd_id {
82 RADEON_HPD_NONE = 0xff, 82 RADEON_HPD_NONE = 0xff,
83}; 83};
84 84
85#define RADEON_MAX_I2C_BUS 16
86
85/* radeon gpio-based i2c 87/* radeon gpio-based i2c
86 * 1. "mask" reg and bits 88 * 1. "mask" reg and bits
87 * grabs the gpio pins for software use 89 * grabs the gpio pins for software use
@@ -445,6 +447,15 @@ extern void atombios_dig_transmitter_setup(struct drm_encoder *encoder,
445extern int radeon_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode, 447extern int radeon_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode,
446 uint8_t write_byte, uint8_t *read_byte); 448 uint8_t write_byte, uint8_t *read_byte);
447 449
450extern void radeon_i2c_init(struct radeon_device *rdev);
451extern void radeon_i2c_fini(struct radeon_device *rdev);
452extern void radeon_combios_i2c_init(struct radeon_device *rdev);
453extern void radeon_atombios_i2c_init(struct radeon_device *rdev);
454extern void radeon_i2c_add(struct radeon_device *rdev,
455 struct radeon_i2c_bus_rec *rec,
456 const char *name);
457extern struct radeon_i2c_chan *radeon_i2c_lookup(struct radeon_device *rdev,
458 struct radeon_i2c_bus_rec *i2c_bus);
448extern struct radeon_i2c_chan *radeon_i2c_create_dp(struct drm_device *dev, 459extern struct radeon_i2c_chan *radeon_i2c_create_dp(struct drm_device *dev,
449 struct radeon_i2c_bus_rec *rec, 460 struct radeon_i2c_bus_rec *rec,
450 const char *name); 461 const char *name);