summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2019-07-01 14:12:38 -0400
committerGuenter Roeck <linux@roeck-us.net>2019-09-03 15:47:17 -0400
commit2c9d5b5e32a2516ae9b1120c7688ea25ffee7805 (patch)
tree4f357bfad28b8e6dd96d0367fedcfdff5bb0c372
parente027a2dea5fdde05740a98f571fc2903060559ce (diff)
hwmon: Remove ads1015 driver
A driver for ADS1015 with more functionality is available in the iio subsystem. Remove the hwmon driver as duplicate. If the chip is used for hardware monitoring, the iio->hwmon bridge should be used. Cc: Dirk Eibach <eibach@gdsys.de> Link: https://lore.kernel.org/r/1562004758-13025-1-git-send-email-linux@roeck-us.net Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Acked-by: Rob Herring <robh@kernel.org> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r--Documentation/devicetree/bindings/iio/adc/ads1015.txt (renamed from Documentation/devicetree/bindings/hwmon/ads1015.txt)0
-rw-r--r--Documentation/hwmon/ads1015.rst90
-rw-r--r--Documentation/hwmon/index.rst1
-rw-r--r--MAINTAINERS8
-rw-r--r--drivers/hwmon/Kconfig10
-rw-r--r--drivers/hwmon/Makefile1
-rw-r--r--drivers/hwmon/ads1015.c324
-rw-r--r--drivers/iio/adc/Kconfig2
8 files changed, 1 insertions, 435 deletions
diff --git a/Documentation/devicetree/bindings/hwmon/ads1015.txt b/Documentation/devicetree/bindings/iio/adc/ads1015.txt
index 918a507d1159..918a507d1159 100644
--- a/Documentation/devicetree/bindings/hwmon/ads1015.txt
+++ b/Documentation/devicetree/bindings/iio/adc/ads1015.txt
diff --git a/Documentation/hwmon/ads1015.rst b/Documentation/hwmon/ads1015.rst
deleted file mode 100644
index e0951c4e57bb..000000000000
--- a/Documentation/hwmon/ads1015.rst
+++ /dev/null
@@ -1,90 +0,0 @@
1Kernel driver ads1015
2=====================
3
4Supported chips:
5
6 * Texas Instruments ADS1015
7
8 Prefix: 'ads1015'
9
10 Datasheet: Publicly available at the Texas Instruments website:
11
12 http://focus.ti.com/lit/ds/symlink/ads1015.pdf
13
14 * Texas Instruments ADS1115
15
16 Prefix: 'ads1115'
17
18 Datasheet: Publicly available at the Texas Instruments website:
19
20 http://focus.ti.com/lit/ds/symlink/ads1115.pdf
21
22Authors:
23 Dirk Eibach, Guntermann & Drunck GmbH <eibach@gdsys.de>
24
25Description
26-----------
27
28This driver implements support for the Texas Instruments ADS1015/ADS1115.
29
30This device is a 12/16-bit A-D converter with 4 inputs.
31
32The inputs can be used single ended or in certain differential combinations.
33
34The inputs can be made available by 8 sysfs input files in0_input - in7_input:
35
36 - in0: Voltage over AIN0 and AIN1.
37 - in1: Voltage over AIN0 and AIN3.
38 - in2: Voltage over AIN1 and AIN3.
39 - in3: Voltage over AIN2 and AIN3.
40 - in4: Voltage over AIN0 and GND.
41 - in5: Voltage over AIN1 and GND.
42 - in6: Voltage over AIN2 and GND.
43 - in7: Voltage over AIN3 and GND.
44
45Which inputs are available can be configured using platform data or devicetree.
46
47By default all inputs are exported.
48
49Platform Data
50-------------
51
52In linux/platform_data/ads1015.h platform data is defined, channel_data contains
53configuration data for the used input combinations:
54
55- pga is the programmable gain amplifier (values are full scale)
56
57 - 0: +/- 6.144 V
58 - 1: +/- 4.096 V
59 - 2: +/- 2.048 V
60 - 3: +/- 1.024 V
61 - 4: +/- 0.512 V
62 - 5: +/- 0.256 V
63
64- data_rate in samples per second
65
66 - 0: 128
67 - 1: 250
68 - 2: 490
69 - 3: 920
70 - 4: 1600
71 - 5: 2400
72 - 6: 3300
73
74Example::
75
76 struct ads1015_platform_data data = {
77 .channel_data = {
78 [2] = { .enabled = true, .pga = 1, .data_rate = 0 },
79 [4] = { .enabled = true, .pga = 4, .data_rate = 5 },
80 }
81 };
82
83In this case only in2_input (FS +/- 4.096 V, 128 SPS) and in4_input
84(FS +/- 0.512 V, 2400 SPS) would be created.
85
86Devicetree
87----------
88
89Configuration is also possible via devicetree:
90Documentation/devicetree/bindings/hwmon/ads1015.txt
diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst
index ee090e51653a..1d301d0e6f4d 100644
--- a/Documentation/hwmon/index.rst
+++ b/Documentation/hwmon/index.rst
@@ -30,7 +30,6 @@ Hardware Monitoring Kernel Drivers
30 adm1031 30 adm1031
31 adm1275 31 adm1275
32 adm9240 32 adm9240
33 ads1015
34 ads7828 33 ads7828
35 adt7410 34 adt7410
36 adt7411 35 adt7411
diff --git a/MAINTAINERS b/MAINTAINERS
index 9cbcf167bdd0..c7035ce2460b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -517,14 +517,6 @@ W: http://ez.analog.com/community/linux-device-drivers
517S: Supported 517S: Supported
518F: drivers/video/backlight/adp8860_bl.c 518F: drivers/video/backlight/adp8860_bl.c
519 519
520ADS1015 HARDWARE MONITOR DRIVER
521M: Dirk Eibach <eibach@gdsys.de>
522L: linux-hwmon@vger.kernel.org
523S: Maintained
524F: Documentation/hwmon/ads1015.rst
525F: drivers/hwmon/ads1015.c
526F: include/linux/platform_data/ads1015.h
527
528ADT746X FAN DRIVER 520ADT746X FAN DRIVER
529M: Colin Leroy <colin@colino.net> 521M: Colin Leroy <colin@colino.net>
530S: Maintained 522S: Maintained
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 650dd71f9724..76cd0647ee2c 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -1570,16 +1570,6 @@ config SENSORS_ADC128D818
1570 This driver can also be built as a module. If so, the module 1570 This driver can also be built as a module. If so, the module
1571 will be called adc128d818. 1571 will be called adc128d818.
1572 1572
1573config SENSORS_ADS1015
1574 tristate "Texas Instruments ADS1015"
1575 depends on I2C
1576 help
1577 If you say yes here you get support for Texas Instruments
1578 ADS1015/ADS1115 12/16-bit 4-input ADC device.
1579
1580 This driver can also be built as a module. If so, the module
1581 will be called ads1015.
1582
1583config SENSORS_ADS7828 1573config SENSORS_ADS7828
1584 tristate "Texas Instruments ADS7828 and compatibles" 1574 tristate "Texas Instruments ADS7828 and compatibles"
1585 depends on I2C 1575 depends on I2C
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 8db472ea04f0..6a52a964038b 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -35,7 +35,6 @@ obj-$(CONFIG_SENSORS_ADM1026) += adm1026.o
35obj-$(CONFIG_SENSORS_ADM1029) += adm1029.o 35obj-$(CONFIG_SENSORS_ADM1029) += adm1029.o
36obj-$(CONFIG_SENSORS_ADM1031) += adm1031.o 36obj-$(CONFIG_SENSORS_ADM1031) += adm1031.o
37obj-$(CONFIG_SENSORS_ADM9240) += adm9240.o 37obj-$(CONFIG_SENSORS_ADM9240) += adm9240.o
38obj-$(CONFIG_SENSORS_ADS1015) += ads1015.o
39obj-$(CONFIG_SENSORS_ADS7828) += ads7828.o 38obj-$(CONFIG_SENSORS_ADS7828) += ads7828.o
40obj-$(CONFIG_SENSORS_ADS7871) += ads7871.o 39obj-$(CONFIG_SENSORS_ADS7871) += ads7871.o
41obj-$(CONFIG_SENSORS_ADT7X10) += adt7x10.o 40obj-$(CONFIG_SENSORS_ADT7X10) += adt7x10.o
diff --git a/drivers/hwmon/ads1015.c b/drivers/hwmon/ads1015.c
deleted file mode 100644
index 3727a3762eb8..000000000000
--- a/drivers/hwmon/ads1015.c
+++ /dev/null
@@ -1,324 +0,0 @@
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * ads1015.c - lm_sensors driver for ads1015 12-bit 4-input ADC
4 * (C) Copyright 2010
5 * Dirk Eibach, Guntermann & Drunck GmbH <eibach@gdsys.de>
6 *
7 * Based on the ads7828 driver by Steve Hardy.
8 *
9 * Datasheet available at: http://focus.ti.com/lit/ds/symlink/ads1015.pdf
10 */
11
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/slab.h>
15#include <linux/delay.h>
16#include <linux/i2c.h>
17#include <linux/hwmon.h>
18#include <linux/hwmon-sysfs.h>
19#include <linux/err.h>
20#include <linux/mutex.h>
21#include <linux/of_device.h>
22#include <linux/of.h>
23
24#include <linux/platform_data/ads1015.h>
25
26/* ADS1015 registers */
27enum {
28 ADS1015_CONVERSION = 0,
29 ADS1015_CONFIG = 1,
30};
31
32/* PGA fullscale voltages in mV */
33static const unsigned int fullscale_table[8] = {
34 6144, 4096, 2048, 1024, 512, 256, 256, 256 };
35
36/* Data rates in samples per second */
37static const unsigned int data_rate_table_1015[8] = {
38 128, 250, 490, 920, 1600, 2400, 3300, 3300
39};
40
41static const unsigned int data_rate_table_1115[8] = {
42 8, 16, 32, 64, 128, 250, 475, 860
43};
44
45#define ADS1015_DEFAULT_CHANNELS 0xff
46#define ADS1015_DEFAULT_PGA 2
47#define ADS1015_DEFAULT_DATA_RATE 4
48
49enum ads1015_chips {
50 ads1015,
51 ads1115,
52};
53
54struct ads1015_data {
55 struct device *hwmon_dev;
56 struct mutex update_lock; /* mutex protect updates */
57 struct ads1015_channel_data channel_data[ADS1015_CHANNELS];
58 enum ads1015_chips id;
59};
60
61static int ads1015_read_adc(struct i2c_client *client, unsigned int channel)
62{
63 u16 config;
64 struct ads1015_data *data = i2c_get_clientdata(client);
65 unsigned int pga = data->channel_data[channel].pga;
66 unsigned int data_rate = data->channel_data[channel].data_rate;
67 unsigned int conversion_time_ms;
68 const unsigned int * const rate_table = data->id == ads1115 ?
69 data_rate_table_1115 : data_rate_table_1015;
70 int res;
71
72 mutex_lock(&data->update_lock);
73
74 /* get channel parameters */
75 res = i2c_smbus_read_word_swapped(client, ADS1015_CONFIG);
76 if (res < 0)
77 goto err_unlock;
78 config = res;
79 conversion_time_ms = DIV_ROUND_UP(1000, rate_table[data_rate]);
80
81 /* setup and start single conversion */
82 config &= 0x001f;
83 config |= (1 << 15) | (1 << 8);
84 config |= (channel & 0x0007) << 12;
85 config |= (pga & 0x0007) << 9;
86 config |= (data_rate & 0x0007) << 5;
87
88 res = i2c_smbus_write_word_swapped(client, ADS1015_CONFIG, config);
89 if (res < 0)
90 goto err_unlock;
91
92 /* wait until conversion finished */
93 msleep(conversion_time_ms);
94 res = i2c_smbus_read_word_swapped(client, ADS1015_CONFIG);
95 if (res < 0)
96 goto err_unlock;
97 config = res;
98 if (!(config & (1 << 15))) {
99 /* conversion not finished in time */
100 res = -EIO;
101 goto err_unlock;
102 }
103
104 res = i2c_smbus_read_word_swapped(client, ADS1015_CONVERSION);
105
106err_unlock:
107 mutex_unlock(&data->update_lock);
108 return res;
109}
110
111static int ads1015_reg_to_mv(struct i2c_client *client, unsigned int channel,
112 s16 reg)
113{
114 struct ads1015_data *data = i2c_get_clientdata(client);
115 unsigned int pga = data->channel_data[channel].pga;
116 int fullscale = fullscale_table[pga];
117 const int mask = data->id == ads1115 ? 0x7fff : 0x7ff0;
118
119 return DIV_ROUND_CLOSEST(reg * fullscale, mask);
120}
121
122/* sysfs callback function */
123static ssize_t in_show(struct device *dev, struct device_attribute *da,
124 char *buf)
125{
126 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
127 struct i2c_client *client = to_i2c_client(dev);
128 int res;
129 int index = attr->index;
130
131 res = ads1015_read_adc(client, index);
132 if (res < 0)
133 return res;
134
135 return sprintf(buf, "%d\n", ads1015_reg_to_mv(client, index, res));
136}
137
138static const struct sensor_device_attribute ads1015_in[] = {
139 SENSOR_ATTR_RO(in0_input, in, 0),
140 SENSOR_ATTR_RO(in1_input, in, 1),
141 SENSOR_ATTR_RO(in2_input, in, 2),
142 SENSOR_ATTR_RO(in3_input, in, 3),
143 SENSOR_ATTR_RO(in4_input, in, 4),
144 SENSOR_ATTR_RO(in5_input, in, 5),
145 SENSOR_ATTR_RO(in6_input, in, 6),
146 SENSOR_ATTR_RO(in7_input, in, 7),
147};
148
149/*
150 * Driver interface
151 */
152
153static int ads1015_remove(struct i2c_client *client)
154{
155 struct ads1015_data *data = i2c_get_clientdata(client);
156 int k;
157
158 hwmon_device_unregister(data->hwmon_dev);
159 for (k = 0; k < ADS1015_CHANNELS; ++k)
160 device_remove_file(&client->dev, &ads1015_in[k].dev_attr);
161 return 0;
162}
163
164#ifdef CONFIG_OF
165static int ads1015_get_channels_config_of(struct i2c_client *client)
166{
167 struct ads1015_data *data = i2c_get_clientdata(client);
168 struct device_node *node;
169
170 if (!client->dev.of_node
171 || !of_get_next_child(client->dev.of_node, NULL))
172 return -EINVAL;
173
174 for_each_child_of_node(client->dev.of_node, node) {
175 u32 pval;
176 unsigned int channel;
177 unsigned int pga = ADS1015_DEFAULT_PGA;
178 unsigned int data_rate = ADS1015_DEFAULT_DATA_RATE;
179
180 if (of_property_read_u32(node, "reg", &pval)) {
181 dev_err(&client->dev, "invalid reg on %pOF\n", node);
182 continue;
183 }
184
185 channel = pval;
186 if (channel >= ADS1015_CHANNELS) {
187 dev_err(&client->dev,
188 "invalid channel index %d on %pOF\n",
189 channel, node);
190 continue;
191 }
192
193 if (!of_property_read_u32(node, "ti,gain", &pval)) {
194 pga = pval;
195 if (pga > 6) {
196 dev_err(&client->dev, "invalid gain on %pOF\n",
197 node);
198 return -EINVAL;
199 }
200 }
201
202 if (!of_property_read_u32(node, "ti,datarate", &pval)) {
203 data_rate = pval;
204 if (data_rate > 7) {
205 dev_err(&client->dev,
206 "invalid data_rate on %pOF\n", node);
207 return -EINVAL;
208 }
209 }
210
211 data->channel_data[channel].enabled = true;
212 data->channel_data[channel].pga = pga;
213 data->channel_data[channel].data_rate = data_rate;
214 }
215
216 return 0;
217}
218#endif
219
220static void ads1015_get_channels_config(struct i2c_client *client)
221{
222 unsigned int k;
223 struct ads1015_data *data = i2c_get_clientdata(client);
224 struct ads1015_platform_data *pdata = dev_get_platdata(&client->dev);
225
226 /* prefer platform data */
227 if (pdata) {
228 memcpy(data->channel_data, pdata->channel_data,
229 sizeof(data->channel_data));
230 return;
231 }
232
233#ifdef CONFIG_OF
234 if (!ads1015_get_channels_config_of(client))
235 return;
236#endif
237
238 /* fallback on default configuration */
239 for (k = 0; k < ADS1015_CHANNELS; ++k) {
240 data->channel_data[k].enabled = true;
241 data->channel_data[k].pga = ADS1015_DEFAULT_PGA;
242 data->channel_data[k].data_rate = ADS1015_DEFAULT_DATA_RATE;
243 }
244}
245
246static int ads1015_probe(struct i2c_client *client,
247 const struct i2c_device_id *id)
248{
249 struct ads1015_data *data;
250 int err;
251 unsigned int k;
252
253 data = devm_kzalloc(&client->dev, sizeof(struct ads1015_data),
254 GFP_KERNEL);
255 if (!data)
256 return -ENOMEM;
257
258 if (client->dev.of_node)
259 data->id = (enum ads1015_chips)
260 of_device_get_match_data(&client->dev);
261 else
262 data->id = id->driver_data;
263 i2c_set_clientdata(client, data);
264 mutex_init(&data->update_lock);
265
266 /* build sysfs attribute group */
267 ads1015_get_channels_config(client);
268 for (k = 0; k < ADS1015_CHANNELS; ++k) {
269 if (!data->channel_data[k].enabled)
270 continue;
271 err = device_create_file(&client->dev, &ads1015_in[k].dev_attr);
272 if (err)
273 goto exit_remove;
274 }
275
276 data->hwmon_dev = hwmon_device_register(&client->dev);
277 if (IS_ERR(data->hwmon_dev)) {
278 err = PTR_ERR(data->hwmon_dev);
279 goto exit_remove;
280 }
281
282 return 0;
283
284exit_remove:
285 for (k = 0; k < ADS1015_CHANNELS; ++k)
286 device_remove_file(&client->dev, &ads1015_in[k].dev_attr);
287 return err;
288}
289
290static const struct i2c_device_id ads1015_id[] = {
291 { "ads1015", ads1015},
292 { "ads1115", ads1115},
293 { }
294};
295MODULE_DEVICE_TABLE(i2c, ads1015_id);
296
297static const struct of_device_id __maybe_unused ads1015_of_match[] = {
298 {
299 .compatible = "ti,ads1015",
300 .data = (void *)ads1015
301 },
302 {
303 .compatible = "ti,ads1115",
304 .data = (void *)ads1115
305 },
306 { },
307};
308MODULE_DEVICE_TABLE(of, ads1015_of_match);
309
310static struct i2c_driver ads1015_driver = {
311 .driver = {
312 .name = "ads1015",
313 .of_match_table = of_match_ptr(ads1015_of_match),
314 },
315 .probe = ads1015_probe,
316 .remove = ads1015_remove,
317 .id_table = ads1015_id,
318};
319
320module_i2c_driver(ads1015_driver);
321
322MODULE_AUTHOR("Dirk Eibach <eibach@gdsys.de>");
323MODULE_DESCRIPTION("ADS1015 driver");
324MODULE_LICENSE("GPL");
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index 7e3286265a38..f0af3a42f53c 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -958,7 +958,7 @@ config TI_ADC161S626
958 958
959config TI_ADS1015 959config TI_ADS1015
960 tristate "Texas Instruments ADS1015 ADC" 960 tristate "Texas Instruments ADS1015 ADC"
961 depends on I2C && !SENSORS_ADS1015 961 depends on I2C
962 select REGMAP_I2C 962 select REGMAP_I2C
963 select IIO_BUFFER 963 select IIO_BUFFER
964 select IIO_TRIGGERED_BUFFER 964 select IIO_TRIGGERED_BUFFER