Skip to contentSkip to conversation

omapfb: Fix regulator API abuse in dss.c and hdmi4.c

PATCH In review Mark Brown 3 participants 9 messages Mar 30, 2016 – Apr 26, 2016

Subsystems (2)
lore
Share & tools
lore

Mark Brown

author
#0 lore raw

PATCH 1/1 omapfb: Fix regulator API abuse in dss.c and hdmi4.c

The voltage changing code in this driver is broken and should be removed. The driver sets a single, exact voltage on probe. Unless there is a very good reason for this (which should be documented in comments) constraints like this need to be set via the machine constraints, voltage setting in a driver is expected to be used in cases where the voltage varies at runtime.

In addition client drivers should almost never be calling regulator_can_set_voltage(), if the device needs to set a voltage it needs to set the voltage and the regulator core will handle the case where the regulator is fixed voltage. If the driver can skip setting the voltage it should just never set the voltage.

---
 drivers/video/fbdev/omap2/omapfb/dss/dsi.c   | 9 ---------
 drivers/video/fbdev/omap2/omapfb/dss/hdmi4.c | 9 ---------
 2 files changed, 18 deletions(-)
drivers/video/fbdev/omap2/omapfb/dss/dsi.c +0 -9
index 0eec073b3919..cfd0e3d5f36a 100644
@@ -1180,15 +1180,6 @@ static int dsi_regulator_init(struct platform_device *dsidev)
 		return PTR_ERR(vdds_dsi);
 	}
 
-	if (regulator_can_change_voltage(vdds_dsi)) {
-		r = regulator_set_voltage(vdds_dsi, 1800000, 1800000);
-		if (r) {
-			devm_regulator_put(vdds_dsi);
-			DSSERR("can't set the DSI regulator voltage\n");
-			return r;
-		}
-	}
-
 	dsi->vdds_dsi_reg = vdds_dsi;
 
 	return 0;
drivers/video/fbdev/omap2/omapfb/dss/hdmi4.c +0 -9
index 7103c659a534..68b5ce1610ea 100644
@@ -114,15 +114,6 @@ static int hdmi_init_regulator(void)
 		return PTR_ERR(reg);
 	}
 
-	if (regulator_can_change_voltage(reg)) {
-		r = regulator_set_voltage(reg, 1800000, 1800000);
-		if (r) {
-			devm_regulator_put(reg);
-			DSSWARN("can't set the regulator voltage\n");
-			return r;
-		}
-	}
-
 	hdmi.vdda_reg = reg;
 
 	return 0;
Signature · 1 line
2.8.0.rc3
#1 lore raw

Hi Mark,

Quoted 26 lines · Mark Brown

The voltage changing code in this driver is broken and should be removed. The driver sets a single, exact voltage on probe. Unless there is a very good reason for this (which should be documented in comments) constraints like this need to be set via the machine constraints, voltage setting in a driver is expected to be used in cases where the voltage varies at runtime.

In addition client drivers should almost never be calling regulator_can_set_voltage(), if the device needs to set a voltage it needs to set the voltage and the regulator core will handle the case where the regulator is fixed voltage. If the driver can skip setting the voltage it should just never set the voltage.

---
 drivers/video/fbdev/omap2/omapfb/dss/dsi.c   | 9 ---------
 drivers/video/fbdev/omap2/omapfb/dss/hdmi4.c | 9 ---------
 2 files changed, 18 deletions(-)
drivers/video/fbdev/omap2/omapfb/dss/dsi.c +0 -0
index 0eec073b3919..cfd0e3d5f36a 100644
@@ -1180,15 +1180,6 @@ static int dsi_regulator_init(struct platform_device *dsidev)
 		return PTR_ERR(vdds_dsi);
 	}

drivers/video/fbdev/omap2/omapfb/dss/dsi.c static int dsi_regulator_init(struct platform_device *dsidev) · line 1191

Quoted 10 lines
drivers/video/fbdev/omap2/omapfb/dss/dsi.c +0 -9
 
-	if (regulator_can_change_voltage(vdds_dsi)) {
-		r = regulator_set_voltage(vdds_dsi, 1800000, 1800000);
-		if (r) {
-			devm_regulator_put(vdds_dsi);
-			DSSERR("can't set the DSI regulator voltage\n");
-			return r;
-		}
-	}
-

This code did fix an issue, see 02b7a32083b9930543663720758de249b4f6a2a3.

Now, even at the time when I wrote that fix, it did feel a bit odd to me. I have to say I don't remember the discussion that led to the patch, perhaps it was something along "yes, the driver should not need to do that, but for the time being do it".

So where are these "machine constraints" defined?

Tomi

author
#2 lore raw
In reply to Mark Brown
Quoted 1 line · Tomi Valkeinen

This code did fix an issue, see 02b7a32083b9930543663720758de249b4f6a2a3.

That change isn't sensible, especially the _can_change_voltage() like I said in the commit log.

Quoted 4 lines

Now, even at the time when I wrote that fix, it did feel a bit odd to me. I have to say I don't remember the discussion that led to the patch, perhaps it was something along "yes, the driver should not need to do that, but for the time being do it".

That wasn't a discusion I was involved in, a quick google suggests it might've been off-list.

Quoted 1 line

So where are these "machine constraints" defined?

They're the DT. Your machine constraints just seem broken and need to be fixed, most likely whoever wrote the constraints for the platform completely failed to understand the purpose of constraints and filled in the maximum range of voltages that the regulator in use on the board can support.

#3 lore raw
In reply to Mark Brown
Quoted 6 lines · Mark Brown
Quoted 1 line · Tomi Valkeinen

This code did fix an issue, see 02b7a32083b9930543663720758de249b4f6a2a3.

That change isn't sensible, especially the _can_change_voltage() like I said in the commit log.

I may remember wrong, but I think regulator_set_voltage() failed if regulator_can_change_voltage() returned false. So I ended up having the 'if' there. But I may remember wrong, or maybe it's been changed since.

Quoted 7 lines
Quoted 4 lines

Now, even at the time when I wrote that fix, it did feel a bit odd to me. I have to say I don't remember the discussion that led to the patch, perhaps it was something along "yes, the driver should not need to do that, but for the time being do it".

That wasn't a discusion I was involved in, a quick google suggests it might've been off-list.

That's possible. With quick googling, this may have longer history than the patch I sent.

Quoted 7 lines
Quoted 1 line

So where are these "machine constraints" defined?

They're the DT. Your machine constraints just seem broken and need to be fixed, most likely whoever wrote the constraints for the platform completely failed to understand the purpose of constraints and filled in the maximum range of voltages that the regulator in use on the board can support.

Ok.

Tero, Tony, with a quick look, for example omap5-board-common.dtsi defines ldo4_reg having range from 1.5 to 1.8. That should be changed to 1.8 only, right? ldo1_reg has a range too, I'm not familiar with that LDO's use, but it's for camera so my guess is that it should be 1.8 too.

I can have a more thorough look tomorrow, and do a test run on omap5 uevm (with Mark's patch).

I wonder why we have the same code in hdmi4. Again with a quick look, omap4 boards seem to use vdac for hdmi, and vdac doesn't have any constraints in twl6030.dtsi, so I presume it's a fixed-voltage.

Anyway, I'm happy to apply this patch (and we need similar for hdmi5, and also for omapdrm), we just need to do any necessary fixes to the .dts first.

Although strictly speaking, I guess that's breaking backward compatibility...

Tomi

author
#4 lore raw
In reply to Mark Brown
Quoted 11 lines · Tomi Valkeinen
Quoted 6 lines · Mark Brown
Quoted 1 line · Tomi Valkeinen

This code did fix an issue, see 02b7a32083b9930543663720758de249b4f6a2a3.

That change isn't sensible, especially the _can_change_voltage() like I said in the commit log.

I may remember wrong, but I think regulator_set_voltage() failed if regulator_can_change_voltage() returned false. So I ended up having the 'if' there. But I may remember wrong, or maybe it's been changed since.

That's not been the case since 2012 but your change was written in 2014...

Quoted 3 lines

I wonder why we have the same code in hdmi4. Again with a quick look, omap4 boards seem to use vdac for hdmi, and vdac doesn't have any constraints in twl6030.dtsi, so I presume it's a fixed-voltage.

Yes, if no range is specified the regulator API won't touch the set voltage.

Quoted 6 lines

Anyway, I'm happy to apply this patch (and we need similar for hdmi5, and also for omapdrm), we just need to do any necessary fixes to the .dts first.

Although strictly speaking, I guess that's breaking backward compatibility...

Will anyone notice?

#5 lore raw
In reply to Mark Brown

Tomi,

Quoted 7 lines · Tomi Valkeinen

Tero, Tony, with a quick look, for example omap5-board-common.dtsi defines ldo4_reg having range from 1.5 to 1.8. That should be changed to 1.8 only, right? ldo1_reg has a range too, I'm not familiar with that LDO's use, but it's for camera so my guess is that it should be 1.8 too.

I can have a more thorough look tomorrow, and do a test run on omap5 uevm (with Mark's patch).

Any news on this fix?

Tony

#6 lore raw
In reply to Mark Brown
Quoted 8 lines · Tony Lindgren

Tomi,

Quoted 5 lines · Tomi Valkeinen

Tero, Tony, with a quick look, for example omap5-board-common.dtsi defines ldo4_reg having range from 1.5 to 1.8. That should be changed to 1.8 only, right? ldo1_reg has a range too, I'm not familiar with that LDO's use, but it's for camera so my guess is that it should be 1.8 too.

Quoted 4 lines
Quoted 2 lines

I can have a more thorough look tomorrow, and do a test run on omap5 uevm (with Mark's patch).

Any news on this fix?

I sent the DT changes to you some time ago:

http://www.spinics.net/lists/linux-omap/msg127893.html
http://www.spinics.net/lists/linux-omap/msg127894.html

We can get rid of the dss code after those are in.

Tomi

#7 lore raw
In reply to Mark Brown
Quoted 10 lines · Tomi Valkeinen
Quoted 9 lines · Tony Lindgren
Quoted 7 lines · Tomi Valkeinen

Tero, Tony, with a quick look, for example omap5-board-common.dtsi defines ldo4_reg having range from 1.5 to 1.8. That should be changed to 1.8 only, right? ldo1_reg has a range too, I'm not familiar with that LDO's use, but it's for camera so my guess is that it should be 1.8 too.

I can have a more thorough look tomorrow, and do a test run on omap5 uevm (with Mark's patch).

Quoted 6 lines
Quoted 1 line

Any news on this fix?

I sent the DT changes to you some time ago:

http://www.spinics.net/lists/linux-omap/msg127893.html
http://www.spinics.net/lists/linux-omap/msg127894.html

OK thanks yeah I have those tagged as fixes.

Quoted 1 line

We can get rid of the dss code after those are in.

OK so I'll apply the fixes and forget about this thread :)

Thanks,

Tony

#8 lore raw
In reply to Mark Brown
Quoted 15 lines · Tony Lindgren
Quoted 14 lines · Tomi Valkeinen
Quoted 10 lines · Tony Lindgren
Quoted 7 lines · Tomi Valkeinen

Tero, Tony, with a quick look, for example omap5-board-common.dtsi defines ldo4_reg having range from 1.5 to 1.8. That should be changed to 1.8 only, right? ldo1_reg has a range too, I'm not familiar with that LDO's use, but it's for camera so my guess is that it should be 1.8 too.

I can have a more thorough look tomorrow, and do a test run on omap5 uevm (with Mark's patch).

Any news on this fix?

I sent the DT changes to you some time ago:

Quoted 8 lines
Quoted 2 lines

http://www.spinics.net/lists/linux-omap/msg127893.html
http://www.spinics.net/lists/linux-omap/msg127894.html

OK thanks yeah I have those tagged as fixes.

Quoted 1 line

We can get rid of the dss code after those are in.

OK so I'll apply the fixes and forget about this thread :)

Fixes for v4.6? If so, I can push the regulator cleanup to omapfb and omapdrm for 4.7, which would be nice.

Tomi