Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Wei Ni and committed by
Jean Delvare
3e0f964f 1daaceb2

+19
+19
drivers/hwmon/lm90.c
··· 95 95 #include <linux/mutex.h> 96 96 #include <linux/sysfs.h> 97 97 #include <linux/interrupt.h> 98 + #include <linux/regulator/consumer.h> 98 99 99 100 /* 100 101 * Addresses to scan ··· 367 366 struct lm90_data { 368 367 struct device *hwmon_dev; 369 368 struct mutex update_lock; 369 + struct regulator *regulator; 370 370 char valid; /* zero until following fields are valid */ 371 371 unsigned long last_updated; /* in jiffies */ 372 372 int kind; ··· 1518 1516 struct device *dev = &client->dev; 1519 1517 struct i2c_adapter *adapter = to_i2c_adapter(dev->parent); 1520 1518 struct lm90_data *data; 1519 + struct regulator *regulator; 1521 1520 int err; 1521 + 1522 + regulator = devm_regulator_get(dev, "vcc"); 1523 + if (IS_ERR(regulator)) 1524 + return PTR_ERR(regulator); 1525 + 1526 + err = regulator_enable(regulator); 1527 + if (err < 0) { 1528 + dev_err(&client->dev, 1529 + "Failed to enable regulator: %d\n", err); 1530 + return err; 1531 + } 1522 1532 1523 1533 data = devm_kzalloc(&client->dev, sizeof(struct lm90_data), GFP_KERNEL); 1524 1534 if (!data) ··· 1538 1524 1539 1525 i2c_set_clientdata(client, data); 1540 1526 mutex_init(&data->update_lock); 1527 + 1528 + data->regulator = regulator; 1541 1529 1542 1530 /* Set the device type */ 1543 1531 data->kind = id->driver_data; ··· 1620 1604 lm90_remove_files(client, data); 1621 1605 exit_restore: 1622 1606 lm90_restore_conf(client, data); 1607 + regulator_disable(data->regulator); 1608 + 1623 1609 return err; 1624 1610 } 1625 1611 ··· 1632 1614 hwmon_device_unregister(data->hwmon_dev); 1633 1615 lm90_remove_files(client, data); 1634 1616 lm90_restore_conf(client, data); 1617 + regulator_disable(data->regulator); 1635 1618 1636 1619 return 0; 1637 1620 }