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

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

Jonathan writes:

First round of new device support, features and cleanups for IIO in the 4.11 cycle.

It's shaping to be another fairly busy cycle. Lots more on the way!

New device support
* ads7950
- new driver supporting ads7950, ads7951, ads7952, ads7953, ads7954,
ads7955, ads7956, ads7957, ads7958, ads7959, ads7960, and ads7961 ADCs.
* cm3605
- New driver for this light sensor and proximity sensor which is an
analog part with some additional digital controls.
* hx711
- New driver.

Core new stuff
* Gravity sensor type. This is a processed datastream in which the device
will try to work out which way is down.
* Split the buffer.h file into two parts. One provides the interface to 'use'
a buffer, the second provides the internals of the buffer functionality as
needed by implementations of buffers.
- Move documentation inline so as to allow use of private: tag when
generating documentation.
- Add some utility functions for the few things that are directly done
with the buffers.
- Stop exporting functions that no-one uses outside of the core code.
- Push docs down by the code in the c file where they should have always
been.
- Fix typo in kernel-doc for buffer.
- push down some includes that were previously happening implicitly.
- stop enabling the timestamp of the dummy device.

Features and cleanups
* ad5592r
- ACPI support
* ad5593r
-ACPI support.
* ad5933
- Fix a false comment about size of a particular register.
* ad7150
- replace S_IRUGO | S_IWUSR with 0644. I'm not that keen on these patches
in general, but as it was nicely presented I took this one anyway. As a
general rule will only take these as part of a larger driver cleanup.
- don't eat an error but rather reutnr it in the write_event_config callback.
* ad7606
- replace non standard range attibute with _scale
* ade7753
- use usleep_range for short sleeps
* ade7754
- use usleep_range for short sleeps
* ade7758
- use usleep_range for short sleeps
* ade7759
- use usleep_range for short sleeps
* ade7854
- use usleep_range for short sleeps
* adis16201
- fix description
* adis16203
- fix description
- fix copyright year
* adis16209
- fix description
* adt7316
- Add braces to arms of if else statement (for consistency)
- Alignment fixes.
* axp288
- Fix up an issue with accidental overwrites of data.
* bmi160
- add deivce tables for i2c and spi to support correctly identifying the
full dt name (including manufacturer).
- device tree binding.
* bmp280
- use usleep_range for short sleeps.
* cm3232
- return error from cm3232_reg_init rather than eating it if the last write
fails.
* dummy driver
- remove a semicolor found at end of a function defintition.
* exynos-adc
- use usleep_range for short sleeps.
* hid-sensor (accel)
- Add timestamp support. The hardware can provide timestamps so lets support
them. If not fall back to timestamps estimated in kernel.
* hid-sensor (light)
- Add a duplicate ID for the light channels so as to keep existing interface
whilst also using the more standard IIO interface.
* hts221
- acpi probing
* imx25-gcq
- Add a macro call to allow this driver to be automatically loaded.
* isl29028
- reorganise code to avoid deep nesting of if statements.
- move chip test and default regs into a function suitable or sharing with
power management code.
- tidy up some code alignment.
* lidar-lite-v3
- introduce compatible strings that make it clear Garmin have consideral
friends.
* mma8452
- avoid returning signed value when unsigned is appropriate
* spmi-vadc
- Update function for generic voltage conversion to take into account that
different channels on this device should be handled differently.
- Rework code to allow per channel voltage scaling and support the standard
options for this hardware.
- Fixup three minor issues with the above patches for this part. These all
effect test builds rather than the native builds for the part, but good to
clean them up anyway.
* st_sensors
- support device matching from the ACPI DST tables.
- acpi based probing for accelerometers
- acpi based probing for pressure sensors
- Allow pressure sensors to read negative values.
- Export sampling frequency for lps25h and lps331ap.
- Add support for the old DT bindings from the period when these deivces
were often supported through windows.

Docs fixup:
* typo in sysfs-bus-iio

+2726 -681
+11 -1
Documentation/ABI/testing/sysfs-bus-iio
··· 170 170 Has all of the equivalent parameters as per voltageY. Units 171 171 after application of scale and offset are m/s^2. 172 172 173 + What: /sys/bus/iio/devices/iio:deviceX/in_gravity_x_raw 174 + What: /sys/bus/iio/devices/iio:deviceX/in_gravity_y_raw 175 + What: /sys/bus/iio/devices/iio:deviceX/in_gravity_z_raw 176 + KernelVersion: 4.11 177 + Contact: linux-iio@vger.kernel.org 178 + Description: 179 + Gravity in direction x, y or z (may be arbitrarily assigned 180 + but should match other such assignments on device). 181 + Units after application of scale and offset are m/s^2. 182 + 173 183 What: /sys/bus/iio/devices/iio:deviceX/in_anglvel_x_raw 174 184 What: /sys/bus/iio/devices/iio:deviceX/in_anglvel_y_raw 175 185 What: /sys/bus/iio/devices/iio:deviceX/in_anglvel_z_raw ··· 815 805 attribute. E.g. if in_voltage0_raw_thresh_rising_value is set to 1200 816 806 and in_voltage0_raw_thresh_rising_hysteresis is set to 50. The event 817 807 will get activated once in_voltage0_raw goes above 1200 and will become 818 - deactived again once the value falls below 1150. 808 + deactivated again once the value falls below 1150. 819 809 820 810 What: /sys/.../events/in_accel_x_raw_roc_rising_value 821 811 What: /sys/.../events/in_accel_x_raw_roc_falling_value
+1 -1
Documentation/devicetree/bindings/iio/accel/lis302.txt
··· 5 5 6 6 7 7 Required properties for the SPI bindings: 8 - - compatible: should be set to "st,lis3lv02d_spi" 8 + - compatible: should be set to "st,lis3lv02d-spi" 9 9 - reg: the chipselect index 10 10 - spi-max-frequency: maximal bus speed, should be set to 1000000 unless 11 11 constrained by external circuitry
+18
Documentation/devicetree/bindings/iio/adc/avia-hx711.txt
··· 1 + * AVIA HX711 ADC chip for weight cells 2 + Bit-banging driver 3 + 4 + Required properties: 5 + - compatible: Should be "avia,hx711" 6 + - sck-gpios: Definition of the GPIO for the clock 7 + - dout-gpios: Definition of the GPIO for data-out 8 + See Documentation/devicetree/bindings/gpio/gpio.txt 9 + - avdd-supply: Definition of the regulator used as analog supply 10 + 11 + Example: 12 + weight@0 { 13 + compatible = "avia,hx711"; 14 + sck-gpios = <&gpio3 10 GPIO_ACTIVE_HIGH>; 15 + dout-gpios = <&gpio0 7 GPIO_ACTIVE_HIGH>; 16 + avdd-suppy = <&avdd>; 17 + }; 18 +
+36
Documentation/devicetree/bindings/iio/imu/bmi160.txt
··· 1 + Bosch BMI160 - Inertial Measurement Unit with Accelerometer, Gyroscope 2 + and externally connectable Magnetometer 3 + 4 + https://www.bosch-sensortec.com/bst/products/all_products/bmi160 5 + 6 + Required properties: 7 + - compatible : should be "bosch,bmi160" 8 + - reg : the I2C address or SPI chip select number of the sensor 9 + - spi-max-frequency : set maximum clock frequency (only for SPI) 10 + 11 + Optional properties: 12 + - interrupt-parent : should be the phandle of the interrupt controller 13 + - interrupts : interrupt mapping for IRQ, must be IRQ_TYPE_LEVEL_LOW 14 + - interrupt-names : set to "INT1" if INT1 pin should be used as interrupt 15 + input, set to "INT2" if INT2 pin should be used instead 16 + 17 + Examples: 18 + 19 + bmi160@68 { 20 + compatible = "bosch,bmi160"; 21 + reg = <0x68>; 22 + 23 + interrupt-parent = <&gpio4>; 24 + interrupts = <12 IRQ_TYPE_LEVEL_LOW>; 25 + interrupt-names = "INT1"; 26 + }; 27 + 28 + bmi160@0 { 29 + compatible = "bosch,bmi160"; 30 + reg = <0>; 31 + spi-max-frequency = <10000000>; 32 + 33 + interrupt-parent = <&gpio2>; 34 + interrupts = <12 IRQ_TYPE_LEVEL_LOW>; 35 + interrupt-names = "INT2"; 36 + };
+41
Documentation/devicetree/bindings/iio/light/cm3605.txt
··· 1 + Capella Microsystems CM3605 2 + Ambient Light and Short Distance Proximity Sensor 3 + 4 + The CM3605 is an entirely analog part which however require quite a bit of 5 + software logic to interface a host operating system. 6 + 7 + This ALS and proximity sensor was one of the very first deployed in mobile 8 + handsets, notably it is used in the very first Nexus One Android phone from 9 + 2010. 10 + 11 + Required properties: 12 + - compatible: must be: "capella,cm3605" 13 + - aset-gpios: GPIO line controlling the ASET line (drive low 14 + to activate the ALS, should be flagged GPIO_ACTIVE_LOW) 15 + - interrupts: the IRQ line (such as a GPIO) that is connected to 16 + the POUT (proximity sensor out) line. The edge detection must 17 + be set to IRQ_TYPE_EDGE_BOTH so as to detect movements toward 18 + and away from the proximity sensor. 19 + - io-channels: the ADC channel used for converting the voltage from 20 + AOUT to a digital representation. 21 + - io-channel-names: must be "aout" 22 + 23 + Optional properties: 24 + - vdd-supply: regulator supplying VDD power to the component. 25 + - capella,aset-resistance-ohms: the sensitivity calibration resistance, 26 + in Ohms. Valid values are: 50000, 100000, 300000 and 600000, 27 + as these are the resistance values that we are supplied with 28 + calibration curves for. If not supplied, 100 kOhm will be assumed 29 + but it is strongly recommended to supply this. 30 + 31 + Example: 32 + 33 + cm3605 { 34 + compatible = "capella,cm3605"; 35 + vdd-supply = <&foo_reg>; 36 + aset-gpios = <&foo_gpio 1 GPIO_ACTIVE_LOW>; 37 + capella,aset-resistance-ohms = <100000>; 38 + interrupts = <1 IRQ_TYPE_EDGE_BOTH>; 39 + io-channels = <&adc 0x01>; 40 + io-channel-names = "aout"; 41 + };
+2
Documentation/devicetree/bindings/iio/st-sensors.txt
··· 27 27 Valid compatible strings: 28 28 29 29 Accelerometers: 30 + - st,lis3lv02d (deprecated, use st,lis3lv02dl-accel) 31 + - st,lis302dl-spi (deprecated, use st,lis3lv02dl-accel) 30 32 - st,lis3lv02dl-accel 31 33 - st,lsm303dlh-accel 32 34 - st,lsm303dlhc-accel
+2
Documentation/devicetree/bindings/vendor-prefixes.txt
··· 40 40 auo AU Optronics Corporation 41 41 auvidea Auvidea GmbH 42 42 avago Avago Technologies 43 + avia avia semiconductor 43 44 avic Shanghai AVIC Optoelectronics Co., Ltd. 44 45 axentia Axentia Technologies AB 45 46 axis Axis Communications AB ··· 108 107 focaltech FocalTech Systems Co.,Ltd 109 108 friendlyarm Guangzhou FriendlyARM Computer Tech Co., Ltd 110 109 fsl Freescale Semiconductor 110 + grmn Garmin Limited 111 111 ge General Electric Company 112 112 geekbuying GeekBuying 113 113 gef GE Fanuc Intelligent Platforms Embedded Systems, Inc.
+2
drivers/iio/accel/Kconfig
··· 140 140 141 141 config IIO_ST_ACCEL_I2C_3AXIS 142 142 tristate 143 + depends on !SENSORS_LIS3_I2C 143 144 depends on IIO_ST_ACCEL_3AXIS 144 145 depends on IIO_ST_SENSORS_I2C 145 146 146 147 config IIO_ST_ACCEL_SPI_3AXIS 147 148 tristate 149 + depends on !SENSORS_LIS3_SPI 148 150 depends on IIO_ST_ACCEL_3AXIS 149 151 depends on IIO_ST_SENSORS_SPI 150 152
+2 -1
drivers/iio/accel/bmc150-accel-core.c
··· 1638 1638 if (block_supported) { 1639 1639 indio_dev->modes |= INDIO_BUFFER_SOFTWARE; 1640 1640 indio_dev->info = &bmc150_accel_info_fifo; 1641 - indio_dev->buffer->attrs = bmc150_accel_fifo_attributes; 1641 + iio_buffer_set_attrs(indio_dev->buffer, 1642 + bmc150_accel_fifo_attributes); 1642 1643 } 1643 1644 } 1644 1645
+84 -20
drivers/iio/accel/hid-sensor-accel-3d.c
··· 42 42 struct hid_sensor_hub_callbacks callbacks; 43 43 struct hid_sensor_common common_attributes; 44 44 struct hid_sensor_hub_attribute_info accel[ACCEL_3D_CHANNEL_MAX]; 45 - u32 accel_val[ACCEL_3D_CHANNEL_MAX]; 45 + /* Reserve for 3 channels + padding + timestamp */ 46 + u32 accel_val[ACCEL_3D_CHANNEL_MAX + 3]; 46 47 int scale_pre_decml; 47 48 int scale_post_decml; 48 49 int scale_precision; 49 50 int value_offset; 51 + int64_t timestamp; 50 52 }; 51 53 52 54 static const u32 accel_3d_addresses[ACCEL_3D_CHANNEL_MAX] = { ··· 89 87 BIT(IIO_CHAN_INFO_SAMP_FREQ) | 90 88 BIT(IIO_CHAN_INFO_HYSTERESIS), 91 89 .scan_index = CHANNEL_SCAN_INDEX_Z, 90 + }, 91 + IIO_CHAN_SOFT_TIMESTAMP(3) 92 + }; 93 + 94 + /* Channel definitions */ 95 + static const struct iio_chan_spec gravity_channels[] = { 96 + { 97 + .type = IIO_GRAVITY, 98 + .modified = 1, 99 + .channel2 = IIO_MOD_X, 100 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 101 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | 102 + BIT(IIO_CHAN_INFO_SCALE) | 103 + BIT(IIO_CHAN_INFO_SAMP_FREQ) | 104 + BIT(IIO_CHAN_INFO_HYSTERESIS), 105 + .scan_index = CHANNEL_SCAN_INDEX_X, 106 + }, { 107 + .type = IIO_GRAVITY, 108 + .modified = 1, 109 + .channel2 = IIO_MOD_Y, 110 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 111 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | 112 + BIT(IIO_CHAN_INFO_SCALE) | 113 + BIT(IIO_CHAN_INFO_SAMP_FREQ) | 114 + BIT(IIO_CHAN_INFO_HYSTERESIS), 115 + .scan_index = CHANNEL_SCAN_INDEX_Y, 116 + }, { 117 + .type = IIO_GRAVITY, 118 + .modified = 1, 119 + .channel2 = IIO_MOD_Z, 120 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 121 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | 122 + BIT(IIO_CHAN_INFO_SCALE) | 123 + BIT(IIO_CHAN_INFO_SAMP_FREQ) | 124 + BIT(IIO_CHAN_INFO_HYSTERESIS), 125 + .scan_index = CHANNEL_SCAN_INDEX_Z, 92 126 } 93 127 }; 94 128 ··· 149 111 int report_id = -1; 150 112 u32 address; 151 113 int ret_type; 114 + struct hid_sensor_hub_device *hsdev = 115 + accel_state->common_attributes.hsdev; 152 116 153 117 *val = 0; 154 118 *val2 = 0; ··· 162 122 if (report_id >= 0) 163 123 *val = sensor_hub_input_attr_get_raw_value( 164 124 accel_state->common_attributes.hsdev, 165 - HID_USAGE_SENSOR_ACCEL_3D, address, 166 - report_id, 125 + hsdev->usage, address, report_id, 167 126 SENSOR_HUB_SYNC); 168 127 else { 169 128 *val = 0; ··· 231 192 }; 232 193 233 194 /* Function to push data to buffer */ 234 - static void hid_sensor_push_data(struct iio_dev *indio_dev, const void *data, 235 - int len) 195 + static void hid_sensor_push_data(struct iio_dev *indio_dev, void *data, 196 + int len, int64_t timestamp) 236 197 { 237 198 dev_dbg(&indio_dev->dev, "hid_sensor_push_data\n"); 238 - iio_push_to_buffers(indio_dev, data); 199 + iio_push_to_buffers_with_timestamp(indio_dev, data, timestamp); 239 200 } 240 201 241 202 /* Callback handler to send event after all samples are received and captured */ ··· 247 208 struct accel_3d_state *accel_state = iio_priv(indio_dev); 248 209 249 210 dev_dbg(&indio_dev->dev, "accel_3d_proc_event\n"); 250 - if (atomic_read(&accel_state->common_attributes.data_ready)) 211 + if (atomic_read(&accel_state->common_attributes.data_ready)) { 212 + if (!accel_state->timestamp) 213 + accel_state->timestamp = iio_get_time_ns(indio_dev); 214 + 251 215 hid_sensor_push_data(indio_dev, 252 - accel_state->accel_val, 253 - sizeof(accel_state->accel_val)); 216 + accel_state->accel_val, 217 + sizeof(accel_state->accel_val), 218 + accel_state->timestamp); 219 + 220 + accel_state->timestamp = 0; 221 + } 254 222 255 223 return 0; 256 224 } ··· 281 235 accel_state->accel_val[CHANNEL_SCAN_INDEX_X + offset] = 282 236 *(u32 *)raw_data; 283 237 ret = 0; 238 + break; 239 + case HID_USAGE_SENSOR_TIME_TIMESTAMP: 240 + accel_state->timestamp = 241 + hid_sensor_convert_timestamp( 242 + &accel_state->common_attributes, 243 + *(int64_t *)raw_data); 284 244 break; 285 245 default: 286 246 break; ··· 324 272 st->accel[2].index, st->accel[2].report_id); 325 273 326 274 st->scale_precision = hid_sensor_format_scale( 327 - HID_USAGE_SENSOR_ACCEL_3D, 275 + hsdev->usage, 328 276 &st->accel[CHANNEL_SCAN_INDEX_X], 329 277 &st->scale_pre_decml, &st->scale_post_decml); 330 278 ··· 347 295 static int hid_accel_3d_probe(struct platform_device *pdev) 348 296 { 349 297 int ret = 0; 350 - static const char *name = "accel_3d"; 298 + static const char *name; 351 299 struct iio_dev *indio_dev; 352 300 struct accel_3d_state *accel_state; 301 + const struct iio_chan_spec *channel_spec; 302 + int channel_size; 303 + 353 304 struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; 354 305 355 306 indio_dev = devm_iio_device_alloc(&pdev->dev, ··· 366 311 accel_state->common_attributes.hsdev = hsdev; 367 312 accel_state->common_attributes.pdev = pdev; 368 313 369 - ret = hid_sensor_parse_common_attributes(hsdev, 370 - HID_USAGE_SENSOR_ACCEL_3D, 314 + if (hsdev->usage == HID_USAGE_SENSOR_ACCEL_3D) { 315 + name = "accel_3d"; 316 + channel_spec = accel_3d_channels; 317 + channel_size = sizeof(accel_3d_channels); 318 + } else { 319 + name = "gravity"; 320 + channel_spec = gravity_channels; 321 + channel_size = sizeof(gravity_channels); 322 + } 323 + ret = hid_sensor_parse_common_attributes(hsdev, hsdev->usage, 371 324 &accel_state->common_attributes); 372 325 if (ret) { 373 326 dev_err(&pdev->dev, "failed to setup common attributes\n"); 374 327 return ret; 375 328 } 329 + indio_dev->channels = kmemdup(channel_spec, channel_size, GFP_KERNEL); 376 330 377 - indio_dev->channels = kmemdup(accel_3d_channels, 378 - sizeof(accel_3d_channels), GFP_KERNEL); 379 331 if (!indio_dev->channels) { 380 332 dev_err(&pdev->dev, "failed to duplicate channels\n"); 381 333 return -ENOMEM; 382 334 } 383 - 384 335 ret = accel_3d_parse_report(pdev, hsdev, 385 - (struct iio_chan_spec *)indio_dev->channels, 386 - HID_USAGE_SENSOR_ACCEL_3D, accel_state); 336 + (struct iio_chan_spec *)indio_dev->channels, 337 + hsdev->usage, accel_state); 387 338 if (ret) { 388 339 dev_err(&pdev->dev, "failed to setup attributes\n"); 389 340 goto error_free_dev_mem; ··· 424 363 accel_state->callbacks.send_event = accel_3d_proc_event; 425 364 accel_state->callbacks.capture_sample = accel_3d_capture_sample; 426 365 accel_state->callbacks.pdev = pdev; 427 - ret = sensor_hub_register_callback(hsdev, HID_USAGE_SENSOR_ACCEL_3D, 366 + ret = sensor_hub_register_callback(hsdev, hsdev->usage, 428 367 &accel_state->callbacks); 429 368 if (ret < 0) { 430 369 dev_err(&pdev->dev, "callback reg failed\n"); ··· 451 390 struct iio_dev *indio_dev = platform_get_drvdata(pdev); 452 391 struct accel_3d_state *accel_state = iio_priv(indio_dev); 453 392 454 - sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_ACCEL_3D); 393 + sensor_hub_remove_callback(hsdev, hsdev->usage); 455 394 iio_device_unregister(indio_dev); 456 395 hid_sensor_remove_trigger(&accel_state->common_attributes); 457 396 iio_triggered_buffer_cleanup(indio_dev); ··· 464 403 { 465 404 /* Format: HID-SENSOR-usage_id_in_hex_lowercase */ 466 405 .name = "HID-SENSOR-200073", 406 + }, 407 + { /* gravity sensor */ 408 + .name = "HID-SENSOR-20007b", 467 409 }, 468 410 { /* sentinel */ } 469 411 };
+2 -2
drivers/iio/accel/mma8452.c
··· 248 248 return -EINVAL; 249 249 } 250 250 251 - static int mma8452_get_odr_index(struct mma8452_data *data) 251 + static unsigned int mma8452_get_odr_index(struct mma8452_data *data) 252 252 { 253 253 return (data->ctrl_reg1 & MMA8452_CTRL_DR_MASK) >> 254 254 MMA8452_CTRL_DR_SHIFT; ··· 260 260 }; 261 261 262 262 /* Datasheet table: step time "Relationship with the ODR" (sample frequency) */ 263 - static const int mma8452_transient_time_step_us[4][8] = { 263 + static const unsigned int mma8452_transient_time_step_us[4][8] = { 264 264 { 1250, 2500, 5000, 10000, 20000, 20000, 20000, 20000 }, /* normal */ 265 265 { 1250, 2500, 5000, 10000, 20000, 80000, 80000, 80000 }, /* l p l n */ 266 266 { 1250, 2500, 2500, 2500, 2500, 2500, 2500, 2500 }, /* high res*/
+1
drivers/iio/accel/ssp_accel_sensor.c
··· 15 15 16 16 #include <linux/iio/common/ssp_sensors.h> 17 17 #include <linux/iio/iio.h> 18 + #include <linux/iio/buffer.h> 18 19 #include <linux/iio/kfifo_buf.h> 19 20 #include <linux/module.h> 20 21 #include <linux/platform_device.h>
+18
drivers/iio/accel/st_accel.h
··· 14 14 #include <linux/types.h> 15 15 #include <linux/iio/common/st_sensors.h> 16 16 17 + enum st_accel_type { 18 + LSM303DLH, 19 + LSM303DLHC, 20 + LIS3DH, 21 + LSM330D, 22 + LSM330DL, 23 + LSM330DLC, 24 + LIS331DLH, 25 + LSM303DL, 26 + LSM303DLM, 27 + LSM330, 28 + LSM303AGR, 29 + LIS2DH12, 30 + LIS3L02DQ, 31 + LNG2DM, 32 + ST_ACCEL_MAX, 33 + }; 34 + 17 35 #define H3LIS331DL_DRIVER_NAME "h3lis331dl_accel" 18 36 #define LIS3LV02DL_ACCEL_DEV_NAME "lis3lv02dl_accel" 19 37 #define LSM303DLHC_ACCEL_DEV_NAME "lsm303dlhc_accel"
+54 -24
drivers/iio/accel/st_accel_i2c.c
··· 11 11 #include <linux/kernel.h> 12 12 #include <linux/module.h> 13 13 #include <linux/slab.h> 14 + #include <linux/acpi.h> 14 15 #include <linux/i2c.h> 15 16 #include <linux/iio/iio.h> 16 17 ··· 21 20 22 21 #ifdef CONFIG_OF 23 22 static const struct of_device_id st_accel_of_match[] = { 23 + { 24 + /* An older compatible */ 25 + .compatible = "st,lis3lv02d", 26 + .data = LIS3LV02DL_ACCEL_DEV_NAME, 27 + }, 24 28 { 25 29 .compatible = "st,lis3lv02dl-accel", 26 30 .data = LIS3LV02DL_ACCEL_DEV_NAME, ··· 101 95 #define st_accel_of_match NULL 102 96 #endif 103 97 98 + #ifdef CONFIG_ACPI 99 + static const struct acpi_device_id st_accel_acpi_match[] = { 100 + {"SMO8A90", LNG2DM}, 101 + { }, 102 + }; 103 + MODULE_DEVICE_TABLE(acpi, st_accel_acpi_match); 104 + #else 105 + #define st_accel_acpi_match NULL 106 + #endif 107 + 108 + static const struct i2c_device_id st_accel_id_table[] = { 109 + { LSM303DLH_ACCEL_DEV_NAME, LSM303DLH }, 110 + { LSM303DLHC_ACCEL_DEV_NAME, LSM303DLHC }, 111 + { LIS3DH_ACCEL_DEV_NAME, LIS3DH }, 112 + { LSM330D_ACCEL_DEV_NAME, LSM330D }, 113 + { LSM330DL_ACCEL_DEV_NAME, LSM330DL }, 114 + { LSM330DLC_ACCEL_DEV_NAME, LSM330DLC }, 115 + { LIS331DLH_ACCEL_DEV_NAME, LIS331DLH }, 116 + { LSM303DL_ACCEL_DEV_NAME, LSM303DL }, 117 + { LSM303DLM_ACCEL_DEV_NAME, LSM303DLM }, 118 + { LSM330_ACCEL_DEV_NAME, LSM330 }, 119 + { LSM303AGR_ACCEL_DEV_NAME, LSM303AGR }, 120 + { LIS2DH12_ACCEL_DEV_NAME, LIS2DH12 }, 121 + { LIS3L02DQ_ACCEL_DEV_NAME, LIS3L02DQ }, 122 + { LNG2DM_ACCEL_DEV_NAME, LNG2DM }, 123 + {}, 124 + }; 125 + MODULE_DEVICE_TABLE(i2c, st_accel_id_table); 126 + 104 127 static int st_accel_i2c_probe(struct i2c_client *client, 105 128 const struct i2c_device_id *id) 106 129 { 107 130 struct iio_dev *indio_dev; 108 131 struct st_sensor_data *adata; 109 - int err; 132 + int ret; 110 133 111 134 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*adata)); 112 135 if (!indio_dev) 113 136 return -ENOMEM; 114 137 115 138 adata = iio_priv(indio_dev); 116 - st_sensors_of_i2c_probe(client, st_accel_of_match); 139 + 140 + if (client->dev.of_node) { 141 + st_sensors_of_i2c_probe(client, st_accel_of_match); 142 + } else if (ACPI_HANDLE(&client->dev)) { 143 + ret = st_sensors_match_acpi_device(&client->dev); 144 + if ((ret < 0) || (ret >= ST_ACCEL_MAX)) 145 + return -ENODEV; 146 + 147 + strncpy(client->name, st_accel_id_table[ret].name, 148 + sizeof(client->name)); 149 + client->name[sizeof(client->name) - 1] = '\0'; 150 + } else if (!id) 151 + return -ENODEV; 152 + 117 153 118 154 st_sensors_i2c_configure(indio_dev, client, adata); 119 155 120 - err = st_accel_common_probe(indio_dev); 121 - if (err < 0) 122 - return err; 156 + ret = st_accel_common_probe(indio_dev); 157 + if (ret < 0) 158 + return ret; 123 159 124 160 return 0; 125 161 } ··· 173 125 return 0; 174 126 } 175 127 176 - static const struct i2c_device_id st_accel_id_table[] = { 177 - { LSM303DLH_ACCEL_DEV_NAME }, 178 - { LSM303DLHC_ACCEL_DEV_NAME }, 179 - { LIS3DH_ACCEL_DEV_NAME }, 180 - { LSM330D_ACCEL_DEV_NAME }, 181 - { LSM330DL_ACCEL_DEV_NAME }, 182 - { LSM330DLC_ACCEL_DEV_NAME }, 183 - { LIS331DLH_ACCEL_DEV_NAME }, 184 - { LSM303DL_ACCEL_DEV_NAME }, 185 - { LSM303DLM_ACCEL_DEV_NAME }, 186 - { LSM330_ACCEL_DEV_NAME }, 187 - { LSM303AGR_ACCEL_DEV_NAME }, 188 - { LIS2DH12_ACCEL_DEV_NAME }, 189 - { LIS3L02DQ_ACCEL_DEV_NAME }, 190 - { LNG2DM_ACCEL_DEV_NAME }, 191 - {}, 192 - }; 193 - MODULE_DEVICE_TABLE(i2c, st_accel_id_table); 194 - 195 128 static struct i2c_driver st_accel_driver = { 196 129 .driver = { 197 130 .name = "st-accel-i2c", 198 131 .of_match_table = of_match_ptr(st_accel_of_match), 132 + .acpi_match_table = ACPI_PTR(st_accel_acpi_match), 199 133 }, 200 134 .probe = st_accel_i2c_probe, 201 135 .remove = st_accel_i2c_remove,
+9
drivers/iio/accel/st_accel_spi.c
··· 65 65 }; 66 66 MODULE_DEVICE_TABLE(spi, st_accel_id_table); 67 67 68 + #ifdef CONFIG_OF 69 + static const struct of_device_id lis302dl_spi_dt_ids[] = { 70 + { .compatible = "st,lis302dl-spi" }, 71 + {} 72 + }; 73 + MODULE_DEVICE_TABLE(of, lis302dl_spi_dt_ids); 74 + #endif 75 + 68 76 static struct spi_driver st_accel_driver = { 69 77 .driver = { 70 78 .name = "st-accel-spi", 79 + .of_match_table = of_match_ptr(lis302dl_spi_dt_ids), 71 80 }, 72 81 .probe = st_accel_spi_probe, 73 82 .remove = st_accel_spi_remove,
+32
drivers/iio/adc/Kconfig
··· 247 247 This driver can also be built as a module. If so, the module will be 248 248 called hi8435. 249 249 250 + config HX711 251 + tristate "AVIA HX711 ADC for weight cells" 252 + depends on GPIOLIB 253 + help 254 + If you say yes here you get support for AVIA HX711 ADC which is used 255 + for weigh cells 256 + 257 + This driver uses two GPIOs, one acts as the clock and controls the 258 + channel selection and gain, the other one is used for the measurement 259 + data 260 + 261 + Currently the raw value is read from the chip and delivered. 262 + To get an actual weight one needs to subtract the 263 + zero offset and multiply by a scale factor. 264 + This should be done in userspace. 265 + 266 + This driver can also be built as a module. If so, the module will be 267 + called hx711. 268 + 250 269 config INA2XX_ADC 251 270 tristate "Texas Instruments INA2xx Power Monitors IIO driver" 252 271 depends on I2C && !SENSORS_INA2XX ··· 567 548 568 549 This driver can also be built as a module. If so, the module will be 569 550 called ti-ads1015. 551 + 552 + config TI_ADS7950 553 + tristate "Texas Instruments ADS7950 ADC driver" 554 + depends on SPI 555 + select IIO_BUFFER 556 + select IIO_TRIGGERED_BUFFER 557 + help 558 + Say yes here to build support for Texas Instruments ADS7950, ADS7951, 559 + ADS7952, ADS7953, ADS7954, ADS7955, ADS7956, ADS7957, ADS7958, ADS7959. 560 + ADS7960, ADS7961. 561 + 562 + To compile this driver as a module, choose M here: the 563 + module will be called ti-ads7950. 570 564 571 565 config TI_ADS8688 572 566 tristate "Texas Instruments ADS8688"
+2
drivers/iio/adc/Makefile
··· 25 25 obj-$(CONFIG_EXYNOS_ADC) += exynos_adc.o 26 26 obj-$(CONFIG_FSL_MX25_ADC) += fsl-imx25-gcq.o 27 27 obj-$(CONFIG_HI8435) += hi8435.o 28 + obj-$(CONFIG_HX711) += hx711.o 28 29 obj-$(CONFIG_IMX7D_ADC) += imx7d_adc.o 29 30 obj-$(CONFIG_INA2XX_ADC) += ina2xx-adc.o 30 31 obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o ··· 52 51 obj-$(CONFIG_TI_ADC128S052) += ti-adc128s052.o 53 52 obj-$(CONFIG_TI_ADC161S626) += ti-adc161s626.o 54 53 obj-$(CONFIG_TI_ADS1015) += ti-ads1015.o 54 + obj-$(CONFIG_TI_ADS7950) += ti-ads7950.o 55 55 obj-$(CONFIG_TI_ADS8688) += ti-ads8688.o 56 56 obj-$(CONFIG_TI_AM335X_ADC) += ti_am335x_adc.o 57 57 obj-$(CONFIG_TWL4030_MADC) += twl4030-madc.o
+1 -31
drivers/iio/adc/axp288_adc.c
··· 28 28 #include <linux/iio/driver.h> 29 29 30 30 #define AXP288_ADC_EN_MASK 0xF1 31 - #define AXP288_ADC_TS_PIN_GPADC 0xF2 32 - #define AXP288_ADC_TS_PIN_ON 0xF3 33 31 34 32 enum axp288_adc_id { 35 33 AXP288_ADC_TS, ··· 121 123 return IIO_VAL_INT; 122 124 } 123 125 124 - static int axp288_adc_set_ts(struct regmap *regmap, unsigned int mode, 125 - unsigned long address) 126 - { 127 - /* channels other than GPADC do not need to switch TS pin */ 128 - if (address != AXP288_GP_ADC_H) 129 - return 0; 130 - 131 - return regmap_write(regmap, AXP288_ADC_TS_PIN_CTRL, mode); 132 - } 133 - 134 126 static int axp288_adc_read_raw(struct iio_dev *indio_dev, 135 127 struct iio_chan_spec const *chan, 136 128 int *val, int *val2, long mask) ··· 131 143 mutex_lock(&indio_dev->mlock); 132 144 switch (mask) { 133 145 case IIO_CHAN_INFO_RAW: 134 - if (axp288_adc_set_ts(info->regmap, AXP288_ADC_TS_PIN_GPADC, 135 - chan->address)) { 136 - dev_err(&indio_dev->dev, "GPADC mode\n"); 137 - ret = -EINVAL; 138 - break; 139 - } 140 146 ret = axp288_adc_read_channel(val, chan->address, info->regmap); 141 - if (axp288_adc_set_ts(info->regmap, AXP288_ADC_TS_PIN_ON, 142 - chan->address)) 143 - dev_err(&indio_dev->dev, "TS pin restore\n"); 144 147 break; 145 148 default: 146 149 ret = -EINVAL; ··· 139 160 mutex_unlock(&indio_dev->mlock); 140 161 141 162 return ret; 142 - } 143 - 144 - static int axp288_adc_set_state(struct regmap *regmap) 145 - { 146 - /* ADC should be always enabled for internal FG to function */ 147 - if (regmap_write(regmap, AXP288_ADC_TS_PIN_CTRL, AXP288_ADC_TS_PIN_ON)) 148 - return -EIO; 149 - 150 - return regmap_write(regmap, AXP20X_ADC_EN1, AXP288_ADC_EN_MASK); 151 163 } 152 164 153 165 static const struct iio_info axp288_adc_iio_info = { ··· 169 199 * Set ADC to enabled state at all time, including system suspend. 170 200 * otherwise internal fuel gauge functionality may be affected. 171 201 */ 172 - ret = axp288_adc_set_state(axp20x->regmap); 202 + ret = regmap_write(info->regmap, AXP20X_ADC_EN1, AXP288_ADC_EN_MASK); 173 203 if (ret) { 174 204 dev_err(&pdev->dev, "unable to enable ADC device\n"); 175 205 return ret;
+1 -1
drivers/iio/adc/exynos_adc.c
··· 632 632 input_report_key(info->input, BTN_TOUCH, 1); 633 633 input_sync(info->input); 634 634 635 - msleep(1); 635 + usleep_range(1000, 1100); 636 636 }; 637 637 638 638 writel(0, ADC_V1_CLRINTPNDNUP(info->regs));
+1
drivers/iio/adc/fsl-imx25-gcq.c
··· 401 401 { .compatible = "fsl,imx25-gcq", }, 402 402 { /* Sentinel */ } 403 403 }; 404 + MODULE_DEVICE_TABLE(of, mx25_gcq_ids); 404 405 405 406 static struct platform_driver mx25_gcq_driver = { 406 407 .driver = {
+532
drivers/iio/adc/hx711.c
··· 1 + /* 2 + * HX711: analog to digital converter for weight sensor module 3 + * 4 + * Copyright (c) 2016 Andreas Klinger <ak@it-klinger.de> 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License as published by 8 + * the Free Software Foundation; either version 2 of the License, or 9 + * (at your option) any later version. 10 + * 11 + * This program is distributed in the hope that it will be useful, 12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + * GNU General Public License for more details. 15 + */ 16 + #include <linux/err.h> 17 + #include <linux/kernel.h> 18 + #include <linux/module.h> 19 + #include <linux/of.h> 20 + #include <linux/platform_device.h> 21 + #include <linux/property.h> 22 + #include <linux/slab.h> 23 + #include <linux/sched.h> 24 + #include <linux/delay.h> 25 + #include <linux/iio/iio.h> 26 + #include <linux/iio/sysfs.h> 27 + #include <linux/gpio/consumer.h> 28 + #include <linux/regulator/consumer.h> 29 + 30 + /* gain to pulse and scale conversion */ 31 + #define HX711_GAIN_MAX 3 32 + 33 + struct hx711_gain_to_scale { 34 + int gain; 35 + int gain_pulse; 36 + int scale; 37 + int channel; 38 + }; 39 + 40 + /* 41 + * .scale depends on AVDD which in turn is known as soon as the regulator 42 + * is available 43 + * therefore we set .scale in hx711_probe() 44 + * 45 + * channel A in documentation is channel 0 in source code 46 + * channel B in documentation is channel 1 in source code 47 + */ 48 + static struct hx711_gain_to_scale hx711_gain_to_scale[HX711_GAIN_MAX] = { 49 + { 128, 1, 0, 0 }, 50 + { 32, 2, 0, 1 }, 51 + { 64, 3, 0, 0 } 52 + }; 53 + 54 + static int hx711_get_gain_to_pulse(int gain) 55 + { 56 + int i; 57 + 58 + for (i = 0; i < HX711_GAIN_MAX; i++) 59 + if (hx711_gain_to_scale[i].gain == gain) 60 + return hx711_gain_to_scale[i].gain_pulse; 61 + return 1; 62 + } 63 + 64 + static int hx711_get_gain_to_scale(int gain) 65 + { 66 + int i; 67 + 68 + for (i = 0; i < HX711_GAIN_MAX; i++) 69 + if (hx711_gain_to_scale[i].gain == gain) 70 + return hx711_gain_to_scale[i].scale; 71 + return 0; 72 + } 73 + 74 + static int hx711_get_scale_to_gain(int scale) 75 + { 76 + int i; 77 + 78 + for (i = 0; i < HX711_GAIN_MAX; i++) 79 + if (hx711_gain_to_scale[i].scale == scale) 80 + return hx711_gain_to_scale[i].gain; 81 + return -EINVAL; 82 + } 83 + 84 + struct hx711_data { 85 + struct device *dev; 86 + struct gpio_desc *gpiod_pd_sck; 87 + struct gpio_desc *gpiod_dout; 88 + struct regulator *reg_avdd; 89 + int gain_set; /* gain set on device */ 90 + int gain_chan_a; /* gain for channel A */ 91 + struct mutex lock; 92 + }; 93 + 94 + static int hx711_cycle(struct hx711_data *hx711_data) 95 + { 96 + int val; 97 + 98 + /* 99 + * if preempted for more then 60us while PD_SCK is high: 100 + * hx711 is going in reset 101 + * ==> measuring is false 102 + */ 103 + preempt_disable(); 104 + gpiod_set_value(hx711_data->gpiod_pd_sck, 1); 105 + val = gpiod_get_value(hx711_data->gpiod_dout); 106 + /* 107 + * here we are not waiting for 0.2 us as suggested by the datasheet, 108 + * because the oscilloscope showed in a test scenario 109 + * at least 1.15 us for PD_SCK high (T3 in datasheet) 110 + * and 0.56 us for PD_SCK low on TI Sitara with 800 MHz 111 + */ 112 + gpiod_set_value(hx711_data->gpiod_pd_sck, 0); 113 + preempt_enable(); 114 + 115 + return val; 116 + } 117 + 118 + static int hx711_read(struct hx711_data *hx711_data) 119 + { 120 + int i, ret; 121 + int value = 0; 122 + int val = gpiod_get_value(hx711_data->gpiod_dout); 123 + 124 + /* we double check if it's really down */ 125 + if (val) 126 + return -EIO; 127 + 128 + for (i = 0; i < 24; i++) { 129 + value <<= 1; 130 + ret = hx711_cycle(hx711_data); 131 + if (ret) 132 + value++; 133 + } 134 + 135 + value ^= 0x800000; 136 + 137 + for (i = 0; i < hx711_get_gain_to_pulse(hx711_data->gain_set); i++) 138 + hx711_cycle(hx711_data); 139 + 140 + return value; 141 + } 142 + 143 + static int hx711_wait_for_ready(struct hx711_data *hx711_data) 144 + { 145 + int i, val; 146 + 147 + /* 148 + * a maximum reset cycle time of 56 ms was measured. 149 + * we round it up to 100 ms 150 + */ 151 + for (i = 0; i < 100; i++) { 152 + val = gpiod_get_value(hx711_data->gpiod_dout); 153 + if (!val) 154 + break; 155 + /* sleep at least 1 ms */ 156 + msleep(1); 157 + } 158 + if (val) 159 + return -EIO; 160 + 161 + return 0; 162 + } 163 + 164 + static int hx711_reset(struct hx711_data *hx711_data) 165 + { 166 + int ret; 167 + int val = gpiod_get_value(hx711_data->gpiod_dout); 168 + 169 + if (val) { 170 + /* 171 + * an examination with the oszilloscope indicated 172 + * that the first value read after the reset is not stable 173 + * if we reset too short; 174 + * the shorter the reset cycle 175 + * the less reliable the first value after reset is; 176 + * there were no problems encountered with a value 177 + * of 10 ms or higher 178 + */ 179 + gpiod_set_value(hx711_data->gpiod_pd_sck, 1); 180 + msleep(10); 181 + gpiod_set_value(hx711_data->gpiod_pd_sck, 0); 182 + 183 + ret = hx711_wait_for_ready(hx711_data); 184 + if (ret) 185 + return ret; 186 + /* 187 + * after a reset the gain is 128 so we do a dummy read 188 + * to set the gain for the next read 189 + */ 190 + ret = hx711_read(hx711_data); 191 + if (ret < 0) 192 + return ret; 193 + 194 + /* 195 + * after a dummy read we need to wait vor readiness 196 + * for not mixing gain pulses with the clock 197 + */ 198 + ret = hx711_wait_for_ready(hx711_data); 199 + if (ret) 200 + return ret; 201 + } 202 + 203 + return val; 204 + } 205 + 206 + static int hx711_set_gain_for_channel(struct hx711_data *hx711_data, int chan) 207 + { 208 + int ret; 209 + 210 + if (chan == 0) { 211 + if (hx711_data->gain_set == 32) { 212 + hx711_data->gain_set = hx711_data->gain_chan_a; 213 + 214 + ret = hx711_read(hx711_data); 215 + if (ret < 0) 216 + return ret; 217 + 218 + ret = hx711_wait_for_ready(hx711_data); 219 + if (ret) 220 + return ret; 221 + } 222 + } else { 223 + if (hx711_data->gain_set != 32) { 224 + hx711_data->gain_set = 32; 225 + 226 + ret = hx711_read(hx711_data); 227 + if (ret < 0) 228 + return ret; 229 + 230 + ret = hx711_wait_for_ready(hx711_data); 231 + if (ret) 232 + return ret; 233 + } 234 + } 235 + 236 + return 0; 237 + } 238 + 239 + static int hx711_read_raw(struct iio_dev *indio_dev, 240 + const struct iio_chan_spec *chan, 241 + int *val, int *val2, long mask) 242 + { 243 + struct hx711_data *hx711_data = iio_priv(indio_dev); 244 + int ret; 245 + 246 + switch (mask) { 247 + case IIO_CHAN_INFO_RAW: 248 + mutex_lock(&hx711_data->lock); 249 + 250 + /* 251 + * hx711_reset() must be called from here 252 + * because it could be calling hx711_read() by itself 253 + */ 254 + if (hx711_reset(hx711_data)) { 255 + mutex_unlock(&hx711_data->lock); 256 + dev_err(hx711_data->dev, "reset failed!"); 257 + return -EIO; 258 + } 259 + 260 + ret = hx711_set_gain_for_channel(hx711_data, chan->channel); 261 + if (ret < 0) { 262 + mutex_unlock(&hx711_data->lock); 263 + return ret; 264 + } 265 + 266 + *val = hx711_read(hx711_data); 267 + 268 + mutex_unlock(&hx711_data->lock); 269 + 270 + if (*val < 0) 271 + return *val; 272 + return IIO_VAL_INT; 273 + case IIO_CHAN_INFO_SCALE: 274 + *val = 0; 275 + mutex_lock(&hx711_data->lock); 276 + 277 + *val2 = hx711_get_gain_to_scale(hx711_data->gain_set); 278 + 279 + mutex_unlock(&hx711_data->lock); 280 + 281 + return IIO_VAL_INT_PLUS_NANO; 282 + default: 283 + return -EINVAL; 284 + } 285 + } 286 + 287 + static int hx711_write_raw(struct iio_dev *indio_dev, 288 + struct iio_chan_spec const *chan, 289 + int val, 290 + int val2, 291 + long mask) 292 + { 293 + struct hx711_data *hx711_data = iio_priv(indio_dev); 294 + int ret; 295 + int gain; 296 + 297 + switch (mask) { 298 + case IIO_CHAN_INFO_SCALE: 299 + /* 300 + * a scale greater than 1 mV per LSB is not possible 301 + * with the HX711, therefore val must be 0 302 + */ 303 + if (val != 0) 304 + return -EINVAL; 305 + 306 + mutex_lock(&hx711_data->lock); 307 + 308 + gain = hx711_get_scale_to_gain(val2); 309 + if (gain < 0) { 310 + mutex_unlock(&hx711_data->lock); 311 + return gain; 312 + } 313 + 314 + if (gain != hx711_data->gain_set) { 315 + hx711_data->gain_set = gain; 316 + if (gain != 32) 317 + hx711_data->gain_chan_a = gain; 318 + 319 + ret = hx711_read(hx711_data); 320 + if (ret < 0) { 321 + mutex_unlock(&hx711_data->lock); 322 + return ret; 323 + } 324 + } 325 + 326 + mutex_unlock(&hx711_data->lock); 327 + return 0; 328 + default: 329 + return -EINVAL; 330 + } 331 + 332 + return 0; 333 + } 334 + 335 + static int hx711_write_raw_get_fmt(struct iio_dev *indio_dev, 336 + struct iio_chan_spec const *chan, 337 + long mask) 338 + { 339 + return IIO_VAL_INT_PLUS_NANO; 340 + } 341 + 342 + static ssize_t hx711_scale_available_show(struct device *dev, 343 + struct device_attribute *attr, 344 + char *buf) 345 + { 346 + struct iio_dev_attr *iio_attr = to_iio_dev_attr(attr); 347 + int channel = iio_attr->address; 348 + int i, len = 0; 349 + 350 + for (i = 0; i < HX711_GAIN_MAX; i++) 351 + if (hx711_gain_to_scale[i].channel == channel) 352 + len += sprintf(buf + len, "0.%09d ", 353 + hx711_gain_to_scale[i].scale); 354 + 355 + len += sprintf(buf + len, "\n"); 356 + 357 + return len; 358 + } 359 + 360 + static IIO_DEVICE_ATTR(in_voltage0_scale_available, S_IRUGO, 361 + hx711_scale_available_show, NULL, 0); 362 + 363 + static IIO_DEVICE_ATTR(in_voltage1_scale_available, S_IRUGO, 364 + hx711_scale_available_show, NULL, 1); 365 + 366 + static struct attribute *hx711_attributes[] = { 367 + &iio_dev_attr_in_voltage0_scale_available.dev_attr.attr, 368 + &iio_dev_attr_in_voltage1_scale_available.dev_attr.attr, 369 + NULL, 370 + }; 371 + 372 + static struct attribute_group hx711_attribute_group = { 373 + .attrs = hx711_attributes, 374 + }; 375 + 376 + static const struct iio_info hx711_iio_info = { 377 + .driver_module = THIS_MODULE, 378 + .read_raw = hx711_read_raw, 379 + .write_raw = hx711_write_raw, 380 + .write_raw_get_fmt = hx711_write_raw_get_fmt, 381 + .attrs = &hx711_attribute_group, 382 + }; 383 + 384 + static const struct iio_chan_spec hx711_chan_spec[] = { 385 + { 386 + .type = IIO_VOLTAGE, 387 + .channel = 0, 388 + .indexed = 1, 389 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 390 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), 391 + }, 392 + { 393 + .type = IIO_VOLTAGE, 394 + .channel = 1, 395 + .indexed = 1, 396 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 397 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), 398 + }, 399 + }; 400 + 401 + static int hx711_probe(struct platform_device *pdev) 402 + { 403 + struct device *dev = &pdev->dev; 404 + struct hx711_data *hx711_data; 405 + struct iio_dev *indio_dev; 406 + int ret; 407 + int i; 408 + 409 + indio_dev = devm_iio_device_alloc(dev, sizeof(struct hx711_data)); 410 + if (!indio_dev) { 411 + dev_err(dev, "failed to allocate IIO device\n"); 412 + return -ENOMEM; 413 + } 414 + 415 + hx711_data = iio_priv(indio_dev); 416 + hx711_data->dev = dev; 417 + 418 + mutex_init(&hx711_data->lock); 419 + 420 + /* 421 + * PD_SCK stands for power down and serial clock input of HX711 422 + * in the driver it is an output 423 + */ 424 + hx711_data->gpiod_pd_sck = devm_gpiod_get(dev, "sck", GPIOD_OUT_LOW); 425 + if (IS_ERR(hx711_data->gpiod_pd_sck)) { 426 + dev_err(dev, "failed to get sck-gpiod: err=%ld\n", 427 + PTR_ERR(hx711_data->gpiod_pd_sck)); 428 + return PTR_ERR(hx711_data->gpiod_pd_sck); 429 + } 430 + 431 + /* 432 + * DOUT stands for serial data output of HX711 433 + * for the driver it is an input 434 + */ 435 + hx711_data->gpiod_dout = devm_gpiod_get(dev, "dout", GPIOD_IN); 436 + if (IS_ERR(hx711_data->gpiod_dout)) { 437 + dev_err(dev, "failed to get dout-gpiod: err=%ld\n", 438 + PTR_ERR(hx711_data->gpiod_dout)); 439 + return PTR_ERR(hx711_data->gpiod_dout); 440 + } 441 + 442 + hx711_data->reg_avdd = devm_regulator_get(dev, "avdd"); 443 + if (IS_ERR(hx711_data->reg_avdd)) 444 + return PTR_ERR(hx711_data->reg_avdd); 445 + 446 + ret = regulator_enable(hx711_data->reg_avdd); 447 + if (ret < 0) 448 + return ret; 449 + 450 + /* 451 + * with 452 + * full scale differential input range: AVDD / GAIN 453 + * full scale output data: 2^24 454 + * we can say: 455 + * AVDD / GAIN = 2^24 456 + * therefore: 457 + * 1 LSB = AVDD / GAIN / 2^24 458 + * AVDD is in uV, but we need 10^-9 mV 459 + * approximately to fit into a 32 bit number: 460 + * 1 LSB = (AVDD * 100) / GAIN / 1678 [10^-9 mV] 461 + */ 462 + ret = regulator_get_voltage(hx711_data->reg_avdd); 463 + if (ret < 0) { 464 + regulator_disable(hx711_data->reg_avdd); 465 + return ret; 466 + } 467 + /* we need 10^-9 mV */ 468 + ret *= 100; 469 + 470 + for (i = 0; i < HX711_GAIN_MAX; i++) 471 + hx711_gain_to_scale[i].scale = 472 + ret / hx711_gain_to_scale[i].gain / 1678; 473 + 474 + hx711_data->gain_set = 128; 475 + hx711_data->gain_chan_a = 128; 476 + 477 + platform_set_drvdata(pdev, indio_dev); 478 + 479 + indio_dev->name = "hx711"; 480 + indio_dev->dev.parent = &pdev->dev; 481 + indio_dev->info = &hx711_iio_info; 482 + indio_dev->modes = INDIO_DIRECT_MODE; 483 + indio_dev->channels = hx711_chan_spec; 484 + indio_dev->num_channels = ARRAY_SIZE(hx711_chan_spec); 485 + 486 + ret = iio_device_register(indio_dev); 487 + if (ret < 0) { 488 + dev_err(dev, "Couldn't register the device\n"); 489 + regulator_disable(hx711_data->reg_avdd); 490 + } 491 + 492 + return ret; 493 + } 494 + 495 + static int hx711_remove(struct platform_device *pdev) 496 + { 497 + struct hx711_data *hx711_data; 498 + struct iio_dev *indio_dev; 499 + 500 + indio_dev = platform_get_drvdata(pdev); 501 + hx711_data = iio_priv(indio_dev); 502 + 503 + iio_device_unregister(indio_dev); 504 + 505 + regulator_disable(hx711_data->reg_avdd); 506 + 507 + return 0; 508 + } 509 + 510 + static const struct of_device_id of_hx711_match[] = { 511 + { .compatible = "avia,hx711", }, 512 + {}, 513 + }; 514 + 515 + MODULE_DEVICE_TABLE(of, of_hx711_match); 516 + 517 + static struct platform_driver hx711_driver = { 518 + .probe = hx711_probe, 519 + .remove = hx711_remove, 520 + .driver = { 521 + .name = "hx711-gpio", 522 + .of_match_table = of_hx711_match, 523 + }, 524 + }; 525 + 526 + module_platform_driver(hx711_driver); 527 + 528 + MODULE_AUTHOR("Andreas Klinger <ak@it-klinger.de>"); 529 + MODULE_DESCRIPTION("HX711 bitbanging driver - ADC for weight cells"); 530 + MODULE_LICENSE("GPL"); 531 + MODULE_ALIAS("platform:hx711-gpio"); 532 +
+2
drivers/iio/adc/ina2xx-adc.c
··· 22 22 23 23 #include <linux/delay.h> 24 24 #include <linux/i2c.h> 25 + #include <linux/iio/iio.h> 26 + #include <linux/iio/buffer.h> 25 27 #include <linux/iio/kfifo_buf.h> 26 28 #include <linux/iio/sysfs.h> 27 29 #include <linux/kthread.h>
+351 -126
drivers/iio/adc/qcom-spmi-vadc.c
··· 1 1 /* 2 - * Copyright (c) 2012-2014, The Linux Foundation. All rights reserved. 2 + * Copyright (c) 2012-2016, The Linux Foundation. All rights reserved. 3 3 * 4 4 * This program is free software; you can redistribute it and/or modify 5 5 * it under the terms of the GNU General Public License version 2 and ··· 84 84 #define VADC_MAX_ADC_CODE 0xa800 85 85 86 86 #define VADC_ABSOLUTE_RANGE_UV 625000 87 - #define VADC_RATIOMETRIC_RANGE_UV 1800000 87 + #define VADC_RATIOMETRIC_RANGE 1800 88 88 89 89 #define VADC_DEF_PRESCALING 0 /* 1:1 */ 90 90 #define VADC_DEF_DECIMATION 0 /* 512 */ ··· 100 100 101 101 #define KELVINMIL_CELSIUSMIL 273150 102 102 103 + #define PMI_CHG_SCALE_1 -138890 104 + #define PMI_CHG_SCALE_2 391750000000LL 105 + 103 106 #define VADC_CHAN_MIN VADC_USBIN 104 107 #define VADC_CHAN_MAX VADC_LR_MUX3_BUF_PU1_PU2_XO_THERM 108 + 109 + /** 110 + * struct vadc_map_pt - Map the graph representation for ADC channel 111 + * @x: Represent the ADC digitized code. 112 + * @y: Represent the physical data which can be temperature, voltage, 113 + * resistance. 114 + */ 115 + struct vadc_map_pt { 116 + s32 x; 117 + s32 y; 118 + }; 105 119 106 120 /* 107 121 * VADC_CALIB_ABSOLUTE: uses the 625mV and 1.25V as reference channels. ··· 162 148 * start of conversion. 163 149 * @avg_samples: ability to provide single result from the ADC 164 150 * that is an average of multiple measurements. 151 + * @scale_fn: Represents the scaling function to convert voltage 152 + * physical units desired by the client for the channel. 153 + * Referenced from enum vadc_scale_fn_type. 165 154 */ 166 155 struct vadc_channel_prop { 167 156 unsigned int channel; ··· 173 156 unsigned int prescale; 174 157 unsigned int hw_settle_time; 175 158 unsigned int avg_samples; 159 + unsigned int scale_fn; 176 160 }; 177 161 178 162 /** ··· 204 186 struct mutex lock; 205 187 }; 206 188 189 + /** 190 + * struct vadc_scale_fn - Scaling function prototype 191 + * @scale: Function pointer to one of the scaling functions 192 + * which takes the adc properties, channel properties, 193 + * and returns the physical result. 194 + */ 195 + struct vadc_scale_fn { 196 + int (*scale)(struct vadc_priv *, const struct vadc_channel_prop *, 197 + u16, int *); 198 + }; 199 + 200 + /** 201 + * enum vadc_scale_fn_type - Scaling function to convert ADC code to 202 + * physical scaled units for the channel. 203 + * SCALE_DEFAULT: Default scaling to convert raw adc code to voltage (uV). 204 + * SCALE_THERM_100K_PULLUP: Returns temperature in millidegC. 205 + * Uses a mapping table with 100K pullup. 206 + * SCALE_PMIC_THERM: Returns result in milli degree's Centigrade. 207 + * SCALE_XOTHERM: Returns XO thermistor voltage in millidegC. 208 + * SCALE_PMI_CHG_TEMP: Conversion for PMI CHG temp 209 + */ 210 + enum vadc_scale_fn_type { 211 + SCALE_DEFAULT = 0, 212 + SCALE_THERM_100K_PULLUP, 213 + SCALE_PMIC_THERM, 214 + SCALE_XOTHERM, 215 + SCALE_PMI_CHG_TEMP, 216 + }; 217 + 207 218 static const struct vadc_prescale_ratio vadc_prescale_ratios[] = { 208 219 {.num = 1, .den = 1}, 209 220 {.num = 1, .den = 3}, ··· 242 195 {.num = 1, .den = 8}, 243 196 {.num = 10, .den = 81}, 244 197 {.num = 1, .den = 10} 198 + }; 199 + 200 + /* Voltage to temperature */ 201 + static const struct vadc_map_pt adcmap_100k_104ef_104fb[] = { 202 + {1758, -40}, 203 + {1742, -35}, 204 + {1719, -30}, 205 + {1691, -25}, 206 + {1654, -20}, 207 + {1608, -15}, 208 + {1551, -10}, 209 + {1483, -5}, 210 + {1404, 0}, 211 + {1315, 5}, 212 + {1218, 10}, 213 + {1114, 15}, 214 + {1007, 20}, 215 + {900, 25}, 216 + {795, 30}, 217 + {696, 35}, 218 + {605, 40}, 219 + {522, 45}, 220 + {448, 50}, 221 + {383, 55}, 222 + {327, 60}, 223 + {278, 65}, 224 + {237, 70}, 225 + {202, 75}, 226 + {172, 80}, 227 + {146, 85}, 228 + {125, 90}, 229 + {107, 95}, 230 + {92, 100}, 231 + {79, 105}, 232 + {68, 110}, 233 + {59, 115}, 234 + {51, 120}, 235 + {44, 125} 245 236 }; 246 237 247 238 static int vadc_read(struct vadc_priv *vadc, u16 offset, u8 *data) ··· 503 418 u16 read_1, read_2; 504 419 int ret; 505 420 506 - vadc->graph[VADC_CALIB_RATIOMETRIC].dx = VADC_RATIOMETRIC_RANGE_UV; 421 + vadc->graph[VADC_CALIB_RATIOMETRIC].dx = VADC_RATIOMETRIC_RANGE; 507 422 vadc->graph[VADC_CALIB_ABSOLUTE].dx = VADC_ABSOLUTE_RANGE_UV; 508 423 509 424 prop = vadc_get_channel(vadc, VADC_REF_1250MV); ··· 553 468 return ret; 554 469 } 555 470 556 - static s32 vadc_calibrate(struct vadc_priv *vadc, 557 - const struct vadc_channel_prop *prop, u16 adc_code) 471 + static int vadc_map_voltage_temp(const struct vadc_map_pt *pts, 472 + u32 tablesize, s32 input, s64 *output) 473 + { 474 + bool descending = 1; 475 + u32 i = 0; 476 + 477 + if (!pts) 478 + return -EINVAL; 479 + 480 + /* Check if table is descending or ascending */ 481 + if (tablesize > 1) { 482 + if (pts[0].x < pts[1].x) 483 + descending = 0; 484 + } 485 + 486 + while (i < tablesize) { 487 + if ((descending) && (pts[i].x < input)) { 488 + /* table entry is less than measured*/ 489 + /* value and table is descending, stop */ 490 + break; 491 + } else if ((!descending) && 492 + (pts[i].x > input)) { 493 + /* table entry is greater than measured*/ 494 + /*value and table is ascending, stop */ 495 + break; 496 + } 497 + i++; 498 + } 499 + 500 + if (i == 0) { 501 + *output = pts[0].y; 502 + } else if (i == tablesize) { 503 + *output = pts[tablesize - 1].y; 504 + } else { 505 + /* result is between search_index and search_index-1 */ 506 + /* interpolate linearly */ 507 + *output = (((s32)((pts[i].y - pts[i - 1].y) * 508 + (input - pts[i - 1].x)) / 509 + (pts[i].x - pts[i - 1].x)) + 510 + pts[i - 1].y); 511 + } 512 + 513 + return 0; 514 + } 515 + 516 + static void vadc_scale_calib(struct vadc_priv *vadc, u16 adc_code, 517 + const struct vadc_channel_prop *prop, 518 + s64 *scale_voltage) 519 + { 520 + *scale_voltage = (adc_code - 521 + vadc->graph[prop->calibration].gnd); 522 + *scale_voltage *= vadc->graph[prop->calibration].dx; 523 + *scale_voltage = div64_s64(*scale_voltage, 524 + vadc->graph[prop->calibration].dy); 525 + if (prop->calibration == VADC_CALIB_ABSOLUTE) 526 + *scale_voltage += 527 + vadc->graph[prop->calibration].dx; 528 + 529 + if (*scale_voltage < 0) 530 + *scale_voltage = 0; 531 + } 532 + 533 + static int vadc_scale_volt(struct vadc_priv *vadc, 534 + const struct vadc_channel_prop *prop, u16 adc_code, 535 + int *result_uv) 558 536 { 559 537 const struct vadc_prescale_ratio *prescale; 560 - s64 voltage; 538 + s64 voltage = 0, result = 0; 561 539 562 - voltage = adc_code - vadc->graph[prop->calibration].gnd; 563 - voltage *= vadc->graph[prop->calibration].dx; 564 - voltage = div64_s64(voltage, vadc->graph[prop->calibration].dy); 565 - 566 - if (prop->calibration == VADC_CALIB_ABSOLUTE) 567 - voltage += vadc->graph[prop->calibration].dx; 568 - 569 - if (voltage < 0) 570 - voltage = 0; 540 + vadc_scale_calib(vadc, adc_code, prop, &voltage); 571 541 572 542 prescale = &vadc_prescale_ratios[prop->prescale]; 573 - 574 543 voltage = voltage * prescale->den; 544 + result = div64_s64(voltage, prescale->num); 545 + *result_uv = result; 575 546 576 - return div64_s64(voltage, prescale->num); 547 + return 0; 548 + } 549 + 550 + static int vadc_scale_therm(struct vadc_priv *vadc, 551 + const struct vadc_channel_prop *prop, u16 adc_code, 552 + int *result_mdec) 553 + { 554 + s64 voltage = 0, result = 0; 555 + 556 + vadc_scale_calib(vadc, adc_code, prop, &voltage); 557 + 558 + if (prop->calibration == VADC_CALIB_ABSOLUTE) 559 + voltage = div64_s64(voltage, 1000); 560 + 561 + vadc_map_voltage_temp(adcmap_100k_104ef_104fb, 562 + ARRAY_SIZE(adcmap_100k_104ef_104fb), 563 + voltage, &result); 564 + result *= 1000; 565 + *result_mdec = result; 566 + 567 + return 0; 568 + } 569 + 570 + static int vadc_scale_die_temp(struct vadc_priv *vadc, 571 + const struct vadc_channel_prop *prop, 572 + u16 adc_code, int *result_mdec) 573 + { 574 + const struct vadc_prescale_ratio *prescale; 575 + s64 voltage = 0; 576 + u64 temp; /* Temporary variable for do_div */ 577 + 578 + vadc_scale_calib(vadc, adc_code, prop, &voltage); 579 + 580 + if (voltage > 0) { 581 + prescale = &vadc_prescale_ratios[prop->prescale]; 582 + temp = voltage * prescale->den; 583 + do_div(temp, prescale->num * 2); 584 + voltage = temp; 585 + } else { 586 + voltage = 0; 587 + } 588 + 589 + voltage -= KELVINMIL_CELSIUSMIL; 590 + *result_mdec = voltage; 591 + 592 + return 0; 593 + } 594 + 595 + static int vadc_scale_chg_temp(struct vadc_priv *vadc, 596 + const struct vadc_channel_prop *prop, 597 + u16 adc_code, int *result_mdec) 598 + { 599 + const struct vadc_prescale_ratio *prescale; 600 + s64 voltage = 0, result = 0; 601 + 602 + vadc_scale_calib(vadc, adc_code, prop, &voltage); 603 + 604 + prescale = &vadc_prescale_ratios[prop->prescale]; 605 + voltage = voltage * prescale->den; 606 + voltage = div64_s64(voltage, prescale->num); 607 + voltage = ((PMI_CHG_SCALE_1) * (voltage * 2)); 608 + voltage = (voltage + PMI_CHG_SCALE_2); 609 + result = div64_s64(voltage, 1000000); 610 + *result_mdec = result; 611 + 612 + return 0; 577 613 } 578 614 579 615 static int vadc_decimation_from_dt(u32 value) ··· 742 536 return __ffs64(value); 743 537 } 744 538 539 + static struct vadc_scale_fn scale_fn[] = { 540 + [SCALE_DEFAULT] = {vadc_scale_volt}, 541 + [SCALE_THERM_100K_PULLUP] = {vadc_scale_therm}, 542 + [SCALE_PMIC_THERM] = {vadc_scale_die_temp}, 543 + [SCALE_XOTHERM] = {vadc_scale_therm}, 544 + [SCALE_PMI_CHG_TEMP] = {vadc_scale_chg_temp}, 545 + }; 546 + 745 547 static int vadc_read_raw(struct iio_dev *indio_dev, 746 548 struct iio_chan_spec const *chan, int *val, int *val2, 747 549 long mask) ··· 766 552 if (ret) 767 553 break; 768 554 769 - *val = vadc_calibrate(vadc, prop, adc_code); 555 + scale_fn[prop->scale_fn].scale(vadc, prop, adc_code, val); 770 556 771 - /* 2mV/K, return milli Celsius */ 772 - *val /= 2; 773 - *val -= KELVINMIL_CELSIUSMIL; 774 557 return IIO_VAL_INT; 775 558 case IIO_CHAN_INFO_RAW: 776 559 prop = &vadc->chan_props[chan->address]; ··· 775 564 if (ret) 776 565 break; 777 566 778 - *val = vadc_calibrate(vadc, prop, adc_code); 567 + *val = (int)adc_code; 779 568 return IIO_VAL_INT; 780 - case IIO_CHAN_INFO_SCALE: 781 - *val = 0; 782 - *val2 = 1000; 783 - return IIO_VAL_INT_PLUS_MICRO; 784 569 default: 785 570 ret = -EINVAL; 786 571 break; ··· 809 602 unsigned int prescale_index; 810 603 enum iio_chan_type type; 811 604 long info_mask; 605 + unsigned int scale_fn; 812 606 }; 813 607 814 - #define VADC_CHAN(_dname, _type, _mask, _pre) \ 608 + #define VADC_CHAN(_dname, _type, _mask, _pre, _scale) \ 609 + [VADC_##_dname] = { \ 610 + .datasheet_name = __stringify(_dname), \ 611 + .prescale_index = _pre, \ 612 + .type = _type, \ 613 + .info_mask = _mask, \ 614 + .scale_fn = _scale \ 615 + }, \ 616 + 617 + #define VADC_NO_CHAN(_dname, _type, _mask, _pre) \ 815 618 [VADC_##_dname] = { \ 816 619 .datasheet_name = __stringify(_dname), \ 817 620 .prescale_index = _pre, \ 818 621 .type = _type, \ 819 622 .info_mask = _mask \ 820 - }, \ 623 + }, 821 624 822 - #define VADC_CHAN_TEMP(_dname, _pre) \ 823 - VADC_CHAN(_dname, IIO_TEMP, BIT(IIO_CHAN_INFO_PROCESSED), _pre) \ 625 + #define VADC_CHAN_TEMP(_dname, _pre, _scale) \ 626 + VADC_CHAN(_dname, IIO_TEMP, \ 627 + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_PROCESSED), \ 628 + _pre, _scale) \ 824 629 825 - #define VADC_CHAN_VOLT(_dname, _pre) \ 630 + #define VADC_CHAN_VOLT(_dname, _pre, _scale) \ 826 631 VADC_CHAN(_dname, IIO_VOLTAGE, \ 827 - BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), \ 632 + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_PROCESSED),\ 633 + _pre, _scale) \ 634 + 635 + #define VADC_CHAN_NO_SCALE(_dname, _pre) \ 636 + VADC_NO_CHAN(_dname, IIO_VOLTAGE, \ 637 + BIT(IIO_CHAN_INFO_RAW), \ 828 638 _pre) \ 829 639 830 640 /* ··· 850 626 * gaps in the array should be treated as reserved channels. 851 627 */ 852 628 static const struct vadc_channels vadc_chans[] = { 853 - VADC_CHAN_VOLT(USBIN, 4) 854 - VADC_CHAN_VOLT(DCIN, 4) 855 - VADC_CHAN_VOLT(VCHG_SNS, 3) 856 - VADC_CHAN_VOLT(SPARE1_03, 1) 857 - VADC_CHAN_VOLT(USB_ID_MV, 1) 858 - VADC_CHAN_VOLT(VCOIN, 1) 859 - VADC_CHAN_VOLT(VBAT_SNS, 1) 860 - VADC_CHAN_VOLT(VSYS, 1) 861 - VADC_CHAN_TEMP(DIE_TEMP, 0) 862 - VADC_CHAN_VOLT(REF_625MV, 0) 863 - VADC_CHAN_VOLT(REF_1250MV, 0) 864 - VADC_CHAN_VOLT(CHG_TEMP, 0) 865 - VADC_CHAN_VOLT(SPARE1, 0) 866 - VADC_CHAN_VOLT(SPARE2, 0) 867 - VADC_CHAN_VOLT(GND_REF, 0) 868 - VADC_CHAN_VOLT(VDD_VADC, 0) 629 + VADC_CHAN_VOLT(USBIN, 4, SCALE_DEFAULT) 630 + VADC_CHAN_VOLT(DCIN, 4, SCALE_DEFAULT) 631 + VADC_CHAN_NO_SCALE(VCHG_SNS, 3) 632 + VADC_CHAN_NO_SCALE(SPARE1_03, 1) 633 + VADC_CHAN_NO_SCALE(USB_ID_MV, 1) 634 + VADC_CHAN_VOLT(VCOIN, 1, SCALE_DEFAULT) 635 + VADC_CHAN_NO_SCALE(VBAT_SNS, 1) 636 + VADC_CHAN_VOLT(VSYS, 1, SCALE_DEFAULT) 637 + VADC_CHAN_TEMP(DIE_TEMP, 0, SCALE_PMIC_THERM) 638 + VADC_CHAN_VOLT(REF_625MV, 0, SCALE_DEFAULT) 639 + VADC_CHAN_VOLT(REF_1250MV, 0, SCALE_DEFAULT) 640 + VADC_CHAN_NO_SCALE(CHG_TEMP, 0) 641 + VADC_CHAN_NO_SCALE(SPARE1, 0) 642 + VADC_CHAN_TEMP(SPARE2, 0, SCALE_PMI_CHG_TEMP) 643 + VADC_CHAN_VOLT(GND_REF, 0, SCALE_DEFAULT) 644 + VADC_CHAN_VOLT(VDD_VADC, 0, SCALE_DEFAULT) 869 645 870 - VADC_CHAN_VOLT(P_MUX1_1_1, 0) 871 - VADC_CHAN_VOLT(P_MUX2_1_1, 0) 872 - VADC_CHAN_VOLT(P_MUX3_1_1, 0) 873 - VADC_CHAN_VOLT(P_MUX4_1_1, 0) 874 - VADC_CHAN_VOLT(P_MUX5_1_1, 0) 875 - VADC_CHAN_VOLT(P_MUX6_1_1, 0) 876 - VADC_CHAN_VOLT(P_MUX7_1_1, 0) 877 - VADC_CHAN_VOLT(P_MUX8_1_1, 0) 878 - VADC_CHAN_VOLT(P_MUX9_1_1, 0) 879 - VADC_CHAN_VOLT(P_MUX10_1_1, 0) 880 - VADC_CHAN_VOLT(P_MUX11_1_1, 0) 881 - VADC_CHAN_VOLT(P_MUX12_1_1, 0) 882 - VADC_CHAN_VOLT(P_MUX13_1_1, 0) 883 - VADC_CHAN_VOLT(P_MUX14_1_1, 0) 884 - VADC_CHAN_VOLT(P_MUX15_1_1, 0) 885 - VADC_CHAN_VOLT(P_MUX16_1_1, 0) 646 + VADC_CHAN_NO_SCALE(P_MUX1_1_1, 0) 647 + VADC_CHAN_NO_SCALE(P_MUX2_1_1, 0) 648 + VADC_CHAN_NO_SCALE(P_MUX3_1_1, 0) 649 + VADC_CHAN_NO_SCALE(P_MUX4_1_1, 0) 650 + VADC_CHAN_NO_SCALE(P_MUX5_1_1, 0) 651 + VADC_CHAN_NO_SCALE(P_MUX6_1_1, 0) 652 + VADC_CHAN_NO_SCALE(P_MUX7_1_1, 0) 653 + VADC_CHAN_NO_SCALE(P_MUX8_1_1, 0) 654 + VADC_CHAN_NO_SCALE(P_MUX9_1_1, 0) 655 + VADC_CHAN_NO_SCALE(P_MUX10_1_1, 0) 656 + VADC_CHAN_NO_SCALE(P_MUX11_1_1, 0) 657 + VADC_CHAN_NO_SCALE(P_MUX12_1_1, 0) 658 + VADC_CHAN_NO_SCALE(P_MUX13_1_1, 0) 659 + VADC_CHAN_NO_SCALE(P_MUX14_1_1, 0) 660 + VADC_CHAN_NO_SCALE(P_MUX15_1_1, 0) 661 + VADC_CHAN_NO_SCALE(P_MUX16_1_1, 0) 886 662 887 - VADC_CHAN_VOLT(P_MUX1_1_3, 1) 888 - VADC_CHAN_VOLT(P_MUX2_1_3, 1) 889 - VADC_CHAN_VOLT(P_MUX3_1_3, 1) 890 - VADC_CHAN_VOLT(P_MUX4_1_3, 1) 891 - VADC_CHAN_VOLT(P_MUX5_1_3, 1) 892 - VADC_CHAN_VOLT(P_MUX6_1_3, 1) 893 - VADC_CHAN_VOLT(P_MUX7_1_3, 1) 894 - VADC_CHAN_VOLT(P_MUX8_1_3, 1) 895 - VADC_CHAN_VOLT(P_MUX9_1_3, 1) 896 - VADC_CHAN_VOLT(P_MUX10_1_3, 1) 897 - VADC_CHAN_VOLT(P_MUX11_1_3, 1) 898 - VADC_CHAN_VOLT(P_MUX12_1_3, 1) 899 - VADC_CHAN_VOLT(P_MUX13_1_3, 1) 900 - VADC_CHAN_VOLT(P_MUX14_1_3, 1) 901 - VADC_CHAN_VOLT(P_MUX15_1_3, 1) 902 - VADC_CHAN_VOLT(P_MUX16_1_3, 1) 663 + VADC_CHAN_NO_SCALE(P_MUX1_1_3, 1) 664 + VADC_CHAN_NO_SCALE(P_MUX2_1_3, 1) 665 + VADC_CHAN_NO_SCALE(P_MUX3_1_3, 1) 666 + VADC_CHAN_NO_SCALE(P_MUX4_1_3, 1) 667 + VADC_CHAN_NO_SCALE(P_MUX5_1_3, 1) 668 + VADC_CHAN_NO_SCALE(P_MUX6_1_3, 1) 669 + VADC_CHAN_NO_SCALE(P_MUX7_1_3, 1) 670 + VADC_CHAN_NO_SCALE(P_MUX8_1_3, 1) 671 + VADC_CHAN_NO_SCALE(P_MUX9_1_3, 1) 672 + VADC_CHAN_NO_SCALE(P_MUX10_1_3, 1) 673 + VADC_CHAN_NO_SCALE(P_MUX11_1_3, 1) 674 + VADC_CHAN_NO_SCALE(P_MUX12_1_3, 1) 675 + VADC_CHAN_NO_SCALE(P_MUX13_1_3, 1) 676 + VADC_CHAN_NO_SCALE(P_MUX14_1_3, 1) 677 + VADC_CHAN_NO_SCALE(P_MUX15_1_3, 1) 678 + VADC_CHAN_NO_SCALE(P_MUX16_1_3, 1) 903 679 904 - VADC_CHAN_VOLT(LR_MUX1_BAT_THERM, 0) 905 - VADC_CHAN_VOLT(LR_MUX2_BAT_ID, 0) 906 - VADC_CHAN_VOLT(LR_MUX3_XO_THERM, 0) 907 - VADC_CHAN_VOLT(LR_MUX4_AMUX_THM1, 0) 908 - VADC_CHAN_VOLT(LR_MUX5_AMUX_THM2, 0) 909 - VADC_CHAN_VOLT(LR_MUX6_AMUX_THM3, 0) 910 - VADC_CHAN_VOLT(LR_MUX7_HW_ID, 0) 911 - VADC_CHAN_VOLT(LR_MUX8_AMUX_THM4, 0) 912 - VADC_CHAN_VOLT(LR_MUX9_AMUX_THM5, 0) 913 - VADC_CHAN_VOLT(LR_MUX10_USB_ID, 0) 914 - VADC_CHAN_VOLT(AMUX_PU1, 0) 915 - VADC_CHAN_VOLT(AMUX_PU2, 0) 916 - VADC_CHAN_VOLT(LR_MUX3_BUF_XO_THERM, 0) 680 + VADC_CHAN_NO_SCALE(LR_MUX1_BAT_THERM, 0) 681 + VADC_CHAN_NO_SCALE(LR_MUX2_BAT_ID, 0) 682 + VADC_CHAN_NO_SCALE(LR_MUX3_XO_THERM, 0) 683 + VADC_CHAN_NO_SCALE(LR_MUX4_AMUX_THM1, 0) 684 + VADC_CHAN_NO_SCALE(LR_MUX5_AMUX_THM2, 0) 685 + VADC_CHAN_NO_SCALE(LR_MUX6_AMUX_THM3, 0) 686 + VADC_CHAN_NO_SCALE(LR_MUX7_HW_ID, 0) 687 + VADC_CHAN_NO_SCALE(LR_MUX8_AMUX_THM4, 0) 688 + VADC_CHAN_NO_SCALE(LR_MUX9_AMUX_THM5, 0) 689 + VADC_CHAN_NO_SCALE(LR_MUX10_USB_ID, 0) 690 + VADC_CHAN_NO_SCALE(AMUX_PU1, 0) 691 + VADC_CHAN_NO_SCALE(AMUX_PU2, 0) 692 + VADC_CHAN_NO_SCALE(LR_MUX3_BUF_XO_THERM, 0) 917 693 918 - VADC_CHAN_VOLT(LR_MUX1_PU1_BAT_THERM, 0) 919 - VADC_CHAN_VOLT(LR_MUX2_PU1_BAT_ID, 0) 920 - VADC_CHAN_VOLT(LR_MUX3_PU1_XO_THERM, 0) 921 - VADC_CHAN_VOLT(LR_MUX4_PU1_AMUX_THM1, 0) 922 - VADC_CHAN_VOLT(LR_MUX5_PU1_AMUX_THM2, 0) 923 - VADC_CHAN_VOLT(LR_MUX6_PU1_AMUX_THM3, 0) 924 - VADC_CHAN_VOLT(LR_MUX7_PU1_AMUX_HW_ID, 0) 925 - VADC_CHAN_VOLT(LR_MUX8_PU1_AMUX_THM4, 0) 926 - VADC_CHAN_VOLT(LR_MUX9_PU1_AMUX_THM5, 0) 927 - VADC_CHAN_VOLT(LR_MUX10_PU1_AMUX_USB_ID, 0) 928 - VADC_CHAN_VOLT(LR_MUX3_BUF_PU1_XO_THERM, 0) 694 + VADC_CHAN_NO_SCALE(LR_MUX1_PU1_BAT_THERM, 0) 695 + VADC_CHAN_NO_SCALE(LR_MUX2_PU1_BAT_ID, 0) 696 + VADC_CHAN_NO_SCALE(LR_MUX3_PU1_XO_THERM, 0) 697 + VADC_CHAN_TEMP(LR_MUX4_PU1_AMUX_THM1, 0, SCALE_THERM_100K_PULLUP) 698 + VADC_CHAN_TEMP(LR_MUX5_PU1_AMUX_THM2, 0, SCALE_THERM_100K_PULLUP) 699 + VADC_CHAN_TEMP(LR_MUX6_PU1_AMUX_THM3, 0, SCALE_THERM_100K_PULLUP) 700 + VADC_CHAN_NO_SCALE(LR_MUX7_PU1_AMUX_HW_ID, 0) 701 + VADC_CHAN_TEMP(LR_MUX8_PU1_AMUX_THM4, 0, SCALE_THERM_100K_PULLUP) 702 + VADC_CHAN_TEMP(LR_MUX9_PU1_AMUX_THM5, 0, SCALE_THERM_100K_PULLUP) 703 + VADC_CHAN_NO_SCALE(LR_MUX10_PU1_AMUX_USB_ID, 0) 704 + VADC_CHAN_TEMP(LR_MUX3_BUF_PU1_XO_THERM, 0, SCALE_XOTHERM) 929 705 930 - VADC_CHAN_VOLT(LR_MUX1_PU2_BAT_THERM, 0) 931 - VADC_CHAN_VOLT(LR_MUX2_PU2_BAT_ID, 0) 932 - VADC_CHAN_VOLT(LR_MUX3_PU2_XO_THERM, 0) 933 - VADC_CHAN_VOLT(LR_MUX4_PU2_AMUX_THM1, 0) 934 - VADC_CHAN_VOLT(LR_MUX5_PU2_AMUX_THM2, 0) 935 - VADC_CHAN_VOLT(LR_MUX6_PU2_AMUX_THM3, 0) 936 - VADC_CHAN_VOLT(LR_MUX7_PU2_AMUX_HW_ID, 0) 937 - VADC_CHAN_VOLT(LR_MUX8_PU2_AMUX_THM4, 0) 938 - VADC_CHAN_VOLT(LR_MUX9_PU2_AMUX_THM5, 0) 939 - VADC_CHAN_VOLT(LR_MUX10_PU2_AMUX_USB_ID, 0) 940 - VADC_CHAN_VOLT(LR_MUX3_BUF_PU2_XO_THERM, 0) 706 + VADC_CHAN_NO_SCALE(LR_MUX1_PU2_BAT_THERM, 0) 707 + VADC_CHAN_NO_SCALE(LR_MUX2_PU2_BAT_ID, 0) 708 + VADC_CHAN_NO_SCALE(LR_MUX3_PU2_XO_THERM, 0) 709 + VADC_CHAN_NO_SCALE(LR_MUX4_PU2_AMUX_THM1, 0) 710 + VADC_CHAN_NO_SCALE(LR_MUX5_PU2_AMUX_THM2, 0) 711 + VADC_CHAN_NO_SCALE(LR_MUX6_PU2_AMUX_THM3, 0) 712 + VADC_CHAN_NO_SCALE(LR_MUX7_PU2_AMUX_HW_ID, 0) 713 + VADC_CHAN_NO_SCALE(LR_MUX8_PU2_AMUX_THM4, 0) 714 + VADC_CHAN_NO_SCALE(LR_MUX9_PU2_AMUX_THM5, 0) 715 + VADC_CHAN_NO_SCALE(LR_MUX10_PU2_AMUX_USB_ID, 0) 716 + VADC_CHAN_NO_SCALE(LR_MUX3_BUF_PU2_XO_THERM, 0) 941 717 942 - VADC_CHAN_VOLT(LR_MUX1_PU1_PU2_BAT_THERM, 0) 943 - VADC_CHAN_VOLT(LR_MUX2_PU1_PU2_BAT_ID, 0) 944 - VADC_CHAN_VOLT(LR_MUX3_PU1_PU2_XO_THERM, 0) 945 - VADC_CHAN_VOLT(LR_MUX4_PU1_PU2_AMUX_THM1, 0) 946 - VADC_CHAN_VOLT(LR_MUX5_PU1_PU2_AMUX_THM2, 0) 947 - VADC_CHAN_VOLT(LR_MUX6_PU1_PU2_AMUX_THM3, 0) 948 - VADC_CHAN_VOLT(LR_MUX7_PU1_PU2_AMUX_HW_ID, 0) 949 - VADC_CHAN_VOLT(LR_MUX8_PU1_PU2_AMUX_THM4, 0) 950 - VADC_CHAN_VOLT(LR_MUX9_PU1_PU2_AMUX_THM5, 0) 951 - VADC_CHAN_VOLT(LR_MUX10_PU1_PU2_AMUX_USB_ID, 0) 952 - VADC_CHAN_VOLT(LR_MUX3_BUF_PU1_PU2_XO_THERM, 0) 718 + VADC_CHAN_NO_SCALE(LR_MUX1_PU1_PU2_BAT_THERM, 0) 719 + VADC_CHAN_NO_SCALE(LR_MUX2_PU1_PU2_BAT_ID, 0) 720 + VADC_CHAN_NO_SCALE(LR_MUX3_PU1_PU2_XO_THERM, 0) 721 + VADC_CHAN_NO_SCALE(LR_MUX4_PU1_PU2_AMUX_THM1, 0) 722 + VADC_CHAN_NO_SCALE(LR_MUX5_PU1_PU2_AMUX_THM2, 0) 723 + VADC_CHAN_NO_SCALE(LR_MUX6_PU1_PU2_AMUX_THM3, 0) 724 + VADC_CHAN_NO_SCALE(LR_MUX7_PU1_PU2_AMUX_HW_ID, 0) 725 + VADC_CHAN_NO_SCALE(LR_MUX8_PU1_PU2_AMUX_THM4, 0) 726 + VADC_CHAN_NO_SCALE(LR_MUX9_PU1_PU2_AMUX_THM5, 0) 727 + VADC_CHAN_NO_SCALE(LR_MUX10_PU1_PU2_AMUX_USB_ID, 0) 728 + VADC_CHAN_NO_SCALE(LR_MUX3_BUF_PU1_PU2_XO_THERM, 0) 953 729 }; 954 730 955 731 static int vadc_get_dt_channel_data(struct device *dev, ··· 1068 844 return ret; 1069 845 } 1070 846 847 + prop.scale_fn = vadc_chans[prop.channel].scale_fn; 1071 848 vadc->chan_props[index] = prop; 1072 849 1073 850 vadc_chan = &vadc_chans[prop.channel];
+490
drivers/iio/adc/ti-ads7950.c
··· 1 + /* 2 + * Texas Instruments ADS7950 SPI ADC driver 3 + * 4 + * Copyright 2016 David Lechner <david@lechnology.com> 5 + * 6 + * Based on iio/ad7923.c: 7 + * Copyright 2011 Analog Devices Inc 8 + * Copyright 2012 CS Systemes d'Information 9 + * 10 + * And also on hwmon/ads79xx.c 11 + * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/ 12 + * Nishanth Menon 13 + * 14 + * This program is free software; you can redistribute it and/or 15 + * modify it under the terms of the GNU General Public License as 16 + * published by the Free Software Foundation version 2. 17 + * 18 + * This program is distributed "as is" WITHOUT ANY WARRANTY of any 19 + * kind, whether express or implied; without even the implied warranty 20 + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 + * GNU General Public License for more details. 22 + */ 23 + 24 + #include <linux/bitops.h> 25 + #include <linux/device.h> 26 + #include <linux/err.h> 27 + #include <linux/interrupt.h> 28 + #include <linux/kernel.h> 29 + #include <linux/module.h> 30 + #include <linux/regulator/consumer.h> 31 + #include <linux/slab.h> 32 + #include <linux/spi/spi.h> 33 + 34 + #include <linux/iio/buffer.h> 35 + #include <linux/iio/iio.h> 36 + #include <linux/iio/sysfs.h> 37 + #include <linux/iio/trigger_consumer.h> 38 + #include <linux/iio/triggered_buffer.h> 39 + 40 + #define TI_ADS7950_CR_MANUAL BIT(12) 41 + #define TI_ADS7950_CR_WRITE BIT(11) 42 + #define TI_ADS7950_CR_CHAN(ch) ((ch) << 7) 43 + #define TI_ADS7950_CR_RANGE_5V BIT(6) 44 + 45 + #define TI_ADS7950_MAX_CHAN 16 46 + 47 + #define TI_ADS7950_TIMESTAMP_SIZE (sizeof(int64_t) / sizeof(__be16)) 48 + 49 + /* val = value, dec = left shift, bits = number of bits of the mask */ 50 + #define TI_ADS7950_EXTRACT(val, dec, bits) \ 51 + (((val) >> (dec)) & ((1 << (bits)) - 1)) 52 + 53 + struct ti_ads7950_state { 54 + struct spi_device *spi; 55 + struct spi_transfer ring_xfer[TI_ADS7950_MAX_CHAN + 2]; 56 + struct spi_transfer scan_single_xfer[3]; 57 + struct spi_message ring_msg; 58 + struct spi_message scan_single_msg; 59 + 60 + struct regulator *reg; 61 + 62 + unsigned int settings; 63 + 64 + /* 65 + * DMA (thus cache coherency maintenance) requires the 66 + * transfer buffers to live in their own cache lines. 67 + */ 68 + __be16 rx_buf[TI_ADS7950_MAX_CHAN + TI_ADS7950_TIMESTAMP_SIZE] 69 + ____cacheline_aligned; 70 + __be16 tx_buf[TI_ADS7950_MAX_CHAN]; 71 + }; 72 + 73 + struct ti_ads7950_chip_info { 74 + const struct iio_chan_spec *channels; 75 + unsigned int num_channels; 76 + }; 77 + 78 + enum ti_ads7950_id { 79 + TI_ADS7950, 80 + TI_ADS7951, 81 + TI_ADS7952, 82 + TI_ADS7953, 83 + TI_ADS7954, 84 + TI_ADS7955, 85 + TI_ADS7956, 86 + TI_ADS7957, 87 + TI_ADS7958, 88 + TI_ADS7959, 89 + TI_ADS7960, 90 + TI_ADS7961, 91 + }; 92 + 93 + #define TI_ADS7950_V_CHAN(index, bits) \ 94 + { \ 95 + .type = IIO_VOLTAGE, \ 96 + .indexed = 1, \ 97 + .channel = index, \ 98 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 99 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ 100 + .address = index, \ 101 + .datasheet_name = "CH##index", \ 102 + .scan_index = index, \ 103 + .scan_type = { \ 104 + .sign = 'u', \ 105 + .realbits = bits, \ 106 + .storagebits = 16, \ 107 + .shift = 12 - (bits), \ 108 + .endianness = IIO_BE, \ 109 + }, \ 110 + } 111 + 112 + #define DECLARE_TI_ADS7950_4_CHANNELS(name, bits) \ 113 + const struct iio_chan_spec name ## _channels[] = { \ 114 + TI_ADS7950_V_CHAN(0, bits), \ 115 + TI_ADS7950_V_CHAN(1, bits), \ 116 + TI_ADS7950_V_CHAN(2, bits), \ 117 + TI_ADS7950_V_CHAN(3, bits), \ 118 + IIO_CHAN_SOFT_TIMESTAMP(4), \ 119 + } 120 + 121 + #define DECLARE_TI_ADS7950_8_CHANNELS(name, bits) \ 122 + const struct iio_chan_spec name ## _channels[] = { \ 123 + TI_ADS7950_V_CHAN(0, bits), \ 124 + TI_ADS7950_V_CHAN(1, bits), \ 125 + TI_ADS7950_V_CHAN(2, bits), \ 126 + TI_ADS7950_V_CHAN(3, bits), \ 127 + TI_ADS7950_V_CHAN(4, bits), \ 128 + TI_ADS7950_V_CHAN(5, bits), \ 129 + TI_ADS7950_V_CHAN(6, bits), \ 130 + TI_ADS7950_V_CHAN(7, bits), \ 131 + IIO_CHAN_SOFT_TIMESTAMP(8), \ 132 + } 133 + 134 + #define DECLARE_TI_ADS7950_12_CHANNELS(name, bits) \ 135 + const struct iio_chan_spec name ## _channels[] = { \ 136 + TI_ADS7950_V_CHAN(0, bits), \ 137 + TI_ADS7950_V_CHAN(1, bits), \ 138 + TI_ADS7950_V_CHAN(2, bits), \ 139 + TI_ADS7950_V_CHAN(3, bits), \ 140 + TI_ADS7950_V_CHAN(4, bits), \ 141 + TI_ADS7950_V_CHAN(5, bits), \ 142 + TI_ADS7950_V_CHAN(6, bits), \ 143 + TI_ADS7950_V_CHAN(7, bits), \ 144 + TI_ADS7950_V_CHAN(8, bits), \ 145 + TI_ADS7950_V_CHAN(9, bits), \ 146 + TI_ADS7950_V_CHAN(10, bits), \ 147 + TI_ADS7950_V_CHAN(11, bits), \ 148 + IIO_CHAN_SOFT_TIMESTAMP(12), \ 149 + } 150 + 151 + #define DECLARE_TI_ADS7950_16_CHANNELS(name, bits) \ 152 + const struct iio_chan_spec name ## _channels[] = { \ 153 + TI_ADS7950_V_CHAN(0, bits), \ 154 + TI_ADS7950_V_CHAN(1, bits), \ 155 + TI_ADS7950_V_CHAN(2, bits), \ 156 + TI_ADS7950_V_CHAN(3, bits), \ 157 + TI_ADS7950_V_CHAN(4, bits), \ 158 + TI_ADS7950_V_CHAN(5, bits), \ 159 + TI_ADS7950_V_CHAN(6, bits), \ 160 + TI_ADS7950_V_CHAN(7, bits), \ 161 + TI_ADS7950_V_CHAN(8, bits), \ 162 + TI_ADS7950_V_CHAN(9, bits), \ 163 + TI_ADS7950_V_CHAN(10, bits), \ 164 + TI_ADS7950_V_CHAN(11, bits), \ 165 + TI_ADS7950_V_CHAN(12, bits), \ 166 + TI_ADS7950_V_CHAN(13, bits), \ 167 + TI_ADS7950_V_CHAN(14, bits), \ 168 + TI_ADS7950_V_CHAN(15, bits), \ 169 + IIO_CHAN_SOFT_TIMESTAMP(16), \ 170 + } 171 + 172 + static DECLARE_TI_ADS7950_4_CHANNELS(ti_ads7950, 12); 173 + static DECLARE_TI_ADS7950_8_CHANNELS(ti_ads7951, 12); 174 + static DECLARE_TI_ADS7950_12_CHANNELS(ti_ads7952, 12); 175 + static DECLARE_TI_ADS7950_16_CHANNELS(ti_ads7953, 12); 176 + static DECLARE_TI_ADS7950_4_CHANNELS(ti_ads7954, 10); 177 + static DECLARE_TI_ADS7950_8_CHANNELS(ti_ads7955, 10); 178 + static DECLARE_TI_ADS7950_12_CHANNELS(ti_ads7956, 10); 179 + static DECLARE_TI_ADS7950_16_CHANNELS(ti_ads7957, 10); 180 + static DECLARE_TI_ADS7950_4_CHANNELS(ti_ads7958, 8); 181 + static DECLARE_TI_ADS7950_8_CHANNELS(ti_ads7959, 8); 182 + static DECLARE_TI_ADS7950_12_CHANNELS(ti_ads7960, 8); 183 + static DECLARE_TI_ADS7950_16_CHANNELS(ti_ads7961, 8); 184 + 185 + static const struct ti_ads7950_chip_info ti_ads7950_chip_info[] = { 186 + [TI_ADS7950] = { 187 + .channels = ti_ads7950_channels, 188 + .num_channels = ARRAY_SIZE(ti_ads7950_channels), 189 + }, 190 + [TI_ADS7951] = { 191 + .channels = ti_ads7951_channels, 192 + .num_channels = ARRAY_SIZE(ti_ads7951_channels), 193 + }, 194 + [TI_ADS7952] = { 195 + .channels = ti_ads7952_channels, 196 + .num_channels = ARRAY_SIZE(ti_ads7952_channels), 197 + }, 198 + [TI_ADS7953] = { 199 + .channels = ti_ads7953_channels, 200 + .num_channels = ARRAY_SIZE(ti_ads7953_channels), 201 + }, 202 + [TI_ADS7954] = { 203 + .channels = ti_ads7954_channels, 204 + .num_channels = ARRAY_SIZE(ti_ads7954_channels), 205 + }, 206 + [TI_ADS7955] = { 207 + .channels = ti_ads7955_channels, 208 + .num_channels = ARRAY_SIZE(ti_ads7955_channels), 209 + }, 210 + [TI_ADS7956] = { 211 + .channels = ti_ads7956_channels, 212 + .num_channels = ARRAY_SIZE(ti_ads7956_channels), 213 + }, 214 + [TI_ADS7957] = { 215 + .channels = ti_ads7957_channels, 216 + .num_channels = ARRAY_SIZE(ti_ads7957_channels), 217 + }, 218 + [TI_ADS7958] = { 219 + .channels = ti_ads7958_channels, 220 + .num_channels = ARRAY_SIZE(ti_ads7958_channels), 221 + }, 222 + [TI_ADS7959] = { 223 + .channels = ti_ads7959_channels, 224 + .num_channels = ARRAY_SIZE(ti_ads7959_channels), 225 + }, 226 + [TI_ADS7960] = { 227 + .channels = ti_ads7960_channels, 228 + .num_channels = ARRAY_SIZE(ti_ads7960_channels), 229 + }, 230 + [TI_ADS7961] = { 231 + .channels = ti_ads7961_channels, 232 + .num_channels = ARRAY_SIZE(ti_ads7961_channels), 233 + }, 234 + }; 235 + 236 + /* 237 + * ti_ads7950_update_scan_mode() setup the spi transfer buffer for the new 238 + * scan mask 239 + */ 240 + static int ti_ads7950_update_scan_mode(struct iio_dev *indio_dev, 241 + const unsigned long *active_scan_mask) 242 + { 243 + struct ti_ads7950_state *st = iio_priv(indio_dev); 244 + int i, cmd, len; 245 + 246 + len = 0; 247 + for_each_set_bit(i, active_scan_mask, indio_dev->num_channels) { 248 + cmd = TI_ADS7950_CR_WRITE | TI_ADS7950_CR_CHAN(i) | st->settings; 249 + st->tx_buf[len++] = cpu_to_be16(cmd); 250 + } 251 + 252 + /* Data for the 1st channel is not returned until the 3rd transfer */ 253 + len += 2; 254 + for (i = 0; i < len; i++) { 255 + if ((i + 2) < len) 256 + st->ring_xfer[i].tx_buf = &st->tx_buf[i]; 257 + if (i >= 2) 258 + st->ring_xfer[i].rx_buf = &st->rx_buf[i - 2]; 259 + st->ring_xfer[i].len = 2; 260 + st->ring_xfer[i].cs_change = 1; 261 + } 262 + /* make sure last transfer's cs_change is not set */ 263 + st->ring_xfer[len - 1].cs_change = 0; 264 + 265 + spi_message_init_with_transfers(&st->ring_msg, st->ring_xfer, len); 266 + 267 + return 0; 268 + } 269 + 270 + static irqreturn_t ti_ads7950_trigger_handler(int irq, void *p) 271 + { 272 + struct iio_poll_func *pf = p; 273 + struct iio_dev *indio_dev = pf->indio_dev; 274 + struct ti_ads7950_state *st = iio_priv(indio_dev); 275 + int ret; 276 + 277 + ret = spi_sync(st->spi, &st->ring_msg); 278 + if (ret < 0) 279 + goto out; 280 + 281 + iio_push_to_buffers_with_timestamp(indio_dev, st->rx_buf, 282 + iio_get_time_ns(indio_dev)); 283 + 284 + out: 285 + iio_trigger_notify_done(indio_dev->trig); 286 + 287 + return IRQ_HANDLED; 288 + } 289 + 290 + static int ti_ads7950_scan_direct(struct ti_ads7950_state *st, unsigned int ch) 291 + { 292 + int ret, cmd; 293 + 294 + cmd = TI_ADS7950_CR_WRITE | TI_ADS7950_CR_CHAN(ch) | st->settings; 295 + st->tx_buf[0] = cpu_to_be16(cmd); 296 + 297 + ret = spi_sync(st->spi, &st->scan_single_msg); 298 + if (ret) 299 + return ret; 300 + 301 + return be16_to_cpu(st->rx_buf[0]); 302 + } 303 + 304 + static int ti_ads7950_get_range(struct ti_ads7950_state *st) 305 + { 306 + int vref; 307 + 308 + vref = regulator_get_voltage(st->reg); 309 + if (vref < 0) 310 + return vref; 311 + 312 + vref /= 1000; 313 + 314 + if (st->settings & TI_ADS7950_CR_RANGE_5V) 315 + vref *= 2; 316 + 317 + return vref; 318 + } 319 + 320 + static int ti_ads7950_read_raw(struct iio_dev *indio_dev, 321 + struct iio_chan_spec const *chan, 322 + int *val, int *val2, long m) 323 + { 324 + struct ti_ads7950_state *st = iio_priv(indio_dev); 325 + int ret; 326 + 327 + switch (m) { 328 + case IIO_CHAN_INFO_RAW: 329 + 330 + ret = iio_device_claim_direct_mode(indio_dev); 331 + if (ret < 0) 332 + return ret; 333 + 334 + ret = ti_ads7950_scan_direct(st, chan->address); 335 + iio_device_release_direct_mode(indio_dev); 336 + if (ret < 0) 337 + return ret; 338 + 339 + if (chan->address != TI_ADS7950_EXTRACT(ret, 12, 4)) 340 + return -EIO; 341 + 342 + *val = TI_ADS7950_EXTRACT(ret, chan->scan_type.shift, 343 + chan->scan_type.realbits); 344 + 345 + return IIO_VAL_INT; 346 + case IIO_CHAN_INFO_SCALE: 347 + ret = ti_ads7950_get_range(st); 348 + if (ret < 0) 349 + return ret; 350 + 351 + *val = ret; 352 + *val2 = (1 << chan->scan_type.realbits) - 1; 353 + 354 + return IIO_VAL_FRACTIONAL; 355 + } 356 + 357 + return -EINVAL; 358 + } 359 + 360 + static const struct iio_info ti_ads7950_info = { 361 + .read_raw = &ti_ads7950_read_raw, 362 + .update_scan_mode = ti_ads7950_update_scan_mode, 363 + .driver_module = THIS_MODULE, 364 + }; 365 + 366 + static int ti_ads7950_probe(struct spi_device *spi) 367 + { 368 + struct ti_ads7950_state *st; 369 + struct iio_dev *indio_dev; 370 + const struct ti_ads7950_chip_info *info; 371 + int ret; 372 + 373 + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 374 + if (!indio_dev) 375 + return -ENOMEM; 376 + 377 + st = iio_priv(indio_dev); 378 + 379 + spi_set_drvdata(spi, indio_dev); 380 + 381 + st->spi = spi; 382 + st->settings = TI_ADS7950_CR_MANUAL | TI_ADS7950_CR_RANGE_5V; 383 + 384 + info = &ti_ads7950_chip_info[spi_get_device_id(spi)->driver_data]; 385 + 386 + indio_dev->name = spi_get_device_id(spi)->name; 387 + indio_dev->dev.parent = &spi->dev; 388 + indio_dev->modes = INDIO_DIRECT_MODE; 389 + indio_dev->channels = info->channels; 390 + indio_dev->num_channels = info->num_channels; 391 + indio_dev->info = &ti_ads7950_info; 392 + 393 + /* 394 + * Setup default message. The sample is read at the end of the first 395 + * transfer, then it takes one full cycle to convert the sample and one 396 + * more cycle to send the value. The conversion process is driven by 397 + * the SPI clock, which is why we have 3 transfers. The middle one is 398 + * just dummy data sent while the chip is converting the sample that 399 + * was read at the end of the first transfer. 400 + */ 401 + 402 + st->scan_single_xfer[0].tx_buf = &st->tx_buf[0]; 403 + st->scan_single_xfer[0].len = 2; 404 + st->scan_single_xfer[0].cs_change = 1; 405 + st->scan_single_xfer[1].tx_buf = &st->tx_buf[0]; 406 + st->scan_single_xfer[1].len = 2; 407 + st->scan_single_xfer[1].cs_change = 1; 408 + st->scan_single_xfer[2].rx_buf = &st->rx_buf[0]; 409 + st->scan_single_xfer[2].len = 2; 410 + 411 + spi_message_init_with_transfers(&st->scan_single_msg, 412 + st->scan_single_xfer, 3); 413 + 414 + st->reg = devm_regulator_get(&spi->dev, "refin"); 415 + if (IS_ERR(st->reg)) { 416 + dev_err(&spi->dev, "Failed get get regulator \"refin\"\n"); 417 + return PTR_ERR(st->reg); 418 + } 419 + 420 + ret = regulator_enable(st->reg); 421 + if (ret) { 422 + dev_err(&spi->dev, "Failed to enable regulator \"refin\"\n"); 423 + return ret; 424 + } 425 + 426 + ret = iio_triggered_buffer_setup(indio_dev, NULL, 427 + &ti_ads7950_trigger_handler, NULL); 428 + if (ret) { 429 + dev_err(&spi->dev, "Failed to setup triggered buffer\n"); 430 + goto error_disable_reg; 431 + } 432 + 433 + ret = iio_device_register(indio_dev); 434 + if (ret) { 435 + dev_err(&spi->dev, "Failed to register iio device\n"); 436 + goto error_cleanup_ring; 437 + } 438 + 439 + return 0; 440 + 441 + error_cleanup_ring: 442 + iio_triggered_buffer_cleanup(indio_dev); 443 + error_disable_reg: 444 + regulator_disable(st->reg); 445 + 446 + return ret; 447 + } 448 + 449 + static int ti_ads7950_remove(struct spi_device *spi) 450 + { 451 + struct iio_dev *indio_dev = spi_get_drvdata(spi); 452 + struct ti_ads7950_state *st = iio_priv(indio_dev); 453 + 454 + iio_device_unregister(indio_dev); 455 + iio_triggered_buffer_cleanup(indio_dev); 456 + regulator_disable(st->reg); 457 + 458 + return 0; 459 + } 460 + 461 + static const struct spi_device_id ti_ads7950_id[] = { 462 + {"ti-ads7950", TI_ADS7950}, 463 + {"ti-ads7951", TI_ADS7951}, 464 + {"ti-ads7952", TI_ADS7952}, 465 + {"ti-ads7953", TI_ADS7953}, 466 + {"ti-ads7954", TI_ADS7954}, 467 + {"ti-ads7955", TI_ADS7955}, 468 + {"ti-ads7956", TI_ADS7956}, 469 + {"ti-ads7957", TI_ADS7957}, 470 + {"ti-ads7958", TI_ADS7958}, 471 + {"ti-ads7959", TI_ADS7959}, 472 + {"ti-ads7960", TI_ADS7960}, 473 + {"ti-ads7961", TI_ADS7961}, 474 + { } 475 + }; 476 + MODULE_DEVICE_TABLE(spi, ti_ads7950_id); 477 + 478 + static struct spi_driver ti_ads7950_driver = { 479 + .driver = { 480 + .name = "ti-ads7950", 481 + }, 482 + .probe = ti_ads7950_probe, 483 + .remove = ti_ads7950_remove, 484 + .id_table = ti_ads7950_id, 485 + }; 486 + module_spi_driver(ti_ads7950_driver); 487 + 488 + MODULE_AUTHOR("David Lechner <david@lechnology.com>"); 489 + MODULE_DESCRIPTION("TI TI_ADS7950 ADC"); 490 + MODULE_LICENSE("GPL v2");
+2 -1
drivers/iio/buffer/industrialio-buffer-cb.c
··· 10 10 #include <linux/slab.h> 11 11 #include <linux/err.h> 12 12 #include <linux/export.h> 13 - #include <linux/iio/buffer.h> 13 + #include <linux/iio/iio.h> 14 + #include <linux/iio/buffer_impl.h> 14 15 #include <linux/iio/consumer.h> 15 16 16 17 struct iio_cb_buffer {
+3
drivers/iio/buffer/kfifo_buf.c
··· 5 5 #include <linux/workqueue.h> 6 6 #include <linux/kfifo.h> 7 7 #include <linux/mutex.h> 8 + #include <linux/iio/iio.h> 9 + #include <linux/iio/buffer.h> 8 10 #include <linux/iio/kfifo_buf.h> 11 + #include <linux/iio/buffer_impl.h> 9 12 #include <linux/sched.h> 10 13 #include <linux/poll.h> 11 14
+31 -5
drivers/iio/common/hid-sensors/hid-sensor-attributes.c
··· 58 58 59 59 {HID_USAGE_SENSOR_PRESSURE, 0, 100, 0}, 60 60 {HID_USAGE_SENSOR_PRESSURE, HID_USAGE_SENSOR_UNITS_PASCAL, 0, 1000000}, 61 + 62 + {HID_USAGE_SENSOR_TIME_TIMESTAMP, 0, 1000000000, 0}, 63 + {HID_USAGE_SENSOR_TIME_TIMESTAMP, HID_USAGE_SENSOR_UNITS_MILLISECOND, 64 + 1000000, 0}, 61 65 }; 62 66 63 67 static int pow_10(unsigned power) ··· 350 346 } 351 347 EXPORT_SYMBOL(hid_sensor_format_scale); 352 348 349 + int64_t hid_sensor_convert_timestamp(struct hid_sensor_common *st, 350 + int64_t raw_value) 351 + { 352 + return st->timestamp_ns_scale * raw_value; 353 + } 354 + EXPORT_SYMBOL(hid_sensor_convert_timestamp); 355 + 353 356 static 354 357 int hid_sensor_get_reporting_interval(struct hid_sensor_hub_device *hsdev, 355 358 u32 usage_id, ··· 378 367 struct hid_sensor_common *st) 379 368 { 380 369 370 + struct hid_sensor_hub_attribute_info timestamp; 381 371 382 372 hid_sensor_get_reporting_interval(hsdev, usage_id, st); 383 373 ··· 397 385 HID_USAGE_SENSOR_PROP_SENSITIVITY_ABS, 398 386 &st->sensitivity); 399 387 400 - hid_dbg(hsdev->hdev, "common attributes: %x:%x, %x:%x, %x:%x %x:%x\n", 401 - st->poll.index, st->poll.report_id, 402 - st->report_state.index, st->report_state.report_id, 403 - st->power_state.index, st->power_state.report_id, 404 - st->sensitivity.index, st->sensitivity.report_id); 388 + sensor_hub_input_get_attribute_info(hsdev, 389 + HID_INPUT_REPORT, usage_id, 390 + HID_USAGE_SENSOR_TIME_TIMESTAMP, 391 + &timestamp); 392 + if (timestamp.index >= 0 && timestamp.report_id) { 393 + int val0, val1; 394 + 395 + hid_sensor_format_scale(HID_USAGE_SENSOR_TIME_TIMESTAMP, 396 + &timestamp, &val0, &val1); 397 + st->timestamp_ns_scale = val0; 398 + } else 399 + st->timestamp_ns_scale = 1000000000; 400 + 401 + hid_dbg(hsdev->hdev, "common attributes: %x:%x, %x:%x, %x:%x %x:%x %x:%x\n", 402 + st->poll.index, st->poll.report_id, 403 + st->report_state.index, st->report_state.report_id, 404 + st->power_state.index, st->power_state.report_id, 405 + st->sensitivity.index, st->sensitivity.report_id, 406 + timestamp.index, timestamp.report_id); 405 407 406 408 return 0; 407 409 }
+1
drivers/iio/common/ssp_sensors/ssp_iio.c
··· 14 14 */ 15 15 16 16 #include <linux/iio/common/ssp_sensors.h> 17 + #include <linux/iio/buffer.h> 17 18 #include <linux/iio/kfifo_buf.h> 18 19 #include <linux/module.h> 19 20 #include <linux/slab.h>
+20
drivers/iio/common/st_sensors/st_sensors_i2c.c
··· 13 13 #include <linux/slab.h> 14 14 #include <linux/iio/iio.h> 15 15 #include <linux/of_device.h> 16 + #include <linux/acpi.h> 16 17 17 18 #include <linux/iio/common/st_sensors_i2c.h> 18 19 ··· 106 105 client->name[sizeof(client->name) - 1] = '\0'; 107 106 } 108 107 EXPORT_SYMBOL(st_sensors_of_i2c_probe); 108 + #endif 109 + 110 + #ifdef CONFIG_ACPI 111 + int st_sensors_match_acpi_device(struct device *dev) 112 + { 113 + const struct acpi_device_id *acpi_id; 114 + kernel_ulong_t driver_data = 0; 115 + 116 + if (ACPI_HANDLE(dev)) { 117 + acpi_id = acpi_match_device(dev->driver->acpi_match_table, dev); 118 + if (!acpi_id) { 119 + dev_err(dev, "No driver data\n"); 120 + return -EINVAL; 121 + } 122 + driver_data = acpi_id->driver_data; 123 + } 124 + return driver_data; 125 + } 126 + EXPORT_SYMBOL(st_sensors_match_acpi_device); 109 127 #endif 110 128 111 129 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
+8
drivers/iio/dac/ad5592r.c
··· 13 13 #include <linux/module.h> 14 14 #include <linux/of.h> 15 15 #include <linux/spi/spi.h> 16 + #include <linux/acpi.h> 16 17 17 18 #define AD5592R_GPIO_READBACK_EN BIT(10) 18 19 #define AD5592R_LDAC_READBACK_EN BIT(6) ··· 149 148 }; 150 149 MODULE_DEVICE_TABLE(of, ad5592r_of_match); 151 150 151 + static const struct acpi_device_id ad5592r_acpi_match[] = { 152 + {"ADS5592", }, 153 + { }, 154 + }; 155 + MODULE_DEVICE_TABLE(acpi, ad5592r_acpi_match); 156 + 152 157 static struct spi_driver ad5592r_spi_driver = { 153 158 .driver = { 154 159 .name = "ad5592r", 155 160 .of_match_table = of_match_ptr(ad5592r_of_match), 161 + .acpi_match_table = ACPI_PTR(ad5592r_acpi_match), 156 162 }, 157 163 .probe = ad5592r_spi_probe, 158 164 .remove = ad5592r_spi_remove,
+8
drivers/iio/dac/ad5593r.c
··· 13 13 #include <linux/i2c.h> 14 14 #include <linux/module.h> 15 15 #include <linux/of.h> 16 + #include <linux/acpi.h> 16 17 17 18 #define AD5593R_MODE_CONF (0 << 4) 18 19 #define AD5593R_MODE_DAC_WRITE (1 << 4) ··· 116 115 }; 117 116 MODULE_DEVICE_TABLE(of, ad5593r_of_match); 118 117 118 + static const struct acpi_device_id ad5593r_acpi_match[] = { 119 + {"ADS5593", }, 120 + { }, 121 + }; 122 + MODULE_DEVICE_TABLE(acpi, ad5593r_acpi_match); 123 + 119 124 static struct i2c_driver ad5593r_driver = { 120 125 .driver = { 121 126 .name = "ad5593r", 122 127 .of_match_table = of_match_ptr(ad5593r_of_match), 128 + .acpi_match_table = ACPI_PTR(ad5593r_acpi_match), 123 129 }, 124 130 .probe = ad5593r_i2c_probe, 125 131 .remove = ad5593r_i2c_remove,
+4 -4
drivers/iio/dummy/iio_simple_dummy.h
··· 88 88 iio_simple_dummy_events_register(struct iio_dev *indio_dev) 89 89 { 90 90 return 0; 91 - }; 91 + } 92 92 93 93 static inline void 94 94 iio_simple_dummy_events_unregister(struct iio_dev *indio_dev) 95 - { }; 95 + {} 96 96 97 97 #endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS*/ 98 98 ··· 119 119 static inline int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev) 120 120 { 121 121 return 0; 122 - }; 122 + } 123 123 124 124 static inline 125 125 void iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev) 126 - {}; 126 + {} 127 127 128 128 #endif /* CONFIG_IIO_SIMPLE_DUMMY_BUFFER */ 129 129 #endif /* _IIO_SIMPLE_DUMMY_H_ */
+1 -3
drivers/iio/dummy/iio_simple_dummy_buffer.c
··· 20 20 21 21 #include <linux/iio/iio.h> 22 22 #include <linux/iio/trigger_consumer.h> 23 + #include <linux/iio/buffer.h> 23 24 #include <linux/iio/kfifo_buf.h> 24 25 25 26 #include "iio_simple_dummy.h" ··· 131 130 } 132 131 133 132 iio_device_attach_buffer(indio_dev, buffer); 134 - 135 - /* Enable timestamps by default */ 136 - buffer->scan_timestamp = true; 137 133 138 134 /* 139 135 * Tell the core what device type specific functions should
+1
drivers/iio/gyro/ssp_gyro_sensor.c
··· 15 15 16 16 #include <linux/iio/common/ssp_sensors.h> 17 17 #include <linux/iio/iio.h> 18 + #include <linux/iio/buffer.h> 18 19 #include <linux/iio/kfifo_buf.h> 19 20 #include <linux/module.h> 20 21 #include <linux/platform_device.h>
+8
drivers/iio/humidity/hts221_i2c.c
··· 10 10 11 11 #include <linux/kernel.h> 12 12 #include <linux/module.h> 13 + #include <linux/acpi.h> 13 14 #include <linux/i2c.h> 14 15 #include <linux/slab.h> 15 16 #include "hts221.h" ··· 84 83 return hts221_probe(iio_dev); 85 84 } 86 85 86 + static const struct acpi_device_id hts221_acpi_match[] = { 87 + {"SMO9100", 0}, 88 + { }, 89 + }; 90 + MODULE_DEVICE_TABLE(acpi, hts221_acpi_match); 91 + 87 92 static const struct of_device_id hts221_i2c_of_match[] = { 88 93 { .compatible = "st,hts221", }, 89 94 {}, ··· 106 99 .driver = { 107 100 .name = "hts221_i2c", 108 101 .of_match_table = of_match_ptr(hts221_i2c_of_match), 102 + .acpi_match_table = ACPI_PTR(hts221_acpi_match), 109 103 }, 110 104 .probe = hts221_i2c_probe, 111 105 .id_table = hts221_i2c_id_table,
+13 -3
drivers/iio/imu/bmi160/bmi160_i2c.c
··· 11 11 * - 0x68 if SDO is pulled to GND 12 12 * - 0x69 if SDO is pulled to VDDIO 13 13 */ 14 - #include <linux/module.h> 15 - #include <linux/i2c.h> 16 - #include <linux/regmap.h> 17 14 #include <linux/acpi.h> 15 + #include <linux/i2c.h> 16 + #include <linux/module.h> 17 + #include <linux/of.h> 18 + #include <linux/regmap.h> 18 19 19 20 #include "bmi160.h" 20 21 ··· 57 56 }; 58 57 MODULE_DEVICE_TABLE(acpi, bmi160_acpi_match); 59 58 59 + #ifdef CONFIG_OF 60 + static const struct of_device_id bmi160_of_match[] = { 61 + { .compatible = "bosch,bmi160" }, 62 + { }, 63 + }; 64 + MODULE_DEVICE_TABLE(of, bmi160_of_match); 65 + #endif 66 + 60 67 static struct i2c_driver bmi160_i2c_driver = { 61 68 .driver = { 62 69 .name = "bmi160_i2c", 63 70 .acpi_match_table = ACPI_PTR(bmi160_acpi_match), 71 + .of_match_table = of_match_ptr(bmi160_of_match), 64 72 }, 65 73 .probe = bmi160_i2c_probe, 66 74 .remove = bmi160_i2c_remove,
+15 -5
drivers/iio/imu/bmi160/bmi160_spi.c
··· 7 7 * the GNU General Public License. See the file COPYING in the main 8 8 * directory of this archive for more details. 9 9 */ 10 - #include <linux/module.h> 11 - #include <linux/spi/spi.h> 12 - #include <linux/regmap.h> 13 10 #include <linux/acpi.h> 11 + #include <linux/module.h> 12 + #include <linux/of.h> 13 + #include <linux/regmap.h> 14 + #include <linux/spi/spi.h> 14 15 15 16 #include "bmi160.h" 16 17 ··· 48 47 }; 49 48 MODULE_DEVICE_TABLE(acpi, bmi160_acpi_match); 50 49 50 + #ifdef CONFIG_OF 51 + static const struct of_device_id bmi160_of_match[] = { 52 + { .compatible = "bosch,bmi160" }, 53 + { }, 54 + }; 55 + MODULE_DEVICE_TABLE(of, bmi160_of_match); 56 + #endif 57 + 51 58 static struct spi_driver bmi160_spi_driver = { 52 59 .probe = bmi160_spi_probe, 53 60 .remove = bmi160_spi_remove, 54 61 .id_table = bmi160_spi_id, 55 62 .driver = { 56 - .acpi_match_table = ACPI_PTR(bmi160_acpi_match), 57 - .name = "bmi160_spi", 63 + .acpi_match_table = ACPI_PTR(bmi160_acpi_match), 64 + .of_match_table = of_match_ptr(bmi160_of_match), 65 + .name = "bmi160_spi", 58 66 }, 59 67 }; 60 68 module_spi_driver(bmi160_spi_driver);
+176 -145
drivers/iio/industrialio-buffer.c
··· 26 26 #include "iio_core.h" 27 27 #include <linux/iio/sysfs.h> 28 28 #include <linux/iio/buffer.h> 29 + #include <linux/iio/buffer_impl.h> 29 30 30 31 static const char * const iio_endian_prefix[] = { 31 32 [IIO_BE] = "be", ··· 210 209 } 211 210 EXPORT_SYMBOL(iio_buffer_init); 212 211 212 + /** 213 + * iio_buffer_set_attrs - Set buffer specific attributes 214 + * @buffer: The buffer for which we are setting attributes 215 + * @attrs: Pointer to a null terminated list of pointers to attributes 216 + */ 217 + void iio_buffer_set_attrs(struct iio_buffer *buffer, 218 + const struct attribute **attrs) 219 + { 220 + buffer->attrs = attrs; 221 + } 222 + EXPORT_SYMBOL_GPL(iio_buffer_set_attrs); 223 + 213 224 static ssize_t iio_show_scan_index(struct device *dev, 214 225 struct device_attribute *attr, 215 226 char *buf) ··· 358 345 clear_bit(bit, buffer->scan_mask); 359 346 return 0; 360 347 } 348 + 349 + static int iio_scan_mask_query(struct iio_dev *indio_dev, 350 + struct iio_buffer *buffer, int bit) 351 + { 352 + if (bit > indio_dev->masklength) 353 + return -EINVAL; 354 + 355 + if (!buffer->scan_mask) 356 + return 0; 357 + 358 + /* Ensure return value is 0 or 1. */ 359 + return !!test_bit(bit, buffer->scan_mask); 360 + }; 361 361 362 362 static ssize_t iio_scan_el_store(struct device *dev, 363 363 struct device_attribute *attr, ··· 775 749 config->scan_timestamp = scan_timestamp; 776 750 777 751 return 0; 752 + } 753 + 754 + /** 755 + * struct iio_demux_table - table describing demux memcpy ops 756 + * @from: index to copy from 757 + * @to: index to copy to 758 + * @length: how many bytes to copy 759 + * @l: list head used for management 760 + */ 761 + struct iio_demux_table { 762 + unsigned from; 763 + unsigned to; 764 + unsigned length; 765 + struct list_head l; 766 + }; 767 + 768 + static void iio_buffer_demux_free(struct iio_buffer *buffer) 769 + { 770 + struct iio_demux_table *p, *q; 771 + list_for_each_entry_safe(p, q, &buffer->demux_list, l) { 772 + list_del(&p->l); 773 + kfree(p); 774 + } 775 + } 776 + 777 + static int iio_buffer_add_demux(struct iio_buffer *buffer, 778 + struct iio_demux_table **p, unsigned int in_loc, unsigned int out_loc, 779 + unsigned int length) 780 + { 781 + 782 + if (*p && (*p)->from + (*p)->length == in_loc && 783 + (*p)->to + (*p)->length == out_loc) { 784 + (*p)->length += length; 785 + } else { 786 + *p = kmalloc(sizeof(**p), GFP_KERNEL); 787 + if (*p == NULL) 788 + return -ENOMEM; 789 + (*p)->from = in_loc; 790 + (*p)->to = out_loc; 791 + (*p)->length = length; 792 + list_add_tail(&(*p)->l, &buffer->demux_list); 793 + } 794 + 795 + return 0; 796 + } 797 + 798 + static int iio_buffer_update_demux(struct iio_dev *indio_dev, 799 + struct iio_buffer *buffer) 800 + { 801 + int ret, in_ind = -1, out_ind, length; 802 + unsigned in_loc = 0, out_loc = 0; 803 + struct iio_demux_table *p = NULL; 804 + 805 + /* Clear out any old demux */ 806 + iio_buffer_demux_free(buffer); 807 + kfree(buffer->demux_bounce); 808 + buffer->demux_bounce = NULL; 809 + 810 + /* First work out which scan mode we will actually have */ 811 + if (bitmap_equal(indio_dev->active_scan_mask, 812 + buffer->scan_mask, 813 + indio_dev->masklength)) 814 + return 0; 815 + 816 + /* Now we have the two masks, work from least sig and build up sizes */ 817 + for_each_set_bit(out_ind, 818 + buffer->scan_mask, 819 + indio_dev->masklength) { 820 + in_ind = find_next_bit(indio_dev->active_scan_mask, 821 + indio_dev->masklength, 822 + in_ind + 1); 823 + while (in_ind != out_ind) { 824 + in_ind = find_next_bit(indio_dev->active_scan_mask, 825 + indio_dev->masklength, 826 + in_ind + 1); 827 + length = iio_storage_bytes_for_si(indio_dev, in_ind); 828 + /* Make sure we are aligned */ 829 + in_loc = roundup(in_loc, length) + length; 830 + } 831 + length = iio_storage_bytes_for_si(indio_dev, in_ind); 832 + out_loc = roundup(out_loc, length); 833 + in_loc = roundup(in_loc, length); 834 + ret = iio_buffer_add_demux(buffer, &p, in_loc, out_loc, length); 835 + if (ret) 836 + goto error_clear_mux_table; 837 + out_loc += length; 838 + in_loc += length; 839 + } 840 + /* Relies on scan_timestamp being last */ 841 + if (buffer->scan_timestamp) { 842 + length = iio_storage_bytes_for_timestamp(indio_dev); 843 + out_loc = roundup(out_loc, length); 844 + in_loc = roundup(in_loc, length); 845 + ret = iio_buffer_add_demux(buffer, &p, in_loc, out_loc, length); 846 + if (ret) 847 + goto error_clear_mux_table; 848 + out_loc += length; 849 + in_loc += length; 850 + } 851 + buffer->demux_bounce = kzalloc(out_loc, GFP_KERNEL); 852 + if (buffer->demux_bounce == NULL) { 853 + ret = -ENOMEM; 854 + goto error_clear_mux_table; 855 + } 856 + return 0; 857 + 858 + error_clear_mux_table: 859 + iio_buffer_demux_free(buffer); 860 + 861 + return ret; 862 + } 863 + 864 + static int iio_update_demux(struct iio_dev *indio_dev) 865 + { 866 + struct iio_buffer *buffer; 867 + int ret; 868 + 869 + list_for_each_entry(buffer, &indio_dev->buffer_list, buffer_list) { 870 + ret = iio_buffer_update_demux(indio_dev, buffer); 871 + if (ret < 0) 872 + goto error_clear_mux_table; 873 + } 874 + return 0; 875 + 876 + error_clear_mux_table: 877 + list_for_each_entry(buffer, &indio_dev->buffer_list, buffer_list) 878 + iio_buffer_demux_free(buffer); 879 + 880 + return ret; 778 881 } 779 882 780 883 static int iio_enable_buffers(struct iio_dev *indio_dev, ··· 1354 1199 } 1355 1200 EXPORT_SYMBOL_GPL(iio_validate_scan_mask_onehot); 1356 1201 1357 - int iio_scan_mask_query(struct iio_dev *indio_dev, 1358 - struct iio_buffer *buffer, int bit) 1359 - { 1360 - if (bit > indio_dev->masklength) 1361 - return -EINVAL; 1362 - 1363 - if (!buffer->scan_mask) 1364 - return 0; 1365 - 1366 - /* Ensure return value is 0 or 1. */ 1367 - return !!test_bit(bit, buffer->scan_mask); 1368 - }; 1369 - EXPORT_SYMBOL_GPL(iio_scan_mask_query); 1370 - 1371 - /** 1372 - * struct iio_demux_table - table describing demux memcpy ops 1373 - * @from: index to copy from 1374 - * @to: index to copy to 1375 - * @length: how many bytes to copy 1376 - * @l: list head used for management 1377 - */ 1378 - struct iio_demux_table { 1379 - unsigned from; 1380 - unsigned to; 1381 - unsigned length; 1382 - struct list_head l; 1383 - }; 1384 - 1385 1202 static const void *iio_demux(struct iio_buffer *buffer, 1386 1203 const void *datain) 1387 1204 { ··· 1385 1258 return 0; 1386 1259 } 1387 1260 1388 - static void iio_buffer_demux_free(struct iio_buffer *buffer) 1389 - { 1390 - struct iio_demux_table *p, *q; 1391 - list_for_each_entry_safe(p, q, &buffer->demux_list, l) { 1392 - list_del(&p->l); 1393 - kfree(p); 1394 - } 1395 - } 1396 - 1397 - 1261 + /** 1262 + * iio_push_to_buffers() - push to a registered buffer. 1263 + * @indio_dev: iio_dev structure for device. 1264 + * @data: Full scan. 1265 + */ 1398 1266 int iio_push_to_buffers(struct iio_dev *indio_dev, const void *data) 1399 1267 { 1400 1268 int ret; ··· 1404 1282 return 0; 1405 1283 } 1406 1284 EXPORT_SYMBOL_GPL(iio_push_to_buffers); 1407 - 1408 - static int iio_buffer_add_demux(struct iio_buffer *buffer, 1409 - struct iio_demux_table **p, unsigned int in_loc, unsigned int out_loc, 1410 - unsigned int length) 1411 - { 1412 - 1413 - if (*p && (*p)->from + (*p)->length == in_loc && 1414 - (*p)->to + (*p)->length == out_loc) { 1415 - (*p)->length += length; 1416 - } else { 1417 - *p = kmalloc(sizeof(**p), GFP_KERNEL); 1418 - if (*p == NULL) 1419 - return -ENOMEM; 1420 - (*p)->from = in_loc; 1421 - (*p)->to = out_loc; 1422 - (*p)->length = length; 1423 - list_add_tail(&(*p)->l, &buffer->demux_list); 1424 - } 1425 - 1426 - return 0; 1427 - } 1428 - 1429 - static int iio_buffer_update_demux(struct iio_dev *indio_dev, 1430 - struct iio_buffer *buffer) 1431 - { 1432 - int ret, in_ind = -1, out_ind, length; 1433 - unsigned in_loc = 0, out_loc = 0; 1434 - struct iio_demux_table *p = NULL; 1435 - 1436 - /* Clear out any old demux */ 1437 - iio_buffer_demux_free(buffer); 1438 - kfree(buffer->demux_bounce); 1439 - buffer->demux_bounce = NULL; 1440 - 1441 - /* First work out which scan mode we will actually have */ 1442 - if (bitmap_equal(indio_dev->active_scan_mask, 1443 - buffer->scan_mask, 1444 - indio_dev->masklength)) 1445 - return 0; 1446 - 1447 - /* Now we have the two masks, work from least sig and build up sizes */ 1448 - for_each_set_bit(out_ind, 1449 - buffer->scan_mask, 1450 - indio_dev->masklength) { 1451 - in_ind = find_next_bit(indio_dev->active_scan_mask, 1452 - indio_dev->masklength, 1453 - in_ind + 1); 1454 - while (in_ind != out_ind) { 1455 - in_ind = find_next_bit(indio_dev->active_scan_mask, 1456 - indio_dev->masklength, 1457 - in_ind + 1); 1458 - length = iio_storage_bytes_for_si(indio_dev, in_ind); 1459 - /* Make sure we are aligned */ 1460 - in_loc = roundup(in_loc, length) + length; 1461 - } 1462 - length = iio_storage_bytes_for_si(indio_dev, in_ind); 1463 - out_loc = roundup(out_loc, length); 1464 - in_loc = roundup(in_loc, length); 1465 - ret = iio_buffer_add_demux(buffer, &p, in_loc, out_loc, length); 1466 - if (ret) 1467 - goto error_clear_mux_table; 1468 - out_loc += length; 1469 - in_loc += length; 1470 - } 1471 - /* Relies on scan_timestamp being last */ 1472 - if (buffer->scan_timestamp) { 1473 - length = iio_storage_bytes_for_timestamp(indio_dev); 1474 - out_loc = roundup(out_loc, length); 1475 - in_loc = roundup(in_loc, length); 1476 - ret = iio_buffer_add_demux(buffer, &p, in_loc, out_loc, length); 1477 - if (ret) 1478 - goto error_clear_mux_table; 1479 - out_loc += length; 1480 - in_loc += length; 1481 - } 1482 - buffer->demux_bounce = kzalloc(out_loc, GFP_KERNEL); 1483 - if (buffer->demux_bounce == NULL) { 1484 - ret = -ENOMEM; 1485 - goto error_clear_mux_table; 1486 - } 1487 - return 0; 1488 - 1489 - error_clear_mux_table: 1490 - iio_buffer_demux_free(buffer); 1491 - 1492 - return ret; 1493 - } 1494 - 1495 - int iio_update_demux(struct iio_dev *indio_dev) 1496 - { 1497 - struct iio_buffer *buffer; 1498 - int ret; 1499 - 1500 - list_for_each_entry(buffer, &indio_dev->buffer_list, buffer_list) { 1501 - ret = iio_buffer_update_demux(indio_dev, buffer); 1502 - if (ret < 0) 1503 - goto error_clear_mux_table; 1504 - } 1505 - return 0; 1506 - 1507 - error_clear_mux_table: 1508 - list_for_each_entry(buffer, &indio_dev->buffer_list, buffer_list) 1509 - iio_buffer_demux_free(buffer); 1510 - 1511 - return ret; 1512 - } 1513 - EXPORT_SYMBOL_GPL(iio_update_demux); 1514 1285 1515 1286 /** 1516 1287 * iio_buffer_release() - Free a buffer's resources ··· 1446 1431 kref_put(&buffer->ref, iio_buffer_release); 1447 1432 } 1448 1433 EXPORT_SYMBOL_GPL(iio_buffer_put); 1434 + 1435 + /** 1436 + * iio_device_attach_buffer - Attach a buffer to a IIO device 1437 + * @indio_dev: The device the buffer should be attached to 1438 + * @buffer: The buffer to attach to the device 1439 + * 1440 + * This function attaches a buffer to a IIO device. The buffer stays attached to 1441 + * the device until the device is freed. The function should only be called at 1442 + * most once per device. 1443 + */ 1444 + void iio_device_attach_buffer(struct iio_dev *indio_dev, 1445 + struct iio_buffer *buffer) 1446 + { 1447 + indio_dev->buffer = iio_buffer_get(buffer); 1448 + } 1449 + EXPORT_SYMBOL_GPL(iio_device_attach_buffer);
+2
drivers/iio/industrialio-core.c
··· 32 32 #include <linux/iio/sysfs.h> 33 33 #include <linux/iio/events.h> 34 34 #include <linux/iio/buffer.h> 35 + #include <linux/iio/buffer_impl.h> 35 36 36 37 /* IDA to assign each registered device a unique id */ 37 38 static DEFINE_IDA(iio_ida); ··· 84 83 [IIO_ELECTRICALCONDUCTIVITY] = "electricalconductivity", 85 84 [IIO_COUNT] = "count", 86 85 [IIO_INDEX] = "index", 86 + [IIO_GRAVITY] = "gravity", 87 87 }; 88 88 89 89 static const char * const iio_modifier_names[] = {
+10
drivers/iio/light/Kconfig
··· 115 115 To compile this driver as a module, choose M here: the module will 116 116 be called cm3323. 117 117 118 + config CM3605 119 + tristate "Capella CM3605 ambient light and proximity sensor" 120 + depends on OF 121 + help 122 + Say Y here if you want to build a driver for Capella CM3605 123 + ambient light and short range proximity sensor. 124 + 125 + To compile this driver as a module, choose M here: the module will 126 + be called cm3605. 127 + 118 128 config CM36651 119 129 depends on I2C 120 130 tristate "CM36651 driver"
+1
drivers/iio/light/Makefile
··· 13 13 obj-$(CONFIG_CM32181) += cm32181.o 14 14 obj-$(CONFIG_CM3232) += cm3232.o 15 15 obj-$(CONFIG_CM3323) += cm3323.o 16 + obj-$(CONFIG_CM3605) += cm3605.o 16 17 obj-$(CONFIG_CM36651) += cm36651.o 17 18 obj-$(CONFIG_GP2AP020A00F) += gp2ap020a00f.o 18 19 obj-$(CONFIG_HID_SENSOR_ALS) += hid-sensor-als.o
+1 -1
drivers/iio/light/cm3232.c
··· 119 119 if (ret < 0) 120 120 dev_err(&chip->client->dev, "Error writing reg_cmd\n"); 121 121 122 - return 0; 122 + return ret; 123 123 } 124 124 125 125 /**
+330
drivers/iio/light/cm3605.c
··· 1 + /* 2 + * CM3605 Ambient Light and Proximity Sensor 3 + * 4 + * Copyright (C) 2016 Linaro Ltd. 5 + * Author: Linus Walleij <linus.walleij@linaro.org> 6 + * 7 + * This hardware was found in the very first Nexus One handset from Google/HTC 8 + * and an early endavour into mobile light and proximity sensors. 9 + */ 10 + 11 + #include <linux/module.h> 12 + #include <linux/iio/iio.h> 13 + #include <linux/iio/sysfs.h> 14 + #include <linux/iio/events.h> 15 + #include <linux/iio/consumer.h> /* To get our ADC channel */ 16 + #include <linux/iio/types.h> /* To deal with our ADC channel */ 17 + #include <linux/init.h> 18 + #include <linux/leds.h> 19 + #include <linux/platform_device.h> 20 + #include <linux/of.h> 21 + #include <linux/regulator/consumer.h> 22 + #include <linux/gpio/consumer.h> 23 + #include <linux/interrupt.h> 24 + #include <linux/math64.h> 25 + #include <linux/pm.h> 26 + 27 + #define CM3605_PROX_CHANNEL 0 28 + #define CM3605_ALS_CHANNEL 1 29 + #define CM3605_AOUT_TYP_MAX_MV 1550 30 + /* It should not go above 1.650V according to the data sheet */ 31 + #define CM3605_AOUT_MAX_MV 1650 32 + 33 + /** 34 + * struct cm3605 - CM3605 state 35 + * @dev: pointer to parent device 36 + * @vdd: regulator controlling VDD 37 + * @aset: sleep enable GPIO, high = sleep 38 + * @aout: IIO ADC channel to convert the AOUT signal 39 + * @als_max: maximum LUX detection (depends on RSET) 40 + * @dir: proximity direction: start as FALLING 41 + * @led: trigger for the infrared LED used by the proximity sensor 42 + */ 43 + struct cm3605 { 44 + struct device *dev; 45 + struct regulator *vdd; 46 + struct gpio_desc *aset; 47 + struct iio_channel *aout; 48 + s32 als_max; 49 + enum iio_event_direction dir; 50 + struct led_trigger *led; 51 + }; 52 + 53 + static irqreturn_t cm3605_prox_irq(int irq, void *d) 54 + { 55 + struct iio_dev *indio_dev = d; 56 + struct cm3605 *cm3605 = iio_priv(indio_dev); 57 + u64 ev; 58 + 59 + ev = IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY, CM3605_PROX_CHANNEL, 60 + IIO_EV_TYPE_THRESH, cm3605->dir); 61 + iio_push_event(indio_dev, ev, iio_get_time_ns(indio_dev)); 62 + 63 + /* Invert the edge for each event */ 64 + if (cm3605->dir == IIO_EV_DIR_RISING) 65 + cm3605->dir = IIO_EV_DIR_FALLING; 66 + else 67 + cm3605->dir = IIO_EV_DIR_RISING; 68 + 69 + return IRQ_HANDLED; 70 + } 71 + 72 + static int cm3605_get_lux(struct cm3605 *cm3605) 73 + { 74 + int ret, res; 75 + s64 lux; 76 + 77 + ret = iio_read_channel_processed(cm3605->aout, &res); 78 + if (ret < 0) 79 + return ret; 80 + 81 + dev_dbg(cm3605->dev, "read %d mV from ADC\n", res); 82 + 83 + /* 84 + * AOUT has an offset of ~30mV then linear at dark 85 + * then goes from 2.54 up to 650 LUX yielding 1.55V 86 + * (1550 mV) so scale the returned value to this interval 87 + * using simple linear interpolation. 88 + */ 89 + if (res < 30) 90 + return 0; 91 + if (res > CM3605_AOUT_MAX_MV) 92 + dev_err(cm3605->dev, "device out of range\n"); 93 + 94 + /* Remove bias */ 95 + lux = res - 30; 96 + 97 + /* Linear interpolation between 0 and ALS typ max */ 98 + lux *= cm3605->als_max; 99 + lux = div64_s64(lux, CM3605_AOUT_TYP_MAX_MV); 100 + 101 + return lux; 102 + } 103 + 104 + static int cm3605_read_raw(struct iio_dev *indio_dev, 105 + struct iio_chan_spec const *chan, 106 + int *val, int *val2, long mask) 107 + { 108 + struct cm3605 *cm3605 = iio_priv(indio_dev); 109 + int ret; 110 + 111 + switch (mask) { 112 + case IIO_CHAN_INFO_RAW: 113 + switch (chan->type) { 114 + case IIO_LIGHT: 115 + ret = cm3605_get_lux(cm3605); 116 + if (ret < 0) 117 + return ret; 118 + *val = ret; 119 + return IIO_VAL_INT; 120 + default: 121 + return -EINVAL; 122 + } 123 + default: 124 + return -EINVAL; 125 + } 126 + } 127 + 128 + static const struct iio_info cm3605_info = { 129 + .driver_module = THIS_MODULE, 130 + .read_raw = cm3605_read_raw, 131 + }; 132 + 133 + static const struct iio_event_spec cm3605_events[] = { 134 + { 135 + .type = IIO_EV_TYPE_THRESH, 136 + .dir = IIO_EV_DIR_EITHER, 137 + .mask_separate = BIT(IIO_EV_INFO_ENABLE), 138 + }, 139 + }; 140 + 141 + static const struct iio_chan_spec cm3605_channels[] = { 142 + { 143 + .type = IIO_PROXIMITY, 144 + .event_spec = cm3605_events, 145 + .num_event_specs = ARRAY_SIZE(cm3605_events), 146 + }, 147 + { 148 + .type = IIO_LIGHT, 149 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 150 + .channel = CM3605_ALS_CHANNEL, 151 + }, 152 + }; 153 + 154 + static int cm3605_probe(struct platform_device *pdev) 155 + { 156 + struct cm3605 *cm3605; 157 + struct iio_dev *indio_dev; 158 + struct device *dev = &pdev->dev; 159 + struct device_node *np = dev->of_node; 160 + enum iio_chan_type ch_type; 161 + u32 rset; 162 + int ret; 163 + 164 + indio_dev = devm_iio_device_alloc(dev, sizeof(*cm3605)); 165 + if (!indio_dev) 166 + return -ENOMEM; 167 + platform_set_drvdata(pdev, indio_dev); 168 + 169 + cm3605 = iio_priv(indio_dev); 170 + cm3605->dev = dev; 171 + cm3605->dir = IIO_EV_DIR_FALLING; 172 + 173 + ret = of_property_read_u32(np, "capella,aset-resistance-ohms", &rset); 174 + if (ret) { 175 + dev_info(dev, "no RSET specified, assuming 100K\n"); 176 + rset = 100000; 177 + } 178 + switch (rset) { 179 + case 50000: 180 + cm3605->als_max = 650; 181 + break; 182 + case 100000: 183 + cm3605->als_max = 300; 184 + break; 185 + case 300000: 186 + cm3605->als_max = 100; 187 + break; 188 + case 600000: 189 + cm3605->als_max = 50; 190 + break; 191 + default: 192 + dev_info(dev, "non-standard resistance\n"); 193 + return -EINVAL; 194 + } 195 + 196 + cm3605->aout = devm_iio_channel_get(dev, "aout"); 197 + if (IS_ERR(cm3605->aout)) { 198 + if (PTR_ERR(cm3605->aout) == -ENODEV) { 199 + dev_err(dev, "no ADC, deferring...\n"); 200 + return -EPROBE_DEFER; 201 + } 202 + dev_err(dev, "failed to get AOUT ADC channel\n"); 203 + return PTR_ERR(cm3605->aout); 204 + } 205 + ret = iio_get_channel_type(cm3605->aout, &ch_type); 206 + if (ret < 0) 207 + return ret; 208 + if (ch_type != IIO_VOLTAGE) { 209 + dev_err(dev, "wrong type of IIO channel specified for AOUT\n"); 210 + return -EINVAL; 211 + } 212 + 213 + cm3605->vdd = devm_regulator_get(dev, "vdd"); 214 + if (IS_ERR(cm3605->vdd)) { 215 + dev_err(dev, "failed to get VDD regulator\n"); 216 + return PTR_ERR(cm3605->vdd); 217 + } 218 + ret = regulator_enable(cm3605->vdd); 219 + if (ret) { 220 + dev_err(dev, "failed to enable VDD regulator\n"); 221 + return ret; 222 + } 223 + 224 + cm3605->aset = devm_gpiod_get(dev, "aset", GPIOD_OUT_HIGH); 225 + if (IS_ERR(cm3605->aset)) { 226 + dev_err(dev, "no ASET GPIO\n"); 227 + ret = PTR_ERR(cm3605->aset); 228 + goto out_disable_vdd; 229 + } 230 + 231 + ret = devm_request_threaded_irq(dev, platform_get_irq(pdev, 0), 232 + cm3605_prox_irq, NULL, 0, "cm3605", indio_dev); 233 + if (ret) { 234 + dev_err(dev, "unable to request IRQ\n"); 235 + goto out_disable_aset; 236 + } 237 + 238 + /* Just name the trigger the same as the driver */ 239 + led_trigger_register_simple("cm3605", &cm3605->led); 240 + led_trigger_event(cm3605->led, LED_FULL); 241 + 242 + indio_dev->dev.parent = dev; 243 + indio_dev->info = &cm3605_info; 244 + indio_dev->name = "cm3605"; 245 + indio_dev->channels = cm3605_channels; 246 + indio_dev->num_channels = ARRAY_SIZE(cm3605_channels); 247 + indio_dev->modes = INDIO_DIRECT_MODE; 248 + 249 + ret = iio_device_register(indio_dev); 250 + if (ret) 251 + goto out_remove_trigger; 252 + dev_info(dev, "Capella Microsystems CM3605 enabled range 0..%d LUX\n", 253 + cm3605->als_max); 254 + 255 + return 0; 256 + 257 + out_remove_trigger: 258 + led_trigger_event(cm3605->led, LED_OFF); 259 + led_trigger_unregister_simple(cm3605->led); 260 + out_disable_aset: 261 + gpiod_set_value_cansleep(cm3605->aset, 0); 262 + out_disable_vdd: 263 + regulator_disable(cm3605->vdd); 264 + return ret; 265 + } 266 + 267 + static int cm3605_remove(struct platform_device *pdev) 268 + { 269 + struct iio_dev *indio_dev = platform_get_drvdata(pdev); 270 + struct cm3605 *cm3605 = iio_priv(indio_dev); 271 + 272 + led_trigger_event(cm3605->led, LED_OFF); 273 + led_trigger_unregister_simple(cm3605->led); 274 + gpiod_set_value_cansleep(cm3605->aset, 0); 275 + iio_device_unregister(indio_dev); 276 + regulator_disable(cm3605->vdd); 277 + 278 + return 0; 279 + } 280 + 281 + static int cm3605_pm_suspend(struct device *dev) 282 + { 283 + struct iio_dev *indio_dev = dev_get_drvdata(dev); 284 + struct cm3605 *cm3605 = iio_priv(indio_dev); 285 + 286 + led_trigger_event(cm3605->led, LED_OFF); 287 + regulator_disable(cm3605->vdd); 288 + 289 + return 0; 290 + } 291 + 292 + static int cm3605_pm_resume(struct device *dev) 293 + { 294 + struct iio_dev *indio_dev = dev_get_drvdata(dev); 295 + struct cm3605 *cm3605 = iio_priv(indio_dev); 296 + int ret; 297 + 298 + ret = regulator_enable(cm3605->vdd); 299 + if (ret) 300 + dev_err(dev, "failed to enable regulator in resume path\n"); 301 + led_trigger_event(cm3605->led, LED_FULL); 302 + 303 + return 0; 304 + } 305 + 306 + static const struct dev_pm_ops cm3605_dev_pm_ops = { 307 + SET_SYSTEM_SLEEP_PM_OPS(cm3605_pm_suspend, 308 + cm3605_pm_resume) 309 + }; 310 + 311 + static const struct of_device_id cm3605_of_match[] = { 312 + {.compatible = "capella,cm3605"}, 313 + { }, 314 + }; 315 + MODULE_DEVICE_TABLE(of, cm3605_of_match); 316 + 317 + static struct platform_driver cm3605_driver = { 318 + .driver = { 319 + .name = "cm3605", 320 + .of_match_table = cm3605_of_match, 321 + .pm = &cm3605_dev_pm_ops, 322 + }, 323 + .probe = cm3605_probe, 324 + .remove = cm3605_remove, 325 + }; 326 + module_platform_driver(cm3605_driver); 327 + 328 + MODULE_AUTHOR("Linus Walleij <linus.walleij@linaro.org>"); 329 + MODULE_DESCRIPTION("CM3605 ambient light and proximity sensor driver"); 330 + MODULE_LICENSE("GPL");
+21 -3
drivers/iio/light/hid-sensor-als.c
··· 31 31 #include <linux/iio/triggered_buffer.h> 32 32 #include "../common/hid-sensors/hid-sensor-trigger.h" 33 33 34 - #define CHANNEL_SCAN_INDEX_ILLUM 0 34 + enum { 35 + CHANNEL_SCAN_INDEX_INTENSITY = 0, 36 + CHANNEL_SCAN_INDEX_ILLUM = 1, 37 + CHANNEL_SCAN_INDEX_MAX 38 + }; 35 39 36 40 struct als_state { 37 41 struct hid_sensor_hub_callbacks callbacks; 38 42 struct hid_sensor_common common_attributes; 39 43 struct hid_sensor_hub_attribute_info als_illum; 40 - u32 illum; 44 + u32 illum[CHANNEL_SCAN_INDEX_MAX]; 41 45 int scale_pre_decml; 42 46 int scale_post_decml; 43 47 int scale_precision; ··· 54 50 .type = IIO_INTENSITY, 55 51 .modified = 1, 56 52 .channel2 = IIO_MOD_LIGHT_BOTH, 53 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 54 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | 55 + BIT(IIO_CHAN_INFO_SCALE) | 56 + BIT(IIO_CHAN_INFO_SAMP_FREQ) | 57 + BIT(IIO_CHAN_INFO_HYSTERESIS), 58 + .scan_index = CHANNEL_SCAN_INDEX_INTENSITY, 59 + }, 60 + { 61 + .type = IIO_LIGHT, 57 62 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 58 63 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | 59 64 BIT(IIO_CHAN_INFO_SCALE) | ··· 99 86 switch (mask) { 100 87 case 0: 101 88 switch (chan->scan_index) { 89 + case CHANNEL_SCAN_INDEX_INTENSITY: 102 90 case CHANNEL_SCAN_INDEX_ILLUM: 103 91 report_id = als_state->als_illum.report_id; 104 92 address = ··· 216 202 struct iio_dev *indio_dev = platform_get_drvdata(priv); 217 203 struct als_state *als_state = iio_priv(indio_dev); 218 204 int ret = -EINVAL; 205 + u32 sample_data = *(u32 *)raw_data; 219 206 220 207 switch (usage_id) { 221 208 case HID_USAGE_SENSOR_LIGHT_ILLUM: 222 - als_state->illum = *(u32 *)raw_data; 209 + als_state->illum[CHANNEL_SCAN_INDEX_INTENSITY] = sample_data; 210 + als_state->illum[CHANNEL_SCAN_INDEX_ILLUM] = sample_data; 223 211 ret = 0; 224 212 break; 225 213 default: ··· 246 230 &st->als_illum); 247 231 if (ret < 0) 248 232 return ret; 233 + als_adjust_channel_bit_mask(channels, CHANNEL_SCAN_INDEX_INTENSITY, 234 + st->als_illum.size); 249 235 als_adjust_channel_bit_mask(channels, CHANNEL_SCAN_INDEX_ILLUM, 250 236 st->als_illum.size); 251 237
+7 -7
drivers/iio/pressure/bmp280-core.c
··· 65 65 struct bmp180_calib calib; 66 66 struct regulator *vddd; 67 67 struct regulator *vdda; 68 - unsigned int start_up_time; /* in milliseconds */ 68 + unsigned int start_up_time; /* in microseconds */ 69 69 70 70 /* log of base 2 of oversampling rate */ 71 71 u8 oversampling_press; ··· 935 935 data->chip_info = &bmp180_chip_info; 936 936 data->oversampling_press = ilog2(8); 937 937 data->oversampling_temp = ilog2(1); 938 - data->start_up_time = 10; 938 + data->start_up_time = 10000; 939 939 break; 940 940 case BMP280_CHIP_ID: 941 941 indio_dev->num_channels = 2; 942 942 data->chip_info = &bmp280_chip_info; 943 943 data->oversampling_press = ilog2(16); 944 944 data->oversampling_temp = ilog2(2); 945 - data->start_up_time = 2; 945 + data->start_up_time = 2000; 946 946 break; 947 947 case BME280_CHIP_ID: 948 948 indio_dev->num_channels = 3; ··· 950 950 data->oversampling_press = ilog2(16); 951 951 data->oversampling_humid = ilog2(16); 952 952 data->oversampling_temp = ilog2(2); 953 - data->start_up_time = 2; 953 + data->start_up_time = 2000; 954 954 break; 955 955 default: 956 956 return -EINVAL; ··· 979 979 goto out_disable_vddd; 980 980 } 981 981 /* Wait to make sure we started up properly */ 982 - mdelay(data->start_up_time); 982 + usleep_range(data->start_up_time, data->start_up_time + 100); 983 983 984 984 /* Bring chip out of reset if there is an assigned GPIO line */ 985 985 gpiod = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); ··· 1038 1038 * Set autosuspend to two orders of magnitude larger than the 1039 1039 * start-up time. 1040 1040 */ 1041 - pm_runtime_set_autosuspend_delay(dev, data->start_up_time *100); 1041 + pm_runtime_set_autosuspend_delay(dev, data->start_up_time / 10); 1042 1042 pm_runtime_use_autosuspend(dev); 1043 1043 pm_runtime_put(dev); 1044 1044 ··· 1101 1101 ret = regulator_enable(data->vdda); 1102 1102 if (ret) 1103 1103 return ret; 1104 - msleep(data->start_up_time); 1104 + usleep_range(data->start_up_time, data->start_up_time + 100); 1105 1105 return data->chip_info->chip_config(data); 1106 1106 } 1107 1107 #endif /* CONFIG_PM */
+8
drivers/iio/pressure/st_pressure.h
··· 14 14 #include <linux/types.h> 15 15 #include <linux/iio/common/st_sensors.h> 16 16 17 + enum st_press_type { 18 + LPS001WP, 19 + LPS25H, 20 + LPS331AP, 21 + LPS22HB, 22 + ST_PRESS_MAX, 23 + }; 24 + 17 25 #define LPS001WP_PRESS_DEV_NAME "lps001wp" 18 26 #define LPS25H_PRESS_DEV_NAME "lps25h" 19 27 #define LPS331AP_PRESS_DEV_NAME "lps331ap"
+7 -5
drivers/iio/pressure/st_pressure_core.c
··· 136 136 .address = ST_PRESS_1_OUT_XL_ADDR, 137 137 .scan_index = 0, 138 138 .scan_type = { 139 - .sign = 'u', 139 + .sign = 's', 140 140 .realbits = 24, 141 141 .storagebits = 32, 142 142 .endianness = IIO_LE, 143 143 }, 144 144 .info_mask_separate = 145 145 BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), 146 + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), 146 147 }, 147 148 { 148 149 .type = IIO_TEMP, 149 150 .address = ST_TEMP_1_OUT_L_ADDR, 150 151 .scan_index = 1, 151 152 .scan_type = { 152 - .sign = 'u', 153 + .sign = 's', 153 154 .realbits = 16, 154 155 .storagebits = 16, 155 156 .endianness = IIO_LE, ··· 159 158 BIT(IIO_CHAN_INFO_RAW) | 160 159 BIT(IIO_CHAN_INFO_SCALE) | 161 160 BIT(IIO_CHAN_INFO_OFFSET), 161 + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), 162 162 }, 163 163 IIO_CHAN_SOFT_TIMESTAMP(2) 164 164 }; ··· 170 168 .address = ST_PRESS_LPS001WP_OUT_L_ADDR, 171 169 .scan_index = 0, 172 170 .scan_type = { 173 - .sign = 'u', 171 + .sign = 's', 174 172 .realbits = 16, 175 173 .storagebits = 16, 176 174 .endianness = IIO_LE, ··· 184 182 .address = ST_TEMP_LPS001WP_OUT_L_ADDR, 185 183 .scan_index = 1, 186 184 .scan_type = { 187 - .sign = 'u', 185 + .sign = 's', 188 186 .realbits = 16, 189 187 .storagebits = 16, 190 188 .endianness = IIO_LE, ··· 202 200 .address = ST_PRESS_1_OUT_XL_ADDR, 203 201 .scan_index = 0, 204 202 .scan_type = { 205 - .sign = 'u', 203 + .sign = 's', 206 204 .realbits = 24, 207 205 .storagebits = 32, 208 206 .endianness = IIO_LE,
+38 -13
drivers/iio/pressure/st_pressure_i2c.c
··· 11 11 #include <linux/kernel.h> 12 12 #include <linux/module.h> 13 13 #include <linux/slab.h> 14 + #include <linux/acpi.h> 14 15 #include <linux/i2c.h> 15 16 #include <linux/iio/iio.h> 16 17 ··· 44 43 #define st_press_of_match NULL 45 44 #endif 46 45 46 + #ifdef CONFIG_ACPI 47 + static const struct acpi_device_id st_press_acpi_match[] = { 48 + {"SNO9210", LPS22HB}, 49 + { }, 50 + }; 51 + MODULE_DEVICE_TABLE(acpi, st_press_acpi_match); 52 + #else 53 + #define st_press_acpi_match NULL 54 + #endif 55 + 56 + static const struct i2c_device_id st_press_id_table[] = { 57 + { LPS001WP_PRESS_DEV_NAME, LPS001WP }, 58 + { LPS25H_PRESS_DEV_NAME, LPS25H }, 59 + { LPS331AP_PRESS_DEV_NAME, LPS331AP }, 60 + { LPS22HB_PRESS_DEV_NAME, LPS22HB }, 61 + {}, 62 + }; 63 + MODULE_DEVICE_TABLE(i2c, st_press_id_table); 64 + 47 65 static int st_press_i2c_probe(struct i2c_client *client, 48 66 const struct i2c_device_id *id) 49 67 { 50 68 struct iio_dev *indio_dev; 51 69 struct st_sensor_data *press_data; 52 - int err; 70 + int ret; 53 71 54 72 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*press_data)); 55 73 if (!indio_dev) 56 74 return -ENOMEM; 57 75 58 76 press_data = iio_priv(indio_dev); 59 - st_sensors_of_i2c_probe(client, st_press_of_match); 77 + 78 + if (client->dev.of_node) { 79 + st_sensors_of_i2c_probe(client, st_press_of_match); 80 + } else if (ACPI_HANDLE(&client->dev)) { 81 + ret = st_sensors_match_acpi_device(&client->dev); 82 + if ((ret < 0) || (ret >= ST_PRESS_MAX)) 83 + return -ENODEV; 84 + 85 + strncpy(client->name, st_press_id_table[ret].name, 86 + sizeof(client->name)); 87 + client->name[sizeof(client->name) - 1] = '\0'; 88 + } else if (!id) 89 + return -ENODEV; 60 90 61 91 st_sensors_i2c_configure(indio_dev, client, press_data); 62 92 63 - err = st_press_common_probe(indio_dev); 64 - if (err < 0) 65 - return err; 93 + ret = st_press_common_probe(indio_dev); 94 + if (ret < 0) 95 + return ret; 66 96 67 97 return 0; 68 98 } ··· 105 73 return 0; 106 74 } 107 75 108 - static const struct i2c_device_id st_press_id_table[] = { 109 - { LPS001WP_PRESS_DEV_NAME }, 110 - { LPS25H_PRESS_DEV_NAME }, 111 - { LPS331AP_PRESS_DEV_NAME }, 112 - {}, 113 - }; 114 - MODULE_DEVICE_TABLE(i2c, st_press_id_table); 115 - 116 76 static struct i2c_driver st_press_driver = { 117 77 .driver = { 118 78 .name = "st-press-i2c", 119 79 .of_match_table = of_match_ptr(st_press_of_match), 80 + .acpi_match_table = ACPI_PTR(st_press_acpi_match), 120 81 }, 121 82 .probe = st_press_i2c_probe, 122 83 .remove = st_press_i2c_remove,
+2
drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
··· 326 326 327 327 static const struct i2c_device_id lidar_id[] = { 328 328 {"lidar-lite-v2", 0}, 329 + {"lidar-lite-v3", 0}, 329 330 { }, 330 331 }; 331 332 MODULE_DEVICE_TABLE(i2c, lidar_id); 332 333 333 334 static const struct of_device_id lidar_dt_ids[] = { 334 335 { .compatible = "pulsedlight,lidar-lite-v2" }, 336 + { .compatible = "grmn,lidar-lite-v3" }, 335 337 { } 336 338 }; 337 339 MODULE_DEVICE_TABLE(of, lidar_dt_ids);
+2 -2
drivers/staging/iio/accel/adis16201_core.c
··· 1 1 /* 2 - * ADIS16201 Programmable Digital Vibration Sensor driver 2 + * ADIS16201 Dual-Axis Digital Inclinometer and Accelerometer 3 3 * 4 4 * Copyright 2010 Analog Devices Inc. 5 5 * ··· 243 243 module_spi_driver(adis16201_driver); 244 244 245 245 MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>"); 246 - MODULE_DESCRIPTION("Analog Devices ADIS16201 Programmable Digital Vibration Sensor driver"); 246 + MODULE_DESCRIPTION("Analog Devices ADIS16201 Dual-Axis Digital Inclinometer and Accelerometer"); 247 247 MODULE_LICENSE("GPL v2"); 248 248 MODULE_ALIAS("spi:adis16201");
+3 -3
drivers/staging/iio/accel/adis16203_core.c
··· 1 1 /* 2 - * ADIS16203 Programmable Digital Vibration Sensor driver 2 + * ADIS16203 Programmable 360 Degrees Inclinometer 3 3 * 4 - * Copyright 2030 Analog Devices Inc. 4 + * Copyright 2010 Analog Devices Inc. 5 5 * 6 6 * Licensed under the GPL-2 or later. 7 7 */ ··· 211 211 module_spi_driver(adis16203_driver); 212 212 213 213 MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>"); 214 - MODULE_DESCRIPTION("Analog Devices ADIS16203 Programmable Digital Vibration Sensor driver"); 214 + MODULE_DESCRIPTION("Analog Devices ADIS16203 Programmable 360 Degrees Inclinometer"); 215 215 MODULE_LICENSE("GPL v2"); 216 216 MODULE_ALIAS("spi:adis16203");
+2 -2
drivers/staging/iio/accel/adis16209_core.c
··· 1 1 /* 2 - * ADIS16209 Programmable Digital Vibration Sensor driver 2 + * ADIS16209 Dual-Axis Digital Inclinometer and Accelerometer 3 3 * 4 4 * Copyright 2010 Analog Devices Inc. 5 5 * ··· 243 243 module_spi_driver(adis16209_driver); 244 244 245 245 MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>"); 246 - MODULE_DESCRIPTION("Analog Devices ADIS16209 Digital Vibration Sensor driver"); 246 + MODULE_DESCRIPTION("Analog Devices ADIS16209 Dual-Axis Digital Inclinometer and Accelerometer"); 247 247 MODULE_LICENSE("GPL v2"); 248 248 MODULE_ALIAS("spi:adis16209");
+41 -42
drivers/staging/iio/adc/ad7606.c
··· 26 26 27 27 #include "ad7606.h" 28 28 29 + /* Scales are computed as 2.5/2**16 and 5/2**16 respectively */ 30 + static const unsigned int scale_avail[2][2] = { 31 + {0, 38147}, {0, 76294} 32 + }; 33 + 29 34 static int ad7606_reset(struct ad7606_state *st) 30 35 { 31 36 if (st->gpio_reset) { ··· 156 151 *val = (short)ret; 157 152 return IIO_VAL_INT; 158 153 case IIO_CHAN_INFO_SCALE: 159 - *val = st->range * 2; 160 - *val2 = st->chip_info->channels[0].scan_type.realbits; 161 - return IIO_VAL_FRACTIONAL_LOG2; 154 + *val = scale_avail[st->range][0]; 155 + *val2 = scale_avail[st->range][1]; 156 + return IIO_VAL_INT_PLUS_MICRO; 162 157 case IIO_CHAN_INFO_OVERSAMPLING_RATIO: 163 158 *val = st->oversampling; 164 159 return IIO_VAL_INT; ··· 166 161 return -EINVAL; 167 162 } 168 163 169 - static ssize_t ad7606_show_range(struct device *dev, 170 - struct device_attribute *attr, char *buf) 164 + static ssize_t in_voltage_scale_available_show(struct device *dev, 165 + struct device_attribute *attr, 166 + char *buf) 171 167 { 172 - struct iio_dev *indio_dev = dev_to_iio_dev(dev); 173 - struct ad7606_state *st = iio_priv(indio_dev); 168 + int i, len = 0; 174 169 175 - return sprintf(buf, "%u\n", st->range); 170 + for (i = 0; i < ARRAY_SIZE(scale_avail); i++) 171 + len += scnprintf(buf + len, PAGE_SIZE - len, "%d.%06u ", 172 + scale_avail[i][0], scale_avail[i][1]); 173 + 174 + buf[len - 1] = '\n'; 175 + 176 + return len; 176 177 } 177 178 178 - static ssize_t ad7606_store_range(struct device *dev, 179 - struct device_attribute *attr, 180 - const char *buf, size_t count) 181 - { 182 - struct iio_dev *indio_dev = dev_to_iio_dev(dev); 183 - struct ad7606_state *st = iio_priv(indio_dev); 184 - unsigned long lval; 185 - int ret; 186 - 187 - ret = kstrtoul(buf, 10, &lval); 188 - if (ret) 189 - return ret; 190 - 191 - if (!(lval == 5000 || lval == 10000)) 192 - return -EINVAL; 193 - 194 - mutex_lock(&indio_dev->mlock); 195 - gpiod_set_value(st->gpio_range, lval == 10000); 196 - st->range = lval; 197 - mutex_unlock(&indio_dev->mlock); 198 - 199 - return count; 200 - } 201 - 202 - static IIO_DEVICE_ATTR(in_voltage_range, S_IRUGO | S_IWUSR, 203 - ad7606_show_range, ad7606_store_range, 0); 204 - static IIO_CONST_ATTR(in_voltage_range_available, "5000 10000"); 179 + static IIO_DEVICE_ATTR_RO(in_voltage_scale_available, 0); 205 180 206 181 static int ad7606_oversampling_get_index(unsigned int val) 207 182 { ··· 203 218 { 204 219 struct ad7606_state *st = iio_priv(indio_dev); 205 220 int values[3]; 206 - int ret; 221 + int ret, i; 207 222 208 223 switch (mask) { 224 + case IIO_CHAN_INFO_SCALE: 225 + ret = -EINVAL; 226 + mutex_lock(&indio_dev->mlock); 227 + for (i = 0; i < ARRAY_SIZE(scale_avail); i++) 228 + if (val2 == scale_avail[i][1]) { 229 + gpiod_set_value(st->gpio_range, i); 230 + st->range = i; 231 + 232 + ret = 0; 233 + break; 234 + } 235 + mutex_unlock(&indio_dev->mlock); 236 + 237 + return ret; 209 238 case IIO_CHAN_INFO_OVERSAMPLING_RATIO: 210 239 if (val2) 211 240 return -EINVAL; ··· 246 247 static IIO_CONST_ATTR(oversampling_ratio_available, "1 2 4 8 16 32 64"); 247 248 248 249 static struct attribute *ad7606_attributes_os_and_range[] = { 249 - &iio_dev_attr_in_voltage_range.dev_attr.attr, 250 - &iio_const_attr_in_voltage_range_available.dev_attr.attr, 250 + &iio_dev_attr_in_voltage_scale_available.dev_attr.attr, 251 251 &iio_const_attr_oversampling_ratio_available.dev_attr.attr, 252 252 NULL, 253 253 }; ··· 265 267 }; 266 268 267 269 static struct attribute *ad7606_attributes_range[] = { 268 - &iio_dev_attr_in_voltage_range.dev_attr.attr, 269 - &iio_const_attr_in_voltage_range_available.dev_attr.attr, 270 + &iio_dev_attr_in_voltage_scale_available.dev_attr.attr, 270 271 NULL, 271 272 }; 272 273 ··· 394 397 static const struct iio_info ad7606_info_range = { 395 398 .driver_module = THIS_MODULE, 396 399 .read_raw = &ad7606_read_raw, 400 + .write_raw = &ad7606_write_raw, 397 401 .attrs = &ad7606_attribute_group_range, 398 402 }; 399 403 ··· 415 417 st->dev = dev; 416 418 st->bops = bops; 417 419 st->base_address = base_address; 418 - st->range = 5000; 420 + /* tied to logic low, analog input range is +/- 5V */ 421 + st->range = 0; 419 422 st->oversampling = 1; 420 423 INIT_WORK(&st->poll_work, &ad7606_poll_bh_to_ring); 421 424 ··· 524 525 struct ad7606_state *st = iio_priv(indio_dev); 525 526 526 527 if (st->gpio_standby) { 527 - gpiod_set_value(st->gpio_range, st->range == 10000); 528 + gpiod_set_value(st->gpio_range, st->range); 528 529 gpiod_set_value(st->gpio_standby, 1); 529 530 ad7606_reset(st); 530 531 }
+2 -1
drivers/staging/iio/addac/adt7316.c
··· 661 661 chip->dac_bits = 12; 662 662 else if (chip->id == ID_ADT7317 || chip->id == ID_ADT7517) 663 663 chip->dac_bits = 10; 664 - } else 664 + } else { 665 665 config3 = chip->config3 & (~ADT7316_DA_HIGH_RESOLUTION); 666 + } 666 667 667 668 ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG3, config3); 668 669 if (ret)
+2 -2
drivers/staging/iio/cdc/ad7150.c
··· 274 274 error_ret: 275 275 mutex_unlock(&chip->state_lock); 276 276 277 - return 0; 277 + return ret; 278 278 } 279 279 280 280 static int ad7150_read_event_value(struct iio_dev *indio_dev, ··· 414 414 415 415 #define AD7150_TIMEOUT(chan, type, dir, ev_type, ev_dir) \ 416 416 IIO_DEVICE_ATTR(in_capacitance##chan##_##type##_##dir##_timeout, \ 417 - S_IRUGO | S_IWUSR, \ 417 + 0644, \ 418 418 &ad7150_show_timeout, \ 419 419 &ad7150_store_timeout, \ 420 420 IIO_UNMOD_EVENT_CODE(IIO_CAPACITANCE, \
+2 -2
drivers/staging/iio/impedance-analyzer/ad5933.c
··· 23 23 #include <linux/iio/kfifo_buf.h> 24 24 25 25 /* AD5933/AD5934 Registers */ 26 - #define AD5933_REG_CONTROL_HB 0x80 /* R/W, 2 bytes */ 27 - #define AD5933_REG_CONTROL_LB 0x81 /* R/W, 2 bytes */ 26 + #define AD5933_REG_CONTROL_HB 0x80 /* R/W, 1 byte */ 27 + #define AD5933_REG_CONTROL_LB 0x81 /* R/W, 1 byte */ 28 28 #define AD5933_REG_FREQ_START 0x82 /* R/W, 3 bytes */ 29 29 #define AD5933_REG_FREQ_INC 0x85 /* R/W, 3 bytes */ 30 30 #define AD5933_REG_INC_NUM 0x88 /* R/W, 2 bytes, 9 bit */
+57 -57
drivers/staging/iio/light/isl29028.c
··· 27 27 #include <linux/iio/iio.h> 28 28 #include <linux/iio/sysfs.h> 29 29 30 - #define ISL29028_CONV_TIME_MS 100 30 + #define ISL29028_CONV_TIME_MS 100 31 31 32 - #define ISL29028_REG_CONFIGURE 0x01 32 + #define ISL29028_REG_CONFIGURE 0x01 33 33 34 - #define ISL29028_CONF_ALS_IR_MODE_ALS 0 35 - #define ISL29028_CONF_ALS_IR_MODE_IR BIT(0) 36 - #define ISL29028_CONF_ALS_IR_MODE_MASK BIT(0) 34 + #define ISL29028_CONF_ALS_IR_MODE_ALS 0 35 + #define ISL29028_CONF_ALS_IR_MODE_IR BIT(0) 36 + #define ISL29028_CONF_ALS_IR_MODE_MASK BIT(0) 37 37 38 - #define ISL29028_CONF_ALS_RANGE_LOW_LUX 0 38 + #define ISL29028_CONF_ALS_RANGE_LOW_LUX 0 39 39 #define ISL29028_CONF_ALS_RANGE_HIGH_LUX BIT(1) 40 - #define ISL29028_CONF_ALS_RANGE_MASK BIT(1) 40 + #define ISL29028_CONF_ALS_RANGE_MASK BIT(1) 41 41 42 - #define ISL29028_CONF_ALS_DIS 0 43 - #define ISL29028_CONF_ALS_EN BIT(2) 44 - #define ISL29028_CONF_ALS_EN_MASK BIT(2) 42 + #define ISL29028_CONF_ALS_DIS 0 43 + #define ISL29028_CONF_ALS_EN BIT(2) 44 + #define ISL29028_CONF_ALS_EN_MASK BIT(2) 45 45 46 - #define ISL29028_CONF_PROX_SLP_SH 4 47 - #define ISL29028_CONF_PROX_SLP_MASK (7 << ISL29028_CONF_PROX_SLP_SH) 46 + #define ISL29028_CONF_PROX_SLP_SH 4 47 + #define ISL29028_CONF_PROX_SLP_MASK (7 << ISL29028_CONF_PROX_SLP_SH) 48 48 49 - #define ISL29028_CONF_PROX_EN BIT(7) 50 - #define ISL29028_CONF_PROX_EN_MASK BIT(7) 49 + #define ISL29028_CONF_PROX_EN BIT(7) 50 + #define ISL29028_CONF_PROX_EN_MASK BIT(7) 51 51 52 - #define ISL29028_REG_INTERRUPT 0x02 52 + #define ISL29028_REG_INTERRUPT 0x02 53 53 54 - #define ISL29028_REG_PROX_DATA 0x08 55 - #define ISL29028_REG_ALSIR_L 0x09 56 - #define ISL29028_REG_ALSIR_U 0x0A 54 + #define ISL29028_REG_PROX_DATA 0x08 55 + #define ISL29028_REG_ALSIR_L 0x09 56 + #define ISL29028_REG_ALSIR_U 0x0A 57 57 58 - #define ISL29028_REG_TEST1_MODE 0x0E 59 - #define ISL29028_REG_TEST2_MODE 0x0F 58 + #define ISL29028_REG_TEST1_MODE 0x0E 59 + #define ISL29028_REG_TEST2_MODE 0x0F 60 60 61 - #define ISL29028_NUM_REGS (ISL29028_REG_TEST2_MODE + 1) 61 + #define ISL29028_NUM_REGS (ISL29028_REG_TEST2_MODE + 1) 62 62 63 63 enum isl29028_als_ir_mode { 64 64 ISL29028_MODE_NONE = 0, ··· 124 124 { 125 125 int ret = 0; 126 126 127 + if (chip->als_ir_mode == mode) 128 + return 0; 129 + 127 130 switch (mode) { 128 131 case ISL29028_MODE_ALS: 129 132 ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, ··· 163 160 164 161 /* Need to wait for conversion time if ALS/IR mode enabled */ 165 162 mdelay(ISL29028_CONV_TIME_MS); 163 + 164 + chip->als_ir_mode = mode; 165 + 166 166 return 0; 167 167 } 168 168 ··· 229 223 int ret; 230 224 int als_ir_data; 231 225 232 - if (chip->als_ir_mode != ISL29028_MODE_ALS) { 233 - ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_ALS); 234 - if (ret < 0) { 235 - dev_err(dev, 236 - "Error in enabling ALS mode err %d\n", ret); 237 - return ret; 238 - } 239 - chip->als_ir_mode = ISL29028_MODE_ALS; 226 + ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_ALS); 227 + if (ret < 0) { 228 + dev_err(dev, "Error in enabling ALS mode err %d\n", ret); 229 + return ret; 240 230 } 241 231 242 232 ret = isl29028_read_als_ir(chip, &als_ir_data); ··· 258 256 struct device *dev = regmap_get_device(chip->regmap); 259 257 int ret; 260 258 261 - if (chip->als_ir_mode != ISL29028_MODE_IR) { 262 - ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_IR); 263 - if (ret < 0) { 264 - dev_err(dev, 265 - "Error in enabling IR mode err %d\n", ret); 266 - return ret; 267 - } 268 - chip->als_ir_mode = ISL29028_MODE_IR; 259 + ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_IR); 260 + if (ret < 0) { 261 + dev_err(dev, "Error in enabling IR mode err %d\n", ret); 262 + return ret; 269 263 } 270 264 return isl29028_read_als_ir(chip, ir_data); 271 265 } ··· 418 420 .write_raw = isl29028_write_raw, 419 421 }; 420 422 421 - static int isl29028_chip_init(struct isl29028_chip *chip) 423 + static int isl29028_chip_init_and_power_on(struct isl29028_chip *chip) 422 424 { 423 425 struct device *dev = regmap_get_device(chip->regmap); 424 426 int ret; 425 - 426 - chip->enable_prox = false; 427 - chip->prox_sampling = 20; 428 - chip->lux_scale = 2000; 429 - chip->als_ir_mode = ISL29028_MODE_NONE; 430 - 431 - ret = regmap_write(chip->regmap, ISL29028_REG_TEST1_MODE, 0x0); 432 - if (ret < 0) { 433 - dev_err(dev, "%s(): write to reg %d failed, err = %d\n", 434 - __func__, ISL29028_REG_TEST1_MODE, ret); 435 - return ret; 436 - } 437 - ret = regmap_write(chip->regmap, ISL29028_REG_TEST2_MODE, 0x0); 438 - if (ret < 0) { 439 - dev_err(dev, "%s(): write to reg %d failed, err = %d\n", 440 - __func__, ISL29028_REG_TEST2_MODE, ret); 441 - return ret; 442 - } 443 427 444 428 ret = regmap_write(chip->regmap, ISL29028_REG_CONFIGURE, 0x0); 445 429 if (ret < 0) { ··· 490 510 return ret; 491 511 } 492 512 493 - ret = isl29028_chip_init(chip); 513 + chip->enable_prox = false; 514 + chip->prox_sampling = 20; 515 + chip->lux_scale = 2000; 516 + chip->als_ir_mode = ISL29028_MODE_NONE; 517 + 518 + ret = regmap_write(chip->regmap, ISL29028_REG_TEST1_MODE, 0x0); 519 + if (ret < 0) { 520 + dev_err(&client->dev, 521 + "%s(): write to reg %d failed, err = %d\n", __func__, 522 + ISL29028_REG_TEST1_MODE, ret); 523 + return ret; 524 + } 525 + ret = regmap_write(chip->regmap, ISL29028_REG_TEST2_MODE, 0x0); 526 + if (ret < 0) { 527 + dev_err(&client->dev, 528 + "%s(): write to reg %d failed, err = %d\n", __func__, 529 + ISL29028_REG_TEST2_MODE, ret); 530 + return ret; 531 + } 532 + 533 + ret = isl29028_chip_init_and_power_on(chip); 494 534 if (ret < 0) { 495 535 dev_err(&client->dev, "chip initialization failed: %d\n", ret); 496 536 return ret;
+1 -1
drivers/staging/iio/meter/ade7753.c
··· 377 377 } 378 378 379 379 ade7753_reset(dev); 380 - msleep(ADE7753_STARTUP_DELAY); 380 + usleep_range(ADE7753_STARTUP_DELAY, ADE7753_STARTUP_DELAY + 100); 381 381 382 382 err_ret: 383 383 return ret;
+1 -1
drivers/staging/iio/meter/ade7753.h
··· 49 49 50 50 #define ADE7753_MAX_TX 4 51 51 #define ADE7753_MAX_RX 4 52 - #define ADE7753_STARTUP_DELAY 1 52 + #define ADE7753_STARTUP_DELAY 1000 53 53 54 54 #define ADE7753_SPI_SLOW (u32)(300 * 1000) 55 55 #define ADE7753_SPI_BURST (u32)(1000 * 1000)
+1 -1
drivers/staging/iio/meter/ade7754.c
··· 389 389 } 390 390 391 391 ade7754_reset(dev); 392 - msleep(ADE7754_STARTUP_DELAY); 392 + usleep_range(ADE7754_STARTUP_DELAY, ADE7754_STARTUP_DELAY + 100); 393 393 394 394 err_ret: 395 395 return ret;
+1 -1
drivers/staging/iio/meter/ade7754.h
··· 67 67 68 68 #define ADE7754_MAX_TX 4 69 69 #define ADE7754_MAX_RX 4 70 - #define ADE7754_STARTUP_DELAY 1 70 + #define ADE7754_STARTUP_DELAY 1000 71 71 72 72 #define ADE7754_SPI_SLOW (u32)(300 * 1000) 73 73 #define ADE7754_SPI_BURST (u32)(1000 * 1000)
+1 -1
drivers/staging/iio/meter/ade7758.h
··· 89 89 90 90 #define ADE7758_MAX_TX 8 91 91 #define ADE7758_MAX_RX 4 92 - #define ADE7758_STARTUP_DELAY 1 92 + #define ADE7758_STARTUP_DELAY 1000 93 93 94 94 #define AD7758_NUM_WAVSEL 5 95 95 #define AD7758_NUM_PHSEL 3
+1 -1
drivers/staging/iio/meter/ade7758_core.c
··· 459 459 } 460 460 461 461 ade7758_reset(dev); 462 - msleep(ADE7758_STARTUP_DELAY); 462 + usleep_range(ADE7758_STARTUP_DELAY, ADE7758_STARTUP_DELAY + 100); 463 463 464 464 err_ret: 465 465 return ret;
+1
drivers/staging/iio/meter/ade7758_ring.c
··· 13 13 #include <asm/unaligned.h> 14 14 15 15 #include <linux/iio/iio.h> 16 + #include <linux/iio/buffer.h> 16 17 #include <linux/iio/kfifo_buf.h> 17 18 #include <linux/iio/trigger_consumer.h> 18 19 #include "ade7758.h"
+1 -1
drivers/staging/iio/meter/ade7759.c
··· 338 338 } 339 339 340 340 ade7759_reset(dev); 341 - msleep(ADE7759_STARTUP_DELAY); 341 + usleep_range(ADE7759_STARTUP_DELAY, ADE7759_STARTUP_DELAY + 100); 342 342 343 343 err_ret: 344 344 return ret;
+1 -1
drivers/staging/iio/meter/ade7759.h
··· 30 30 31 31 #define ADE7759_MAX_TX 6 32 32 #define ADE7759_MAX_RX 6 33 - #define ADE7759_STARTUP_DELAY 1 33 + #define ADE7759_STARTUP_DELAY 1000 34 34 35 35 #define ADE7759_SPI_SLOW (u32)(300 * 1000) 36 36 #define ADE7759_SPI_BURST (u32)(1000 * 1000)
+1 -1
drivers/staging/iio/meter/ade7854.c
··· 444 444 } 445 445 446 446 ade7854_reset(dev); 447 - msleep(ADE7854_STARTUP_DELAY); 447 + usleep_range(ADE7854_STARTUP_DELAY, ADE7854_STARTUP_DELAY + 100); 448 448 449 449 err_ret: 450 450 return ret;
+1 -1
drivers/staging/iio/meter/ade7854.h
··· 136 136 137 137 #define ADE7854_MAX_TX 7 138 138 #define ADE7854_MAX_RX 7 139 - #define ADE7854_STARTUP_DELAY 1 139 + #define ADE7854_STARTUP_DELAY 1000 140 140 141 141 #define ADE7854_SPI_SLOW (u32)(300 * 1000) 142 142 #define ADE7854_SPI_BURST (u32)(1000 * 1000)
+1 -1
drivers/staging/iio/trigger/iio-trig-bfin-timer.c
··· 133 133 return sprintf(buf, "%lu\n", val); 134 134 } 135 135 136 - static DEVICE_ATTR(frequency, S_IRUGO | S_IWUSR, iio_bfin_tmr_frequency_show, 136 + static DEVICE_ATTR(frequency, 0644, iio_bfin_tmr_frequency_show, 137 137 iio_bfin_tmr_frequency_store); 138 138 139 139 static struct attribute *iio_bfin_tmr_trigger_attrs[] = {
+4
include/linux/hid-sensor-hub.h
··· 232 232 atomic_t data_ready; 233 233 atomic_t user_requested_state; 234 234 struct iio_trigger *trigger; 235 + int timestamp_ns_scale; 235 236 struct hid_sensor_hub_attribute_info poll; 236 237 struct hid_sensor_hub_attribute_info report_state; 237 238 struct hid_sensor_hub_attribute_info power_state; ··· 271 270 int *val0, int *val1); 272 271 273 272 s32 hid_sensor_read_poll_value(struct hid_sensor_common *st); 273 + 274 + int64_t hid_sensor_convert_timestamp(struct hid_sensor_common *st, 275 + int64_t raw_value); 274 276 275 277 #endif
+4
include/linux/hid-sensor-ids.h
··· 52 52 #define HID_USAGE_SENSOR_ANGL_VELOCITY_Y_AXIS 0x200458 53 53 #define HID_USAGE_SENSOR_ANGL_VELOCITY_Z_AXIS 0x200459 54 54 55 + /* Gravity vector */ 56 + #define HID_USAGE_SENSOR_GRAVITY_VECTOR 0x20007B 57 + 55 58 /* ORIENTATION: Compass 3D: (200083) */ 56 59 #define HID_USAGE_SENSOR_COMPASS_3D 0x200083 57 60 #define HID_USAGE_SENSOR_DATA_ORIENTATION 0x200470 ··· 98 95 #define HID_USAGE_SENSOR_TIME_HOUR 0x200525 99 96 #define HID_USAGE_SENSOR_TIME_MINUTE 0x200526 100 97 #define HID_USAGE_SENSOR_TIME_SECOND 0x200527 98 + #define HID_USAGE_SENSOR_TIME_TIMESTAMP 0x200529 101 99 102 100 /* Units */ 103 101 #define HID_USAGE_SENSOR_UNITS_NOT_SPECIFIED 0x00
+6 -154
include/linux/iio/buffer.h
··· 11 11 #define _IIO_BUFFER_GENERIC_H_ 12 12 #include <linux/sysfs.h> 13 13 #include <linux/iio/iio.h> 14 - #include <linux/kref.h> 15 - 16 - #ifdef CONFIG_IIO_BUFFER 17 14 18 15 struct iio_buffer; 19 16 20 - /** 21 - * INDIO_BUFFER_FLAG_FIXED_WATERMARK - Watermark level of the buffer can not be 22 - * configured. It has a fixed value which will be buffer specific. 23 - */ 24 - #define INDIO_BUFFER_FLAG_FIXED_WATERMARK BIT(0) 17 + void iio_buffer_set_attrs(struct iio_buffer *buffer, 18 + const struct attribute **attrs); 25 19 26 - /** 27 - * struct iio_buffer_access_funcs - access functions for buffers. 28 - * @store_to: actually store stuff to the buffer 29 - * @read_first_n: try to get a specified number of bytes (must exist) 30 - * @data_available: indicates how much data is available for reading from 31 - * the buffer. 32 - * @request_update: if a parameter change has been marked, update underlying 33 - * storage. 34 - * @set_bytes_per_datum:set number of bytes per datum 35 - * @set_length: set number of datums in buffer 36 - * @enable: called if the buffer is attached to a device and the 37 - * device starts sampling. Calls are balanced with 38 - * @disable. 39 - * @disable: called if the buffer is attached to a device and the 40 - * device stops sampling. Calles are balanced with @enable. 41 - * @release: called when the last reference to the buffer is dropped, 42 - * should free all resources allocated by the buffer. 43 - * @modes: Supported operating modes by this buffer type 44 - * @flags: A bitmask combination of INDIO_BUFFER_FLAG_* 45 - * 46 - * The purpose of this structure is to make the buffer element 47 - * modular as event for a given driver, different usecases may require 48 - * different buffer designs (space efficiency vs speed for example). 49 - * 50 - * It is worth noting that a given buffer implementation may only support a 51 - * small proportion of these functions. The core code 'should' cope fine with 52 - * any of them not existing. 53 - **/ 54 - struct iio_buffer_access_funcs { 55 - int (*store_to)(struct iio_buffer *buffer, const void *data); 56 - int (*read_first_n)(struct iio_buffer *buffer, 57 - size_t n, 58 - char __user *buf); 59 - size_t (*data_available)(struct iio_buffer *buffer); 60 - 61 - int (*request_update)(struct iio_buffer *buffer); 62 - 63 - int (*set_bytes_per_datum)(struct iio_buffer *buffer, size_t bpd); 64 - int (*set_length)(struct iio_buffer *buffer, int length); 65 - 66 - int (*enable)(struct iio_buffer *buffer, struct iio_dev *indio_dev); 67 - int (*disable)(struct iio_buffer *buffer, struct iio_dev *indio_dev); 68 - 69 - void (*release)(struct iio_buffer *buffer); 70 - 71 - unsigned int modes; 72 - unsigned int flags; 73 - }; 74 - 75 - /** 76 - * struct iio_buffer - general buffer structure 77 - * @length: [DEVICE] number of datums in buffer 78 - * @bytes_per_datum: [DEVICE] size of individual datum including timestamp 79 - * @scan_el_attrs: [DRIVER] control of scan elements if that scan mode 80 - * control method is used 81 - * @scan_mask: [INTERN] bitmask used in masking scan mode elements 82 - * @scan_timestamp: [INTERN] does the scan mode include a timestamp 83 - * @access: [DRIVER] buffer access functions associated with the 84 - * implementation. 85 - * @scan_el_dev_attr_list:[INTERN] list of scan element related attributes. 86 - * @buffer_group: [INTERN] attributes of the buffer group 87 - * @scan_el_group: [DRIVER] attribute group for those attributes not 88 - * created from the iio_chan_info array. 89 - * @pollq: [INTERN] wait queue to allow for polling on the buffer. 90 - * @stufftoread: [INTERN] flag to indicate new data. 91 - * @attrs: [INTERN] standard attributes of the buffer 92 - * @demux_list: [INTERN] list of operations required to demux the scan. 93 - * @demux_bounce: [INTERN] buffer for doing gather from incoming scan. 94 - * @buffer_list: [INTERN] entry in the devices list of current buffers. 95 - * @ref: [INTERN] reference count of the buffer. 96 - * @watermark: [INTERN] number of datums to wait for poll/read. 97 - */ 98 - struct iio_buffer { 99 - int length; 100 - int bytes_per_datum; 101 - struct attribute_group *scan_el_attrs; 102 - long *scan_mask; 103 - bool scan_timestamp; 104 - const struct iio_buffer_access_funcs *access; 105 - struct list_head scan_el_dev_attr_list; 106 - struct attribute_group buffer_group; 107 - struct attribute_group scan_el_group; 108 - wait_queue_head_t pollq; 109 - bool stufftoread; 110 - const struct attribute **attrs; 111 - struct list_head demux_list; 112 - void *demux_bounce; 113 - struct list_head buffer_list; 114 - struct kref ref; 115 - unsigned int watermark; 116 - }; 117 - 118 - /** 119 - * iio_update_buffers() - add or remove buffer from active list 120 - * @indio_dev: device to add buffer to 121 - * @insert_buffer: buffer to insert 122 - * @remove_buffer: buffer_to_remove 123 - * 124 - * Note this will tear down the all buffering and build it up again 125 - */ 126 - int iio_update_buffers(struct iio_dev *indio_dev, 127 - struct iio_buffer *insert_buffer, 128 - struct iio_buffer *remove_buffer); 129 - 130 - /** 131 - * iio_buffer_init() - Initialize the buffer structure 132 - * @buffer: buffer to be initialized 133 - **/ 134 - void iio_buffer_init(struct iio_buffer *buffer); 135 - 136 - int iio_scan_mask_query(struct iio_dev *indio_dev, 137 - struct iio_buffer *buffer, int bit); 138 - 139 - /** 140 - * iio_push_to_buffers() - push to a registered buffer. 141 - * @indio_dev: iio_dev structure for device. 142 - * @data: Full scan. 143 - */ 144 20 int iio_push_to_buffers(struct iio_dev *indio_dev, const void *data); 145 21 146 - /* 22 + /** 147 23 * iio_push_to_buffers_with_timestamp() - push data and timestamp to buffers 148 24 * @indio_dev: iio_dev structure for device. 149 25 * @data: sample data ··· 44 168 return iio_push_to_buffers(indio_dev, data); 45 169 } 46 170 47 - int iio_update_demux(struct iio_dev *indio_dev); 48 - 49 171 bool iio_validate_scan_mask_onehot(struct iio_dev *indio_dev, 50 - const unsigned long *mask); 172 + const unsigned long *mask); 51 173 52 - struct iio_buffer *iio_buffer_get(struct iio_buffer *buffer); 53 - void iio_buffer_put(struct iio_buffer *buffer); 54 - 55 - /** 56 - * iio_device_attach_buffer - Attach a buffer to a IIO device 57 - * @indio_dev: The device the buffer should be attached to 58 - * @buffer: The buffer to attach to the device 59 - * 60 - * This function attaches a buffer to a IIO device. The buffer stays attached to 61 - * the device until the device is freed. The function should only be called at 62 - * most once per device. 63 - */ 64 - static inline void iio_device_attach_buffer(struct iio_dev *indio_dev, 65 - struct iio_buffer *buffer) 66 - { 67 - indio_dev->buffer = iio_buffer_get(buffer); 68 - } 69 - 70 - #else /* CONFIG_IIO_BUFFER */ 71 - 72 - static inline void iio_buffer_get(struct iio_buffer *buffer) {} 73 - static inline void iio_buffer_put(struct iio_buffer *buffer) {} 74 - 75 - #endif /* CONFIG_IIO_BUFFER */ 174 + void iio_device_attach_buffer(struct iio_dev *indio_dev, 175 + struct iio_buffer *buffer); 76 176 77 177 #endif /* _IIO_BUFFER_GENERIC_H_ */
+162
include/linux/iio/buffer_impl.h
··· 1 + #ifndef _IIO_BUFFER_GENERIC_IMPL_H_ 2 + #define _IIO_BUFFER_GENERIC_IMPL_H_ 3 + #include <linux/sysfs.h> 4 + #include <linux/kref.h> 5 + 6 + #ifdef CONFIG_IIO_BUFFER 7 + 8 + struct iio_dev; 9 + struct iio_buffer; 10 + 11 + /** 12 + * INDIO_BUFFER_FLAG_FIXED_WATERMARK - Watermark level of the buffer can not be 13 + * configured. It has a fixed value which will be buffer specific. 14 + */ 15 + #define INDIO_BUFFER_FLAG_FIXED_WATERMARK BIT(0) 16 + 17 + /** 18 + * struct iio_buffer_access_funcs - access functions for buffers. 19 + * @store_to: actually store stuff to the buffer 20 + * @read_first_n: try to get a specified number of bytes (must exist) 21 + * @data_available: indicates how much data is available for reading from 22 + * the buffer. 23 + * @request_update: if a parameter change has been marked, update underlying 24 + * storage. 25 + * @set_bytes_per_datum:set number of bytes per datum 26 + * @set_length: set number of datums in buffer 27 + * @enable: called if the buffer is attached to a device and the 28 + * device starts sampling. Calls are balanced with 29 + * @disable. 30 + * @disable: called if the buffer is attached to a device and the 31 + * device stops sampling. Calles are balanced with @enable. 32 + * @release: called when the last reference to the buffer is dropped, 33 + * should free all resources allocated by the buffer. 34 + * @modes: Supported operating modes by this buffer type 35 + * @flags: A bitmask combination of INDIO_BUFFER_FLAG_* 36 + * 37 + * The purpose of this structure is to make the buffer element 38 + * modular as event for a given driver, different usecases may require 39 + * different buffer designs (space efficiency vs speed for example). 40 + * 41 + * It is worth noting that a given buffer implementation may only support a 42 + * small proportion of these functions. The core code 'should' cope fine with 43 + * any of them not existing. 44 + **/ 45 + struct iio_buffer_access_funcs { 46 + int (*store_to)(struct iio_buffer *buffer, const void *data); 47 + int (*read_first_n)(struct iio_buffer *buffer, 48 + size_t n, 49 + char __user *buf); 50 + size_t (*data_available)(struct iio_buffer *buffer); 51 + 52 + int (*request_update)(struct iio_buffer *buffer); 53 + 54 + int (*set_bytes_per_datum)(struct iio_buffer *buffer, size_t bpd); 55 + int (*set_length)(struct iio_buffer *buffer, int length); 56 + 57 + int (*enable)(struct iio_buffer *buffer, struct iio_dev *indio_dev); 58 + int (*disable)(struct iio_buffer *buffer, struct iio_dev *indio_dev); 59 + 60 + void (*release)(struct iio_buffer *buffer); 61 + 62 + unsigned int modes; 63 + unsigned int flags; 64 + }; 65 + 66 + /** 67 + * struct iio_buffer - general buffer structure 68 + * 69 + * Note that the internals of this structure should only be of interest to 70 + * those writing new buffer implementations. 71 + */ 72 + struct iio_buffer { 73 + /** @length: Number of datums in buffer. */ 74 + int length; 75 + 76 + /** @bytes_per_datum: Size of individual datum including timestamp. */ 77 + int bytes_per_datum; 78 + 79 + /** 80 + * @access: Buffer access functions associated with the 81 + * implementation. 82 + */ 83 + const struct iio_buffer_access_funcs *access; 84 + 85 + /** @scan_mask: Bitmask used in masking scan mode elements. */ 86 + long *scan_mask; 87 + 88 + /** @demux_list: List of operations required to demux the scan. */ 89 + struct list_head demux_list; 90 + 91 + /** @pollq: Wait queue to allow for polling on the buffer. */ 92 + wait_queue_head_t pollq; 93 + 94 + /** @watermark: Number of datums to wait for poll/read. */ 95 + unsigned int watermark; 96 + 97 + /* private: */ 98 + /* 99 + * @scan_el_attrs: Control of scan elements if that scan mode 100 + * control method is used. 101 + */ 102 + struct attribute_group *scan_el_attrs; 103 + 104 + /* @scan_timestamp: Does the scan mode include a timestamp. */ 105 + bool scan_timestamp; 106 + 107 + /* @scan_el_dev_attr_list: List of scan element related attributes. */ 108 + struct list_head scan_el_dev_attr_list; 109 + 110 + /* @buffer_group: Attributes of the buffer group. */ 111 + struct attribute_group buffer_group; 112 + 113 + /* 114 + * @scan_el_group: Attribute group for those attributes not 115 + * created from the iio_chan_info array. 116 + */ 117 + struct attribute_group scan_el_group; 118 + 119 + /* @stufftoread: Flag to indicate new data. */ 120 + bool stufftoread; 121 + 122 + /* @attrs: Standard attributes of the buffer. */ 123 + const struct attribute **attrs; 124 + 125 + /* @demux_bounce: Buffer for doing gather from incoming scan. */ 126 + void *demux_bounce; 127 + 128 + /* @buffer_list: Entry in the devices list of current buffers. */ 129 + struct list_head buffer_list; 130 + 131 + /* @ref: Reference count of the buffer. */ 132 + struct kref ref; 133 + }; 134 + 135 + /** 136 + * iio_update_buffers() - add or remove buffer from active list 137 + * @indio_dev: device to add buffer to 138 + * @insert_buffer: buffer to insert 139 + * @remove_buffer: buffer_to_remove 140 + * 141 + * Note this will tear down the all buffering and build it up again 142 + */ 143 + int iio_update_buffers(struct iio_dev *indio_dev, 144 + struct iio_buffer *insert_buffer, 145 + struct iio_buffer *remove_buffer); 146 + 147 + /** 148 + * iio_buffer_init() - Initialize the buffer structure 149 + * @buffer: buffer to be initialized 150 + **/ 151 + void iio_buffer_init(struct iio_buffer *buffer); 152 + 153 + struct iio_buffer *iio_buffer_get(struct iio_buffer *buffer); 154 + void iio_buffer_put(struct iio_buffer *buffer); 155 + 156 + #else /* CONFIG_IIO_BUFFER */ 157 + 158 + static inline void iio_buffer_get(struct iio_buffer *buffer) {} 159 + static inline void iio_buffer_put(struct iio_buffer *buffer) {} 160 + 161 + #endif /* CONFIG_IIO_BUFFER */ 162 + #endif /* _IIO_BUFFER_GENERIC_IMPL_H_ */
+9
include/linux/iio/common/st_sensors_i2c.h
··· 28 28 } 29 29 #endif 30 30 31 + #ifdef CONFIG_ACPI 32 + int st_sensors_match_acpi_device(struct device *dev); 33 + #else 34 + static inline int st_sensors_match_acpi_device(struct device *dev) 35 + { 36 + return -ENODEV; 37 + } 38 + #endif 39 + 31 40 #endif /* ST_SENSORS_I2C_H */
+2 -3
include/linux/iio/kfifo_buf.h
··· 1 1 #ifndef __LINUX_IIO_KFIFO_BUF_H__ 2 2 #define __LINUX_IIO_KFIFO_BUF_H__ 3 3 4 - #include <linux/kfifo.h> 5 - #include <linux/iio/iio.h> 6 - #include <linux/iio/buffer.h> 4 + struct iio_buffer; 5 + struct device; 7 6 8 7 struct iio_buffer *iio_kfifo_allocate(void); 9 8 void iio_kfifo_free(struct iio_buffer *r);
+1
include/uapi/linux/iio/types.h
··· 42 42 IIO_ELECTRICALCONDUCTIVITY, 43 43 IIO_COUNT, 44 44 IIO_INDEX, 45 + IIO_GRAVITY, 45 46 }; 46 47 47 48 enum iio_modifier {
+2
tools/iio/iio_event_monitor.c
··· 57 57 [IIO_RESISTANCE] = "resistance", 58 58 [IIO_PH] = "ph", 59 59 [IIO_UVINDEX] = "uvindex", 60 + [IIO_GRAVITY] = "gravity", 60 61 }; 61 62 62 63 static const char * const iio_ev_type_text[] = { ··· 150 149 case IIO_RESISTANCE: 151 150 case IIO_PH: 152 151 case IIO_UVINDEX: 152 + case IIO_GRAVITY: 153 153 break; 154 154 default: 155 155 return false;