Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'iio-for-3.13a' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-next

Jonathan writes:

First round of new drivers, functionality and cleanups for IIO in the 3.13 cycle

A number of new drivers and some new functionality + a lot of cleanups
all over IIO.

New Core Elements

1) New INT_TIME info_mask element for integration time, which may have
different effects on measurement noise and similar, than an amplifier
and hence is different from existing SCALE. Already existed in some
drivers as a custom attribute.

2) Introduce a iio_push_buffers_with_timestamp helper to cover the common
case of filling the last 64 bits of data to be passed to the buffer with
a timestamp. Applied to lots of drivers. Cuts down on repeated code and
moves a slightly fiddly bit of logic into a single location.

3) Introduce info_mask_[shared_by_dir/shared_by_all] elements to allow support
of elements such as sampling_frequency which is typically shared by all
input channels on a device. This reduces code and makes these controls
available from in kernel consumers of IIO devices.

New drivers

1) MCP3422/3/4 ADC

2) TSL4531 ambient light sensor

3) TCS3472/5 color light sensor

4) GP2AP020A00F ambient light / proximity sensor

5) LPS001WP support added to ST pressure sensor driver.

New driver functionality

1) ti_am335x_adc Add buffered sampling support.
This device has a hardware fifo that is fed directly into an IIO kfifo
buffer based on a watershed interrupt. Note this will act as an example
of how to handle this increasingly common type of device.
The only previous example - sca3000 - take a less than optimal approach
which is largely why it is still in staging.
A couple of little cleanups for that new functionality followed later.

Core cleanups:

1) MAINTAINERS - Sachin actually brought my email address up to date because
I said I'd do it and never got around to it :)

2) Assign buffer list elements as single element lists to simplify the
iio_buffer_is_active logic.

3) wake_up_interruptible_poll instead of wake_up_interruptible to only wake
up threads waiting for poll notifications.

4) Add O_CLOEXEC flag to anon_inode_get_fd call for IIO event interface.

5) Change iio_push_to_buffers to take a void * pointer so as to avoid some
annoying and unnecessary type casts.

6) iio_compute_scan_bytes incorrectly took a long rather than unsigned long.

7) Various minor tidy ups.

Driver cleanups (in no particular order)

1) Another set of devm_ allocations patches from Sachin Kamat.

2) tsl2x7x - 0 to NULL cleanup.

3) hmc5843 - fix missing > in MODULE_AUTHOR

4) Set of strict_strto* to kstrto* conversions.

5) mxs-lradc - fix ordering of resource removal to match creation

6) mxs-lradc - add MODULE_ALIAS

7) adc7606 - drop a work pending test duplicated in core functions.

8) hmc5843 - devm_ allocation patch

9) Series of redundant breaks removed.

10) ad2s1200 - pr_err -> dev_err

11) adjd_s311 - use INT_TIME

12) ST sensors - large set of cleanups from Lee Jones and removed restriction
to using only triggers provided by the st_sensors themselves from
Dennis Ciocca.

13) dummy and tmp006 provide sampling_frequency via info_mask_shared_by_all.

14) tcs3472 - fix incorrect buffer size and wrong device pointer used in
suspend / resume functions.

15) max1363 - use defaults for buffer setup ops as provided by the triggered
buffer helpers as they are the same as were specified in max1363 driver.

16) Trivial tidy ups in a number of other drivers.

+3919 -1151
+11
Documentation/ABI/testing/sysfs-bus-iio
··· 811 811 Writing '1' stores the current device configuration into 812 812 on-chip EEPROM. After power-up or chip reset the device will 813 813 automatically load the saved configuration. 814 + 815 + What: /sys/.../iio:deviceX/in_intensity_red_integration_time 816 + What: /sys/.../iio:deviceX/in_intensity_green_integration_time 817 + What: /sys/.../iio:deviceX/in_intensity_blue_integration_time 818 + What: /sys/.../iio:deviceX/in_intensity_clear_integration_time 819 + What: /sys/.../iio:deviceX/in_illuminance_integration_time 820 + KernelVersion: 3.12 821 + Contact: linux-iio@vger.kernel.org 822 + Description: 823 + This attribute is used to get/set the integration time in 824 + seconds.
+21
Documentation/devicetree/bindings/iio/light/gp2ap020a00f.txt
··· 1 + * Sharp GP2AP020A00F I2C Proximity/ALS sensor 2 + 3 + The proximity detector sensor requires power supply 4 + for its built-in led. It is also defined by this binding. 5 + 6 + Required properties: 7 + 8 + - compatible : should be "sharp,gp2ap020a00f" 9 + - reg : the I2C slave address of the light sensor 10 + - interrupts : interrupt specifier for the sole interrupt generated 11 + by the device 12 + - vled-supply : VLED power supply, as covered in ../regulator/regulator.txt 13 + 14 + Example: 15 + 16 + gp2ap020a00f@39 { 17 + compatible = "sharp,gp2ap020a00f"; 18 + reg = <0x39>; 19 + interrupts = <2 0>; 20 + vled-supply = <...>; 21 + };
+2 -2
MAINTAINERS
··· 4195 4195 F: drivers/media/rc/iguanair.c 4196 4196 4197 4197 IIO SUBSYSTEM AND DRIVERS 4198 - M: Jonathan Cameron <jic23@cam.ac.uk> 4198 + M: Jonathan Cameron <jic23@kernel.org> 4199 4199 L: linux-iio@vger.kernel.org 4200 4200 S: Maintained 4201 4201 F: drivers/iio/ ··· 7947 7947 F: drivers/staging/media/go7007/ 7948 7948 7949 7949 STAGING - INDUSTRIAL IO 7950 - M: Jonathan Cameron <jic23@cam.ac.uk> 7950 + M: Jonathan Cameron <jic23@kernel.org> 7951 7951 L: linux-iio@vger.kernel.org 7952 7952 S: Odd Fixes 7953 7953 F: drivers/staging/iio/
+2 -5
drivers/iio/accel/bma180.c
··· 471 471 struct iio_poll_func *pf = p; 472 472 struct iio_dev *indio_dev = pf->indio_dev; 473 473 struct bma180_data *data = iio_priv(indio_dev); 474 + int64_t time_ns = iio_get_time_ns(); 474 475 int bit, ret, i = 0; 475 476 476 477 mutex_lock(&data->mutex); 477 - if (indio_dev->scan_timestamp) { 478 - ret = indio_dev->scan_bytes / sizeof(s64) - 1; 479 - ((s64 *)data->buff)[ret] = iio_get_time_ns(); 480 - } 481 478 482 479 for_each_set_bit(bit, indio_dev->buffer->scan_mask, 483 480 indio_dev->masklength) { ··· 487 490 } 488 491 mutex_unlock(&data->mutex); 489 492 490 - iio_push_to_buffers(indio_dev, (u8 *)data->buff); 493 + iio_push_to_buffers_with_timestamp(indio_dev, data->buff, time_ns); 491 494 err: 492 495 iio_trigger_notify_done(indio_dev->trig); 493 496
+4 -3
drivers/iio/accel/hid-sensor-accel-3d.c
··· 182 182 }; 183 183 184 184 /* Function to push data to buffer */ 185 - static void hid_sensor_push_data(struct iio_dev *indio_dev, u8 *data, int len) 185 + static void hid_sensor_push_data(struct iio_dev *indio_dev, const void *data, 186 + int len) 186 187 { 187 188 dev_dbg(&indio_dev->dev, "hid_sensor_push_data\n"); 188 - iio_push_to_buffers(indio_dev, (u8 *)data); 189 + iio_push_to_buffers(indio_dev, data); 189 190 } 190 191 191 192 /* Callback handler to send event after all samples are received and captured */ ··· 201 200 accel_state->common_attributes.data_ready); 202 201 if (accel_state->common_attributes.data_ready) 203 202 hid_sensor_push_data(indio_dev, 204 - (u8 *)accel_state->accel_val, 203 + accel_state->accel_val, 205 204 sizeof(accel_state->accel_val)); 206 205 207 206 return 0;
+15 -15
drivers/iio/accel/st_accel_core.c
··· 452 452 int st_accel_common_probe(struct iio_dev *indio_dev, 453 453 struct st_sensors_platform_data *plat_data) 454 454 { 455 - int err; 456 455 struct st_sensor_data *adata = iio_priv(indio_dev); 456 + int irq = adata->get_irq_data_ready(indio_dev); 457 + int err; 457 458 458 459 indio_dev->modes = INDIO_DIRECT_MODE; 459 460 indio_dev->info = &accel_info; ··· 462 461 err = st_sensors_check_device_support(indio_dev, 463 462 ARRAY_SIZE(st_accel_sensors), st_accel_sensors); 464 463 if (err < 0) 465 - goto st_accel_common_probe_error; 464 + return err; 466 465 467 466 adata->num_data_channels = ST_ACCEL_NUMBER_DATA_CHANNELS; 468 467 adata->multiread_bit = adata->sensor->multi_read_bit; ··· 479 478 480 479 err = st_sensors_init_sensor(indio_dev, plat_data); 481 480 if (err < 0) 482 - goto st_accel_common_probe_error; 481 + return err; 483 482 484 - if (adata->get_irq_data_ready(indio_dev) > 0) { 485 - err = st_accel_allocate_ring(indio_dev); 486 - if (err < 0) 487 - goto st_accel_common_probe_error; 483 + err = st_accel_allocate_ring(indio_dev); 484 + if (err < 0) 485 + return err; 488 486 487 + if (irq > 0) { 489 488 err = st_sensors_allocate_trigger(indio_dev, 490 489 ST_ACCEL_TRIGGER_OPS); 491 490 if (err < 0) ··· 496 495 if (err) 497 496 goto st_accel_device_register_error; 498 497 499 - return err; 498 + return 0; 500 499 501 500 st_accel_device_register_error: 502 - if (adata->get_irq_data_ready(indio_dev) > 0) 501 + if (irq > 0) 503 502 st_sensors_deallocate_trigger(indio_dev); 504 503 st_accel_probe_trigger_error: 505 - if (adata->get_irq_data_ready(indio_dev) > 0) 506 - st_accel_deallocate_ring(indio_dev); 507 - st_accel_common_probe_error: 504 + st_accel_deallocate_ring(indio_dev); 505 + 508 506 return err; 509 507 } 510 508 EXPORT_SYMBOL(st_accel_common_probe); ··· 513 513 struct st_sensor_data *adata = iio_priv(indio_dev); 514 514 515 515 iio_device_unregister(indio_dev); 516 - if (adata->get_irq_data_ready(indio_dev) > 0) { 516 + if (adata->get_irq_data_ready(indio_dev) > 0) 517 517 st_sensors_deallocate_trigger(indio_dev); 518 - st_accel_deallocate_ring(indio_dev); 519 - } 518 + 519 + st_accel_deallocate_ring(indio_dev); 520 520 } 521 521 EXPORT_SYMBOL(st_accel_common_remove); 522 522
+11
drivers/iio/adc/Kconfig
··· 145 145 This driver can also be built as a module. If so, the module will be 146 146 called mcp320x. 147 147 148 + config MCP3422 149 + tristate "Microchip Technology MCP3422/3/4 driver" 150 + depends on I2C 151 + help 152 + Say yes here to build support for Microchip Technology's MCP3422, 153 + MCP3423 or MCP3424 analog to digital converters. 154 + 155 + This driver can also be built as a module. If so, the module will be 156 + called mcp3422. 157 + 148 158 config NAU7802 149 159 tristate "Nuvoton NAU7802 ADC driver" 150 160 depends on I2C ··· 177 167 config TI_AM335X_ADC 178 168 tristate "TI's AM335X ADC driver" 179 169 depends on MFD_TI_AM335X_TSCADC 170 + select IIO_KFIFO_BUF 180 171 help 181 172 Say yes here to build support for Texas Instruments ADC 182 173 driver which is also a MFD client.
+1
drivers/iio/adc/Makefile
··· 16 16 obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o 17 17 obj-$(CONFIG_MAX1363) += max1363.o 18 18 obj-$(CONFIG_MCP320X) += mcp320x.o 19 + obj-$(CONFIG_MCP3422) += mcp3422.o 19 20 obj-$(CONFIG_NAU7802) += nau7802.o 20 21 obj-$(CONFIG_TI_ADC081C) += ti-adc081c.o 21 22 obj-$(CONFIG_TI_AM335X_ADC) += ti_am335x_adc.o
+6 -7
drivers/iio/adc/ad7266.c
··· 96 96 97 97 ret = spi_read(st->spi, st->data, 4); 98 98 if (ret == 0) { 99 - if (indio_dev->scan_timestamp) 100 - ((s64 *)st->data)[1] = pf->timestamp; 101 - iio_push_to_buffers(indio_dev, (u8 *)st->data); 99 + iio_push_to_buffers_with_timestamp(indio_dev, st->data, 100 + pf->timestamp); 102 101 } 103 102 104 103 iio_trigger_notify_done(indio_dev->trig); ··· 292 293 .driver_module = THIS_MODULE, 293 294 }; 294 295 295 - static unsigned long ad7266_available_scan_masks[] = { 296 + static const unsigned long ad7266_available_scan_masks[] = { 296 297 0x003, 297 298 0x00c, 298 299 0x030, ··· 302 303 0x000, 303 304 }; 304 305 305 - static unsigned long ad7266_available_scan_masks_diff[] = { 306 + static const unsigned long ad7266_available_scan_masks_diff[] = { 306 307 0x003, 307 308 0x00c, 308 309 0x030, 309 310 0x000, 310 311 }; 311 312 312 - static unsigned long ad7266_available_scan_masks_fixed[] = { 313 + static const unsigned long ad7266_available_scan_masks_fixed[] = { 313 314 0x003, 314 315 0x000, 315 316 }; ··· 317 318 struct ad7266_chan_info { 318 319 const struct iio_chan_spec *channels; 319 320 unsigned int num_channels; 320 - unsigned long *scan_masks; 321 + const unsigned long *scan_masks; 321 322 }; 322 323 323 324 #define AD7266_CHAN_INFO_INDEX(_differential, _signed, _fixed) \
+2 -8
drivers/iio/adc/ad7298.c
··· 159 159 struct iio_poll_func *pf = p; 160 160 struct iio_dev *indio_dev = pf->indio_dev; 161 161 struct ad7298_state *st = iio_priv(indio_dev); 162 - s64 time_ns = 0; 163 162 int b_sent; 164 163 165 164 b_sent = spi_sync(st->spi, &st->ring_msg); 166 165 if (b_sent) 167 166 goto done; 168 167 169 - if (indio_dev->scan_timestamp) { 170 - time_ns = iio_get_time_ns(); 171 - memcpy((u8 *)st->rx_buf + indio_dev->scan_bytes - sizeof(s64), 172 - &time_ns, sizeof(time_ns)); 173 - } 174 - 175 - iio_push_to_buffers(indio_dev, (u8 *)st->rx_buf); 168 + iio_push_to_buffers_with_timestamp(indio_dev, st->rx_buf, 169 + iio_get_time_ns()); 176 170 177 171 done: 178 172 iio_trigger_notify_done(indio_dev->trig);
+2 -7
drivers/iio/adc/ad7476.c
··· 64 64 struct iio_poll_func *pf = p; 65 65 struct iio_dev *indio_dev = pf->indio_dev; 66 66 struct ad7476_state *st = iio_priv(indio_dev); 67 - s64 time_ns; 68 67 int b_sent; 69 68 70 69 b_sent = spi_sync(st->spi, &st->msg); 71 70 if (b_sent < 0) 72 71 goto done; 73 72 74 - time_ns = iio_get_time_ns(); 75 - 76 - if (indio_dev->scan_timestamp) 77 - ((s64 *)st->data)[1] = time_ns; 78 - 79 - iio_push_to_buffers(indio_dev, st->data); 73 + iio_push_to_buffers_with_timestamp(indio_dev, st->data, 74 + iio_get_time_ns()); 80 75 done: 81 76 iio_trigger_notify_done(indio_dev->trig); 82 77
+2 -8
drivers/iio/adc/ad7887.c
··· 121 121 struct iio_poll_func *pf = p; 122 122 struct iio_dev *indio_dev = pf->indio_dev; 123 123 struct ad7887_state *st = iio_priv(indio_dev); 124 - s64 time_ns; 125 124 int b_sent; 126 125 127 126 b_sent = spi_sync(st->spi, st->ring_msg); 128 127 if (b_sent) 129 128 goto done; 130 129 131 - time_ns = iio_get_time_ns(); 132 - 133 - if (indio_dev->scan_timestamp) 134 - memcpy(st->data + indio_dev->scan_bytes - sizeof(s64), 135 - &time_ns, sizeof(time_ns)); 136 - 137 - iio_push_to_buffers(indio_dev, st->data); 130 + iio_push_to_buffers_with_timestamp(indio_dev, st->data, 131 + iio_get_time_ns()); 138 132 done: 139 133 iio_trigger_notify_done(indio_dev->trig); 140 134
+2 -8
drivers/iio/adc/ad7923.c
··· 174 174 struct iio_poll_func *pf = p; 175 175 struct iio_dev *indio_dev = pf->indio_dev; 176 176 struct ad7923_state *st = iio_priv(indio_dev); 177 - s64 time_ns = 0; 178 177 int b_sent; 179 178 180 179 b_sent = spi_sync(st->spi, &st->ring_msg); 181 180 if (b_sent) 182 181 goto done; 183 182 184 - if (indio_dev->scan_timestamp) { 185 - time_ns = iio_get_time_ns(); 186 - memcpy((u8 *)st->rx_buf + indio_dev->scan_bytes - sizeof(s64), 187 - &time_ns, sizeof(time_ns)); 188 - } 189 - 190 - iio_push_to_buffers(indio_dev, (u8 *)st->rx_buf); 183 + iio_push_to_buffers_with_timestamp(indio_dev, st->rx_buf, 184 + iio_get_time_ns()); 191 185 192 186 done: 193 187 iio_trigger_notify_done(indio_dev->trig);
+1 -5
drivers/iio/adc/ad_sigma_delta.c
··· 368 368 369 369 memset(data, 0x00, 16); 370 370 371 - /* Guaranteed to be aligned with 8 byte boundary */ 372 - if (indio_dev->scan_timestamp) 373 - ((s64 *)data)[1] = pf->timestamp; 374 - 375 371 reg_size = indio_dev->channels[0].scan_type.realbits + 376 372 indio_dev->channels[0].scan_type.shift; 377 373 reg_size = DIV_ROUND_UP(reg_size, 8); ··· 387 391 break; 388 392 } 389 393 390 - iio_push_to_buffers(indio_dev, (uint8_t *)data); 394 + iio_push_to_buffers_with_timestamp(indio_dev, data, pf->timestamp); 391 395 392 396 iio_trigger_notify_done(indio_dev->trig); 393 397 sigma_delta->irq_dis = false;
+2 -8
drivers/iio/adc/at91_adc.c
··· 83 83 j++; 84 84 } 85 85 86 - if (idev->scan_timestamp) { 87 - s64 *timestamp = (s64 *)((u8 *)st->buffer + 88 - ALIGN(j, sizeof(s64))); 89 - *timestamp = pf->timestamp; 90 - } 91 - 92 - iio_push_to_buffers(idev, (u8 *)st->buffer); 86 + iio_push_to_buffers_with_timestamp(idev, st->buffer, pf->timestamp); 93 87 94 88 iio_trigger_notify_done(idev->trig); 95 89 ··· 273 279 int i, ret; 274 280 275 281 st->trig = devm_kzalloc(&idev->dev, 276 - st->trigger_number * sizeof(st->trig), 282 + st->trigger_number * sizeof(*st->trig), 277 283 GFP_KERNEL); 278 284 279 285 if (st->trig == NULL) {
+2 -13
drivers/iio/adc/max1363.c
··· 1436 1436 struct iio_poll_func *pf = p; 1437 1437 struct iio_dev *indio_dev = pf->indio_dev; 1438 1438 struct max1363_state *st = iio_priv(indio_dev); 1439 - s64 time_ns; 1440 1439 __u8 *rxbuf; 1441 1440 int b_sent; 1442 1441 size_t d_size; ··· 1469 1470 if (b_sent < 0) 1470 1471 goto done_free; 1471 1472 1472 - time_ns = iio_get_time_ns(); 1473 - 1474 - if (indio_dev->scan_timestamp) 1475 - memcpy(rxbuf + d_size - sizeof(s64), &time_ns, sizeof(time_ns)); 1476 - iio_push_to_buffers(indio_dev, rxbuf); 1473 + iio_push_to_buffers_with_timestamp(indio_dev, rxbuf, iio_get_time_ns()); 1477 1474 1478 1475 done_free: 1479 1476 kfree(rxbuf); ··· 1478 1483 1479 1484 return IRQ_HANDLED; 1480 1485 } 1481 - 1482 - static const struct iio_buffer_setup_ops max1363_buffered_setup_ops = { 1483 - .postenable = &iio_triggered_buffer_postenable, 1484 - .preenable = &iio_sw_buffer_preenable, 1485 - .predisable = &iio_triggered_buffer_predisable, 1486 - }; 1487 1486 1488 1487 static int max1363_probe(struct i2c_client *client, 1489 1488 const struct i2c_device_id *id) ··· 1548 1559 goto error_disable_reg; 1549 1560 1550 1561 ret = iio_triggered_buffer_setup(indio_dev, NULL, 1551 - &max1363_trigger_handler, &max1363_buffered_setup_ops); 1562 + &max1363_trigger_handler, NULL); 1552 1563 if (ret) 1553 1564 goto error_disable_reg; 1554 1565
+409
drivers/iio/adc/mcp3422.c
··· 1 + /* 2 + * mcp3422.c - driver for the Microchip mcp3422/3/4 chip family 3 + * 4 + * Copyright (C) 2013, Angelo Compagnucci 5 + * Author: Angelo Compagnucci <angelo.compagnucci@gmail.com> 6 + * 7 + * Datasheet: http://ww1.microchip.com/downloads/en/devicedoc/22088b.pdf 8 + * 9 + * This driver exports the value of analog input voltage to sysfs, the 10 + * voltage unit is nV. 11 + * 12 + * This program is free software; you can redistribute it and/or modify 13 + * it under the terms of the GNU General Public License as published by 14 + * the Free Software Foundation; either version 2 of the License, or 15 + * (at your option) any later version. 16 + */ 17 + 18 + #include <linux/err.h> 19 + #include <linux/i2c.h> 20 + #include <linux/module.h> 21 + #include <linux/delay.h> 22 + #include <linux/sysfs.h> 23 + 24 + #include <linux/iio/iio.h> 25 + #include <linux/iio/sysfs.h> 26 + 27 + /* Masks */ 28 + #define MCP3422_CHANNEL_MASK 0x60 29 + #define MCP3422_PGA_MASK 0x03 30 + #define MCP3422_SRATE_MASK 0x0C 31 + #define MCP3422_SRATE_240 0x0 32 + #define MCP3422_SRATE_60 0x1 33 + #define MCP3422_SRATE_15 0x2 34 + #define MCP3422_SRATE_3 0x3 35 + #define MCP3422_PGA_1 0 36 + #define MCP3422_PGA_2 1 37 + #define MCP3422_PGA_4 2 38 + #define MCP3422_PGA_8 3 39 + #define MCP3422_CONT_SAMPLING 0x10 40 + 41 + #define MCP3422_CHANNEL(config) (((config) & MCP3422_CHANNEL_MASK) >> 5) 42 + #define MCP3422_PGA(config) ((config) & MCP3422_PGA_MASK) 43 + #define MCP3422_SAMPLE_RATE(config) (((config) & MCP3422_SRATE_MASK) >> 2) 44 + 45 + #define MCP3422_CHANNEL_VALUE(value) (((value) << 5) & MCP3422_CHANNEL_MASK) 46 + #define MCP3422_PGA_VALUE(value) ((value) & MCP3422_PGA_MASK) 47 + #define MCP3422_SAMPLE_RATE_VALUE(value) ((value << 2) & MCP3422_SRATE_MASK) 48 + 49 + #define MCP3422_CHAN(_index) \ 50 + { \ 51 + .type = IIO_VOLTAGE, \ 52 + .indexed = 1, \ 53 + .channel = _index, \ 54 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) \ 55 + | BIT(IIO_CHAN_INFO_SCALE), \ 56 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ), \ 57 + } 58 + 59 + /* LSB is in nV to eliminate floating point */ 60 + static const u32 rates_to_lsb[] = {1000000, 250000, 62500, 15625}; 61 + 62 + /* 63 + * scales calculated as: 64 + * rates_to_lsb[sample_rate] / (1 << pga); 65 + * pga is 1 for 0, 2 66 + */ 67 + 68 + static const int mcp3422_scales[4][4] = { 69 + { 1000000, 250000, 62500, 15625 }, 70 + { 500000 , 125000, 31250, 7812 }, 71 + { 250000 , 62500 , 15625, 3906 }, 72 + { 125000 , 31250 , 7812 , 1953 } }; 73 + 74 + /* Constant msleep times for data acquisitions */ 75 + static const int mcp3422_read_times[4] = { 76 + [MCP3422_SRATE_240] = 1000 / 240, 77 + [MCP3422_SRATE_60] = 1000 / 60, 78 + [MCP3422_SRATE_15] = 1000 / 15, 79 + [MCP3422_SRATE_3] = 1000 / 3 }; 80 + 81 + /* sample rates to integer conversion table */ 82 + static const int mcp3422_sample_rates[4] = { 83 + [MCP3422_SRATE_240] = 240, 84 + [MCP3422_SRATE_60] = 60, 85 + [MCP3422_SRATE_15] = 15, 86 + [MCP3422_SRATE_3] = 3 }; 87 + 88 + /* sample rates to sign extension table */ 89 + static const int mcp3422_sign_extend[4] = { 90 + [MCP3422_SRATE_240] = 12, 91 + [MCP3422_SRATE_60] = 14, 92 + [MCP3422_SRATE_15] = 16, 93 + [MCP3422_SRATE_3] = 18 }; 94 + 95 + /* Client data (each client gets its own) */ 96 + struct mcp3422 { 97 + struct i2c_client *i2c; 98 + u8 config; 99 + u8 pga[4]; 100 + struct mutex lock; 101 + }; 102 + 103 + static int mcp3422_update_config(struct mcp3422 *adc, u8 newconfig) 104 + { 105 + int ret; 106 + 107 + mutex_lock(&adc->lock); 108 + 109 + ret = i2c_master_send(adc->i2c, &newconfig, 1); 110 + if (ret > 0) { 111 + adc->config = newconfig; 112 + ret = 0; 113 + } 114 + 115 + mutex_unlock(&adc->lock); 116 + 117 + return ret; 118 + } 119 + 120 + static int mcp3422_read(struct mcp3422 *adc, int *value, u8 *config) 121 + { 122 + int ret = 0; 123 + u8 sample_rate = MCP3422_SAMPLE_RATE(adc->config); 124 + u8 buf[4] = {0, 0, 0, 0}; 125 + u32 temp; 126 + 127 + if (sample_rate == MCP3422_SRATE_3) { 128 + ret = i2c_master_recv(adc->i2c, buf, 4); 129 + temp = buf[0] << 16 | buf[1] << 8 | buf[2]; 130 + *config = buf[3]; 131 + } else { 132 + ret = i2c_master_recv(adc->i2c, buf, 3); 133 + temp = buf[0] << 8 | buf[1]; 134 + *config = buf[2]; 135 + } 136 + 137 + *value = sign_extend32(temp, mcp3422_sign_extend[sample_rate]); 138 + 139 + return ret; 140 + } 141 + 142 + static int mcp3422_read_channel(struct mcp3422 *adc, 143 + struct iio_chan_spec const *channel, int *value) 144 + { 145 + int ret; 146 + u8 config; 147 + u8 req_channel = channel->channel; 148 + 149 + if (req_channel != MCP3422_CHANNEL(adc->config)) { 150 + config = adc->config; 151 + config &= ~MCP3422_CHANNEL_MASK; 152 + config |= MCP3422_CHANNEL_VALUE(req_channel); 153 + config &= ~MCP3422_PGA_MASK; 154 + config |= MCP3422_PGA_VALUE(adc->pga[req_channel]); 155 + ret = mcp3422_update_config(adc, config); 156 + if (ret < 0) 157 + return ret; 158 + msleep(mcp3422_read_times[MCP3422_SAMPLE_RATE(adc->config)]); 159 + } 160 + 161 + return mcp3422_read(adc, value, &config); 162 + } 163 + 164 + static int mcp3422_read_raw(struct iio_dev *iio, 165 + struct iio_chan_spec const *channel, int *val1, 166 + int *val2, long mask) 167 + { 168 + struct mcp3422 *adc = iio_priv(iio); 169 + int err; 170 + 171 + u8 sample_rate = MCP3422_SAMPLE_RATE(adc->config); 172 + u8 pga = MCP3422_PGA(adc->config); 173 + 174 + switch (mask) { 175 + case IIO_CHAN_INFO_RAW: 176 + err = mcp3422_read_channel(adc, channel, val1); 177 + if (err < 0) 178 + return -EINVAL; 179 + return IIO_VAL_INT; 180 + 181 + case IIO_CHAN_INFO_SCALE: 182 + 183 + *val1 = 0; 184 + *val2 = mcp3422_scales[sample_rate][pga]; 185 + return IIO_VAL_INT_PLUS_NANO; 186 + 187 + case IIO_CHAN_INFO_SAMP_FREQ: 188 + *val1 = mcp3422_sample_rates[MCP3422_SAMPLE_RATE(adc->config)]; 189 + return IIO_VAL_INT; 190 + 191 + default: 192 + break; 193 + } 194 + 195 + return -EINVAL; 196 + } 197 + 198 + static int mcp3422_write_raw(struct iio_dev *iio, 199 + struct iio_chan_spec const *channel, int val1, 200 + int val2, long mask) 201 + { 202 + struct mcp3422 *adc = iio_priv(iio); 203 + u8 temp; 204 + u8 config = adc->config; 205 + u8 req_channel = channel->channel; 206 + u8 sample_rate = MCP3422_SAMPLE_RATE(config); 207 + u8 i; 208 + 209 + switch (mask) { 210 + case IIO_CHAN_INFO_SCALE: 211 + if (val1 != 0) 212 + return -EINVAL; 213 + 214 + for (i = 0; i < ARRAY_SIZE(mcp3422_scales[0]); i++) { 215 + if (val2 == mcp3422_scales[sample_rate][i]) { 216 + adc->pga[req_channel] = i; 217 + 218 + config &= ~MCP3422_CHANNEL_MASK; 219 + config |= MCP3422_CHANNEL_VALUE(req_channel); 220 + config &= ~MCP3422_PGA_MASK; 221 + config |= MCP3422_PGA_VALUE(adc->pga[req_channel]); 222 + 223 + return mcp3422_update_config(adc, config); 224 + } 225 + } 226 + return -EINVAL; 227 + 228 + case IIO_CHAN_INFO_SAMP_FREQ: 229 + switch (val1) { 230 + case 240: 231 + temp = MCP3422_SRATE_240; 232 + break; 233 + case 60: 234 + temp = MCP3422_SRATE_60; 235 + break; 236 + case 15: 237 + temp = MCP3422_SRATE_15; 238 + break; 239 + case 3: 240 + temp = MCP3422_SRATE_3; 241 + break; 242 + default: 243 + return -EINVAL; 244 + } 245 + 246 + config &= ~MCP3422_CHANNEL_MASK; 247 + config |= MCP3422_CHANNEL_VALUE(req_channel); 248 + config &= ~MCP3422_SRATE_MASK; 249 + config |= MCP3422_SAMPLE_RATE_VALUE(temp); 250 + 251 + return mcp3422_update_config(adc, config); 252 + 253 + default: 254 + break; 255 + } 256 + 257 + return -EINVAL; 258 + } 259 + 260 + static int mcp3422_write_raw_get_fmt(struct iio_dev *indio_dev, 261 + struct iio_chan_spec const *chan, long mask) 262 + { 263 + switch (mask) { 264 + case IIO_CHAN_INFO_SCALE: 265 + return IIO_VAL_INT_PLUS_NANO; 266 + case IIO_CHAN_INFO_SAMP_FREQ: 267 + return IIO_VAL_INT_PLUS_MICRO; 268 + default: 269 + return -EINVAL; 270 + } 271 + } 272 + 273 + static ssize_t mcp3422_show_scales(struct device *dev, 274 + struct device_attribute *attr, char *buf) 275 + { 276 + struct mcp3422 *adc = iio_priv(dev_to_iio_dev(dev)); 277 + u8 sample_rate = MCP3422_SAMPLE_RATE(adc->config); 278 + 279 + return sprintf(buf, "0.%09u 0.%09u 0.%09u 0.%09u\n", 280 + mcp3422_scales[sample_rate][0], 281 + mcp3422_scales[sample_rate][1], 282 + mcp3422_scales[sample_rate][2], 283 + mcp3422_scales[sample_rate][3]); 284 + } 285 + 286 + static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("240 60 15 3"); 287 + static IIO_DEVICE_ATTR(in_voltage_scale_available, S_IRUGO, 288 + mcp3422_show_scales, NULL, 0); 289 + 290 + static struct attribute *mcp3422_attributes[] = { 291 + &iio_const_attr_sampling_frequency_available.dev_attr.attr, 292 + &iio_dev_attr_in_voltage_scale_available.dev_attr.attr, 293 + NULL, 294 + }; 295 + 296 + static const struct attribute_group mcp3422_attribute_group = { 297 + .attrs = mcp3422_attributes, 298 + }; 299 + 300 + static const struct iio_chan_spec mcp3422_channels[] = { 301 + MCP3422_CHAN(0), 302 + MCP3422_CHAN(1), 303 + }; 304 + 305 + static const struct iio_chan_spec mcp3424_channels[] = { 306 + MCP3422_CHAN(0), 307 + MCP3422_CHAN(1), 308 + MCP3422_CHAN(2), 309 + MCP3422_CHAN(3), 310 + }; 311 + 312 + static const struct iio_info mcp3422_info = { 313 + .read_raw = mcp3422_read_raw, 314 + .write_raw = mcp3422_write_raw, 315 + .write_raw_get_fmt = mcp3422_write_raw_get_fmt, 316 + .attrs = &mcp3422_attribute_group, 317 + .driver_module = THIS_MODULE, 318 + }; 319 + 320 + static int mcp3422_probe(struct i2c_client *client, 321 + const struct i2c_device_id *id) 322 + { 323 + struct iio_dev *indio_dev; 324 + struct mcp3422 *adc; 325 + int err; 326 + u8 config; 327 + 328 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) 329 + return -ENODEV; 330 + 331 + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*adc)); 332 + if (!indio_dev) 333 + return -ENOMEM; 334 + 335 + adc = iio_priv(indio_dev); 336 + adc->i2c = client; 337 + 338 + mutex_init(&adc->lock); 339 + 340 + indio_dev->dev.parent = &client->dev; 341 + indio_dev->name = dev_name(&client->dev); 342 + indio_dev->modes = INDIO_DIRECT_MODE; 343 + indio_dev->info = &mcp3422_info; 344 + 345 + switch ((unsigned int)(id->driver_data)) { 346 + case 2: 347 + case 3: 348 + indio_dev->channels = mcp3422_channels; 349 + indio_dev->num_channels = ARRAY_SIZE(mcp3422_channels); 350 + break; 351 + case 4: 352 + indio_dev->channels = mcp3424_channels; 353 + indio_dev->num_channels = ARRAY_SIZE(mcp3424_channels); 354 + break; 355 + } 356 + 357 + /* meaningful default configuration */ 358 + config = (MCP3422_CONT_SAMPLING 359 + | MCP3422_CHANNEL_VALUE(1) 360 + | MCP3422_PGA_VALUE(MCP3422_PGA_1) 361 + | MCP3422_SAMPLE_RATE_VALUE(MCP3422_SRATE_240)); 362 + mcp3422_update_config(adc, config); 363 + 364 + err = iio_device_register(indio_dev); 365 + if (err < 0) 366 + return err; 367 + 368 + i2c_set_clientdata(client, indio_dev); 369 + 370 + return 0; 371 + } 372 + 373 + static int mcp3422_remove(struct i2c_client *client) 374 + { 375 + iio_device_unregister(i2c_get_clientdata(client)); 376 + return 0; 377 + } 378 + 379 + static const struct i2c_device_id mcp3422_id[] = { 380 + { "mcp3422", 2 }, 381 + { "mcp3423", 3 }, 382 + { "mcp3424", 4 }, 383 + { } 384 + }; 385 + MODULE_DEVICE_TABLE(i2c, mcp3422_id); 386 + 387 + #ifdef CONFIG_OF 388 + static const struct of_device_id mcp3422_of_match[] = { 389 + { .compatible = "mcp3422" }, 390 + { } 391 + }; 392 + MODULE_DEVICE_TABLE(of, mcp3422_of_match); 393 + #endif 394 + 395 + static struct i2c_driver mcp3422_driver = { 396 + .driver = { 397 + .name = "mcp3422", 398 + .owner = THIS_MODULE, 399 + .of_match_table = of_match_ptr(mcp3422_of_match), 400 + }, 401 + .probe = mcp3422_probe, 402 + .remove = mcp3422_remove, 403 + .id_table = mcp3422_id, 404 + }; 405 + module_i2c_driver(mcp3422_driver); 406 + 407 + MODULE_AUTHOR("Angelo Compagnucci <angelo.compagnucci@gmail.com>"); 408 + MODULE_DESCRIPTION("Microchip mcp3422/3/4 driver"); 409 + MODULE_LICENSE("GPL v2");
+207 -18
drivers/iio/adc/ti_am335x_adc.c
··· 28 28 #include <linux/iio/driver.h> 29 29 30 30 #include <linux/mfd/ti_am335x_tscadc.h> 31 + #include <linux/iio/buffer.h> 32 + #include <linux/iio/kfifo_buf.h> 31 33 32 34 struct tiadc_device { 33 35 struct ti_tscadc_dev *mfd_tscadc; 34 36 int channels; 35 37 u8 channel_line[8]; 36 38 u8 channel_step[8]; 39 + int buffer_en_ch_steps; 40 + u16 data[8]; 37 41 }; 38 42 39 43 static unsigned int tiadc_readl(struct tiadc_device *adc, unsigned int reg) ··· 60 56 return step_en; 61 57 } 62 58 63 - static void tiadc_step_config(struct tiadc_device *adc_dev) 59 + static u32 get_adc_step_bit(struct tiadc_device *adc_dev, int chan) 64 60 { 61 + return 1 << adc_dev->channel_step[chan]; 62 + } 63 + 64 + static void tiadc_step_config(struct iio_dev *indio_dev) 65 + { 66 + struct tiadc_device *adc_dev = iio_priv(indio_dev); 65 67 unsigned int stepconfig; 66 68 int i, steps; 67 69 ··· 82 72 */ 83 73 84 74 steps = TOTAL_STEPS - adc_dev->channels; 85 - stepconfig = STEPCONFIG_AVG_16 | STEPCONFIG_FIFO1; 75 + if (iio_buffer_enabled(indio_dev)) 76 + stepconfig = STEPCONFIG_AVG_16 | STEPCONFIG_FIFO1 77 + | STEPCONFIG_MODE_SWCNT; 78 + else 79 + stepconfig = STEPCONFIG_AVG_16 | STEPCONFIG_FIFO1; 86 80 87 81 for (i = 0; i < adc_dev->channels; i++) { 88 82 int chan; ··· 99 85 adc_dev->channel_step[i] = steps; 100 86 steps++; 101 87 } 102 - 103 88 } 89 + 90 + static irqreturn_t tiadc_irq_h(int irq, void *private) 91 + { 92 + struct iio_dev *indio_dev = private; 93 + struct tiadc_device *adc_dev = iio_priv(indio_dev); 94 + unsigned int status, config; 95 + status = tiadc_readl(adc_dev, REG_IRQSTATUS); 96 + 97 + /* 98 + * ADC and touchscreen share the IRQ line. 99 + * FIFO0 interrupts are used by TSC. Handle FIFO1 IRQs here only 100 + */ 101 + if (status & IRQENB_FIFO1OVRRUN) { 102 + /* FIFO Overrun. Clear flag. Disable/Enable ADC to recover */ 103 + config = tiadc_readl(adc_dev, REG_CTRL); 104 + config &= ~(CNTRLREG_TSCSSENB); 105 + tiadc_writel(adc_dev, REG_CTRL, config); 106 + tiadc_writel(adc_dev, REG_IRQSTATUS, IRQENB_FIFO1OVRRUN 107 + | IRQENB_FIFO1UNDRFLW | IRQENB_FIFO1THRES); 108 + tiadc_writel(adc_dev, REG_CTRL, (config | CNTRLREG_TSCSSENB)); 109 + return IRQ_HANDLED; 110 + } else if (status & IRQENB_FIFO1THRES) { 111 + /* Disable irq and wake worker thread */ 112 + tiadc_writel(adc_dev, REG_IRQCLR, IRQENB_FIFO1THRES); 113 + return IRQ_WAKE_THREAD; 114 + } 115 + 116 + return IRQ_NONE; 117 + } 118 + 119 + static irqreturn_t tiadc_worker_h(int irq, void *private) 120 + { 121 + struct iio_dev *indio_dev = private; 122 + struct tiadc_device *adc_dev = iio_priv(indio_dev); 123 + int i, k, fifo1count, read; 124 + u16 *data = adc_dev->data; 125 + 126 + fifo1count = tiadc_readl(adc_dev, REG_FIFO1CNT); 127 + for (k = 0; k < fifo1count; k = k + i) { 128 + for (i = 0; i < (indio_dev->scan_bytes)/2; i++) { 129 + read = tiadc_readl(adc_dev, REG_FIFO1); 130 + data[i] = read & FIFOREAD_DATA_MASK; 131 + } 132 + iio_push_to_buffers(indio_dev, (u8 *) data); 133 + } 134 + 135 + tiadc_writel(adc_dev, REG_IRQSTATUS, IRQENB_FIFO1THRES); 136 + tiadc_writel(adc_dev, REG_IRQENABLE, IRQENB_FIFO1THRES); 137 + 138 + return IRQ_HANDLED; 139 + } 140 + 141 + static int tiadc_buffer_preenable(struct iio_dev *indio_dev) 142 + { 143 + struct tiadc_device *adc_dev = iio_priv(indio_dev); 144 + int i, fifo1count, read; 145 + 146 + tiadc_writel(adc_dev, REG_IRQCLR, (IRQENB_FIFO1THRES | 147 + IRQENB_FIFO1OVRRUN | 148 + IRQENB_FIFO1UNDRFLW)); 149 + 150 + /* Flush FIFO. Needed in corner cases in simultaneous tsc/adc use */ 151 + fifo1count = tiadc_readl(adc_dev, REG_FIFO1CNT); 152 + for (i = 0; i < fifo1count; i++) 153 + read = tiadc_readl(adc_dev, REG_FIFO1); 154 + 155 + return iio_sw_buffer_preenable(indio_dev); 156 + } 157 + 158 + static int tiadc_buffer_postenable(struct iio_dev *indio_dev) 159 + { 160 + struct tiadc_device *adc_dev = iio_priv(indio_dev); 161 + struct iio_buffer *buffer = indio_dev->buffer; 162 + unsigned int enb = 0; 163 + u8 bit; 164 + 165 + tiadc_step_config(indio_dev); 166 + for_each_set_bit(bit, buffer->scan_mask, adc_dev->channels) 167 + enb |= (get_adc_step_bit(adc_dev, bit) << 1); 168 + adc_dev->buffer_en_ch_steps = enb; 169 + 170 + am335x_tsc_se_set(adc_dev->mfd_tscadc, enb); 171 + 172 + tiadc_writel(adc_dev, REG_IRQSTATUS, IRQENB_FIFO1THRES 173 + | IRQENB_FIFO1OVRRUN | IRQENB_FIFO1UNDRFLW); 174 + tiadc_writel(adc_dev, REG_IRQENABLE, IRQENB_FIFO1THRES 175 + | IRQENB_FIFO1OVRRUN); 176 + 177 + return 0; 178 + } 179 + 180 + static int tiadc_buffer_predisable(struct iio_dev *indio_dev) 181 + { 182 + struct tiadc_device *adc_dev = iio_priv(indio_dev); 183 + int fifo1count, i, read; 184 + 185 + tiadc_writel(adc_dev, REG_IRQCLR, (IRQENB_FIFO1THRES | 186 + IRQENB_FIFO1OVRRUN | IRQENB_FIFO1UNDRFLW)); 187 + am335x_tsc_se_clr(adc_dev->mfd_tscadc, adc_dev->buffer_en_ch_steps); 188 + 189 + /* Flush FIFO of leftover data in the time it takes to disable adc */ 190 + fifo1count = tiadc_readl(adc_dev, REG_FIFO1CNT); 191 + for (i = 0; i < fifo1count; i++) 192 + read = tiadc_readl(adc_dev, REG_FIFO1); 193 + 194 + return 0; 195 + } 196 + 197 + static int tiadc_buffer_postdisable(struct iio_dev *indio_dev) 198 + { 199 + tiadc_step_config(indio_dev); 200 + 201 + return 0; 202 + } 203 + 204 + static const struct iio_buffer_setup_ops tiadc_buffer_setup_ops = { 205 + .preenable = &tiadc_buffer_preenable, 206 + .postenable = &tiadc_buffer_postenable, 207 + .predisable = &tiadc_buffer_predisable, 208 + .postdisable = &tiadc_buffer_postdisable, 209 + }; 210 + 211 + static int tiadc_iio_buffered_hardware_setup(struct iio_dev *indio_dev, 212 + irqreturn_t (*pollfunc_bh)(int irq, void *p), 213 + irqreturn_t (*pollfunc_th)(int irq, void *p), 214 + int irq, 215 + unsigned long flags, 216 + const struct iio_buffer_setup_ops *setup_ops) 217 + { 218 + int ret; 219 + 220 + indio_dev->buffer = iio_kfifo_allocate(indio_dev); 221 + if (!indio_dev->buffer) 222 + return -ENOMEM; 223 + 224 + ret = request_threaded_irq(irq, pollfunc_th, pollfunc_bh, 225 + flags, indio_dev->name, indio_dev); 226 + if (ret) 227 + goto error_kfifo_free; 228 + 229 + indio_dev->setup_ops = setup_ops; 230 + indio_dev->modes |= INDIO_BUFFER_HARDWARE; 231 + 232 + ret = iio_buffer_register(indio_dev, 233 + indio_dev->channels, 234 + indio_dev->num_channels); 235 + if (ret) 236 + goto error_free_irq; 237 + 238 + return 0; 239 + 240 + error_free_irq: 241 + free_irq(irq, indio_dev); 242 + error_kfifo_free: 243 + iio_kfifo_free(indio_dev->buffer); 244 + return ret; 245 + } 246 + 247 + static void tiadc_iio_buffered_hardware_remove(struct iio_dev *indio_dev) 248 + { 249 + struct tiadc_device *adc_dev = iio_priv(indio_dev); 250 + 251 + free_irq(adc_dev->mfd_tscadc->irq, indio_dev); 252 + iio_kfifo_free(indio_dev->buffer); 253 + iio_buffer_unregister(indio_dev); 254 + } 255 + 104 256 105 257 static const char * const chan_name_ain[] = { 106 258 "AIN0", ··· 300 120 chan->channel = adc_dev->channel_line[i]; 301 121 chan->info_mask_separate = BIT(IIO_CHAN_INFO_RAW); 302 122 chan->datasheet_name = chan_name_ain[chan->channel]; 123 + chan->scan_index = i; 303 124 chan->scan_type.sign = 'u'; 304 125 chan->scan_type.realbits = 12; 305 - chan->scan_type.storagebits = 32; 126 + chan->scan_type.storagebits = 16; 306 127 } 307 128 308 129 indio_dev->channels = chan_array; ··· 323 142 struct tiadc_device *adc_dev = iio_priv(indio_dev); 324 143 int i, map_val; 325 144 unsigned int fifo1count, read, stepid; 326 - u32 step = UINT_MAX; 327 145 bool found = false; 328 146 u32 step_en; 329 147 unsigned long timeout = jiffies + usecs_to_jiffies 330 148 (IDLE_TIMEOUT * adc_dev->channels); 149 + 150 + if (iio_buffer_enabled(indio_dev)) 151 + return -EBUSY; 152 + 331 153 step_en = get_adc_step_mask(adc_dev); 332 154 am335x_tsc_se_set(adc_dev->mfd_tscadc, step_en); 333 155 ··· 352 168 * Hence we need to flush out this data. 353 169 */ 354 170 355 - for (i = 0; i < ARRAY_SIZE(adc_dev->channel_step); i++) { 356 - if (chan->channel == adc_dev->channel_line[i]) { 357 - step = adc_dev->channel_step[i]; 358 - break; 359 - } 360 - } 361 - if (WARN_ON_ONCE(step == UINT_MAX)) 362 - return -EINVAL; 363 - 364 171 fifo1count = tiadc_readl(adc_dev, REG_FIFO1CNT); 365 172 for (i = 0; i < fifo1count; i++) { 366 173 read = tiadc_readl(adc_dev, REG_FIFO1); ··· 361 186 if (stepid == map_val) { 362 187 read = read & FIFOREAD_DATA_MASK; 363 188 found = true; 364 - *val = read; 189 + *val = (u16) read; 365 190 } 366 191 } 367 192 ··· 412 237 indio_dev->modes = INDIO_DIRECT_MODE; 413 238 indio_dev->info = &tiadc_info; 414 239 415 - tiadc_step_config(adc_dev); 240 + tiadc_step_config(indio_dev); 241 + tiadc_writel(adc_dev, REG_FIFO1THR, FIFO1_THRESHOLD); 416 242 417 243 err = tiadc_channel_init(indio_dev, adc_dev->channels); 418 244 if (err < 0) 419 245 return err; 420 246 421 - err = iio_device_register(indio_dev); 247 + err = tiadc_iio_buffered_hardware_setup(indio_dev, 248 + &tiadc_worker_h, 249 + &tiadc_irq_h, 250 + adc_dev->mfd_tscadc->irq, 251 + IRQF_SHARED, 252 + &tiadc_buffer_setup_ops); 253 + 422 254 if (err) 423 255 goto err_free_channels; 256 + 257 + err = iio_device_register(indio_dev); 258 + if (err) 259 + goto err_buffer_unregister; 424 260 425 261 platform_set_drvdata(pdev, indio_dev); 426 262 427 263 return 0; 428 264 265 + err_buffer_unregister: 266 + tiadc_iio_buffered_hardware_remove(indio_dev); 429 267 err_free_channels: 430 268 tiadc_channels_remove(indio_dev); 431 269 return err; ··· 451 263 u32 step_en; 452 264 453 265 iio_device_unregister(indio_dev); 266 + tiadc_iio_buffered_hardware_remove(indio_dev); 454 267 tiadc_channels_remove(indio_dev); 455 268 456 269 step_en = get_adc_step_mask(adc_dev); ··· 490 301 restore &= ~(CNTRLREG_POWERDOWN); 491 302 tiadc_writel(adc_dev, REG_CTRL, restore); 492 303 493 - tiadc_step_config(adc_dev); 304 + tiadc_step_config(indio_dev); 494 305 495 306 return 0; 496 307 }
+4 -4
drivers/iio/buffer_cb.c
··· 7 7 8 8 struct iio_cb_buffer { 9 9 struct iio_buffer buffer; 10 - int (*cb)(u8 *data, void *private); 10 + int (*cb)(const void *data, void *private); 11 11 void *private; 12 12 struct iio_channel *channels; 13 13 }; 14 14 15 - static int iio_buffer_cb_store_to(struct iio_buffer *buffer, u8 *data) 15 + static int iio_buffer_cb_store_to(struct iio_buffer *buffer, const void *data) 16 16 { 17 17 struct iio_cb_buffer *cb_buff = container_of(buffer, 18 18 struct iio_cb_buffer, ··· 21 21 return cb_buff->cb(data, cb_buff->private); 22 22 } 23 23 24 - static struct iio_buffer_access_funcs iio_cb_access = { 24 + static const struct iio_buffer_access_funcs iio_cb_access = { 25 25 .store_to = &iio_buffer_cb_store_to, 26 26 }; 27 27 28 28 struct iio_cb_buffer *iio_channel_get_all_cb(struct device *dev, 29 - int (*cb)(u8 *data, 29 + int (*cb)(const void *data, 30 30 void *private), 31 31 void *private) 32 32 {
+2 -5
drivers/iio/common/st_sensors/st_sensors_buffer.c
··· 113 113 if (len < 0) 114 114 goto st_sensors_get_buffer_element_error; 115 115 116 - if (indio_dev->scan_timestamp) 117 - *(s64 *)((u8 *)sdata->buffer_data + 118 - ALIGN(len, sizeof(s64))) = pf->timestamp; 119 - 120 - iio_push_to_buffers(indio_dev, sdata->buffer_data); 116 + iio_push_to_buffers_with_timestamp(indio_dev, sdata->buffer_data, 117 + pf->timestamp); 121 118 122 119 st_sensors_get_buffer_element_error: 123 120 iio_trigger_notify_done(indio_dev->trig);
+39 -31
drivers/iio/common/st_sensors/st_sensors_core.c
··· 198 198 } 199 199 EXPORT_SYMBOL(st_sensors_set_axis_enable); 200 200 201 - int st_sensors_init_sensor(struct iio_dev *indio_dev, 202 - struct st_sensors_platform_data *pdata) 201 + static int st_sensors_set_drdy_int_pin(struct iio_dev *indio_dev, 202 + struct st_sensors_platform_data *pdata) 203 203 { 204 - int err; 205 204 struct st_sensor_data *sdata = iio_priv(indio_dev); 206 - 207 - mutex_init(&sdata->tb.buf_lock); 208 205 209 206 switch (pdata->drdy_int_pin) { 210 207 case 1: 211 208 if (sdata->sensor->drdy_irq.mask_int1 == 0) { 212 209 dev_err(&indio_dev->dev, 213 210 "DRDY on INT1 not available.\n"); 214 - err = -EINVAL; 215 - goto init_error; 211 + return -EINVAL; 216 212 } 217 213 sdata->drdy_int_pin = 1; 218 214 break; ··· 216 220 if (sdata->sensor->drdy_irq.mask_int2 == 0) { 217 221 dev_err(&indio_dev->dev, 218 222 "DRDY on INT2 not available.\n"); 219 - err = -EINVAL; 220 - goto init_error; 223 + return -EINVAL; 221 224 } 222 225 sdata->drdy_int_pin = 2; 223 226 break; 224 227 default: 225 228 dev_err(&indio_dev->dev, "DRDY on pdata not valid.\n"); 226 - err = -EINVAL; 227 - goto init_error; 229 + return -EINVAL; 228 230 } 231 + 232 + return 0; 233 + } 234 + 235 + int st_sensors_init_sensor(struct iio_dev *indio_dev, 236 + struct st_sensors_platform_data *pdata) 237 + { 238 + struct st_sensor_data *sdata = iio_priv(indio_dev); 239 + int err = 0; 240 + 241 + mutex_init(&sdata->tb.buf_lock); 242 + 243 + if (pdata) 244 + err = st_sensors_set_drdy_int_pin(indio_dev, pdata); 229 245 230 246 err = st_sensors_set_enable(indio_dev, false); 231 247 if (err < 0) 232 - goto init_error; 248 + return err; 233 249 234 - err = st_sensors_set_fullscale(indio_dev, 235 - sdata->current_fullscale->num); 236 - if (err < 0) 237 - goto init_error; 250 + if (sdata->current_fullscale) { 251 + err = st_sensors_set_fullscale(indio_dev, 252 + sdata->current_fullscale->num); 253 + if (err < 0) 254 + return err; 255 + } else 256 + dev_info(&indio_dev->dev, "Full-scale not possible\n"); 238 257 239 258 err = st_sensors_set_odr(indio_dev, sdata->odr); 240 259 if (err < 0) 241 - goto init_error; 260 + return err; 242 261 243 262 /* set BDU */ 244 263 err = st_sensors_write_data_with_mask(indio_dev, 245 264 sdata->sensor->bdu.addr, sdata->sensor->bdu.mask, true); 246 265 if (err < 0) 247 - goto init_error; 266 + return err; 248 267 249 268 err = st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS); 250 269 251 - init_error: 252 270 return err; 253 271 } 254 272 EXPORT_SYMBOL(st_sensors_init_sensor); ··· 272 262 int err; 273 263 u8 drdy_mask; 274 264 struct st_sensor_data *sdata = iio_priv(indio_dev); 265 + 266 + if (!sdata->sensor->drdy_irq.addr) 267 + return 0; 275 268 276 269 /* Enable/Disable the interrupt generator 1. */ 277 270 if (sdata->sensor->drdy_irq.ig1.en_addr > 0) { ··· 331 318 unsigned int byte_for_channel = ch->scan_type.storagebits >> 3; 332 319 333 320 outdata = kmalloc(byte_for_channel, GFP_KERNEL); 334 - if (!outdata) { 335 - err = -EINVAL; 336 - goto st_sensors_read_axis_data_error; 337 - } 321 + if (!outdata) 322 + return -ENOMEM; 338 323 339 324 err = sdata->tf->read_multiple_byte(&sdata->tb, sdata->dev, 340 325 ch->address, byte_for_channel, ··· 347 336 348 337 st_sensors_free_memory: 349 338 kfree(outdata); 350 - st_sensors_read_axis_data_error: 339 + 351 340 return err; 352 341 } 353 342 ··· 360 349 mutex_lock(&indio_dev->mlock); 361 350 if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) { 362 351 err = -EBUSY; 363 - goto read_error; 352 + goto out; 364 353 } else { 365 354 err = st_sensors_set_enable(indio_dev, true); 366 355 if (err < 0) 367 - goto read_error; 356 + goto out; 368 357 369 358 msleep((sdata->sensor->bootime * 1000) / sdata->odr); 370 359 err = st_sensors_read_axis_data(indio_dev, ch, val); 371 360 if (err < 0) 372 - goto read_error; 361 + goto out; 373 362 374 363 *val = *val >> ch->scan_type.shift; 375 364 376 365 err = st_sensors_set_enable(indio_dev, false); 377 366 } 367 + out: 378 368 mutex_unlock(&indio_dev->mlock); 379 369 380 - return err; 381 - 382 - read_error: 383 - mutex_unlock(&indio_dev->mlock); 384 370 return err; 385 371 } 386 372 EXPORT_SYMBOL(st_sensors_read_info_raw);
+2 -1
drivers/iio/dac/ad5064.c
··· 285 285 .name = "powerdown", 286 286 .read = ad5064_read_dac_powerdown, 287 287 .write = ad5064_write_dac_powerdown, 288 + .shared = IIO_SEPARATE, 288 289 }, 289 - IIO_ENUM("powerdown_mode", false, &ad5064_powerdown_mode_enum), 290 + IIO_ENUM("powerdown_mode", IIO_SEPARATE, &ad5064_powerdown_mode_enum), 290 291 IIO_ENUM_AVAILABLE("powerdown_mode", &ad5064_powerdown_mode_enum), 291 292 { }, 292 293 };
+3 -1
drivers/iio/dac/ad5380.c
··· 247 247 .name = "powerdown", 248 248 .read = ad5380_read_dac_powerdown, 249 249 .write = ad5380_write_dac_powerdown, 250 + .shared = IIO_SEPARATE, 250 251 }, 251 - IIO_ENUM("powerdown_mode", true, &ad5380_powerdown_mode_enum), 252 + IIO_ENUM("powerdown_mode", IIO_SHARED_BY_TYPE, 253 + &ad5380_powerdown_mode_enum), 252 254 IIO_ENUM_AVAILABLE("powerdown_mode", &ad5380_powerdown_mode_enum), 253 255 { }, 254 256 };
+2 -1
drivers/iio/dac/ad5446.c
··· 132 132 .name = "powerdown", 133 133 .read = ad5446_read_dac_powerdown, 134 134 .write = ad5446_write_dac_powerdown, 135 + .shared = IIO_SEPARATE, 135 136 }, 136 - IIO_ENUM("powerdown_mode", false, &ad5446_powerdown_mode_enum), 137 + IIO_ENUM("powerdown_mode", IIO_SEPARATE, &ad5446_powerdown_mode_enum), 137 138 IIO_ENUM_AVAILABLE("powerdown_mode", &ad5446_powerdown_mode_enum), 138 139 { }, 139 140 };
+3 -1
drivers/iio/dac/ad5504.c
··· 248 248 .name = "powerdown", 249 249 .read = ad5504_read_dac_powerdown, 250 250 .write = ad5504_write_dac_powerdown, 251 + .shared = IIO_SEPARATE, 251 252 }, 252 - IIO_ENUM("powerdown_mode", true, &ad5504_powerdown_mode_enum), 253 + IIO_ENUM("powerdown_mode", IIO_SHARED_BY_TYPE, 254 + &ad5504_powerdown_mode_enum), 253 255 IIO_ENUM_AVAILABLE("powerdown_mode", &ad5504_powerdown_mode_enum), 254 256 { }, 255 257 };
+3 -1
drivers/iio/dac/ad5624r_spi.c
··· 163 163 .name = "powerdown", 164 164 .read = ad5624r_read_dac_powerdown, 165 165 .write = ad5624r_write_dac_powerdown, 166 + .shared = IIO_SEPARATE, 166 167 }, 167 - IIO_ENUM("powerdown_mode", true, &ad5624r_powerdown_mode_enum), 168 + IIO_ENUM("powerdown_mode", IIO_SHARED_BY_TYPE, 169 + &ad5624r_powerdown_mode_enum), 168 170 IIO_ENUM_AVAILABLE("powerdown_mode", &ad5624r_powerdown_mode_enum), 169 171 { }, 170 172 };
+2 -2
drivers/iio/dac/ad5686.c
··· 213 213 return ret; 214 214 *val = ret; 215 215 return IIO_VAL_INT; 216 - break; 217 216 case IIO_CHAN_INFO_SCALE: 218 217 scale_uv = (st->vref_mv * 100000) 219 218 >> (chan->scan_type.realbits); ··· 264 265 .name = "powerdown", 265 266 .read = ad5686_read_dac_powerdown, 266 267 .write = ad5686_write_dac_powerdown, 268 + .shared = IIO_SEPARATE, 267 269 }, 268 - IIO_ENUM("powerdown_mode", false, &ad5686_powerdown_mode_enum), 270 + IIO_ENUM("powerdown_mode", IIO_SEPARATE, &ad5686_powerdown_mode_enum), 269 271 IIO_ENUM_AVAILABLE("powerdown_mode", &ad5686_powerdown_mode_enum), 270 272 { }, 271 273 };
+1
drivers/iio/dac/ad5755.c
··· 386 386 .name = "powerdown", 387 387 .read = ad5755_read_powerdown, 388 388 .write = ad5755_write_powerdown, 389 + .shared = IIO_SEPARATE, 389 390 }, 390 391 { }, 391 392 };
+3 -2
drivers/iio/dac/ad5791.c
··· 287 287 static const struct iio_chan_spec_ext_info ad5791_ext_info[] = { 288 288 { 289 289 .name = "powerdown", 290 - .shared = true, 290 + .shared = IIO_SHARED_BY_TYPE, 291 291 .read = ad5791_read_dac_powerdown, 292 292 .write = ad5791_write_dac_powerdown, 293 293 }, 294 - IIO_ENUM("powerdown_mode", true, &ad5791_powerdown_mode_enum), 294 + IIO_ENUM("powerdown_mode", IIO_SHARED_BY_TYPE, 295 + &ad5791_powerdown_mode_enum), 295 296 IIO_ENUM_AVAILABLE("powerdown_mode", &ad5791_powerdown_mode_enum), 296 297 { }, 297 298 };
+1
drivers/iio/dac/ad7303.c
··· 169 169 .name = "powerdown", 170 170 .read = ad7303_read_dac_powerdown, 171 171 .write = ad7303_write_dac_powerdown, 172 + .shared = IIO_SEPARATE, 172 173 }, 173 174 { }, 174 175 };
+2 -1
drivers/iio/dac/mcp4725.c
··· 195 195 .name = "powerdown", 196 196 .read = mcp4725_read_powerdown, 197 197 .write = mcp4725_write_powerdown, 198 + .shared = IIO_SEPARATE, 198 199 }, 199 - IIO_ENUM("powerdown_mode", false, &mcp4725_powerdown_mode_enum), 200 + IIO_ENUM("powerdown_mode", IIO_SEPARATE, &mcp4725_powerdown_mode_enum), 200 201 IIO_ENUM_AVAILABLE("powerdown_mode", &mcp4725_powerdown_mode_enum), 201 202 { }, 202 203 };
+1
drivers/iio/frequency/adf4350.c
··· 351 351 .read = adf4350_read, \ 352 352 .write = adf4350_write, \ 353 353 .private = _ident, \ 354 + .shared = IIO_SEPARATE, \ 354 355 } 355 356 356 357 static const struct iio_chan_spec_ext_info adf4350_ext_info[] = {
-2
drivers/iio/gyro/adis16130.c
··· 103 103 default: 104 104 return -EINVAL; 105 105 } 106 - break; 107 106 case IIO_CHAN_INFO_OFFSET: 108 107 switch (chan->type) { 109 108 case IIO_ANGL_VEL: ··· 114 115 default: 115 116 return -EINVAL; 116 117 } 117 - break; 118 118 } 119 119 120 120 return -EINVAL;
-1
drivers/iio/gyro/adis16260.c
··· 239 239 default: 240 240 return -EINVAL; 241 241 } 242 - break; 243 242 case IIO_CHAN_INFO_OFFSET: 244 243 *val = 250000 / 1453; /* 25 C = 0x00 */ 245 244 return IIO_VAL_INT;
-1
drivers/iio/gyro/adxrs450.c
··· 354 354 default: 355 355 return -EINVAL; 356 356 } 357 - break; 358 357 case IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW: 359 358 ret = adxrs450_spi_read_reg_16(indio_dev, ADXRS450_QUAD1, &t); 360 359 if (ret)
+4 -3
drivers/iio/gyro/hid-sensor-gyro-3d.c
··· 182 182 }; 183 183 184 184 /* Function to push data to buffer */ 185 - static void hid_sensor_push_data(struct iio_dev *indio_dev, u8 *data, int len) 185 + static void hid_sensor_push_data(struct iio_dev *indio_dev, const void *data, 186 + int len) 186 187 { 187 188 dev_dbg(&indio_dev->dev, "hid_sensor_push_data\n"); 188 - iio_push_to_buffers(indio_dev, (u8 *)data); 189 + iio_push_to_buffers(indio_dev, data); 189 190 } 190 191 191 192 /* Callback handler to send event after all samples are received and captured */ ··· 201 200 gyro_state->common_attributes.data_ready); 202 201 if (gyro_state->common_attributes.data_ready) 203 202 hid_sensor_push_data(indio_dev, 204 - (u8 *)gyro_state->gyro_val, 203 + gyro_state->gyro_val, 205 204 sizeof(gyro_state->gyro_val)); 206 205 207 206 return 0;
+1 -4
drivers/iio/gyro/itg3200_buffer.c
··· 55 55 if (ret < 0) 56 56 goto error_ret; 57 57 58 - if (indio_dev->scan_timestamp) 59 - memcpy(buf + indio_dev->scan_bytes - sizeof(s64), 60 - &pf->timestamp, sizeof(pf->timestamp)); 58 + iio_push_to_buffers_with_timestamp(indio_dev, buf, pf->timestamp); 61 59 62 - iio_push_to_buffers(indio_dev, (u8 *)buf); 63 60 iio_trigger_notify_done(indio_dev->trig); 64 61 65 62 error_ret:
+15 -15
drivers/iio/gyro/st_gyro_core.c
··· 305 305 int st_gyro_common_probe(struct iio_dev *indio_dev, 306 306 struct st_sensors_platform_data *pdata) 307 307 { 308 - int err; 309 308 struct st_sensor_data *gdata = iio_priv(indio_dev); 309 + int irq = gdata->get_irq_data_ready(indio_dev); 310 + int err; 310 311 311 312 indio_dev->modes = INDIO_DIRECT_MODE; 312 313 indio_dev->info = &gyro_info; ··· 315 314 err = st_sensors_check_device_support(indio_dev, 316 315 ARRAY_SIZE(st_gyro_sensors), st_gyro_sensors); 317 316 if (err < 0) 318 - goto st_gyro_common_probe_error; 317 + return err; 319 318 320 319 gdata->num_data_channels = ST_GYRO_NUMBER_DATA_CHANNELS; 321 320 gdata->multiread_bit = gdata->sensor->multi_read_bit; ··· 328 327 329 328 err = st_sensors_init_sensor(indio_dev, pdata); 330 329 if (err < 0) 331 - goto st_gyro_common_probe_error; 330 + return err; 332 331 333 - if (gdata->get_irq_data_ready(indio_dev) > 0) { 334 - err = st_gyro_allocate_ring(indio_dev); 335 - if (err < 0) 336 - goto st_gyro_common_probe_error; 332 + err = st_gyro_allocate_ring(indio_dev); 333 + if (err < 0) 334 + return err; 337 335 336 + if (irq > 0) { 338 337 err = st_sensors_allocate_trigger(indio_dev, 339 338 ST_GYRO_TRIGGER_OPS); 340 339 if (err < 0) ··· 345 344 if (err) 346 345 goto st_gyro_device_register_error; 347 346 348 - return err; 347 + return 0; 349 348 350 349 st_gyro_device_register_error: 351 - if (gdata->get_irq_data_ready(indio_dev) > 0) 350 + if (irq > 0) 352 351 st_sensors_deallocate_trigger(indio_dev); 353 352 st_gyro_probe_trigger_error: 354 - if (gdata->get_irq_data_ready(indio_dev) > 0) 355 - st_gyro_deallocate_ring(indio_dev); 356 - st_gyro_common_probe_error: 353 + st_gyro_deallocate_ring(indio_dev); 354 + 357 355 return err; 358 356 } 359 357 EXPORT_SYMBOL(st_gyro_common_probe); ··· 362 362 struct st_sensor_data *gdata = iio_priv(indio_dev); 363 363 364 364 iio_device_unregister(indio_dev); 365 - if (gdata->get_irq_data_ready(indio_dev) > 0) { 365 + if (gdata->get_irq_data_ready(indio_dev) > 0) 366 366 st_sensors_deallocate_trigger(indio_dev); 367 - st_gyro_deallocate_ring(indio_dev); 368 - } 367 + 368 + st_gyro_deallocate_ring(indio_dev); 369 369 } 370 370 EXPORT_SYMBOL(st_gyro_common_remove); 371 371
+1 -1
drivers/iio/iio_core.h
··· 30 30 const char *buf, 31 31 size_t len), 32 32 u64 mask, 33 - bool generic, 33 + enum iio_shared_by shared_by, 34 34 struct device *dev, 35 35 struct list_head *attr_list); 36 36
+2 -7
drivers/iio/imu/adis16400_buffer.c
··· 82 82 spi_setup(st->adis.spi); 83 83 } 84 84 85 - /* Guaranteed to be aligned with 8 byte boundary */ 86 - if (indio_dev->scan_timestamp) { 87 - void *b = adis->buffer + indio_dev->scan_bytes - sizeof(s64); 88 - *(s64 *)b = pf->timestamp; 89 - } 90 - 91 - iio_push_to_buffers(indio_dev, adis->buffer); 85 + iio_push_to_buffers_with_timestamp(indio_dev, adis->buffer, 86 + pf->timestamp); 92 87 93 88 iio_trigger_notify_done(indio_dev->trig); 94 89
+2 -7
drivers/iio/imu/adis_buffer.c
··· 102 102 mutex_unlock(&adis->txrx_lock); 103 103 } 104 104 105 - /* Guaranteed to be aligned with 8 byte boundary */ 106 - if (indio_dev->scan_timestamp) { 107 - void *b = adis->buffer + indio_dev->scan_bytes - sizeof(s64); 108 - *(s64 *)b = pf->timestamp; 109 - } 110 - 111 - iio_push_to_buffers(indio_dev, adis->buffer); 105 + iio_push_to_buffers_with_timestamp(indio_dev, adis->buffer, 106 + pf->timestamp); 112 107 113 108 iio_trigger_notify_done(indio_dev->trig); 114 109
+2 -4
drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
··· 124 124 u8 data[INV_MPU6050_OUTPUT_DATA_SIZE]; 125 125 u16 fifo_count; 126 126 s64 timestamp; 127 - u64 *tmp; 128 127 129 128 mutex_lock(&indio_dev->mlock); 130 129 if (!(st->chip_config.accl_fifo_enable | ··· 169 170 if (0 == result) 170 171 timestamp = 0; 171 172 172 - tmp = (u64 *)data; 173 - tmp[DIV_ROUND_UP(bytes_per_datum, 8)] = timestamp; 174 - result = iio_push_to_buffers(indio_dev, data); 173 + result = iio_push_to_buffers_with_timestamp(indio_dev, data, 174 + timestamp); 175 175 if (result) 176 176 goto flush_fifo; 177 177 fifo_count -= bytes_per_datum;
+27 -33
drivers/iio/industrialio-buffer.c
··· 31 31 [IIO_LE] = "le", 32 32 }; 33 33 34 - static bool iio_buffer_is_active(struct iio_dev *indio_dev, 35 - struct iio_buffer *buf) 34 + static bool iio_buffer_is_active(struct iio_buffer *buf) 36 35 { 37 - struct list_head *p; 38 - 39 - list_for_each(p, &indio_dev->buffer_list) 40 - if (p == &buf->buffer_list) 41 - return true; 42 - 43 - return false; 36 + return !list_empty(&buf->buffer_list); 44 37 } 45 38 46 39 /** ··· 72 79 void iio_buffer_init(struct iio_buffer *buffer) 73 80 { 74 81 INIT_LIST_HEAD(&buffer->demux_list); 82 + INIT_LIST_HEAD(&buffer->buffer_list); 75 83 init_waitqueue_head(&buffer->pollq); 76 84 } 77 85 EXPORT_SYMBOL(iio_buffer_init); ··· 140 146 if (ret < 0) 141 147 return ret; 142 148 mutex_lock(&indio_dev->mlock); 143 - if (iio_buffer_is_active(indio_dev, indio_dev->buffer)) { 149 + if (iio_buffer_is_active(indio_dev->buffer)) { 144 150 ret = -EBUSY; 145 151 goto error_ret; 146 152 } ··· 186 192 return ret; 187 193 188 194 mutex_lock(&indio_dev->mlock); 189 - if (iio_buffer_is_active(indio_dev, indio_dev->buffer)) { 195 + if (iio_buffer_is_active(indio_dev->buffer)) { 190 196 ret = -EBUSY; 191 197 goto error_ret; 192 198 } ··· 208 214 &iio_show_scan_index, 209 215 NULL, 210 216 0, 211 - 0, 217 + IIO_SEPARATE, 212 218 &indio_dev->dev, 213 219 &buffer->scan_el_dev_attr_list); 214 220 if (ret) ··· 243 249 0, 244 250 &indio_dev->dev, 245 251 &buffer->scan_el_dev_attr_list); 252 + if (ret) 253 + goto error_ret; 246 254 attrcount++; 247 255 ret = attrcount; 248 256 error_ret: ··· 392 396 return len; 393 397 394 398 mutex_lock(&indio_dev->mlock); 395 - if (iio_buffer_is_active(indio_dev, indio_dev->buffer)) { 399 + if (iio_buffer_is_active(indio_dev->buffer)) { 396 400 ret = -EBUSY; 397 401 } else { 398 402 if (buffer->access->set_length) ··· 410 414 char *buf) 411 415 { 412 416 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 413 - return sprintf(buf, "%d\n", 414 - iio_buffer_is_active(indio_dev, 415 - indio_dev->buffer)); 417 + return sprintf(buf, "%d\n", iio_buffer_is_active(indio_dev->buffer)); 416 418 } 417 419 EXPORT_SYMBOL(iio_buffer_show_enable); 418 420 419 - /* note NULL used as error indicator as it doesn't make sense. */ 421 + /* Note NULL used as error indicator as it doesn't make sense. */ 420 422 static const unsigned long *iio_scan_mask_match(const unsigned long *av_masks, 421 423 unsigned int masklength, 422 424 const unsigned long *mask) ··· 429 435 return NULL; 430 436 } 431 437 432 - static int iio_compute_scan_bytes(struct iio_dev *indio_dev, const long *mask, 433 - bool timestamp) 438 + static int iio_compute_scan_bytes(struct iio_dev *indio_dev, 439 + const unsigned long *mask, bool timestamp) 434 440 { 435 441 const struct iio_chan_spec *ch; 436 442 unsigned bytes = 0; ··· 484 490 indio_dev->active_scan_mask = NULL; 485 491 486 492 if (remove_buffer) 487 - list_del(&remove_buffer->buffer_list); 493 + list_del_init(&remove_buffer->buffer_list); 488 494 if (insert_buffer) 489 495 list_add(&insert_buffer->buffer_list, &indio_dev->buffer_list); 490 496 ··· 496 502 return 0; 497 503 } 498 504 499 - /* What scan mask do we actually have ?*/ 505 + /* What scan mask do we actually have? */ 500 506 compound_mask = kcalloc(BITS_TO_LONGS(indio_dev->masklength), 501 507 sizeof(long), GFP_KERNEL); 502 508 if (compound_mask == NULL) { ··· 521 527 * Roll back. 522 528 * Note can only occur when adding a buffer. 523 529 */ 524 - list_del(&insert_buffer->buffer_list); 530 + list_del_init(&insert_buffer->buffer_list); 525 531 indio_dev->active_scan_mask = old_mask; 526 532 success = -EINVAL; 527 533 } ··· 562 568 goto error_run_postdisable; 563 569 } 564 570 } 565 - /* Definitely possible for devices to support both of these.*/ 571 + /* Definitely possible for devices to support both of these. */ 566 572 if (indio_dev->modes & INDIO_BUFFER_TRIGGERED) { 567 573 if (!indio_dev->trig) { 568 574 printk(KERN_INFO "Buffer not started: no trigger\n"); ··· 573 579 indio_dev->currentmode = INDIO_BUFFER_TRIGGERED; 574 580 } else if (indio_dev->modes & INDIO_BUFFER_HARDWARE) { 575 581 indio_dev->currentmode = INDIO_BUFFER_HARDWARE; 576 - } else { /* should never be reached */ 582 + } else { /* Should never be reached */ 577 583 ret = -EINVAL; 578 584 goto error_run_postdisable; 579 585 } ··· 605 611 error_remove_inserted: 606 612 607 613 if (insert_buffer) 608 - list_del(&insert_buffer->buffer_list); 614 + list_del_init(&insert_buffer->buffer_list); 609 615 indio_dev->active_scan_mask = old_mask; 610 616 kfree(compound_mask); 611 617 error_ret: ··· 622 628 int ret; 623 629 bool requested_state; 624 630 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 625 - struct iio_buffer *pbuf = indio_dev->buffer; 626 631 bool inlist; 627 632 628 633 ret = strtobool(buf, &requested_state); ··· 631 638 mutex_lock(&indio_dev->mlock); 632 639 633 640 /* Find out if it is in the list */ 634 - inlist = iio_buffer_is_active(indio_dev, pbuf); 641 + inlist = iio_buffer_is_active(indio_dev->buffer); 635 642 /* Already in desired state */ 636 643 if (inlist == requested_state) 637 644 goto done; ··· 696 703 697 704 /** 698 705 * iio_scan_mask_set() - set particular bit in the scan mask 706 + * @indio_dev: the iio device 699 707 * @buffer: the buffer whose scan mask we are interested in 700 708 * @bit: the bit to be set. 701 709 * ··· 717 723 if (trialmask == NULL) 718 724 return -ENOMEM; 719 725 if (!indio_dev->masklength) { 720 - WARN_ON("trying to set scanmask prior to registering buffer\n"); 726 + WARN_ON("Trying to set scanmask prior to registering buffer\n"); 721 727 goto err_invalid_mask; 722 728 } 723 729 bitmap_copy(trialmask, buffer->scan_mask, indio_dev->masklength); ··· 772 778 struct list_head l; 773 779 }; 774 780 775 - static unsigned char *iio_demux(struct iio_buffer *buffer, 776 - unsigned char *datain) 781 + static const void *iio_demux(struct iio_buffer *buffer, 782 + const void *datain) 777 783 { 778 784 struct iio_demux_table *t; 779 785 ··· 786 792 return buffer->demux_bounce; 787 793 } 788 794 789 - static int iio_push_to_buffer(struct iio_buffer *buffer, unsigned char *data) 795 + static int iio_push_to_buffer(struct iio_buffer *buffer, const void *data) 790 796 { 791 - unsigned char *dataout = iio_demux(buffer, data); 797 + const void *dataout = iio_demux(buffer, data); 792 798 793 799 return buffer->access->store_to(buffer, dataout); 794 800 } ··· 803 809 } 804 810 805 811 806 - int iio_push_to_buffers(struct iio_dev *indio_dev, unsigned char *data) 812 + int iio_push_to_buffers(struct iio_dev *indio_dev, const void *data) 807 813 { 808 814 int ret; 809 815 struct iio_buffer *buf;
+115 -73
drivers/iio/industrialio-core.c
··· 101 101 [IIO_CHAN_INFO_PHASE] = "phase", 102 102 [IIO_CHAN_INFO_HARDWAREGAIN] = "hardwaregain", 103 103 [IIO_CHAN_INFO_HYSTERESIS] = "hysteresis", 104 + [IIO_CHAN_INFO_INT_TIME] = "integration_time", 104 105 }; 105 106 106 107 const struct iio_chan_spec ··· 517 516 struct device_attribute *attr, 518 517 const char *buf, 519 518 size_t len), 520 - bool generic) 519 + enum iio_shared_by shared_by) 521 520 { 522 - int ret; 523 - char *name_format, *full_postfix; 521 + int ret = 0; 522 + char *name_format = NULL; 523 + char *full_postfix; 524 524 sysfs_attr_init(&dev_attr->attr); 525 525 526 526 /* Build up postfix of <extend_name>_<modifier>_postfix */ 527 - if (chan->modified && !generic) { 527 + if (chan->modified && (shared_by == IIO_SEPARATE)) { 528 528 if (chan->extend_name) 529 529 full_postfix = kasprintf(GFP_KERNEL, "%s_%s_%s", 530 530 iio_modifier_names[chan ··· 546 544 chan->extend_name, 547 545 postfix); 548 546 } 549 - if (full_postfix == NULL) { 550 - ret = -ENOMEM; 551 - goto error_ret; 552 - } 547 + if (full_postfix == NULL) 548 + return -ENOMEM; 553 549 554 550 if (chan->differential) { /* Differential can not have modifier */ 555 - if (generic) 551 + switch (shared_by) { 552 + case IIO_SHARED_BY_ALL: 553 + name_format = kasprintf(GFP_KERNEL, "%s", full_postfix); 554 + break; 555 + case IIO_SHARED_BY_DIR: 556 + name_format = kasprintf(GFP_KERNEL, "%s_%s", 557 + iio_direction[chan->output], 558 + full_postfix); 559 + break; 560 + case IIO_SHARED_BY_TYPE: 556 561 name_format 557 562 = kasprintf(GFP_KERNEL, "%s_%s-%s_%s", 558 563 iio_direction[chan->output], 559 564 iio_chan_type_name_spec[chan->type], 560 565 iio_chan_type_name_spec[chan->type], 561 566 full_postfix); 562 - else if (chan->indexed) 567 + break; 568 + case IIO_SEPARATE: 569 + if (!chan->indexed) { 570 + WARN_ON("Differential channels must be indexed\n"); 571 + ret = -EINVAL; 572 + goto error_free_full_postfix; 573 + } 563 574 name_format 564 - = kasprintf(GFP_KERNEL, "%s_%s%d-%s%d_%s", 575 + = kasprintf(GFP_KERNEL, 576 + "%s_%s%d-%s%d_%s", 565 577 iio_direction[chan->output], 566 578 iio_chan_type_name_spec[chan->type], 567 579 chan->channel, 568 580 iio_chan_type_name_spec[chan->type], 569 581 chan->channel2, 570 582 full_postfix); 571 - else { 572 - WARN_ON("Differential channels must be indexed\n"); 573 - ret = -EINVAL; 574 - goto error_free_full_postfix; 583 + break; 575 584 } 576 585 } else { /* Single ended */ 577 - if (generic) 586 + switch (shared_by) { 587 + case IIO_SHARED_BY_ALL: 588 + name_format = kasprintf(GFP_KERNEL, "%s", full_postfix); 589 + break; 590 + case IIO_SHARED_BY_DIR: 591 + name_format = kasprintf(GFP_KERNEL, "%s_%s", 592 + iio_direction[chan->output], 593 + full_postfix); 594 + break; 595 + case IIO_SHARED_BY_TYPE: 578 596 name_format 579 597 = kasprintf(GFP_KERNEL, "%s_%s_%s", 580 598 iio_direction[chan->output], 581 599 iio_chan_type_name_spec[chan->type], 582 600 full_postfix); 583 - else if (chan->indexed) 584 - name_format 585 - = kasprintf(GFP_KERNEL, "%s_%s%d_%s", 586 - iio_direction[chan->output], 587 - iio_chan_type_name_spec[chan->type], 588 - chan->channel, 589 - full_postfix); 590 - else 591 - name_format 592 - = kasprintf(GFP_KERNEL, "%s_%s_%s", 593 - iio_direction[chan->output], 594 - iio_chan_type_name_spec[chan->type], 595 - full_postfix); 601 + break; 602 + 603 + case IIO_SEPARATE: 604 + if (chan->indexed) 605 + name_format 606 + = kasprintf(GFP_KERNEL, "%s_%s%d_%s", 607 + iio_direction[chan->output], 608 + iio_chan_type_name_spec[chan->type], 609 + chan->channel, 610 + full_postfix); 611 + else 612 + name_format 613 + = kasprintf(GFP_KERNEL, "%s_%s_%s", 614 + iio_direction[chan->output], 615 + iio_chan_type_name_spec[chan->type], 616 + full_postfix); 617 + break; 618 + } 596 619 } 597 620 if (name_format == NULL) { 598 621 ret = -ENOMEM; ··· 641 614 dev_attr->attr.mode |= S_IWUSR; 642 615 dev_attr->store = writefunc; 643 616 } 644 - kfree(name_format); 645 - kfree(full_postfix); 646 - 647 - return 0; 648 - 649 617 error_free_name_format: 650 618 kfree(name_format); 651 619 error_free_full_postfix: 652 620 kfree(full_postfix); 653 - error_ret: 621 + 654 622 return ret; 655 623 } 656 624 ··· 664 642 const char *buf, 665 643 size_t len), 666 644 u64 mask, 667 - bool generic, 645 + enum iio_shared_by shared_by, 668 646 struct device *dev, 669 647 struct list_head *attr_list) 670 648 { ··· 678 656 } 679 657 ret = __iio_device_attr_init(&iio_attr->dev_attr, 680 658 postfix, chan, 681 - readfunc, writefunc, generic); 659 + readfunc, writefunc, shared_by); 682 660 if (ret) 683 661 goto error_iio_dev_attr_free; 684 662 iio_attr->c = chan; ··· 686 664 list_for_each_entry(t, attr_list, l) 687 665 if (strcmp(t->dev_attr.attr.name, 688 666 iio_attr->dev_attr.attr.name) == 0) { 689 - if (!generic) 667 + if (shared_by == IIO_SEPARATE) 690 668 dev_err(dev, "tried to double register : %s\n", 691 669 t->dev_attr.attr.name); 692 670 ret = -EBUSY; ··· 704 682 return ret; 705 683 } 706 684 685 + static int iio_device_add_info_mask_type(struct iio_dev *indio_dev, 686 + struct iio_chan_spec const *chan, 687 + enum iio_shared_by shared_by, 688 + const long *infomask) 689 + { 690 + int i, ret, attrcount = 0; 691 + 692 + for_each_set_bit(i, infomask, sizeof(infomask)*8) { 693 + ret = __iio_add_chan_devattr(iio_chan_info_postfix[i], 694 + chan, 695 + &iio_read_channel_info, 696 + &iio_write_channel_info, 697 + i, 698 + shared_by, 699 + &indio_dev->dev, 700 + &indio_dev->channel_attr_list); 701 + if ((ret == -EBUSY) && (shared_by != IIO_SEPARATE)) 702 + continue; 703 + else if (ret < 0) 704 + return ret; 705 + attrcount++; 706 + } 707 + 708 + return attrcount; 709 + } 710 + 707 711 static int iio_device_add_channel_sysfs(struct iio_dev *indio_dev, 708 712 struct iio_chan_spec const *chan) 709 713 { 710 714 int ret, attrcount = 0; 711 - int i; 712 715 const struct iio_chan_spec_ext_info *ext_info; 713 716 714 717 if (chan->channel < 0) 715 718 return 0; 716 - for_each_set_bit(i, &chan->info_mask_separate, sizeof(long)*8) { 717 - ret = __iio_add_chan_devattr(iio_chan_info_postfix[i], 718 - chan, 719 - &iio_read_channel_info, 720 - &iio_write_channel_info, 721 - i, 722 - 0, 723 - &indio_dev->dev, 724 - &indio_dev->channel_attr_list); 725 - if (ret < 0) 726 - goto error_ret; 727 - attrcount++; 728 - } 729 - for_each_set_bit(i, &chan->info_mask_shared_by_type, sizeof(long)*8) { 730 - ret = __iio_add_chan_devattr(iio_chan_info_postfix[i], 731 - chan, 732 - &iio_read_channel_info, 733 - &iio_write_channel_info, 734 - i, 735 - 1, 736 - &indio_dev->dev, 737 - &indio_dev->channel_attr_list); 738 - if (ret == -EBUSY) { 739 - ret = 0; 740 - continue; 741 - } else if (ret < 0) { 742 - goto error_ret; 743 - } 744 - attrcount++; 745 - } 719 + ret = iio_device_add_info_mask_type(indio_dev, chan, 720 + IIO_SEPARATE, 721 + &chan->info_mask_separate); 722 + if (ret < 0) 723 + return ret; 724 + attrcount += ret; 725 + 726 + ret = iio_device_add_info_mask_type(indio_dev, chan, 727 + IIO_SHARED_BY_TYPE, 728 + &chan->info_mask_shared_by_type); 729 + if (ret < 0) 730 + return ret; 731 + attrcount += ret; 732 + 733 + ret = iio_device_add_info_mask_type(indio_dev, chan, 734 + IIO_SHARED_BY_DIR, 735 + &chan->info_mask_shared_by_dir); 736 + if (ret < 0) 737 + return ret; 738 + attrcount += ret; 739 + 740 + ret = iio_device_add_info_mask_type(indio_dev, chan, 741 + IIO_SHARED_BY_ALL, 742 + &chan->info_mask_shared_by_all); 743 + if (ret < 0) 744 + return ret; 745 + attrcount += ret; 746 746 747 747 if (chan->ext_info) { 748 748 unsigned int i = 0; ··· 784 740 continue; 785 741 786 742 if (ret) 787 - goto error_ret; 743 + return ret; 788 744 789 745 attrcount++; 790 746 } 791 747 } 792 748 793 - ret = attrcount; 794 - error_ret: 795 - return ret; 749 + return attrcount; 796 750 } 797 751 798 752 static void iio_device_remove_and_free_read_attr(struct iio_dev *indio_dev,
+1 -1
drivers/iio/industrialio-event.c
··· 159 159 } 160 160 spin_unlock_irq(&ev_int->wait.lock); 161 161 fd = anon_inode_getfd("iio:event", 162 - &iio_event_chrdev_fileops, ev_int, O_RDONLY); 162 + &iio_event_chrdev_fileops, ev_int, O_RDONLY | O_CLOEXEC); 163 163 if (fd < 0) { 164 164 spin_lock_irq(&ev_int->wait.lock); 165 165 __clear_bit(IIO_BUSY_BIT_POS, &ev_int->flags);
+3 -2
drivers/iio/kfifo_buf.c
··· 7 7 #include <linux/mutex.h> 8 8 #include <linux/iio/kfifo_buf.h> 9 9 #include <linux/sched.h> 10 + #include <linux/poll.h> 10 11 11 12 struct iio_kfifo { 12 13 struct iio_buffer buffer; ··· 95 94 } 96 95 97 96 static int iio_store_to_kfifo(struct iio_buffer *r, 98 - u8 *data) 97 + const void *data) 99 98 { 100 99 int ret; 101 100 struct iio_kfifo *kf = iio_to_kfifo(r); ··· 103 102 if (ret != 1) 104 103 return -EBUSY; 105 104 r->stufftoread = true; 106 - wake_up_interruptible(&r->pollq); 105 + wake_up_interruptible_poll(&r->pollq, POLLIN | POLLRDNORM); 107 106 108 107 return 0; 109 108 }
+32
drivers/iio/light/Kconfig
··· 27 27 To compile this driver as a module, choose M here: the 28 28 module will be called apds9300. 29 29 30 + config GP2AP020A00F 31 + tristate "Sharp GP2AP020A00F Proximity/ALS sensor" 32 + depends on I2C 33 + select IIO_BUFFER 34 + select IIO_TRIGGERED_BUFFER 35 + help 36 + Say Y here if you have a Sharp GP2AP020A00F proximity/ALS combo-chip 37 + hooked to an I2C bus. 38 + 39 + To compile this driver as a module, choose M here: the 40 + module will be called gp2ap020a00f. 41 + 30 42 config HID_SENSOR_ALS 31 43 depends on HID_SENSOR_HUB 32 44 select IIO_BUFFER ··· 67 55 changes. The ALS-control output values can be set per zone for the 68 56 three current output channels. 69 57 58 + config TCS3472 59 + tristate "TAOS TCS3472 color light-to-digital converter" 60 + depends on I2C 61 + help 62 + If you say yes here you get support for the TAOS TCS3472 63 + family of color light-to-digital converters with IR filter. 64 + 65 + This driver can also be built as a module. If so, the module 66 + will be called tcs3472. 67 + 70 68 config SENSORS_TSL2563 71 69 tristate "TAOS TSL2560, TSL2561, TSL2562 and TSL2563 ambient light sensors" 72 70 depends on I2C ··· 86 64 87 65 This driver can also be built as a module. If so, the module 88 66 will be called tsl2563. 67 + 68 + config TSL4531 69 + tristate "TAOS TSL4531 ambient light sensors" 70 + depends on I2C 71 + help 72 + Say Y here if you want to build a driver for the TAOS TSL4531 family 73 + of ambient light sensors with direct lux output. 74 + 75 + To compile this driver as a module, choose M here: the 76 + module will be called tsl4531. 89 77 90 78 config VCNL4000 91 79 tristate "VCNL4000 combined ALS and proximity sensor"
+3
drivers/iio/light/Makefile
··· 5 5 # When adding new entries keep the list in alphabetical order 6 6 obj-$(CONFIG_ADJD_S311) += adjd_s311.o 7 7 obj-$(CONFIG_APDS9300) += apds9300.o 8 + obj-$(CONFIG_GP2AP020A00F) += gp2ap020a00f.o 8 9 obj-$(CONFIG_HID_SENSOR_ALS) += hid-sensor-als.o 9 10 obj-$(CONFIG_SENSORS_LM3533) += lm3533-als.o 10 11 obj-$(CONFIG_SENSORS_TSL2563) += tsl2563.o 12 + obj-$(CONFIG_TCS3472) += tcs3472.o 13 + obj-$(CONFIG_TSL4531) += tsl4531.o 11 14 obj-$(CONFIG_VCNL4000) += vcnl4000.o
+22 -55
drivers/iio/light/adjd_s311.c
··· 114 114 return 0; 115 115 } 116 116 117 - static ssize_t adjd_s311_read_int_time(struct iio_dev *indio_dev, 118 - uintptr_t private, const struct iio_chan_spec *chan, char *buf) 119 - { 120 - struct adjd_s311_data *data = iio_priv(indio_dev); 121 - s32 ret; 122 - 123 - ret = i2c_smbus_read_word_data(data->client, 124 - ADJD_S311_INT_REG(chan->address)); 125 - if (ret < 0) 126 - return ret; 127 - 128 - return sprintf(buf, "%d\n", ret & ADJD_S311_INT_MASK); 129 - } 130 - 131 - static ssize_t adjd_s311_write_int_time(struct iio_dev *indio_dev, 132 - uintptr_t private, const struct iio_chan_spec *chan, const char *buf, 133 - size_t len) 134 - { 135 - struct adjd_s311_data *data = iio_priv(indio_dev); 136 - unsigned long int_time; 137 - int ret; 138 - 139 - ret = kstrtoul(buf, 10, &int_time); 140 - if (ret) 141 - return ret; 142 - 143 - if (int_time > ADJD_S311_INT_MASK) 144 - return -EINVAL; 145 - 146 - ret = i2c_smbus_write_word_data(data->client, 147 - ADJD_S311_INT_REG(chan->address), int_time); 148 - if (ret < 0) 149 - return ret; 150 - 151 - return len; 152 - } 153 - 154 117 static irqreturn_t adjd_s311_trigger_handler(int irq, void *p) 155 118 { 156 119 struct iio_poll_func *pf = p; ··· 138 175 len += 2; 139 176 } 140 177 141 - if (indio_dev->scan_timestamp) 142 - *(s64 *)((u8 *)data->buffer + ALIGN(len, sizeof(s64))) 143 - = time_ns; 144 - iio_push_to_buffers(indio_dev, (u8 *)data->buffer); 178 + iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, time_ns); 145 179 146 180 done: 147 181 iio_trigger_notify_done(indio_dev->trig); ··· 146 186 return IRQ_HANDLED; 147 187 } 148 188 149 - static const struct iio_chan_spec_ext_info adjd_s311_ext_info[] = { 150 - { 151 - .name = "integration_time", 152 - .read = adjd_s311_read_int_time, 153 - .write = adjd_s311_write_int_time, 154 - }, 155 - { } 156 - }; 157 - 158 189 #define ADJD_S311_CHANNEL(_color, _scan_idx) { \ 159 190 .type = IIO_INTENSITY, \ 160 191 .modified = 1, \ 161 192 .address = (IDX_##_color), \ 162 193 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 163 - BIT(IIO_CHAN_INFO_HARDWAREGAIN), \ 194 + BIT(IIO_CHAN_INFO_HARDWAREGAIN) | \ 195 + BIT(IIO_CHAN_INFO_INT_TIME), \ 164 196 .channel2 = (IIO_MOD_LIGHT_##_color), \ 165 197 .scan_index = (_scan_idx), \ 166 198 .scan_type = IIO_ST('u', 10, 16, 0), \ 167 - .ext_info = adjd_s311_ext_info, \ 168 199 } 169 200 170 201 static const struct iio_chan_spec adjd_s311_channels[] = { ··· 187 236 return ret; 188 237 *val = ret & ADJD_S311_CAP_MASK; 189 238 return IIO_VAL_INT; 239 + case IIO_CHAN_INFO_INT_TIME: 240 + ret = i2c_smbus_read_word_data(data->client, 241 + ADJD_S311_INT_REG(chan->address)); 242 + if (ret < 0) 243 + return ret; 244 + *val = 0; 245 + /* 246 + * not documented, based on measurement: 247 + * 4095 LSBs correspond to roughly 4 ms 248 + */ 249 + *val2 = ret & ADJD_S311_INT_MASK; 250 + return IIO_VAL_INT_PLUS_MICRO; 190 251 } 191 252 return -EINVAL; 192 253 } ··· 208 245 int val, int val2, long mask) 209 246 { 210 247 struct adjd_s311_data *data = iio_priv(indio_dev); 211 - int ret; 212 248 213 249 switch (mask) { 214 250 case IIO_CHAN_INFO_HARDWAREGAIN: 215 251 if (val < 0 || val > ADJD_S311_CAP_MASK) 216 252 return -EINVAL; 217 253 218 - ret = i2c_smbus_write_byte_data(data->client, 254 + return i2c_smbus_write_byte_data(data->client, 219 255 ADJD_S311_CAP_REG(chan->address), val); 220 - return ret; 256 + case IIO_CHAN_INFO_INT_TIME: 257 + if (val != 0 || val2 < 0 || val2 > ADJD_S311_INT_MASK) 258 + return -EINVAL; 259 + 260 + return i2c_smbus_write_word_data(data->client, 261 + ADJD_S311_INT_REG(chan->address), val2); 221 262 } 222 263 return -EINVAL; 223 264 }
+1617
drivers/iio/light/gp2ap020a00f.c
··· 1 + /* 2 + * Copyright (C) 2013 Samsung Electronics Co., Ltd. 3 + * Author: Jacek Anaszewski <j.anaszewski@samsung.com> 4 + * 5 + * IIO features supported by the driver: 6 + * 7 + * Read-only raw channels: 8 + * - illiminance_clear [lux] 9 + * - illiminance_ir 10 + * - proximity 11 + * 12 + * Triggered buffer: 13 + * - illiminance_clear 14 + * - illiminance_ir 15 + * - proximity 16 + * 17 + * Events: 18 + * - illuminance_clear (rising and falling) 19 + * - proximity (rising and falling) 20 + * - both falling and rising thresholds for the proximity events 21 + * must be set to the values greater than 0. 22 + * 23 + * The driver supports triggered buffers for all the three 24 + * channels as well as high and low threshold events for the 25 + * illuminance_clear and proxmimity channels. Triggers 26 + * can be enabled simultaneously with both illuminance_clear 27 + * events. Proximity events cannot be enabled simultaneously 28 + * with any triggers or illuminance events. Enabling/disabling 29 + * one of the proximity events automatically enables/disables 30 + * the other one. 31 + * 32 + * This program is free software; you can redistribute it and/or modify 33 + * it under the terms of the GNU General Public License version 2, as 34 + * published by the Free Software Foundation. 35 + */ 36 + 37 + #include <linux/debugfs.h> 38 + #include <linux/delay.h> 39 + #include <linux/i2c.h> 40 + #include <linux/interrupt.h> 41 + #include <linux/irq.h> 42 + #include <linux/irq_work.h> 43 + #include <linux/module.h> 44 + #include <linux/mutex.h> 45 + #include <linux/regmap.h> 46 + #include <linux/regulator/consumer.h> 47 + #include <linux/slab.h> 48 + #include <linux/iio/buffer.h> 49 + #include <linux/iio/events.h> 50 + #include <linux/iio/iio.h> 51 + #include <linux/iio/sysfs.h> 52 + #include <linux/iio/trigger.h> 53 + #include <linux/iio/trigger_consumer.h> 54 + #include <linux/iio/triggered_buffer.h> 55 + 56 + #define GP2A_I2C_NAME "gp2ap020a00f" 57 + 58 + /* Registers */ 59 + #define GP2AP020A00F_OP_REG 0x00 /* Basic operations */ 60 + #define GP2AP020A00F_ALS_REG 0x01 /* ALS related settings */ 61 + #define GP2AP020A00F_PS_REG 0x02 /* PS related settings */ 62 + #define GP2AP020A00F_LED_REG 0x03 /* LED reg */ 63 + #define GP2AP020A00F_TL_L_REG 0x04 /* ALS: Threshold low LSB */ 64 + #define GP2AP020A00F_TL_H_REG 0x05 /* ALS: Threshold low MSB */ 65 + #define GP2AP020A00F_TH_L_REG 0x06 /* ALS: Threshold high LSB */ 66 + #define GP2AP020A00F_TH_H_REG 0x07 /* ALS: Threshold high MSB */ 67 + #define GP2AP020A00F_PL_L_REG 0x08 /* PS: Threshold low LSB */ 68 + #define GP2AP020A00F_PL_H_REG 0x09 /* PS: Threshold low MSB */ 69 + #define GP2AP020A00F_PH_L_REG 0x0a /* PS: Threshold high LSB */ 70 + #define GP2AP020A00F_PH_H_REG 0x0b /* PS: Threshold high MSB */ 71 + #define GP2AP020A00F_D0_L_REG 0x0c /* ALS result: Clear/Illuminance LSB */ 72 + #define GP2AP020A00F_D0_H_REG 0x0d /* ALS result: Clear/Illuminance MSB */ 73 + #define GP2AP020A00F_D1_L_REG 0x0e /* ALS result: IR LSB */ 74 + #define GP2AP020A00F_D1_H_REG 0x0f /* ALS result: IR LSB */ 75 + #define GP2AP020A00F_D2_L_REG 0x10 /* PS result LSB */ 76 + #define GP2AP020A00F_D2_H_REG 0x11 /* PS result MSB */ 77 + #define GP2AP020A00F_NUM_REGS 0x12 /* Number of registers */ 78 + 79 + /* OP_REG bits */ 80 + #define GP2AP020A00F_OP3_MASK 0x80 /* Software shutdown */ 81 + #define GP2AP020A00F_OP3_SHUTDOWN 0x00 82 + #define GP2AP020A00F_OP3_OPERATION 0x80 83 + #define GP2AP020A00F_OP2_MASK 0x40 /* Auto shutdown/Continuous mode */ 84 + #define GP2AP020A00F_OP2_AUTO_SHUTDOWN 0x00 85 + #define GP2AP020A00F_OP2_CONT_OPERATION 0x40 86 + #define GP2AP020A00F_OP_MASK 0x30 /* Operating mode selection */ 87 + #define GP2AP020A00F_OP_ALS_AND_PS 0x00 88 + #define GP2AP020A00F_OP_ALS 0x10 89 + #define GP2AP020A00F_OP_PS 0x20 90 + #define GP2AP020A00F_OP_DEBUG 0x30 91 + #define GP2AP020A00F_PROX_MASK 0x08 /* PS: detection/non-detection */ 92 + #define GP2AP020A00F_PROX_NON_DETECT 0x00 93 + #define GP2AP020A00F_PROX_DETECT 0x08 94 + #define GP2AP020A00F_FLAG_P 0x04 /* PS: interrupt result */ 95 + #define GP2AP020A00F_FLAG_A 0x02 /* ALS: interrupt result */ 96 + #define GP2AP020A00F_TYPE_MASK 0x01 /* Output data type selection */ 97 + #define GP2AP020A00F_TYPE_MANUAL_CALC 0x00 98 + #define GP2AP020A00F_TYPE_AUTO_CALC 0x01 99 + 100 + /* ALS_REG bits */ 101 + #define GP2AP020A00F_PRST_MASK 0xc0 /* Number of measurement cycles */ 102 + #define GP2AP020A00F_PRST_ONCE 0x00 103 + #define GP2AP020A00F_PRST_4_CYCLES 0x40 104 + #define GP2AP020A00F_PRST_8_CYCLES 0x80 105 + #define GP2AP020A00F_PRST_16_CYCLES 0xc0 106 + #define GP2AP020A00F_RES_A_MASK 0x38 /* ALS: Resolution */ 107 + #define GP2AP020A00F_RES_A_800ms 0x00 108 + #define GP2AP020A00F_RES_A_400ms 0x08 109 + #define GP2AP020A00F_RES_A_200ms 0x10 110 + #define GP2AP020A00F_RES_A_100ms 0x18 111 + #define GP2AP020A00F_RES_A_25ms 0x20 112 + #define GP2AP020A00F_RES_A_6_25ms 0x28 113 + #define GP2AP020A00F_RES_A_1_56ms 0x30 114 + #define GP2AP020A00F_RES_A_0_39ms 0x38 115 + #define GP2AP020A00F_RANGE_A_MASK 0x07 /* ALS: Max measurable range */ 116 + #define GP2AP020A00F_RANGE_A_x1 0x00 117 + #define GP2AP020A00F_RANGE_A_x2 0x01 118 + #define GP2AP020A00F_RANGE_A_x4 0x02 119 + #define GP2AP020A00F_RANGE_A_x8 0x03 120 + #define GP2AP020A00F_RANGE_A_x16 0x04 121 + #define GP2AP020A00F_RANGE_A_x32 0x05 122 + #define GP2AP020A00F_RANGE_A_x64 0x06 123 + #define GP2AP020A00F_RANGE_A_x128 0x07 124 + 125 + /* PS_REG bits */ 126 + #define GP2AP020A00F_ALC_MASK 0x80 /* Auto light cancel */ 127 + #define GP2AP020A00F_ALC_ON 0x80 128 + #define GP2AP020A00F_ALC_OFF 0x00 129 + #define GP2AP020A00F_INTTYPE_MASK 0x40 /* Interrupt type setting */ 130 + #define GP2AP020A00F_INTTYPE_LEVEL 0x00 131 + #define GP2AP020A00F_INTTYPE_PULSE 0x40 132 + #define GP2AP020A00F_RES_P_MASK 0x38 /* PS: Resolution */ 133 + #define GP2AP020A00F_RES_P_800ms_x2 0x00 134 + #define GP2AP020A00F_RES_P_400ms_x2 0x08 135 + #define GP2AP020A00F_RES_P_200ms_x2 0x10 136 + #define GP2AP020A00F_RES_P_100ms_x2 0x18 137 + #define GP2AP020A00F_RES_P_25ms_x2 0x20 138 + #define GP2AP020A00F_RES_P_6_25ms_x2 0x28 139 + #define GP2AP020A00F_RES_P_1_56ms_x2 0x30 140 + #define GP2AP020A00F_RES_P_0_39ms_x2 0x38 141 + #define GP2AP020A00F_RANGE_P_MASK 0x07 /* PS: Max measurable range */ 142 + #define GP2AP020A00F_RANGE_P_x1 0x00 143 + #define GP2AP020A00F_RANGE_P_x2 0x01 144 + #define GP2AP020A00F_RANGE_P_x4 0x02 145 + #define GP2AP020A00F_RANGE_P_x8 0x03 146 + #define GP2AP020A00F_RANGE_P_x16 0x04 147 + #define GP2AP020A00F_RANGE_P_x32 0x05 148 + #define GP2AP020A00F_RANGE_P_x64 0x06 149 + #define GP2AP020A00F_RANGE_P_x128 0x07 150 + 151 + /* LED reg bits */ 152 + #define GP2AP020A00F_INTVAL_MASK 0xc0 /* Intermittent operating */ 153 + #define GP2AP020A00F_INTVAL_0 0x00 154 + #define GP2AP020A00F_INTVAL_4 0x40 155 + #define GP2AP020A00F_INTVAL_8 0x80 156 + #define GP2AP020A00F_INTVAL_16 0xc0 157 + #define GP2AP020A00F_IS_MASK 0x30 /* ILED drive peak current */ 158 + #define GP2AP020A00F_IS_13_8mA 0x00 159 + #define GP2AP020A00F_IS_27_5mA 0x10 160 + #define GP2AP020A00F_IS_55mA 0x20 161 + #define GP2AP020A00F_IS_110mA 0x30 162 + #define GP2AP020A00F_PIN_MASK 0x0c /* INT terminal setting */ 163 + #define GP2AP020A00F_PIN_ALS_OR_PS 0x00 164 + #define GP2AP020A00F_PIN_ALS 0x04 165 + #define GP2AP020A00F_PIN_PS 0x08 166 + #define GP2AP020A00F_PIN_PS_DETECT 0x0c 167 + #define GP2AP020A00F_FREQ_MASK 0x02 /* LED modulation frequency */ 168 + #define GP2AP020A00F_FREQ_327_5kHz 0x00 169 + #define GP2AP020A00F_FREQ_81_8kHz 0x02 170 + #define GP2AP020A00F_RST 0x01 /* Software reset */ 171 + 172 + #define GP2AP020A00F_SCAN_MODE_LIGHT_CLEAR 0 173 + #define GP2AP020A00F_SCAN_MODE_LIGHT_IR 1 174 + #define GP2AP020A00F_SCAN_MODE_PROXIMITY 2 175 + #define GP2AP020A00F_CHAN_TIMESTAMP 3 176 + 177 + #define GP2AP020A00F_DATA_READY_TIMEOUT msecs_to_jiffies(1000) 178 + #define GP2AP020A00F_DATA_REG(chan) (GP2AP020A00F_D0_L_REG + \ 179 + (chan) * 2) 180 + #define GP2AP020A00F_THRESH_REG(th_val_id) (GP2AP020A00F_TL_L_REG + \ 181 + (th_val_id) * 2) 182 + #define GP2AP020A00F_THRESH_VAL_ID(reg_addr) ((reg_addr - 4) / 2) 183 + 184 + #define GP2AP020A00F_SUBTRACT_MODE 0 185 + #define GP2AP020A00F_ADD_MODE 1 186 + 187 + #define GP2AP020A00F_MAX_CHANNELS 3 188 + 189 + enum gp2ap020a00f_opmode { 190 + GP2AP020A00F_OPMODE_READ_RAW_CLEAR, 191 + GP2AP020A00F_OPMODE_READ_RAW_IR, 192 + GP2AP020A00F_OPMODE_READ_RAW_PROXIMITY, 193 + GP2AP020A00F_OPMODE_ALS, 194 + GP2AP020A00F_OPMODE_PS, 195 + GP2AP020A00F_OPMODE_ALS_AND_PS, 196 + GP2AP020A00F_OPMODE_PROX_DETECT, 197 + GP2AP020A00F_OPMODE_SHUTDOWN, 198 + GP2AP020A00F_NUM_OPMODES, 199 + }; 200 + 201 + enum gp2ap020a00f_cmd { 202 + GP2AP020A00F_CMD_READ_RAW_CLEAR, 203 + GP2AP020A00F_CMD_READ_RAW_IR, 204 + GP2AP020A00F_CMD_READ_RAW_PROXIMITY, 205 + GP2AP020A00F_CMD_TRIGGER_CLEAR_EN, 206 + GP2AP020A00F_CMD_TRIGGER_CLEAR_DIS, 207 + GP2AP020A00F_CMD_TRIGGER_IR_EN, 208 + GP2AP020A00F_CMD_TRIGGER_IR_DIS, 209 + GP2AP020A00F_CMD_TRIGGER_PROX_EN, 210 + GP2AP020A00F_CMD_TRIGGER_PROX_DIS, 211 + GP2AP020A00F_CMD_ALS_HIGH_EV_EN, 212 + GP2AP020A00F_CMD_ALS_HIGH_EV_DIS, 213 + GP2AP020A00F_CMD_ALS_LOW_EV_EN, 214 + GP2AP020A00F_CMD_ALS_LOW_EV_DIS, 215 + GP2AP020A00F_CMD_PROX_HIGH_EV_EN, 216 + GP2AP020A00F_CMD_PROX_HIGH_EV_DIS, 217 + GP2AP020A00F_CMD_PROX_LOW_EV_EN, 218 + GP2AP020A00F_CMD_PROX_LOW_EV_DIS, 219 + }; 220 + 221 + enum gp2ap020a00f_flags { 222 + GP2AP020A00F_FLAG_ALS_CLEAR_TRIGGER, 223 + GP2AP020A00F_FLAG_ALS_IR_TRIGGER, 224 + GP2AP020A00F_FLAG_PROX_TRIGGER, 225 + GP2AP020A00F_FLAG_PROX_RISING_EV, 226 + GP2AP020A00F_FLAG_PROX_FALLING_EV, 227 + GP2AP020A00F_FLAG_ALS_RISING_EV, 228 + GP2AP020A00F_FLAG_ALS_FALLING_EV, 229 + GP2AP020A00F_FLAG_LUX_MODE_HI, 230 + GP2AP020A00F_FLAG_DATA_READY, 231 + }; 232 + 233 + enum gp2ap020a00f_thresh_val_id { 234 + GP2AP020A00F_THRESH_TL, 235 + GP2AP020A00F_THRESH_TH, 236 + GP2AP020A00F_THRESH_PL, 237 + GP2AP020A00F_THRESH_PH, 238 + }; 239 + 240 + struct gp2ap020a00f_data { 241 + const struct gp2ap020a00f_platform_data *pdata; 242 + struct i2c_client *client; 243 + struct mutex lock; 244 + char *buffer; 245 + struct regulator *vled_reg; 246 + unsigned long flags; 247 + enum gp2ap020a00f_opmode cur_opmode; 248 + struct iio_trigger *trig; 249 + struct regmap *regmap; 250 + unsigned int thresh_val[4]; 251 + u8 debug_reg_addr; 252 + struct irq_work work; 253 + wait_queue_head_t data_ready_queue; 254 + }; 255 + 256 + static const u8 gp2ap020a00f_reg_init_tab[] = { 257 + [GP2AP020A00F_OP_REG] = GP2AP020A00F_OP3_SHUTDOWN, 258 + [GP2AP020A00F_ALS_REG] = GP2AP020A00F_RES_A_25ms | 259 + GP2AP020A00F_RANGE_A_x8, 260 + [GP2AP020A00F_PS_REG] = GP2AP020A00F_ALC_ON | 261 + GP2AP020A00F_RES_P_1_56ms_x2 | 262 + GP2AP020A00F_RANGE_P_x4, 263 + [GP2AP020A00F_LED_REG] = GP2AP020A00F_INTVAL_0 | 264 + GP2AP020A00F_IS_110mA | 265 + GP2AP020A00F_FREQ_327_5kHz, 266 + [GP2AP020A00F_TL_L_REG] = 0, 267 + [GP2AP020A00F_TL_H_REG] = 0, 268 + [GP2AP020A00F_TH_L_REG] = 0, 269 + [GP2AP020A00F_TH_H_REG] = 0, 270 + [GP2AP020A00F_PL_L_REG] = 0, 271 + [GP2AP020A00F_PL_H_REG] = 0, 272 + [GP2AP020A00F_PH_L_REG] = 0, 273 + [GP2AP020A00F_PH_H_REG] = 0, 274 + }; 275 + 276 + static bool gp2ap020a00f_is_volatile_reg(struct device *dev, unsigned int reg) 277 + { 278 + switch (reg) { 279 + case GP2AP020A00F_OP_REG: 280 + case GP2AP020A00F_D0_L_REG: 281 + case GP2AP020A00F_D0_H_REG: 282 + case GP2AP020A00F_D1_L_REG: 283 + case GP2AP020A00F_D1_H_REG: 284 + case GP2AP020A00F_D2_L_REG: 285 + case GP2AP020A00F_D2_H_REG: 286 + return true; 287 + default: 288 + return false; 289 + } 290 + } 291 + 292 + static const struct regmap_config gp2ap020a00f_regmap_config = { 293 + .reg_bits = 8, 294 + .val_bits = 8, 295 + 296 + .max_register = GP2AP020A00F_D2_H_REG, 297 + .cache_type = REGCACHE_RBTREE, 298 + 299 + .volatile_reg = gp2ap020a00f_is_volatile_reg, 300 + }; 301 + 302 + static const struct gp2ap020a00f_mutable_config_regs { 303 + u8 op_reg; 304 + u8 als_reg; 305 + u8 ps_reg; 306 + u8 led_reg; 307 + } opmode_regs_settings[GP2AP020A00F_NUM_OPMODES] = { 308 + [GP2AP020A00F_OPMODE_READ_RAW_CLEAR] = { 309 + GP2AP020A00F_OP_ALS | GP2AP020A00F_OP2_CONT_OPERATION 310 + | GP2AP020A00F_OP3_OPERATION 311 + | GP2AP020A00F_TYPE_AUTO_CALC, 312 + GP2AP020A00F_PRST_ONCE, 313 + GP2AP020A00F_INTTYPE_LEVEL, 314 + GP2AP020A00F_PIN_ALS 315 + }, 316 + [GP2AP020A00F_OPMODE_READ_RAW_IR] = { 317 + GP2AP020A00F_OP_ALS | GP2AP020A00F_OP2_CONT_OPERATION 318 + | GP2AP020A00F_OP3_OPERATION 319 + | GP2AP020A00F_TYPE_MANUAL_CALC, 320 + GP2AP020A00F_PRST_ONCE, 321 + GP2AP020A00F_INTTYPE_LEVEL, 322 + GP2AP020A00F_PIN_ALS 323 + }, 324 + [GP2AP020A00F_OPMODE_READ_RAW_PROXIMITY] = { 325 + GP2AP020A00F_OP_PS | GP2AP020A00F_OP2_CONT_OPERATION 326 + | GP2AP020A00F_OP3_OPERATION 327 + | GP2AP020A00F_TYPE_MANUAL_CALC, 328 + GP2AP020A00F_PRST_ONCE, 329 + GP2AP020A00F_INTTYPE_LEVEL, 330 + GP2AP020A00F_PIN_PS 331 + }, 332 + [GP2AP020A00F_OPMODE_PROX_DETECT] = { 333 + GP2AP020A00F_OP_PS | GP2AP020A00F_OP2_CONT_OPERATION 334 + | GP2AP020A00F_OP3_OPERATION 335 + | GP2AP020A00F_TYPE_MANUAL_CALC, 336 + GP2AP020A00F_PRST_4_CYCLES, 337 + GP2AP020A00F_INTTYPE_PULSE, 338 + GP2AP020A00F_PIN_PS_DETECT 339 + }, 340 + [GP2AP020A00F_OPMODE_ALS] = { 341 + GP2AP020A00F_OP_ALS | GP2AP020A00F_OP2_CONT_OPERATION 342 + | GP2AP020A00F_OP3_OPERATION 343 + | GP2AP020A00F_TYPE_AUTO_CALC, 344 + GP2AP020A00F_PRST_ONCE, 345 + GP2AP020A00F_INTTYPE_LEVEL, 346 + GP2AP020A00F_PIN_ALS 347 + }, 348 + [GP2AP020A00F_OPMODE_PS] = { 349 + GP2AP020A00F_OP_PS | GP2AP020A00F_OP2_CONT_OPERATION 350 + | GP2AP020A00F_OP3_OPERATION 351 + | GP2AP020A00F_TYPE_MANUAL_CALC, 352 + GP2AP020A00F_PRST_4_CYCLES, 353 + GP2AP020A00F_INTTYPE_LEVEL, 354 + GP2AP020A00F_PIN_PS 355 + }, 356 + [GP2AP020A00F_OPMODE_ALS_AND_PS] = { 357 + GP2AP020A00F_OP_ALS_AND_PS 358 + | GP2AP020A00F_OP2_CONT_OPERATION 359 + | GP2AP020A00F_OP3_OPERATION 360 + | GP2AP020A00F_TYPE_AUTO_CALC, 361 + GP2AP020A00F_PRST_4_CYCLES, 362 + GP2AP020A00F_INTTYPE_LEVEL, 363 + GP2AP020A00F_PIN_ALS_OR_PS 364 + }, 365 + [GP2AP020A00F_OPMODE_SHUTDOWN] = { GP2AP020A00F_OP3_SHUTDOWN, }, 366 + }; 367 + 368 + static int gp2ap020a00f_set_operation_mode(struct gp2ap020a00f_data *data, 369 + enum gp2ap020a00f_opmode op) 370 + { 371 + unsigned int op_reg_val; 372 + int err; 373 + 374 + if (op != GP2AP020A00F_OPMODE_SHUTDOWN) { 375 + err = regmap_read(data->regmap, GP2AP020A00F_OP_REG, 376 + &op_reg_val); 377 + if (err < 0) 378 + return err; 379 + /* 380 + * Shutdown the device if the operation being executed entails 381 + * mode transition. 382 + */ 383 + if ((opmode_regs_settings[op].op_reg & GP2AP020A00F_OP_MASK) != 384 + (op_reg_val & GP2AP020A00F_OP_MASK)) { 385 + /* set shutdown mode */ 386 + err = regmap_update_bits(data->regmap, 387 + GP2AP020A00F_OP_REG, GP2AP020A00F_OP3_MASK, 388 + GP2AP020A00F_OP3_SHUTDOWN); 389 + if (err < 0) 390 + return err; 391 + } 392 + 393 + err = regmap_update_bits(data->regmap, GP2AP020A00F_ALS_REG, 394 + GP2AP020A00F_PRST_MASK, opmode_regs_settings[op] 395 + .als_reg); 396 + if (err < 0) 397 + return err; 398 + 399 + err = regmap_update_bits(data->regmap, GP2AP020A00F_PS_REG, 400 + GP2AP020A00F_INTTYPE_MASK, opmode_regs_settings[op] 401 + .ps_reg); 402 + if (err < 0) 403 + return err; 404 + 405 + err = regmap_update_bits(data->regmap, GP2AP020A00F_LED_REG, 406 + GP2AP020A00F_PIN_MASK, opmode_regs_settings[op] 407 + .led_reg); 408 + if (err < 0) 409 + return err; 410 + } 411 + 412 + /* Set OP_REG and apply operation mode (power on / off) */ 413 + err = regmap_update_bits(data->regmap, 414 + GP2AP020A00F_OP_REG, 415 + GP2AP020A00F_OP_MASK | GP2AP020A00F_OP2_MASK | 416 + GP2AP020A00F_OP3_MASK | GP2AP020A00F_TYPE_MASK, 417 + opmode_regs_settings[op].op_reg); 418 + if (err < 0) 419 + return err; 420 + 421 + data->cur_opmode = op; 422 + 423 + return 0; 424 + } 425 + 426 + static bool gp2ap020a00f_als_enabled(struct gp2ap020a00f_data *data) 427 + { 428 + return test_bit(GP2AP020A00F_FLAG_ALS_CLEAR_TRIGGER, &data->flags) || 429 + test_bit(GP2AP020A00F_FLAG_ALS_IR_TRIGGER, &data->flags) || 430 + test_bit(GP2AP020A00F_FLAG_ALS_RISING_EV, &data->flags) || 431 + test_bit(GP2AP020A00F_FLAG_ALS_FALLING_EV, &data->flags); 432 + } 433 + 434 + static bool gp2ap020a00f_prox_detect_enabled(struct gp2ap020a00f_data *data) 435 + { 436 + return test_bit(GP2AP020A00F_FLAG_PROX_RISING_EV, &data->flags) || 437 + test_bit(GP2AP020A00F_FLAG_PROX_FALLING_EV, &data->flags); 438 + } 439 + 440 + static int gp2ap020a00f_write_event_threshold(struct gp2ap020a00f_data *data, 441 + enum gp2ap020a00f_thresh_val_id th_val_id, 442 + bool enable) 443 + { 444 + __le16 thresh_buf = 0; 445 + unsigned int thresh_reg_val; 446 + 447 + if (!enable) 448 + thresh_reg_val = 0; 449 + else if (test_bit(GP2AP020A00F_FLAG_LUX_MODE_HI, &data->flags) && 450 + th_val_id != GP2AP020A00F_THRESH_PL && 451 + th_val_id != GP2AP020A00F_THRESH_PH) 452 + /* 453 + * For the high lux mode ALS threshold has to be scaled down 454 + * to allow for proper comparison with the output value. 455 + */ 456 + thresh_reg_val = data->thresh_val[th_val_id] / 16; 457 + else 458 + thresh_reg_val = data->thresh_val[th_val_id] > 16000 ? 459 + 16000 : 460 + data->thresh_val[th_val_id]; 461 + 462 + thresh_buf = cpu_to_le16(thresh_reg_val); 463 + 464 + return regmap_bulk_write(data->regmap, 465 + GP2AP020A00F_THRESH_REG(th_val_id), 466 + (u8 *)&thresh_buf, 2); 467 + } 468 + 469 + static int gp2ap020a00f_alter_opmode(struct gp2ap020a00f_data *data, 470 + enum gp2ap020a00f_opmode diff_mode, int add_sub) 471 + { 472 + enum gp2ap020a00f_opmode new_mode; 473 + 474 + if (diff_mode != GP2AP020A00F_OPMODE_ALS && 475 + diff_mode != GP2AP020A00F_OPMODE_PS) 476 + return -EINVAL; 477 + 478 + if (add_sub == GP2AP020A00F_ADD_MODE) { 479 + if (data->cur_opmode == GP2AP020A00F_OPMODE_SHUTDOWN) 480 + new_mode = diff_mode; 481 + else 482 + new_mode = GP2AP020A00F_OPMODE_ALS_AND_PS; 483 + } else { 484 + if (data->cur_opmode == GP2AP020A00F_OPMODE_ALS_AND_PS) 485 + new_mode = (diff_mode == GP2AP020A00F_OPMODE_ALS) ? 486 + GP2AP020A00F_OPMODE_PS : 487 + GP2AP020A00F_OPMODE_ALS; 488 + else 489 + new_mode = GP2AP020A00F_OPMODE_SHUTDOWN; 490 + } 491 + 492 + return gp2ap020a00f_set_operation_mode(data, new_mode); 493 + } 494 + 495 + static int gp2ap020a00f_exec_cmd(struct gp2ap020a00f_data *data, 496 + enum gp2ap020a00f_cmd cmd) 497 + { 498 + int err = 0; 499 + 500 + switch (cmd) { 501 + case GP2AP020A00F_CMD_READ_RAW_CLEAR: 502 + if (data->cur_opmode != GP2AP020A00F_OPMODE_SHUTDOWN) 503 + return -EBUSY; 504 + err = gp2ap020a00f_set_operation_mode(data, 505 + GP2AP020A00F_OPMODE_READ_RAW_CLEAR); 506 + break; 507 + case GP2AP020A00F_CMD_READ_RAW_IR: 508 + if (data->cur_opmode != GP2AP020A00F_OPMODE_SHUTDOWN) 509 + return -EBUSY; 510 + err = gp2ap020a00f_set_operation_mode(data, 511 + GP2AP020A00F_OPMODE_READ_RAW_IR); 512 + break; 513 + case GP2AP020A00F_CMD_READ_RAW_PROXIMITY: 514 + if (data->cur_opmode != GP2AP020A00F_OPMODE_SHUTDOWN) 515 + return -EBUSY; 516 + err = gp2ap020a00f_set_operation_mode(data, 517 + GP2AP020A00F_OPMODE_READ_RAW_PROXIMITY); 518 + break; 519 + case GP2AP020A00F_CMD_TRIGGER_CLEAR_EN: 520 + if (data->cur_opmode == GP2AP020A00F_OPMODE_PROX_DETECT) 521 + return -EBUSY; 522 + if (!gp2ap020a00f_als_enabled(data)) 523 + err = gp2ap020a00f_alter_opmode(data, 524 + GP2AP020A00F_OPMODE_ALS, 525 + GP2AP020A00F_ADD_MODE); 526 + set_bit(GP2AP020A00F_FLAG_ALS_CLEAR_TRIGGER, &data->flags); 527 + break; 528 + case GP2AP020A00F_CMD_TRIGGER_CLEAR_DIS: 529 + clear_bit(GP2AP020A00F_FLAG_ALS_CLEAR_TRIGGER, &data->flags); 530 + if (gp2ap020a00f_als_enabled(data)) 531 + break; 532 + err = gp2ap020a00f_alter_opmode(data, 533 + GP2AP020A00F_OPMODE_ALS, 534 + GP2AP020A00F_SUBTRACT_MODE); 535 + break; 536 + case GP2AP020A00F_CMD_TRIGGER_IR_EN: 537 + if (data->cur_opmode == GP2AP020A00F_OPMODE_PROX_DETECT) 538 + return -EBUSY; 539 + if (!gp2ap020a00f_als_enabled(data)) 540 + err = gp2ap020a00f_alter_opmode(data, 541 + GP2AP020A00F_OPMODE_ALS, 542 + GP2AP020A00F_ADD_MODE); 543 + set_bit(GP2AP020A00F_FLAG_ALS_IR_TRIGGER, &data->flags); 544 + break; 545 + case GP2AP020A00F_CMD_TRIGGER_IR_DIS: 546 + clear_bit(GP2AP020A00F_FLAG_ALS_IR_TRIGGER, &data->flags); 547 + if (gp2ap020a00f_als_enabled(data)) 548 + break; 549 + err = gp2ap020a00f_alter_opmode(data, 550 + GP2AP020A00F_OPMODE_ALS, 551 + GP2AP020A00F_SUBTRACT_MODE); 552 + break; 553 + case GP2AP020A00F_CMD_TRIGGER_PROX_EN: 554 + if (data->cur_opmode == GP2AP020A00F_OPMODE_PROX_DETECT) 555 + return -EBUSY; 556 + err = gp2ap020a00f_alter_opmode(data, 557 + GP2AP020A00F_OPMODE_PS, 558 + GP2AP020A00F_ADD_MODE); 559 + set_bit(GP2AP020A00F_FLAG_PROX_TRIGGER, &data->flags); 560 + break; 561 + case GP2AP020A00F_CMD_TRIGGER_PROX_DIS: 562 + clear_bit(GP2AP020A00F_FLAG_PROX_TRIGGER, &data->flags); 563 + err = gp2ap020a00f_alter_opmode(data, 564 + GP2AP020A00F_OPMODE_PS, 565 + GP2AP020A00F_SUBTRACT_MODE); 566 + break; 567 + case GP2AP020A00F_CMD_ALS_HIGH_EV_EN: 568 + if (test_bit(GP2AP020A00F_FLAG_ALS_RISING_EV, &data->flags)) 569 + return 0; 570 + if (data->cur_opmode == GP2AP020A00F_OPMODE_PROX_DETECT) 571 + return -EBUSY; 572 + if (!gp2ap020a00f_als_enabled(data)) { 573 + err = gp2ap020a00f_alter_opmode(data, 574 + GP2AP020A00F_OPMODE_ALS, 575 + GP2AP020A00F_ADD_MODE); 576 + if (err < 0) 577 + return err; 578 + } 579 + set_bit(GP2AP020A00F_FLAG_ALS_RISING_EV, &data->flags); 580 + err = gp2ap020a00f_write_event_threshold(data, 581 + GP2AP020A00F_THRESH_TH, true); 582 + break; 583 + case GP2AP020A00F_CMD_ALS_HIGH_EV_DIS: 584 + if (!test_bit(GP2AP020A00F_FLAG_ALS_RISING_EV, &data->flags)) 585 + return 0; 586 + clear_bit(GP2AP020A00F_FLAG_ALS_RISING_EV, &data->flags); 587 + if (!gp2ap020a00f_als_enabled(data)) { 588 + err = gp2ap020a00f_alter_opmode(data, 589 + GP2AP020A00F_OPMODE_ALS, 590 + GP2AP020A00F_SUBTRACT_MODE); 591 + if (err < 0) 592 + return err; 593 + } 594 + err = gp2ap020a00f_write_event_threshold(data, 595 + GP2AP020A00F_THRESH_TH, false); 596 + break; 597 + case GP2AP020A00F_CMD_ALS_LOW_EV_EN: 598 + if (test_bit(GP2AP020A00F_FLAG_ALS_FALLING_EV, &data->flags)) 599 + return 0; 600 + if (data->cur_opmode == GP2AP020A00F_OPMODE_PROX_DETECT) 601 + return -EBUSY; 602 + if (!gp2ap020a00f_als_enabled(data)) { 603 + err = gp2ap020a00f_alter_opmode(data, 604 + GP2AP020A00F_OPMODE_ALS, 605 + GP2AP020A00F_ADD_MODE); 606 + if (err < 0) 607 + return err; 608 + } 609 + set_bit(GP2AP020A00F_FLAG_ALS_FALLING_EV, &data->flags); 610 + err = gp2ap020a00f_write_event_threshold(data, 611 + GP2AP020A00F_THRESH_TL, true); 612 + break; 613 + case GP2AP020A00F_CMD_ALS_LOW_EV_DIS: 614 + if (!test_bit(GP2AP020A00F_FLAG_ALS_FALLING_EV, &data->flags)) 615 + return 0; 616 + clear_bit(GP2AP020A00F_FLAG_ALS_FALLING_EV, &data->flags); 617 + if (!gp2ap020a00f_als_enabled(data)) { 618 + err = gp2ap020a00f_alter_opmode(data, 619 + GP2AP020A00F_OPMODE_ALS, 620 + GP2AP020A00F_SUBTRACT_MODE); 621 + if (err < 0) 622 + return err; 623 + } 624 + err = gp2ap020a00f_write_event_threshold(data, 625 + GP2AP020A00F_THRESH_TL, false); 626 + break; 627 + case GP2AP020A00F_CMD_PROX_HIGH_EV_EN: 628 + if (test_bit(GP2AP020A00F_FLAG_PROX_RISING_EV, &data->flags)) 629 + return 0; 630 + if (gp2ap020a00f_als_enabled(data) || 631 + data->cur_opmode == GP2AP020A00F_OPMODE_PS) 632 + return -EBUSY; 633 + if (!gp2ap020a00f_prox_detect_enabled(data)) { 634 + err = gp2ap020a00f_set_operation_mode(data, 635 + GP2AP020A00F_OPMODE_PROX_DETECT); 636 + if (err < 0) 637 + return err; 638 + } 639 + set_bit(GP2AP020A00F_FLAG_PROX_RISING_EV, &data->flags); 640 + err = gp2ap020a00f_write_event_threshold(data, 641 + GP2AP020A00F_THRESH_PH, true); 642 + break; 643 + case GP2AP020A00F_CMD_PROX_HIGH_EV_DIS: 644 + if (!test_bit(GP2AP020A00F_FLAG_PROX_RISING_EV, &data->flags)) 645 + return 0; 646 + clear_bit(GP2AP020A00F_FLAG_PROX_RISING_EV, &data->flags); 647 + err = gp2ap020a00f_set_operation_mode(data, 648 + GP2AP020A00F_OPMODE_SHUTDOWN); 649 + if (err < 0) 650 + return err; 651 + err = gp2ap020a00f_write_event_threshold(data, 652 + GP2AP020A00F_THRESH_PH, false); 653 + break; 654 + case GP2AP020A00F_CMD_PROX_LOW_EV_EN: 655 + if (test_bit(GP2AP020A00F_FLAG_PROX_FALLING_EV, &data->flags)) 656 + return 0; 657 + if (gp2ap020a00f_als_enabled(data) || 658 + data->cur_opmode == GP2AP020A00F_OPMODE_PS) 659 + return -EBUSY; 660 + if (!gp2ap020a00f_prox_detect_enabled(data)) { 661 + err = gp2ap020a00f_set_operation_mode(data, 662 + GP2AP020A00F_OPMODE_PROX_DETECT); 663 + if (err < 0) 664 + return err; 665 + } 666 + set_bit(GP2AP020A00F_FLAG_PROX_FALLING_EV, &data->flags); 667 + err = gp2ap020a00f_write_event_threshold(data, 668 + GP2AP020A00F_THRESH_PL, true); 669 + break; 670 + case GP2AP020A00F_CMD_PROX_LOW_EV_DIS: 671 + if (!test_bit(GP2AP020A00F_FLAG_PROX_FALLING_EV, &data->flags)) 672 + return 0; 673 + clear_bit(GP2AP020A00F_FLAG_PROX_FALLING_EV, &data->flags); 674 + err = gp2ap020a00f_set_operation_mode(data, 675 + GP2AP020A00F_OPMODE_SHUTDOWN); 676 + if (err < 0) 677 + return err; 678 + err = gp2ap020a00f_write_event_threshold(data, 679 + GP2AP020A00F_THRESH_PL, false); 680 + break; 681 + } 682 + 683 + return err; 684 + } 685 + 686 + static int wait_conversion_complete_irq(struct gp2ap020a00f_data *data) 687 + { 688 + int ret; 689 + 690 + ret = wait_event_timeout(data->data_ready_queue, 691 + test_bit(GP2AP020A00F_FLAG_DATA_READY, 692 + &data->flags), 693 + GP2AP020A00F_DATA_READY_TIMEOUT); 694 + clear_bit(GP2AP020A00F_FLAG_DATA_READY, &data->flags); 695 + 696 + return ret > 0 ? 0 : -ETIME; 697 + } 698 + 699 + static int gp2ap020a00f_read_output(struct gp2ap020a00f_data *data, 700 + unsigned int output_reg, int *val) 701 + { 702 + u8 reg_buf[2]; 703 + int err; 704 + 705 + err = wait_conversion_complete_irq(data); 706 + if (err < 0) 707 + dev_dbg(&data->client->dev, "data ready timeout\n"); 708 + 709 + err = regmap_bulk_read(data->regmap, output_reg, reg_buf, 2); 710 + if (err < 0) 711 + return err; 712 + 713 + *val = le16_to_cpup((__le16 *)reg_buf); 714 + 715 + return err; 716 + } 717 + 718 + static bool gp2ap020a00f_adjust_lux_mode(struct gp2ap020a00f_data *data, 719 + int output_val) 720 + { 721 + u8 new_range = 0xff; 722 + int err; 723 + 724 + if (!test_bit(GP2AP020A00F_FLAG_LUX_MODE_HI, &data->flags)) { 725 + if (output_val > 16000) { 726 + set_bit(GP2AP020A00F_FLAG_LUX_MODE_HI, &data->flags); 727 + new_range = GP2AP020A00F_RANGE_A_x128; 728 + } 729 + } else { 730 + if (output_val < 1000) { 731 + clear_bit(GP2AP020A00F_FLAG_LUX_MODE_HI, &data->flags); 732 + new_range = GP2AP020A00F_RANGE_A_x8; 733 + } 734 + } 735 + 736 + if (new_range != 0xff) { 737 + /* Clear als threshold registers to avoid spurious 738 + * events caused by lux mode transition. 739 + */ 740 + err = gp2ap020a00f_write_event_threshold(data, 741 + GP2AP020A00F_THRESH_TH, false); 742 + if (err < 0) { 743 + dev_err(&data->client->dev, 744 + "Clearing als threshold register failed.\n"); 745 + return false; 746 + } 747 + 748 + err = gp2ap020a00f_write_event_threshold(data, 749 + GP2AP020A00F_THRESH_TL, false); 750 + if (err < 0) { 751 + dev_err(&data->client->dev, 752 + "Clearing als threshold register failed.\n"); 753 + return false; 754 + } 755 + 756 + /* Change lux mode */ 757 + err = regmap_update_bits(data->regmap, 758 + GP2AP020A00F_OP_REG, 759 + GP2AP020A00F_OP3_MASK, 760 + GP2AP020A00F_OP3_SHUTDOWN); 761 + 762 + if (err < 0) { 763 + dev_err(&data->client->dev, 764 + "Shutting down the device failed.\n"); 765 + return false; 766 + } 767 + 768 + err = regmap_update_bits(data->regmap, 769 + GP2AP020A00F_ALS_REG, 770 + GP2AP020A00F_RANGE_A_MASK, 771 + new_range); 772 + 773 + if (err < 0) { 774 + dev_err(&data->client->dev, 775 + "Adjusting device lux mode failed.\n"); 776 + return false; 777 + } 778 + 779 + err = regmap_update_bits(data->regmap, 780 + GP2AP020A00F_OP_REG, 781 + GP2AP020A00F_OP3_MASK, 782 + GP2AP020A00F_OP3_OPERATION); 783 + 784 + if (err < 0) { 785 + dev_err(&data->client->dev, 786 + "Powering up the device failed.\n"); 787 + return false; 788 + } 789 + 790 + /* Adjust als threshold register values to the new lux mode */ 791 + if (test_bit(GP2AP020A00F_FLAG_ALS_RISING_EV, &data->flags)) { 792 + err = gp2ap020a00f_write_event_threshold(data, 793 + GP2AP020A00F_THRESH_TH, true); 794 + if (err < 0) { 795 + dev_err(&data->client->dev, 796 + "Adjusting als threshold value failed.\n"); 797 + return false; 798 + } 799 + } 800 + 801 + if (test_bit(GP2AP020A00F_FLAG_ALS_FALLING_EV, &data->flags)) { 802 + err = gp2ap020a00f_write_event_threshold(data, 803 + GP2AP020A00F_THRESH_TL, true); 804 + if (err < 0) { 805 + dev_err(&data->client->dev, 806 + "Adjusting als threshold value failed.\n"); 807 + return false; 808 + } 809 + } 810 + 811 + return true; 812 + } 813 + 814 + return false; 815 + } 816 + 817 + static void gp2ap020a00f_output_to_lux(struct gp2ap020a00f_data *data, 818 + int *output_val) 819 + { 820 + if (test_bit(GP2AP020A00F_FLAG_LUX_MODE_HI, &data->flags)) 821 + *output_val *= 16; 822 + } 823 + 824 + static void gp2ap020a00f_iio_trigger_work(struct irq_work *work) 825 + { 826 + struct gp2ap020a00f_data *data = 827 + container_of(work, struct gp2ap020a00f_data, work); 828 + 829 + iio_trigger_poll(data->trig, 0); 830 + } 831 + 832 + static irqreturn_t gp2ap020a00f_prox_sensing_handler(int irq, void *data) 833 + { 834 + struct iio_dev *indio_dev = data; 835 + struct gp2ap020a00f_data *priv = iio_priv(indio_dev); 836 + unsigned int op_reg_val; 837 + int ret; 838 + 839 + /* Read interrupt flags */ 840 + ret = regmap_read(priv->regmap, GP2AP020A00F_OP_REG, &op_reg_val); 841 + if (ret < 0) 842 + return IRQ_HANDLED; 843 + 844 + if (gp2ap020a00f_prox_detect_enabled(priv)) { 845 + if (op_reg_val & GP2AP020A00F_PROX_DETECT) { 846 + iio_push_event(indio_dev, 847 + IIO_UNMOD_EVENT_CODE( 848 + IIO_PROXIMITY, 849 + GP2AP020A00F_SCAN_MODE_PROXIMITY, 850 + IIO_EV_TYPE_ROC, 851 + IIO_EV_DIR_RISING), 852 + iio_get_time_ns()); 853 + } else { 854 + iio_push_event(indio_dev, 855 + IIO_UNMOD_EVENT_CODE( 856 + IIO_PROXIMITY, 857 + GP2AP020A00F_SCAN_MODE_PROXIMITY, 858 + IIO_EV_TYPE_ROC, 859 + IIO_EV_DIR_FALLING), 860 + iio_get_time_ns()); 861 + } 862 + } 863 + 864 + return IRQ_HANDLED; 865 + } 866 + 867 + static irqreturn_t gp2ap020a00f_thresh_event_handler(int irq, void *data) 868 + { 869 + struct iio_dev *indio_dev = data; 870 + struct gp2ap020a00f_data *priv = iio_priv(indio_dev); 871 + u8 op_reg_flags, d0_reg_buf[2]; 872 + unsigned int output_val, op_reg_val; 873 + int thresh_val_id, ret; 874 + 875 + /* Read interrupt flags */ 876 + ret = regmap_read(priv->regmap, GP2AP020A00F_OP_REG, 877 + &op_reg_val); 878 + if (ret < 0) 879 + goto done; 880 + 881 + op_reg_flags = op_reg_val & (GP2AP020A00F_FLAG_A | GP2AP020A00F_FLAG_P 882 + | GP2AP020A00F_PROX_DETECT); 883 + 884 + op_reg_val &= (~GP2AP020A00F_FLAG_A & ~GP2AP020A00F_FLAG_P 885 + & ~GP2AP020A00F_PROX_DETECT); 886 + 887 + /* Clear interrupt flags (if not in INTTYPE_PULSE mode) */ 888 + if (priv->cur_opmode != GP2AP020A00F_OPMODE_PROX_DETECT) { 889 + ret = regmap_write(priv->regmap, GP2AP020A00F_OP_REG, 890 + op_reg_val); 891 + if (ret < 0) 892 + goto done; 893 + } 894 + 895 + if (op_reg_flags & GP2AP020A00F_FLAG_A) { 896 + /* Check D0 register to assess if the lux mode 897 + * transition is required. 898 + */ 899 + ret = regmap_bulk_read(priv->regmap, GP2AP020A00F_D0_L_REG, 900 + d0_reg_buf, 2); 901 + if (ret < 0) 902 + goto done; 903 + 904 + output_val = le16_to_cpup((__le16 *)d0_reg_buf); 905 + 906 + if (gp2ap020a00f_adjust_lux_mode(priv, output_val)) 907 + goto done; 908 + 909 + gp2ap020a00f_output_to_lux(priv, &output_val); 910 + 911 + /* 912 + * We need to check output value to distinguish 913 + * between high and low ambient light threshold event. 914 + */ 915 + if (test_bit(GP2AP020A00F_FLAG_ALS_RISING_EV, &priv->flags)) { 916 + thresh_val_id = 917 + GP2AP020A00F_THRESH_VAL_ID(GP2AP020A00F_TH_L_REG); 918 + if (output_val > priv->thresh_val[thresh_val_id]) 919 + iio_push_event(indio_dev, 920 + IIO_MOD_EVENT_CODE( 921 + IIO_LIGHT, 922 + GP2AP020A00F_SCAN_MODE_LIGHT_CLEAR, 923 + IIO_MOD_LIGHT_CLEAR, 924 + IIO_EV_TYPE_THRESH, 925 + IIO_EV_DIR_RISING), 926 + iio_get_time_ns()); 927 + } 928 + 929 + if (test_bit(GP2AP020A00F_FLAG_ALS_FALLING_EV, &priv->flags)) { 930 + thresh_val_id = 931 + GP2AP020A00F_THRESH_VAL_ID(GP2AP020A00F_TL_L_REG); 932 + if (output_val < priv->thresh_val[thresh_val_id]) 933 + iio_push_event(indio_dev, 934 + IIO_MOD_EVENT_CODE( 935 + IIO_LIGHT, 936 + GP2AP020A00F_SCAN_MODE_LIGHT_CLEAR, 937 + IIO_MOD_LIGHT_CLEAR, 938 + IIO_EV_TYPE_THRESH, 939 + IIO_EV_DIR_FALLING), 940 + iio_get_time_ns()); 941 + } 942 + } 943 + 944 + if (priv->cur_opmode == GP2AP020A00F_OPMODE_READ_RAW_CLEAR || 945 + priv->cur_opmode == GP2AP020A00F_OPMODE_READ_RAW_IR || 946 + priv->cur_opmode == GP2AP020A00F_OPMODE_READ_RAW_PROXIMITY) { 947 + set_bit(GP2AP020A00F_FLAG_DATA_READY, &priv->flags); 948 + wake_up(&priv->data_ready_queue); 949 + goto done; 950 + } 951 + 952 + if (test_bit(GP2AP020A00F_FLAG_ALS_CLEAR_TRIGGER, &priv->flags) || 953 + test_bit(GP2AP020A00F_FLAG_ALS_IR_TRIGGER, &priv->flags) || 954 + test_bit(GP2AP020A00F_FLAG_PROX_TRIGGER, &priv->flags)) 955 + /* This fires off the trigger. */ 956 + irq_work_queue(&priv->work); 957 + 958 + done: 959 + return IRQ_HANDLED; 960 + } 961 + 962 + static irqreturn_t gp2ap020a00f_trigger_handler(int irq, void *data) 963 + { 964 + struct iio_poll_func *pf = data; 965 + struct iio_dev *indio_dev = pf->indio_dev; 966 + struct gp2ap020a00f_data *priv = iio_priv(indio_dev); 967 + size_t d_size = 0; 968 + __le32 light_lux; 969 + int i, out_val, ret; 970 + 971 + for_each_set_bit(i, indio_dev->active_scan_mask, 972 + indio_dev->masklength) { 973 + ret = regmap_bulk_read(priv->regmap, 974 + GP2AP020A00F_DATA_REG(i), 975 + &priv->buffer[d_size], 2); 976 + if (ret < 0) 977 + goto done; 978 + 979 + if (i == GP2AP020A00F_SCAN_MODE_LIGHT_CLEAR || 980 + i == GP2AP020A00F_SCAN_MODE_LIGHT_IR) { 981 + out_val = le16_to_cpup((__le16 *)&priv->buffer[d_size]); 982 + gp2ap020a00f_output_to_lux(priv, &out_val); 983 + light_lux = cpu_to_le32(out_val); 984 + memcpy(&priv->buffer[d_size], (u8 *)&light_lux, 4); 985 + d_size += 4; 986 + } else { 987 + d_size += 2; 988 + } 989 + } 990 + 991 + iio_push_to_buffers_with_timestamp(indio_dev, priv->buffer, 992 + pf->timestamp); 993 + done: 994 + iio_trigger_notify_done(indio_dev->trig); 995 + 996 + return IRQ_HANDLED; 997 + } 998 + 999 + static u8 gp2ap020a00f_get_reg_by_event_code(u64 event_code) 1000 + { 1001 + int event_dir = IIO_EVENT_CODE_EXTRACT_DIR(event_code); 1002 + 1003 + switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) { 1004 + case IIO_PROXIMITY: 1005 + if (event_dir == IIO_EV_DIR_RISING) 1006 + return GP2AP020A00F_PH_L_REG; 1007 + else 1008 + return GP2AP020A00F_PL_L_REG; 1009 + case IIO_LIGHT: 1010 + if (event_dir == IIO_EV_DIR_RISING) 1011 + return GP2AP020A00F_TH_L_REG; 1012 + else 1013 + return GP2AP020A00F_TL_L_REG; 1014 + } 1015 + 1016 + return -EINVAL; 1017 + } 1018 + 1019 + static int gp2ap020a00f_write_event_val(struct iio_dev *indio_dev, 1020 + u64 event_code, int val) 1021 + { 1022 + struct gp2ap020a00f_data *data = iio_priv(indio_dev); 1023 + bool event_en = false; 1024 + u8 thresh_val_id; 1025 + u8 thresh_reg_l; 1026 + int err = 0; 1027 + 1028 + mutex_lock(&data->lock); 1029 + 1030 + thresh_reg_l = gp2ap020a00f_get_reg_by_event_code(event_code); 1031 + thresh_val_id = GP2AP020A00F_THRESH_VAL_ID(thresh_reg_l); 1032 + 1033 + if (thresh_val_id > GP2AP020A00F_THRESH_PH) { 1034 + err = -EINVAL; 1035 + goto error_unlock; 1036 + } 1037 + 1038 + switch (thresh_reg_l) { 1039 + case GP2AP020A00F_TH_L_REG: 1040 + event_en = test_bit(GP2AP020A00F_FLAG_ALS_RISING_EV, 1041 + &data->flags); 1042 + break; 1043 + case GP2AP020A00F_TL_L_REG: 1044 + event_en = test_bit(GP2AP020A00F_FLAG_ALS_FALLING_EV, 1045 + &data->flags); 1046 + break; 1047 + case GP2AP020A00F_PH_L_REG: 1048 + if (val == 0) { 1049 + err = -EINVAL; 1050 + goto error_unlock; 1051 + } 1052 + event_en = test_bit(GP2AP020A00F_FLAG_PROX_RISING_EV, 1053 + &data->flags); 1054 + break; 1055 + case GP2AP020A00F_PL_L_REG: 1056 + if (val == 0) { 1057 + err = -EINVAL; 1058 + goto error_unlock; 1059 + } 1060 + event_en = test_bit(GP2AP020A00F_FLAG_PROX_FALLING_EV, 1061 + &data->flags); 1062 + break; 1063 + } 1064 + 1065 + data->thresh_val[thresh_val_id] = val; 1066 + err = gp2ap020a00f_write_event_threshold(data, thresh_val_id, 1067 + event_en); 1068 + error_unlock: 1069 + mutex_unlock(&data->lock); 1070 + 1071 + return err; 1072 + } 1073 + 1074 + static int gp2ap020a00f_read_event_val(struct iio_dev *indio_dev, 1075 + u64 event_code, int *val) 1076 + { 1077 + struct gp2ap020a00f_data *data = iio_priv(indio_dev); 1078 + u8 thresh_reg_l; 1079 + int err = 0; 1080 + 1081 + mutex_lock(&data->lock); 1082 + 1083 + thresh_reg_l = gp2ap020a00f_get_reg_by_event_code(event_code); 1084 + 1085 + if (thresh_reg_l > GP2AP020A00F_PH_L_REG) { 1086 + err = -EINVAL; 1087 + goto error_unlock; 1088 + } 1089 + 1090 + *val = data->thresh_val[GP2AP020A00F_THRESH_VAL_ID(thresh_reg_l)]; 1091 + 1092 + error_unlock: 1093 + mutex_unlock(&data->lock); 1094 + 1095 + return err; 1096 + } 1097 + 1098 + static int gp2ap020a00f_write_prox_event_config(struct iio_dev *indio_dev, 1099 + u64 event_code, int state) 1100 + { 1101 + struct gp2ap020a00f_data *data = iio_priv(indio_dev); 1102 + enum gp2ap020a00f_cmd cmd_high_ev, cmd_low_ev; 1103 + int err; 1104 + 1105 + cmd_high_ev = state ? GP2AP020A00F_CMD_PROX_HIGH_EV_EN : 1106 + GP2AP020A00F_CMD_PROX_HIGH_EV_DIS; 1107 + cmd_low_ev = state ? GP2AP020A00F_CMD_PROX_LOW_EV_EN : 1108 + GP2AP020A00F_CMD_PROX_LOW_EV_DIS; 1109 + 1110 + /* 1111 + * In order to enable proximity detection feature in the device 1112 + * both high and low threshold registers have to be written 1113 + * with different values, greater than zero. 1114 + */ 1115 + if (state) { 1116 + if (data->thresh_val[GP2AP020A00F_THRESH_PL] == 0) 1117 + return -EINVAL; 1118 + 1119 + if (data->thresh_val[GP2AP020A00F_THRESH_PH] == 0) 1120 + return -EINVAL; 1121 + } 1122 + 1123 + err = gp2ap020a00f_exec_cmd(data, cmd_high_ev); 1124 + if (err < 0) 1125 + return err; 1126 + 1127 + err = gp2ap020a00f_exec_cmd(data, cmd_low_ev); 1128 + if (err < 0) 1129 + return err; 1130 + 1131 + free_irq(data->client->irq, indio_dev); 1132 + 1133 + if (state) 1134 + err = request_threaded_irq(data->client->irq, NULL, 1135 + &gp2ap020a00f_prox_sensing_handler, 1136 + IRQF_TRIGGER_RISING | 1137 + IRQF_TRIGGER_FALLING | 1138 + IRQF_ONESHOT, 1139 + "gp2ap020a00f_prox_sensing", 1140 + indio_dev); 1141 + else { 1142 + err = request_threaded_irq(data->client->irq, NULL, 1143 + &gp2ap020a00f_thresh_event_handler, 1144 + IRQF_TRIGGER_FALLING | 1145 + IRQF_ONESHOT, 1146 + "gp2ap020a00f_thresh_event", 1147 + indio_dev); 1148 + } 1149 + 1150 + return err; 1151 + } 1152 + 1153 + static int gp2ap020a00f_write_event_config(struct iio_dev *indio_dev, 1154 + u64 event_code, int state) 1155 + { 1156 + struct gp2ap020a00f_data *data = iio_priv(indio_dev); 1157 + enum gp2ap020a00f_cmd cmd; 1158 + int err; 1159 + 1160 + mutex_lock(&data->lock); 1161 + 1162 + switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) { 1163 + case IIO_PROXIMITY: 1164 + err = gp2ap020a00f_write_prox_event_config(indio_dev, 1165 + event_code, state); 1166 + break; 1167 + case IIO_LIGHT: 1168 + if (IIO_EVENT_CODE_EXTRACT_DIR(event_code) 1169 + == IIO_EV_DIR_RISING) { 1170 + cmd = state ? GP2AP020A00F_CMD_ALS_HIGH_EV_EN : 1171 + GP2AP020A00F_CMD_ALS_HIGH_EV_DIS; 1172 + err = gp2ap020a00f_exec_cmd(data, cmd); 1173 + } else { 1174 + cmd = state ? GP2AP020A00F_CMD_ALS_LOW_EV_EN : 1175 + GP2AP020A00F_CMD_ALS_LOW_EV_DIS; 1176 + err = gp2ap020a00f_exec_cmd(data, cmd); 1177 + } 1178 + break; 1179 + default: 1180 + err = -EINVAL; 1181 + } 1182 + 1183 + mutex_unlock(&data->lock); 1184 + 1185 + return err; 1186 + } 1187 + 1188 + static int gp2ap020a00f_read_event_config(struct iio_dev *indio_dev, 1189 + u64 event_code) 1190 + { 1191 + struct gp2ap020a00f_data *data = iio_priv(indio_dev); 1192 + int event_en = 0; 1193 + 1194 + mutex_lock(&data->lock); 1195 + 1196 + switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) { 1197 + case IIO_PROXIMITY: 1198 + if (IIO_EVENT_CODE_EXTRACT_DIR(event_code) 1199 + == IIO_EV_DIR_RISING) 1200 + event_en = test_bit(GP2AP020A00F_FLAG_PROX_RISING_EV, 1201 + &data->flags); 1202 + else 1203 + event_en = test_bit(GP2AP020A00F_FLAG_PROX_FALLING_EV, 1204 + &data->flags); 1205 + break; 1206 + case IIO_LIGHT: 1207 + if (IIO_EVENT_CODE_EXTRACT_DIR(event_code) 1208 + == IIO_EV_DIR_RISING) 1209 + event_en = test_bit(GP2AP020A00F_FLAG_ALS_RISING_EV, 1210 + &data->flags); 1211 + else 1212 + event_en = test_bit(GP2AP020A00F_FLAG_ALS_FALLING_EV, 1213 + &data->flags); 1214 + break; 1215 + } 1216 + 1217 + mutex_unlock(&data->lock); 1218 + 1219 + return event_en; 1220 + } 1221 + 1222 + static int gp2ap020a00f_read_channel(struct gp2ap020a00f_data *data, 1223 + struct iio_chan_spec const *chan, int *val) 1224 + { 1225 + enum gp2ap020a00f_cmd cmd; 1226 + int err; 1227 + 1228 + switch (chan->scan_index) { 1229 + case GP2AP020A00F_SCAN_MODE_LIGHT_CLEAR: 1230 + cmd = GP2AP020A00F_CMD_READ_RAW_CLEAR; 1231 + break; 1232 + case GP2AP020A00F_SCAN_MODE_LIGHT_IR: 1233 + cmd = GP2AP020A00F_CMD_READ_RAW_IR; 1234 + break; 1235 + case GP2AP020A00F_SCAN_MODE_PROXIMITY: 1236 + cmd = GP2AP020A00F_CMD_READ_RAW_PROXIMITY; 1237 + break; 1238 + default: 1239 + return -EINVAL; 1240 + } 1241 + 1242 + err = gp2ap020a00f_exec_cmd(data, cmd); 1243 + if (err < 0) { 1244 + dev_err(&data->client->dev, 1245 + "gp2ap020a00f_exec_cmd failed\n"); 1246 + goto error_ret; 1247 + } 1248 + 1249 + err = gp2ap020a00f_read_output(data, chan->address, val); 1250 + if (err < 0) 1251 + dev_err(&data->client->dev, 1252 + "gp2ap020a00f_read_output failed\n"); 1253 + 1254 + err = gp2ap020a00f_set_operation_mode(data, 1255 + GP2AP020A00F_OPMODE_SHUTDOWN); 1256 + if (err < 0) 1257 + dev_err(&data->client->dev, 1258 + "Failed to shut down the device.\n"); 1259 + 1260 + if (cmd == GP2AP020A00F_CMD_READ_RAW_CLEAR || 1261 + cmd == GP2AP020A00F_CMD_READ_RAW_IR) 1262 + gp2ap020a00f_output_to_lux(data, val); 1263 + 1264 + error_ret: 1265 + return err; 1266 + } 1267 + 1268 + static int gp2ap020a00f_read_raw(struct iio_dev *indio_dev, 1269 + struct iio_chan_spec const *chan, 1270 + int *val, int *val2, 1271 + long mask) 1272 + { 1273 + struct gp2ap020a00f_data *data = iio_priv(indio_dev); 1274 + int err = -EINVAL; 1275 + 1276 + mutex_lock(&data->lock); 1277 + 1278 + switch (mask) { 1279 + case IIO_CHAN_INFO_RAW: 1280 + if (iio_buffer_enabled(indio_dev)) { 1281 + err = -EBUSY; 1282 + goto error_unlock; 1283 + } 1284 + 1285 + err = gp2ap020a00f_read_channel(data, chan, val); 1286 + break; 1287 + } 1288 + 1289 + error_unlock: 1290 + mutex_unlock(&data->lock); 1291 + 1292 + return err < 0 ? err : IIO_VAL_INT; 1293 + } 1294 + 1295 + static const struct iio_chan_spec gp2ap020a00f_channels[] = { 1296 + { 1297 + .type = IIO_LIGHT, 1298 + .channel2 = IIO_MOD_LIGHT_CLEAR, 1299 + .modified = 1, 1300 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 1301 + .scan_type = { 1302 + .sign = 'u', 1303 + .realbits = 24, 1304 + .shift = 0, 1305 + .storagebits = 32, 1306 + .endianness = IIO_LE, 1307 + }, 1308 + .scan_index = GP2AP020A00F_SCAN_MODE_LIGHT_CLEAR, 1309 + .address = GP2AP020A00F_D0_L_REG, 1310 + .event_mask = IIO_EV_BIT(IIO_EV_TYPE_THRESH, 1311 + IIO_EV_DIR_RISING) | 1312 + IIO_EV_BIT(IIO_EV_TYPE_THRESH, 1313 + IIO_EV_DIR_FALLING), 1314 + }, 1315 + { 1316 + .type = IIO_LIGHT, 1317 + .channel2 = IIO_MOD_LIGHT_IR, 1318 + .modified = 1, 1319 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 1320 + .scan_type = { 1321 + .sign = 'u', 1322 + .realbits = 24, 1323 + .shift = 0, 1324 + .storagebits = 32, 1325 + .endianness = IIO_LE, 1326 + }, 1327 + .scan_index = GP2AP020A00F_SCAN_MODE_LIGHT_IR, 1328 + .address = GP2AP020A00F_D1_L_REG, 1329 + }, 1330 + { 1331 + .type = IIO_PROXIMITY, 1332 + .modified = 0, 1333 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 1334 + .scan_type = { 1335 + .sign = 'u', 1336 + .realbits = 16, 1337 + .shift = 0, 1338 + .storagebits = 16, 1339 + .endianness = IIO_LE, 1340 + }, 1341 + .scan_index = GP2AP020A00F_SCAN_MODE_PROXIMITY, 1342 + .address = GP2AP020A00F_D2_L_REG, 1343 + .event_mask = IIO_EV_BIT(IIO_EV_TYPE_ROC, 1344 + IIO_EV_DIR_RISING) | 1345 + IIO_EV_BIT(IIO_EV_TYPE_ROC, 1346 + IIO_EV_DIR_FALLING), 1347 + }, 1348 + IIO_CHAN_SOFT_TIMESTAMP(GP2AP020A00F_CHAN_TIMESTAMP), 1349 + }; 1350 + 1351 + static const struct iio_info gp2ap020a00f_info = { 1352 + .read_raw = &gp2ap020a00f_read_raw, 1353 + .read_event_value = &gp2ap020a00f_read_event_val, 1354 + .read_event_config = &gp2ap020a00f_read_event_config, 1355 + .write_event_value = &gp2ap020a00f_write_event_val, 1356 + .write_event_config = &gp2ap020a00f_write_event_config, 1357 + .driver_module = THIS_MODULE, 1358 + }; 1359 + 1360 + static int gp2ap020a00f_buffer_postenable(struct iio_dev *indio_dev) 1361 + { 1362 + struct gp2ap020a00f_data *data = iio_priv(indio_dev); 1363 + int i, err = 0; 1364 + 1365 + mutex_lock(&data->lock); 1366 + 1367 + /* 1368 + * Enable triggers according to the scan_mask. Enabling either 1369 + * LIGHT_CLEAR or LIGHT_IR scan mode results in enabling ALS 1370 + * module in the device, which generates samples in both D0 (clear) 1371 + * and D1 (ir) registers. As the two registers are bound to the 1372 + * two separate IIO channels they are treated in the driver logic 1373 + * as if they were controlled independently. 1374 + */ 1375 + for_each_set_bit(i, indio_dev->active_scan_mask, 1376 + indio_dev->masklength) { 1377 + switch (i) { 1378 + case GP2AP020A00F_SCAN_MODE_LIGHT_CLEAR: 1379 + err = gp2ap020a00f_exec_cmd(data, 1380 + GP2AP020A00F_CMD_TRIGGER_CLEAR_EN); 1381 + break; 1382 + case GP2AP020A00F_SCAN_MODE_LIGHT_IR: 1383 + err = gp2ap020a00f_exec_cmd(data, 1384 + GP2AP020A00F_CMD_TRIGGER_IR_EN); 1385 + break; 1386 + case GP2AP020A00F_SCAN_MODE_PROXIMITY: 1387 + err = gp2ap020a00f_exec_cmd(data, 1388 + GP2AP020A00F_CMD_TRIGGER_PROX_EN); 1389 + break; 1390 + } 1391 + } 1392 + 1393 + if (err < 0) 1394 + goto error_unlock; 1395 + 1396 + data->buffer = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); 1397 + if (!data->buffer) { 1398 + err = -ENOMEM; 1399 + goto error_unlock; 1400 + } 1401 + 1402 + err = iio_triggered_buffer_postenable(indio_dev); 1403 + 1404 + error_unlock: 1405 + mutex_unlock(&data->lock); 1406 + 1407 + return err; 1408 + } 1409 + 1410 + static int gp2ap020a00f_buffer_predisable(struct iio_dev *indio_dev) 1411 + { 1412 + struct gp2ap020a00f_data *data = iio_priv(indio_dev); 1413 + int i, err; 1414 + 1415 + mutex_lock(&data->lock); 1416 + 1417 + err = iio_triggered_buffer_predisable(indio_dev); 1418 + if (err < 0) 1419 + goto error_unlock; 1420 + 1421 + for_each_set_bit(i, indio_dev->active_scan_mask, 1422 + indio_dev->masklength) { 1423 + switch (i) { 1424 + case GP2AP020A00F_SCAN_MODE_LIGHT_CLEAR: 1425 + err = gp2ap020a00f_exec_cmd(data, 1426 + GP2AP020A00F_CMD_TRIGGER_CLEAR_DIS); 1427 + break; 1428 + case GP2AP020A00F_SCAN_MODE_LIGHT_IR: 1429 + err = gp2ap020a00f_exec_cmd(data, 1430 + GP2AP020A00F_CMD_TRIGGER_IR_DIS); 1431 + break; 1432 + case GP2AP020A00F_SCAN_MODE_PROXIMITY: 1433 + err = gp2ap020a00f_exec_cmd(data, 1434 + GP2AP020A00F_CMD_TRIGGER_PROX_DIS); 1435 + break; 1436 + } 1437 + } 1438 + 1439 + if (err == 0) 1440 + kfree(data->buffer); 1441 + 1442 + error_unlock: 1443 + mutex_unlock(&data->lock); 1444 + 1445 + return err; 1446 + } 1447 + 1448 + static const struct iio_buffer_setup_ops gp2ap020a00f_buffer_setup_ops = { 1449 + .preenable = &iio_sw_buffer_preenable, 1450 + .postenable = &gp2ap020a00f_buffer_postenable, 1451 + .predisable = &gp2ap020a00f_buffer_predisable, 1452 + }; 1453 + 1454 + static const struct iio_trigger_ops gp2ap020a00f_trigger_ops = { 1455 + .owner = THIS_MODULE, 1456 + }; 1457 + 1458 + static int gp2ap020a00f_probe(struct i2c_client *client, 1459 + const struct i2c_device_id *id) 1460 + { 1461 + struct gp2ap020a00f_data *data; 1462 + struct iio_dev *indio_dev; 1463 + struct regmap *regmap; 1464 + int err; 1465 + 1466 + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 1467 + if (!indio_dev) 1468 + return -ENOMEM; 1469 + 1470 + data = iio_priv(indio_dev); 1471 + 1472 + data->vled_reg = devm_regulator_get(&client->dev, "vled"); 1473 + if (IS_ERR(data->vled_reg)) 1474 + return PTR_ERR(data->vled_reg); 1475 + 1476 + err = regulator_enable(data->vled_reg); 1477 + if (err) 1478 + return err; 1479 + 1480 + regmap = devm_regmap_init_i2c(client, &gp2ap020a00f_regmap_config); 1481 + if (IS_ERR(regmap)) { 1482 + dev_err(&client->dev, "Regmap initialization failed.\n"); 1483 + err = PTR_ERR(regmap); 1484 + goto error_regulator_disable; 1485 + } 1486 + 1487 + /* Initialize device registers */ 1488 + err = regmap_bulk_write(regmap, GP2AP020A00F_OP_REG, 1489 + gp2ap020a00f_reg_init_tab, 1490 + ARRAY_SIZE(gp2ap020a00f_reg_init_tab)); 1491 + 1492 + if (err < 0) { 1493 + dev_err(&client->dev, "Device initialization failed.\n"); 1494 + goto error_regulator_disable; 1495 + } 1496 + 1497 + i2c_set_clientdata(client, indio_dev); 1498 + 1499 + data->client = client; 1500 + data->cur_opmode = GP2AP020A00F_OPMODE_SHUTDOWN; 1501 + data->regmap = regmap; 1502 + init_waitqueue_head(&data->data_ready_queue); 1503 + 1504 + mutex_init(&data->lock); 1505 + indio_dev->dev.parent = &client->dev; 1506 + indio_dev->channels = gp2ap020a00f_channels; 1507 + indio_dev->num_channels = ARRAY_SIZE(gp2ap020a00f_channels); 1508 + indio_dev->info = &gp2ap020a00f_info; 1509 + indio_dev->name = id->name; 1510 + indio_dev->modes = INDIO_DIRECT_MODE; 1511 + 1512 + /* Allocate buffer */ 1513 + err = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time, 1514 + &gp2ap020a00f_trigger_handler, &gp2ap020a00f_buffer_setup_ops); 1515 + if (err < 0) 1516 + goto error_regulator_disable; 1517 + 1518 + /* Allocate trigger */ 1519 + data->trig = devm_iio_trigger_alloc(&client->dev, "%s-trigger", 1520 + indio_dev->name); 1521 + if (data->trig == NULL) { 1522 + err = -ENOMEM; 1523 + dev_err(&indio_dev->dev, "Failed to allocate iio trigger.\n"); 1524 + goto error_uninit_buffer; 1525 + } 1526 + 1527 + /* This needs to be requested here for read_raw calls to work. */ 1528 + err = request_threaded_irq(client->irq, NULL, 1529 + &gp2ap020a00f_thresh_event_handler, 1530 + IRQF_TRIGGER_FALLING | 1531 + IRQF_ONESHOT, 1532 + "gp2ap020a00f_als_event", 1533 + indio_dev); 1534 + if (err < 0) { 1535 + dev_err(&client->dev, "Irq request failed.\n"); 1536 + goto error_uninit_buffer; 1537 + } 1538 + 1539 + data->trig->ops = &gp2ap020a00f_trigger_ops; 1540 + data->trig->dev.parent = &data->client->dev; 1541 + 1542 + init_irq_work(&data->work, gp2ap020a00f_iio_trigger_work); 1543 + 1544 + err = iio_trigger_register(data->trig); 1545 + if (err < 0) { 1546 + dev_err(&client->dev, "Failed to register iio trigger.\n"); 1547 + goto error_free_irq; 1548 + } 1549 + 1550 + err = iio_device_register(indio_dev); 1551 + if (err < 0) 1552 + goto error_trigger_unregister; 1553 + 1554 + return 0; 1555 + 1556 + error_trigger_unregister: 1557 + iio_trigger_unregister(data->trig); 1558 + error_free_irq: 1559 + free_irq(client->irq, indio_dev); 1560 + error_uninit_buffer: 1561 + iio_triggered_buffer_cleanup(indio_dev); 1562 + error_regulator_disable: 1563 + regulator_disable(data->vled_reg); 1564 + 1565 + return err; 1566 + } 1567 + 1568 + static int gp2ap020a00f_remove(struct i2c_client *client) 1569 + { 1570 + struct iio_dev *indio_dev = i2c_get_clientdata(client); 1571 + struct gp2ap020a00f_data *data = iio_priv(indio_dev); 1572 + int err; 1573 + 1574 + err = gp2ap020a00f_set_operation_mode(data, 1575 + GP2AP020A00F_OPMODE_SHUTDOWN); 1576 + if (err < 0) 1577 + dev_err(&indio_dev->dev, "Failed to power off the device.\n"); 1578 + 1579 + iio_device_unregister(indio_dev); 1580 + iio_trigger_unregister(data->trig); 1581 + free_irq(client->irq, indio_dev); 1582 + iio_triggered_buffer_cleanup(indio_dev); 1583 + regulator_disable(data->vled_reg); 1584 + 1585 + return 0; 1586 + } 1587 + 1588 + static const struct i2c_device_id gp2ap020a00f_id[] = { 1589 + { GP2A_I2C_NAME, 0 }, 1590 + { } 1591 + }; 1592 + 1593 + MODULE_DEVICE_TABLE(i2c, gp2ap020a00f_id); 1594 + 1595 + #ifdef CONFIG_OF 1596 + static const struct of_device_id gp2ap020a00f_of_match[] = { 1597 + { .compatible = "sharp,gp2ap020a00f" }, 1598 + { } 1599 + }; 1600 + #endif 1601 + 1602 + static struct i2c_driver gp2ap020a00f_driver = { 1603 + .driver = { 1604 + .name = GP2A_I2C_NAME, 1605 + .of_match_table = of_match_ptr(gp2ap020a00f_of_match), 1606 + .owner = THIS_MODULE, 1607 + }, 1608 + .probe = gp2ap020a00f_probe, 1609 + .remove = gp2ap020a00f_remove, 1610 + .id_table = gp2ap020a00f_id, 1611 + }; 1612 + 1613 + module_i2c_driver(gp2ap020a00f_driver); 1614 + 1615 + MODULE_AUTHOR("Jacek Anaszewski <j.anaszewski@samsung.com>"); 1616 + MODULE_DESCRIPTION("Sharp GP2AP020A00F Proximity/ALS sensor driver"); 1617 + MODULE_LICENSE("GPL v2");
+4 -3
drivers/iio/light/hid-sensor-als.c
··· 161 161 }; 162 162 163 163 /* Function to push data to buffer */ 164 - static void hid_sensor_push_data(struct iio_dev *indio_dev, u8 *data, int len) 164 + static void hid_sensor_push_data(struct iio_dev *indio_dev, const void *data, 165 + int len) 165 166 { 166 167 dev_dbg(&indio_dev->dev, "hid_sensor_push_data\n"); 167 - iio_push_to_buffers(indio_dev, (u8 *)data); 168 + iio_push_to_buffers(indio_dev, data); 168 169 } 169 170 170 171 /* Callback handler to send event after all samples are received and captured */ ··· 180 179 als_state->common_attributes.data_ready); 181 180 if (als_state->common_attributes.data_ready) 182 181 hid_sensor_push_data(indio_dev, 183 - (u8 *)&als_state->illum, 182 + &als_state->illum, 184 183 sizeof(als_state->illum)); 185 184 186 185 return 0;
+367
drivers/iio/light/tcs3472.c
··· 1 + /* 2 + * tcs3472.c - Support for TAOS TCS3472 color light-to-digital converter 3 + * 4 + * Copyright (c) 2013 Peter Meerwald <pmeerw@pmeerw.net> 5 + * 6 + * This file is subject to the terms and conditions of version 2 of 7 + * the GNU General Public License. See the file COPYING in the main 8 + * directory of this archive for more details. 9 + * 10 + * Color light sensor with 16-bit channels for red, green, blue, clear); 11 + * 7-bit I2C slave address 0x39 (TCS34721, TCS34723) or 0x29 (TCS34725, 12 + * TCS34727) 13 + * 14 + * TODO: interrupt support, thresholds, wait time 15 + */ 16 + 17 + #include <linux/module.h> 18 + #include <linux/i2c.h> 19 + #include <linux/delay.h> 20 + #include <linux/pm.h> 21 + 22 + #include <linux/iio/iio.h> 23 + #include <linux/iio/sysfs.h> 24 + #include <linux/iio/trigger_consumer.h> 25 + #include <linux/iio/buffer.h> 26 + #include <linux/iio/triggered_buffer.h> 27 + 28 + #define TCS3472_DRV_NAME "tcs3472" 29 + 30 + #define TCS3472_COMMAND BIT(7) 31 + #define TCS3472_AUTO_INCR BIT(5) 32 + 33 + #define TCS3472_ENABLE (TCS3472_COMMAND | 0x00) 34 + #define TCS3472_ATIME (TCS3472_COMMAND | 0x01) 35 + #define TCS3472_WTIME (TCS3472_COMMAND | 0x03) 36 + #define TCS3472_AILT (TCS3472_COMMAND | 0x04) 37 + #define TCS3472_AIHT (TCS3472_COMMAND | 0x06) 38 + #define TCS3472_PERS (TCS3472_COMMAND | 0x0c) 39 + #define TCS3472_CONFIG (TCS3472_COMMAND | 0x0d) 40 + #define TCS3472_CONTROL (TCS3472_COMMAND | 0x0f) 41 + #define TCS3472_ID (TCS3472_COMMAND | 0x12) 42 + #define TCS3472_STATUS (TCS3472_COMMAND | 0x13) 43 + #define TCS3472_CDATA (TCS3472_COMMAND | TCS3472_AUTO_INCR | 0x14) 44 + #define TCS3472_RDATA (TCS3472_COMMAND | TCS3472_AUTO_INCR | 0x16) 45 + #define TCS3472_GDATA (TCS3472_COMMAND | TCS3472_AUTO_INCR | 0x18) 46 + #define TCS3472_BDATA (TCS3472_COMMAND | TCS3472_AUTO_INCR | 0x1a) 47 + 48 + #define TCS3472_STATUS_AVALID BIT(0) 49 + #define TCS3472_ENABLE_AEN BIT(1) 50 + #define TCS3472_ENABLE_PON BIT(0) 51 + #define TCS3472_CONTROL_AGAIN_MASK (BIT(0) | BIT(1)) 52 + 53 + struct tcs3472_data { 54 + struct i2c_client *client; 55 + u8 enable; 56 + u8 control; 57 + u8 atime; 58 + u16 buffer[8]; /* 4 16-bit channels + 64-bit timestamp */ 59 + }; 60 + 61 + #define TCS3472_CHANNEL(_color, _si, _addr) { \ 62 + .type = IIO_INTENSITY, \ 63 + .modified = 1, \ 64 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 65 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_CALIBSCALE) | \ 66 + BIT(IIO_CHAN_INFO_INT_TIME), \ 67 + .channel2 = IIO_MOD_LIGHT_##_color, \ 68 + .address = _addr, \ 69 + .scan_index = _si, \ 70 + .scan_type = IIO_ST('u', 16, 16, 0), \ 71 + } 72 + 73 + static const int tcs3472_agains[] = { 1, 4, 16, 60 }; 74 + 75 + static const struct iio_chan_spec tcs3472_channels[] = { 76 + TCS3472_CHANNEL(CLEAR, 0, TCS3472_CDATA), 77 + TCS3472_CHANNEL(RED, 1, TCS3472_RDATA), 78 + TCS3472_CHANNEL(GREEN, 2, TCS3472_GDATA), 79 + TCS3472_CHANNEL(BLUE, 3, TCS3472_BDATA), 80 + IIO_CHAN_SOFT_TIMESTAMP(4), 81 + }; 82 + 83 + static int tcs3472_req_data(struct tcs3472_data *data) 84 + { 85 + int tries = 50; 86 + int ret; 87 + 88 + while (tries--) { 89 + ret = i2c_smbus_read_byte_data(data->client, TCS3472_STATUS); 90 + if (ret < 0) 91 + return ret; 92 + if (ret & TCS3472_STATUS_AVALID) 93 + break; 94 + msleep(20); 95 + } 96 + 97 + if (tries < 0) { 98 + dev_err(&data->client->dev, "data not ready\n"); 99 + return -EIO; 100 + } 101 + 102 + return 0; 103 + } 104 + 105 + static int tcs3472_read_raw(struct iio_dev *indio_dev, 106 + struct iio_chan_spec const *chan, 107 + int *val, int *val2, long mask) 108 + { 109 + struct tcs3472_data *data = iio_priv(indio_dev); 110 + int ret; 111 + 112 + switch (mask) { 113 + case IIO_CHAN_INFO_RAW: 114 + ret = tcs3472_req_data(data); 115 + if (ret < 0) 116 + return ret; 117 + ret = i2c_smbus_read_word_data(data->client, chan->address); 118 + if (ret < 0) 119 + return ret; 120 + *val = ret; 121 + return IIO_VAL_INT; 122 + case IIO_CHAN_INFO_CALIBSCALE: 123 + *val = tcs3472_agains[data->control & 124 + TCS3472_CONTROL_AGAIN_MASK]; 125 + return IIO_VAL_INT; 126 + case IIO_CHAN_INFO_INT_TIME: 127 + *val = 0; 128 + *val2 = (256 - data->atime) * 2400; 129 + return IIO_VAL_INT_PLUS_MICRO; 130 + } 131 + return -EINVAL; 132 + } 133 + 134 + static int tcs3472_write_raw(struct iio_dev *indio_dev, 135 + struct iio_chan_spec const *chan, 136 + int val, int val2, long mask) 137 + { 138 + struct tcs3472_data *data = iio_priv(indio_dev); 139 + int i; 140 + 141 + switch (mask) { 142 + case IIO_CHAN_INFO_CALIBSCALE: 143 + if (val2 != 0) 144 + return -EINVAL; 145 + for (i = 0; i < ARRAY_SIZE(tcs3472_agains); i++) { 146 + if (val == tcs3472_agains[i]) { 147 + data->control &= ~TCS3472_CONTROL_AGAIN_MASK; 148 + data->control |= i; 149 + return i2c_smbus_write_byte_data( 150 + data->client, TCS3472_CONTROL, 151 + data->control); 152 + } 153 + } 154 + return -EINVAL; 155 + case IIO_CHAN_INFO_INT_TIME: 156 + if (val != 0) 157 + return -EINVAL; 158 + for (i = 0; i < 256; i++) { 159 + if (val2 == (256 - i) * 2400) { 160 + data->atime = i; 161 + return i2c_smbus_write_word_data( 162 + data->client, TCS3472_ATIME, 163 + data->atime); 164 + } 165 + 166 + } 167 + return -EINVAL; 168 + } 169 + return -EINVAL; 170 + } 171 + 172 + static irqreturn_t tcs3472_trigger_handler(int irq, void *p) 173 + { 174 + struct iio_poll_func *pf = p; 175 + struct iio_dev *indio_dev = pf->indio_dev; 176 + struct tcs3472_data *data = iio_priv(indio_dev); 177 + int len = 0; 178 + int i, j = 0; 179 + 180 + int ret = tcs3472_req_data(data); 181 + if (ret < 0) 182 + goto done; 183 + 184 + for_each_set_bit(i, indio_dev->active_scan_mask, 185 + indio_dev->masklength) { 186 + ret = i2c_smbus_read_word_data(data->client, 187 + TCS3472_CDATA + 2*i); 188 + if (ret < 0) 189 + goto done; 190 + 191 + data->buffer[j++] = ret; 192 + len += 2; 193 + } 194 + 195 + iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, 196 + iio_get_time_ns()); 197 + 198 + done: 199 + iio_trigger_notify_done(indio_dev->trig); 200 + 201 + return IRQ_HANDLED; 202 + } 203 + 204 + static ssize_t tcs3472_show_int_time_available(struct device *dev, 205 + struct device_attribute *attr, 206 + char *buf) 207 + { 208 + size_t len = 0; 209 + int i; 210 + 211 + for (i = 1; i <= 256; i++) 212 + len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06d ", 213 + 2400 * i); 214 + 215 + /* replace trailing space by newline */ 216 + buf[len - 1] = '\n'; 217 + 218 + return len; 219 + } 220 + 221 + static IIO_CONST_ATTR(calibscale_available, "1 4 16 60"); 222 + static IIO_DEV_ATTR_INT_TIME_AVAIL(tcs3472_show_int_time_available); 223 + 224 + static struct attribute *tcs3472_attributes[] = { 225 + &iio_const_attr_calibscale_available.dev_attr.attr, 226 + &iio_dev_attr_integration_time_available.dev_attr.attr, 227 + NULL 228 + }; 229 + 230 + static const struct attribute_group tcs3472_attribute_group = { 231 + .attrs = tcs3472_attributes, 232 + }; 233 + 234 + static const struct iio_info tcs3472_info = { 235 + .read_raw = tcs3472_read_raw, 236 + .write_raw = tcs3472_write_raw, 237 + .attrs = &tcs3472_attribute_group, 238 + .driver_module = THIS_MODULE, 239 + }; 240 + 241 + static int tcs3472_probe(struct i2c_client *client, 242 + const struct i2c_device_id *id) 243 + { 244 + struct tcs3472_data *data; 245 + struct iio_dev *indio_dev; 246 + int ret; 247 + 248 + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 249 + if (indio_dev == NULL) 250 + return -ENOMEM; 251 + 252 + data = iio_priv(indio_dev); 253 + i2c_set_clientdata(client, indio_dev); 254 + data->client = client; 255 + 256 + indio_dev->dev.parent = &client->dev; 257 + indio_dev->info = &tcs3472_info; 258 + indio_dev->name = TCS3472_DRV_NAME; 259 + indio_dev->channels = tcs3472_channels; 260 + indio_dev->num_channels = ARRAY_SIZE(tcs3472_channels); 261 + indio_dev->modes = INDIO_DIRECT_MODE; 262 + 263 + ret = i2c_smbus_read_byte_data(data->client, TCS3472_ID); 264 + if (ret < 0) 265 + return ret; 266 + 267 + if (ret == 0x44) 268 + dev_info(&client->dev, "TCS34721/34725 found\n"); 269 + else if (ret == 0x4d) 270 + dev_info(&client->dev, "TCS34723/34727 found\n"); 271 + else 272 + return -ENODEV; 273 + 274 + ret = i2c_smbus_read_byte_data(data->client, TCS3472_CONTROL); 275 + if (ret < 0) 276 + return ret; 277 + data->control = ret; 278 + 279 + ret = i2c_smbus_read_byte_data(data->client, TCS3472_ATIME); 280 + if (ret < 0) 281 + return ret; 282 + data->atime = ret; 283 + 284 + ret = i2c_smbus_read_byte_data(data->client, TCS3472_ENABLE); 285 + if (ret < 0) 286 + return ret; 287 + 288 + /* enable device */ 289 + data->enable = ret | TCS3472_ENABLE_PON | TCS3472_ENABLE_AEN; 290 + ret = i2c_smbus_write_byte_data(data->client, TCS3472_ENABLE, 291 + data->enable); 292 + if (ret < 0) 293 + return ret; 294 + 295 + ret = iio_triggered_buffer_setup(indio_dev, NULL, 296 + tcs3472_trigger_handler, NULL); 297 + if (ret < 0) 298 + return ret; 299 + 300 + ret = iio_device_register(indio_dev); 301 + if (ret < 0) 302 + goto buffer_cleanup; 303 + 304 + return 0; 305 + 306 + buffer_cleanup: 307 + iio_triggered_buffer_cleanup(indio_dev); 308 + return ret; 309 + } 310 + 311 + static int tcs3472_powerdown(struct tcs3472_data *data) 312 + { 313 + return i2c_smbus_write_byte_data(data->client, TCS3472_ENABLE, 314 + data->enable & ~(TCS3472_ENABLE_AEN | TCS3472_ENABLE_PON)); 315 + } 316 + 317 + static int tcs3472_remove(struct i2c_client *client) 318 + { 319 + struct iio_dev *indio_dev = i2c_get_clientdata(client); 320 + 321 + iio_device_unregister(indio_dev); 322 + iio_triggered_buffer_cleanup(indio_dev); 323 + tcs3472_powerdown(iio_priv(indio_dev)); 324 + 325 + return 0; 326 + } 327 + 328 + #ifdef CONFIG_PM_SLEEP 329 + static int tcs3472_suspend(struct device *dev) 330 + { 331 + struct tcs3472_data *data = iio_priv(i2c_get_clientdata( 332 + to_i2c_client(dev))); 333 + return tcs3472_powerdown(data); 334 + } 335 + 336 + static int tcs3472_resume(struct device *dev) 337 + { 338 + struct tcs3472_data *data = iio_priv(i2c_get_clientdata( 339 + to_i2c_client(dev))); 340 + return i2c_smbus_write_byte_data(data->client, TCS3472_ENABLE, 341 + data->enable | (TCS3472_ENABLE_AEN | TCS3472_ENABLE_PON)); 342 + } 343 + #endif 344 + 345 + static SIMPLE_DEV_PM_OPS(tcs3472_pm_ops, tcs3472_suspend, tcs3472_resume); 346 + 347 + static const struct i2c_device_id tcs3472_id[] = { 348 + { "tcs3472", 0 }, 349 + { } 350 + }; 351 + MODULE_DEVICE_TABLE(i2c, tcs3472_id); 352 + 353 + static struct i2c_driver tcs3472_driver = { 354 + .driver = { 355 + .name = TCS3472_DRV_NAME, 356 + .pm = &tcs3472_pm_ops, 357 + .owner = THIS_MODULE, 358 + }, 359 + .probe = tcs3472_probe, 360 + .remove = tcs3472_remove, 361 + .id_table = tcs3472_id, 362 + }; 363 + module_i2c_driver(tcs3472_driver); 364 + 365 + MODULE_AUTHOR("Peter Meerwald <pmeerw@pmeerw.net>"); 366 + MODULE_DESCRIPTION("TCS3472 color light sensors driver"); 367 + MODULE_LICENSE("GPL");
+258
drivers/iio/light/tsl4531.c
··· 1 + /* 2 + * tsl4531.c - Support for TAOS TSL4531 ambient light sensor 3 + * 4 + * Copyright 2013 Peter Meerwald <pmeerw@pmeerw.net> 5 + * 6 + * This file is subject to the terms and conditions of version 2 of 7 + * the GNU General Public License. See the file COPYING in the main 8 + * directory of this archive for more details. 9 + * 10 + * IIO driver for the TSL4531x family 11 + * TSL45311/TSL45313: 7-bit I2C slave address 0x39 12 + * TSL45315/TSL45317: 7-bit I2C slave address 0x29 13 + * 14 + * TODO: single cycle measurement 15 + */ 16 + 17 + #include <linux/module.h> 18 + #include <linux/i2c.h> 19 + #include <linux/err.h> 20 + #include <linux/delay.h> 21 + 22 + #include <linux/iio/iio.h> 23 + #include <linux/iio/sysfs.h> 24 + 25 + #define TSL4531_DRV_NAME "tsl4531" 26 + 27 + #define TCS3472_COMMAND BIT(7) 28 + 29 + #define TSL4531_CONTROL (TCS3472_COMMAND | 0x00) 30 + #define TSL4531_CONFIG (TCS3472_COMMAND | 0x01) 31 + #define TSL4531_DATA (TCS3472_COMMAND | 0x04) 32 + #define TSL4531_ID (TCS3472_COMMAND | 0x0a) 33 + 34 + /* operating modes in control register */ 35 + #define TSL4531_MODE_POWERDOWN 0x00 36 + #define TSL4531_MODE_SINGLE_ADC 0x02 37 + #define TSL4531_MODE_NORMAL 0x03 38 + 39 + /* integration time control in config register */ 40 + #define TSL4531_TCNTRL_400MS 0x00 41 + #define TSL4531_TCNTRL_200MS 0x01 42 + #define TSL4531_TCNTRL_100MS 0x02 43 + 44 + /* part number in id register */ 45 + #define TSL45311_ID 0x8 46 + #define TSL45313_ID 0x9 47 + #define TSL45315_ID 0xa 48 + #define TSL45317_ID 0xb 49 + #define TSL4531_ID_SHIFT 4 50 + 51 + struct tsl4531_data { 52 + struct i2c_client *client; 53 + struct mutex lock; 54 + int int_time; 55 + }; 56 + 57 + static IIO_CONST_ATTR_INT_TIME_AVAIL("0.1 0.2 0.4"); 58 + 59 + static struct attribute *tsl4531_attributes[] = { 60 + &iio_const_attr_integration_time_available.dev_attr.attr, 61 + NULL 62 + }; 63 + 64 + static const struct attribute_group tsl4531_attribute_group = { 65 + .attrs = tsl4531_attributes, 66 + }; 67 + 68 + static const struct iio_chan_spec tsl4531_channels[] = { 69 + { 70 + .type = IIO_LIGHT, 71 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 72 + BIT(IIO_CHAN_INFO_SCALE) | 73 + BIT(IIO_CHAN_INFO_INT_TIME) 74 + } 75 + }; 76 + 77 + static int tsl4531_read_raw(struct iio_dev *indio_dev, 78 + struct iio_chan_spec const *chan, 79 + int *val, int *val2, long mask) 80 + { 81 + struct tsl4531_data *data = iio_priv(indio_dev); 82 + int ret; 83 + 84 + switch (mask) { 85 + case IIO_CHAN_INFO_RAW: 86 + ret = i2c_smbus_read_word_data(data->client, 87 + TSL4531_DATA); 88 + if (ret < 0) 89 + return ret; 90 + *val = ret; 91 + return IIO_VAL_INT; 92 + case IIO_CHAN_INFO_SCALE: 93 + /* 0.. 1x, 1 .. 2x, 2 .. 4x */ 94 + *val = 1 << data->int_time; 95 + return IIO_VAL_INT; 96 + case IIO_CHAN_INFO_INT_TIME: 97 + if (data->int_time == 0) 98 + *val2 = 400000; 99 + else if (data->int_time == 1) 100 + *val2 = 200000; 101 + else if (data->int_time == 2) 102 + *val2 = 100000; 103 + else 104 + return -EINVAL; 105 + *val = 0; 106 + return IIO_VAL_INT_PLUS_MICRO; 107 + default: 108 + return -EINVAL; 109 + } 110 + } 111 + 112 + static int tsl4531_write_raw(struct iio_dev *indio_dev, 113 + struct iio_chan_spec const *chan, 114 + int val, int val2, long mask) 115 + { 116 + struct tsl4531_data *data = iio_priv(indio_dev); 117 + int int_time, ret; 118 + 119 + switch (mask) { 120 + case IIO_CHAN_INFO_INT_TIME: 121 + if (val != 0) 122 + return -EINVAL; 123 + if (val2 == 400000) 124 + int_time = 0; 125 + else if (val2 == 200000) 126 + int_time = 1; 127 + else if (val2 == 100000) 128 + int_time = 2; 129 + else 130 + return -EINVAL; 131 + mutex_lock(&data->lock); 132 + ret = i2c_smbus_write_byte_data(data->client, 133 + TSL4531_CONFIG, int_time); 134 + if (ret >= 0) 135 + data->int_time = int_time; 136 + mutex_unlock(&data->lock); 137 + return ret; 138 + default: 139 + return -EINVAL; 140 + } 141 + } 142 + 143 + static const struct iio_info tsl4531_info = { 144 + .read_raw = tsl4531_read_raw, 145 + .write_raw = tsl4531_write_raw, 146 + .attrs = &tsl4531_attribute_group, 147 + .driver_module = THIS_MODULE, 148 + }; 149 + 150 + static int tsl4531_check_id(struct i2c_client *client) 151 + { 152 + int ret = i2c_smbus_read_byte_data(client, TSL4531_ID); 153 + if (ret < 0) 154 + return ret; 155 + 156 + switch (ret >> TSL4531_ID_SHIFT) { 157 + case TSL45311_ID: 158 + case TSL45313_ID: 159 + case TSL45315_ID: 160 + case TSL45317_ID: 161 + return 1; 162 + default: 163 + return 0; 164 + } 165 + } 166 + 167 + static int tsl4531_probe(struct i2c_client *client, 168 + const struct i2c_device_id *id) 169 + { 170 + struct tsl4531_data *data; 171 + struct iio_dev *indio_dev; 172 + int ret; 173 + 174 + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 175 + if (!indio_dev) 176 + return -ENOMEM; 177 + 178 + data = iio_priv(indio_dev); 179 + i2c_set_clientdata(client, indio_dev); 180 + data->client = client; 181 + mutex_init(&data->lock); 182 + 183 + if (!tsl4531_check_id(client)) { 184 + dev_err(&client->dev, "no TSL4531 sensor\n"); 185 + return -ENODEV; 186 + } 187 + 188 + ret = i2c_smbus_write_byte_data(data->client, TSL4531_CONTROL, 189 + TSL4531_MODE_NORMAL); 190 + if (ret < 0) 191 + return ret; 192 + 193 + ret = i2c_smbus_write_byte_data(data->client, TSL4531_CONFIG, 194 + TSL4531_TCNTRL_400MS); 195 + if (ret < 0) 196 + return ret; 197 + 198 + indio_dev->dev.parent = &client->dev; 199 + indio_dev->info = &tsl4531_info; 200 + indio_dev->channels = tsl4531_channels; 201 + indio_dev->num_channels = ARRAY_SIZE(tsl4531_channels); 202 + indio_dev->name = TSL4531_DRV_NAME; 203 + indio_dev->modes = INDIO_DIRECT_MODE; 204 + 205 + return iio_device_register(indio_dev); 206 + } 207 + 208 + static int tsl4531_powerdown(struct i2c_client *client) 209 + { 210 + return i2c_smbus_write_byte_data(client, TSL4531_CONTROL, 211 + TSL4531_MODE_POWERDOWN); 212 + } 213 + 214 + static int tsl4531_remove(struct i2c_client *client) 215 + { 216 + iio_device_unregister(i2c_get_clientdata(client)); 217 + tsl4531_powerdown(client); 218 + 219 + return 0; 220 + } 221 + 222 + #ifdef CONFIG_PM_SLEEP 223 + static int tsl4531_suspend(struct device *dev) 224 + { 225 + return tsl4531_powerdown(to_i2c_client(dev)); 226 + } 227 + 228 + static int tsl4531_resume(struct device *dev) 229 + { 230 + return i2c_smbus_write_byte_data(to_i2c_client(dev), TSL4531_CONTROL, 231 + TSL4531_MODE_NORMAL); 232 + } 233 + #endif 234 + 235 + static SIMPLE_DEV_PM_OPS(tsl4531_pm_ops, tsl4531_suspend, tsl4531_resume); 236 + 237 + static const struct i2c_device_id tsl4531_id[] = { 238 + { "tsl4531", 0 }, 239 + { } 240 + }; 241 + MODULE_DEVICE_TABLE(i2c, tsl4531_id); 242 + 243 + static struct i2c_driver tsl4531_driver = { 244 + .driver = { 245 + .name = TSL4531_DRV_NAME, 246 + .pm = &tsl4531_pm_ops, 247 + .owner = THIS_MODULE, 248 + }, 249 + .probe = tsl4531_probe, 250 + .remove = tsl4531_remove, 251 + .id_table = tsl4531_id, 252 + }; 253 + 254 + module_i2c_driver(tsl4531_driver); 255 + 256 + MODULE_AUTHOR("Peter Meerwald <pmeerw@pmeerw.net>"); 257 + MODULE_DESCRIPTION("TAOS TSL4531 ambient light sensors driver"); 258 + MODULE_LICENSE("GPL");
+4 -3
drivers/iio/magnetometer/hid-sensor-magn-3d.c
··· 183 183 }; 184 184 185 185 /* Function to push data to buffer */ 186 - static void hid_sensor_push_data(struct iio_dev *indio_dev, u8 *data, int len) 186 + static void hid_sensor_push_data(struct iio_dev *indio_dev, const void *data, 187 + int len) 187 188 { 188 189 dev_dbg(&indio_dev->dev, "hid_sensor_push_data\n"); 189 - iio_push_to_buffers(indio_dev, (u8 *)data); 190 + iio_push_to_buffers(indio_dev, data); 190 191 } 191 192 192 193 /* Callback handler to send event after all samples are received and captured */ ··· 202 201 magn_state->common_attributes.data_ready); 203 202 if (magn_state->common_attributes.data_ready) 204 203 hid_sensor_push_data(indio_dev, 205 - (u8 *)magn_state->magn_val, 204 + magn_state->magn_val, 206 205 sizeof(magn_state->magn_val)); 207 206 208 207 return 0;
+16 -15
drivers/iio/magnetometer/st_magn_core.c
··· 348 348 int st_magn_common_probe(struct iio_dev *indio_dev, 349 349 struct st_sensors_platform_data *pdata) 350 350 { 351 - int err; 352 351 struct st_sensor_data *mdata = iio_priv(indio_dev); 352 + int irq = mdata->get_irq_data_ready(indio_dev); 353 + int err; 353 354 354 355 indio_dev->modes = INDIO_DIRECT_MODE; 355 356 indio_dev->info = &magn_info; ··· 358 357 err = st_sensors_check_device_support(indio_dev, 359 358 ARRAY_SIZE(st_magn_sensors), st_magn_sensors); 360 359 if (err < 0) 361 - goto st_magn_common_probe_error; 360 + return err; 362 361 363 362 mdata->num_data_channels = ST_MAGN_NUMBER_DATA_CHANNELS; 364 363 mdata->multiread_bit = mdata->sensor->multi_read_bit; ··· 371 370 372 371 err = st_sensors_init_sensor(indio_dev, pdata); 373 372 if (err < 0) 374 - goto st_magn_common_probe_error; 373 + return err; 375 374 376 - if (mdata->get_irq_data_ready(indio_dev) > 0) { 377 - err = st_magn_allocate_ring(indio_dev); 378 - if (err < 0) 379 - goto st_magn_common_probe_error; 375 + err = st_magn_allocate_ring(indio_dev); 376 + if (err < 0) 377 + return err; 378 + 379 + if (irq > 0) { 380 380 err = st_sensors_allocate_trigger(indio_dev, NULL); 381 381 if (err < 0) 382 382 goto st_magn_probe_trigger_error; ··· 387 385 if (err) 388 386 goto st_magn_device_register_error; 389 387 390 - return err; 388 + return 0; 391 389 392 390 st_magn_device_register_error: 393 - if (mdata->get_irq_data_ready(indio_dev) > 0) 391 + if (irq > 0) 394 392 st_sensors_deallocate_trigger(indio_dev); 395 393 st_magn_probe_trigger_error: 396 - if (mdata->get_irq_data_ready(indio_dev) > 0) 397 - st_magn_deallocate_ring(indio_dev); 398 - st_magn_common_probe_error: 394 + st_magn_deallocate_ring(indio_dev); 395 + 399 396 return err; 400 397 } 401 398 EXPORT_SYMBOL(st_magn_common_probe); ··· 404 403 struct st_sensor_data *mdata = iio_priv(indio_dev); 405 404 406 405 iio_device_unregister(indio_dev); 407 - if (mdata->get_irq_data_ready(indio_dev) > 0) { 406 + if (mdata->get_irq_data_ready(indio_dev) > 0) 408 407 st_sensors_deallocate_trigger(indio_dev); 409 - st_magn_deallocate_ring(indio_dev); 410 - } 408 + 409 + st_magn_deallocate_ring(indio_dev); 411 410 } 412 411 EXPORT_SYMBOL(st_magn_common_remove); 413 412
+1
drivers/iio/pressure/st_pressure.h
··· 14 14 #include <linux/types.h> 15 15 #include <linux/iio/common/st_sensors.h> 16 16 17 + #define LPS001WP_PRESS_DEV_NAME "lps001wp" 17 18 #define LPS331AP_PRESS_DEV_NAME "lps331ap" 18 19 19 20 /**
+188 -78
drivers/iio/pressure/st_pressure_core.c
··· 36 36 ST_PRESS_LSB_PER_CELSIUS) 37 37 #define ST_PRESS_NUMBER_DATA_CHANNELS 1 38 38 39 - /* DEFAULT VALUE FOR SENSORS */ 40 - #define ST_PRESS_DEFAULT_OUT_XL_ADDR 0x28 41 - #define ST_TEMP_DEFAULT_OUT_L_ADDR 0x2b 42 - 43 39 /* FULLSCALE */ 44 40 #define ST_PRESS_FS_AVL_1260MB 1260 45 41 46 - /* CUSTOM VALUES FOR SENSOR 1 */ 47 - #define ST_PRESS_1_WAI_EXP 0xbb 48 - #define ST_PRESS_1_ODR_ADDR 0x20 49 - #define ST_PRESS_1_ODR_MASK 0x70 50 - #define ST_PRESS_1_ODR_AVL_1HZ_VAL 0x01 51 - #define ST_PRESS_1_ODR_AVL_7HZ_VAL 0x05 52 - #define ST_PRESS_1_ODR_AVL_13HZ_VAL 0x06 53 - #define ST_PRESS_1_ODR_AVL_25HZ_VAL 0x07 54 - #define ST_PRESS_1_PW_ADDR 0x20 55 - #define ST_PRESS_1_PW_MASK 0x80 56 - #define ST_PRESS_1_FS_ADDR 0x23 57 - #define ST_PRESS_1_FS_MASK 0x30 58 - #define ST_PRESS_1_FS_AVL_1260_VAL 0x00 59 - #define ST_PRESS_1_FS_AVL_1260_GAIN ST_PRESS_KPASCAL_NANO_SCALE 60 - #define ST_PRESS_1_FS_AVL_TEMP_GAIN ST_PRESS_CELSIUS_NANO_SCALE 61 - #define ST_PRESS_1_BDU_ADDR 0x20 62 - #define ST_PRESS_1_BDU_MASK 0x04 63 - #define ST_PRESS_1_DRDY_IRQ_ADDR 0x22 64 - #define ST_PRESS_1_DRDY_IRQ_INT1_MASK 0x04 65 - #define ST_PRESS_1_DRDY_IRQ_INT2_MASK 0x20 66 - #define ST_PRESS_1_MULTIREAD_BIT true 67 - #define ST_PRESS_1_TEMP_OFFSET 42500 42 + /* CUSTOM VALUES FOR LPS331AP SENSOR */ 43 + #define ST_PRESS_LPS331AP_WAI_EXP 0xbb 44 + #define ST_PRESS_LPS331AP_ODR_ADDR 0x20 45 + #define ST_PRESS_LPS331AP_ODR_MASK 0x70 46 + #define ST_PRESS_LPS331AP_ODR_AVL_1HZ_VAL 0x01 47 + #define ST_PRESS_LPS331AP_ODR_AVL_7HZ_VAL 0x05 48 + #define ST_PRESS_LPS331AP_ODR_AVL_13HZ_VAL 0x06 49 + #define ST_PRESS_LPS331AP_ODR_AVL_25HZ_VAL 0x07 50 + #define ST_PRESS_LPS331AP_PW_ADDR 0x20 51 + #define ST_PRESS_LPS331AP_PW_MASK 0x80 52 + #define ST_PRESS_LPS331AP_FS_ADDR 0x23 53 + #define ST_PRESS_LPS331AP_FS_MASK 0x30 54 + #define ST_PRESS_LPS331AP_FS_AVL_1260_VAL 0x00 55 + #define ST_PRESS_LPS331AP_FS_AVL_1260_GAIN ST_PRESS_KPASCAL_NANO_SCALE 56 + #define ST_PRESS_LPS331AP_FS_AVL_TEMP_GAIN ST_PRESS_CELSIUS_NANO_SCALE 57 + #define ST_PRESS_LPS331AP_BDU_ADDR 0x20 58 + #define ST_PRESS_LPS331AP_BDU_MASK 0x04 59 + #define ST_PRESS_LPS331AP_DRDY_IRQ_ADDR 0x22 60 + #define ST_PRESS_LPS331AP_DRDY_IRQ_INT1_MASK 0x04 61 + #define ST_PRESS_LPS331AP_DRDY_IRQ_INT2_MASK 0x20 62 + #define ST_PRESS_LPS331AP_MULTIREAD_BIT true 63 + #define ST_PRESS_LPS331AP_TEMP_OFFSET 42500 64 + #define ST_PRESS_LPS331AP_OUT_XL_ADDR 0x28 65 + #define ST_TEMP_LPS331AP_OUT_L_ADDR 0x2b 68 66 69 - static const struct iio_chan_spec st_press_channels[] = { 70 - ST_SENSORS_LSM_CHANNELS(IIO_PRESSURE, 67 + /* CUSTOM VALUES FOR LPS001WP SENSOR */ 68 + #define ST_PRESS_LPS001WP_WAI_EXP 0xba 69 + #define ST_PRESS_LPS001WP_ODR_ADDR 0x20 70 + #define ST_PRESS_LPS001WP_ODR_MASK 0x30 71 + #define ST_PRESS_LPS001WP_ODR_AVL_1HZ_VAL 0x01 72 + #define ST_PRESS_LPS001WP_ODR_AVL_7HZ_VAL 0x02 73 + #define ST_PRESS_LPS001WP_ODR_AVL_13HZ_VAL 0x03 74 + #define ST_PRESS_LPS001WP_PW_ADDR 0x20 75 + #define ST_PRESS_LPS001WP_PW_MASK 0x40 76 + #define ST_PRESS_LPS001WP_BDU_ADDR 0x20 77 + #define ST_PRESS_LPS001WP_BDU_MASK 0x04 78 + #define ST_PRESS_LPS001WP_MULTIREAD_BIT true 79 + #define ST_PRESS_LPS001WP_OUT_L_ADDR 0x28 80 + #define ST_TEMP_LPS001WP_OUT_L_ADDR 0x2a 81 + 82 + static const struct iio_chan_spec st_press_lps331ap_channels[] = { 83 + { 84 + .type = IIO_PRESSURE, 85 + .channel2 = IIO_NO_MOD, 86 + .address = ST_PRESS_LPS331AP_OUT_XL_ADDR, 87 + .scan_index = ST_SENSORS_SCAN_X, 88 + .scan_type = { 89 + .sign = 'u', 90 + .realbits = 24, 91 + .storagebits = 24, 92 + .endianness = IIO_LE, 93 + }, 94 + .info_mask_separate = 71 95 BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), 72 - ST_SENSORS_SCAN_X, 0, IIO_NO_MOD, 'u', IIO_LE, 24, 24, 73 - ST_PRESS_DEFAULT_OUT_XL_ADDR), 74 - ST_SENSORS_LSM_CHANNELS(IIO_TEMP, 75 - BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE) | 76 - BIT(IIO_CHAN_INFO_OFFSET), 77 - -1, 0, IIO_NO_MOD, 's', IIO_LE, 16, 16, 78 - ST_TEMP_DEFAULT_OUT_L_ADDR), 96 + .modified = 0, 97 + }, 98 + { 99 + .type = IIO_TEMP, 100 + .channel2 = IIO_NO_MOD, 101 + .address = ST_TEMP_LPS331AP_OUT_L_ADDR, 102 + .scan_index = -1, 103 + .scan_type = { 104 + .sign = 'u', 105 + .realbits = 16, 106 + .storagebits = 16, 107 + .endianness = IIO_LE, 108 + }, 109 + .info_mask_separate = 110 + BIT(IIO_CHAN_INFO_RAW) | 111 + BIT(IIO_CHAN_INFO_SCALE) | 112 + BIT(IIO_CHAN_INFO_OFFSET), 113 + .modified = 0, 114 + }, 115 + IIO_CHAN_SOFT_TIMESTAMP(1) 116 + }; 117 + 118 + static const struct iio_chan_spec st_press_lps001wp_channels[] = { 119 + { 120 + .type = IIO_PRESSURE, 121 + .channel2 = IIO_NO_MOD, 122 + .address = ST_PRESS_LPS001WP_OUT_L_ADDR, 123 + .scan_index = ST_SENSORS_SCAN_X, 124 + .scan_type = { 125 + .sign = 'u', 126 + .realbits = 16, 127 + .storagebits = 16, 128 + .endianness = IIO_LE, 129 + }, 130 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 131 + .modified = 0, 132 + }, 133 + { 134 + .type = IIO_TEMP, 135 + .channel2 = IIO_NO_MOD, 136 + .address = ST_TEMP_LPS001WP_OUT_L_ADDR, 137 + .scan_index = -1, 138 + .scan_type = { 139 + .sign = 'u', 140 + .realbits = 16, 141 + .storagebits = 16, 142 + .endianness = IIO_LE, 143 + }, 144 + .info_mask_separate = 145 + BIT(IIO_CHAN_INFO_RAW) | 146 + BIT(IIO_CHAN_INFO_OFFSET), 147 + .modified = 0, 148 + }, 79 149 IIO_CHAN_SOFT_TIMESTAMP(1) 80 150 }; 81 151 82 152 static const struct st_sensors st_press_sensors[] = { 83 153 { 84 - .wai = ST_PRESS_1_WAI_EXP, 154 + .wai = ST_PRESS_LPS331AP_WAI_EXP, 85 155 .sensors_supported = { 86 156 [0] = LPS331AP_PRESS_DEV_NAME, 87 157 }, 88 - .ch = (struct iio_chan_spec *)st_press_channels, 158 + .ch = (struct iio_chan_spec *)st_press_lps331ap_channels, 159 + .num_ch = ARRAY_SIZE(st_press_lps331ap_channels), 89 160 .odr = { 90 - .addr = ST_PRESS_1_ODR_ADDR, 91 - .mask = ST_PRESS_1_ODR_MASK, 161 + .addr = ST_PRESS_LPS331AP_ODR_ADDR, 162 + .mask = ST_PRESS_LPS331AP_ODR_MASK, 92 163 .odr_avl = { 93 - { 1, ST_PRESS_1_ODR_AVL_1HZ_VAL, }, 94 - { 7, ST_PRESS_1_ODR_AVL_7HZ_VAL, }, 95 - { 13, ST_PRESS_1_ODR_AVL_13HZ_VAL, }, 96 - { 25, ST_PRESS_1_ODR_AVL_25HZ_VAL, }, 164 + { 1, ST_PRESS_LPS331AP_ODR_AVL_1HZ_VAL, }, 165 + { 7, ST_PRESS_LPS331AP_ODR_AVL_7HZ_VAL, }, 166 + { 13, ST_PRESS_LPS331AP_ODR_AVL_13HZ_VAL, }, 167 + { 25, ST_PRESS_LPS331AP_ODR_AVL_25HZ_VAL, }, 97 168 }, 98 169 }, 99 170 .pw = { 100 - .addr = ST_PRESS_1_PW_ADDR, 101 - .mask = ST_PRESS_1_PW_MASK, 171 + .addr = ST_PRESS_LPS331AP_PW_ADDR, 172 + .mask = ST_PRESS_LPS331AP_PW_MASK, 102 173 .value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE, 103 174 .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE, 104 175 }, 105 176 .fs = { 106 - .addr = ST_PRESS_1_FS_ADDR, 107 - .mask = ST_PRESS_1_FS_MASK, 177 + .addr = ST_PRESS_LPS331AP_FS_ADDR, 178 + .mask = ST_PRESS_LPS331AP_FS_MASK, 108 179 .fs_avl = { 109 180 [0] = { 110 181 .num = ST_PRESS_FS_AVL_1260MB, 111 - .value = ST_PRESS_1_FS_AVL_1260_VAL, 112 - .gain = ST_PRESS_1_FS_AVL_1260_GAIN, 113 - .gain2 = ST_PRESS_1_FS_AVL_TEMP_GAIN, 182 + .value = ST_PRESS_LPS331AP_FS_AVL_1260_VAL, 183 + .gain = ST_PRESS_LPS331AP_FS_AVL_1260_GAIN, 184 + .gain2 = ST_PRESS_LPS331AP_FS_AVL_TEMP_GAIN, 114 185 }, 115 186 }, 116 187 }, 117 188 .bdu = { 118 - .addr = ST_PRESS_1_BDU_ADDR, 119 - .mask = ST_PRESS_1_BDU_MASK, 189 + .addr = ST_PRESS_LPS331AP_BDU_ADDR, 190 + .mask = ST_PRESS_LPS331AP_BDU_MASK, 120 191 }, 121 192 .drdy_irq = { 122 - .addr = ST_PRESS_1_DRDY_IRQ_ADDR, 123 - .mask_int1 = ST_PRESS_1_DRDY_IRQ_INT1_MASK, 124 - .mask_int2 = ST_PRESS_1_DRDY_IRQ_INT2_MASK, 193 + .addr = ST_PRESS_LPS331AP_DRDY_IRQ_ADDR, 194 + .mask_int1 = ST_PRESS_LPS331AP_DRDY_IRQ_INT1_MASK, 195 + .mask_int2 = ST_PRESS_LPS331AP_DRDY_IRQ_INT2_MASK, 125 196 }, 126 - .multi_read_bit = ST_PRESS_1_MULTIREAD_BIT, 197 + .multi_read_bit = ST_PRESS_LPS331AP_MULTIREAD_BIT, 198 + .bootime = 2, 199 + }, 200 + { 201 + .wai = ST_PRESS_LPS001WP_WAI_EXP, 202 + .sensors_supported = { 203 + [0] = LPS001WP_PRESS_DEV_NAME, 204 + }, 205 + .ch = (struct iio_chan_spec *)st_press_lps001wp_channels, 206 + .num_ch = ARRAY_SIZE(st_press_lps001wp_channels), 207 + .odr = { 208 + .addr = ST_PRESS_LPS001WP_ODR_ADDR, 209 + .mask = ST_PRESS_LPS001WP_ODR_MASK, 210 + .odr_avl = { 211 + { 1, ST_PRESS_LPS001WP_ODR_AVL_1HZ_VAL, }, 212 + { 7, ST_PRESS_LPS001WP_ODR_AVL_7HZ_VAL, }, 213 + { 13, ST_PRESS_LPS001WP_ODR_AVL_13HZ_VAL, }, 214 + }, 215 + }, 216 + .pw = { 217 + .addr = ST_PRESS_LPS001WP_PW_ADDR, 218 + .mask = ST_PRESS_LPS001WP_PW_MASK, 219 + .value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE, 220 + .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE, 221 + }, 222 + .fs = { 223 + .addr = 0, 224 + }, 225 + .bdu = { 226 + .addr = ST_PRESS_LPS001WP_BDU_ADDR, 227 + .mask = ST_PRESS_LPS001WP_BDU_MASK, 228 + }, 229 + .drdy_irq = { 230 + .addr = 0, 231 + }, 232 + .multi_read_bit = ST_PRESS_LPS001WP_MULTIREAD_BIT, 127 233 .bootime = 2, 128 234 }, 129 235 }; ··· 316 210 int st_press_common_probe(struct iio_dev *indio_dev, 317 211 struct st_sensors_platform_data *plat_data) 318 212 { 319 - int err; 320 213 struct st_sensor_data *pdata = iio_priv(indio_dev); 214 + int irq = pdata->get_irq_data_ready(indio_dev); 215 + int err; 321 216 322 217 indio_dev->modes = INDIO_DIRECT_MODE; 323 218 indio_dev->info = &press_info; 324 219 325 220 err = st_sensors_check_device_support(indio_dev, 326 - ARRAY_SIZE(st_press_sensors), st_press_sensors); 221 + ARRAY_SIZE(st_press_sensors), 222 + st_press_sensors); 327 223 if (err < 0) 328 - goto st_press_common_probe_error; 224 + return err; 329 225 330 226 pdata->num_data_channels = ST_PRESS_NUMBER_DATA_CHANNELS; 331 - pdata->multiread_bit = pdata->sensor->multi_read_bit; 332 - indio_dev->channels = pdata->sensor->ch; 333 - indio_dev->num_channels = ARRAY_SIZE(st_press_channels); 227 + pdata->multiread_bit = pdata->sensor->multi_read_bit; 228 + indio_dev->channels = pdata->sensor->ch; 229 + indio_dev->num_channels = pdata->sensor->num_ch; 334 230 335 - pdata->current_fullscale = (struct st_sensor_fullscale_avl *) 336 - &pdata->sensor->fs.fs_avl[0]; 231 + if (pdata->sensor->fs.addr != 0) 232 + pdata->current_fullscale = (struct st_sensor_fullscale_avl *) 233 + &pdata->sensor->fs.fs_avl[0]; 234 + 337 235 pdata->odr = pdata->sensor->odr.odr_avl[0].hz; 338 236 339 - if (!plat_data) 237 + /* Some devices don't support a data ready pin. */ 238 + if (!plat_data && pdata->sensor->drdy_irq.addr) 340 239 plat_data = 341 240 (struct st_sensors_platform_data *)&default_press_pdata; 342 241 343 242 err = st_sensors_init_sensor(indio_dev, plat_data); 344 243 if (err < 0) 345 - goto st_press_common_probe_error; 244 + return err; 346 245 347 - if (pdata->get_irq_data_ready(indio_dev) > 0) { 348 - err = st_press_allocate_ring(indio_dev); 349 - if (err < 0) 350 - goto st_press_common_probe_error; 246 + err = st_press_allocate_ring(indio_dev); 247 + if (err < 0) 248 + return err; 351 249 250 + if (irq > 0) { 352 251 err = st_sensors_allocate_trigger(indio_dev, 353 - ST_PRESS_TRIGGER_OPS); 252 + ST_PRESS_TRIGGER_OPS); 354 253 if (err < 0) 355 254 goto st_press_probe_trigger_error; 356 255 } ··· 367 256 return err; 368 257 369 258 st_press_device_register_error: 370 - if (pdata->get_irq_data_ready(indio_dev) > 0) 259 + if (irq > 0) 371 260 st_sensors_deallocate_trigger(indio_dev); 372 261 st_press_probe_trigger_error: 373 - if (pdata->get_irq_data_ready(indio_dev) > 0) 374 - st_press_deallocate_ring(indio_dev); 375 - st_press_common_probe_error: 262 + st_press_deallocate_ring(indio_dev); 263 + 376 264 return err; 377 265 } 378 266 EXPORT_SYMBOL(st_press_common_probe); ··· 381 271 struct st_sensor_data *pdata = iio_priv(indio_dev); 382 272 383 273 iio_device_unregister(indio_dev); 384 - if (pdata->get_irq_data_ready(indio_dev) > 0) { 274 + if (pdata->get_irq_data_ready(indio_dev) > 0) 385 275 st_sensors_deallocate_trigger(indio_dev); 386 - st_press_deallocate_ring(indio_dev); 387 - } 276 + 277 + st_press_deallocate_ring(indio_dev); 388 278 } 389 279 EXPORT_SYMBOL(st_press_common_remove); 390 280
+1
drivers/iio/pressure/st_pressure_i2c.c
··· 49 49 } 50 50 51 51 static const struct i2c_device_id st_press_id_table[] = { 52 + { LPS001WP_PRESS_DEV_NAME }, 52 53 { LPS331AP_PRESS_DEV_NAME }, 53 54 {}, 54 55 };
+28 -31
drivers/iio/temperature/tmp006.c
··· 70 70 return i2c_smbus_read_word_swapped(data->client, reg); 71 71 } 72 72 73 + static const int tmp006_freqs[5][2] = { {4, 0}, {2, 0}, {1, 0}, 74 + {0, 500000}, {0, 250000} }; 75 + 73 76 static int tmp006_read_raw(struct iio_dev *indio_dev, 74 77 struct iio_chan_spec const *channel, int *val, 75 78 int *val2, long mask) 76 79 { 77 80 struct tmp006_data *data = iio_priv(indio_dev); 78 81 s32 ret; 82 + int cr; 79 83 80 84 switch (mask) { 81 85 case IIO_CHAN_INFO_RAW: ··· 110 106 break; 111 107 } 112 108 return IIO_VAL_INT_PLUS_MICRO; 109 + case IIO_CHAN_INFO_SAMP_FREQ: 110 + cr = (data->config & TMP006_CONFIG_CR_MASK) 111 + >> TMP006_CONFIG_CR_SHIFT; 112 + *val = tmp006_freqs[cr][0]; 113 + *val2 = tmp006_freqs[cr][1]; 114 + return IIO_VAL_INT_PLUS_MICRO; 113 115 default: 114 116 break; 115 117 } ··· 123 113 return -EINVAL; 124 114 } 125 115 126 - static const char * const tmp006_freqs[] = { "4", "2", "1", "0.5", "0.25" }; 127 - 128 - static ssize_t tmp006_show_freq(struct device *dev, 129 - struct device_attribute *attr, char *buf) 116 + static int tmp006_write_raw(struct iio_dev *indio_dev, 117 + struct iio_chan_spec const *chan, 118 + int val, 119 + int val2, 120 + long mask) 130 121 { 131 - struct tmp006_data *data = iio_priv(dev_to_iio_dev(dev)); 132 - int cr = (data->config & TMP006_CONFIG_CR_MASK) 133 - >> TMP006_CONFIG_CR_SHIFT; 134 - return sprintf(buf, "%s\n", tmp006_freqs[cr]); 135 - } 136 - 137 - static ssize_t tmp006_store_freq(struct device *dev, 138 - struct device_attribute *attr, 139 - const char *buf, size_t len) 140 - { 141 - struct iio_dev *indio_dev = dev_to_iio_dev(dev); 142 122 struct tmp006_data *data = iio_priv(indio_dev); 143 123 int i; 144 - bool found = false; 145 124 146 125 for (i = 0; i < ARRAY_SIZE(tmp006_freqs); i++) 147 - if (sysfs_streq(buf, tmp006_freqs[i])) { 148 - found = true; 149 - break; 126 + if ((val == tmp006_freqs[i][0]) && 127 + (val2 == tmp006_freqs[i][1])) { 128 + data->config &= ~TMP006_CONFIG_CR_MASK; 129 + data->config |= i << TMP006_CONFIG_CR_SHIFT; 130 + 131 + return i2c_smbus_write_word_swapped(data->client, 132 + TMP006_CONFIG, 133 + data->config); 134 + 150 135 } 151 - if (!found) 152 - return -EINVAL; 153 - 154 - data->config &= ~TMP006_CONFIG_CR_MASK; 155 - data->config |= i << TMP006_CONFIG_CR_SHIFT; 156 - 157 - return i2c_smbus_write_word_swapped(data->client, TMP006_CONFIG, 158 - data->config); 136 + return -EINVAL; 159 137 } 160 - 161 - static IIO_DEV_ATTR_SAMP_FREQ(S_IRUGO | S_IWUSR, 162 - tmp006_show_freq, tmp006_store_freq); 163 138 164 139 static IIO_CONST_ATTR(sampling_frequency_available, "4 2 1 0.5 0.25"); 165 140 166 141 static struct attribute *tmp006_attributes[] = { 167 - &iio_dev_attr_sampling_frequency.dev_attr.attr, 168 142 &iio_const_attr_sampling_frequency_available.dev_attr.attr, 169 143 NULL 170 144 }; ··· 162 168 .type = IIO_VOLTAGE, 163 169 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 164 170 BIT(IIO_CHAN_INFO_SCALE), 171 + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), 165 172 }, 166 173 { 167 174 .type = IIO_TEMP, 168 175 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 169 176 BIT(IIO_CHAN_INFO_SCALE), 177 + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), 170 178 } 171 179 }; 172 180 173 181 static const struct iio_info tmp006_info = { 174 182 .read_raw = tmp006_read_raw, 183 + .write_raw = tmp006_write_raw, 175 184 .attrs = &tmp006_attribute_group, 176 185 .driver_module = THIS_MODULE, 177 186 };
+9 -3
drivers/input/touchscreen/ti_am335x_tsc.c
··· 52 52 u32 config_inp[4]; 53 53 u32 bit_xp, bit_xn, bit_yp, bit_yn; 54 54 u32 inp_xp, inp_xn, inp_yp, inp_yn; 55 + u32 step_mask; 55 56 }; 56 57 57 58 static unsigned int titsc_readl(struct titsc *ts, unsigned int reg) ··· 197 196 198 197 /* The steps1 … end and bit 0 for TS_Charge */ 199 198 stepenable = (1 << (end_step + 2)) - 1; 200 - am335x_tsc_se_set(ts_dev->mfd_tscadc, stepenable); 199 + ts_dev->step_mask = stepenable; 200 + am335x_tsc_se_set(ts_dev->mfd_tscadc, ts_dev->step_mask); 201 201 } 202 202 203 203 static void titsc_read_coordinates(struct titsc *ts_dev, ··· 262 260 unsigned int fsm; 263 261 264 262 status = titsc_readl(ts_dev, REG_IRQSTATUS); 263 + /* 264 + * ADC and touchscreen share the IRQ line. 265 + * FIFO1 interrupts are used by ADC. Handle FIFO0 IRQs here only 266 + */ 265 267 if (status & IRQENB_FIFO0THRES) { 266 268 267 269 titsc_read_coordinates(ts_dev, &x, &y, &z1, &z2); ··· 322 316 323 317 if (irqclr) { 324 318 titsc_writel(ts_dev, REG_IRQSTATUS, irqclr); 325 - am335x_tsc_se_update(ts_dev->mfd_tscadc); 319 + am335x_tsc_se_set(ts_dev->mfd_tscadc, ts_dev->step_mask); 326 320 return IRQ_HANDLED; 327 321 } 328 322 return IRQ_NONE; ··· 395 389 } 396 390 397 391 err = request_irq(ts_dev->irq, titsc_irq, 398 - 0, pdev->dev.driver->name, ts_dev); 392 + IRQF_SHARED, pdev->dev.driver->name, ts_dev); 399 393 if (err) { 400 394 dev_err(&pdev->dev, "failed to allocate irq.\n"); 401 395 goto err_free_mem;
+1 -5
drivers/staging/iio/accel/lis3l02dq_ring.c
··· 146 146 if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength)) 147 147 len = lis3l02dq_get_buffer_element(indio_dev, data); 148 148 149 - /* Guaranteed to be aligned with 8 byte boundary */ 150 - if (indio_dev->scan_timestamp) 151 - *(s64 *)((u8 *)data + ALIGN(len, sizeof(s64))) 152 - = pf->timestamp; 153 - iio_push_to_buffers(indio_dev, (u8 *)data); 149 + iio_push_to_buffers_with_timestamp(indio_dev, data, pf->timestamp); 154 150 155 151 kfree(data); 156 152 done:
+4 -4
drivers/staging/iio/accel/sca3000_core.c
··· 624 624 struct sca3000_state *st = iio_priv(indio_dev); 625 625 int ret, base_freq = 0; 626 626 int ctrlval; 627 - long val; 627 + int val; 628 628 629 - ret = strict_strtol(buf, 10, &val); 629 + ret = kstrtoint(buf, 10, &val); 630 630 if (ret) 631 631 return ret; 632 632 ··· 931 931 { 932 932 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 933 933 struct sca3000_state *st = iio_priv(indio_dev); 934 - long val; 934 + u8 val; 935 935 int ret; 936 936 u8 protect_mask = SCA3000_FREE_FALL_DETECT; 937 937 938 938 mutex_lock(&st->lock); 939 - ret = strict_strtol(buf, 10, &val); 939 + ret = kstrtou8(buf, 10, &val); 940 940 if (ret) 941 941 goto error_ret; 942 942
+2 -2
drivers/staging/iio/accel/sca3000_ring.c
··· 177 177 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 178 178 struct sca3000_state *st = iio_priv(indio_dev); 179 179 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 180 - long val; 180 + u8 val; 181 181 int ret; 182 182 183 183 mutex_lock(&st->lock); 184 - ret = strict_strtol(buf, 10, &val); 184 + ret = kstrtou8(buf, 10, &val); 185 185 if (ret) 186 186 goto error_ret; 187 187 ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_INT_MASK, 1);
+4 -11
drivers/staging/iio/adc/ad7192.c
··· 623 623 return -ENODEV; 624 624 } 625 625 626 - indio_dev = iio_device_alloc(sizeof(*st)); 626 + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 627 627 if (indio_dev == NULL) 628 628 return -ENOMEM; 629 629 630 630 st = iio_priv(indio_dev); 631 631 632 - st->reg = regulator_get(&spi->dev, "vcc"); 632 + st->reg = devm_regulator_get(&spi->dev, "vcc"); 633 633 if (!IS_ERR(st->reg)) { 634 634 ret = regulator_enable(st->reg); 635 635 if (ret) 636 - goto error_put_reg; 636 + return ret; 637 637 638 638 voltage_uv = regulator_get_voltage(st->reg); 639 639 } ··· 677 677 error_disable_reg: 678 678 if (!IS_ERR(st->reg)) 679 679 regulator_disable(st->reg); 680 - error_put_reg: 681 - if (!IS_ERR(st->reg)) 682 - regulator_put(st->reg); 683 - 684 - iio_device_free(indio_dev); 685 680 686 681 return ret; 687 682 } ··· 689 694 iio_device_unregister(indio_dev); 690 695 ad_sd_cleanup_buffer_and_trigger(indio_dev); 691 696 692 - if (!IS_ERR(st->reg)) { 697 + if (!IS_ERR(st->reg)) 693 698 regulator_disable(st->reg); 694 - regulator_put(st->reg); 695 - } 696 699 697 700 return 0; 698 701 }
+4 -7
drivers/staging/iio/adc/ad7280a.c
··· 835 835 int ret; 836 836 const unsigned short tACQ_ns[4] = {465, 1010, 1460, 1890}; 837 837 const unsigned short nAVG[4] = {1, 2, 4, 8}; 838 - struct iio_dev *indio_dev = iio_device_alloc(sizeof(*st)); 838 + struct iio_dev *indio_dev; 839 839 840 + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 840 841 if (indio_dev == NULL) 841 842 return -ENOMEM; 842 843 ··· 861 860 862 861 ret = ad7280_chain_setup(st); 863 862 if (ret < 0) 864 - goto error_free_device; 863 + return ret; 865 864 866 865 st->slave_num = ret; 867 866 st->scan_cnt = (st->slave_num + 1) * AD7280A_NUM_CH; ··· 892 891 893 892 ret = ad7280_channel_init(st); 894 893 if (ret < 0) 895 - goto error_free_device; 894 + return ret; 896 895 897 896 indio_dev->num_channels = ret; 898 897 indio_dev->channels = st->channels; ··· 941 940 error_free_channels: 942 941 kfree(st->channels); 943 942 944 - error_free_device: 945 - iio_device_free(indio_dev); 946 - 947 943 return ret; 948 944 } 949 945 ··· 958 960 959 961 kfree(st->channels); 960 962 kfree(st->iio_attr); 961 - iio_device_free(indio_dev); 962 963 963 964 return 0; 964 965 }
+8 -19
drivers/staging/iio/adc/ad7291.c
··· 528 528 struct iio_dev *indio_dev; 529 529 int ret = 0; 530 530 531 - indio_dev = iio_device_alloc(sizeof(*chip)); 532 - if (indio_dev == NULL) { 533 - ret = -ENOMEM; 534 - goto error_ret; 535 - } 531 + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip)); 532 + if (!indio_dev) 533 + return -ENOMEM; 536 534 chip = iio_priv(indio_dev); 537 535 538 536 if (pdata && pdata->use_external_ref) { 539 - chip->reg = regulator_get(&client->dev, "vref"); 537 + chip->reg = devm_regulator_get(&client->dev, "vref"); 540 538 if (IS_ERR(chip->reg)) 541 - goto error_free; 539 + return ret; 542 540 543 541 ret = regulator_enable(chip->reg); 544 542 if (ret) 545 - goto error_put_reg; 543 + return ret; 546 544 } 547 545 548 546 mutex_init(&chip->state_lock); ··· 599 601 error_disable_reg: 600 602 if (chip->reg) 601 603 regulator_disable(chip->reg); 602 - error_put_reg: 603 - if (chip->reg) 604 - regulator_put(chip->reg); 605 - error_free: 606 - iio_device_free(indio_dev); 607 - error_ret: 604 + 608 605 return ret; 609 606 } 610 607 ··· 613 620 if (client->irq) 614 621 free_irq(client->irq, indio_dev); 615 622 616 - if (chip->reg) { 623 + if (chip->reg) 617 624 regulator_disable(chip->reg); 618 - regulator_put(chip->reg); 619 - } 620 - 621 - iio_device_free(indio_dev); 622 625 623 626 return 0; 624 627 }
+8 -18
drivers/staging/iio/adc/ad7606_core.c
··· 425 425 struct ad7606_state *st = iio_priv(indio_dev); 426 426 427 427 if (iio_buffer_enabled(indio_dev)) { 428 - if (!work_pending(&st->poll_work)) 429 - schedule_work(&st->poll_work); 428 + schedule_work(&st->poll_work); 430 429 } else { 431 430 st->done = true; 432 431 wake_up_interruptible(&st->wq_data_avail); ··· 465 466 struct ad7606_platform_data *pdata = dev->platform_data; 466 467 struct ad7606_state *st; 467 468 int ret; 468 - struct iio_dev *indio_dev = iio_device_alloc(sizeof(*st)); 469 + struct iio_dev *indio_dev; 469 470 470 - if (indio_dev == NULL) { 471 - ret = -ENOMEM; 472 - goto error_ret; 473 - } 471 + indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); 472 + if (!indio_dev) 473 + return ERR_PTR(-ENOMEM); 474 474 475 475 st = iio_priv(indio_dev); 476 476 ··· 487 489 st->oversampling = pdata->default_os; 488 490 } 489 491 490 - st->reg = regulator_get(dev, "vcc"); 492 + st->reg = devm_regulator_get(dev, "vcc"); 491 493 if (!IS_ERR(st->reg)) { 492 494 ret = regulator_enable(st->reg); 493 495 if (ret) 494 - goto error_put_reg; 496 + return ERR_PTR(ret); 495 497 } 496 498 497 499 st->pdata = pdata; ··· 552 554 error_disable_reg: 553 555 if (!IS_ERR(st->reg)) 554 556 regulator_disable(st->reg); 555 - error_put_reg: 556 - if (!IS_ERR(st->reg)) 557 - regulator_put(st->reg); 558 - iio_device_free(indio_dev); 559 - error_ret: 560 557 return ERR_PTR(ret); 561 558 } 562 559 ··· 563 570 ad7606_ring_cleanup(indio_dev); 564 571 565 572 free_irq(irq, indio_dev); 566 - if (!IS_ERR(st->reg)) { 573 + if (!IS_ERR(st->reg)) 567 574 regulator_disable(st->reg); 568 - regulator_put(st->reg); 569 - } 570 575 571 576 ad7606_free_gpios(st); 572 - iio_device_free(indio_dev); 573 577 574 578 return 0; 575 579 }
+1 -7
drivers/staging/iio/adc/ad7606_ring.c
··· 46 46 struct ad7606_state *st = container_of(work_s, struct ad7606_state, 47 47 poll_work); 48 48 struct iio_dev *indio_dev = iio_priv_to_dev(st); 49 - s64 time_ns; 50 49 __u8 *buf; 51 50 int ret; 52 51 ··· 77 78 goto done; 78 79 } 79 80 80 - time_ns = iio_get_time_ns(); 81 - 82 - if (indio_dev->scan_timestamp) 83 - *((s64 *)(buf + indio_dev->scan_bytes - sizeof(s64))) = time_ns; 84 - 85 - iio_push_to_buffers(indio_dev, buf); 81 + iio_push_to_buffers_with_timestamp(indio_dev, buf, iio_get_time_ns()); 86 82 done: 87 83 gpio_set_value(st->pdata->gpio_convst, 0); 88 84 iio_trigger_notify_done(indio_dev->trig);
+7 -21
drivers/staging/iio/adc/ad7780.c
··· 171 171 struct iio_dev *indio_dev; 172 172 int ret, voltage_uv = 0; 173 173 174 - indio_dev = iio_device_alloc(sizeof(*st)); 174 + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 175 175 if (indio_dev == NULL) 176 176 return -ENOMEM; 177 177 ··· 180 180 181 181 ad_sd_init(&st->sd, indio_dev, spi, &ad7780_sigma_delta_info); 182 182 183 - st->reg = regulator_get(&spi->dev, "vcc"); 183 + st->reg = devm_regulator_get(&spi->dev, "vcc"); 184 184 if (!IS_ERR(st->reg)) { 185 185 ret = regulator_enable(st->reg); 186 186 if (ret) 187 - goto error_put_reg; 187 + return ret; 188 188 189 189 voltage_uv = regulator_get_voltage(st->reg); 190 190 } ··· 210 210 211 211 if (pdata && gpio_is_valid(pdata->gpio_pdrst)) { 212 212 213 - ret = gpio_request_one(pdata->gpio_pdrst, GPIOF_OUT_INIT_LOW, 214 - "AD7780 /PDRST"); 213 + ret = devm_gpio_request_one(&spi->dev, pdata->gpio_pdrst, 214 + GPIOF_OUT_INIT_LOW, "AD7780 /PDRST"); 215 215 if (ret) { 216 216 dev_err(&spi->dev, "failed to request GPIO PDRST\n"); 217 217 goto error_disable_reg; ··· 223 223 224 224 ret = ad_sd_setup_buffer_and_trigger(indio_dev); 225 225 if (ret) 226 - goto error_free_gpio; 226 + goto error_disable_reg; 227 227 228 228 ret = iio_device_register(indio_dev); 229 229 if (ret) ··· 233 233 234 234 error_cleanup_buffer_and_trigger: 235 235 ad_sd_cleanup_buffer_and_trigger(indio_dev); 236 - error_free_gpio: 237 - if (pdata && gpio_is_valid(pdata->gpio_pdrst)) 238 - gpio_free(pdata->gpio_pdrst); 239 236 error_disable_reg: 240 237 if (!IS_ERR(st->reg)) 241 238 regulator_disable(st->reg); 242 - error_put_reg: 243 - if (!IS_ERR(st->reg)) 244 - regulator_put(st->reg); 245 - 246 - iio_device_free(indio_dev); 247 239 248 240 return ret; 249 241 } ··· 248 256 iio_device_unregister(indio_dev); 249 257 ad_sd_cleanup_buffer_and_trigger(indio_dev); 250 258 251 - if (gpio_is_valid(st->powerdown_gpio)) 252 - gpio_free(st->powerdown_gpio); 253 - 254 - if (!IS_ERR(st->reg)) { 259 + if (!IS_ERR(st->reg)) 255 260 regulator_disable(st->reg); 256 - regulator_put(st->reg); 257 - } 258 - iio_device_free(indio_dev); 259 261 260 262 return 0; 261 263 }
+20 -39
drivers/staging/iio/adc/ad7816.c
··· 356 356 return -EINVAL; 357 357 } 358 358 359 - indio_dev = iio_device_alloc(sizeof(*chip)); 360 - if (indio_dev == NULL) { 361 - ret = -ENOMEM; 362 - goto error_ret; 363 - } 359 + indio_dev = devm_iio_device_alloc(&spi_dev->dev, sizeof(*chip)); 360 + if (!indio_dev) 361 + return -ENOMEM; 364 362 chip = iio_priv(indio_dev); 365 363 /* this is only used for device removal purposes */ 366 364 dev_set_drvdata(&spi_dev->dev, indio_dev); ··· 370 372 chip->convert_pin = pins[1]; 371 373 chip->busy_pin = pins[2]; 372 374 373 - ret = gpio_request(chip->rdwr_pin, spi_get_device_id(spi_dev)->name); 375 + ret = devm_gpio_request(&spi_dev->dev, chip->rdwr_pin, 376 + spi_get_device_id(spi_dev)->name); 374 377 if (ret) { 375 378 dev_err(&spi_dev->dev, "Fail to request rdwr gpio PIN %d.\n", 376 379 chip->rdwr_pin); 377 - goto error_free_device; 380 + return ret; 378 381 } 379 382 gpio_direction_input(chip->rdwr_pin); 380 - ret = gpio_request(chip->convert_pin, spi_get_device_id(spi_dev)->name); 383 + ret = devm_gpio_request(&spi_dev->dev, chip->convert_pin, 384 + spi_get_device_id(spi_dev)->name); 381 385 if (ret) { 382 386 dev_err(&spi_dev->dev, "Fail to request convert gpio PIN %d.\n", 383 387 chip->convert_pin); 384 - goto error_free_gpio_rdwr; 388 + return ret; 385 389 } 386 390 gpio_direction_input(chip->convert_pin); 387 - ret = gpio_request(chip->busy_pin, spi_get_device_id(spi_dev)->name); 391 + ret = devm_gpio_request(&spi_dev->dev, chip->busy_pin, 392 + spi_get_device_id(spi_dev)->name); 388 393 if (ret) { 389 394 dev_err(&spi_dev->dev, "Fail to request busy gpio PIN %d.\n", 390 395 chip->busy_pin); 391 - goto error_free_gpio_convert; 396 + return ret; 392 397 } 393 398 gpio_direction_input(chip->busy_pin); 394 399 ··· 402 401 403 402 if (spi_dev->irq) { 404 403 /* Only low trigger is supported in ad7816/7/8 */ 405 - ret = request_threaded_irq(spi_dev->irq, 406 - NULL, 407 - &ad7816_event_handler, 408 - IRQF_TRIGGER_LOW | IRQF_ONESHOT, 409 - indio_dev->name, 410 - indio_dev); 404 + ret = devm_request_threaded_irq(&spi_dev->dev, spi_dev->irq, 405 + NULL, 406 + &ad7816_event_handler, 407 + IRQF_TRIGGER_LOW | IRQF_ONESHOT, 408 + indio_dev->name, 409 + indio_dev); 411 410 if (ret) 412 - goto error_free_gpio; 411 + return ret; 413 412 } 414 413 415 414 ret = iio_device_register(indio_dev); 416 415 if (ret) 417 - goto error_free_irq; 416 + return ret; 418 417 419 418 dev_info(&spi_dev->dev, "%s temperature sensor and ADC registered.\n", 420 419 indio_dev->name); 421 420 422 421 return 0; 423 - error_free_irq: 424 - free_irq(spi_dev->irq, indio_dev); 425 - error_free_gpio: 426 - gpio_free(chip->busy_pin); 427 - error_free_gpio_convert: 428 - gpio_free(chip->convert_pin); 429 - error_free_gpio_rdwr: 430 - gpio_free(chip->rdwr_pin); 431 - error_free_device: 432 - iio_device_free(indio_dev); 433 - error_ret: 434 - return ret; 435 422 } 436 423 437 424 static int ad7816_remove(struct spi_device *spi_dev) 438 425 { 439 426 struct iio_dev *indio_dev = dev_get_drvdata(&spi_dev->dev); 440 - struct ad7816_chip_info *chip = iio_priv(indio_dev); 441 427 442 428 iio_device_unregister(indio_dev); 443 - dev_set_drvdata(&spi_dev->dev, NULL); 444 - if (spi_dev->irq) 445 - free_irq(spi_dev->irq, indio_dev); 446 - gpio_free(chip->busy_pin); 447 - gpio_free(chip->convert_pin); 448 - gpio_free(chip->rdwr_pin); 449 - iio_device_free(indio_dev); 450 429 451 430 return 0; 452 431 }
+5 -11
drivers/staging/iio/adc/ad799x_core.c
··· 586 586 int ret; 587 587 struct ad799x_platform_data *pdata = client->dev.platform_data; 588 588 struct ad799x_state *st; 589 - struct iio_dev *indio_dev = iio_device_alloc(sizeof(*st)); 589 + struct iio_dev *indio_dev; 590 590 591 + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*st)); 591 592 if (indio_dev == NULL) 592 593 return -ENOMEM; 593 594 ··· 607 606 608 607 st->int_vref_mv = pdata->vref_mv; 609 608 610 - st->reg = regulator_get(&client->dev, "vcc"); 609 + st->reg = devm_regulator_get(&client->dev, "vcc"); 611 610 if (!IS_ERR(st->reg)) { 612 611 ret = regulator_enable(st->reg); 613 612 if (ret) 614 - goto error_put_reg; 613 + return ret; 615 614 } 616 615 st->client = client; 617 616 ··· 651 650 error_disable_reg: 652 651 if (!IS_ERR(st->reg)) 653 652 regulator_disable(st->reg); 654 - error_put_reg: 655 - if (!IS_ERR(st->reg)) 656 - regulator_put(st->reg); 657 - iio_device_free(indio_dev); 658 653 659 654 return ret; 660 655 } ··· 665 668 free_irq(client->irq, indio_dev); 666 669 667 670 ad799x_ring_cleanup(indio_dev); 668 - if (!IS_ERR(st->reg)) { 671 + if (!IS_ERR(st->reg)) 669 672 regulator_disable(st->reg); 670 - regulator_put(st->reg); 671 - } 672 673 kfree(st->rx_buf); 673 - iio_device_free(indio_dev); 674 674 675 675 return 0; 676 676 }
+2 -8
drivers/staging/iio/adc/ad799x_ring.c
··· 35 35 struct iio_poll_func *pf = p; 36 36 struct iio_dev *indio_dev = pf->indio_dev; 37 37 struct ad799x_state *st = iio_priv(indio_dev); 38 - s64 time_ns; 39 38 int b_sent; 40 39 u8 cmd; 41 40 ··· 64 65 if (b_sent < 0) 65 66 goto out; 66 67 67 - time_ns = iio_get_time_ns(); 68 - 69 - if (indio_dev->scan_timestamp) 70 - memcpy(st->rx_buf + indio_dev->scan_bytes - sizeof(s64), 71 - &time_ns, sizeof(time_ns)); 72 - 73 - iio_push_to_buffers(indio_dev, st->rx_buf); 68 + iio_push_to_buffers_with_timestamp(indio_dev, st->rx_buf, 69 + iio_get_time_ns()); 74 70 out: 75 71 iio_trigger_notify_done(indio_dev->trig); 76 72
+14 -35
drivers/staging/iio/adc/lpc32xx_adc.c
··· 137 137 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 138 138 if (!res) { 139 139 dev_err(&pdev->dev, "failed to get platform I/O memory\n"); 140 - retval = -EBUSY; 141 - goto errout1; 140 + return -EBUSY; 142 141 } 143 142 144 - iodev = iio_device_alloc(sizeof(struct lpc32xx_adc_info)); 145 - if (!iodev) { 146 - dev_err(&pdev->dev, "failed allocating iio device\n"); 147 - retval = -ENOMEM; 148 - goto errout1; 149 - } 143 + iodev = devm_iio_device_alloc(&pdev->dev, sizeof(*info)); 144 + if (!iodev) 145 + return -ENOMEM; 150 146 151 147 info = iio_priv(iodev); 152 148 153 - info->adc_base = ioremap(res->start, resource_size(res)); 149 + info->adc_base = devm_ioremap(&pdev->dev, res->start, 150 + resource_size(res)); 154 151 if (!info->adc_base) { 155 152 dev_err(&pdev->dev, "failed mapping memory\n"); 156 - retval = -EBUSY; 157 - goto errout2; 153 + return -EBUSY; 158 154 } 159 155 160 - info->clk = clk_get(&pdev->dev, NULL); 156 + info->clk = devm_clk_get(&pdev->dev, NULL); 161 157 if (IS_ERR(info->clk)) { 162 158 dev_err(&pdev->dev, "failed getting clock\n"); 163 - goto errout3; 159 + return PTR_ERR(info->clk); 164 160 } 165 161 166 162 irq = platform_get_irq(pdev, 0); 167 163 if ((irq < 0) || (irq >= NR_IRQS)) { 168 164 dev_err(&pdev->dev, "failed getting interrupt resource\n"); 169 - retval = -EINVAL; 170 - goto errout4; 165 + return -EINVAL; 171 166 } 172 167 173 - retval = request_irq(irq, lpc32xx_adc_isr, 0, MOD_NAME, info); 168 + retval = devm_request_irq(&pdev->dev, irq, lpc32xx_adc_isr, 0, 169 + MOD_NAME, info); 174 170 if (retval < 0) { 175 171 dev_err(&pdev->dev, "failed requesting interrupt\n"); 176 - goto errout4; 172 + return retval; 177 173 } 178 174 179 175 platform_set_drvdata(pdev, iodev); ··· 185 189 186 190 retval = iio_device_register(iodev); 187 191 if (retval) 188 - goto errout5; 192 + return retval; 189 193 190 194 dev_info(&pdev->dev, "LPC32XX ADC driver loaded, IRQ %d\n", irq); 191 195 192 196 return 0; 193 - 194 - errout5: 195 - free_irq(irq, info); 196 - errout4: 197 - clk_put(info->clk); 198 - errout3: 199 - iounmap(info->adc_base); 200 - errout2: 201 - iio_device_free(iodev); 202 - errout1: 203 - return retval; 204 197 } 205 198 206 199 static int lpc32xx_adc_remove(struct platform_device *pdev) 207 200 { 208 201 struct iio_dev *iodev = platform_get_drvdata(pdev); 209 - struct lpc32xx_adc_info *info = iio_priv(iodev); 210 - int irq = platform_get_irq(pdev, 0); 211 202 212 203 iio_device_unregister(iodev); 213 - free_irq(irq, info); 214 - clk_put(info->clk); 215 - iounmap(info->adc_base); 216 - iio_device_free(iodev); 217 204 218 205 return 0; 219 206 }
+8 -13
drivers/staging/iio/adc/mxs-lradc.c
··· 625 625 j++; 626 626 } 627 627 628 - if (iio->scan_timestamp) { 629 - s64 *timestamp = (s64 *)((u8 *)lradc->buffer + 630 - ALIGN(j, sizeof(s64))); 631 - *timestamp = pf->timestamp; 632 - } 633 - 634 - iio_push_to_buffers(iio, (u8 *)lradc->buffer); 628 + iio_push_to_buffers_with_timestamp(iio, lradc->buffer, pf->timestamp); 635 629 636 630 iio_trigger_notify_done(iio->trig); 637 631 ··· 981 987 /* Register the touchscreen input device. */ 982 988 ret = mxs_lradc_ts_register(lradc); 983 989 if (ret) 984 - goto err_dev; 990 + goto err_ts_register; 985 991 986 992 /* Register IIO device. */ 987 993 ret = iio_device_register(iio); ··· 994 1000 995 1001 err_ts: 996 1002 mxs_lradc_ts_unregister(lradc); 1003 + err_ts_register: 1004 + mxs_lradc_hw_stop(lradc); 997 1005 err_dev: 998 1006 mxs_lradc_trigger_remove(iio); 999 1007 err_trig: ··· 1008 1012 struct iio_dev *iio = platform_get_drvdata(pdev); 1009 1013 struct mxs_lradc *lradc = iio_priv(iio); 1010 1014 1011 - mxs_lradc_ts_unregister(lradc); 1012 - 1013 - mxs_lradc_hw_stop(lradc); 1014 - 1015 1015 iio_device_unregister(iio); 1016 - iio_triggered_buffer_cleanup(iio); 1016 + mxs_lradc_ts_unregister(lradc); 1017 + mxs_lradc_hw_stop(lradc); 1017 1018 mxs_lradc_trigger_remove(iio); 1019 + iio_triggered_buffer_cleanup(iio); 1018 1020 1019 1021 return 0; 1020 1022 } ··· 1032 1038 MODULE_AUTHOR("Marek Vasut <marex@denx.de>"); 1033 1039 MODULE_DESCRIPTION("Freescale i.MX28 LRADC driver"); 1034 1040 MODULE_LICENSE("GPL v2"); 1041 + MODULE_ALIAS("platform:" DRIVER_NAME);
+35 -51
drivers/staging/iio/addac/adt7316.c
··· 412 412 struct iio_dev *dev_info = dev_to_iio_dev(dev); 413 413 struct adt7316_chip_info *chip = iio_priv(dev_info); 414 414 u8 config2; 415 - unsigned long data = 0; 415 + u8 data; 416 416 int ret; 417 417 418 418 if (!(chip->config2 & ADT7316_AD_SINGLE_CH_MODE)) 419 419 return -EPERM; 420 420 421 - ret = strict_strtoul(buf, 10, &data); 421 + ret = kstrtou8(buf, 10, &data); 422 422 if (ret) 423 423 return -EINVAL; 424 424 ··· 823 823 struct iio_dev *dev_info = dev_to_iio_dev(dev); 824 824 struct adt7316_chip_info *chip = iio_priv(dev_info); 825 825 u8 dac_config; 826 - unsigned long data = 0; 826 + u8 data; 827 827 int ret; 828 828 829 - ret = strict_strtoul(buf, 16, &data); 829 + ret = kstrtou8(buf, 16, &data); 830 830 if (ret || data > ADT7316_DA_2VREF_CH_MASK) 831 831 return -EINVAL; 832 832 ··· 878 878 struct iio_dev *dev_info = dev_to_iio_dev(dev); 879 879 struct adt7316_chip_info *chip = iio_priv(dev_info); 880 880 u8 dac_config; 881 - unsigned long data; 881 + u8 data; 882 882 int ret; 883 883 884 884 if (!(chip->config3 & ADT7316_DA_EN_VIA_DAC_LDCA)) 885 885 return -EPERM; 886 886 887 - ret = strict_strtoul(buf, 10, &data); 887 + ret = kstrtou8(buf, 10, &data); 888 888 if (ret || data > ADT7316_DA_EN_MODE_MASK) 889 889 return -EINVAL; 890 890 ··· 933 933 struct iio_dev *dev_info = dev_to_iio_dev(dev); 934 934 struct adt7316_chip_info *chip = iio_priv(dev_info); 935 935 u8 ldac_config; 936 - unsigned long data; 936 + u8 data; 937 937 int ret; 938 938 939 939 if (chip->config3 & ADT7316_DA_EN_VIA_DAC_LDCA) { ··· 941 941 ADT7316_DA_EN_MODE_LDAC) 942 942 return -EPERM; 943 943 944 - ret = strict_strtoul(buf, 16, &data); 944 + ret = kstrtou8(buf, 16, &data); 945 945 if (ret || data > ADT7316_LDAC_EN_DA_MASK) 946 946 return -EINVAL; 947 947 ··· 1079 1079 struct iio_dev *dev_info = dev_to_iio_dev(dev); 1080 1080 struct adt7316_chip_info *chip = iio_priv(dev_info); 1081 1081 u8 ldac_config; 1082 - unsigned long data; 1082 + u8 data; 1083 1083 int ret; 1084 1084 1085 1085 if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX) { 1086 - ret = strict_strtoul(buf, 16, &data); 1086 + ret = kstrtou8(buf, 16, &data); 1087 1087 if (ret || data > 3) 1088 1088 return -EINVAL; 1089 1089 ··· 1093 1093 else if (data & 0x2) 1094 1094 ldac_config |= ADT7516_DAC_CD_IN_VREF; 1095 1095 } else { 1096 - ret = strict_strtoul(buf, 16, &data); 1096 + ret = kstrtou8(buf, 16, &data); 1097 1097 if (ret) 1098 1098 return -EINVAL; 1099 1099 ··· 1281 1281 static ssize_t adt7316_store_temp_offset(struct adt7316_chip_info *chip, 1282 1282 int offset_addr, const char *buf, size_t len) 1283 1283 { 1284 - long data; 1284 + int data; 1285 1285 u8 val; 1286 1286 int ret; 1287 1287 1288 - ret = strict_strtol(buf, 10, &data); 1288 + ret = kstrtoint(buf, 10, &data); 1289 1289 if (ret || data > 127 || data < -128) 1290 1290 return -EINVAL; 1291 1291 ··· 1442 1442 int channel, const char *buf, size_t len) 1443 1443 { 1444 1444 u8 msb, lsb, offset; 1445 - unsigned long data; 1445 + u16 data; 1446 1446 int ret; 1447 1447 1448 1448 if (channel >= ADT7316_DA_MSB_DATA_REGS || ··· 1454 1454 1455 1455 offset = chip->dac_bits - 8; 1456 1456 1457 - ret = strict_strtoul(buf, 10, &data); 1457 + ret = kstrtou16(buf, 10, &data); 1458 1458 if (ret || data >= (1 << chip->dac_bits)) 1459 1459 return -EINVAL; 1460 1460 ··· 1830 1830 { 1831 1831 struct iio_dev *dev_info = dev_to_iio_dev(dev); 1832 1832 struct adt7316_chip_info *chip = iio_priv(dev_info); 1833 - unsigned long data; 1833 + u16 data; 1834 1834 int ret; 1835 1835 u8 mask; 1836 1836 1837 - ret = strict_strtoul(buf, 16, &data); 1837 + ret = kstrtou16(buf, 16, &data); 1838 1838 if (ret || data >= ADT7316_VDD_INT_MASK + 1) 1839 1839 return -EINVAL; 1840 1840 ··· 1901 1901 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 1902 1902 struct iio_dev *dev_info = dev_to_iio_dev(dev); 1903 1903 struct adt7316_chip_info *chip = iio_priv(dev_info); 1904 - long data; 1904 + int data; 1905 1905 u8 val; 1906 1906 int ret; 1907 1907 ··· 1909 1909 this_attr->address > ADT7316_EX_TEMP_LOW) 1910 1910 return -EPERM; 1911 1911 1912 - ret = strict_strtol(buf, 10, &data); 1912 + ret = kstrtoint(buf, 10, &data); 1913 1913 if (ret) 1914 1914 return -EINVAL; 1915 1915 ··· 2106 2106 unsigned short *adt7316_platform_data = dev->platform_data; 2107 2107 int ret = 0; 2108 2108 2109 - indio_dev = iio_device_alloc(sizeof(*chip)); 2110 - if (indio_dev == NULL) { 2111 - ret = -ENOMEM; 2112 - goto error_ret; 2113 - } 2109 + indio_dev = devm_iio_device_alloc(dev, sizeof(*chip)); 2110 + if (!indio_dev) 2111 + return -ENOMEM; 2114 2112 chip = iio_priv(indio_dev); 2115 2113 /* this is only used for device removal purposes */ 2116 2114 dev_set_drvdata(dev, indio_dev); ··· 2144 2146 if (adt7316_platform_data[0]) 2145 2147 chip->bus.irq_flags = adt7316_platform_data[0]; 2146 2148 2147 - ret = request_threaded_irq(chip->bus.irq, 2148 - NULL, 2149 - &adt7316_event_handler, 2150 - chip->bus.irq_flags | IRQF_ONESHOT, 2151 - indio_dev->name, 2152 - indio_dev); 2149 + ret = devm_request_threaded_irq(dev, chip->bus.irq, 2150 + NULL, 2151 + &adt7316_event_handler, 2152 + chip->bus.irq_flags | 2153 + IRQF_ONESHOT, 2154 + indio_dev->name, 2155 + indio_dev); 2153 2156 if (ret) 2154 - goto error_free_dev; 2157 + return ret; 2155 2158 2156 2159 if (chip->bus.irq_flags & IRQF_TRIGGER_HIGH) 2157 2160 chip->config1 |= ADT7316_INT_POLARITY; 2158 2161 } 2159 2162 2160 2163 ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG1, chip->config1); 2161 - if (ret) { 2162 - ret = -EIO; 2163 - goto error_unreg_irq; 2164 - } 2164 + if (ret) 2165 + return -EIO; 2165 2166 2166 2167 ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG3, chip->config3); 2167 - if (ret) { 2168 - ret = -EIO; 2169 - goto error_unreg_irq; 2170 - } 2168 + if (ret) 2169 + return -EIO; 2171 2170 2172 2171 ret = iio_device_register(indio_dev); 2173 2172 if (ret) 2174 - goto error_unreg_irq; 2173 + return ret; 2175 2174 2176 2175 dev_info(dev, "%s temperature sensor, ADC and DAC registered.\n", 2177 2176 indio_dev->name); 2178 2177 2179 2178 return 0; 2180 - 2181 - error_unreg_irq: 2182 - free_irq(chip->bus.irq, indio_dev); 2183 - error_free_dev: 2184 - iio_device_free(indio_dev); 2185 - error_ret: 2186 - return ret; 2187 2179 } 2188 2180 EXPORT_SYMBOL(adt7316_probe); 2189 2181 2190 2182 int adt7316_remove(struct device *dev) 2191 2183 { 2192 2184 struct iio_dev *indio_dev = dev_get_drvdata(dev); 2193 - struct adt7316_chip_info *chip = iio_priv(indio_dev); 2194 2185 2195 2186 iio_device_unregister(indio_dev); 2196 - if (chip->bus.irq) 2197 - free_irq(chip->bus.irq, indio_dev); 2198 - iio_device_free(indio_dev); 2199 2187 2200 2188 return 0; 2201 2189 }
+4 -12
drivers/staging/iio/frequency/ad5930.c
··· 94 94 struct iio_dev *idev; 95 95 int ret = 0; 96 96 97 - idev = iio_device_alloc(sizeof(*st)); 98 - if (idev == NULL) { 99 - ret = -ENOMEM; 100 - goto error_ret; 101 - } 97 + idev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 98 + if (!idev) 99 + return -ENOMEM; 102 100 spi_set_drvdata(spi, idev); 103 101 st = iio_priv(idev); 104 102 ··· 108 110 109 111 ret = iio_device_register(idev); 110 112 if (ret) 111 - goto error_free_dev; 113 + return ret; 112 114 spi->max_speed_hz = 2000000; 113 115 spi->mode = SPI_MODE_3; 114 116 spi->bits_per_word = 16; 115 117 spi_setup(spi); 116 118 117 119 return 0; 118 - 119 - error_free_dev: 120 - iio_device_free(idev); 121 - error_ret: 122 - return ret; 123 120 } 124 121 125 122 static int ad5930_remove(struct spi_device *spi) 126 123 { 127 124 iio_device_unregister(spi_get_drvdata(spi)); 128 - iio_device_free(spi_get_drvdata(spi)); 129 125 130 126 return 0; 131 127 }
+14 -22
drivers/staging/iio/frequency/ad9832.c
··· 81 81 struct ad9832_state *st = iio_priv(indio_dev); 82 82 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 83 83 int ret; 84 - long val; 84 + unsigned long val; 85 85 86 - ret = strict_strtoul(buf, 10, &val); 86 + ret = kstrtoul(buf, 10, &val); 87 87 if (ret) 88 88 goto error_ret; 89 89 ··· 214 214 return -ENODEV; 215 215 } 216 216 217 - reg = regulator_get(&spi->dev, "vcc"); 217 + reg = devm_regulator_get(&spi->dev, "vcc"); 218 218 if (!IS_ERR(reg)) { 219 219 ret = regulator_enable(reg); 220 220 if (ret) 221 - goto error_put_reg; 221 + return ret; 222 222 } 223 223 224 - indio_dev = iio_device_alloc(sizeof(*st)); 224 + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 225 225 if (indio_dev == NULL) { 226 226 ret = -ENOMEM; 227 227 goto error_disable_reg; ··· 279 279 ret = spi_sync(st->spi, &st->msg); 280 280 if (ret) { 281 281 dev_err(&spi->dev, "device init failed\n"); 282 - goto error_free_device; 282 + goto error_disable_reg; 283 283 } 284 284 285 285 ret = ad9832_write_frequency(st, AD9832_FREQ0HM, pdata->freq0); 286 286 if (ret) 287 - goto error_free_device; 287 + goto error_disable_reg; 288 288 289 289 ret = ad9832_write_frequency(st, AD9832_FREQ1HM, pdata->freq1); 290 290 if (ret) 291 - goto error_free_device; 291 + goto error_disable_reg; 292 292 293 293 ret = ad9832_write_phase(st, AD9832_PHASE0H, pdata->phase0); 294 294 if (ret) 295 - goto error_free_device; 295 + goto error_disable_reg; 296 296 297 297 ret = ad9832_write_phase(st, AD9832_PHASE1H, pdata->phase1); 298 298 if (ret) 299 - goto error_free_device; 299 + goto error_disable_reg; 300 300 301 301 ret = ad9832_write_phase(st, AD9832_PHASE2H, pdata->phase2); 302 302 if (ret) 303 - goto error_free_device; 303 + goto error_disable_reg; 304 304 305 305 ret = ad9832_write_phase(st, AD9832_PHASE3H, pdata->phase3); 306 306 if (ret) 307 - goto error_free_device; 307 + goto error_disable_reg; 308 308 309 309 ret = iio_device_register(indio_dev); 310 310 if (ret) 311 - goto error_free_device; 311 + goto error_disable_reg; 312 312 313 313 return 0; 314 314 315 - error_free_device: 316 - iio_device_free(indio_dev); 317 315 error_disable_reg: 318 316 if (!IS_ERR(reg)) 319 317 regulator_disable(reg); 320 - error_put_reg: 321 - if (!IS_ERR(reg)) 322 - regulator_put(reg); 323 318 324 319 return ret; 325 320 } ··· 325 330 struct ad9832_state *st = iio_priv(indio_dev); 326 331 327 332 iio_device_unregister(indio_dev); 328 - if (!IS_ERR(st->reg)) { 333 + if (!IS_ERR(st->reg)) 329 334 regulator_disable(st->reg); 330 - regulator_put(st->reg); 331 - } 332 - iio_device_free(indio_dev); 333 335 334 336 return 0; 335 337 }
+13 -20
drivers/staging/iio/frequency/ad9834.c
··· 70 70 struct ad9834_state *st = iio_priv(indio_dev); 71 71 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 72 72 int ret; 73 - long val; 73 + unsigned long val; 74 74 75 - ret = strict_strtoul(buf, 10, &val); 75 + ret = kstrtoul(buf, 10, &val); 76 76 if (ret) 77 77 goto error_ret; 78 78 ··· 327 327 return -ENODEV; 328 328 } 329 329 330 - reg = regulator_get(&spi->dev, "vcc"); 330 + reg = devm_regulator_get(&spi->dev, "vcc"); 331 331 if (!IS_ERR(reg)) { 332 332 ret = regulator_enable(reg); 333 333 if (ret) 334 - goto error_put_reg; 334 + return ret; 335 335 } 336 336 337 - indio_dev = iio_device_alloc(sizeof(*st)); 337 + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 338 338 if (indio_dev == NULL) { 339 339 ret = -ENOMEM; 340 340 goto error_disable_reg; ··· 388 388 ret = spi_sync(st->spi, &st->msg); 389 389 if (ret) { 390 390 dev_err(&spi->dev, "device init failed\n"); 391 - goto error_free_device; 391 + goto error_disable_reg; 392 392 } 393 393 394 394 ret = ad9834_write_frequency(st, AD9834_REG_FREQ0, pdata->freq0); 395 395 if (ret) 396 - goto error_free_device; 396 + goto error_disable_reg; 397 397 398 398 ret = ad9834_write_frequency(st, AD9834_REG_FREQ1, pdata->freq1); 399 399 if (ret) 400 - goto error_free_device; 400 + goto error_disable_reg; 401 401 402 402 ret = ad9834_write_phase(st, AD9834_REG_PHASE0, pdata->phase0); 403 403 if (ret) 404 - goto error_free_device; 404 + goto error_disable_reg; 405 405 406 406 ret = ad9834_write_phase(st, AD9834_REG_PHASE1, pdata->phase1); 407 407 if (ret) 408 - goto error_free_device; 408 + goto error_disable_reg; 409 409 410 410 ret = iio_device_register(indio_dev); 411 411 if (ret) 412 - goto error_free_device; 412 + goto error_disable_reg; 413 413 414 414 return 0; 415 415 416 - error_free_device: 417 - iio_device_free(indio_dev); 418 416 error_disable_reg: 419 417 if (!IS_ERR(reg)) 420 418 regulator_disable(reg); 421 - error_put_reg: 422 - if (!IS_ERR(reg)) 423 - regulator_put(reg); 419 + 424 420 return ret; 425 421 } 426 422 ··· 426 430 struct ad9834_state *st = iio_priv(indio_dev); 427 431 428 432 iio_device_unregister(indio_dev); 429 - if (!IS_ERR(st->reg)) { 433 + if (!IS_ERR(st->reg)) 430 434 regulator_disable(st->reg); 431 - regulator_put(st->reg); 432 - } 433 - iio_device_free(indio_dev); 434 435 435 436 return 0; 436 437 }
+4 -12
drivers/staging/iio/frequency/ad9850.c
··· 80 80 struct iio_dev *idev; 81 81 int ret = 0; 82 82 83 - idev = iio_device_alloc(sizeof(*st)); 84 - if (idev == NULL) { 85 - ret = -ENOMEM; 86 - goto error_ret; 87 - } 83 + idev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 84 + if (!idev) 85 + return -ENOMEM; 88 86 spi_set_drvdata(spi, idev); 89 87 st = iio_priv(idev); 90 88 mutex_init(&st->lock); ··· 94 96 95 97 ret = iio_device_register(idev); 96 98 if (ret) 97 - goto error_free_dev; 99 + return ret; 98 100 spi->max_speed_hz = 2000000; 99 101 spi->mode = SPI_MODE_3; 100 102 spi->bits_per_word = 16; 101 103 spi_setup(spi); 102 104 103 105 return 0; 104 - 105 - error_free_dev: 106 - iio_device_free(idev); 107 - error_ret: 108 - return ret; 109 106 } 110 107 111 108 static int ad9850_remove(struct spi_device *spi) 112 109 { 113 110 iio_device_unregister(spi_get_drvdata(spi)); 114 - iio_device_free(spi_get_drvdata(spi)); 115 111 116 112 return 0; 117 113 }
+4 -13
drivers/staging/iio/frequency/ad9852.c
··· 229 229 struct iio_dev *idev; 230 230 int ret = 0; 231 231 232 - idev = iio_device_alloc(sizeof(*st)); 233 - if (idev == NULL) { 234 - ret = -ENOMEM; 235 - goto error_ret; 236 - } 232 + idev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 233 + if (!idev) 234 + return -ENOMEM; 237 235 st = iio_priv(idev); 238 236 spi_set_drvdata(spi, idev); 239 237 mutex_init(&st->lock); ··· 243 245 244 246 ret = iio_device_register(idev); 245 247 if (ret) 246 - goto error_free_dev; 248 + return ret; 247 249 spi->max_speed_hz = 2000000; 248 250 spi->mode = SPI_MODE_3; 249 251 spi->bits_per_word = 8; ··· 251 253 ad9852_init(st); 252 254 253 255 return 0; 254 - 255 - error_free_dev: 256 - iio_device_free(idev); 257 - 258 - error_ret: 259 - return ret; 260 256 } 261 257 262 258 static int ad9852_remove(struct spi_device *spi) 263 259 { 264 260 iio_device_unregister(spi_get_drvdata(spi)); 265 - iio_device_free(spi_get_drvdata(spi)); 266 261 267 262 return 0; 268 263 }
+4 -12
drivers/staging/iio/frequency/ad9910.c
··· 367 367 struct iio_dev *idev; 368 368 int ret = 0; 369 369 370 - idev = iio_device_alloc(sizeof(*st)); 371 - if (idev == NULL) { 372 - ret = -ENOMEM; 373 - goto error_ret; 374 - } 370 + idev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 371 + if (!idev) 372 + return -ENOMEM; 375 373 spi_set_drvdata(spi, idev); 376 374 st = iio_priv(idev); 377 375 mutex_init(&st->lock); ··· 381 383 382 384 ret = iio_device_register(idev); 383 385 if (ret) 384 - goto error_free_dev; 386 + return ret; 385 387 spi->max_speed_hz = 2000000; 386 388 spi->mode = SPI_MODE_3; 387 389 spi->bits_per_word = 8; 388 390 spi_setup(spi); 389 391 ad9910_init(st); 390 392 return 0; 391 - 392 - error_free_dev: 393 - iio_device_free(idev); 394 - error_ret: 395 - return ret; 396 393 } 397 394 398 395 static int ad9910_remove(struct spi_device *spi) 399 396 { 400 397 iio_device_unregister(spi_get_drvdata(spi)); 401 - iio_device_free(spi_get_drvdata(spi)); 402 398 403 399 return 0; 404 400 }
+4 -13
drivers/staging/iio/frequency/ad9951.c
··· 176 176 struct iio_dev *idev; 177 177 int ret = 0; 178 178 179 - idev = iio_device_alloc(sizeof(*st)); 180 - if (idev == NULL) { 181 - ret = -ENOMEM; 182 - goto error_ret; 183 - } 179 + idev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 180 + if (!idev) 181 + return -ENOMEM; 184 182 spi_set_drvdata(spi, idev); 185 183 st = iio_priv(idev); 186 184 mutex_init(&st->lock); ··· 191 193 192 194 ret = iio_device_register(idev); 193 195 if (ret) 194 - goto error_free_dev; 196 + return ret; 195 197 spi->max_speed_hz = 2000000; 196 198 spi->mode = SPI_MODE_3; 197 199 spi->bits_per_word = 8; 198 200 spi_setup(spi); 199 201 ad9951_init(st); 200 202 return 0; 201 - 202 - error_free_dev: 203 - iio_device_free(idev); 204 - 205 - error_ret: 206 - return ret; 207 203 } 208 204 209 205 static int ad9951_remove(struct spi_device *spi) 210 206 { 211 207 iio_device_unregister(spi_get_drvdata(spi)); 212 - iio_device_free(spi_get_drvdata(spi)); 213 208 214 209 return 0; 215 210 }
+16
drivers/staging/iio/iio_simple_dummy.c
··· 90 90 * when converting to standard units (microvolts) 91 91 */ 92 92 BIT(IIO_CHAN_INFO_SCALE), 93 + /* 94 + * sampling_frequency 95 + * The frequency in Hz at which the channels are sampled 96 + */ 97 + .info_mask_shared_by_dir = BIT(IIO_CHAN_INFO_SAMP_FREQ), 93 98 /* The ordering of elements in the buffer via an enum */ 94 99 .scan_index = voltage0, 95 100 .scan_type = { /* Description of storage in buffer */ ··· 135 130 * input channels of type IIO_VOLTAGE. 136 131 */ 137 132 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), 133 + /* 134 + * sampling_frequency 135 + * The frequency in Hz at which the channels are sampled 136 + */ 138 137 .scan_index = diffvoltage1m2, 139 138 .scan_type = { /* Description of storage in buffer */ 140 139 .sign = 's', /* signed */ ··· 156 147 .channel2 = 4, 157 148 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 158 149 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), 150 + .info_mask_shared_by_dir = BIT(IIO_CHAN_INFO_SAMP_FREQ), 159 151 .scan_index = diffvoltage3m4, 160 152 .scan_type = { 161 153 .sign = 's', ··· 183 173 */ 184 174 BIT(IIO_CHAN_INFO_CALIBSCALE) | 185 175 BIT(IIO_CHAN_INFO_CALIBBIAS), 176 + .info_mask_shared_by_dir = BIT(IIO_CHAN_INFO_SAMP_FREQ), 186 177 .scan_index = accelx, 187 178 .scan_type = { /* Description of storage in buffer */ 188 179 .sign = 's', /* signed */ ··· 282 271 *val = st->accel_calibscale->val; 283 272 *val2 = st->accel_calibscale->val2; 284 273 ret = IIO_VAL_INT_PLUS_MICRO; 274 + break; 275 + case IIO_CHAN_INFO_SAMP_FREQ: 276 + *val = 3; 277 + *val2 = 33; 278 + ret = IIO_VAL_INT_PLUS_NANO; 285 279 break; 286 280 default: 287 281 break;
+2 -5
drivers/staging/iio/iio_simple_dummy_buffer.c
··· 82 82 len += 2; 83 83 } 84 84 } 85 - /* Store the timestamp at an 8 byte aligned offset */ 86 - if (indio_dev->scan_timestamp) 87 - *(s64 *)((u8 *)data + ALIGN(len, sizeof(s64))) 88 - = iio_get_time_ns(); 89 - iio_push_to_buffers(indio_dev, (u8 *)data); 85 + 86 + iio_push_to_buffers_with_timestamp(indio_dev, data, iio_get_time_ns()); 90 87 91 88 kfree(data); 92 89
+13 -19
drivers/staging/iio/impedance-analyzer/ad5933.c
··· 323 323 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 324 324 struct ad5933_state *st = iio_priv(indio_dev); 325 325 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 326 - long val; 326 + unsigned long val; 327 327 int ret; 328 328 329 - ret = strict_strtoul(buf, 10, &val); 329 + ret = kstrtoul(buf, 10, &val); 330 330 if (ret) 331 331 return ret; 332 332 ··· 400 400 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 401 401 struct ad5933_state *st = iio_priv(indio_dev); 402 402 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 403 - long val; 403 + u16 val; 404 404 int i, ret = 0; 405 405 unsigned short dat; 406 406 407 407 if (this_attr->address != AD5933_IN_PGA_GAIN) { 408 - ret = strict_strtol(buf, 10, &val); 408 + ret = kstrtou16(buf, 10, &val); 409 409 if (ret) 410 410 return ret; 411 411 } ··· 434 434 ret = ad5933_cmd(st, 0); 435 435 break; 436 436 case AD5933_OUT_SETTLING_CYCLES: 437 - val = clamp(val, 0L, 0x7FFL); 437 + val = clamp(val, (u16)0, (u16)0x7FF); 438 438 st->settling_cycles = val; 439 439 440 440 /* 2x, 4x handling, see datasheet */ ··· 448 448 AD5933_REG_SETTLING_CYCLES, 2, (u8 *)&dat); 449 449 break; 450 450 case AD5933_FREQ_POINTS: 451 - val = clamp(val, 0L, 511L); 451 + val = clamp(val, (u16)0, (u16)511); 452 452 st->freq_points = val; 453 453 454 454 dat = cpu_to_be16(val); ··· 676 676 } else { 677 677 buf[0] = be16_to_cpu(buf[0]); 678 678 } 679 - iio_push_to_buffers(indio_dev, (u8 *)buf); 679 + iio_push_to_buffers(indio_dev, buf); 680 680 } else { 681 681 /* no data available - try again later */ 682 682 schedule_delayed_work(&st->work, st->poll_time_jiffies); ··· 703 703 int ret, voltage_uv = 0; 704 704 struct ad5933_platform_data *pdata = client->dev.platform_data; 705 705 struct ad5933_state *st; 706 - struct iio_dev *indio_dev = iio_device_alloc(sizeof(*st)); 706 + struct iio_dev *indio_dev; 707 + 708 + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*st)); 707 709 if (indio_dev == NULL) 708 710 return -ENOMEM; 709 711 ··· 718 716 else 719 717 st->pdata = pdata; 720 718 721 - st->reg = regulator_get(&client->dev, "vcc"); 719 + st->reg = devm_regulator_get(&client->dev, "vcc"); 722 720 if (!IS_ERR(st->reg)) { 723 721 ret = regulator_enable(st->reg); 724 722 if (ret) 725 - goto error_put_reg; 723 + return ret; 726 724 voltage_uv = regulator_get_voltage(st->reg); 727 725 } 728 726 ··· 780 778 error_disable_reg: 781 779 if (!IS_ERR(st->reg)) 782 780 regulator_disable(st->reg); 783 - error_put_reg: 784 - if (!IS_ERR(st->reg)) 785 - regulator_put(st->reg); 786 - 787 - iio_device_free(indio_dev); 788 781 789 782 return ret; 790 783 } ··· 792 795 iio_device_unregister(indio_dev); 793 796 iio_buffer_unregister(indio_dev); 794 797 iio_kfifo_free(indio_dev->buffer); 795 - if (!IS_ERR(st->reg)) { 798 + if (!IS_ERR(st->reg)) 796 799 regulator_disable(st->reg); 797 - regulator_put(st->reg); 798 - } 799 - iio_device_free(indio_dev); 800 800 801 801 return 0; 802 802 }
+9 -9
drivers/staging/iio/light/isl29018.c
··· 240 240 unsigned long lval; 241 241 unsigned int new_range; 242 242 243 - if (strict_strtoul(buf, 10, &lval)) 243 + if (kstrtoul(buf, 10, &lval)) 244 244 return -EINVAL; 245 245 246 246 if (!(lval == 1000UL || lval == 4000UL || ··· 279 279 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 280 280 struct isl29018_chip *chip = iio_priv(indio_dev); 281 281 int status; 282 - unsigned long lval; 282 + unsigned int val; 283 283 unsigned int new_adc_bit; 284 284 285 - if (strict_strtoul(buf, 10, &lval)) 285 + if (kstrtouint(buf, 10, &val)) 286 286 return -EINVAL; 287 - if (!(lval == 4 || lval == 8 || lval == 12 || lval == 16)) { 287 + if (!(val == 4 || val == 8 || val == 12 || val == 16)) { 288 288 dev_err(dev, "The resolution is not supported\n"); 289 289 return -EINVAL; 290 290 } 291 291 292 292 mutex_lock(&chip->lock); 293 - status = isl29018_set_resolution(chip, lval, &new_adc_bit); 293 + status = isl29018_set_resolution(chip, val, &new_adc_bit); 294 294 if (status < 0) { 295 295 mutex_unlock(&chip->lock); 296 296 dev_err(dev, "Error in setting resolution\n"); ··· 319 319 { 320 320 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 321 321 struct isl29018_chip *chip = iio_priv(indio_dev); 322 - unsigned long lval; 322 + int val; 323 323 324 - if (strict_strtoul(buf, 10, &lval)) 324 + if (kstrtoint(buf, 10, &val)) 325 325 return -EINVAL; 326 - if (!(lval == 0UL || lval == 1UL)) { 326 + if (!(val == 0 || val == 1)) { 327 327 dev_err(dev, "The mode is not supported\n"); 328 328 return -EINVAL; 329 329 } ··· 331 331 /* get the "proximity scheme" i.e. if the chip does on chip 332 332 infrared suppression (1 means perform on chip suppression) */ 333 333 mutex_lock(&chip->lock); 334 - chip->prox_scheme = (int)lval; 334 + chip->prox_scheme = val; 335 335 mutex_unlock(&chip->lock); 336 336 337 337 return count;
+20 -28
drivers/staging/iio/light/tsl2583.c
··· 493 493 struct device_attribute *attr, const char *buf, size_t len) 494 494 { 495 495 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 496 - unsigned long value; 496 + int value; 497 497 498 - if (strict_strtoul(buf, 0, &value)) 498 + if (kstrtoint(buf, 0, &value)) 499 499 return -EINVAL; 500 500 501 501 if (value == 0) ··· 536 536 { 537 537 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 538 538 struct tsl2583_chip *chip = iio_priv(indio_dev); 539 - unsigned long value; 539 + int value; 540 540 541 - if (strict_strtoul(buf, 0, &value)) 541 + if (kstrtoint(buf, 0, &value)) 542 542 return -EINVAL; 543 543 544 544 switch (value) { ··· 582 582 { 583 583 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 584 584 struct tsl2583_chip *chip = iio_priv(indio_dev); 585 - unsigned long value; 585 + int value; 586 586 587 - if (strict_strtoul(buf, 0, &value)) 587 + if (kstrtoint(buf, 0, &value)) 588 588 return -EINVAL; 589 589 590 590 if ((value < 50) || (value > 650)) ··· 619 619 { 620 620 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 621 621 struct tsl2583_chip *chip = iio_priv(indio_dev); 622 - unsigned long value; 622 + int value; 623 623 624 - if (strict_strtoul(buf, 0, &value)) 624 + if (kstrtoint(buf, 0, &value)) 625 625 return -EINVAL; 626 626 627 627 if (value) ··· 644 644 { 645 645 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 646 646 struct tsl2583_chip *chip = iio_priv(indio_dev); 647 - unsigned long value; 647 + int value; 648 648 649 - if (strict_strtoul(buf, 0, &value)) 649 + if (kstrtoint(buf, 0, &value)) 650 650 return -EINVAL; 651 651 652 652 if (value) ··· 671 671 struct device_attribute *attr, const char *buf, size_t len) 672 672 { 673 673 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 674 - unsigned long value; 674 + int value; 675 675 676 - if (strict_strtoul(buf, 0, &value)) 676 + if (kstrtoint(buf, 0, &value)) 677 677 return -EINVAL; 678 678 679 679 if (value == 1) ··· 815 815 return -EOPNOTSUPP; 816 816 } 817 817 818 - indio_dev = iio_device_alloc(sizeof(*chip)); 819 - if (indio_dev == NULL) { 820 - ret = -ENOMEM; 821 - dev_err(&clientp->dev, "iio allocation failed\n"); 822 - goto fail1; 823 - } 818 + indio_dev = devm_iio_device_alloc(&clientp->dev, sizeof(*chip)); 819 + if (!indio_dev) 820 + return -ENOMEM; 824 821 chip = iio_priv(indio_dev); 825 822 chip->client = clientp; 826 823 i2c_set_clientdata(clientp, indio_dev); ··· 832 835 if (ret < 0) { 833 836 dev_err(&clientp->dev, "i2c_smbus_write_bytes() to cmd " 834 837 "reg failed in taos_probe(), err = %d\n", ret); 835 - goto fail2; 838 + return ret; 836 839 } 837 840 ret = i2c_smbus_read_byte(clientp); 838 841 if (ret < 0) { 839 842 dev_err(&clientp->dev, "i2c_smbus_read_byte from " 840 843 "reg failed in taos_probe(), err = %d\n", ret); 841 844 842 - goto fail2; 845 + return ret; 843 846 } 844 847 buf[i] = ret; 845 848 } ··· 847 850 if (!taos_tsl258x_device(buf)) { 848 851 dev_info(&clientp->dev, "i2c device found but does not match " 849 852 "expected id in taos_probe()\n"); 850 - goto fail2; 853 + return -EINVAL; 851 854 } 852 855 853 856 ret = i2c_smbus_write_byte(clientp, (TSL258X_CMD_REG | TSL258X_CNTRL)); 854 857 if (ret < 0) { 855 858 dev_err(&clientp->dev, "i2c_smbus_write_byte() to cmd reg " 856 859 "failed in taos_probe(), err = %d\n", ret); 857 - goto fail2; 860 + return ret; 858 861 } 859 862 860 863 indio_dev->info = &tsl2583_info; ··· 864 867 ret = iio_device_register(indio_dev); 865 868 if (ret) { 866 869 dev_err(&clientp->dev, "iio registration failed\n"); 867 - goto fail2; 870 + return ret; 868 871 } 869 872 870 873 /* Load up the V2 defaults (these are hard coded defaults for now) */ ··· 875 878 876 879 dev_info(&clientp->dev, "Light sensor found.\n"); 877 880 return 0; 878 - fail1: 879 - iio_device_free(indio_dev); 880 - fail2: 881 - return ret; 882 881 } 883 882 884 883 #ifdef CONFIG_PM_SLEEP ··· 919 926 static int taos_remove(struct i2c_client *client) 920 927 { 921 928 iio_device_unregister(i2c_get_clientdata(client)); 922 - iio_device_free(i2c_get_clientdata(client)); 923 929 924 930 return 0; 925 931 }
+14 -34
drivers/staging/iio/light/tsl2x7x_core.c
··· 550 550 static void tsl2x7x_defaults(struct tsl2X7X_chip *chip) 551 551 { 552 552 /* If Operational settings defined elsewhere.. */ 553 - if (chip->pdata && chip->pdata->platform_default_settings != 0) 553 + if (chip->pdata && chip->pdata->platform_default_settings) 554 554 memcpy(&(chip->tsl2x7x_settings), 555 555 chip->pdata->platform_default_settings, 556 556 sizeof(tsl2x7x_default_settings)); ··· 951 951 case tsl2771: 952 952 case tmd2771: 953 953 return snprintf(buf, PAGE_SIZE, "%s\n", "1 8 16 128"); 954 - break; 955 954 } 956 955 957 956 return snprintf(buf, PAGE_SIZE, "%s\n", "1 8 16 120"); ··· 1345 1346 break; 1346 1347 default: 1347 1348 return -EINVAL; 1348 - break; 1349 1349 } 1350 1350 break; 1351 1351 case IIO_CHAN_INFO_RAW: ··· 1364 1366 break; 1365 1367 default: 1366 1368 return -EINVAL; 1367 - break; 1368 1369 } 1369 1370 break; 1370 1371 case IIO_CHAN_INFO_CALIBSCALE: ··· 1416 1419 case tsl2772: 1417 1420 case tmd2772: 1418 1421 return -EINVAL; 1419 - break; 1420 1422 } 1421 1423 chip->tsl2x7x_settings.als_gain = 3; 1422 1424 break; ··· 1427 1431 case tsl2771: 1428 1432 case tmd2771: 1429 1433 return -EINVAL; 1430 - break; 1431 1434 } 1432 1435 chip->tsl2x7x_settings.als_gain = 3; 1433 1436 break; ··· 1503 1508 case tsl2671: 1504 1509 case tsl2771: 1505 1510 return ((*id & 0xf0) == TRITON_ID); 1506 - break; 1507 1511 case tmd2671: 1508 1512 case tmd2771: 1509 1513 return ((*id & 0xf0) == HALIBUT_ID); 1510 - break; 1511 1514 case tsl2572: 1512 1515 case tsl2672: 1513 1516 case tmd2672: 1514 1517 case tsl2772: 1515 1518 case tmd2772: 1516 1519 return ((*id & 0xf0) == SWORDFISH_ID); 1517 - break; 1518 1520 } 1519 1521 1520 1522 return -EINVAL; ··· 1843 1851 struct iio_dev *indio_dev; 1844 1852 struct tsl2X7X_chip *chip; 1845 1853 1846 - indio_dev = iio_device_alloc(sizeof(*chip)); 1854 + indio_dev = devm_iio_device_alloc(&clientp->dev, sizeof(*chip)); 1847 1855 if (!indio_dev) 1848 1856 return -ENOMEM; 1849 1857 ··· 1854 1862 ret = tsl2x7x_i2c_read(chip->client, 1855 1863 TSL2X7X_CHIPID, &device_id); 1856 1864 if (ret < 0) 1857 - goto fail1; 1865 + return ret; 1858 1866 1859 1867 if ((!tsl2x7x_device_id(&device_id, id->driver_data)) || 1860 1868 (tsl2x7x_device_id(&device_id, id->driver_data) == -EINVAL)) { 1861 1869 dev_info(&chip->client->dev, 1862 1870 "%s: i2c device found does not match expected id\n", 1863 1871 __func__); 1864 - ret = -EINVAL; 1865 - goto fail1; 1872 + return -EINVAL; 1866 1873 } 1867 1874 1868 1875 ret = i2c_smbus_write_byte(clientp, (TSL2X7X_CMD_REG | TSL2X7X_CNTRL)); 1869 1876 if (ret < 0) { 1870 1877 dev_err(&clientp->dev, "%s: write to cmd reg failed. err = %d\n", 1871 1878 __func__, ret); 1872 - goto fail1; 1879 + return ret; 1873 1880 } 1874 1881 1875 1882 /* ALS and PROX functions can be invoked via user space poll ··· 1890 1899 indio_dev->num_channels = chip->chip_info->chan_table_elements; 1891 1900 1892 1901 if (clientp->irq) { 1893 - ret = request_threaded_irq(clientp->irq, 1894 - NULL, 1895 - &tsl2x7x_event_handler, 1896 - IRQF_TRIGGER_RISING | IRQF_ONESHOT, 1897 - "TSL2X7X_event", 1898 - indio_dev); 1902 + ret = devm_request_threaded_irq(&clientp->dev, clientp->irq, 1903 + NULL, 1904 + &tsl2x7x_event_handler, 1905 + IRQF_TRIGGER_RISING | 1906 + IRQF_ONESHOT, 1907 + "TSL2X7X_event", 1908 + indio_dev); 1899 1909 if (ret) { 1900 1910 dev_err(&clientp->dev, 1901 1911 "%s: irq request failed", __func__); 1902 - goto fail1; 1912 + return ret; 1903 1913 } 1904 1914 } 1905 1915 ··· 1913 1921 if (ret) { 1914 1922 dev_err(&clientp->dev, 1915 1923 "%s: iio registration failed\n", __func__); 1916 - goto fail2; 1924 + return ret; 1917 1925 } 1918 1926 1919 1927 dev_info(&clientp->dev, "%s Light sensor found.\n", id->name); 1920 1928 1921 1929 return 0; 1922 - 1923 - fail2: 1924 - if (clientp->irq) 1925 - free_irq(clientp->irq, indio_dev); 1926 - fail1: 1927 - iio_device_free(indio_dev); 1928 - 1929 - return ret; 1930 1930 } 1931 1931 1932 1932 static int tsl2x7x_suspend(struct device *dev) ··· 1964 1980 tsl2x7x_chip_off(indio_dev); 1965 1981 1966 1982 iio_device_unregister(indio_dev); 1967 - if (client->irq) 1968 - free_irq(client->irq, indio_dev); 1969 - 1970 - iio_device_free(indio_dev); 1971 1983 1972 1984 return 0; 1973 1985 }
+8 -18
drivers/staging/iio/magnetometer/hmc5843.c
··· 643 643 struct iio_dev *indio_dev; 644 644 int err = 0; 645 645 646 - indio_dev = iio_device_alloc(sizeof(*data)); 647 - if (indio_dev == NULL) { 648 - err = -ENOMEM; 649 - goto exit; 650 - } 646 + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 647 + if (indio_dev == NULL) 648 + return -ENOMEM; 651 649 652 650 /* default settings at probe */ 653 651 data = iio_priv(indio_dev); ··· 663 665 664 666 err = iio_device_register(indio_dev); 665 667 if (err) 666 - goto exit_free2; 668 + return err; 667 669 668 670 return 0; 669 - 670 - exit_free2: 671 - iio_device_free(indio_dev); 672 - exit: 673 - return err; 674 671 } 675 672 676 673 static int hmc5843_remove(struct i2c_client *client) 677 674 { 678 - struct iio_dev *indio_dev = i2c_get_clientdata(client); 679 - 680 - iio_device_unregister(indio_dev); 675 + iio_device_unregister(i2c_get_clientdata(client)); 681 676 /* sleep mode to save power */ 682 677 hmc5843_configure(client, HMC5843_MODE_SLEEP); 683 - iio_device_free(indio_dev); 684 678 685 679 return 0; 686 680 } ··· 681 691 static int hmc5843_suspend(struct device *dev) 682 692 { 683 693 hmc5843_configure(to_i2c_client(dev), HMC5843_MODE_SLEEP); 694 + 684 695 return 0; 685 696 } 686 697 687 698 static int hmc5843_resume(struct device *dev) 688 699 { 689 700 struct i2c_client *client = to_i2c_client(dev); 690 - struct iio_dev *indio_dev = i2c_get_clientdata(client); 691 - struct hmc5843_data *data = iio_priv(indio_dev); 701 + struct hmc5843_data *data = iio_priv(i2c_get_clientdata(client)); 692 702 693 703 hmc5843_configure(client, data->operating_mode); 694 704 ··· 720 730 }; 721 731 module_i2c_driver(hmc5843_driver); 722 732 723 - MODULE_AUTHOR("Shubhrajyoti Datta <shubhrajyoti@ti.com"); 733 + MODULE_AUTHOR("Shubhrajyoti Datta <shubhrajyoti@ti.com>"); 724 734 MODULE_DESCRIPTION("HMC5843/5883/5883L driver"); 725 735 MODULE_LICENSE("GPL");
+11 -20
drivers/staging/iio/meter/ade7753.c
··· 186 186 { 187 187 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 188 188 int ret; 189 - long val; 189 + u8 val; 190 190 191 - ret = strict_strtol(buf, 10, &val); 191 + ret = kstrtou8(buf, 10, &val); 192 192 if (ret) 193 193 goto error_ret; 194 194 ret = ade7753_spi_write_reg_8(dev, this_attr->address, val); ··· 204 204 { 205 205 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 206 206 int ret; 207 - long val; 207 + u16 val; 208 208 209 - ret = strict_strtol(buf, 10, &val); 209 + ret = kstrtou16(buf, 10, &val); 210 210 if (ret) 211 211 goto error_ret; 212 212 ret = ade7753_spi_write_reg_16(dev, this_attr->address, val); ··· 399 399 { 400 400 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 401 401 struct ade7753_state *st = iio_priv(indio_dev); 402 - unsigned long val; 402 + u16 val; 403 403 int ret; 404 404 u16 reg, t; 405 405 406 - ret = strict_strtol(buf, 10, &val); 406 + ret = kstrtou16(buf, 10, &val); 407 407 if (ret) 408 408 return ret; 409 409 if (val == 0) ··· 497 497 struct iio_dev *indio_dev; 498 498 499 499 /* setup the industrialio driver allocated elements */ 500 - indio_dev = iio_device_alloc(sizeof(*st)); 501 - if (indio_dev == NULL) { 502 - ret = -ENOMEM; 503 - goto error_ret; 504 - } 500 + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 501 + if (!indio_dev) 502 + return -ENOMEM; 505 503 /* this is only used for removal purposes */ 506 504 spi_set_drvdata(spi, indio_dev); 507 505 ··· 515 517 /* Get the device into a sane initial state */ 516 518 ret = ade7753_initial_setup(indio_dev); 517 519 if (ret) 518 - goto error_free_dev; 520 + return ret; 519 521 520 522 ret = iio_device_register(indio_dev); 521 523 if (ret) 522 - goto error_free_dev; 524 + return ret; 523 525 524 526 return 0; 525 - 526 - error_free_dev: 527 - iio_device_free(indio_dev); 528 - 529 - error_ret: 530 - return ret; 531 527 } 532 528 533 529 /* fixme, confirm ordering in this function */ ··· 531 539 532 540 iio_device_unregister(indio_dev); 533 541 ade7753_stop_device(&indio_dev->dev); 534 - iio_device_free(indio_dev); 535 542 536 543 return 0; 537 544 }
+11 -20
drivers/staging/iio/meter/ade7754.c
··· 186 186 { 187 187 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 188 188 int ret; 189 - long val; 189 + u8 val; 190 190 191 - ret = strict_strtol(buf, 10, &val); 191 + ret = kstrtou8(buf, 10, &val); 192 192 if (ret) 193 193 goto error_ret; 194 194 ret = ade7754_spi_write_reg_8(dev, this_attr->address, val); ··· 204 204 { 205 205 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 206 206 int ret; 207 - long val; 207 + u16 val; 208 208 209 - ret = strict_strtol(buf, 10, &val); 209 + ret = kstrtou16(buf, 10, &val); 210 210 if (ret) 211 211 goto error_ret; 212 212 ret = ade7754_spi_write_reg_16(dev, this_attr->address, val); ··· 419 419 { 420 420 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 421 421 struct ade7754_state *st = iio_priv(indio_dev); 422 - unsigned long val; 422 + u16 val; 423 423 int ret; 424 424 u8 reg, t; 425 425 426 - ret = strict_strtol(buf, 10, &val); 426 + ret = kstrtou16(buf, 10, &val); 427 427 if (ret) 428 428 return ret; 429 429 if (val == 0) ··· 520 520 struct iio_dev *indio_dev; 521 521 522 522 /* setup the industrialio driver allocated elements */ 523 - indio_dev = iio_device_alloc(sizeof(*st)); 524 - if (indio_dev == NULL) { 525 - ret = -ENOMEM; 526 - goto error_ret; 527 - } 523 + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 524 + if (!indio_dev) 525 + return -ENOMEM; 528 526 /* this is only used for removal purposes */ 529 527 spi_set_drvdata(spi, indio_dev); 530 528 ··· 538 540 /* Get the device into a sane initial state */ 539 541 ret = ade7754_initial_setup(indio_dev); 540 542 if (ret) 541 - goto error_free_dev; 543 + return ret; 542 544 ret = iio_device_register(indio_dev); 543 545 if (ret) 544 - goto error_free_dev; 546 + return ret; 545 547 546 548 return 0; 547 - 548 - error_free_dev: 549 - iio_device_free(indio_dev); 550 - 551 - error_ret: 552 - return ret; 553 549 } 554 550 555 551 /* fixme, confirm ordering in this function */ ··· 553 561 554 562 iio_device_unregister(indio_dev); 555 563 ade7754_stop_device(&indio_dev->dev); 556 - iio_device_free(indio_dev); 557 564 558 565 return 0; 559 566 }
+12 -20
drivers/staging/iio/meter/ade7758_core.c
··· 269 269 { 270 270 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 271 271 int ret; 272 - long val; 272 + u8 val; 273 273 274 - ret = strict_strtol(buf, 10, &val); 274 + ret = kstrtou8(buf, 10, &val); 275 275 if (ret) 276 276 goto error_ret; 277 277 ret = ade7758_spi_write_reg_8(dev, this_attr->address, val); ··· 287 287 { 288 288 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 289 289 int ret; 290 - long val; 290 + u16 val; 291 291 292 - ret = strict_strtol(buf, 10, &val); 292 + ret = kstrtou16(buf, 10, &val); 293 293 if (ret) 294 294 goto error_ret; 295 295 ret = ade7758_spi_write_reg_16(dev, this_attr->address, val); ··· 502 502 size_t len) 503 503 { 504 504 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 505 - unsigned long val; 505 + u16 val; 506 506 int ret; 507 507 u8 reg, t; 508 508 509 - ret = strict_strtol(buf, 10, &val); 509 + ret = kstrtou16(buf, 10, &val); 510 510 if (ret) 511 511 return ret; 512 512 ··· 849 849 { 850 850 int ret; 851 851 struct ade7758_state *st; 852 - struct iio_dev *indio_dev = iio_device_alloc(sizeof(*st)); 852 + struct iio_dev *indio_dev; 853 853 854 - if (indio_dev == NULL) { 855 - ret = -ENOMEM; 856 - goto error_ret; 857 - } 854 + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 855 + if (!indio_dev) 856 + return -ENOMEM; 858 857 859 858 st = iio_priv(indio_dev); 860 859 /* this is only used for removal purposes */ ··· 861 862 862 863 /* Allocate the comms buffers */ 863 864 st->rx = kcalloc(ADE7758_MAX_RX, sizeof(*st->rx), GFP_KERNEL); 864 - if (st->rx == NULL) { 865 - ret = -ENOMEM; 866 - goto error_free_dev; 867 - } 865 + if (!st->rx) 866 + return -ENOMEM; 868 867 st->tx = kcalloc(ADE7758_MAX_TX, sizeof(*st->tx), GFP_KERNEL); 869 868 if (st->tx == NULL) { 870 869 ret = -ENOMEM; ··· 917 920 kfree(st->tx); 918 921 error_free_rx: 919 922 kfree(st->rx); 920 - error_free_dev: 921 - iio_device_free(indio_dev); 922 - error_ret: 923 923 return ret; 924 924 } 925 925 ··· 932 938 ade7758_unconfigure_ring(indio_dev); 933 939 kfree(st->tx); 934 940 kfree(st->rx); 935 - 936 - iio_device_free(indio_dev); 937 941 938 942 return 0; 939 943 }
+1 -5
drivers/staging/iio/meter/ade7758_ring.c
··· 69 69 if (ade7758_spi_read_burst(indio_dev) >= 0) 70 70 *dat32 = get_unaligned_be32(&st->rx_buf[5]) & 0xFFFFFF; 71 71 72 - /* Guaranteed to be aligned with 8 byte boundary */ 73 - if (indio_dev->scan_timestamp) 74 - dat64[1] = pf->timestamp; 75 - 76 - iio_push_to_buffers(indio_dev, (u8 *)dat64); 72 + iio_push_to_buffers_with_timestamp(indio_dev, dat64, pf->timestamp); 77 73 78 74 iio_trigger_notify_done(indio_dev->trig); 79 75
+11 -19
drivers/staging/iio/meter/ade7759.c
··· 185 185 { 186 186 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 187 187 int ret; 188 - long val; 188 + u8 val; 189 189 190 - ret = strict_strtol(buf, 10, &val); 190 + ret = kstrtou8(buf, 10, &val); 191 191 if (ret) 192 192 goto error_ret; 193 193 ret = ade7759_spi_write_reg_8(dev, this_attr->address, val); ··· 203 203 { 204 204 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 205 205 int ret; 206 - long val; 206 + u16 val; 207 207 208 - ret = strict_strtol(buf, 10, &val); 208 + ret = kstrtou16(buf, 10, &val); 209 209 if (ret) 210 210 goto error_ret; 211 211 ret = ade7759_spi_write_reg_16(dev, this_attr->address, val); ··· 360 360 { 361 361 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 362 362 struct ade7759_state *st = iio_priv(indio_dev); 363 - unsigned long val; 363 + u16 val; 364 364 int ret; 365 365 u16 reg, t; 366 366 367 - ret = strict_strtol(buf, 10, &val); 367 + ret = kstrtou16(buf, 10, &val); 368 368 if (ret) 369 369 return ret; 370 370 if (val == 0) ··· 444 444 struct iio_dev *indio_dev; 445 445 446 446 /* setup the industrialio driver allocated elements */ 447 - indio_dev = iio_device_alloc(sizeof(*st)); 448 - if (indio_dev == NULL) { 449 - ret = -ENOMEM; 450 - goto error_ret; 451 - } 447 + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 448 + if (!indio_dev) 449 + return -ENOMEM; 452 450 /* this is only used for removal purposes */ 453 451 spi_set_drvdata(spi, indio_dev); 454 452 ··· 461 463 /* Get the device into a sane initial state */ 462 464 ret = ade7759_initial_setup(indio_dev); 463 465 if (ret) 464 - goto error_free_dev; 466 + return ret; 465 467 466 468 ret = iio_device_register(indio_dev); 467 469 if (ret) 468 - goto error_free_dev; 470 + return ret; 469 471 470 472 return 0; 471 - 472 - error_free_dev: 473 - iio_device_free(indio_dev); 474 - error_ret: 475 - return ret; 476 473 } 477 474 478 475 /* fixme, confirm ordering in this function */ ··· 477 484 478 485 iio_device_unregister(indio_dev); 479 486 ade7759_stop_device(&indio_dev->dev); 480 - iio_device_free(indio_dev); 481 487 482 488 return 0; 483 489 }
+1 -3
drivers/staging/iio/meter/ade7854-i2c.c
··· 208 208 struct ade7854_state *st; 209 209 struct iio_dev *indio_dev; 210 210 211 - indio_dev = iio_device_alloc(sizeof(*st)); 211 + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*st)); 212 212 if (indio_dev == NULL) 213 213 return -ENOMEM; 214 214 st = iio_priv(indio_dev); ··· 225 225 st->irq = client->irq; 226 226 227 227 ret = ade7854_probe(indio_dev, &client->dev); 228 - if (ret) 229 - iio_device_free(indio_dev); 230 228 231 229 return ret; 232 230 }
+1 -3
drivers/staging/iio/meter/ade7854-spi.c
··· 278 278 struct ade7854_state *st; 279 279 struct iio_dev *indio_dev; 280 280 281 - indio_dev = iio_device_alloc(sizeof(*st)); 281 + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 282 282 if (indio_dev == NULL) 283 283 return -ENOMEM; 284 284 st = iio_priv(indio_dev); ··· 296 296 297 297 298 298 ret = ade7854_probe(indio_dev, &spi->dev); 299 - if (ret) 300 - iio_device_free(indio_dev); 301 299 302 300 return 0; 303 301 }
+9 -13
drivers/staging/iio/meter/ade7854.c
··· 100 100 struct ade7854_state *st = iio_priv(indio_dev); 101 101 102 102 int ret; 103 - long val; 103 + u8 val; 104 104 105 - ret = strict_strtol(buf, 10, &val); 105 + ret = kstrtou8(buf, 10, &val); 106 106 if (ret) 107 107 goto error_ret; 108 108 ret = st->write_reg_8(dev, this_attr->address, val); ··· 121 121 struct ade7854_state *st = iio_priv(indio_dev); 122 122 123 123 int ret; 124 - long val; 124 + u16 val; 125 125 126 - ret = strict_strtol(buf, 10, &val); 126 + ret = kstrtou16(buf, 10, &val); 127 127 if (ret) 128 128 goto error_ret; 129 129 ret = st->write_reg_16(dev, this_attr->address, val); ··· 142 142 struct ade7854_state *st = iio_priv(indio_dev); 143 143 144 144 int ret; 145 - long val; 145 + u32 val; 146 146 147 - ret = strict_strtol(buf, 10, &val); 147 + ret = kstrtou32(buf, 10, &val); 148 148 if (ret) 149 149 goto error_ret; 150 150 ret = st->write_reg_24(dev, this_attr->address, val); ··· 163 163 struct ade7854_state *st = iio_priv(indio_dev); 164 164 165 165 int ret; 166 - long val; 166 + u32 val; 167 167 168 - ret = strict_strtol(buf, 10, &val); 168 + ret = kstrtou32(buf, 10, &val); 169 169 if (ret) 170 170 goto error_ret; 171 171 ret = st->write_reg_32(dev, this_attr->address, val); ··· 550 550 551 551 ret = iio_device_register(indio_dev); 552 552 if (ret) 553 - goto error_free_dev; 553 + return ret; 554 554 555 555 /* Get the device into a sane initial state */ 556 556 ret = ade7854_initial_setup(indio_dev); ··· 561 561 562 562 error_unreg_dev: 563 563 iio_device_unregister(indio_dev); 564 - error_free_dev: 565 - iio_device_free(indio_dev); 566 - 567 564 return ret; 568 565 } 569 566 EXPORT_SYMBOL(ade7854_probe); ··· 568 571 int ade7854_remove(struct iio_dev *indio_dev) 569 572 { 570 573 iio_device_unregister(indio_dev); 571 - iio_device_free(indio_dev); 572 574 573 575 return 0; 574 576 }
+10 -18
drivers/staging/iio/resolver/ad2s1200.c
··· 107 107 unsigned short *pins = spi->dev.platform_data; 108 108 109 109 for (pn = 0; pn < AD2S1200_PN; pn++) 110 - if (gpio_request_one(pins[pn], GPIOF_DIR_OUT, DRV_NAME)) { 111 - pr_err("%s: request gpio pin %d failed\n", 112 - DRV_NAME, pins[pn]); 113 - goto error_ret; 110 + ret = devm_gpio_request_one(&spi->dev, pins[pn], GPIOF_DIR_OUT, 111 + DRV_NAME); 112 + if (ret) { 113 + dev_err(&spi->dev, "request gpio pin %d failed\n", 114 + pins[pn]); 115 + return ret; 114 116 } 115 - indio_dev = iio_device_alloc(sizeof(*st)); 116 - if (indio_dev == NULL) { 117 - ret = -ENOMEM; 118 - goto error_ret; 119 - } 117 + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 118 + if (!indio_dev) 119 + return -ENOMEM; 120 120 spi_set_drvdata(spi, indio_dev); 121 121 st = iio_priv(indio_dev); 122 122 mutex_init(&st->lock); ··· 133 133 134 134 ret = iio_device_register(indio_dev); 135 135 if (ret) 136 - goto error_free_dev; 136 + return ret; 137 137 138 138 spi->max_speed_hz = AD2S1200_HZ; 139 139 spi->mode = SPI_MODE_3; 140 140 spi_setup(spi); 141 141 142 142 return 0; 143 - 144 - error_free_dev: 145 - iio_device_free(indio_dev); 146 - error_ret: 147 - for (--pn; pn >= 0; pn--) 148 - gpio_free(pins[pn]); 149 - return ret; 150 143 } 151 144 152 145 static int ad2s1200_remove(struct spi_device *spi) 153 146 { 154 147 iio_device_unregister(spi_get_drvdata(spi)); 155 - iio_device_free(spi_get_drvdata(spi)); 156 148 157 149 return 0; 158 150 }
+14 -20
drivers/staging/iio/resolver/ad2s1210.c
··· 206 206 size_t len) 207 207 { 208 208 struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev)); 209 - unsigned long fclkin; 209 + unsigned int fclkin; 210 210 int ret; 211 211 212 - ret = strict_strtoul(buf, 10, &fclkin); 212 + ret = kstrtouint(buf, 10, &fclkin); 213 213 if (ret) 214 214 return ret; 215 215 if (fclkin < AD2S1210_MIN_CLKIN || fclkin > AD2S1210_MAX_CLKIN) { ··· 243 243 const char *buf, size_t len) 244 244 { 245 245 struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev)); 246 - unsigned long fexcit; 246 + unsigned int fexcit; 247 247 int ret; 248 248 249 - ret = strict_strtoul(buf, 10, &fexcit); 249 + ret = kstrtouint(buf, 10, &fexcit); 250 250 if (ret < 0) 251 251 return ret; 252 252 if (fexcit < AD2S1210_MIN_EXCIT || fexcit > AD2S1210_MAX_EXCIT) { ··· 282 282 const char *buf, size_t len) 283 283 { 284 284 struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev)); 285 - unsigned long udata; 285 + unsigned char udata; 286 286 unsigned char data; 287 287 int ret; 288 288 289 - ret = strict_strtoul(buf, 16, &udata); 289 + ret = kstrtou8(buf, 16, &udata); 290 290 if (ret) 291 291 return -EINVAL; 292 292 ··· 337 337 { 338 338 struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev)); 339 339 unsigned char data; 340 - unsigned long udata; 340 + unsigned char udata; 341 341 int ret; 342 342 343 - ret = strict_strtoul(buf, 10, &udata); 343 + ret = kstrtou8(buf, 10, &udata); 344 344 if (ret || udata < 10 || udata > 16) { 345 345 pr_err("ad2s1210: resolution out of range\n"); 346 346 return -EINVAL; ··· 438 438 struct device_attribute *attr, const char *buf, size_t len) 439 439 { 440 440 struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev)); 441 - unsigned long data; 441 + unsigned char data; 442 442 int ret; 443 443 struct iio_dev_attr *iattr = to_iio_dev_attr(attr); 444 444 445 - ret = strict_strtoul(buf, 10, &data); 445 + ret = kstrtou8(buf, 10, &data); 446 446 if (ret) 447 447 return -EINVAL; 448 448 mutex_lock(&st->lock); ··· 669 669 if (spi->dev.platform_data == NULL) 670 670 return -EINVAL; 671 671 672 - indio_dev = iio_device_alloc(sizeof(*st)); 673 - if (indio_dev == NULL) { 674 - ret = -ENOMEM; 675 - goto error_ret; 676 - } 672 + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 673 + if (!indio_dev) 674 + return -ENOMEM; 677 675 st = iio_priv(indio_dev); 678 676 st->pdata = spi->dev.platform_data; 679 677 ret = ad2s1210_setup_gpios(st); 680 678 if (ret < 0) 681 - goto error_free_dev; 679 + return ret; 682 680 683 681 spi_set_drvdata(spi, indio_dev); 684 682 ··· 707 709 708 710 error_free_gpios: 709 711 ad2s1210_free_gpios(st); 710 - error_free_dev: 711 - iio_device_free(indio_dev); 712 - error_ret: 713 712 return ret; 714 713 } 715 714 ··· 716 721 717 722 iio_device_unregister(indio_dev); 718 723 ad2s1210_free_gpios(iio_priv(indio_dev)); 719 - iio_device_free(indio_dev); 720 724 721 725 return 0; 722 726 }
+4 -12
drivers/staging/iio/resolver/ad2s90.c
··· 64 64 struct ad2s90_state *st; 65 65 int ret = 0; 66 66 67 - indio_dev = iio_device_alloc(sizeof(*st)); 68 - if (indio_dev == NULL) { 69 - ret = -ENOMEM; 70 - goto error_ret; 71 - } 67 + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 68 + if (!indio_dev) 69 + return -ENOMEM; 72 70 st = iio_priv(indio_dev); 73 71 spi_set_drvdata(spi, indio_dev); 74 72 ··· 81 83 82 84 ret = iio_device_register(indio_dev); 83 85 if (ret) 84 - goto error_free_dev; 86 + return ret; 85 87 86 88 /* need 600ns between CS and the first falling edge of SCLK */ 87 89 spi->max_speed_hz = 830000; ··· 89 91 spi_setup(spi); 90 92 91 93 return 0; 92 - 93 - error_free_dev: 94 - iio_device_free(indio_dev); 95 - error_ret: 96 - return ret; 97 94 } 98 95 99 96 static int ad2s90_remove(struct spi_device *spi) 100 97 { 101 98 iio_device_unregister(spi_get_drvdata(spi)); 102 - iio_device_free(spi_get_drvdata(spi)); 103 99 104 100 return 0; 105 101 }
+9 -14
drivers/staging/iio/trigger/iio-trig-bfin-timer.c
··· 83 83 { 84 84 struct iio_trigger *trig = to_iio_trigger(dev); 85 85 struct bfin_tmr_state *st = iio_trigger_get_drvdata(trig); 86 - unsigned long val; 86 + unsigned int val; 87 87 bool enabled; 88 88 int ret; 89 89 90 - ret = strict_strtoul(buf, 10, &val); 90 + ret = kstrtouint(buf, 10, &val); 91 91 if (ret) 92 - goto error_ret; 92 + return ret; 93 93 94 94 if (val > 100000) { 95 - ret = -EINVAL; 96 - goto error_ret; 97 - } 95 + return -EINVAL; 98 96 99 97 enabled = get_enabled_gptimers() & st->t->bit; 100 98 101 99 if (enabled) 102 100 disable_gptimers(st->t->bit); 103 101 104 - if (!val) 105 - goto error_ret; 102 + if (val == 0) 103 + return count; 106 104 107 105 val = get_sclk() / val; 108 - if (val <= 4 || val <= st->duty) { 109 - ret = -EINVAL; 110 - goto error_ret; 111 - } 106 + if (val <= 4 || val <= st->duty) 107 + return -EINVAL; 112 108 113 109 set_gptimer_period(st->t->id, val); 114 110 set_gptimer_pwidth(st->t->id, val - st->duty); ··· 112 116 if (enabled) 113 117 enable_gptimers(st->t->bit); 114 118 115 - error_ret: 116 - return ret ? ret : count; 119 + return count; 117 120 } 118 121 119 122 static ssize_t iio_bfin_tmr_frequency_show(struct device *dev,
+2 -2
drivers/staging/iio/trigger/iio-trig-periodic-rtc.c
··· 53 53 { 54 54 struct iio_trigger *trig = to_iio_trigger(dev); 55 55 struct iio_prtc_trigger_info *trig_info = iio_trigger_get_drvdata(trig); 56 - unsigned long val; 56 + int val; 57 57 int ret; 58 58 59 - ret = strict_strtoul(buf, 10, &val); 59 + ret = kstrtoint(buf, 10, &val); 60 60 if (ret) 61 61 goto error_ret; 62 62
+28 -3
include/linux/iio/buffer.h
··· 36 36 * any of them not existing. 37 37 **/ 38 38 struct iio_buffer_access_funcs { 39 - int (*store_to)(struct iio_buffer *buffer, u8 *data); 39 + int (*store_to)(struct iio_buffer *buffer, const void *data); 40 40 int (*read_first_n)(struct iio_buffer *buffer, 41 41 size_t n, 42 42 char __user *buf); ··· 81 81 bool stufftoread; 82 82 const struct attribute_group *attrs; 83 83 struct list_head demux_list; 84 - unsigned char *demux_bounce; 84 + void *demux_bounce; 85 85 struct list_head buffer_list; 86 86 }; 87 87 ··· 120 120 * @indio_dev: iio_dev structure for device. 121 121 * @data: Full scan. 122 122 */ 123 - int iio_push_to_buffers(struct iio_dev *indio_dev, unsigned char *data); 123 + int iio_push_to_buffers(struct iio_dev *indio_dev, const void *data); 124 + 125 + /* 126 + * iio_push_to_buffers_with_timestamp() - push data and timestamp to buffers 127 + * @indio_dev: iio_dev structure for device. 128 + * @data: sample data 129 + * @timestamp: timestamp for the sample data 130 + * 131 + * Pushes data to the IIO device's buffers. If timestamps are enabled for the 132 + * device the function will store the supplied timestamp as the last element in 133 + * the sample data buffer before pushing it to the device buffers. The sample 134 + * data buffer needs to be large enough to hold the additional timestamp 135 + * (usually the buffer should be indio->scan_bytes bytes large). 136 + * 137 + * Returns 0 on success, a negative error code otherwise. 138 + */ 139 + static inline int iio_push_to_buffers_with_timestamp(struct iio_dev *indio_dev, 140 + void *data, int64_t timestamp) 141 + { 142 + if (indio_dev->scan_timestamp) { 143 + size_t ts_offset = indio_dev->scan_bytes / sizeof(int64_t) - 1; 144 + ((int64_t *)data)[ts_offset] = timestamp; 145 + } 146 + 147 + return iio_push_to_buffers(indio_dev, data); 148 + } 124 149 125 150 int iio_update_demux(struct iio_dev *indio_dev); 126 151
+1
include/linux/iio/common/st_sensors.h
··· 184 184 u8 wai; 185 185 char sensors_supported[ST_SENSORS_MAX_4WAI][ST_SENSORS_MAX_NAME]; 186 186 struct iio_chan_spec *ch; 187 + int num_ch; 187 188 struct st_sensor_odr odr; 188 189 struct st_sensor_power pw; 189 190 struct st_sensor_axis enable_axis;
+1 -1
include/linux/iio/consumer.h
··· 77 77 * fail. 78 78 */ 79 79 struct iio_cb_buffer *iio_channel_get_all_cb(struct device *dev, 80 - int (*cb)(u8 *data, 80 + int (*cb)(const void *data, 81 81 void *private), 82 82 void *private); 83 83 /**
+24 -11
include/linux/iio/iio.h
··· 36 36 IIO_CHAN_INFO_PHASE, 37 37 IIO_CHAN_INFO_HARDWAREGAIN, 38 38 IIO_CHAN_INFO_HYSTERESIS, 39 + IIO_CHAN_INFO_INT_TIME, 40 + }; 41 + 42 + enum iio_shared_by { 43 + IIO_SEPARATE, 44 + IIO_SHARED_BY_TYPE, 45 + IIO_SHARED_BY_DIR, 46 + IIO_SHARED_BY_ALL 39 47 }; 40 48 41 49 enum iio_endian { ··· 65 57 */ 66 58 struct iio_chan_spec_ext_info { 67 59 const char *name; 68 - bool shared; 60 + enum iio_shared_by shared; 69 61 ssize_t (*read)(struct iio_dev *, uintptr_t private, 70 62 struct iio_chan_spec const *, char *buf); 71 63 ssize_t (*write)(struct iio_dev *, uintptr_t private, ··· 133 125 #define IIO_ENUM_AVAILABLE(_name, _e) \ 134 126 { \ 135 127 .name = (_name "_available"), \ 136 - .shared = true, \ 128 + .shared = IIO_SHARED_BY_TYPE, \ 137 129 .read = iio_enum_available_read, \ 138 130 .private = (uintptr_t)(_e), \ 139 131 } ··· 154 146 * shift: Shift right by this before masking out 155 147 * realbits. 156 148 * endianness: little or big endian 157 - * @info_mask: What information is to be exported about this channel. 158 - * This includes calibbias, scale etc. 159 149 * @info_mask_separate: What information is to be exported that is specific to 160 150 * this channel. 161 151 * @info_mask_shared_by_type: What information is to be exported that is shared 162 - * by all channels of the same type. 152 + * by all channels of the same type. 153 + * @info_mask_shared_by_dir: What information is to be exported that is shared 154 + * by all channels of the same direction. 155 + * @info_mask_shared_by_all: What information is to be exported that is shared 156 + * by all channels. 163 157 * @event_mask: What events can this channel produce. 164 158 * @ext_info: Array of extended info attributes for this channel. 165 159 * The array is NULL terminated, the last element should ··· 196 186 u8 shift; 197 187 enum iio_endian endianness; 198 188 } scan_type; 199 - long info_mask; 200 189 long info_mask_separate; 201 190 long info_mask_shared_by_type; 191 + long info_mask_shared_by_dir; 192 + long info_mask_shared_by_all; 202 193 long event_mask; 203 194 const struct iio_chan_spec_ext_info *ext_info; 204 195 const char *extend_name; ··· 223 212 enum iio_chan_info_enum type) 224 213 { 225 214 return (chan->info_mask_separate & BIT(type)) | 226 - (chan->info_mask_shared_by_type & BIT(type)); 215 + (chan->info_mask_shared_by_type & BIT(type)) | 216 + (chan->info_mask_shared_by_dir & BIT(type)) | 217 + (chan->info_mask_shared_by_all & BIT(type)); 227 218 } 228 219 229 220 #define IIO_ST(si, rb, sb, sh) \ ··· 470 457 { 471 458 if (indio_dev) 472 459 put_device(&indio_dev->dev); 473 - }; 460 + } 474 461 475 462 /** 476 463 * dev_to_iio_dev() - Get IIO device struct from a device struct ··· 606 593 { 607 594 return indio_dev->currentmode 608 595 & (INDIO_BUFFER_TRIGGERED | INDIO_BUFFER_HARDWARE); 609 - }; 596 + } 610 597 611 598 /** 612 599 * iio_get_debugfs_dentry() - helper function to get the debugfs_dentry ··· 616 603 static inline struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev) 617 604 { 618 605 return indio_dev->debugfs_dentry; 619 - }; 606 + } 620 607 #else 621 608 static inline struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev) 622 609 { 623 610 return NULL; 624 - }; 611 + } 625 612 #endif 626 613 627 614 int iio_str_to_fixpoint(const char *str, int fract_mult, int *integer,
+15
include/linux/iio/sysfs.h
··· 100 100 #define IIO_CONST_ATTR_SAMP_FREQ_AVAIL(_string) \ 101 101 IIO_CONST_ATTR(sampling_frequency_available, _string) 102 102 103 + /** 104 + * IIO_DEV_ATTR_INT_TIME_AVAIL - list available integration times 105 + * @_show: output method for the attribute 106 + **/ 107 + #define IIO_DEV_ATTR_INT_TIME_AVAIL(_show) \ 108 + IIO_DEVICE_ATTR(integration_time_available, S_IRUGO, _show, NULL, 0) 109 + /** 110 + * IIO_CONST_ATTR_INT_TIME_AVAIL - list available integration times 111 + * @_string: frequency string for the attribute 112 + * 113 + * Constant version 114 + **/ 115 + #define IIO_CONST_ATTR_INT_TIME_AVAIL(_string) \ 116 + IIO_CONST_ATTR(integration_time_available, _string) 117 + 103 118 #define IIO_DEV_ATTR_TEMP_RAW(_show) \ 104 119 IIO_DEVICE_ATTR(in_temp_raw, S_IRUGO, _show, NULL, 0) 105 120
+9
include/linux/mfd/ti_am335x_tscadc.h
··· 46 46 /* Step Enable */ 47 47 #define STEPENB_MASK (0x1FFFF << 0) 48 48 #define STEPENB(val) ((val) << 0) 49 + #define ENB(val) (1 << (val)) 50 + #define STPENB_STEPENB STEPENB(0x1FFFF) 51 + #define STPENB_STEPENB_TC STEPENB(0x1FFF) 49 52 50 53 /* IRQ enable */ 51 54 #define IRQENB_HW_PEN BIT(0) 52 55 #define IRQENB_FIFO0THRES BIT(2) 56 + #define IRQENB_FIFO0OVRRUN BIT(3) 57 + #define IRQENB_FIFO0UNDRFLW BIT(4) 53 58 #define IRQENB_FIFO1THRES BIT(5) 59 + #define IRQENB_FIFO1OVRRUN BIT(6) 60 + #define IRQENB_FIFO1UNDRFLW BIT(7) 54 61 #define IRQENB_PENUP BIT(9) 55 62 56 63 /* Step Configuration */ 57 64 #define STEPCONFIG_MODE_MASK (3 << 0) 58 65 #define STEPCONFIG_MODE(val) ((val) << 0) 66 + #define STEPCONFIG_MODE_SWCNT STEPCONFIG_MODE(1) 59 67 #define STEPCONFIG_MODE_HWSYNC STEPCONFIG_MODE(2) 60 68 #define STEPCONFIG_AVG_MASK (7 << 2) 61 69 #define STEPCONFIG_AVG(val) ((val) << 2) ··· 131 123 #define ADC_CLK 3000000 132 124 #define TOTAL_STEPS 16 133 125 #define TOTAL_CHANNELS 8 126 + #define FIFO1_THRESHOLD 19 134 127 135 128 /* 136 129 * ADC runs at 3MHz, and it takes