Skip to contentSkip to conversation

regulator: anatop: add is_enabled interface

PATCH In review Anson Huang 3 participants 8 messages Dec 16, 2013 – Dec 17, 2013 Voltage and current regulator framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 regulator: anatop: add is_enabled interface

Add is_enabled interface for anatop regulator in case some drivers need to know regulator's status.

---
 drivers/regulator/anatop-regulator.c |   15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/regulator/anatop-regulator.c +15 -0
index c734d09..770d836 100644
@@ -97,10 +97,25 @@ static int anatop_regmap_get_voltage_sel(struct regulator_dev *reg)
 	return regulator_get_voltage_sel_regmap(reg);
 }
 
+static int anatop_regmap_is_enabled(struct regulator_dev *reg)
+{
+	struct anatop_regulator *anatop_reg = rdev_get_drvdata(reg);
+	u32 val;
+
+	if (!anatop_reg->control_reg)
+		return -ENOTSUPP;
+
+	regmap_read(anatop_reg->anatop, anatop_reg->control_reg, &val);
+
+	return (val >> anatop_reg->vol_bit_shift) &
+		((1 << anatop_reg->vol_bit_width) - 1) ? 1 : 0;
+}
+
 static struct regulator_ops anatop_rops = {
 	.set_voltage_sel = anatop_regmap_set_voltage_sel,
 	.set_voltage_time_sel = anatop_regmap_set_voltage_time_sel,
 	.get_voltage_sel = anatop_regmap_get_voltage_sel,
+	.is_enabled = anatop_regmap_is_enabled,
 	.list_voltage = regulator_list_voltage_linear,
 	.map_voltage = regulator_map_voltage_linear,
 };
Signature · 1 line
1.7.9.5
maintainer
#1 lore raw

drivers/regulator/anatop-regulator.c static int anatop_regmap_get_voltage_sel(struct regulator_dev *reg) · line 106

Quoted 6 lines · Anson Huang
drivers/regulator/anatop-regulator.c +6 -0
+{
+	struct anatop_regulator *anatop_reg = rdev_get_drvdata(reg);
+	u32 val;
+
+	if (!anatop_reg->control_reg)
+		return -ENOTSUPP;

In what situation would this happen and why would the operation be provided in those situations?

drivers/regulator/anatop-regulator.c static int anatop_regmap_get_voltage_sel(struct regulator_dev *reg) · line 112

Quoted 5 lines
drivers/regulator/anatop-regulator.c +5 -0
+	regmap_read(anatop_reg->anatop, anatop_reg->control_reg, &val);
+
+	return (val >> anatop_reg->vol_bit_shift) &
+		((1 << anatop_reg->vol_bit_width) - 1) ? 1 : 0;
+}

This isn't terribly legible but it looks like it's trying to read to see if a non-zero voltage has been written. If that's the case it looks like enable and disable operations should be supported since presumably the register can be written as well.

Please try to avoid the ternery operator, especially in cases like this where it's not adding anything.

#2 lore raw

Hi, Mark
Thanks for your quick reply, see below inline:

Best Regards.
Anson huang 黄勇才

Freescale Semiconductor Shanghai
上海浦东新区亮景路192号A座2楼
201203
Tel:021-28937058

Quoted 9 lines

-----Original Message-----
From: Mark Brown [mailto:[email protected]]
Sent: Tuesday, December 17, 2013 2:58 AM
To: Huang Yongcai-B20788
Cc: [email protected]; [email protected]
Subject: Re: [PATCH] regulator: anatop: add is_enabled interface

On Mon, Dec 16, 2013 at 04:20:27PM -0500, Anson Huang wrote:

Quoted 9 lines

drivers/regulator/anatop-regulator.c static int anatop_regmap_get_voltage_sel(struct regulator_dev *reg) · line 106

Quoted 6 lines
drivers/regulator/anatop-regulator.c +6 -0
+{
+	struct anatop_regulator *anatop_reg = rdev_get_drvdata(reg);
+	u32 val;
+
+	if (!anatop_reg->control_reg)
+		return -ENOTSUPP;

In what situation would this happen and why would the operation be provided in those situations?

[Anson] This condition check is to avoid the case that control_reg is not Initialized correctly in the probe function.

Quoted 10 lines

drivers/regulator/anatop-regulator.c static int anatop_regmap_get_voltage_sel(struct regulator_dev *reg)

Quoted 5 lines
drivers/regulator/anatop-regulator.c +4 -0
+	regmap_read(anatop_reg->anatop, anatop_reg->control_reg, &val);
+
+	return (val >> anatop_reg->vol_bit_shift) &
+		((1 << anatop_reg->vol_bit_width) - 1) ? 1 : 0; }

This isn't terribly legible but it looks like it's trying to read to see if a non-zero voltage has been written. If that's the case it looks like enable and disable operations should be supported since presumably the register can be written as well.

[Anson]Yes, from the register description, we can see that if the bit field of REGx_TARG is not 0, then the LDO is enabled and there is output available. Adding this Interface is because some specific requirement of our i.MX6's freq/volt scaling, and We will add the enable/disable interface later when we add the GPU/VPU driver, as only VDDPU can be on/off according to GPU/VPU's behavior, and there is a complicated flow We need to follow, current is_enabled interface is for the case of VDDPU is turned off In uboot.

1. For cpufreq change, we need to scale VDDARM as well as VDDSOC/PU's voltage, each setpoint has different VDDARM, VDDSOC/PU voltage;
2. VDDARM and VDDSOC will be always on but VDDPU can be off in uboot due to the big leakage it has(as high as ~43mA on i.MX6Q), as it is only for GPU/VPU module, and we will have dynamic VDDPU power management available, so VDDPU LDO's status is changing according to GPU/VPU's behavior;
3. If VDDPU is off during cpufreq change, then there is no need to scaling VDDPU's voltage, so we will check whether VDDPU is enabled before scaling it in cpufreq driver, this is done in my other patch thread;

Quoted 3 lines

Please try to avoid the ternery operator, especially in cases like this where it's not adding anything.

[Anson] Accepted, will send out V2 patch if you think adding this interface for
our cpufreq driver is acceptable. ���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m���� ������?�I�

maintainer
#3 lore raw

On Tue, Dec 17, 2013 at 02:38:56AM +0000, [email protected] wrote:

Please fix the line length you're using to word wrap, it should be less than 80 columns to make your mails readable.

Quoted 8 lines
Quoted 5 lines

drivers/regulator/anatop-regulator.c static int anatop_regmap_get_voltage_sel(struct regulator_dev *reg) · line 106

Quoted 2 lines
drivers/regulator/anatop-regulator.c +2 -0
+	if (!anatop_reg->control_reg)
+		return -ENOTSUPP;

In what situation would this happen and why would the operation be provided in those situations?

[Anson] This condition check is to avoid the case that control_reg is not Initialized correctly in the probe function.

Why would that happen without the probe function failing - it would be better to add the error checking there wouldn't it?

Quoted 9 lines

1. For cpufreq change, we need to scale VDDARM as well as VDDSOC/PU's voltage, each setpoint has different VDDARM, VDDSOC/PU voltage;
2. VDDARM and VDDSOC will be always on but VDDPU can be off in uboot due to the big leakage it has(as high as ~43mA on i.MX6Q), as it is only for GPU/VPU module, and we will have dynamic VDDPU power management available, so VDDPU LDO's status is changing according to GPU/VPU's behavior;
3. If VDDPU is off during cpufreq change, then there is no need to scaling VDDPU's voltage, so we will check whether VDDPU is enabled before scaling it in cpufreq driver, this is done in my other patch thread;

This sounds like you need to have some higher level synchronisation between whatever is managing this supply and your cpufreq driver - if you rely on reading back the current status from the hardware there will always be races between reading the state and the other thing doing the enable or disable.

#4 lore raw

Sent from Anson's iPhone

Quoted 10 lines · 在 2013年12月17日,20:29,"Mark Brown" <[email protected]> 写道:

On Tue, Dec 17, 2013 at 02:38:56AM +0000, [email protected] wrote:

Please fix the line length you're using to word wrap, it should be less than 80 columns to make your mails readable.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/regulator/anatop-regulator.c +2 -0
+    if (!anatop_reg->control_reg)
+        return -ENOTSUPP;
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

In what situation would this happen and why would the operation be provided in those situations?

[Anson] This condition check is to avoid the case that control_reg is not Initialized correctly in the probe function.

Why would that happen without the probe function failing - it would be better to add the error checking there wouldn't it?

Okay, than what about other functions? there is such condition check there is other functions too, that is why I add it here. if you think it is no necessary, I will remove this check in my patch?

Quoted 11 lines
Quoted 10 lines

1. For cpufreq change, we need to scale VDDARM as well as VDDSOC/PU's voltage, each setpoint has different VDDARM, VDDSOC/PU voltage;
2. VDDARM and VDDSOC will be always on but VDDPU can be off in uboot due to the big leakage it has(as high as ~43mA on i.MX6Q), as it is only for GPU/VPU module, and we will have dynamic VDDPU power management available, so VDDPU LDO's status is changing according to GPU/VPU's behavior;
3. If VDDPU is off during cpufreq change, then there is no need to scaling VDDPU's voltage, so we will check whether VDDPU is enabled before scaling it in cpufreq driver, this is done in my other patch thread;

Quoted 5 lines

This sounds like you need to have some higher level synchronisation between whatever is managing this supply and your cpufreq driver - if you rely on reading back the current status from the hardware there will always be races between reading the state and the other thing doing the enable or disable.

yes, you are right. but I think we have handled that, all the operations of this LDO will via regulator interface, and regulator framework already has mutex lock. so there should be no such race in kernel as long as we all use regulator interface to access anatop LDO.�翳簕.n�+壏煯壄�+%娝�遍荻w�簕.n�+壏{炳G珴�妠ay�蕠跈�,jf"穐殢飦�戧鐉_璁(殠娸"濟�m���G珴�⒏?櫒璀�&x忈秈O曟瑉窔v豝�m��� �鹅�⒏?朓�

maintainer
#5 lore raw
Quoted 5 lines · On Tue, Dec 17, 2013 at 12:38:33PM +0000, [email protected] wrote:
Quoted 1 line

better to add the error checking there wouldn't it?

Okay, than what about other functions? there is such condition check there is other functions too, that is why I add it here. if you think it is no necessary, I will remove this check in my patch?

It shouldn't be in the other functions either.

Quoted 10 lines
Quoted 5 lines

This sounds like you need to have some higher level synchronisation between whatever is managing this supply and your cpufreq driver - if you rely on reading back the current status from the hardware there will always be races between reading the state and the other thing doing the enable or disable.

yes, you are right. but I think we have handled that, all the operations of this LDO will via regulator interface, and regulator framework already has mutex lock. so there should be no such race in kernel as long as we all use regulator interface to access anatop LDO.

No, that's not going to work. Consider this sequence:

cpufreq other driver
disable()
is_enabled()
enable()

The locking the regulator core does won't help you here, nothing stops the state of the regulator changing after it's read. Your cpufreq driver should just change the voltage and not worry if the regulator is enabled, the voltage change won't have any effect while the regulator is off and presumably if it does get enabled then it needs to be enabled at whatever voltage cpufreq set anyway.

In any case I'd be much happier with this patch if it implemented the enable and disable operations as well.

#6 lore raw

Sent from Anson's iPhone

Quoted 11 lines · 在 2013年12月17日,21:00,"Mark Brown" <[email protected]> 写道:
Quoted 5 lines · On Tue, Dec 17, 2013 at 12:38:33PM +0000, [email protected] wrote:
Quoted 1 line

better to add the error checking there wouldn't it?

Okay, than what about other functions? there is such condition check there is other functions too, that is why I add it here. if you think it is no necessary, I will remove this check in my patch?

It shouldn't be in the other functions either.

got it, I will remove it later.

Quoted 26 lines
Quoted 11 lines
Quoted 6 lines

This sounds like you need to have some higher level synchronisation between whatever is managing this supply and your cpufreq driver - if you rely on reading back the current status from the hardware there will always be races between reading the state and the other thing doing the enable or disable.

yes, you are right. but I think we have handled that, all the operations of this LDO will via regulator interface, and regulator framework already has mutex lock. so there should be no such race in kernel as long as we all use regulator interface to access anatop LDO.

No, that's not going to work. Consider this sequence:

cpufreq other driver
disable()
is_enabled()
enable()

The locking the regulator core does won't help you here, nothing stops the state of the regulator changing after it's read. Your cpufreq driver should just change the voltage and not worry if the regulator is enabled, the voltage change won't have any effect while the regulator is off and presumably if it does get enabled then it needs to be enabled at whatever voltage cpufreq set anyway.

Quoted 2 lines

In any case I'd be much happier with this patch if it implemented the enable and disable operations as well.

understand now. then maybe I should remove the PU check in cpufreq, although setting PU LDO if it is off before would bring unnessary power leak. I will add all these changes together with the dynamic PU LDO management feature, thanks for your time!�翳簕.n�+壏煯壄�+%娝�遍荻w�簕.n�+壏{炳G珴�妠ay�蕠跈�,jf"穐殢飦�戧鐉_璁(殠娸"濟�m���G珴�⒏?櫒璀�&x忈秈O曟瑉窔v豝�m��� �鹅�⒏?朓�

maintainer
#7 lore raw
Quoted 7 lines · On Tue, Dec 17, 2013 at 01:10:12PM +0000, [email protected] wrote:
Quoted 2 lines

In any case I'd be much happier with this patch if it implemented the enable and disable operations as well.

understand now. then maybe I should remove the PU check in cpufreq, although setting PU LDO if it is off before would bring unnessary power leak. I will add all these changes together with the dynamic PU LDO management feature, thanks for your time!

If you've implemented the enable support correctly then setting the voltage shouldn't enable the regulator.