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

Merge tag 'iio-for-4.9a' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into work-testing

Jonathan writes:

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

Device support

* ak8974
- New driver and bindings for this 2009 vintage magnetometer (it was very
popular back then!)
* atlas-ph-sensor
- ORP sensor support(I had to look up what one of these was)
* cio-dac
- New driver for Measurement Computing DAC boards
* dmard06
- New driver for Domintech DMARDO6 accelerometer. Also vendor prefix.
* dmard09
- New driver for Domintech DMARD09 accelerometer.
* maxim-thermocouple
- max6675 and max31855 new driver
* mt6577 auxdac
- new driver for this Mediatek chip mt2701, mt6577 and mt8173 have this
hardware.
* ti-adc161s626
- new driver for this TI single channel differential ADC.
* vcnl4000
- support vcnl4010 and vcnl4020 which are compatible for all features
currently supported by this driver.

New features

* Core
- Allow retrieving of underlying iio_dev from a callback buffer handle.
This is needed to allow client drivers to perform operations such as
configuring the trigger used.
* hid-sensors
- asynchronous resume support to avoid really long resume times.
* kxcjk-1013
- add the mysterious KIOX000A ACPI id seen in the wild.
* Tools
- lsiio now enumerates processed as well as raw channels.

Cleanup

* ad7298
- use iio_device_claim_direct_mode and friends to simplify locking around
mode switching and drop some boilerplate.
* ad7793
- use iio_device_claim_direct_mode and friends to simplify locking around
mode switching and drop some boilerplate.
* ade7854
- checkpatch fixups (alignment of parameters)
* atlas-ph-sensor
- use iio_device_claim_direct_mode and friends to simplify locking around
mode switching and drop some boilerplate.
- Switch to REGCACHE_NONE as there are no useful register to cache.
* bma180
- use iio_device_claim_direct_mode and friends to simplify locking around
mode switching and drop some boilerplate.
* hdc100x
- Add mention of the HDC1000 and HDC1008 to the Kconfig help text.
* isl29018
- Add driver specific prefixes to defines and function names.
- Remove excessive logging.
- Drop newlines which add nothing to readability.
- General tidying up of comments.
- Drop I2C_CLASS_HWMON as irrelevant to driver.
* isl29028
- Add driver specific prefixes to defines, enums and function names.
- Drop comma's from available attribute output as not ABI compliant.
- Drop I2C_CLASS_HWMON as irrelevant to driver.
* kxsd9
- devicetree bindings.
* mag3110
- This one wasn't locking to protect against mode switches during
raw_reads. Use the iio_claim_direct_mode function to fix this buglet.
* maxim-theromcouple
- Fix missing selects for triggered buffer support in Kconfig.
* nau7802
- Use complete instead of complete_all as only one completion at a time.
* sx9500
- Use complete instead of complete_all as only one completion at a time.
* us5182d
- Add a missing error code asignment instead of checking the result of
an already checked statement.
* vcnl4000
- Use BIT macro where appropriate.
- Refactor return codes in read_raw callback.
- Add some missing locking for concurrent accesses to the device.

+2817 -274
+1
Documentation/devicetree/bindings/i2c/trivial-devices.txt
··· 38 38 dallas,ds75 Digital Thermometer and Thermostat 39 39 dlg,da9053 DA9053: flexible system level PMIC with multicore support 40 40 dlg,da9063 DA9063: system PMIC for quad-core application processors 41 + domintech,dmard09 DMARD09: 3-axis Accelerometer 41 42 epson,rx8010 I2C-BUS INTERFACE REAL TIME CLOCK MODULE 42 43 epson,rx8025 High-Stability. I2C-Bus INTERFACE REAL TIME CLOCK MODULE 43 44 epson,rx8581 I2C-BUS INTERFACE REAL TIME CLOCK MODULE
+19
Documentation/devicetree/bindings/iio/accel/dmard06.txt
··· 1 + Device tree bindings for Domintech DMARD05, DMARD06, DMARD07 accelerometers 2 + 3 + Required properties: 4 + - compatible : Should be "domintech,dmard05" 5 + or "domintech,dmard06" 6 + or "domintech,dmard07" 7 + - reg : I2C address of the chip. Should be 0x1c 8 + 9 + Example: 10 + &i2c1 { 11 + /* ... */ 12 + 13 + accelerometer@1c { 14 + compatible = "domintech,dmard06"; 15 + reg = <0x1c>; 16 + }; 17 + 18 + /* ... */ 19 + };
+22
Documentation/devicetree/bindings/iio/accel/kionix,kxsd9.txt
··· 1 + Kionix KXSD9 Accelerometer device tree bindings 2 + 3 + Required properties: 4 + - compatible: should be set to "kionix,kxsd9" 5 + - reg: i2c slave address 6 + 7 + Optional properties: 8 + - vdd-supply: The input supply for VDD 9 + - iovdd-supply: The input supply for IOVDD 10 + - interrupts: The movement detection interrupt 11 + - mount-matrix: See mount-matrix.txt 12 + 13 + Example: 14 + 15 + kxsd9@18 { 16 + compatible = "kionix,kxsd9"; 17 + reg = <0x18>; 18 + interrupt-parent = <&foo>; 19 + interrupts = <57 IRQ_TYPE_EDGE_FALLING>; 20 + iovdd-supply = <&bar>; 21 + vdd-supply = <&baz>; 22 + };
+29
Documentation/devicetree/bindings/iio/adc/mt6577_auxadc.txt
··· 1 + * Mediatek AUXADC - Analog to Digital Converter on Mediatek mobile soc (mt65xx/mt81xx/mt27xx) 2 + =============== 3 + 4 + The Auxiliary Analog/Digital Converter (AUXADC) is an ADC found 5 + in some Mediatek SoCs which among other things measures the temperatures 6 + in the SoC. It can be used directly with register accesses, but it is also 7 + used by thermal controller which reads the temperatures from the AUXADC 8 + directly via its own bus interface. See 9 + Documentation/devicetree/bindings/thermal/mediatek-thermal.txt 10 + for the Thermal Controller which holds a phandle to the AUXADC. 11 + 12 + Required properties: 13 + - compatible: Should be one of: 14 + - "mediatek,mt2701-auxadc": For MT2701 family of SoCs 15 + - "mediatek,mt8173-auxadc": For MT8173 family of SoCs 16 + - reg: Address range of the AUXADC unit. 17 + - clocks: Should contain a clock specifier for each entry in clock-names 18 + - clock-names: Should contain "main". 19 + - #io-channel-cells: Should be 1, see ../iio-bindings.txt 20 + 21 + Example: 22 + 23 + auxadc: adc@11001000 { 24 + compatible = "mediatek,mt2701-auxadc"; 25 + reg = <0 0x11001000 0 0x1000>; 26 + clocks = <&pericfg CLK_PERI_AUXADC>; 27 + clock-names = "main"; 28 + #io-channel-cells = <1>; 29 + };
+16
Documentation/devicetree/bindings/iio/adc/ti-adc161s626.txt
··· 1 + * Texas Instruments ADC141S626 and ADC161S626 chips 2 + 3 + Required properties: 4 + - compatible: Should be "ti,adc141s626" or "ti,adc161s626" 5 + - reg: spi chip select number for the device 6 + 7 + Recommended properties: 8 + - spi-max-frequency: Definition as per 9 + Documentation/devicetree/bindings/spi/spi-bus.txt 10 + 11 + Example: 12 + adc@0 { 13 + compatible = "ti,adc161s626"; 14 + reg = <0>; 15 + spi-max-frequency = <4300000>; 16 + };
+22
Documentation/devicetree/bindings/iio/chemical/atlas,orp-sm.txt
··· 1 + * Atlas Scientific ORP-SM OEM sensor 2 + 3 + https://www.atlas-scientific.com/_files/_datasheets/_oem/ORP_oem_datasheet.pdf 4 + 5 + Required properties: 6 + 7 + - compatible: must be "atlas,orp-sm" 8 + - reg: the I2C address of the sensor 9 + - interrupt-parent: should be the phandle for the interrupt controller 10 + - interrupts: the sole interrupt generated by the device 11 + 12 + Refer to interrupt-controller/interrupts.txt for generic interrupt client 13 + node bindings. 14 + 15 + Example: 16 + 17 + atlas@66 { 18 + compatible = "atlas,orp-sm"; 19 + reg = <0x66>; 20 + interrupt-parent = <&gpio1>; 21 + interrupts = <16 2>; 22 + };
+29
Documentation/devicetree/bindings/iio/magnetometer/ak8974.txt
··· 1 + * Asahi Kasei AK8974 magnetometer sensor 2 + 3 + Required properties: 4 + 5 + - compatible : should be "asahi-kasei,ak8974" 6 + - reg : the I2C address of the magnetometer 7 + 8 + Optional properties: 9 + 10 + - avdd-supply: regulator supply for the analog voltage 11 + (see regulator/regulator.txt) 12 + - dvdd-supply: regulator supply for the digital voltage 13 + (see regulator/regulator.txt) 14 + - interrupts: data ready (DRDY) and interrupt (INT1) lines 15 + from the chip, the DRDY interrupt must be placed first. 16 + The interrupts can be triggered on rising or falling 17 + edges alike. 18 + - mount-matrix: an optional 3x3 mounting rotation matrix 19 + 20 + Example: 21 + 22 + ak8974@0f { 23 + compatible = "asahi-kasei,ak8974"; 24 + reg = <0x0f>; 25 + avdd-supply = <&foo_reg>; 26 + dvdd-supply = <&bar_reg>; 27 + interrupts = <0 IRQ_TYPE_EDGE_RISING>, 28 + <1 IRQ_TYPE_EDGE_RISING>; 29 + };
+21
Documentation/devicetree/bindings/iio/temperature/maxim_thermocouple.txt
··· 1 + Maxim thermocouple support 2 + 3 + * https://datasheets.maximintegrated.com/en/ds/MAX6675.pdf 4 + * https://datasheets.maximintegrated.com/en/ds/MAX31855.pdf 5 + 6 + Required properties: 7 + 8 + - compatible: must be "maxim,max31855" or "maxim,max6675" 9 + - reg: SPI chip select number for the device 10 + - spi-max-frequency: must be 4300000 11 + - spi-cpha: must be defined for max6675 to enable SPI mode 1 12 + 13 + Refer to spi/spi-bus.txt for generic SPI slave bindings. 14 + 15 + Example: 16 + 17 + max31855@0 { 18 + compatible = "maxim,max31855"; 19 + reg = <0>; 20 + spi-max-frequency = <4300000>; 21 + };
-21
Documentation/devicetree/bindings/soc/mediatek/auxadc.txt
··· 1 - MediaTek AUXADC 2 - =============== 3 - 4 - The Auxiliary Analog/Digital Converter (AUXADC) is an ADC found 5 - in some Mediatek SoCs which among other things measures the temperatures 6 - in the SoC. It can be used directly with register accesses, but it is also 7 - used by thermal controller which reads the temperatures from the AUXADC 8 - directly via its own bus interface. See 9 - Documentation/devicetree/bindings/thermal/mediatek-thermal.txt 10 - for the Thermal Controller which holds a phandle to the AUXADC. 11 - 12 - Required properties: 13 - - compatible: Must be "mediatek,mt8173-auxadc" 14 - - reg: Address range of the AUXADC unit 15 - 16 - Example: 17 - 18 - auxadc: auxadc@11001000 { 19 - compatible = "mediatek,mt8173-auxadc"; 20 - reg = <0 0x11001000 0 0x1000>; 21 - };
+1
Documentation/devicetree/bindings/vendor-prefixes.txt
··· 75 75 dlg Dialog Semiconductor 76 76 dlink D-Link Corporation 77 77 dmo Data Modul AG 78 + domintech Domintech Co., Ltd. 78 79 dptechnics DPTechnics 79 80 dragino Dragino Technology Co., Limited 80 81 ea Embedded Artists AB
+13
MAINTAINERS
··· 1965 1965 F: drivers/media/i2c/as3645a.c 1966 1966 F: include/media/i2c/as3645a.h 1967 1967 1968 + ASAHI KASEI AK8974 DRIVER 1969 + M: Linus Walleij <linus.walleij@linaro.org> 1970 + L: linux-iio@vger.kernel.org 1971 + W: http://www.akm.com/ 1972 + S: Supported 1973 + F: drivers/iio/magnetometer/ak8974.c 1974 + 1968 1975 ASC7621 HARDWARE MONITOR DRIVER 1969 1976 M: George Joseph <george.joseph@fairview5.com> 1970 1977 L: linux-hwmon@vger.kernel.org ··· 7503 7496 L: linux-iio@vger.kernel.org 7504 7497 S: Maintained 7505 7498 F: drivers/iio/potentiometer/mcp4531.c 7499 + 7500 + MEASUREMENT COMPUTING CIO-DAC IIO DRIVER 7501 + M: William Breathitt Gray <vilhelm.gray@gmail.com> 7502 + L: linux-iio@vger.kernel.org 7503 + S: Maintained 7504 + F: drivers/iio/dac/cio-dac.c 7506 7505 7507 7506 MEDIA DRIVERS FOR RENESAS - FCP 7508 7507 M: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
+21
drivers/iio/accel/Kconfig
··· 50 50 tristate 51 51 select REGMAP_SPI 52 52 53 + config DMARD06 54 + tristate "Domintech DMARD06 Digital Accelerometer Driver" 55 + depends on OF || COMPILE_TEST 56 + depends on I2C 57 + help 58 + Say yes here to build support for the Domintech low-g tri-axial 59 + digital accelerometers: DMARD05, DMARD06, DMARD07. 60 + 61 + To compile this driver as a module, choose M here: the 62 + module will be called dmard06. 63 + 64 + config DMARD09 65 + tristate "Domintech DMARD09 3-axis Accelerometer Driver" 66 + depends on I2C 67 + help 68 + Say yes here to get support for the Domintech DMARD09 3-axis 69 + accelerometer. 70 + 71 + Choosing M will build the driver as a module. If so, the module 72 + will be called dmard09. 73 + 53 74 config HID_SENSOR_ACCEL_3D 54 75 depends on HID_SENSOR_HUB 55 76 select IIO_BUFFER
+2
drivers/iio/accel/Makefile
··· 8 8 obj-$(CONFIG_BMC150_ACCEL) += bmc150-accel-core.o 9 9 obj-$(CONFIG_BMC150_ACCEL_I2C) += bmc150-accel-i2c.o 10 10 obj-$(CONFIG_BMC150_ACCEL_SPI) += bmc150-accel-spi.o 11 + obj-$(CONFIG_DMARD06) += dmard06.o 12 + obj-$(CONFIG_DMARD09) += dmard09.o 11 13 obj-$(CONFIG_HID_SENSOR_ACCEL_3D) += hid-sensor-accel-3d.o 12 14 obj-$(CONFIG_KXCJK1013) += kxcjk-1013.o 13 15 obj-$(CONFIG_KXSD9) += kxsd9.o
+5 -4
drivers/iio/accel/bma180.c
··· 469 469 470 470 switch (mask) { 471 471 case IIO_CHAN_INFO_RAW: 472 + ret = iio_device_claim_direct_mode(indio_dev); 473 + if (ret) 474 + return ret; 475 + 472 476 mutex_lock(&data->mutex); 473 - if (iio_buffer_enabled(indio_dev)) { 474 - mutex_unlock(&data->mutex); 475 - return -EBUSY; 476 - } 477 477 ret = bma180_get_data_reg(data, chan->scan_index); 478 478 mutex_unlock(&data->mutex); 479 + iio_device_release_direct_mode(indio_dev); 479 480 if (ret < 0) 480 481 return ret; 481 482 *val = sign_extend32(ret >> chan->scan_type.shift,
+241
drivers/iio/accel/dmard06.c
··· 1 + /* 2 + * IIO driver for Domintech DMARD06 accelerometer 3 + * 4 + * Copyright (C) 2016 Aleksei Mamlin <mamlinav@gmail.com> 5 + * 6 + * This program is free software; you can redistribute it and/or modify it 7 + * under the terms and conditions of the GNU General Public License, 8 + * version 2, as published by the Free Software Foundation. 9 + */ 10 + 11 + #include <linux/module.h> 12 + #include <linux/i2c.h> 13 + #include <linux/iio/iio.h> 14 + 15 + #define DMARD06_DRV_NAME "dmard06" 16 + 17 + /* Device data registers */ 18 + #define DMARD06_CHIP_ID_REG 0x0f 19 + #define DMARD06_TOUT_REG 0x40 20 + #define DMARD06_XOUT_REG 0x41 21 + #define DMARD06_YOUT_REG 0x42 22 + #define DMARD06_ZOUT_REG 0x43 23 + #define DMARD06_CTRL1_REG 0x44 24 + 25 + /* Device ID value */ 26 + #define DMARD05_CHIP_ID 0x05 27 + #define DMARD06_CHIP_ID 0x06 28 + #define DMARD07_CHIP_ID 0x07 29 + 30 + /* Device values */ 31 + #define DMARD05_AXIS_SCALE_VAL 15625 32 + #define DMARD06_AXIS_SCALE_VAL 31250 33 + #define DMARD06_TEMP_CENTER_VAL 25 34 + #define DMARD06_SIGN_BIT 7 35 + 36 + /* Device power modes */ 37 + #define DMARD06_MODE_NORMAL 0x27 38 + #define DMARD06_MODE_POWERDOWN 0x00 39 + 40 + /* Device channels */ 41 + #define DMARD06_ACCEL_CHANNEL(_axis, _reg) { \ 42 + .type = IIO_ACCEL, \ 43 + .address = _reg, \ 44 + .channel2 = IIO_MOD_##_axis, \ 45 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 46 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ 47 + .modified = 1, \ 48 + } 49 + 50 + #define DMARD06_TEMP_CHANNEL(_reg) { \ 51 + .type = IIO_TEMP, \ 52 + .address = _reg, \ 53 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 54 + BIT(IIO_CHAN_INFO_OFFSET), \ 55 + } 56 + 57 + struct dmard06_data { 58 + struct i2c_client *client; 59 + u8 chip_id; 60 + }; 61 + 62 + static const struct iio_chan_spec dmard06_channels[] = { 63 + DMARD06_ACCEL_CHANNEL(X, DMARD06_XOUT_REG), 64 + DMARD06_ACCEL_CHANNEL(Y, DMARD06_YOUT_REG), 65 + DMARD06_ACCEL_CHANNEL(Z, DMARD06_ZOUT_REG), 66 + DMARD06_TEMP_CHANNEL(DMARD06_TOUT_REG), 67 + }; 68 + 69 + static int dmard06_read_raw(struct iio_dev *indio_dev, 70 + struct iio_chan_spec const *chan, 71 + int *val, int *val2, long mask) 72 + { 73 + struct dmard06_data *dmard06 = iio_priv(indio_dev); 74 + int ret; 75 + 76 + switch (mask) { 77 + case IIO_CHAN_INFO_RAW: 78 + ret = i2c_smbus_read_byte_data(dmard06->client, 79 + chan->address); 80 + if (ret < 0) { 81 + dev_err(&dmard06->client->dev, 82 + "Error reading data: %d\n", ret); 83 + return ret; 84 + } 85 + 86 + *val = sign_extend32(ret, DMARD06_SIGN_BIT); 87 + 88 + if (dmard06->chip_id == DMARD06_CHIP_ID) 89 + *val = *val >> 1; 90 + 91 + switch (chan->type) { 92 + case IIO_ACCEL: 93 + return IIO_VAL_INT; 94 + case IIO_TEMP: 95 + if (dmard06->chip_id != DMARD06_CHIP_ID) 96 + *val = *val / 2; 97 + return IIO_VAL_INT; 98 + default: 99 + return -EINVAL; 100 + } 101 + case IIO_CHAN_INFO_OFFSET: 102 + switch (chan->type) { 103 + case IIO_TEMP: 104 + *val = DMARD06_TEMP_CENTER_VAL; 105 + return IIO_VAL_INT; 106 + default: 107 + return -EINVAL; 108 + } 109 + case IIO_CHAN_INFO_SCALE: 110 + switch (chan->type) { 111 + case IIO_ACCEL: 112 + *val = 0; 113 + if (dmard06->chip_id == DMARD06_CHIP_ID) 114 + *val2 = DMARD06_AXIS_SCALE_VAL; 115 + else 116 + *val2 = DMARD05_AXIS_SCALE_VAL; 117 + return IIO_VAL_INT_PLUS_MICRO; 118 + default: 119 + return -EINVAL; 120 + } 121 + default: 122 + return -EINVAL; 123 + } 124 + } 125 + 126 + static const struct iio_info dmard06_info = { 127 + .driver_module = THIS_MODULE, 128 + .read_raw = dmard06_read_raw, 129 + }; 130 + 131 + static int dmard06_probe(struct i2c_client *client, 132 + const struct i2c_device_id *id) 133 + { 134 + int ret; 135 + struct iio_dev *indio_dev; 136 + struct dmard06_data *dmard06; 137 + 138 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { 139 + dev_err(&client->dev, "I2C check functionality failed\n"); 140 + return -ENXIO; 141 + } 142 + 143 + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*dmard06)); 144 + if (!indio_dev) { 145 + dev_err(&client->dev, "Failed to allocate iio device\n"); 146 + return -ENOMEM; 147 + } 148 + 149 + dmard06 = iio_priv(indio_dev); 150 + dmard06->client = client; 151 + 152 + ret = i2c_smbus_read_byte_data(dmard06->client, DMARD06_CHIP_ID_REG); 153 + if (ret < 0) { 154 + dev_err(&client->dev, "Error reading chip id: %d\n", ret); 155 + return ret; 156 + } 157 + 158 + if (ret != DMARD05_CHIP_ID && ret != DMARD06_CHIP_ID && 159 + ret != DMARD07_CHIP_ID) { 160 + dev_err(&client->dev, "Invalid chip id: %02d\n", ret); 161 + return -ENODEV; 162 + } 163 + 164 + dmard06->chip_id = ret; 165 + 166 + i2c_set_clientdata(client, indio_dev); 167 + indio_dev->dev.parent = &client->dev; 168 + indio_dev->name = DMARD06_DRV_NAME; 169 + indio_dev->modes = INDIO_DIRECT_MODE; 170 + indio_dev->channels = dmard06_channels; 171 + indio_dev->num_channels = ARRAY_SIZE(dmard06_channels); 172 + indio_dev->info = &dmard06_info; 173 + 174 + return devm_iio_device_register(&client->dev, indio_dev); 175 + } 176 + 177 + #ifdef CONFIG_PM_SLEEP 178 + static int dmard06_suspend(struct device *dev) 179 + { 180 + struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); 181 + struct dmard06_data *dmard06 = iio_priv(indio_dev); 182 + int ret; 183 + 184 + ret = i2c_smbus_write_byte_data(dmard06->client, DMARD06_CTRL1_REG, 185 + DMARD06_MODE_POWERDOWN); 186 + if (ret < 0) 187 + return ret; 188 + 189 + return 0; 190 + } 191 + 192 + static int dmard06_resume(struct device *dev) 193 + { 194 + struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); 195 + struct dmard06_data *dmard06 = iio_priv(indio_dev); 196 + int ret; 197 + 198 + ret = i2c_smbus_write_byte_data(dmard06->client, DMARD06_CTRL1_REG, 199 + DMARD06_MODE_NORMAL); 200 + if (ret < 0) 201 + return ret; 202 + 203 + return 0; 204 + } 205 + 206 + static SIMPLE_DEV_PM_OPS(dmard06_pm_ops, dmard06_suspend, dmard06_resume); 207 + #define DMARD06_PM_OPS (&dmard06_pm_ops) 208 + #else 209 + #define DMARD06_PM_OPS NULL 210 + #endif 211 + 212 + static const struct i2c_device_id dmard06_id[] = { 213 + { "dmard05", 0 }, 214 + { "dmard06", 0 }, 215 + { "dmard07", 0 }, 216 + { } 217 + }; 218 + MODULE_DEVICE_TABLE(i2c, dmard06_id); 219 + 220 + static const struct of_device_id dmard06_of_match[] = { 221 + { .compatible = "domintech,dmard05" }, 222 + { .compatible = "domintech,dmard06" }, 223 + { .compatible = "domintech,dmard07" }, 224 + { } 225 + }; 226 + MODULE_DEVICE_TABLE(of, dmard06_of_match); 227 + 228 + static struct i2c_driver dmard06_driver = { 229 + .probe = dmard06_probe, 230 + .id_table = dmard06_id, 231 + .driver = { 232 + .name = DMARD06_DRV_NAME, 233 + .of_match_table = of_match_ptr(dmard06_of_match), 234 + .pm = DMARD06_PM_OPS, 235 + }, 236 + }; 237 + module_i2c_driver(dmard06_driver); 238 + 239 + MODULE_AUTHOR("Aleksei Mamlin <mamlinav@gmail.com>"); 240 + MODULE_DESCRIPTION("Domintech DMARD06 accelerometer driver"); 241 + MODULE_LICENSE("GPL v2");
+157
drivers/iio/accel/dmard09.c
··· 1 + /* 2 + * IIO driver for the 3-axis accelerometer Domintech DMARD09. 3 + * 4 + * Copyright (c) 2016, Jelle van der Waa <jelle@vdwaa.nl> 5 + * 6 + * This program is free software; you can redistribute it and/or modify it 7 + * under the terms and conditions of the GNU General Public License, 8 + * version 2, as published by the Free Software Foundation. 9 + * 10 + * This program is distributed in the hope it will be useful, but WITHOUT 11 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 + * more details. 14 + */ 15 + 16 + #include <asm/unaligned.h> 17 + #include <linux/module.h> 18 + #include <linux/i2c.h> 19 + #include <linux/iio/iio.h> 20 + 21 + #define DMARD09_DRV_NAME "dmard09" 22 + 23 + #define DMARD09_REG_CHIPID 0x18 24 + #define DMARD09_REG_STAT 0x0A 25 + #define DMARD09_REG_X 0x0C 26 + #define DMARD09_REG_Y 0x0E 27 + #define DMARD09_REG_Z 0x10 28 + #define DMARD09_CHIPID 0x95 29 + 30 + #define DMARD09_BUF_LEN 8 31 + #define DMARD09_AXIS_X 0 32 + #define DMARD09_AXIS_Y 1 33 + #define DMARD09_AXIS_Z 2 34 + #define DMARD09_AXIS_X_OFFSET ((DMARD09_AXIS_X + 1) * 2) 35 + #define DMARD09_AXIS_Y_OFFSET ((DMARD09_AXIS_Y + 1 )* 2) 36 + #define DMARD09_AXIS_Z_OFFSET ((DMARD09_AXIS_Z + 1) * 2) 37 + 38 + struct dmard09_data { 39 + struct i2c_client *client; 40 + }; 41 + 42 + #define DMARD09_CHANNEL(_axis, offset) { \ 43 + .type = IIO_ACCEL, \ 44 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 45 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ 46 + .modified = 1, \ 47 + .address = offset, \ 48 + .channel2 = IIO_MOD_##_axis, \ 49 + } 50 + 51 + static const struct iio_chan_spec dmard09_channels[] = { 52 + DMARD09_CHANNEL(X, DMARD09_AXIS_X_OFFSET), 53 + DMARD09_CHANNEL(Y, DMARD09_AXIS_Y_OFFSET), 54 + DMARD09_CHANNEL(Z, DMARD09_AXIS_Z_OFFSET), 55 + }; 56 + 57 + static int dmard09_read_raw(struct iio_dev *indio_dev, 58 + struct iio_chan_spec const *chan, 59 + int *val, int *val2, long mask) 60 + { 61 + struct dmard09_data *data = iio_priv(indio_dev); 62 + u8 buf[DMARD09_BUF_LEN]; 63 + int ret; 64 + s16 accel; 65 + 66 + switch (mask) { 67 + case IIO_CHAN_INFO_RAW: 68 + /* 69 + * Read from the DMAR09_REG_STAT register, since the chip 70 + * caches reads from the individual X, Y, Z registers. 71 + */ 72 + ret = i2c_smbus_read_i2c_block_data(data->client, 73 + DMARD09_REG_STAT, 74 + DMARD09_BUF_LEN, buf); 75 + if (ret < 0) { 76 + dev_err(&data->client->dev, "Error reading reg %d\n", 77 + DMARD09_REG_STAT); 78 + return ret; 79 + } 80 + 81 + accel = get_unaligned_le16(&buf[chan->address]); 82 + 83 + /* Remove lower 3 bits and sign extend */ 84 + accel <<= 4; 85 + accel >>= 7; 86 + 87 + *val = accel; 88 + 89 + return IIO_VAL_INT; 90 + default: 91 + return -EINVAL; 92 + } 93 + } 94 + 95 + static const struct iio_info dmard09_info = { 96 + .driver_module = THIS_MODULE, 97 + .read_raw = dmard09_read_raw, 98 + }; 99 + 100 + static int dmard09_probe(struct i2c_client *client, 101 + const struct i2c_device_id *id) 102 + { 103 + int ret; 104 + struct iio_dev *indio_dev; 105 + struct dmard09_data *data; 106 + 107 + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 108 + if (!indio_dev) { 109 + dev_err(&client->dev, "iio allocation failed\n"); 110 + return -ENOMEM; 111 + } 112 + 113 + data = iio_priv(indio_dev); 114 + data->client = client; 115 + 116 + ret = i2c_smbus_read_byte_data(data->client, DMARD09_REG_CHIPID); 117 + if (ret < 0) { 118 + dev_err(&client->dev, "Error reading chip id %d\n", ret); 119 + return ret; 120 + } 121 + 122 + if (ret != DMARD09_CHIPID) { 123 + dev_err(&client->dev, "Invalid chip id %d\n", ret); 124 + return -ENODEV; 125 + } 126 + 127 + i2c_set_clientdata(client, indio_dev); 128 + indio_dev->dev.parent = &client->dev; 129 + indio_dev->name = DMARD09_DRV_NAME; 130 + indio_dev->modes = INDIO_DIRECT_MODE; 131 + indio_dev->channels = dmard09_channels; 132 + indio_dev->num_channels = ARRAY_SIZE(dmard09_channels); 133 + indio_dev->info = &dmard09_info; 134 + 135 + return devm_iio_device_register(&client->dev, indio_dev); 136 + } 137 + 138 + static const struct i2c_device_id dmard09_id[] = { 139 + { "dmard09", 0}, 140 + { }, 141 + }; 142 + 143 + MODULE_DEVICE_TABLE(i2c, dmard09_id); 144 + 145 + static struct i2c_driver dmard09_driver = { 146 + .driver = { 147 + .name = DMARD09_DRV_NAME 148 + }, 149 + .probe = dmard09_probe, 150 + .id_table = dmard09_id, 151 + }; 152 + 153 + module_i2c_driver(dmard09_driver); 154 + 155 + MODULE_AUTHOR("Jelle van der Waa <jelle@vdwaa.nl>"); 156 + MODULE_DESCRIPTION("DMARD09 3-axis accelerometer driver"); 157 + MODULE_LICENSE("GPL");
+1
drivers/iio/accel/kxcjk-1013.c
··· 1392 1392 {"KXCJ1013", KXCJK1013}, 1393 1393 {"KXCJ1008", KXCJ91008}, 1394 1394 {"KXCJ9000", KXCJ91008}, 1395 + {"KIOX000A", KXCJ91008}, 1395 1396 {"KXTJ1009", KXTJ21009}, 1396 1397 {"SMO8500", KXCJ91008}, 1397 1398 { },
+25
drivers/iio/adc/Kconfig
··· 317 317 This driver can also be built as a module. If so, the module will be 318 318 called mcp3422. 319 319 320 + config MEDIATEK_MT6577_AUXADC 321 + tristate "MediaTek AUXADC driver" 322 + depends on ARCH_MEDIATEK || COMPILE_TEST 323 + depends on HAS_IOMEM 324 + help 325 + Say yes here to enable support for MediaTek mt65xx AUXADC. 326 + 327 + The driver supports immediate mode operation to read from one of sixteen 328 + channels (external or internal). 329 + 330 + This driver can also be built as a module. If so, the module will be 331 + called mt6577_auxadc. 332 + 320 333 config MEN_Z188_ADC 321 334 tristate "MEN 16z188 ADC IP Core support" 322 335 depends on MCB ··· 438 425 439 426 This driver can also be built as a module. If so, the module will be 440 427 called ti-adc128s052. 428 + 429 + config TI_ADC161S626 430 + tristate "Texas Instruments ADC161S626 1-channel differential ADC" 431 + depends on SPI 432 + select IIO_BUFFER 433 + select IIO_TRIGGERED_BUFFER 434 + help 435 + If you say yes here you get support for Texas Instruments ADC141S626, 436 + and ADC161S626 chips. 437 + 438 + This driver can also be built as a module. If so, the module will be 439 + called ti-adc161s626. 441 440 442 441 config TI_ADS1015 443 442 tristate "Texas Instruments ADS1015 ADC"
+2
drivers/iio/adc/Makefile
··· 31 31 obj-$(CONFIG_MAX1363) += max1363.o 32 32 obj-$(CONFIG_MCP320X) += mcp320x.o 33 33 obj-$(CONFIG_MCP3422) += mcp3422.o 34 + obj-$(CONFIG_MEDIATEK_MT6577_AUXADC) += mt6577_auxadc.o 34 35 obj-$(CONFIG_MEN_Z188_ADC) += men_z188_adc.o 35 36 obj-$(CONFIG_MXS_LRADC) += mxs-lradc.o 36 37 obj-$(CONFIG_NAU7802) += nau7802.o ··· 42 41 obj-$(CONFIG_TI_ADC081C) += ti-adc081c.o 43 42 obj-$(CONFIG_TI_ADC0832) += ti-adc0832.o 44 43 obj-$(CONFIG_TI_ADC128S052) += ti-adc128s052.o 44 + obj-$(CONFIG_TI_ADC161S626) += ti-adc161s626.o 45 45 obj-$(CONFIG_TI_ADS1015) += ti-ads1015.o 46 46 obj-$(CONFIG_TI_ADS8688) += ti-ads8688.o 47 47 obj-$(CONFIG_TI_AM335X_ADC) += ti_am335x_adc.o
+10 -10
drivers/iio/adc/ad7298.c
··· 239 239 240 240 switch (m) { 241 241 case IIO_CHAN_INFO_RAW: 242 - mutex_lock(&indio_dev->mlock); 243 - if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) { 244 - ret = -EBUSY; 245 - } else { 246 - if (chan->address == AD7298_CH_TEMP) 247 - ret = ad7298_scan_temp(st, val); 248 - else 249 - ret = ad7298_scan_direct(st, chan->address); 250 - } 251 - mutex_unlock(&indio_dev->mlock); 242 + ret = iio_device_claim_direct_mode(indio_dev); 243 + if (ret) 244 + return ret; 245 + 246 + if (chan->address == AD7298_CH_TEMP) 247 + ret = ad7298_scan_temp(st, val); 248 + else 249 + ret = ad7298_scan_direct(st, chan->address); 250 + 251 + iio_device_release_direct_mode(indio_dev); 252 252 253 253 if (ret < 0) 254 254 return ret;
+4 -6
drivers/iio/adc/ad7793.c
··· 519 519 int ret, i; 520 520 unsigned int tmp; 521 521 522 - mutex_lock(&indio_dev->mlock); 523 - if (iio_buffer_enabled(indio_dev)) { 524 - mutex_unlock(&indio_dev->mlock); 525 - return -EBUSY; 526 - } 522 + ret = iio_device_claim_direct_mode(indio_dev); 523 + if (ret) 524 + return ret; 527 525 528 526 switch (mask) { 529 527 case IIO_CHAN_INFO_SCALE: ··· 546 548 ret = -EINVAL; 547 549 } 548 550 549 - mutex_unlock(&indio_dev->mlock); 551 + iio_device_release_direct_mode(indio_dev); 550 552 return ret; 551 553 } 552 554
+291
drivers/iio/adc/mt6577_auxadc.c
··· 1 + /* 2 + * Copyright (c) 2016 MediaTek Inc. 3 + * Author: Zhiyong Tao <zhiyong.tao@mediatek.com> 4 + * 5 + * This program is free software; you can redistribute it and/or modify 6 + * it under the terms of the GNU General Public License version 2 as 7 + * published by the Free Software Foundation. 8 + * 9 + * This program is distributed in the hope that it will be useful, 10 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 + * GNU General Public License for more details. 13 + */ 14 + 15 + #include <linux/clk.h> 16 + #include <linux/delay.h> 17 + #include <linux/err.h> 18 + #include <linux/kernel.h> 19 + #include <linux/module.h> 20 + #include <linux/of.h> 21 + #include <linux/of_device.h> 22 + #include <linux/platform_device.h> 23 + #include <linux/iopoll.h> 24 + #include <linux/io.h> 25 + #include <linux/iio/iio.h> 26 + 27 + /* Register definitions */ 28 + #define MT6577_AUXADC_CON0 0x00 29 + #define MT6577_AUXADC_CON1 0x04 30 + #define MT6577_AUXADC_CON2 0x10 31 + #define MT6577_AUXADC_STA BIT(0) 32 + 33 + #define MT6577_AUXADC_DAT0 0x14 34 + #define MT6577_AUXADC_RDY0 BIT(12) 35 + 36 + #define MT6577_AUXADC_MISC 0x94 37 + #define MT6577_AUXADC_PDN_EN BIT(14) 38 + 39 + #define MT6577_AUXADC_DAT_MASK 0xfff 40 + #define MT6577_AUXADC_SLEEP_US 1000 41 + #define MT6577_AUXADC_TIMEOUT_US 10000 42 + #define MT6577_AUXADC_POWER_READY_MS 1 43 + #define MT6577_AUXADC_SAMPLE_READY_US 25 44 + 45 + struct mt6577_auxadc_device { 46 + void __iomem *reg_base; 47 + struct clk *adc_clk; 48 + struct mutex lock; 49 + }; 50 + 51 + #define MT6577_AUXADC_CHANNEL(idx) { \ 52 + .type = IIO_VOLTAGE, \ 53 + .indexed = 1, \ 54 + .channel = (idx), \ 55 + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), \ 56 + } 57 + 58 + static const struct iio_chan_spec mt6577_auxadc_iio_channels[] = { 59 + MT6577_AUXADC_CHANNEL(0), 60 + MT6577_AUXADC_CHANNEL(1), 61 + MT6577_AUXADC_CHANNEL(2), 62 + MT6577_AUXADC_CHANNEL(3), 63 + MT6577_AUXADC_CHANNEL(4), 64 + MT6577_AUXADC_CHANNEL(5), 65 + MT6577_AUXADC_CHANNEL(6), 66 + MT6577_AUXADC_CHANNEL(7), 67 + MT6577_AUXADC_CHANNEL(8), 68 + MT6577_AUXADC_CHANNEL(9), 69 + MT6577_AUXADC_CHANNEL(10), 70 + MT6577_AUXADC_CHANNEL(11), 71 + MT6577_AUXADC_CHANNEL(12), 72 + MT6577_AUXADC_CHANNEL(13), 73 + MT6577_AUXADC_CHANNEL(14), 74 + MT6577_AUXADC_CHANNEL(15), 75 + }; 76 + 77 + static inline void mt6577_auxadc_mod_reg(void __iomem *reg, 78 + u32 or_mask, u32 and_mask) 79 + { 80 + u32 val; 81 + 82 + val = readl(reg); 83 + val |= or_mask; 84 + val &= ~and_mask; 85 + writel(val, reg); 86 + } 87 + 88 + static int mt6577_auxadc_read(struct iio_dev *indio_dev, 89 + struct iio_chan_spec const *chan) 90 + { 91 + u32 val; 92 + void __iomem *reg_channel; 93 + int ret; 94 + struct mt6577_auxadc_device *adc_dev = iio_priv(indio_dev); 95 + 96 + reg_channel = adc_dev->reg_base + MT6577_AUXADC_DAT0 + 97 + chan->channel * 0x04; 98 + 99 + mutex_lock(&adc_dev->lock); 100 + 101 + mt6577_auxadc_mod_reg(adc_dev->reg_base + MT6577_AUXADC_CON1, 102 + 0, 1 << chan->channel); 103 + 104 + /* read channel and make sure old ready bit == 0 */ 105 + ret = readl_poll_timeout(reg_channel, val, 106 + ((val & MT6577_AUXADC_RDY0) == 0), 107 + MT6577_AUXADC_SLEEP_US, 108 + MT6577_AUXADC_TIMEOUT_US); 109 + if (ret < 0) { 110 + dev_err(indio_dev->dev.parent, 111 + "wait for channel[%d] ready bit clear time out\n", 112 + chan->channel); 113 + goto err_timeout; 114 + } 115 + 116 + /* set bit to trigger sample */ 117 + mt6577_auxadc_mod_reg(adc_dev->reg_base + MT6577_AUXADC_CON1, 118 + 1 << chan->channel, 0); 119 + 120 + /* we must delay here for hardware sample channel data */ 121 + udelay(MT6577_AUXADC_SAMPLE_READY_US); 122 + 123 + /* check MTK_AUXADC_CON2 if auxadc is idle */ 124 + ret = readl_poll_timeout(adc_dev->reg_base + MT6577_AUXADC_CON2, val, 125 + ((val & MT6577_AUXADC_STA) == 0), 126 + MT6577_AUXADC_SLEEP_US, 127 + MT6577_AUXADC_TIMEOUT_US); 128 + if (ret < 0) { 129 + dev_err(indio_dev->dev.parent, 130 + "wait for auxadc idle time out\n"); 131 + goto err_timeout; 132 + } 133 + 134 + /* read channel and make sure ready bit == 1 */ 135 + ret = readl_poll_timeout(reg_channel, val, 136 + ((val & MT6577_AUXADC_RDY0) != 0), 137 + MT6577_AUXADC_SLEEP_US, 138 + MT6577_AUXADC_TIMEOUT_US); 139 + if (ret < 0) { 140 + dev_err(indio_dev->dev.parent, 141 + "wait for channel[%d] data ready time out\n", 142 + chan->channel); 143 + goto err_timeout; 144 + } 145 + 146 + /* read data */ 147 + val = readl(reg_channel) & MT6577_AUXADC_DAT_MASK; 148 + 149 + mutex_unlock(&adc_dev->lock); 150 + 151 + return val; 152 + 153 + err_timeout: 154 + 155 + mutex_unlock(&adc_dev->lock); 156 + 157 + return -ETIMEDOUT; 158 + } 159 + 160 + static int mt6577_auxadc_read_raw(struct iio_dev *indio_dev, 161 + struct iio_chan_spec const *chan, 162 + int *val, 163 + int *val2, 164 + long info) 165 + { 166 + switch (info) { 167 + case IIO_CHAN_INFO_PROCESSED: 168 + *val = mt6577_auxadc_read(indio_dev, chan); 169 + if (*val < 0) { 170 + dev_err(indio_dev->dev.parent, 171 + "failed to sample data on channel[%d]\n", 172 + chan->channel); 173 + return *val; 174 + } 175 + return IIO_VAL_INT; 176 + 177 + default: 178 + return -EINVAL; 179 + } 180 + } 181 + 182 + static const struct iio_info mt6577_auxadc_info = { 183 + .driver_module = THIS_MODULE, 184 + .read_raw = &mt6577_auxadc_read_raw, 185 + }; 186 + 187 + static int mt6577_auxadc_probe(struct platform_device *pdev) 188 + { 189 + struct mt6577_auxadc_device *adc_dev; 190 + unsigned long adc_clk_rate; 191 + struct resource *res; 192 + struct iio_dev *indio_dev; 193 + int ret; 194 + 195 + indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*adc_dev)); 196 + if (!indio_dev) 197 + return -ENOMEM; 198 + 199 + adc_dev = iio_priv(indio_dev); 200 + indio_dev->dev.parent = &pdev->dev; 201 + indio_dev->name = dev_name(&pdev->dev); 202 + indio_dev->info = &mt6577_auxadc_info; 203 + indio_dev->modes = INDIO_DIRECT_MODE; 204 + indio_dev->channels = mt6577_auxadc_iio_channels; 205 + indio_dev->num_channels = ARRAY_SIZE(mt6577_auxadc_iio_channels); 206 + 207 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 208 + adc_dev->reg_base = devm_ioremap_resource(&pdev->dev, res); 209 + if (IS_ERR(adc_dev->reg_base)) { 210 + dev_err(&pdev->dev, "failed to get auxadc base address\n"); 211 + return PTR_ERR(adc_dev->reg_base); 212 + } 213 + 214 + adc_dev->adc_clk = devm_clk_get(&pdev->dev, "main"); 215 + if (IS_ERR(adc_dev->adc_clk)) { 216 + dev_err(&pdev->dev, "failed to get auxadc clock\n"); 217 + return PTR_ERR(adc_dev->adc_clk); 218 + } 219 + 220 + ret = clk_prepare_enable(adc_dev->adc_clk); 221 + if (ret) { 222 + dev_err(&pdev->dev, "failed to enable auxadc clock\n"); 223 + return ret; 224 + } 225 + 226 + adc_clk_rate = clk_get_rate(adc_dev->adc_clk); 227 + if (!adc_clk_rate) { 228 + ret = -EINVAL; 229 + dev_err(&pdev->dev, "null clock rate\n"); 230 + goto err_disable_clk; 231 + } 232 + 233 + mutex_init(&adc_dev->lock); 234 + 235 + mt6577_auxadc_mod_reg(adc_dev->reg_base + MT6577_AUXADC_MISC, 236 + MT6577_AUXADC_PDN_EN, 0); 237 + mdelay(MT6577_AUXADC_POWER_READY_MS); 238 + 239 + platform_set_drvdata(pdev, indio_dev); 240 + 241 + ret = iio_device_register(indio_dev); 242 + if (ret < 0) { 243 + dev_err(&pdev->dev, "failed to register iio device\n"); 244 + goto err_power_off; 245 + } 246 + 247 + return 0; 248 + 249 + err_power_off: 250 + mt6577_auxadc_mod_reg(adc_dev->reg_base + MT6577_AUXADC_MISC, 251 + 0, MT6577_AUXADC_PDN_EN); 252 + err_disable_clk: 253 + clk_disable_unprepare(adc_dev->adc_clk); 254 + return ret; 255 + } 256 + 257 + static int mt6577_auxadc_remove(struct platform_device *pdev) 258 + { 259 + struct iio_dev *indio_dev = platform_get_drvdata(pdev); 260 + struct mt6577_auxadc_device *adc_dev = iio_priv(indio_dev); 261 + 262 + iio_device_unregister(indio_dev); 263 + 264 + mt6577_auxadc_mod_reg(adc_dev->reg_base + MT6577_AUXADC_MISC, 265 + 0, MT6577_AUXADC_PDN_EN); 266 + 267 + clk_disable_unprepare(adc_dev->adc_clk); 268 + 269 + return 0; 270 + } 271 + 272 + static const struct of_device_id mt6577_auxadc_of_match[] = { 273 + { .compatible = "mediatek,mt2701-auxadc", }, 274 + { .compatible = "mediatek,mt8173-auxadc", }, 275 + { } 276 + }; 277 + MODULE_DEVICE_TABLE(of, mt6577_auxadc_of_match); 278 + 279 + static struct platform_driver mt6577_auxadc_driver = { 280 + .driver = { 281 + .name = "mt6577-auxadc", 282 + .of_match_table = mt6577_auxadc_of_match, 283 + }, 284 + .probe = mt6577_auxadc_probe, 285 + .remove = mt6577_auxadc_remove, 286 + }; 287 + module_platform_driver(mt6577_auxadc_driver); 288 + 289 + MODULE_AUTHOR("Zhiyong Tao <zhiyong.tao@mediatek.com>"); 290 + MODULE_DESCRIPTION("MTK AUXADC Device Driver"); 291 + MODULE_LICENSE("GPL v2");
+1 -1
drivers/iio/adc/nau7802.c
··· 197 197 if (st->conversion_count < NAU7802_MIN_CONVERSIONS) 198 198 st->conversion_count++; 199 199 if (st->conversion_count >= NAU7802_MIN_CONVERSIONS) 200 - complete_all(&st->value_ok); 200 + complete(&st->value_ok); 201 201 202 202 return IRQ_HANDLED; 203 203 }
+248
drivers/iio/adc/ti-adc161s626.c
··· 1 + /* 2 + * ti-adc161s626.c - Texas Instruments ADC161S626 1-channel differential ADC 3 + * 4 + * ADC Devices Supported: 5 + * adc141s626 - 14-bit ADC 6 + * adc161s626 - 16-bit ADC 7 + * 8 + * Copyright (C) 2016 Matt Ranostay <mranostay@gmail.com> 9 + * 10 + * This program is free software; you can redistribute it and/or modify 11 + * it under the terms of the GNU General Public License as published by 12 + * the Free Software Foundation; either version 2 of the License, or 13 + * (at your option) any later version. 14 + * 15 + * This program is distributed in the hope that it will be useful, 16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 + * GNU General Public License for more details. 19 + */ 20 + 21 + #include <linux/module.h> 22 + #include <linux/init.h> 23 + #include <linux/err.h> 24 + #include <linux/spi/spi.h> 25 + #include <linux/iio/iio.h> 26 + #include <linux/iio/trigger.h> 27 + #include <linux/iio/buffer.h> 28 + #include <linux/iio/trigger_consumer.h> 29 + #include <linux/iio/triggered_buffer.h> 30 + 31 + #define TI_ADC_DRV_NAME "ti-adc161s626" 32 + 33 + enum { 34 + TI_ADC141S626, 35 + TI_ADC161S626, 36 + }; 37 + 38 + static const struct iio_chan_spec ti_adc141s626_channels[] = { 39 + { 40 + .type = IIO_VOLTAGE, 41 + .channel = 0, 42 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 43 + .scan_index = 0, 44 + .scan_type = { 45 + .sign = 's', 46 + .realbits = 14, 47 + .storagebits = 16, 48 + }, 49 + }, 50 + IIO_CHAN_SOFT_TIMESTAMP(1), 51 + }; 52 + 53 + static const struct iio_chan_spec ti_adc161s626_channels[] = { 54 + { 55 + .type = IIO_VOLTAGE, 56 + .channel = 0, 57 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 58 + .scan_index = 0, 59 + .scan_type = { 60 + .sign = 's', 61 + .realbits = 16, 62 + .storagebits = 16, 63 + }, 64 + }, 65 + IIO_CHAN_SOFT_TIMESTAMP(1), 66 + }; 67 + 68 + struct ti_adc_data { 69 + struct iio_dev *indio_dev; 70 + struct spi_device *spi; 71 + u8 read_size; 72 + u8 shift; 73 + 74 + u8 buffer[16] ____cacheline_aligned; 75 + }; 76 + 77 + static int ti_adc_read_measurement(struct ti_adc_data *data, 78 + struct iio_chan_spec const *chan, int *val) 79 + { 80 + int ret; 81 + 82 + switch (data->read_size) { 83 + case 2: { 84 + __be16 buf; 85 + 86 + ret = spi_read(data->spi, (void *) &buf, 2); 87 + if (ret) 88 + return ret; 89 + 90 + *val = be16_to_cpu(buf); 91 + break; 92 + } 93 + case 3: { 94 + __be32 buf; 95 + 96 + ret = spi_read(data->spi, (void *) &buf, 3); 97 + if (ret) 98 + return ret; 99 + 100 + *val = be32_to_cpu(buf) >> 8; 101 + break; 102 + } 103 + default: 104 + return -EINVAL; 105 + } 106 + 107 + *val = sign_extend32(*val >> data->shift, chan->scan_type.realbits - 1); 108 + 109 + return 0; 110 + } 111 + 112 + static irqreturn_t ti_adc_trigger_handler(int irq, void *private) 113 + { 114 + struct iio_poll_func *pf = private; 115 + struct iio_dev *indio_dev = pf->indio_dev; 116 + struct ti_adc_data *data = iio_priv(indio_dev); 117 + int ret; 118 + 119 + ret = ti_adc_read_measurement(data, &indio_dev->channels[0], 120 + (int *) &data->buffer); 121 + if (!ret) 122 + iio_push_to_buffers_with_timestamp(indio_dev, 123 + data->buffer, 124 + iio_get_time_ns(indio_dev)); 125 + 126 + iio_trigger_notify_done(indio_dev->trig); 127 + 128 + return IRQ_HANDLED; 129 + } 130 + 131 + static int ti_adc_read_raw(struct iio_dev *indio_dev, 132 + struct iio_chan_spec const *chan, 133 + int *val, int *val2, long mask) 134 + { 135 + struct ti_adc_data *data = iio_priv(indio_dev); 136 + int ret; 137 + 138 + if (mask != IIO_CHAN_INFO_RAW) 139 + return -EINVAL; 140 + 141 + ret = iio_device_claim_direct_mode(indio_dev); 142 + if (ret) 143 + return ret; 144 + 145 + ret = ti_adc_read_measurement(data, chan, val); 146 + iio_device_release_direct_mode(indio_dev); 147 + 148 + if (!ret) 149 + return IIO_VAL_INT; 150 + 151 + return 0; 152 + } 153 + 154 + static const struct iio_info ti_adc_info = { 155 + .driver_module = THIS_MODULE, 156 + .read_raw = ti_adc_read_raw, 157 + }; 158 + 159 + static int ti_adc_probe(struct spi_device *spi) 160 + { 161 + struct iio_dev *indio_dev; 162 + struct ti_adc_data *data; 163 + int ret; 164 + 165 + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*data)); 166 + if (!indio_dev) 167 + return -ENOMEM; 168 + 169 + indio_dev->info = &ti_adc_info; 170 + indio_dev->dev.parent = &spi->dev; 171 + indio_dev->dev.of_node = spi->dev.of_node; 172 + indio_dev->name = TI_ADC_DRV_NAME; 173 + indio_dev->modes = INDIO_DIRECT_MODE; 174 + spi_set_drvdata(spi, indio_dev); 175 + 176 + data = iio_priv(indio_dev); 177 + data->spi = spi; 178 + 179 + switch (spi_get_device_id(spi)->driver_data) { 180 + case TI_ADC141S626: 181 + indio_dev->channels = ti_adc141s626_channels; 182 + indio_dev->num_channels = ARRAY_SIZE(ti_adc141s626_channels); 183 + data->shift = 0; 184 + data->read_size = 2; 185 + break; 186 + case TI_ADC161S626: 187 + indio_dev->channels = ti_adc161s626_channels; 188 + indio_dev->num_channels = ARRAY_SIZE(ti_adc161s626_channels); 189 + data->shift = 6; 190 + data->read_size = 3; 191 + break; 192 + } 193 + 194 + ret = iio_triggered_buffer_setup(indio_dev, NULL, 195 + ti_adc_trigger_handler, NULL); 196 + if (ret) 197 + return ret; 198 + 199 + ret = iio_device_register(indio_dev); 200 + if (ret) 201 + goto error_unreg_buffer; 202 + 203 + return 0; 204 + 205 + error_unreg_buffer: 206 + iio_triggered_buffer_cleanup(indio_dev); 207 + 208 + return ret; 209 + } 210 + 211 + static int ti_adc_remove(struct spi_device *spi) 212 + { 213 + struct iio_dev *indio_dev = spi_get_drvdata(spi); 214 + 215 + iio_device_unregister(indio_dev); 216 + iio_triggered_buffer_cleanup(indio_dev); 217 + 218 + return 0; 219 + } 220 + 221 + static const struct of_device_id ti_adc_dt_ids[] = { 222 + { .compatible = "ti,adc141s626", }, 223 + { .compatible = "ti,adc161s626", }, 224 + {} 225 + }; 226 + MODULE_DEVICE_TABLE(of, ti_adc_dt_ids); 227 + 228 + static const struct spi_device_id ti_adc_id[] = { 229 + {"adc141s626", TI_ADC141S626}, 230 + {"adc161s626", TI_ADC161S626}, 231 + {}, 232 + }; 233 + MODULE_DEVICE_TABLE(spi, ti_adc_id); 234 + 235 + static struct spi_driver ti_adc_driver = { 236 + .driver = { 237 + .name = TI_ADC_DRV_NAME, 238 + .of_match_table = of_match_ptr(ti_adc_dt_ids), 239 + }, 240 + .probe = ti_adc_probe, 241 + .remove = ti_adc_remove, 242 + .id_table = ti_adc_id, 243 + }; 244 + module_spi_driver(ti_adc_driver); 245 + 246 + MODULE_AUTHOR("Matt Ranostay <mranostay@gmail.com>"); 247 + MODULE_DESCRIPTION("Texas Instruments ADC1x1S 1-channel differential ADC"); 248 + MODULE_LICENSE("GPL");
+14 -10
drivers/iio/buffer/industrialio-buffer-cb.c
··· 18 18 int (*cb)(const void *data, void *private); 19 19 void *private; 20 20 struct iio_channel *channels; 21 + struct iio_dev *indio_dev; 21 22 }; 22 23 23 24 static struct iio_cb_buffer *buffer_to_cb_buffer(struct iio_buffer *buffer) ··· 53 52 { 54 53 int ret; 55 54 struct iio_cb_buffer *cb_buff; 56 - struct iio_dev *indio_dev; 57 55 struct iio_channel *chan; 58 56 59 57 cb_buff = kzalloc(sizeof(*cb_buff), GFP_KERNEL); ··· 72 72 goto error_free_cb_buff; 73 73 } 74 74 75 - indio_dev = cb_buff->channels[0].indio_dev; 75 + cb_buff->indio_dev = cb_buff->channels[0].indio_dev; 76 76 cb_buff->buffer.scan_mask 77 - = kcalloc(BITS_TO_LONGS(indio_dev->masklength), sizeof(long), 78 - GFP_KERNEL); 77 + = kcalloc(BITS_TO_LONGS(cb_buff->indio_dev->masklength), 78 + sizeof(long), GFP_KERNEL); 79 79 if (cb_buff->buffer.scan_mask == NULL) { 80 80 ret = -ENOMEM; 81 81 goto error_release_channels; 82 82 } 83 83 chan = &cb_buff->channels[0]; 84 84 while (chan->indio_dev) { 85 - if (chan->indio_dev != indio_dev) { 85 + if (chan->indio_dev != cb_buff->indio_dev) { 86 86 ret = -EINVAL; 87 87 goto error_free_scan_mask; 88 88 } ··· 105 105 106 106 int iio_channel_start_all_cb(struct iio_cb_buffer *cb_buff) 107 107 { 108 - return iio_update_buffers(cb_buff->channels[0].indio_dev, 109 - &cb_buff->buffer, 108 + return iio_update_buffers(cb_buff->indio_dev, &cb_buff->buffer, 110 109 NULL); 111 110 } 112 111 EXPORT_SYMBOL_GPL(iio_channel_start_all_cb); 113 112 114 113 void iio_channel_stop_all_cb(struct iio_cb_buffer *cb_buff) 115 114 { 116 - iio_update_buffers(cb_buff->channels[0].indio_dev, 117 - NULL, 118 - &cb_buff->buffer); 115 + iio_update_buffers(cb_buff->indio_dev, NULL, &cb_buff->buffer); 119 116 } 120 117 EXPORT_SYMBOL_GPL(iio_channel_stop_all_cb); 121 118 ··· 129 132 return cb_buffer->channels; 130 133 } 131 134 EXPORT_SYMBOL_GPL(iio_channel_cb_get_channels); 135 + 136 + struct iio_dev 137 + *iio_channel_cb_get_iio_dev(const struct iio_cb_buffer *cb_buffer) 138 + { 139 + return cb_buffer->indio_dev; 140 + } 141 + EXPORT_SYMBOL_GPL(iio_channel_cb_get_iio_dev); 132 142 133 143 MODULE_AUTHOR("Jonathan Cameron <jic23@kernel.org>"); 134 144 MODULE_DESCRIPTION("Industrial I/O callback buffer");
+1
drivers/iio/chemical/Kconfig
··· 16 16 Atlas Scientific OEM SM sensors: 17 17 * pH SM sensor 18 18 * EC SM sensor 19 + * ORP SM sensor 19 20 20 21 To compile this driver as module, choose M here: the 21 22 module will be called atlas-ph-sensor.
+57 -24
drivers/iio/chemical/atlas-ph-sensor.c
··· 66 66 #define ATLAS_REG_TDS_DATA 0x1c 67 67 #define ATLAS_REG_PSS_DATA 0x20 68 68 69 + #define ATLAS_REG_ORP_CALIB_STATUS 0x0d 70 + #define ATLAS_REG_ORP_DATA 0x0e 71 + 69 72 #define ATLAS_PH_INT_TIME_IN_US 450000 70 73 #define ATLAS_EC_INT_TIME_IN_US 650000 74 + #define ATLAS_ORP_INT_TIME_IN_US 450000 71 75 72 76 enum { 73 77 ATLAS_PH_SM, 74 78 ATLAS_EC_SM, 79 + ATLAS_ORP_SM, 75 80 }; 76 81 77 82 struct atlas_data { ··· 89 84 __be32 buffer[6]; /* 96-bit data + 32-bit pad + 64-bit timestamp */ 90 85 }; 91 86 92 - static const struct regmap_range atlas_volatile_ranges[] = { 93 - regmap_reg_range(ATLAS_REG_INT_CONTROL, ATLAS_REG_INT_CONTROL), 94 - regmap_reg_range(ATLAS_REG_PH_DATA, ATLAS_REG_PH_DATA + 4), 95 - regmap_reg_range(ATLAS_REG_EC_DATA, ATLAS_REG_PSS_DATA + 4), 96 - }; 97 - 98 - static const struct regmap_access_table atlas_volatile_table = { 99 - .yes_ranges = atlas_volatile_ranges, 100 - .n_yes_ranges = ARRAY_SIZE(atlas_volatile_ranges), 101 - }; 102 - 103 87 static const struct regmap_config atlas_regmap_config = { 104 88 .name = ATLAS_REGMAP_NAME, 105 - 106 89 .reg_bits = 8, 107 90 .val_bits = 8, 108 - 109 - .volatile_table = &atlas_volatile_table, 110 - .max_register = ATLAS_REG_PSS_DATA + 4, 111 - .cache_type = REGCACHE_RBTREE, 112 91 }; 113 92 114 93 static const struct iio_chan_spec atlas_ph_channels[] = { ··· 164 175 }, 165 176 }; 166 177 178 + static const struct iio_chan_spec atlas_orp_channels[] = { 179 + { 180 + .type = IIO_VOLTAGE, 181 + .address = ATLAS_REG_ORP_DATA, 182 + .info_mask_separate = 183 + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), 184 + .scan_index = 0, 185 + .scan_type = { 186 + .sign = 's', 187 + .realbits = 32, 188 + .storagebits = 32, 189 + .endianness = IIO_BE, 190 + }, 191 + }, 192 + IIO_CHAN_SOFT_TIMESTAMP(1), 193 + }; 194 + 167 195 static int atlas_check_ph_calibration(struct atlas_data *data) 168 196 { 169 197 struct device *dev = &data->client->dev; ··· 246 240 return 0; 247 241 } 248 242 243 + static int atlas_check_orp_calibration(struct atlas_data *data) 244 + { 245 + struct device *dev = &data->client->dev; 246 + int ret; 247 + unsigned int val; 248 + 249 + ret = regmap_read(data->regmap, ATLAS_REG_ORP_CALIB_STATUS, &val); 250 + if (ret) 251 + return ret; 252 + 253 + if (!val) 254 + dev_warn(dev, "device has not been calibrated\n"); 255 + 256 + return 0; 257 + }; 258 + 249 259 struct atlas_device { 250 260 const struct iio_chan_spec *channels; 251 261 int num_channels; ··· 286 264 .calibration = &atlas_check_ec_calibration, 287 265 .delay = ATLAS_EC_INT_TIME_IN_US, 288 266 }, 289 - 267 + [ATLAS_ORP_SM] = { 268 + .channels = atlas_orp_channels, 269 + .num_channels = 2, 270 + .data_reg = ATLAS_REG_ORP_DATA, 271 + .calibration = &atlas_check_orp_calibration, 272 + .delay = ATLAS_ORP_INT_TIME_IN_US, 273 + }, 290 274 }; 291 275 292 276 static int atlas_set_powermode(struct atlas_data *data, int on) ··· 430 402 case IIO_PH: 431 403 case IIO_CONCENTRATION: 432 404 case IIO_ELECTRICALCONDUCTIVITY: 433 - mutex_lock(&indio_dev->mlock); 405 + case IIO_VOLTAGE: 406 + ret = iio_device_claim_direct_mode(indio_dev); 407 + if (ret) 408 + return ret; 434 409 435 - if (iio_buffer_enabled(indio_dev)) 436 - ret = -EBUSY; 437 - else 438 - ret = atlas_read_measurement(data, 439 - chan->address, &reg); 410 + ret = atlas_read_measurement(data, chan->address, &reg); 440 411 441 - mutex_unlock(&indio_dev->mlock); 412 + iio_device_release_direct_mode(indio_dev); 442 413 break; 443 414 default: 444 415 ret = -EINVAL; ··· 467 440 *val = 0; /* 0.000000001 */ 468 441 *val2 = 1000; 469 442 return IIO_VAL_INT_PLUS_NANO; 443 + case IIO_VOLTAGE: 444 + *val = 1; /* 0.1 */ 445 + *val2 = 10; 446 + break; 470 447 default: 471 448 return -EINVAL; 472 449 } ··· 506 475 static const struct i2c_device_id atlas_id[] = { 507 476 { "atlas-ph-sm", ATLAS_PH_SM}, 508 477 { "atlas-ec-sm", ATLAS_EC_SM}, 478 + { "atlas-orp-sm", ATLAS_ORP_SM}, 509 479 {} 510 480 }; 511 481 MODULE_DEVICE_TABLE(i2c, atlas_id); ··· 514 482 static const struct of_device_id atlas_dt_ids[] = { 515 483 { .compatible = "atlas,ph-sm", .data = (void *)ATLAS_PH_SM, }, 516 484 { .compatible = "atlas,ec-sm", .data = (void *)ATLAS_EC_SM, }, 485 + { .compatible = "atlas,orp-sm", .data = (void *)ATLAS_ORP_SM, }, 517 486 { } 518 487 }; 519 488 MODULE_DEVICE_TABLE(of, atlas_dt_ids);
+21 -1
drivers/iio/common/hid-sensors/hid-sensor-trigger.c
··· 122 122 #endif 123 123 } 124 124 125 + static void hid_sensor_set_power_work(struct work_struct *work) 126 + { 127 + struct hid_sensor_common *attrb = container_of(work, 128 + struct hid_sensor_common, 129 + work); 130 + _hid_sensor_power_state(attrb, true); 131 + } 132 + 125 133 static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig, 126 134 bool state) 127 135 { ··· 138 130 139 131 void hid_sensor_remove_trigger(struct hid_sensor_common *attrb) 140 132 { 133 + cancel_work_sync(&attrb->work); 141 134 iio_trigger_unregister(attrb->trigger); 142 135 iio_trigger_free(attrb->trigger); 143 136 } ··· 179 170 goto error_unreg_trigger; 180 171 181 172 iio_device_set_drvdata(indio_dev, attrb); 173 + 174 + INIT_WORK(&attrb->work, hid_sensor_set_power_work); 175 + 182 176 pm_suspend_ignore_children(&attrb->pdev->dev, true); 183 177 pm_runtime_enable(&attrb->pdev->dev); 184 178 /* Default to 3 seconds, but can be changed from sysfs */ ··· 214 202 struct platform_device *pdev = to_platform_device(dev); 215 203 struct iio_dev *indio_dev = platform_get_drvdata(pdev); 216 204 struct hid_sensor_common *attrb = iio_device_get_drvdata(indio_dev); 205 + schedule_work(&attrb->work); 206 + return 0; 207 + } 217 208 209 + static int hid_sensor_runtime_resume(struct device *dev) 210 + { 211 + struct platform_device *pdev = to_platform_device(dev); 212 + struct iio_dev *indio_dev = platform_get_drvdata(pdev); 213 + struct hid_sensor_common *attrb = iio_device_get_drvdata(indio_dev); 218 214 return _hid_sensor_power_state(attrb, true); 219 215 } 220 216 ··· 231 211 const struct dev_pm_ops hid_sensor_pm_ops = { 232 212 SET_SYSTEM_SLEEP_PM_OPS(hid_sensor_suspend, hid_sensor_resume) 233 213 SET_RUNTIME_PM_OPS(hid_sensor_suspend, 234 - hid_sensor_resume, NULL) 214 + hid_sensor_runtime_resume, NULL) 235 215 }; 236 216 EXPORT_SYMBOL(hid_sensor_pm_ops); 237 217
+9
drivers/iio/dac/Kconfig
··· 181 181 To compile this driver as module choose M here: the module will be called 182 182 ad7303. 183 183 184 + config CIO_DAC 185 + tristate "Measurement Computing CIO-DAC IIO driver" 186 + depends on X86 && ISA_BUS_API 187 + help 188 + Say yes here to build support for the Measurement Computing CIO-DAC 189 + analog output device family (CIO-DAC16, CIO-DAC08, PC104-DAC06). The 190 + base port addresses for the devices may be configured via the base 191 + array module parameter. 192 + 184 193 config LPC18XX_DAC 185 194 tristate "NXP LPC18xx DAC driver" 186 195 depends on ARCH_LPC18XX || COMPILE_TEST
+1
drivers/iio/dac/Makefile
··· 20 20 obj-$(CONFIG_AD5791) += ad5791.o 21 21 obj-$(CONFIG_AD5686) += ad5686.o 22 22 obj-$(CONFIG_AD7303) += ad7303.o 23 + obj-$(CONFIG_CIO_DAC) += cio-dac.o 23 24 obj-$(CONFIG_LPC18XX_DAC) += lpc18xx_dac.o 24 25 obj-$(CONFIG_M62332) += m62332.o 25 26 obj-$(CONFIG_MAX517) += max517.o
+144
drivers/iio/dac/cio-dac.c
··· 1 + /* 2 + * IIO driver for the Measurement Computing CIO-DAC 3 + * Copyright (C) 2016 William Breathitt Gray 4 + * 5 + * This program is free software; you can redistribute it and/or modify 6 + * it under the terms of the GNU General Public License, version 2, as 7 + * published by the Free Software Foundation. 8 + * 9 + * This program is distributed in the hope that it will be useful, but 10 + * WITHOUT ANY WARRANTY; without even the implied warranty of 11 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 + * General Public License for more details. 13 + * 14 + * This driver supports the following Measurement Computing devices: CIO-DAC16, 15 + * CIO-DAC06, and PC104-DAC06. 16 + */ 17 + #include <linux/bitops.h> 18 + #include <linux/device.h> 19 + #include <linux/errno.h> 20 + #include <linux/iio/iio.h> 21 + #include <linux/iio/types.h> 22 + #include <linux/io.h> 23 + #include <linux/ioport.h> 24 + #include <linux/isa.h> 25 + #include <linux/module.h> 26 + #include <linux/moduleparam.h> 27 + 28 + #define CIO_DAC_NUM_CHAN 16 29 + 30 + #define CIO_DAC_CHAN(chan) { \ 31 + .type = IIO_VOLTAGE, \ 32 + .channel = chan, \ 33 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 34 + .indexed = 1, \ 35 + .output = 1 \ 36 + } 37 + 38 + #define CIO_DAC_EXTENT 32 39 + 40 + static unsigned int base[max_num_isa_dev(CIO_DAC_EXTENT)]; 41 + static unsigned int num_cio_dac; 42 + module_param_array(base, uint, &num_cio_dac, 0); 43 + MODULE_PARM_DESC(base, "Measurement Computing CIO-DAC base addresses"); 44 + 45 + /** 46 + * struct cio_dac_iio - IIO device private data structure 47 + * @chan_out_states: channels' output states 48 + * @base: base port address of the IIO device 49 + */ 50 + struct cio_dac_iio { 51 + int chan_out_states[CIO_DAC_NUM_CHAN]; 52 + unsigned int base; 53 + }; 54 + 55 + static int cio_dac_read_raw(struct iio_dev *indio_dev, 56 + struct iio_chan_spec const *chan, int *val, int *val2, long mask) 57 + { 58 + struct cio_dac_iio *const priv = iio_priv(indio_dev); 59 + 60 + if (mask != IIO_CHAN_INFO_RAW) 61 + return -EINVAL; 62 + 63 + *val = priv->chan_out_states[chan->channel]; 64 + 65 + return IIO_VAL_INT; 66 + } 67 + 68 + static int cio_dac_write_raw(struct iio_dev *indio_dev, 69 + struct iio_chan_spec const *chan, int val, int val2, long mask) 70 + { 71 + struct cio_dac_iio *const priv = iio_priv(indio_dev); 72 + const unsigned int chan_addr_offset = 2 * chan->channel; 73 + 74 + if (mask != IIO_CHAN_INFO_RAW) 75 + return -EINVAL; 76 + 77 + /* DAC can only accept up to a 16-bit value */ 78 + if ((unsigned int)val > 65535) 79 + return -EINVAL; 80 + 81 + priv->chan_out_states[chan->channel] = val; 82 + outw(val, priv->base + chan_addr_offset); 83 + 84 + return 0; 85 + } 86 + 87 + static const struct iio_info cio_dac_info = { 88 + .driver_module = THIS_MODULE, 89 + .read_raw = cio_dac_read_raw, 90 + .write_raw = cio_dac_write_raw 91 + }; 92 + 93 + static const struct iio_chan_spec cio_dac_channels[CIO_DAC_NUM_CHAN] = { 94 + CIO_DAC_CHAN(0), CIO_DAC_CHAN(1), CIO_DAC_CHAN(2), CIO_DAC_CHAN(3), 95 + CIO_DAC_CHAN(4), CIO_DAC_CHAN(5), CIO_DAC_CHAN(6), CIO_DAC_CHAN(7), 96 + CIO_DAC_CHAN(8), CIO_DAC_CHAN(9), CIO_DAC_CHAN(10), CIO_DAC_CHAN(11), 97 + CIO_DAC_CHAN(12), CIO_DAC_CHAN(13), CIO_DAC_CHAN(14), CIO_DAC_CHAN(15) 98 + }; 99 + 100 + static int cio_dac_probe(struct device *dev, unsigned int id) 101 + { 102 + struct iio_dev *indio_dev; 103 + struct cio_dac_iio *priv; 104 + unsigned int i; 105 + 106 + indio_dev = devm_iio_device_alloc(dev, sizeof(*priv)); 107 + if (!indio_dev) 108 + return -ENOMEM; 109 + 110 + if (!devm_request_region(dev, base[id], CIO_DAC_EXTENT, 111 + dev_name(dev))) { 112 + dev_err(dev, "Unable to request port addresses (0x%X-0x%X)\n", 113 + base[id], base[id] + CIO_DAC_EXTENT); 114 + return -EBUSY; 115 + } 116 + 117 + indio_dev->info = &cio_dac_info; 118 + indio_dev->modes = INDIO_DIRECT_MODE; 119 + indio_dev->channels = cio_dac_channels; 120 + indio_dev->num_channels = CIO_DAC_NUM_CHAN; 121 + indio_dev->name = dev_name(dev); 122 + 123 + priv = iio_priv(indio_dev); 124 + priv->base = base[id]; 125 + 126 + /* initialize DAC outputs to 0V */ 127 + for (i = 0; i < 32; i += 2) 128 + outw(0, base[id] + i); 129 + 130 + return devm_iio_device_register(dev, indio_dev); 131 + } 132 + 133 + static struct isa_driver cio_dac_driver = { 134 + .probe = cio_dac_probe, 135 + .driver = { 136 + .name = "cio-dac" 137 + } 138 + }; 139 + 140 + module_isa_driver(cio_dac_driver, num_cio_dac); 141 + 142 + MODULE_AUTHOR("William Breathitt Gray <vilhelm.gray@gmail.com>"); 143 + MODULE_DESCRIPTION("Measurement Computing CIO-DAC IIO driver"); 144 + MODULE_LICENSE("GPL v2");
+4 -4
drivers/iio/humidity/Kconfig
··· 26 26 tristate "TI HDC100x relative humidity and temperature sensor" 27 27 depends on I2C 28 28 help 29 - Say yes here to build support for the TI HDC100x series of 30 - relative humidity and temperature sensors. 29 + Say yes here to build support for the Texas Instruments 30 + HDC1000 and HDC1008 relative humidity and temperature sensors. 31 31 32 - To compile this driver as a module, choose M here: the module 33 - will be called hdc100x. 32 + To compile this driver as a module, choose M here: the module 33 + will be called hdc100x. 34 34 35 35 config HTU21 36 36 tristate "Measurement Specialties HTU21 humidity & temperature sensor"
+3 -3
drivers/iio/light/Kconfig
··· 333 333 will be called us5182d. 334 334 335 335 config VCNL4000 336 - tristate "VCNL4000 combined ALS and proximity sensor" 336 + tristate "VCNL4000/4010/4020 combined ALS and proximity sensor" 337 337 depends on I2C 338 338 help 339 - Say Y here if you want to build a driver for the Vishay VCNL4000 340 - combined ambient light and proximity sensor. 339 + Say Y here if you want to build a driver for the Vishay VCNL4000, 340 + VCNL4010, VCNL4020 combined ambient light and proximity sensor. 341 341 342 342 To compile this driver as a module, choose M here: the 343 343 module will be called vcnl4000.
+1 -1
drivers/iio/light/us5182d.c
··· 894 894 goto out_err; 895 895 896 896 if (data->default_continuous) { 897 - pm_runtime_set_active(&client->dev); 897 + ret = pm_runtime_set_active(&client->dev); 898 898 if (ret < 0) 899 899 goto out_err; 900 900 }
+44 -30
drivers/iio/light/vcnl4000.c
··· 1 1 /* 2 - * vcnl4000.c - Support for Vishay VCNL4000 combined ambient light and 3 - * proximity sensor 2 + * vcnl4000.c - Support for Vishay VCNL4000/4010/4020 combined ambient 3 + * light and proximity sensor 4 4 * 5 5 * Copyright 2012 Peter Meerwald <pmeerw@pmeerw.net> 6 6 * ··· 13 13 * TODO: 14 14 * allow to adjust IR current 15 15 * proximity threshold and event handling 16 + * periodic ALS/proximity measurement (VCNL4010/20) 17 + * interrupts (VCNL4010/20) 16 18 */ 17 19 18 20 #include <linux/module.h> ··· 26 24 #include <linux/iio/sysfs.h> 27 25 28 26 #define VCNL4000_DRV_NAME "vcnl4000" 27 + #define VCNL4000_ID 0x01 28 + #define VCNL4010_ID 0x02 /* for VCNL4020, VCNL4010 */ 29 29 30 30 #define VCNL4000_COMMAND 0x80 /* Command register */ 31 31 #define VCNL4000_PROD_REV 0x81 /* Product ID and Revision ID */ ··· 41 37 #define VCNL4000_PS_MOD_ADJ 0x8a /* Proximity modulator timing adjustment */ 42 38 43 39 /* Bit masks for COMMAND register */ 44 - #define VCNL4000_AL_RDY 0x40 /* ALS data ready? */ 45 - #define VCNL4000_PS_RDY 0x20 /* proximity data ready? */ 46 - #define VCNL4000_AL_OD 0x10 /* start on-demand ALS measurement */ 47 - #define VCNL4000_PS_OD 0x08 /* start on-demand proximity measurement */ 40 + #define VCNL4000_AL_RDY BIT(6) /* ALS data ready? */ 41 + #define VCNL4000_PS_RDY BIT(5) /* proximity data ready? */ 42 + #define VCNL4000_AL_OD BIT(4) /* start on-demand ALS measurement */ 43 + #define VCNL4000_PS_OD BIT(3) /* start on-demand proximity measurement */ 48 44 49 45 struct vcnl4000_data { 50 46 struct i2c_client *client; 47 + struct mutex lock; 51 48 }; 52 49 53 50 static const struct i2c_device_id vcnl4000_id[] = { ··· 64 59 __be16 buf; 65 60 int ret; 66 61 62 + mutex_lock(&data->lock); 63 + 67 64 ret = i2c_smbus_write_byte_data(data->client, VCNL4000_COMMAND, 68 65 req_mask); 69 66 if (ret < 0) 70 - return ret; 67 + goto fail; 71 68 72 69 /* wait for data to become ready */ 73 70 while (tries--) { 74 71 ret = i2c_smbus_read_byte_data(data->client, VCNL4000_COMMAND); 75 72 if (ret < 0) 76 - return ret; 73 + goto fail; 77 74 if (ret & rdy_mask) 78 75 break; 79 76 msleep(20); /* measurement takes up to 100 ms */ ··· 84 77 if (tries < 0) { 85 78 dev_err(&data->client->dev, 86 79 "vcnl4000_measure() failed, data not ready\n"); 87 - return -EIO; 80 + ret = -EIO; 81 + goto fail; 88 82 } 89 83 90 84 ret = i2c_smbus_read_i2c_block_data(data->client, 91 85 data_reg, sizeof(buf), (u8 *) &buf); 92 86 if (ret < 0) 93 - return ret; 87 + goto fail; 94 88 89 + mutex_unlock(&data->lock); 95 90 *val = be16_to_cpu(buf); 96 91 97 92 return 0; 93 + 94 + fail: 95 + mutex_unlock(&data->lock); 96 + return ret; 98 97 } 99 98 100 99 static const struct iio_chan_spec vcnl4000_channels[] = { ··· 118 105 struct iio_chan_spec const *chan, 119 106 int *val, int *val2, long mask) 120 107 { 121 - int ret = -EINVAL; 108 + int ret; 122 109 struct vcnl4000_data *data = iio_priv(indio_dev); 123 110 124 111 switch (mask) { ··· 130 117 VCNL4000_AL_RESULT_HI, val); 131 118 if (ret < 0) 132 119 return ret; 133 - ret = IIO_VAL_INT; 134 - break; 120 + return IIO_VAL_INT; 135 121 case IIO_PROXIMITY: 136 122 ret = vcnl4000_measure(data, 137 123 VCNL4000_PS_OD, VCNL4000_PS_RDY, 138 124 VCNL4000_PS_RESULT_HI, val); 139 125 if (ret < 0) 140 126 return ret; 141 - ret = IIO_VAL_INT; 142 - break; 127 + return IIO_VAL_INT; 143 128 default: 144 - break; 129 + return -EINVAL; 145 130 } 146 - break; 147 131 case IIO_CHAN_INFO_SCALE: 148 - if (chan->type == IIO_LIGHT) { 149 - *val = 0; 150 - *val2 = 250000; 151 - ret = IIO_VAL_INT_PLUS_MICRO; 152 - } 153 - break; 154 - default: 155 - break; 156 - } 132 + if (chan->type != IIO_LIGHT) 133 + return -EINVAL; 157 134 158 - return ret; 135 + *val = 0; 136 + *val2 = 250000; 137 + return IIO_VAL_INT_PLUS_MICRO; 138 + default: 139 + return -EINVAL; 140 + } 159 141 } 160 142 161 143 static const struct iio_info vcnl4000_info = { ··· 163 155 { 164 156 struct vcnl4000_data *data; 165 157 struct iio_dev *indio_dev; 166 - int ret; 158 + int ret, prod_id; 167 159 168 160 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 169 161 if (!indio_dev) ··· 172 164 data = iio_priv(indio_dev); 173 165 i2c_set_clientdata(client, indio_dev); 174 166 data->client = client; 167 + mutex_init(&data->lock); 175 168 176 169 ret = i2c_smbus_read_byte_data(data->client, VCNL4000_PROD_REV); 177 170 if (ret < 0) 178 171 return ret; 179 172 180 - dev_info(&client->dev, "VCNL4000 Ambient light/proximity sensor, Prod %02x, Rev: %02x\n", 181 - ret >> 4, ret & 0xf); 173 + prod_id = ret >> 4; 174 + if (prod_id != VCNL4010_ID && prod_id != VCNL4000_ID) 175 + return -ENODEV; 176 + 177 + dev_dbg(&client->dev, "%s Ambient light/proximity sensor, Rev: %02x\n", 178 + (prod_id == VCNL4010_ID) ? "VCNL4010/4020" : "VCNL4000", 179 + ret & 0xf); 182 180 183 181 indio_dev->dev.parent = &client->dev; 184 182 indio_dev->info = &vcnl4000_info;
+15 -1
drivers/iio/magnetometer/Kconfig
··· 5 5 6 6 menu "Magnetometer sensors" 7 7 8 + config AK8974 9 + tristate "Asahi Kasei AK8974 3-Axis Magnetometer" 10 + depends on I2C 11 + depends on OF 12 + select REGMAP_I2C 13 + select IIO_BUFFER 14 + select IIO_TRIGGERED_BUFFER 15 + help 16 + Say yes here to build support for Asahi Kasei AK8974 or 17 + AMI305 I2C-based 3-axis magnetometer chips. 18 + 19 + To compile this driver as a module, choose M here: the module 20 + will be called ak8974. 21 + 8 22 config AK8975 9 - tristate "Asahi Kasei AK 3-Axis Magnetometer" 23 + tristate "Asahi Kasei AK8975 3-Axis Magnetometer" 10 24 depends on I2C 11 25 depends on GPIOLIB || COMPILE_TEST 12 26 select IIO_BUFFER
+1
drivers/iio/magnetometer/Makefile
··· 3 3 # 4 4 5 5 # When adding new entries keep the list in alphabetical order 6 + obj-$(CONFIG_AK8974) += ak8974.o 6 7 obj-$(CONFIG_AK8975) += ak8975.o 7 8 obj-$(CONFIG_BMC150_MAGN) += bmc150_magn.o 8 9 obj-$(CONFIG_BMC150_MAGN_I2C) += bmc150_magn_i2c.o
+863
drivers/iio/magnetometer/ak8974.c
··· 1 + /* 2 + * Driver for the Asahi Kasei EMD Corporation AK8974 3 + * and Aichi Steel AMI305 magnetometer chips. 4 + * Based on a patch from Samu Onkalo and the AK8975 IIO driver. 5 + * 6 + * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 7 + * Copyright (c) 2010 NVIDIA Corporation. 8 + * Copyright (C) 2016 Linaro Ltd. 9 + * 10 + * Author: Samu Onkalo <samu.p.onkalo@nokia.com> 11 + * Author: Linus Walleij <linus.walleij@linaro.org> 12 + */ 13 + #include <linux/module.h> 14 + #include <linux/kernel.h> 15 + #include <linux/i2c.h> 16 + #include <linux/interrupt.h> 17 + #include <linux/irq.h> /* For irq_get_irq_data() */ 18 + #include <linux/completion.h> 19 + #include <linux/err.h> 20 + #include <linux/mutex.h> 21 + #include <linux/delay.h> 22 + #include <linux/bitops.h> 23 + #include <linux/regmap.h> 24 + #include <linux/regulator/consumer.h> 25 + #include <linux/pm_runtime.h> 26 + 27 + #include <linux/iio/iio.h> 28 + #include <linux/iio/sysfs.h> 29 + #include <linux/iio/buffer.h> 30 + #include <linux/iio/trigger.h> 31 + #include <linux/iio/trigger_consumer.h> 32 + #include <linux/iio/triggered_buffer.h> 33 + 34 + /* 35 + * 16-bit registers are little-endian. LSB is at the address defined below 36 + * and MSB is at the next higher address. 37 + */ 38 + 39 + /* These registers are common for AK8974 and AMI305 */ 40 + #define AK8974_SELFTEST 0x0C 41 + #define AK8974_SELFTEST_IDLE 0x55 42 + #define AK8974_SELFTEST_OK 0xAA 43 + 44 + #define AK8974_INFO 0x0D 45 + 46 + #define AK8974_WHOAMI 0x0F 47 + #define AK8974_WHOAMI_VALUE_AMI305 0x47 48 + #define AK8974_WHOAMI_VALUE_AK8974 0x48 49 + 50 + #define AK8974_DATA_X 0x10 51 + #define AK8974_DATA_Y 0x12 52 + #define AK8974_DATA_Z 0x14 53 + #define AK8974_INT_SRC 0x16 54 + #define AK8974_STATUS 0x18 55 + #define AK8974_INT_CLEAR 0x1A 56 + #define AK8974_CTRL1 0x1B 57 + #define AK8974_CTRL2 0x1C 58 + #define AK8974_CTRL3 0x1D 59 + #define AK8974_INT_CTRL 0x1E 60 + #define AK8974_INT_THRES 0x26 /* Absolute any axis value threshold */ 61 + #define AK8974_PRESET 0x30 62 + 63 + /* AK8974-specific offsets */ 64 + #define AK8974_OFFSET_X 0x20 65 + #define AK8974_OFFSET_Y 0x22 66 + #define AK8974_OFFSET_Z 0x24 67 + /* AMI305-specific offsets */ 68 + #define AMI305_OFFSET_X 0x6C 69 + #define AMI305_OFFSET_Y 0x72 70 + #define AMI305_OFFSET_Z 0x78 71 + 72 + /* Different temperature registers */ 73 + #define AK8974_TEMP 0x31 74 + #define AMI305_TEMP 0x60 75 + 76 + #define AK8974_INT_X_HIGH BIT(7) /* Axis over +threshold */ 77 + #define AK8974_INT_Y_HIGH BIT(6) 78 + #define AK8974_INT_Z_HIGH BIT(5) 79 + #define AK8974_INT_X_LOW BIT(4) /* Axis below -threshold */ 80 + #define AK8974_INT_Y_LOW BIT(3) 81 + #define AK8974_INT_Z_LOW BIT(2) 82 + #define AK8974_INT_RANGE BIT(1) /* Range overflow (any axis) */ 83 + 84 + #define AK8974_STATUS_DRDY BIT(6) /* Data ready */ 85 + #define AK8974_STATUS_OVERRUN BIT(5) /* Data overrun */ 86 + #define AK8974_STATUS_INT BIT(4) /* Interrupt occurred */ 87 + 88 + #define AK8974_CTRL1_POWER BIT(7) /* 0 = standby; 1 = active */ 89 + #define AK8974_CTRL1_RATE BIT(4) /* 0 = 10 Hz; 1 = 20 Hz */ 90 + #define AK8974_CTRL1_FORCE_EN BIT(1) /* 0 = normal; 1 = force */ 91 + #define AK8974_CTRL1_MODE2 BIT(0) /* 0 */ 92 + 93 + #define AK8974_CTRL2_INT_EN BIT(4) /* 1 = enable interrupts */ 94 + #define AK8974_CTRL2_DRDY_EN BIT(3) /* 1 = enable data ready signal */ 95 + #define AK8974_CTRL2_DRDY_POL BIT(2) /* 1 = data ready active high */ 96 + #define AK8974_CTRL2_RESDEF (AK8974_CTRL2_DRDY_POL) 97 + 98 + #define AK8974_CTRL3_RESET BIT(7) /* Software reset */ 99 + #define AK8974_CTRL3_FORCE BIT(6) /* Start forced measurement */ 100 + #define AK8974_CTRL3_SELFTEST BIT(4) /* Set selftest register */ 101 + #define AK8974_CTRL3_RESDEF 0x00 102 + 103 + #define AK8974_INT_CTRL_XEN BIT(7) /* Enable interrupt for this axis */ 104 + #define AK8974_INT_CTRL_YEN BIT(6) 105 + #define AK8974_INT_CTRL_ZEN BIT(5) 106 + #define AK8974_INT_CTRL_XYZEN (BIT(7)|BIT(6)|BIT(5)) 107 + #define AK8974_INT_CTRL_POL BIT(3) /* 0 = active low; 1 = active high */ 108 + #define AK8974_INT_CTRL_PULSE BIT(1) /* 0 = latched; 1 = pulse (50 usec) */ 109 + #define AK8974_INT_CTRL_RESDEF (AK8974_INT_CTRL_XYZEN | AK8974_INT_CTRL_POL) 110 + 111 + /* The AMI305 has elaborate FW version and serial number registers */ 112 + #define AMI305_VER 0xE8 113 + #define AMI305_SN 0xEA 114 + 115 + #define AK8974_MAX_RANGE 2048 116 + 117 + #define AK8974_POWERON_DELAY 50 118 + #define AK8974_ACTIVATE_DELAY 1 119 + #define AK8974_SELFTEST_DELAY 1 120 + /* 121 + * Set the autosuspend to two orders of magnitude larger than the poweron 122 + * delay to make sane reasonable power tradeoff savings (5 seconds in 123 + * this case). 124 + */ 125 + #define AK8974_AUTOSUSPEND_DELAY 5000 126 + 127 + #define AK8974_MEASTIME 3 128 + 129 + #define AK8974_PWR_ON 1 130 + #define AK8974_PWR_OFF 0 131 + 132 + /** 133 + * struct ak8974 - state container for the AK8974 driver 134 + * @i2c: parent I2C client 135 + * @orientation: mounting matrix, flipped axis etc 136 + * @map: regmap to access the AK8974 registers over I2C 137 + * @regs: the avdd and dvdd power regulators 138 + * @name: the name of the part 139 + * @variant: the whoami ID value (for selecting code paths) 140 + * @lock: locks the magnetometer for exclusive use during a measurement 141 + * @drdy_irq: uses the DRDY IRQ line 142 + * @drdy_complete: completion for DRDY 143 + * @drdy_active_low: the DRDY IRQ is active low 144 + */ 145 + struct ak8974 { 146 + struct i2c_client *i2c; 147 + struct iio_mount_matrix orientation; 148 + struct regmap *map; 149 + struct regulator_bulk_data regs[2]; 150 + const char *name; 151 + u8 variant; 152 + struct mutex lock; 153 + bool drdy_irq; 154 + struct completion drdy_complete; 155 + bool drdy_active_low; 156 + }; 157 + 158 + static const char ak8974_reg_avdd[] = "avdd"; 159 + static const char ak8974_reg_dvdd[] = "dvdd"; 160 + 161 + static int ak8974_set_power(struct ak8974 *ak8974, bool mode) 162 + { 163 + int ret; 164 + u8 val; 165 + 166 + val = mode ? AK8974_CTRL1_POWER : 0; 167 + val |= AK8974_CTRL1_FORCE_EN; 168 + ret = regmap_write(ak8974->map, AK8974_CTRL1, val); 169 + if (ret < 0) 170 + return ret; 171 + 172 + if (mode) 173 + msleep(AK8974_ACTIVATE_DELAY); 174 + 175 + return 0; 176 + } 177 + 178 + static int ak8974_reset(struct ak8974 *ak8974) 179 + { 180 + int ret; 181 + 182 + /* Power on to get register access. Sets CTRL1 reg to reset state */ 183 + ret = ak8974_set_power(ak8974, AK8974_PWR_ON); 184 + if (ret) 185 + return ret; 186 + ret = regmap_write(ak8974->map, AK8974_CTRL2, AK8974_CTRL2_RESDEF); 187 + if (ret) 188 + return ret; 189 + ret = regmap_write(ak8974->map, AK8974_CTRL3, AK8974_CTRL3_RESDEF); 190 + if (ret) 191 + return ret; 192 + ret = regmap_write(ak8974->map, AK8974_INT_CTRL, 193 + AK8974_INT_CTRL_RESDEF); 194 + if (ret) 195 + return ret; 196 + 197 + /* After reset, power off is default state */ 198 + return ak8974_set_power(ak8974, AK8974_PWR_OFF); 199 + } 200 + 201 + static int ak8974_configure(struct ak8974 *ak8974) 202 + { 203 + int ret; 204 + 205 + ret = regmap_write(ak8974->map, AK8974_CTRL2, AK8974_CTRL2_DRDY_EN | 206 + AK8974_CTRL2_INT_EN); 207 + if (ret) 208 + return ret; 209 + ret = regmap_write(ak8974->map, AK8974_CTRL3, 0); 210 + if (ret) 211 + return ret; 212 + ret = regmap_write(ak8974->map, AK8974_INT_CTRL, AK8974_INT_CTRL_POL); 213 + if (ret) 214 + return ret; 215 + 216 + return regmap_write(ak8974->map, AK8974_PRESET, 0); 217 + } 218 + 219 + static int ak8974_trigmeas(struct ak8974 *ak8974) 220 + { 221 + unsigned int clear; 222 + u8 mask; 223 + u8 val; 224 + int ret; 225 + 226 + /* Clear any previous measurement overflow status */ 227 + ret = regmap_read(ak8974->map, AK8974_INT_CLEAR, &clear); 228 + if (ret) 229 + return ret; 230 + 231 + /* If we have a DRDY IRQ line, use it */ 232 + if (ak8974->drdy_irq) { 233 + mask = AK8974_CTRL2_INT_EN | 234 + AK8974_CTRL2_DRDY_EN | 235 + AK8974_CTRL2_DRDY_POL; 236 + val = AK8974_CTRL2_DRDY_EN; 237 + 238 + if (!ak8974->drdy_active_low) 239 + val |= AK8974_CTRL2_DRDY_POL; 240 + 241 + init_completion(&ak8974->drdy_complete); 242 + ret = regmap_update_bits(ak8974->map, AK8974_CTRL2, 243 + mask, val); 244 + if (ret) 245 + return ret; 246 + } 247 + 248 + /* Force a measurement */ 249 + return regmap_update_bits(ak8974->map, 250 + AK8974_CTRL3, 251 + AK8974_CTRL3_FORCE, 252 + AK8974_CTRL3_FORCE); 253 + } 254 + 255 + static int ak8974_await_drdy(struct ak8974 *ak8974) 256 + { 257 + int timeout = 2; 258 + unsigned int val; 259 + int ret; 260 + 261 + if (ak8974->drdy_irq) { 262 + ret = wait_for_completion_timeout(&ak8974->drdy_complete, 263 + 1 + msecs_to_jiffies(1000)); 264 + if (!ret) { 265 + dev_err(&ak8974->i2c->dev, 266 + "timeout waiting for DRDY IRQ\n"); 267 + return -ETIMEDOUT; 268 + } 269 + return 0; 270 + } 271 + 272 + /* Default delay-based poll loop */ 273 + do { 274 + msleep(AK8974_MEASTIME); 275 + ret = regmap_read(ak8974->map, AK8974_STATUS, &val); 276 + if (ret < 0) 277 + return ret; 278 + if (val & AK8974_STATUS_DRDY) 279 + return 0; 280 + } while (--timeout); 281 + if (!timeout) { 282 + dev_err(&ak8974->i2c->dev, 283 + "timeout waiting for DRDY\n"); 284 + return -ETIMEDOUT; 285 + } 286 + 287 + return 0; 288 + } 289 + 290 + static int ak8974_getresult(struct ak8974 *ak8974, s16 *result) 291 + { 292 + unsigned int src; 293 + int ret; 294 + 295 + ret = ak8974_await_drdy(ak8974); 296 + if (ret) 297 + return ret; 298 + ret = regmap_read(ak8974->map, AK8974_INT_SRC, &src); 299 + if (ret < 0) 300 + return ret; 301 + 302 + /* Out of range overflow! Strong magnet close? */ 303 + if (src & AK8974_INT_RANGE) { 304 + dev_err(&ak8974->i2c->dev, 305 + "range overflow in sensor\n"); 306 + return -ERANGE; 307 + } 308 + 309 + ret = regmap_bulk_read(ak8974->map, AK8974_DATA_X, result, 6); 310 + if (ret) 311 + return ret; 312 + 313 + return ret; 314 + } 315 + 316 + static irqreturn_t ak8974_drdy_irq(int irq, void *d) 317 + { 318 + struct ak8974 *ak8974 = d; 319 + 320 + if (!ak8974->drdy_irq) 321 + return IRQ_NONE; 322 + 323 + /* TODO: timestamp here to get good measurement stamps */ 324 + return IRQ_WAKE_THREAD; 325 + } 326 + 327 + static irqreturn_t ak8974_drdy_irq_thread(int irq, void *d) 328 + { 329 + struct ak8974 *ak8974 = d; 330 + unsigned int val; 331 + int ret; 332 + 333 + /* Check if this was a DRDY from us */ 334 + ret = regmap_read(ak8974->map, AK8974_STATUS, &val); 335 + if (ret < 0) { 336 + dev_err(&ak8974->i2c->dev, "error reading DRDY status\n"); 337 + return IRQ_HANDLED; 338 + } 339 + if (val & AK8974_STATUS_DRDY) { 340 + /* Yes this was our IRQ */ 341 + complete(&ak8974->drdy_complete); 342 + return IRQ_HANDLED; 343 + } 344 + 345 + /* We may be on a shared IRQ, let the next client check */ 346 + return IRQ_NONE; 347 + } 348 + 349 + static int ak8974_selftest(struct ak8974 *ak8974) 350 + { 351 + struct device *dev = &ak8974->i2c->dev; 352 + unsigned int val; 353 + int ret; 354 + 355 + ret = regmap_read(ak8974->map, AK8974_SELFTEST, &val); 356 + if (ret) 357 + return ret; 358 + if (val != AK8974_SELFTEST_IDLE) { 359 + dev_err(dev, "selftest not idle before test\n"); 360 + return -EIO; 361 + } 362 + 363 + /* Trigger self-test */ 364 + ret = regmap_update_bits(ak8974->map, 365 + AK8974_CTRL3, 366 + AK8974_CTRL3_SELFTEST, 367 + AK8974_CTRL3_SELFTEST); 368 + if (ret) { 369 + dev_err(dev, "could not write CTRL3\n"); 370 + return ret; 371 + } 372 + 373 + msleep(AK8974_SELFTEST_DELAY); 374 + 375 + ret = regmap_read(ak8974->map, AK8974_SELFTEST, &val); 376 + if (ret) 377 + return ret; 378 + if (val != AK8974_SELFTEST_OK) { 379 + dev_err(dev, "selftest result NOT OK (%02x)\n", val); 380 + return -EIO; 381 + } 382 + 383 + ret = regmap_read(ak8974->map, AK8974_SELFTEST, &val); 384 + if (ret) 385 + return ret; 386 + if (val != AK8974_SELFTEST_IDLE) { 387 + dev_err(dev, "selftest not idle after test (%02x)\n", val); 388 + return -EIO; 389 + } 390 + dev_dbg(dev, "passed self-test\n"); 391 + 392 + return 0; 393 + } 394 + 395 + static int ak8974_get_u16_val(struct ak8974 *ak8974, u8 reg, u16 *val) 396 + { 397 + int ret; 398 + u16 bulk; 399 + 400 + ret = regmap_bulk_read(ak8974->map, reg, &bulk, 2); 401 + if (ret) 402 + return ret; 403 + *val = le16_to_cpu(bulk); 404 + 405 + return 0; 406 + } 407 + 408 + static int ak8974_detect(struct ak8974 *ak8974) 409 + { 410 + unsigned int whoami; 411 + const char *name; 412 + int ret; 413 + unsigned int fw; 414 + u16 sn; 415 + 416 + ret = regmap_read(ak8974->map, AK8974_WHOAMI, &whoami); 417 + if (ret) 418 + return ret; 419 + 420 + switch (whoami) { 421 + case AK8974_WHOAMI_VALUE_AMI305: 422 + name = "ami305"; 423 + ret = regmap_read(ak8974->map, AMI305_VER, &fw); 424 + if (ret) 425 + return ret; 426 + fw &= 0x7f; /* only bits 0 thru 6 valid */ 427 + ret = ak8974_get_u16_val(ak8974, AMI305_SN, &sn); 428 + if (ret) 429 + return ret; 430 + dev_info(&ak8974->i2c->dev, 431 + "detected %s, FW ver %02x, S/N: %04x\n", 432 + name, fw, sn); 433 + break; 434 + case AK8974_WHOAMI_VALUE_AK8974: 435 + name = "ak8974"; 436 + dev_info(&ak8974->i2c->dev, "detected AK8974\n"); 437 + break; 438 + default: 439 + dev_err(&ak8974->i2c->dev, "unsupported device (%02x) ", 440 + whoami); 441 + return -ENODEV; 442 + } 443 + 444 + ak8974->name = name; 445 + ak8974->variant = whoami; 446 + 447 + return 0; 448 + } 449 + 450 + static int ak8974_read_raw(struct iio_dev *indio_dev, 451 + struct iio_chan_spec const *chan, 452 + int *val, int *val2, 453 + long mask) 454 + { 455 + struct ak8974 *ak8974 = iio_priv(indio_dev); 456 + s16 hw_values[3]; 457 + int ret = -EINVAL; 458 + 459 + pm_runtime_get_sync(&ak8974->i2c->dev); 460 + mutex_lock(&ak8974->lock); 461 + 462 + switch (mask) { 463 + case IIO_CHAN_INFO_RAW: 464 + if (chan->address > 2) { 465 + dev_err(&ak8974->i2c->dev, "faulty channel address\n"); 466 + ret = -EIO; 467 + goto out_unlock; 468 + } 469 + ret = ak8974_trigmeas(ak8974); 470 + if (ret) 471 + goto out_unlock; 472 + ret = ak8974_getresult(ak8974, hw_values); 473 + if (ret) 474 + goto out_unlock; 475 + 476 + /* 477 + * We read all axes and discard all but one, for optimized 478 + * reading, use the triggered buffer. 479 + */ 480 + *val = le16_to_cpu(hw_values[chan->address]); 481 + 482 + ret = IIO_VAL_INT; 483 + } 484 + 485 + out_unlock: 486 + mutex_unlock(&ak8974->lock); 487 + pm_runtime_mark_last_busy(&ak8974->i2c->dev); 488 + pm_runtime_put_autosuspend(&ak8974->i2c->dev); 489 + 490 + return ret; 491 + } 492 + 493 + static void ak8974_fill_buffer(struct iio_dev *indio_dev) 494 + { 495 + struct ak8974 *ak8974 = iio_priv(indio_dev); 496 + int ret; 497 + s16 hw_values[8]; /* Three axes + 64bit padding */ 498 + 499 + pm_runtime_get_sync(&ak8974->i2c->dev); 500 + mutex_lock(&ak8974->lock); 501 + 502 + ret = ak8974_trigmeas(ak8974); 503 + if (ret) { 504 + dev_err(&ak8974->i2c->dev, "error triggering measure\n"); 505 + goto out_unlock; 506 + } 507 + ret = ak8974_getresult(ak8974, hw_values); 508 + if (ret) { 509 + dev_err(&ak8974->i2c->dev, "error getting measures\n"); 510 + goto out_unlock; 511 + } 512 + 513 + iio_push_to_buffers_with_timestamp(indio_dev, hw_values, 514 + iio_get_time_ns(indio_dev)); 515 + 516 + out_unlock: 517 + mutex_unlock(&ak8974->lock); 518 + pm_runtime_mark_last_busy(&ak8974->i2c->dev); 519 + pm_runtime_put_autosuspend(&ak8974->i2c->dev); 520 + } 521 + 522 + static irqreturn_t ak8974_handle_trigger(int irq, void *p) 523 + { 524 + const struct iio_poll_func *pf = p; 525 + struct iio_dev *indio_dev = pf->indio_dev; 526 + 527 + ak8974_fill_buffer(indio_dev); 528 + iio_trigger_notify_done(indio_dev->trig); 529 + 530 + return IRQ_HANDLED; 531 + } 532 + 533 + static const struct iio_mount_matrix * 534 + ak8974_get_mount_matrix(const struct iio_dev *indio_dev, 535 + const struct iio_chan_spec *chan) 536 + { 537 + struct ak8974 *ak8974 = iio_priv(indio_dev); 538 + 539 + return &ak8974->orientation; 540 + } 541 + 542 + static const struct iio_chan_spec_ext_info ak8974_ext_info[] = { 543 + IIO_MOUNT_MATRIX(IIO_SHARED_BY_DIR, ak8974_get_mount_matrix), 544 + { }, 545 + }; 546 + 547 + #define AK8974_AXIS_CHANNEL(axis, index) \ 548 + { \ 549 + .type = IIO_MAGN, \ 550 + .modified = 1, \ 551 + .channel2 = IIO_MOD_##axis, \ 552 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 553 + .ext_info = ak8974_ext_info, \ 554 + .address = index, \ 555 + .scan_index = index, \ 556 + .scan_type = { \ 557 + .sign = 's', \ 558 + .realbits = 16, \ 559 + .storagebits = 16, \ 560 + .endianness = IIO_LE \ 561 + }, \ 562 + } 563 + 564 + static const struct iio_chan_spec ak8974_channels[] = { 565 + AK8974_AXIS_CHANNEL(X, 0), 566 + AK8974_AXIS_CHANNEL(Y, 1), 567 + AK8974_AXIS_CHANNEL(Z, 2), 568 + IIO_CHAN_SOFT_TIMESTAMP(3), 569 + }; 570 + 571 + static const unsigned long ak8974_scan_masks[] = { 0x7, 0 }; 572 + 573 + static const struct iio_info ak8974_info = { 574 + .read_raw = &ak8974_read_raw, 575 + .driver_module = THIS_MODULE, 576 + }; 577 + 578 + static bool ak8974_writeable_reg(struct device *dev, unsigned int reg) 579 + { 580 + struct i2c_client *i2c = to_i2c_client(dev); 581 + struct iio_dev *indio_dev = i2c_get_clientdata(i2c); 582 + struct ak8974 *ak8974 = iio_priv(indio_dev); 583 + 584 + switch (reg) { 585 + case AK8974_CTRL1: 586 + case AK8974_CTRL2: 587 + case AK8974_CTRL3: 588 + case AK8974_INT_CTRL: 589 + case AK8974_INT_THRES: 590 + case AK8974_INT_THRES + 1: 591 + case AK8974_PRESET: 592 + case AK8974_PRESET + 1: 593 + return true; 594 + case AK8974_OFFSET_X: 595 + case AK8974_OFFSET_X + 1: 596 + case AK8974_OFFSET_Y: 597 + case AK8974_OFFSET_Y + 1: 598 + case AK8974_OFFSET_Z: 599 + case AK8974_OFFSET_Z + 1: 600 + if (ak8974->variant == AK8974_WHOAMI_VALUE_AK8974) 601 + return true; 602 + return false; 603 + case AMI305_OFFSET_X: 604 + case AMI305_OFFSET_X + 1: 605 + case AMI305_OFFSET_Y: 606 + case AMI305_OFFSET_Y + 1: 607 + case AMI305_OFFSET_Z: 608 + case AMI305_OFFSET_Z + 1: 609 + if (ak8974->variant == AK8974_WHOAMI_VALUE_AMI305) 610 + return true; 611 + return false; 612 + default: 613 + return false; 614 + } 615 + } 616 + 617 + static const struct regmap_config ak8974_regmap_config = { 618 + .reg_bits = 8, 619 + .val_bits = 8, 620 + .max_register = 0xff, 621 + .writeable_reg = ak8974_writeable_reg, 622 + }; 623 + 624 + static int ak8974_probe(struct i2c_client *i2c, 625 + const struct i2c_device_id *id) 626 + { 627 + struct iio_dev *indio_dev; 628 + struct ak8974 *ak8974; 629 + unsigned long irq_trig; 630 + int irq = i2c->irq; 631 + int ret; 632 + 633 + /* Register with IIO */ 634 + indio_dev = devm_iio_device_alloc(&i2c->dev, sizeof(*ak8974)); 635 + if (indio_dev == NULL) 636 + return -ENOMEM; 637 + 638 + ak8974 = iio_priv(indio_dev); 639 + i2c_set_clientdata(i2c, indio_dev); 640 + ak8974->i2c = i2c; 641 + mutex_init(&ak8974->lock); 642 + 643 + ret = of_iio_read_mount_matrix(&i2c->dev, 644 + "mount-matrix", 645 + &ak8974->orientation); 646 + if (ret) 647 + return ret; 648 + 649 + ak8974->regs[0].supply = ak8974_reg_avdd; 650 + ak8974->regs[1].supply = ak8974_reg_dvdd; 651 + 652 + ret = devm_regulator_bulk_get(&i2c->dev, 653 + ARRAY_SIZE(ak8974->regs), 654 + ak8974->regs); 655 + if (ret < 0) { 656 + dev_err(&i2c->dev, "cannot get regulators\n"); 657 + return ret; 658 + } 659 + 660 + ret = regulator_bulk_enable(ARRAY_SIZE(ak8974->regs), ak8974->regs); 661 + if (ret < 0) { 662 + dev_err(&i2c->dev, "cannot enable regulators\n"); 663 + return ret; 664 + } 665 + 666 + /* Take runtime PM online */ 667 + pm_runtime_get_noresume(&i2c->dev); 668 + pm_runtime_set_active(&i2c->dev); 669 + pm_runtime_enable(&i2c->dev); 670 + 671 + ak8974->map = devm_regmap_init_i2c(i2c, &ak8974_regmap_config); 672 + if (IS_ERR(ak8974->map)) { 673 + dev_err(&i2c->dev, "failed to allocate register map\n"); 674 + return PTR_ERR(ak8974->map); 675 + } 676 + 677 + ret = ak8974_set_power(ak8974, AK8974_PWR_ON); 678 + if (ret) { 679 + dev_err(&i2c->dev, "could not power on\n"); 680 + goto power_off; 681 + } 682 + 683 + ret = ak8974_detect(ak8974); 684 + if (ret) { 685 + dev_err(&i2c->dev, "neither AK8974 nor AMI305 found\n"); 686 + goto power_off; 687 + } 688 + 689 + ret = ak8974_selftest(ak8974); 690 + if (ret) 691 + dev_err(&i2c->dev, "selftest failed (continuing anyway)\n"); 692 + 693 + ret = ak8974_reset(ak8974); 694 + if (ret) { 695 + dev_err(&i2c->dev, "AK8974 reset failed\n"); 696 + goto power_off; 697 + } 698 + 699 + pm_runtime_set_autosuspend_delay(&i2c->dev, 700 + AK8974_AUTOSUSPEND_DELAY); 701 + pm_runtime_use_autosuspend(&i2c->dev); 702 + pm_runtime_put(&i2c->dev); 703 + 704 + indio_dev->dev.parent = &i2c->dev; 705 + indio_dev->channels = ak8974_channels; 706 + indio_dev->num_channels = ARRAY_SIZE(ak8974_channels); 707 + indio_dev->info = &ak8974_info; 708 + indio_dev->available_scan_masks = ak8974_scan_masks; 709 + indio_dev->modes = INDIO_DIRECT_MODE; 710 + indio_dev->name = ak8974->name; 711 + 712 + ret = iio_triggered_buffer_setup(indio_dev, NULL, 713 + ak8974_handle_trigger, 714 + NULL); 715 + if (ret) { 716 + dev_err(&i2c->dev, "triggered buffer setup failed\n"); 717 + goto disable_pm; 718 + } 719 + 720 + /* If we have a valid DRDY IRQ, make use of it */ 721 + if (irq > 0) { 722 + irq_trig = irqd_get_trigger_type(irq_get_irq_data(irq)); 723 + if (irq_trig == IRQF_TRIGGER_RISING) { 724 + dev_info(&i2c->dev, "enable rising edge DRDY IRQ\n"); 725 + } else if (irq_trig == IRQF_TRIGGER_FALLING) { 726 + ak8974->drdy_active_low = true; 727 + dev_info(&i2c->dev, "enable falling edge DRDY IRQ\n"); 728 + } else { 729 + irq_trig = IRQF_TRIGGER_RISING; 730 + } 731 + irq_trig |= IRQF_ONESHOT; 732 + irq_trig |= IRQF_SHARED; 733 + 734 + ret = devm_request_threaded_irq(&i2c->dev, 735 + irq, 736 + ak8974_drdy_irq, 737 + ak8974_drdy_irq_thread, 738 + irq_trig, 739 + ak8974->name, 740 + ak8974); 741 + if (ret) { 742 + dev_err(&i2c->dev, "unable to request DRDY IRQ " 743 + "- proceeding without IRQ\n"); 744 + goto no_irq; 745 + } 746 + ak8974->drdy_irq = true; 747 + } 748 + 749 + no_irq: 750 + ret = iio_device_register(indio_dev); 751 + if (ret) { 752 + dev_err(&i2c->dev, "device register failed\n"); 753 + goto cleanup_buffer; 754 + } 755 + 756 + return 0; 757 + 758 + cleanup_buffer: 759 + iio_triggered_buffer_cleanup(indio_dev); 760 + disable_pm: 761 + pm_runtime_put_noidle(&i2c->dev); 762 + pm_runtime_disable(&i2c->dev); 763 + ak8974_set_power(ak8974, AK8974_PWR_OFF); 764 + power_off: 765 + regulator_bulk_disable(ARRAY_SIZE(ak8974->regs), ak8974->regs); 766 + 767 + return ret; 768 + } 769 + 770 + static int __exit ak8974_remove(struct i2c_client *i2c) 771 + { 772 + struct iio_dev *indio_dev = i2c_get_clientdata(i2c); 773 + struct ak8974 *ak8974 = iio_priv(indio_dev); 774 + 775 + iio_device_unregister(indio_dev); 776 + iio_triggered_buffer_cleanup(indio_dev); 777 + pm_runtime_get_sync(&i2c->dev); 778 + pm_runtime_put_noidle(&i2c->dev); 779 + pm_runtime_disable(&i2c->dev); 780 + ak8974_set_power(ak8974, AK8974_PWR_OFF); 781 + regulator_bulk_disable(ARRAY_SIZE(ak8974->regs), ak8974->regs); 782 + 783 + return 0; 784 + } 785 + 786 + #ifdef CONFIG_PM 787 + static int ak8974_runtime_suspend(struct device *dev) 788 + { 789 + struct ak8974 *ak8974 = 790 + iio_priv(i2c_get_clientdata(to_i2c_client(dev))); 791 + 792 + ak8974_set_power(ak8974, AK8974_PWR_OFF); 793 + regulator_bulk_disable(ARRAY_SIZE(ak8974->regs), ak8974->regs); 794 + 795 + return 0; 796 + } 797 + 798 + static int ak8974_runtime_resume(struct device *dev) 799 + { 800 + struct ak8974 *ak8974 = 801 + iio_priv(i2c_get_clientdata(to_i2c_client(dev))); 802 + int ret; 803 + 804 + ret = regulator_bulk_enable(ARRAY_SIZE(ak8974->regs), ak8974->regs); 805 + if (ret) 806 + return ret; 807 + msleep(AK8974_POWERON_DELAY); 808 + ret = ak8974_set_power(ak8974, AK8974_PWR_ON); 809 + if (ret) 810 + goto out_regulator_disable; 811 + 812 + ret = ak8974_configure(ak8974); 813 + if (ret) 814 + goto out_disable_power; 815 + 816 + return 0; 817 + 818 + out_disable_power: 819 + ak8974_set_power(ak8974, AK8974_PWR_OFF); 820 + out_regulator_disable: 821 + regulator_bulk_disable(ARRAY_SIZE(ak8974->regs), ak8974->regs); 822 + 823 + return ret; 824 + } 825 + #endif /* CONFIG_PM */ 826 + 827 + static const struct dev_pm_ops ak8974_dev_pm_ops = { 828 + SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, 829 + pm_runtime_force_resume) 830 + SET_RUNTIME_PM_OPS(ak8974_runtime_suspend, 831 + ak8974_runtime_resume, NULL) 832 + }; 833 + 834 + static const struct i2c_device_id ak8974_id[] = { 835 + {"ami305", 0 }, 836 + {"ak8974", 0 }, 837 + {} 838 + }; 839 + MODULE_DEVICE_TABLE(i2c, ak8974_id); 840 + 841 + static const struct of_device_id ak8974_of_match[] = { 842 + { .compatible = "asahi-kasei,ak8974", }, 843 + {} 844 + }; 845 + MODULE_DEVICE_TABLE(of, ak8974_of_match); 846 + 847 + static struct i2c_driver ak8974_driver = { 848 + .driver = { 849 + .name = "ak8974", 850 + .owner = THIS_MODULE, 851 + .pm = &ak8974_dev_pm_ops, 852 + .of_match_table = of_match_ptr(ak8974_of_match), 853 + }, 854 + .probe = ak8974_probe, 855 + .remove = __exit_p(ak8974_remove), 856 + .id_table = ak8974_id, 857 + }; 858 + module_i2c_driver(ak8974_driver); 859 + 860 + MODULE_DESCRIPTION("AK8974 and AMI305 3-axis magnetometer driver"); 861 + MODULE_AUTHOR("Samu Onkalo"); 862 + MODULE_AUTHOR("Linus Walleij"); 863 + MODULE_LICENSE("GPL v2");
+15 -8
drivers/iio/magnetometer/mag3110.c
··· 154 154 155 155 switch (mask) { 156 156 case IIO_CHAN_INFO_RAW: 157 - if (iio_buffer_enabled(indio_dev)) 158 - return -EBUSY; 157 + ret = iio_device_claim_direct_mode(indio_dev); 158 + if (ret) 159 + return ret; 159 160 160 161 switch (chan->type) { 161 162 case IIO_MAGN: /* in 0.1 uT / LSB */ 162 163 ret = mag3110_read(data, buffer); 163 164 if (ret < 0) 164 - return ret; 165 + goto release; 165 166 *val = sign_extend32( 166 167 be16_to_cpu(buffer[chan->scan_index]), 15); 167 - return IIO_VAL_INT; 168 + ret = IIO_VAL_INT; 169 + break; 168 170 case IIO_TEMP: /* in 1 C / LSB */ 169 171 mutex_lock(&data->lock); 170 172 ret = mag3110_request(data); 171 173 if (ret < 0) { 172 174 mutex_unlock(&data->lock); 173 - return ret; 175 + goto release; 174 176 } 175 177 ret = i2c_smbus_read_byte_data(data->client, 176 178 MAG3110_DIE_TEMP); 177 179 mutex_unlock(&data->lock); 178 180 if (ret < 0) 179 - return ret; 181 + goto release; 180 182 *val = sign_extend32(ret, 7); 181 - return IIO_VAL_INT; 183 + ret = IIO_VAL_INT; 184 + break; 182 185 default: 183 - return -EINVAL; 186 + ret = -EINVAL; 184 187 } 188 + release: 189 + iio_device_release_direct_mode(indio_dev); 190 + return ret; 191 + 185 192 case IIO_CHAN_INFO_SCALE: 186 193 switch (chan->type) { 187 194 case IIO_MAGN:
+1 -1
drivers/iio/proximity/sx9500.c
··· 516 516 sx9500_push_events(indio_dev); 517 517 518 518 if (val & SX9500_CONVDONE_IRQ) 519 - complete_all(&data->completion); 519 + complete(&data->completion); 520 520 521 521 out: 522 522 mutex_unlock(&data->mutex);
+16
drivers/iio/temperature/Kconfig
··· 3 3 # 4 4 menu "Temperature sensors" 5 5 6 + config MAXIM_THERMOCOUPLE 7 + tristate "Maxim thermocouple sensors" 8 + depends on SPI 9 + select IIO_BUFFER 10 + select IIO_TRIGGERED_BUFFER 11 + help 12 + If you say yes here you get support for the Maxim series of 13 + thermocouple sensors connected via SPI. 14 + 15 + Supported sensors: 16 + * MAX6675 17 + * MAX31855 18 + 19 + This driver can also be built as a module. If so, the module will 20 + be called maxim_thermocouple. 21 + 6 22 config MLX90614 7 23 tristate "MLX90614 contact-less infrared sensor" 8 24 depends on I2C
+1
drivers/iio/temperature/Makefile
··· 2 2 # Makefile for industrial I/O temperature drivers 3 3 # 4 4 5 + obj-$(CONFIG_MAXIM_THERMOCOUPLE) += maxim_thermocouple.o 5 6 obj-$(CONFIG_MLX90614) += mlx90614.o 6 7 obj-$(CONFIG_TMP006) += tmp006.o 7 8 obj-$(CONFIG_TSYS01) += tsys01.o
+281
drivers/iio/temperature/maxim_thermocouple.c
··· 1 + /* 2 + * maxim_thermocouple.c - Support for Maxim thermocouple chips 3 + * 4 + * Copyright (C) 2016 Matt Ranostay <mranostay@gmail.com> 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 + 17 + #include <linux/module.h> 18 + #include <linux/init.h> 19 + #include <linux/mutex.h> 20 + #include <linux/err.h> 21 + #include <linux/spi/spi.h> 22 + #include <linux/iio/iio.h> 23 + #include <linux/iio/trigger.h> 24 + #include <linux/iio/buffer.h> 25 + #include <linux/iio/triggered_buffer.h> 26 + #include <linux/iio/trigger_consumer.h> 27 + 28 + #define MAXIM_THERMOCOUPLE_DRV_NAME "maxim_thermocouple" 29 + 30 + enum { 31 + MAX6675, 32 + MAX31855, 33 + }; 34 + 35 + const struct iio_chan_spec max6675_channels[] = { 36 + { /* thermocouple temperature */ 37 + .type = IIO_TEMP, 38 + .info_mask_separate = 39 + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), 40 + .scan_index = 0, 41 + .scan_type = { 42 + .sign = 's', 43 + .realbits = 13, 44 + .storagebits = 16, 45 + .shift = 3, 46 + .endianness = IIO_BE, 47 + }, 48 + }, 49 + IIO_CHAN_SOFT_TIMESTAMP(1), 50 + }; 51 + 52 + const struct iio_chan_spec max31855_channels[] = { 53 + { /* thermocouple temperature */ 54 + .type = IIO_TEMP, 55 + .address = 2, 56 + .info_mask_separate = 57 + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), 58 + .scan_index = 0, 59 + .scan_type = { 60 + .sign = 's', 61 + .realbits = 14, 62 + .storagebits = 16, 63 + .shift = 2, 64 + .endianness = IIO_BE, 65 + }, 66 + }, 67 + { /* cold junction temperature */ 68 + .type = IIO_TEMP, 69 + .address = 0, 70 + .channel2 = IIO_MOD_TEMP_AMBIENT, 71 + .modified = 1, 72 + .info_mask_separate = 73 + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), 74 + .scan_index = 1, 75 + .scan_type = { 76 + .sign = 's', 77 + .realbits = 12, 78 + .storagebits = 16, 79 + .shift = 4, 80 + .endianness = IIO_BE, 81 + }, 82 + }, 83 + IIO_CHAN_SOFT_TIMESTAMP(2), 84 + }; 85 + 86 + static const unsigned long max31855_scan_masks[] = {0x3, 0}; 87 + 88 + struct maxim_thermocouple_chip { 89 + const struct iio_chan_spec *channels; 90 + const unsigned long *scan_masks; 91 + u8 num_channels; 92 + u8 read_size; 93 + 94 + /* bit-check for valid input */ 95 + u32 status_bit; 96 + }; 97 + 98 + const struct maxim_thermocouple_chip maxim_thermocouple_chips[] = { 99 + [MAX6675] = { 100 + .channels = max6675_channels, 101 + .num_channels = ARRAY_SIZE(max6675_channels), 102 + .read_size = 2, 103 + .status_bit = BIT(2), 104 + }, 105 + [MAX31855] = { 106 + .channels = max31855_channels, 107 + .num_channels = ARRAY_SIZE(max31855_channels), 108 + .read_size = 4, 109 + .scan_masks = max31855_scan_masks, 110 + .status_bit = BIT(16), 111 + }, 112 + }; 113 + 114 + struct maxim_thermocouple_data { 115 + struct spi_device *spi; 116 + const struct maxim_thermocouple_chip *chip; 117 + 118 + u8 buffer[16] ____cacheline_aligned; 119 + }; 120 + 121 + static int maxim_thermocouple_read(struct maxim_thermocouple_data *data, 122 + struct iio_chan_spec const *chan, int *val) 123 + { 124 + unsigned int storage_bytes = data->chip->read_size; 125 + unsigned int shift = chan->scan_type.shift + (chan->address * 8); 126 + unsigned int buf; 127 + int ret; 128 + 129 + ret = spi_read(data->spi, (void *) &buf, storage_bytes); 130 + if (ret) 131 + return ret; 132 + 133 + switch (storage_bytes) { 134 + case 2: 135 + *val = be16_to_cpu(buf); 136 + break; 137 + case 4: 138 + *val = be32_to_cpu(buf); 139 + break; 140 + } 141 + 142 + /* check to be sure this is a valid reading */ 143 + if (*val & data->chip->status_bit) 144 + return -EINVAL; 145 + 146 + *val = sign_extend32(*val >> shift, chan->scan_type.realbits - 1); 147 + 148 + return 0; 149 + } 150 + 151 + static irqreturn_t maxim_thermocouple_trigger_handler(int irq, void *private) 152 + { 153 + struct iio_poll_func *pf = private; 154 + struct iio_dev *indio_dev = pf->indio_dev; 155 + struct maxim_thermocouple_data *data = iio_priv(indio_dev); 156 + int ret; 157 + 158 + ret = spi_read(data->spi, data->buffer, data->chip->read_size); 159 + if (!ret) { 160 + iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, 161 + iio_get_time_ns(indio_dev)); 162 + } 163 + 164 + iio_trigger_notify_done(indio_dev->trig); 165 + 166 + return IRQ_HANDLED; 167 + } 168 + 169 + static int maxim_thermocouple_read_raw(struct iio_dev *indio_dev, 170 + struct iio_chan_spec const *chan, 171 + int *val, int *val2, long mask) 172 + { 173 + struct maxim_thermocouple_data *data = iio_priv(indio_dev); 174 + int ret = -EINVAL; 175 + 176 + switch (mask) { 177 + case IIO_CHAN_INFO_RAW: 178 + ret = iio_device_claim_direct_mode(indio_dev); 179 + if (ret) 180 + return ret; 181 + 182 + ret = maxim_thermocouple_read(data, chan, val); 183 + iio_device_release_direct_mode(indio_dev); 184 + 185 + if (!ret) 186 + return IIO_VAL_INT; 187 + 188 + break; 189 + case IIO_CHAN_INFO_SCALE: 190 + switch (chan->channel2) { 191 + case IIO_MOD_TEMP_AMBIENT: 192 + *val = 62; 193 + *val2 = 500000; /* 1000 * 0.0625 */ 194 + ret = IIO_VAL_INT_PLUS_MICRO; 195 + break; 196 + default: 197 + *val = 250; /* 1000 * 0.25 */ 198 + ret = IIO_VAL_INT; 199 + }; 200 + break; 201 + } 202 + 203 + return ret; 204 + } 205 + 206 + static const struct iio_info maxim_thermocouple_info = { 207 + .driver_module = THIS_MODULE, 208 + .read_raw = maxim_thermocouple_read_raw, 209 + }; 210 + 211 + static int maxim_thermocouple_probe(struct spi_device *spi) 212 + { 213 + const struct spi_device_id *id = spi_get_device_id(spi); 214 + struct iio_dev *indio_dev; 215 + struct maxim_thermocouple_data *data; 216 + const struct maxim_thermocouple_chip *chip = 217 + &maxim_thermocouple_chips[id->driver_data]; 218 + int ret; 219 + 220 + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*data)); 221 + if (!indio_dev) 222 + return -ENOMEM; 223 + 224 + indio_dev->info = &maxim_thermocouple_info; 225 + indio_dev->name = MAXIM_THERMOCOUPLE_DRV_NAME; 226 + indio_dev->channels = chip->channels; 227 + indio_dev->available_scan_masks = chip->scan_masks; 228 + indio_dev->num_channels = chip->num_channels; 229 + indio_dev->modes = INDIO_DIRECT_MODE; 230 + 231 + data = iio_priv(indio_dev); 232 + data->spi = spi; 233 + data->chip = chip; 234 + 235 + ret = iio_triggered_buffer_setup(indio_dev, NULL, 236 + maxim_thermocouple_trigger_handler, NULL); 237 + if (ret) 238 + return ret; 239 + 240 + ret = iio_device_register(indio_dev); 241 + if (ret) 242 + goto error_unreg_buffer; 243 + 244 + return 0; 245 + 246 + error_unreg_buffer: 247 + iio_triggered_buffer_cleanup(indio_dev); 248 + 249 + return ret; 250 + } 251 + 252 + static int maxim_thermocouple_remove(struct spi_device *spi) 253 + { 254 + struct iio_dev *indio_dev = spi_get_drvdata(spi); 255 + 256 + iio_device_unregister(indio_dev); 257 + iio_triggered_buffer_cleanup(indio_dev); 258 + 259 + return 0; 260 + } 261 + 262 + static const struct spi_device_id maxim_thermocouple_id[] = { 263 + {"max6675", MAX6675}, 264 + {"max31855", MAX31855}, 265 + {}, 266 + }; 267 + MODULE_DEVICE_TABLE(spi, maxim_thermocouple_id); 268 + 269 + static struct spi_driver maxim_thermocouple_driver = { 270 + .driver = { 271 + .name = MAXIM_THERMOCOUPLE_DRV_NAME, 272 + }, 273 + .probe = maxim_thermocouple_probe, 274 + .remove = maxim_thermocouple_remove, 275 + .id_table = maxim_thermocouple_id, 276 + }; 277 + module_spi_driver(maxim_thermocouple_driver); 278 + 279 + MODULE_AUTHOR("Matt Ranostay <mranostay@gmail.com>"); 280 + MODULE_DESCRIPTION("Maxim thermocouple sensors"); 281 + MODULE_LICENSE("GPL");
+58 -76
drivers/staging/iio/light/isl29018.c
··· 32 32 #include <linux/iio/sysfs.h> 33 33 #include <linux/acpi.h> 34 34 35 - #define CONVERSION_TIME_MS 100 35 + #define ISL29018_CONV_TIME_MS 100 36 36 37 37 #define ISL29018_REG_ADD_COMMAND1 0x00 38 - #define COMMMAND1_OPMODE_SHIFT 5 39 - #define COMMMAND1_OPMODE_MASK (7 << COMMMAND1_OPMODE_SHIFT) 40 - #define COMMMAND1_OPMODE_POWER_DOWN 0 41 - #define COMMMAND1_OPMODE_ALS_ONCE 1 42 - #define COMMMAND1_OPMODE_IR_ONCE 2 43 - #define COMMMAND1_OPMODE_PROX_ONCE 3 38 + #define ISL29018_CMD1_OPMODE_SHIFT 5 39 + #define ISL29018_CMD1_OPMODE_MASK (7 << ISL29018_CMD1_OPMODE_SHIFT) 40 + #define ISL29018_CMD1_OPMODE_POWER_DOWN 0 41 + #define ISL29018_CMD1_OPMODE_ALS_ONCE 1 42 + #define ISL29018_CMD1_OPMODE_IR_ONCE 2 43 + #define ISL29018_CMD1_OPMODE_PROX_ONCE 3 44 44 45 - #define ISL29018_REG_ADD_COMMANDII 0x01 46 - #define COMMANDII_RESOLUTION_SHIFT 2 47 - #define COMMANDII_RESOLUTION_MASK (0x3 << COMMANDII_RESOLUTION_SHIFT) 45 + #define ISL29018_REG_ADD_COMMAND2 0x01 46 + #define ISL29018_CMD2_RESOLUTION_SHIFT 2 47 + #define ISL29018_CMD2_RESOLUTION_MASK (0x3 << ISL29018_CMD2_RESOLUTION_SHIFT) 48 48 49 - #define COMMANDII_RANGE_SHIFT 0 50 - #define COMMANDII_RANGE_MASK (0x3 << COMMANDII_RANGE_SHIFT) 49 + #define ISL29018_CMD2_RANGE_SHIFT 0 50 + #define ISL29018_CMD2_RANGE_MASK (0x3 << ISL29018_CMD2_RANGE_SHIFT) 51 51 52 - #define COMMANDII_SCHEME_SHIFT 7 53 - #define COMMANDII_SCHEME_MASK (0x1 << COMMANDII_SCHEME_SHIFT) 52 + #define ISL29018_CMD2_SCHEME_SHIFT 7 53 + #define ISL29018_CMD2_SCHEME_MASK (0x1 << ISL29018_CMD2_SCHEME_SHIFT) 54 54 55 55 #define ISL29018_REG_ADD_DATA_LSB 0x02 56 56 #define ISL29018_REG_ADD_DATA_MSB 0x03 ··· 127 127 if (i >= ARRAY_SIZE(isl29018_int_utimes[chip->type])) 128 128 return -EINVAL; 129 129 130 - ret = regmap_update_bits(chip->regmap, ISL29018_REG_ADD_COMMANDII, 131 - COMMANDII_RESOLUTION_MASK, 132 - i << COMMANDII_RESOLUTION_SHIFT); 130 + ret = regmap_update_bits(chip->regmap, ISL29018_REG_ADD_COMMAND2, 131 + ISL29018_CMD2_RESOLUTION_MASK, 132 + i << ISL29018_CMD2_RESOLUTION_SHIFT); 133 133 if (ret < 0) 134 134 return ret; 135 135 136 - /* keep the same range when integration time changes */ 136 + /* Keep the same range when integration time changes */ 137 137 int_time = chip->int_time; 138 138 for (i = 0; i < ARRAY_SIZE(isl29018_scales[int_time]); ++i) { 139 139 if (chip->scale.scale == isl29018_scales[int_time][i].scale && ··· 163 163 if (i >= ARRAY_SIZE(isl29018_scales[chip->int_time])) 164 164 return -EINVAL; 165 165 166 - ret = regmap_update_bits(chip->regmap, ISL29018_REG_ADD_COMMANDII, 167 - COMMANDII_RANGE_MASK, 168 - i << COMMANDII_RANGE_SHIFT); 166 + ret = regmap_update_bits(chip->regmap, ISL29018_REG_ADD_COMMAND2, 167 + ISL29018_CMD2_RANGE_MASK, 168 + i << ISL29018_CMD2_RANGE_SHIFT); 169 169 if (ret < 0) 170 170 return ret; 171 171 ··· 183 183 184 184 /* Set mode */ 185 185 status = regmap_write(chip->regmap, ISL29018_REG_ADD_COMMAND1, 186 - mode << COMMMAND1_OPMODE_SHIFT); 186 + mode << ISL29018_CMD1_OPMODE_SHIFT); 187 187 if (status) { 188 188 dev_err(dev, 189 189 "Error in setting operating mode err %d\n", status); 190 190 return status; 191 191 } 192 - msleep(CONVERSION_TIME_MS); 192 + msleep(ISL29018_CONV_TIME_MS); 193 193 status = regmap_read(chip->regmap, ISL29018_REG_ADD_DATA_LSB, &lsb); 194 194 if (status < 0) { 195 195 dev_err(dev, ··· 213 213 int lux_data; 214 214 unsigned int data_x_range; 215 215 216 - lux_data = isl29018_read_sensor_input(chip, COMMMAND1_OPMODE_ALS_ONCE); 217 - 216 + lux_data = isl29018_read_sensor_input(chip, 217 + ISL29018_CMD1_OPMODE_ALS_ONCE); 218 218 if (lux_data < 0) 219 219 return lux_data; 220 220 ··· 230 230 { 231 231 int ir_data; 232 232 233 - ir_data = isl29018_read_sensor_input(chip, COMMMAND1_OPMODE_IR_ONCE); 234 - 233 + ir_data = isl29018_read_sensor_input(chip, 234 + ISL29018_CMD1_OPMODE_IR_ONCE); 235 235 if (ir_data < 0) 236 236 return ir_data; 237 237 ··· 249 249 struct device *dev = regmap_get_device(chip->regmap); 250 250 251 251 /* Do proximity sensing with required scheme */ 252 - status = regmap_update_bits(chip->regmap, ISL29018_REG_ADD_COMMANDII, 253 - COMMANDII_SCHEME_MASK, 254 - scheme << COMMANDII_SCHEME_SHIFT); 252 + status = regmap_update_bits(chip->regmap, ISL29018_REG_ADD_COMMAND2, 253 + ISL29018_CMD2_SCHEME_MASK, 254 + scheme << ISL29018_CMD2_SCHEME_SHIFT); 255 255 if (status) { 256 256 dev_err(dev, "Error in setting operating mode\n"); 257 257 return status; 258 258 } 259 259 260 260 prox_data = isl29018_read_sensor_input(chip, 261 - COMMMAND1_OPMODE_PROX_ONCE); 261 + ISL29018_CMD1_OPMODE_PROX_ONCE); 262 262 if (prox_data < 0) 263 263 return prox_data; 264 264 ··· 267 267 return 0; 268 268 } 269 269 270 - ir_data = isl29018_read_sensor_input(chip, COMMMAND1_OPMODE_IR_ONCE); 271 - 270 + ir_data = isl29018_read_sensor_input(chip, 271 + ISL29018_CMD1_OPMODE_IR_ONCE); 272 272 if (ir_data < 0) 273 273 return ir_data; 274 274 ··· 280 280 return 0; 281 281 } 282 282 283 - static ssize_t show_scale_available(struct device *dev, 283 + static ssize_t isl29018_show_scale_available(struct device *dev, 284 284 struct device_attribute *attr, char *buf) 285 285 { 286 286 struct iio_dev *indio_dev = dev_to_iio_dev(dev); ··· 297 297 return len; 298 298 } 299 299 300 - static ssize_t show_int_time_available(struct device *dev, 300 + static ssize_t isl29018_show_int_time_available(struct device *dev, 301 301 struct device_attribute *attr, char *buf) 302 302 { 303 303 struct iio_dev *indio_dev = dev_to_iio_dev(dev); ··· 313 313 return len; 314 314 } 315 315 316 - /* proximity scheme */ 317 - static ssize_t show_prox_infrared_suppression(struct device *dev, 316 + static ssize_t isl29018_show_prox_infrared_suppression(struct device *dev, 318 317 struct device_attribute *attr, 319 318 char *buf) 320 319 { ··· 321 322 struct isl29018_chip *chip = iio_priv(indio_dev); 322 323 323 324 /* 324 - * return the "proximity scheme" i.e. if the chip does on chip 325 + * Return the "proximity scheme" i.e. if the chip does on chip 325 326 * infrared suppression (1 means perform on chip suppression) 326 327 */ 327 328 return sprintf(buf, "%d\n", chip->prox_scheme); 328 329 } 329 330 330 - static ssize_t store_prox_infrared_suppression(struct device *dev, 331 + static ssize_t isl29018_store_prox_infrared_suppression(struct device *dev, 331 332 struct device_attribute *attr, 332 333 const char *buf, size_t count) 333 334 { ··· 337 338 338 339 if (kstrtoint(buf, 10, &val)) 339 340 return -EINVAL; 340 - if (!(val == 0 || val == 1)) { 341 - dev_err(dev, "The mode is not supported\n"); 341 + if (!(val == 0 || val == 1)) 342 342 return -EINVAL; 343 - } 344 343 345 344 /* 346 - * get the "proximity scheme" i.e. if the chip does on chip 345 + * Get the "proximity scheme" i.e. if the chip does on chip 347 346 * infrared suppression (1 means perform on chip suppression) 348 347 */ 349 348 mutex_lock(&chip->lock); ··· 351 354 return count; 352 355 } 353 356 354 - /* Channel IO */ 355 357 static int isl29018_write_raw(struct iio_dev *indio_dev, 356 358 struct iio_chan_spec const *chan, 357 359 int val, ··· 487 491 }; 488 492 489 493 static IIO_DEVICE_ATTR(in_illuminance_integration_time_available, S_IRUGO, 490 - show_int_time_available, NULL, 0); 494 + isl29018_show_int_time_available, NULL, 0); 491 495 static IIO_DEVICE_ATTR(in_illuminance_scale_available, S_IRUGO, 492 - show_scale_available, NULL, 0); 496 + isl29018_show_scale_available, NULL, 0); 493 497 static IIO_DEVICE_ATTR(proximity_on_chip_ambient_infrared_suppression, 494 498 S_IRUGO | S_IWUSR, 495 - show_prox_infrared_suppression, 496 - store_prox_infrared_suppression, 0); 499 + isl29018_show_prox_infrared_suppression, 500 + isl29018_store_prox_infrared_suppression, 0); 497 501 498 502 #define ISL29018_DEV_ATTR(name) (&iio_dev_attr_##name.dev_attr.attr) 499 503 ··· 537 541 if (id != ISL29035_DEVICE_ID) 538 542 return -ENODEV; 539 543 540 - /* clear out brownout bit */ 544 + /* Clear brownout bit */ 541 545 return regmap_update_bits(chip->regmap, ISL29035_REG_DEVICE_ID, 542 546 ISL29035_BOUT_MASK, 0); 543 547 } ··· 570 574 * conversions, clear the test registers, and then rewrite all 571 575 * registers to the desired values. 572 576 * ... 573 - * FOR ISL29011, ISL29018, ISL29021, ISL29023 577 + * For ISL29011, ISL29018, ISL29021, ISL29023 574 578 * 1. Write 0x00 to register 0x08 (TEST) 575 579 * 2. Write 0x00 to register 0x00 (CMD1) 576 580 * 3. Rewrite all registers to the desired values ··· 599 603 600 604 usleep_range(1000, 2000); /* per data sheet, page 10 */ 601 605 602 - /* set defaults */ 606 + /* Set defaults */ 603 607 status = isl29018_set_scale(chip, chip->scale.scale, 604 608 chip->scale.uscale); 605 609 if (status < 0) { ··· 631 635 .write_raw = isl29018_write_raw, 632 636 }; 633 637 634 - static bool is_volatile_reg(struct device *dev, unsigned int reg) 638 + static bool isl29018_is_volatile_reg(struct device *dev, unsigned int reg) 635 639 { 636 640 switch (reg) { 637 641 case ISL29018_REG_ADD_DATA_LSB: ··· 645 649 } 646 650 } 647 651 648 - /* 649 - * isl29018_regmap_config: regmap configuration. 650 - * Use RBTREE mechanism for caching. 651 - */ 652 652 static const struct regmap_config isl29018_regmap_config = { 653 653 .reg_bits = 8, 654 654 .val_bits = 8, 655 - .volatile_reg = is_volatile_reg, 655 + .volatile_reg = isl29018_is_volatile_reg, 656 656 .max_register = ISL29018_REG_TEST, 657 657 .num_reg_defaults_raw = ISL29018_REG_TEST + 1, 658 658 .cache_type = REGCACHE_RBTREE, 659 659 }; 660 660 661 - /* isl29035_regmap_config: regmap configuration for ISL29035 */ 662 661 static const struct regmap_config isl29035_regmap_config = { 663 662 .reg_bits = 8, 664 663 .val_bits = 8, 665 - .volatile_reg = is_volatile_reg, 664 + .volatile_reg = isl29018_is_volatile_reg, 666 665 .max_register = ISL29035_REG_DEVICE_ID, 667 666 .num_reg_defaults_raw = ISL29035_REG_DEVICE_ID + 1, 668 667 .cache_type = REGCACHE_RBTREE, 669 668 }; 670 669 671 - struct chip_info { 670 + struct isl29018_chip_info { 672 671 const struct iio_chan_spec *channels; 673 672 int num_channels; 674 673 const struct iio_info *indio_info; 675 674 const struct regmap_config *regmap_cfg; 676 675 }; 677 676 678 - static const struct chip_info chip_info_tbl[] = { 677 + static const struct isl29018_chip_info isl29018_chip_info_tbl[] = { 679 678 [isl29018] = { 680 679 .channels = isl29018_channels, 681 680 .num_channels = ARRAY_SIZE(isl29018_channels), ··· 715 724 int dev_id = 0; 716 725 717 726 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip)); 718 - if (!indio_dev) { 719 - dev_err(&client->dev, "iio allocation fails\n"); 727 + if (!indio_dev) 720 728 return -ENOMEM; 721 - } 722 729 chip = iio_priv(indio_dev); 723 730 724 731 i2c_set_clientdata(client, indio_dev); ··· 739 750 chip->suspended = false; 740 751 741 752 chip->regmap = devm_regmap_init_i2c(client, 742 - chip_info_tbl[dev_id].regmap_cfg); 753 + isl29018_chip_info_tbl[dev_id].regmap_cfg); 743 754 if (IS_ERR(chip->regmap)) { 744 755 err = PTR_ERR(chip->regmap); 745 756 dev_err(&client->dev, "regmap initialization fails: %d\n", err); ··· 750 761 if (err) 751 762 return err; 752 763 753 - indio_dev->info = chip_info_tbl[dev_id].indio_info; 754 - indio_dev->channels = chip_info_tbl[dev_id].channels; 755 - indio_dev->num_channels = chip_info_tbl[dev_id].num_channels; 764 + indio_dev->info = isl29018_chip_info_tbl[dev_id].indio_info; 765 + indio_dev->channels = isl29018_chip_info_tbl[dev_id].channels; 766 + indio_dev->num_channels = isl29018_chip_info_tbl[dev_id].num_channels; 756 767 indio_dev->name = name; 757 768 indio_dev->dev.parent = &client->dev; 758 769 indio_dev->modes = INDIO_DIRECT_MODE; 759 - err = devm_iio_device_register(&client->dev, indio_dev); 760 - if (err) { 761 - dev_err(&client->dev, "iio registration fails\n"); 762 - return err; 763 - } 764 - 765 - return 0; 770 + return devm_iio_device_register(&client->dev, indio_dev); 766 771 } 767 772 768 773 #ifdef CONFIG_PM_SLEEP ··· 823 840 MODULE_DEVICE_TABLE(of, isl29018_of_match); 824 841 825 842 static struct i2c_driver isl29018_driver = { 826 - .class = I2C_CLASS_HWMON, 827 843 .driver = { 828 844 .name = "isl29018", 829 845 .acpi_match_table = ACPI_PTR(isl29018_acpi_match),
+51 -52
drivers/staging/iio/light/isl29028.c
··· 27 27 #include <linux/iio/iio.h> 28 28 #include <linux/iio/sysfs.h> 29 29 30 - #define CONVERSION_TIME_MS 100 30 + #define ISL29028_CONV_TIME_MS 100 31 31 32 32 #define ISL29028_REG_CONFIGURE 0x01 33 33 34 - #define CONFIGURE_ALS_IR_MODE_ALS 0 35 - #define CONFIGURE_ALS_IR_MODE_IR BIT(0) 36 - #define CONFIGURE_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 CONFIGURE_ALS_RANGE_LOW_LUX 0 39 - #define CONFIGURE_ALS_RANGE_HIGH_LUX BIT(1) 40 - #define CONFIGURE_ALS_RANGE_MASK BIT(1) 38 + #define ISL29028_CONF_ALS_RANGE_LOW_LUX 0 39 + #define ISL29028_CONF_ALS_RANGE_HIGH_LUX BIT(1) 40 + #define ISL29028_CONF_ALS_RANGE_MASK BIT(1) 41 41 42 - #define CONFIGURE_ALS_DIS 0 43 - #define CONFIGURE_ALS_EN BIT(2) 44 - #define CONFIGURE_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 CONFIGURE_PROX_DRIVE BIT(3) 46 + #define ISL29028_CONF_PROX_SLP_SH 4 47 + #define ISL29028_CONF_PROX_SLP_MASK (7 << ISL29028_CONF_PROX_SLP_SH) 47 48 48 - #define CONFIGURE_PROX_SLP_SH 4 49 - #define CONFIGURE_PROX_SLP_MASK (7 << CONFIGURE_PROX_SLP_SH) 50 - 51 - #define CONFIGURE_PROX_EN BIT(7) 52 - #define CONFIGURE_PROX_EN_MASK BIT(7) 49 + #define ISL29028_CONF_PROX_EN BIT(7) 50 + #define ISL29028_CONF_PROX_EN_MASK BIT(7) 53 51 54 52 #define ISL29028_REG_INTERRUPT 0x02 55 53 ··· 60 62 61 63 #define ISL29028_NUM_REGS (ISL29028_REG_TEST2_MODE + 1) 62 64 63 - enum als_ir_mode { 64 - MODE_NONE = 0, 65 - MODE_ALS, 66 - MODE_IR 65 + enum isl29028_als_ir_mode { 66 + ISL29028_MODE_NONE = 0, 67 + ISL29028_MODE_ALS, 68 + ISL29028_MODE_IR, 67 69 }; 68 70 69 71 struct isl29028_chip { ··· 74 76 bool enable_prox; 75 77 76 78 int lux_scale; 77 - int als_ir_mode; 79 + enum isl29028_als_ir_mode als_ir_mode; 78 80 }; 79 81 80 82 static int isl29028_set_proxim_sampling(struct isl29028_chip *chip, ··· 89 91 break; 90 92 } 91 93 return regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, 92 - CONFIGURE_PROX_SLP_MASK, sel << CONFIGURE_PROX_SLP_SH); 94 + ISL29028_CONF_PROX_SLP_MASK, 95 + sel << ISL29028_CONF_PROX_SLP_SH); 93 96 } 94 97 95 98 static int isl29028_enable_proximity(struct isl29028_chip *chip, bool enable) ··· 99 100 int val = 0; 100 101 101 102 if (enable) 102 - val = CONFIGURE_PROX_EN; 103 + val = ISL29028_CONF_PROX_EN; 103 104 ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, 104 - CONFIGURE_PROX_EN_MASK, val); 105 + ISL29028_CONF_PROX_EN_MASK, val); 105 106 if (ret < 0) 106 107 return ret; 107 108 ··· 112 113 113 114 static int isl29028_set_als_scale(struct isl29028_chip *chip, int lux_scale) 114 115 { 115 - int val = (lux_scale == 2000) ? CONFIGURE_ALS_RANGE_HIGH_LUX : 116 - CONFIGURE_ALS_RANGE_LOW_LUX; 116 + int val = (lux_scale == 2000) ? ISL29028_CONF_ALS_RANGE_HIGH_LUX : 117 + ISL29028_CONF_ALS_RANGE_LOW_LUX; 117 118 118 119 return regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, 119 - CONFIGURE_ALS_RANGE_MASK, val); 120 + ISL29028_CONF_ALS_RANGE_MASK, val); 120 121 } 121 122 122 123 static int isl29028_set_als_ir_mode(struct isl29028_chip *chip, 123 - enum als_ir_mode mode) 124 + enum isl29028_als_ir_mode mode) 124 125 { 125 126 int ret = 0; 126 127 127 128 switch (mode) { 128 - case MODE_ALS: 129 + case ISL29028_MODE_ALS: 129 130 ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, 130 - CONFIGURE_ALS_IR_MODE_MASK, 131 - CONFIGURE_ALS_IR_MODE_ALS); 131 + ISL29028_CONF_ALS_IR_MODE_MASK, 132 + ISL29028_CONF_ALS_IR_MODE_ALS); 132 133 if (ret < 0) 133 134 return ret; 134 135 135 136 ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, 136 - CONFIGURE_ALS_RANGE_MASK, 137 - CONFIGURE_ALS_RANGE_HIGH_LUX); 137 + ISL29028_CONF_ALS_RANGE_MASK, 138 + ISL29028_CONF_ALS_RANGE_HIGH_LUX); 138 139 break; 139 140 140 - case MODE_IR: 141 + case ISL29028_MODE_IR: 141 142 ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, 142 - CONFIGURE_ALS_IR_MODE_MASK, 143 - CONFIGURE_ALS_IR_MODE_IR); 143 + ISL29028_CONF_ALS_IR_MODE_MASK, 144 + ISL29028_CONF_ALS_IR_MODE_IR); 144 145 break; 145 146 146 - case MODE_NONE: 147 + case ISL29028_MODE_NONE: 147 148 return regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, 148 - CONFIGURE_ALS_EN_MASK, CONFIGURE_ALS_DIS); 149 + ISL29028_CONF_ALS_EN_MASK, ISL29028_CONF_ALS_DIS); 149 150 } 150 151 151 152 if (ret < 0) ··· 153 154 154 155 /* Enable the ALS/IR */ 155 156 ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, 156 - CONFIGURE_ALS_EN_MASK, CONFIGURE_ALS_EN); 157 + ISL29028_CONF_ALS_EN_MASK, 158 + ISL29028_CONF_ALS_EN); 157 159 if (ret < 0) 158 160 return ret; 159 161 160 162 /* Need to wait for conversion time if ALS/IR mode enabled */ 161 - mdelay(CONVERSION_TIME_MS); 163 + mdelay(ISL29028_CONV_TIME_MS); 162 164 return 0; 163 165 } 164 166 ··· 223 223 int ret; 224 224 int als_ir_data; 225 225 226 - if (chip->als_ir_mode != MODE_ALS) { 227 - ret = isl29028_set_als_ir_mode(chip, MODE_ALS); 226 + if (chip->als_ir_mode != ISL29028_MODE_ALS) { 227 + ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_ALS); 228 228 if (ret < 0) { 229 229 dev_err(dev, 230 230 "Error in enabling ALS mode err %d\n", ret); 231 231 return ret; 232 232 } 233 - chip->als_ir_mode = MODE_ALS; 233 + chip->als_ir_mode = ISL29028_MODE_ALS; 234 234 } 235 235 236 236 ret = isl29028_read_als_ir(chip, &als_ir_data); ··· 256 256 struct device *dev = regmap_get_device(chip->regmap); 257 257 int ret; 258 258 259 - if (chip->als_ir_mode != MODE_IR) { 260 - ret = isl29028_set_als_ir_mode(chip, MODE_IR); 259 + if (chip->als_ir_mode != ISL29028_MODE_IR) { 260 + ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_IR); 261 261 if (ret < 0) { 262 262 dev_err(dev, 263 263 "Error in enabling IR mode err %d\n", ret); 264 264 return ret; 265 265 } 266 - chip->als_ir_mode = MODE_IR; 266 + chip->als_ir_mode = ISL29028_MODE_IR; 267 267 } 268 268 return isl29028_read_als_ir(chip, ir_data); 269 269 } ··· 383 383 } 384 384 385 385 static IIO_CONST_ATTR(in_proximity_sampling_frequency_available, 386 - "1, 3, 5, 10, 13, 20, 83, 100"); 387 - static IIO_CONST_ATTR(in_illuminance_scale_available, "125, 2000"); 386 + "1 3 5 10 13 20 83 100"); 387 + static IIO_CONST_ATTR(in_illuminance_scale_available, "125 2000"); 388 388 389 389 #define ISL29028_DEV_ATTR(name) (&iio_dev_attr_##name.dev_attr.attr) 390 390 #define ISL29028_CONST_ATTR(name) (&iio_const_attr_##name.dev_attr.attr) ··· 428 428 chip->enable_prox = false; 429 429 chip->prox_sampling = 20; 430 430 chip->lux_scale = 2000; 431 - chip->als_ir_mode = MODE_NONE; 431 + chip->als_ir_mode = ISL29028_MODE_NONE; 432 432 433 433 ret = regmap_write(chip->regmap, ISL29028_REG_TEST1_MODE, 0x0); 434 434 if (ret < 0) { ··· 462 462 return ret; 463 463 } 464 464 465 - static bool is_volatile_reg(struct device *dev, unsigned int reg) 465 + static bool isl29028_is_volatile_reg(struct device *dev, unsigned int reg) 466 466 { 467 467 switch (reg) { 468 468 case ISL29028_REG_INTERRUPT: ··· 478 478 static const struct regmap_config isl29028_regmap_config = { 479 479 .reg_bits = 8, 480 480 .val_bits = 8, 481 - .volatile_reg = is_volatile_reg, 481 + .volatile_reg = isl29028_is_volatile_reg, 482 482 .max_register = ISL29028_NUM_REGS - 1, 483 483 .num_reg_defaults_raw = ISL29028_NUM_REGS, 484 484 .cache_type = REGCACHE_RBTREE, ··· 546 546 MODULE_DEVICE_TABLE(of, isl29028_of_match); 547 547 548 548 static struct i2c_driver isl29028_driver = { 549 - .class = I2C_CLASS_HWMON, 550 549 .driver = { 551 550 .name = "isl29028", 552 551 .of_match_table = isl29028_of_match,
+20 -20
drivers/staging/iio/meter/ade7854.c
··· 23 23 #include "ade7854.h" 24 24 25 25 static ssize_t ade7854_read_8bit(struct device *dev, 26 - struct device_attribute *attr, 27 - char *buf) 26 + struct device_attribute *attr, 27 + char *buf) 28 28 { 29 29 int ret; 30 30 u8 val = 0; ··· 40 40 } 41 41 42 42 static ssize_t ade7854_read_16bit(struct device *dev, 43 - struct device_attribute *attr, 44 - char *buf) 43 + struct device_attribute *attr, 44 + char *buf) 45 45 { 46 46 int ret; 47 47 u16 val = 0; ··· 57 57 } 58 58 59 59 static ssize_t ade7854_read_24bit(struct device *dev, 60 - struct device_attribute *attr, 61 - char *buf) 60 + struct device_attribute *attr, 61 + char *buf) 62 62 { 63 63 int ret; 64 64 u32 val; ··· 74 74 } 75 75 76 76 static ssize_t ade7854_read_32bit(struct device *dev, 77 - struct device_attribute *attr, 78 - char *buf) 77 + struct device_attribute *attr, 78 + char *buf) 79 79 { 80 80 int ret; 81 81 u32 val = 0; ··· 91 91 } 92 92 93 93 static ssize_t ade7854_write_8bit(struct device *dev, 94 - struct device_attribute *attr, 95 - const char *buf, 96 - size_t len) 94 + struct device_attribute *attr, 95 + const char *buf, 96 + size_t len) 97 97 { 98 98 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 99 99 struct iio_dev *indio_dev = dev_to_iio_dev(dev); ··· 112 112 } 113 113 114 114 static ssize_t ade7854_write_16bit(struct device *dev, 115 - struct device_attribute *attr, 116 - const char *buf, 117 - size_t len) 115 + struct device_attribute *attr, 116 + const char *buf, 117 + size_t len) 118 118 { 119 119 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 120 120 struct iio_dev *indio_dev = dev_to_iio_dev(dev); ··· 133 133 } 134 134 135 135 static ssize_t ade7854_write_24bit(struct device *dev, 136 - struct device_attribute *attr, 137 - const char *buf, 138 - size_t len) 136 + struct device_attribute *attr, 137 + const char *buf, 138 + size_t len) 139 139 { 140 140 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 141 141 struct iio_dev *indio_dev = dev_to_iio_dev(dev); ··· 154 154 } 155 155 156 156 static ssize_t ade7854_write_32bit(struct device *dev, 157 - struct device_attribute *attr, 158 - const char *buf, 159 - size_t len) 157 + struct device_attribute *attr, 158 + const char *buf, 159 + size_t len) 160 160 { 161 161 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 162 162 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
+1
include/linux/hid-sensor-hub.h
··· 236 236 struct hid_sensor_hub_attribute_info report_state; 237 237 struct hid_sensor_hub_attribute_info power_state; 238 238 struct hid_sensor_hub_attribute_info sensitivity; 239 + struct work_struct work; 239 240 }; 240 241 241 242 /* Convert from hid unit expo to regular exponent */
+12
include/linux/iio/consumer.h
··· 165 165 *iio_channel_cb_get_channels(const struct iio_cb_buffer *cb_buffer); 166 166 167 167 /** 168 + * iio_channel_cb_get_iio_dev() - get access to the underlying device. 169 + * @cb_buffer: The callback buffer from whom we want the device 170 + * information. 171 + * 172 + * This function allows one to obtain information about the device. 173 + * The primary aim is to allow drivers that are consuming a device to query 174 + * things like current trigger. 175 + */ 176 + struct iio_dev 177 + *iio_channel_cb_get_iio_dev(const struct iio_cb_buffer *cb_buffer); 178 + 179 + /** 168 180 * iio_read_channel_raw() - read from a given channel 169 181 * @chan: The channel being queried. 170 182 * @val: Value read back.
+2 -1
tools/iio/lsiio.c
··· 51 51 52 52 while (ent = readdir(dp), ent) 53 53 if (check_prefix(ent->d_name, "in_") && 54 - check_postfix(ent->d_name, "_raw")) 54 + (check_postfix(ent->d_name, "_raw") || 55 + check_postfix(ent->d_name, "_input"))) 55 56 printf(" %-10s\n", ent->d_name); 56 57 57 58 return (closedir(dp) == -1) ? -errno : 0;