Mark Brown | fb6c023 | 2009-07-20 12:43:45 +0100 | [diff] [blame] | 1 | /* |
| 2 | * drivers/hwmon/wm8350-hwmon.c - Wolfson Microelectronics WM8350 PMIC |
| 3 | * hardware monitoring features. |
| 4 | * |
| 5 | * Copyright (C) 2009 Wolfson Microelectronics plc |
| 6 | * |
| 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. |
| 10 | * |
| 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 |
| 14 | * more details. |
| 15 | * |
| 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 |
| 19 | */ |
| 20 | |
| 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> |
| 27 | |
| 28 | #include <linux/mfd/wm8350/core.h> |
| 29 | #include <linux/mfd/wm8350/comparator.h> |
| 30 | |
Guenter Roeck | a68abd3 | 2012-01-20 09:43:54 -0800 | [diff] [blame] | 31 | static const char * const input_names[] = { |
Mark Brown | fb6c023 | 2009-07-20 12:43:45 +0100 | [diff] [blame] | 32 | [WM8350_AUXADC_USB] = "USB", |
| 33 | [WM8350_AUXADC_LINE] = "Line", |
| 34 | [WM8350_AUXADC_BATT] = "Battery", |
| 35 | }; |
| 36 | |
Mark Brown | fb6c023 | 2009-07-20 12:43:45 +0100 | [diff] [blame] | 37 | static ssize_t show_voltage(struct device *dev, |
| 38 | struct device_attribute *attr, char *buf) |
| 39 | { |
| 40 | struct wm8350 *wm8350 = dev_get_drvdata(dev); |
| 41 | int channel = to_sensor_dev_attr(attr)->index; |
| 42 | int val; |
| 43 | |
| 44 | val = wm8350_read_auxadc(wm8350, channel, 0, 0) * WM8350_AUX_COEFF; |
| 45 | val = DIV_ROUND_CLOSEST(val, 1000); |
| 46 | |
| 47 | return sprintf(buf, "%d\n", val); |
| 48 | } |
| 49 | |
| 50 | static ssize_t show_label(struct device *dev, |
| 51 | struct device_attribute *attr, char *buf) |
| 52 | { |
| 53 | int channel = to_sensor_dev_attr(attr)->index; |
| 54 | |
| 55 | return sprintf(buf, "%s\n", input_names[channel]); |
| 56 | } |
| 57 | |
| 58 | #define WM8350_NAMED_VOLTAGE(id, name) \ |
| 59 | static SENSOR_DEVICE_ATTR(in##id##_input, S_IRUGO, show_voltage,\ |
| 60 | NULL, name); \ |
| 61 | static SENSOR_DEVICE_ATTR(in##id##_label, S_IRUGO, show_label, \ |
| 62 | NULL, name) |
| 63 | |
Mark Brown | fb6c023 | 2009-07-20 12:43:45 +0100 | [diff] [blame] | 64 | WM8350_NAMED_VOLTAGE(0, WM8350_AUXADC_USB); |
| 65 | WM8350_NAMED_VOLTAGE(1, WM8350_AUXADC_BATT); |
| 66 | WM8350_NAMED_VOLTAGE(2, WM8350_AUXADC_LINE); |
| 67 | |
Axel Lin | b3aabd6 | 2014-06-17 23:12:08 +0800 | [diff] [blame] | 68 | static struct attribute *wm8350_attrs[] = { |
Mark Brown | fb6c023 | 2009-07-20 12:43:45 +0100 | [diff] [blame] | 69 | &sensor_dev_attr_in0_input.dev_attr.attr, |
| 70 | &sensor_dev_attr_in0_label.dev_attr.attr, |
| 71 | &sensor_dev_attr_in1_input.dev_attr.attr, |
| 72 | &sensor_dev_attr_in1_label.dev_attr.attr, |
| 73 | &sensor_dev_attr_in2_input.dev_attr.attr, |
| 74 | &sensor_dev_attr_in2_label.dev_attr.attr, |
| 75 | |
| 76 | NULL, |
| 77 | }; |
| 78 | |
Axel Lin | b3aabd6 | 2014-06-17 23:12:08 +0800 | [diff] [blame] | 79 | ATTRIBUTE_GROUPS(wm8350); |
Mark Brown | fb6c023 | 2009-07-20 12:43:45 +0100 | [diff] [blame] | 80 | |
Bill Pemberton | 6c931ae | 2012-11-19 13:22:35 -0500 | [diff] [blame] | 81 | static int wm8350_hwmon_probe(struct platform_device *pdev) |
Mark Brown | fb6c023 | 2009-07-20 12:43:45 +0100 | [diff] [blame] | 82 | { |
| 83 | struct wm8350 *wm8350 = platform_get_drvdata(pdev); |
Axel Lin | b3aabd6 | 2014-06-17 23:12:08 +0800 | [diff] [blame] | 84 | struct device *hwmon_dev; |
Mark Brown | fb6c023 | 2009-07-20 12:43:45 +0100 | [diff] [blame] | 85 | |
Axel Lin | b3aabd6 | 2014-06-17 23:12:08 +0800 | [diff] [blame] | 86 | hwmon_dev = devm_hwmon_device_register_with_groups(&pdev->dev, "wm8350", |
| 87 | wm8350, |
| 88 | wm8350_groups); |
| 89 | return PTR_ERR_OR_ZERO(hwmon_dev); |
Mark Brown | fb6c023 | 2009-07-20 12:43:45 +0100 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | static struct platform_driver wm8350_hwmon_driver = { |
| 93 | .probe = wm8350_hwmon_probe, |
Mark Brown | fb6c023 | 2009-07-20 12:43:45 +0100 | [diff] [blame] | 94 | .driver = { |
| 95 | .name = "wm8350-hwmon", |
| 96 | .owner = THIS_MODULE, |
| 97 | }, |
| 98 | }; |
| 99 | |
Axel Lin | 25a236a | 2011-11-25 02:31:00 -0500 | [diff] [blame] | 100 | module_platform_driver(wm8350_hwmon_driver); |
Mark Brown | fb6c023 | 2009-07-20 12:43:45 +0100 | [diff] [blame] | 101 | |
| 102 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); |
| 103 | MODULE_DESCRIPTION("WM8350 Hardware Monitoring"); |
| 104 | MODULE_LICENSE("GPL"); |
| 105 | MODULE_ALIAS("platform:wm8350-hwmon"); |