Skip to contentSkip to conversation

Add power control for lm90

PATCH Superseded Wei Ni 6 participants 41 messages Aug 8, 2013 – Aug 9, 2013

Subsystems (4)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Wei Ni

author
#0 lore raw

v2 cover Add power control for lm90

The device lm90 can be controlled by the vdd rail.
Add function to power on/off the vdd.
Enable the nct1008 on Tegra114 Dalmore board, and set the vdd-regulator.

This series is v2, previous version patches:
[v1]: http://www.mail-archive.com/linux-tegra at vger.kernel.org/msg12034.html

Changes from v1:
1. if get regulator failed, we should continue to run probe function, not return fail.
2. call regulator_put() in error handler and remove function.
3. add LM90 DT binding document.

Wei Ni (3):
hwmon: (lm90) Add power control
ARM: dt: t114 dalmore: add dt entry for nct1008
Documentation: dt: hwmon: add OF document for lm90

 Documentation/devicetree/bindings/hwmon/lm90.txt |   20 +++++++++
 arch/arm/boot/dts/tegra114-dalmore.dts           |   10 ++++-
 drivers/hwmon/lm90.c                             |   49 ++++++++++++++++++++++
 3 files changed, 78 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/hwmon/lm90.txt
Signature · 1 line
1.7.9.5
author
#1 lore raw

PATCH v2 1/3 hwmon: (lm90) Add power control

The device lm90 can be controlled by the vdd rail. Adding the power control support to power on/off the vdd rail. And make sure that power is enabled before accessing the device.

---
 drivers/hwmon/lm90.c |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
drivers/hwmon/lm90.c +49 -0
index cdff742..306a348 100644
@@ -89,6 +89,7 @@
 #include <linux/err.h>
 #include <linux/mutex.h>
 #include <linux/sysfs.h>
+#include <linux/regulator/consumer.h>
 
 /*
  * Addresses to scan
@@ -302,6 +303,7 @@ static const struct lm90_params lm90_params[] = {
 struct lm90_data {
 	struct device *hwmon_dev;
 	struct mutex update_lock;
+	struct regulator *lm90_reg;
 	char valid; /* zero until following fields are valid */
 	unsigned long last_updated; /* in jiffies */
 	int kind;
@@ -1391,6 +1393,32 @@ static void lm90_init_client(struct i2c_client *client)
 		i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config);
 }
 
+static void lm90_power_control(struct i2c_client *client, bool is_enable)
+{
+	struct lm90_data *data = i2c_get_clientdata(client);
+	int ret;
+
+	if (!data->lm90_reg)
+		return;
+
+	mutex_lock(&data->update_lock);
+
+	if (is_enable)
+		ret = regulator_enable(data->lm90_reg);
+	else
+		ret = regulator_disable(data->lm90_reg);
+
+	if (ret < 0)
+		dev_err(&client->dev,
+			"Error in %s rail vdd, error %d\n",
+			(is_enable) ? "enabling" : "disabling", ret);
+	else
+		dev_info(&client->dev, "success in %s rail vdd\n",
+			 (is_enable) ? "enabling" : "disabling");
+
+	mutex_unlock(&data->update_lock);
+}
+
 static int lm90_probe(struct i2c_client *client,
 		      const struct i2c_device_id *id)
 {
@@ -1406,6 +1434,20 @@ static int lm90_probe(struct i2c_client *client,
 	i2c_set_clientdata(client, data);
 	mutex_init(&data->update_lock);
 
+	data->lm90_reg = regulator_get(&client->dev, "vdd");
+	if (IS_ERR_OR_NULL(data->lm90_reg)) {
+		if (PTR_ERR(data->lm90_reg) == -ENODEV)
+			dev_info(&client->dev,
+				 "No regulator found for vdd. Assuming vdd is always powered.");
+		else
+			dev_warn(&client->dev,
+				 "Error [%ld] in getting the regulator handle for vdd.\n",
+				 PTR_ERR(data->lm90_reg));
+		data->lm90_reg = NULL;
+	}
+
+	lm90_power_control(client, true);
+
 	/* Set the device type */
 	data->kind = id->driver_data;
 	if (data->kind == adm1032) {
@@ -1473,6 +1515,10 @@ exit_remove_files:
 	lm90_remove_files(client, data);
 exit_restore:
 	lm90_restore_conf(client, data);
+	lm90_power_control(client, false);
+	if (data->lm90_reg)
+		regulator_put(data->lm90_reg);
+
 	return err;
 }
 
@@ -1483,6 +1529,9 @@ static int lm90_remove(struct i2c_client *client)
 	hwmon_device_unregister(data->hwmon_dev);
 	lm90_remove_files(client, data);
 	lm90_restore_conf(client, data);
+	lm90_power_control(client, false);
+	if (data->lm90_reg)
+		regulator_put(data->lm90_reg);
 
 	return 0;
 }
Signature · 1 line
1.7.9.5
author
#30 lore raw

PATCH v2 2/3 ARM: dt: t114 dalmore: add dt entry for nct1008

In reply to Wei Ni

Enable thermal sensor nct1008 for t114 dalmore.

---
 arch/arm/boot/dts/tegra114-dalmore.dts |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
arch/arm/boot/dts/tegra114-dalmore.dts +9 -1
index b5a42f0..9d4d2b2 100644
@@ -738,6 +738,14 @@
 			realtek,ldo1-en-gpios =
 				<&gpio TEGRA_GPIO(V, 3) GPIO_ACTIVE_HIGH>;
 		};
+
+		nct1008 {
+			compatible = "onnn,nct1008";
+			reg = <0x4c>;
+			vdd-supply = <&palmas_ldo6_reg>;
+			interrupt-parent = <&gpio>;
+			interrupts = <TEGRA_GPIO(O, 4) IRQ_TYPE_LEVEL_LOW>;
+		};
 	};
 
 	i2c at 7000d000 {
@@ -945,7 +953,7 @@
 						regulator-max-microvolt = <1800000>;
 					};
 
-					ldo6 {
+					palmas_ldo6_reg: ldo6 {
 						regulator-name = "vdd-sensor-2v85";
 						regulator-min-microvolt = <2850000>;
 						regulator-max-microvolt = <2850000>;
Signature · 1 line
1.7.9.5
author
#37 lore raw

PATCH v2 3/3 Documentation: dt: hwmon: add OF document for lm90

In reply to Wei Ni

Add OF document for lm90 in Documentation/devicetree/.

---
 Documentation/devicetree/bindings/hwmon/lm90.txt |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/lm90.txt
Documentation/devicetree/bindings/hwmon/lm90.txt new file +20 -0
new file mode 100644
index 0000000..8024f11
@@ -0,0 +1,20 @@
+* LM90 series thermometer.
+
+Required node properties:
+- compatible: manufacture and chip name,
+              which are listed in the Documentation/hwmon/lm90
+- reg: I2C bus address of the device
+
+Optional properties:
+- vdd-supply: vdd regulator for the supply voltage. If this is not set,
+              assuming vdd is always powered.
+- interrupts: lm90 can support interrupt mode, you can set interrupt here.
+
+Example lm90 node:
+
+nct1008 {
+	compatible = "onnn,nct1008";
+	reg = <0x4c>;
+	vdd-supply = <&palmas_ldo6_reg>;
+	interrupt-parent = <&gpio>;
+	interrupts = <TEGRA_GPIO(O, 4) IRQ_TYPE_LEVEL_LOW>;
Signature · 1 line
1.7.9.5
#2 lore raw

Re: [PATCH v2 1/3] hwmon: (lm90) Add power control

In reply to Wei Ni
Quoted 10 lines

The device lm90 can be controlled by the vdd rail. Adding the power control support to power on/off the vdd rail. And make sure that power is enabled before accessing the device.

---
 drivers/hwmon/lm90.c |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
drivers/hwmon/lm90.c +0 -0

[...]

Quoted 12 lines
drivers/hwmon/lm90.c +12 -0
+static void lm90_power_control(struct i2c_client *client, bool is_enable)
+{
+	struct lm90_data *data = i2c_get_clientdata(client);
+	int ret;
+
+	if (!data->lm90_reg)
+		return;
+
+	mutex_lock(&data->update_lock);
+
+	if (is_enable)
+		ret = regulator_enable(data->lm90_reg);

drivers/hwmon/lm90.c static void lm90_init_client(struct i2c_client *client) · line 1417

Quoted 10 lines
drivers/hwmon/lm90.c +10 -0
+	else
+		ret = regulator_disable(data->lm90_reg);
+
+	if (ret < 0)
+		dev_err(&client->dev,
+			"Error in %s rail vdd, error %d\n",
+			(is_enable) ? "enabling" : "disabling", ret);
+	else
+		dev_info(&client->dev, "success in %s rail vdd\n",
+			 (is_enable) ? "enabling" : "disabling");

dev_dbg() ?

drivers/hwmon/lm90.c static int lm90_probe(struct i2c_client *client, · line 1438

Quoted 13 lines
drivers/hwmon/lm90.c +6 -0
+
+	mutex_unlock(&data->update_lock);
+}
+
 static int lm90_probe(struct i2c_client *client,
 		      const struct i2c_device_id *id)
 {
@@ -1406,6 +1434,20 @@ static int lm90_probe(struct i2c_client *client,
 	i2c_set_clientdata(client, data);
 	mutex_init(&data->update_lock);
 
+	data->lm90_reg = regulator_get(&client->dev, "vdd");
+	if (IS_ERR_OR_NULL(data->lm90_reg)) {

What about deferred probe?
if (PTR_ERR(data->lm90_reg) == -EPROBE_DEFER)
return -EPROBE_DEFER;

drivers/hwmon/lm90.c static int lm90_probe(struct i2c_client *client, · line 1441

Quoted 3 lines
drivers/hwmon/lm90.c +3 -0
+		if (PTR_ERR(data->lm90_reg) == -ENODEV)
+			dev_info(&client->dev,
+				 "No regulator found for vdd. Assuming vdd is always powered.");

On my opinion it is unnecessary message.

drivers/hwmon/lm90.c static int lm90_probe(struct i2c_client *client, · line 1445

Quoted 4 lines
drivers/hwmon/lm90.c +4 -0
+		else
+			dev_warn(&client->dev,
+				 "Error [%ld] in getting the regulator handle for vdd.\n",
+				 PTR_ERR(data->lm90_reg));

Ditto.

drivers/hwmon/lm90.c static int lm90_probe(struct i2c_client *client, · line 1446

Quoted 1 line
drivers/hwmon/lm90.c +1 -0
+		data->lm90_reg = NULL;

You can just use !IS_ERR(data->lm90_reg) macro in the future, rather than set this to NULL.

[...]

---

maintainer
#4 lore raw

Re: [PATCH v2 1/3] hwmon: (lm90) Add power control

In reply to Wei Ni
Quoted 33 lines · Wei Ni

The device lm90 can be controlled by the vdd rail. Adding the power control support to power on/off the vdd rail. And make sure that power is enabled before accessing the device.

---
  drivers/hwmon/lm90.c |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 49 insertions(+)
drivers/hwmon/lm90.c +2 -0
index cdff742..306a348 100644
@@ -89,6 +89,7 @@
  #include <linux/err.h>
  #include <linux/mutex.h>
  #include <linux/sysfs.h>
+#include <linux/regulator/consumer.h>
 
  /*
   * Addresses to scan
@@ -302,6 +303,7 @@ static const struct lm90_params lm90_params[] = {
  struct lm90_data {
  	struct device *hwmon_dev;
  	struct mutex update_lock;
+	struct regulator *lm90_reg;
  	char valid; /* zero until following fields are valid */
  	unsigned long last_updated; /* in jiffies */
  	int kind;
@@ -1391,6 +1393,32 @@ static void lm90_init_client(struct i2c_client *client)
  		i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config);
  }
 

drivers/hwmon/lm90.c static void lm90_init_client(struct i2c_client *client) · line 1405

Quoted 10 lines
drivers/hwmon/lm90.c +10 -0
+static void lm90_power_control(struct i2c_client *client, bool is_enable)
+{
+	struct lm90_data *data = i2c_get_clientdata(client);
+	int ret;
+
+	if (!data->lm90_reg)
+		return;
+
+	mutex_lock(&data->update_lock);
+

This is only called during probe and remove, so the mutex is unnecessary.

drivers/hwmon/lm90.c static void lm90_init_client(struct i2c_client *client) · line 1418

Quoted 13 lines
drivers/hwmon/lm90.c +13 -0
+	if (is_enable)
+		ret = regulator_enable(data->lm90_reg);
+	else
+		ret = regulator_disable(data->lm90_reg);
+
+	if (ret < 0)
+		dev_err(&client->dev,
+			"Error in %s rail vdd, error %d\n",
+			(is_enable) ? "enabling" : "disabling", ret);
+	else
+		dev_info(&client->dev, "success in %s rail vdd\n",
+			 (is_enable) ? "enabling" : "disabling");
+

which reduces the function to (pretty much unnecessary) messages and an if statement which you only need because you have the function.

You should just call regulator_enable in probe and regulator_disable in remove.

Guenter

drivers/hwmon/lm90.c static int lm90_probe(struct i2c_client *client, · line 1437

Quoted 11 lines
drivers/hwmon/lm90.c +4 -0
+	mutex_unlock(&data->update_lock);
+}
+
  static int lm90_probe(struct i2c_client *client,
  		      const struct i2c_device_id *id)
  {
@@ -1406,6 +1434,20 @@ static int lm90_probe(struct i2c_client *client,
  	i2c_set_clientdata(client, data);
  	mutex_init(&data->update_lock);
 
+	data->lm90_reg = regulator_get(&client->dev, "vdd");

You should use devm_regulator_get(). Then you also don't need the call to regulator_put().

drivers/hwmon/lm90.c static int lm90_probe(struct i2c_client *client, · line 1438

Quoted 1 line
drivers/hwmon/lm90.c +1 -0
+	if (IS_ERR_OR_NULL(data->lm90_reg)) {

The function never returns NULL except if the regulator subsystem is not configured, so IS_ERR() is more appropriate.

If the regulator subsystem is not configured, you especially don't need or want to pollute the log with an error message.

drivers/hwmon/lm90.c static int lm90_probe(struct i2c_client *client, · line 1445

Quoted 7 lines
drivers/hwmon/lm90.c +7 -0
+		if (PTR_ERR(data->lm90_reg) == -ENODEV)
+			dev_info(&client->dev,
+				 "No regulator found for vdd. Assuming vdd is always powered.");
+		else
+			dev_warn(&client->dev,
+				 "Error [%ld] in getting the regulator handle for vdd.\n",
+				 PTR_ERR(data->lm90_reg));

I consider the messages unnecessary and confusing. You are polluting the log of pretty much every PC user who has one of the supported chips in the system, and of everyone else not using regulators for this chip.

drivers/hwmon/lm90.c static int lm90_probe(struct i2c_client *client, · line 1446

Quoted 1 line
drivers/hwmon/lm90.c +1 -0
+		data->lm90_reg = NULL;

As pointed out, this is unnecessary, and you should handle -EPROBE_DEFER correctly.

Quoted 29 lines
drivers/hwmon/lm90.c +11 -0
+	}
+
+	lm90_power_control(client, true);
+
  	/* Set the device type */
  	data->kind = id->driver_data;
  	if (data->kind == adm1032) {
@@ -1473,6 +1515,10 @@ exit_remove_files:
  	lm90_remove_files(client, data);
  exit_restore:
  	lm90_restore_conf(client, data);
+	lm90_power_control(client, false);
+	if (data->lm90_reg)
+		regulator_put(data->lm90_reg);
+
  	return err;
  }
 
@@ -1483,6 +1529,9 @@ static int lm90_remove(struct i2c_client *client)
  	hwmon_device_unregister(data->hwmon_dev);
  	lm90_remove_files(client, data);
  	lm90_restore_conf(client, data);
+	lm90_power_control(client, false);
+	if (data->lm90_reg)
+		regulator_put(data->lm90_reg);
 
  	return 0;
  }
author
#3 lore raw

Re: [PATCH v2 1/3] hwmon: (lm90) Add power control

In reply to Alexander Shiyan
Quoted 27 lines · Alexander Shiyan
Quoted 10 lines

The device lm90 can be controlled by the vdd rail. Adding the power control support to power on/off the vdd rail. And make sure that power is enabled before accessing the device.

---
 drivers/hwmon/lm90.c |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
drivers/hwmon/lm90.c +0 -0

[...]

Quoted 16 lines
drivers/hwmon/lm90.c +16 -0
+static void lm90_power_control(struct i2c_client *client, bool is_enable)
+{
+	struct lm90_data *data = i2c_get_clientdata(client);
+	int ret;
+
+	if (!data->lm90_reg)
+		return;
+
+	mutex_lock(&data->update_lock);
+
+	if (is_enable)
+		ret = regulator_enable(data->lm90_reg);
+	else
+		ret = regulator_disable(data->lm90_reg);
+
+	if (ret < 0)
Quoted 8 lines

drivers/hwmon/lm90.c static void lm90_init_client(struct i2c_client *client) · line 1417

Quoted 6 lines
drivers/hwmon/lm90.c +6 -0
+		dev_err(&client->dev,
+			"Error in %s rail vdd, error %d\n",
+			(is_enable) ? "enabling" : "disabling", ret);
+	else
+		dev_info(&client->dev, "success in %s rail vdd\n",
+			 (is_enable) ? "enabling" : "disabling");

dev_dbg() ?

As Guenter said, I will remove these messages, and remove this function, the code will be more clean.

Quoted 12 lines
Quoted 12 lines
drivers/hwmon/lm90.c +4 -0
+
+	mutex_unlock(&data->update_lock);
+}
+
 static int lm90_probe(struct i2c_client *client,
 		      const struct i2c_device_id *id)
 {
@@ -1406,6 +1434,20 @@ static int lm90_probe(struct i2c_client *client,
 	i2c_set_clientdata(client, data);
 	mutex_init(&data->update_lock);
 
Quoted 6 lines

drivers/hwmon/lm90.c static int lm90_probe(struct i2c_client *client, · line 1438

Quoted 2 lines
drivers/hwmon/lm90.c +2 -0
+	data->lm90_reg = regulator_get(&client->dev, "vdd");
+	if (IS_ERR_OR_NULL(data->lm90_reg)) {

What about deferred probe?
if (PTR_ERR(data->lm90_reg) == -EPROBE_DEFER)
return -EPROBE_DEFER;

Oh, yes, I should add it.

Quoted 7 lines

drivers/hwmon/lm90.c static int lm90_probe(struct i2c_client *client, · line 1441

Quoted 4 lines
drivers/hwmon/lm90.c +3 -0
+		if (PTR_ERR(data->lm90_reg) == -ENODEV)
+			dev_info(&client->dev,
+				 "No regulator found for vdd. Assuming vdd is always powered.");

On my opinion it is unnecessary message.

Quoted 6 lines

drivers/hwmon/lm90.c static int lm90_probe(struct i2c_client *client, · line 1445

Quoted 4 lines
drivers/hwmon/lm90.c +4 -0
+		else
+			dev_warn(&client->dev,
+				 "Error [%ld] in getting the regulator handle for vdd.\n",
+				 PTR_ERR(data->lm90_reg));

Ditto.

I will remove these log messages.

Quoted 5 lines

drivers/hwmon/lm90.c static int lm90_probe(struct i2c_client *client, · line 1446

Quoted 2 lines
drivers/hwmon/lm90.c +1 -0
+		data->lm90_reg = NULL;

You can just use !IS_ERR(data->lm90_reg) macro in the future, rather than set this to NULL.

Yes, it's better, I will do it.

Quoted 5 lines

[...]

---

author
#5 lore raw

Re: [PATCH v2 1/3] hwmon: (lm90) Add power control

In reply to Guenter Roeck
Quoted 34 lines · Guenter Roeck
Quoted 33 lines · Wei Ni

The device lm90 can be controlled by the vdd rail. Adding the power control support to power on/off the vdd rail. And make sure that power is enabled before accessing the device.

---
  drivers/hwmon/lm90.c |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 49 insertions(+)
drivers/hwmon/lm90.c +2 -0
index cdff742..306a348 100644
@@ -89,6 +89,7 @@
  #include <linux/err.h>
  #include <linux/mutex.h>
  #include <linux/sysfs.h>
+#include <linux/regulator/consumer.h>
 
  /*
   * Addresses to scan
@@ -302,6 +303,7 @@ static const struct lm90_params lm90_params[] = {
  struct lm90_data {
  	struct device *hwmon_dev;
  	struct mutex update_lock;
+	struct regulator *lm90_reg;
  	char valid; /* zero until following fields are valid */
  	unsigned long last_updated; /* in jiffies */
  	int kind;
@@ -1391,6 +1393,32 @@ static void lm90_init_client(struct i2c_client *client)
  		i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config);
  }
 
Quoted 12 lines

drivers/hwmon/lm90.c static void lm90_init_client(struct i2c_client *client) · line 1405

Quoted 10 lines
drivers/hwmon/lm90.c +10 -0
+static void lm90_power_control(struct i2c_client *client, bool is_enable)
+{
+	struct lm90_data *data = i2c_get_clientdata(client);
+	int ret;
+
+	if (!data->lm90_reg)
+		return;
+
+	mutex_lock(&data->update_lock);
+

This is only called during probe and remove, so the mutex is unnecessary.

I considered that we may call this function in suspend/resume routine, so I add this mutex.
But as you said, currently we doesn't have these routine yet, the mutex is unnecessary, so I will remove it.

Quoted 17 lines
Quoted 4 lines
drivers/hwmon/lm90.c +3 -0
+	if (is_enable)
+		ret = regulator_enable(data->lm90_reg);
+	else

drivers/hwmon/lm90.c static void lm90_init_client(struct i2c_client *client) · line 1418

Quoted 10 lines
drivers/hwmon/lm90.c +10 -0
+		ret = regulator_disable(data->lm90_reg);
+
+	if (ret < 0)
+		dev_err(&client->dev,
+			"Error in %s rail vdd, error %d\n",
+			(is_enable) ? "enabling" : "disabling", ret);
+	else
+		dev_info(&client->dev, "success in %s rail vdd\n",
+			 (is_enable) ? "enabling" : "disabling");
+

which reduces the function to (pretty much unnecessary) messages and an if statement which you only need because you have the function.

Quoted 1 line

You should just call regulator_enable in probe and regulator_disable in remove.

Ok, I will remove these messages and this function.

Quoted 13 lines

Guenter

Quoted 10 lines
drivers/hwmon/lm90.c +3 -0
+	mutex_unlock(&data->update_lock);
+}
+
  static int lm90_probe(struct i2c_client *client,
  		      const struct i2c_device_id *id)
  {
@@ -1406,6 +1434,20 @@ static int lm90_probe(struct i2c_client *client,
  	i2c_set_clientdata(client, data);
  	mutex_init(&data->update_lock);
 
Quoted 3 lines

drivers/hwmon/lm90.c static int lm90_probe(struct i2c_client *client, · line 1437

Quoted 1 line
drivers/hwmon/lm90.c +1 -0
+	data->lm90_reg = regulator_get(&client->dev, "vdd");

You should use devm_regulator_get(). Then you also don't need the call to regulator_put().

Oh, yes, you are right, I will do it.

Quoted 9 lines

drivers/hwmon/lm90.c static int lm90_probe(struct i2c_client *client, · line 1438

Quoted 2 lines
drivers/hwmon/lm90.c +1 -0
+	if (IS_ERR_OR_NULL(data->lm90_reg)) {

The function never returns NULL except if the regulator subsystem is not configured, so IS_ERR() is more appropriate.

If the regulator subsystem is not configured, you especially don't need or want to pollute the log with an error message.

Quoted 11 lines

drivers/hwmon/lm90.c static int lm90_probe(struct i2c_client *client, · line 1445

Quoted 7 lines
drivers/hwmon/lm90.c +7 -0
+		if (PTR_ERR(data->lm90_reg) == -ENODEV)
+			dev_info(&client->dev,
+				 "No regulator found for vdd. Assuming vdd is always powered.");
+		else
+			dev_warn(&client->dev,
+				 "Error [%ld] in getting the regulator handle for vdd.\n",
+				 PTR_ERR(data->lm90_reg));

I consider the messages unnecessary and confusing. You are polluting the log of pretty much every PC user who has one of the supported chips in the system, and of everyone else not using regulators for this chip.

Ok, I will remove these codes.
So I will write something like:

if (!IS_ERR(data->lm90_reg)) {
    ret = regulator_enable(data->lm90_reg);
    if (ret < 0) {
        dev_err();
        return ret;
    }
} else {
    if (PTR_ERR(data->lm90_reg) == -EPROBE_DEFER)
        return -EPRPBE_DEFER;

        data->lm90_reg = !!IS_ERR(data->lm90_reg);
}
Quoted 4 lines

drivers/hwmon/lm90.c static int lm90_probe(struct i2c_client *client, · line 1446

Quoted 2 lines
drivers/hwmon/lm90.c +1 -0
+		data->lm90_reg = NULL;

As pointed out, this is unnecessary, and you should handle -EPROBE_DEFER correctly.

I think get_regulator() will return error values, not only -EPROBE_DEFER, so we should set data->lm90_reg to NULL to handle other error values.

Quoted 31 lines
Quoted 30 lines
drivers/hwmon/lm90.c +11 -0
+	}
+
+	lm90_power_control(client, true);
+
  	/* Set the device type */
  	data->kind = id->driver_data;
  	if (data->kind == adm1032) {
@@ -1473,6 +1515,10 @@ exit_remove_files:
  	lm90_remove_files(client, data);
  exit_restore:
  	lm90_restore_conf(client, data);
+	lm90_power_control(client, false);
+	if (data->lm90_reg)
+		regulator_put(data->lm90_reg);
+
  	return err;
  }
 
@@ -1483,6 +1529,9 @@ static int lm90_remove(struct i2c_client *client)
  	hwmon_device_unregister(data->hwmon_dev);
  	lm90_remove_files(client, data);
  	lm90_restore_conf(client, data);
+	lm90_power_control(client, false);
+	if (data->lm90_reg)
+		regulator_put(data->lm90_reg);
 
  	return 0;
  }
#6 lore raw

Re: [PATCH v2 1/3] hwmon: (lm90) Add power control

Quoted 9 lines · Guenter Roeck
Quoted 8 lines · Wei Ni
Quoted 7 lines

The device lm90 can be controlled by the vdd rail. Adding the power control support to power on/off the vdd rail. And make sure that power is enabled before accessing the device.

---
  drivers/hwmon/lm90.c |   49 +++++++++++++++++++++++++++++++++++++++++++++++++

[...]

Quoted 6 lines
Quoted 3 lines

I consider the messages unnecessary and confusing. You are polluting the log of pretty much every PC user who has one of the supported chips in the system, and of everyone else not using regulators for this chip.

Ok, I will remove these codes.
So I will write something like:

Quoted 11 lines
if (!IS_ERR(data->lm90_reg)) {
    ret = regulator_enable(data->lm90_reg);
    if (ret < 0) {
        dev_err();
        return ret;
    }
} else {
    if (PTR_ERR(data->lm90_reg) == -EPROBE_DEFER)
        return -EPRPBE_DEFER;

        data->lm90_reg = !!IS_ERR(data->lm90_reg);

No. You do not need this line.

Just use in remove():
if (!IS_ERR(data->lm90_reg))
regulator_disable(data->lm90_reg);

---

author
#7 lore raw

Re: [PATCH v2 1/3] hwmon: (lm90) Add power control

Quoted 26 lines · Alexander Shiyan
Quoted 9 lines · Guenter Roeck
Quoted 8 lines · Wei Ni
Quoted 7 lines

The device lm90 can be controlled by the vdd rail. Adding the power control support to power on/off the vdd rail. And make sure that power is enabled before accessing the device.

---
  drivers/hwmon/lm90.c |   49 +++++++++++++++++++++++++++++++++++++++++++++++++

[...]

Quoted 16 lines
Quoted 3 lines

I consider the messages unnecessary and confusing. You are polluting the log of pretty much every PC user who has one of the supported chips in the system, and of everyone else not using regulators for this chip.

Ok, I will remove these codes.
So I will write something like:

if (!IS_ERR(data->lm90_reg)) {
    ret = regulator_enable(data->lm90_reg);
    if (ret < 0) {
        dev_err();
        return ret;
    }
} else {
    if (PTR_ERR(data->lm90_reg) == -EPROBE_DEFER)
        return -EPRPBE_DEFER;
Quoted 7 lines
Quoted 1 line
        data->lm90_reg = !!IS_ERR(data->lm90_reg);

No. You do not need this line.

Just use in remove():
if (!IS_ERR(data->lm90_reg))
regulator_disable(data->lm90_reg);

Oh, I see, thank you very much.

Quoted 3 lines

---

author
#8 lore raw

Re: [PATCH v2 1/3] hwmon: (lm90) Add power control

In reply to Alexander Shiyan
Quoted 26 lines · Alexander Shiyan
Quoted 9 lines · Guenter Roeck
Quoted 8 lines · Wei Ni
Quoted 7 lines

The device lm90 can be controlled by the vdd rail. Adding the power control support to power on/off the vdd rail. And make sure that power is enabled before accessing the device.

---
  drivers/hwmon/lm90.c |   49 +++++++++++++++++++++++++++++++++++++++++++++++++

[...]

Quoted 16 lines
Quoted 3 lines

I consider the messages unnecessary and confusing. You are polluting the log of pretty much every PC user who has one of the supported chips in the system, and of everyone else not using regulators for this chip.

Ok, I will remove these codes.
So I will write something like:

if (!IS_ERR(data->lm90_reg)) {
    ret = regulator_enable(data->lm90_reg);
    if (ret < 0) {
        dev_err();
        return ret;
    }
} else {
    if (PTR_ERR(data->lm90_reg) == -EPROBE_DEFER)
        return -EPRPBE_DEFER;
Quoted 1 line
Quoted 1 line
        data->lm90_reg = !!IS_ERR(data->lm90_reg);

BTW, since it may return EPROBE_DEFER, these codes should be put in the beginning of the probe() function, should before allocate lm90_data.

Quoted 9 lines

No. You do not need this line.

Just use in remove():
if (!IS_ERR(data->lm90_reg))
regulator_disable(data->lm90_reg);

---

#16 lore raw

Re: [PATCH v2 1/3] hwmon: (lm90) Add power control

In reply to Wei Ni
Quoted 6 lines · Wei Ni
drivers/hwmon/lm90.c +6 -0
+	mutex_lock(&data->update_lock);
+
+	if (is_enable)
+		ret = regulator_enable(data->lm90_reg);
+	else
+		ret = regulator_disable(data->lm90_reg);

drivers/hwmon/lm90.c static void lm90_init_client(struct i2c_client *client) · line 1419

Quoted 10 lines
drivers/hwmon/lm90.c +10 -0
+
+	if (ret < 0)
+		dev_err(&client->dev,
+			"Error in %s rail vdd, error %d\n",
+			(is_enable) ? "enabling" : "disabling", ret);
+	else
+		dev_info(&client->dev, "success in %s rail vdd\n",
+			 (is_enable) ? "enabling" : "disabling");
+
+	mutex_unlock(&data->update_lock);

Two things here. One is that it's not clear what this lokc is protecting since the only thing in the locked region is the regulator operation and that is thread safe. The other thing is that I'm not seeing anthing that ensures that enables and disables are matched - regulators are reference counted so two enables need two disables.

drivers/hwmon/lm90.c static int lm90_probe(struct i2c_client *client, · line 1438

Quoted 2 lines
drivers/hwmon/lm90.c +2 -0
+	data->lm90_reg = regulator_get(&client->dev, "vdd");
+	if (IS_ERR_OR_NULL(data->lm90_reg)) {

NULL is a valid regulator, use IS_ERR().

drivers/hwmon/lm90.c static int lm90_probe(struct i2c_client *client, · line 1445

Quoted 7 lines
drivers/hwmon/lm90.c +7 -0
+		if (PTR_ERR(data->lm90_reg) == -ENODEV)
+			dev_info(&client->dev,
+				 "No regulator found for vdd. Assuming vdd is always powered.");
+		else
+			dev_warn(&client->dev,
+				 "Error [%ld] in getting the regulator handle for vdd.\n",
+				 PTR_ERR(data->lm90_reg));

You shouldn't just be ignoring errors here, though there are deployment difficulties with making sure a stub regulator is provided. These should be getting easier after the next merge window, the stubs will be being tweaked slightly to have an "assume it's there" option even when regulators are used. Especially in cases with device tree you should be paying attention to -EPROBE_DEFER, that will accurately reflect if a regulator is present but not loaded yet.

That said if you *are* going to do this you should request the
regulator using devm_regulator_get_optional(), this is intended to
support things that don't need regulators (though that's not the case
here).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130808/243e1ee6/attachment.sig>

maintainer
#9 lore raw

Re: [PATCH v2 1/3] hwmon: (lm90) Add power control

In reply to Wei Ni
Quoted 48 lines · Wei Ni
Quoted 34 lines · Guenter Roeck
Quoted 33 lines · Wei Ni

The device lm90 can be controlled by the vdd rail. Adding the power control support to power on/off the vdd rail. And make sure that power is enabled before accessing the device.

---
   drivers/hwmon/lm90.c |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
   1 file changed, 49 insertions(+)
drivers/hwmon/lm90.c +2 -0
index cdff742..306a348 100644
@@ -89,6 +89,7 @@
   #include <linux/err.h>
   #include <linux/mutex.h>
   #include <linux/sysfs.h>
+#include <linux/regulator/consumer.h>
 
   /*
    * Addresses to scan
@@ -302,6 +303,7 @@ static const struct lm90_params lm90_params[] = {
   struct lm90_data {
   	struct device *hwmon_dev;
   	struct mutex update_lock;
+	struct regulator *lm90_reg;
   	char valid; /* zero until following fields are valid */
   	unsigned long last_updated; /* in jiffies */
   	int kind;
@@ -1391,6 +1393,32 @@ static void lm90_init_client(struct i2c_client *client)
   		i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config);
   }
 
Quoted 12 lines

drivers/hwmon/lm90.c static void lm90_init_client(struct i2c_client *client) · line 1405

Quoted 10 lines
drivers/hwmon/lm90.c +10 -0
+static void lm90_power_control(struct i2c_client *client, bool is_enable)
+{
+	struct lm90_data *data = i2c_get_clientdata(client);
+	int ret;
+
+	if (!data->lm90_reg)
+		return;
+
+	mutex_lock(&data->update_lock);
+

This is only called during probe and remove, so the mutex is unnecessary.

Quoted 5 lines

I considered that we may call this function in suspend/resume routine, so I add this mutex.
But as you said, currently we doesn't have these routine yet, the mutex is unnecessary, so I will remove it.

In that case, you can call
mutex_lock()
regulator_enable() / regulator_disable()
mutex_unlock()

directly in those functions. Again no need for the additional function.

Quoted 63 lines
Quoted 17 lines
Quoted 4 lines
drivers/hwmon/lm90.c +3 -0
+	if (is_enable)
+		ret = regulator_enable(data->lm90_reg);
+	else

drivers/hwmon/lm90.c static void lm90_init_client(struct i2c_client *client) · line 1418

Quoted 10 lines
drivers/hwmon/lm90.c +10 -0
+		ret = regulator_disable(data->lm90_reg);
+
+	if (ret < 0)
+		dev_err(&client->dev,
+			"Error in %s rail vdd, error %d\n",
+			(is_enable) ? "enabling" : "disabling", ret);
+	else
+		dev_info(&client->dev, "success in %s rail vdd\n",
+			 (is_enable) ? "enabling" : "disabling");
+

which reduces the function to (pretty much unnecessary) messages and an if statement which you only need because you have the function.

Quoted 1 line

You should just call regulator_enable in probe and regulator_disable in remove.

Ok, I will remove these messages and this function.

Quoted 13 lines

Guenter

Quoted 10 lines
drivers/hwmon/lm90.c +3 -0
+	mutex_unlock(&data->update_lock);
+}
+
   static int lm90_probe(struct i2c_client *client,
   		      const struct i2c_device_id *id)
   {
@@ -1406,6 +1434,20 @@ static int lm90_probe(struct i2c_client *client,
   	i2c_set_clientdata(client, data);
   	mutex_init(&data->update_lock);
 
Quoted 3 lines

drivers/hwmon/lm90.c static int lm90_probe(struct i2c_client *client, · line 1437

Quoted 1 line
drivers/hwmon/lm90.c +1 -0
+	data->lm90_reg = regulator_get(&client->dev, "vdd");

You should use devm_regulator_get(). Then you also don't need the call to regulator_put().

Oh, yes, you are right, I will do it.

Quoted 9 lines

drivers/hwmon/lm90.c static int lm90_probe(struct i2c_client *client, · line 1438

Quoted 2 lines
drivers/hwmon/lm90.c +1 -0
+	if (IS_ERR_OR_NULL(data->lm90_reg)) {

The function never returns NULL except if the regulator subsystem is not configured, so IS_ERR() is more appropriate.

If the regulator subsystem is not configured, you especially don't need or want to pollute the log with an error message.

Quoted 11 lines

drivers/hwmon/lm90.c static int lm90_probe(struct i2c_client *client, · line 1445

Quoted 7 lines
drivers/hwmon/lm90.c +7 -0
+		if (PTR_ERR(data->lm90_reg) == -ENODEV)
+			dev_info(&client->dev,
+				 "No regulator found for vdd. Assuming vdd is always powered.");
+		else
+			dev_warn(&client->dev,
+				 "Error [%ld] in getting the regulator handle for vdd.\n",
+				 PTR_ERR(data->lm90_reg));

I consider the messages unnecessary and confusing. You are polluting the log of pretty much every PC user who has one of the supported chips in the system, and of everyone else not using regulators for this chip.

Ok, I will remove these codes.
So I will write something like:

Quoted 7 lines
if (!IS_ERR(data->lm90_reg)) {
     ret = regulator_enable(data->lm90_reg);
     if (ret < 0) {
         dev_err();
         return ret;
     }
} else {

Handle the error in the if case.

Quoted 4 lines
     if (PTR_ERR(data->lm90_reg) == -EPROBE_DEFER)
         return -EPRPBE_DEFER;

         data->lm90_reg = !!IS_ERR(data->lm90_reg);

You know that IS_ERR is true here. Unless I am missing something, this would assign "1" to lm90_reg.

Quoted 11 lines

}

Quoted 4 lines

drivers/hwmon/lm90.c static int lm90_probe(struct i2c_client *client, · line 1446

Quoted 2 lines
drivers/hwmon/lm90.c +1 -0
+		data->lm90_reg = NULL;

As pointed out, this is unnecessary, and you should handle -EPROBE_DEFER correctly.

I think get_regulator() will return error values, not only -EPROBE_DEFER, so we should set data->lm90_reg to NULL to handle other error values.

Matter of opinion if you want to check for IS_ERR or NULL later on.

Quoted 34 lines
Quoted 31 lines
Quoted 30 lines
drivers/hwmon/lm90.c +11 -0
+	}
+
+	lm90_power_control(client, true);
+
   	/* Set the device type */
   	data->kind = id->driver_data;
   	if (data->kind == adm1032) {
@@ -1473,6 +1515,10 @@ exit_remove_files:
   	lm90_remove_files(client, data);
   exit_restore:
   	lm90_restore_conf(client, data);
+	lm90_power_control(client, false);
+	if (data->lm90_reg)
+		regulator_put(data->lm90_reg);
+
   	return err;
   }
 
@@ -1483,6 +1529,9 @@ static int lm90_remove(struct i2c_client *client)
   	hwmon_device_unregister(data->hwmon_dev);
   	lm90_remove_files(client, data);
   	lm90_restore_conf(client, data);
+	lm90_power_control(client, false);
+	if (data->lm90_reg)
+		regulator_put(data->lm90_reg);
 
   	return 0;
   }
maintainer
#17 lore raw

Re: [PATCH v2 1/3] hwmon: (lm90) Add power control

In reply to Mark Brown
Quoted 46 lines · Mark Brown
Quoted 6 lines · Wei Ni
drivers/hwmon/lm90.c +6 -0
+	mutex_lock(&data->update_lock);
+
+	if (is_enable)
+		ret = regulator_enable(data->lm90_reg);
+	else
+		ret = regulator_disable(data->lm90_reg);

drivers/hwmon/lm90.c static void lm90_init_client(struct i2c_client *client) · line 1419

Quoted 10 lines
drivers/hwmon/lm90.c +10 -0
+
+	if (ret < 0)
+		dev_err(&client->dev,
+			"Error in %s rail vdd, error %d\n",
+			(is_enable) ? "enabling" : "disabling", ret);
+	else
+		dev_info(&client->dev, "success in %s rail vdd\n",
+			 (is_enable) ? "enabling" : "disabling");
+
+	mutex_unlock(&data->update_lock);

Two things here. One is that it's not clear what this lokc is protecting since the only thing in the locked region is the regulator operation and that is thread safe. The other thing is that I'm not seeing anthing that ensures that enables and disables are matched - regulators are reference counted so two enables need two disables.

drivers/hwmon/lm90.c static int lm90_probe(struct i2c_client *client, · line 1438

Quoted 2 lines
drivers/hwmon/lm90.c +2 -0
+	data->lm90_reg = regulator_get(&client->dev, "vdd");
+	if (IS_ERR_OR_NULL(data->lm90_reg)) {

NULL is a valid regulator, use IS_ERR().

drivers/hwmon/lm90.c static int lm90_probe(struct i2c_client *client, · line 1445

Quoted 7 lines
drivers/hwmon/lm90.c +7 -0
+		if (PTR_ERR(data->lm90_reg) == -ENODEV)
+			dev_info(&client->dev,
+				 "No regulator found for vdd. Assuming vdd is always powered.");
+		else
+			dev_warn(&client->dev,
+				 "Error [%ld] in getting the regulator handle for vdd.\n",
+				 PTR_ERR(data->lm90_reg));

You shouldn't just be ignoring errors here, though there are deployment difficulties with making sure a stub regulator is provided. These should be getting easier after the next merge window, the stubs will be being tweaked slightly to have an "assume it's there" option even when regulators are used. Especially in cases with device tree you should be paying attention to -EPROBE_DEFER, that will accurately reflect if a regulator is present but not loaded yet.

Quoted 5 lines

That said if you *are* going to do this you should request the regulator using devm_regulator_get_optional(), this is intended to support things that don't need regulators (though that's not the case here).

The lm90 driver works perfectly fine without regulator.

Guenter

#18 lore raw

Re: [PATCH v2 1/3] hwmon: (lm90) Add power control

Quoted 8 lines · Guenter Roeck
Quoted 4 lines · Mark Brown

That said if you *are* going to do this you should request the regulator using devm_regulator_get_optional(), this is intended to support things that don't need regulators (though that's not the case here).

The lm90 driver works perfectly fine without regulator.

I'd be most surprised if the device worked without power, if the driver fails to get and enable a regulator for it then that's not great (especially if it does so silently).

Note that the regulator API is written to stub itself out if not
enabled, the code should be able to assume that it's there.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130808/9155fabb/attachment.sig>

maintainer
#19 lore raw

Re: [PATCH v2 1/3] hwmon: (lm90) Add power control

Quoted 8 lines · Mark Brown
Quoted 6 lines · Guenter Roeck
Quoted 4 lines · Mark Brown

That said if you *are* going to do this you should request the regulator using devm_regulator_get_optional(), this is intended to support things that don't need regulators (though that's not the case here).

Quoted 6 lines
Quoted 1 line

The lm90 driver works perfectly fine without regulator.

I'd be most surprised if the device worked without power, if the driver fails to get and enable a regulator for it then that's not great (especially if it does so silently).

Correct, but it appears that the driver magically worked for a long time without it.

Is it guaranteed that the driver keeps working for all cases where regulator support is enabled in the kernel, and where it used to work so far without mandating the existence of this specific regulator ? My main concern is having to deal with complaints that the driver stopped working for no good reason.

In this context, is it common practice to name such regulators "vdd" or similar ? What if there are multiple LM90 or compatible chips in a system, connected to different power rails ? Who determines if the regulator is supposed to be named "vdd" or "vcc" or anything else, and to which power rails it is actually connected ? How can and does one guarantee that "vdd" is the correct regulator to use for all systems ? What if some other driver requests "vdd", but the chip it supports happens to be connected to a different power rail ?

Sorry for my ignorance in that matter. I did browse through Documentation/power, but did not find a clear answer.

Quoted 3 lines

Note that the regulator API is written to stub itself out if not enabled, the code should be able to assume that it's there.

I am aware of that; this is why the driver should not dump an error message if the function returns NULL and bail out, as it did originally.

Guenter

#20 lore raw

Re: [PATCH v2 1/3] hwmon: (lm90) Add power control

Quoted 8 lines · Guenter Roeck
Quoted 3 lines · Mark Brown

I'd be most surprised if the device worked without power, if the driver fails to get and enable a regulator for it then that's not great (especially if it does so silently).

Correct, but it appears that the driver magically worked for a long time without it.

Sure, it'll work in systems that have always on regulators.

Quoted 5 lines

Is it guaranteed that the driver keeps working for all cases where regulator support is enabled in the kernel, and where it used to work so far without mandating the existence of this specific regulator ? My main concern is having to deal with complaints that the driver stopped working for no good reason.

Sure, that's the transition issues I mentioned - the regulator API does have stubbing facilities which should cover things and it's very easy to define stub regulators if you need to. Like I say I expect this to be a lot easier after the next merge window as another way of doing stubs is being added which should make this even easier by avoiding disrupting drivers that do genuinely want to check for absent supplies and handle that better.

Quoted 8 lines

In this context, is it common practice to name such regulators "vdd" or similar ? What if there are multiple LM90 or compatible chips in a system, connected to different power rails ? Who determines if the regulator is supposed to be named "vdd" or "vcc" or anything else, and to which power rails it is actually connected ? How can and does one guarantee that "vdd" is the correct regulator to use for all systems ? What if some other driver requests "vdd", but the chip it supports happens to be connected to a different power rail ?

That's not what the name means - they are nothing to do with the board.
The names requested by a driver are defined with regard to the device
and should be the names used by the chip itself as defined in the
datasheet. A board that uses regulators then maps these onto specific
regulators in the system, the driver doesn't need to know anything about
this process.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130808/47397104/attachment.sig>

#13 lore raw

Re: [PATCH v2 1/3] hwmon: (lm90) Add power control

In reply to Guenter Roeck
Quoted 21 lines · Guenter Roeck
Quoted 10 lines · Wei Ni

The device lm90 can be controlled by the vdd rail. Adding the power control support to power on/off the vdd rail. And make sure that power is enabled before accessing the device.

drivers/hwmon/lm90.c +0 -0
 
  static int lm90_probe(struct i2c_client *client,
                const struct i2c_device_id *id)
  {

drivers/hwmon/lm90.c static int lm90_probe(struct i2c_client *client, · line 1437

Quoted 4 lines
drivers/hwmon/lm90.c +1 -0
@@ -1406,6 +1434,20 @@ static int lm90_probe(struct i2c_client *client,
      i2c_set_clientdata(client, data);
      mutex_init(&data->update_lock);
 
+    data->lm90_reg = regulator_get(&client->dev, "vdd");

You should use devm_regulator_get(). Then you also don't need the call to regulator_put().

drivers/hwmon/lm90.c static int lm90_probe(struct i2c_client *client, · line 1438

Quoted 1 line
drivers/hwmon/lm90.c +1 -0
+    if (IS_ERR_OR_NULL(data->lm90_reg)) {
Quoted 7 lines

The function never returns NULL except if the regulator subsystem is not configured,
so IS_ERR() is more appropriate.

If the regulator subsystem is not configured, you especially don't need or want
to pollute the log with an error message.

DT parsing errors should be reported. However, if there's nothing to parse, it's not an error.

So, I think this should report an error message *if* there is a DT property that defines the regulator to use. If there's no property, just use no regulator. If there is a property, it had better be possible to parse it.

#10 lore raw

Re: [PATCH v2 1/3] hwmon: (lm90) Add power control

In reply to Guenter Roeck
Quoted 1 line · Guenter Roeck

On 08/08/2013 02:47 AM, Wei Ni wrote:

...

Quoted 5 lines
Quoted 4 lines

I think get_regulator() will return error values, not only -EPROBE_DEFER, so we should set data->lm90_reg to NULL to handle other error values.

Matter of opinion if you want to check for IS_ERR or NULL later on.

No, if regulator returns either:

* Something valid
* Someting IS_ERR()

... then everywhere has to check the value using IS_ERR().

If regulator returns either:

* Something valid
* Someting NULL

... then everywhere has to check the value against NULL.

checking against both IS_ERR() and NULL shouldn't ever happen, and likewise IS_ERR_OR_NULL() is deprecated.

#31 lore raw

Re: [PATCH v2 2/3] ARM: dt: t114 dalmore: add dt entry for nct1008

In reply to Wei Ni
Quoted 1 line · Wei Ni

Enable thermal sensor nct1008 for t114 dalmore.

It'd be best to remove this patch from the series; send one series to the LM90 maintainer with just the driver and DT binding changes, and another series to the Tegra maintainer with the *.dts changes. You can tell me not to apply the *.dts changes until the driver/binding changes are accepted (or just wait until they are before sending the patch).

#38 lore raw

Re: [PATCH v2 3/3] Documentation: dt: hwmon: add OF document for lm90

In reply to Wei Ni

Documentation/devicetree/bindings/hwmon/lm90.txt line 5

Quoted 7 lines · Wei Ni

Add OF document for lm90 in Documentation/devicetree/.

Documentation/devicetree/bindings/hwmon/lm90.txt +3 -0
 
+Required node properties:
+- compatible: manufacture and chip name,
+              which are listed in the Documentation/hwmon/lm90

You need to specify the exact values here. DT binding documentations should be OS-agnostic, and hence can't depend on Linux-specific documentation or other details.

Quoted 2 lines

+Optional properties:
+- vdd-supply: vdd regulator for the supply voltage. If this is not set,

s/set/present/.

Quoted 1 line

+- interrupts: lm90 can support interrupt mode, you can set interrupt here.

You might want to mention that a single entry ("specifier") is expected in the list.

maintainer
#11 lore raw

Re: [PATCH v2 1/3] hwmon: (lm90) Add power control

In reply to Stephen Warren
Quoted 14 lines · Stephen Warren
Quoted 1 line · Guenter Roeck

On 08/08/2013 02:47 AM, Wei Ni wrote:

...

Quoted 5 lines
Quoted 4 lines

I think get_regulator() will return error values, not only -EPROBE_DEFER, so we should set data->lm90_reg to NULL to handle other error values.

Matter of opinion if you want to check for IS_ERR or NULL later on.

No, if regulator returns either:

* Something valid
* Someting IS_ERR()

Quoted 9 lines

... then everywhere has to check the value using IS_ERR().

If regulator returns either:

* Something valid
* Someting NULL

... then everywhere has to check the value against NULL.

Other drivers calling get_regulator() don't check against NULL, so it should not be needed here either.

Guenter

Quoted 3 lines

checking against both IS_ERR() and NULL shouldn't ever happen, and likewise IS_ERR_OR_NULL() is deprecated.

maintainer
#14 lore raw

Re: [PATCH v2 1/3] hwmon: (lm90) Add power control

In reply to Stephen Warren
Quoted 30 lines · Stephen Warren
Quoted 21 lines · Guenter Roeck
Quoted 10 lines · Wei Ni

The device lm90 can be controlled by the vdd rail. Adding the power control support to power on/off the vdd rail. And make sure that power is enabled before accessing the device.

drivers/hwmon/lm90.c +0 -0
 
  static int lm90_probe(struct i2c_client *client,
                const struct i2c_device_id *id)
  {

drivers/hwmon/lm90.c static int lm90_probe(struct i2c_client *client, · line 1437

Quoted 4 lines
drivers/hwmon/lm90.c +1 -0
@@ -1406,6 +1434,20 @@ static int lm90_probe(struct i2c_client *client,
      i2c_set_clientdata(client, data);
      mutex_init(&data->update_lock);
 
+    data->lm90_reg = regulator_get(&client->dev, "vdd");

You should use devm_regulator_get(). Then you also don't need the call to regulator_put().

drivers/hwmon/lm90.c static int lm90_probe(struct i2c_client *client, · line 1438

Quoted 1 line
drivers/hwmon/lm90.c +1 -0
+    if (IS_ERR_OR_NULL(data->lm90_reg)) {
Quoted 7 lines

The function never returns NULL except if the regulator subsystem is not configured,
so IS_ERR() is more appropriate.

If the regulator subsystem is not configured, you especially don't need or want
to pollute the log with an error message.

Quoted 8 lines

DT parsing errors should be reported. However, if there's nothing to parse, it's not an error.

So, I think this should report an error message *if* there is a DT property that defines the regulator to use. If there's no property, just use no regulator. If there is a property, it had better be possible to parse it.

Agreed.

Guenter

#12 lore raw

Re: [PATCH v2 1/3] hwmon: (lm90) Add power control

In reply to Guenter Roeck
Quoted 19 lines · Guenter Roeck
Quoted 18 lines · Stephen Warren
Quoted 1 line · Guenter Roeck

On 08/08/2013 02:47 AM, Wei Ni wrote:

...

Quoted 5 lines
Quoted 4 lines

I think get_regulator() will return error values, not only -EPROBE_DEFER, so we should set data->lm90_reg to NULL to handle other error values.

Matter of opinion if you want to check for IS_ERR or NULL later on.

No, if regulator returns either:

* Something valid
* Someting IS_ERR()

... then everywhere has to check the value using IS_ERR().

If regulator returns either:

Quoted 7 lines
Quoted 5 lines

* Something valid
* Someting NULL

... then everywhere has to check the value against NULL.

Other drivers calling get_regulator() don't check against NULL, so it should not be needed here either.

Right I should have mentioned that I believe regulator falls into the first valid-or-IS_ERR case, and not the second valid-or-NULL case.

#15 lore raw

Re: [PATCH v2 1/3] hwmon: (lm90) Add power control

In reply to Stephen Warren
Quoted 6 lines · Stephen Warren
Quoted 3 lines · Guenter Roeck

If the regulator subsystem is not configured, you especially don't need or want
to pollute the log with an error message.

Quoted 7 lines

DT parsing errors should be reported. However, if there's nothing to parse, it's not an error.

So, I think this should report an error message *if* there is a DT property that defines the regulator to use. If there's no property, just use no regulator. If there is a property, it had better be possible to parse it.

On a DT system you should get this behaviour simply by paying attention
to the error code from the regualtor API - the core should complain
loudly if the DT is incomprehensible.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130808/5d4dd604/attachment.sig>

maintainer
#21 lore raw

Re: [PATCH v2 1/3] hwmon: (lm90) Add power control

In reply to Mark Brown
Quoted 18 lines · Mark Brown
Quoted 8 lines · Guenter Roeck
Quoted 3 lines · Mark Brown

I'd be most surprised if the device worked without power, if the driver fails to get and enable a regulator for it then that's not great (especially if it does so silently).

Correct, but it appears that the driver magically worked for a long time without it.

Sure, it'll work in systems that have always on regulators.

Quoted 5 lines

Is it guaranteed that the driver keeps working for all cases where regulator support is enabled in the kernel, and where it used to work so far without mandating the existence of this specific regulator ? My main concern is having to deal with complaints that the driver stopped working for no good reason.

Quoted 8 lines

Sure, that's the transition issues I mentioned - the regulator API does have stubbing facilities which should cover things and it's very easy to define stub regulators if you need to. Like I say I expect this to be a lot easier after the next merge window as another way of doing stubs is being added which should make this even easier by avoiding disrupting drivers that do genuinely want to check for absent supplies and handle that better.

We will need to make sure that all dts files using any of the compatible chips are updated accordingly. There are several entries in various dts files for adm1032, adt7461, lm90, and nct1008.

Quoted 10 lines
Quoted 8 lines

In this context, is it common practice to name such regulators "vdd" or similar ? What if there are multiple LM90 or compatible chips in a system, connected to different power rails ? Who determines if the regulator is supposed to be named "vdd" or "vcc" or anything else, and to which power rails it is actually connected ? How can and does one guarantee that "vdd" is the correct regulator to use for all systems ? What if some other driver requests "vdd", but the chip it supports happens to be connected to a different power rail ?

That's not what the name means - they are nothing to do with the board.

Ok, makes sense.

Quoted 2 lines

The names requested by a driver are defined with regard to the device and should be the names used by the chip itself as defined in the

9 votes for vdd, 11 votes for vcc, one undecided (no datasheet available). Guess one is as good as the other ;-).

Guenter

Quoted 3 lines

datasheet. A board that uses regulators then maps these onto specific regulators in the system, the driver doesn't need to know anything about this process.

#33 lore raw

Re: [PATCH v2 2/3] ARM: dt: t114 dalmore: add dt entry for nct1008

In reply to Wei Ni

Hello.

Quoted 12 lines · Wei Ni

Enable thermal sensor nct1008 for t114 dalmore.

---
  arch/arm/boot/dts/tegra114-dalmore.dts |   10 +++++++++-
  1 file changed, 9 insertions(+), 1 deletion(-)
arch/arm/boot/dts/tegra114-dalmore.dts +0 -0
index b5a42f0..9d4d2b2 100644

arch/arm/boot/dts/tegra114-dalmore.dts line 742

Quoted 5 lines
arch/arm/boot/dts/tegra114-dalmore.dts +2 -0
@@ -738,6 +738,14 @@
  			realtek,ldo1-en-gpios =
  				<&gpio TEGRA_GPIO(V, 3) GPIO_ACTIVE_HIGH>;
  		};
+
+		nct1008 {

ePAPR [1] says: "the name of a node should be somewhat generic, reflecting
the function of the device and not its precise programming model". So I suggest "thermal"

arch/arm/boot/dts/tegra114-dalmore.dts line 749

Quoted 7 lines
arch/arm/boot/dts/tegra114-dalmore.dts +6 -0
+			compatible = "onnn,nct1008";
+			reg = <0x4c>;
+			vdd-supply = <&palmas_ldo6_reg>;
+			interrupt-parent = <&gpio>;
+			interrupts = <TEGRA_GPIO(O, 4) IRQ_TYPE_LEVEL_LOW>;
+		};
  	};

[1] http://www.power.org/resources/downloads/Power_ePAPR_APPROVED_v1.0.pdf

WBR, Sergei

#34 lore raw

Re: [PATCH v2 2/3] ARM: dt: t114 dalmore: add dt entry for nct1008

Quoted 11 lines · Sergei Shtylyov

Hello.

Quoted 6 lines · Wei Ni

Enable thermal sensor nct1008 for t114 dalmore.

---
  arch/arm/boot/dts/tegra114-dalmore.dts |   10 +++++++++-
  1 file changed, 9 insertions(+), 1 deletion(-)
Quoted 15 lines

arch/arm/boot/dts/tegra114-dalmore.dts line 742

Quoted 11 lines
arch/arm/boot/dts/tegra114-dalmore.dts +2 -0
index b5a42f0..9d4d2b2 100644
@@ -738,6 +738,14 @@
              realtek,ldo1-en-gpios =
                  <&gpio TEGRA_GPIO(V, 3) GPIO_ACTIVE_HIGH>;
          };
+
+        nct1008 {

ePAPR [1] says: "the name of a node should be somewhat generic,
reflecting the function of the device and not its precise programming model". So I suggest "thermal"

True, although there's quite some precedent for node-names being the chip name for external chips in existing DTs. If we change this node name, I'd like to see a patch that makes all the other "nct1008" nodes match the new name...

#22 lore raw

Re: [PATCH v2 1/3] hwmon: (lm90) Add power control

In reply to Guenter Roeck
Quoted 10 lines · Guenter Roeck
Quoted 7 lines · Mark Brown

Sure, that's the transition issues I mentioned - the regulator API does have stubbing facilities which should cover things and it's very easy to define stub regulators if you need to. Like I say I expect this to be a lot easier after the next merge window as another way of doing stubs is being added which should make this even easier by avoiding disrupting drivers that do genuinely want to check for absent supplies and handle that better.

Quoted 3 lines

We will need to make sure that all dts files using any of the compatible chips are updated accordingly. There are several entries in various dts files for adm1032, adt7461, lm90, and nct1008.

Yes, and probably also board files as well. Or either just accept bisection trouble for now or wait till the better stubbing is in there - that will mean that for DT systems the core will just assume the supply is really there and not fail requests if it's not in the DT.

Quoted 5 lines
Quoted 2 lines

The names requested by a driver are defined with regard to the device and should be the names used by the chip itself as defined in the

9 votes for vdd, 11 votes for vcc, one undecided (no datasheet available). Guess one is as good as the other ;-).

What I've suggested before is to use the name from the part for which
the driver is named. Assuming the vendor doesn't randomly change their
datasheet (but that causes problems for hardware engineers so tends to
be avoided).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130808/df7e3102/attachment.sig>

maintainer
#23 lore raw

Re: [PATCH v2 1/3] hwmon: (lm90) Add power control

Quoted 11 lines · Mark Brown
Quoted 9 lines · Guenter Roeck
Quoted 7 lines · Mark Brown

Sure, that's the transition issues I mentioned - the regulator API does have stubbing facilities which should cover things and it's very easy to define stub regulators if you need to. Like I say I expect this to be a lot easier after the next merge window as another way of doing stubs is being added which should make this even easier by avoiding disrupting drivers that do genuinely want to check for absent supplies and handle that better.

Quoted 6 lines
Quoted 3 lines

We will need to make sure that all dts files using any of the compatible chips are updated accordingly. There are several entries in various dts files for adm1032, adt7461, lm90, and nct1008.

Yes, and probably also board files as well. Or either just accept bisection trouble for now or wait till the better stubbing is in there -

Ah, that is exactly the trouble I wanted to avoid.

Quoted 6 lines

that will mean that for DT systems the core will just assume the supply is really there and not fail requests if it's not in the DT.

Quoted 2 lines
Quoted 2 lines

The names requested by a driver are defined with regard to the device and should be the names used by the chip itself as defined in the

Quoted 8 lines
Quoted 2 lines

9 votes for vdd, 11 votes for vcc, one undecided (no datasheet available). Guess one is as good as the other ;-).

What I've suggested before is to use the name from the part for which the driver is named. Assuming the vendor doesn't randomly change their datasheet (but that causes problems for hardware engineers so tends to be avoided).

Makes sense.

Guenter

maintainer
#35 lore raw

Re: [PATCH v2 2/3] ARM: dt: t114 dalmore: add dt entry for nct1008

In reply to Stephen Warren
Quoted 28 lines · Stephen Warren
Quoted 11 lines · Sergei Shtylyov

Hello.

Quoted 6 lines · Wei Ni

Enable thermal sensor nct1008 for t114 dalmore.

---
   arch/arm/boot/dts/tegra114-dalmore.dts |   10 +++++++++-
   1 file changed, 9 insertions(+), 1 deletion(-)
Quoted 15 lines

arch/arm/boot/dts/tegra114-dalmore.dts line 742

Quoted 11 lines
arch/arm/boot/dts/tegra114-dalmore.dts +2 -0
index b5a42f0..9d4d2b2 100644
@@ -738,6 +738,14 @@
               realtek,ldo1-en-gpios =
                   <&gpio TEGRA_GPIO(V, 3) GPIO_ACTIVE_HIGH>;
           };
+
+        nct1008 {

ePAPR [1] says: "the name of a node should be somewhat generic,
reflecting the function of the device and not its precise programming model". So I suggest "thermal"

Quoted 5 lines

True, although there's quite some precedent for node-names being the chip name for external chips in existing DTs. If we change this node name, I'd like to see a patch that makes all the other "nct1008" nodes match the new name...

On the other side, one should not use a bad example as an argument or excuse to make the same mistake again (though I keep hearing it all the time ... ). I for my part tend to use something like temp-sensor or temp-sensor@1c. Advantage of that kind of node name is that it auto-describes the node.

Guenter

#24 lore raw

Proposal: I2C device power (Was: hwmon: (lm90) Add power control)

In reply to Guenter Roeck

Hi all.

Instead of adding the support of regulators in each device, let's think about whether it is possible to create a global regulator for any device on the I2C bus.

I see it like this:
We add an extra field in the i2c_board_info structure "power_name" and handle it in the i2c_device_{probe/remove} functions.

The question remains how to maintain such regulator in the PM functions, but we can discuss it.

Changes like this, will remove existing regulators from drivers and allows to use power regulator for any I2C device.
If such idea is good, such changes could be made to other devices (SPI, w1, etc.). Thanks.

---

author
#32 lore raw

Re: [PATCH v2 2/3] ARM: dt: t114 dalmore: add dt entry for nct1008

In reply to Stephen Warren
Quoted 8 lines · Stephen Warren
Quoted 1 line · Wei Ni

Enable thermal sensor nct1008 for t114 dalmore.

It'd be best to remove this patch from the series; send one series to the LM90 maintainer with just the driver and DT binding changes, and another series to the Tegra maintainer with the *.dts changes. You can tell me not to apply the *.dts changes until the driver/binding changes are accepted (or just wait until they are before sending the patch).

Ok, I will do it.

Quoted 1 line
author
#39 lore raw

Re: [PATCH v2 3/3] Documentation: dt: hwmon: add OF document for lm90

In reply to Stephen Warren
Quoted 5 lines · Stephen Warren
Quoted 3 lines · Wei Ni

Add OF document for lm90 in Documentation/devicetree/.

Documentation/devicetree/bindings/hwmon/lm90.txt +0 -0
Quoted 7 lines

Documentation/devicetree/bindings/hwmon/lm90.txt line 5

Quoted 3 lines
Documentation/devicetree/bindings/hwmon/lm90.txt +3 -0
+Required node properties:
+- compatible: manufacture and chip name,
+              which are listed in the Documentation/hwmon/lm90

You need to specify the exact values here. DT binding documentations should be OS-agnostic, and hence can't depend on Linux-specific documentation or other details.

Ok, I will list it.

Quoted 5 lines
Quoted 3 lines

+Optional properties:
+- vdd-supply: vdd regulator for the supply voltage. If this is not set,

s/set/present/.

Oh, yes, I will change it.

Quoted 5 lines
Quoted 2 lines

+- interrupts: lm90 can support interrupt mode, you can set interrupt here.

You might want to mention that a single entry ("specifier") is expected in the list.

Sorry, I didn't get your point, could you explain more?

Quoted 1 line
author
#36 lore raw

Re: [PATCH v2 2/3] ARM: dt: t114 dalmore: add dt entry for nct1008

In reply to Guenter Roeck
Quoted 35 lines · Guenter Roeck
Quoted 28 lines · Stephen Warren
Quoted 11 lines · Sergei Shtylyov

Hello.

Quoted 6 lines · Wei Ni

Enable thermal sensor nct1008 for t114 dalmore.

---
   arch/arm/boot/dts/tegra114-dalmore.dts |   10 +++++++++-
   1 file changed, 9 insertions(+), 1 deletion(-)
Quoted 15 lines

arch/arm/boot/dts/tegra114-dalmore.dts line 742

Quoted 11 lines
arch/arm/boot/dts/tegra114-dalmore.dts +2 -0
index b5a42f0..9d4d2b2 100644
@@ -738,6 +738,14 @@
               realtek,ldo1-en-gpios =
                   <&gpio TEGRA_GPIO(V, 3) GPIO_ACTIVE_HIGH>;
           };
+
+        nct1008 {

ePAPR [1] says: "the name of a node should be somewhat generic,
reflecting the function of the device and not its precise programming model". So I suggest "thermal"

Quoted 5 lines

True, although there's quite some precedent for node-names being the chip name for external chips in existing DTs. If we change this node name, I'd like to see a patch that makes all the other "nct1008" nodes match the new name...

Quoted 4 lines

On the other side, one should not use a bad example as an argument or excuse to make the same mistake again (though I keep hearing it all the time ... ). I for my part tend to use something like temp-sensor or temp-sensor at 1c. Advantage of that kind of node name is that it auto-describes the node.

Ok, so I will set the node name as "temp-sensor"
And I will send out patches to change all other "nct1008" nodes.

Quoted 3 lines

Guenter

author
#28 lore raw

Re: [PATCH v2 1/3] hwmon: (lm90) Add power control

In reply to Mark Brown
Quoted 32 lines · Mark Brown

* PGP Signed by an unknown key

Quoted 6 lines · Wei Ni
drivers/hwmon/lm90.c +6 -0
+	mutex_lock(&data->update_lock);
+
+	if (is_enable)
+		ret = regulator_enable(data->lm90_reg);
+	else
+		ret = regulator_disable(data->lm90_reg);

drivers/hwmon/lm90.c static void lm90_init_client(struct i2c_client *client) · line 1419

Quoted 10 lines
drivers/hwmon/lm90.c +10 -0
+
+	if (ret < 0)
+		dev_err(&client->dev,
+			"Error in %s rail vdd, error %d\n",
+			(is_enable) ? "enabling" : "disabling", ret);
+	else
+		dev_info(&client->dev, "success in %s rail vdd\n",
+			 (is_enable) ? "enabling" : "disabling");
+
+	mutex_unlock(&data->update_lock);

Two things here. One is that it's not clear what this lokc is protecting since the only thing in the locked region is the regulator operation and that is thread safe. The other thing is that I'm not seeing anthing that ensures that enables and disables are matched - regulators are reference counted so two enables need two disables.

drivers/hwmon/lm90.c static int lm90_probe(struct i2c_client *client, · line 1438

Quoted 2 lines
drivers/hwmon/lm90.c +2 -0
+	data->lm90_reg = regulator_get(&client->dev, "vdd");
+	if (IS_ERR_OR_NULL(data->lm90_reg)) {

NULL is a valid regulator, use IS_ERR().

Quoted 12 lines

drivers/hwmon/lm90.c static int lm90_probe(struct i2c_client *client, · line 1445

Quoted 7 lines
drivers/hwmon/lm90.c +7 -0
+		if (PTR_ERR(data->lm90_reg) == -ENODEV)
+			dev_info(&client->dev,
+				 "No regulator found for vdd. Assuming vdd is always powered.");
+		else
+			dev_warn(&client->dev,
+				 "Error [%ld] in getting the regulator handle for vdd.\n",
+				 PTR_ERR(data->lm90_reg));

You shouldn't just be ignoring errors here, though there are deployment difficulties with making sure a stub regulator is provided. These should be getting easier after the next merge window, the stubs will be being tweaked slightly to have an "assume it's there" option even when

Oh, really, could you show me the patch, I wish to take a look :)

Wei.

Quoted 12 lines

regulators are used. Especially in cases with device tree you should be paying attention to -EPROBE_DEFER, that will accurately reflect if a regulator is present but not loaded yet.

That said if you *are* going to do this you should request the regulator using devm_regulator_get_optional(), this is intended to support things that don't need regulators (though that's not the case here).

* Unknown Key
* 0x7EA229BD

#25 lore raw

Re: Proposal: I2C device power (Was: hwmon: (lm90) Add power control)

In reply to Alexander Shiyan
Quoted 6 lines · Alexander Shiyan

Instead of adding the support of regulators in each device, let's think about whether it is possible to create a global regulator for any device on the I2C bus.

I see it like this:
We add an extra field in the i2c_board_info structure "power_name" and handle it in the i2c_device_{probe/remove} functions.

This would need to be an array of supplies, relatively few devices need only a single power supply. This is also not something that should be handled in I2C, power is not something that's uniquely needed by devices on an I2C bus.

Quoted 2 lines

The question remains how to maintain such regulator in the PM functions, but we can discuss it.

Well, there's some basic stuff for this for clocks already - a similar
pattern should work. You need to use runtime PM to hook in the power
management and it's not going to work for everything (especially things
that can be wake sources) but there's some value in trying to factor out
the basic use case.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130809/a404b149/attachment.sig>

#26 lore raw

Re: Proposal: I2C device power (Was: hwmon: (lm90) Add power control)

Quoted 5 lines · Alexander Shiyan
Quoted 3 lines

Instead of adding the support of regulators in each device, let's think about whether it is possible to create a global regulator for any device on the I2C bus.

Quoted 8 lines
Quoted 3 lines

I see it like this:
We add an extra field in the i2c_board_info structure "power_name" and handle it in the i2c_device_{probe/remove} functions.

This would need to be an array of supplies, relatively few devices need only a single power supply. This is also not something that should be handled in I2C, power is not something that's uniquely needed by devices on an I2C bus.

Additional regulators can be handled in the driver, or "parent"-scheme can be used. Is not it?

---

#29 lore raw

Re: [PATCH v2 1/3] hwmon: (lm90) Add power control

In reply to Wei Ni
Quoted 8 lines · Wei Ni
Quoted 4 lines · Mark Brown

You shouldn't just be ignoring errors here, though there are deployment difficulties with making sure a stub regulator is provided. These should be getting easier after the next merge window, the stubs will be being tweaked slightly to have an "assume it's there" option even when

Oh, really, could you show me the patch, I wish to take a look :)

No patch quite yet - the basic idea is that for plain regulator_get()
you'll only ever get -EPROBE_DEFER as an error, not -ENODEV. If the
regulator is missing in the DT we assume it's there and provide a dummy
if the DT doesn't hook it up. If the consumer genuinely wants to see if
a supply might not be wired up it should use regulator_get_optional()
which is in -next at the minute.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130809/4b97e752/attachment.sig>

#27 lore raw

Re: Proposal: I2C device power (Was: hwmon: (lm90) Add power control)

In reply to Alexander Shiyan
Quoted 7 lines · Alexander Shiyan
Quoted 4 lines

This would need to be an array of supplies, relatively few devices need only a single power supply. This is also not something that should be handled in I2C, power is not something that's uniquely needed by devices on an I2C bus.

Additional regulators can be handled in the driver, or "parent"-scheme can be used. Is not it?

Given how common it is to have multiple supplies it seems sensible to
just handle that in the core - it's common to have a digital supply and
an analogue supply for example. The regulator framework already has
APIs for working with multiple regulators in a single call so it's not
going to be much more effort on the framework side.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130809/cc925490/attachment.sig>

#40 lore raw

Re: [PATCH v2 3/3] Documentation: dt: hwmon: add OF document for lm90

In reply to Wei Ni
Quoted 4 lines · Wei Ni
Quoted 3 lines · Stephen Warren
Quoted 1 line · Wei Ni

Add OF document for lm90 in Documentation/devicetree/.

Quoted 8 lines
Quoted 6 lines

Documentation/devicetree/bindings/hwmon/lm90.txt

Quoted 3 lines
Documentation/devicetree/bindings/hwmon/lm90.txt +1 -0
 
+- interrupts: lm90 can support interrupt mode, you can set interrupt here.

You might want to mention that a single entry ("specifier") is expected in the list.

Sorry, I didn't get your point, could you explain more?

In general, a device may have more than one interrupt output. Hence in general, the interrupts property is a list of 1 or more interrupt specifiers. In this case, that list should be a single entry. The binding should state this. how about:

----------
Optional properties:
interrupts: Contains a single interrupt specifier which describes the LM90 XXXX output. See interrupt-controller/interrupts.txt for the format.
----------

(where you'd replace XXXX with the pin/signal name from the datasheet).