TAOS tsl2x7x
A message that is not in the archive (sent off-list or not yet received): [email protected]
Sorry Jon, my battery packed up half way through writing this.
Quoted 11 lines · Jon Brenner
Quoted 2 lines · Jonathan Cameron
Quoted 1 line · Jon Brenner
TAOS device driver (version 7) for the tsl/tmd 2771 and 2772 device
families (inc. all variants).
Quoted 7 lines
Quoted 3 lines
Updates:
Documentation - added prefix corrections.Sorry Jon,
Few more bits in here..
Quoted 9 lines
Quoted 1 line
err. I still see
illuminance0_calibrateandproximity_calibrate. Bothof
Quoted 1 line
those want prefixes as well.
OK - Was under impression those didn't want
in_.
Will fix - should have asked.How about the 'available' abi
(ie.dev_attr_illuminance0_calibscale_available) ?
Yes. in_ as well
Quoted 7 lines
Quoted 1 line
Also
in_illuminance0_intergration_timeisn't in the abi docs. If weare
Quoted 2 lines
happy with this abi, we'll move
it intoinfo_maskin the core.It's in the sysfs-bus-iio-light doc.
Noticed that most do not have the 'in_' prefix in this doc. Do they need it?
Yes. My bad as I clearly missed it. Been meaning to do pass of all drivers and clean up prefixes. Just never get round to it!
In most cases the attributes are generated from the channel description and so the prefix is added by that. I clearly missed a lot of instances of attributes directly defined in various drivers and in the documentation.
Quoted 5 lines
Quoted 4 lines
Also the merge on the docs seems to have messed up. Pleasee fix that.
What do you mean by messed up - please explain?7
I made a few fixes in syfs-bus-iio that have I think been reverted by your patch. I've highlighted them inline below.
Quoted 9 lines
What about the /Documentation/light/ directory - do you still what this in there?
Quoted 1 line
Note that if this crosses with the move out of staging series then
the
Quoted 2 lines
header paths will need
updating.When is this going to happen and what header paths are you talking about?
Shortly (i.e. later this week unless anyone hits significant issues)
Basically, drivers/staging/iio/*.h -> include/linux/iio/*
So all the core headers. Here,
"../events.h" -> <iio/events.h>
"../sysfs.h" -> <iio/sysfs.h>
"../iio.h" -> <iio/iio.h>
I think...
Also, staging/iio/Documentation/sysfs-bus-iio -> Documentation/ABI/experimental/sysfs-bus-iio which will cause issues with your additions to that file.
If the last few fixes go in here by Wednesday I'll do an update on my series before I send it on to Greg to take into account your new driver.
Shortly after that series has gone, we'll start hammering any remaining abi issues in the clean drivers and pushing them out of staging into drivers/iio/<type>/ as well.
For the coming merge window we really want to get the core out, but obviously it would be good to do a few drivers as well!
Quoted 81 lines
Quoted 5 lines
Sorry for making life hard all over again!
Thanks
JonQuoted 3 lines
Jonathan
Quoted 1 line
Code - removed FP division, incorporation of new
IIO_CHAN_INFO_bitmasks into .info_mask, various comment and consistency clean-ups.
Quoted 12 lines
Quoted 12 lines
Signed-off-by Jon Brenner<[email protected]>--- .../light/sysfs-bus-iio-light-tsl2583 | 6 + .../light/sysfs-bus-iio-light-tsl2x7x | 13 + drivers/staging/iio/Documentation/sysfs-bus-iio | 16 +- .../staging/iio/Documentation/sysfs-bus-iio-light | 8 +- drivers/staging/iio/light/Kconfig | 8 + drivers/staging/iio/light/Makefile | 1 + drivers/staging/iio/light/tsl2x7x.h | 100 + drivers/staging/iio/light/tsl2x7x_core.c | 2073++++++++++++++++++++
Quoted 3 lines
Quoted 3 lines
8 files changed, 2217 insertions(+), 8 deletions(-)diff --git
a/drivers/staging/iio/Documentation/light/sysfs-bus-iio-light-tsl2583 b/drivers/staging/iio/Documentation/light/sysfs-bus-iio-light-tsl2583
Quoted 4 lines
Quoted 4 lines
new file mode 100755
index 0000000..8f2a038
---/dev/null
+++b/drivers/staging/iio/Documentation/light/sysfs-bus-iio-light-tsl2583
Quoted 6 lines
Review line 5
Quoted 6 lines
(quoted diff) +5
-0@@ -0,0 +1,6 @@ +What: /sys/bus/iio/devices/device[n]/illuminance0_calibrate +KernelVersion: 2.6.37 +Contact: [email protected] +Description: + This property causes an internal calibration of the als gaintrim
Quoted 2 lines
Quoted 2 lines
(quoted diff) +1
-0+ value which is later used in calculating illuminance in lux.diff --git
a/drivers/staging/iio/Documentation/light/sysfs-bus-iio-light-tsl2x7x b/drivers/staging/iio/Documentation/light/sysfs-bus-iio-light-tsl2x7x
Quoted 4 lines
Quoted 4 lines
new file mode 100755
index 0000000..c0b1d4d
---/dev/null
+++b/drivers/staging/iio/Documentation/light/sysfs-bus-iio-light-tsl2x7x
Quoted 7 lines
Quoted 7 lines
(quoted diff) +6
-0@@ -0,0 +1,13 @@ +What: /sys/bus/iio/devices/device[n]/illuminance0_calibrate +KernelVersion: 3.3-rc1 +Contact: [email protected] +Description: + Causes an internal calibration of the als gain trim + value which is later used in calculating illuminance in lux.Quoted 8 lines
Review
Quoted 8 lines
(quoted diff) +7
-0+ +What: /sys/bus/iio/devices/device[n]/proximity_calibrate +KernelVersion: 3.3-rc1 +Contact: [email protected] +Description: + Causes a recalculation and adjustment to the + proximity_thresh_rising_value.(quoted diff) +0
-0b/drivers/staging/iio/Documentation/sysfs-bus-iio
Quoted 4 lines
drivers/staging/iio/Documentation/sysfs-bus-iio
Quoted 4 lines
index ca12784..14cba73 100644
drivers/staging/iio/Documentation/sysfs-bus-iio +0
-0@@ -258,6 +258,8 @@What /sys/bus/iio/devices/iio:deviceX/in_accel_z_calibscale
Quoted 9 lines
drivers/staging/iio/Documentation/sysfs-bus-iio
Quoted 9 lines
drivers/staging/iio/Documentation/sysfs-bus-iio +2
-0What /sys/bus/iio/devices/iio:deviceX/in_anglvel_x_calibscale What /sys/bus/iio/devices/iio:deviceX/in_anglvel_y_calibscale What /sys/bus/iio/devices/iio:deviceX/in_anglvel_z_calibscale +what /sys/bus/iio/devices/iio:deviceX/in_illuminance0_calibscale +what /sys/bus/iio/devices/iio:deviceX/in_proximity_calibscale KernelVersion: 2.6.35 Contact: [email protected] Description:@@ -453,10 +455,14 @@What:
/sys/.../events/in_magn_z_raw_thresh_rising_value
Quoted 4 lines
Quoted 3 lines
drivers/staging/iio/Documentation/sysfs-bus-iio line 457
Quoted 3 lines
drivers/staging/iio/Documentation/sysfs-bus-iio +0
-0What: /sys/.../events/in_magn_z_raw_thresh_falling_value What: /sys/.../events/in_voltageY_supply_raw_thresh_rising_valueWhat:
/sys/.../events/in_voltageY_supply_raw_thresh_falling_value
This leaves us with two in_voltageY_raw_thresh_falling_value entries and in_tempY_raw_thresh_falling_value entries. These were originally there due to a cut and paste messup by me but I've fixed them already. Your patch puts the error back again!
Quoted 18 lines
Quoted 6 lines
drivers/staging/iio/Documentation/sysfs-bus-iio line 460
Quoted 5 lines
drivers/staging/iio/Documentation/sysfs-bus-iio +2
-2-What: /sys/.../events/in_voltageY_raw_thresh_rising_value What: /sys/.../events/in_voltageY_raw_thresh_falling_value -What: /sys/.../events/in_tempY_raw_thresh_rising_value +What: /sys/.../events/in_voltageY_raw_thresh_falling_value +What: /sys/.../events/in_tempY_raw_thresh_falling_valueerr. I think a merge has gone wrong here. Please fix. Check the
rest
Quoted 10 lines
as well.
drivers/staging/iio/Documentation/sysfs-bus-iio
Quoted 9 lines
drivers/staging/iio/Documentation/sysfs-bus-iio +4
-0What: /sys/.../events/in_tempY_raw_thresh_falling_value +What: /sys/.../events/in_illuminance0_thresh_falling_value +what: /sys/.../events/in_illuminance0_thresh_rising_value +what: /sys/.../events/in_proximity_thresh_falling_value +what: /sys/.../events/in_proximity_thresh_rising_value KernelVersion: 2.6.37 Contact: [email protected] Description:@@ -490,9 +496,9 @@What:
/sys/.../events/in_magn_z_raw_roc_rising_value
Quoted 7 lines
Quoted 7 lines
drivers/staging/iio/Documentation/sysfs-bus-iio line 500
Quoted 7 lines
drivers/staging/iio/Documentation/sysfs-bus-iio +1
-2What: /sys/.../events/in_magn_z_raw_roc_falling_value What: /sys/.../events/in_voltageY_supply_raw_roc_rising_value What: /sys/.../events/in_voltageY_supply_raw_roc_falling_value -What: /sys/.../events/in_voltageY_raw_roc_rising_value What: /sys/.../events/in_voltageY_raw_roc_falling_value -What: /sys/.../events/in_tempY_raw_roc_rising_value +What: /sys/.../events/in_voltageY_raw_roc_falling_value
The patch leaves us with two in_voltageY_raw_roc_falling_value entries whereas a fixup I pushed out the other day had changed one of them into a rising varient.
Quoted 824 lines
Quoted 5 lines
drivers/staging/iio/Documentation/sysfs-bus-iio
Quoted 5 lines
drivers/staging/iio/Documentation/sysfs-bus-iio +1
-0+What: /sys/.../events/in_tempY_raw_roc_falling_value What: /sys/.../events/in_tempY_raw_roc_falling_value KernelVersion: 2.6.37 Contact: [email protected]@@ -556,6 +562,8 @@What:
/sys/.../events/in_tempY_thresh_falling_periodQuoted 9 lines
Review
Quoted 9 lines
drivers/staging/iio/Documentation/sysfs-bus-iio +2
-0What: /sys/.../events/in_tempY_roc_rising_period What: /sys/.../events/in_tempY_roc_falling_period What: /sys/.../events/in_accel_x&y&z_mag_falling_period +What: /sys/.../events/in_intensity_thresh_period +What: /sys/.../events/in_proximity_thresh_period KernelVersion: 2.6.37 Contact: [email protected] Description:(quoted diff) +0
-0b/drivers/staging/iio/Documentation/sysfs-bus-iio-light
Quoted 6 lines
drivers/staging/iio/Documentation/sysfs-bus-iio-light Contact: [email protected] · line 77
Quoted 6 lines
index edbf470..4385c70 100644
drivers/staging/iio/Documentation/sysfs-bus-iio-light +0
-0@@ -76,10 +76,10 @@ Contact: [email protected] Description: This property gets/sets the sensors ADC analog integrationtime.
Quoted 13 lines
Review
Quoted 13 lines
drivers/staging/iio/Documentation/sysfs-bus-iio-light +4
-4-What: /sys/bus/iio/devices/device[n]/illuminance0_calibscale +What: /sys/bus/iio/devices/device[n]/lux_table KernelVersion: 2.6.37 Contact: [email protected] Description: - Hardware or software applied calibration scale factor assumed - to account for attenuation due to industrial design (glass - filters or aperture holes). + This property gets/sets the table of coefficients + used in calculating illuminance in lux. +(quoted diff) +0
-0b/drivers/staging/iio/light/Kconfig
Quoted 5 lines
drivers/staging/iio/light/Kconfig config TSL2583 · line 41
Quoted 5 lines
index bb633f6..821ad6b 100644
drivers/staging/iio/light/Kconfig +0
-0@@ -41,4 +41,12 @@ config TSL2583 Provides support for the TAOS tsl2580, tsl2581 and tsl2583devices.
Quoted 4 lines
drivers/staging/iio/light/Kconfig config TSL2583 · line 45
Quoted 4 lines
drivers/staging/iio/light/Kconfig +2
-0Access ALS data via iio, sysfs. +config TSL2x7x + tristate "TAOS TSL/TMD2x71 and TSL/TMD2x72 Family of light andproximity sensors"
Quoted 3 lines
drivers/staging/iio/light/Kconfig config TSL2583 · line 48
Quoted 3 lines
drivers/staging/iio/light/Kconfig +3
-0+ depends on I2C + help + Support for: tsl2571, tsl2671, tmd2671, tsl2771, tmd2771,tsl2572, tsl2672,
Quoted 5 lines
Review
Quoted 5 lines
drivers/staging/iio/light/Kconfig +3
-0+ tmd2672, tsl2772, tmd2772 devices. + Provides iio_events and direct access via sysfs. + endmenu(quoted diff) +0
-0b/drivers/staging/iio/light/Makefile
Quoted 9 lines
Review
Quoted 9 lines
index 535d313..141af1e 100644
drivers/staging/iio/light/Makefile +1
-0@@ -6,3 +6,4 @@ obj-$(CONFIG_SENSORS_TSL2563) += tsl2563.o obj-$(CONFIG_SENSORS_ISL29018) += isl29018.o obj-$(CONFIG_SENSORS_ISL29028) += isl29028.o obj-$(CONFIG_TSL2583) += tsl2583.o +obj-$(CONFIG_TSL2x7x) += tsl2x7x_core.o(quoted diff) +0
-0
b/drivers/staging/iio/light/tsl2x7x.hQuoted 4 lines
Quoted 4 lines
new file mode 100755
index 0000000..c4acf5fdrivers/staging/iio/light/tsl2x7x.h new file +0
-0Quoted 8 lines
drivers/staging/iio/light/tsl2x7x.h line 7
Quoted 8 lines
drivers/staging/iio/light/tsl2x7x.h new file +7
-0@@ -0,0 +1,100 @@ +/* +* Device driver for monitoring ambient light intensity (lux) +* and proximity (prox) within the TAOS TSL2X7X family of devices. +* +* Copyright (c) 2012, TAOS Corporation. +* +* This program is free software; you can redistribute it and/or modify
Quoted 1 line
drivers/staging/iio/light/tsl2x7x.h line 8
Quoted 1 line
drivers/staging/iio/light/tsl2x7x.h new file +1
-0+* it under the terms of the GNU General Public License as published by
Quoted 1 line
drivers/staging/iio/light/tsl2x7x.h line 9
Quoted 1 line
drivers/staging/iio/light/tsl2x7x.h new file +1
-0+* the Free Software Foundation; either version 2 of the License, or
Quoted 3 lines
drivers/staging/iio/light/tsl2x7x.h line 12
Quoted 3 lines
drivers/staging/iio/light/tsl2x7x.h new file +3
-0+* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, but WITHOUT
Quoted 1 line
drivers/staging/iio/light/tsl2x7x.h line 13
Quoted 1 line
drivers/staging/iio/light/tsl2x7x.h new file +1
-0+* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
Quoted 1 line
drivers/staging/iio/light/tsl2x7x.h line 14
Quoted 1 line
drivers/staging/iio/light/tsl2x7x.h new file +1
-0+* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
Quoted 3 lines
drivers/staging/iio/light/tsl2x7x.h line 17
Quoted 3 lines
drivers/staging/iio/light/tsl2x7x.h new file +3
-0+* more details. +* +* You should have received a copy of the GNU General Public License along
Quoted 1 line
drivers/staging/iio/light/tsl2x7x.h line 18
Quoted 1 line
drivers/staging/iio/light/tsl2x7x.h new file +1
-0+* with this program; if not, write to the Free Software Foundation, Inc.,
Quoted 10 lines
drivers/staging/iio/light/tsl2x7x.h line 28
Quoted 10 lines
drivers/staging/iio/light/tsl2x7x.h new file +10
-0+* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef __TSL2X7X_H +#define __TSL2X7X_H +#include <linux/pm.h> + +/* Max number of segments allowable in LUX table */ +#define TSL2X7X_MAX_LUX_TABLE_SIZE 9 +#define MAX_DEFAULT_TABLE_BYTES (sizeof(int) *
TSL2X7X_MAX_LUX_TABLE_SIZE)Quoted 5 lines
Quoted 5 lines
drivers/staging/iio/light/tsl2x7x.h new file +5
-0+ +struct iio_dev ; + +struct tsl2x7x_lux { +unsigned int ratio;Quoted 8 lines
drivers/staging/iio/light/tsl2x7x.h line 41
Quoted 8 lines
drivers/staging/iio/light/tsl2x7x.h new file +8
-0+unsigned int ch0; +unsigned int ch1; +}; + +/** +* struct tsl2x7x_default_settings - power on defaults unless +* overridden by platform data. +* @als_time: ALS Integration time - multiple of 50mS
Quoted 4 lines
Quoted 4 lines
drivers/staging/iio/light/tsl2x7x.h new file +4
-0+* @als_gain: Index into the ALS gain table. +* @als_gain_trim: default gain trim to account for +* aperture effects. +* @wait_time: Time between PRX and ALS cycles Quoted 8 lines
drivers/staging/iio/light/tsl2x7x.h line 53
Quoted 8 lines
drivers/staging/iio/light/tsl2x7x.h new file +8
-0+* in 2.7 periods +* @prx_time: 5.2ms prox integration time - +* decrease in 2.7ms periods +* @prx_gain: Proximity gain index +* @prox_config: Prox configuration filters. +* @als_cal_target: Known external ALS reading for +* calibration. +* @interrupts_en: Enable/Disable - 0x00 = none, 0x10 = als,
Quoted 1 line
drivers/staging/iio/light/tsl2x7x.h line 54
Quoted 1 line
drivers/staging/iio/light/tsl2x7x.h new file +1
-0+* 0x20 = prx, 0x30 = bth
Quoted 22 lines
Quoted 22 lines
drivers/staging/iio/light/tsl2x7x.h new file +22
-0+* @persistence: H/W Filters, Number of 'out of limits' +* ADC readings PRX/ALS. +* @als_thresh_low: CH0 'low' count to trigger interrupt. +* @als_thresh_high: CH0 'high' count to trigger interrupt. +* @prox_thres_low: Low threshold proximity detection. +* @prox_thres_high: High threshold proximity detection +* @prox_pulse_count: Number if proximity emitter pulses +* @prox_max_samples_cal: Used for prox cal. +*/ +struct tsl2x7x_settings { +int als_time; +int als_gain; +int als_gain_trim; +int wait_time; +int prx_time; +int prox_gain; +int prox_config; +int als_cal_target; +u8 interrupts_en; +u8 persistence; +int als_thresh_low; +int als_thresh_high;Quoted 8 lines
drivers/staging/iio/light/tsl2x7x.h line 84
Quoted 8 lines
drivers/staging/iio/light/tsl2x7x.h new file +8
-0+int prox_thres_low; +int prox_thres_high; +int prox_pulse_count; +int prox_max_samples_cal; +}; + +/** +* struct tsl2X7X_platform_data - Platform callback, glass and defaults
Quoted 4 lines
Quoted 4 lines
drivers/staging/iio/light/tsl2x7x.h new file +4
-0+* @platform_power: Suspend/resume platform callback +* @power_on: Power on callback +* @power_off: Power off callback +* @platform_lux_table: Device specific glass coefficents Quoted 8 lines
drivers/staging/iio/light/tsl2x7x.h line 96
Quoted 8 lines
drivers/staging/iio/light/tsl2x7x.h new file +8
-0+* @platform_default_settings: Device specific power on defaults +* +*/ +struct tsl2X7X_platform_data { +int (*platform_power)(struct device *dev,pm_message_t ); +int (*power_on) (struct iio_dev *indio_dev); +int (*power_off) (struct i2c_client *dev); +struct tsl2x7x_lux platform_lux_table[TSL2X7X_MAX_LUX_TABLE_SIZE];
Quoted 5 lines
Review
Quoted 5 lines
drivers/staging/iio/light/tsl2x7x.h new file +4
-0+ struct tsl2x7x_settings *platform_default_settings; +}; + +#endif /* __TSL2X7X_H */ (quoted diff) +0
-0
b/drivers/staging/iio/light/tsl2x7x_core.cQuoted 8 lines
drivers/staging/iio/light/tsl2x7x_core.c line 3
Quoted 8 lines
new file mode 100755
index 0000000..79605a8drivers/staging/iio/light/tsl2x7x_core.c new file +3
-0@@ -0,0 +1,2073 @@ +/* +* Device driver for monitoring ambient light intensity in (lux) +* and proximity detection (prox) within the TAOS TSL2X7X family of devices.
Quoted 4 lines
drivers/staging/iio/light/tsl2x7x_core.c line 7
Quoted 4 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +4
-0+* +* Copyright (c) 2012, TAOS Corporation. +* +* This program is free software; you can redistribute it and/or modify
Quoted 1 line
drivers/staging/iio/light/tsl2x7x_core.c line 8
Quoted 1 line
drivers/staging/iio/light/tsl2x7x_core.c new file +1
-0+* it under the terms of the GNU General Public License as published by
Quoted 1 line
drivers/staging/iio/light/tsl2x7x_core.c line 9
Quoted 1 line
drivers/staging/iio/light/tsl2x7x_core.c new file +1
-0+* the Free Software Foundation; either version 2 of the License, or
Quoted 3 lines
drivers/staging/iio/light/tsl2x7x_core.c line 12
Quoted 3 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +3
-0+* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, but WITHOUT
Quoted 1 line
drivers/staging/iio/light/tsl2x7x_core.c line 13
Quoted 1 line
drivers/staging/iio/light/tsl2x7x_core.c new file +1
-0+* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
Quoted 1 line
drivers/staging/iio/light/tsl2x7x_core.c line 14
Quoted 1 line
drivers/staging/iio/light/tsl2x7x_core.c new file +1
-0+* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
Quoted 3 lines
drivers/staging/iio/light/tsl2x7x_core.c line 17
Quoted 3 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +3
-0+* more details. +* +* You should have received a copy of the GNU General Public License along
Quoted 1 line
drivers/staging/iio/light/tsl2x7x_core.c line 18
Quoted 1 line
drivers/staging/iio/light/tsl2x7x_core.c new file +1
-0+* with this program; if not, write to the Free Software Foundation, Inc.,
Quoted 1 line
drivers/staging/iio/light/tsl2x7x_core.c line 19
Quoted 1 line
drivers/staging/iio/light/tsl2x7x_core.c new file +1
-0+* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Quoted 23 lines
Quoted 23 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +23
-0+*/ + +#include <linux/kernel.h> +#include <linux/i2c.h> +#include <linux/errno.h> +#include <linux/delay.h> +#include <linux/mutex.h> +#include <linux/interrupt.h> +#include <linux/slab.h> +#include <linux/module.h> +#include <linux/version.h> +#include "tsl2x7x.h" +#include "../events.h" +#include "../iio.h" +#include "../sysfs.h" + +/* Cal defs*/ +#define PROX_STAT_CAL 0 +#define PROX_STAT_SAMP 1 +#define MAX_SAMPLES_CAL 200 + +/* TSL2X7X Device ID */ +#define TRITON_ID 0x00Quoted 8 lines
drivers/staging/iio/light/tsl2x7x_core.c line 50
Quoted 8 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +8
-0+#define SWORDFISH_ID 0x30 +#define HALIBUT_ID 0x20 + +/* Lux calculation constants */ +#define TSL2X7X_LUX_CALC_OVER_FLOW 65535 + +/* TAOS Register definitions - note: +* depending on device, some of these register are not used and the
Quoted 139 lines
Quoted 139 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +139
-0+* register address is benign. +*/ +/* 2X7X register offsets */ +#define TSL2X7X_MAX_CONFIG_REG 16 + +/* Device Registers and Masks */ +#define TSL2X7X_CNTRL 0x00 +#define TSL2X7X_ALS_TIME 0X01 +#define TSL2X7X_PRX_TIME 0x02 +#define TSL2X7X_WAIT_TIME 0x03 +#define TSL2X7X_ALS_MINTHRESHLO 0X04 +#define TSL2X7X_ALS_MINTHRESHHI 0X05 +#define TSL2X7X_ALS_MAXTHRESHLO 0X06 +#define TSL2X7X_ALS_MAXTHRESHHI 0X07 +#define TSL2X7X_PRX_MINTHRESHLO 0X08 +#define TSL2X7X_PRX_MINTHRESHHI 0X09 +#define TSL2X7X_PRX_MAXTHRESHLO 0X0A +#define TSL2X7X_PRX_MAXTHRESHHI 0X0B +#define TSL2X7X_PERSISTENCE 0x0C +#define TSL2X7X_PRX_CONFIG 0x0D +#define TSL2X7X_PRX_COUNT 0x0E +#define TSL2X7X_GAIN 0x0F +#define TSL2X7X_NOTUSED 0x10 +#define TSL2X7X_REVID 0x11 +#define TSL2X7X_CHIPID 0x12 +#define TSL2X7X_STATUS 0x13 +#define TSL2X7X_ALS_CHAN0LO 0x14 +#define TSL2X7X_ALS_CHAN0HI 0x15 +#define TSL2X7X_ALS_CHAN1LO 0x16 +#define TSL2X7X_ALS_CHAN1HI 0x17 +#define TSL2X7X_PRX_LO 0x18 +#define TSL2X7X_PRX_HI 0x19 + +/* tsl2X7X cmd reg masks */ +#define TSL2X7X_CMD_REG 0x80 +#define TSL2X7X_CMD_SPL_FN 0x60 + +#define TSL2X7X_CMD_PROX_INT_CLR 0X05 +#define TSL2X7X_CMD_ALS_INT_CLR 0x06 +#define TSL2X7X_CMD_PROXALS_INT_CLR 0X07 + +/* tsl2X7X cntrl reg masks */ +#define TSL2X7X_CNTL_ADC_ENBL 0x02 +#define TSL2X7X_CNTL_PWR_ON 0x01 + +/* tsl2X7X status reg masks */ +#define TSL2X7X_STA_ADC_VALID 0x01 +#define TSL2X7X_STA_PRX_VALID 0x02 +#define TSL2X7X_STA_ADC_PRX_VALID (TSL2X7X_STA_ADC_VALID |\ + TSL2X7X_STA_PRX_VALID) +#define TSL2X7X_STA_ALS_INTR 0x10 +#define TSL2X7X_STA_PRX_INTR 0x20 + +/* tsl2X7X cntrl reg masks */ +#define TSL2X7X_CNTL_REG_CLEAR 0x00 +#define TSL2X7X_CNTL_PROX_INT_ENBL 0X20 +#define TSL2X7X_CNTL_ALS_INT_ENBL 0X10 +#define TSL2X7X_CNTL_WAIT_TMR_ENBL 0X08 +#define TSL2X7X_CNTL_PROX_DET_ENBL 0X04 +#define TSL2X7X_CNTL_PWRON 0x01 +#define TSL2X7X_CNTL_ALSPON_ENBL 0x03 +#define TSL2X7X_CNTL_INTALSPON_ENBL 0x13 +#define TSL2X7X_CNTL_PROXPON_ENBL 0x0F +#define TSL2X7X_CNTL_INTPROXPON_ENBL 0x2F + +/*Prox diode to use */ +#define TSL2X7X_DIODE0 0x10 +#define TSL2X7X_DIODE1 0x20 +#define TSL2X7X_DIODE_BOTH 0x30 + +/* LED Power */ +#define TSL2X7X_mA100 0x00 +#define TSL2X7X_mA50 0x40 +#define TSL2X7X_mA25 0x80 +#define TSL2X7X_mA13 0xD0 +#define TSL2X7X_MAX_TIMER_CNT (0xFF) + +/*Common device IIO EventMask */ +#define TSL2X7X_EVENT_MASK \ + (IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING) | \ + IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING)), + +/* TAOS txx2x7x Device family members */ +enum { + tsl2571, + tsl2671, + tmd2671, + tsl2771, + tmd2771, + tsl2572, + tsl2672, + tmd2672, + tsl2772, + tmd2772 +}; + +enum { +TSL2X7X_CHIP_UNKNOWN =0 , +TSL2X7X_CHIP_WORKING =1 , +TSL2X7X_CHIP_SUSPENDED =2 +}; + +struct tsl2x7x_parse_result { +int integer; +int fract; +}; + +/* Per-device data */ +struct tsl2x7x_als_info { +u16 als_ch0; +u16 als_ch1; +u16 lux; +}; + +struct tsl2x7x_prox_stat { +int min; +int max; +int mean; +unsigned long stddev; +}; + +struct tsl2x7x_chip_info { +int chan_table_elements; +struct iio_chan_spec channel[4 ]; +const struct iio_info *info; +}; + +struct tsl2X7X_chip { +kernel_ulong_t id; +struct mutex prox_mutex; +struct mutex als_mutex; +struct i2c_client *client; +u16 prox_data; +struct tsl2x7x_als_info als_cur_info; +struct tsl2x7x_settings tsl2x7x_settings; +struct tsl2X7X_platform_data *pdata; +int als_time_scale; +int als_saturation; +int tsl2x7x_chip_status;Quoted 8 lines
drivers/staging/iio/light/tsl2x7x_core.c line 197
Quoted 8 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +8
-0+u8 tsl2x7x_config[TSL2X7X_MAX_CONFIG_REG ]; +const struct tsl2x7x_chip_info *chip_info; +const struct iio_info *info; +s64 event_timestamp; +/* This structure is intentionally large to accommodate +* updates via sysfs. */ +/* Sized to 9 = max 8 segments + 1 termination segment */ +struct tsl2x7x_lux tsl2x7x_device_lux[TSL2X7X_MAX_LUX_TABLE_SIZE];
Quoted 20 lines
Quoted 20 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +20
-0+}; + +/* Different devices require different coefficents */ +static const struct tsl2x7x_lux tsl2x71_lux_table[] = { + {14461 ,611 ,1211 }, + {18540 ,352 ,623 }, + {0 ,0 ,0 }, +}; + +static const struct tsl2x7x_lux tmd2x71_lux_table[] = { + {11635 ,115 ,256 }, + {15536 ,87 ,179 }, + {0 ,0 ,0 }, +}; + +static const struct tsl2x7x_lux tsl2x72_lux_table[] = { + {14013 ,466 ,917 }, + {18222 ,310 ,552 }, + {0 ,0 ,0 }, +};Quoted 8 lines
drivers/staging/iio/light/tsl2x7x_core.c line 225
Quoted 8 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +8
-0+ +static const struct tsl2x7x_lux tmd2x72_lux_table[] = { + {13218 ,130 ,262 }, + {17592 ,92 ,169 }, + {0 ,0 ,0 }, +}; + +static const struct tsl2x7x_lux *tsl2x7x_default_lux_table_group[]= {
Quoted 68 lines
Quoted 68 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +68
-0+ [tsl2571] = tsl2x71_lux_table, + [tsl2671] = tsl2x71_lux_table, + [tmd2671] = tmd2x71_lux_table, + [tsl2771] = tsl2x71_lux_table, + [tmd2771] = tmd2x71_lux_table, + [tsl2572] = tsl2x72_lux_table, + [tsl2672] = tsl2x72_lux_table, + [tmd2672] = tmd2x72_lux_table, + [tsl2772] = tsl2x72_lux_table, + [tmd2772] = tmd2x72_lux_table, +}; + +static const struct tsl2x7x_settings tsl2x7x_default_settings = { + .als_time =219 ,/* 101 ms */ + .als_gain =0 , + .prx_time =254 ,/* 5.4 ms */ + .prox_gain =1 , + .wait_time =245 , + .prox_config =0 , + .als_gain_trim =1000 , + .als_cal_target =150 , + .als_thresh_low =200 , + .als_thresh_high =256 , + .persistence =255 , + .interrupts_en =0 , + .prox_thres_low =0 , + .prox_thres_high =512 , + .prox_max_samples_cal =30 , + .prox_pulse_count =8 +}; + +static const s16 tsl2X7X_als_gainadj[] = { +1 , +8 , +16 , +120 +}; + +static const s16 tsl2X7X_prx_gainadj[] = { +1 , +2 , +4 , +8 +}; + +/* Channel variations */ +enum { +ALS , +PRX , +ALSPRX , +PRX2 , +ALSPRX2 , +}; + +const u8 device_channel_config[] = { +ALS , +PRX , +PRX , +ALSPRX , +ALSPRX , +ALS , +PRX2 , +PRX2 , +ALSPRX2 , +ALSPRX2 +}; + +/** Quoted 8 lines
drivers/staging/iio/light/tsl2x7x_core.c line 301
Quoted 8 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +8
-0+* tsl2x7x_parse_buffer() - parse a decimal result from a buffer. +* @*buf: pointer to char buffer to parse +* @*result: pointer to buffer to contain +* resulting interger / decimal as ints. +* +*/ +static int +tsl2x7x_parse_buffer(const char *buf, struct tsl2x7x_parse_result*result)
Quoted 72 lines
Quoted 72 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +72
-0+{ +int integer =0 , fract =0 , fract_mult =100000 ; +bool integer_part = true, negative = false; + +if (buf[0 ] =='-' ) { + negative = true; + buf++; + } + +while (*buf) { +if ('0' <= *buf&& *buf<='9' ) { +if (integer_part) + integer = integer*10 + *buf -'0' ; +else { + fract += fract_mult*(*buf -'0' ); +if (fract_mult ==1 ) +break ; + fract_mult /=10 ; + } + }else if (*buf =='\n' ) { +if (*(buf +1 ) =='\0' ) +break ; +else +return -EINVAL ; + }else if (*buf =='.' ) { + integer_part = false; + }else { +return -EINVAL ; + } + buf++; + } +if (negative) { +if (integer) + integer = -integer; +else + fract = -fract; + } + + result->integer = integer; + result->fract = fract; + +return 0 ; +} + +/** +* tsl2x7x_i2c_read() - Read a byte from a register. +* @client: i2c client +* @reg: device register to read from +* @*val: pointer to location to store register contents. +* +*/ +static int +tsl2x7x_i2c_read (struct i2c_client *client,u8 reg,u8 *val) +{ +int ret =0 ; + +/* select register to write */ + ret =i2c_smbus_write_byte (client, (TSL2X7X_CMD_REG | reg)); +if (ret<0 ) { +dev_err (&client->dev,"%s: failed to write register %x\n" + , __func__, reg); +return ret; + } + +/* read the data */ + ret =i2c_smbus_read_byte (client); +if (ret>=0 ) + *val = (u8 )ret; +else +dev_err (&client->dev,"%s: failed to read register %x\n" + , __func__, reg); +Quoted 8 lines
drivers/staging/iio/light/tsl2x7x_core.c line 381
Quoted 8 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +8
-0+return ret; +} + +/** +* tsl2x7x_get_lux() - Reads and calculates current lux value. +* @indio_dev: pointer to IIO device +* +* The raw ch0 and ch1 values of the ambient light sensed in the last
Quoted 2 lines
drivers/staging/iio/light/tsl2x7x_core.c line 383
Quoted 2 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +2
-0+* integration cycle are read from the device. +* Time scale factor array values are adjusted based on the integration time.
Quoted 1 line
drivers/staging/iio/light/tsl2x7x_core.c line 384
Quoted 1 line
drivers/staging/iio/light/tsl2x7x_core.c new file +1
-0+* The raw values are multiplied by a scale factor, and device gain is obtained
Quoted 1 line
drivers/staging/iio/light/tsl2x7x_core.c line 385
Quoted 1 line
drivers/staging/iio/light/tsl2x7x_core.c new file +1
-0+* using gain index. Limit checks are done next, then the ratio of a multiple
Quoted 1 line
drivers/staging/iio/light/tsl2x7x_core.c line 386
Quoted 1 line
drivers/staging/iio/light/tsl2x7x_core.c new file +1
-0+* of ch1 value, to the ch0 value, is calculated. Array tsl2x7x_device_lux[]
Quoted 1 line
drivers/staging/iio/light/tsl2x7x_core.c line 387
Quoted 1 line
drivers/staging/iio/light/tsl2x7x_core.c new file +1
-0+* is then scanned to find the first ratio value that is just above the ratio
Quoted 1 line
drivers/staging/iio/light/tsl2x7x_core.c line 388
Quoted 1 line
drivers/staging/iio/light/tsl2x7x_core.c new file +1
-0+* we just calculated. The ch0 and ch1 multiplier constants in the array are
Quoted 1 line
drivers/staging/iio/light/tsl2x7x_core.c line 389
Quoted 1 line
drivers/staging/iio/light/tsl2x7x_core.c new file +1
-0+* then used along with the time scale factor array values, to calculate the
Quoted 64 lines
Quoted 64 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +64
-0+* lux. +*/ +static int tsl2x7x_get_lux (struct iio_dev *indio_dev) +{ +u16 ch0, ch1;/* separated ch0/ch1 data from device */ +u32 lux;/* raw lux calculated from device data */ +u64 lux64; +u32 ratio; +u8 buf[4 ]; +struct tsl2x7x_lux *p; +struct tsl2X7X_chip *chip =iio_priv (indio_dev); +int i, ret; +u32 ch0lux =0 ; +u32 ch1lux =0 ; + +if (mutex_trylock (&chip->als_mutex) ==0 ) +return chip->als_cur_info.lux;/* busy, so return LAST VALUE */ + +if (chip->tsl2x7x_chip_status !=TSL2X7X_CHIP_WORKING ) { +/* device is not enabled */ +dev_err (&chip->client->dev,"%s: device is not enabled\n" , + __func__); + ret = -EBUSY ; + goto out_unlock; + } + + ret =tsl2x7x_i2c_read (chip->client, + (TSL2X7X_CMD_REG |TSL2X7X_STATUS ),&buf[0 ]); +if (ret<0 ) { +dev_err (&chip->client->dev, +"%s: Failed to read STATUS Reg\n" , __func__); + goto out_unlock; + } +/* is data new& valid */ +if (!(buf[0 ]&TSL2X7X_STA_ADC_VALID )) { +dev_err (&chip->client->dev, +"%s: data not valid yet\n" , __func__); + ret = chip->als_cur_info.lux;/* return LAST VALUE */ + goto out_unlock; + } + +for (i =0 ; i<4 ; i++) { + ret =tsl2x7x_i2c_read (chip->client, + (TSL2X7X_CMD_REG | (TSL2X7X_ALS_CHAN0LO + i)), + &buf[i]); +if (ret<0 ) { +dev_err (&chip->client->dev, +"%s: failed to read. err=%x\n" , __func__, ret); + goto out_unlock; + } + } + +/* clear any existing interrupt status */ + ret =i2c_smbus_write_byte (chip->client, + (TSL2X7X_CMD_REG | +TSL2X7X_CMD_SPL_FN | +TSL2X7X_CMD_ALS_INT_CLR )); +if (ret<0 ) { +dev_err (&chip->client->dev, +"%s: i2c_write_command failed - err = %d\n" , + __func__, ret); + goto out_unlock;/* have no data, so return failure */ + } +Quoted 8 lines
drivers/staging/iio/light/tsl2x7x_core.c line 461
Quoted 8 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +8
-0+/* extract ALS/lux data */ + ch0 =le16_to_cpup ((const __le16 *)&buf[0 ]); + ch1 =le16_to_cpup ((const __le16 *)&buf[2 ]); + + chip->als_cur_info.als_ch0 = ch0; + chip->als_cur_info.als_ch1 = ch1; + +if ((ch0>= chip->als_saturation) || (ch1>= chip->als_saturation)){
Quoted 21 lines
Quoted 21 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +21
-0+ lux =TSL2X7X_LUX_CALC_OVER_FLOW ; + goto return_max; + } + +if (ch0 ==0 ) { +/* have no data, so return LAST VALUE */ + ret = chip->als_cur_info.lux; + goto out_unlock; + } +/* calculate ratio */ + ratio = (ch1<<15 ) / ch0; +/* convert to unscaled lux using the pointer to the table */ + p = (struct tsl2x7x_lux *) chip->tsl2x7x_device_lux; +while (p->ratio !=0 && p->ratio< ratio) + p++; + +if (p->ratio ==0 ) { + lux =0 ; + }else { + ch0lux =DIV_ROUND_UP ((ch0 * p->ch0), + tsl2X7X_als_gainadj[chip->tsl2x7x_settings.als_gain]);Quoted 8 lines
drivers/staging/iio/light/tsl2x7x_core.c line 490
Quoted 8 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +8
-0+ ch1lux =DIV_ROUND_UP ((ch1 * p->ch1), + tsl2X7X_als_gainadj[chip->tsl2x7x_settings.als_gain]); + lux = ch0lux - ch1lux; + } + +/* note: lux is 31 bit max at this point */ +if (ch1lux> ch0lux) { + dev_dbg(&chip->client->dev, "ch1lux> ch0lux-return lastvalue\n");
Quoted 7 lines
Quoted 7 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +7
-0+ ret = chip->als_cur_info.lux; + goto out_unlock; + } + +/* adjust for active time scale */ +if (chip->als_time_scale ==0 ) + lux =0 ;Quoted 8 lines
drivers/staging/iio/light/tsl2x7x_core.c line 505
Quoted 8 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +8
-0+else + lux = (lux + (chip->als_time_scale>>1 )) / + chip->als_time_scale; + +/* adjust for active gain scale +* The tsl2x7x_device_lux tables have a factor of 256 built-in. +* User-specified gain provides a multiplier. +* Apply user-specified gain before shifting right to retain precision.
Quoted 2 lines
drivers/staging/iio/light/tsl2x7x_core.c line 507
Quoted 2 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +2
-0+* Use 64 bits to avoid overflow on multiplication. +* Then go back to 32 bits before division to avoid using
div_u64().Quoted 81 lines
Quoted 81 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +81
-0+*/ + + lux64 = lux; + lux64 = lux64 * chip->tsl2x7x_settings.als_gain_trim; + lux64>>=8 ; + lux = lux64; + lux = (lux +500 ) /1000 ; + +if (lux>TSL2X7X_LUX_CALC_OVER_FLOW )/* check for overflow */ + lux =TSL2X7X_LUX_CALC_OVER_FLOW ; + +/* Update the structure with the latest lux. */ +return_max: + chip->als_cur_info.lux = lux; + ret = lux; + +out_unlock: +mutex_unlock (&chip->als_mutex); + +return ret; +} + +/** +* tsl2x7x_get_prox() - Reads proximity data registers and updates +* chip->prox_data. +* +* @indio_dev: pointer to IIO device +*/ +static int tsl2x7x_get_prox (struct iio_dev *indio_dev) +{ +int i; +int ret; +u8 status; +u8 chdata[2 ]; +struct tsl2X7X_chip *chip =iio_priv (indio_dev); + +if (mutex_trylock (&chip->prox_mutex) ==0 ) { +dev_err (&chip->client->dev, +"%s: Can't get prox mutex\n" , __func__); +return -EBUSY ; + } + + ret =tsl2x7x_i2c_read (chip->client, + (TSL2X7X_CMD_REG |TSL2X7X_STATUS ),&status); +if (ret<0 ) { +dev_err (&chip->client->dev, +"%s: i2c err=%d\n" , __func__, ret); + goto prox_poll_err; + } + +switch (chip->id) { +case tsl2571: +case tsl2671: +case tmd2671: +case tsl2771: +case tmd2771: +if (!(status&TSL2X7X_STA_ADC_VALID )) + goto prox_poll_err; +break ; +case tsl2572: +case tsl2672: +case tmd2672: +case tsl2772: +case tmd2772: +if (!(status&TSL2X7X_STA_PRX_VALID )) + goto prox_poll_err; +break ; + } + +for (i =0 ; i<2 ; i++) { + ret =tsl2x7x_i2c_read (chip->client, + (TSL2X7X_CMD_REG | + (TSL2X7X_PRX_LO + i)),&chdata[i]); +if (ret<0 ) + goto prox_poll_err; + } + + chip->prox_data = +le16_to_cpup ((const __le16 *)&chdata[0 ]); + +prox_poll_err:Quoted 8 lines
drivers/staging/iio/light/tsl2x7x_core.c line 596
Quoted 8 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +8
-0+ +mutex_unlock (&chip->prox_mutex); + +return chip->prox_data; +} + +/** +* tsl2x7x_defaults() - Populates the device nominal operating parameters
Quoted 1 line
drivers/staging/iio/light/tsl2x7x_core.c line 597
Quoted 1 line
drivers/staging/iio/light/tsl2x7x_core.c new file +1
-0+* with those provided by a 'platform' data struct or
Quoted 5 lines
Quoted 5 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +5
-0+* with prefined defaults. +* +* @chip: pointer to device structure. +*/ +static void tsl2x7x_defaults(struct tsl2X7X_ch