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

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

Jonathan writes:

First set of IIO new device support, features and cleanup for the 4.12 cycle.

Quite a bit of outreachy activity here with a driver from a current intern
and a number of cleanup patches as part of the next round.

Getting a pull request in early this cycle as it's looking like another large
cycle for IIO.

New device support
* adxl345
- initial device support. Note, once complete support is done the intent
is to superceded the driver in input/misc.
- bindings.
- conversion from i2c direct calls to regmap and driver split.
- spi support.
* chromeos light and proximity.
- new driver.
* devantech srf04 ultrasonic ranger
- new driver with device tree bindings.
* hid temperature
- new driver for environemntal temperature support from hid devices.
* max30102 oximeter
- new driver with device tree bindings.
* st lsm6dsx
- refactor and addition of device support for lsm6dsl and lsm6ds3h.

Staging graduation
* isl29028 including copyright notice update to reflect Brian's work.
* lpc32xx_adc.
* spear adc. It's not perfect and there are some datasheet disagreements, but
it works and is good enough to graduate.

New features
* documentation
- abi docs for in_proximity_sampling_frequency_available.
- generalise counting direction ABI docs as a second driver is going to
use them.
* hid-sensor-prox
- Add support for HID_USAGE_SENSOR_HUMAN_PRESENCE if used on a particular
device.
* isl29028
- runtime pm.
* meson-saradc
- switch from polling to interrupt mode and improved read_raw_sample function
to avoid unnecessary loop.
* tmp007
- interrupt and threshold event support.

Cleanups and minor fixes
* ad2s1210
- permissions to octal.
* ad7192
- permissions to octal.
- use BIT macro.
* ad9832
- merge header definitions into source file.
* ad9834
- merge header definitions into source file.
* ade7753
- merge header definitions into source file.
- cleanup include ordering.
* ade7854
- simplify return logic.
* adis16201
- merge header definitions into source file.
- rename _core.c to .c as there is nothing else.
* adis16203
- merge header definitions into source file.
- rename _core.c to .c as there is nothing else.
* adis16209
- merge header definitions into source file.
- rename _core.c to .c as there is nothing else.
* adis16240
- permissions to octal.
- merge header definitions into source file.
- rename _core.c to .c as there is nothing else.
* adt7136
- permissions to octal.
* cio-dac
- set missing parent device.
* documentation
- update version numbers on sysfs ABI for counter bits that didn't quite.
make 4.9.
* isl29028
- mdelay to msleep.
- incorrrect sleep time when taking first proximity reading.
* lmp91000
- set missing parent device.
* lpc32xx
- Consistent prefixes for defines.
- rename local state structure to _state.
* max30100
- set missing parent device.
* max30102
- set missing parent device.
* maxim-thermocouple
- set missing parent device.
* meter driver header
- permissions to octal.
* pulsedlight-lidar-lite-v2
- set missing parent device.
* quad-8
- set missing parent device.
* st104
- set missing parent device.

Other
* Mailmap
- update Matt Ranostay's email address to the Konsolko one.

+3400 -1125
+1
.mailmap
··· 109 109 Mauro Carvalho Chehab <mchehab@kernel.org> <mchehab@s-opensource.com> 110 110 Matt Ranostay <mranostay@gmail.com> Matthew Ranostay <mranostay@embeddedalley.com> 111 111 Matt Ranostay <mranostay@gmail.com> <matt.ranostay@intel.com> 112 + Matt Ranostay <matt.ranostay@konsulko.com> <matt@ranostay.consulting> 112 113 Mayuresh Janorkar <mayur@ti.com> 113 114 Michael Buesch <m@bues.ch> 114 115 Michel Dänzer <michel@tungstengraphics.com>
+17 -2
Documentation/ABI/testing/sysfs-bus-iio
··· 55 55 then it is to be found in the base device directory. 56 56 57 57 What: /sys/bus/iio/devices/iio:deviceX/sampling_frequency_available 58 + What: /sys/bus/iio/devices/iio:deviceX/in_proximity_sampling_frequency_available 58 59 What: /sys/.../iio:deviceX/buffer/sampling_frequency_available 59 60 What: /sys/bus/iio/devices/triggerX/sampling_frequency_available 60 61 KernelVersion: 2.6.35 ··· 1594 1593 can be processed to siemens per meter. 1595 1594 1596 1595 What: /sys/bus/iio/devices/iio:deviceX/in_countY_raw 1597 - KernelVersion: 4.9 1596 + KernelVersion: 4.10 1598 1597 Contact: linux-iio@vger.kernel.org 1599 1598 Description: 1600 1599 Raw counter device counts from channel Y. For quadrature ··· 1602 1601 the counts of a single quadrature signal phase from channel Y. 1603 1602 1604 1603 What: /sys/bus/iio/devices/iio:deviceX/in_indexY_raw 1605 - KernelVersion: 4.9 1604 + KernelVersion: 4.10 1606 1605 Contact: linux-iio@vger.kernel.org 1607 1606 Description: 1608 1607 Raw counter device index value from channel Y. This attribute 1609 1608 provides an absolute positional reference (e.g. a pulse once per 1610 1609 revolution) which may be used to home positional systems as 1611 1610 required. 1611 + 1612 + What: /sys/bus/iio/devices/iio:deviceX/in_count_count_direction_available 1613 + KernelVersion: 4.12 1614 + Contact: linux-iio@vger.kernel.org 1615 + Description: 1616 + A list of possible counting directions which are: 1617 + - "up" : counter device is increasing. 1618 + - "down": counter device is decreasing. 1619 + 1620 + What: /sys/bus/iio/devices/iio:deviceX/in_countY_count_direction 1621 + KernelVersion: 4.12 1622 + Contact: linux-iio@vger.kernel.org 1623 + Description: 1624 + Raw counter device counters direction for channel Y.
+8 -16
Documentation/ABI/testing/sysfs-bus-iio-counter-104-quad-8
··· 1 - What: /sys/bus/iio/devices/iio:deviceX/in_count_count_direction_available 2 1 What: /sys/bus/iio/devices/iio:deviceX/in_count_count_mode_available 3 2 What: /sys/bus/iio/devices/iio:deviceX/in_count_noise_error_available 4 3 What: /sys/bus/iio/devices/iio:deviceX/in_count_quadrature_mode_available 5 4 What: /sys/bus/iio/devices/iio:deviceX/in_index_index_polarity_available 6 5 What: /sys/bus/iio/devices/iio:deviceX/in_index_synchronous_mode_available 7 - KernelVersion: 4.9 6 + KernelVersion: 4.10 8 7 Contact: linux-iio@vger.kernel.org 9 8 Description: 10 9 Discrete set of available values for the respective counter 11 10 configuration are listed in this file. 12 11 13 - What: /sys/bus/iio/devices/iio:deviceX/in_countY_count_direction 14 - KernelVersion: 4.9 15 - Contact: linux-iio@vger.kernel.org 16 - Description: 17 - Read-only attribute that indicates whether the counter for 18 - channel Y is counting up or down. 19 - 20 12 What: /sys/bus/iio/devices/iio:deviceX/in_countY_count_mode 21 - KernelVersion: 4.9 13 + KernelVersion: 4.10 22 14 Contact: linux-iio@vger.kernel.org 23 15 Description: 24 16 Count mode for channel Y. Four count modes are available: ··· 44 52 continuously throughout. 45 53 46 54 What: /sys/bus/iio/devices/iio:deviceX/in_countY_noise_error 47 - KernelVersion: 4.9 55 + KernelVersion: 4.10 48 56 Contact: linux-iio@vger.kernel.org 49 57 Description: 50 58 Read-only attribute that indicates whether excessive noise is ··· 52 60 irrelevant in non-quadrature clock mode. 53 61 54 62 What: /sys/bus/iio/devices/iio:deviceX/in_countY_preset 55 - KernelVersion: 4.9 63 + KernelVersion: 4.10 56 64 Contact: linux-iio@vger.kernel.org 57 65 Description: 58 66 If the counter device supports preset registers, the preset 59 67 count for channel Y is provided by this attribute. 60 68 61 69 What: /sys/bus/iio/devices/iio:deviceX/in_countY_quadrature_mode 62 - KernelVersion: 4.9 70 + KernelVersion: 4.10 63 71 Contact: linux-iio@vger.kernel.org 64 72 Description: 65 73 Configure channel Y counter for non-quadrature or quadrature ··· 80 88 decoded for UP/DN clock. 81 89 82 90 What: /sys/bus/iio/devices/iio:deviceX/in_countY_set_to_preset_on_index 83 - KernelVersion: 4.9 91 + KernelVersion: 4.10 84 92 Contact: linux-iio@vger.kernel.org 85 93 Description: 86 94 Whether to set channel Y counter with channel Y preset value ··· 88 96 Valid attribute values are boolean. 89 97 90 98 What: /sys/bus/iio/devices/iio:deviceX/in_indexY_index_polarity 91 - KernelVersion: 4.9 99 + KernelVersion: 4.10 92 100 Contact: linux-iio@vger.kernel.org 93 101 Description: 94 102 Active level of channel Y index input; irrelevant in 95 103 non-synchronous load mode. 96 104 97 105 What: /sys/bus/iio/devices/iio:deviceX/in_indexY_synchronous_mode 98 - KernelVersion: 4.9 106 + KernelVersion: 4.10 99 107 Contact: linux-iio@vger.kernel.org 100 108 Description: 101 109 Configure channel Y counter for non-synchronous or synchronous
+38
Documentation/devicetree/bindings/iio/accel/adxl345.txt
··· 1 + Analog Devices ADXL345 3-Axis, +/-(2g/4g/8g/16g) Digital Accelerometer 2 + 3 + http://www.analog.com/en/products/mems/accelerometers/adxl345.html 4 + 5 + Required properties: 6 + - compatible : should be "adi,adxl345" 7 + - reg : the I2C address or SPI chip select number of the sensor 8 + 9 + Required properties for SPI bus usage: 10 + - spi-max-frequency : set maximum clock frequency, must be 5000000 11 + - spi-cpol and spi-cpha : must be defined for adxl345 to enable SPI mode 3 12 + 13 + Optional properties: 14 + - interrupt-parent : phandle to the parent interrupt controller as documented 15 + in Documentation/devicetree/bindings/interrupt-controller/interrupts.txt 16 + - interrupts: interrupt mapping for IRQ as documented in 17 + Documentation/devicetree/bindings/interrupt-controller/interrupts.txt 18 + 19 + Example for a I2C device node: 20 + 21 + accelerometer@2a { 22 + compatible = "adi,adxl345"; 23 + reg = <0x53>; 24 + interrupt-parent = <&gpio1>; 25 + interrupts = <0 IRQ_TYPE_LEVEL_HIGH>; 26 + }; 27 + 28 + Example for a SPI device node: 29 + 30 + accelerometer@0 { 31 + compatible = "adi,adxl345"; 32 + reg = <0>; 33 + spi-max-frequency = <5000000>; 34 + spi-cpol; 35 + spi-cpha; 36 + interrupt-parent = <&gpio1>; 37 + interrupts = <0 IRQ_TYPE_LEVEL_HIGH>; 38 + };
+2
Documentation/devicetree/bindings/iio/adc/amlogic,meson-saradc.txt
··· 7 7 - "amlogic,meson-gxm-saradc" for GXM 8 8 along with the generic "amlogic,meson-saradc" 9 9 - reg: the physical base address and length of the registers 10 + - interrupts: the interrupt indicating end of sampling 10 11 - clocks: phandle and clock identifier (see clock-names) 11 12 - clock-names: mandatory clocks: 12 13 - "clkin" for the reference clock (typically XTAL) ··· 24 23 compatible = "amlogic,meson-gxl-saradc", "amlogic,meson-saradc"; 25 24 #io-channel-cells = <1>; 26 25 reg = <0x0 0x8680 0x0 0x34>; 26 + interrupts = <GIC_SPI 73 IRQ_TYPE_EDGE_RISING>; 27 27 clocks = <&xtal>, 28 28 <&clkc CLKID_SAR_ADC>, 29 29 <&clkc CLKID_SANA>,
+30
Documentation/devicetree/bindings/iio/health/max30102.txt
··· 1 + Maxim MAX30102 heart rate and pulse oximeter sensor 2 + 3 + * https://datasheets.maximintegrated.com/en/ds/MAX30102.pdf 4 + 5 + Required properties: 6 + - compatible: must be "maxim,max30102" 7 + - reg: the I2C address of the sensor 8 + - interrupt-parent: should be the phandle for the interrupt controller 9 + - interrupts: the sole interrupt generated by the device 10 + 11 + Refer to interrupt-controller/interrupts.txt for generic 12 + interrupt client node bindings. 13 + 14 + Optional properties: 15 + - maxim,red-led-current-microamp: configuration for RED LED current 16 + - maxim,ir-led-current-microamp: configuration for IR LED current 17 + 18 + Note that each step is approximately 200 microamps, ranging from 0 uA to 19 + 50800 uA. 20 + 21 + Example: 22 + 23 + max30100@57 { 24 + compatible = "maxim,max30102"; 25 + reg = <0x57>; 26 + maxim,red-led-current-microamp = <7000>; 27 + maxim,ir-led-current-microamp = <7000>; 28 + interrupt-parent = <&gpio1>; 29 + interrupts = <16 2>; 30 + };
+2
Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt
··· 3 3 Required properties: 4 4 - compatible: must be one of: 5 5 "st,lsm6ds3" 6 + "st,lsm6ds3h" 7 + "st,lsm6dsl" 6 8 "st,lsm6dsm" 7 9 - reg: i2c address of the sensor / spi cs line 8 10
+28
Documentation/devicetree/bindings/iio/proximity/devantech-srf04.txt
··· 1 + * Devantech SRF04 ultrasonic range finder 2 + Bit-banging driver using two GPIOs 3 + 4 + Required properties: 5 + - compatible: Should be "devantech,srf04" 6 + 7 + - trig-gpios: Definition of the GPIO for the triggering (output) 8 + This GPIO is set for about 10 us by the driver to tell the 9 + device it should initiate the measurement cycle. 10 + 11 + - echo-gpios: Definition of the GPIO for the echo (input) 12 + This GPIO is set by the device as soon as an ultrasonic 13 + burst is sent out and reset when the first echo is 14 + received. 15 + Thus this GPIO is set while the ultrasonic waves are doing 16 + one round trip. 17 + It needs to be an GPIO which is able to deliver an 18 + interrupt because the time between two interrupts is 19 + measured in the driver. 20 + See Documentation/devicetree/bindings/gpio/gpio.txt for 21 + information on how to specify a consumer gpio. 22 + 23 + Example: 24 + srf04@0 { 25 + compatible = "devantech,srf04"; 26 + trig-gpios = <&gpio1 15 GPIO_ACTIVE_HIGH>; 27 + echo-gpios = <&gpio2 6 GPIO_ACTIVE_HIGH>; 28 + };
+6
MAINTAINERS
··· 3853 3853 S: Maintained 3854 3854 F: drivers/usb/dwc3/ 3855 3855 3856 + DEVANTECH SRF ULTRASONIC RANGER IIO DRIVER 3857 + M: Andreas Klinger <ak@it-klinger.de> 3858 + L: linux-iio@vger.kernel.org 3859 + S: Maintained 3860 + F: drivers/iio/proximity/srf*.c 3861 + 3856 3862 DEVICE COREDUMP (DEV_COREDUMP) 3857 3863 M: Johannes Berg <johannes@sipsolutions.net> 3858 3864 L: linux-kernel@vger.kernel.org
+31
drivers/iio/accel/Kconfig
··· 5 5 6 6 menu "Accelerometers" 7 7 8 + config ADXL345 9 + tristate 10 + 11 + config ADXL345_I2C 12 + tristate "Analog Devices ADXL345 3-Axis Digital Accelerometer I2C Driver" 13 + depends on INPUT_ADXL34X=n 14 + depends on I2C 15 + select ADXL345 16 + select REGMAP_I2C 17 + help 18 + Say Y here if you want to build support for the Analog Devices 19 + ADXL345 3-axis digital accelerometer. 20 + 21 + To compile this driver as a module, choose M here: the module 22 + will be called adxl345_i2c and you will also get adxl345_core 23 + for the core module. 24 + 25 + config ADXL345_SPI 26 + tristate "Analog Devices ADXL345 3-Axis Digital Accelerometer SPI Driver" 27 + depends on INPUT_ADXL34X=n 28 + depends on SPI 29 + select ADXL345 30 + select REGMAP_SPI 31 + help 32 + Say Y here if you want to build support for the Analog Devices 33 + ADXL345 3-axis digital accelerometer. 34 + 35 + To compile this driver as a module, choose M here: the module 36 + will be called adxl345_spi and you will also get adxl345_core 37 + for the core module. 38 + 8 39 config BMA180 9 40 tristate "Bosch BMA180/BMA250 3-Axis Accelerometer Driver" 10 41 depends on I2C
+3
drivers/iio/accel/Makefile
··· 3 3 # 4 4 5 5 # When adding new entries keep the list in alphabetical order 6 + obj-$(CONFIG_ADXL345) += adxl345_core.o 7 + obj-$(CONFIG_ADXL345_I2C) += adxl345_i2c.o 8 + obj-$(CONFIG_ADXL345_SPI) += adxl345_spi.o 6 9 obj-$(CONFIG_BMA180) += bma180.o 7 10 obj-$(CONFIG_BMA220) += bma220_spi.o 8 11 obj-$(CONFIG_BMC150_ACCEL) += bmc150-accel-core.o
+18
drivers/iio/accel/adxl345.h
··· 1 + /* 2 + * ADXL345 3-Axis Digital Accelerometer 3 + * 4 + * Copyright (c) 2017 Eva Rachel Retuya <eraretuya@gmail.com> 5 + * 6 + * This file is subject to the terms and conditions of version 2 of 7 + * the GNU General Public License. See the file COPYING in the main 8 + * directory of this archive for more details. 9 + */ 10 + 11 + #ifndef _ADXL345_H_ 12 + #define _ADXL345_H_ 13 + 14 + int adxl345_core_probe(struct device *dev, struct regmap *regmap, 15 + const char *name); 16 + int adxl345_core_remove(struct device *dev); 17 + 18 + #endif /* _ADXL345_H_ */
+179
drivers/iio/accel/adxl345_core.c
··· 1 + /* 2 + * ADXL345 3-Axis Digital Accelerometer IIO core driver 3 + * 4 + * Copyright (c) 2017 Eva Rachel Retuya <eraretuya@gmail.com> 5 + * 6 + * This file is subject to the terms and conditions of version 2 of 7 + * the GNU General Public License. See the file COPYING in the main 8 + * directory of this archive for more details. 9 + */ 10 + 11 + #include <linux/module.h> 12 + #include <linux/regmap.h> 13 + 14 + #include <linux/iio/iio.h> 15 + 16 + #include "adxl345.h" 17 + 18 + #define ADXL345_REG_DEVID 0x00 19 + #define ADXL345_REG_POWER_CTL 0x2D 20 + #define ADXL345_REG_DATA_FORMAT 0x31 21 + #define ADXL345_REG_DATAX0 0x32 22 + #define ADXL345_REG_DATAY0 0x34 23 + #define ADXL345_REG_DATAZ0 0x36 24 + 25 + #define ADXL345_POWER_CTL_MEASURE BIT(3) 26 + #define ADXL345_POWER_CTL_STANDBY 0x00 27 + 28 + #define ADXL345_DATA_FORMAT_FULL_RES BIT(3) /* Up to 13-bits resolution */ 29 + #define ADXL345_DATA_FORMAT_2G 0 30 + #define ADXL345_DATA_FORMAT_4G 1 31 + #define ADXL345_DATA_FORMAT_8G 2 32 + #define ADXL345_DATA_FORMAT_16G 3 33 + 34 + #define ADXL345_DEVID 0xE5 35 + 36 + /* 37 + * In full-resolution mode, scale factor is maintained at ~4 mg/LSB 38 + * in all g ranges. 39 + * 40 + * At +/- 16g with 13-bit resolution, scale is computed as: 41 + * (16 + 16) * 9.81 / (2^13 - 1) = 0.0383 42 + */ 43 + static const int adxl345_uscale = 38300; 44 + 45 + struct adxl345_data { 46 + struct regmap *regmap; 47 + u8 data_range; 48 + }; 49 + 50 + #define ADXL345_CHANNEL(reg, axis) { \ 51 + .type = IIO_ACCEL, \ 52 + .modified = 1, \ 53 + .channel2 = IIO_MOD_##axis, \ 54 + .address = reg, \ 55 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 56 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ 57 + } 58 + 59 + static const struct iio_chan_spec adxl345_channels[] = { 60 + ADXL345_CHANNEL(ADXL345_REG_DATAX0, X), 61 + ADXL345_CHANNEL(ADXL345_REG_DATAY0, Y), 62 + ADXL345_CHANNEL(ADXL345_REG_DATAZ0, Z), 63 + }; 64 + 65 + static int adxl345_read_raw(struct iio_dev *indio_dev, 66 + struct iio_chan_spec const *chan, 67 + int *val, int *val2, long mask) 68 + { 69 + struct adxl345_data *data = iio_priv(indio_dev); 70 + __le16 regval; 71 + int ret; 72 + 73 + switch (mask) { 74 + case IIO_CHAN_INFO_RAW: 75 + /* 76 + * Data is stored in adjacent registers: 77 + * ADXL345_REG_DATA(X0/Y0/Z0) contain the least significant byte 78 + * and ADXL345_REG_DATA(X0/Y0/Z0) + 1 the most significant byte 79 + */ 80 + ret = regmap_bulk_read(data->regmap, chan->address, &regval, 81 + sizeof(regval)); 82 + if (ret < 0) 83 + return ret; 84 + 85 + *val = sign_extend32(le16_to_cpu(regval), 12); 86 + return IIO_VAL_INT; 87 + case IIO_CHAN_INFO_SCALE: 88 + *val = 0; 89 + *val2 = adxl345_uscale; 90 + 91 + return IIO_VAL_INT_PLUS_MICRO; 92 + } 93 + 94 + return -EINVAL; 95 + } 96 + 97 + static const struct iio_info adxl345_info = { 98 + .driver_module = THIS_MODULE, 99 + .read_raw = adxl345_read_raw, 100 + }; 101 + 102 + int adxl345_core_probe(struct device *dev, struct regmap *regmap, 103 + const char *name) 104 + { 105 + struct adxl345_data *data; 106 + struct iio_dev *indio_dev; 107 + u32 regval; 108 + int ret; 109 + 110 + ret = regmap_read(regmap, ADXL345_REG_DEVID, &regval); 111 + if (ret < 0) { 112 + dev_err(dev, "Error reading device ID: %d\n", ret); 113 + return ret; 114 + } 115 + 116 + if (regval != ADXL345_DEVID) { 117 + dev_err(dev, "Invalid device ID: %x, expected %x\n", 118 + regval, ADXL345_DEVID); 119 + return -ENODEV; 120 + } 121 + 122 + indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); 123 + if (!indio_dev) 124 + return -ENOMEM; 125 + 126 + data = iio_priv(indio_dev); 127 + dev_set_drvdata(dev, indio_dev); 128 + data->regmap = regmap; 129 + /* Enable full-resolution mode */ 130 + data->data_range = ADXL345_DATA_FORMAT_FULL_RES; 131 + 132 + ret = regmap_write(data->regmap, ADXL345_REG_DATA_FORMAT, 133 + data->data_range); 134 + if (ret < 0) { 135 + dev_err(dev, "Failed to set data range: %d\n", ret); 136 + return ret; 137 + } 138 + 139 + indio_dev->dev.parent = dev; 140 + indio_dev->name = name; 141 + indio_dev->info = &adxl345_info; 142 + indio_dev->modes = INDIO_DIRECT_MODE; 143 + indio_dev->channels = adxl345_channels; 144 + indio_dev->num_channels = ARRAY_SIZE(adxl345_channels); 145 + 146 + /* Enable measurement mode */ 147 + ret = regmap_write(data->regmap, ADXL345_REG_POWER_CTL, 148 + ADXL345_POWER_CTL_MEASURE); 149 + if (ret < 0) { 150 + dev_err(dev, "Failed to enable measurement mode: %d\n", ret); 151 + return ret; 152 + } 153 + 154 + ret = iio_device_register(indio_dev); 155 + if (ret < 0) { 156 + dev_err(dev, "iio_device_register failed: %d\n", ret); 157 + regmap_write(data->regmap, ADXL345_REG_POWER_CTL, 158 + ADXL345_POWER_CTL_STANDBY); 159 + } 160 + 161 + return ret; 162 + } 163 + EXPORT_SYMBOL_GPL(adxl345_core_probe); 164 + 165 + int adxl345_core_remove(struct device *dev) 166 + { 167 + struct iio_dev *indio_dev = dev_get_drvdata(dev); 168 + struct adxl345_data *data = iio_priv(indio_dev); 169 + 170 + iio_device_unregister(indio_dev); 171 + 172 + return regmap_write(data->regmap, ADXL345_REG_POWER_CTL, 173 + ADXL345_POWER_CTL_STANDBY); 174 + } 175 + EXPORT_SYMBOL_GPL(adxl345_core_remove); 176 + 177 + MODULE_AUTHOR("Eva Rachel Retuya <eraretuya@gmail.com>"); 178 + MODULE_DESCRIPTION("ADXL345 3-Axis Digital Accelerometer core driver"); 179 + MODULE_LICENSE("GPL v2");
+73
drivers/iio/accel/adxl345_i2c.c
··· 1 + /* 2 + * ADXL345 3-Axis Digital Accelerometer I2C driver 3 + * 4 + * Copyright (c) 2017 Eva Rachel Retuya <eraretuya@gmail.com> 5 + * 6 + * This file is subject to the terms and conditions of version 2 of 7 + * the GNU General Public License. See the file COPYING in the main 8 + * directory of this archive for more details. 9 + * 10 + * 7-bit I2C slave address: 0x1D (ALT ADDRESS pin tied to VDDIO) or 11 + * 0x53 (ALT ADDRESS pin grounded) 12 + */ 13 + 14 + #include <linux/i2c.h> 15 + #include <linux/module.h> 16 + #include <linux/regmap.h> 17 + 18 + #include "adxl345.h" 19 + 20 + static const struct regmap_config adxl345_i2c_regmap_config = { 21 + .reg_bits = 8, 22 + .val_bits = 8, 23 + }; 24 + 25 + static int adxl345_i2c_probe(struct i2c_client *client, 26 + const struct i2c_device_id *id) 27 + { 28 + struct regmap *regmap; 29 + 30 + regmap = devm_regmap_init_i2c(client, &adxl345_i2c_regmap_config); 31 + if (IS_ERR(regmap)) { 32 + dev_err(&client->dev, "Error initializing i2c regmap: %ld\n", 33 + PTR_ERR(regmap)); 34 + return PTR_ERR(regmap); 35 + } 36 + 37 + return adxl345_core_probe(&client->dev, regmap, id ? id->name : NULL); 38 + } 39 + 40 + static int adxl345_i2c_remove(struct i2c_client *client) 41 + { 42 + return adxl345_core_remove(&client->dev); 43 + } 44 + 45 + static const struct i2c_device_id adxl345_i2c_id[] = { 46 + { "adxl345", 0 }, 47 + { } 48 + }; 49 + 50 + MODULE_DEVICE_TABLE(i2c, adxl345_i2c_id); 51 + 52 + static const struct of_device_id adxl345_of_match[] = { 53 + { .compatible = "adi,adxl345" }, 54 + { }, 55 + }; 56 + 57 + MODULE_DEVICE_TABLE(of, adxl345_of_match); 58 + 59 + static struct i2c_driver adxl345_i2c_driver = { 60 + .driver = { 61 + .name = "adxl345_i2c", 62 + .of_match_table = adxl345_of_match, 63 + }, 64 + .probe = adxl345_i2c_probe, 65 + .remove = adxl345_i2c_remove, 66 + .id_table = adxl345_i2c_id, 67 + }; 68 + 69 + module_i2c_driver(adxl345_i2c_driver); 70 + 71 + MODULE_AUTHOR("Eva Rachel Retuya <eraretuya@gmail.com>"); 72 + MODULE_DESCRIPTION("ADXL345 3-Axis Digital Accelerometer I2C driver"); 73 + MODULE_LICENSE("GPL v2");
+81
drivers/iio/accel/adxl345_spi.c
··· 1 + /* 2 + * ADXL345 3-Axis Digital Accelerometer SPI driver 3 + * 4 + * Copyright (c) 2017 Eva Rachel Retuya <eraretuya@gmail.com> 5 + * 6 + * This file is subject to the terms and conditions of version 2 of 7 + * the GNU General Public License. See the file COPYING in the main 8 + * directory of this archive for more details. 9 + */ 10 + 11 + #include <linux/module.h> 12 + #include <linux/regmap.h> 13 + #include <linux/spi/spi.h> 14 + 15 + #include "adxl345.h" 16 + 17 + #define ADXL345_MAX_SPI_FREQ_HZ 5000000 18 + 19 + static const struct regmap_config adxl345_spi_regmap_config = { 20 + .reg_bits = 8, 21 + .val_bits = 8, 22 + /* Setting bits 7 and 6 enables multiple-byte read */ 23 + .read_flag_mask = BIT(7) | BIT(6), 24 + }; 25 + 26 + static int adxl345_spi_probe(struct spi_device *spi) 27 + { 28 + const struct spi_device_id *id = spi_get_device_id(spi); 29 + struct regmap *regmap; 30 + 31 + /* Bail out if max_speed_hz exceeds 5 MHz */ 32 + if (spi->max_speed_hz > ADXL345_MAX_SPI_FREQ_HZ) { 33 + dev_err(&spi->dev, "SPI CLK, %d Hz exceeds 5 MHz\n", 34 + spi->max_speed_hz); 35 + return -EINVAL; 36 + } 37 + 38 + regmap = devm_regmap_init_spi(spi, &adxl345_spi_regmap_config); 39 + if (IS_ERR(regmap)) { 40 + dev_err(&spi->dev, "Error initializing spi regmap: %ld\n", 41 + PTR_ERR(regmap)); 42 + return PTR_ERR(regmap); 43 + } 44 + 45 + return adxl345_core_probe(&spi->dev, regmap, id->name); 46 + } 47 + 48 + static int adxl345_spi_remove(struct spi_device *spi) 49 + { 50 + return adxl345_core_remove(&spi->dev); 51 + } 52 + 53 + static const struct spi_device_id adxl345_spi_id[] = { 54 + { "adxl345", 0 }, 55 + { } 56 + }; 57 + 58 + MODULE_DEVICE_TABLE(spi, adxl345_spi_id); 59 + 60 + static const struct of_device_id adxl345_of_match[] = { 61 + { .compatible = "adi,adxl345" }, 62 + { }, 63 + }; 64 + 65 + MODULE_DEVICE_TABLE(of, adxl345_of_match); 66 + 67 + static struct spi_driver adxl345_spi_driver = { 68 + .driver = { 69 + .name = "adxl345_spi", 70 + .of_match_table = adxl345_of_match, 71 + }, 72 + .probe = adxl345_spi_probe, 73 + .remove = adxl345_spi_remove, 74 + .id_table = adxl345_spi_id, 75 + }; 76 + 77 + module_spi_driver(adxl345_spi_driver); 78 + 79 + MODULE_AUTHOR("Eva Rachel Retuya <eraretuya@gmail.com>"); 80 + MODULE_DESCRIPTION("ADXL345 3-Axis Digital Accelerometer SPI driver"); 81 + MODULE_LICENSE("GPL v2");
+23
drivers/iio/adc/Kconfig
··· 305 305 To compile this driver as a module, choose M here: the module will be 306 306 called lpc18xx_adc. 307 307 308 + config LPC32XX_ADC 309 + tristate "NXP LPC32XX ADC" 310 + depends on ARCH_LPC32XX || COMPILE_TEST 311 + depends on HAS_IOMEM 312 + help 313 + Say yes here to build support for the integrated ADC inside the 314 + LPC32XX SoC. Note that this feature uses the same hardware as the 315 + touchscreen driver, so you should either select only one of the two 316 + drivers (lpc32xx_adc or lpc32xx_ts) or, in the OpenFirmware case, 317 + activate only one via device tree selection. Provides direct access 318 + via sysfs. 319 + 308 320 config LTC2485 309 321 tristate "Linear Technology LTC2485 ADC driver" 310 322 depends on I2C ··· 505 493 506 494 To compile this driver as a module, choose M here: the 507 495 module will be called rockchip_saradc. 496 + 497 + config SPEAR_ADC 498 + tristate "ST SPEAr ADC" 499 + depends on PLAT_SPEAR || COMPILE_TEST 500 + depends on HAS_IOMEM 501 + help 502 + Say yes here to build support for the integrated ADC inside the 503 + ST SPEAr SoC. Provides direct access via sysfs. 504 + 505 + To compile this driver as a module, choose M here: the 506 + module will be called spear_adc. 508 507 509 508 config STM32_ADC_CORE 510 509 tristate "STMicroelectronics STM32 adc core"
+2
drivers/iio/adc/Makefile
··· 30 30 obj-$(CONFIG_INA2XX_ADC) += ina2xx-adc.o 31 31 obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o 32 32 obj-$(CONFIG_LPC18XX_ADC) += lpc18xx_adc.o 33 + obj-$(CONFIG_LPC32XX_ADC) += lpc32xx_adc.o 33 34 obj-$(CONFIG_LTC2485) += ltc2485.o 34 35 obj-$(CONFIG_MAX1027) += max1027.o 35 36 obj-$(CONFIG_MAX11100) += max11100.o ··· 47 46 obj-$(CONFIG_QCOM_SPMI_VADC) += qcom-spmi-vadc.o 48 47 obj-$(CONFIG_RCAR_GYRO_ADC) += rcar-gyroadc.o 49 48 obj-$(CONFIG_ROCKCHIP_SARADC) += rockchip_saradc.o 49 + obj-$(CONFIG_SPEAR_ADC) += spear_adc.o 50 50 obj-$(CONFIG_STX104) += stx104.o 51 51 obj-$(CONFIG_STM32_ADC_CORE) += stm32-adc-core.o 52 52 obj-$(CONFIG_STM32_ADC) += stm32-adc.o
+67 -23
drivers/iio/adc/meson_saradc.c
··· 18 18 #include <linux/io.h> 19 19 #include <linux/iio/iio.h> 20 20 #include <linux/module.h> 21 + #include <linux/interrupt.h> 21 22 #include <linux/of.h> 23 + #include <linux/of_irq.h> 22 24 #include <linux/of_device.h> 23 25 #include <linux/platform_device.h> 24 26 #include <linux/regmap.h> ··· 165 163 #define MESON_SAR_ADC_REG13_12BIT_CALIBRATION_MASK GENMASK(13, 8) 166 164 167 165 #define MESON_SAR_ADC_MAX_FIFO_SIZE 32 166 + #define MESON_SAR_ADC_TIMEOUT 100 /* ms */ 168 167 169 168 #define MESON_SAR_ADC_CHAN(_chan) { \ 170 169 .type = IIO_VOLTAGE, \ ··· 232 229 struct clk_gate clk_gate; 233 230 struct clk *adc_div_clk; 234 231 struct clk_divider clk_div; 232 + struct completion done; 235 233 }; 236 234 237 235 static const struct regmap_config meson_sar_adc_regmap_config = { ··· 278 274 int *val) 279 275 { 280 276 struct meson_sar_adc_priv *priv = iio_priv(indio_dev); 281 - int ret, regval, fifo_chan, fifo_val, sum = 0, count = 0; 277 + int regval, fifo_chan, fifo_val, count; 282 278 283 - ret = meson_sar_adc_wait_busy_clear(indio_dev); 284 - if (ret) 285 - return ret; 279 + if(!wait_for_completion_timeout(&priv->done, 280 + msecs_to_jiffies(MESON_SAR_ADC_TIMEOUT))) 281 + return -ETIMEDOUT; 286 282 287 - while (meson_sar_adc_get_fifo_count(indio_dev) > 0 && 288 - count < MESON_SAR_ADC_MAX_FIFO_SIZE) { 289 - regmap_read(priv->regmap, MESON_SAR_ADC_FIFO_RD, &regval); 290 - 291 - fifo_chan = FIELD_GET(MESON_SAR_ADC_FIFO_RD_CHAN_ID_MASK, 292 - regval); 293 - if (fifo_chan != chan->channel) 294 - continue; 295 - 296 - fifo_val = FIELD_GET(MESON_SAR_ADC_FIFO_RD_SAMPLE_VALUE_MASK, 297 - regval); 298 - fifo_val &= (BIT(priv->data->resolution) - 1); 299 - 300 - sum += fifo_val; 301 - count++; 283 + count = meson_sar_adc_get_fifo_count(indio_dev); 284 + if (count != 1) { 285 + dev_err(&indio_dev->dev, 286 + "ADC FIFO has %d element(s) instead of one\n", count); 287 + return -EINVAL; 302 288 } 303 289 304 - if (!count) 305 - return -ENOENT; 290 + regmap_read(priv->regmap, MESON_SAR_ADC_FIFO_RD, &regval); 291 + fifo_chan = FIELD_GET(MESON_SAR_ADC_FIFO_RD_CHAN_ID_MASK, regval); 292 + if (fifo_chan != chan->channel) { 293 + dev_err(&indio_dev->dev, 294 + "ADC FIFO entry belongs to channel %d instead of %d\n", 295 + fifo_chan, chan->channel); 296 + return -EINVAL; 297 + } 306 298 307 - *val = sum / count; 299 + fifo_val = FIELD_GET(MESON_SAR_ADC_FIFO_RD_SAMPLE_VALUE_MASK, regval); 300 + fifo_val &= GENMASK(priv->data->resolution - 1, 0); 301 + *val = fifo_val; 308 302 309 303 return 0; 310 304 } ··· 380 378 { 381 379 struct meson_sar_adc_priv *priv = iio_priv(indio_dev); 382 380 381 + reinit_completion(&priv->done); 382 + 383 + regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG0, 384 + MESON_SAR_ADC_REG0_FIFO_IRQ_EN, 385 + MESON_SAR_ADC_REG0_FIFO_IRQ_EN); 386 + 383 387 regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG0, 384 388 MESON_SAR_ADC_REG0_SAMPLE_ENGINE_ENABLE, 385 389 MESON_SAR_ADC_REG0_SAMPLE_ENGINE_ENABLE); ··· 398 390 static void meson_sar_adc_stop_sample_engine(struct iio_dev *indio_dev) 399 391 { 400 392 struct meson_sar_adc_priv *priv = iio_priv(indio_dev); 393 + 394 + regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG0, 395 + MESON_SAR_ADC_REG0_FIFO_IRQ_EN, 0); 401 396 402 397 regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG0, 403 398 MESON_SAR_ADC_REG0_SAMPLING_STOP, ··· 654 643 { 655 644 struct meson_sar_adc_priv *priv = iio_priv(indio_dev); 656 645 int ret; 646 + u32 regval; 657 647 658 648 ret = meson_sar_adc_lock(indio_dev); 659 649 if (ret) ··· 679 667 goto err_sana_clk; 680 668 } 681 669 670 + regval = FIELD_PREP(MESON_SAR_ADC_REG0_FIFO_CNT_IRQ_MASK, 1); 671 + regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG0, 672 + MESON_SAR_ADC_REG0_FIFO_CNT_IRQ_MASK, regval); 682 673 regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG11, 683 674 MESON_SAR_ADC_REG11_BANDGAP_EN, 684 675 MESON_SAR_ADC_REG11_BANDGAP_EN); ··· 743 728 return 0; 744 729 } 745 730 731 + static irqreturn_t meson_sar_adc_irq(int irq, void *data) 732 + { 733 + struct iio_dev *indio_dev = data; 734 + struct meson_sar_adc_priv *priv = iio_priv(indio_dev); 735 + unsigned int cnt, threshold; 736 + u32 regval; 737 + 738 + regmap_read(priv->regmap, MESON_SAR_ADC_REG0, &regval); 739 + cnt = FIELD_GET(MESON_SAR_ADC_REG0_FIFO_COUNT_MASK, regval); 740 + threshold = FIELD_GET(MESON_SAR_ADC_REG0_FIFO_CNT_IRQ_MASK, regval); 741 + 742 + if (cnt < threshold) 743 + return IRQ_NONE; 744 + 745 + complete(&priv->done); 746 + 747 + return IRQ_HANDLED; 748 + } 749 + 746 750 static const struct iio_info meson_sar_adc_iio_info = { 747 751 .read_raw = meson_sar_adc_iio_info_read_raw, 748 752 .driver_module = THIS_MODULE, ··· 804 770 struct resource *res; 805 771 void __iomem *base; 806 772 const struct of_device_id *match; 807 - int ret; 773 + int irq, ret; 808 774 809 775 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*priv)); 810 776 if (!indio_dev) { ··· 813 779 } 814 780 815 781 priv = iio_priv(indio_dev); 782 + init_completion(&priv->done); 816 783 817 784 match = of_match_device(meson_sar_adc_of_match, &pdev->dev); 818 785 priv->data = match->data; ··· 831 796 base = devm_ioremap_resource(&pdev->dev, res); 832 797 if (IS_ERR(base)) 833 798 return PTR_ERR(base); 799 + 800 + irq = irq_of_parse_and_map(pdev->dev.of_node, 0); 801 + if (!irq) 802 + return -EINVAL; 803 + 804 + ret = devm_request_irq(&pdev->dev, irq, meson_sar_adc_irq, IRQF_SHARED, 805 + dev_name(&pdev->dev), indio_dev); 806 + if (ret) 807 + return ret; 834 808 835 809 priv->regmap = devm_regmap_init_mmio(&pdev->dev, base, 836 810 &meson_sar_adc_regmap_config);
+1
drivers/iio/adc/stx104.c
··· 318 318 } 319 319 320 320 indio_dev->name = dev_name(dev); 321 + indio_dev->dev.parent = dev; 321 322 322 323 priv = iio_priv(indio_dev); 323 324 priv->base = base[id];
+3
drivers/iio/common/hid-sensors/hid-sensor-attributes.c
··· 62 62 {HID_USAGE_SENSOR_TIME_TIMESTAMP, 0, 1000000000, 0}, 63 63 {HID_USAGE_SENSOR_TIME_TIMESTAMP, HID_USAGE_SENSOR_UNITS_MILLISECOND, 64 64 1000000, 0}, 65 + 66 + {HID_USAGE_SENSOR_TEMPERATURE, 0, 1000, 0}, 67 + {HID_USAGE_SENSOR_TEMPERATURE, HID_USAGE_SENSOR_UNITS_DEGREES, 1000, 0}, 65 68 }; 66 69 67 70 static int pow_10(unsigned power)
+1
drivers/iio/counter/104-quad-8.c
··· 551 551 indio_dev->num_channels = ARRAY_SIZE(quad8_channels); 552 552 indio_dev->channels = quad8_channels; 553 553 indio_dev->name = dev_name(dev); 554 + indio_dev->dev.parent = dev; 554 555 555 556 priv = iio_priv(indio_dev); 556 557 priv->base = base[id];
+1
drivers/iio/dac/cio-dac.c
··· 119 119 indio_dev->channels = cio_dac_channels; 120 120 indio_dev->num_channels = CIO_DAC_NUM_CHAN; 121 121 indio_dev->name = dev_name(dev); 122 + indio_dev->dev.parent = dev; 122 123 123 124 priv = iio_priv(indio_dev); 124 125 priv->base = base[id];
+13
drivers/iio/health/Kconfig
··· 46 46 To compile this driver as a module, choose M here: the 47 47 module will be called max30100. 48 48 49 + config MAX30102 50 + tristate "MAX30102 heart rate and pulse oximeter sensor" 51 + depends on I2C 52 + select REGMAP_I2C 53 + select IIO_BUFFER 54 + select IIO_KFIFO_BUF 55 + help 56 + Say Y here to build I2C interface support for the Maxim 57 + MAX30102 heart rate, and pulse oximeter sensor. 58 + 59 + To compile this driver as a module, choose M here: the 60 + module will be called max30102. 61 + 49 62 endmenu 50 63 51 64 endmenu
+1
drivers/iio/health/Makefile
··· 7 7 obj-$(CONFIG_AFE4403) += afe4403.o 8 8 obj-$(CONFIG_AFE4404) += afe4404.o 9 9 obj-$(CONFIG_MAX30100) += max30100.o 10 + obj-$(CONFIG_MAX30102) += max30102.o
+1
drivers/iio/health/max30100.c
··· 449 449 indio_dev->available_scan_masks = max30100_scan_masks; 450 450 indio_dev->modes = (INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE); 451 451 indio_dev->setup_ops = &max30100_buffer_setup_ops; 452 + indio_dev->dev.parent = &client->dev; 452 453 453 454 data = iio_priv(indio_dev); 454 455 data->indio_dev = indio_dev;
+486
drivers/iio/health/max30102.c
··· 1 + /* 2 + * max30102.c - Support for MAX30102 heart rate and pulse oximeter sensor 3 + * 4 + * Copyright (C) 2017 Matt Ranostay <matt@ranostay.consulting> 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 + * TODO: proximity power saving feature 17 + */ 18 + 19 + #include <linux/module.h> 20 + #include <linux/init.h> 21 + #include <linux/interrupt.h> 22 + #include <linux/delay.h> 23 + #include <linux/err.h> 24 + #include <linux/irq.h> 25 + #include <linux/i2c.h> 26 + #include <linux/mutex.h> 27 + #include <linux/of.h> 28 + #include <linux/regmap.h> 29 + #include <linux/iio/iio.h> 30 + #include <linux/iio/buffer.h> 31 + #include <linux/iio/kfifo_buf.h> 32 + 33 + #define MAX30102_REGMAP_NAME "max30102_regmap" 34 + #define MAX30102_DRV_NAME "max30102" 35 + 36 + #define MAX30102_REG_INT_STATUS 0x00 37 + #define MAX30102_REG_INT_STATUS_PWR_RDY BIT(0) 38 + #define MAX30102_REG_INT_STATUS_PROX_INT BIT(4) 39 + #define MAX30102_REG_INT_STATUS_ALC_OVF BIT(5) 40 + #define MAX30102_REG_INT_STATUS_PPG_RDY BIT(6) 41 + #define MAX30102_REG_INT_STATUS_FIFO_RDY BIT(7) 42 + 43 + #define MAX30102_REG_INT_ENABLE 0x02 44 + #define MAX30102_REG_INT_ENABLE_PROX_INT_EN BIT(4) 45 + #define MAX30102_REG_INT_ENABLE_ALC_OVF_EN BIT(5) 46 + #define MAX30102_REG_INT_ENABLE_PPG_EN BIT(6) 47 + #define MAX30102_REG_INT_ENABLE_FIFO_EN BIT(7) 48 + #define MAX30102_REG_INT_ENABLE_MASK 0xf0 49 + #define MAX30102_REG_INT_ENABLE_MASK_SHIFT 4 50 + 51 + #define MAX30102_REG_FIFO_WR_PTR 0x04 52 + #define MAX30102_REG_FIFO_OVR_CTR 0x05 53 + #define MAX30102_REG_FIFO_RD_PTR 0x06 54 + #define MAX30102_REG_FIFO_DATA 0x07 55 + #define MAX30102_REG_FIFO_DATA_ENTRY_LEN 6 56 + 57 + #define MAX30102_REG_FIFO_CONFIG 0x08 58 + #define MAX30102_REG_FIFO_CONFIG_AVG_4SAMPLES BIT(1) 59 + #define MAX30102_REG_FIFO_CONFIG_AVG_SHIFT 5 60 + #define MAX30102_REG_FIFO_CONFIG_AFULL BIT(0) 61 + 62 + #define MAX30102_REG_MODE_CONFIG 0x09 63 + #define MAX30102_REG_MODE_CONFIG_MODE_SPO2_EN BIT(0) 64 + #define MAX30102_REG_MODE_CONFIG_MODE_HR_EN BIT(1) 65 + #define MAX30102_REG_MODE_CONFIG_MODE_MASK 0x03 66 + #define MAX30102_REG_MODE_CONFIG_PWR BIT(7) 67 + 68 + #define MAX30102_REG_SPO2_CONFIG 0x0a 69 + #define MAX30102_REG_SPO2_CONFIG_PULSE_411_US 0x03 70 + #define MAX30102_REG_SPO2_CONFIG_SR_400HZ 0x03 71 + #define MAX30102_REG_SPO2_CONFIG_SR_MASK 0x07 72 + #define MAX30102_REG_SPO2_CONFIG_SR_MASK_SHIFT 2 73 + #define MAX30102_REG_SPO2_CONFIG_ADC_4096_STEPS BIT(0) 74 + #define MAX30102_REG_SPO2_CONFIG_ADC_MASK_SHIFT 5 75 + 76 + #define MAX30102_REG_RED_LED_CONFIG 0x0c 77 + #define MAX30102_REG_IR_LED_CONFIG 0x0d 78 + 79 + #define MAX30102_REG_TEMP_CONFIG 0x21 80 + #define MAX30102_REG_TEMP_CONFIG_TEMP_EN BIT(0) 81 + 82 + #define MAX30102_REG_TEMP_INTEGER 0x1f 83 + #define MAX30102_REG_TEMP_FRACTION 0x20 84 + 85 + struct max30102_data { 86 + struct i2c_client *client; 87 + struct iio_dev *indio_dev; 88 + struct mutex lock; 89 + struct regmap *regmap; 90 + 91 + u8 buffer[8]; 92 + __be32 processed_buffer[2]; /* 2 x 18-bit (padded to 32-bits) */ 93 + }; 94 + 95 + static const struct regmap_config max30102_regmap_config = { 96 + .name = MAX30102_REGMAP_NAME, 97 + 98 + .reg_bits = 8, 99 + .val_bits = 8, 100 + }; 101 + 102 + static const unsigned long max30102_scan_masks[] = {0x3, 0}; 103 + 104 + static const struct iio_chan_spec max30102_channels[] = { 105 + { 106 + .type = IIO_INTENSITY, 107 + .channel2 = IIO_MOD_LIGHT_RED, 108 + .modified = 1, 109 + 110 + .scan_index = 0, 111 + .scan_type = { 112 + .sign = 'u', 113 + .shift = 8, 114 + .realbits = 18, 115 + .storagebits = 32, 116 + .endianness = IIO_BE, 117 + }, 118 + }, 119 + { 120 + .type = IIO_INTENSITY, 121 + .channel2 = IIO_MOD_LIGHT_IR, 122 + .modified = 1, 123 + 124 + .scan_index = 1, 125 + .scan_type = { 126 + .sign = 'u', 127 + .shift = 8, 128 + .realbits = 18, 129 + .storagebits = 32, 130 + .endianness = IIO_BE, 131 + }, 132 + }, 133 + { 134 + .type = IIO_TEMP, 135 + .info_mask_separate = 136 + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), 137 + .scan_index = -1, 138 + }, 139 + }; 140 + 141 + static int max30102_set_powermode(struct max30102_data *data, bool state) 142 + { 143 + return regmap_update_bits(data->regmap, MAX30102_REG_MODE_CONFIG, 144 + MAX30102_REG_MODE_CONFIG_PWR, 145 + state ? 0 : MAX30102_REG_MODE_CONFIG_PWR); 146 + } 147 + 148 + static int max30102_buffer_postenable(struct iio_dev *indio_dev) 149 + { 150 + struct max30102_data *data = iio_priv(indio_dev); 151 + 152 + return max30102_set_powermode(data, true); 153 + } 154 + 155 + static int max30102_buffer_predisable(struct iio_dev *indio_dev) 156 + { 157 + struct max30102_data *data = iio_priv(indio_dev); 158 + 159 + return max30102_set_powermode(data, false); 160 + } 161 + 162 + static const struct iio_buffer_setup_ops max30102_buffer_setup_ops = { 163 + .postenable = max30102_buffer_postenable, 164 + .predisable = max30102_buffer_predisable, 165 + }; 166 + 167 + static inline int max30102_fifo_count(struct max30102_data *data) 168 + { 169 + unsigned int val; 170 + int ret; 171 + 172 + ret = regmap_read(data->regmap, MAX30102_REG_INT_STATUS, &val); 173 + if (ret) 174 + return ret; 175 + 176 + /* FIFO has one sample slot left */ 177 + if (val & MAX30102_REG_INT_STATUS_FIFO_RDY) 178 + return 1; 179 + 180 + return 0; 181 + } 182 + 183 + static int max30102_read_measurement(struct max30102_data *data) 184 + { 185 + int ret; 186 + u8 *buffer = (u8 *) &data->buffer; 187 + 188 + ret = i2c_smbus_read_i2c_block_data(data->client, 189 + MAX30102_REG_FIFO_DATA, 190 + MAX30102_REG_FIFO_DATA_ENTRY_LEN, 191 + buffer); 192 + 193 + memcpy(&data->processed_buffer[0], &buffer[0], 3); 194 + memcpy(&data->processed_buffer[1], &buffer[3], 3); 195 + 196 + return (ret == MAX30102_REG_FIFO_DATA_ENTRY_LEN) ? 0 : -EINVAL; 197 + } 198 + 199 + static irqreturn_t max30102_interrupt_handler(int irq, void *private) 200 + { 201 + struct iio_dev *indio_dev = private; 202 + struct max30102_data *data = iio_priv(indio_dev); 203 + int ret, cnt = 0; 204 + 205 + mutex_lock(&data->lock); 206 + 207 + while (cnt || (cnt = max30102_fifo_count(data)) > 0) { 208 + ret = max30102_read_measurement(data); 209 + if (ret) 210 + break; 211 + 212 + iio_push_to_buffers(data->indio_dev, data->processed_buffer); 213 + cnt--; 214 + } 215 + 216 + mutex_unlock(&data->lock); 217 + 218 + return IRQ_HANDLED; 219 + } 220 + 221 + static int max30102_get_current_idx(unsigned int val, int *reg) 222 + { 223 + /* each step is 0.200 mA */ 224 + *reg = val / 200; 225 + 226 + return *reg > 0xff ? -EINVAL : 0; 227 + } 228 + 229 + static int max30102_led_init(struct max30102_data *data) 230 + { 231 + struct device *dev = &data->client->dev; 232 + struct device_node *np = dev->of_node; 233 + unsigned int val; 234 + int reg, ret; 235 + 236 + ret = of_property_read_u32(np, "maxim,red-led-current-microamp", &val); 237 + if (ret) { 238 + dev_info(dev, "no red-led-current-microamp set\n"); 239 + 240 + /* Default to 7 mA RED LED */ 241 + val = 7000; 242 + } 243 + 244 + ret = max30102_get_current_idx(val, &reg); 245 + if (ret) { 246 + dev_err(dev, "invalid RED LED current setting %d\n", val); 247 + return ret; 248 + } 249 + 250 + ret = regmap_write(data->regmap, MAX30102_REG_RED_LED_CONFIG, reg); 251 + if (ret) 252 + return ret; 253 + 254 + ret = of_property_read_u32(np, "maxim,ir-led-current-microamp", &val); 255 + if (ret) { 256 + dev_info(dev, "no ir-led-current-microamp set\n"); 257 + 258 + /* Default to 7 mA IR LED */ 259 + val = 7000; 260 + } 261 + 262 + ret = max30102_get_current_idx(val, &reg); 263 + if (ret) { 264 + dev_err(dev, "invalid IR LED current setting %d", val); 265 + return ret; 266 + } 267 + 268 + return regmap_write(data->regmap, MAX30102_REG_IR_LED_CONFIG, reg); 269 + } 270 + 271 + static int max30102_chip_init(struct max30102_data *data) 272 + { 273 + int ret; 274 + 275 + /* setup LED current settings */ 276 + ret = max30102_led_init(data); 277 + if (ret) 278 + return ret; 279 + 280 + /* enable 18-bit HR + SPO2 readings at 400Hz */ 281 + ret = regmap_write(data->regmap, MAX30102_REG_SPO2_CONFIG, 282 + (MAX30102_REG_SPO2_CONFIG_ADC_4096_STEPS 283 + << MAX30102_REG_SPO2_CONFIG_ADC_MASK_SHIFT) | 284 + (MAX30102_REG_SPO2_CONFIG_SR_400HZ 285 + << MAX30102_REG_SPO2_CONFIG_SR_MASK_SHIFT) | 286 + MAX30102_REG_SPO2_CONFIG_PULSE_411_US); 287 + if (ret) 288 + return ret; 289 + 290 + /* enable SPO2 mode */ 291 + ret = regmap_update_bits(data->regmap, MAX30102_REG_MODE_CONFIG, 292 + MAX30102_REG_MODE_CONFIG_MODE_MASK, 293 + MAX30102_REG_MODE_CONFIG_MODE_HR_EN | 294 + MAX30102_REG_MODE_CONFIG_MODE_SPO2_EN); 295 + if (ret) 296 + return ret; 297 + 298 + /* average 4 samples + generate FIFO interrupt */ 299 + ret = regmap_write(data->regmap, MAX30102_REG_FIFO_CONFIG, 300 + (MAX30102_REG_FIFO_CONFIG_AVG_4SAMPLES 301 + << MAX30102_REG_FIFO_CONFIG_AVG_SHIFT) | 302 + MAX30102_REG_FIFO_CONFIG_AFULL); 303 + if (ret) 304 + return ret; 305 + 306 + /* enable FIFO interrupt */ 307 + return regmap_update_bits(data->regmap, MAX30102_REG_INT_ENABLE, 308 + MAX30102_REG_INT_ENABLE_MASK, 309 + MAX30102_REG_INT_ENABLE_FIFO_EN); 310 + } 311 + 312 + static int max30102_read_temp(struct max30102_data *data, int *val) 313 + { 314 + int ret; 315 + unsigned int reg; 316 + 317 + ret = regmap_read(data->regmap, MAX30102_REG_TEMP_INTEGER, &reg); 318 + if (ret < 0) 319 + return ret; 320 + *val = reg << 4; 321 + 322 + ret = regmap_read(data->regmap, MAX30102_REG_TEMP_FRACTION, &reg); 323 + if (ret < 0) 324 + return ret; 325 + 326 + *val |= reg & 0xf; 327 + *val = sign_extend32(*val, 11); 328 + 329 + return 0; 330 + } 331 + 332 + static int max30102_get_temp(struct max30102_data *data, int *val) 333 + { 334 + int ret; 335 + 336 + /* start acquisition */ 337 + ret = regmap_update_bits(data->regmap, MAX30102_REG_TEMP_CONFIG, 338 + MAX30102_REG_TEMP_CONFIG_TEMP_EN, 339 + MAX30102_REG_TEMP_CONFIG_TEMP_EN); 340 + if (ret) 341 + return ret; 342 + 343 + msleep(35); 344 + 345 + return max30102_read_temp(data, val); 346 + } 347 + 348 + static int max30102_read_raw(struct iio_dev *indio_dev, 349 + struct iio_chan_spec const *chan, 350 + int *val, int *val2, long mask) 351 + { 352 + struct max30102_data *data = iio_priv(indio_dev); 353 + int ret = -EINVAL; 354 + 355 + switch (mask) { 356 + case IIO_CHAN_INFO_RAW: 357 + /* 358 + * Temperature reading can only be acquired while engine 359 + * is running 360 + */ 361 + mutex_lock(&indio_dev->mlock); 362 + 363 + if (!iio_buffer_enabled(indio_dev)) 364 + ret = -EBUSY; 365 + else { 366 + ret = max30102_get_temp(data, val); 367 + if (!ret) 368 + ret = IIO_VAL_INT; 369 + } 370 + 371 + mutex_unlock(&indio_dev->mlock); 372 + break; 373 + case IIO_CHAN_INFO_SCALE: 374 + *val = 1; /* 0.0625 */ 375 + *val2 = 16; 376 + ret = IIO_VAL_FRACTIONAL; 377 + break; 378 + } 379 + 380 + return ret; 381 + } 382 + 383 + static const struct iio_info max30102_info = { 384 + .driver_module = THIS_MODULE, 385 + .read_raw = max30102_read_raw, 386 + }; 387 + 388 + static int max30102_probe(struct i2c_client *client, 389 + const struct i2c_device_id *id) 390 + { 391 + struct max30102_data *data; 392 + struct iio_buffer *buffer; 393 + struct iio_dev *indio_dev; 394 + int ret; 395 + 396 + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 397 + if (!indio_dev) 398 + return -ENOMEM; 399 + 400 + buffer = devm_iio_kfifo_allocate(&client->dev); 401 + if (!buffer) 402 + return -ENOMEM; 403 + 404 + iio_device_attach_buffer(indio_dev, buffer); 405 + 406 + indio_dev->name = MAX30102_DRV_NAME; 407 + indio_dev->channels = max30102_channels; 408 + indio_dev->info = &max30102_info; 409 + indio_dev->num_channels = ARRAY_SIZE(max30102_channels); 410 + indio_dev->available_scan_masks = max30102_scan_masks; 411 + indio_dev->modes = (INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE); 412 + indio_dev->setup_ops = &max30102_buffer_setup_ops; 413 + indio_dev->dev.parent = &client->dev; 414 + 415 + data = iio_priv(indio_dev); 416 + data->indio_dev = indio_dev; 417 + data->client = client; 418 + 419 + mutex_init(&data->lock); 420 + i2c_set_clientdata(client, indio_dev); 421 + 422 + data->regmap = devm_regmap_init_i2c(client, &max30102_regmap_config); 423 + if (IS_ERR(data->regmap)) { 424 + dev_err(&client->dev, "regmap initialization failed.\n"); 425 + return PTR_ERR(data->regmap); 426 + } 427 + max30102_set_powermode(data, false); 428 + 429 + ret = max30102_chip_init(data); 430 + if (ret) 431 + return ret; 432 + 433 + if (client->irq <= 0) { 434 + dev_err(&client->dev, "no valid irq defined\n"); 435 + return -EINVAL; 436 + } 437 + 438 + ret = devm_request_threaded_irq(&client->dev, client->irq, 439 + NULL, max30102_interrupt_handler, 440 + IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 441 + "max30102_irq", indio_dev); 442 + if (ret) { 443 + dev_err(&client->dev, "request irq (%d) failed\n", client->irq); 444 + return ret; 445 + } 446 + 447 + return iio_device_register(indio_dev); 448 + } 449 + 450 + static int max30102_remove(struct i2c_client *client) 451 + { 452 + struct iio_dev *indio_dev = i2c_get_clientdata(client); 453 + struct max30102_data *data = iio_priv(indio_dev); 454 + 455 + iio_device_unregister(indio_dev); 456 + max30102_set_powermode(data, false); 457 + 458 + return 0; 459 + } 460 + 461 + static const struct i2c_device_id max30102_id[] = { 462 + { "max30102", 0 }, 463 + {} 464 + }; 465 + MODULE_DEVICE_TABLE(i2c, max30102_id); 466 + 467 + static const struct of_device_id max30102_dt_ids[] = { 468 + { .compatible = "maxim,max30102" }, 469 + { } 470 + }; 471 + MODULE_DEVICE_TABLE(of, max30102_dt_ids); 472 + 473 + static struct i2c_driver max30102_driver = { 474 + .driver = { 475 + .name = MAX30102_DRV_NAME, 476 + .of_match_table = of_match_ptr(max30102_dt_ids), 477 + }, 478 + .probe = max30102_probe, 479 + .remove = max30102_remove, 480 + .id_table = max30102_id, 481 + }; 482 + module_i2c_driver(max30102_driver); 483 + 484 + MODULE_AUTHOR("Matt Ranostay <matt@ranostay.consulting>"); 485 + MODULE_DESCRIPTION("MAX30102 heart rate and pulse oximeter sensor"); 486 + MODULE_LICENSE("GPL");
+1 -1
drivers/iio/imu/st_lsm6dsx/Kconfig
··· 8 8 select IIO_ST_LSM6DSX_SPI if (SPI_MASTER) 9 9 help 10 10 Say yes here to build support for STMicroelectronics LSM6DSx imu 11 - sensor. Supported devices: lsm6ds3, lsm6dsm 11 + sensor. Supported devices: lsm6ds3, lsm6ds3h, lsm6dsl, lsm6dsm 12 12 13 13 To compile this driver as a module, choose M here: the module 14 14 will be called st_lsm6dsx.
+6 -1
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
··· 15 15 #include <linux/device.h> 16 16 17 17 #define ST_LSM6DS3_DEV_NAME "lsm6ds3" 18 + #define ST_LSM6DS3H_DEV_NAME "lsm6ds3h" 19 + #define ST_LSM6DSL_DEV_NAME "lsm6dsl" 18 20 #define ST_LSM6DSM_DEV_NAME "lsm6dsm" 19 21 20 22 enum st_lsm6dsx_hw_id { 21 23 ST_LSM6DS3_ID, 24 + ST_LSM6DS3H_ID, 25 + ST_LSM6DSL_ID, 22 26 ST_LSM6DSM_ID, 27 + ST_LSM6DSX_MAX_ID, 23 28 }; 24 29 25 30 #define ST_LSM6DSX_CHAN_SIZE 2 ··· 55 50 struct st_lsm6dsx_settings { 56 51 u8 wai; 57 52 u16 max_fifo_size; 58 - enum st_lsm6dsx_hw_id id; 53 + enum st_lsm6dsx_hw_id id[ST_LSM6DSX_MAX_ID]; 59 54 }; 60 55 61 56 enum st_lsm6dsx_sensor_id {
+5 -4
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
··· 1 1 /* 2 2 * STMicroelectronics st_lsm6dsx FIFO buffer library driver 3 3 * 4 - * LSM6DS3/LSM6DSM: The FIFO buffer can be configured to store data 5 - * from gyroscope and accelerometer. Samples are queued without any tag 6 - * according to a specific pattern based on 'FIFO data sets' (6 bytes each): 4 + * LSM6DS3/LSM6DS3H/LSM6DSL/LSM6DSM: The FIFO buffer can be configured 5 + * to store data from gyroscope and accelerometer. Samples are queued 6 + * without any tag according to a specific pattern based on 'FIFO data sets' 7 + * (6 bytes each): 7 8 * - 1st data set is reserved for gyroscope data 8 9 * - 2nd data set is reserved for accelerometer data 9 10 * The FIFO pattern changes depending on the ODRs and decimation factors ··· 207 206 } 208 207 209 208 /** 210 - * st_lsm6dsx_read_fifo() - LSM6DS3-LSM6DSM read FIFO routine 209 + * st_lsm6dsx_read_fifo() - LSM6DS3-LSM6DS3H-LSM6DSL-LSM6DSM read FIFO routine 211 210 * @hw: Pointer to instance of struct st_lsm6dsx_hw. 212 211 * 213 212 * Read samples from the hw FIFO and push them to IIO buffers.
+25 -15
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
··· 17 17 * - Gyroscope supported full-scale [dps]: +-125/+-245/+-500/+-1000/+-2000 18 18 * - FIFO size: 8KB 19 19 * 20 - * - LSM6DSM: 20 + * - LSM6DS3H/LSM6DSL/LSM6DSM: 21 21 * - Accelerometer/Gyroscope supported ODR [Hz]: 13, 26, 52, 104, 208, 416 22 22 * - Accelerometer supported full-scale [g]: +-2/+-4/+-8/+-16 23 23 * - Gyroscope supported full-scale [dps]: +-125/+-245/+-500/+-1000/+-2000 ··· 73 73 #define ST_LSM6DSX_REG_GYRO_OUT_X_L_ADDR 0x22 74 74 #define ST_LSM6DSX_REG_GYRO_OUT_Y_L_ADDR 0x24 75 75 #define ST_LSM6DSX_REG_GYRO_OUT_Z_L_ADDR 0x26 76 - 77 - #define ST_LSM6DS3_WHOAMI 0x69 78 - #define ST_LSM6DSM_WHOAMI 0x6a 79 - 80 - #define ST_LSM6DS3_MAX_FIFO_SIZE 8192 81 - #define ST_LSM6DSM_MAX_FIFO_SIZE 4096 82 76 83 77 #define ST_LSM6DSX_ACC_FS_2G_GAIN IIO_G_TO_M_S_2(61) 84 78 #define ST_LSM6DSX_ACC_FS_4G_GAIN IIO_G_TO_M_S_2(122) ··· 158 164 159 165 static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { 160 166 { 161 - .wai = ST_LSM6DS3_WHOAMI, 162 - .max_fifo_size = ST_LSM6DS3_MAX_FIFO_SIZE, 163 - .id = ST_LSM6DS3_ID, 167 + .wai = 0x69, 168 + .max_fifo_size = 8192, 169 + .id = { 170 + [0] = ST_LSM6DS3_ID, 171 + }, 164 172 }, 165 173 { 166 - .wai = ST_LSM6DSM_WHOAMI, 167 - .max_fifo_size = ST_LSM6DSM_MAX_FIFO_SIZE, 168 - .id = ST_LSM6DSM_ID, 174 + .wai = 0x69, 175 + .max_fifo_size = 4096, 176 + .id = { 177 + [0] = ST_LSM6DS3H_ID, 178 + }, 179 + }, 180 + { 181 + .wai = 0x6a, 182 + .max_fifo_size = 4096, 183 + .id = { 184 + [0] = ST_LSM6DSL_ID, 185 + [1] = ST_LSM6DSM_ID, 186 + }, 169 187 }, 170 188 }; 171 189 ··· 247 241 248 242 static int st_lsm6dsx_check_whoami(struct st_lsm6dsx_hw *hw, int id) 249 243 { 250 - int err, i; 244 + int err, i, j; 251 245 u8 data; 252 246 253 247 for (i = 0; i < ARRAY_SIZE(st_lsm6dsx_sensor_settings); i++) { 254 - if (id == st_lsm6dsx_sensor_settings[i].id) 248 + for (j = 0; j < ST_LSM6DSX_MAX_ID; j++) { 249 + if (id == st_lsm6dsx_sensor_settings[i].id[j]) 250 + break; 251 + } 252 + if (j < ST_LSM6DSX_MAX_ID) 255 253 break; 256 254 } 257 255
+10
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c
··· 71 71 .data = (void *)ST_LSM6DS3_ID, 72 72 }, 73 73 { 74 + .compatible = "st,lsm6ds3h", 75 + .data = (void *)ST_LSM6DS3H_ID, 76 + }, 77 + { 78 + .compatible = "st,lsm6dsl", 79 + .data = (void *)ST_LSM6DSL_ID, 80 + }, 81 + { 74 82 .compatible = "st,lsm6dsm", 75 83 .data = (void *)ST_LSM6DSM_ID, 76 84 }, ··· 88 80 89 81 static const struct i2c_device_id st_lsm6dsx_i2c_id_table[] = { 90 82 { ST_LSM6DS3_DEV_NAME, ST_LSM6DS3_ID }, 83 + { ST_LSM6DS3H_DEV_NAME, ST_LSM6DS3H_ID }, 84 + { ST_LSM6DSL_DEV_NAME, ST_LSM6DSL_ID }, 91 85 { ST_LSM6DSM_DEV_NAME, ST_LSM6DSM_ID }, 92 86 {}, 93 87 };
+10
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c
··· 88 88 .data = (void *)ST_LSM6DS3_ID, 89 89 }, 90 90 { 91 + .compatible = "st,lsm6ds3h", 92 + .data = (void *)ST_LSM6DS3H_ID, 93 + }, 94 + { 95 + .compatible = "st,lsm6dsl", 96 + .data = (void *)ST_LSM6DSL_ID, 97 + }, 98 + { 91 99 .compatible = "st,lsm6dsm", 92 100 .data = (void *)ST_LSM6DSM_ID, 93 101 }, ··· 105 97 106 98 static const struct spi_device_id st_lsm6dsx_spi_id_table[] = { 107 99 { ST_LSM6DS3_DEV_NAME, ST_LSM6DS3_ID }, 100 + { ST_LSM6DS3H_DEV_NAME, ST_LSM6DS3H_ID }, 101 + { ST_LSM6DSL_DEV_NAME, ST_LSM6DSL_ID }, 108 102 { ST_LSM6DSM_DEV_NAME, ST_LSM6DSM_ID }, 109 103 {}, 110 104 };
+10
drivers/iio/light/Kconfig
··· 136 136 To compile this driver as a module, choose M here: 137 137 the module will be called cm36651. 138 138 139 + config IIO_CROS_EC_LIGHT_PROX 140 + tristate "ChromeOS EC Light and Proximity Sensors" 141 + depends on IIO_CROS_EC_SENSORS_CORE 142 + help 143 + Say Y here if you use the light and proximity sensors 144 + presented by the ChromeOS EC Sensor hub. 145 + 146 + To compile this driver as a module, choose M here: 147 + the module will be called cros_ec_light_prox. 148 + 139 149 config GP2AP020A00F 140 150 tristate "Sharp GP2AP020A00F Proximity/ALS sensor" 141 151 depends on I2C
+1
drivers/iio/light/Makefile
··· 15 15 obj-$(CONFIG_CM3323) += cm3323.o 16 16 obj-$(CONFIG_CM3605) += cm3605.o 17 17 obj-$(CONFIG_CM36651) += cm36651.o 18 + obj-$(CONFIG_IIO_CROS_EC_LIGHT_PROX) += cros_ec_light_prox.o 18 19 obj-$(CONFIG_GP2AP020A00F) += gp2ap020a00f.o 19 20 obj-$(CONFIG_HID_SENSOR_ALS) += hid-sensor-als.o 20 21 obj-$(CONFIG_HID_SENSOR_PROX) += hid-sensor-prox.o
+289
drivers/iio/light/cros_ec_light_prox.c
··· 1 + /* 2 + * cros_ec_light_prox - Driver for light and prox sensors behing CrosEC. 3 + * 4 + * Copyright (C) 2017 Google, Inc 5 + * 6 + * This software is licensed under the terms of the GNU General Public 7 + * License version 2, as published by the Free Software Foundation, and 8 + * may be copied, distributed, and modified under those terms. 9 + * 10 + * This program is distributed in the hope that it will be useful, 11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 + * GNU General Public License for more details. 14 + */ 15 + 16 + #include <linux/delay.h> 17 + #include <linux/device.h> 18 + #include <linux/iio/buffer.h> 19 + #include <linux/iio/iio.h> 20 + #include <linux/iio/kfifo_buf.h> 21 + #include <linux/iio/trigger.h> 22 + #include <linux/iio/triggered_buffer.h> 23 + #include <linux/iio/trigger_consumer.h> 24 + #include <linux/kernel.h> 25 + #include <linux/mfd/cros_ec.h> 26 + #include <linux/mfd/cros_ec_commands.h> 27 + #include <linux/module.h> 28 + #include <linux/platform_device.h> 29 + #include <linux/slab.h> 30 + #include <linux/sysfs.h> 31 + 32 + #include "../common/cros_ec_sensors/cros_ec_sensors_core.h" 33 + 34 + /* 35 + * We only represent one entry for light or proximity. EC is merging different 36 + * light sensors to return the what the eye would see. For proximity, we 37 + * currently support only one light source. 38 + */ 39 + #define CROS_EC_LIGHT_PROX_MAX_CHANNELS (1 + 1) 40 + 41 + /* State data for ec_sensors iio driver. */ 42 + struct cros_ec_light_prox_state { 43 + /* Shared by all sensors */ 44 + struct cros_ec_sensors_core_state core; 45 + 46 + struct iio_chan_spec channels[CROS_EC_LIGHT_PROX_MAX_CHANNELS]; 47 + }; 48 + 49 + static int cros_ec_light_prox_read(struct iio_dev *indio_dev, 50 + struct iio_chan_spec const *chan, 51 + int *val, int *val2, long mask) 52 + { 53 + struct cros_ec_light_prox_state *st = iio_priv(indio_dev); 54 + u16 data = 0; 55 + s64 val64; 56 + int ret = IIO_VAL_INT; 57 + int idx = chan->scan_index; 58 + 59 + mutex_lock(&st->core.cmd_lock); 60 + 61 + switch (mask) { 62 + case IIO_CHAN_INFO_RAW: 63 + if (chan->type == IIO_PROXIMITY) { 64 + if (cros_ec_sensors_read_cmd(indio_dev, 1 << idx, 65 + (s16 *)&data) < 0) { 66 + ret = -EIO; 67 + break; 68 + } 69 + *val = data; 70 + } else { 71 + ret = -EINVAL; 72 + } 73 + break; 74 + case IIO_CHAN_INFO_PROCESSED: 75 + if (chan->type == IIO_LIGHT) { 76 + if (cros_ec_sensors_read_cmd(indio_dev, 1 << idx, 77 + (s16 *)&data) < 0) { 78 + ret = -EIO; 79 + break; 80 + } 81 + /* 82 + * The data coming from the light sensor is 83 + * pre-processed and represents the ambient light 84 + * illuminance reading expressed in lux. 85 + */ 86 + *val = data; 87 + ret = IIO_VAL_INT; 88 + } else { 89 + ret = -EINVAL; 90 + } 91 + break; 92 + case IIO_CHAN_INFO_CALIBBIAS: 93 + st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_OFFSET; 94 + st->core.param.sensor_offset.flags = 0; 95 + 96 + if (cros_ec_motion_send_host_cmd(&st->core, 0)) { 97 + ret = -EIO; 98 + break; 99 + } 100 + 101 + /* Save values */ 102 + st->core.calib[0] = st->core.resp->sensor_offset.offset[0]; 103 + 104 + *val = st->core.calib[idx]; 105 + break; 106 + case IIO_CHAN_INFO_CALIBSCALE: 107 + /* 108 + * RANGE is used for calibration 109 + * scale is a number x.y, where x is coded on 16 bits, 110 + * y coded on 16 bits, between 0 and 9999. 111 + */ 112 + st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_RANGE; 113 + st->core.param.sensor_range.data = EC_MOTION_SENSE_NO_VALUE; 114 + 115 + if (cros_ec_motion_send_host_cmd(&st->core, 0)) { 116 + ret = -EIO; 117 + break; 118 + } 119 + 120 + val64 = st->core.resp->sensor_range.ret; 121 + *val = val64 >> 16; 122 + *val2 = (val64 & 0xffff) * 100; 123 + ret = IIO_VAL_INT_PLUS_MICRO; 124 + break; 125 + default: 126 + ret = cros_ec_sensors_core_read(&st->core, chan, val, val2, 127 + mask); 128 + break; 129 + } 130 + 131 + mutex_unlock(&st->core.cmd_lock); 132 + 133 + return ret; 134 + } 135 + 136 + static int cros_ec_light_prox_write(struct iio_dev *indio_dev, 137 + struct iio_chan_spec const *chan, 138 + int val, int val2, long mask) 139 + { 140 + struct cros_ec_light_prox_state *st = iio_priv(indio_dev); 141 + int ret = 0; 142 + int idx = chan->scan_index; 143 + 144 + mutex_lock(&st->core.cmd_lock); 145 + 146 + switch (mask) { 147 + case IIO_CHAN_INFO_CALIBBIAS: 148 + st->core.calib[idx] = val; 149 + /* Send to EC for each axis, even if not complete */ 150 + st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_OFFSET; 151 + st->core.param.sensor_offset.flags = MOTION_SENSE_SET_OFFSET; 152 + st->core.param.sensor_offset.offset[0] = st->core.calib[0]; 153 + st->core.param.sensor_offset.temp = 154 + EC_MOTION_SENSE_INVALID_CALIB_TEMP; 155 + if (cros_ec_motion_send_host_cmd(&st->core, 0)) 156 + ret = -EIO; 157 + break; 158 + case IIO_CHAN_INFO_CALIBSCALE: 159 + st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_RANGE; 160 + st->core.param.sensor_range.data = (val << 16) | (val2 / 100); 161 + if (cros_ec_motion_send_host_cmd(&st->core, 0)) 162 + ret = -EIO; 163 + break; 164 + default: 165 + ret = cros_ec_sensors_core_write(&st->core, chan, val, val2, 166 + mask); 167 + break; 168 + } 169 + 170 + mutex_unlock(&st->core.cmd_lock); 171 + 172 + return ret; 173 + } 174 + 175 + static const struct iio_info cros_ec_light_prox_info = { 176 + .read_raw = &cros_ec_light_prox_read, 177 + .write_raw = &cros_ec_light_prox_write, 178 + .driver_module = THIS_MODULE, 179 + }; 180 + 181 + static int cros_ec_light_prox_probe(struct platform_device *pdev) 182 + { 183 + struct device *dev = &pdev->dev; 184 + struct cros_ec_dev *ec_dev = dev_get_drvdata(dev->parent); 185 + struct cros_ec_device *ec_device; 186 + struct iio_dev *indio_dev; 187 + struct cros_ec_light_prox_state *state; 188 + struct iio_chan_spec *channel; 189 + int ret; 190 + 191 + if (!ec_dev || !ec_dev->ec_dev) { 192 + dev_warn(dev, "No CROS EC device found.\n"); 193 + return -EINVAL; 194 + } 195 + ec_device = ec_dev->ec_dev; 196 + 197 + indio_dev = devm_iio_device_alloc(dev, sizeof(*state)); 198 + if (!indio_dev) 199 + return -ENOMEM; 200 + 201 + ret = cros_ec_sensors_core_init(pdev, indio_dev, true); 202 + if (ret) 203 + return ret; 204 + 205 + indio_dev->info = &cros_ec_light_prox_info; 206 + state = iio_priv(indio_dev); 207 + state->core.type = state->core.resp->info.type; 208 + state->core.loc = state->core.resp->info.location; 209 + channel = state->channels; 210 + 211 + /* Common part */ 212 + channel->info_mask_shared_by_all = 213 + BIT(IIO_CHAN_INFO_SAMP_FREQ) | 214 + BIT(IIO_CHAN_INFO_FREQUENCY); 215 + channel->scan_type.realbits = CROS_EC_SENSOR_BITS; 216 + channel->scan_type.storagebits = CROS_EC_SENSOR_BITS; 217 + channel->scan_type.shift = 0; 218 + channel->scan_index = 0; 219 + channel->ext_info = cros_ec_sensors_ext_info; 220 + channel->scan_type.sign = 'u'; 221 + 222 + state->core.calib[0] = 0; 223 + 224 + /* Sensor specific */ 225 + switch (state->core.type) { 226 + case MOTIONSENSE_TYPE_LIGHT: 227 + channel->type = IIO_LIGHT; 228 + channel->info_mask_separate = 229 + BIT(IIO_CHAN_INFO_PROCESSED) | 230 + BIT(IIO_CHAN_INFO_CALIBBIAS) | 231 + BIT(IIO_CHAN_INFO_CALIBSCALE); 232 + break; 233 + case MOTIONSENSE_TYPE_PROX: 234 + channel->type = IIO_PROXIMITY; 235 + channel->info_mask_separate = 236 + BIT(IIO_CHAN_INFO_RAW) | 237 + BIT(IIO_CHAN_INFO_CALIBBIAS) | 238 + BIT(IIO_CHAN_INFO_CALIBSCALE); 239 + break; 240 + default: 241 + dev_warn(dev, "Unknown motion sensor\n"); 242 + return -EINVAL; 243 + } 244 + 245 + /* Timestamp */ 246 + channel++; 247 + channel->type = IIO_TIMESTAMP; 248 + channel->channel = -1; 249 + channel->scan_index = 1; 250 + channel->scan_type.sign = 's'; 251 + channel->scan_type.realbits = 64; 252 + channel->scan_type.storagebits = 64; 253 + 254 + indio_dev->channels = state->channels; 255 + 256 + indio_dev->num_channels = CROS_EC_LIGHT_PROX_MAX_CHANNELS; 257 + 258 + state->core.read_ec_sensors_data = cros_ec_sensors_read_cmd; 259 + 260 + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL, 261 + cros_ec_sensors_capture, NULL); 262 + if (ret) 263 + return ret; 264 + 265 + return devm_iio_device_register(dev, indio_dev); 266 + } 267 + 268 + static const struct platform_device_id cros_ec_light_prox_ids[] = { 269 + { 270 + .name = "cros-ec-prox", 271 + }, 272 + { 273 + .name = "cros-ec-light", 274 + }, 275 + { /* sentinel */ } 276 + }; 277 + MODULE_DEVICE_TABLE(platform, cros_ec_light_prox_ids); 278 + 279 + static struct platform_driver cros_ec_light_prox_platform_driver = { 280 + .driver = { 281 + .name = "cros-ec-light-prox", 282 + }, 283 + .probe = cros_ec_light_prox_probe, 284 + .id_table = cros_ec_light_prox_ids, 285 + }; 286 + module_platform_driver(cros_ec_light_prox_platform_driver); 287 + 288 + MODULE_DESCRIPTION("ChromeOS EC light/proximity sensors driver"); 289 + MODULE_LICENSE("GPL v2");
+7
drivers/iio/light/hid-sensor-prox.c
··· 240 240 st->common_attributes.sensitivity.index, 241 241 st->common_attributes.sensitivity.report_id); 242 242 } 243 + if (st->common_attributes.sensitivity.index < 0) 244 + sensor_hub_input_get_attribute_info(hsdev, 245 + HID_FEATURE_REPORT, usage_id, 246 + HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS | 247 + HID_USAGE_SENSOR_HUMAN_PRESENCE, 248 + &st->common_attributes.sensitivity); 249 + 243 250 return ret; 244 251 } 245 252
+1
drivers/iio/potentiostat/lmp91000.c
··· 325 325 indio_dev->channels = lmp91000_channels; 326 326 indio_dev->num_channels = ARRAY_SIZE(lmp91000_channels); 327 327 indio_dev->name = LMP91000_DRV_NAME; 328 + indio_dev->dev.parent = &client->dev; 328 329 indio_dev->modes = INDIO_DIRECT_MODE; 329 330 i2c_set_clientdata(client, indio_dev); 330 331
+11
drivers/iio/proximity/Kconfig
··· 32 32 To compile this driver as a module, choose M here: the 33 33 module will be called pulsedlight-lite-v2 34 34 35 + config SRF04 36 + tristate "Devantech SRF04 ultrasonic ranger sensor" 37 + depends on GPIOLIB 38 + help 39 + Say Y here to build a driver for Devantech SRF04 ultrasonic 40 + ranger sensor. This driver can be used to measure the distance 41 + of objects. It is using two GPIOs. 42 + 43 + To compile this driver as a module, choose M here: the 44 + module will be called srf04. 45 + 35 46 config SX9500 36 47 tristate "SX9500 Semtech proximity sensor" 37 48 select IIO_BUFFER
+1
drivers/iio/proximity/Makefile
··· 5 5 # When adding new entries keep the list in alphabetical order 6 6 obj-$(CONFIG_AS3935) += as3935.o 7 7 obj-$(CONFIG_LIDAR_LITE_V2) += pulsedlight-lidar-lite-v2.o 8 + obj-$(CONFIG_SRF04) += srf04.o 8 9 obj-$(CONFIG_SRF08) += srf08.o 9 10 obj-$(CONFIG_SX9500) += sx9500.o
+1
drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
··· 278 278 indio_dev->name = LIDAR_DRV_NAME; 279 279 indio_dev->channels = lidar_channels; 280 280 indio_dev->num_channels = ARRAY_SIZE(lidar_channels); 281 + indio_dev->dev.parent = &client->dev; 281 282 indio_dev->modes = INDIO_DIRECT_MODE; 282 283 283 284 i2c_set_clientdata(client, indio_dev);
+304
drivers/iio/proximity/srf04.c
··· 1 + /* 2 + * SRF04: ultrasonic sensor for distance measuring by using GPIOs 3 + * 4 + * Copyright (c) 2017 Andreas Klinger <ak@it-klinger.de> 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License as published by 8 + * the Free Software Foundation; either version 2 of the License, or 9 + * (at your option) any later version. 10 + * 11 + * This program is distributed in the hope that it will be useful, 12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + * GNU General Public License for more details. 15 + * 16 + * For details about the device see: 17 + * http://www.robot-electronics.co.uk/htm/srf04tech.htm 18 + * 19 + * the measurement cycle as timing diagram looks like: 20 + * 21 + * +---+ 22 + * GPIO | | 23 + * trig: --+ +------------------------------------------------------ 24 + * ^ ^ 25 + * |<->| 26 + * udelay(10) 27 + * 28 + * ultra +-+ +-+ +-+ 29 + * sonic | | | | | | 30 + * burst: ---------+ +-+ +-+ +----------------------------------------- 31 + * . 32 + * ultra . +-+ +-+ +-+ 33 + * sonic . | | | | | | 34 + * echo: ----------------------------------+ +-+ +-+ +---------------- 35 + * . . 36 + * +------------------------+ 37 + * GPIO | | 38 + * echo: -------------------+ +--------------- 39 + * ^ ^ 40 + * interrupt interrupt 41 + * (ts_rising) (ts_falling) 42 + * |<---------------------->| 43 + * pulse time measured 44 + * --> one round trip of ultra sonic waves 45 + */ 46 + #include <linux/err.h> 47 + #include <linux/gpio/consumer.h> 48 + #include <linux/kernel.h> 49 + #include <linux/module.h> 50 + #include <linux/of.h> 51 + #include <linux/platform_device.h> 52 + #include <linux/property.h> 53 + #include <linux/sched.h> 54 + #include <linux/interrupt.h> 55 + #include <linux/delay.h> 56 + #include <linux/iio/iio.h> 57 + #include <linux/iio/sysfs.h> 58 + 59 + struct srf04_data { 60 + struct device *dev; 61 + struct gpio_desc *gpiod_trig; 62 + struct gpio_desc *gpiod_echo; 63 + struct mutex lock; 64 + int irqnr; 65 + ktime_t ts_rising; 66 + ktime_t ts_falling; 67 + struct completion rising; 68 + struct completion falling; 69 + }; 70 + 71 + static irqreturn_t srf04_handle_irq(int irq, void *dev_id) 72 + { 73 + struct iio_dev *indio_dev = dev_id; 74 + struct srf04_data *data = iio_priv(indio_dev); 75 + ktime_t now = ktime_get(); 76 + 77 + if (gpiod_get_value(data->gpiod_echo)) { 78 + data->ts_rising = now; 79 + complete(&data->rising); 80 + } else { 81 + data->ts_falling = now; 82 + complete(&data->falling); 83 + } 84 + 85 + return IRQ_HANDLED; 86 + } 87 + 88 + static int srf04_read(struct srf04_data *data) 89 + { 90 + int ret; 91 + ktime_t ktime_dt; 92 + u64 dt_ns; 93 + u32 time_ns, distance_mm; 94 + 95 + /* 96 + * just one read-echo-cycle can take place at a time 97 + * ==> lock against concurrent reading calls 98 + */ 99 + mutex_lock(&data->lock); 100 + 101 + reinit_completion(&data->rising); 102 + reinit_completion(&data->falling); 103 + 104 + gpiod_set_value(data->gpiod_trig, 1); 105 + udelay(10); 106 + gpiod_set_value(data->gpiod_trig, 0); 107 + 108 + /* it cannot take more than 20 ms */ 109 + ret = wait_for_completion_killable_timeout(&data->rising, HZ/50); 110 + if (ret < 0) { 111 + mutex_unlock(&data->lock); 112 + return ret; 113 + } else if (ret == 0) { 114 + mutex_unlock(&data->lock); 115 + return -ETIMEDOUT; 116 + } 117 + 118 + ret = wait_for_completion_killable_timeout(&data->falling, HZ/50); 119 + if (ret < 0) { 120 + mutex_unlock(&data->lock); 121 + return ret; 122 + } else if (ret == 0) { 123 + mutex_unlock(&data->lock); 124 + return -ETIMEDOUT; 125 + } 126 + 127 + ktime_dt = ktime_sub(data->ts_falling, data->ts_rising); 128 + 129 + mutex_unlock(&data->lock); 130 + 131 + dt_ns = ktime_to_ns(ktime_dt); 132 + /* 133 + * measuring more than 3 meters is beyond the capabilities of 134 + * the sensor 135 + * ==> filter out invalid results for not measuring echos of 136 + * another us sensor 137 + * 138 + * formula: 139 + * distance 3 m 140 + * time = ---------- = --------- = 9404389 ns 141 + * speed 319 m/s 142 + * 143 + * using a minimum speed at -20 °C of 319 m/s 144 + */ 145 + if (dt_ns > 9404389) 146 + return -EIO; 147 + 148 + time_ns = dt_ns; 149 + 150 + /* 151 + * the speed as function of the temperature is approximately: 152 + * 153 + * speed = 331,5 + 0,6 * Temp 154 + * with Temp in °C 155 + * and speed in m/s 156 + * 157 + * use 343 m/s as ultrasonic speed at 20 °C here in absence of the 158 + * temperature 159 + * 160 + * therefore: 161 + * time 343 162 + * distance = ------ * ----- 163 + * 10^6 2 164 + * with time in ns 165 + * and distance in mm (one way) 166 + * 167 + * because we limit to 3 meters the multiplication with 343 just 168 + * fits into 32 bit 169 + */ 170 + distance_mm = time_ns * 343 / 2000000; 171 + 172 + return distance_mm; 173 + } 174 + 175 + static int srf04_read_raw(struct iio_dev *indio_dev, 176 + struct iio_chan_spec const *channel, int *val, 177 + int *val2, long info) 178 + { 179 + struct srf04_data *data = iio_priv(indio_dev); 180 + int ret; 181 + 182 + if (channel->type != IIO_DISTANCE) 183 + return -EINVAL; 184 + 185 + switch (info) { 186 + case IIO_CHAN_INFO_RAW: 187 + ret = srf04_read(data); 188 + if (ret < 0) 189 + return ret; 190 + *val = ret; 191 + return IIO_VAL_INT; 192 + case IIO_CHAN_INFO_SCALE: 193 + /* 194 + * theoretical maximum resolution is 3 mm 195 + * 1 LSB is 1 mm 196 + */ 197 + *val = 0; 198 + *val2 = 1000; 199 + return IIO_VAL_INT_PLUS_MICRO; 200 + default: 201 + return -EINVAL; 202 + } 203 + } 204 + 205 + static const struct iio_info srf04_iio_info = { 206 + .driver_module = THIS_MODULE, 207 + .read_raw = srf04_read_raw, 208 + }; 209 + 210 + static const struct iio_chan_spec srf04_chan_spec[] = { 211 + { 212 + .type = IIO_DISTANCE, 213 + .info_mask_separate = 214 + BIT(IIO_CHAN_INFO_RAW) | 215 + BIT(IIO_CHAN_INFO_SCALE), 216 + }, 217 + }; 218 + 219 + static int srf04_probe(struct platform_device *pdev) 220 + { 221 + struct device *dev = &pdev->dev; 222 + struct srf04_data *data; 223 + struct iio_dev *indio_dev; 224 + int ret; 225 + 226 + indio_dev = devm_iio_device_alloc(dev, sizeof(struct srf04_data)); 227 + if (!indio_dev) { 228 + dev_err(dev, "failed to allocate IIO device\n"); 229 + return -ENOMEM; 230 + } 231 + 232 + data = iio_priv(indio_dev); 233 + data->dev = dev; 234 + 235 + mutex_init(&data->lock); 236 + init_completion(&data->rising); 237 + init_completion(&data->falling); 238 + 239 + data->gpiod_trig = devm_gpiod_get(dev, "trig", GPIOD_OUT_LOW); 240 + if (IS_ERR(data->gpiod_trig)) { 241 + dev_err(dev, "failed to get trig-gpios: err=%ld\n", 242 + PTR_ERR(data->gpiod_trig)); 243 + return PTR_ERR(data->gpiod_trig); 244 + } 245 + 246 + data->gpiod_echo = devm_gpiod_get(dev, "echo", GPIOD_IN); 247 + if (IS_ERR(data->gpiod_echo)) { 248 + dev_err(dev, "failed to get echo-gpios: err=%ld\n", 249 + PTR_ERR(data->gpiod_echo)); 250 + return PTR_ERR(data->gpiod_echo); 251 + } 252 + 253 + if (gpiod_cansleep(data->gpiod_echo)) { 254 + dev_err(data->dev, "cansleep-GPIOs not supported\n"); 255 + return -ENODEV; 256 + } 257 + 258 + data->irqnr = gpiod_to_irq(data->gpiod_echo); 259 + if (data->irqnr < 0) { 260 + dev_err(data->dev, "gpiod_to_irq: %d\n", data->irqnr); 261 + return data->irqnr; 262 + } 263 + 264 + ret = devm_request_irq(dev, data->irqnr, srf04_handle_irq, 265 + IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, 266 + pdev->name, indio_dev); 267 + if (ret < 0) { 268 + dev_err(data->dev, "request_irq: %d\n", ret); 269 + return ret; 270 + } 271 + 272 + platform_set_drvdata(pdev, indio_dev); 273 + 274 + indio_dev->name = "srf04"; 275 + indio_dev->dev.parent = &pdev->dev; 276 + indio_dev->info = &srf04_iio_info; 277 + indio_dev->modes = INDIO_DIRECT_MODE; 278 + indio_dev->channels = srf04_chan_spec; 279 + indio_dev->num_channels = ARRAY_SIZE(srf04_chan_spec); 280 + 281 + return devm_iio_device_register(dev, indio_dev); 282 + } 283 + 284 + static const struct of_device_id of_srf04_match[] = { 285 + { .compatible = "devantech,srf04", }, 286 + {}, 287 + }; 288 + 289 + MODULE_DEVICE_TABLE(of, of_srf04_match); 290 + 291 + static struct platform_driver srf04_driver = { 292 + .probe = srf04_probe, 293 + .driver = { 294 + .name = "srf04-gpio", 295 + .of_match_table = of_srf04_match, 296 + }, 297 + }; 298 + 299 + module_platform_driver(srf04_driver); 300 + 301 + MODULE_AUTHOR("Andreas Klinger <ak@it-klinger.de>"); 302 + MODULE_DESCRIPTION("SRF04 ultrasonic sensor for distance measuring using GPIOs"); 303 + MODULE_LICENSE("GPL"); 304 + MODULE_ALIAS("platform:srf04");
+14
drivers/iio/temperature/Kconfig
··· 19 19 This driver can also be built as a module. If so, the module will 20 20 be called maxim_thermocouple. 21 21 22 + config HID_SENSOR_TEMP 23 + tristate "HID Environmental temperature sensor" 24 + depends on HID_SENSOR_HUB 25 + select IIO_BUFFER 26 + select IIO_TRIGGERED_BUFFER 27 + select HID_SENSOR_IIO_COMMON 28 + select HID_SENSOR_IIO_TRIGGER 29 + help 30 + Say yes here to build support for the HID SENSOR 31 + temperature driver 32 + 33 + To compile this driver as a module, choose M here: the module 34 + will be called hid-sensor-temperature. 35 + 22 36 config MLX90614 23 37 tristate "MLX90614 contact-less infrared sensor" 24 38 depends on I2C
+1
drivers/iio/temperature/Makefile
··· 2 2 # Makefile for industrial I/O temperature drivers 3 3 # 4 4 5 + obj-$(CONFIG_HID_SENSOR_TEMP) += hid-sensor-temperature.o 5 6 obj-$(CONFIG_MAXIM_THERMOCOUPLE) += maxim_thermocouple.o 6 7 obj-$(CONFIG_MLX90614) += mlx90614.o 7 8 obj-$(CONFIG_TMP006) += tmp006.o
+311
drivers/iio/temperature/hid-sensor-temperature.c
··· 1 + /* 2 + * HID Sensors Driver 3 + * Copyright (c) 2017, Intel Corporation. 4 + * 5 + * This program is free software; you can redistribute it and/or modify it 6 + * under the terms and conditions of the GNU General Public License, 7 + * version 2, as published by the Free Software Foundation. 8 + * 9 + * This program is distributed in the hope it will be useful, but WITHOUT 10 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 + * more details. 13 + * 14 + * You should have received a copy of the GNU General Public License along with 15 + * this program. 16 + */ 17 + #include <linux/device.h> 18 + #include <linux/hid-sensor-hub.h> 19 + #include <linux/iio/buffer.h> 20 + #include <linux/iio/iio.h> 21 + #include <linux/iio/triggered_buffer.h> 22 + #include <linux/iio/trigger_consumer.h> 23 + #include <linux/module.h> 24 + #include <linux/platform_device.h> 25 + 26 + #include "../common/hid-sensors/hid-sensor-trigger.h" 27 + 28 + struct temperature_state { 29 + struct hid_sensor_common common_attributes; 30 + struct hid_sensor_hub_attribute_info temperature_attr; 31 + s32 temperature_data; 32 + int scale_pre_decml; 33 + int scale_post_decml; 34 + int scale_precision; 35 + int value_offset; 36 + }; 37 + 38 + /* Channel definitions */ 39 + static const struct iio_chan_spec temperature_channels[] = { 40 + { 41 + .type = IIO_TEMP, 42 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 43 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | 44 + BIT(IIO_CHAN_INFO_SCALE) | 45 + BIT(IIO_CHAN_INFO_SAMP_FREQ) | 46 + BIT(IIO_CHAN_INFO_HYSTERESIS), 47 + }, 48 + IIO_CHAN_SOFT_TIMESTAMP(3), 49 + }; 50 + 51 + /* Adjust channel real bits based on report descriptor */ 52 + static void temperature_adjust_channel_bit_mask(struct iio_chan_spec *channels, 53 + int channel, int size) 54 + { 55 + channels[channel].scan_type.sign = 's'; 56 + /* Real storage bits will change based on the report desc. */ 57 + channels[channel].scan_type.realbits = size * 8; 58 + /* Maximum size of a sample to capture is s32 */ 59 + channels[channel].scan_type.storagebits = sizeof(s32) * 8; 60 + } 61 + 62 + static int temperature_read_raw(struct iio_dev *indio_dev, 63 + struct iio_chan_spec const *chan, 64 + int *val, int *val2, long mask) 65 + { 66 + struct temperature_state *temp_st = iio_priv(indio_dev); 67 + 68 + switch (mask) { 69 + case IIO_CHAN_INFO_RAW: 70 + if (chan->type != IIO_TEMP) 71 + return -EINVAL; 72 + hid_sensor_power_state( 73 + &temp_st->common_attributes, true); 74 + *val = sensor_hub_input_attr_get_raw_value( 75 + temp_st->common_attributes.hsdev, 76 + HID_USAGE_SENSOR_TEMPERATURE, 77 + HID_USAGE_SENSOR_DATA_ENVIRONMENTAL_TEMPERATURE, 78 + temp_st->temperature_attr.report_id, 79 + SENSOR_HUB_SYNC); 80 + hid_sensor_power_state( 81 + &temp_st->common_attributes, 82 + false); 83 + 84 + return IIO_VAL_INT; 85 + 86 + case IIO_CHAN_INFO_SCALE: 87 + *val = temp_st->scale_pre_decml; 88 + *val2 = temp_st->scale_post_decml; 89 + return temp_st->scale_precision; 90 + 91 + case IIO_CHAN_INFO_OFFSET: 92 + *val = temp_st->value_offset; 93 + return IIO_VAL_INT; 94 + 95 + case IIO_CHAN_INFO_SAMP_FREQ: 96 + return hid_sensor_read_samp_freq_value( 97 + &temp_st->common_attributes, val, val2); 98 + 99 + case IIO_CHAN_INFO_HYSTERESIS: 100 + return hid_sensor_read_raw_hyst_value( 101 + &temp_st->common_attributes, val, val2); 102 + default: 103 + return -EINVAL; 104 + } 105 + } 106 + 107 + static int temperature_write_raw(struct iio_dev *indio_dev, 108 + struct iio_chan_spec const *chan, 109 + int val, int val2, long mask) 110 + { 111 + struct temperature_state *temp_st = iio_priv(indio_dev); 112 + 113 + switch (mask) { 114 + case IIO_CHAN_INFO_SAMP_FREQ: 115 + return hid_sensor_write_samp_freq_value( 116 + &temp_st->common_attributes, val, val2); 117 + case IIO_CHAN_INFO_HYSTERESIS: 118 + return hid_sensor_write_raw_hyst_value( 119 + &temp_st->common_attributes, val, val2); 120 + default: 121 + return -EINVAL; 122 + } 123 + } 124 + 125 + static const struct iio_info temperature_info = { 126 + .driver_module = THIS_MODULE, 127 + .read_raw = &temperature_read_raw, 128 + .write_raw = &temperature_write_raw, 129 + }; 130 + 131 + /* Callback handler to send event after all samples are received and captured */ 132 + static int temperature_proc_event(struct hid_sensor_hub_device *hsdev, 133 + unsigned int usage_id, void *pdev) 134 + { 135 + struct iio_dev *indio_dev = platform_get_drvdata(pdev); 136 + struct temperature_state *temp_st = iio_priv(indio_dev); 137 + 138 + if (atomic_read(&temp_st->common_attributes.data_ready)) 139 + iio_push_to_buffers_with_timestamp(indio_dev, 140 + &temp_st->temperature_data, 141 + iio_get_time_ns(indio_dev)); 142 + 143 + return 0; 144 + } 145 + 146 + /* Capture samples in local storage */ 147 + static int temperature_capture_sample(struct hid_sensor_hub_device *hsdev, 148 + unsigned int usage_id, size_t raw_len, 149 + char *raw_data, void *pdev) 150 + { 151 + struct iio_dev *indio_dev = platform_get_drvdata(pdev); 152 + struct temperature_state *temp_st = iio_priv(indio_dev); 153 + 154 + switch (usage_id) { 155 + case HID_USAGE_SENSOR_DATA_ENVIRONMENTAL_TEMPERATURE: 156 + temp_st->temperature_data = *(s32 *)raw_data; 157 + return 0; 158 + default: 159 + return -EINVAL; 160 + } 161 + } 162 + 163 + /* Parse report which is specific to an usage id*/ 164 + static int temperature_parse_report(struct platform_device *pdev, 165 + struct hid_sensor_hub_device *hsdev, 166 + struct iio_chan_spec *channels, 167 + unsigned int usage_id, 168 + struct temperature_state *st) 169 + { 170 + int ret; 171 + 172 + ret = sensor_hub_input_get_attribute_info(hsdev, HID_INPUT_REPORT, 173 + usage_id, 174 + HID_USAGE_SENSOR_DATA_ENVIRONMENTAL_TEMPERATURE, 175 + &st->temperature_attr); 176 + if (ret < 0) 177 + return ret; 178 + 179 + temperature_adjust_channel_bit_mask(channels, 0, 180 + st->temperature_attr.size); 181 + 182 + st->scale_precision = hid_sensor_format_scale( 183 + HID_USAGE_SENSOR_TEMPERATURE, 184 + &st->temperature_attr, 185 + &st->scale_pre_decml, &st->scale_post_decml); 186 + 187 + /* Set Sensitivity field ids, when there is no individual modifier */ 188 + if (st->common_attributes.sensitivity.index < 0) 189 + sensor_hub_input_get_attribute_info(hsdev, 190 + HID_FEATURE_REPORT, usage_id, 191 + HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS | 192 + HID_USAGE_SENSOR_DATA_ENVIRONMENTAL_TEMPERATURE, 193 + &st->common_attributes.sensitivity); 194 + 195 + return ret; 196 + } 197 + 198 + static struct hid_sensor_hub_callbacks temperature_callbacks = { 199 + .send_event = &temperature_proc_event, 200 + .capture_sample = &temperature_capture_sample, 201 + }; 202 + 203 + /* Function to initialize the processing for usage id */ 204 + static int hid_temperature_probe(struct platform_device *pdev) 205 + { 206 + static const char *name = "temperature"; 207 + struct iio_dev *indio_dev; 208 + struct temperature_state *temp_st; 209 + struct iio_chan_spec *temp_chans; 210 + struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev); 211 + int ret; 212 + 213 + indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*temp_st)); 214 + if (!indio_dev) 215 + return -ENOMEM; 216 + 217 + temp_st = iio_priv(indio_dev); 218 + temp_st->common_attributes.hsdev = hsdev; 219 + temp_st->common_attributes.pdev = pdev; 220 + 221 + ret = hid_sensor_parse_common_attributes(hsdev, 222 + HID_USAGE_SENSOR_TEMPERATURE, 223 + &temp_st->common_attributes); 224 + if (ret) 225 + return ret; 226 + 227 + temp_chans = devm_kmemdup(&indio_dev->dev, temperature_channels, 228 + sizeof(temperature_channels), GFP_KERNEL); 229 + if (!temp_chans) 230 + return -ENOMEM; 231 + 232 + ret = temperature_parse_report(pdev, hsdev, temp_chans, 233 + HID_USAGE_SENSOR_TEMPERATURE, temp_st); 234 + if (ret) 235 + return ret; 236 + 237 + indio_dev->channels = temp_chans; 238 + indio_dev->num_channels = ARRAY_SIZE(temperature_channels); 239 + indio_dev->dev.parent = &pdev->dev; 240 + indio_dev->info = &temperature_info; 241 + indio_dev->name = name; 242 + indio_dev->modes = INDIO_DIRECT_MODE; 243 + 244 + ret = devm_iio_triggered_buffer_setup(&pdev->dev, indio_dev, 245 + &iio_pollfunc_store_time, NULL, NULL); 246 + if (ret) 247 + return ret; 248 + 249 + atomic_set(&temp_st->common_attributes.data_ready, 0); 250 + ret = hid_sensor_setup_trigger(indio_dev, name, 251 + &temp_st->common_attributes); 252 + if (ret) 253 + return ret; 254 + 255 + platform_set_drvdata(pdev, indio_dev); 256 + 257 + temperature_callbacks.pdev = pdev; 258 + ret = sensor_hub_register_callback(hsdev, HID_USAGE_SENSOR_TEMPERATURE, 259 + &temperature_callbacks); 260 + if (ret) 261 + goto error_remove_trigger; 262 + 263 + ret = devm_iio_device_register(indio_dev->dev.parent, indio_dev); 264 + if (ret) 265 + goto error_remove_callback; 266 + 267 + return ret; 268 + 269 + error_remove_callback: 270 + sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_TEMPERATURE); 271 + error_remove_trigger: 272 + hid_sensor_remove_trigger(&temp_st->common_attributes); 273 + return ret; 274 + } 275 + 276 + /* Function to deinitialize the processing for usage id */ 277 + static int hid_temperature_remove(struct platform_device *pdev) 278 + { 279 + struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev); 280 + struct iio_dev *indio_dev = platform_get_drvdata(pdev); 281 + struct temperature_state *temp_st = iio_priv(indio_dev); 282 + 283 + sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_TEMPERATURE); 284 + hid_sensor_remove_trigger(&temp_st->common_attributes); 285 + 286 + return 0; 287 + } 288 + 289 + static const struct platform_device_id hid_temperature_ids[] = { 290 + { 291 + /* Format: HID-SENSOR-usage_id_in_hex_lowercase */ 292 + .name = "HID-SENSOR-200033", 293 + }, 294 + { /* sentinel */ } 295 + }; 296 + MODULE_DEVICE_TABLE(platform, hid_temperature_ids); 297 + 298 + static struct platform_driver hid_temperature_platform_driver = { 299 + .id_table = hid_temperature_ids, 300 + .driver = { 301 + .name = "temperature-sensor", 302 + .pm = &hid_sensor_pm_ops, 303 + }, 304 + .probe = hid_temperature_probe, 305 + .remove = hid_temperature_remove, 306 + }; 307 + module_platform_driver(hid_temperature_platform_driver); 308 + 309 + MODULE_DESCRIPTION("HID Environmental temperature sensor"); 310 + MODULE_AUTHOR("Song Hongyan <hongyan.song@intel.com>"); 311 + MODULE_LICENSE("GPL v2");
+1
drivers/iio/temperature/maxim_thermocouple.c
··· 231 231 indio_dev->available_scan_masks = chip->scan_masks; 232 232 indio_dev->num_channels = chip->num_channels; 233 233 indio_dev->modes = INDIO_DIRECT_MODE; 234 + indio_dev->dev.parent = &spi->dev; 234 235 235 236 data = iio_priv(indio_dev); 236 237 data->spi = spi;
+265 -12
drivers/iio/temperature/tmp007.c
··· 11 11 * 12 12 * (7-bit I2C slave address (0x40 - 0x47), changeable via ADR pins) 13 13 * 14 - * Note: This driver assumes that the sensor has been calibrated beforehand 15 - * 16 - * TODO: ALERT irq, limit threshold events 14 + * Note: 15 + * 1. This driver assumes that the sensor has been calibrated beforehand 16 + * 2. Limit threshold events are enabled at the start 17 + * 3. Operating mode: INT 17 18 * 18 19 */ 19 20 ··· 25 24 #include <linux/pm.h> 26 25 #include <linux/bitops.h> 27 26 #include <linux/of.h> 27 + #include <linux/irq.h> 28 + #include <linux/interrupt.h> 28 29 29 30 #include <linux/iio/iio.h> 30 31 #include <linux/iio/sysfs.h> 32 + #include <linux/iio/events.h> 31 33 32 34 #define TMP007_TDIE 0x01 33 35 #define TMP007_CONFIG 0x02 34 36 #define TMP007_TOBJECT 0x03 35 37 #define TMP007_STATUS 0x04 36 38 #define TMP007_STATUS_MASK 0x05 39 + #define TMP007_TOBJ_HIGH_LIMIT 0x06 40 + #define TMP007_TOBJ_LOW_LIMIT 0x07 41 + #define TMP007_TDIE_HIGH_LIMIT 0x08 42 + #define TMP007_TDIE_LOW_LIMIT 0x09 37 43 #define TMP007_MANUFACTURER_ID 0x1e 38 44 #define TMP007_DEVICE_ID 0x1f 39 45 40 46 #define TMP007_CONFIG_CONV_EN BIT(12) 41 - #define TMP007_CONFIG_COMP_EN BIT(5) 42 47 #define TMP007_CONFIG_TC_EN BIT(6) 43 48 #define TMP007_CONFIG_CR_MASK GENMASK(11, 9) 49 + #define TMP007_CONFIG_ALERT_EN BIT(8) 44 50 #define TMP007_CONFIG_CR_SHIFT 9 45 51 52 + /* Status register flags */ 53 + #define TMP007_STATUS_ALERT BIT(15) 46 54 #define TMP007_STATUS_CONV_READY BIT(14) 55 + #define TMP007_STATUS_OHF BIT(13) 56 + #define TMP007_STATUS_OLF BIT(12) 57 + #define TMP007_STATUS_LHF BIT(11) 58 + #define TMP007_STATUS_LLF BIT(10) 47 59 #define TMP007_STATUS_DATA_VALID BIT(9) 48 60 49 61 #define TMP007_MANUFACTURER_MAGIC 0x5449 ··· 66 52 67 53 struct tmp007_data { 68 54 struct i2c_client *client; 55 + struct mutex lock; 69 56 u16 config; 57 + u16 status_mask; 70 58 }; 71 59 72 60 static const int tmp007_avgs[5][2] = { {4, 0}, {2, 0}, {1, 0}, ··· 172 156 return -EINVAL; 173 157 } 174 158 159 + static irqreturn_t tmp007_interrupt_handler(int irq, void *private) 160 + { 161 + struct iio_dev *indio_dev = private; 162 + struct tmp007_data *data = iio_priv(indio_dev); 163 + int ret; 164 + 165 + ret = i2c_smbus_read_word_swapped(data->client, TMP007_STATUS); 166 + if ((ret < 0) || !(ret & (TMP007_STATUS_OHF | TMP007_STATUS_OLF | 167 + TMP007_STATUS_LHF | TMP007_STATUS_LLF))) 168 + return IRQ_NONE; 169 + 170 + if (ret & TMP007_STATUS_OHF) 171 + iio_push_event(indio_dev, 172 + IIO_MOD_EVENT_CODE(IIO_TEMP, 0, 173 + IIO_MOD_TEMP_OBJECT, 174 + IIO_EV_TYPE_THRESH, 175 + IIO_EV_DIR_RISING), 176 + iio_get_time_ns(indio_dev)); 177 + 178 + if (ret & TMP007_STATUS_OLF) 179 + iio_push_event(indio_dev, 180 + IIO_MOD_EVENT_CODE(IIO_TEMP, 0, 181 + IIO_MOD_TEMP_OBJECT, 182 + IIO_EV_TYPE_THRESH, 183 + IIO_EV_DIR_FALLING), 184 + iio_get_time_ns(indio_dev)); 185 + 186 + if (ret & TMP007_STATUS_LHF) 187 + iio_push_event(indio_dev, 188 + IIO_MOD_EVENT_CODE(IIO_TEMP, 0, 189 + IIO_MOD_TEMP_AMBIENT, 190 + IIO_EV_TYPE_THRESH, 191 + IIO_EV_DIR_RISING), 192 + iio_get_time_ns(indio_dev)); 193 + 194 + if (ret & TMP007_STATUS_LLF) 195 + iio_push_event(indio_dev, 196 + IIO_MOD_EVENT_CODE(IIO_TEMP, 0, 197 + IIO_MOD_TEMP_AMBIENT, 198 + IIO_EV_TYPE_THRESH, 199 + IIO_EV_DIR_FALLING), 200 + iio_get_time_ns(indio_dev)); 201 + 202 + return IRQ_HANDLED; 203 + } 204 + 205 + static int tmp007_write_event_config(struct iio_dev *indio_dev, 206 + const struct iio_chan_spec *chan, enum iio_event_type type, 207 + enum iio_event_direction dir, int state) 208 + { 209 + struct tmp007_data *data = iio_priv(indio_dev); 210 + unsigned int status_mask; 211 + int ret; 212 + 213 + switch (chan->channel2) { 214 + case IIO_MOD_TEMP_AMBIENT: 215 + if (dir == IIO_EV_DIR_RISING) 216 + status_mask = TMP007_STATUS_LHF; 217 + else 218 + status_mask = TMP007_STATUS_LLF; 219 + break; 220 + case IIO_MOD_TEMP_OBJECT: 221 + if (dir == IIO_EV_DIR_RISING) 222 + status_mask = TMP007_STATUS_OHF; 223 + else 224 + status_mask = TMP007_STATUS_OLF; 225 + break; 226 + default: 227 + return -EINVAL; 228 + } 229 + 230 + mutex_lock(&data->lock); 231 + ret = i2c_smbus_read_word_swapped(data->client, TMP007_STATUS_MASK); 232 + mutex_unlock(&data->lock); 233 + if (ret < 0) 234 + return ret; 235 + 236 + if (state) 237 + ret |= status_mask; 238 + else 239 + ret &= ~status_mask; 240 + 241 + return i2c_smbus_write_word_swapped(data->client, TMP007_STATUS_MASK, 242 + data->status_mask = ret); 243 + } 244 + 245 + static int tmp007_read_event_config(struct iio_dev *indio_dev, 246 + const struct iio_chan_spec *chan, enum iio_event_type type, 247 + enum iio_event_direction dir) 248 + { 249 + struct tmp007_data *data = iio_priv(indio_dev); 250 + unsigned int mask; 251 + 252 + switch (chan->channel2) { 253 + case IIO_MOD_TEMP_AMBIENT: 254 + if (dir == IIO_EV_DIR_RISING) 255 + mask = TMP007_STATUS_LHF; 256 + else 257 + mask = TMP007_STATUS_LLF; 258 + break; 259 + case IIO_MOD_TEMP_OBJECT: 260 + if (dir == IIO_EV_DIR_RISING) 261 + mask = TMP007_STATUS_OHF; 262 + else 263 + mask = TMP007_STATUS_OLF; 264 + break; 265 + default: 266 + return -EINVAL; 267 + } 268 + 269 + return !!(data->status_mask & mask); 270 + } 271 + 272 + static int tmp007_read_thresh(struct iio_dev *indio_dev, 273 + const struct iio_chan_spec *chan, enum iio_event_type type, 274 + enum iio_event_direction dir, enum iio_event_info info, 275 + int *val, int *val2) 276 + { 277 + struct tmp007_data *data = iio_priv(indio_dev); 278 + int ret; 279 + u8 reg; 280 + 281 + switch (chan->channel2) { 282 + case IIO_MOD_TEMP_AMBIENT: /* LSB: 0.5 degree Celsius */ 283 + if (dir == IIO_EV_DIR_RISING) 284 + reg = TMP007_TDIE_HIGH_LIMIT; 285 + else 286 + reg = TMP007_TDIE_LOW_LIMIT; 287 + break; 288 + case IIO_MOD_TEMP_OBJECT: 289 + if (dir == IIO_EV_DIR_RISING) 290 + reg = TMP007_TOBJ_HIGH_LIMIT; 291 + else 292 + reg = TMP007_TOBJ_LOW_LIMIT; 293 + break; 294 + default: 295 + return -EINVAL; 296 + } 297 + 298 + ret = i2c_smbus_read_word_swapped(data->client, reg); 299 + if (ret < 0) 300 + return ret; 301 + 302 + /* Shift length 7 bits = 6(15:6) + 1(0.5 LSB) */ 303 + *val = sign_extend32(ret, 15) >> 7; 304 + 305 + return IIO_VAL_INT; 306 + } 307 + 308 + static int tmp007_write_thresh(struct iio_dev *indio_dev, 309 + const struct iio_chan_spec *chan, enum iio_event_type type, 310 + enum iio_event_direction dir, enum iio_event_info info, 311 + int val, int val2) 312 + { 313 + struct tmp007_data *data = iio_priv(indio_dev); 314 + u8 reg; 315 + 316 + switch (chan->channel2) { 317 + case IIO_MOD_TEMP_AMBIENT: 318 + if (dir == IIO_EV_DIR_RISING) 319 + reg = TMP007_TDIE_HIGH_LIMIT; 320 + else 321 + reg = TMP007_TDIE_LOW_LIMIT; 322 + break; 323 + case IIO_MOD_TEMP_OBJECT: 324 + if (dir == IIO_EV_DIR_RISING) 325 + reg = TMP007_TOBJ_HIGH_LIMIT; 326 + else 327 + reg = TMP007_TOBJ_LOW_LIMIT; 328 + break; 329 + default: 330 + return -EINVAL; 331 + } 332 + 333 + /* Full scale threshold value is +/- 256 degree Celsius */ 334 + if (val < -256 || val > 255) 335 + return -EINVAL; 336 + 337 + /* Shift length 7 bits = 6(15:6) + 1(0.5 LSB) */ 338 + return i2c_smbus_write_word_swapped(data->client, reg, (val << 7)); 339 + } 340 + 175 341 static IIO_CONST_ATTR(sampling_frequency_available, "4 2 1 0.5 0.25"); 176 342 177 343 static struct attribute *tmp007_attributes[] = { ··· 365 167 .attrs = tmp007_attributes, 366 168 }; 367 169 170 + static const struct iio_event_spec tmp007_obj_event[] = { 171 + { 172 + .type = IIO_EV_TYPE_THRESH, 173 + .dir = IIO_EV_DIR_RISING, 174 + .mask_separate = BIT(IIO_EV_INFO_VALUE) | 175 + BIT(IIO_EV_INFO_ENABLE), 176 + }, 177 + { 178 + .type = IIO_EV_TYPE_THRESH, 179 + .dir = IIO_EV_DIR_FALLING, 180 + .mask_separate = BIT(IIO_EV_INFO_VALUE) | 181 + BIT(IIO_EV_INFO_ENABLE), 182 + }, 183 + }; 184 + 185 + static const struct iio_event_spec tmp007_die_event[] = { 186 + { 187 + .type = IIO_EV_TYPE_THRESH, 188 + .dir = IIO_EV_DIR_RISING, 189 + .mask_separate = BIT(IIO_EV_INFO_VALUE) | 190 + BIT(IIO_EV_INFO_ENABLE), 191 + }, 192 + { 193 + .type = IIO_EV_TYPE_THRESH, 194 + .dir = IIO_EV_DIR_FALLING, 195 + .mask_separate = BIT(IIO_EV_INFO_VALUE) | 196 + BIT(IIO_EV_INFO_ENABLE), 197 + }, 198 + }; 199 + 368 200 static const struct iio_chan_spec tmp007_channels[] = { 369 201 { 370 202 .type = IIO_TEMP, ··· 403 175 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 404 176 BIT(IIO_CHAN_INFO_SCALE), 405 177 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), 178 + .event_spec = tmp007_die_event, 179 + .num_event_specs = ARRAY_SIZE(tmp007_die_event), 406 180 }, 407 181 { 408 182 .type = IIO_TEMP, ··· 413 183 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | 414 184 BIT(IIO_CHAN_INFO_SCALE), 415 185 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), 186 + .event_spec = tmp007_obj_event, 187 + .num_event_specs = ARRAY_SIZE(tmp007_obj_event), 416 188 } 417 189 }; 418 190 419 191 static const struct iio_info tmp007_info = { 420 192 .read_raw = tmp007_read_raw, 421 193 .write_raw = tmp007_write_raw, 194 + .read_event_config = tmp007_read_event_config, 195 + .write_event_config = tmp007_write_event_config, 196 + .read_event_value = tmp007_read_thresh, 197 + .write_event_value = tmp007_write_thresh, 422 198 .attrs = &tmp007_attribute_group, 423 199 .driver_module = THIS_MODULE, 424 200 }; ··· 450 214 struct tmp007_data *data; 451 215 struct iio_dev *indio_dev; 452 216 int ret; 453 - u16 status; 454 217 455 218 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA)) 456 219 return -EOPNOTSUPP; ··· 466 231 data = iio_priv(indio_dev); 467 232 i2c_set_clientdata(client, indio_dev); 468 233 data->client = client; 234 + mutex_init(&data->lock); 469 235 470 236 indio_dev->dev.parent = &client->dev; 471 237 indio_dev->name = "tmp007"; ··· 479 243 /* 480 244 * Set Configuration register: 481 245 * 1. Conversion ON 482 - * 2. Comparator mode 246 + * 2. ALERT enable 483 247 * 3. Transient correction enable 484 248 */ 485 249 ··· 488 252 return ret; 489 253 490 254 data->config = ret; 491 - data->config |= (TMP007_CONFIG_CONV_EN | TMP007_CONFIG_COMP_EN | TMP007_CONFIG_TC_EN); 255 + data->config |= (TMP007_CONFIG_CONV_EN | TMP007_CONFIG_ALERT_EN | TMP007_CONFIG_TC_EN); 492 256 493 257 ret = i2c_smbus_write_word_swapped(data->client, TMP007_CONFIG, 494 258 data->config); ··· 496 260 return ret; 497 261 498 262 /* 263 + * Only the following flags can activate ALERT pin. Data conversion/validity flags 264 + * flags can still be polled for getting temperature data 265 + * 499 266 * Set Status Mask register: 500 - * 1. Conversion ready enable 501 - * 2. Data valid enable 267 + * 1. Object temperature high limit enable 268 + * 2. Object temperature low limit enable 269 + * 3. TDIE temperature high limit enable 270 + * 4. TDIE temperature low limit enable 502 271 */ 503 272 504 273 ret = i2c_smbus_read_word_swapped(data->client, TMP007_STATUS_MASK); 505 274 if (ret < 0) 506 275 goto error_powerdown; 507 276 508 - status = ret; 509 - status |= (TMP007_STATUS_CONV_READY | TMP007_STATUS_DATA_VALID); 277 + data->status_mask = ret; 278 + data->status_mask |= (TMP007_STATUS_OHF | TMP007_STATUS_OLF 279 + | TMP007_STATUS_LHF | TMP007_STATUS_LLF); 510 280 511 - ret = i2c_smbus_write_word_swapped(data->client, TMP007_STATUS_MASK, status); 281 + ret = i2c_smbus_write_word_swapped(data->client, TMP007_STATUS_MASK, data->status_mask); 512 282 if (ret < 0) 513 283 goto error_powerdown; 284 + 285 + if (client->irq) { 286 + ret = devm_request_threaded_irq(&client->dev, client->irq, 287 + NULL, tmp007_interrupt_handler, 288 + IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 289 + tmp007_id->name, indio_dev); 290 + if (ret) { 291 + dev_err(&client->dev, "irq request error %d\n", -ret); 292 + goto error_powerdown; 293 + } 294 + } 514 295 515 296 return iio_device_register(indio_dev); 516 297
-7
drivers/staging/iio/accel/Makefile
··· 2 2 # Makefile for industrial I/O accelerometer drivers 3 3 # 4 4 5 - adis16201-y := adis16201_core.o 6 5 obj-$(CONFIG_ADIS16201) += adis16201.o 7 - 8 - adis16203-y := adis16203_core.o 9 6 obj-$(CONFIG_ADIS16203) += adis16203.o 10 - 11 - adis16209-y := adis16209_core.o 12 7 obj-$(CONFIG_ADIS16209) += adis16209.o 13 - 14 - adis16240-y := adis16240_core.o 15 8 obj-$(CONFIG_ADIS16240) += adis16240.o
-144
drivers/staging/iio/accel/adis16201.h
··· 1 - #ifndef SPI_ADIS16201_H_ 2 - #define SPI_ADIS16201_H_ 3 - 4 - #define ADIS16201_STARTUP_DELAY 220 /* ms */ 5 - 6 - /* Flash memory write count */ 7 - #define ADIS16201_FLASH_CNT 0x00 8 - 9 - /* Output, power supply */ 10 - #define ADIS16201_SUPPLY_OUT 0x02 11 - 12 - /* Output, x-axis accelerometer */ 13 - #define ADIS16201_XACCL_OUT 0x04 14 - 15 - /* Output, y-axis accelerometer */ 16 - #define ADIS16201_YACCL_OUT 0x06 17 - 18 - /* Output, auxiliary ADC input */ 19 - #define ADIS16201_AUX_ADC 0x08 20 - 21 - /* Output, temperature */ 22 - #define ADIS16201_TEMP_OUT 0x0A 23 - 24 - /* Output, x-axis inclination */ 25 - #define ADIS16201_XINCL_OUT 0x0C 26 - 27 - /* Output, y-axis inclination */ 28 - #define ADIS16201_YINCL_OUT 0x0E 29 - 30 - /* Calibration, x-axis acceleration offset */ 31 - #define ADIS16201_XACCL_OFFS 0x10 32 - 33 - /* Calibration, y-axis acceleration offset */ 34 - #define ADIS16201_YACCL_OFFS 0x12 35 - 36 - /* x-axis acceleration scale factor */ 37 - #define ADIS16201_XACCL_SCALE 0x14 38 - 39 - /* y-axis acceleration scale factor */ 40 - #define ADIS16201_YACCL_SCALE 0x16 41 - 42 - /* Calibration, x-axis inclination offset */ 43 - #define ADIS16201_XINCL_OFFS 0x18 44 - 45 - /* Calibration, y-axis inclination offset */ 46 - #define ADIS16201_YINCL_OFFS 0x1A 47 - 48 - /* x-axis inclination scale factor */ 49 - #define ADIS16201_XINCL_SCALE 0x1C 50 - 51 - /* y-axis inclination scale factor */ 52 - #define ADIS16201_YINCL_SCALE 0x1E 53 - 54 - /* Alarm 1 amplitude threshold */ 55 - #define ADIS16201_ALM_MAG1 0x20 56 - 57 - /* Alarm 2 amplitude threshold */ 58 - #define ADIS16201_ALM_MAG2 0x22 59 - 60 - /* Alarm 1, sample period */ 61 - #define ADIS16201_ALM_SMPL1 0x24 62 - 63 - /* Alarm 2, sample period */ 64 - #define ADIS16201_ALM_SMPL2 0x26 65 - 66 - /* Alarm control */ 67 - #define ADIS16201_ALM_CTRL 0x28 68 - 69 - /* Auxiliary DAC data */ 70 - #define ADIS16201_AUX_DAC 0x30 71 - 72 - /* General-purpose digital input/output control */ 73 - #define ADIS16201_GPIO_CTRL 0x32 74 - 75 - /* Miscellaneous control */ 76 - #define ADIS16201_MSC_CTRL 0x34 77 - 78 - /* Internal sample period (rate) control */ 79 - #define ADIS16201_SMPL_PRD 0x36 80 - 81 - /* Operation, filter configuration */ 82 - #define ADIS16201_AVG_CNT 0x38 83 - 84 - /* Operation, sleep mode control */ 85 - #define ADIS16201_SLP_CNT 0x3A 86 - 87 - /* Diagnostics, system status register */ 88 - #define ADIS16201_DIAG_STAT 0x3C 89 - 90 - /* Operation, system command register */ 91 - #define ADIS16201_GLOB_CMD 0x3E 92 - 93 - /* MSC_CTRL */ 94 - 95 - /* Self-test enable */ 96 - #define ADIS16201_MSC_CTRL_SELF_TEST_EN BIT(8) 97 - 98 - /* Data-ready enable: 1 = enabled, 0 = disabled */ 99 - #define ADIS16201_MSC_CTRL_DATA_RDY_EN BIT(2) 100 - 101 - /* Data-ready polarity: 1 = active high, 0 = active low */ 102 - #define ADIS16201_MSC_CTRL_ACTIVE_HIGH BIT(1) 103 - 104 - /* Data-ready line selection: 1 = DIO1, 0 = DIO0 */ 105 - #define ADIS16201_MSC_CTRL_DATA_RDY_DIO1 BIT(0) 106 - 107 - /* DIAG_STAT */ 108 - 109 - /* Alarm 2 status: 1 = alarm active, 0 = alarm inactive */ 110 - #define ADIS16201_DIAG_STAT_ALARM2 BIT(9) 111 - 112 - /* Alarm 1 status: 1 = alarm active, 0 = alarm inactive */ 113 - #define ADIS16201_DIAG_STAT_ALARM1 BIT(8) 114 - 115 - /* SPI communications failure */ 116 - #define ADIS16201_DIAG_STAT_SPI_FAIL_BIT 3 117 - 118 - /* Flash update failure */ 119 - #define ADIS16201_DIAG_STAT_FLASH_UPT_BIT 2 120 - 121 - /* Power supply above 3.625 V */ 122 - #define ADIS16201_DIAG_STAT_POWER_HIGH_BIT 1 123 - 124 - /* Power supply below 3.15 V */ 125 - #define ADIS16201_DIAG_STAT_POWER_LOW_BIT 0 126 - 127 - /* GLOB_CMD */ 128 - 129 - #define ADIS16201_GLOB_CMD_SW_RESET BIT(7) 130 - #define ADIS16201_GLOB_CMD_FACTORY_CAL BIT(1) 131 - 132 - #define ADIS16201_ERROR_ACTIVE BIT(14) 133 - 134 - enum adis16201_scan { 135 - ADIS16201_SCAN_ACC_X, 136 - ADIS16201_SCAN_ACC_Y, 137 - ADIS16201_SCAN_INCLI_X, 138 - ADIS16201_SCAN_INCLI_Y, 139 - ADIS16201_SCAN_SUPPLY, 140 - ADIS16201_SCAN_AUX_ADC, 141 - ADIS16201_SCAN_TEMP, 142 - }; 143 - 144 - #endif /* SPI_ADIS16201_H_ */
+139 -1
drivers/staging/iio/accel/adis16201_core.c drivers/staging/iio/accel/adis16201.c
··· 20 20 #include <linux/iio/buffer.h> 21 21 #include <linux/iio/imu/adis.h> 22 22 23 - #include "adis16201.h" 23 + #define ADIS16201_STARTUP_DELAY 220 /* ms */ 24 + 25 + /* Flash memory write count */ 26 + #define ADIS16201_FLASH_CNT 0x00 27 + 28 + /* Output, power supply */ 29 + #define ADIS16201_SUPPLY_OUT 0x02 30 + 31 + /* Output, x-axis accelerometer */ 32 + #define ADIS16201_XACCL_OUT 0x04 33 + 34 + /* Output, y-axis accelerometer */ 35 + #define ADIS16201_YACCL_OUT 0x06 36 + 37 + /* Output, auxiliary ADC input */ 38 + #define ADIS16201_AUX_ADC 0x08 39 + 40 + /* Output, temperature */ 41 + #define ADIS16201_TEMP_OUT 0x0A 42 + 43 + /* Output, x-axis inclination */ 44 + #define ADIS16201_XINCL_OUT 0x0C 45 + 46 + /* Output, y-axis inclination */ 47 + #define ADIS16201_YINCL_OUT 0x0E 48 + 49 + /* Calibration, x-axis acceleration offset */ 50 + #define ADIS16201_XACCL_OFFS 0x10 51 + 52 + /* Calibration, y-axis acceleration offset */ 53 + #define ADIS16201_YACCL_OFFS 0x12 54 + 55 + /* x-axis acceleration scale factor */ 56 + #define ADIS16201_XACCL_SCALE 0x14 57 + 58 + /* y-axis acceleration scale factor */ 59 + #define ADIS16201_YACCL_SCALE 0x16 60 + 61 + /* Calibration, x-axis inclination offset */ 62 + #define ADIS16201_XINCL_OFFS 0x18 63 + 64 + /* Calibration, y-axis inclination offset */ 65 + #define ADIS16201_YINCL_OFFS 0x1A 66 + 67 + /* x-axis inclination scale factor */ 68 + #define ADIS16201_XINCL_SCALE 0x1C 69 + 70 + /* y-axis inclination scale factor */ 71 + #define ADIS16201_YINCL_SCALE 0x1E 72 + 73 + /* Alarm 1 amplitude threshold */ 74 + #define ADIS16201_ALM_MAG1 0x20 75 + 76 + /* Alarm 2 amplitude threshold */ 77 + #define ADIS16201_ALM_MAG2 0x22 78 + 79 + /* Alarm 1, sample period */ 80 + #define ADIS16201_ALM_SMPL1 0x24 81 + 82 + /* Alarm 2, sample period */ 83 + #define ADIS16201_ALM_SMPL2 0x26 84 + 85 + /* Alarm control */ 86 + #define ADIS16201_ALM_CTRL 0x28 87 + 88 + /* Auxiliary DAC data */ 89 + #define ADIS16201_AUX_DAC 0x30 90 + 91 + /* General-purpose digital input/output control */ 92 + #define ADIS16201_GPIO_CTRL 0x32 93 + 94 + /* Miscellaneous control */ 95 + #define ADIS16201_MSC_CTRL 0x34 96 + 97 + /* Internal sample period (rate) control */ 98 + #define ADIS16201_SMPL_PRD 0x36 99 + 100 + /* Operation, filter configuration */ 101 + #define ADIS16201_AVG_CNT 0x38 102 + 103 + /* Operation, sleep mode control */ 104 + #define ADIS16201_SLP_CNT 0x3A 105 + 106 + /* Diagnostics, system status register */ 107 + #define ADIS16201_DIAG_STAT 0x3C 108 + 109 + /* Operation, system command register */ 110 + #define ADIS16201_GLOB_CMD 0x3E 111 + 112 + /* MSC_CTRL */ 113 + 114 + /* Self-test enable */ 115 + #define ADIS16201_MSC_CTRL_SELF_TEST_EN BIT(8) 116 + 117 + /* Data-ready enable: 1 = enabled, 0 = disabled */ 118 + #define ADIS16201_MSC_CTRL_DATA_RDY_EN BIT(2) 119 + 120 + /* Data-ready polarity: 1 = active high, 0 = active low */ 121 + #define ADIS16201_MSC_CTRL_ACTIVE_HIGH BIT(1) 122 + 123 + /* Data-ready line selection: 1 = DIO1, 0 = DIO0 */ 124 + #define ADIS16201_MSC_CTRL_DATA_RDY_DIO1 BIT(0) 125 + 126 + /* DIAG_STAT */ 127 + 128 + /* Alarm 2 status: 1 = alarm active, 0 = alarm inactive */ 129 + #define ADIS16201_DIAG_STAT_ALARM2 BIT(9) 130 + 131 + /* Alarm 1 status: 1 = alarm active, 0 = alarm inactive */ 132 + #define ADIS16201_DIAG_STAT_ALARM1 BIT(8) 133 + 134 + /* SPI communications failure */ 135 + #define ADIS16201_DIAG_STAT_SPI_FAIL_BIT 3 136 + 137 + /* Flash update failure */ 138 + #define ADIS16201_DIAG_STAT_FLASH_UPT_BIT 2 139 + 140 + /* Power supply above 3.625 V */ 141 + #define ADIS16201_DIAG_STAT_POWER_HIGH_BIT 1 142 + 143 + /* Power supply below 3.15 V */ 144 + #define ADIS16201_DIAG_STAT_POWER_LOW_BIT 0 145 + 146 + /* GLOB_CMD */ 147 + 148 + #define ADIS16201_GLOB_CMD_SW_RESET BIT(7) 149 + #define ADIS16201_GLOB_CMD_FACTORY_CAL BIT(1) 150 + 151 + #define ADIS16201_ERROR_ACTIVE BIT(14) 152 + 153 + enum adis16201_scan { 154 + ADIS16201_SCAN_ACC_X, 155 + ADIS16201_SCAN_ACC_Y, 156 + ADIS16201_SCAN_INCLI_X, 157 + ADIS16201_SCAN_INCLI_Y, 158 + ADIS16201_SCAN_SUPPLY, 159 + ADIS16201_SCAN_AUX_ADC, 160 + ADIS16201_SCAN_TEMP, 161 + }; 24 162 25 163 static const u8 adis16201_addresses[] = { 26 164 [ADIS16201_SCAN_ACC_X] = ADIS16201_XACCL_OFFS,
-125
drivers/staging/iio/accel/adis16203.h
··· 1 - #ifndef SPI_ADIS16203_H_ 2 - #define SPI_ADIS16203_H_ 3 - 4 - #define ADIS16203_STARTUP_DELAY 220 /* ms */ 5 - 6 - /* Flash memory write count */ 7 - #define ADIS16203_FLASH_CNT 0x00 8 - 9 - /* Output, power supply */ 10 - #define ADIS16203_SUPPLY_OUT 0x02 11 - 12 - /* Output, auxiliary ADC input */ 13 - #define ADIS16203_AUX_ADC 0x08 14 - 15 - /* Output, temperature */ 16 - #define ADIS16203_TEMP_OUT 0x0A 17 - 18 - /* Output, x-axis inclination */ 19 - #define ADIS16203_XINCL_OUT 0x0C 20 - 21 - /* Output, y-axis inclination */ 22 - #define ADIS16203_YINCL_OUT 0x0E 23 - 24 - /* Incline null calibration */ 25 - #define ADIS16203_INCL_NULL 0x18 26 - 27 - /* Alarm 1 amplitude threshold */ 28 - #define ADIS16203_ALM_MAG1 0x20 29 - 30 - /* Alarm 2 amplitude threshold */ 31 - #define ADIS16203_ALM_MAG2 0x22 32 - 33 - /* Alarm 1, sample period */ 34 - #define ADIS16203_ALM_SMPL1 0x24 35 - 36 - /* Alarm 2, sample period */ 37 - #define ADIS16203_ALM_SMPL2 0x26 38 - 39 - /* Alarm control */ 40 - #define ADIS16203_ALM_CTRL 0x28 41 - 42 - /* Auxiliary DAC data */ 43 - #define ADIS16203_AUX_DAC 0x30 44 - 45 - /* General-purpose digital input/output control */ 46 - #define ADIS16203_GPIO_CTRL 0x32 47 - 48 - /* Miscellaneous control */ 49 - #define ADIS16203_MSC_CTRL 0x34 50 - 51 - /* Internal sample period (rate) control */ 52 - #define ADIS16203_SMPL_PRD 0x36 53 - 54 - /* Operation, filter configuration */ 55 - #define ADIS16203_AVG_CNT 0x38 56 - 57 - /* Operation, sleep mode control */ 58 - #define ADIS16203_SLP_CNT 0x3A 59 - 60 - /* Diagnostics, system status register */ 61 - #define ADIS16203_DIAG_STAT 0x3C 62 - 63 - /* Operation, system command register */ 64 - #define ADIS16203_GLOB_CMD 0x3E 65 - 66 - /* MSC_CTRL */ 67 - 68 - /* Self-test at power-on: 1 = disabled, 0 = enabled */ 69 - #define ADIS16203_MSC_CTRL_PWRUP_SELF_TEST BIT(10) 70 - 71 - /* Reverses rotation of both inclination outputs */ 72 - #define ADIS16203_MSC_CTRL_REVERSE_ROT_EN BIT(9) 73 - 74 - /* Self-test enable */ 75 - #define ADIS16203_MSC_CTRL_SELF_TEST_EN BIT(8) 76 - 77 - /* Data-ready enable: 1 = enabled, 0 = disabled */ 78 - #define ADIS16203_MSC_CTRL_DATA_RDY_EN BIT(2) 79 - 80 - /* Data-ready polarity: 1 = active high, 0 = active low */ 81 - #define ADIS16203_MSC_CTRL_ACTIVE_HIGH BIT(1) 82 - 83 - /* Data-ready line selection: 1 = DIO1, 0 = DIO0 */ 84 - #define ADIS16203_MSC_CTRL_DATA_RDY_DIO1 BIT(0) 85 - 86 - /* DIAG_STAT */ 87 - 88 - /* Alarm 2 status: 1 = alarm active, 0 = alarm inactive */ 89 - #define ADIS16203_DIAG_STAT_ALARM2 BIT(9) 90 - 91 - /* Alarm 1 status: 1 = alarm active, 0 = alarm inactive */ 92 - #define ADIS16203_DIAG_STAT_ALARM1 BIT(8) 93 - 94 - /* Self-test diagnostic error flag */ 95 - #define ADIS16203_DIAG_STAT_SELFTEST_FAIL_BIT 5 96 - 97 - /* SPI communications failure */ 98 - #define ADIS16203_DIAG_STAT_SPI_FAIL_BIT 3 99 - 100 - /* Flash update failure */ 101 - #define ADIS16203_DIAG_STAT_FLASH_UPT_BIT 2 102 - 103 - /* Power supply above 3.625 V */ 104 - #define ADIS16203_DIAG_STAT_POWER_HIGH_BIT 1 105 - 106 - /* Power supply below 3.15 V */ 107 - #define ADIS16203_DIAG_STAT_POWER_LOW_BIT 0 108 - 109 - /* GLOB_CMD */ 110 - 111 - #define ADIS16203_GLOB_CMD_SW_RESET BIT(7) 112 - #define ADIS16203_GLOB_CMD_CLEAR_STAT BIT(4) 113 - #define ADIS16203_GLOB_CMD_FACTORY_CAL BIT(1) 114 - 115 - #define ADIS16203_ERROR_ACTIVE BIT(14) 116 - 117 - enum adis16203_scan { 118 - ADIS16203_SCAN_INCLI_X, 119 - ADIS16203_SCAN_INCLI_Y, 120 - ADIS16203_SCAN_SUPPLY, 121 - ADIS16203_SCAN_AUX_ADC, 122 - ADIS16203_SCAN_TEMP, 123 - }; 124 - 125 - #endif /* SPI_ADIS16203_H_ */
+129 -9
drivers/staging/iio/accel/adis16203_core.c drivers/staging/iio/accel/adis16203.c
··· 7 7 */ 8 8 9 9 #include <linux/delay.h> 10 - #include <linux/mutex.h> 11 10 #include <linux/device.h> 12 - #include <linux/kernel.h> 13 - #include <linux/spi/spi.h> 14 - #include <linux/slab.h> 15 - #include <linux/sysfs.h> 16 - #include <linux/module.h> 17 11 18 - #include <linux/iio/iio.h> 19 - #include <linux/iio/sysfs.h> 20 12 #include <linux/iio/buffer.h> 13 + #include <linux/iio/iio.h> 21 14 #include <linux/iio/imu/adis.h> 15 + #include <linux/iio/sysfs.h> 22 16 23 - #include "adis16203.h" 17 + #include <linux/kernel.h> 18 + #include <linux/module.h> 19 + #include <linux/mutex.h> 20 + #include <linux/slab.h> 21 + #include <linux/spi/spi.h> 22 + #include <linux/sysfs.h> 23 + 24 + #define ADIS16203_STARTUP_DELAY 220 /* ms */ 25 + 26 + /* Flash memory write count */ 27 + #define ADIS16203_FLASH_CNT 0x00 28 + 29 + /* Output, power supply */ 30 + #define ADIS16203_SUPPLY_OUT 0x02 31 + 32 + /* Output, auxiliary ADC input */ 33 + #define ADIS16203_AUX_ADC 0x08 34 + 35 + /* Output, temperature */ 36 + #define ADIS16203_TEMP_OUT 0x0A 37 + 38 + /* Output, x-axis inclination */ 39 + #define ADIS16203_XINCL_OUT 0x0C 40 + 41 + /* Output, y-axis inclination */ 42 + #define ADIS16203_YINCL_OUT 0x0E 43 + 44 + /* Incline null calibration */ 45 + #define ADIS16203_INCL_NULL 0x18 46 + 47 + /* Alarm 1 amplitude threshold */ 48 + #define ADIS16203_ALM_MAG1 0x20 49 + 50 + /* Alarm 2 amplitude threshold */ 51 + #define ADIS16203_ALM_MAG2 0x22 52 + 53 + /* Alarm 1, sample period */ 54 + #define ADIS16203_ALM_SMPL1 0x24 55 + 56 + /* Alarm 2, sample period */ 57 + #define ADIS16203_ALM_SMPL2 0x26 58 + 59 + /* Alarm control */ 60 + #define ADIS16203_ALM_CTRL 0x28 61 + 62 + /* Auxiliary DAC data */ 63 + #define ADIS16203_AUX_DAC 0x30 64 + 65 + /* General-purpose digital input/output control */ 66 + #define ADIS16203_GPIO_CTRL 0x32 67 + 68 + /* Miscellaneous control */ 69 + #define ADIS16203_MSC_CTRL 0x34 70 + 71 + /* Internal sample period (rate) control */ 72 + #define ADIS16203_SMPL_PRD 0x36 73 + 74 + /* Operation, filter configuration */ 75 + #define ADIS16203_AVG_CNT 0x38 76 + 77 + /* Operation, sleep mode control */ 78 + #define ADIS16203_SLP_CNT 0x3A 79 + 80 + /* Diagnostics, system status register */ 81 + #define ADIS16203_DIAG_STAT 0x3C 82 + 83 + /* Operation, system command register */ 84 + #define ADIS16203_GLOB_CMD 0x3E 85 + 86 + /* MSC_CTRL */ 87 + 88 + /* Self-test at power-on: 1 = disabled, 0 = enabled */ 89 + #define ADIS16203_MSC_CTRL_PWRUP_SELF_TEST BIT(10) 90 + 91 + /* Reverses rotation of both inclination outputs */ 92 + #define ADIS16203_MSC_CTRL_REVERSE_ROT_EN BIT(9) 93 + 94 + /* Self-test enable */ 95 + #define ADIS16203_MSC_CTRL_SELF_TEST_EN BIT(8) 96 + 97 + /* Data-ready enable: 1 = enabled, 0 = disabled */ 98 + #define ADIS16203_MSC_CTRL_DATA_RDY_EN BIT(2) 99 + 100 + /* Data-ready polarity: 1 = active high, 0 = active low */ 101 + #define ADIS16203_MSC_CTRL_ACTIVE_HIGH BIT(1) 102 + 103 + /* Data-ready line selection: 1 = DIO1, 0 = DIO0 */ 104 + #define ADIS16203_MSC_CTRL_DATA_RDY_DIO1 BIT(0) 105 + 106 + /* DIAG_STAT */ 107 + 108 + /* Alarm 2 status: 1 = alarm active, 0 = alarm inactive */ 109 + #define ADIS16203_DIAG_STAT_ALARM2 BIT(9) 110 + 111 + /* Alarm 1 status: 1 = alarm active, 0 = alarm inactive */ 112 + #define ADIS16203_DIAG_STAT_ALARM1 BIT(8) 113 + 114 + /* Self-test diagnostic error flag */ 115 + #define ADIS16203_DIAG_STAT_SELFTEST_FAIL_BIT 5 116 + 117 + /* SPI communications failure */ 118 + #define ADIS16203_DIAG_STAT_SPI_FAIL_BIT 3 119 + 120 + /* Flash update failure */ 121 + #define ADIS16203_DIAG_STAT_FLASH_UPT_BIT 2 122 + 123 + /* Power supply above 3.625 V */ 124 + #define ADIS16203_DIAG_STAT_POWER_HIGH_BIT 1 125 + 126 + /* Power supply below 3.15 V */ 127 + #define ADIS16203_DIAG_STAT_POWER_LOW_BIT 0 128 + 129 + /* GLOB_CMD */ 130 + 131 + #define ADIS16203_GLOB_CMD_SW_RESET BIT(7) 132 + #define ADIS16203_GLOB_CMD_CLEAR_STAT BIT(4) 133 + #define ADIS16203_GLOB_CMD_FACTORY_CAL BIT(1) 134 + 135 + #define ADIS16203_ERROR_ACTIVE BIT(14) 136 + 137 + enum adis16203_scan { 138 + ADIS16203_SCAN_INCLI_X, 139 + ADIS16203_SCAN_INCLI_Y, 140 + ADIS16203_SCAN_SUPPLY, 141 + ADIS16203_SCAN_AUX_ADC, 142 + ADIS16203_SCAN_TEMP, 143 + }; 24 144 25 145 #define DRIVER_NAME "adis16203" 26 146
-144
drivers/staging/iio/accel/adis16209.h
··· 1 - #ifndef SPI_ADIS16209_H_ 2 - #define SPI_ADIS16209_H_ 3 - 4 - #define ADIS16209_STARTUP_DELAY 220 /* ms */ 5 - 6 - /* Flash memory write count */ 7 - #define ADIS16209_FLASH_CNT 0x00 8 - 9 - /* Output, power supply */ 10 - #define ADIS16209_SUPPLY_OUT 0x02 11 - 12 - /* Output, x-axis accelerometer */ 13 - #define ADIS16209_XACCL_OUT 0x04 14 - 15 - /* Output, y-axis accelerometer */ 16 - #define ADIS16209_YACCL_OUT 0x06 17 - 18 - /* Output, auxiliary ADC input */ 19 - #define ADIS16209_AUX_ADC 0x08 20 - 21 - /* Output, temperature */ 22 - #define ADIS16209_TEMP_OUT 0x0A 23 - 24 - /* Output, x-axis inclination */ 25 - #define ADIS16209_XINCL_OUT 0x0C 26 - 27 - /* Output, y-axis inclination */ 28 - #define ADIS16209_YINCL_OUT 0x0E 29 - 30 - /* Output, +/-180 vertical rotational position */ 31 - #define ADIS16209_ROT_OUT 0x10 32 - 33 - /* Calibration, x-axis acceleration offset null */ 34 - #define ADIS16209_XACCL_NULL 0x12 35 - 36 - /* Calibration, y-axis acceleration offset null */ 37 - #define ADIS16209_YACCL_NULL 0x14 38 - 39 - /* Calibration, x-axis inclination offset null */ 40 - #define ADIS16209_XINCL_NULL 0x16 41 - 42 - /* Calibration, y-axis inclination offset null */ 43 - #define ADIS16209_YINCL_NULL 0x18 44 - 45 - /* Calibration, vertical rotation offset null */ 46 - #define ADIS16209_ROT_NULL 0x1A 47 - 48 - /* Alarm 1 amplitude threshold */ 49 - #define ADIS16209_ALM_MAG1 0x20 50 - 51 - /* Alarm 2 amplitude threshold */ 52 - #define ADIS16209_ALM_MAG2 0x22 53 - 54 - /* Alarm 1, sample period */ 55 - #define ADIS16209_ALM_SMPL1 0x24 56 - 57 - /* Alarm 2, sample period */ 58 - #define ADIS16209_ALM_SMPL2 0x26 59 - 60 - /* Alarm control */ 61 - #define ADIS16209_ALM_CTRL 0x28 62 - 63 - /* Auxiliary DAC data */ 64 - #define ADIS16209_AUX_DAC 0x30 65 - 66 - /* General-purpose digital input/output control */ 67 - #define ADIS16209_GPIO_CTRL 0x32 68 - 69 - /* Miscellaneous control */ 70 - #define ADIS16209_MSC_CTRL 0x34 71 - 72 - /* Internal sample period (rate) control */ 73 - #define ADIS16209_SMPL_PRD 0x36 74 - 75 - /* Operation, filter configuration */ 76 - #define ADIS16209_AVG_CNT 0x38 77 - 78 - /* Operation, sleep mode control */ 79 - #define ADIS16209_SLP_CNT 0x3A 80 - 81 - /* Diagnostics, system status register */ 82 - #define ADIS16209_DIAG_STAT 0x3C 83 - 84 - /* Operation, system command register */ 85 - #define ADIS16209_GLOB_CMD 0x3E 86 - 87 - /* MSC_CTRL */ 88 - 89 - /* Self-test at power-on: 1 = disabled, 0 = enabled */ 90 - #define ADIS16209_MSC_CTRL_PWRUP_SELF_TEST BIT(10) 91 - 92 - /* Self-test enable */ 93 - #define ADIS16209_MSC_CTRL_SELF_TEST_EN BIT(8) 94 - 95 - /* Data-ready enable: 1 = enabled, 0 = disabled */ 96 - #define ADIS16209_MSC_CTRL_DATA_RDY_EN BIT(2) 97 - 98 - /* Data-ready polarity: 1 = active high, 0 = active low */ 99 - #define ADIS16209_MSC_CTRL_ACTIVE_HIGH BIT(1) 100 - 101 - /* Data-ready line selection: 1 = DIO2, 0 = DIO1 */ 102 - #define ADIS16209_MSC_CTRL_DATA_RDY_DIO2 BIT(0) 103 - 104 - /* DIAG_STAT */ 105 - 106 - /* Alarm 2 status: 1 = alarm active, 0 = alarm inactive */ 107 - #define ADIS16209_DIAG_STAT_ALARM2 BIT(9) 108 - 109 - /* Alarm 1 status: 1 = alarm active, 0 = alarm inactive */ 110 - #define ADIS16209_DIAG_STAT_ALARM1 BIT(8) 111 - 112 - /* Self-test diagnostic error flag: 1 = error condition, 0 = normal operation */ 113 - #define ADIS16209_DIAG_STAT_SELFTEST_FAIL_BIT 5 114 - 115 - /* SPI communications failure */ 116 - #define ADIS16209_DIAG_STAT_SPI_FAIL_BIT 3 117 - 118 - /* Flash update failure */ 119 - #define ADIS16209_DIAG_STAT_FLASH_UPT_BIT 2 120 - 121 - /* Power supply above 3.625 V */ 122 - #define ADIS16209_DIAG_STAT_POWER_HIGH_BIT 1 123 - 124 - /* Power supply below 3.15 V */ 125 - #define ADIS16209_DIAG_STAT_POWER_LOW_BIT 0 126 - 127 - /* GLOB_CMD */ 128 - 129 - #define ADIS16209_GLOB_CMD_SW_RESET BIT(7) 130 - #define ADIS16209_GLOB_CMD_CLEAR_STAT BIT(4) 131 - #define ADIS16209_GLOB_CMD_FACTORY_CAL BIT(1) 132 - 133 - #define ADIS16209_ERROR_ACTIVE BIT(14) 134 - 135 - #define ADIS16209_SCAN_SUPPLY 0 136 - #define ADIS16209_SCAN_ACC_X 1 137 - #define ADIS16209_SCAN_ACC_Y 2 138 - #define ADIS16209_SCAN_AUX_ADC 3 139 - #define ADIS16209_SCAN_TEMP 4 140 - #define ADIS16209_SCAN_INCLI_X 5 141 - #define ADIS16209_SCAN_INCLI_Y 6 142 - #define ADIS16209_SCAN_ROT 7 143 - 144 - #endif /* SPI_ADIS16209_H_ */
+139 -1
drivers/staging/iio/accel/adis16209_core.c drivers/staging/iio/accel/adis16209.c
··· 21 21 #include <linux/iio/buffer.h> 22 22 #include <linux/iio/imu/adis.h> 23 23 24 - #include "adis16209.h" 24 + #define ADIS16209_STARTUP_DELAY 220 /* ms */ 25 + 26 + /* Flash memory write count */ 27 + #define ADIS16209_FLASH_CNT 0x00 28 + 29 + /* Output, power supply */ 30 + #define ADIS16209_SUPPLY_OUT 0x02 31 + 32 + /* Output, x-axis accelerometer */ 33 + #define ADIS16209_XACCL_OUT 0x04 34 + 35 + /* Output, y-axis accelerometer */ 36 + #define ADIS16209_YACCL_OUT 0x06 37 + 38 + /* Output, auxiliary ADC input */ 39 + #define ADIS16209_AUX_ADC 0x08 40 + 41 + /* Output, temperature */ 42 + #define ADIS16209_TEMP_OUT 0x0A 43 + 44 + /* Output, x-axis inclination */ 45 + #define ADIS16209_XINCL_OUT 0x0C 46 + 47 + /* Output, y-axis inclination */ 48 + #define ADIS16209_YINCL_OUT 0x0E 49 + 50 + /* Output, +/-180 vertical rotational position */ 51 + #define ADIS16209_ROT_OUT 0x10 52 + 53 + /* Calibration, x-axis acceleration offset null */ 54 + #define ADIS16209_XACCL_NULL 0x12 55 + 56 + /* Calibration, y-axis acceleration offset null */ 57 + #define ADIS16209_YACCL_NULL 0x14 58 + 59 + /* Calibration, x-axis inclination offset null */ 60 + #define ADIS16209_XINCL_NULL 0x16 61 + 62 + /* Calibration, y-axis inclination offset null */ 63 + #define ADIS16209_YINCL_NULL 0x18 64 + 65 + /* Calibration, vertical rotation offset null */ 66 + #define ADIS16209_ROT_NULL 0x1A 67 + 68 + /* Alarm 1 amplitude threshold */ 69 + #define ADIS16209_ALM_MAG1 0x20 70 + 71 + /* Alarm 2 amplitude threshold */ 72 + #define ADIS16209_ALM_MAG2 0x22 73 + 74 + /* Alarm 1, sample period */ 75 + #define ADIS16209_ALM_SMPL1 0x24 76 + 77 + /* Alarm 2, sample period */ 78 + #define ADIS16209_ALM_SMPL2 0x26 79 + 80 + /* Alarm control */ 81 + #define ADIS16209_ALM_CTRL 0x28 82 + 83 + /* Auxiliary DAC data */ 84 + #define ADIS16209_AUX_DAC 0x30 85 + 86 + /* General-purpose digital input/output control */ 87 + #define ADIS16209_GPIO_CTRL 0x32 88 + 89 + /* Miscellaneous control */ 90 + #define ADIS16209_MSC_CTRL 0x34 91 + 92 + /* Internal sample period (rate) control */ 93 + #define ADIS16209_SMPL_PRD 0x36 94 + 95 + /* Operation, filter configuration */ 96 + #define ADIS16209_AVG_CNT 0x38 97 + 98 + /* Operation, sleep mode control */ 99 + #define ADIS16209_SLP_CNT 0x3A 100 + 101 + /* Diagnostics, system status register */ 102 + #define ADIS16209_DIAG_STAT 0x3C 103 + 104 + /* Operation, system command register */ 105 + #define ADIS16209_GLOB_CMD 0x3E 106 + 107 + /* MSC_CTRL */ 108 + 109 + /* Self-test at power-on: 1 = disabled, 0 = enabled */ 110 + #define ADIS16209_MSC_CTRL_PWRUP_SELF_TEST BIT(10) 111 + 112 + /* Self-test enable */ 113 + #define ADIS16209_MSC_CTRL_SELF_TEST_EN BIT(8) 114 + 115 + /* Data-ready enable: 1 = enabled, 0 = disabled */ 116 + #define ADIS16209_MSC_CTRL_DATA_RDY_EN BIT(2) 117 + 118 + /* Data-ready polarity: 1 = active high, 0 = active low */ 119 + #define ADIS16209_MSC_CTRL_ACTIVE_HIGH BIT(1) 120 + 121 + /* Data-ready line selection: 1 = DIO2, 0 = DIO1 */ 122 + #define ADIS16209_MSC_CTRL_DATA_RDY_DIO2 BIT(0) 123 + 124 + /* DIAG_STAT */ 125 + 126 + /* Alarm 2 status: 1 = alarm active, 0 = alarm inactive */ 127 + #define ADIS16209_DIAG_STAT_ALARM2 BIT(9) 128 + 129 + /* Alarm 1 status: 1 = alarm active, 0 = alarm inactive */ 130 + #define ADIS16209_DIAG_STAT_ALARM1 BIT(8) 131 + 132 + /* Self-test diagnostic error flag: 1 = error condition, 0 = normal operation */ 133 + #define ADIS16209_DIAG_STAT_SELFTEST_FAIL_BIT 5 134 + 135 + /* SPI communications failure */ 136 + #define ADIS16209_DIAG_STAT_SPI_FAIL_BIT 3 137 + 138 + /* Flash update failure */ 139 + #define ADIS16209_DIAG_STAT_FLASH_UPT_BIT 2 140 + 141 + /* Power supply above 3.625 V */ 142 + #define ADIS16209_DIAG_STAT_POWER_HIGH_BIT 1 143 + 144 + /* Power supply below 3.15 V */ 145 + #define ADIS16209_DIAG_STAT_POWER_LOW_BIT 0 146 + 147 + /* GLOB_CMD */ 148 + 149 + #define ADIS16209_GLOB_CMD_SW_RESET BIT(7) 150 + #define ADIS16209_GLOB_CMD_CLEAR_STAT BIT(4) 151 + #define ADIS16209_GLOB_CMD_FACTORY_CAL BIT(1) 152 + 153 + #define ADIS16209_ERROR_ACTIVE BIT(14) 154 + 155 + #define ADIS16209_SCAN_SUPPLY 0 156 + #define ADIS16209_SCAN_ACC_X 1 157 + #define ADIS16209_SCAN_ACC_Y 2 158 + #define ADIS16209_SCAN_AUX_ADC 3 159 + #define ADIS16209_SCAN_TEMP 4 160 + #define ADIS16209_SCAN_INCLI_X 5 161 + #define ADIS16209_SCAN_INCLI_Y 6 162 + #define ADIS16209_SCAN_ROT 7 25 163 26 164 static const u8 adis16209_addresses[8][1] = { 27 165 [ADIS16209_SCAN_SUPPLY] = { },
-179
drivers/staging/iio/accel/adis16240.h
··· 1 - #ifndef SPI_ADIS16240_H_ 2 - #define SPI_ADIS16240_H_ 3 - 4 - #define ADIS16240_STARTUP_DELAY 220 /* ms */ 5 - 6 - /* Flash memory write count */ 7 - #define ADIS16240_FLASH_CNT 0x00 8 - 9 - /* Output, power supply */ 10 - #define ADIS16240_SUPPLY_OUT 0x02 11 - 12 - /* Output, x-axis accelerometer */ 13 - #define ADIS16240_XACCL_OUT 0x04 14 - 15 - /* Output, y-axis accelerometer */ 16 - #define ADIS16240_YACCL_OUT 0x06 17 - 18 - /* Output, z-axis accelerometer */ 19 - #define ADIS16240_ZACCL_OUT 0x08 20 - 21 - /* Output, auxiliary ADC input */ 22 - #define ADIS16240_AUX_ADC 0x0A 23 - 24 - /* Output, temperature */ 25 - #define ADIS16240_TEMP_OUT 0x0C 26 - 27 - /* Output, x-axis acceleration peak */ 28 - #define ADIS16240_XPEAK_OUT 0x0E 29 - 30 - /* Output, y-axis acceleration peak */ 31 - #define ADIS16240_YPEAK_OUT 0x10 32 - 33 - /* Output, z-axis acceleration peak */ 34 - #define ADIS16240_ZPEAK_OUT 0x12 35 - 36 - /* Output, sum-of-squares acceleration peak */ 37 - #define ADIS16240_XYZPEAK_OUT 0x14 38 - 39 - /* Output, Capture Buffer 1, X and Y acceleration */ 40 - #define ADIS16240_CAPT_BUF1 0x16 41 - 42 - /* Output, Capture Buffer 2, Z acceleration */ 43 - #define ADIS16240_CAPT_BUF2 0x18 44 - 45 - /* Diagnostic, error flags */ 46 - #define ADIS16240_DIAG_STAT 0x1A 47 - 48 - /* Diagnostic, event counter */ 49 - #define ADIS16240_EVNT_CNTR 0x1C 50 - 51 - /* Diagnostic, check sum value from firmware test */ 52 - #define ADIS16240_CHK_SUM 0x1E 53 - 54 - /* Calibration, x-axis acceleration offset adjustment */ 55 - #define ADIS16240_XACCL_OFF 0x20 56 - 57 - /* Calibration, y-axis acceleration offset adjustment */ 58 - #define ADIS16240_YACCL_OFF 0x22 59 - 60 - /* Calibration, z-axis acceleration offset adjustment */ 61 - #define ADIS16240_ZACCL_OFF 0x24 62 - 63 - /* Clock, hour and minute */ 64 - #define ADIS16240_CLK_TIME 0x2E 65 - 66 - /* Clock, month and day */ 67 - #define ADIS16240_CLK_DATE 0x30 68 - 69 - /* Clock, year */ 70 - #define ADIS16240_CLK_YEAR 0x32 71 - 72 - /* Wake-up setting, hour and minute */ 73 - #define ADIS16240_WAKE_TIME 0x34 74 - 75 - /* Wake-up setting, month and day */ 76 - #define ADIS16240_WAKE_DATE 0x36 77 - 78 - /* Alarm 1 amplitude threshold */ 79 - #define ADIS16240_ALM_MAG1 0x38 80 - 81 - /* Alarm 2 amplitude threshold */ 82 - #define ADIS16240_ALM_MAG2 0x3A 83 - 84 - /* Alarm control */ 85 - #define ADIS16240_ALM_CTRL 0x3C 86 - 87 - /* Capture, external trigger control */ 88 - #define ADIS16240_XTRIG_CTRL 0x3E 89 - 90 - /* Capture, address pointer */ 91 - #define ADIS16240_CAPT_PNTR 0x40 92 - 93 - /* Capture, configuration and control */ 94 - #define ADIS16240_CAPT_CTRL 0x42 95 - 96 - /* General-purpose digital input/output control */ 97 - #define ADIS16240_GPIO_CTRL 0x44 98 - 99 - /* Miscellaneous control */ 100 - #define ADIS16240_MSC_CTRL 0x46 101 - 102 - /* Internal sample period (rate) control */ 103 - #define ADIS16240_SMPL_PRD 0x48 104 - 105 - /* System command */ 106 - #define ADIS16240_GLOB_CMD 0x4A 107 - 108 - /* MSC_CTRL */ 109 - 110 - /* Enables sum-of-squares output (XYZPEAK_OUT) */ 111 - #define ADIS16240_MSC_CTRL_XYZPEAK_OUT_EN BIT(15) 112 - 113 - /* Enables peak tracking output (XPEAK_OUT, YPEAK_OUT, and ZPEAK_OUT) */ 114 - #define ADIS16240_MSC_CTRL_X_Y_ZPEAK_OUT_EN BIT(14) 115 - 116 - /* Self-test enable: 1 = apply electrostatic force, 0 = disabled */ 117 - #define ADIS16240_MSC_CTRL_SELF_TEST_EN BIT(8) 118 - 119 - /* Data-ready enable: 1 = enabled, 0 = disabled */ 120 - #define ADIS16240_MSC_CTRL_DATA_RDY_EN BIT(2) 121 - 122 - /* Data-ready polarity: 1 = active high, 0 = active low */ 123 - #define ADIS16240_MSC_CTRL_ACTIVE_HIGH BIT(1) 124 - 125 - /* Data-ready line selection: 1 = DIO2, 0 = DIO1 */ 126 - #define ADIS16240_MSC_CTRL_DATA_RDY_DIO2 BIT(0) 127 - 128 - /* DIAG_STAT */ 129 - 130 - /* Alarm 2 status: 1 = alarm active, 0 = alarm inactive */ 131 - #define ADIS16240_DIAG_STAT_ALARM2 BIT(9) 132 - 133 - /* Alarm 1 status: 1 = alarm active, 0 = alarm inactive */ 134 - #define ADIS16240_DIAG_STAT_ALARM1 BIT(8) 135 - 136 - /* Capture buffer full: 1 = capture buffer is full */ 137 - #define ADIS16240_DIAG_STAT_CPT_BUF_FUL BIT(7) 138 - 139 - /* Flash test, checksum flag: 1 = mismatch, 0 = match */ 140 - #define ADIS16240_DIAG_STAT_CHKSUM BIT(6) 141 - 142 - /* Power-on, self-test flag: 1 = failure, 0 = pass */ 143 - #define ADIS16240_DIAG_STAT_PWRON_FAIL_BIT 5 144 - 145 - /* Power-on self-test: 1 = in-progress, 0 = complete */ 146 - #define ADIS16240_DIAG_STAT_PWRON_BUSY BIT(4) 147 - 148 - /* SPI communications failure */ 149 - #define ADIS16240_DIAG_STAT_SPI_FAIL_BIT 3 150 - 151 - /* Flash update failure */ 152 - #define ADIS16240_DIAG_STAT_FLASH_UPT_BIT 2 153 - 154 - /* Power supply above 3.625 V */ 155 - #define ADIS16240_DIAG_STAT_POWER_HIGH_BIT 1 156 - 157 - /* Power supply below 3.15 V */ 158 - #define ADIS16240_DIAG_STAT_POWER_LOW_BIT 0 159 - 160 - /* GLOB_CMD */ 161 - 162 - #define ADIS16240_GLOB_CMD_RESUME BIT(8) 163 - #define ADIS16240_GLOB_CMD_SW_RESET BIT(7) 164 - #define ADIS16240_GLOB_CMD_STANDBY BIT(2) 165 - 166 - #define ADIS16240_ERROR_ACTIVE BIT(14) 167 - 168 - /* At the moment triggers are only used for ring buffer 169 - * filling. This may change! 170 - */ 171 - 172 - #define ADIS16240_SCAN_ACC_X 0 173 - #define ADIS16240_SCAN_ACC_Y 1 174 - #define ADIS16240_SCAN_ACC_Z 2 175 - #define ADIS16240_SCAN_SUPPLY 3 176 - #define ADIS16240_SCAN_AUX_ADC 4 177 - #define ADIS16240_SCAN_TEMP 5 178 - 179 - #endif /* SPI_ADIS16240_H_ */
+175 -2
drivers/staging/iio/accel/adis16240_core.c drivers/staging/iio/accel/adis16240.c
··· 24 24 #include <linux/iio/buffer.h> 25 25 #include <linux/iio/imu/adis.h> 26 26 27 - #include "adis16240.h" 27 + #define ADIS16240_STARTUP_DELAY 220 /* ms */ 28 + 29 + /* Flash memory write count */ 30 + #define ADIS16240_FLASH_CNT 0x00 31 + 32 + /* Output, power supply */ 33 + #define ADIS16240_SUPPLY_OUT 0x02 34 + 35 + /* Output, x-axis accelerometer */ 36 + #define ADIS16240_XACCL_OUT 0x04 37 + 38 + /* Output, y-axis accelerometer */ 39 + #define ADIS16240_YACCL_OUT 0x06 40 + 41 + /* Output, z-axis accelerometer */ 42 + #define ADIS16240_ZACCL_OUT 0x08 43 + 44 + /* Output, auxiliary ADC input */ 45 + #define ADIS16240_AUX_ADC 0x0A 46 + 47 + /* Output, temperature */ 48 + #define ADIS16240_TEMP_OUT 0x0C 49 + 50 + /* Output, x-axis acceleration peak */ 51 + #define ADIS16240_XPEAK_OUT 0x0E 52 + 53 + /* Output, y-axis acceleration peak */ 54 + #define ADIS16240_YPEAK_OUT 0x10 55 + 56 + /* Output, z-axis acceleration peak */ 57 + #define ADIS16240_ZPEAK_OUT 0x12 58 + 59 + /* Output, sum-of-squares acceleration peak */ 60 + #define ADIS16240_XYZPEAK_OUT 0x14 61 + 62 + /* Output, Capture Buffer 1, X and Y acceleration */ 63 + #define ADIS16240_CAPT_BUF1 0x16 64 + 65 + /* Output, Capture Buffer 2, Z acceleration */ 66 + #define ADIS16240_CAPT_BUF2 0x18 67 + 68 + /* Diagnostic, error flags */ 69 + #define ADIS16240_DIAG_STAT 0x1A 70 + 71 + /* Diagnostic, event counter */ 72 + #define ADIS16240_EVNT_CNTR 0x1C 73 + 74 + /* Diagnostic, check sum value from firmware test */ 75 + #define ADIS16240_CHK_SUM 0x1E 76 + 77 + /* Calibration, x-axis acceleration offset adjustment */ 78 + #define ADIS16240_XACCL_OFF 0x20 79 + 80 + /* Calibration, y-axis acceleration offset adjustment */ 81 + #define ADIS16240_YACCL_OFF 0x22 82 + 83 + /* Calibration, z-axis acceleration offset adjustment */ 84 + #define ADIS16240_ZACCL_OFF 0x24 85 + 86 + /* Clock, hour and minute */ 87 + #define ADIS16240_CLK_TIME 0x2E 88 + 89 + /* Clock, month and day */ 90 + #define ADIS16240_CLK_DATE 0x30 91 + 92 + /* Clock, year */ 93 + #define ADIS16240_CLK_YEAR 0x32 94 + 95 + /* Wake-up setting, hour and minute */ 96 + #define ADIS16240_WAKE_TIME 0x34 97 + 98 + /* Wake-up setting, month and day */ 99 + #define ADIS16240_WAKE_DATE 0x36 100 + 101 + /* Alarm 1 amplitude threshold */ 102 + #define ADIS16240_ALM_MAG1 0x38 103 + 104 + /* Alarm 2 amplitude threshold */ 105 + #define ADIS16240_ALM_MAG2 0x3A 106 + 107 + /* Alarm control */ 108 + #define ADIS16240_ALM_CTRL 0x3C 109 + 110 + /* Capture, external trigger control */ 111 + #define ADIS16240_XTRIG_CTRL 0x3E 112 + 113 + /* Capture, address pointer */ 114 + #define ADIS16240_CAPT_PNTR 0x40 115 + 116 + /* Capture, configuration and control */ 117 + #define ADIS16240_CAPT_CTRL 0x42 118 + 119 + /* General-purpose digital input/output control */ 120 + #define ADIS16240_GPIO_CTRL 0x44 121 + 122 + /* Miscellaneous control */ 123 + #define ADIS16240_MSC_CTRL 0x46 124 + 125 + /* Internal sample period (rate) control */ 126 + #define ADIS16240_SMPL_PRD 0x48 127 + 128 + /* System command */ 129 + #define ADIS16240_GLOB_CMD 0x4A 130 + 131 + /* MSC_CTRL */ 132 + 133 + /* Enables sum-of-squares output (XYZPEAK_OUT) */ 134 + #define ADIS16240_MSC_CTRL_XYZPEAK_OUT_EN BIT(15) 135 + 136 + /* Enables peak tracking output (XPEAK_OUT, YPEAK_OUT, and ZPEAK_OUT) */ 137 + #define ADIS16240_MSC_CTRL_X_Y_ZPEAK_OUT_EN BIT(14) 138 + 139 + /* Self-test enable: 1 = apply electrostatic force, 0 = disabled */ 140 + #define ADIS16240_MSC_CTRL_SELF_TEST_EN BIT(8) 141 + 142 + /* Data-ready enable: 1 = enabled, 0 = disabled */ 143 + #define ADIS16240_MSC_CTRL_DATA_RDY_EN BIT(2) 144 + 145 + /* Data-ready polarity: 1 = active high, 0 = active low */ 146 + #define ADIS16240_MSC_CTRL_ACTIVE_HIGH BIT(1) 147 + 148 + /* Data-ready line selection: 1 = DIO2, 0 = DIO1 */ 149 + #define ADIS16240_MSC_CTRL_DATA_RDY_DIO2 BIT(0) 150 + 151 + /* DIAG_STAT */ 152 + 153 + /* Alarm 2 status: 1 = alarm active, 0 = alarm inactive */ 154 + #define ADIS16240_DIAG_STAT_ALARM2 BIT(9) 155 + 156 + /* Alarm 1 status: 1 = alarm active, 0 = alarm inactive */ 157 + #define ADIS16240_DIAG_STAT_ALARM1 BIT(8) 158 + 159 + /* Capture buffer full: 1 = capture buffer is full */ 160 + #define ADIS16240_DIAG_STAT_CPT_BUF_FUL BIT(7) 161 + 162 + /* Flash test, checksum flag: 1 = mismatch, 0 = match */ 163 + #define ADIS16240_DIAG_STAT_CHKSUM BIT(6) 164 + 165 + /* Power-on, self-test flag: 1 = failure, 0 = pass */ 166 + #define ADIS16240_DIAG_STAT_PWRON_FAIL_BIT 5 167 + 168 + /* Power-on self-test: 1 = in-progress, 0 = complete */ 169 + #define ADIS16240_DIAG_STAT_PWRON_BUSY BIT(4) 170 + 171 + /* SPI communications failure */ 172 + #define ADIS16240_DIAG_STAT_SPI_FAIL_BIT 3 173 + 174 + /* Flash update failure */ 175 + #define ADIS16240_DIAG_STAT_FLASH_UPT_BIT 2 176 + 177 + /* Power supply above 3.625 V */ 178 + #define ADIS16240_DIAG_STAT_POWER_HIGH_BIT 1 179 + 180 + /* Power supply below 3.15 V */ 181 + #define ADIS16240_DIAG_STAT_POWER_LOW_BIT 0 182 + 183 + /* GLOB_CMD */ 184 + 185 + #define ADIS16240_GLOB_CMD_RESUME BIT(8) 186 + #define ADIS16240_GLOB_CMD_SW_RESET BIT(7) 187 + #define ADIS16240_GLOB_CMD_STANDBY BIT(2) 188 + 189 + #define ADIS16240_ERROR_ACTIVE BIT(14) 190 + 191 + /* At the moment triggers are only used for ring buffer 192 + * filling. This may change! 193 + */ 194 + 195 + #define ADIS16240_SCAN_ACC_X 0 196 + #define ADIS16240_SCAN_ACC_Y 1 197 + #define ADIS16240_SCAN_ACC_Z 2 198 + #define ADIS16240_SCAN_SUPPLY 3 199 + #define ADIS16240_SCAN_AUX_ADC 4 200 + #define ADIS16240_SCAN_TEMP 5 28 201 29 202 static ssize_t adis16240_spi_read_signed(struct device *dev, 30 203 struct device_attribute *attr, ··· 238 65 return ret; 239 66 } 240 67 241 - static IIO_DEVICE_ATTR(in_accel_xyz_squared_peak_raw, S_IRUGO, 68 + static IIO_DEVICE_ATTR(in_accel_xyz_squared_peak_raw, 0444, 242 69 adis16240_read_12bit_signed, NULL, 243 70 ADIS16240_XYZPEAK_OUT); 244 71
-22
drivers/staging/iio/adc/Kconfig
··· 80 80 To compile this driver as a module, choose M here: the 81 81 module will be called ad7280a 82 82 83 - config LPC32XX_ADC 84 - tristate "NXP LPC32XX ADC" 85 - depends on ARCH_LPC32XX || COMPILE_TEST 86 - depends on HAS_IOMEM 87 - help 88 - Say yes here to build support for the integrated ADC inside the 89 - LPC32XX SoC. Note that this feature uses the same hardware as the 90 - touchscreen driver, so you should either select only one of the two 91 - drivers (lpc32xx_adc or lpc32xx_ts) or, in the OpenFirmware case, 92 - activate only one via device tree selection. Provides direct access 93 - via sysfs. 94 - 95 - config SPEAR_ADC 96 - tristate "ST SPEAr ADC" 97 - depends on PLAT_SPEAR || COMPILE_TEST 98 - depends on HAS_IOMEM 99 - help 100 - Say yes here to build support for the integrated ADC inside the 101 - ST SPEAr SoC. Provides direct access via sysfs. 102 - 103 - To compile this driver as a module, choose M here: the 104 - module will be called spear_adc. 105 83 endmenu
-2
drivers/staging/iio/adc/Makefile
··· 10 10 obj-$(CONFIG_AD7816) += ad7816.o 11 11 obj-$(CONFIG_AD7192) += ad7192.o 12 12 obj-$(CONFIG_AD7280) += ad7280a.o 13 - obj-$(CONFIG_LPC32XX_ADC) += lpc32xx_adc.o 14 - obj-$(CONFIG_SPEAR_ADC) += spear_adc.o
+4 -4
drivers/staging/iio/adc/ad7192.c
··· 342 342 343 343 static IIO_DEVICE_ATTR_NAMED(in_v_m_v_scale_available, 344 344 in_voltage-voltage_scale_available, 345 - S_IRUGO, ad7192_show_scale_available, NULL, 0); 345 + 0444, ad7192_show_scale_available, NULL, 0); 346 346 347 - static IIO_DEVICE_ATTR(in_voltage_scale_available, S_IRUGO, 347 + static IIO_DEVICE_ATTR(in_voltage_scale_available, 0444, 348 348 ad7192_show_scale_available, NULL, 0); 349 349 350 350 static ssize_t ad7192_show_ac_excitation(struct device *dev, ··· 412 412 return ret ? ret : len; 413 413 } 414 414 415 - static IIO_DEVICE_ATTR(bridge_switch_en, S_IRUGO | S_IWUSR, 415 + static IIO_DEVICE_ATTR(bridge_switch_en, 0644, 416 416 ad7192_show_bridge_switch, ad7192_set, 417 417 AD7192_REG_GPOCON); 418 418 419 - static IIO_DEVICE_ATTR(ac_excitation_en, S_IRUGO | S_IWUSR, 419 + static IIO_DEVICE_ATTR(ac_excitation_en, 0644, 420 420 ad7192_show_ac_excitation, ad7192_set, 421 421 AD7192_REG_MODE); 422 422
+47 -43
drivers/staging/iio/adc/lpc32xx_adc.c drivers/iio/adc/lpc32xx_adc.c
··· 38 38 /* 39 39 * LPC32XX registers definitions 40 40 */ 41 - #define LPC32XX_ADC_SELECT(x) ((x) + 0x04) 42 - #define LPC32XX_ADC_CTRL(x) ((x) + 0x08) 43 - #define LPC32XX_ADC_VALUE(x) ((x) + 0x48) 41 + #define LPC32XXAD_SELECT(x) ((x) + 0x04) 42 + #define LPC32XXAD_CTRL(x) ((x) + 0x08) 43 + #define LPC32XXAD_VALUE(x) ((x) + 0x48) 44 44 45 - /* Bit definitions for LPC32XX_ADC_SELECT: */ 46 - #define AD_REFm 0x00000200 /* constant, always write this value! */ 47 - #define AD_REFp 0x00000080 /* constant, always write this value! */ 48 - #define AD_IN 0x00000010 /* multiple of this is the */ 49 - /* channel number: 0, 1, 2 */ 50 - #define AD_INTERNAL 0x00000004 /* constant, always write this value! */ 45 + /* Bit definitions for LPC32XXAD_SELECT: */ 46 + /* constant, always write this value! */ 47 + #define LPC32XXAD_REFm 0x00000200 48 + /* constant, always write this value! */ 49 + #define LPC32XXAD_REFp 0x00000080 50 + /* multiple of this is the channel number: 0, 1, 2 */ 51 + #define LPC32XXAD_IN 0x00000010 52 + /* constant, always write this value! */ 53 + #define LPC32XXAD_INTERNAL 0x00000004 51 54 52 - /* Bit definitions for LPC32XX_ADC_CTRL: */ 53 - #define AD_STROBE 0x00000002 54 - #define AD_PDN_CTRL 0x00000004 55 + /* Bit definitions for LPC32XXAD_CTRL: */ 56 + #define LPC32XXAD_STROBE 0x00000002 57 + #define LPC32XXAD_PDN_CTRL 0x00000004 55 58 56 - /* Bit definitions for LPC32XX_ADC_VALUE: */ 57 - #define ADC_VALUE_MASK 0x000003FF 59 + /* Bit definitions for LPC32XXAD_VALUE: */ 60 + #define LPC32XXAD_VALUE_MASK 0x000003FF 58 61 59 - #define MOD_NAME "lpc32xx-adc" 62 + #define LPC32XXAD_NAME "lpc32xx-adc" 60 63 61 - struct lpc32xx_adc_info { 64 + struct lpc32xx_adc_state { 62 65 void __iomem *adc_base; 63 66 struct clk *clk; 64 67 struct completion completion; ··· 75 72 int *val2, 76 73 long mask) 77 74 { 78 - struct lpc32xx_adc_info *info = iio_priv(indio_dev); 75 + struct lpc32xx_adc_state *st = iio_priv(indio_dev); 79 76 80 77 if (mask == IIO_CHAN_INFO_RAW) { 81 78 mutex_lock(&indio_dev->mlock); 82 - clk_prepare_enable(info->clk); 79 + clk_prepare_enable(st->clk); 83 80 /* Measurement setup */ 84 - __raw_writel(AD_INTERNAL | (chan->address) | AD_REFp | AD_REFm, 85 - LPC32XX_ADC_SELECT(info->adc_base)); 81 + __raw_writel(LPC32XXAD_INTERNAL | (chan->address) | 82 + LPC32XXAD_REFp | LPC32XXAD_REFm, 83 + LPC32XXAD_SELECT(st->adc_base)); 86 84 /* Trigger conversion */ 87 - __raw_writel(AD_PDN_CTRL | AD_STROBE, 88 - LPC32XX_ADC_CTRL(info->adc_base)); 89 - wait_for_completion(&info->completion); /* set by ISR */ 90 - clk_disable_unprepare(info->clk); 91 - *val = info->value; 85 + __raw_writel(LPC32XXAD_PDN_CTRL | LPC32XXAD_STROBE, 86 + LPC32XXAD_CTRL(st->adc_base)); 87 + wait_for_completion(&st->completion); /* set by ISR */ 88 + clk_disable_unprepare(st->clk); 89 + *val = st->value; 92 90 mutex_unlock(&indio_dev->mlock); 93 91 94 92 return IIO_VAL_INT; ··· 108 104 .indexed = 1, \ 109 105 .channel = _index, \ 110 106 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 111 - .address = AD_IN * _index, \ 107 + .address = LPC32XXAD_IN * _index, \ 112 108 .scan_index = _index, \ 113 109 } 114 110 ··· 120 116 121 117 static irqreturn_t lpc32xx_adc_isr(int irq, void *dev_id) 122 118 { 123 - struct lpc32xx_adc_info *info = dev_id; 119 + struct lpc32xx_adc_state *st = dev_id; 124 120 125 121 /* Read value and clear irq */ 126 - info->value = __raw_readl(LPC32XX_ADC_VALUE(info->adc_base)) & 127 - ADC_VALUE_MASK; 128 - complete(&info->completion); 122 + st->value = __raw_readl(LPC32XXAD_VALUE(st->adc_base)) & 123 + LPC32XXAD_VALUE_MASK; 124 + complete(&st->completion); 129 125 130 126 return IRQ_HANDLED; 131 127 } 132 128 133 129 static int lpc32xx_adc_probe(struct platform_device *pdev) 134 130 { 135 - struct lpc32xx_adc_info *info = NULL; 131 + struct lpc32xx_adc_state *st = NULL; 136 132 struct resource *res; 137 133 int retval = -ENODEV; 138 134 struct iio_dev *iodev = NULL; ··· 144 140 return -ENXIO; 145 141 } 146 142 147 - iodev = devm_iio_device_alloc(&pdev->dev, sizeof(*info)); 143 + iodev = devm_iio_device_alloc(&pdev->dev, sizeof(*st)); 148 144 if (!iodev) 149 145 return -ENOMEM; 150 146 151 - info = iio_priv(iodev); 147 + st = iio_priv(iodev); 152 148 153 - info->adc_base = devm_ioremap(&pdev->dev, res->start, 154 - resource_size(res)); 155 - if (!info->adc_base) { 149 + st->adc_base = devm_ioremap(&pdev->dev, res->start, 150 + resource_size(res)); 151 + if (!st->adc_base) { 156 152 dev_err(&pdev->dev, "failed mapping memory\n"); 157 153 return -EBUSY; 158 154 } 159 155 160 - info->clk = devm_clk_get(&pdev->dev, NULL); 161 - if (IS_ERR(info->clk)) { 156 + st->clk = devm_clk_get(&pdev->dev, NULL); 157 + if (IS_ERR(st->clk)) { 162 158 dev_err(&pdev->dev, "failed getting clock\n"); 163 - return PTR_ERR(info->clk); 159 + return PTR_ERR(st->clk); 164 160 } 165 161 166 162 irq = platform_get_irq(pdev, 0); ··· 170 166 } 171 167 172 168 retval = devm_request_irq(&pdev->dev, irq, lpc32xx_adc_isr, 0, 173 - MOD_NAME, info); 169 + LPC32XXAD_NAME, st); 174 170 if (retval < 0) { 175 171 dev_err(&pdev->dev, "failed requesting interrupt\n"); 176 172 return retval; ··· 178 174 179 175 platform_set_drvdata(pdev, iodev); 180 176 181 - init_completion(&info->completion); 177 + init_completion(&st->completion); 182 178 183 - iodev->name = MOD_NAME; 179 + iodev->name = LPC32XXAD_NAME; 184 180 iodev->dev.parent = &pdev->dev; 185 181 iodev->info = &lpc32xx_adc_iio_info; 186 182 iodev->modes = INDIO_DIRECT_MODE; ··· 207 203 static struct platform_driver lpc32xx_adc_driver = { 208 204 .probe = lpc32xx_adc_probe, 209 205 .driver = { 210 - .name = MOD_NAME, 206 + .name = LPC32XXAD_NAME, 211 207 .of_match_table = of_match_ptr(lpc32xx_adc_match), 212 208 }, 213 209 };
drivers/staging/iio/adc/spear_adc.c drivers/iio/adc/spear_adc.c
+54 -54
drivers/staging/iio/addac/adt7316.c
··· 267 267 return len; 268 268 } 269 269 270 - static IIO_DEVICE_ATTR(enabled, S_IRUGO | S_IWUSR, 270 + static IIO_DEVICE_ATTR(enabled, 0644, 271 271 adt7316_show_enabled, 272 272 adt7316_store_enabled, 273 273 0); ··· 311 311 return len; 312 312 } 313 313 314 - static IIO_DEVICE_ATTR(select_ex_temp, S_IRUGO | S_IWUSR, 314 + static IIO_DEVICE_ATTR(select_ex_temp, 0644, 315 315 adt7316_show_select_ex_temp, 316 316 adt7316_store_select_ex_temp, 317 317 0); ··· 352 352 return len; 353 353 } 354 354 355 - static IIO_DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, 355 + static IIO_DEVICE_ATTR(mode, 0644, 356 356 adt7316_show_mode, 357 357 adt7316_store_mode, 358 358 0); ··· 364 364 return sprintf(buf, "single_channel\nround_robin\n"); 365 365 } 366 366 367 - static IIO_DEVICE_ATTR(all_modes, S_IRUGO, adt7316_show_all_modes, NULL, 0); 367 + static IIO_DEVICE_ATTR(all_modes, 0444, adt7316_show_all_modes, NULL, 0); 368 368 369 369 static ssize_t adt7316_show_ad_channel(struct device *dev, 370 370 struct device_attribute *attr, ··· 446 446 return len; 447 447 } 448 448 449 - static IIO_DEVICE_ATTR(ad_channel, S_IRUGO | S_IWUSR, 449 + static IIO_DEVICE_ATTR(ad_channel, 0644, 450 450 adt7316_show_ad_channel, 451 451 adt7316_store_ad_channel, 452 452 0); ··· 469 469 "2 - External Temperature\n"); 470 470 } 471 471 472 - static IIO_DEVICE_ATTR(all_ad_channels, S_IRUGO, 472 + static IIO_DEVICE_ATTR(all_ad_channels, 0444, 473 473 adt7316_show_all_ad_channels, NULL, 0); 474 474 475 475 static ssize_t adt7316_show_disable_averaging(struct device *dev, ··· 506 506 return len; 507 507 } 508 508 509 - static IIO_DEVICE_ATTR(disable_averaging, S_IRUGO | S_IWUSR, 509 + static IIO_DEVICE_ATTR(disable_averaging, 0644, 510 510 adt7316_show_disable_averaging, 511 511 adt7316_store_disable_averaging, 512 512 0); ··· 545 545 return len; 546 546 } 547 547 548 - static IIO_DEVICE_ATTR(enable_smbus_timeout, S_IRUGO | S_IWUSR, 548 + static IIO_DEVICE_ATTR(enable_smbus_timeout, 0644, 549 549 adt7316_show_enable_smbus_timeout, 550 550 adt7316_store_enable_smbus_timeout, 551 551 0); ··· 583 583 return len; 584 584 } 585 585 586 - static IIO_DEVICE_ATTR(powerdown, S_IRUGO | S_IWUSR, 586 + static IIO_DEVICE_ATTR(powerdown, 0644, 587 587 adt7316_show_powerdown, 588 588 adt7316_store_powerdown, 589 589 0); ··· 621 621 return len; 622 622 } 623 623 624 - static IIO_DEVICE_ATTR(fast_ad_clock, S_IRUGO | S_IWUSR, 624 + static IIO_DEVICE_ATTR(fast_ad_clock, 0644, 625 625 adt7316_show_fast_ad_clock, 626 626 adt7316_store_fast_ad_clock, 627 627 0); ··· 674 674 return len; 675 675 } 676 676 677 - static IIO_DEVICE_ATTR(da_high_resolution, S_IRUGO | S_IWUSR, 677 + static IIO_DEVICE_ATTR(da_high_resolution, 0644, 678 678 adt7316_show_da_high_resolution, 679 679 adt7316_store_da_high_resolution, 680 680 0); ··· 720 720 return len; 721 721 } 722 722 723 - static IIO_DEVICE_ATTR(AIN_internal_Vref, S_IRUGO | S_IWUSR, 723 + static IIO_DEVICE_ATTR(AIN_internal_Vref, 0644, 724 724 adt7316_show_AIN_internal_Vref, 725 725 adt7316_store_AIN_internal_Vref, 726 726 0); ··· 760 760 return len; 761 761 } 762 762 763 - static IIO_DEVICE_ATTR(enable_proportion_DACA, S_IRUGO | S_IWUSR, 763 + static IIO_DEVICE_ATTR(enable_proportion_DACA, 0644, 764 764 adt7316_show_enable_prop_DACA, 765 765 adt7316_store_enable_prop_DACA, 766 766 0); ··· 799 799 return len; 800 800 } 801 801 802 - static IIO_DEVICE_ATTR(enable_proportion_DACB, S_IRUGO | S_IWUSR, 802 + static IIO_DEVICE_ATTR(enable_proportion_DACB, 0644, 803 803 adt7316_show_enable_prop_DACB, 804 804 adt7316_store_enable_prop_DACB, 805 805 0); ··· 842 842 return len; 843 843 } 844 844 845 - static IIO_DEVICE_ATTR(DAC_2Vref_channels_mask, S_IRUGO | S_IWUSR, 845 + static IIO_DEVICE_ATTR(DAC_2Vref_channels_mask, 0644, 846 846 adt7316_show_DAC_2Vref_ch_mask, 847 847 adt7316_store_DAC_2Vref_ch_mask, 848 848 0); ··· 902 902 return len; 903 903 } 904 904 905 - static IIO_DEVICE_ATTR(DAC_update_mode, S_IRUGO | S_IWUSR, 905 + static IIO_DEVICE_ATTR(DAC_update_mode, 0644, 906 906 adt7316_show_DAC_update_mode, 907 907 adt7316_store_DAC_update_mode, 908 908 0); ··· 922 922 return sprintf(buf, "manual\n"); 923 923 } 924 924 925 - static IIO_DEVICE_ATTR(all_DAC_update_modes, S_IRUGO, 925 + static IIO_DEVICE_ATTR(all_DAC_update_modes, 0444, 926 926 adt7316_show_all_DAC_update_modes, NULL, 0); 927 927 928 928 ··· 961 961 return len; 962 962 } 963 963 964 - static IIO_DEVICE_ATTR(update_DAC, S_IRUGO | S_IWUSR, 964 + static IIO_DEVICE_ATTR(update_DAC, 0644, 965 965 NULL, 966 966 adt7316_store_update_DAC, 967 967 0); ··· 1006 1006 return len; 1007 1007 } 1008 1008 1009 - static IIO_DEVICE_ATTR(DA_AB_Vref_bypass, S_IRUGO | S_IWUSR, 1009 + static IIO_DEVICE_ATTR(DA_AB_Vref_bypass, 0644, 1010 1010 adt7316_show_DA_AB_Vref_bypass, 1011 1011 adt7316_store_DA_AB_Vref_bypass, 1012 1012 0); ··· 1051 1051 return len; 1052 1052 } 1053 1053 1054 - static IIO_DEVICE_ATTR(DA_CD_Vref_bypass, S_IRUGO | S_IWUSR, 1054 + static IIO_DEVICE_ATTR(DA_CD_Vref_bypass, 0644, 1055 1055 adt7316_show_DA_CD_Vref_bypass, 1056 1056 adt7316_store_DA_CD_Vref_bypass, 1057 1057 0); ··· 1112 1112 return len; 1113 1113 } 1114 1114 1115 - static IIO_DEVICE_ATTR(DAC_internal_Vref, S_IRUGO | S_IWUSR, 1115 + static IIO_DEVICE_ATTR(DAC_internal_Vref, 0644, 1116 1116 adt7316_show_DAC_internal_Vref, 1117 1117 adt7316_store_DAC_internal_Vref, 1118 1118 0); ··· 1201 1201 1202 1202 return adt7316_show_ad(chip, ADT7316_AD_SINGLE_CH_VDD, buf); 1203 1203 } 1204 - static IIO_DEVICE_ATTR(VDD, S_IRUGO, adt7316_show_VDD, NULL, 0); 1204 + static IIO_DEVICE_ATTR(VDD, 0444, adt7316_show_VDD, NULL, 0); 1205 1205 1206 1206 static ssize_t adt7316_show_in_temp(struct device *dev, 1207 1207 struct device_attribute *attr, ··· 1213 1213 return adt7316_show_ad(chip, ADT7316_AD_SINGLE_CH_IN, buf); 1214 1214 } 1215 1215 1216 - static IIO_DEVICE_ATTR(in_temp, S_IRUGO, adt7316_show_in_temp, NULL, 0); 1216 + static IIO_DEVICE_ATTR(in_temp, 0444, adt7316_show_in_temp, NULL, 0); 1217 1217 1218 1218 static ssize_t adt7316_show_ex_temp_AIN1(struct device *dev, 1219 1219 struct device_attribute *attr, ··· 1225 1225 return adt7316_show_ad(chip, ADT7316_AD_SINGLE_CH_EX, buf); 1226 1226 } 1227 1227 1228 - static IIO_DEVICE_ATTR(ex_temp_AIN1, S_IRUGO, adt7316_show_ex_temp_AIN1, 1228 + static IIO_DEVICE_ATTR(ex_temp_AIN1, 0444, adt7316_show_ex_temp_AIN1, 1229 1229 NULL, 0); 1230 - static IIO_DEVICE_ATTR(ex_temp, S_IRUGO, adt7316_show_ex_temp_AIN1, NULL, 0); 1230 + static IIO_DEVICE_ATTR(ex_temp, 0444, adt7316_show_ex_temp_AIN1, NULL, 0); 1231 1231 1232 1232 static ssize_t adt7316_show_AIN2(struct device *dev, 1233 1233 struct device_attribute *attr, ··· 1238 1238 1239 1239 return adt7316_show_ad(chip, ADT7516_AD_SINGLE_CH_AIN2, buf); 1240 1240 } 1241 - static IIO_DEVICE_ATTR(AIN2, S_IRUGO, adt7316_show_AIN2, NULL, 0); 1241 + static IIO_DEVICE_ATTR(AIN2, 0444, adt7316_show_AIN2, NULL, 0); 1242 1242 1243 1243 static ssize_t adt7316_show_AIN3(struct device *dev, 1244 1244 struct device_attribute *attr, ··· 1249 1249 1250 1250 return adt7316_show_ad(chip, ADT7516_AD_SINGLE_CH_AIN3, buf); 1251 1251 } 1252 - static IIO_DEVICE_ATTR(AIN3, S_IRUGO, adt7316_show_AIN3, NULL, 0); 1252 + static IIO_DEVICE_ATTR(AIN3, 0444, adt7316_show_AIN3, NULL, 0); 1253 1253 1254 1254 static ssize_t adt7316_show_AIN4(struct device *dev, 1255 1255 struct device_attribute *attr, ··· 1260 1260 1261 1261 return adt7316_show_ad(chip, ADT7516_AD_SINGLE_CH_AIN4, buf); 1262 1262 } 1263 - static IIO_DEVICE_ATTR(AIN4, S_IRUGO, adt7316_show_AIN4, NULL, 0); 1263 + static IIO_DEVICE_ATTR(AIN4, 0444, adt7316_show_AIN4, NULL, 0); 1264 1264 1265 1265 static ssize_t adt7316_show_temp_offset(struct adt7316_chip_info *chip, 1266 1266 int offset_addr, char *buf) ··· 1325 1325 len); 1326 1326 } 1327 1327 1328 - static IIO_DEVICE_ATTR(in_temp_offset, S_IRUGO | S_IWUSR, 1328 + static IIO_DEVICE_ATTR(in_temp_offset, 0644, 1329 1329 adt7316_show_in_temp_offset, 1330 1330 adt7316_store_in_temp_offset, 0); 1331 1331 ··· 1351 1351 len); 1352 1352 } 1353 1353 1354 - static IIO_DEVICE_ATTR(ex_temp_offset, S_IRUGO | S_IWUSR, 1354 + static IIO_DEVICE_ATTR(ex_temp_offset, 0644, 1355 1355 adt7316_show_ex_temp_offset, 1356 1356 adt7316_store_ex_temp_offset, 0); 1357 1357 ··· 1378 1378 ADT7316_IN_ANALOG_TEMP_OFFSET, buf, len); 1379 1379 } 1380 1380 1381 - static IIO_DEVICE_ATTR(in_analog_temp_offset, S_IRUGO | S_IWUSR, 1381 + static IIO_DEVICE_ATTR(in_analog_temp_offset, 0644, 1382 1382 adt7316_show_in_analog_temp_offset, 1383 1383 adt7316_store_in_analog_temp_offset, 0); 1384 1384 ··· 1405 1405 ADT7316_EX_ANALOG_TEMP_OFFSET, buf, len); 1406 1406 } 1407 1407 1408 - static IIO_DEVICE_ATTR(ex_analog_temp_offset, S_IRUGO | S_IWUSR, 1408 + static IIO_DEVICE_ATTR(ex_analog_temp_offset, 0644, 1409 1409 adt7316_show_ex_analog_temp_offset, 1410 1410 adt7316_store_ex_analog_temp_offset, 0); 1411 1411 ··· 1500 1500 return adt7316_store_DAC(chip, 0, buf, len); 1501 1501 } 1502 1502 1503 - static IIO_DEVICE_ATTR(DAC_A, S_IRUGO | S_IWUSR, adt7316_show_DAC_A, 1503 + static IIO_DEVICE_ATTR(DAC_A, 0644, adt7316_show_DAC_A, 1504 1504 adt7316_store_DAC_A, 0); 1505 1505 1506 1506 static ssize_t adt7316_show_DAC_B(struct device *dev, ··· 1524 1524 return adt7316_store_DAC(chip, 1, buf, len); 1525 1525 } 1526 1526 1527 - static IIO_DEVICE_ATTR(DAC_B, S_IRUGO | S_IWUSR, adt7316_show_DAC_B, 1527 + static IIO_DEVICE_ATTR(DAC_B, 0644, adt7316_show_DAC_B, 1528 1528 adt7316_store_DAC_B, 0); 1529 1529 1530 1530 static ssize_t adt7316_show_DAC_C(struct device *dev, ··· 1548 1548 return adt7316_store_DAC(chip, 2, buf, len); 1549 1549 } 1550 1550 1551 - static IIO_DEVICE_ATTR(DAC_C, S_IRUGO | S_IWUSR, adt7316_show_DAC_C, 1551 + static IIO_DEVICE_ATTR(DAC_C, 0644, adt7316_show_DAC_C, 1552 1552 adt7316_store_DAC_C, 0); 1553 1553 1554 1554 static ssize_t adt7316_show_DAC_D(struct device *dev, ··· 1572 1572 return adt7316_store_DAC(chip, 3, buf, len); 1573 1573 } 1574 1574 1575 - static IIO_DEVICE_ATTR(DAC_D, S_IRUGO | S_IWUSR, adt7316_show_DAC_D, 1575 + static IIO_DEVICE_ATTR(DAC_D, 0644, adt7316_show_DAC_D, 1576 1576 adt7316_store_DAC_D, 0); 1577 1577 1578 1578 static ssize_t adt7316_show_device_id(struct device *dev, ··· 1591 1591 return sprintf(buf, "%d\n", id); 1592 1592 } 1593 1593 1594 - static IIO_DEVICE_ATTR(device_id, S_IRUGO, adt7316_show_device_id, NULL, 0); 1594 + static IIO_DEVICE_ATTR(device_id, 0444, adt7316_show_device_id, NULL, 0); 1595 1595 1596 1596 static ssize_t adt7316_show_manufactorer_id(struct device *dev, 1597 1597 struct device_attribute *attr, ··· 1609 1609 return sprintf(buf, "%d\n", id); 1610 1610 } 1611 1611 1612 - static IIO_DEVICE_ATTR(manufactorer_id, S_IRUGO, 1612 + static IIO_DEVICE_ATTR(manufactorer_id, 0444, 1613 1613 adt7316_show_manufactorer_id, NULL, 0); 1614 1614 1615 1615 static ssize_t adt7316_show_device_rev(struct device *dev, ··· 1628 1628 return sprintf(buf, "%d\n", rev); 1629 1629 } 1630 1630 1631 - static IIO_DEVICE_ATTR(device_rev, S_IRUGO, adt7316_show_device_rev, NULL, 0); 1631 + static IIO_DEVICE_ATTR(device_rev, 0444, adt7316_show_device_rev, NULL, 0); 1632 1632 1633 1633 static ssize_t adt7316_show_bus_type(struct device *dev, 1634 1634 struct device_attribute *attr, ··· 1649 1649 return sprintf(buf, "i2c\n"); 1650 1650 } 1651 1651 1652 - static IIO_DEVICE_ATTR(bus_type, S_IRUGO, adt7316_show_bus_type, NULL, 0); 1652 + static IIO_DEVICE_ATTR(bus_type, 0444, adt7316_show_bus_type, NULL, 0); 1653 1653 1654 1654 static struct attribute *adt7316_attributes[] = { 1655 1655 &iio_dev_attr_all_modes.dev_attr.attr, ··· 1972 1972 } 1973 1973 1974 1974 static IIO_DEVICE_ATTR(int_mask, 1975 - S_IRUGO | S_IWUSR, 1975 + 0644, 1976 1976 adt7316_show_int_mask, adt7316_set_int_mask, 1977 1977 0); 1978 1978 static IIO_DEVICE_ATTR(in_temp_high_value, 1979 - S_IRUGO | S_IWUSR, 1979 + 0644, 1980 1980 adt7316_show_ad_bound, adt7316_set_ad_bound, 1981 1981 ADT7316_IN_TEMP_HIGH); 1982 1982 static IIO_DEVICE_ATTR(in_temp_low_value, 1983 - S_IRUGO | S_IWUSR, 1983 + 0644, 1984 1984 adt7316_show_ad_bound, adt7316_set_ad_bound, 1985 1985 ADT7316_IN_TEMP_LOW); 1986 1986 static IIO_DEVICE_ATTR(ex_temp_high_value, 1987 - S_IRUGO | S_IWUSR, 1987 + 0644, 1988 1988 adt7316_show_ad_bound, adt7316_set_ad_bound, 1989 1989 ADT7316_EX_TEMP_HIGH); 1990 1990 static IIO_DEVICE_ATTR(ex_temp_low_value, 1991 - S_IRUGO | S_IWUSR, 1991 + 0644, 1992 1992 adt7316_show_ad_bound, adt7316_set_ad_bound, 1993 1993 ADT7316_EX_TEMP_LOW); 1994 1994 1995 1995 /* NASTY duplication to be fixed */ 1996 1996 static IIO_DEVICE_ATTR(ex_temp_ain1_high_value, 1997 - S_IRUGO | S_IWUSR, 1997 + 0644, 1998 1998 adt7316_show_ad_bound, adt7316_set_ad_bound, 1999 1999 ADT7316_EX_TEMP_HIGH); 2000 2000 static IIO_DEVICE_ATTR(ex_temp_ain1_low_value, 2001 - S_IRUGO | S_IWUSR, 2001 + 0644, 2002 2002 adt7316_show_ad_bound, adt7316_set_ad_bound, 2003 2003 ADT7316_EX_TEMP_LOW); 2004 2004 static IIO_DEVICE_ATTR(ain2_high_value, 2005 - S_IRUGO | S_IWUSR, 2005 + 0644, 2006 2006 adt7316_show_ad_bound, adt7316_set_ad_bound, 2007 2007 ADT7516_AIN2_HIGH); 2008 2008 static IIO_DEVICE_ATTR(ain2_low_value, 2009 - S_IRUGO | S_IWUSR, 2009 + 0644, 2010 2010 adt7316_show_ad_bound, adt7316_set_ad_bound, 2011 2011 ADT7516_AIN2_LOW); 2012 2012 static IIO_DEVICE_ATTR(ain3_high_value, 2013 - S_IRUGO | S_IWUSR, 2013 + 0644, 2014 2014 adt7316_show_ad_bound, adt7316_set_ad_bound, 2015 2015 ADT7516_AIN3_HIGH); 2016 2016 static IIO_DEVICE_ATTR(ain3_low_value, 2017 - S_IRUGO | S_IWUSR, 2017 + 0644, 2018 2018 adt7316_show_ad_bound, adt7316_set_ad_bound, 2019 2019 ADT7516_AIN3_LOW); 2020 2020 static IIO_DEVICE_ATTR(ain4_high_value, 2021 - S_IRUGO | S_IWUSR, 2021 + 0644, 2022 2022 adt7316_show_ad_bound, adt7316_set_ad_bound, 2023 2023 ADT7516_AIN4_HIGH); 2024 2024 static IIO_DEVICE_ATTR(ain4_low_value, 2025 - S_IRUGO | S_IWUSR, 2025 + 0644, 2026 2026 adt7316_show_ad_bound, adt7316_set_ad_bound, 2027 2027 ADT7516_AIN4_LOW); 2028 2028 static IIO_DEVICE_ATTR(int_enabled, 2029 - S_IRUGO | S_IWUSR, 2029 + 0644, 2030 2030 adt7316_show_int_enabled, 2031 2031 adt7316_set_int_enabled, 0); 2032 2032
+4 -4
drivers/staging/iio/cdc/ad7152.c
··· 41 41 #define AD7152_REG_CFG2 26 42 42 43 43 /* Status Register Bit Designations (AD7152_REG_STATUS) */ 44 - #define AD7152_STATUS_RDY1 (1 << 0) 45 - #define AD7152_STATUS_RDY2 (1 << 1) 46 - #define AD7152_STATUS_C1C2 (1 << 2) 47 - #define AD7152_STATUS_PWDN (1 << 7) 44 + #define AD7152_STATUS_RDY1 BIT(0) 45 + #define AD7152_STATUS_RDY2 BIT(1) 46 + #define AD7152_STATUS_C1C2 BIT(2) 47 + #define AD7152_STATUS_PWDN BIT(7) 48 48 49 49 /* Setup Register Bit Designations (AD7152_REG_CHx_SETUP) */ 50 50 #define AD7152_SETUP_CAPDIFF (1 << 5)
+92
drivers/staging/iio/frequency/ad9832.c
··· 22 22 23 23 #include "ad9832.h" 24 24 25 + /* Registers */ 26 + 27 + #define AD9832_FREQ0LL 0x0 28 + #define AD9832_FREQ0HL 0x1 29 + #define AD9832_FREQ0LM 0x2 30 + #define AD9832_FREQ0HM 0x3 31 + #define AD9832_FREQ1LL 0x4 32 + #define AD9832_FREQ1HL 0x5 33 + #define AD9832_FREQ1LM 0x6 34 + #define AD9832_FREQ1HM 0x7 35 + #define AD9832_PHASE0L 0x8 36 + #define AD9832_PHASE0H 0x9 37 + #define AD9832_PHASE1L 0xA 38 + #define AD9832_PHASE1H 0xB 39 + #define AD9832_PHASE2L 0xC 40 + #define AD9832_PHASE2H 0xD 41 + #define AD9832_PHASE3L 0xE 42 + #define AD9832_PHASE3H 0xF 43 + 44 + #define AD9832_PHASE_SYM 0x10 45 + #define AD9832_FREQ_SYM 0x11 46 + #define AD9832_PINCTRL_EN 0x12 47 + #define AD9832_OUTPUT_EN 0x13 48 + 49 + /* Command Control Bits */ 50 + 51 + #define AD9832_CMD_PHA8BITSW 0x1 52 + #define AD9832_CMD_PHA16BITSW 0x0 53 + #define AD9832_CMD_FRE8BITSW 0x3 54 + #define AD9832_CMD_FRE16BITSW 0x2 55 + #define AD9832_CMD_FPSELECT 0x6 56 + #define AD9832_CMD_SYNCSELSRC 0x8 57 + #define AD9832_CMD_SLEEPRESCLR 0xC 58 + 59 + #define AD9832_FREQ BIT(11) 60 + #define AD9832_PHASE(x) (((x) & 3) << 9) 61 + #define AD9832_SYNC BIT(13) 62 + #define AD9832_SELSRC BIT(12) 63 + #define AD9832_SLEEP BIT(13) 64 + #define AD9832_RESET BIT(12) 65 + #define AD9832_CLR BIT(11) 66 + #define CMD_SHIFT 12 67 + #define ADD_SHIFT 8 68 + #define AD9832_FREQ_BITS 32 69 + #define AD9832_PHASE_BITS 12 70 + #define RES_MASK(bits) ((1 << (bits)) - 1) 71 + 72 + /** 73 + * struct ad9832_state - driver instance specific data 74 + * @spi: spi_device 75 + * @avdd: supply regulator for the analog section 76 + * @dvdd: supply regulator for the digital section 77 + * @mclk: external master clock 78 + * @ctrl_fp: cached frequency/phase control word 79 + * @ctrl_ss: cached sync/selsrc control word 80 + * @ctrl_src: cached sleep/reset/clr word 81 + * @xfer: default spi transfer 82 + * @msg: default spi message 83 + * @freq_xfer: tuning word spi transfer 84 + * @freq_msg: tuning word spi message 85 + * @phase_xfer: tuning word spi transfer 86 + * @phase_msg: tuning word spi message 87 + * @data: spi transmit buffer 88 + * @phase_data: tuning word spi transmit buffer 89 + * @freq_data: tuning word spi transmit buffer 90 + */ 91 + 92 + struct ad9832_state { 93 + struct spi_device *spi; 94 + struct regulator *avdd; 95 + struct regulator *dvdd; 96 + unsigned long mclk; 97 + unsigned short ctrl_fp; 98 + unsigned short ctrl_ss; 99 + unsigned short ctrl_src; 100 + struct spi_transfer xfer; 101 + struct spi_message msg; 102 + struct spi_transfer freq_xfer[4]; 103 + struct spi_message freq_msg; 104 + struct spi_transfer phase_xfer[2]; 105 + struct spi_message phase_msg; 106 + /* 107 + * DMA (thus cache coherency maintenance) requires the 108 + * transfer buffers to live in their own cache lines. 109 + */ 110 + union { 111 + __be16 freq_data[4]____cacheline_aligned; 112 + __be16 phase_data[2]; 113 + __be16 data; 114 + }; 115 + }; 116 + 25 117 static unsigned long ad9832_calc_freqreg(unsigned long mclk, unsigned long fout) 26 118 { 27 119 unsigned long long freqreg = (u64)fout *
-92
drivers/staging/iio/frequency/ad9832.h
··· 8 8 #ifndef IIO_DDS_AD9832_H_ 9 9 #define IIO_DDS_AD9832_H_ 10 10 11 - /* Registers */ 12 - 13 - #define AD9832_FREQ0LL 0x0 14 - #define AD9832_FREQ0HL 0x1 15 - #define AD9832_FREQ0LM 0x2 16 - #define AD9832_FREQ0HM 0x3 17 - #define AD9832_FREQ1LL 0x4 18 - #define AD9832_FREQ1HL 0x5 19 - #define AD9832_FREQ1LM 0x6 20 - #define AD9832_FREQ1HM 0x7 21 - #define AD9832_PHASE0L 0x8 22 - #define AD9832_PHASE0H 0x9 23 - #define AD9832_PHASE1L 0xA 24 - #define AD9832_PHASE1H 0xB 25 - #define AD9832_PHASE2L 0xC 26 - #define AD9832_PHASE2H 0xD 27 - #define AD9832_PHASE3L 0xE 28 - #define AD9832_PHASE3H 0xF 29 - 30 - #define AD9832_PHASE_SYM 0x10 31 - #define AD9832_FREQ_SYM 0x11 32 - #define AD9832_PINCTRL_EN 0x12 33 - #define AD9832_OUTPUT_EN 0x13 34 - 35 - /* Command Control Bits */ 36 - 37 - #define AD9832_CMD_PHA8BITSW 0x1 38 - #define AD9832_CMD_PHA16BITSW 0x0 39 - #define AD9832_CMD_FRE8BITSW 0x3 40 - #define AD9832_CMD_FRE16BITSW 0x2 41 - #define AD9832_CMD_FPSELECT 0x6 42 - #define AD9832_CMD_SYNCSELSRC 0x8 43 - #define AD9832_CMD_SLEEPRESCLR 0xC 44 - 45 - #define AD9832_FREQ BIT(11) 46 - #define AD9832_PHASE(x) (((x) & 3) << 9) 47 - #define AD9832_SYNC BIT(13) 48 - #define AD9832_SELSRC BIT(12) 49 - #define AD9832_SLEEP BIT(13) 50 - #define AD9832_RESET BIT(12) 51 - #define AD9832_CLR BIT(11) 52 - #define CMD_SHIFT 12 53 - #define ADD_SHIFT 8 54 - #define AD9832_FREQ_BITS 32 55 - #define AD9832_PHASE_BITS 12 56 - #define RES_MASK(bits) ((1 << (bits)) - 1) 57 - 58 - /** 59 - * struct ad9832_state - driver instance specific data 60 - * @spi: spi_device 61 - * @avdd: supply regulator for the analog section 62 - * @dvdd: supply regulator for the digital section 63 - * @mclk: external master clock 64 - * @ctrl_fp: cached frequency/phase control word 65 - * @ctrl_ss: cached sync/selsrc control word 66 - * @ctrl_src: cached sleep/reset/clr word 67 - * @xfer: default spi transfer 68 - * @msg: default spi message 69 - * @freq_xfer: tuning word spi transfer 70 - * @freq_msg: tuning word spi message 71 - * @phase_xfer: tuning word spi transfer 72 - * @phase_msg: tuning word spi message 73 - * @data: spi transmit buffer 74 - * @phase_data: tuning word spi transmit buffer 75 - * @freq_data: tuning word spi transmit buffer 76 - */ 77 - 78 - struct ad9832_state { 79 - struct spi_device *spi; 80 - struct regulator *avdd; 81 - struct regulator *dvdd; 82 - unsigned long mclk; 83 - unsigned short ctrl_fp; 84 - unsigned short ctrl_ss; 85 - unsigned short ctrl_src; 86 - struct spi_transfer xfer; 87 - struct spi_message msg; 88 - struct spi_transfer freq_xfer[4]; 89 - struct spi_message freq_msg; 90 - struct spi_transfer phase_xfer[2]; 91 - struct spi_message phase_msg; 92 - /* 93 - * DMA (thus cache coherency maintenance) requires the 94 - * transfer buffers to live in their own cache lines. 95 - */ 96 - union { 97 - __be16 freq_data[4]____cacheline_aligned; 98 - __be16 phase_data[2]; 99 - __be16 data; 100 - }; 101 - }; 102 - 103 11 /* 104 12 * TODO: struct ad9832_platform_data needs to go into include/linux/iio 105 13 */
+72
drivers/staging/iio/frequency/ad9834.c
··· 25 25 26 26 #include "ad9834.h" 27 27 28 + /* Registers */ 29 + 30 + #define AD9834_REG_CMD 0 31 + #define AD9834_REG_FREQ0 BIT(14) 32 + #define AD9834_REG_FREQ1 BIT(15) 33 + #define AD9834_REG_PHASE0 (BIT(15) | BIT(14)) 34 + #define AD9834_REG_PHASE1 (BIT(15) | BIT(14) | BIT(13)) 35 + 36 + /* Command Control Bits */ 37 + 38 + #define AD9834_B28 BIT(13) 39 + #define AD9834_HLB BIT(12) 40 + #define AD9834_FSEL BIT(11) 41 + #define AD9834_PSEL BIT(10) 42 + #define AD9834_PIN_SW BIT(9) 43 + #define AD9834_RESET BIT(8) 44 + #define AD9834_SLEEP1 BIT(7) 45 + #define AD9834_SLEEP12 BIT(6) 46 + #define AD9834_OPBITEN BIT(5) 47 + #define AD9834_SIGN_PIB BIT(4) 48 + #define AD9834_DIV2 BIT(3) 49 + #define AD9834_MODE BIT(1) 50 + 51 + #define AD9834_FREQ_BITS 28 52 + #define AD9834_PHASE_BITS 12 53 + 54 + #define RES_MASK(bits) (BIT(bits) - 1) 55 + 56 + /** 57 + * struct ad9834_state - driver instance specific data 58 + * @spi: spi_device 59 + * @reg: supply regulator 60 + * @mclk: external master clock 61 + * @control: cached control word 62 + * @xfer: default spi transfer 63 + * @msg: default spi message 64 + * @freq_xfer: tuning word spi transfer 65 + * @freq_msg: tuning word spi message 66 + * @data: spi transmit buffer 67 + * @freq_data: tuning word spi transmit buffer 68 + */ 69 + 70 + struct ad9834_state { 71 + struct spi_device *spi; 72 + struct regulator *reg; 73 + unsigned int mclk; 74 + unsigned short control; 75 + unsigned short devid; 76 + struct spi_transfer xfer; 77 + struct spi_message msg; 78 + struct spi_transfer freq_xfer[2]; 79 + struct spi_message freq_msg; 80 + 81 + /* 82 + * DMA (thus cache coherency maintenance) requires the 83 + * transfer buffers to live in their own cache lines. 84 + */ 85 + __be16 data ____cacheline_aligned; 86 + __be16 freq_data[2]; 87 + }; 88 + 89 + /** 90 + * ad9834_supported_device_ids: 91 + */ 92 + 93 + enum ad9834_supported_device_ids { 94 + ID_AD9833, 95 + ID_AD9834, 96 + ID_AD9837, 97 + ID_AD9838, 98 + }; 99 + 28 100 static unsigned int ad9834_calc_freqreg(unsigned long mclk, unsigned long fout) 29 101 { 30 102 unsigned long long freqreg = (u64)fout * (u64)BIT(AD9834_FREQ_BITS);
-72
drivers/staging/iio/frequency/ad9834.h
··· 8 8 #ifndef IIO_DDS_AD9834_H_ 9 9 #define IIO_DDS_AD9834_H_ 10 10 11 - /* Registers */ 12 - 13 - #define AD9834_REG_CMD 0 14 - #define AD9834_REG_FREQ0 BIT(14) 15 - #define AD9834_REG_FREQ1 BIT(15) 16 - #define AD9834_REG_PHASE0 (BIT(15) | BIT(14)) 17 - #define AD9834_REG_PHASE1 (BIT(15) | BIT(14) | BIT(13)) 18 - 19 - /* Command Control Bits */ 20 - 21 - #define AD9834_B28 BIT(13) 22 - #define AD9834_HLB BIT(12) 23 - #define AD9834_FSEL BIT(11) 24 - #define AD9834_PSEL BIT(10) 25 - #define AD9834_PIN_SW BIT(9) 26 - #define AD9834_RESET BIT(8) 27 - #define AD9834_SLEEP1 BIT(7) 28 - #define AD9834_SLEEP12 BIT(6) 29 - #define AD9834_OPBITEN BIT(5) 30 - #define AD9834_SIGN_PIB BIT(4) 31 - #define AD9834_DIV2 BIT(3) 32 - #define AD9834_MODE BIT(1) 33 - 34 - #define AD9834_FREQ_BITS 28 35 - #define AD9834_PHASE_BITS 12 36 - 37 - #define RES_MASK(bits) (BIT(bits) - 1) 38 - 39 - /** 40 - * struct ad9834_state - driver instance specific data 41 - * @spi: spi_device 42 - * @reg: supply regulator 43 - * @mclk: external master clock 44 - * @control: cached control word 45 - * @xfer: default spi transfer 46 - * @msg: default spi message 47 - * @freq_xfer: tuning word spi transfer 48 - * @freq_msg: tuning word spi message 49 - * @data: spi transmit buffer 50 - * @freq_data: tuning word spi transmit buffer 51 - */ 52 - 53 - struct ad9834_state { 54 - struct spi_device *spi; 55 - struct regulator *reg; 56 - unsigned int mclk; 57 - unsigned short control; 58 - unsigned short devid; 59 - struct spi_transfer xfer; 60 - struct spi_message msg; 61 - struct spi_transfer freq_xfer[2]; 62 - struct spi_message freq_msg; 63 - 64 - /* 65 - * DMA (thus cache coherency maintenance) requires the 66 - * transfer buffers to live in their own cache lines. 67 - */ 68 - __be16 data ____cacheline_aligned; 69 - __be16 freq_data[2]; 70 - }; 71 - 72 11 /* 73 12 * TODO: struct ad7887_platform_data needs to go into include/linux/iio 74 13 */ ··· 34 95 unsigned short phase1; 35 96 bool en_div2; 36 97 bool en_signbit_msb_out; 37 - }; 38 - 39 - /** 40 - * ad9834_supported_device_ids: 41 - */ 42 - 43 - enum ad9834_supported_device_ids { 44 - ID_AD9833, 45 - ID_AD9834, 46 - ID_AD9837, 47 - ID_AD9838, 48 98 }; 49 99 50 100 #endif /* IIO_DDS_AD9834_H_ */
+8 -8
drivers/staging/iio/impedance-analyzer/ad5933.c
··· 345 345 return ret ? ret : len; 346 346 } 347 347 348 - static IIO_DEVICE_ATTR(out_voltage0_freq_start, S_IRUGO | S_IWUSR, 348 + static IIO_DEVICE_ATTR(out_voltage0_freq_start, 0644, 349 349 ad5933_show_frequency, 350 350 ad5933_store_frequency, 351 351 AD5933_REG_FREQ_START); 352 352 353 - static IIO_DEVICE_ATTR(out_voltage0_freq_increment, S_IRUGO | S_IWUSR, 353 + static IIO_DEVICE_ATTR(out_voltage0_freq_increment, 0644, 354 354 ad5933_show_frequency, 355 355 ad5933_store_frequency, 356 356 AD5933_REG_FREQ_INC); ··· 469 469 return ret ? ret : len; 470 470 } 471 471 472 - static IIO_DEVICE_ATTR(out_voltage0_scale, S_IRUGO | S_IWUSR, 472 + static IIO_DEVICE_ATTR(out_voltage0_scale, 0644, 473 473 ad5933_show, 474 474 ad5933_store, 475 475 AD5933_OUT_RANGE); 476 476 477 - static IIO_DEVICE_ATTR(out_voltage0_scale_available, S_IRUGO, 477 + static IIO_DEVICE_ATTR(out_voltage0_scale_available, 0444, 478 478 ad5933_show, 479 479 NULL, 480 480 AD5933_OUT_RANGE_AVAIL); 481 481 482 - static IIO_DEVICE_ATTR(in_voltage0_scale, S_IRUGO | S_IWUSR, 482 + static IIO_DEVICE_ATTR(in_voltage0_scale, 0644, 483 483 ad5933_show, 484 484 ad5933_store, 485 485 AD5933_IN_PGA_GAIN); 486 486 487 - static IIO_DEVICE_ATTR(in_voltage0_scale_available, S_IRUGO, 487 + static IIO_DEVICE_ATTR(in_voltage0_scale_available, 0444, 488 488 ad5933_show, 489 489 NULL, 490 490 AD5933_IN_PGA_GAIN_AVAIL); 491 491 492 - static IIO_DEVICE_ATTR(out_voltage0_freq_points, S_IRUGO | S_IWUSR, 492 + static IIO_DEVICE_ATTR(out_voltage0_freq_points, 0644, 493 493 ad5933_show, 494 494 ad5933_store, 495 495 AD5933_FREQ_POINTS); 496 496 497 - static IIO_DEVICE_ATTR(out_voltage0_settling_cycles, S_IRUGO | S_IWUSR, 497 + static IIO_DEVICE_ATTR(out_voltage0_settling_cycles, 0644, 498 498 ad5933_show, 499 499 ad5933_store, 500 500 AD5933_OUT_SETTLING_CYCLES);
+26 -13
drivers/staging/iio/light/isl29028.c
··· 3 3 * ISL29028 is Concurrent Ambient Light and Proximity Sensor 4 4 * 5 5 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. 6 + * Copyright (c) 2016-2017 Brian Masney <masneyb@onstation.org> 6 7 * 7 8 * This program is free software; you can redistribute it and/or modify it 8 9 * under the terms and conditions of the GNU General Public License, ··· 64 63 65 64 #define ISL29028_POWER_OFF_DELAY_MS 2000 66 65 66 + static const unsigned int isl29028_prox_sleep_time[] = {800, 400, 200, 100, 75, 67 + 50, 12, 0}; 68 + 67 69 enum isl29028_als_ir_mode { 68 70 ISL29028_MODE_NONE = 0, 69 71 ISL29028_MODE_ALS, ··· 82 78 enum isl29028_als_ir_mode als_ir_mode; 83 79 }; 84 80 81 + static int isl29028_find_prox_sleep_time_index(int sampling) 82 + { 83 + unsigned int period = DIV_ROUND_UP(1000, sampling); 84 + int i; 85 + 86 + for (i = 0; i < ARRAY_SIZE(isl29028_prox_sleep_time); ++i) { 87 + if (period >= isl29028_prox_sleep_time[i]) 88 + break; 89 + } 90 + 91 + return i; 92 + } 93 + 85 94 static int isl29028_set_proxim_sampling(struct isl29028_chip *chip, 86 95 unsigned int sampling) 87 96 { 88 97 struct device *dev = regmap_get_device(chip->regmap); 89 - static unsigned int prox_period[] = {800, 400, 200, 100, 75, 50, 12, 0}; 90 - unsigned int period = DIV_ROUND_UP(1000, sampling); 91 - int sel, ret; 98 + int sleep_index, ret; 92 99 93 - for (sel = 0; sel < ARRAY_SIZE(prox_period); ++sel) { 94 - if (period >= prox_period[sel]) 95 - break; 96 - } 97 - 100 + sleep_index = isl29028_find_prox_sleep_time_index(sampling); 98 101 ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, 99 102 ISL29028_CONF_PROX_SLP_MASK, 100 - sel << ISL29028_CONF_PROX_SLP_SH); 103 + sleep_index << ISL29028_CONF_PROX_SLP_SH); 101 104 102 105 if (ret < 0) { 103 106 dev_err(dev, "%s(): Error %d setting the proximity sampling\n", ··· 119 108 120 109 static int isl29028_enable_proximity(struct isl29028_chip *chip) 121 110 { 122 - int ret; 111 + int sleep_index, ret; 123 112 124 113 ret = isl29028_set_proxim_sampling(chip, chip->prox_sampling); 125 114 if (ret < 0) ··· 132 121 return ret; 133 122 134 123 /* Wait for conversion to be complete for first sample */ 135 - mdelay(DIV_ROUND_UP(1000, chip->prox_sampling)); 124 + sleep_index = isl29028_find_prox_sleep_time_index(chip->prox_sampling); 125 + msleep(isl29028_prox_sleep_time[sleep_index]); 136 126 137 127 return 0; 138 128 } ··· 204 192 return ret; 205 193 206 194 /* Need to wait for conversion time if ALS/IR mode enabled */ 207 - mdelay(ISL29028_CONV_TIME_MS); 195 + msleep(ISL29028_CONV_TIME_MS); 208 196 209 197 chip->als_ir_mode = mode; 210 198 ··· 657 645 } 658 646 659 647 static const struct dev_pm_ops isl29028_pm_ops = { 660 - SET_SYSTEM_SLEEP_PM_OPS(isl29028_suspend, isl29028_resume) 648 + SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, 649 + pm_runtime_force_resume) 661 650 SET_RUNTIME_PM_OPS(isl29028_suspend, isl29028_resume, NULL) 662 651 }; 663 652
+74 -8
drivers/staging/iio/meter/ade7753.c
··· 6 6 * Licensed under the GPL-2 or later. 7 7 */ 8 8 9 + #include <linux/delay.h> 10 + #include <linux/device.h> 9 11 #include <linux/interrupt.h> 10 12 #include <linux/irq.h> 11 - #include <linux/delay.h> 12 - #include <linux/mutex.h> 13 - #include <linux/device.h> 14 13 #include <linux/kernel.h> 15 - #include <linux/spi/spi.h> 16 - #include <linux/slab.h> 17 - #include <linux/sysfs.h> 18 14 #include <linux/list.h> 19 15 #include <linux/module.h> 20 - 16 + #include <linux/mutex.h> 17 + #include <linux/slab.h> 18 + #include <linux/sysfs.h> 21 19 #include <linux/iio/iio.h> 22 20 #include <linux/iio/sysfs.h> 21 + #include <linux/spi/spi.h> 23 22 #include "meter.h" 24 - #include "ade7753.h" 23 + 24 + #define ADE7753_WAVEFORM 0x01 25 + #define ADE7753_AENERGY 0x02 26 + #define ADE7753_RAENERGY 0x03 27 + #define ADE7753_LAENERGY 0x04 28 + #define ADE7753_VAENERGY 0x05 29 + #define ADE7753_RVAENERGY 0x06 30 + #define ADE7753_LVAENERGY 0x07 31 + #define ADE7753_LVARENERGY 0x08 32 + #define ADE7753_MODE 0x09 33 + #define ADE7753_IRQEN 0x0A 34 + #define ADE7753_STATUS 0x0B 35 + #define ADE7753_RSTSTATUS 0x0C 36 + #define ADE7753_CH1OS 0x0D 37 + #define ADE7753_CH2OS 0x0E 38 + #define ADE7753_GAIN 0x0F 39 + #define ADE7753_PHCAL 0x10 40 + #define ADE7753_APOS 0x11 41 + #define ADE7753_WGAIN 0x12 42 + #define ADE7753_WDIV 0x13 43 + #define ADE7753_CFNUM 0x14 44 + #define ADE7753_CFDEN 0x15 45 + #define ADE7753_IRMS 0x16 46 + #define ADE7753_VRMS 0x17 47 + #define ADE7753_IRMSOS 0x18 48 + #define ADE7753_VRMSOS 0x19 49 + #define ADE7753_VAGAIN 0x1A 50 + #define ADE7753_VADIV 0x1B 51 + #define ADE7753_LINECYC 0x1C 52 + #define ADE7753_ZXTOUT 0x1D 53 + #define ADE7753_SAGCYC 0x1E 54 + #define ADE7753_SAGLVL 0x1F 55 + #define ADE7753_IPKLVL 0x20 56 + #define ADE7753_VPKLVL 0x21 57 + #define ADE7753_IPEAK 0x22 58 + #define ADE7753_RSTIPEAK 0x23 59 + #define ADE7753_VPEAK 0x24 60 + #define ADE7753_RSTVPEAK 0x25 61 + #define ADE7753_TEMP 0x26 62 + #define ADE7753_PERIOD 0x27 63 + #define ADE7753_TMODE 0x3D 64 + #define ADE7753_CHKSUM 0x3E 65 + #define ADE7753_DIEREV 0x3F 66 + 67 + #define ADE7753_READ_REG(a) a 68 + #define ADE7753_WRITE_REG(a) ((a) | 0x80) 69 + 70 + #define ADE7753_MAX_TX 4 71 + #define ADE7753_MAX_RX 4 72 + #define ADE7753_STARTUP_DELAY 1000 73 + 74 + #define ADE7753_SPI_SLOW (u32)(300 * 1000) 75 + #define ADE7753_SPI_BURST (u32)(1000 * 1000) 76 + #define ADE7753_SPI_FAST (u32)(2000 * 1000) 77 + 78 + /** 79 + * struct ade7753_state - device instance specific data 80 + * @us: actual spi_device 81 + * @tx: transmit buffer 82 + * @rx: receive buffer 83 + * @buf_lock: mutex to protect tx and rx 84 + **/ 85 + struct ade7753_state { 86 + struct spi_device *us; 87 + struct mutex buf_lock; 88 + u8 tx[ADE7753_MAX_TX] ____cacheline_aligned; 89 + u8 rx[ADE7753_MAX_RX]; 90 + }; 25 91 26 92 static int ade7753_spi_write_reg_8(struct device *dev, 27 93 u8 reg_address,
-72
drivers/staging/iio/meter/ade7753.h
··· 1 - #ifndef _ADE7753_H 2 - #define _ADE7753_H 3 - 4 - #define ADE7753_WAVEFORM 0x01 5 - #define ADE7753_AENERGY 0x02 6 - #define ADE7753_RAENERGY 0x03 7 - #define ADE7753_LAENERGY 0x04 8 - #define ADE7753_VAENERGY 0x05 9 - #define ADE7753_RVAENERGY 0x06 10 - #define ADE7753_LVAENERGY 0x07 11 - #define ADE7753_LVARENERGY 0x08 12 - #define ADE7753_MODE 0x09 13 - #define ADE7753_IRQEN 0x0A 14 - #define ADE7753_STATUS 0x0B 15 - #define ADE7753_RSTSTATUS 0x0C 16 - #define ADE7753_CH1OS 0x0D 17 - #define ADE7753_CH2OS 0x0E 18 - #define ADE7753_GAIN 0x0F 19 - #define ADE7753_PHCAL 0x10 20 - #define ADE7753_APOS 0x11 21 - #define ADE7753_WGAIN 0x12 22 - #define ADE7753_WDIV 0x13 23 - #define ADE7753_CFNUM 0x14 24 - #define ADE7753_CFDEN 0x15 25 - #define ADE7753_IRMS 0x16 26 - #define ADE7753_VRMS 0x17 27 - #define ADE7753_IRMSOS 0x18 28 - #define ADE7753_VRMSOS 0x19 29 - #define ADE7753_VAGAIN 0x1A 30 - #define ADE7753_VADIV 0x1B 31 - #define ADE7753_LINECYC 0x1C 32 - #define ADE7753_ZXTOUT 0x1D 33 - #define ADE7753_SAGCYC 0x1E 34 - #define ADE7753_SAGLVL 0x1F 35 - #define ADE7753_IPKLVL 0x20 36 - #define ADE7753_VPKLVL 0x21 37 - #define ADE7753_IPEAK 0x22 38 - #define ADE7753_RSTIPEAK 0x23 39 - #define ADE7753_VPEAK 0x24 40 - #define ADE7753_RSTVPEAK 0x25 41 - #define ADE7753_TEMP 0x26 42 - #define ADE7753_PERIOD 0x27 43 - #define ADE7753_TMODE 0x3D 44 - #define ADE7753_CHKSUM 0x3E 45 - #define ADE7753_DIEREV 0x3F 46 - 47 - #define ADE7753_READ_REG(a) a 48 - #define ADE7753_WRITE_REG(a) ((a) | 0x80) 49 - 50 - #define ADE7753_MAX_TX 4 51 - #define ADE7753_MAX_RX 4 52 - #define ADE7753_STARTUP_DELAY 1000 53 - 54 - #define ADE7753_SPI_SLOW (u32)(300 * 1000) 55 - #define ADE7753_SPI_BURST (u32)(1000 * 1000) 56 - #define ADE7753_SPI_FAST (u32)(2000 * 1000) 57 - 58 - /** 59 - * struct ade7753_state - device instance specific data 60 - * @us: actual spi_device 61 - * @tx: transmit buffer 62 - * @rx: receive buffer 63 - * @buf_lock: mutex to protect tx and rx 64 - **/ 65 - struct ade7753_state { 66 - struct spi_device *us; 67 - struct mutex buf_lock; 68 - u8 tx[ADE7753_MAX_TX] ____cacheline_aligned; 69 - u8 rx[ADE7753_MAX_RX]; 70 - }; 71 - 72 - #endif
+1 -3
drivers/staging/iio/meter/ade7854.c
··· 426 426 else 427 427 irqen &= ~BIT(17); 428 428 429 - ret = st->write_reg_32(dev, ADE7854_MASK0, irqen); 430 - 431 - return ret; 429 + return st->write_reg_32(dev, ADE7854_MASK0, irqen); 432 430 } 433 431 434 432 static int ade7854_initial_setup(struct iio_dev *indio_dev)
+30 -30
drivers/staging/iio/meter/meter.h
··· 81 81 IIO_DEVICE_ATTR(reactive_power_c_gain, _mode, _show, _store, _addr) 82 82 83 83 #define IIO_DEV_ATTR_CURRENT_A(_show, _addr) \ 84 - IIO_DEVICE_ATTR(current_a, S_IRUGO, _show, NULL, _addr) 84 + IIO_DEVICE_ATTR(current_a, 0444, _show, NULL, _addr) 85 85 86 86 #define IIO_DEV_ATTR_CURRENT_B(_show, _addr) \ 87 - IIO_DEVICE_ATTR(current_b, S_IRUGO, _show, NULL, _addr) 87 + IIO_DEVICE_ATTR(current_b, 0444, _show, NULL, _addr) 88 88 89 89 #define IIO_DEV_ATTR_CURRENT_C(_show, _addr) \ 90 - IIO_DEVICE_ATTR(current_c, S_IRUGO, _show, NULL, _addr) 90 + IIO_DEVICE_ATTR(current_c, 0444, _show, NULL, _addr) 91 91 92 92 #define IIO_DEV_ATTR_VOLT_A(_show, _addr) \ 93 - IIO_DEVICE_ATTR(volt_a, S_IRUGO, _show, NULL, _addr) 93 + IIO_DEVICE_ATTR(volt_a, 0444, _show, NULL, _addr) 94 94 95 95 #define IIO_DEV_ATTR_VOLT_B(_show, _addr) \ 96 - IIO_DEVICE_ATTR(volt_b, S_IRUGO, _show, NULL, _addr) 96 + IIO_DEVICE_ATTR(volt_b, 0444, _show, NULL, _addr) 97 97 98 98 #define IIO_DEV_ATTR_VOLT_C(_show, _addr) \ 99 - IIO_DEVICE_ATTR(volt_c, S_IRUGO, _show, NULL, _addr) 99 + IIO_DEVICE_ATTR(volt_c, 0444, _show, NULL, _addr) 100 100 101 101 #define IIO_DEV_ATTR_AENERGY(_show, _addr) \ 102 - IIO_DEVICE_ATTR(aenergy, S_IRUGO, _show, NULL, _addr) 102 + IIO_DEVICE_ATTR(aenergy, 0444, _show, NULL, _addr) 103 103 104 104 #define IIO_DEV_ATTR_LENERGY(_show, _addr) \ 105 - IIO_DEVICE_ATTR(lenergy, S_IRUGO, _show, NULL, _addr) 105 + IIO_DEVICE_ATTR(lenergy, 0444, _show, NULL, _addr) 106 106 107 107 #define IIO_DEV_ATTR_RAENERGY(_show, _addr) \ 108 - IIO_DEVICE_ATTR(raenergy, S_IRUGO, _show, NULL, _addr) 108 + IIO_DEVICE_ATTR(raenergy, 0444, _show, NULL, _addr) 109 109 110 110 #define IIO_DEV_ATTR_LAENERGY(_show, _addr) \ 111 - IIO_DEVICE_ATTR(laenergy, S_IRUGO, _show, NULL, _addr) 111 + IIO_DEVICE_ATTR(laenergy, 0444, _show, NULL, _addr) 112 112 113 113 #define IIO_DEV_ATTR_VAENERGY(_show, _addr) \ 114 - IIO_DEVICE_ATTR(vaenergy, S_IRUGO, _show, NULL, _addr) 114 + IIO_DEVICE_ATTR(vaenergy, 0444, _show, NULL, _addr) 115 115 116 116 #define IIO_DEV_ATTR_LVAENERGY(_show, _addr) \ 117 - IIO_DEVICE_ATTR(lvaenergy, S_IRUGO, _show, NULL, _addr) 117 + IIO_DEVICE_ATTR(lvaenergy, 0444, _show, NULL, _addr) 118 118 119 119 #define IIO_DEV_ATTR_RVAENERGY(_show, _addr) \ 120 - IIO_DEVICE_ATTR(rvaenergy, S_IRUGO, _show, NULL, _addr) 120 + IIO_DEVICE_ATTR(rvaenergy, 0444, _show, NULL, _addr) 121 121 122 122 #define IIO_DEV_ATTR_LVARENERGY(_show, _addr) \ 123 - IIO_DEVICE_ATTR(lvarenergy, S_IRUGO, _show, NULL, _addr) 123 + IIO_DEVICE_ATTR(lvarenergy, 0444, _show, NULL, _addr) 124 124 125 125 #define IIO_DEV_ATTR_CHKSUM(_show, _addr) \ 126 - IIO_DEVICE_ATTR(chksum, S_IRUGO, _show, NULL, _addr) 126 + IIO_DEVICE_ATTR(chksum, 0444, _show, NULL, _addr) 127 127 128 128 #define IIO_DEV_ATTR_ANGLE0(_show, _addr) \ 129 - IIO_DEVICE_ATTR(angle0, S_IRUGO, _show, NULL, _addr) 129 + IIO_DEVICE_ATTR(angle0, 0444, _show, NULL, _addr) 130 130 131 131 #define IIO_DEV_ATTR_ANGLE1(_show, _addr) \ 132 - IIO_DEVICE_ATTR(angle1, S_IRUGO, _show, NULL, _addr) 132 + IIO_DEVICE_ATTR(angle1, 0444, _show, NULL, _addr) 133 133 134 134 #define IIO_DEV_ATTR_ANGLE2(_show, _addr) \ 135 - IIO_DEVICE_ATTR(angle2, S_IRUGO, _show, NULL, _addr) 135 + IIO_DEVICE_ATTR(angle2, 0444, _show, NULL, _addr) 136 136 137 137 #define IIO_DEV_ATTR_AWATTHR(_show, _addr) \ 138 - IIO_DEVICE_ATTR(awatthr, S_IRUGO, _show, NULL, _addr) 138 + IIO_DEVICE_ATTR(awatthr, 0444, _show, NULL, _addr) 139 139 140 140 #define IIO_DEV_ATTR_BWATTHR(_show, _addr) \ 141 - IIO_DEVICE_ATTR(bwatthr, S_IRUGO, _show, NULL, _addr) 141 + IIO_DEVICE_ATTR(bwatthr, 0444, _show, NULL, _addr) 142 142 143 143 #define IIO_DEV_ATTR_CWATTHR(_show, _addr) \ 144 - IIO_DEVICE_ATTR(cwatthr, S_IRUGO, _show, NULL, _addr) 144 + IIO_DEVICE_ATTR(cwatthr, 0444, _show, NULL, _addr) 145 145 146 146 #define IIO_DEV_ATTR_AFWATTHR(_show, _addr) \ 147 - IIO_DEVICE_ATTR(afwatthr, S_IRUGO, _show, NULL, _addr) 147 + IIO_DEVICE_ATTR(afwatthr, 0444, _show, NULL, _addr) 148 148 149 149 #define IIO_DEV_ATTR_BFWATTHR(_show, _addr) \ 150 - IIO_DEVICE_ATTR(bfwatthr, S_IRUGO, _show, NULL, _addr) 150 + IIO_DEVICE_ATTR(bfwatthr, 0444, _show, NULL, _addr) 151 151 152 152 #define IIO_DEV_ATTR_CFWATTHR(_show, _addr) \ 153 - IIO_DEVICE_ATTR(cfwatthr, S_IRUGO, _show, NULL, _addr) 153 + IIO_DEVICE_ATTR(cfwatthr, 0444, _show, NULL, _addr) 154 154 155 155 #define IIO_DEV_ATTR_AVARHR(_show, _addr) \ 156 - IIO_DEVICE_ATTR(avarhr, S_IRUGO, _show, NULL, _addr) 156 + IIO_DEVICE_ATTR(avarhr, 0444, _show, NULL, _addr) 157 157 158 158 #define IIO_DEV_ATTR_BVARHR(_show, _addr) \ 159 - IIO_DEVICE_ATTR(bvarhr, S_IRUGO, _show, NULL, _addr) 159 + IIO_DEVICE_ATTR(bvarhr, 0444, _show, NULL, _addr) 160 160 161 161 #define IIO_DEV_ATTR_CVARHR(_show, _addr) \ 162 - IIO_DEVICE_ATTR(cvarhr, S_IRUGO, _show, NULL, _addr) 162 + IIO_DEVICE_ATTR(cvarhr, 0444, _show, NULL, _addr) 163 163 164 164 #define IIO_DEV_ATTR_AVAHR(_show, _addr) \ 165 - IIO_DEVICE_ATTR(avahr, S_IRUGO, _show, NULL, _addr) 165 + IIO_DEVICE_ATTR(avahr, 0444, _show, NULL, _addr) 166 166 167 167 #define IIO_DEV_ATTR_BVAHR(_show, _addr) \ 168 - IIO_DEVICE_ATTR(bvahr, S_IRUGO, _show, NULL, _addr) 168 + IIO_DEVICE_ATTR(bvahr, 0444, _show, NULL, _addr) 169 169 170 170 #define IIO_DEV_ATTR_CVAHR(_show, _addr) \ 171 - IIO_DEVICE_ATTR(cvahr, S_IRUGO, _show, NULL, _addr) 171 + IIO_DEVICE_ATTR(cvahr, 0444, _show, NULL, _addr) 172 172 173 173 #define IIO_DEV_ATTR_IOS(_mode, _show, _store, _addr) \ 174 174 IIO_DEVICE_ATTR(ios, _mode, _show, _store, _addr)
+12 -12
drivers/staging/iio/resolver/ad2s1210.c
··· 531 531 return ret; 532 532 } 533 533 534 - static IIO_DEVICE_ATTR(fclkin, S_IRUGO | S_IWUSR, 534 + static IIO_DEVICE_ATTR(fclkin, 0644, 535 535 ad2s1210_show_fclkin, ad2s1210_store_fclkin, 0); 536 - static IIO_DEVICE_ATTR(fexcit, S_IRUGO | S_IWUSR, 536 + static IIO_DEVICE_ATTR(fexcit, 0644, 537 537 ad2s1210_show_fexcit, ad2s1210_store_fexcit, 0); 538 - static IIO_DEVICE_ATTR(control, S_IRUGO | S_IWUSR, 538 + static IIO_DEVICE_ATTR(control, 0644, 539 539 ad2s1210_show_control, ad2s1210_store_control, 0); 540 - static IIO_DEVICE_ATTR(bits, S_IRUGO | S_IWUSR, 540 + static IIO_DEVICE_ATTR(bits, 0644, 541 541 ad2s1210_show_resolution, ad2s1210_store_resolution, 0); 542 - static IIO_DEVICE_ATTR(fault, S_IRUGO | S_IWUSR, 542 + static IIO_DEVICE_ATTR(fault, 0644, 543 543 ad2s1210_show_fault, ad2s1210_clear_fault, 0); 544 544 545 - static IIO_DEVICE_ATTR(los_thrd, S_IRUGO | S_IWUSR, 545 + static IIO_DEVICE_ATTR(los_thrd, 0644, 546 546 ad2s1210_show_reg, ad2s1210_store_reg, 547 547 AD2S1210_REG_LOS_THRD); 548 - static IIO_DEVICE_ATTR(dos_ovr_thrd, S_IRUGO | S_IWUSR, 548 + static IIO_DEVICE_ATTR(dos_ovr_thrd, 0644, 549 549 ad2s1210_show_reg, ad2s1210_store_reg, 550 550 AD2S1210_REG_DOS_OVR_THRD); 551 - static IIO_DEVICE_ATTR(dos_mis_thrd, S_IRUGO | S_IWUSR, 551 + static IIO_DEVICE_ATTR(dos_mis_thrd, 0644, 552 552 ad2s1210_show_reg, ad2s1210_store_reg, 553 553 AD2S1210_REG_DOS_MIS_THRD); 554 - static IIO_DEVICE_ATTR(dos_rst_max_thrd, S_IRUGO | S_IWUSR, 554 + static IIO_DEVICE_ATTR(dos_rst_max_thrd, 0644, 555 555 ad2s1210_show_reg, ad2s1210_store_reg, 556 556 AD2S1210_REG_DOS_RST_MAX_THRD); 557 - static IIO_DEVICE_ATTR(dos_rst_min_thrd, S_IRUGO | S_IWUSR, 557 + static IIO_DEVICE_ATTR(dos_rst_min_thrd, 0644, 558 558 ad2s1210_show_reg, ad2s1210_store_reg, 559 559 AD2S1210_REG_DOS_RST_MIN_THRD); 560 - static IIO_DEVICE_ATTR(lot_high_thrd, S_IRUGO | S_IWUSR, 560 + static IIO_DEVICE_ATTR(lot_high_thrd, 0644, 561 561 ad2s1210_show_reg, ad2s1210_store_reg, 562 562 AD2S1210_REG_LOT_HIGH_THRD); 563 - static IIO_DEVICE_ATTR(lot_low_thrd, S_IRUGO | S_IWUSR, 563 + static IIO_DEVICE_ATTR(lot_low_thrd, 0644, 564 564 ad2s1210_show_reg, ad2s1210_store_reg, 565 565 AD2S1210_REG_LOT_LOW_THRD); 566 566
+4
include/linux/hid-sensor-ids.h
··· 45 45 #define HID_USAGE_SENSOR_DATA_ATMOSPHERIC_PRESSURE 0x200430 46 46 #define HID_USAGE_SENSOR_ATMOSPHERIC_PRESSURE 0x200431 47 47 48 + /* Tempreture (200033) */ 49 + #define HID_USAGE_SENSOR_TEMPERATURE 0x200033 50 + #define HID_USAGE_SENSOR_DATA_ENVIRONMENTAL_TEMPERATURE 0x200434 51 + 48 52 /* Gyro 3D: (200076) */ 49 53 #define HID_USAGE_SENSOR_GYRO_3D 0x200076 50 54 #define HID_USAGE_SENSOR_DATA_ANGL_VELOCITY 0x200456