aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2017-09-10 05:44:46 -0400
committerGuenter Roeck <linux@roeck-us.net>2017-10-29 21:36:03 -0400
commit186731145f920fb1514200043bcaf9c689693857 (patch)
tree1ba4a4b99bda0fb42cd79770a52f39979e1ee9ed /drivers/hwmon
parent1b50b776355fa6c6d7b3281a63c275d5c18d629d (diff)
hwmon: (sht15) Root out platform data
After finding out there are active users of this sensor I noticed: - It has a single PXA27x board file using the platform data - The platform data is only used to carry two GPIO pins, all other fields are unused - The driver does not use GPIO descriptors but the legacy GPIO API I saw we can swiftly fix this by: - Killing off the platform data entirely - Define a GPIO descriptor lookup table in the board file - Use the standard devm_gpiod_get() to grab the GPIO descriptors from either the device tree or the board file table. This compiles, but needs testing. Cc: arm@kernel.org Cc: Marco Franchi <marco.franchi@nxp.com> Cc: Davide Hug <d@videhug.ch> Cc: Jonathan Cameron <jic23@cam.ac.uk> Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Acked-by: Arnd Bergmann <arnd@arndb.de> Tested-by: Marco Franchi <marco.franchi@nxp.com> Acked-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/sht15.c167
1 files changed, 54 insertions, 113 deletions
diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
index e4d642b673c6..0e3e5f83f5cf 100644
--- a/drivers/hwmon/sht15.c
+++ b/drivers/hwmon/sht15.c
@@ -18,13 +18,11 @@
18 18
19#include <linux/interrupt.h> 19#include <linux/interrupt.h>
20#include <linux/irq.h> 20#include <linux/irq.h>
21#include <linux/gpio.h>
22#include <linux/module.h> 21#include <linux/module.h>
23#include <linux/init.h> 22#include <linux/init.h>
24#include <linux/hwmon.h> 23#include <linux/hwmon.h>
25#include <linux/hwmon-sysfs.h> 24#include <linux/hwmon-sysfs.h>
26#include <linux/mutex.h> 25#include <linux/mutex.h>
27#include <linux/platform_data/sht15.h>
28#include <linux/platform_device.h> 26#include <linux/platform_device.h>
29#include <linux/sched.h> 27#include <linux/sched.h>
30#include <linux/delay.h> 28#include <linux/delay.h>
@@ -34,7 +32,8 @@
34#include <linux/slab.h> 32#include <linux/slab.h>
35#include <linux/atomic.h> 33#include <linux/atomic.h>
36#include <linux/bitrev.h> 34#include <linux/bitrev.h>
37#include <linux/of_gpio.h> 35#include <linux/gpio/consumer.h>
36#include <linux/of.h>
38 37
39/* Commands */ 38/* Commands */
40#define SHT15_MEASURE_TEMP 0x03 39#define SHT15_MEASURE_TEMP 0x03
@@ -122,7 +121,8 @@ static const u8 sht15_crc8_table[] = {
122 121
123/** 122/**
124 * struct sht15_data - device instance specific data 123 * struct sht15_data - device instance specific data
125 * @pdata: platform data (gpio's etc). 124 * @sck: clock GPIO line
125 * @data: data GPIO line
126 * @read_work: bh of interrupt handler. 126 * @read_work: bh of interrupt handler.
127 * @wait_queue: wait queue for getting values from device. 127 * @wait_queue: wait queue for getting values from device.
128 * @val_temp: last temperature value read from device. 128 * @val_temp: last temperature value read from device.
@@ -150,7 +150,8 @@ static const u8 sht15_crc8_table[] = {
150 * @interrupt_handled: flag used to indicate a handler has been scheduled. 150 * @interrupt_handled: flag used to indicate a handler has been scheduled.
151 */ 151 */
152struct sht15_data { 152struct sht15_data {
153 struct sht15_platform_data *pdata; 153 struct gpio_desc *sck;
154 struct gpio_desc *data;
154 struct work_struct read_work; 155 struct work_struct read_work;
155 wait_queue_head_t wait_queue; 156 wait_queue_head_t wait_queue;
156 uint16_t val_temp; 157 uint16_t val_temp;
@@ -205,16 +206,16 @@ static int sht15_connection_reset(struct sht15_data *data)
205{ 206{
206 int i, err; 207 int i, err;
207 208
208 err = gpio_direction_output(data->pdata->gpio_data, 1); 209 err = gpiod_direction_output(data->data, 1);
209 if (err) 210 if (err)
210 return err; 211 return err;
211 ndelay(SHT15_TSCKL); 212 ndelay(SHT15_TSCKL);
212 gpio_set_value(data->pdata->gpio_sck, 0); 213 gpiod_set_value(data->sck, 0);
213 ndelay(SHT15_TSCKL); 214 ndelay(SHT15_TSCKL);
214 for (i = 0; i < 9; ++i) { 215 for (i = 0; i < 9; ++i) {
215 gpio_set_value(data->pdata->gpio_sck, 1); 216 gpiod_set_value(data->sck, 1);
216 ndelay(SHT15_TSCKH); 217 ndelay(SHT15_TSCKH);
217 gpio_set_value(data->pdata->gpio_sck, 0); 218 gpiod_set_value(data->sck, 0);
218 ndelay(SHT15_TSCKL); 219 ndelay(SHT15_TSCKL);
219 } 220 }
220 return 0; 221 return 0;
@@ -227,11 +228,11 @@ static int sht15_connection_reset(struct sht15_data *data)
227 */ 228 */
228static inline void sht15_send_bit(struct sht15_data *data, int val) 229static inline void sht15_send_bit(struct sht15_data *data, int val)
229{ 230{
230 gpio_set_value(data->pdata->gpio_data, val); 231 gpiod_set_value(data->data, val);
231 ndelay(SHT15_TSU); 232 ndelay(SHT15_TSU);
232 gpio_set_value(data->pdata->gpio_sck, 1); 233 gpiod_set_value(data->sck, 1);
233 ndelay(SHT15_TSCKH); 234 ndelay(SHT15_TSCKH);
234 gpio_set_value(data->pdata->gpio_sck, 0); 235 gpiod_set_value(data->sck, 0);
235 ndelay(SHT15_TSCKL); /* clock low time */ 236 ndelay(SHT15_TSCKL); /* clock low time */
236} 237}
237 238
@@ -248,23 +249,23 @@ static int sht15_transmission_start(struct sht15_data *data)
248 int err; 249 int err;
249 250
250 /* ensure data is high and output */ 251 /* ensure data is high and output */
251 err = gpio_direction_output(data->pdata->gpio_data, 1); 252 err = gpiod_direction_output(data->data, 1);
252 if (err) 253 if (err)
253 return err; 254 return err;
254 ndelay(SHT15_TSU); 255 ndelay(SHT15_TSU);
255 gpio_set_value(data->pdata->gpio_sck, 0); 256 gpiod_set_value(data->sck, 0);
256 ndelay(SHT15_TSCKL); 257 ndelay(SHT15_TSCKL);
257 gpio_set_value(data->pdata->gpio_sck, 1); 258 gpiod_set_value(data->sck, 1);
258 ndelay(SHT15_TSCKH); 259 ndelay(SHT15_TSCKH);
259 gpio_set_value(data->pdata->gpio_data, 0); 260 gpiod_set_value(data->data, 0);
260 ndelay(SHT15_TSU); 261 ndelay(SHT15_TSU);
261 gpio_set_value(data->pdata->gpio_sck, 0); 262 gpiod_set_value(data->sck, 0);
262 ndelay(SHT15_TSCKL); 263 ndelay(SHT15_TSCKL);
263 gpio_set_value(data->pdata->gpio_sck, 1); 264 gpiod_set_value(data->sck, 1);
264 ndelay(SHT15_TSCKH); 265 ndelay(SHT15_TSCKH);
265 gpio_set_value(data->pdata->gpio_data, 1); 266 gpiod_set_value(data->data, 1);
266 ndelay(SHT15_TSU); 267 ndelay(SHT15_TSU);
267 gpio_set_value(data->pdata->gpio_sck, 0); 268 gpiod_set_value(data->sck, 0);
268 ndelay(SHT15_TSCKL); 269 ndelay(SHT15_TSCKL);
269 return 0; 270 return 0;
270} 271}
@@ -292,20 +293,20 @@ static int sht15_wait_for_response(struct sht15_data *data)
292{ 293{
293 int err; 294 int err;
294 295
295 err = gpio_direction_input(data->pdata->gpio_data); 296 err = gpiod_direction_input(data->data);
296 if (err) 297 if (err)
297 return err; 298 return err;
298 gpio_set_value(data->pdata->gpio_sck, 1); 299 gpiod_set_value(data->sck, 1);
299 ndelay(SHT15_TSCKH); 300 ndelay(SHT15_TSCKH);
300 if (gpio_get_value(data->pdata->gpio_data)) { 301 if (gpiod_get_value(data->data)) {
301 gpio_set_value(data->pdata->gpio_sck, 0); 302 gpiod_set_value(data->sck, 0);
302 dev_err(data->dev, "Command not acknowledged\n"); 303 dev_err(data->dev, "Command not acknowledged\n");
303 err = sht15_connection_reset(data); 304 err = sht15_connection_reset(data);
304 if (err) 305 if (err)
305 return err; 306 return err;
306 return -EIO; 307 return -EIO;
307 } 308 }
308 gpio_set_value(data->pdata->gpio_sck, 0); 309 gpiod_set_value(data->sck, 0);
309 ndelay(SHT15_TSCKL); 310 ndelay(SHT15_TSCKL);
310 return 0; 311 return 0;
311} 312}
@@ -360,17 +361,17 @@ static int sht15_ack(struct sht15_data *data)
360{ 361{
361 int err; 362 int err;
362 363
363 err = gpio_direction_output(data->pdata->gpio_data, 0); 364 err = gpiod_direction_output(data->data, 0);
364 if (err) 365 if (err)
365 return err; 366 return err;
366 ndelay(SHT15_TSU); 367 ndelay(SHT15_TSU);
367 gpio_set_value(data->pdata->gpio_sck, 1); 368 gpiod_set_value(data->sck, 1);
368 ndelay(SHT15_TSU); 369 ndelay(SHT15_TSU);
369 gpio_set_value(data->pdata->gpio_sck, 0); 370 gpiod_set_value(data->sck, 0);
370 ndelay(SHT15_TSU); 371 ndelay(SHT15_TSU);
371 gpio_set_value(data->pdata->gpio_data, 1); 372 gpiod_set_value(data->data, 1);
372 373
373 return gpio_direction_input(data->pdata->gpio_data); 374 return gpiod_direction_input(data->data);
374} 375}
375 376
376/** 377/**
@@ -383,13 +384,13 @@ static int sht15_end_transmission(struct sht15_data *data)
383{ 384{
384 int err; 385 int err;
385 386
386 err = gpio_direction_output(data->pdata->gpio_data, 1); 387 err = gpiod_direction_output(data->data, 1);
387 if (err) 388 if (err)
388 return err; 389 return err;
389 ndelay(SHT15_TSU); 390 ndelay(SHT15_TSU);
390 gpio_set_value(data->pdata->gpio_sck, 1); 391 gpiod_set_value(data->sck, 1);
391 ndelay(SHT15_TSCKH); 392 ndelay(SHT15_TSCKH);
392 gpio_set_value(data->pdata->gpio_sck, 0); 393 gpiod_set_value(data->sck, 0);
393 ndelay(SHT15_TSCKL); 394 ndelay(SHT15_TSCKL);
394 return 0; 395 return 0;
395} 396}
@@ -405,10 +406,10 @@ static u8 sht15_read_byte(struct sht15_data *data)
405 406
406 for (i = 0; i < 8; ++i) { 407 for (i = 0; i < 8; ++i) {
407 byte <<= 1; 408 byte <<= 1;
408 gpio_set_value(data->pdata->gpio_sck, 1); 409 gpiod_set_value(data->sck, 1);
409 ndelay(SHT15_TSCKH); 410 ndelay(SHT15_TSCKH);
410 byte |= !!gpio_get_value(data->pdata->gpio_data); 411 byte |= !!gpiod_get_value(data->data);
411 gpio_set_value(data->pdata->gpio_sck, 0); 412 gpiod_set_value(data->sck, 0);
412 ndelay(SHT15_TSCKL); 413 ndelay(SHT15_TSCKL);
413 } 414 }
414 return byte; 415 return byte;
@@ -428,7 +429,7 @@ static int sht15_send_status(struct sht15_data *data, u8 status)
428 err = sht15_send_cmd(data, SHT15_WRITE_STATUS); 429 err = sht15_send_cmd(data, SHT15_WRITE_STATUS);
429 if (err) 430 if (err)
430 return err; 431 return err;
431 err = gpio_direction_output(data->pdata->gpio_data, 1); 432 err = gpiod_direction_output(data->data, 1);
432 if (err) 433 if (err)
433 return err; 434 return err;
434 ndelay(SHT15_TSU); 435 ndelay(SHT15_TSU);
@@ -528,14 +529,14 @@ static int sht15_measurement(struct sht15_data *data,
528 if (ret) 529 if (ret)
529 return ret; 530 return ret;
530 531
531 ret = gpio_direction_input(data->pdata->gpio_data); 532 ret = gpiod_direction_input(data->data);
532 if (ret) 533 if (ret)
533 return ret; 534 return ret;
534 atomic_set(&data->interrupt_handled, 0); 535 atomic_set(&data->interrupt_handled, 0);
535 536
536 enable_irq(gpio_to_irq(data->pdata->gpio_data)); 537 enable_irq(gpiod_to_irq(data->data));
537 if (gpio_get_value(data->pdata->gpio_data) == 0) { 538 if (gpiod_get_value(data->data) == 0) {
538 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data)); 539 disable_irq_nosync(gpiod_to_irq(data->data));
539 /* Only relevant if the interrupt hasn't occurred. */ 540 /* Only relevant if the interrupt hasn't occurred. */
540 if (!atomic_read(&data->interrupt_handled)) 541 if (!atomic_read(&data->interrupt_handled))
541 schedule_work(&data->read_work); 542 schedule_work(&data->read_work);
@@ -547,7 +548,7 @@ static int sht15_measurement(struct sht15_data *data,
547 data->state = SHT15_READING_NOTHING; 548 data->state = SHT15_READING_NOTHING;
548 return -EIO; 549 return -EIO;
549 } else if (ret == 0) { /* timeout occurred */ 550 } else if (ret == 0) { /* timeout occurred */
550 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data)); 551 disable_irq_nosync(gpiod_to_irq(data->data));
551 ret = sht15_connection_reset(data); 552 ret = sht15_connection_reset(data);
552 if (ret) 553 if (ret)
553 return ret; 554 return ret;
@@ -826,15 +827,15 @@ static void sht15_bh_read_data(struct work_struct *work_s)
826 read_work); 827 read_work);
827 828
828 /* Firstly, verify the line is low */ 829 /* Firstly, verify the line is low */
829 if (gpio_get_value(data->pdata->gpio_data)) { 830 if (gpiod_get_value(data->data)) {
830 /* 831 /*
831 * If not, then start the interrupt again - care here as could 832 * If not, then start the interrupt again - care here as could
832 * have gone low in meantime so verify it hasn't! 833 * have gone low in meantime so verify it hasn't!
833 */ 834 */
834 atomic_set(&data->interrupt_handled, 0); 835 atomic_set(&data->interrupt_handled, 0);
835 enable_irq(gpio_to_irq(data->pdata->gpio_data)); 836 enable_irq(gpiod_to_irq(data->data));
836 /* If still not occurred or another handler was scheduled */ 837 /* If still not occurred or another handler was scheduled */
837 if (gpio_get_value(data->pdata->gpio_data) 838 if (gpiod_get_value(data->data)
838 || atomic_read(&data->interrupt_handled)) 839 || atomic_read(&data->interrupt_handled))
839 return; 840 return;
840 } 841 }
@@ -918,46 +919,6 @@ static const struct of_device_id sht15_dt_match[] = {
918 { }, 919 { },
919}; 920};
920MODULE_DEVICE_TABLE(of, sht15_dt_match); 921MODULE_DEVICE_TABLE(of, sht15_dt_match);
921
922/*
923 * This function returns NULL if pdev isn't a device instatiated by dt,
924 * a pointer to pdata if it could successfully get all information
925 * from dt or a negative ERR_PTR() on error.
926 */
927static struct sht15_platform_data *sht15_probe_dt(struct device *dev)
928{
929 struct device_node *np = dev->of_node;
930 struct sht15_platform_data *pdata;
931
932 /* no device tree device */
933 if (!np)
934 return NULL;
935
936 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
937 if (!pdata)
938 return ERR_PTR(-ENOMEM);
939
940 pdata->gpio_data = of_get_named_gpio(np, "data-gpios", 0);
941 if (pdata->gpio_data < 0) {
942 if (pdata->gpio_data != -EPROBE_DEFER)
943 dev_err(dev, "data-gpios not found\n");
944 return ERR_PTR(pdata->gpio_data);
945 }
946
947 pdata->gpio_sck = of_get_named_gpio(np, "clk-gpios", 0);
948 if (pdata->gpio_sck < 0) {
949 if (pdata->gpio_sck != -EPROBE_DEFER)
950 dev_err(dev, "clk-gpios not found\n");
951 return ERR_PTR(pdata->gpio_sck);
952 }
953
954 return pdata;
955}
956#else
957static inline struct sht15_platform_data *sht15_probe_dt(struct device *dev)
958{
959 return NULL;
960}
961#endif 922#endif
962 923
963static int sht15_probe(struct platform_device *pdev) 924static int sht15_probe(struct platform_device *pdev)
@@ -977,25 +938,6 @@ static int sht15_probe(struct platform_device *pdev)
977 data->dev = &pdev->dev; 938 data->dev = &pdev->dev;
978 init_waitqueue_head(&data->wait_queue); 939 init_waitqueue_head(&data->wait_queue);
979 940
980 data->pdata = sht15_probe_dt(&pdev->dev);
981 if (IS_ERR(data->pdata))
982 return PTR_ERR(data->pdata);
983 if (data->pdata == NULL) {
984 data->pdata = dev_get_platdata(&pdev->dev);
985 if (data->pdata == NULL) {
986 dev_err(&pdev->dev, "no platform data supplied\n");
987 return -EINVAL;
988 }
989 }
990
991 data->supply_uv = data->pdata->supply_mv * 1000;
992 if (data->pdata->checksum)
993 data->checksumming = true;
994 if (data->pdata->no_otp_reload)
995 status |= SHT15_STATUS_NO_OTP_RELOAD;
996 if (data->pdata->low_resolution)
997 status |= SHT15_STATUS_LOW_RESOLUTION;
998
999 /* 941 /*
1000 * If a regulator is available, 942 * If a regulator is available,
1001 * query what the supply voltage actually is! 943 * query what the supply voltage actually is!
@@ -1030,21 +972,20 @@ static int sht15_probe(struct platform_device *pdev)
1030 } 972 }
1031 973
1032 /* Try requesting the GPIOs */ 974 /* Try requesting the GPIOs */
1033 ret = devm_gpio_request_one(&pdev->dev, data->pdata->gpio_sck, 975 data->sck = devm_gpiod_get(&pdev->dev, "clk", GPIOD_OUT_LOW);
1034 GPIOF_OUT_INIT_LOW, "SHT15 sck"); 976 if (IS_ERR(data->sck)) {
1035 if (ret) { 977 ret = PTR_ERR(data->sck);
1036 dev_err(&pdev->dev, "clock line GPIO request failed\n"); 978 dev_err(&pdev->dev, "clock line GPIO request failed\n");
1037 goto err_release_reg; 979 goto err_release_reg;
1038 } 980 }
1039 981 data->data = devm_gpiod_get(&pdev->dev, "data", GPIOD_IN);
1040 ret = devm_gpio_request(&pdev->dev, data->pdata->gpio_data, 982 if (IS_ERR(data->data)) {
1041 "SHT15 data"); 983 ret = PTR_ERR(data->data);
1042 if (ret) {
1043 dev_err(&pdev->dev, "data line GPIO request failed\n"); 984 dev_err(&pdev->dev, "data line GPIO request failed\n");
1044 goto err_release_reg; 985 goto err_release_reg;
1045 } 986 }
1046 987
1047 ret = devm_request_irq(&pdev->dev, gpio_to_irq(data->pdata->gpio_data), 988 ret = devm_request_irq(&pdev->dev, gpiod_to_irq(data->data),
1048 sht15_interrupt_fired, 989 sht15_interrupt_fired,
1049 IRQF_TRIGGER_FALLING, 990 IRQF_TRIGGER_FALLING,
1050 "sht15 data", 991 "sht15 data",
@@ -1053,7 +994,7 @@ static int sht15_probe(struct platform_device *pdev)
1053 dev_err(&pdev->dev, "failed to get irq for data line\n"); 994 dev_err(&pdev->dev, "failed to get irq for data line\n");
1054 goto err_release_reg; 995 goto err_release_reg;
1055 } 996 }
1056 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data)); 997 disable_irq_nosync(gpiod_to_irq(data->data));
1057 ret = sht15_connection_reset(data); 998 ret = sht15_connection_reset(data);
1058 if (ret) 999 if (ret)
1059 goto err_release_reg; 1000 goto err_release_reg;