Re: [PATCH v2] iio: light: Add support for UPISEMI uS5182d als and proximity sensor
Hi Jonathan, Thanks for the review, I'll send out a new version soon. Replies inline. On 08.08.2015 17:54, Jonathan Cameron wrote: On 04/08/15 14:40, Adriana Reus wrote: Add support for UPISEMI us5182d als and proximity sensor. Supports raw readings. Data sheet for this device can be found here: http://www.upi-semi.com/temp/uS5182D-DS-P0103-temp.pdf Signed-off-by: Adriana Reus Device tree docs? Adding soon. Various other bits and bobs inline. --- Changes since v1: added data-sheet link to commit message drivers/iio/light/Kconfig | 10 + drivers/iio/light/Makefile | 1 + drivers/iio/light/us5182d.c | 539 3 files changed, 550 insertions(+) create mode 100644 drivers/iio/light/us5182d.c diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig index a459341..0aa819d 100644 --- a/drivers/iio/light/Kconfig +++ b/drivers/iio/light/Kconfig @@ -285,6 +285,16 @@ config TSL4531 To compile this driver as a module, choose M here: the module will be called tsl4531. +config US5182D + tristate "UPISEMI light and proximity sensor" + depends on I2C + help +If you say yes here you get support for the UPISEMI US5182D +ambient light and proximity sensor. + +This driver can also be built as a module. If so, the module +will be called us5182d. + config VCNL4000 tristate "VCNL4000 combined ALS and proximity sensor" depends on I2C diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile index 91c74c0..528cc8f 100644 --- a/drivers/iio/light/Makefile +++ b/drivers/iio/light/Makefile @@ -27,4 +27,5 @@ obj-$(CONFIG_STK3310) += stk3310.o obj-$(CONFIG_TCS3414) += tcs3414.o obj-$(CONFIG_TCS3472) += tcs3472.o obj-$(CONFIG_TSL4531) += tsl4531.o +obj-$(CONFIG_US5182D) += us5182d.o obj-$(CONFIG_VCNL4000)+= vcnl4000.o diff --git a/drivers/iio/light/us5182d.c b/drivers/iio/light/us5182d.c new file mode 100644 index 000..6654bb0 --- /dev/null +++ b/drivers/iio/light/us5182d.c @@ -0,0 +1,539 @@ +/* + * Copyright (c) 2015 Intel Corporation + * + * Driver for UPISEMI us5182d Proximity and Ambient Light Sensor. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * To do: Interrupt support. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define US5182D_REG_CFG0 0x00 +#define US5182D_REG_CFG1 0x01 +#define US5182D_REG_CFG2 0x02 +#define US5182D_REG_CFG3 0x03 +#define US5182D_REG_CFG4 0x10 + +/* + * Registers for tuning the auto dark current cancelling feature. + * DARK_TH(reg 0x27,0x28) - threshold (counts) for auto dark cancelling. + * when ALS > DARK_TH --> ALS_Code = ALS - Upper(0x2A) * Dark + * when ALS < DARK_TH --> ALS_Code = ALS - Lower(0x29) * Dark + */ +#define US5182D_REG_UDARK_TH 0x27 +#define US5182D_REG_DARK_AUTO_EN 0x2b +#define US5182D_REG_AUTO_LDARK_TH 0x29 +#define US5182D_REG_AUTO_HDARK_TH 0x2a + +/* + * power-mode - oneshot, non-interrupt, word mode access for + * als code, th registers. + */ +#define US5182D_REG_CFG0_DEFAULT 0x81 I'd prefer to see the elements of this register broken down. Something like (guessing what is in this reg to a degree). #define US5182D_REG_CFG0_DEFAULT \ (US5182D_AGAIN_1X | (US5182_OPMODE_ALS << US5182D_OPMODE_SHIFT)) Perhaps even define the inverse cases so that the values themselves act as documentation. (so SHUTDOWN_DIS and ONESHOT_DIS) Same is true for any of thes registers that are compound values. Basically the code should be explicity where it can be rather than requiring docs that don't make it obvious which parts of the value are the cause of what. OK, I'll try to break down the compound registers values. + +/* + * no als fault queue, 16 bit als resolution (supports 12 and 14 also), + * max-range 12354. + */ +#define US5182D_REG_CFG1_DEFAULT 0x10 + +/* + * 16 bit resolution for PX, x16 sensing amplifier for px + * supports [x1 x2 x4 x8 x16 x32 x64 x128] + */ +#define US5182D_REG_CFG2_DEFAULT 0x14 + +/* + * led current : 100mA, supports [12.5 25 50 100] mA, + * interrupt source selection "px approach", + * [als or ps, als only, ps only, ps approach] + */ +#define US5182D_REG_CFG3_DEFAULT 0x3C + +/* + * led frequency ADC Clock/2 from [ADC Clock/2, /4, /8, /10] + * automatic 50/60 Hz ripple rejection
Re: [PATCH v2] iio: light: Add support for UPISEMI uS5182d als and proximity sensor
Hi Jonathan, Thanks for the review, I'll send out a new version soon. Replies inline. On 08.08.2015 17:54, Jonathan Cameron wrote: On 04/08/15 14:40, Adriana Reus wrote: Add support for UPISEMI us5182d als and proximity sensor. Supports raw readings. Data sheet for this device can be found here: http://www.upi-semi.com/temp/uS5182D-DS-P0103-temp.pdf Signed-off-by: Adriana Reus adriana.r...@intel.com Device tree docs? Adding soon. Various other bits and bobs inline. --- Changes since v1: added data-sheet link to commit message drivers/iio/light/Kconfig | 10 + drivers/iio/light/Makefile | 1 + drivers/iio/light/us5182d.c | 539 3 files changed, 550 insertions(+) create mode 100644 drivers/iio/light/us5182d.c diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig index a459341..0aa819d 100644 --- a/drivers/iio/light/Kconfig +++ b/drivers/iio/light/Kconfig @@ -285,6 +285,16 @@ config TSL4531 To compile this driver as a module, choose M here: the module will be called tsl4531. +config US5182D + tristate UPISEMI light and proximity sensor + depends on I2C + help +If you say yes here you get support for the UPISEMI US5182D +ambient light and proximity sensor. + +This driver can also be built as a module. If so, the module +will be called us5182d. + config VCNL4000 tristate VCNL4000 combined ALS and proximity sensor depends on I2C diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile index 91c74c0..528cc8f 100644 --- a/drivers/iio/light/Makefile +++ b/drivers/iio/light/Makefile @@ -27,4 +27,5 @@ obj-$(CONFIG_STK3310) += stk3310.o obj-$(CONFIG_TCS3414) += tcs3414.o obj-$(CONFIG_TCS3472) += tcs3472.o obj-$(CONFIG_TSL4531) += tsl4531.o +obj-$(CONFIG_US5182D) += us5182d.o obj-$(CONFIG_VCNL4000)+= vcnl4000.o diff --git a/drivers/iio/light/us5182d.c b/drivers/iio/light/us5182d.c new file mode 100644 index 000..6654bb0 --- /dev/null +++ b/drivers/iio/light/us5182d.c @@ -0,0 +1,539 @@ +/* + * Copyright (c) 2015 Intel Corporation + * + * Driver for UPISEMI us5182d Proximity and Ambient Light Sensor. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * To do: Interrupt support. + */ + +#include linux/kernel.h +#include linux/module.h +#include linux/acpi.h +#include linux/delay.h +#include linux/i2c.h +#include linux/iio/iio.h +#include linux/iio/sysfs.h +#include linux/mutex.h + +#define US5182D_REG_CFG0 0x00 +#define US5182D_REG_CFG1 0x01 +#define US5182D_REG_CFG2 0x02 +#define US5182D_REG_CFG3 0x03 +#define US5182D_REG_CFG4 0x10 + +/* + * Registers for tuning the auto dark current cancelling feature. + * DARK_TH(reg 0x27,0x28) - threshold (counts) for auto dark cancelling. + * when ALS DARK_TH -- ALS_Code = ALS - Upper(0x2A) * Dark + * when ALS DARK_TH -- ALS_Code = ALS - Lower(0x29) * Dark + */ +#define US5182D_REG_UDARK_TH 0x27 +#define US5182D_REG_DARK_AUTO_EN 0x2b +#define US5182D_REG_AUTO_LDARK_TH 0x29 +#define US5182D_REG_AUTO_HDARK_TH 0x2a + +/* + * power-mode - oneshot, non-interrupt, word mode access for + * als code, th registers. + */ +#define US5182D_REG_CFG0_DEFAULT 0x81 I'd prefer to see the elements of this register broken down. Something like (guessing what is in this reg to a degree). #define US5182D_REG_CFG0_DEFAULT \ (US5182D_AGAIN_1X | (US5182_OPMODE_ALS US5182D_OPMODE_SHIFT)) Perhaps even define the inverse cases so that the values themselves act as documentation. (so SHUTDOWN_DIS and ONESHOT_DIS) Same is true for any of thes registers that are compound values. Basically the code should be explicity where it can be rather than requiring docs that don't make it obvious which parts of the value are the cause of what. OK, I'll try to break down the compound registers values. + +/* + * no als fault queue, 16 bit als resolution (supports 12 and 14 also), + * max-range 12354. + */ +#define US5182D_REG_CFG1_DEFAULT 0x10 + +/* + * 16 bit resolution for PX, x16 sensing amplifier for px + * supports [x1 x2 x4 x8 x16 x32 x64 x128] + */ +#define US5182D_REG_CFG2_DEFAULT 0x14 + +/* + * led current : 100mA, supports [12.5 25 50 100] mA, + * interrupt source selection px approach, + * [als or ps, als only, ps only, ps approach] + */ +#define US5182D_REG_CFG3_DEFAULT
Re: [PATCH v2] iio: light: Add support for UPISEMI uS5182d als and proximity sensor
On 04/08/15 14:40, Adriana Reus wrote: > Add support for UPISEMI us5182d als and proximity sensor. > Supports raw readings. > Data sheet for this device can be found here: > http://www.upi-semi.com/temp/uS5182D-DS-P0103-temp.pdf > > Signed-off-by: Adriana Reus Device tree docs? Various other bits and bobs inline. > --- > Changes since v1: added data-sheet link to commit message > drivers/iio/light/Kconfig | 10 + > drivers/iio/light/Makefile | 1 + > drivers/iio/light/us5182d.c | 539 > > 3 files changed, 550 insertions(+) > create mode 100644 drivers/iio/light/us5182d.c > > diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig > index a459341..0aa819d 100644 > --- a/drivers/iio/light/Kconfig > +++ b/drivers/iio/light/Kconfig > @@ -285,6 +285,16 @@ config TSL4531 >To compile this driver as a module, choose M here: the >module will be called tsl4531. > > +config US5182D > + tristate "UPISEMI light and proximity sensor" > + depends on I2C > + help > + If you say yes here you get support for the UPISEMI US5182D > + ambient light and proximity sensor. > + > + This driver can also be built as a module. If so, the module > + will be called us5182d. > + > config VCNL4000 > tristate "VCNL4000 combined ALS and proximity sensor" > depends on I2C > diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile > index 91c74c0..528cc8f 100644 > --- a/drivers/iio/light/Makefile > +++ b/drivers/iio/light/Makefile > @@ -27,4 +27,5 @@ obj-$(CONFIG_STK3310) += stk3310.o > obj-$(CONFIG_TCS3414)+= tcs3414.o > obj-$(CONFIG_TCS3472)+= tcs3472.o > obj-$(CONFIG_TSL4531)+= tsl4531.o > +obj-$(CONFIG_US5182D)+= us5182d.o > obj-$(CONFIG_VCNL4000) += vcnl4000.o > diff --git a/drivers/iio/light/us5182d.c b/drivers/iio/light/us5182d.c > new file mode 100644 > index 000..6654bb0 > --- /dev/null > +++ b/drivers/iio/light/us5182d.c > @@ -0,0 +1,539 @@ > +/* > + * Copyright (c) 2015 Intel Corporation > + * > + * Driver for UPISEMI us5182d Proximity and Ambient Light Sensor. > + * > + * This program is free software; you can redistribute it and/or modify it > + * under the terms of the GNU General Public License version 2 as published > by > + * the Free Software Foundation. > + * > + * This program is distributed in the hope it will be useful, but WITHOUT > + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or > + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for > + * more details. > + * > + * To do: Interrupt support. > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define US5182D_REG_CFG0 0x00 > +#define US5182D_REG_CFG1 0x01 > +#define US5182D_REG_CFG2 0x02 > +#define US5182D_REG_CFG3 0x03 > +#define US5182D_REG_CFG4 0x10 > + > +/* > + * Registers for tuning the auto dark current cancelling feature. > + * DARK_TH(reg 0x27,0x28) - threshold (counts) for auto dark cancelling. > + * when ALS > DARK_TH --> ALS_Code = ALS - Upper(0x2A) * Dark > + * when ALS < DARK_TH --> ALS_Code = ALS - Lower(0x29) * Dark > + */ > +#define US5182D_REG_UDARK_TH 0x27 > +#define US5182D_REG_DARK_AUTO_EN 0x2b > +#define US5182D_REG_AUTO_LDARK_TH0x29 > +#define US5182D_REG_AUTO_HDARK_TH0x2a > + > +/* > + * power-mode - oneshot, non-interrupt, word mode access for > + * als code, th registers. > + */ > +#define US5182D_REG_CFG0_DEFAULT 0x81 I'd prefer to see the elements of this register broken down. Something like (guessing what is in this reg to a degree). #define US5182D_REG_CFG0_DEFAULT \ (US5182D_AGAIN_1X | (US5182_OPMODE_ALS << US5182D_OPMODE_SHIFT)) Perhaps even define the inverse cases so that the values themselves act as documentation. (so SHUTDOWN_DIS and ONESHOT_DIS) Same is true for any of thes registers that are compound values. Basically the code should be explicity where it can be rather than requiring docs that don't make it obvious which parts of the value are the cause of what. > + > +/* > + * no als fault queue, 16 bit als resolution (supports 12 and 14 also), > + * max-range 12354. > + */ > +#define US5182D_REG_CFG1_DEFAULT 0x10 > + > +/* > + * 16 bit resolution for PX, x16 sensing amplifier for px > + * supports [x1 x2 x4 x8 x16 x32 x64 x128] > + */ > +#define US5182D_REG_CFG2_DEFAULT 0x14 > + > +/* > + * led current : 100mA, supports [12.5 25 50 100] mA, > + * interrupt source selection "px approach", > + * [als or ps, als only, ps only, ps approach] > + */ > +#define US5182D_REG_CFG3_DEFAULT 0x3C > + > +/* > + * led frequency ADC Clock/2 from [ADC Clock/2, /4, /8, /10] > + * automatic 50/60 Hz ripple rejection
Re: [PATCH v2] iio: light: Add support for UPISEMI uS5182d als and proximity sensor
On 04/08/15 14:40, Adriana Reus wrote: Add support for UPISEMI us5182d als and proximity sensor. Supports raw readings. Data sheet for this device can be found here: http://www.upi-semi.com/temp/uS5182D-DS-P0103-temp.pdf Signed-off-by: Adriana Reus adriana.r...@intel.com Device tree docs? Various other bits and bobs inline. --- Changes since v1: added data-sheet link to commit message drivers/iio/light/Kconfig | 10 + drivers/iio/light/Makefile | 1 + drivers/iio/light/us5182d.c | 539 3 files changed, 550 insertions(+) create mode 100644 drivers/iio/light/us5182d.c diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig index a459341..0aa819d 100644 --- a/drivers/iio/light/Kconfig +++ b/drivers/iio/light/Kconfig @@ -285,6 +285,16 @@ config TSL4531 To compile this driver as a module, choose M here: the module will be called tsl4531. +config US5182D + tristate UPISEMI light and proximity sensor + depends on I2C + help + If you say yes here you get support for the UPISEMI US5182D + ambient light and proximity sensor. + + This driver can also be built as a module. If so, the module + will be called us5182d. + config VCNL4000 tristate VCNL4000 combined ALS and proximity sensor depends on I2C diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile index 91c74c0..528cc8f 100644 --- a/drivers/iio/light/Makefile +++ b/drivers/iio/light/Makefile @@ -27,4 +27,5 @@ obj-$(CONFIG_STK3310) += stk3310.o obj-$(CONFIG_TCS3414)+= tcs3414.o obj-$(CONFIG_TCS3472)+= tcs3472.o obj-$(CONFIG_TSL4531)+= tsl4531.o +obj-$(CONFIG_US5182D)+= us5182d.o obj-$(CONFIG_VCNL4000) += vcnl4000.o diff --git a/drivers/iio/light/us5182d.c b/drivers/iio/light/us5182d.c new file mode 100644 index 000..6654bb0 --- /dev/null +++ b/drivers/iio/light/us5182d.c @@ -0,0 +1,539 @@ +/* + * Copyright (c) 2015 Intel Corporation + * + * Driver for UPISEMI us5182d Proximity and Ambient Light Sensor. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * To do: Interrupt support. + */ + +#include linux/kernel.h +#include linux/module.h +#include linux/acpi.h +#include linux/delay.h +#include linux/i2c.h +#include linux/iio/iio.h +#include linux/iio/sysfs.h +#include linux/mutex.h + +#define US5182D_REG_CFG0 0x00 +#define US5182D_REG_CFG1 0x01 +#define US5182D_REG_CFG2 0x02 +#define US5182D_REG_CFG3 0x03 +#define US5182D_REG_CFG4 0x10 + +/* + * Registers for tuning the auto dark current cancelling feature. + * DARK_TH(reg 0x27,0x28) - threshold (counts) for auto dark cancelling. + * when ALS DARK_TH -- ALS_Code = ALS - Upper(0x2A) * Dark + * when ALS DARK_TH -- ALS_Code = ALS - Lower(0x29) * Dark + */ +#define US5182D_REG_UDARK_TH 0x27 +#define US5182D_REG_DARK_AUTO_EN 0x2b +#define US5182D_REG_AUTO_LDARK_TH0x29 +#define US5182D_REG_AUTO_HDARK_TH0x2a + +/* + * power-mode - oneshot, non-interrupt, word mode access for + * als code, th registers. + */ +#define US5182D_REG_CFG0_DEFAULT 0x81 I'd prefer to see the elements of this register broken down. Something like (guessing what is in this reg to a degree). #define US5182D_REG_CFG0_DEFAULT \ (US5182D_AGAIN_1X | (US5182_OPMODE_ALS US5182D_OPMODE_SHIFT)) Perhaps even define the inverse cases so that the values themselves act as documentation. (so SHUTDOWN_DIS and ONESHOT_DIS) Same is true for any of thes registers that are compound values. Basically the code should be explicity where it can be rather than requiring docs that don't make it obvious which parts of the value are the cause of what. + +/* + * no als fault queue, 16 bit als resolution (supports 12 and 14 also), + * max-range 12354. + */ +#define US5182D_REG_CFG1_DEFAULT 0x10 + +/* + * 16 bit resolution for PX, x16 sensing amplifier for px + * supports [x1 x2 x4 x8 x16 x32 x64 x128] + */ +#define US5182D_REG_CFG2_DEFAULT 0x14 + +/* + * led current : 100mA, supports [12.5 25 50 100] mA, + * interrupt source selection px approach, + * [als or ps, als only, ps only, ps approach] + */ +#define US5182D_REG_CFG3_DEFAULT 0x3C + +/* + * led frequency ADC Clock/2 from [ADC Clock/2, /4, /8, /10] + * automatic 50/60 Hz ripple rejection disabled.
Re: [PATCH v2] iio: light: Add support for UPISEMI uS5182d als and proximity sensor
On 04.08.2015 17:40, Peter Meerwald wrote: On Tue, 4 Aug 2015, Adriana Reus wrote: Add support for UPISEMI us5182d als and proximity sensor. Supports raw readings. Data sheet for this device can be found here: http://www.upi-semi.com/temp/uS5182D-DS-P0103-temp.pdf comments below Thank you for the comments. Added answers inline, I'll address them in a new patch-set. Signed-off-by: Adriana Reus --- Changes since v1: added data-sheet link to commit message drivers/iio/light/Kconfig | 10 + drivers/iio/light/Makefile | 1 + drivers/iio/light/us5182d.c | 539 3 files changed, 550 insertions(+) create mode 100644 drivers/iio/light/us5182d.c diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig index a459341..0aa819d 100644 --- a/drivers/iio/light/Kconfig +++ b/drivers/iio/light/Kconfig @@ -285,6 +285,16 @@ config TSL4531 To compile this driver as a module, choose M here: the module will be called tsl4531. +config US5182D + tristate "UPISEMI light and proximity sensor" + depends on I2C + help +If you say yes here you get support for the UPISEMI US5182D +ambient light and proximity sensor. + +This driver can also be built as a module. If so, the module +will be called us5182d. + config VCNL4000 tristate "VCNL4000 combined ALS and proximity sensor" depends on I2C diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile index 91c74c0..528cc8f 100644 --- a/drivers/iio/light/Makefile +++ b/drivers/iio/light/Makefile @@ -27,4 +27,5 @@ obj-$(CONFIG_STK3310) += stk3310.o obj-$(CONFIG_TCS3414) += tcs3414.o obj-$(CONFIG_TCS3472) += tcs3472.o obj-$(CONFIG_TSL4531) += tsl4531.o +obj-$(CONFIG_US5182D) += us5182d.o obj-$(CONFIG_VCNL4000)+= vcnl4000.o diff --git a/drivers/iio/light/us5182d.c b/drivers/iio/light/us5182d.c new file mode 100644 index 000..6654bb0 --- /dev/null +++ b/drivers/iio/light/us5182d.c @@ -0,0 +1,539 @@ +/* + * Copyright (c) 2015 Intel Corporation + * + * Driver for UPISEMI us5182d Proximity and Ambient Light Sensor. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * To do: Interrupt support. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define US5182D_REG_CFG0 0x00 +#define US5182D_REG_CFG1 0x01 +#define US5182D_REG_CFG2 0x02 +#define US5182D_REG_CFG3 0x03 +#define US5182D_REG_CFG4 0x10 + +/* + * Registers for tuning the auto dark current cancelling feature. + * DARK_TH(reg 0x27,0x28) - threshold (counts) for auto dark cancelling. + * when ALS > DARK_TH --> ALS_Code = ALS - Upper(0x2A) * Dark + * when ALS < DARK_TH --> ALS_Code = ALS - Lower(0x29) * Dark + */ +#define US5182D_REG_UDARK_TH 0x27 +#define US5182D_REG_DARK_AUTO_EN 0x2b +#define US5182D_REG_AUTO_LDARK_TH 0x29 +#define US5182D_REG_AUTO_HDARK_TH 0x2a + +/* + * power-mode - oneshot, non-interrupt, word mode access for + * als code, th registers. + */ +#define US5182D_REG_CFG0_DEFAULT 0x81 + +/* + * no als fault queue, 16 bit als resolution (supports 12 and 14 also), + * max-range 12354. + */ +#define US5182D_REG_CFG1_DEFAULT 0x10 + +/* + * 16 bit resolution for PX, x16 sensing amplifier for px + * supports [x1 x2 x4 x8 x16 x32 x64 x128] + */ +#define US5182D_REG_CFG2_DEFAULT 0x14 + +/* + * led current : 100mA, supports [12.5 25 50 100] mA, + * interrupt source selection "px approach", + * [als or ps, als only, ps only, ps approach] + */ +#define US5182D_REG_CFG3_DEFAULT 0x3C + +/* + * led frequency ADC Clock/2 from [ADC Clock/2, /4, /8, /10] + * automatic 50/60 Hz ripple rejection disabled. + */ +#define US5182D_REG_CFG4_DEFAULT 0x00 + +#define US5182D_REG_DARK_AUTO_EN_DEFAULT 0x80 +#define US5182D_REG_AUTO_LDARK_TH_DEFAULT 0x16 +#define US5182D_REG_AUTO_HDARK_TH_DEFAULT 0x00 + +#define US5182D_REG_ADL0x0c +#define US5182D_REG_PDL0x0e + +#define US5182D_REG_MODE_STORE 0x21 +#define US5182D_STORE_MODE 0x01 + +#define US5182D_REG_CHIPID 0xb2 + +#define US5182D_ONESHOT_EN_MASKBIT(6) +#define US5182D_SHUTDOWN_EN_MASK BIT(7) +#define US5182D_OPMODE_MASKGENMASK(5, 4) +#define US5182D_AGAIN_MASK 0x07 +#define
Re: [PATCH v2] iio: light: Add support for UPISEMI uS5182d als and proximity sensor
On 04.08.2015 17:40, Peter Meerwald wrote: On Tue, 4 Aug 2015, Adriana Reus wrote: Add support for UPISEMI us5182d als and proximity sensor. Supports raw readings. Data sheet for this device can be found here: http://www.upi-semi.com/temp/uS5182D-DS-P0103-temp.pdf comments below Thank you for the comments. Added answers inline, I'll address them in a new patch-set. Signed-off-by: Adriana Reus adriana.r...@intel.com --- Changes since v1: added data-sheet link to commit message drivers/iio/light/Kconfig | 10 + drivers/iio/light/Makefile | 1 + drivers/iio/light/us5182d.c | 539 3 files changed, 550 insertions(+) create mode 100644 drivers/iio/light/us5182d.c diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig index a459341..0aa819d 100644 --- a/drivers/iio/light/Kconfig +++ b/drivers/iio/light/Kconfig @@ -285,6 +285,16 @@ config TSL4531 To compile this driver as a module, choose M here: the module will be called tsl4531. +config US5182D + tristate UPISEMI light and proximity sensor + depends on I2C + help +If you say yes here you get support for the UPISEMI US5182D +ambient light and proximity sensor. + +This driver can also be built as a module. If so, the module +will be called us5182d. + config VCNL4000 tristate VCNL4000 combined ALS and proximity sensor depends on I2C diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile index 91c74c0..528cc8f 100644 --- a/drivers/iio/light/Makefile +++ b/drivers/iio/light/Makefile @@ -27,4 +27,5 @@ obj-$(CONFIG_STK3310) += stk3310.o obj-$(CONFIG_TCS3414) += tcs3414.o obj-$(CONFIG_TCS3472) += tcs3472.o obj-$(CONFIG_TSL4531) += tsl4531.o +obj-$(CONFIG_US5182D) += us5182d.o obj-$(CONFIG_VCNL4000)+= vcnl4000.o diff --git a/drivers/iio/light/us5182d.c b/drivers/iio/light/us5182d.c new file mode 100644 index 000..6654bb0 --- /dev/null +++ b/drivers/iio/light/us5182d.c @@ -0,0 +1,539 @@ +/* + * Copyright (c) 2015 Intel Corporation + * + * Driver for UPISEMI us5182d Proximity and Ambient Light Sensor. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * To do: Interrupt support. + */ + +#include linux/kernel.h +#include linux/module.h +#include linux/acpi.h +#include linux/delay.h +#include linux/i2c.h +#include linux/iio/iio.h +#include linux/iio/sysfs.h +#include linux/mutex.h + +#define US5182D_REG_CFG0 0x00 +#define US5182D_REG_CFG1 0x01 +#define US5182D_REG_CFG2 0x02 +#define US5182D_REG_CFG3 0x03 +#define US5182D_REG_CFG4 0x10 + +/* + * Registers for tuning the auto dark current cancelling feature. + * DARK_TH(reg 0x27,0x28) - threshold (counts) for auto dark cancelling. + * when ALS DARK_TH -- ALS_Code = ALS - Upper(0x2A) * Dark + * when ALS DARK_TH -- ALS_Code = ALS - Lower(0x29) * Dark + */ +#define US5182D_REG_UDARK_TH 0x27 +#define US5182D_REG_DARK_AUTO_EN 0x2b +#define US5182D_REG_AUTO_LDARK_TH 0x29 +#define US5182D_REG_AUTO_HDARK_TH 0x2a + +/* + * power-mode - oneshot, non-interrupt, word mode access for + * als code, th registers. + */ +#define US5182D_REG_CFG0_DEFAULT 0x81 + +/* + * no als fault queue, 16 bit als resolution (supports 12 and 14 also), + * max-range 12354. + */ +#define US5182D_REG_CFG1_DEFAULT 0x10 + +/* + * 16 bit resolution for PX, x16 sensing amplifier for px + * supports [x1 x2 x4 x8 x16 x32 x64 x128] + */ +#define US5182D_REG_CFG2_DEFAULT 0x14 + +/* + * led current : 100mA, supports [12.5 25 50 100] mA, + * interrupt source selection px approach, + * [als or ps, als only, ps only, ps approach] + */ +#define US5182D_REG_CFG3_DEFAULT 0x3C + +/* + * led frequency ADC Clock/2 from [ADC Clock/2, /4, /8, /10] + * automatic 50/60 Hz ripple rejection disabled. + */ +#define US5182D_REG_CFG4_DEFAULT 0x00 + +#define US5182D_REG_DARK_AUTO_EN_DEFAULT 0x80 +#define US5182D_REG_AUTO_LDARK_TH_DEFAULT 0x16 +#define US5182D_REG_AUTO_HDARK_TH_DEFAULT 0x00 + +#define US5182D_REG_ADL0x0c +#define US5182D_REG_PDL0x0e + +#define US5182D_REG_MODE_STORE 0x21 +#define US5182D_STORE_MODE 0x01 + +#define US5182D_REG_CHIPID 0xb2 + +#define US5182D_ONESHOT_EN_MASKBIT(6) +#define US5182D_SHUTDOWN_EN_MASK BIT(7)
Re: [PATCH v2] iio: light: Add support for UPISEMI uS5182d als and proximity sensor
On Tue, 4 Aug 2015, Adriana Reus wrote: > Add support for UPISEMI us5182d als and proximity sensor. > Supports raw readings. > Data sheet for this device can be found here: > http://www.upi-semi.com/temp/uS5182D-DS-P0103-temp.pdf comments below > Signed-off-by: Adriana Reus > --- > Changes since v1: added data-sheet link to commit message > drivers/iio/light/Kconfig | 10 + > drivers/iio/light/Makefile | 1 + > drivers/iio/light/us5182d.c | 539 > > 3 files changed, 550 insertions(+) > create mode 100644 drivers/iio/light/us5182d.c > > diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig > index a459341..0aa819d 100644 > --- a/drivers/iio/light/Kconfig > +++ b/drivers/iio/light/Kconfig > @@ -285,6 +285,16 @@ config TSL4531 >To compile this driver as a module, choose M here: the >module will be called tsl4531. > > +config US5182D > + tristate "UPISEMI light and proximity sensor" > + depends on I2C > + help > + If you say yes here you get support for the UPISEMI US5182D > + ambient light and proximity sensor. > + > + This driver can also be built as a module. If so, the module > + will be called us5182d. > + > config VCNL4000 > tristate "VCNL4000 combined ALS and proximity sensor" > depends on I2C > diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile > index 91c74c0..528cc8f 100644 > --- a/drivers/iio/light/Makefile > +++ b/drivers/iio/light/Makefile > @@ -27,4 +27,5 @@ obj-$(CONFIG_STK3310) += stk3310.o > obj-$(CONFIG_TCS3414)+= tcs3414.o > obj-$(CONFIG_TCS3472)+= tcs3472.o > obj-$(CONFIG_TSL4531)+= tsl4531.o > +obj-$(CONFIG_US5182D)+= us5182d.o > obj-$(CONFIG_VCNL4000) += vcnl4000.o > diff --git a/drivers/iio/light/us5182d.c b/drivers/iio/light/us5182d.c > new file mode 100644 > index 000..6654bb0 > --- /dev/null > +++ b/drivers/iio/light/us5182d.c > @@ -0,0 +1,539 @@ > +/* > + * Copyright (c) 2015 Intel Corporation > + * > + * Driver for UPISEMI us5182d Proximity and Ambient Light Sensor. > + * > + * This program is free software; you can redistribute it and/or modify it > + * under the terms of the GNU General Public License version 2 as published > by > + * the Free Software Foundation. > + * > + * This program is distributed in the hope it will be useful, but WITHOUT > + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or > + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for > + * more details. > + * > + * To do: Interrupt support. > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define US5182D_REG_CFG0 0x00 > +#define US5182D_REG_CFG1 0x01 > +#define US5182D_REG_CFG2 0x02 > +#define US5182D_REG_CFG3 0x03 > +#define US5182D_REG_CFG4 0x10 > + > +/* > + * Registers for tuning the auto dark current cancelling feature. > + * DARK_TH(reg 0x27,0x28) - threshold (counts) for auto dark cancelling. > + * when ALS > DARK_TH --> ALS_Code = ALS - Upper(0x2A) * Dark > + * when ALS < DARK_TH --> ALS_Code = ALS - Lower(0x29) * Dark > + */ > +#define US5182D_REG_UDARK_TH 0x27 > +#define US5182D_REG_DARK_AUTO_EN 0x2b > +#define US5182D_REG_AUTO_LDARK_TH0x29 > +#define US5182D_REG_AUTO_HDARK_TH0x2a > + > +/* > + * power-mode - oneshot, non-interrupt, word mode access for > + * als code, th registers. > + */ > +#define US5182D_REG_CFG0_DEFAULT 0x81 > + > +/* > + * no als fault queue, 16 bit als resolution (supports 12 and 14 also), > + * max-range 12354. > + */ > +#define US5182D_REG_CFG1_DEFAULT 0x10 > + > +/* > + * 16 bit resolution for PX, x16 sensing amplifier for px > + * supports [x1 x2 x4 x8 x16 x32 x64 x128] > + */ > +#define US5182D_REG_CFG2_DEFAULT 0x14 > + > +/* > + * led current : 100mA, supports [12.5 25 50 100] mA, > + * interrupt source selection "px approach", > + * [als or ps, als only, ps only, ps approach] > + */ > +#define US5182D_REG_CFG3_DEFAULT 0x3C > + > +/* > + * led frequency ADC Clock/2 from [ADC Clock/2, /4, /8, /10] > + * automatic 50/60 Hz ripple rejection disabled. > + */ > +#define US5182D_REG_CFG4_DEFAULT 0x00 > + > +#define US5182D_REG_DARK_AUTO_EN_DEFAULT 0x80 > +#define US5182D_REG_AUTO_LDARK_TH_DEFAULT0x16 > +#define US5182D_REG_AUTO_HDARK_TH_DEFAULT0x00 > + > +#define US5182D_REG_ADL 0x0c > +#define US5182D_REG_PDL 0x0e > + > +#define US5182D_REG_MODE_STORE 0x21 > +#define US5182D_STORE_MODE 0x01 > + > +#define US5182D_REG_CHIPID 0xb2 > + > +#define US5182D_ONESHOT_EN_MASK BIT(6) > +#define US5182D_SHUTDOWN_EN_MASK BIT(7) > +#define
Re: [PATCH v2] iio: light: Add support for UPISEMI uS5182d als and proximity sensor
On Tue, Aug 4, 2015 at 4:40 PM, Adriana Reus wrote: > Add support for UPISEMI us5182d als and proximity sensor. > Supports raw readings. > Data sheet for this device can be found here: > http://www.upi-semi.com/temp/uS5182D-DS-P0103-temp.pdf > > Signed-off-by: Adriana Reus Looks good to me. Thanks Adriana! Acked-by: Daniel Baluta > --- > Changes since v1: added data-sheet link to commit message > drivers/iio/light/Kconfig | 10 + > drivers/iio/light/Makefile | 1 + > drivers/iio/light/us5182d.c | 539 > > 3 files changed, 550 insertions(+) > create mode 100644 drivers/iio/light/us5182d.c > > diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig > index a459341..0aa819d 100644 > --- a/drivers/iio/light/Kconfig > +++ b/drivers/iio/light/Kconfig > @@ -285,6 +285,16 @@ config TSL4531 > To compile this driver as a module, choose M here: the > module will be called tsl4531. > > +config US5182D > + tristate "UPISEMI light and proximity sensor" > + depends on I2C > + help > +If you say yes here you get support for the UPISEMI US5182D > +ambient light and proximity sensor. > + > +This driver can also be built as a module. If so, the module > +will be called us5182d. > + > config VCNL4000 > tristate "VCNL4000 combined ALS and proximity sensor" > depends on I2C > diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile > index 91c74c0..528cc8f 100644 > --- a/drivers/iio/light/Makefile > +++ b/drivers/iio/light/Makefile > @@ -27,4 +27,5 @@ obj-$(CONFIG_STK3310) += stk3310.o > obj-$(CONFIG_TCS3414) += tcs3414.o > obj-$(CONFIG_TCS3472) += tcs3472.o > obj-$(CONFIG_TSL4531) += tsl4531.o > +obj-$(CONFIG_US5182D) += us5182d.o > obj-$(CONFIG_VCNL4000) += vcnl4000.o > diff --git a/drivers/iio/light/us5182d.c b/drivers/iio/light/us5182d.c > new file mode 100644 > index 000..6654bb0 > --- /dev/null > +++ b/drivers/iio/light/us5182d.c > @@ -0,0 +1,539 @@ > +/* > + * Copyright (c) 2015 Intel Corporation > + * > + * Driver for UPISEMI us5182d Proximity and Ambient Light Sensor. > + * > + * This program is free software; you can redistribute it and/or modify it > + * under the terms of the GNU General Public License version 2 as published > by > + * the Free Software Foundation. > + * > + * This program is distributed in the hope it will be useful, but WITHOUT > + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or > + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for > + * more details. > + * > + * To do: Interrupt support. > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define US5182D_REG_CFG0 0x00 > +#define US5182D_REG_CFG1 0x01 > +#define US5182D_REG_CFG2 0x02 > +#define US5182D_REG_CFG3 0x03 > +#define US5182D_REG_CFG4 0x10 > + > +/* > + * Registers for tuning the auto dark current cancelling feature. > + * DARK_TH(reg 0x27,0x28) - threshold (counts) for auto dark cancelling. > + * when ALS > DARK_TH --> ALS_Code = ALS - Upper(0x2A) * Dark > + * when ALS < DARK_TH --> ALS_Code = ALS - Lower(0x29) * Dark > + */ > +#define US5182D_REG_UDARK_TH 0x27 > +#define US5182D_REG_DARK_AUTO_EN 0x2b > +#define US5182D_REG_AUTO_LDARK_TH 0x29 > +#define US5182D_REG_AUTO_HDARK_TH 0x2a > + > +/* > + * power-mode - oneshot, non-interrupt, word mode access for > + * als code, th registers. > + */ > +#define US5182D_REG_CFG0_DEFAULT 0x81 > + > +/* > + * no als fault queue, 16 bit als resolution (supports 12 and 14 also), > + * max-range 12354. > + */ > +#define US5182D_REG_CFG1_DEFAULT 0x10 > + > +/* > + * 16 bit resolution for PX, x16 sensing amplifier for px > + * supports [x1 x2 x4 x8 x16 x32 x64 x128] > + */ > +#define US5182D_REG_CFG2_DEFAULT 0x14 > + > +/* > + * led current : 100mA, supports [12.5 25 50 100] mA, > + * interrupt source selection "px approach", > + * [als or ps, als only, ps only, ps approach] > + */ > +#define US5182D_REG_CFG3_DEFAULT 0x3C > + > +/* > + * led frequency ADC Clock/2 from [ADC Clock/2, /4, /8, /10] > + * automatic 50/60 Hz ripple rejection disabled. > + */ > +#define US5182D_REG_CFG4_DEFAULT 0x00 > + > +#define US5182D_REG_DARK_AUTO_EN_DEFAULT 0x80 > +#define US5182D_REG_AUTO_LDARK_TH_DEFAULT 0x16 > +#define US5182D_REG_AUTO_HDARK_TH_DEFAULT 0x00 > + > +#define US5182D_REG_ADL0x0c > +#define US5182D_REG_PDL0x0e > + > +#define US5182D_REG_MODE_STORE 0x21 > +#define US5182D_STORE_MODE 0x01 > + > +#define US5182D_REG_CHIPID 0xb2 > + > +#define US5182D_ONESHOT_EN_MASK
Re: [PATCH v2] iio: light: Add support for UPISEMI uS5182d als and proximity sensor
On Tue, Aug 4, 2015 at 4:40 PM, Adriana Reus adriana.r...@intel.com wrote: Add support for UPISEMI us5182d als and proximity sensor. Supports raw readings. Data sheet for this device can be found here: http://www.upi-semi.com/temp/uS5182D-DS-P0103-temp.pdf Signed-off-by: Adriana Reus adriana.r...@intel.com Looks good to me. Thanks Adriana! Acked-by: Daniel Baluta daniel.bal...@intel.com --- Changes since v1: added data-sheet link to commit message drivers/iio/light/Kconfig | 10 + drivers/iio/light/Makefile | 1 + drivers/iio/light/us5182d.c | 539 3 files changed, 550 insertions(+) create mode 100644 drivers/iio/light/us5182d.c diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig index a459341..0aa819d 100644 --- a/drivers/iio/light/Kconfig +++ b/drivers/iio/light/Kconfig @@ -285,6 +285,16 @@ config TSL4531 To compile this driver as a module, choose M here: the module will be called tsl4531. +config US5182D + tristate UPISEMI light and proximity sensor + depends on I2C + help +If you say yes here you get support for the UPISEMI US5182D +ambient light and proximity sensor. + +This driver can also be built as a module. If so, the module +will be called us5182d. + config VCNL4000 tristate VCNL4000 combined ALS and proximity sensor depends on I2C diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile index 91c74c0..528cc8f 100644 --- a/drivers/iio/light/Makefile +++ b/drivers/iio/light/Makefile @@ -27,4 +27,5 @@ obj-$(CONFIG_STK3310) += stk3310.o obj-$(CONFIG_TCS3414) += tcs3414.o obj-$(CONFIG_TCS3472) += tcs3472.o obj-$(CONFIG_TSL4531) += tsl4531.o +obj-$(CONFIG_US5182D) += us5182d.o obj-$(CONFIG_VCNL4000) += vcnl4000.o diff --git a/drivers/iio/light/us5182d.c b/drivers/iio/light/us5182d.c new file mode 100644 index 000..6654bb0 --- /dev/null +++ b/drivers/iio/light/us5182d.c @@ -0,0 +1,539 @@ +/* + * Copyright (c) 2015 Intel Corporation + * + * Driver for UPISEMI us5182d Proximity and Ambient Light Sensor. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * To do: Interrupt support. + */ + +#include linux/kernel.h +#include linux/module.h +#include linux/acpi.h +#include linux/delay.h +#include linux/i2c.h +#include linux/iio/iio.h +#include linux/iio/sysfs.h +#include linux/mutex.h + +#define US5182D_REG_CFG0 0x00 +#define US5182D_REG_CFG1 0x01 +#define US5182D_REG_CFG2 0x02 +#define US5182D_REG_CFG3 0x03 +#define US5182D_REG_CFG4 0x10 + +/* + * Registers for tuning the auto dark current cancelling feature. + * DARK_TH(reg 0x27,0x28) - threshold (counts) for auto dark cancelling. + * when ALS DARK_TH -- ALS_Code = ALS - Upper(0x2A) * Dark + * when ALS DARK_TH -- ALS_Code = ALS - Lower(0x29) * Dark + */ +#define US5182D_REG_UDARK_TH 0x27 +#define US5182D_REG_DARK_AUTO_EN 0x2b +#define US5182D_REG_AUTO_LDARK_TH 0x29 +#define US5182D_REG_AUTO_HDARK_TH 0x2a + +/* + * power-mode - oneshot, non-interrupt, word mode access for + * als code, th registers. + */ +#define US5182D_REG_CFG0_DEFAULT 0x81 + +/* + * no als fault queue, 16 bit als resolution (supports 12 and 14 also), + * max-range 12354. + */ +#define US5182D_REG_CFG1_DEFAULT 0x10 + +/* + * 16 bit resolution for PX, x16 sensing amplifier for px + * supports [x1 x2 x4 x8 x16 x32 x64 x128] + */ +#define US5182D_REG_CFG2_DEFAULT 0x14 + +/* + * led current : 100mA, supports [12.5 25 50 100] mA, + * interrupt source selection px approach, + * [als or ps, als only, ps only, ps approach] + */ +#define US5182D_REG_CFG3_DEFAULT 0x3C + +/* + * led frequency ADC Clock/2 from [ADC Clock/2, /4, /8, /10] + * automatic 50/60 Hz ripple rejection disabled. + */ +#define US5182D_REG_CFG4_DEFAULT 0x00 + +#define US5182D_REG_DARK_AUTO_EN_DEFAULT 0x80 +#define US5182D_REG_AUTO_LDARK_TH_DEFAULT 0x16 +#define US5182D_REG_AUTO_HDARK_TH_DEFAULT 0x00 + +#define US5182D_REG_ADL0x0c +#define US5182D_REG_PDL0x0e + +#define US5182D_REG_MODE_STORE 0x21 +#define US5182D_STORE_MODE 0x01 + +#define US5182D_REG_CHIPID 0xb2 + +#define
Re: [PATCH v2] iio: light: Add support for UPISEMI uS5182d als and proximity sensor
On Tue, 4 Aug 2015, Adriana Reus wrote: Add support for UPISEMI us5182d als and proximity sensor. Supports raw readings. Data sheet for this device can be found here: http://www.upi-semi.com/temp/uS5182D-DS-P0103-temp.pdf comments below Signed-off-by: Adriana Reus adriana.r...@intel.com --- Changes since v1: added data-sheet link to commit message drivers/iio/light/Kconfig | 10 + drivers/iio/light/Makefile | 1 + drivers/iio/light/us5182d.c | 539 3 files changed, 550 insertions(+) create mode 100644 drivers/iio/light/us5182d.c diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig index a459341..0aa819d 100644 --- a/drivers/iio/light/Kconfig +++ b/drivers/iio/light/Kconfig @@ -285,6 +285,16 @@ config TSL4531 To compile this driver as a module, choose M here: the module will be called tsl4531. +config US5182D + tristate UPISEMI light and proximity sensor + depends on I2C + help + If you say yes here you get support for the UPISEMI US5182D + ambient light and proximity sensor. + + This driver can also be built as a module. If so, the module + will be called us5182d. + config VCNL4000 tristate VCNL4000 combined ALS and proximity sensor depends on I2C diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile index 91c74c0..528cc8f 100644 --- a/drivers/iio/light/Makefile +++ b/drivers/iio/light/Makefile @@ -27,4 +27,5 @@ obj-$(CONFIG_STK3310) += stk3310.o obj-$(CONFIG_TCS3414)+= tcs3414.o obj-$(CONFIG_TCS3472)+= tcs3472.o obj-$(CONFIG_TSL4531)+= tsl4531.o +obj-$(CONFIG_US5182D)+= us5182d.o obj-$(CONFIG_VCNL4000) += vcnl4000.o diff --git a/drivers/iio/light/us5182d.c b/drivers/iio/light/us5182d.c new file mode 100644 index 000..6654bb0 --- /dev/null +++ b/drivers/iio/light/us5182d.c @@ -0,0 +1,539 @@ +/* + * Copyright (c) 2015 Intel Corporation + * + * Driver for UPISEMI us5182d Proximity and Ambient Light Sensor. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * To do: Interrupt support. + */ + +#include linux/kernel.h +#include linux/module.h +#include linux/acpi.h +#include linux/delay.h +#include linux/i2c.h +#include linux/iio/iio.h +#include linux/iio/sysfs.h +#include linux/mutex.h + +#define US5182D_REG_CFG0 0x00 +#define US5182D_REG_CFG1 0x01 +#define US5182D_REG_CFG2 0x02 +#define US5182D_REG_CFG3 0x03 +#define US5182D_REG_CFG4 0x10 + +/* + * Registers for tuning the auto dark current cancelling feature. + * DARK_TH(reg 0x27,0x28) - threshold (counts) for auto dark cancelling. + * when ALS DARK_TH -- ALS_Code = ALS - Upper(0x2A) * Dark + * when ALS DARK_TH -- ALS_Code = ALS - Lower(0x29) * Dark + */ +#define US5182D_REG_UDARK_TH 0x27 +#define US5182D_REG_DARK_AUTO_EN 0x2b +#define US5182D_REG_AUTO_LDARK_TH0x29 +#define US5182D_REG_AUTO_HDARK_TH0x2a + +/* + * power-mode - oneshot, non-interrupt, word mode access for + * als code, th registers. + */ +#define US5182D_REG_CFG0_DEFAULT 0x81 + +/* + * no als fault queue, 16 bit als resolution (supports 12 and 14 also), + * max-range 12354. + */ +#define US5182D_REG_CFG1_DEFAULT 0x10 + +/* + * 16 bit resolution for PX, x16 sensing amplifier for px + * supports [x1 x2 x4 x8 x16 x32 x64 x128] + */ +#define US5182D_REG_CFG2_DEFAULT 0x14 + +/* + * led current : 100mA, supports [12.5 25 50 100] mA, + * interrupt source selection px approach, + * [als or ps, als only, ps only, ps approach] + */ +#define US5182D_REG_CFG3_DEFAULT 0x3C + +/* + * led frequency ADC Clock/2 from [ADC Clock/2, /4, /8, /10] + * automatic 50/60 Hz ripple rejection disabled. + */ +#define US5182D_REG_CFG4_DEFAULT 0x00 + +#define US5182D_REG_DARK_AUTO_EN_DEFAULT 0x80 +#define US5182D_REG_AUTO_LDARK_TH_DEFAULT0x16 +#define US5182D_REG_AUTO_HDARK_TH_DEFAULT0x00 + +#define US5182D_REG_ADL 0x0c +#define US5182D_REG_PDL 0x0e + +#define US5182D_REG_MODE_STORE 0x21 +#define US5182D_STORE_MODE 0x01 + +#define US5182D_REG_CHIPID 0xb2 + +#define US5182D_ONESHOT_EN_MASK BIT(6) +#define US5182D_SHUTDOWN_EN_MASK BIT(7) +#define US5182D_OPMODE_MASK