All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@cam.ac.uk>
To: lm-sensors@vger.kernel.org
Subject: [lm-sensors] [RFC] LM75 add regulator support
Date: Thu, 25 Jun 2009 16:11:56 +0000	[thread overview]
Message-ID: <4A43A1CC.2040701@cam.ac.uk> (raw)


Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>

---
Data sheet trawling has established that, of the devices listed by
this driver, there are two voltage ranges. (2.7-5.5 or 3-5.5)
This driver uses the i2c id to identify which is need and request that
from a 'vcc' regulator.

What do people think about adding this support?

On the embedded board I'm using this allows the relevant, heavily
shared, supply to only be brought up if module is loaded. 

This obviously only effects devices that supply such a regulator
in their machine config (typically embedded). The fall throughs
on voltage setting failure are to allow for regulator definitions that
don't allow the voltages to be changed.

diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c
index 55bd87c..a06025d 100644
--- a/drivers/hwmon/lm75.c
+++ b/drivers/hwmon/lm75.c
@@ -27,6 +27,7 @@
 #include <linux/hwmon-sysfs.h>
 #include <linux/err.h>
 #include <linux/mutex.h>
+#include <linux/regulator/consumer.h>
 #include "lm75.h"
 
 
@@ -81,6 +82,7 @@ struct lm75_data {
 						   0 = input
 						   1 = max
 						   2 = hyst */
+	struct regulator	*reg;
 };
 
 static int lm75_read_value(struct i2c_client *client, u8 reg);
@@ -146,6 +148,7 @@ lm75_probe(struct i2c_client *client, const struct i2c_device_id *id)
 	int status;
 	u8 set_mask, clr_mask;
 	int new;
+	int min_voltage;
 
 	if (!i2c_check_functionality(client->adapter,
 			I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA))
@@ -158,6 +161,56 @@ lm75_probe(struct i2c_client *client, const struct i2c_device_id *id)
 	i2c_set_clientdata(client, data);
 	mutex_init(&data->update_lock);
 
+	data->reg = regulator_get(&client->dev, "vcc");
+
+	/* Voltage ranges:
+	 * lm75a 2.7 - 5.5V
+	 * lm75b 3 - 5.5 V
+	 * lm75c 3 - 5.5
+	 * ds1775 2.7 - 5.5V
+	 * ds75 2.7 - 5.5V
+	 * max6625 3 - 5.5V
+	 * max6626 3 - 5.5V
+	 * mcp980x 2.7 - 5.5V
+	 * stds75 2.7 - 5.5V
+	 * tcn75 2.7 - 5.5V
+	 * tmp100 2.7 - 5.5V
+	 * tmp101 2.7 - 5.5V
+	 * tmp175 2.7 - 5.5V
+	 * tmp75 2.7 - 5.5V
+	 * tmp275 2.7 - 5.5V
+	 */
+	if (!IS_ERR(data->reg)) {
+		switch (id->driver_data) {
+		default:
+		case 1: /* lm75 */
+		case max6625:
+		case max6626:
+			min_voltage = 3000000;
+			break;
+		case lm75a:
+		case ds1775:
+		case ds75:
+		case mcp980x:
+		case stds75:
+		case tcn75:
+		case tmp100:
+		case tmp101:
+		case tmp175:
+		case tmp75:
+		case tmp275:
+			min_voltage = 2700000;
+			break;
+		}
+		status = regulator_set_voltage(data->reg,
+					       min_voltage,
+					       5500000);
+		if (status)
+			dev_info(&client->dev, "could not set voltage\n");
+		status = regulator_enable(data->reg);
+		if (status)
+			dev_info(&client->dev, "could not enable regulator\n");
+	}
 	/* Set to LM75 resolution (9 bits, 1/2 degree C) and range.
 	 * Then tweak to be more precise when appropriate.
 	 */
@@ -210,6 +263,10 @@ static int lm75_remove(struct i2c_client *client)
 	sysfs_remove_group(&client->dev.kobj, &lm75_group);
 	lm75_write_value(client, LM75_REG_CONF, data->orig_conf);
 	i2c_set_clientdata(client, NULL);
+	if (!IS_ERR(data->reg)) {
+		regulator_disable(data->reg);
+		regulator_put(data->reg);
+	}
 	kfree(data);
 	return 0;
 }

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

             reply	other threads:[~2009-06-25 16:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-25 16:11 Jonathan Cameron [this message]
2009-06-25 17:04 ` [lm-sensors] [RFC] LM75 add regulator support Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4A43A1CC.2040701@cam.ac.uk \
    --to=jic23@cam.ac.uk \
    --cc=lm-sensors@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.