wm8350-hwmon.c (bf61c8840efe60fd8f91446860b63338fb424158) | wm8350-hwmon.c (b3aabd6db3700dfa6ab334c96cbf16c04929b8a2) |
---|---|
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 --- 14 unchanged lines hidden (view full) --- 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 | 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 --- 14 unchanged lines hidden (view full) --- 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 |
31static ssize_t show_name(struct device *dev, 32 struct device_attribute *attr, char *buf) 33{ 34 return sprintf(buf, "wm8350\n"); 35} 36 | |
37static const char * const input_names[] = { 38 [WM8350_AUXADC_USB] = "USB", 39 [WM8350_AUXADC_LINE] = "Line", 40 [WM8350_AUXADC_BATT] = "Battery", 41}; 42 | 31static const char * const input_names[] = { 32 [WM8350_AUXADC_USB] = "USB", 33 [WM8350_AUXADC_LINE] = "Line", 34 [WM8350_AUXADC_BATT] = "Battery", 35}; 36 |
43 | |
44static ssize_t show_voltage(struct device *dev, 45 struct device_attribute *attr, char *buf) 46{ 47 struct wm8350 *wm8350 = dev_get_drvdata(dev); 48 int channel = to_sensor_dev_attr(attr)->index; 49 int val; 50 51 val = wm8350_read_auxadc(wm8350, channel, 0, 0) * WM8350_AUX_COEFF; --- 11 unchanged lines hidden (view full) --- 63} 64 65#define WM8350_NAMED_VOLTAGE(id, name) \ 66 static SENSOR_DEVICE_ATTR(in##id##_input, S_IRUGO, show_voltage,\ 67 NULL, name); \ 68 static SENSOR_DEVICE_ATTR(in##id##_label, S_IRUGO, show_label, \ 69 NULL, name) 70 | 37static 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; --- 11 unchanged lines hidden (view full) --- 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 |
71static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); 72 | |
73WM8350_NAMED_VOLTAGE(0, WM8350_AUXADC_USB); 74WM8350_NAMED_VOLTAGE(1, WM8350_AUXADC_BATT); 75WM8350_NAMED_VOLTAGE(2, WM8350_AUXADC_LINE); 76 | 64WM8350_NAMED_VOLTAGE(0, WM8350_AUXADC_USB); 65WM8350_NAMED_VOLTAGE(1, WM8350_AUXADC_BATT); 66WM8350_NAMED_VOLTAGE(2, WM8350_AUXADC_LINE); 67 |
77static struct attribute *wm8350_attributes[] = { 78 &dev_attr_name.attr, 79 | 68static struct attribute *wm8350_attrs[] = { |
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, 86 87 NULL, 88}; 89 | 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 |
90static const struct attribute_group wm8350_attr_group = { 91 .attrs = wm8350_attributes, 92}; | 79ATTRIBUTE_GROUPS(wm8350); |
93 94static int wm8350_hwmon_probe(struct platform_device *pdev) 95{ 96 struct wm8350 *wm8350 = platform_get_drvdata(pdev); | 80 81static int wm8350_hwmon_probe(struct platform_device *pdev) 82{ 83 struct wm8350 *wm8350 = platform_get_drvdata(pdev); |
97 int ret; | 84 struct device *hwmon_dev; |
98 | 85 |
99 ret = sysfs_create_group(&pdev->dev.kobj, &wm8350_attr_group); 100 if (ret) 101 goto err; 102 103 wm8350->hwmon.classdev = hwmon_device_register(&pdev->dev); 104 if (IS_ERR(wm8350->hwmon.classdev)) { 105 ret = PTR_ERR(wm8350->hwmon.classdev); 106 goto err_group; 107 } 108 109 return 0; 110 111err_group: 112 sysfs_remove_group(&pdev->dev.kobj, &wm8350_attr_group); 113err: 114 return ret; | 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); |
115} 116 | 90} 91 |
117static int wm8350_hwmon_remove(struct platform_device *pdev) 118{ 119 struct wm8350 *wm8350 = platform_get_drvdata(pdev); 120 121 hwmon_device_unregister(wm8350->hwmon.classdev); 122 sysfs_remove_group(&pdev->dev.kobj, &wm8350_attr_group); 123 124 return 0; 125} 126 | |
127static struct platform_driver wm8350_hwmon_driver = { 128 .probe = wm8350_hwmon_probe, | 92static struct platform_driver wm8350_hwmon_driver = { 93 .probe = wm8350_hwmon_probe, |
129 .remove = wm8350_hwmon_remove, | |
130 .driver = { 131 .name = "wm8350-hwmon", 132 .owner = THIS_MODULE, 133 }, 134}; 135 136module_platform_driver(wm8350_hwmon_driver); 137 138MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); 139MODULE_DESCRIPTION("WM8350 Hardware Monitoring"); 140MODULE_LICENSE("GPL"); 141MODULE_ALIAS("platform:wm8350-hwmon"); | 94 .driver = { 95 .name = "wm8350-hwmon", 96 .owner = THIS_MODULE, 97 }, 98}; 99 100module_platform_driver(wm8350_hwmon_driver); 101 102MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); 103MODULE_DESCRIPTION("WM8350 Hardware Monitoring"); 104MODULE_LICENSE("GPL"); 105MODULE_ALIAS("platform:wm8350-hwmon"); |