diff options
author | Wei Ni <wni@nvidia.com> | 2013-11-15 04:40:39 -0500 |
---|---|---|
committer | Jean Delvare <khali@endymion.delvare> | 2013-11-15 04:40:39 -0500 |
commit | 3e0f964f2ad38d2d4c2616fb8f12016cf6ea1758 (patch) | |
tree | f0f5d78cf5e7f740783831585e69881646895401 /drivers/hwmon | |
parent | 1daaceb26d5e6cc08eedf03f64ab220f62243c22 (diff) |
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>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r-- | drivers/hwmon/lm90.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c index 03735c490891..4c4c1421bf28 100644 --- a/drivers/hwmon/lm90.c +++ b/drivers/hwmon/lm90.c | |||
@@ -95,6 +95,7 @@ | |||
95 | #include <linux/mutex.h> | 95 | #include <linux/mutex.h> |
96 | #include <linux/sysfs.h> | 96 | #include <linux/sysfs.h> |
97 | #include <linux/interrupt.h> | 97 | #include <linux/interrupt.h> |
98 | #include <linux/regulator/consumer.h> | ||
98 | 99 | ||
99 | /* | 100 | /* |
100 | * Addresses to scan | 101 | * Addresses to scan |
@@ -366,6 +367,7 @@ enum lm90_temp11_reg_index { | |||
366 | struct lm90_data { | 367 | struct lm90_data { |
367 | struct device *hwmon_dev; | 368 | struct device *hwmon_dev; |
368 | struct mutex update_lock; | 369 | struct mutex update_lock; |
370 | struct regulator *regulator; | ||
369 | char valid; /* zero until following fields are valid */ | 371 | char valid; /* zero until following fields are valid */ |
370 | unsigned long last_updated; /* in jiffies */ | 372 | unsigned long last_updated; /* in jiffies */ |
371 | int kind; | 373 | int kind; |
@@ -1516,8 +1518,20 @@ static int lm90_probe(struct i2c_client *client, | |||
1516 | struct device *dev = &client->dev; | 1518 | struct device *dev = &client->dev; |
1517 | struct i2c_adapter *adapter = to_i2c_adapter(dev->parent); | 1519 | struct i2c_adapter *adapter = to_i2c_adapter(dev->parent); |
1518 | struct lm90_data *data; | 1520 | struct lm90_data *data; |
1521 | struct regulator *regulator; | ||
1519 | int err; | 1522 | int err; |
1520 | 1523 | ||
1524 | regulator = devm_regulator_get(dev, "vcc"); | ||
1525 | if (IS_ERR(regulator)) | ||
1526 | return PTR_ERR(regulator); | ||
1527 | |||
1528 | err = regulator_enable(regulator); | ||
1529 | if (err < 0) { | ||
1530 | dev_err(&client->dev, | ||
1531 | "Failed to enable regulator: %d\n", err); | ||
1532 | return err; | ||
1533 | } | ||
1534 | |||
1521 | data = devm_kzalloc(&client->dev, sizeof(struct lm90_data), GFP_KERNEL); | 1535 | data = devm_kzalloc(&client->dev, sizeof(struct lm90_data), GFP_KERNEL); |
1522 | if (!data) | 1536 | if (!data) |
1523 | return -ENOMEM; | 1537 | return -ENOMEM; |
@@ -1525,6 +1539,8 @@ static int lm90_probe(struct i2c_client *client, | |||
1525 | i2c_set_clientdata(client, data); | 1539 | i2c_set_clientdata(client, data); |
1526 | mutex_init(&data->update_lock); | 1540 | mutex_init(&data->update_lock); |
1527 | 1541 | ||
1542 | data->regulator = regulator; | ||
1543 | |||
1528 | /* Set the device type */ | 1544 | /* Set the device type */ |
1529 | data->kind = id->driver_data; | 1545 | data->kind = id->driver_data; |
1530 | if (data->kind == adm1032) { | 1546 | if (data->kind == adm1032) { |
@@ -1604,6 +1620,8 @@ exit_remove_files: | |||
1604 | lm90_remove_files(client, data); | 1620 | lm90_remove_files(client, data); |
1605 | exit_restore: | 1621 | exit_restore: |
1606 | lm90_restore_conf(client, data); | 1622 | lm90_restore_conf(client, data); |
1623 | regulator_disable(data->regulator); | ||
1624 | |||
1607 | return err; | 1625 | return err; |
1608 | } | 1626 | } |
1609 | 1627 | ||
@@ -1614,6 +1632,7 @@ static int lm90_remove(struct i2c_client *client) | |||
1614 | hwmon_device_unregister(data->hwmon_dev); | 1632 | hwmon_device_unregister(data->hwmon_dev); |
1615 | lm90_remove_files(client, data); | 1633 | lm90_remove_files(client, data); |
1616 | lm90_restore_conf(client, data); | 1634 | lm90_restore_conf(client, data); |
1635 | regulator_disable(data->regulator); | ||
1617 | 1636 | ||
1618 | return 0; | 1637 | return 0; |
1619 | } | 1638 | } |