Re: [PATCHv2 3/5] misc: Driver for APDS990X ALS and proximity sensors
On 10/08/10 14:42, Samu Onkalo wrote: > This is a driver for Avago APDS990X combined ALS and proximity sensor. > > Interface is sysfs based. The driver uses interrupts to provide new data. > The driver supports pm_runtime and regulator frameworks. > > See Documentation/misc-devices/apds990x.txt for details Couple of nitpicks inline based on a quick read. > > Signed-off-by: Samu Onkalo > --- > drivers/misc/apds990x.c | 1303 > ++ > include/linux/i2c/apds990x.h | 58 ++ > 2 files changed, 1361 insertions(+), 0 deletions(-) > create mode 100644 drivers/misc/apds990x.c > create mode 100644 include/linux/i2c/apds990x.h > > diff --git a/drivers/misc/apds990x.c b/drivers/misc/apds990x.c > new file mode 100644 > index 000..658c5c4 > --- /dev/null > +++ b/drivers/misc/apds990x.c > @@ -0,0 +1,1303 @@ > +/* > + * This file is part of the APDS990x sensor driver. > + * Chip is combined proximity and ambient light sensor. > + * > + * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). > + * > + * Contact: Samu Onkalo > + * > + * 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 that 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. > + * > + * You should have received a copy of the GNU General Public License > + * along with this program; if not, write to the Free Software > + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA > + * 02110-1301 USA > + * > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +/* Register map */ > +#define APDS990X_ENABLE 0x00 /* Enable of states and interrupts */ > +#define APDS990X_ATIME0x01 /* ALS ADC time */ > +#define APDS990X_PTIME0x02 /* Proximity ADC time */ > +#define APDS990X_WTIME0x03 /* Wait time */ > +#define APDS990X_AILTL0x04 /* ALS interrupt low threshold low byte */ > +#define APDS990X_AILTH0x05 /* ALS interrupt low threshold hi byte */ > +#define APDS990X_AIHTL0x06 /* ALS interrupt hi threshold low byte */ > +#define APDS990X_AIHTH0x07 /* ALS interrupt hi threshold hi byte */ > +#define APDS990X_PILTL0x08 /* Proximity interrupt low threshold low > byte */ > +#define APDS990X_PILTH0x09 /* Proximity interrupt low threshold hi > byte */ > +#define APDS990X_PIHTL0x0a /* Proximity interrupt hi threshold low > byte */ > +#define APDS990X_PIHTH0x0b /* Proximity interrupt hi threshold hi > byte */ > +#define APDS990X_PERS 0x0c /* Interrupt persistence filters */ > +#define APDS990X_CONFIG 0x0d /* Configuration */ > +#define APDS990X_PPCOUNT 0x0e /* Proximity pulse count */ > +#define APDS990X_CONTROL 0x0f /* Gain control register */ > +#define APDS990X_REV 0x11 /* Revision Number */ > +#define APDS990X_ID 0x12 /* Device ID */ > +#define APDS990X_STATUS 0x13 /* Device status */ > +#define APDS990X_CDATAL 0x14 /* Clear ADC low data register */ > +#define APDS990X_CDATAH 0x15 /* Clear ADC high data register */ > +#define APDS990X_IRDATAL 0x16 /* IR ADC low data register */ > +#define APDS990X_IRDATAH 0x17 /* IR ADC high data register */ > +#define APDS990X_PDATAL 0x18 /* Proximity ADC low data register */ > +#define APDS990X_PDATAH 0x19 /* Proximity ADC high data register */ > + > +/* Control */ > +#define APDS990X_MAX_AGAIN 3 > + > +/* Enable register */ > +#define APDS990X_EN_PIEN (0x1 << 5) > +#define APDS990X_EN_AIEN (0x1 << 4) > +#define APDS990X_EN_WEN (0x1 << 3) > +#define APDS990X_EN_PEN (0x1 << 2) > +#define APDS990X_EN_AEN (0x1 << 1) > +#define APDS990X_EN_PON (0x1 << 0) > +#define APDS990X_EN_DISABLE_ALL 0 > + > +/* Status register */ > +#define APDS990X_ST_PINT (0x1 << 5) > +#define APDS990X_ST_AINT (0x1 << 4) > + > +/* I2C access types */ > +#define APDS990x_CMD_TYPE_MASK (0x03 << 5) > +#define APDS990x_CMD_TYPE_RB (0x00 << 5) /* Repeated byte */ > +#define APDS990x_CMD_TYPE_INC(0x01 << 5) /* Auto increment */ > +#define APDS990x_CMD_TYPE_SPE(0x03 << 5) /* Special function */ > + > +#define APDS990x_ADDR_SHIFT 0 > +#define APDS990x_CMD 0x80 > + > +/* Interrupt ack commands */ > +#define APDS990X_INT_ACK_ALS 0x6 > +#define APDS990X_INT_ACK_PS 0x5 > +#define APDS990X_INT_ACK_BOTH0x7 > + > +/* ptime */ > +#define APDS990X_PTIME_DEFAULT 0xff /* Recommended conversion time > 2.7ms*/ > + > +/* wtime */ > +#define APDS990X_WTIME_DEFAULT 0xee /* ~50ms wait time */ > + > +#define APDS9
[PATCHv2 3/5] misc: Driver for APDS990X ALS and proximity sensors
This is a driver for Avago APDS990X combined ALS and proximity sensor. Interface is sysfs based. The driver uses interrupts to provide new data. The driver supports pm_runtime and regulator frameworks. See Documentation/misc-devices/apds990x.txt for details Signed-off-by: Samu Onkalo --- drivers/misc/apds990x.c | 1303 ++ include/linux/i2c/apds990x.h | 58 ++ 2 files changed, 1361 insertions(+), 0 deletions(-) create mode 100644 drivers/misc/apds990x.c create mode 100644 include/linux/i2c/apds990x.h diff --git a/drivers/misc/apds990x.c b/drivers/misc/apds990x.c new file mode 100644 index 000..658c5c4 --- /dev/null +++ b/drivers/misc/apds990x.c @@ -0,0 +1,1303 @@ +/* + * This file is part of the APDS990x sensor driver. + * Chip is combined proximity and ambient light sensor. + * + * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). + * + * Contact: Samu Onkalo + * + * 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 that 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Register map */ +#define APDS990X_ENABLE 0x00 /* Enable of states and interrupts */ +#define APDS990X_ATIME 0x01 /* ALS ADC time */ +#define APDS990X_PTIME 0x02 /* Proximity ADC time */ +#define APDS990X_WTIME 0x03 /* Wait time */ +#define APDS990X_AILTL 0x04 /* ALS interrupt low threshold low byte */ +#define APDS990X_AILTH 0x05 /* ALS interrupt low threshold hi byte */ +#define APDS990X_AIHTL 0x06 /* ALS interrupt hi threshold low byte */ +#define APDS990X_AIHTH 0x07 /* ALS interrupt hi threshold hi byte */ +#define APDS990X_PILTL 0x08 /* Proximity interrupt low threshold low byte */ +#define APDS990X_PILTH 0x09 /* Proximity interrupt low threshold hi byte */ +#define APDS990X_PIHTL 0x0a /* Proximity interrupt hi threshold low byte */ +#define APDS990X_PIHTH 0x0b /* Proximity interrupt hi threshold hi byte */ +#define APDS990X_PERS 0x0c /* Interrupt persistence filters */ +#define APDS990X_CONFIG 0x0d /* Configuration */ +#define APDS990X_PPCOUNT 0x0e /* Proximity pulse count */ +#define APDS990X_CONTROL 0x0f /* Gain control register */ +#define APDS990X_REV0x11 /* Revision Number */ +#define APDS990X_ID 0x12 /* Device ID */ +#define APDS990X_STATUS 0x13 /* Device status */ +#define APDS990X_CDATAL 0x14 /* Clear ADC low data register */ +#define APDS990X_CDATAH 0x15 /* Clear ADC high data register */ +#define APDS990X_IRDATAL 0x16 /* IR ADC low data register */ +#define APDS990X_IRDATAH 0x17 /* IR ADC high data register */ +#define APDS990X_PDATAL 0x18 /* Proximity ADC low data register */ +#define APDS990X_PDATAH 0x19 /* Proximity ADC high data register */ + +/* Control */ +#define APDS990X_MAX_AGAIN 3 + +/* Enable register */ +#define APDS990X_EN_PIEN (0x1 << 5) +#define APDS990X_EN_AIEN (0x1 << 4) +#define APDS990X_EN_WEN(0x1 << 3) +#define APDS990X_EN_PEN(0x1 << 2) +#define APDS990X_EN_AEN(0x1 << 1) +#define APDS990X_EN_PON(0x1 << 0) +#define APDS990X_EN_DISABLE_ALL 0 + +/* Status register */ +#define APDS990X_ST_PINT (0x1 << 5) +#define APDS990X_ST_AINT (0x1 << 4) + +/* I2C access types */ +#define APDS990x_CMD_TYPE_MASK (0x03 << 5) +#define APDS990x_CMD_TYPE_RB (0x00 << 5) /* Repeated byte */ +#define APDS990x_CMD_TYPE_INC (0x01 << 5) /* Auto increment */ +#define APDS990x_CMD_TYPE_SPE (0x03 << 5) /* Special function */ + +#define APDS990x_ADDR_SHIFT0 +#define APDS990x_CMD 0x80 + +/* Interrupt ack commands */ +#define APDS990X_INT_ACK_ALS 0x6 +#define APDS990X_INT_ACK_PS0x5 +#define APDS990X_INT_ACK_BOTH 0x7 + +/* ptime */ +#define APDS990X_PTIME_DEFAULT 0xff /* Recommended conversion time 2.7ms*/ + +/* wtime */ +#define APDS990X_WTIME_DEFAULT 0xee /* ~50ms wait time */ + +#define APDS990X_TIME_TO_ADC 1024 /* One timetick as ADC count value */ + +/* Persistence */ +#define APDS990X_APERS_SHIFT 0 +#define APDS990X_PPERS_SHIFT 4 + +/* Supported ID:s */ +#define APDS990X_ID_0 0x0 +#define APDS990X_ID_4 0x4 +#define APDS990X_ID_29 0x29 + +/* pgain and pdiode settings */ +#define APDS_PGAIN_1X 0x0 +#define APDS_PDIODE_IR0x2 + +#define APDS990X_L