From 5b812ea536da6ae88f79b48fbde1df8ad1e32ff2 Mon Sep 17 00:00:00 2001 From: Alexander Holler Date: Wed, 10 Jul 2013 09:31:00 +0100 Subject: iio: hid-sensor-als: add module alias for autoload Add a MODULE_DEVICE_TABLE in order to let hotplug mechanisms automatically load the driver. This makes it also possible to use the usual driver name instead of HID-SENSOR-2000xx which isn't very descriptive in kernel messages. Signed-off-by: Alexander Holler Acked-by:Srinivas Pandruvada Signed-off-by: Jonathan Cameron --- drivers/iio/light/hid-sensor-als.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'drivers/iio/light') diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c index cdc2cad0f01b..9adfef07d8c2 100644 --- a/drivers/iio/light/hid-sensor-als.c +++ b/drivers/iio/light/hid-sensor-als.c @@ -30,10 +30,6 @@ #include #include "../common/hid-sensors/hid-sensor-trigger.h" -/*Format: HID-SENSOR-usage_id_in_hex*/ -/*Usage ID from spec for Ambiant-Light: 0x200041*/ -#define DRIVER_NAME "HID-SENSOR-200041" - #define CHANNEL_SCAN_INDEX_ILLUM 0 struct als_state { @@ -355,9 +351,19 @@ static int hid_als_remove(struct platform_device *pdev) return 0; } +static struct platform_device_id hid_als_ids[] = { + { + /* Format: HID-SENSOR-usage_id_in_hex_lowercase */ + .name = "HID-SENSOR-200041", + }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(platform, hid_als_ids); + static struct platform_driver hid_als_platform_driver = { + .id_table = hid_als_ids, .driver = { - .name = DRIVER_NAME, + .name = KBUILD_MODNAME, .owner = THIS_MODULE, }, .probe = hid_als_probe, -- cgit v1.2.3 From 3edc84e6054616b87a3d155fe65fa51f2eae82aa Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Mon, 15 Jul 2013 08:45:00 +0100 Subject: iio: Add a comment to about alphabetical order to Kconfigs and Makefiles Keeping Makefile and Kconfig entries in alphabetical order usually works better than just appending new entries at the end, since it reduces the amount of conflicts. This patch adds a comment to the IIO Kconfig and Makefile files to document that the entries should be kept in alphabetical order. Also reorder those entries which weren't in alphabetical order yet. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron --- drivers/iio/accel/Kconfig | 16 +++++++++------- drivers/iio/accel/Makefile | 4 ++-- drivers/iio/adc/Kconfig | 36 +++++++++++++++++++----------------- drivers/iio/adc/Makefile | 1 + drivers/iio/amplifiers/Kconfig | 2 ++ drivers/iio/amplifiers/Makefile | 1 + drivers/iio/common/Makefile | 1 + drivers/iio/dac/Kconfig | 38 ++++++++++++++++++++------------------ drivers/iio/dac/Makefile | 1 + drivers/iio/frequency/Kconfig | 1 + drivers/iio/frequency/Makefile | 1 + drivers/iio/gyro/Kconfig | 2 ++ drivers/iio/gyro/Makefile | 1 + drivers/iio/imu/Kconfig | 2 ++ drivers/iio/imu/Makefile | 1 + drivers/iio/light/Kconfig | 24 +++++++++++++----------- drivers/iio/light/Makefile | 3 ++- drivers/iio/magnetometer/Kconfig | 2 ++ drivers/iio/magnetometer/Makefile | 1 + drivers/iio/pressure/Kconfig | 2 ++ drivers/iio/pressure/Makefile | 1 + drivers/iio/trigger/Kconfig | 2 ++ drivers/iio/trigger/Makefile | 1 + 23 files changed, 88 insertions(+), 56 deletions(-) (limited to 'drivers/iio/light') diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig index a00267525b66..61ca7ec0f3e7 100644 --- a/drivers/iio/accel/Kconfig +++ b/drivers/iio/accel/Kconfig @@ -1,6 +1,8 @@ # # Accelerometer drivers # +# When adding new entries keep the list in alphabetical order + menu "Accelerometers" config HID_SENSOR_ACCEL_3D @@ -14,13 +16,6 @@ config HID_SENSOR_ACCEL_3D Say yes here to build support for the HID SENSOR accelerometers 3D. -config KXSD9 - tristate "Kionix KXSD9 Accelerometer Driver" - depends on SPI - help - Say yes here to build support for the Kionix KXSD9 accelerometer. - Currently this only supports the device via an SPI interface. - config IIO_ST_ACCEL_3AXIS tristate "STMicroelectronics accelerometers 3-Axis Driver" depends on (I2C || SPI_MASTER) && SYSFS @@ -51,4 +46,11 @@ config IIO_ST_ACCEL_SPI_3AXIS depends on IIO_ST_ACCEL_3AXIS depends on IIO_ST_SENSORS_SPI +config KXSD9 + tristate "Kionix KXSD9 Accelerometer Driver" + depends on SPI + help + Say yes here to build support for the Kionix KXSD9 accelerometer. + Currently this only supports the device via an SPI interface. + endmenu diff --git a/drivers/iio/accel/Makefile b/drivers/iio/accel/Makefile index 87d8fa264894..2f95a3dffa47 100644 --- a/drivers/iio/accel/Makefile +++ b/drivers/iio/accel/Makefile @@ -2,7 +2,9 @@ # Makefile for industrial I/O accelerometer drivers # +# When adding new entries keep the list in alphabetical order obj-$(CONFIG_HID_SENSOR_ACCEL_3D) += hid-sensor-accel-3d.o +obj-$(CONFIG_KXSD9) += kxsd9.o obj-$(CONFIG_IIO_ST_ACCEL_3AXIS) += st_accel.o st_accel-y := st_accel_core.o @@ -10,5 +12,3 @@ st_accel-$(CONFIG_IIO_BUFFER) += st_accel_buffer.o obj-$(CONFIG_IIO_ST_ACCEL_I2C_3AXIS) += st_accel_i2c.o obj-$(CONFIG_IIO_ST_ACCEL_SPI_3AXIS) += st_accel_spi.o - -obj-$(CONFIG_KXSD9) += kxsd9.o diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index 2eced9d53a0b..dd6bd1bff4b7 100644 --- a/drivers/iio/adc/Kconfig +++ b/drivers/iio/adc/Kconfig @@ -1,6 +1,8 @@ # # ADC drivers # +# When adding new entries keep the list in alphabetical order + menu "Analog to digital converters" config AD_SIGMA_DELTA @@ -30,17 +32,20 @@ config AD7298 To compile this driver as a module, choose M here: the module will be called ad7298. -config AD7923 - tristate "Analog Devices AD7923 and similar ADCs driver" +config AD7476 + tristate "Analog Devices AD7476 and similar 1-channel ADCs driver" depends on SPI select IIO_BUFFER select IIO_TRIGGERED_BUFFER help - Say yes here to build support for Analog Devices - AD7904, AD7914, AD7923, AD7924 4 Channel ADCs. + Say yes here to build support for Analog Devices AD7273, AD7274, AD7276, + AD7277, AD7278, AD7475, AD7476, AD7477, AD7478, AD7466, AD7467, AD7468, + AD7495, AD7910, AD7920, AD7920 SPI analog to digital converters (ADC). + + If unsure, say N (but it's safe to say "Y"). To compile this driver as a module, choose M here: the - module will be called ad7923. + module will be called ad7476. config AD7791 tristate "Analog Devices AD7791 ADC driver" @@ -66,33 +71,30 @@ config AD7793 To compile this driver as a module, choose M here: the module will be called AD7793. -config AD7476 - tristate "Analog Devices AD7476 and similar 1-channel ADCs driver" +config AD7887 + tristate "Analog Devices AD7887 ADC driver" depends on SPI select IIO_BUFFER select IIO_TRIGGERED_BUFFER help - Say yes here to build support for Analog Devices AD7273, AD7274, AD7276, - AD7277, AD7278, AD7475, AD7476, AD7477, AD7478, AD7466, AD7467, AD7468, - AD7495, AD7910, AD7920, AD7920 SPI analog to digital converters (ADC). - + Say yes here to build support for Analog Devices + AD7887 SPI analog to digital converter (ADC). If unsure, say N (but it's safe to say "Y"). To compile this driver as a module, choose M here: the - module will be called ad7476. + module will be called ad7887. -config AD7887 - tristate "Analog Devices AD7887 ADC driver" +config AD7923 + tristate "Analog Devices AD7923 and similar ADCs driver" depends on SPI select IIO_BUFFER select IIO_TRIGGERED_BUFFER help Say yes here to build support for Analog Devices - AD7887 SPI analog to digital converter (ADC). - If unsure, say N (but it's safe to say "Y"). + AD7904, AD7914, AD7923, AD7924 4 Channel ADCs. To compile this driver as a module, choose M here: the - module will be called ad7887. + module will be called ad7923. config AT91_ADC tristate "Atmel AT91 ADC" diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile index d184139d1cd7..2a4324ec7f14 100644 --- a/drivers/iio/adc/Makefile +++ b/drivers/iio/adc/Makefile @@ -2,6 +2,7 @@ # Makefile for IIO ADC drivers # +# When adding new entries keep the list in alphabetical order obj-$(CONFIG_AD_SIGMA_DELTA) += ad_sigma_delta.o obj-$(CONFIG_AD7266) += ad7266.o obj-$(CONFIG_AD7298) += ad7298.o diff --git a/drivers/iio/amplifiers/Kconfig b/drivers/iio/amplifiers/Kconfig index 05d707ed7d4f..e9c5f2cd9257 100644 --- a/drivers/iio/amplifiers/Kconfig +++ b/drivers/iio/amplifiers/Kconfig @@ -1,6 +1,8 @@ # # Gain Amplifiers, etc. # +# When adding new entries keep the list in alphabetical order + menu "Amplifiers" config AD8366 diff --git a/drivers/iio/amplifiers/Makefile b/drivers/iio/amplifiers/Makefile index a6ca366908e0..8da4b787898a 100644 --- a/drivers/iio/amplifiers/Makefile +++ b/drivers/iio/amplifiers/Makefile @@ -2,4 +2,5 @@ # Makefile iio/amplifiers # +# When adding new entries keep the list in alphabetical order obj-$(CONFIG_AD8366) += ad8366.o diff --git a/drivers/iio/common/Makefile b/drivers/iio/common/Makefile index c2352beb5d97..3112df0060e9 100644 --- a/drivers/iio/common/Makefile +++ b/drivers/iio/common/Makefile @@ -6,5 +6,6 @@ # instead of duplicating in each module. # +# When adding new entries keep the list in alphabetical order obj-y += hid-sensors/ obj-y += st_sensors/ diff --git a/drivers/iio/dac/Kconfig b/drivers/iio/dac/Kconfig index b9fd4c7bfd98..3c6a78a75b78 100644 --- a/drivers/iio/dac/Kconfig +++ b/drivers/iio/dac/Kconfig @@ -1,6 +1,8 @@ # # DAC drivers # +# When adding new entries keep the list in alphabetical order + menu "Digital to analog converters" config AD5064 @@ -48,13 +50,6 @@ config AD5421 To compile this driver as module choose M here: the module will be called ad5421. -config AD5624R_SPI - tristate "Analog Devices AD5624/44/64R DAC spi driver" - depends on SPI - help - Say yes here to build support for Analog Devices AD5624R, AD5644R and - AD5664R converters (DAC). This driver uses the common SPI interface. - config AD5446 tristate "Analog Devices AD5446 and similar single channel DACs driver" depends on (SPI_MASTER && I2C!=m) || I2C @@ -87,6 +82,24 @@ config AD5504 To compile this driver as a module, choose M here: the module will be called ad5504. +config AD5624R_SPI + tristate "Analog Devices AD5624/44/64R DAC spi driver" + depends on SPI + help + Say yes here to build support for Analog Devices AD5624R, AD5644R and + AD5664R converters (DAC). This driver uses the common SPI interface. + +config AD5686 + tristate "Analog Devices AD5686R/AD5685R/AD5684R DAC SPI driver" + depends on SPI + help + Say yes here to build support for Analog Devices AD5686R, AD5685R, + AD5684R, AD5791 Voltage Output Digital to + Analog Converter. + + To compile this driver as a module, choose M here: the + module will be called ad5686. + config AD5755 tristate "Analog Devices AD5755/AD5755-1/AD5757/AD5735/AD5737 DAC driver" depends on SPI_MASTER @@ -119,17 +132,6 @@ config AD5791 To compile this driver as a module, choose M here: the module will be called ad5791. -config AD5686 - tristate "Analog Devices AD5686R/AD5685R/AD5684R DAC SPI driver" - depends on SPI - help - Say yes here to build support for Analog Devices AD5686R, AD5685R, - AD5684R, AD5791 Voltage Output Digital to - Analog Converter. - - To compile this driver as a module, choose M here: the - module will be called ad5686. - config AD7303 tristate "Analog Devices AD7303 DAC driver" depends on SPI diff --git a/drivers/iio/dac/Makefile b/drivers/iio/dac/Makefile index c8d7ab6bff01..bb84ad64463f 100644 --- a/drivers/iio/dac/Makefile +++ b/drivers/iio/dac/Makefile @@ -2,6 +2,7 @@ # Makefile for industrial I/O DAC drivers # +# When adding new entries keep the list in alphabetical order obj-$(CONFIG_AD5360) += ad5360.o obj-$(CONFIG_AD5380) += ad5380.o obj-$(CONFIG_AD5421) += ad5421.o diff --git a/drivers/iio/frequency/Kconfig b/drivers/iio/frequency/Kconfig index 6aaa33ef4544..dc5e0b72882f 100644 --- a/drivers/iio/frequency/Kconfig +++ b/drivers/iio/frequency/Kconfig @@ -4,6 +4,7 @@ # Clock Distribution device drivers # Phase-Locked Loop (PLL) frequency synthesizers # +# When adding new entries keep the list in alphabetical order menu "Frequency Synthesizers DDS/PLL" diff --git a/drivers/iio/frequency/Makefile b/drivers/iio/frequency/Makefile index 00d26e5d1dc2..2bca03f3e2e3 100644 --- a/drivers/iio/frequency/Makefile +++ b/drivers/iio/frequency/Makefile @@ -2,5 +2,6 @@ # Makefile iio/frequency # +# When adding new entries keep the list in alphabetical order obj-$(CONFIG_AD9523) += ad9523.o obj-$(CONFIG_ADF4350) += adf4350.o diff --git a/drivers/iio/gyro/Kconfig b/drivers/iio/gyro/Kconfig index 1fdcc8451fdf..5913735bca9a 100644 --- a/drivers/iio/gyro/Kconfig +++ b/drivers/iio/gyro/Kconfig @@ -1,6 +1,8 @@ # # IIO Digital Gyroscope Sensor drivers configuration # +# When adding new entries keep the list in alphabetical order + menu "Digital gyroscope sensors" config ADIS16080 diff --git a/drivers/iio/gyro/Makefile b/drivers/iio/gyro/Makefile index e9dc034aa18b..36091d5a0f45 100644 --- a/drivers/iio/gyro/Makefile +++ b/drivers/iio/gyro/Makefile @@ -2,6 +2,7 @@ # Makefile for industrial I/O gyroscope sensor drivers # +# When adding new entries keep the list in alphabetical order obj-$(CONFIG_ADIS16080) += adis16080.o obj-$(CONFIG_ADIS16130) += adis16130.o obj-$(CONFIG_ADIS16136) += adis16136.o diff --git a/drivers/iio/imu/Kconfig b/drivers/iio/imu/Kconfig index 4f40a10cb74f..663e88a1a3c1 100644 --- a/drivers/iio/imu/Kconfig +++ b/drivers/iio/imu/Kconfig @@ -1,6 +1,8 @@ # # IIO imu drivers configuration # +# When adding new entries keep the list in alphabetical order + menu "Inertial measurement units" config ADIS16400 diff --git a/drivers/iio/imu/Makefile b/drivers/iio/imu/Makefile index f2f56ceaed26..114d2c17cbe2 100644 --- a/drivers/iio/imu/Makefile +++ b/drivers/iio/imu/Makefile @@ -2,6 +2,7 @@ # Makefile for Inertial Measurement Units # +# When adding new entries keep the list in alphabetical order adis16400-y := adis16400_core.o adis16400-$(CONFIG_IIO_BUFFER) += adis16400_buffer.o obj-$(CONFIG_ADIS16400) += adis16400.o diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig index 5ef1a396e0c9..3bd29f810e6d 100644 --- a/drivers/iio/light/Kconfig +++ b/drivers/iio/light/Kconfig @@ -1,6 +1,8 @@ # # Light sensors # +# When adding new entries keep the list in alphabetical order + menu "Light sensors" config ADJD_S311 @@ -15,6 +17,17 @@ config ADJD_S311 This driver can also be built as a module. If so, the module will be called adjd_s311. +config HID_SENSOR_ALS + depends on HID_SENSOR_HUB + select IIO_BUFFER + select IIO_TRIGGERED_BUFFER + select HID_SENSOR_IIO_COMMON + select HID_SENSOR_IIO_TRIGGER + tristate "HID ALS" + help + Say yes here to build support for the HID SENSOR + Ambient light sensor. + config SENSORS_LM3533 tristate "LM3533 ambient light sensor" depends on MFD_LM3533 @@ -52,15 +65,4 @@ config VCNL4000 To compile this driver as a module, choose M here: the module will be called vcnl4000. -config HID_SENSOR_ALS - depends on HID_SENSOR_HUB - select IIO_BUFFER - select IIO_TRIGGERED_BUFFER - select HID_SENSOR_IIO_COMMON - select HID_SENSOR_IIO_TRIGGER - tristate "HID ALS" - help - Say yes here to build support for the HID SENSOR - Ambient light sensor. - endmenu diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile index 040d9c75f8e6..edef939861f0 100644 --- a/drivers/iio/light/Makefile +++ b/drivers/iio/light/Makefile @@ -2,8 +2,9 @@ # Makefile for IIO Light sensors # +# When adding new entries keep the list in alphabetical order obj-$(CONFIG_ADJD_S311) += adjd_s311.o +obj-$(CONFIG_HID_SENSOR_ALS) += hid-sensor-als.o obj-$(CONFIG_SENSORS_LM3533) += lm3533-als.o obj-$(CONFIG_SENSORS_TSL2563) += tsl2563.o obj-$(CONFIG_VCNL4000) += vcnl4000.o -obj-$(CONFIG_HID_SENSOR_ALS) += hid-sensor-als.o diff --git a/drivers/iio/magnetometer/Kconfig b/drivers/iio/magnetometer/Kconfig index 4d55b1b851b3..4fa923f37b97 100644 --- a/drivers/iio/magnetometer/Kconfig +++ b/drivers/iio/magnetometer/Kconfig @@ -1,6 +1,8 @@ # # Magnetometer sensors # +# When adding new entries keep the list in alphabetical order + menu "Magnetometer sensors" config AK8975 diff --git a/drivers/iio/magnetometer/Makefile b/drivers/iio/magnetometer/Makefile index 7f328e37fbab..f91b1b68d392 100644 --- a/drivers/iio/magnetometer/Makefile +++ b/drivers/iio/magnetometer/Makefile @@ -2,6 +2,7 @@ # Makefile for industrial I/O Magnetometer sensor drivers # +# When adding new entries keep the list in alphabetical order obj-$(CONFIG_AK8975) += ak8975.o obj-$(CONFIG_HID_SENSOR_MAGNETOMETER_3D) += hid-sensor-magn-3d.o diff --git a/drivers/iio/pressure/Kconfig b/drivers/iio/pressure/Kconfig index 56ae8905c8e1..26fdc0bdb99d 100644 --- a/drivers/iio/pressure/Kconfig +++ b/drivers/iio/pressure/Kconfig @@ -1,6 +1,8 @@ # # Pressure drivers # +# When adding new entries keep the list in alphabetical order + menu "Pressure sensors" config IIO_ST_PRESS diff --git a/drivers/iio/pressure/Makefile b/drivers/iio/pressure/Makefile index d4bb33e5c846..be71464c2752 100644 --- a/drivers/iio/pressure/Makefile +++ b/drivers/iio/pressure/Makefile @@ -2,6 +2,7 @@ # Makefile for industrial I/O pressure drivers # +# When adding new entries keep the list in alphabetical order obj-$(CONFIG_IIO_ST_PRESS) += st_pressure.o st_pressure-y := st_pressure_core.o st_pressure-$(CONFIG_IIO_BUFFER) += st_pressure_buffer.o diff --git a/drivers/iio/trigger/Kconfig b/drivers/iio/trigger/Kconfig index 0a4a5164963f..79996123a71b 100644 --- a/drivers/iio/trigger/Kconfig +++ b/drivers/iio/trigger/Kconfig @@ -1,6 +1,8 @@ # # Industrial I/O standalone triggers # +# When adding new entries keep the list in alphabetical order + menu "Triggers - standalone" config IIO_INTERRUPT_TRIGGER diff --git a/drivers/iio/trigger/Makefile b/drivers/iio/trigger/Makefile index ce319a51b6af..0694daecaf22 100644 --- a/drivers/iio/trigger/Makefile +++ b/drivers/iio/trigger/Makefile @@ -2,5 +2,6 @@ # Makefile for triggers not associated with iio-devices # +# When adding new entries keep the list in alphabetical order obj-$(CONFIG_IIO_INTERRUPT_TRIGGER) += iio-trig-interrupt.o obj-$(CONFIG_IIO_SYSFS_TRIGGER) += iio-trig-sysfs.o -- cgit v1.2.3 From 03eff7b60dc3e5d2539a5f9685a9fb9a530e01e8 Mon Sep 17 00:00:00 2001 From: Oleksandr Kravchenko Date: Mon, 22 Jul 2013 14:11:00 +0100 Subject: iio: add APDS9300 ambilent light sensor driver This patch adds IIO driver for APDS9300 ambient light sensor (ALS). http://www.avagotech.com/docs/AV02-1077EN The driver allows to read raw data from ADC registers or calculate lux value. It also can handle threshold interrupt. Signed-off-by: Oleksandr Kravchenko Signed-off-by: Jonathan Cameron --- .../devicetree/bindings/iio/light/apds9300.txt | 22 + drivers/iio/light/Kconfig | 10 + drivers/iio/light/Makefile | 1 + drivers/iio/light/apds9300.c | 512 +++++++++++++++++++++ 4 files changed, 545 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/light/apds9300.txt create mode 100644 drivers/iio/light/apds9300.c (limited to 'drivers/iio/light') diff --git a/Documentation/devicetree/bindings/iio/light/apds9300.txt b/Documentation/devicetree/bindings/iio/light/apds9300.txt new file mode 100644 index 000000000000..d6f66c73ddbf --- /dev/null +++ b/Documentation/devicetree/bindings/iio/light/apds9300.txt @@ -0,0 +1,22 @@ +* Avago APDS9300 ambient light sensor + +http://www.avagotech.com/docs/AV02-1077EN + +Required properties: + + - compatible : should be "avago,apds9300" + - reg : the I2C address of the sensor + +Optional properties: + + - interrupt-parent : should be the phandle for the interrupt controller + - interrupts : interrupt mapping for GPIO IRQ + +Example: + +apds9300@39 { + compatible = "avago,apds9300"; + reg = <0x39>; + interrupt-parent = <&gpio2>; + interrupts = <29 8>; +}; diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig index 3bd29f810e6d..bf9fa0d7aff9 100644 --- a/drivers/iio/light/Kconfig +++ b/drivers/iio/light/Kconfig @@ -17,6 +17,16 @@ config ADJD_S311 This driver can also be built as a module. If so, the module will be called adjd_s311. +config APDS9300 + tristate "APDS9300 ambient light sensor" + depends on I2C + help + Say Y here if you want to build a driver for the Avago APDS9300 + ambient light sensor. + + To compile this driver as a module, choose M here: the + module will be called apds9300. + config HID_SENSOR_ALS depends on HID_SENSOR_HUB select IIO_BUFFER diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile index edef939861f0..354ee9ab2379 100644 --- a/drivers/iio/light/Makefile +++ b/drivers/iio/light/Makefile @@ -4,6 +4,7 @@ # When adding new entries keep the list in alphabetical order obj-$(CONFIG_ADJD_S311) += adjd_s311.o +obj-$(CONFIG_APDS9300) += apds9300.o obj-$(CONFIG_HID_SENSOR_ALS) += hid-sensor-als.o obj-$(CONFIG_SENSORS_LM3533) += lm3533-als.o obj-$(CONFIG_SENSORS_TSL2563) += tsl2563.o diff --git a/drivers/iio/light/apds9300.c b/drivers/iio/light/apds9300.c new file mode 100644 index 000000000000..66a58bda6dc8 --- /dev/null +++ b/drivers/iio/light/apds9300.c @@ -0,0 +1,512 @@ +/* + * apds9300.c - IIO driver for Avago APDS9300 ambient light sensor + * + * Copyright 2013 Oleksandr Kravchenko + * + * This file is subject to the terms and conditions of version 2 of + * the GNU General Public License. See the file COPYING in the main + * directory of this archive for more details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define APDS9300_DRV_NAME "apds9300" +#define APDS9300_IRQ_NAME "apds9300_event" + +/* Command register bits */ +#define APDS9300_CMD BIT(7) /* Select command register. Must write as 1 */ +#define APDS9300_WORD BIT(5) /* I2C write/read: if 1 word, if 0 byte */ +#define APDS9300_CLEAR BIT(6) /* Interrupt clear. Clears pending interrupt */ + +/* Register set */ +#define APDS9300_CONTROL 0x00 /* Control of basic functions */ +#define APDS9300_THRESHLOWLOW 0x02 /* Low byte of low interrupt threshold */ +#define APDS9300_THRESHHIGHLOW 0x04 /* Low byte of high interrupt threshold */ +#define APDS9300_INTERRUPT 0x06 /* Interrupt control */ +#define APDS9300_DATA0LOW 0x0c /* Low byte of ADC channel 0 */ +#define APDS9300_DATA1LOW 0x0e /* Low byte of ADC channel 1 */ + +/* Power on/off value for APDS9300_CONTROL register */ +#define APDS9300_POWER_ON 0x03 +#define APDS9300_POWER_OFF 0x00 + +/* Interrupts */ +#define APDS9300_INTR_ENABLE 0x10 +/* Interrupt Persist Function: Any value outside of threshold range */ +#define APDS9300_THRESH_INTR 0x01 + +#define APDS9300_THRESH_MAX 0xffff /* Max threshold value */ + +struct apds9300_data { + struct i2c_client *client; + struct mutex mutex; + int power_state; + int thresh_low; + int thresh_hi; + int intr_en; +}; + +/* Lux calculation */ + +/* Calculated values 1000 * (CH1/CH0)^1.4 for CH1/CH0 from 0 to 0.52 */ +static const u16 apds9300_lux_ratio[] = { + 0, 2, 4, 7, 11, 15, 19, 24, 29, 34, 40, 45, 51, 57, 64, 70, 77, 84, 91, + 98, 105, 112, 120, 128, 136, 144, 152, 160, 168, 177, 185, 194, 203, + 212, 221, 230, 239, 249, 258, 268, 277, 287, 297, 307, 317, 327, 337, + 347, 358, 368, 379, 390, 400, +}; + +static unsigned long apds9300_calculate_lux(u16 ch0, u16 ch1) +{ + unsigned long lux, tmp; + + /* avoid division by zero */ + if (ch0 == 0) + return 0; + + tmp = DIV_ROUND_UP(ch1 * 100, ch0); + if (tmp <= 52) { + lux = 3150 * ch0 - (unsigned long)DIV_ROUND_UP_ULL(ch0 + * apds9300_lux_ratio[tmp] * 5930ull, 1000); + } else if (tmp <= 65) { + lux = 2290 * ch0 - 2910 * ch1; + } else if (tmp <= 80) { + lux = 1570 * ch0 - 1800 * ch1; + } else if (tmp <= 130) { + lux = 338 * ch0 - 260 * ch1; + } else { + lux = 0; + } + + return lux / 100000; +} + +static int apds9300_get_adc_val(struct apds9300_data *data, int adc_number) +{ + int ret; + u8 flags = APDS9300_CMD | APDS9300_WORD; + + if (!data->power_state) + return -EBUSY; + + /* Select ADC0 or ADC1 data register */ + flags |= adc_number ? APDS9300_DATA1LOW : APDS9300_DATA0LOW; + + ret = i2c_smbus_read_word_data(data->client, flags); + if (ret < 0) + dev_err(&data->client->dev, + "failed to read ADC%d value\n", adc_number); + + return ret; +} + +static int apds9300_set_thresh_low(struct apds9300_data *data, int value) +{ + int ret; + + if (!data->power_state) + return -EBUSY; + + if (value > APDS9300_THRESH_MAX) + return -EINVAL; + + ret = i2c_smbus_write_word_data(data->client, APDS9300_THRESHLOWLOW + | APDS9300_CMD | APDS9300_WORD, value); + if (ret) { + dev_err(&data->client->dev, "failed to set thresh_low\n"); + return ret; + } + data->thresh_low = value; + + return 0; +} + +static int apds9300_set_thresh_hi(struct apds9300_data *data, int value) +{ + int ret; + + if (!data->power_state) + return -EBUSY; + + if (value > APDS9300_THRESH_MAX) + return -EINVAL; + + ret = i2c_smbus_write_word_data(data->client, APDS9300_THRESHHIGHLOW + | APDS9300_CMD | APDS9300_WORD, value); + if (ret) { + dev_err(&data->client->dev, "failed to set thresh_hi\n"); + return ret; + } + data->thresh_hi = value; + + return 0; +} + +static int apds9300_set_intr_state(struct apds9300_data *data, int state) +{ + int ret; + u8 cmd; + + if (!data->power_state) + return -EBUSY; + + cmd = state ? APDS9300_INTR_ENABLE | APDS9300_THRESH_INTR : 0x00; + ret = i2c_smbus_write_byte_data(data->client, + APDS9300_INTERRUPT | APDS9300_CMD, cmd); + if (ret) { + dev_err(&data->client->dev, + "failed to set interrupt state %d\n", state); + return ret; + } + data->intr_en = state; + + return 0; +} + +static int apds9300_set_power_state(struct apds9300_data *data, int state) +{ + int ret; + u8 cmd; + + cmd = state ? APDS9300_POWER_ON : APDS9300_POWER_OFF; + ret = i2c_smbus_write_byte_data(data->client, + APDS9300_CONTROL | APDS9300_CMD, cmd); + if (ret) { + dev_err(&data->client->dev, + "failed to set power state %d\n", state); + return ret; + } + data->power_state = state; + + return 0; +} + +static void apds9300_clear_intr(struct apds9300_data *data) +{ + int ret; + + ret = i2c_smbus_write_byte(data->client, APDS9300_CLEAR | APDS9300_CMD); + if (ret < 0) + dev_err(&data->client->dev, "failed to clear interrupt\n"); +} + +static int apds9300_chip_init(struct apds9300_data *data) +{ + int ret; + + /* Need to set power off to ensure that the chip is off */ + ret = apds9300_set_power_state(data, 0); + if (ret < 0) + goto err; + /* + * Probe the chip. To do so we try to power up the device and then to + * read back the 0x03 code + */ + ret = apds9300_set_power_state(data, 1); + if (ret < 0) + goto err; + ret = i2c_smbus_read_byte_data(data->client, + APDS9300_CONTROL | APDS9300_CMD); + if (ret != APDS9300_POWER_ON) { + ret = -ENODEV; + goto err; + } + /* + * Disable interrupt to ensure thai it is doesn't enable + * i.e. after device soft reset + */ + ret = apds9300_set_intr_state(data, 0); + if (ret < 0) + goto err; + + return 0; + +err: + dev_err(&data->client->dev, "failed to init the chip\n"); + return ret; +} + +static int apds9300_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int *val, int *val2, + long mask) +{ + int ch0, ch1, ret = -EINVAL; + struct apds9300_data *data = iio_priv(indio_dev); + + mutex_lock(&data->mutex); + switch (chan->type) { + case IIO_LIGHT: + ch0 = apds9300_get_adc_val(data, 0); + if (ch0 < 0) { + ret = ch0; + break; + } + ch1 = apds9300_get_adc_val(data, 1); + if (ch1 < 0) { + ret = ch1; + break; + } + *val = apds9300_calculate_lux(ch0, ch1); + ret = IIO_VAL_INT; + break; + case IIO_INTENSITY: + ret = apds9300_get_adc_val(data, chan->channel); + if (ret < 0) + break; + *val = ret; + ret = IIO_VAL_INT; + break; + default: + break; + } + mutex_unlock(&data->mutex); + + return ret; +} + +static int apds9300_read_thresh(struct iio_dev *indio_dev, u64 event_code, + int *val) +{ + struct apds9300_data *data = iio_priv(indio_dev); + + switch (IIO_EVENT_CODE_EXTRACT_DIR(event_code)) { + case IIO_EV_DIR_RISING: + *val = data->thresh_hi; + break; + case IIO_EV_DIR_FALLING: + *val = data->thresh_low; + break; + default: + return -EINVAL; + } + + return 0; +} + +static int apds9300_write_thresh(struct iio_dev *indio_dev, u64 event_code, + int val) +{ + struct apds9300_data *data = iio_priv(indio_dev); + int ret; + + mutex_lock(&data->mutex); + if (IIO_EVENT_CODE_EXTRACT_DIR(event_code) == IIO_EV_DIR_RISING) + ret = apds9300_set_thresh_hi(data, val); + else + ret = apds9300_set_thresh_low(data, val); + mutex_unlock(&data->mutex); + + return ret; +} + +static int apds9300_read_interrupt_config(struct iio_dev *indio_dev, + u64 event_code) +{ + struct apds9300_data *data = iio_priv(indio_dev); + + return data->intr_en; +} + +static int apds9300_write_interrupt_config(struct iio_dev *indio_dev, + u64 event_code, int state) +{ + struct apds9300_data *data = iio_priv(indio_dev); + int ret; + + mutex_lock(&data->mutex); + ret = apds9300_set_intr_state(data, state); + mutex_unlock(&data->mutex); + + return ret; +} + +static const struct iio_info apds9300_info_no_irq = { + .driver_module = THIS_MODULE, + .read_raw = apds9300_read_raw, +}; + +static const struct iio_info apds9300_info = { + .driver_module = THIS_MODULE, + .read_raw = apds9300_read_raw, + .read_event_value = apds9300_read_thresh, + .write_event_value = apds9300_write_thresh, + .read_event_config = apds9300_read_interrupt_config, + .write_event_config = apds9300_write_interrupt_config, +}; + +static const struct iio_chan_spec apds9300_channels[] = { + { + .type = IIO_LIGHT, + .channel = 0, + .indexed = true, + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), + }, { + .type = IIO_INTENSITY, + .channel = 0, + .channel2 = IIO_MOD_LIGHT_BOTH, + .indexed = true, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .event_mask = (IIO_EV_BIT(IIO_EV_TYPE_THRESH, + IIO_EV_DIR_RISING) | + IIO_EV_BIT(IIO_EV_TYPE_THRESH, + IIO_EV_DIR_FALLING)), + }, { + .type = IIO_INTENSITY, + .channel = 1, + .channel2 = IIO_MOD_LIGHT_IR, + .indexed = true, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + }, +}; + +static irqreturn_t apds9300_interrupt_handler(int irq, void *private) +{ + struct iio_dev *dev_info = private; + struct apds9300_data *data = iio_priv(dev_info); + + iio_push_event(dev_info, + IIO_UNMOD_EVENT_CODE(IIO_INTENSITY, 0, + IIO_EV_TYPE_THRESH, + IIO_EV_DIR_EITHER), + iio_get_time_ns()); + + apds9300_clear_intr(data); + + return IRQ_HANDLED; +} + +static int apds9300_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct apds9300_data *data; + struct iio_dev *indio_dev; + int ret; + + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); + if (!indio_dev) + return -ENOMEM; + + data = iio_priv(indio_dev); + i2c_set_clientdata(client, indio_dev); + data->client = client; + + ret = apds9300_chip_init(data); + if (ret < 0) + goto err; + + mutex_init(&data->mutex); + + indio_dev->dev.parent = &client->dev; + indio_dev->channels = apds9300_channels; + indio_dev->num_channels = ARRAY_SIZE(apds9300_channels); + indio_dev->name = APDS9300_DRV_NAME; + indio_dev->modes = INDIO_DIRECT_MODE; + + if (client->irq) + indio_dev->info = &apds9300_info; + else + indio_dev->info = &apds9300_info_no_irq; + + if (client->irq) { + ret = devm_request_threaded_irq(&client->dev, client->irq, + NULL, apds9300_interrupt_handler, + IRQF_TRIGGER_FALLING | IRQF_ONESHOT, + APDS9300_IRQ_NAME, indio_dev); + if (ret) { + dev_err(&client->dev, "irq request error %d\n", -ret); + goto err; + } + } + + ret = iio_device_register(indio_dev); + if (ret < 0) + goto err; + + return 0; + +err: + /* Ensure that power off in case of error */ + apds9300_set_power_state(data, 0); + return ret; +} + +static int apds9300_remove(struct i2c_client *client) +{ + struct iio_dev *indio_dev = i2c_get_clientdata(client); + struct apds9300_data *data = iio_priv(indio_dev); + + iio_device_unregister(indio_dev); + + /* Ensure that power off and interrupts are disabled */ + apds9300_set_intr_state(data, 0); + apds9300_set_power_state(data, 0); + + return 0; +} + +#ifdef CONFIG_PM_SLEEP +static int apds9300_suspend(struct device *dev) +{ + struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); + struct apds9300_data *data = iio_priv(indio_dev); + int ret; + + mutex_lock(&data->mutex); + ret = apds9300_set_power_state(data, 0); + mutex_unlock(&data->mutex); + + return ret; +} + +static int apds9300_resume(struct device *dev) +{ + struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); + struct apds9300_data *data = iio_priv(indio_dev); + int ret; + + mutex_lock(&data->mutex); + ret = apds9300_set_power_state(data, 1); + mutex_unlock(&data->mutex); + + return ret; +} + +static SIMPLE_DEV_PM_OPS(apds9300_pm_ops, apds9300_suspend, apds9300_resume); +#define APDS9300_PM_OPS (&apds9300_pm_ops) +#else +#define APDS9300_PM_OPS NULL +#endif + +static struct i2c_device_id apds9300_id[] = { + { APDS9300_DRV_NAME, 0 }, + { } +}; + +MODULE_DEVICE_TABLE(i2c, apds9300_id); + +static struct i2c_driver apds9300_driver = { + .driver = { + .name = APDS9300_DRV_NAME, + .owner = THIS_MODULE, + .pm = APDS9300_PM_OPS, + }, + .probe = apds9300_probe, + .remove = apds9300_remove, + .id_table = apds9300_id, +}; + +module_i2c_driver(apds9300_driver); + +MODULE_AUTHOR("Kravchenko Oleksandr "); +MODULE_AUTHOR("GlobalLogic inc."); +MODULE_DESCRIPTION("APDS9300 ambient light photo sensor driver"); +MODULE_LICENSE("GPL"); -- cgit v1.2.3 From 47aff92ce081d8c9013f52e021cdfee5eebdbd2b Mon Sep 17 00:00:00 2001 From: Sachin Kamat Date: Tue, 30 Jul 2013 09:44:00 +0100 Subject: iio: light: hid-sensor-als: Use devm_iio_device_alloc Using devm_iio_device_alloc makes code simpler. Signed-off-by: Sachin Kamat Cc: Srinivas Pandruvada Signed-off-by: Jonathan Cameron --- drivers/iio/light/hid-sensor-als.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'drivers/iio/light') diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c index 9adfef07d8c2..84cf0043c99d 100644 --- a/drivers/iio/light/hid-sensor-als.c +++ b/drivers/iio/light/hid-sensor-als.c @@ -249,11 +249,9 @@ static int hid_als_probe(struct platform_device *pdev) struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; struct iio_chan_spec *channels; - indio_dev = iio_device_alloc(sizeof(struct als_state)); - if (indio_dev == NULL) { - ret = -ENOMEM; - goto error_ret; - } + indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(struct als_state)); + if (!indio_dev) + return -ENOMEM; platform_set_drvdata(pdev, indio_dev); als_state = iio_priv(indio_dev); @@ -264,14 +262,13 @@ static int hid_als_probe(struct platform_device *pdev) &als_state->common_attributes); if (ret) { dev_err(&pdev->dev, "failed to setup common attributes\n"); - goto error_free_dev; + return ret; } channels = kmemdup(als_channels, sizeof(als_channels), GFP_KERNEL); if (!channels) { - ret = -ENOMEM; dev_err(&pdev->dev, "failed to duplicate channels\n"); - goto error_free_dev; + return -ENOMEM; } ret = als_parse_report(pdev, hsdev, channels, @@ -329,9 +326,6 @@ error_unreg_buffer_funcs: iio_triggered_buffer_cleanup(indio_dev); error_free_dev_mem: kfree(indio_dev->channels); -error_free_dev: - iio_device_free(indio_dev); -error_ret: return ret; } @@ -346,7 +340,6 @@ static int hid_als_remove(struct platform_device *pdev) hid_sensor_remove_trigger(indio_dev); iio_triggered_buffer_cleanup(indio_dev); kfree(indio_dev->channels); - iio_device_free(indio_dev); return 0; } -- cgit v1.2.3 From 3d0ccbaff396920eedeb6a8d0dbb3c95847e937e Mon Sep 17 00:00:00 2001 From: Sachin Kamat Date: Tue, 30 Jul 2013 09:44:00 +0100 Subject: iio: light: lm3533-als: Use devm_iio_device_alloc Using devm_iio_device_alloc makes code simpler. Signed-off-by: Sachin Kamat Cc: Johan Hovold Signed-off-by: Jonathan Cameron --- drivers/iio/light/lm3533-als.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'drivers/iio/light') diff --git a/drivers/iio/light/lm3533-als.c b/drivers/iio/light/lm3533-als.c index 5fa31a4ef82a..c1aadc6b865a 100644 --- a/drivers/iio/light/lm3533-als.c +++ b/drivers/iio/light/lm3533-als.c @@ -847,7 +847,7 @@ static int lm3533_als_probe(struct platform_device *pdev) return -EINVAL; } - indio_dev = iio_device_alloc(sizeof(*als)); + indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*als)); if (!indio_dev) return -ENOMEM; @@ -870,7 +870,7 @@ static int lm3533_als_probe(struct platform_device *pdev) if (als->irq) { ret = lm3533_als_setup_irq(als, indio_dev); if (ret) - goto err_free_dev; + return ret; } ret = lm3533_als_setup(als, pdata); @@ -894,8 +894,6 @@ err_disable: err_free_irq: if (als->irq) free_irq(als->irq, indio_dev); -err_free_dev: - iio_device_free(indio_dev); return ret; } @@ -910,7 +908,6 @@ static int lm3533_als_remove(struct platform_device *pdev) lm3533_als_disable(als); if (als->irq) free_irq(als->irq, indio_dev); - iio_device_free(indio_dev); return 0; } -- cgit v1.2.3 From bace48f44adb954ad71e62779d1be52dae3f0caf Mon Sep 17 00:00:00 2001 From: Sachin Kamat Date: Tue, 30 Jul 2013 09:44:00 +0100 Subject: iio: light: tsl2563: Use devm_* APIs devm_* APIs are device managed and make code simpler. Signed-off-by: Sachin Kamat Reviewed-by: Amit Kucheria Signed-off-by: Jonathan Cameron --- drivers/iio/light/tsl2563.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) (limited to 'drivers/iio/light') diff --git a/drivers/iio/light/tsl2563.c b/drivers/iio/light/tsl2563.c index 1f529f36f138..ebb962c5c323 100644 --- a/drivers/iio/light/tsl2563.c +++ b/drivers/iio/light/tsl2563.c @@ -702,7 +702,7 @@ static int tsl2563_probe(struct i2c_client *client, int err = 0; u8 id = 0; - indio_dev = iio_device_alloc(sizeof(*chip)); + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip)); if (!indio_dev) return -ENOMEM; @@ -714,13 +714,13 @@ static int tsl2563_probe(struct i2c_client *client, err = tsl2563_detect(chip); if (err) { dev_err(&client->dev, "detect error %d\n", -err); - goto fail1; + return err; } err = tsl2563_read_id(chip, &id); if (err) { dev_err(&client->dev, "read id error %d\n", -err); - goto fail1; + return err; } mutex_init(&chip->lock); @@ -751,7 +751,7 @@ static int tsl2563_probe(struct i2c_client *client, indio_dev->info = &tsl2563_info_no_irq; if (client->irq) { - err = request_threaded_irq(client->irq, + err = devm_request_threaded_irq(&client->dev, client->irq, NULL, &tsl2563_event_handler, IRQF_TRIGGER_RISING | IRQF_ONESHOT, @@ -759,14 +759,14 @@ static int tsl2563_probe(struct i2c_client *client, indio_dev); if (err) { dev_err(&client->dev, "irq request error %d\n", -err); - goto fail1; + return err; } } err = tsl2563_configure(chip); if (err) { dev_err(&client->dev, "configure error %d\n", -err); - goto fail2; + return err; } INIT_DELAYED_WORK(&chip->poweroff_work, tsl2563_poweroff_work); @@ -777,19 +777,14 @@ static int tsl2563_probe(struct i2c_client *client, err = iio_device_register(indio_dev); if (err) { dev_err(&client->dev, "iio registration error %d\n", -err); - goto fail3; + goto fail; } return 0; -fail3: +fail: cancel_delayed_work(&chip->poweroff_work); flush_scheduled_work(); -fail2: - if (client->irq) - free_irq(client->irq, indio_dev); -fail1: - iio_device_free(indio_dev); return err; } @@ -807,10 +802,6 @@ static int tsl2563_remove(struct i2c_client *client) chip->intr); flush_scheduled_work(); tsl2563_set_power(chip, 0); - if (client->irq) - free_irq(client->irq, indio_dev); - - iio_device_free(indio_dev); return 0; } -- cgit v1.2.3 From ccf12c3310b489c39e78a3fc06c9ef15a4570078 Mon Sep 17 00:00:00 2001 From: Peter Meerwald Date: Mon, 29 Jul 2013 23:18:00 +0100 Subject: iio:adjd_s311: Use devm_iio_device_alloc Signed-off-by: Peter Meerwald Signed-off-by: Jonathan Cameron --- drivers/iio/light/adjd_s311.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'drivers/iio/light') diff --git a/drivers/iio/light/adjd_s311.c b/drivers/iio/light/adjd_s311.c index 5f4749e60b04..55b9e185d164 100644 --- a/drivers/iio/light/adjd_s311.c +++ b/drivers/iio/light/adjd_s311.c @@ -293,11 +293,10 @@ static int adjd_s311_probe(struct i2c_client *client, struct iio_dev *indio_dev; int err; - indio_dev = iio_device_alloc(sizeof(*data)); - if (indio_dev == NULL) { - err = -ENOMEM; - goto exit; - } + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); + if (indio_dev == NULL) + return -ENOMEM; + data = iio_priv(indio_dev); i2c_set_clientdata(client, indio_dev); data->client = client; @@ -312,7 +311,7 @@ static int adjd_s311_probe(struct i2c_client *client, err = iio_triggered_buffer_setup(indio_dev, NULL, adjd_s311_trigger_handler, NULL); if (err < 0) - goto exit_free_device; + return err; err = iio_device_register(indio_dev); if (err) @@ -324,9 +323,6 @@ static int adjd_s311_probe(struct i2c_client *client, exit_unreg_buffer: iio_triggered_buffer_cleanup(indio_dev); -exit_free_device: - iio_device_free(indio_dev); -exit: return err; } @@ -338,7 +334,6 @@ static int adjd_s311_remove(struct i2c_client *client) iio_device_unregister(indio_dev); iio_triggered_buffer_cleanup(indio_dev); kfree(data->buffer); - iio_device_free(indio_dev); return 0; } -- cgit v1.2.3 From 2669d723ac6a01857273848a090c747f044a62d3 Mon Sep 17 00:00:00 2001 From: Peter Meerwald Date: Mon, 29 Jul 2013 23:18:00 +0100 Subject: iio:vcnl4000: Use devm_iio_device_alloc Signed-off-by: Peter Meerwald Signed-off-by: Jonathan Cameron --- drivers/iio/light/vcnl4000.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'drivers/iio/light') diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c index 1014943d949a..2bb304215b1d 100644 --- a/drivers/iio/light/vcnl4000.c +++ b/drivers/iio/light/vcnl4000.c @@ -157,7 +157,7 @@ static int vcnl4000_probe(struct i2c_client *client, struct iio_dev *indio_dev; int ret; - indio_dev = iio_device_alloc(sizeof(*data)); + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); if (!indio_dev) return -ENOMEM; @@ -167,7 +167,7 @@ static int vcnl4000_probe(struct i2c_client *client, ret = i2c_smbus_read_byte_data(data->client, VCNL4000_PROD_REV); if (ret < 0) - goto error_free_dev; + return ret; dev_info(&client->dev, "VCNL4000 Ambient light/proximity sensor, Prod %02x, Rev: %02x\n", ret >> 4, ret & 0xf); @@ -181,22 +181,14 @@ static int vcnl4000_probe(struct i2c_client *client, ret = iio_device_register(indio_dev); if (ret < 0) - goto error_free_dev; + return ret; return 0; - -error_free_dev: - iio_device_free(indio_dev); - return ret; } static int vcnl4000_remove(struct i2c_client *client) { - struct iio_dev *indio_dev = i2c_get_clientdata(client); - - iio_device_unregister(indio_dev); - iio_device_free(indio_dev); - + iio_device_unregister(i2c_get_clientdata(client)); return 0; } -- cgit v1.2.3 From 0c0427acd5bfd25a44c074ac0a517d667ddf0a27 Mon Sep 17 00:00:00 2001 From: Peter Meerwald Date: Sun, 18 Aug 2013 14:07:00 +0100 Subject: iio: Remove unnecessary _write_raw_get_fmt() in several hid-sensor drivers IIO_VAL_INT_PLUS_MICRO is the default, no need to return it explicitly Signed-off-by: Peter Meerwald Acked-by: srinivas pandruvada Signed-off-by: Jonathan Cameron --- drivers/iio/accel/hid-sensor-accel-3d.c | 8 -------- drivers/iio/gyro/hid-sensor-gyro-3d.c | 8 -------- drivers/iio/light/hid-sensor-als.c | 8 -------- drivers/iio/magnetometer/hid-sensor-magn-3d.c | 8 -------- 4 files changed, 32 deletions(-) (limited to 'drivers/iio/light') diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c b/drivers/iio/accel/hid-sensor-accel-3d.c index 68df3416b612..46d22f3fb1a9 100644 --- a/drivers/iio/accel/hid-sensor-accel-3d.c +++ b/drivers/iio/accel/hid-sensor-accel-3d.c @@ -175,18 +175,10 @@ static int accel_3d_write_raw(struct iio_dev *indio_dev, return ret; } -static int accel_3d_write_raw_get_fmt(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - long mask) -{ - return IIO_VAL_INT_PLUS_MICRO; -} - static const struct iio_info accel_3d_info = { .driver_module = THIS_MODULE, .read_raw = &accel_3d_read_raw, .write_raw = &accel_3d_write_raw, - .write_raw_get_fmt = &accel_3d_write_raw_get_fmt, }; /* Function to push data to buffer */ diff --git a/drivers/iio/gyro/hid-sensor-gyro-3d.c b/drivers/iio/gyro/hid-sensor-gyro-3d.c index d9d7befdd77b..c688d974d3e3 100644 --- a/drivers/iio/gyro/hid-sensor-gyro-3d.c +++ b/drivers/iio/gyro/hid-sensor-gyro-3d.c @@ -175,18 +175,10 @@ static int gyro_3d_write_raw(struct iio_dev *indio_dev, return ret; } -static int gyro_3d_write_raw_get_fmt(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - long mask) -{ - return IIO_VAL_INT_PLUS_MICRO; -} - static const struct iio_info gyro_3d_info = { .driver_module = THIS_MODULE, .read_raw = &gyro_3d_read_raw, .write_raw = &gyro_3d_write_raw, - .write_raw_get_fmt = &gyro_3d_write_raw_get_fmt, }; /* Function to push data to buffer */ diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c index 84cf0043c99d..e59d00c3139c 100644 --- a/drivers/iio/light/hid-sensor-als.c +++ b/drivers/iio/light/hid-sensor-als.c @@ -154,18 +154,10 @@ static int als_write_raw(struct iio_dev *indio_dev, return ret; } -static int als_write_raw_get_fmt(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - long mask) -{ - return IIO_VAL_INT_PLUS_MICRO; -} - static const struct iio_info als_info = { .driver_module = THIS_MODULE, .read_raw = &als_read_raw, .write_raw = &als_write_raw, - .write_raw_get_fmt = &als_write_raw_get_fmt, }; /* Function to push data to buffer */ diff --git a/drivers/iio/magnetometer/hid-sensor-magn-3d.c b/drivers/iio/magnetometer/hid-sensor-magn-3d.c index 5a6162d1a2c0..a98460b15e4b 100644 --- a/drivers/iio/magnetometer/hid-sensor-magn-3d.c +++ b/drivers/iio/magnetometer/hid-sensor-magn-3d.c @@ -176,18 +176,10 @@ static int magn_3d_write_raw(struct iio_dev *indio_dev, return ret; } -static int magn_3d_write_raw_get_fmt(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - long mask) -{ - return IIO_VAL_INT_PLUS_MICRO; -} - static const struct iio_info magn_3d_info = { .driver_module = THIS_MODULE, .read_raw = &magn_3d_read_raw, .write_raw = &magn_3d_write_raw, - .write_raw_get_fmt = &magn_3d_write_raw_get_fmt, }; /* Function to push data to buffer */ -- cgit v1.2.3 From 4c730292656675000a3631b12cefb6238c57d1e3 Mon Sep 17 00:00:00 2001 From: Peter Meerwald Date: Sun, 18 Aug 2013 13:59:00 +0100 Subject: iio: adjd_s311: Cleanup unused #defines using word reads, no need for HI/LO register #defines Signed-off-by: Peter Meerwald Signed-off-by: Jonathan Cameron --- drivers/iio/light/adjd_s311.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) (limited to 'drivers/iio/light') diff --git a/drivers/iio/light/adjd_s311.c b/drivers/iio/light/adjd_s311.c index 55b9e185d164..00ab980f8e3c 100644 --- a/drivers/iio/light/adjd_s311.c +++ b/drivers/iio/light/adjd_s311.c @@ -37,22 +37,14 @@ #define ADJD_S311_CAP_GREEN 0x07 #define ADJD_S311_CAP_BLUE 0x08 #define ADJD_S311_CAP_CLEAR 0x09 -#define ADJD_S311_INT_RED_LO 0x0a -#define ADJD_S311_INT_RED_HI 0x0b -#define ADJD_S311_INT_GREEN_LO 0x0c -#define ADJD_S311_INT_GREEN_HI 0x0d -#define ADJD_S311_INT_BLUE_LO 0x0e -#define ADJD_S311_INT_BLUE_HI 0x0f -#define ADJD_S311_INT_CLEAR_LO 0x10 -#define ADJD_S311_INT_CLEAR_HI 0x11 -#define ADJD_S311_DATA_RED_LO 0x40 -#define ADJD_S311_DATA_RED_HI 0x41 -#define ADJD_S311_DATA_GREEN_LO 0x42 -#define ADJD_S311_DATA_GREEN_HI 0x43 -#define ADJD_S311_DATA_BLUE_LO 0x44 -#define ADJD_S311_DATA_BLUE_HI 0x45 -#define ADJD_S311_DATA_CLEAR_LO 0x46 -#define ADJD_S311_DATA_CLEAR_HI 0x47 +#define ADJD_S311_INT_RED 0x0a +#define ADJD_S311_INT_GREEN 0x0c +#define ADJD_S311_INT_BLUE 0x0e +#define ADJD_S311_INT_CLEAR 0x10 +#define ADJD_S311_DATA_RED 0x40 +#define ADJD_S311_DATA_GREEN 0x42 +#define ADJD_S311_DATA_BLUE 0x44 +#define ADJD_S311_DATA_CLEAR 0x46 #define ADJD_S311_OFFSET_RED 0x48 #define ADJD_S311_OFFSET_GREEN 0x49 #define ADJD_S311_OFFSET_BLUE 0x4a @@ -73,8 +65,8 @@ enum adjd_s311_channel_idx { IDX_RED, IDX_GREEN, IDX_BLUE, IDX_CLEAR }; -#define ADJD_S311_DATA_REG(chan) (ADJD_S311_DATA_RED_LO + (chan) * 2) -#define ADJD_S311_INT_REG(chan) (ADJD_S311_INT_RED_LO + (chan) * 2) +#define ADJD_S311_DATA_REG(chan) (ADJD_S311_DATA_RED + (chan) * 2) +#define ADJD_S311_INT_REG(chan) (ADJD_S311_INT_RED + (chan) * 2) #define ADJD_S311_CAP_REG(chan) (ADJD_S311_CAP_RED + (chan)) static int adjd_s311_req_data(struct iio_dev *indio_dev) -- cgit v1.2.3