hwmon: (lm90) Add power control
The device lm90 can be controlled by the vcc rail. Adding the regulator support to power on/off the vcc rail. Enable the "vcc" regulator before accessing the device. [JD: Rename variables to avoid confusion with registers.] Signed-off-by: Wei Ni <wni@nvidia.com> Signed-off-by: Jean Delvare <khali@linux-fr.org>
This commit is contained in:
Родитель
1daaceb26d
Коммит
3e0f964f2a
|
@ -95,6 +95,7 @@
|
||||||
#include <linux/mutex.h>
|
#include <linux/mutex.h>
|
||||||
#include <linux/sysfs.h>
|
#include <linux/sysfs.h>
|
||||||
#include <linux/interrupt.h>
|
#include <linux/interrupt.h>
|
||||||
|
#include <linux/regulator/consumer.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Addresses to scan
|
* Addresses to scan
|
||||||
|
@ -366,6 +367,7 @@ enum lm90_temp11_reg_index {
|
||||||
struct lm90_data {
|
struct lm90_data {
|
||||||
struct device *hwmon_dev;
|
struct device *hwmon_dev;
|
||||||
struct mutex update_lock;
|
struct mutex update_lock;
|
||||||
|
struct regulator *regulator;
|
||||||
char valid; /* zero until following fields are valid */
|
char valid; /* zero until following fields are valid */
|
||||||
unsigned long last_updated; /* in jiffies */
|
unsigned long last_updated; /* in jiffies */
|
||||||
int kind;
|
int kind;
|
||||||
|
@ -1516,8 +1518,20 @@ static int lm90_probe(struct i2c_client *client,
|
||||||
struct device *dev = &client->dev;
|
struct device *dev = &client->dev;
|
||||||
struct i2c_adapter *adapter = to_i2c_adapter(dev->parent);
|
struct i2c_adapter *adapter = to_i2c_adapter(dev->parent);
|
||||||
struct lm90_data *data;
|
struct lm90_data *data;
|
||||||
|
struct regulator *regulator;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
regulator = devm_regulator_get(dev, "vcc");
|
||||||
|
if (IS_ERR(regulator))
|
||||||
|
return PTR_ERR(regulator);
|
||||||
|
|
||||||
|
err = regulator_enable(regulator);
|
||||||
|
if (err < 0) {
|
||||||
|
dev_err(&client->dev,
|
||||||
|
"Failed to enable regulator: %d\n", err);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
data = devm_kzalloc(&client->dev, sizeof(struct lm90_data), GFP_KERNEL);
|
data = devm_kzalloc(&client->dev, sizeof(struct lm90_data), GFP_KERNEL);
|
||||||
if (!data)
|
if (!data)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
@ -1525,6 +1539,8 @@ static int lm90_probe(struct i2c_client *client,
|
||||||
i2c_set_clientdata(client, data);
|
i2c_set_clientdata(client, data);
|
||||||
mutex_init(&data->update_lock);
|
mutex_init(&data->update_lock);
|
||||||
|
|
||||||
|
data->regulator = regulator;
|
||||||
|
|
||||||
/* Set the device type */
|
/* Set the device type */
|
||||||
data->kind = id->driver_data;
|
data->kind = id->driver_data;
|
||||||
if (data->kind == adm1032) {
|
if (data->kind == adm1032) {
|
||||||
|
@ -1604,6 +1620,8 @@ exit_remove_files:
|
||||||
lm90_remove_files(client, data);
|
lm90_remove_files(client, data);
|
||||||
exit_restore:
|
exit_restore:
|
||||||
lm90_restore_conf(client, data);
|
lm90_restore_conf(client, data);
|
||||||
|
regulator_disable(data->regulator);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1614,6 +1632,7 @@ static int lm90_remove(struct i2c_client *client)
|
||||||
hwmon_device_unregister(data->hwmon_dev);
|
hwmon_device_unregister(data->hwmon_dev);
|
||||||
lm90_remove_files(client, data);
|
lm90_remove_files(client, data);
|
||||||
lm90_restore_conf(client, data);
|
lm90_restore_conf(client, data);
|
||||||
|
regulator_disable(data->regulator);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче