Skip to contentSkip to conversation

further radeon drm kms hw i2c fixes

PATCH In review Alex Deucher 2 participants 5 messages Feb 6, 2010 – Feb 8, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 further radeon drm kms hw i2c fixes

These patches add further fixes to the hw i2c code. Still left to do:
- Find a way to not expose the internal bit algo bus used by radeon algo
- Figure out why hw i2c isn't working for LVDS on mac laptops
- Any other remaining bugs

Alex

From 2da017df9b25aa2dd50f53f28efa293f15ed5acc Mon Sep 17 00:00:00 2001
From: Alex Deucher <[email protected]>
Date: Sat, 6 Feb 2010 16:43:52 -0500
Subject: [PATCH] drm/radeon/kms: straighten out hw i2c gpio lines

The line mapping is different depending on the asic.

---
 drivers/gpu/drm/radeon/radeon_combios.c |   56 +++++++++++++++++-
 drivers/gpu/drm/radeon/radeon_i2c.c     |   98 +++++++++++++++++++++++++++---
 drivers/gpu/drm/radeon/radeon_reg.h     |    6 +-
 3 files changed, 144 insertions(+), 16 deletions(-)
drivers/gpu/drm/radeon/radeon_combios.c +53 -3
index 06b4c3f..1d398af 100644
@@ -507,9 +507,55 @@ static struct radeon_i2c_bus_rec combios_setup_i2c_bus(struct radeon_device *rde
 		i2c.y_data_reg = ddc_line;
 	}
 
-	if (rdev->family < CHIP_R200)
-		i2c.hw_capable = false;
-	else {
+	switch (rdev->family) {
+	case CHIP_R100:
+	case CHIP_RV100:
+	case CHIP_RS100:
+	case CHIP_RV200:
+	case CHIP_RS200:
+		switch (ddc_line) {
+		case RADEON_GPIO_DVI_DDC:
+			/* in theory this should be hw capable,
+			 * but it doesn't seem to work
+			 */
+			i2c.hw_capable = false;
+			break;
+		default:
+			i2c.hw_capable = false;
+			break;
+		}
+		break;
+	case CHIP_R200:
+	case CHIP_RV250:
+	case CHIP_RS300:
+	case CHIP_RV280:
+		switch (ddc_line) {
+		case RADEON_GPIO_VGA_DDC:
+		case RADEON_GPIO_DVI_DDC:
+		case RADEON_GPIO_CRT2_DDC:
+			i2c.hw_capable = true;
+			break;
+		default:
+			i2c.hw_capable = false;
+			break;
+		}
+		break;
+	case CHIP_R300:
+	case CHIP_R350:
+		switch (ddc_line) {
+		case RADEON_GPIO_VGA_DDC:
+		case RADEON_GPIO_DVI_DDC:
+			i2c.hw_capable = true;
+			break;
+		default:
+			i2c.hw_capable = false;
+			break;
+		}
+		break;
+	case CHIP_RV350:
+	case CHIP_RV380:
+	case CHIP_RS400:
+	case CHIP_RS480:
 		switch (ddc_line) {
 		case RADEON_GPIO_VGA_DDC:
 		case RADEON_GPIO_DVI_DDC:
@@ -525,6 +571,10 @@ static struct radeon_i2c_bus_rec combios_setup_i2c_bus(struct radeon_device *rde
 			i2c.hw_capable = false;
 			break;
 		}
+		break;
+	default:
+		i2c.hw_capable = false;
+		break;
 	}
 	i2c.mm_i2c = false;
 	i2c.i2c_id = 0;
drivers/gpu/drm/radeon/radeon_i2c.c +88 -10

122 lines not on this page · raw message

drivers/gpu/drm/radeon/radeon_reg.h +3 -3
index e293f2b..b4a0667 100644
@@ -1083,9 +1083,9 @@
 
 #define RADEON_DVI_I2C_CNTL_0		    0x02e0
 #       define R200_DVI_I2C_PIN_SEL(x)      ((x) << 3)
-#       define R200_SEL_DDC1                0 /* 0x60 - VGA_DDC */
-#       define R200_SEL_DDC2                1 /* 0x64 - DVI_DDC */
-#       define R200_SEL_DDC3                2 /* 0x68 - MONID_DDC */
+#       define R200_SEL_DDC1                0 /* depends on asic */
+#       define R200_SEL_DDC2                1 /* depends on asic */
+#       define R200_SEL_DDC3                2 /* depends on asic */
 #	define RADEON_SW_WANTS_TO_USE_DVI_I2C (1 << 13)
 #	define RADEON_SW_CAN_USE_DVI_I2C      (1 << 13)
 #	define RADEON_SW_DONE_USING_DVI_I2C   (1 << 14)
Signature · 1 line
1.5.6.3

From 8a073952cc7ab4ed328cbabe9d88038185c1538c Mon Sep 17 00:00:00 2001
From: Alex Deucher <[email protected]>
Date: Sat, 6 Feb 2010 16:58:01 -0500
Subject: [PATCH] drm/radeon/kms: protect hw i2c engine with a mutex

Only one hw i2c engine, but it can service several gpio lines by selecting the line you want to use.

---
 drivers/gpu/drm/radeon/radeon.h        |    1 +
 drivers/gpu/drm/radeon/radeon_device.c |    1 +
 drivers/gpu/drm/radeon/radeon_i2c.c    |   11 +++++++++++
 3 files changed, 13 insertions(+), 0 deletions(-)
drivers/gpu/drm/radeon/radeon.h +1 -0
index 63aadc8..83f8453 100644
@@ -943,6 +943,7 @@ struct radeon_device {
 	struct work_struct hotplug_work;
 	int num_crtc; /* number of crtcs */
 	bool edid_in_rom; /* hardcoded edid in rom */
+	struct mutex dc_hw_i2c_mutex; /* display controller hw i2c mutex */
 
 	/* audio stuff */
 	struct timer_list	audio_timer;
drivers/gpu/drm/radeon/radeon_device.c +1 -0
index 42cfadd..85d2322 100644
@@ -641,6 +641,7 @@ int radeon_device_init(struct radeon_device *rdev,
 	mutex_init(&rdev->cs_mutex);
 	mutex_init(&rdev->ib_pool.mutex);
 	mutex_init(&rdev->cp.mutex);
+	mutex_init(&rdev->dc_hw_i2c_mutex);
 	if (rdev->family >= CHIP_R600)
 		spin_lock_init(&rdev->ih.lock);
 	mutex_init(&rdev->gem.mutex);
drivers/gpu/drm/radeon/radeon_i2c.c +11 -0
index 0ab8523..e0a2017 100644
@@ -82,6 +82,7 @@ static void radeon_i2c_do_lock(struct radeon_i2c_chan *i2c, int lock_state)
 			else
 				reg = RADEON_GPIO_CRT2_DDC;
 
+			mutex_lock(&rdev->dc_hw_i2c_mutex);
 			if (rec->a_clk_reg == reg) {
 				WREG32(RADEON_DVI_I2C_CNTL_0, (RADEON_I2C_SOFT_RST |
 							       R200_DVI_I2C_PIN_SEL(R200_SEL_DDC1)));
@@ -89,6 +90,7 @@ static void radeon_i2c_do_lock(struct radeon_i2c_chan *i2c, int lock_state)
 				WREG32(RADEON_DVI_I2C_CNTL_0, (RADEON_I2C_SOFT_RST |
 							       R200_DVI_I2C_PIN_SEL(R200_SEL_DDC3)));
 			}
+			mutex_unlock(&rdev->dc_hw_i2c_mutex);
 		}
 	}
 
@@ -195,6 +197,8 @@ static int r100_hw_i2c_xfer(struct i2c_adapter *i2c_adap,
 	u32 i2c_cntl_0, i2c_cntl_1, i2c_data;
 	u32 tmp, reg;
 
+	mutex_lock(&rdev->dc_hw_i2c_mutex);
+
 	reg = ((prescale << RADEON_I2C_PRESCALE_SHIFT) |
 	       RADEON_I2C_START |
 	       RADEON_I2C_STOP |
@@ -405,6 +409,9 @@ done:
 		tmp &= ~ATOM_S6_HW_I2C_BUSY_STATE;
 		WREG32(RADEON_BIOS_6_SCRATCH, tmp);
 	}
+
+	mutex_unlock(&rdev->dc_hw_i2c_mutex);
+
 	return ret;
 }
 
@@ -425,6 +432,8 @@ static int r500_hw_i2c_xfer(struct i2c_adapter *i2c_adap,
 	u32 tmp, reg;
 	u32 saved1, saved2;
 
+	mutex_lock(&rdev->dc_hw_i2c_mutex);
+
 	/* clear gpio mask bits */
 	tmp = RREG32(rec->mask_clk_reg);
 	tmp &= ~rec->mask_clk_mask;
@@ -639,6 +648,8 @@ done:
 	tmp &= ~ATOM_S6_HW_I2C_BUSY_STATE;
 	WREG32(RADEON_BIOS_6_SCRATCH, tmp);
 
+	mutex_unlock(&rdev->dc_hw_i2c_mutex);
+
 	return ret;
 }
 
Signature · 1 line
1.5.6.3

From 3e025dc76a7d50bd9111ad5b91fe19a1a1277b92 Mon Sep 17 00:00:00 2001
From: Alex Deucher <[email protected]>
Date: Sat, 6 Feb 2010 17:06:42 -0500
Subject: [PATCH] drm/radeon/kms: take the pm mutex when using hw i2c

we need a constant sclk for i2c prescale. Also, get the current sclk when calculating prescale rather than using the default sclk.

---
 drivers/gpu/drm/radeon/radeon_i2c.c |   26 +++++++++++++++++---------
 1 files changed, 17 insertions(+), 9 deletions(-)
drivers/gpu/drm/radeon/radeon_i2c.c +17 -9
index e0a2017..b715632 100644
@@ -192,12 +192,16 @@ static int r100_hw_i2c_xfer(struct i2c_adapter *i2c_adap,
 	struct radeon_i2c_bus_rec *rec = &i2c->rec;
 	struct i2c_msg *p;
 	int i, j, k, ret = num;
-	/* XXX: use get_engine_clock() to get the current sclk */
-	u32 prescale = (((rdev->clock.default_sclk * 10)/(4 * 128 * 100) + 1) << 8) + 128;
+	u32 sclk, prescale;
 	u32 i2c_cntl_0, i2c_cntl_1, i2c_data;
 	u32 tmp, reg;
 
 	mutex_lock(&rdev->dc_hw_i2c_mutex);
+	/* take the pm lock since we need a constant sclk */
+	mutex_lock(&rdev->pm.mutex);
+
+	sclk = radeon_get_engine_clock(rdev);
+	prescale = (((sclk * 10)/(4 * 128 * 100) + 1) << 8) + 128;
 
 	reg = ((prescale << RADEON_I2C_PRESCALE_SHIFT) |
 	       RADEON_I2C_START |
@@ -410,6 +414,7 @@ done:
 		WREG32(RADEON_BIOS_6_SCRATCH, tmp);
 	}
 
+	mutex_unlock(&rdev->pm.mutex);
 	mutex_unlock(&rdev->dc_hw_i2c_mutex);
 
 	return ret;
@@ -427,12 +432,19 @@ static int r500_hw_i2c_xfer(struct i2c_adapter *i2c_adap,
 	struct i2c_msg *p;
 	int i2c_clock = 50;
 	int i, j, remaining, current_count, buffer_offset, ret = num;
-	/* XXX: use get_engine_clock() to get the current sclk */
-	u32 prescale;
+	u32 sclk, prescale;
 	u32 tmp, reg;
 	u32 saved1, saved2;
 
 	mutex_lock(&rdev->dc_hw_i2c_mutex);
+	/* take the pm lock since we need a constant sclk */
+	mutex_lock(&rdev->pm.mutex);
+
+	sclk = radeon_get_engine_clock(rdev);
+	if (rdev->family == CHIP_R520)
+		prescale = (127 << 8) + ((sclk * 10) / (4 * 127 * i2c_clock));
+	else
+		prescale = (((sclk * 10)/(4 * 128 * 100) + 1) << 8) + 128;
 
 	/* clear gpio mask bits */
 	tmp = RREG32(rec->mask_clk_reg);
@@ -486,11 +498,6 @@ static int r500_hw_i2c_xfer(struct i2c_adapter *i2c_adap,
 		goto done;
 	}
 
-	if (rdev->family == CHIP_R520)
-		prescale = (127 << 8) + ((rdev->clock.default_sclk * 10) / (4 * 127 * i2c_clock));
-	else
-		prescale = (((rdev->clock.default_sclk * 10)/(4 * 128 * 100) + 1) << 8) + 128;
-
 	reg = AVIVO_DC_I2C_START | AVIVO_DC_I2C_STOP | AVIVO_DC_I2C_EN;
 	switch (rec->mask_clk_reg) {
 	case AVIVO_DC_GPIO_DDC1_MASK:
@@ -648,6 +655,7 @@ done:
 	tmp &= ~ATOM_S6_HW_I2C_BUSY_STATE;
 	WREG32(RADEON_BIOS_6_SCRATCH, tmp);
 
+	mutex_unlock(&rdev->pm.mutex);
 	mutex_unlock(&rdev->dc_hw_i2c_mutex);
 
 	return ret;
Signature · 1 line
1.5.6.3

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation Stay online with enterprise data centers and the best network in the business Choose flexible plans and management services without long-term contracts Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com

--
_______________________________________________
Dri-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dri-devel

#1 lore raw

2010/2/6 Alex Deucher <[email protected]>:

Quoted 6 lines

These patches add further fixes to the hw i2c code.  Still left to do:
- Find a way to not expose the internal bit algo bus used by radeon algo
- Figure out why hw i2c isn't working for LVDS on mac laptops
- Any other remaining bugs

Alex

Ups, my PM bug. Thanks for fixing.

Signature · 13 lines
Rafał

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
--
_______________________________________________
Dri-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dri-devel
#2 lore raw

2010/2/8 Rafał Miłecki <[email protected]>:

Quoted 9 lines

2010/2/6 Alex Deucher <[email protected]>:

Quoted 6 lines

These patches add further fixes to the hw i2c code.  Still left to do:
- Find a way to not expose the internal bit algo bus used by radeon algo
- Figure out why hw i2c isn't working for LVDS on mac laptops
- Any other remaining bugs

Alex

Ups, my PM bug. Thanks for fixing.

What was your PM bug?

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation Stay online with enterprise data centers and the best network in the business Choose flexible plans and management services without long-term contracts Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
--
_______________________________________________
Dri-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dri-devel

#3 lore raw

W dniu 8 lutego 2010 15:38 użytkownik Alex Deucher

Quoted 7 lines · <[email protected]> napisał:

2010/2/8 Rafał Miłecki <[email protected]>:

Quoted 6 lines

2010/2/6 Alex Deucher <[email protected]>:

Quoted 5 lines

These patches add further fixes to the hw i2c code.  Still left to do:
- Find a way to not expose the internal bit algo bus used by radeon algo
- Figure out why hw i2c isn't working for LVDS on mac laptops
- Any other remaining bugs

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Alex

Ups, my PM bug. Thanks for fixing.

What was your PM bug?

I thought that I introduced I2C bug with my power management code. When I saw you commit I thought about some old I2C fix in radeonhd:
http://cgit.freedesktop.org/xorg/driver/xf86-video-radeonhd/commit/?id=42a81085042606cd812732a13b66527d37fc625c

I thought it's the same bug Matthias was hitting with radeonhd with PM.

Btw. do we need anything like radeonhd got in
ace8f44f6cbd7fd393b5a8a30468471ccee3726c commit?

Signature · 13 lines
Rafał

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
--
_______________________________________________
Dri-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dri-devel
#4 lore raw

2010/2/8 Rafał Miłecki <[email protected]>:

Quoted 15 lines

W dniu 8 lutego 2010 15:38 użytkownik Alex Deucher

Quoted 7 lines · <[email protected]> napisał:

2010/2/8 Rafał Miłecki <[email protected]>:

Quoted 6 lines

2010/2/6 Alex Deucher <[email protected]>:

Quoted 5 lines

These patches add further fixes to the hw i2c code.  Still left to do:
- Find a way to not expose the internal bit algo bus used by radeon algo
- Figure out why hw i2c isn't working for LVDS on mac laptops
- Any other remaining bugs

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Alex

Ups, my PM bug. Thanks for fixing.

What was your PM bug?

Quoted 9 lines

I thought that I introduced I2C bug with my power management code. When I saw you commit I thought about some old I2C fix in radeonhd:
http://cgit.freedesktop.org/xorg/driver/xf86-video-radeonhd/commit/?id=42a81085042606cd812732a13b66527d37fc625c

I thought it's the same bug Matthias was hitting with radeonhd with PM.

Btw. do we need anything like radeonhd got in
ace8f44f6cbd7fd393b5a8a30468471ccee3726c commit?

Yes.

Quoted 3 lines

--
Rafał

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation Stay online with enterprise data centers and the best network in the business Choose flexible plans and management services without long-term contracts Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
--