2 * drivers/hwmon/wm8350-hwmon.c - Wolfson Microelectronics WM8350 PMIC
3 * hardware monitoring features.
5 * Copyright (C) 2009 Wolfson Microelectronics plc
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License v2 as published by the
9 * Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <linux/kernel.h>
22 #include <linux/module.h>
23 #include <linux/err.h>
24 #include <linux/platform_device.h>
25 #include <linux/hwmon.h>
26 #include <linux/hwmon-sysfs.h>
28 #include <linux/mfd/wm8350/core.h>
29 #include <linux/mfd/wm8350/comparator.h>
31 static ssize_t show_name(struct device *dev,
32 struct device_attribute *attr, char *buf)
34 return sprintf(buf, "wm8350\n");
37 static const char *input_names[] = {
38 [WM8350_AUXADC_USB] = "USB",
39 [WM8350_AUXADC_LINE] = "Line",
40 [WM8350_AUXADC_BATT] = "Battery",
44 static ssize_t show_voltage(struct device *dev,
45 struct device_attribute *attr, char *buf)
47 struct wm8350 *wm8350 = dev_get_drvdata(dev);
48 int channel = to_sensor_dev_attr(attr)->index;
51 val = wm8350_read_auxadc(wm8350, channel, 0, 0) * WM8350_AUX_COEFF;
52 val = DIV_ROUND_CLOSEST(val, 1000);
54 return sprintf(buf, "%d\n", val);
57 static ssize_t show_label(struct device *dev,
58 struct device_attribute *attr, char *buf)
60 int channel = to_sensor_dev_attr(attr)->index;
62 return sprintf(buf, "%s\n", input_names[channel]);
65 #define WM8350_NAMED_VOLTAGE(id, name) \
66 static SENSOR_DEVICE_ATTR(in##id##_input, S_IRUGO, show_voltage,\
68 static SENSOR_DEVICE_ATTR(in##id##_label, S_IRUGO, show_label, \
71 static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
73 WM8350_NAMED_VOLTAGE(0, WM8350_AUXADC_USB);
74 WM8350_NAMED_VOLTAGE(1, WM8350_AUXADC_BATT);
75 WM8350_NAMED_VOLTAGE(2, WM8350_AUXADC_LINE);
77 static struct attribute *wm8350_attributes[] = {
80 &sensor_dev_attr_in0_input.dev_attr.attr,
81 &sensor_dev_attr_in0_label.dev_attr.attr,
82 &sensor_dev_attr_in1_input.dev_attr.attr,
83 &sensor_dev_attr_in1_label.dev_attr.attr,
84 &sensor_dev_attr_in2_input.dev_attr.attr,
85 &sensor_dev_attr_in2_label.dev_attr.attr,
90 static const struct attribute_group wm8350_attr_group = {
91 .attrs = wm8350_attributes,
94 static int __devinit wm8350_hwmon_probe(struct platform_device *pdev)
96 struct wm8350 *wm8350 = platform_get_drvdata(pdev);
99 ret = sysfs_create_group(&pdev->dev.kobj, &wm8350_attr_group);
103 wm8350->hwmon.classdev = hwmon_device_register(&pdev->dev);
104 if (IS_ERR(wm8350->hwmon.classdev)) {
105 ret = PTR_ERR(wm8350->hwmon.classdev);
112 sysfs_remove_group(&pdev->dev.kobj, &wm8350_attr_group);
117 static int __devexit wm8350_hwmon_remove(struct platform_device *pdev)
119 struct wm8350 *wm8350 = platform_get_drvdata(pdev);
121 hwmon_device_unregister(wm8350->hwmon.classdev);
122 sysfs_remove_group(&pdev->dev.kobj, &wm8350_attr_group);
127 static struct platform_driver wm8350_hwmon_driver = {
128 .probe = wm8350_hwmon_probe,
129 .remove = __devexit_p(wm8350_hwmon_remove),
131 .name = "wm8350-hwmon",
132 .owner = THIS_MODULE,
136 static int __init wm8350_hwmon_init(void)
138 return platform_driver_register(&wm8350_hwmon_driver);
140 module_init(wm8350_hwmon_init);
142 static void __exit wm8350_hwmon_exit(void)
144 platform_driver_unregister(&wm8350_hwmon_driver);
146 module_exit(wm8350_hwmon_exit);
148 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
149 MODULE_DESCRIPTION("WM8350 Hardware Monitoring");
150 MODULE_LICENSE("GPL");
151 MODULE_ALIAS("platform:wm8350-hwmon");