diff options
author | Alan Tull <atull@opensource.altera.com> | 2014-10-15 14:55:09 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2014-11-30 23:13:13 -0500 |
commit | ddbb4db4ced1ba784fcd3500179a7291b6c5d7b7 (patch) | |
tree | 9d06aeb930ba86bfcc68ef659d392f98a263aff6 /drivers/hwmon | |
parent | 11c119986f2700e9daca0d795fbe84a988939655 (diff) |
hwmon: (pmbus) Add regulator support
Add support for simple on/off control of each channel.
To add regulator support, the pmbus part driver needs to add
regulator_desc information and number of regulators to its
pmbus_driver_info struct.
regulator_desc can be declared using default macro for a
regulator (PMBUS_REGULATOR) that is in pmbus.h
The regulator_init_data can be initialized from either
platform data or the device tree.
Signed-off-by: Alan Tull <atull@opensource.altera.com>
Reviewed-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r-- | drivers/hwmon/pmbus/pmbus.h | 26 | ||||
-rw-r--r-- | drivers/hwmon/pmbus/pmbus_core.c | 87 |
2 files changed, 113 insertions, 0 deletions
diff --git a/drivers/hwmon/pmbus/pmbus.h b/drivers/hwmon/pmbus/pmbus.h index 3ae79a7d1b00..89a23ff836e7 100644 --- a/drivers/hwmon/pmbus/pmbus.h +++ b/drivers/hwmon/pmbus/pmbus.h | |||
@@ -19,6 +19,8 @@ | |||
19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include <linux/regulator/driver.h> | ||
23 | |||
22 | #ifndef PMBUS_H | 24 | #ifndef PMBUS_H |
23 | #define PMBUS_H | 25 | #define PMBUS_H |
24 | 26 | ||
@@ -186,6 +188,11 @@ | |||
186 | #define PMBUS_VIRT_STATUS_VMON (PMBUS_VIRT_BASE + 35) | 188 | #define PMBUS_VIRT_STATUS_VMON (PMBUS_VIRT_BASE + 35) |
187 | 189 | ||
188 | /* | 190 | /* |
191 | * OPERATION | ||
192 | */ | ||
193 | #define PB_OPERATION_CONTROL_ON (1<<7) | ||
194 | |||
195 | /* | ||
189 | * CAPABILITY | 196 | * CAPABILITY |
190 | */ | 197 | */ |
191 | #define PB_CAPABILITY_SMBALERT (1<<4) | 198 | #define PB_CAPABILITY_SMBALERT (1<<4) |
@@ -365,8 +372,27 @@ struct pmbus_driver_info { | |||
365 | */ | 372 | */ |
366 | int (*identify)(struct i2c_client *client, | 373 | int (*identify)(struct i2c_client *client, |
367 | struct pmbus_driver_info *info); | 374 | struct pmbus_driver_info *info); |
375 | |||
376 | /* Regulator functionality, if supported by this chip driver. */ | ||
377 | int num_regulators; | ||
378 | const struct regulator_desc *reg_desc; | ||
368 | }; | 379 | }; |
369 | 380 | ||
381 | /* Regulator ops */ | ||
382 | |||
383 | extern struct regulator_ops pmbus_regulator_ops; | ||
384 | |||
385 | /* Macro for filling in array of struct regulator_desc */ | ||
386 | #define PMBUS_REGULATOR(_name, _id) \ | ||
387 | [_id] = { \ | ||
388 | .name = (_name # _id), \ | ||
389 | .id = (_id), \ | ||
390 | .of_match = of_match_ptr(_name # _id), \ | ||
391 | .regulators_node = of_match_ptr("regulators"), \ | ||
392 | .ops = &pmbus_regulator_ops, \ | ||
393 | .owner = THIS_MODULE, \ | ||
394 | } | ||
395 | |||
370 | /* Function declarations */ | 396 | /* Function declarations */ |
371 | 397 | ||
372 | void pmbus_clear_cache(struct i2c_client *client); | 398 | void pmbus_clear_cache(struct i2c_client *client); |
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index d6c3701eb7f9..f2e47c7dd808 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c | |||
@@ -29,6 +29,8 @@ | |||
29 | #include <linux/hwmon-sysfs.h> | 29 | #include <linux/hwmon-sysfs.h> |
30 | #include <linux/jiffies.h> | 30 | #include <linux/jiffies.h> |
31 | #include <linux/i2c/pmbus.h> | 31 | #include <linux/i2c/pmbus.h> |
32 | #include <linux/regulator/driver.h> | ||
33 | #include <linux/regulator/machine.h> | ||
32 | #include "pmbus.h" | 34 | #include "pmbus.h" |
33 | 35 | ||
34 | /* | 36 | /* |
@@ -1758,6 +1760,84 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data, | |||
1758 | return 0; | 1760 | return 0; |
1759 | } | 1761 | } |
1760 | 1762 | ||
1763 | #if IS_ENABLED(CONFIG_REGULATOR) | ||
1764 | static int pmbus_regulator_is_enabled(struct regulator_dev *rdev) | ||
1765 | { | ||
1766 | struct device *dev = rdev_get_dev(rdev); | ||
1767 | struct i2c_client *client = to_i2c_client(dev->parent); | ||
1768 | u8 page = rdev_get_id(rdev); | ||
1769 | int ret; | ||
1770 | |||
1771 | ret = pmbus_read_byte_data(client, page, PMBUS_OPERATION); | ||
1772 | if (ret < 0) | ||
1773 | return ret; | ||
1774 | |||
1775 | return !!(ret & PB_OPERATION_CONTROL_ON); | ||
1776 | } | ||
1777 | |||
1778 | static int _pmbus_regulator_on_off(struct regulator_dev *rdev, bool enable) | ||
1779 | { | ||
1780 | struct device *dev = rdev_get_dev(rdev); | ||
1781 | struct i2c_client *client = to_i2c_client(dev->parent); | ||
1782 | u8 page = rdev_get_id(rdev); | ||
1783 | |||
1784 | return pmbus_update_byte_data(client, page, PMBUS_OPERATION, | ||
1785 | PB_OPERATION_CONTROL_ON, | ||
1786 | enable ? PB_OPERATION_CONTROL_ON : 0); | ||
1787 | } | ||
1788 | |||
1789 | static int pmbus_regulator_enable(struct regulator_dev *rdev) | ||
1790 | { | ||
1791 | return _pmbus_regulator_on_off(rdev, 1); | ||
1792 | } | ||
1793 | |||
1794 | static int pmbus_regulator_disable(struct regulator_dev *rdev) | ||
1795 | { | ||
1796 | return _pmbus_regulator_on_off(rdev, 0); | ||
1797 | } | ||
1798 | |||
1799 | struct regulator_ops pmbus_regulator_ops = { | ||
1800 | .enable = pmbus_regulator_enable, | ||
1801 | .disable = pmbus_regulator_disable, | ||
1802 | .is_enabled = pmbus_regulator_is_enabled, | ||
1803 | }; | ||
1804 | EXPORT_SYMBOL_GPL(pmbus_regulator_ops); | ||
1805 | |||
1806 | static int pmbus_regulator_register(struct pmbus_data *data) | ||
1807 | { | ||
1808 | struct device *dev = data->dev; | ||
1809 | const struct pmbus_driver_info *info = data->info; | ||
1810 | const struct pmbus_platform_data *pdata = dev_get_platdata(dev); | ||
1811 | struct regulator_dev *rdev; | ||
1812 | int i; | ||
1813 | |||
1814 | for (i = 0; i < info->num_regulators; i++) { | ||
1815 | struct regulator_config config = { }; | ||
1816 | |||
1817 | config.dev = dev; | ||
1818 | config.driver_data = data; | ||
1819 | |||
1820 | if (pdata && pdata->reg_init_data) | ||
1821 | config.init_data = &pdata->reg_init_data[i]; | ||
1822 | |||
1823 | rdev = devm_regulator_register(dev, &info->reg_desc[i], | ||
1824 | &config); | ||
1825 | if (IS_ERR(rdev)) { | ||
1826 | dev_err(dev, "Failed to register %s regulator\n", | ||
1827 | info->reg_desc[i].name); | ||
1828 | return PTR_ERR(rdev); | ||
1829 | } | ||
1830 | } | ||
1831 | |||
1832 | return 0; | ||
1833 | } | ||
1834 | #else | ||
1835 | static int pmbus_regulator_register(struct pmbus_data *data) | ||
1836 | { | ||
1837 | return 0; | ||
1838 | } | ||
1839 | #endif | ||
1840 | |||
1761 | int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id, | 1841 | int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id, |
1762 | struct pmbus_driver_info *info) | 1842 | struct pmbus_driver_info *info) |
1763 | { | 1843 | { |
@@ -1812,8 +1892,15 @@ int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id, | |||
1812 | dev_err(dev, "Failed to register hwmon device\n"); | 1892 | dev_err(dev, "Failed to register hwmon device\n"); |
1813 | goto out_kfree; | 1893 | goto out_kfree; |
1814 | } | 1894 | } |
1895 | |||
1896 | ret = pmbus_regulator_register(data); | ||
1897 | if (ret) | ||
1898 | goto out_unregister; | ||
1899 | |||
1815 | return 0; | 1900 | return 0; |
1816 | 1901 | ||
1902 | out_unregister: | ||
1903 | hwmon_device_unregister(data->hwmon_dev); | ||
1817 | out_kfree: | 1904 | out_kfree: |
1818 | kfree(data->group.attrs); | 1905 | kfree(data->group.attrs); |
1819 | return ret; | 1906 | return ret; |