Re: Newbie Question About Dev-Interface Method
Hi Rory, On Thu, 7 Oct 2010 14:37:57 -0700, Rory Filer wrote: I'm working on a proof-of-concept device which contains several chips connected to the same adapter (/dev/ic2-0) on the I2C bus. Some of these have kernel-space drivers (e.g. GPIO Expander) and some don't. For the ones that don't I've opted to use the method described in the kernel Documentation/i2c/dev-interface document. This works great and does all I need for now. This is the general procedure I'm following as outlined in kernel - Documentation/i2c/dev-interface. - open /dev/i2c-N - Set the chip's address by calling ioctl(file, I2C_SLAVE, address) - interact with the chip using read/write or smb calls, etc. - close the file when done I'm assuming that a kernel space chip driver like our gpio expander (pca953x.c) also uses the same adapter driver as my user-space application since that expander chip is on the same bus. Let's clarify right away: i2c-dev (which handles /dev/i2c-* nodes) is NOT an adapter driver. It is a bridge driver between user-space and your adapter driver. Your adapter driver is most likely one living in drivers/i2c/busses, and depends on the actual hardware you run on. My question is, what happens if a kernel driver is using the bus at the same time my user-mode application is? It will work fine. Even if the user space app. may not be running when the chip driver runs, the adapter has an address written into it via the ioctl() call, I noted above. Incorrect. The address isn't written to the adapter, it is a setting local to i2c-dev and even specific to the file handle you got when opening a /dev/i2c-* node. Each subsequent read, write or smbus call in your user-space driver automatically includes the slave address, which is only valid for the read, write or smbus call in question. Can unpredictable results occur in this scenario? No. I think I could protect against it by writing a thread to serialize accesses to the I2C bus, but that only works if my entire application is running inside one process. I'm hoping someone on the list might be able to advise. The i2c-core module already serializes all accesses to every given i2c adapter through i2c_transfer() and i2c_smbus_xfer(). -- Jean Delvare http://khali.linux-fr.org/wishlist.html -- To unsubscribe from this list: send the line unsubscribe linux-i2c in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCHv2 2/5] misc: update bhsfh driver to Kconfig and Makefile
Compilation support for bhsfh driver Signed-off-by: Samu Onkalo samu.p.onk...@nokia.com --- drivers/misc/Kconfig | 10 ++ drivers/misc/Makefile |1 + 2 files changed, 11 insertions(+), 0 deletions(-) diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index b743312..f2e8065 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -314,6 +314,16 @@ config SENSORS_BH1780 This driver can also be built as a module. If so, the module will be called bh1780gli. +config SENSORS_BHSFH + tristate BH1770GLC / SFH7770 combined ALS / Proximity sensor; + depends on I2C + ---help--- + Say Y here if you want to build a driver for BH1770GLC / SFH7770 + combined ambient light and proximity sensor chip + + To compile this driver as a module, choose M here: the + module will be called bhsfh. If unsure, say N here. + config HMC6352 tristate Honeywell HMC6352 compass depends on I2C diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index 42eab95..fd5a4b7 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -16,6 +16,7 @@ obj-$(CONFIG_TIFM_CORE) += tifm_core.o obj-$(CONFIG_TIFM_7XX1)+= tifm_7xx1.o obj-$(CONFIG_PHANTOM) += phantom.o obj-$(CONFIG_SENSORS_BH1780) += bh1780gli.o +obj-$(CONFIG_SENSORS_BHSFH)+= bhsfh.o obj-$(CONFIG_SGI_IOC4) += ioc4.o obj-$(CONFIG_ENCLOSURE_SERVICES) += enclosure.o obj-$(CONFIG_KGDB_TESTS) += kgdbts.o -- 1.6.0.4 -- To unsubscribe from this list: send the line unsubscribe linux-i2c in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCHv2 4/5] misc: update apds990x driver to Kconfig and Makefile
Compilation support for apds990x driver Signed-off-by: Samu Onkalo samu.p.onk...@nokia.com --- drivers/misc/Kconfig | 11 +++ drivers/misc/Makefile |1 + 2 files changed, 12 insertions(+), 0 deletions(-) diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index f2e8065..cc7c363 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -324,6 +324,17 @@ config SENSORS_BHSFH To compile this driver as a module, choose M here: the module will be called bhsfh. If unsure, say N here. +config SENSORS_APDS990X +tristate APDS990X combined als and proximity sensors +depends on I2C +default n +---help--- + Say Y here if you want to build a driver for Avago APDS990x + combined ambient light and proximity sensor chip + + To compile this driver as a module, choose M here: the + module will be called apds990x. If unsure, say N here. + config HMC6352 tristate Honeywell HMC6352 compass depends on I2C diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index fd5a4b7..b90cea7 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -17,6 +17,7 @@ obj-$(CONFIG_TIFM_7XX1) += tifm_7xx1.o obj-$(CONFIG_PHANTOM) += phantom.o obj-$(CONFIG_SENSORS_BH1780) += bh1780gli.o obj-$(CONFIG_SENSORS_BHSFH)+= bhsfh.o +obj-$(CONFIG_SENSORS_APDS990X) += apds990x.o obj-$(CONFIG_SGI_IOC4) += ioc4.o obj-$(CONFIG_ENCLOSURE_SERVICES) += enclosure.o obj-$(CONFIG_KGDB_TESTS) += kgdbts.o -- 1.6.0.4 -- To unsubscribe from this list: send the line unsubscribe linux-i2c in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCHv2 5/5] Documentation: Short descriptions for bhsfh and apds990x drivers
Add short documentation for two ALS / proximity chip drivers. bhsfh document update Signed-off-by: Samu Onkalo samu.p.onk...@nokia.com --- Documentation/misc-devices/apds990x.txt | 152 +++ Documentation/misc-devices/bhsfh.txt| 148 ++ 2 files changed, 300 insertions(+), 0 deletions(-) create mode 100644 Documentation/misc-devices/apds990x.txt create mode 100644 Documentation/misc-devices/bhsfh.txt diff --git a/Documentation/misc-devices/apds990x.txt b/Documentation/misc-devices/apds990x.txt new file mode 100644 index 000..7b61495 --- /dev/null +++ b/Documentation/misc-devices/apds990x.txt @@ -0,0 +1,152 @@ +Kernel driver apds990x +== + +Supported chips: +Avago APDS990X + +Data sheet: +Not freely available + +Author: +Samu Onkalo samu.p.onk...@nokia.com + +Description +--- + +APDS990x is a combined ambient light and proximity sensor. ALS and proximity +functionality are highly connected. ALS measurement path must be running +while the proximity functionality is enabled. + +ALS produces only raw measurement values. Further processing is needed +to get sensible LUX values. Vice versa, HW threshold control has nothing +to do with LUX values. Threshold detection triggs to raw conversion values. +Driver makes necessary conversions to both directions so that user handles +only LUX values. ALS contains 4 different gain steps. Driver automatically +selects suitable gain step. After each measurement, reliability of the results +is estimated and new measurement is trigged if necessary. + +Platform data can provide tuned values to the conversion formulas if +values are known. Otherwise plain sensor default values are used. + +Proximity side is little bit simpler. There is no need for complex conversions. +It produces directly usable values. + +Driver controls chip operational state using pm_runtime framework. +Voltage regulators are controlled based on chip operational state. + +SYSFS +- + + +chip_id + RO - shows detected chip type and version + +power_state + RW - enable / disable chip. Uses counting logic +1 enables the chip +0 disables the chip +lux0_input + RO - measured LUX value +sysfs_notify called when threshold interrupt occurs + +lux0_sensor_range + RO - lux0_input max value. Actually never reaches since sensor tends +to saturate much before that. Real max value varies depending +on the light spectrum etc. + + +lux0_rate + RW - measurement rate in Hz + +lux0_rate_avail + RO - supported measurement rates + +lux0_calibscale + RW - calibration value. Set to neutral value by default. +Output results are multiplied with calibscale / calibscale_default +value. + +lux0_calibscale_default + RO - neutral calibration value + +lux0_thresh_above_value + RW - HI level threshold value. All results above the value +trigs an interrupt. 65535 (i.e. sensor_range) disables the above +interrupt. + +lux0_thresh_below_value + RW - LO level threshold value. All results below the value +trigs an interrupt. 0 disables the below interrupt. + +prox0_raw + RO - measured proximity value +sysfs_notify called when threshold interrupt occurs + +prox0_sensor_range + RO - prox0_raw max value (1023) + +prox0_raw_en + RW - enable / disable proximity - uses counting logic +1 enables the proximity +0 disables the proximity + +prox0_reporting_mode + RW - trigger / periodic. In trigger mode the driver tells two possible +values: 0 or prox0_sensor_range value. 0 means no proximity, +1023 means proximity. This causes minimal number of interrupts. +In periodic mode the driver reports all values above +prox0_thresh_above. This causes more interrupts, but it can give +_rough_ estimate about the distance. + +prox0_reporting_mode_avail + RO - accepted values to prox0_reporting_mode (trigger, periodic) + +prox0_thresh_above_value + RW - threshold level which trigs proximity events. + +Platform data +- + + +#define APDS_IRLED_CURR_12mA 0x3 +#define APDS_IRLED_CURR_25mA 0x2 +#define APDS_IRLED_CURR_50mA 0x1 +#define APDS_IRLED_CURR_100mA 0x0 + +/* + * Structure for tuning ALS calculation to match with environment. + * There depends on the material above the sensor and the sensor + * itself. If the GA is zero, driver will use uncovered sensor default values + * format: decimal value * APDS_PARAM_SCALE + */ +#define APDS_PARAM_SCALE 4096 +struct apds990x_chip_factors { + int ga; /* Glass attenuation */ + int cf1;/* Clear channel factor 1 */ + int irf1; /* Ir channel factor 1 */ + int cf2;/* Clear channel factor 2 */ + int irf2; /* Ir channel factor 2 */ + int
[PATCHv2 1/5] misc: Driver for bh1770glc / sfh7770 ALS and proximity sensor
This is a driver for ROHM BH1770GLC and OSRAM SFH7770 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/bhsfh.txt for details Signed-off-by: Samu Onkalo samu.p.onk...@nokia.com --- drivers/misc/bhsfh.c | 1443 + include/linux/i2c/bhsfh.h | 42 ++ 2 files changed, 1485 insertions(+), 0 deletions(-) create mode 100644 drivers/misc/bhsfh.c create mode 100644 include/linux/i2c/bhsfh.h diff --git a/drivers/misc/bhsfh.c b/drivers/misc/bhsfh.c new file mode 100644 index 000..e82fadb --- /dev/null +++ b/drivers/misc/bhsfh.c @@ -0,0 +1,1443 @@ +/* + * This file is part of the ROHM BH1770GLC / OSRAM SFH7770 sensor driver. + * Chip is combined proximity and ambient light sensor. + * + * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). + * + * Contact: Samu Onkalo samu.p.onk...@nokia.com + * + * 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 linux/kernel.h +#include linux/module.h +#include linux/i2c.h +#include linux/interrupt.h +#include linux/mutex.h +#include linux/i2c/bhsfh.h +#include linux/regulator/consumer.h +#include linux/pm_runtime.h +#include linux/workqueue.h +#include linux/delay.h +#include linux/wait.h +#include linux/slab.h + +#define BHSFH_ALS_CONTROL 0x80 /* ALS operation mode control */ +#define BHSFH_PS_CONTROL 0x81 /* PS operation mode control */ +#define BHSFH_I_LED0x82 /* active LED and LED1, LED2 current */ +#define BHSFH_I_LED3 0x83 /* LED3 current setting */ +#define BHSFH_ALS_PS_MEAS 0x84 /* Forced mode trigger */ +#define BHSFH_PS_MEAS_RATE 0x85 /* PS meas. rate at stand alone mode */ +#define BHSFH_ALS_MEAS_RATE0x86 /* ALS meas. rate at stand alone mode */ +#define BHSFH_PART_ID 0x8a /* Part number and revision ID */ +#define BHSFH_MANUFACT_ID 0x8b /* Manufacturerer ID */ +#define BHSFH_ALS_DATA_0 0x8c /* ALS DATA low byte */ +#define BHSFH_ALS_DATA_1 0x8d /* ALS DATA high byte */ +#define BHSFH_ALS_PS_STATUS0x8e /* Measurement data and int status */ +#define BHSFH_PS_DATA_LED1 0x8f /* PS data from LED1 */ +#define BHSFH_PS_DATA_LED2 0x90 /* PS data from LED2 */ +#define BHSFH_PS_DATA_LED3 0x91 /* PS data from LED3 */ +#define BHSFH_INTERRUPT0x92 /* Interrupt setting */ +#define BHSFH_PS_TH_LED1 0x93 /* PS interrupt threshold for LED1 */ +#define BHSFH_PS_TH_LED2 0x94 /* PS interrupt threshold for LED2 */ +#define BHSFH_PS_TH_LED3 0x95 /* PS interrupt threshold for LED3 */ +#define BHSFH_ALS_TH_UP_0 0x96 /* ALS upper threshold low byte */ +#define BHSFH_ALS_TH_UP_1 0x97 /* ALS upper threshold high byte */ +#define BHSFH_ALS_TH_LOW_0 0x98 /* ALS lower threshold low byte */ +#define BHSFH_ALS_TH_LOW_1 0x99 /* ALS lower threshold high byte */ + +/* MANUFACT_ID */ +#define BHSFH_MANUFACT_ROHM0x01 +#define BHSFH_MANUFACT_OSRAM 0x03 + +/* PART_ID */ +#define BHSFH_PART 0x90 +#define BHSFH_PART_MASK0xf0 +#define BHSFH_REV_MASK 0x0f +#define BHSFH_REV_SHIFT0 +#define BHSFH_REV_00x00 +#define BHSFH_REV_10x01 + +/* ALS_MEAS_RATE */ +#define BHSFH_ALS_MAX_RATE 9 + +/* PS_MEAS_RATE */ +#define BHSFH_PS_MAX_RATE 4 + +/* Operating modes for both */ +#define BHSFH_STANDBY 0x00 +#define BHSFH_FORCED 0x02 +#define BHSFH_STANDALONE 0x03 +#define BHSFH_SWRESET (0x01 2) + +#define BHSFH_PS_TRIG_MEAS (1 0) +#define BHSFH_ALS_TRIG_MEAS(1 1) + +/* Interrupt control */ +#define BHSFH_INT_OUTPUT_MODE (1 3) /* 0 = latched */ +#define BHSFH_INT_POLARITY (1 2) /* 1 = active high */ +#define BHSFH_INT_ALS_ENA (1 1) +#define BHSFH_INT_PS_ENA (1 0) + +/* Interrupt status */ +#define BHSFH_INT_LED1_DATA(1 0) +#define BHSFH_INT_LED1_INT (1 1) +#define BHSFH_INT_LED2_DATA(1 2) +#define BHSFH_INT_LED2_INT (1 3) +#define BHSFH_INT_LED3_DATA(1 4) +#define BHSFH_INT_LED3_INT (1 5) +#define BHSFH_INT_LEDS_INT ((1 1) | (1 3) | (1 5)) +#define BHSFH_INT_ALS_DATA (1 6) +#define BHSFH_INT_ALS_INT (1 7) + +/* Led channels */ +#define BHSFH_LED1
[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 samu.p.onk...@nokia.com --- 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 samu.p.onk...@nokia.com + * + * 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 linux/kernel.h +#include linux/module.h +#include linux/i2c.h +#include linux/interrupt.h +#include linux/mutex.h +#include linux/regulator/consumer.h +#include linux/pm_runtime.h +#include linux/delay.h +#include linux/wait.h +#include linux/slab.h +#include linux/i2c/apds990x.h + +/* 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
Re: [PATCHv2 2/5] misc: update bhsfh driver to Kconfig and Makefile
On 10/08/10 14:42, Samu Onkalo wrote: Compilation support for bhsfh driver Signed-off-by: Samu Onkalo samu.p.onk...@nokia.com --- drivers/misc/Kconfig | 10 ++ drivers/misc/Makefile |1 + 2 files changed, 11 insertions(+), 0 deletions(-) diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index b743312..f2e8065 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -314,6 +314,16 @@ config SENSORS_BH1780 This driver can also be built as a module. If so, the module will be called bh1780gli. +config SENSORS_BHSFH + tristate BH1770GLC / SFH7770 combined ALS / Proximity sensor; + depends on I2C + ---help--- + Say Y here if you want to build a driver for BH1770GLC / SFH7770 + combined ambient light and proximity sensor chip + + To compile this driver as a module, choose M here: the + module will be called bhsfh. If unsure, say N here. + Really not keen on the naming. The above comment made me think this was a single chip integrating both of the parts. Reading the code makes it clear that they just share an interface. So please name it after one of them. Lots of reasons not to invent combined names like this. * non obvious thing to grep for. * 3rd part comes along with a different name. Do you change the driver name? So best bet is always just to pick a supported part and name the driver after that. The device table stuff and clear descriptions in kconfig will make it obvious what the part supports. config HMC6352 tristate Honeywell HMC6352 compass depends on I2C diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index 42eab95..fd5a4b7 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -16,6 +16,7 @@ obj-$(CONFIG_TIFM_CORE) += tifm_core.o obj-$(CONFIG_TIFM_7XX1) += tifm_7xx1.o obj-$(CONFIG_PHANTOM)+= phantom.o obj-$(CONFIG_SENSORS_BH1780) += bh1780gli.o +obj-$(CONFIG_SENSORS_BHSFH) += bhsfh.o obj-$(CONFIG_SGI_IOC4) += ioc4.o obj-$(CONFIG_ENCLOSURE_SERVICES) += enclosure.o obj-$(CONFIG_KGDB_TESTS) += kgdbts.o -- To unsubscribe from this list: send the line unsubscribe linux-i2c in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCHv2 1/5] misc: Driver for bh1770glc / sfh7770 ALS and proximity sensor
On 10/08/10 14:42, Samu Onkalo wrote: This is a driver for ROHM BH1770GLC and OSRAM SFH7770 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/bhsfh.txt for details Couple of nitpicks / formatting suggestions inline. Signed-off-by: Samu Onkalo samu.p.onk...@nokia.com --- drivers/misc/bhsfh.c | 1443 + include/linux/i2c/bhsfh.h | 42 ++ 2 files changed, 1485 insertions(+), 0 deletions(-) create mode 100644 drivers/misc/bhsfh.c create mode 100644 include/linux/i2c/bhsfh.h diff --git a/drivers/misc/bhsfh.c b/drivers/misc/bhsfh.c new file mode 100644 index 000..e82fadb --- /dev/null +++ b/drivers/misc/bhsfh.c @@ -0,0 +1,1443 @@ +/* + * This file is part of the ROHM BH1770GLC / OSRAM SFH7770 sensor driver. + * Chip is combined proximity and ambient light sensor. + * + * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). + * + * Contact: Samu Onkalo samu.p.onk...@nokia.com + * + * 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 linux/kernel.h +#include linux/module.h +#include linux/i2c.h +#include linux/interrupt.h +#include linux/mutex.h +#include linux/i2c/bhsfh.h +#include linux/regulator/consumer.h +#include linux/pm_runtime.h +#include linux/workqueue.h +#include linux/delay.h +#include linux/wait.h +#include linux/slab.h + +#define BHSFH_ALS_CONTROL0x80 /* ALS operation mode control */ +#define BHSFH_PS_CONTROL 0x81 /* PS operation mode control */ +#define BHSFH_I_LED 0x82 /* active LED and LED1, LED2 current */ +#define BHSFH_I_LED3 0x83 /* LED3 current setting */ +#define BHSFH_ALS_PS_MEAS0x84 /* Forced mode trigger */ +#define BHSFH_PS_MEAS_RATE 0x85 /* PS meas. rate at stand alone mode */ +#define BHSFH_ALS_MEAS_RATE 0x86 /* ALS meas. rate at stand alone mode */ +#define BHSFH_PART_ID0x8a /* Part number and revision ID */ +#define BHSFH_MANUFACT_ID0x8b /* Manufacturerer ID */ +#define BHSFH_ALS_DATA_0 0x8c /* ALS DATA low byte */ +#define BHSFH_ALS_DATA_1 0x8d /* ALS DATA high byte */ +#define BHSFH_ALS_PS_STATUS 0x8e /* Measurement data and int status */ +#define BHSFH_PS_DATA_LED1 0x8f /* PS data from LED1 */ +#define BHSFH_PS_DATA_LED2 0x90 /* PS data from LED2 */ +#define BHSFH_PS_DATA_LED3 0x91 /* PS data from LED3 */ +#define BHSFH_INTERRUPT 0x92 /* Interrupt setting */ +#define BHSFH_PS_TH_LED1 0x93 /* PS interrupt threshold for LED1 */ +#define BHSFH_PS_TH_LED2 0x94 /* PS interrupt threshold for LED2 */ +#define BHSFH_PS_TH_LED3 0x95 /* PS interrupt threshold for LED3 */ +#define BHSFH_ALS_TH_UP_00x96 /* ALS upper threshold low byte */ +#define BHSFH_ALS_TH_UP_10x97 /* ALS upper threshold high byte */ +#define BHSFH_ALS_TH_LOW_0 0x98 /* ALS lower threshold low byte */ +#define BHSFH_ALS_TH_LOW_1 0x99 /* ALS lower threshold high byte */ + +/* MANUFACT_ID */ +#define BHSFH_MANUFACT_ROHM 0x01 +#define BHSFH_MANUFACT_OSRAM 0x03 + +/* PART_ID */ +#define BHSFH_PART 0x90 +#define BHSFH_PART_MASK 0xf0 +#define BHSFH_REV_MASK 0x0f +#define BHSFH_REV_SHIFT 0 +#define BHSFH_REV_0 0x00 +#define BHSFH_REV_1 0x01 + +/* ALS_MEAS_RATE */ +#define BHSFH_ALS_MAX_RATE 9 + +/* PS_MEAS_RATE */ +#define BHSFH_PS_MAX_RATE4 + +/* Operating modes for both */ +#define BHSFH_STANDBY0x00 +#define BHSFH_FORCED 0x02 +#define BHSFH_STANDALONE 0x03 +#define BHSFH_SWRESET(0x01 2) + +#define BHSFH_PS_TRIG_MEAS (1 0) +#define BHSFH_ALS_TRIG_MEAS (1 1) + +/* Interrupt control */ +#define BHSFH_INT_OUTPUT_MODE(1 3) /* 0 = latched */ +#define BHSFH_INT_POLARITY (1 2) /* 1 = active high */ +#define BHSFH_INT_ALS_ENA(1 1) +#define BHSFH_INT_PS_ENA (1 0) + +/* Interrupt status */ +#define BHSFH_INT_LED1_DATA (1 0) +#define BHSFH_INT_LED1_INT (1 1) +#define BHSFH_INT_LED2_DATA (1 2) +#define BHSFH_INT_LED2_INT (1 3) +#define BHSFH_INT_LED3_DATA (1 4) +#define BHSFH_INT_LED3_INT (1 5) +#define BHSFH_INT_LEDS_INT ((1
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 samu.p.onk...@nokia.com --- 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 samu.p.onk...@nokia.com + * + * 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 linux/kernel.h +#include linux/module.h +#include linux/i2c.h +#include linux/interrupt.h +#include linux/mutex.h +#include linux/regulator/consumer.h +#include linux/pm_runtime.h +#include linux/delay.h +#include linux/wait.h +#include linux/slab.h +#include linux/i2c/apds990x.h + +/* 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
RE: Newbie Question About Dev-Interface Method
I'm assuming that a kernel space chip driver like our gpio expander (pca953x.c) also uses the same adapter driver as my user-space application since that expander chip is on the same bus. Let's clarify right away: i2c-dev (which handles /dev/i2c-* nodes) is NOT an adapter driver. It is a bridge driver between user-space and your adapter driver. Your adapter driver is most likely one living in drivers/i2c/busses, and depends on the actual hardware you run on. OK, thanks that's clear. I was confused by the terminology in the dev-interface document. When it said to open an adapter, I thought that meant I was using the associated adapter driver. Incorrect. The address isn't written to the adapter, it is a setting local to i2c-dev and even specific to the file handle you got when opening a /dev/i2c-* node. Each subsequent read, write or smbus call in your user-space driver automatically includes the slave address, which is only valid for the read, write or smbus call in question. Excellent! - in the words of a famous Swiss restaurant's wine menu, this leaves me nothing to hope for! Jean, thank you for your help, it saved me a ton pouring over source code and allowed me to get on with the job at hand. Much appreciated. Regards, Rory -- To unsubscribe from this list: send the line unsubscribe linux-i2c in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html