TAOS tsl2x7x
Subsystems (3)
PATCH v3 1/1 TAOS tsl2x7x
TAOS device driver (version 3) for the tsl/tmd 2771 and 2772 device families (inc. all variants).
--- .../light/sysfs-bus-iio-light-tsl2583 | 6 + .../light/sysfs-bus-iio-light-tsl2x7x | 20 + drivers/staging/iio/Documentation/sysfs-bus-iio | 7 + .../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_core.c | 1948 ++++++++++++++++++++ drivers/staging/iio/light/tsl2x7x_core.h | 75 + 8 files changed, 2069 insertions(+), 4 deletions(-)
drivers/staging/iio/Documentation/light/sysfs-bus-iio-light-tsl2583 new file +6 -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 gain trim + value which is later used in calculating illuminance in lux.
drivers/staging/iio/Documentation/light/sysfs-bus-iio-light-tsl2x7x new file +20 -0
@@ -0,0 +1,20 @@ +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 gain trim + value which is later used in calculating illuminance in lux. + +What: /sys/bus/iio/devices/device[n]/illuminance0_both_raw +KernelVersion: 3.3-rc1 +Contact: [email protected] +Description: + Simultainious ALS channel data. + +What: /sys/bus/iio/devices/device[n]/proximity_calibrate +KernelVersion: 3.3-rc1 +Contact: [email protected] +Description: + Causes an recalculation and adjustment to the + proximity_thresh_rising_value. +
drivers/staging/iio/Documentation/sysfs-bus-iio +7 -0
@@ -258,6 +258,8 @@ What /sys/bus/iio/devices/iio:deviceX/in_accel_z_calibscale What /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/illuminance0_calibscale +what /sys/bus/iio/devices/iio:deviceX/proximity_calibscale KernelVersion: 2.6.35 Contact: [email protected] Description:
@@ -457,6 +459,10 @@ What: /sys/.../events/in_voltageY_raw_thresh_falling_value What: /sys/.../events/in_voltageY_raw_thresh_falling_value What: /sys/.../events/in_tempY_raw_thresh_falling_value What: /sys/.../events/in_tempY_raw_thresh_falling_value +What: /sys/.../events/illuminance0_thresh_falling_value +what: /sys/.../events/illuminance0_thresh_rising_value +what: /sys/.../events/proximity_thresh_falling_value +what: /sys/.../events/proximity_thresh_rising_value KernelVersion: 2.6.37 Contact: [email protected] Description:
@@ -739,3 +745,4 @@ Description: system. To minimize the current consumption of the system, the bridge can be disconnected (when it is not being used using the bridge_switch_en attribute. +
drivers/staging/iio/Documentation/sysfs-bus-iio-light +4 -4
@@ -76,10 +76,10 @@ Contact: [email protected] Description: This property gets/sets the sensors ADC analog integration time. -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. +
drivers/staging/iio/light/Kconfig +8 -0
@@ -31,4 +31,12 @@ config TSL2583 Provides support for the TAOS tsl2580, tsl2581 and tsl2583 devices. Access ALS data via iio, sysfs. +config TSL2x7x + tristate "TAOS TSL/TMD2x71 and TSL/TMD2x72 Family of light and proximity sensors" + depends on I2C + help + Support for: tsl2571, tsl2671, tmd2671, tsl2771, tmd2771, tsl2572, tsl2672, + tmd2672, tsl2772, tmd2772 devices. + Provides iio_events and direct access via sysfs. + endmenu
drivers/staging/iio/light/Makefile +1 -0
@@ -5,3 +5,4 @@ obj-$(CONFIG_SENSORS_TSL2563) += tsl2563.o obj-$(CONFIG_SENSORS_ISL29018) += isl29018.o obj-$(CONFIG_TSL2583) += tsl2583.o +obj-$(CONFIG_TSL2x7x) += tsl2x7x_core.o
drivers/staging/iio/light/tsl2x7x_core.c new file +1948 -0
1,948 lines not on this page · raw message
drivers/staging/iio/light/tsl2x7x_core.h new file +75 -0
75 lines not on this page · raw message
--
1.7.4.1
Quoted 1 line · Jon Brenner
TAOS device driver (version 3) for the tsl/tmd 2771 and 2772 device families (inc. all variants).
trivial comments follow.
Review
Quoted 2 lines
+++
b/drivers/staging/iio/light/tsl2x7x_core.c(quoted diff) +0
-0@@ -0,0 +1,1948 @@
[]
drivers/staging/iio/light/tsl2x7x_core.c line 326
Quoted 10 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +10
-0+static int +tsl2x7x_i2c_read (struct i2c_client *client,u8 reg,u8 *val) +{ +int ret; + +/* select register to write */ + ret =i2c_smbus_write_byte (client, (TSL2X7X_CMD_REG | reg)); +if (ret <0 ) { +dev_err (&client->dev,"tsl2x7x_i2c_read failed to write" +" register %x\n" , reg);
Please coalesce formats.
You can also use %s, __func__
dev_err(&client->dev, "%s: failed to write register %x\n", __func__, reg);
drivers/staging/iio/light/tsl2x7x_core.c line 349
Quoted 2 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +2
-0+static int tsl2x7x_get_lux (struct iio_dev *indio_dev) +{
[]
drivers/staging/iio/light/tsl2x7x_core.c line 362
Quoted 2 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +2
-0+if (mutex_trylock (&chip->als_mutex) ==0 ) { +dev_info (&chip->client->dev,"tsl2x7x_get_lux device is busy\n" );
"%s:", __func___
drivers/staging/iio/light/tsl2x7x_core.c line 368
Quoted 1 line
drivers/staging/iio/light/tsl2x7x_core.c new file +1
-0+dev_err (&chip->client->dev,"tsl2x7x_get_lux device is not enabled\n" );
[]
drivers/staging/iio/light/tsl2x7x_core.c line 377
Quoted 2 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +2
-0+dev_err (&chip->client->dev, +"tsl2x7x_get_lux failed to read CMD_REG\n" );
[]
Review line 19
Quoted 2 lines
(quoted diff) +2
-0+ dev_err(&chip->client->dev, + "tsl2x7x_get_lux data not valid yet\n");
[]
drivers/staging/iio/light/tsl2x7x_core.c line 395
Quoted 3 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +3
-0+dev_err (&chip->client->dev, +"tsl2x7x_get_lux failed to read" +" ret: %x\n" , ret);
[]
drivers/staging/iio/light/tsl2x7x_core.c line 410
Quoted 3 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +3
-0+dev_err (&chip->client->dev, +"tsl2x7x_i2c_write_command failed in tsl2x7x_get_lux, err = %d\n" , + ret);
Align arguments please and maybe:
dev_err(&chip->client->dev, "%s: "tsl2x7x_i2c_write_command failed, err = %d\n", __func__, ret);
[]
drivers/staging/iio/light/tsl2x7x_core.c line 443
Quoted 6 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +6
-0+if (p->ratio ==0 ) { + lux =0 ; + }else { + ch0lux = ((ch0 * p->ch0) + + (tsl2X7X_als_gainadj[chip->tsl2x7x_settings.als_gain] >>1 )) + / tsl2X7X_als_gainadj[chip->tsl2x7x_settings.als_gain];
The alignment is pretty hard to read. Maybe DIV_ROUND_UP?
drivers/staging/iio/light/tsl2x7x_core.c line 447
Quoted 3 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +3
-0+ ch1lux = ((ch1 * p->ch1) + + (tsl2X7X_als_gainadj[chip->tsl2x7x_settings.als_gain] >>1 )) + / tsl2X7X_als_gainadj[chip->tsl2x7x_settings.als_gain];
and here.
drivers/staging/iio/light/tsl2x7x_core.c line 541
Quoted 5 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +5
-0+if (!(status &TSL2X7X_STA_PRX_VALID )) { + err_cnt++; +if (err_cnt >CONSECUTIVE_RETRIES ) { +dev_err (&chip->client->dev, +"Consec. retries exceeded\n" );
alignment, etc...
drivers/staging/iio/light/tsl2x7x_core.c line 672
Quoted 1 line
drivers/staging/iio/light/tsl2x7x_core.c new file +1
-0+static int tsl2x7x_chip_on (struct iio_dev *indio_dev)
[]
drivers/staging/iio/light/tsl2x7x_core.c line 688
Quoted 3 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +3
-0+/* Non calculated parameters */ + chip->tsl2x7x_config[TSL2X7X_PRX_TIME ] = + chip->tsl2x7x_settings.prx_time;
maybe a macro or some temporaries forchip->tsl2x7x_config and chip->tsl2x7x_settings?
whatevertypeof chip->tsl2x7x_config *cfg = &chip->tsl2x7x_config; whatevertypeof chip->tsl2x7x_settings *settings = &chip->tsl2x7x_settings; cfg[TSL2X7X_PRX_TIME] = settings->prx_time;
drivers/staging/iio/light/tsl2x7x_core.c line 690
Quoted 2 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +2
-0+ chip->tsl2x7x_config[TSL2X7X_WAIT_TIME ] = + chip->tsl2x7x_settings.wait_time;
cfg[TSL2X7X_WAIT_TIME] = settings->wait_time;
Quoted 10 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +10
-0+ chip->tsl2x7x_config[TSL2X7X_PRX_CONFIG ] = + chip->tsl2x7x_settings.prox_config; + + chip->tsl2x7x_config[TSL2X7X_ALS_MINTHRESHLO ] = + (chip->tsl2x7x_settings.als_thresh_low) &0xFF ; + chip->tsl2x7x_config[TSL2X7X_ALS_MINTHRESHHI ] = + (chip->tsl2x7x_settings.als_thresh_low >>8 ) &0xFF ; + chip->tsl2x7x_config[TSL2X7X_ALS_MAXTHRESHLO ] = + (chip->tsl2x7x_settings.als_thresh_high) &0xFF ; + chip->tsl2x7x_config[TSL2X7X_ALS_MAXTHRESHHI] =
drivers/staging/iio/light/tsl2x7x_core.c line 710
Quoted 10 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +10
-0+ (chip->tsl2x7x_settings.als_thresh_high >>8 ) &0xFF ; + chip->tsl2x7x_config[TSL2X7X_PERSISTENCE ] = + chip->tsl2x7x_settings.als_persistence; + + chip->tsl2x7x_config[TSL2X7X_PRX_COUNT ] = + chip->tsl2x7x_settings.prox_pulse_count; + chip->tsl2x7x_config[TSL2X7X_PRX_MINTHRESHLO ] = + chip->tsl2x7x_settings.prox_thres_low; + chip->tsl2x7x_config[TSL2X7X_PRX_MAXTHRESHLO ] = + chip->tsl2x7x_settings.prox_thres_high;
etc...
drivers/staging/iio/light/tsl2x7x_core.c line 834
Quoted 1 line
drivers/staging/iio/light/tsl2x7x_core.c new file +1
-0+static unsigned long tsl2x7x_isqrt (unsigned long x)
There's int_sqrt in kernel.h
Quoted 7 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +7
-0+* Proximity calibration helper function +* runs through a collection of data samples, +* sets the min, max, mean, and std dev. +*/ +static +void tsl2x7x_prox_calculate (u16 *data,int length,struct prox_stat *statP) +{
drivers/staging/iio/light/tsl2x7x_core.c line 873
Quoted 10 lines
drivers/staging/iio/light/tsl2x7x_core.c new file +10
-0+int i; +int min, max, sum, mean; +unsigned long stddev; +int tmp; + +if (length ==0 ) + length =1 ; + + sum =0 ; + min =0xffff ;
INT_MAX?
drivers/staging/iio/light/tsl2x7x_core.c line 874
Quoted 1 line
drivers/staging/iio/light/tsl2x7x_core.c new file +1
-0+ max =0 ;
INT_MIN?
The rest of the patch is too long, and didn't read more. Maybe later.