On 20/08/15 11:12, 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
Applied to the togreg branch of iio.git - initially pushed out
as testing for the autobuilders to play with it.
Thanks,
Jonathan
> ---
> Changes since v5:
> * fixed typos (thank you, Peter)
>
> drivers/iio/light/Kconfig | 10 +
> drivers/iio/light/Makefile | 1 +
> drivers/iio/light/us5182d.c | 507
>
> 3 files changed, 518 insertions(+)
> create mode 100644 drivers/iio/light/us5182d.c
>
> diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig
> index 7ed859a..0442f01 100644
> --- a/drivers/iio/light/Kconfig
> +++ b/drivers/iio/light/Kconfig
> @@ -287,6 +287,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..49dab3c
> --- /dev/null
> +++ b/drivers/iio/light/us5182d.c
> @@ -0,0 +1,507 @@
> +/*
> + * 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_CFG0_ONESHOT_EN BIT(6)
> +#define US5182D_CFG0_SHUTDOWN_EN BIT(7)
> +#define US5182D_CFG0_WORD_ENABLE BIT(0)
> +
> +#define US5182D_REG_CFG1 0x01
> +#define US5182D_CFG1_ALS_RES16 BIT(4)
> +#define US5182D_CFG1_AGAIN_DEFAULT 0x00
> +
> +#define US5182D_REG_CFG2 0x02
> +#define US5182D_CFG2_PX_RES16BIT(4)
> +#define US5182D_CFG2_PXGAIN_DEFAULT BIT(2)
> +
> +#define US5182D_REG_CFG3 0x03
> +#define US5182D_CFG3_LED_CURRENT100 (BIT(4) | BIT(5))
> +
> +#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_GAIN 0x29
> +#define US5182D_REG_AUTO_HDARK_GAIN 0x2a
> +
> +#define US5182D_OPMODE_ALS 0x01
> +#define US5182D_OPMODE_PX0x02
> +#define US5182D_OPMODE_SHIFT 4
> +
> +#define US5182D_REG_DARK_AUTO_EN_DEFAULT 0x80
> +#define US5182D_REG_AUTO_LDARK_GAIN_DEFAULT 0x16
> +#define US5182D_REG_AUTO_HDARK_GAIN_DEFAULT 0x00
> +
> +#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_OPMODE_MASK GENMASK(5, 4)
> +#define US5182D_AGAIN_MASK