0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <linux/kernel.h>
0010 #include <linux/module.h>
0011 #include <linux/err.h>
0012 #include <linux/platform_device.h>
0013 #include <linux/hwmon.h>
0014 #include <linux/hwmon-sysfs.h>
0015
0016 #include <linux/mfd/wm8350/core.h>
0017 #include <linux/mfd/wm8350/comparator.h>
0018
0019 static const char * const input_names[] = {
0020 [WM8350_AUXADC_USB] = "USB",
0021 [WM8350_AUXADC_LINE] = "Line",
0022 [WM8350_AUXADC_BATT] = "Battery",
0023 };
0024
0025 static ssize_t show_voltage(struct device *dev,
0026 struct device_attribute *attr, char *buf)
0027 {
0028 struct wm8350 *wm8350 = dev_get_drvdata(dev);
0029 int channel = to_sensor_dev_attr(attr)->index;
0030 int val;
0031
0032 val = wm8350_read_auxadc(wm8350, channel, 0, 0) * WM8350_AUX_COEFF;
0033 val = DIV_ROUND_CLOSEST(val, 1000);
0034
0035 return sprintf(buf, "%d\n", val);
0036 }
0037
0038 static ssize_t show_label(struct device *dev,
0039 struct device_attribute *attr, char *buf)
0040 {
0041 int channel = to_sensor_dev_attr(attr)->index;
0042
0043 return sprintf(buf, "%s\n", input_names[channel]);
0044 }
0045
0046 #define WM8350_NAMED_VOLTAGE(id, name) \
0047 static SENSOR_DEVICE_ATTR(in##id##_input, S_IRUGO, show_voltage,\
0048 NULL, name); \
0049 static SENSOR_DEVICE_ATTR(in##id##_label, S_IRUGO, show_label, \
0050 NULL, name)
0051
0052 WM8350_NAMED_VOLTAGE(0, WM8350_AUXADC_USB);
0053 WM8350_NAMED_VOLTAGE(1, WM8350_AUXADC_BATT);
0054 WM8350_NAMED_VOLTAGE(2, WM8350_AUXADC_LINE);
0055
0056 static struct attribute *wm8350_attrs[] = {
0057 &sensor_dev_attr_in0_input.dev_attr.attr,
0058 &sensor_dev_attr_in0_label.dev_attr.attr,
0059 &sensor_dev_attr_in1_input.dev_attr.attr,
0060 &sensor_dev_attr_in1_label.dev_attr.attr,
0061 &sensor_dev_attr_in2_input.dev_attr.attr,
0062 &sensor_dev_attr_in2_label.dev_attr.attr,
0063
0064 NULL,
0065 };
0066
0067 ATTRIBUTE_GROUPS(wm8350);
0068
0069 static int wm8350_hwmon_probe(struct platform_device *pdev)
0070 {
0071 struct wm8350 *wm8350 = platform_get_drvdata(pdev);
0072 struct device *hwmon_dev;
0073
0074 hwmon_dev = devm_hwmon_device_register_with_groups(&pdev->dev, "wm8350",
0075 wm8350,
0076 wm8350_groups);
0077 return PTR_ERR_OR_ZERO(hwmon_dev);
0078 }
0079
0080 static struct platform_driver wm8350_hwmon_driver = {
0081 .probe = wm8350_hwmon_probe,
0082 .driver = {
0083 .name = "wm8350-hwmon",
0084 },
0085 };
0086
0087 module_platform_driver(wm8350_hwmon_driver);
0088
0089 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
0090 MODULE_DESCRIPTION("WM8350 Hardware Monitoring");
0091 MODULE_LICENSE("GPL");
0092 MODULE_ALIAS("platform:wm8350-hwmon");