aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorPunit Agrawal <punit.agrawal@arm.com>2015-05-21 10:08:45 -0400
committerSudeep Holla <sudeep.holla@arm.com>2015-10-09 06:05:52 -0400
commitea98b29a05e9c70dbe159cbc6254d111059a2bb9 (patch)
tree92303c920a7515ebdee52bd89453cf939a7bb105 /drivers/hwmon
parent38a1bdc9ff9f6c8cfad228eac5c1ce31ce038b25 (diff)
hwmon: Support sensors exported via ARM SCP interface
Create a driver to add support for SoC sensors exported by the System Control Processor (SCP) via the System Control and Power Interface (SCPI). The supported sensor types is one of voltage, temperature, current, and power. The sensor labels and values provided by the SCP are exported via the hwmon sysfs interface. Signed-off-by: Punit Agrawal <punit.agrawal@arm.com> Acked-by: Guenter Roeck <linux@roeck-us.net> Cc: Sudeep Holla <sudeep.holla@arm.com>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/Kconfig8
-rw-r--r--drivers/hwmon/Makefile1
-rw-r--r--drivers/hwmon/scpi-hwmon.c186
3 files changed, 195 insertions, 0 deletions
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 500b262b89bb..4663693b58f6 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -321,6 +321,14 @@ config SENSORS_APPLESMC
321 Say Y here if you have an applicable laptop and want to experience 321 Say Y here if you have an applicable laptop and want to experience
322 the awesome power of applesmc. 322 the awesome power of applesmc.
323 323
324config SENSORS_ARM_SCPI
325 tristate "ARM SCPI Sensors"
326 depends on ARM_SCPI_PROTOCOL
327 help
328 This driver provides support for temperature, voltage, current
329 and power sensors available on ARM Ltd's SCP based platforms. The
330 actual number and type of sensors exported depend on the platform.
331
324config SENSORS_ASB100 332config SENSORS_ASB100
325 tristate "Asus ASB100 Bach" 333 tristate "Asus ASB100 Bach"
326 depends on X86 && I2C 334 depends on X86 && I2C
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 9e0f3dd2841d..66e7a4715da7 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -44,6 +44,7 @@ obj-$(CONFIG_SENSORS_ADT7462) += adt7462.o
44obj-$(CONFIG_SENSORS_ADT7470) += adt7470.o 44obj-$(CONFIG_SENSORS_ADT7470) += adt7470.o
45obj-$(CONFIG_SENSORS_ADT7475) += adt7475.o 45obj-$(CONFIG_SENSORS_ADT7475) += adt7475.o
46obj-$(CONFIG_SENSORS_APPLESMC) += applesmc.o 46obj-$(CONFIG_SENSORS_APPLESMC) += applesmc.o
47obj-$(CONFIG_SENSORS_ARM_SCPI) += scpi-hwmon.o
47obj-$(CONFIG_SENSORS_ASC7621) += asc7621.o 48obj-$(CONFIG_SENSORS_ASC7621) += asc7621.o
48obj-$(CONFIG_SENSORS_ATXP1) += atxp1.o 49obj-$(CONFIG_SENSORS_ATXP1) += atxp1.o
49obj-$(CONFIG_SENSORS_CORETEMP) += coretemp.o 50obj-$(CONFIG_SENSORS_CORETEMP) += coretemp.o
diff --git a/drivers/hwmon/scpi-hwmon.c b/drivers/hwmon/scpi-hwmon.c
new file mode 100644
index 000000000000..c7d1d1423427
--- /dev/null
+++ b/drivers/hwmon/scpi-hwmon.c
@@ -0,0 +1,186 @@
1/*
2 * System Control and Power Interface(SCPI) based hwmon sensor driver
3 *
4 * Copyright (C) 2015 ARM Ltd.
5 * Punit Agrawal <punit.agrawal@arm.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
12 * kind, whether express or implied; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */
16
17#include <linux/hwmon.h>
18#include <linux/module.h>
19#include <linux/platform_device.h>
20#include <linux/scpi_protocol.h>
21#include <linux/slab.h>
22#include <linux/sysfs.h>
23
24struct sensor_data {
25 struct scpi_sensor_info info;
26 struct device_attribute dev_attr_input;
27 struct device_attribute dev_attr_label;
28 char input[20];
29 char label[20];
30};
31
32struct scpi_sensors {
33 struct scpi_ops *scpi_ops;
34 struct sensor_data *data;
35 struct attribute **attrs;
36 struct attribute_group group;
37 const struct attribute_group *groups[2];
38};
39
40/* hwmon callback functions */
41static ssize_t
42scpi_show_sensor(struct device *dev, struct device_attribute *attr, char *buf)
43{
44 struct scpi_sensors *scpi_sensors = dev_get_drvdata(dev);
45 struct scpi_ops *scpi_ops = scpi_sensors->scpi_ops;
46 struct sensor_data *sensor;
47 u32 value;
48 int ret;
49
50 sensor = container_of(attr, struct sensor_data, dev_attr_input);
51
52 ret = scpi_ops->sensor_get_value(sensor->info.sensor_id, &value);
53 if (ret)
54 return ret;
55
56 return sprintf(buf, "%u\n", value);
57}
58
59static ssize_t
60scpi_show_label(struct device *dev, struct device_attribute *attr, char *buf)
61{
62 struct sensor_data *sensor;
63
64 sensor = container_of(attr, struct sensor_data, dev_attr_label);
65
66 return sprintf(buf, "%s\n", sensor->info.name);
67}
68
69static int scpi_hwmon_probe(struct platform_device *pdev)
70{
71 u16 nr_sensors, i;
72 int num_temp = 0, num_volt = 0, num_current = 0, num_power = 0;
73 struct scpi_ops *scpi_ops;
74 struct device *hwdev, *dev = &pdev->dev;
75 struct scpi_sensors *scpi_sensors;
76 int ret;
77
78 scpi_ops = get_scpi_ops();
79 if (!scpi_ops)
80 return -EPROBE_DEFER;
81
82 ret = scpi_ops->sensor_get_capability(&nr_sensors);
83 if (ret)
84 return ret;
85
86 if (!nr_sensors)
87 return -ENODEV;
88
89 scpi_sensors = devm_kzalloc(dev, sizeof(*scpi_sensors), GFP_KERNEL);
90 if (!scpi_sensors)
91 return -ENOMEM;
92
93 scpi_sensors->data = devm_kcalloc(dev, nr_sensors,
94 sizeof(*scpi_sensors->data), GFP_KERNEL);
95 if (!scpi_sensors->data)
96 return -ENOMEM;
97
98 scpi_sensors->attrs = devm_kcalloc(dev, (nr_sensors * 2) + 1,
99 sizeof(*scpi_sensors->attrs), GFP_KERNEL);
100 if (!scpi_sensors->attrs)
101 return -ENOMEM;
102
103 scpi_sensors->scpi_ops = scpi_ops;
104
105 for (i = 0; i < nr_sensors; i++) {
106 struct sensor_data *sensor = &scpi_sensors->data[i];
107
108 ret = scpi_ops->sensor_get_info(i, &sensor->info);
109 if (ret)
110 return ret;
111
112 switch (sensor->info.class) {
113 case TEMPERATURE:
114 snprintf(sensor->input, sizeof(sensor->input),
115 "temp%d_input", num_temp + 1);
116 snprintf(sensor->label, sizeof(sensor->input),
117 "temp%d_label", num_temp + 1);
118 num_temp++;
119 break;
120 case VOLTAGE:
121 snprintf(sensor->input, sizeof(sensor->input),
122 "in%d_input", num_volt);
123 snprintf(sensor->label, sizeof(sensor->input),
124 "in%d_label", num_volt);
125 num_volt++;
126 break;
127 case CURRENT:
128 snprintf(sensor->input, sizeof(sensor->input),
129 "curr%d_input", num_current + 1);
130 snprintf(sensor->label, sizeof(sensor->input),
131 "curr%d_label", num_current + 1);
132 num_current++;
133 break;
134 case POWER:
135 snprintf(sensor->input, sizeof(sensor->input),
136 "power%d_input", num_power + 1);
137 snprintf(sensor->label, sizeof(sensor->input),
138 "power%d_label", num_power + 1);
139 num_power++;
140 break;
141 default:
142 break;
143 }
144
145 sensor->dev_attr_input.attr.mode = S_IRUGO;
146 sensor->dev_attr_input.show = scpi_show_sensor;
147 sensor->dev_attr_input.attr.name = sensor->input;
148
149 sensor->dev_attr_label.attr.mode = S_IRUGO;
150 sensor->dev_attr_label.show = scpi_show_label;
151 sensor->dev_attr_label.attr.name = sensor->label;
152
153 scpi_sensors->attrs[i << 1] = &sensor->dev_attr_input.attr;
154 scpi_sensors->attrs[(i << 1) + 1] = &sensor->dev_attr_label.attr;
155
156 sysfs_attr_init(scpi_sensors->attrs[i << 1]);
157 sysfs_attr_init(scpi_sensors->attrs[(i << 1) + 1]);
158 }
159
160 scpi_sensors->group.attrs = scpi_sensors->attrs;
161 scpi_sensors->groups[0] = &scpi_sensors->group;
162
163 hwdev = devm_hwmon_device_register_with_groups(dev,
164 "scpi_sensors", scpi_sensors, scpi_sensors->groups);
165
166 return PTR_ERR_OR_ZERO(hwdev);
167}
168
169static const struct of_device_id scpi_of_match[] = {
170 {.compatible = "arm,scpi-sensors"},
171 {},
172};
173
174static struct platform_driver scpi_hwmon_platdrv = {
175 .driver = {
176 .name = "scpi-hwmon",
177 .owner = THIS_MODULE,
178 .of_match_table = scpi_of_match,
179 },
180 .probe = scpi_hwmon_probe,
181};
182module_platform_driver(scpi_hwmon_platdrv);
183
184MODULE_AUTHOR("Punit Agrawal <punit.agrawal@arm.com>");
185MODULE_DESCRIPTION("ARM SCPI HWMON interface driver");
186MODULE_LICENSE("GPL v2");