TAOS 258x: Device Driver
Subsystems (3)
PATCH 1/1 TAOS 258x: Device Driver
From: Jon Brenner <[email protected]>
Support for TAOS tsl2580/01/03 ALS devices.
Uses sysfs/iio methods.
--- drivers/staging/iio/Documentation/sysfs-bus-iio | 6 + .../staging/iio/Documentation/sysfs-bus-iio-light | 7 + drivers/staging/iio/light/Kconfig | 9 + drivers/staging/iio/light/Makefile | 1 + drivers/staging/iio/light/tsl2583.c | 943 ++++++++++++++++++++ 5 files changed, 966 insertions(+), 0 deletions(-)
drivers/staging/iio/Documentation/sysfs-bus-iio +6 -0
@@ -6,6 +6,12 @@ Description: Corresponds to a grouping of sensor channels. X is the IIO index of the device. +What: /sys/bus/iio/devices/device[n]/power_state +KernelVersion: 2.6.37 +Contact: [email protected] +Description: + This property gets/sets the device power state. + What: /sys/bus/iio/devices/triggerX KernelVersion: 2.6.35 Contact: [email protected]
drivers/staging/iio/Documentation/sysfs-bus-iio-light +7 -0
@@ -62,3 +62,10 @@ Description: sensing mode. This value should be the output from a reading and if expressed in SI units, should include _input. If this value is not in SI units, then it should include _raw. + +What: /sys/bus/iio/devices/device[n]/lux_table +KernelVersion: 2.6.37 +Contact: [email protected] +Description: + This property gets/sets the table of coefficients + used in calculating illuminance in lux.
drivers/staging/iio/light/Kconfig +9 -0
@@ -13,6 +13,15 @@ config SENSORS_TSL2563 This driver can also be built as a module. If so, the module will be called tsl2563. +config SENSORS_TSL2583 + tristate "TAOS TSL2580, TSL2581, and TSL2583 light-to-digital converters" + depends on I2C + help + Y = in kernel. + M = as module. + Provides support for the TAOS tsl2580, tsl2581, and tsl2583 devices. + Access ALS data via iio, sysfs. + config SENSORS_ISL29018 tristate "ISL 29018 light and proximity sensor" depends on I2C
drivers/staging/iio/light/Makefile +1 -0
@@ -3,4 +3,5 @@ # obj-$(CONFIG_SENSORS_TSL2563) += tsl2563.o +obj-$(CONFIG_SENSORS_TSL2583) += tsl2583.o obj-$(CONFIG_SENSORS_ISL29018) += isl29018.o
drivers/staging/iio/light/tsl2583.c new file +943 -0
943 lines not on this page · raw message
--
1.7.0.4
Quoted 4 lines · Jon Brenner
From: Jon Brenner <[email protected]>
Support for TAOS tsl2580/01/03 ALS devices.
Uses sysfs/iio methods.
Hi Jon,
As I pm'd you the other day, please remember to make version of patch clear in title, and include details of what has changed since previous version.
The 'scale' attribute is a problem. I've suggested one possible solution but I'm open to others. It ought to be handled in a generalizable way but isn't currently.
Please document the _target and calibrate attributes in part specific documentation file.
Otherwise, various small points inline.
Jonathan
Quoted 16 lines
Signed-off-by Jon August Brenner <[email protected]>--- drivers/staging/iio/Documentation/sysfs-bus-iio | 6 + .../staging/iio/Documentation/sysfs-bus-iio-light | 7 + drivers/staging/iio/light/Kconfig | 9 + drivers/staging/iio/light/Makefile | 1 + drivers/staging/iio/light/tsl2583.c | 943 ++++++++++++++++++++ 5 files changed, 966 insertions(+), 0 deletions(-)drivers/staging/iio/Documentation/sysfs-bus-iio +0
-0
drivers/staging/iio/Documentation/sysfs-bus-iio Description: · line 13
Quoted 8 lines
drivers/staging/iio/Documentation/sysfs-bus-iio +5
-0@@ -6,6 +6,12 @@ Description: Corresponds to a grouping of sensor channels. X is the IIO index of the device. +What: /sys/bus/iio/devices/device[n]/power_state +KernelVersion: 2.6.37 +Contact: [email protected] +Description: + This property gets/sets the device power state.
Where the options are?
There is some on going debate about how best to handle explicit userspace power control. For now I'll let this go in, but we will need to clean it up in the long run. Basically this is an issue that effects several subsystems and their ought to be one coherent solution.
Quoted 9 lines
drivers/staging/iio/Documentation/sysfs-bus-iio +1
-0+ What: /sys/bus/iio/devices/triggerX KernelVersion: 2.6.35 Contact: [email protected]drivers/staging/iio/Documentation/sysfs-bus-iio-light +0
-0
drivers/staging/iio/Documentation/sysfs-bus-iio-light Description: · line 71
Quoted 10 lines
drivers/staging/iio/Documentation/sysfs-bus-iio-light +7
-0@@ -62,3 +62,10 @@ Description: sensing mode. This value should be the output from a reading and if expressed in SI units, should include _input. If this value is not in SI units, then it should include _raw. + +What: /sys/bus/iio/devices/device[n]/lux_table +KernelVersion: 2.6.37 +Contact: [email protected] +Description: + This property gets/sets the table of coefficients + used in calculating illuminance in lux.
This one probably wants to be in a separate file as we only have one user so far and it's not as though a device agnostic userspace program is going to know what to do with it. Put it in syfsf-bus-iio-light-tsl2583 please.
drivers/staging/iio/light/Kconfig config SENSORS_TSL2563 · line 15
Quoted 8 lines
drivers/staging/iio/light/Kconfig +0
-0@@ -13,6 +13,15 @@ config SENSORS_TSL2563 This driver can also be built as a module. If so, the module will be called tsl2563.
ouch, how the heck did that SENSORS prefix creep into this file. That's the convention for hwmon, not IIO. Guess I wasn't keeping a close eye on this. Please drop the prefix. We may well introduce an IIO one shortly as part of the move out of staging, but for now no prefix is the norm.
Quoted 48 lines
drivers/staging/iio/light/Kconfig +9
-0+config SENSORS_TSL2583 + tristate "TAOS TSL2580, TSL2581, and TSL2583 light-to-digital converters" + depends on I2C + help + Y = in kernel. + M = as module. + Provides support for the TAOS tsl2580, tsl2581, and tsl2583 devices. + Access ALS data via iio, sysfs. + config SENSORS_ISL29018 tristate "ISL 29018 light and proximity sensor" depends on I2Cdrivers/staging/iio/light/Makefile +1
-0@@ -3,4 +3,5 @@ # obj-$(CONFIG_SENSORS_TSL2563) += tsl2563.o +obj-$(CONFIG_SENSORS_TSL2583) += tsl2583.o obj-$(CONFIG_SENSORS_ISL29018) += isl29018.odrivers/staging/iio/light/tsl2583.c new file +20
-0@@ -0,0 +1,943 @@ +/* +* Device driver for monitoring ambient light intensity (lux) +* within the TAOS tsl258x family of devices (tsl2580, tsl2581). +* +* Copyright (c) 2011, TAOS Corporation. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* 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 Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/
drivers/staging/iio/light/tsl2583.c line 30
Quoted 10 lines
drivers/staging/iio/light/tsl2583.c new file +10
-0+ +#include <linux/kernel.h> +#include <linux/i2c.h> +#include <linux/errno.h> +#include <linux/delay.h> +#include <linux/string.h> +#include <linux/mutex.h> +#include "../iio.h" + +
Please prefix this with TSL258X to avoid possible namespace clashes in future.
Quoted 23 lines
drivers/staging/iio/light/tsl2583.c new file +23
-0+#define MAX_DEVICE_REGS 32 + +/* Triton register offsets */ +#define TAOS_REG_MAX 8 + +/* Device Registers and Masks */ +#define TSL258X_CNTRL 0x00 +#define TSL258X_ALS_TIME 0X01 +#define TSL258X_INTERRUPT 0x02 +#define TSL258X_GAIN 0x07 +#define TSL258X_REVID 0x11 +#define TSL258X_CHIPID 0x12 +#define TSL258X_ALS_CHAN0LO 0x14 +#define TSL258X_ALS_CHAN0HI 0x15 +#define TSL258X_ALS_CHAN1LO 0x16 +#define TSL258X_ALS_CHAN1HI 0x17 +#define TSL258X_TMR_LO 0x18 +#define TSL258X_TMR_HI 0x19 + +/* tsl2583 cmd reg masks */ +#define TSL258X_CMD_REG 0x80 +#define TSL258X_CMD_SPL_FN 0x60 +#define TSL258X_CMD_ALS_INT_CLR 0X01
drivers/staging/iio/light/tsl2583.c line 63
Quoted 10 lines
drivers/staging/iio/light/tsl2583.c new file +10
-0+ +/* tsl2583 cntrl reg masks */ +#define TSL258X_CNTL_ADC_ENBL 0x02 +#define TSL258X_CNTL_PWR_ON 0x01 + +/* tsl2583 status reg masks */ +#define TSL258X_STA_ADC_VALID 0x01 +#define TSL258X_STA_ADC_INTR 0x10 + +/* Lux calculation constants */
Again please prefix.
drivers/staging/iio/light/tsl2583.c line 65
Quoted 2 lines
drivers/staging/iio/light/tsl2583.c new file +2
-0+#define LUX_CALC_OVER_FLOW 65535 +
Ideally part names in these. You might have another TAOS driver where these are defined differently which will make life confusing!
Quoted 12 lines
drivers/staging/iio/light/tsl2583.c new file +12
-0+enum { +TAOS_CHIP_UNKNOWN =0 ,TAOS_CHIP_WORKING =1 ,TAOS_CHIP_SLEEP =2 +}TAOS_CHIP_WORKING_STATUS ; + +/* Per-device data */ +struct taos_als_info { +u16 als_ch0; +u16 als_ch1; +u16 lux; +}; + +struct taos_settings {
drivers/staging/iio/light/tsl2583.c line 87
Quoted 10 lines
drivers/staging/iio/light/tsl2583.c new file +10
-0+int als_time; +int als_gain; +int als_gain_trim; +int als_cal_target; +}; + +struct tsl2583_chip { +struct mutex als_mutex; +struct i2c_client *client; +struct iio_dev *iio_dev;
unused so remove
drivers/staging/iio/light/tsl2583.c line 88
Quoted 1 line
drivers/staging/iio/light/tsl2583.c new file +1
-0+struct delayed_work update_lux;
unused.
drivers/staging/iio/light/tsl2583.c line 89
Quoted 1 line
drivers/staging/iio/light/tsl2583.c new file +1
-0+unsigned int addr;
unused.
drivers/staging/iio/light/tsl2583.c line 90
Quoted 1 line
drivers/staging/iio/light/tsl2583.c new file +1
-0+char taos_id;
I think this is set to 0 then never checked anywhere? Hence remove
drivers/staging/iio/light/tsl2583.c line 91
Quoted 1 line
drivers/staging/iio/light/tsl2583.c new file +1
-0+char valid;
never used
drivers/staging/iio/light/tsl2583.c line 103
Quoted 12 lines
drivers/staging/iio/light/tsl2583.c new file +12
-0+unsigned long last_updated; +struct taos_als_info als_cur_info; +struct taos_settings taos_settings; +int als_time_scale; +int als_saturation; +int taos_chip_status; +u8 taos_config[8 ]; +}; + +static int taos_i2c_read (struct i2c_client *client,u8 reg,u8 *val, +unsigned int len); +static int taos_i2c_write_command (struct i2c_client *client,u8 reg);
Don't need these definitions.
Quoted 16 lines
drivers/staging/iio/light/tsl2583.c new file +16
-0+ +/* +* Initial values for device - this values can/will be changed by driver. +* and applications as needed. +* These values are dynamic. +*/ +static const u8 taos_config[8 ] = { +0x00 ,0xee ,0x00 ,0x03 ,0x00 ,0xFF ,0xFF ,0x00 +};/* cntrl atime intC Athl0 Athl1 Athh0 Athh1 gain */ + +struct taos_lux { +unsigned int ratio; +unsigned int ch0; +unsigned int ch1; +}; +
drivers/staging/iio/light/tsl2583.c line 129
Quoted 10 lines
drivers/staging/iio/light/tsl2583.c new file +10
-0+/* This structure is intentionally large to accommodate updates via sysfs. */ +/* Sized to 11 = max 10 segments + 1 termination segment */ +/* Assumption is is one and only one type of glass used */ +struct taos_lux taos_device_lux[11 ] = { + {9830 ,8520 ,15729 }, + {12452 ,10807 ,23344 }, + {14746 ,6383 ,11705 }, + {17695 ,4063 ,6554 }, +}; +
I don't think this is used?
Quoted 9 lines
drivers/staging/iio/light/tsl2583.c new file +9
-0+struct taos_lux taos_lux; + +struct gainadj { +s16 ch0; +s16 ch1; +}; + +/* Index = (0 - 3) Used to validate the gain selection index */ +static const struct gainadj gainadj[] = {
drivers/staging/iio/light/tsl2583.c line 148
Quoted 10 lines
drivers/staging/iio/light/tsl2583.c new file +10
-0+ { 1, 1 }, + { 8, 8 }, + { 16, 16 }, + { 107, 115 } +}; + +/* +* Provides initial operational parameter defaults. +* These defaults may be changed through the device's sysfs files. +*/
How about pasing in taos_settings and making all of this func a bit more readable?
Quoted 40 lines
drivers/staging/iio/light/tsl2583.c new file +40
-0+static void taos_defaults (struct tsl2583_chip *chip) +{ +/* Operational parameters */ + chip->taos_settings.als_time =450 ; +/* must be a multiple of 50mS */ + chip->taos_settings.als_gain =2 ; +/* this is actually an index into the gain table */ +/* assume clear glass as default */ + chip->taos_settings.als_gain_trim =1000 ; +/* default gain trim to account for aperture effects */ + chip->taos_settings.als_cal_target =130 ; +/* Known external ALS reading used for calibration */ +} + +/* +* Read a number of bytes starting at register (reg) location. +* Return 0, or i2c_smbus_write_byte ERROR code. +*/ +static int +taos_i2c_read (struct i2c_client *client,u8 reg,u8 *val,unsigned int len) +{ +int ret; +int i; + +for (i =0 ; i < len; i++) { +/* select register to write */ + ret =i2c_smbus_write_byte (client, (TSL258X_CMD_REG | reg)); +if (ret <0 ) { +dev_err (&client->dev,"taos_i2c_read failed to write" +" register %x\n" , reg); +return ret; + } +/* read the data */ + *val =i2c_smbus_read_byte (client); + val++; + reg++; + } +return 0 ; +} +
drivers/staging/iio/light/tsl2583.c line 198
Quoted 10 lines
drivers/staging/iio/light/tsl2583.c new file +10
-0+/* +* This function is used to send a command to device command/control register +* All bytes sent using this command have their MSBit set - it's a command! +* Return 0, or i2c_smbus_write_byte error code. +*/ +static int taos_i2c_write_command (struct i2c_client *client,u8 reg) +{ +int ret; + +/* write the data */
Why update reg? reg | TSL258X_CMD_REG.
Also this is only used once in the code. I'd just roll this line in directly there and get rid of this wrapper function.
drivers/staging/iio/light/tsl2583.c line 200
Quoted 2 lines
drivers/staging/iio/light/tsl2583.c new file +2
-0+ ret =i2c_smbus_write_byte (client, (reg |=TSL258X_CMD_REG )); +if (ret <0 ) {
The error is pretty well reported by the one caller anyway
drivers/staging/iio/light/tsl2583.c line 203
Quoted 3 lines
drivers/staging/iio/light/tsl2583.c new file +3
-0+dev_err (&client->dev,"FAILED: i2c_smbus_write_byte\n" ); +return ret; + }
Could just return ret as you check this for <0 anyway.
Quoted 64 lines
drivers/staging/iio/light/tsl2583.c new file +64
-0+return 0 ; +} + +/* +* Reads and calculates current lux value. +* The raw ch0 and ch1 values of the ambient light sensed in the last +* integration cycle are read from the device. +* Time scale factor array values are adjusted based on the integration time. +* The raw values are multiplied by a scale factor, and device gain is obtained +* using gain index. Limit checks are done next, then the ratio of a multiple +* of ch1 value, to the ch0 value, is calculated. The array taos_device_lux[] +* declared above is then scanned to find the first ratio value that is just +* above the ratio we just calculated. The ch0 and ch1 multiplier constants in +* the array are then used along with the time scale factor array values, to +* calculate the lux. +*/ +static int taos_get_lux (struct i2c_client *client) +{ +u32 ch0, ch1;/* separated ch0/ch1 data from device */ +u32 lux;/* raw lux calculated from device data */ +u32 ratio; +u8 buf[5 ]; +struct taos_lux *p; +struct tsl2583_chip *chip =i2c_get_clientdata (client); +int i, ret; +u32 ch0lux =0 ; +u32 ch1lux =0 ; + +if (mutex_trylock (&chip->als_mutex) ==0 ) { +dev_info (&client->dev,"taos_get_lux device is busy\n" ); +return chip->als_cur_info.lux;/* busy, so return LAST VALUE */ + } + +if (chip->taos_chip_status !=TAOS_CHIP_WORKING ) { +/* device is not enabled */ +dev_err (&client->dev,"taos_get_lux device is not enabled\n" ); + ret = -EBUSY ; + goto out_unlock; + } + + ret =taos_i2c_read (client, (TSL258X_CMD_REG ), &buf[0 ],1 ); +if (ret <0 ) { +dev_err (&client->dev,"taos_get_lux failed to read CMD_REG\n" ); + goto out_unlock; + } +/* is data new & valid */ +if (!(buf[0 ] &TSL258X_STA_ADC_INTR )) { +dev_err (&client->dev,"taos_get_lux data not valid\n" ); + ret = chip->als_cur_info.lux;/* return LAST VALUE */ + goto out_unlock; + } + +for (i =0 ; i <4 ; i++) { +int reg =TSL258X_CMD_REG | (TSL258X_ALS_CHAN0LO + i); + ret =taos_i2c_read (client, reg, &buf[i],1 ); +if (ret <0 ) { +dev_err (&client->dev,"taos_get_lux failed to read" +" register %x\n" , reg); + goto out_unlock; + } + } + +/* clear status, really interrupt status (interrupts are off), but +* we use the bit anyway */
drivers/staging/iio/light/tsl2583.c line 277
Quoted 10 lines
drivers/staging/iio/light/tsl2583.c new file +10
-0+ ret =taos_i2c_write_command (client, +TSL258X_CMD_REG |TSL258X_CMD_SPL_FN |TSL258X_CMD_ALS_INT_CLR ); +if (ret <0 ) { +dev_err (&client->dev, +"taos_i2c_write_command failed in taos_get_lux, err = %d\n" , + ret); + goto out_unlock;/* have no data, so return failure */ + } + +/* extract ALS/lux data */
These appear to be endianness convesions. ch0 = le16tocpu(&buf[0])? That way they compile out to a copy if we happen to be on a little endian machine. Also these seem to be explicitly 16 bits, so u16 makes more sense.
drivers/staging/iio/light/tsl2583.c line 284
Quoted 7 lines
drivers/staging/iio/light/tsl2583.c new file +7
-0+ ch0 = (buf[1 ] <<8 ) | buf[0 ]; + ch1 = (buf[3 ] <<8 ) | 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))
would be easier to read if you set ret to lux max here an avoid jumping into the if statement below.
drivers/staging/iio/light/tsl2583.c line 294
Quoted 10 lines
drivers/staging/iio/light/tsl2583.c new file +10
-0+ goto return_max; + +if (ch0 ==0 ) { +/* have no data, so return LAST VALUE */ + ret = chip->als_cur_info.lux =0 ; + goto out_unlock; + } +/* calculate ratio */ + ratio = (ch1 <<15 ) / ch0; +/* convert to unscaled lux using the pointer to the table */
&taos_device_lux[0] perhaps?
Quoted 75 lines
drivers/staging/iio/light/tsl2583.c new file +75
-0+for (p = (struct taos_lux *) taos_device_lux; + p->ratio !=0 && p->ratio < ratio; p++) + ; + +if (p->ratio ==0 ) { + lux =0 ; + }else { + ch0lux = ((ch0 * p->ch0) + + (gainadj[chip->taos_settings.als_gain].ch0 >>1 )) + / gainadj[chip->taos_settings.als_gain].ch0; + ch1lux = ((ch1 * p->ch1) + + (gainadj[chip->taos_settings.als_gain].ch1 >>1 )) + / gainadj[chip->taos_settings.als_gain].ch1; + lux = ch0lux - ch1lux; + } + +/* note: lux is 31 bit max at this point */ +if (ch1lux > ch0lux) { +dev_dbg (&client->dev,"No Data - Return last value\n" ); + ret = chip->als_cur_info.lux =0 ; + goto out_unlock; + } + +/* adjust for active time scale */ +if (chip->als_time_scale ==0 ) + lux =0 ; +else + lux = (lux + (chip->als_time_scale >>1 )) / + chip->als_time_scale; + +/* adjust for active gain scale */ + lux >>=13 ;/* tables have factor of 8192 builtin for accuracy */ + lux = (lux * chip->taos_settings.als_gain_trim +500 ) /1000 ; +if (lux >LUX_CALC_OVER_FLOW ) {/* check for overflow */ +return_max: + lux =LUX_CALC_OVER_FLOW ; + } + +/* Update the structure with the latest VALID lux. */ + chip->als_cur_info.lux = lux; + ret = lux; + +out_unlock: +mutex_unlock (&chip->als_mutex); +return ret; +} + +/* +* Obtain single reading and calculate the als_gain_trim (later used +* to derive actual lux). +* Return updated gain_trim value. +*/ +int taos_als_calibrate (struct i2c_client *client) +{ +struct tsl2583_chip *chip =i2c_get_clientdata (client); +u8 reg_val; +unsigned int gain_trim_val; +int ret; +int lux_val; + + ret =i2c_smbus_write_byte (client, (TSL258X_CMD_REG |TSL258X_CNTRL )); +if (ret <0 ) { +dev_err (&client->dev, +"taos_als_calibrate failed to reach the CNTRL register, ret=%d\n" , + ret); +return ret; + } + + reg_val =i2c_smbus_read_byte (client); +if ((reg_val & (TSL258X_CNTL_ADC_ENBL |TSL258X_CNTL_PWR_ON )) + != (TSL258X_CNTL_ADC_ENBL |TSL258X_CNTL_PWR_ON )) { +dev_err (&client->dev, +"taos_als_calibrate failed: device not powered on with ADC enabled\n" ); +return -ENODATA ; + }
drivers/staging/iio/light/tsl2583.c line 379
Quoted 10 lines
drivers/staging/iio/light/tsl2583.c new file +10
-0+ + ret =i2c_smbus_write_byte (client, (TSL258X_CMD_REG |TSL258X_CNTRL )); +if (ret <0 ) { +dev_err (&client->dev, +"taos_als_calibrate failed to reach the STATUS register, ret=%d\n" , + ret); +return ret; + } + reg_val =i2c_smbus_read_byte (client); +
what if it's an error? Then we want to return that rather than -ENODATA.
drivers/staging/iio/light/tsl2583.c line 392
Quoted 13 lines
drivers/staging/iio/light/tsl2583.c new file +13
-0+if ((reg_val &TSL258X_STA_ADC_VALID ) !=TSL258X_STA_ADC_VALID ) { +dev_err (&client->dev, +"taos_als_calibrate failed: STATUS - ADC not valid.\n" ); +return -ENODATA ; + } + lux_val =taos_get_lux (client); +if (lux_val <0 ) { +dev_err (&client->dev,"taos_als_calibrate failed to get lux\n" ); +return lux_val; + } + gain_trim_val = (unsigned int ) (((chip->taos_settings.als_cal_target) + * chip->taos_settings.als_gain_trim) / lux_val); +
If it is worth printing this to the log, we don't care about where it is stored just what it is. Otherwise, shouldn't be here.
Quoted 25 lines
drivers/staging/iio/light/tsl2583.c new file +25
-0+dev_info (&client->dev,"taos_settings.als_cal_target = %d\n" +"taos_settings.als_gain_trim = %d\nlux_val = %d\n" , + chip->taos_settings.als_cal_target, + chip->taos_settings.als_gain_trim, + lux_val); + +if ((gain_trim_val <250 ) || (gain_trim_val >4000 )) { +dev_err (&client->dev, +"taos_als_calibrate failed: trim_val of %d is out of range\n" , + gain_trim_val); +return -ENODATA ; + } + chip->taos_settings.als_gain_trim = (int ) gain_trim_val; + +return (int ) gain_trim_val; +} + +/* +* Turn the device on. +* Configuration must be set before calling this function. +*/ +static int taos_chip_on (struct i2c_client *client) +{ +int i; +int ret =0 ;
drivers/staging/iio/light/tsl2583.c line 427
Quoted 10 lines
drivers/staging/iio/light/tsl2583.c new file +10
-0+u8 *uP; +u8 utmp; +int als_count; +int als_time; +struct tsl2583_chip *chip =i2c_get_clientdata (client); + +/* and make sure we're not already on */ +if (chip->taos_chip_status ==TAOS_CHIP_WORKING ) { +/* if forcing a register update - turn off, then on */ +dev_info (&client->dev,"device is already enabled\n" );
-EINVAL perhaps?
Quoted 9 lines
drivers/staging/iio/light/tsl2583.c new file +9
-0+return -1 ; + } + +/* determine als integration regster */ + als_count = (chip->taos_settings.als_time *100 +135 ) /270 ; +if (als_count ==0 ) + als_count =1 ;/* ensure at least one cycle */ + +/* convert back to time (encompasses overrides) */
drivers/staging/iio/light/tsl2583.c line 446
Quoted 10 lines
drivers/staging/iio/light/tsl2583.c new file +10
-0+ als_time = (als_count *27 +5 ) /10 ; + chip->taos_config[TSL258X_ALS_TIME ] =256 - als_count; + +/* Set the gain based on taos_settings struct */ + chip->taos_config[TSL258X_GAIN ] = chip->taos_settings.als_gain; + +/* set chip struct re scaling and saturation */ + chip->als_saturation = als_count *922 ;/* 90% of full scale */ + chip->als_time_scale = (als_time +25 ) /50 ; +
We still don't know what SKATE is... Any publically available terms possible?
Quoted 12 lines
drivers/staging/iio/light/tsl2583.c new file +12
-0+/* SKATE Specific power-on / adc enable sequence +* Power on the device 1st. */ + utmp =TSL258X_CNTL_PWR_ON ; + ret =i2c_smbus_write_byte_data (client,TSL258X_CMD_REG |TSL258X_CNTRL , + utmp); +if (ret <0 ) { +dev_err (&client->dev,"taos_chip_on failed on CNTRL reg.\n" ); +return -1 ; + } + +/* Use the following shadow copy for our delay before enabling ADC. +* Write all the registers. */
drivers/staging/iio/light/tsl2583.c line 468
Quoted 10 lines
drivers/staging/iio/light/tsl2583.c new file +10
-0+for (i =0 , uP = chip->taos_config; i <TAOS_REG_MAX ; i++) { + ret =i2c_smbus_write_byte_data (client,TSL258X_CMD_REG + i, + *uP++); +if (ret <0 ) { +dev_err (&client->dev, +"taos_chip_on failed on reg %d.\n" , i); +return -1 ; + } + } +
If not time critical lest make that a sleep.
drivers/staging/iio/light/tsl2583.c line 479
Quoted 11 lines
drivers/staging/iio/light/tsl2583.c new file +11
-0+mdelay (3 ); +/* NOW enable the ADC +* initialize the desired mode of operation */ + utmp =TSL258X_CNTL_PWR_ON |TSL258X_CNTL_ADC_ENBL ; + ret =i2c_smbus_write_byte_data (client,TSL258X_CMD_REG |TSL258X_CNTRL , + utmp); +if (ret <0 ) { +dev_err (&client->dev,"taos_chip_on failed on 2nd CTRL reg.\n" ); +return -1 ; + } + chip->taos_chip_status =TAOS_CHIP_WORKING ;
conventionally blank line here.
drivers/staging/iio/light/tsl2583.c line 490
Quoted 11 lines
drivers/staging/iio/light/tsl2583.c new file +11
-0+return ret; +} + +/* Turn the device OFF. */ +static int taos_chip_off (struct i2c_client *client) +{ +struct tsl2583_chip *chip =i2c_get_clientdata (client); +int ret; +u8 utmp; + +/* turn device off */
Kind of obvious comment in this function ;) Please remove.
drivers/staging/iio/light/tsl2583.c line 492
Quoted 2 lines
drivers/staging/iio/light/tsl2583.c new file +2
-0+ chip->taos_chip_status =TAOS_CHIP_SLEEP ; + utmp =0x00 ;
Why not just put this value into the function call and get rid of utmp as a variable?
Quoted 24 lines
drivers/staging/iio/light/tsl2583.c new file +24
-0+ ret =i2c_smbus_write_byte_data (client,TSL258X_CMD_REG |TSL258X_CNTRL , + utmp); +return ret; +} + +/* Sysfs Interface Functions */ +static ssize_t taos_device_id (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct tsl2583_chip *chip = indio_dev->dev_data; + +return sprintf (buf,"%s\n" , chip->client->name); +} + +static ssize_t taos_power_state_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct tsl2583_chip *chip = indio_dev->dev_data; + +return sprintf (buf,"%d\n" , chip->taos_chip_status); +} +
drivers/staging/iio/light/tsl2583.c line 526
Quoted 10 lines
drivers/staging/iio/light/tsl2583.c new file +10
-0+static ssize_t taos_power_state_store (struct device *dev, +struct device_attribute *attr,const char *buf,size_t len) +{ +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct tsl2583_chip *chip = indio_dev->dev_data; +unsigned long value; + +if (strict_strtoul (buf,0 , &value)) +return -EINVAL ; +
(wishful thought of the day)
One day someone will write a nice standard 'boolean' test function that everyone will agree on... This works for me though ;)
Quoted 16 lines
drivers/staging/iio/light/tsl2583.c new file +16
-0+if (value ==0 ) +taos_chip_off (chip->client); +else +taos_chip_on (chip->client); + +return len; +} + +static ssize_t taos_gain_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct tsl2583_chip *chip = indio_dev->dev_data; + +return sprintf (buf,"%d\n" , chip->taos_settings.als_gain); +}
drivers/staging/iio/light/tsl2583.c line 552
Quoted 10 lines
drivers/staging/iio/light/tsl2583.c new file +10
-0+ +static ssize_t taos_gain_store (struct device *dev, +struct device_attribute *attr,const char *buf,size_t len) +{ +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct tsl2583_chip *chip = indio_dev->dev_data; +unsigned long value; +if (strict_strtoul (buf,0 , &value)) +return -EINVAL ; +
I still wonder if there isn't a way of avoiding this index issue. It's horrible and really feels like something we ought to able to handle reasonably well...
Quoted 5 lines
drivers/staging/iio/light/tsl2583.c new file +5
-0+if (value >3 ) { +dev_err (dev,"Invalid Gain Index: Enter 0-3\n" ); +return -1 ; + }else { + chip->taos_settings.als_gain = value;
drivers/staging/iio/light/tsl2583.c line 567
Quoted 10 lines
drivers/staging/iio/light/tsl2583.c new file +10
-0+ } +return len; +} + +static ssize_t taos_gain_available_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +return sprintf (buf,"%s\n" ,"0 1 2 3" ); +} +
Just to confirm, is this a frequency in Hz? If it is can we renaming it to taos_als_frequency_show to avoid confusing me?
Quoted 179 lines
drivers/staging/iio/light/tsl2583.c new file +178
-0+static ssize_t taos_als_time_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct tsl2583_chip *chip = indio_dev->dev_data; + +return sprintf (buf,"%d\n" , chip->taos_settings.als_time); +} + +static ssize_t taos_als_time_store (struct device *dev, +struct device_attribute *attr,const char *buf,size_t len) +{ +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct tsl2583_chip *chip = indio_dev->dev_data; +unsigned long value; + +if (strict_strtoul (buf,0 , &value)) +return -EINVAL ; + +if ((value <50 ) || (value >650 )) +return -EINVAL ; + +if (value %50 ) +return -EINVAL ; + + chip->taos_settings.als_time = value; + +return len; +} + +static ssize_t taos_als_time_available_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +return sprintf (buf,"%s\n" ,"50 100 150 200 250 300 350 400 450 500 550 600 650" ); +} + +static ssize_t taos_als_trim_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct tsl2583_chip *chip = indio_dev->dev_data; + +return sprintf (buf,"%d\n" , chip->taos_settings.als_gain_trim); +} + +static ssize_t taos_als_trim_store (struct device *dev, +struct device_attribute *attr,const char *buf,size_t len) +{ +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct tsl2583_chip *chip = indio_dev->dev_data; +unsigned long value; + +if (strict_strtoul (buf,0 , &value)) +return -EINVAL ; + +if (value) + chip->taos_settings.als_gain_trim = value; + +return len; +} + +static ssize_t taos_als_cal_target_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct tsl2583_chip *chip = indio_dev->dev_data; + +return sprintf (buf,"%d\n" , chip->taos_settings.als_cal_target); +} + +static ssize_t taos_als_cal_target_store (struct device *dev, +struct device_attribute *attr,const char *buf,size_t len) +{ +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct tsl2583_chip *chip = indio_dev->dev_data; +unsigned long value; + +if (strict_strtoul (buf,0 , &value)) +return -EINVAL ; + +if (value) + chip->taos_settings.als_cal_target = value; + +return len; +} + +static ssize_t taos_lux_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct tsl2583_chip *chip = indio_dev->dev_data; +int lux; + + lux =taos_get_lux (chip->client); + +return sprintf (buf,"%d\n" , lux); +} + +static ssize_t taos_do_calibrate (struct device *dev, +struct device_attribute *attr,const char *buf,size_t len) +{ +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct tsl2583_chip *chip = indio_dev->dev_data; +unsigned long value; + +if (strict_strtoul (buf,0 , &value)) +return -EINVAL ; + +if (value ==1 ) +taos_als_calibrate (chip->client); + +return len; +} + +static ssize_t taos_luxtable_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +int i; +int offset =0 ; + +for (i =0 ; i <ARRAY_SIZE (taos_device_lux); i++) { + offset +=sprintf (buf + offset,"%d,%d,%d," , + taos_device_lux[i].ratio, + taos_device_lux[i].ch0, + taos_device_lux[i].ch1); +if (taos_device_lux[i].ratio ==0 ) { +/* We just printed the first "0" entry. +* Now get rid of the extra "," and break. */ + offset--; +break ; + } + } + + offset +=sprintf (buf + offset,"\n" ); +return offset; +} + +static ssize_t taos_luxtable_store (struct device *dev, +struct device_attribute *attr,const char *buf,size_t len) +{ +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct tsl2583_chip *chip = indio_dev->dev_data; +int value[ARRAY_SIZE (taos_device_lux)]; +int n; + +get_options (buf,ARRAY_SIZE (value), value); + +/* We now have an array of ints starting at value[1], and +* enumerated by value[0]. +* We expect each group of three ints is one table entry, +* and the last table entry is all 0. +*/ + n = value[0 ]; +if ((n %3 ) || n <6 || n > (ARRAY_SIZE (taos_device_lux) -3 )) { +dev_info (dev,"LUX TABLE INPUT ERROR 1 Value[0]=%d\n" , n); +return -EINVAL ; + } +if ((value[(n -2 )] | value[(n -1 )] | value[n]) !=0 ) { +dev_info (dev,"LUX TABLE INPUT ERROR 2 Value[0]=%d\n" , n); +return -EINVAL ; + } + +if (chip->taos_chip_status ==TAOS_CHIP_WORKING ) +taos_chip_off (chip->client); + +/* Zero out the table */ +memset (taos_device_lux,0 ,sizeof (taos_device_lux)); +memcpy (taos_device_lux, &value[1 ], (value[0 ] *4 )); + +taos_chip_on (chip->client); + +return len; +} + +static DEVICE_ATTR(name, S_IRUGO, taos_device_id, NULL); +static DEVICE_ATTR(power_state, S_IRUGO | S_IWUSR, + taos_power_state_show, taos_power_state_store); +
drivers/staging/iio/light/tsl2583.c line 755
Quoted 10 lines
drivers/staging/iio/light/tsl2583.c new file +10
-0+static DEVICE_ATTR(illuminance0_calibscale, S_IRUGO | S_IWUSR, + taos_gain_show, taos_gain_store); +static DEVICE_ATTR(illuminance0_calibscale_available, S_IRUGO, + taos_gain_available_show, NULL); + +static DEVICE_ATTR(sampling_frequency, S_IRUGO | S_IWUSR, + taos_als_time_show, taos_als_time_store); +static DEVICE_ATTR(sampling_frequency_available, S_IRUGO, + taos_als_time_available_show, NULL); +
scale as a stand alone attribute isn't defined. Please document this. Looking at what you do with it, it's another factor effecting the overal gain on the reading that reaches userspace. Ideally you'd roll this into your calibscale parameter, but I can see that would get complex to manage. Will have a think about this. In devices with a simple conversion function (adc's etc) we handle this by leaving this software value be applied by userspace (and output it as in_scale). The issue here that as far as userspace is concerned both of your scales have been applied before it sees the data and at different more or less random looking points in the calculation.
Actually, looking at the calculation you could output illuminance0_raw and let userspace apply a multiplier based on your trim value and offset +0.5? If you want to hold trim in driver then just implement read and write to
illuminance0_scale
and have read onlyilluminance0_offset (rather tediously for this device, offset is applied before scale, so you'll need to divide 0.5 by whatever your trim is).
We'll have to do pin down how to do this before moving out of staging so best to get it right now.
drivers/staging/iio/light/tsl2583.c line 760
Quoted 5 lines
drivers/staging/iio/light/tsl2583.c new file +5
-0+static DEVICE_ATTR(scale, S_IRUGO | S_IWUSR, + taos_als_trim_show, taos_als_trim_store); + +static DEVICE_ATTR(illuminance0_target, S_IRUGO | S_IWUSR, + taos_als_cal_target_show, taos_als_cal_target_store);
This needs documenting. Also if it is calculated units (e.g. lux) needs to be illuminance0_input_target to make that explicit.
drivers/staging/iio/light/tsl2583.c line 763
Quoted 3 lines
drivers/staging/iio/light/tsl2583.c new file +3
-0+ +static DEVICE_ATTR(illuminance0_input, S_IRUGO, taos_lux_show, NULL); +static DEVICE_ATTR(calibrate, S_IWUSR, NULL, taos_do_calibrate);
calibrate needs documentation.
Quoted 15 lines
drivers/staging/iio/light/tsl2583.c new file +15
-0+static DEVICE_ATTR(lux_table, S_IRUGO | S_IWUSR, + taos_luxtable_show, taos_luxtable_store); + +static struct attribute *sysfs_attrs_ctrl[] = { + &dev_attr_name.attr, + &dev_attr_power_state.attr, + &dev_attr_illuminance0_calibscale.attr, + &dev_attr_illuminance0_calibscale_available.attr, + &dev_attr_sampling_frequency.attr, + &dev_attr_sampling_frequency_available.attr, + &dev_attr_scale.attr, + &dev_attr_illuminance0_target.attr, + &dev_attr_illuminance0_input.attr, + &dev_attr_calibrate.attr, + &dev_attr_lux_table.attr,
drivers/staging/iio/light/tsl2583.c line 788
Quoted 10 lines
drivers/staging/iio/light/tsl2583.c new file +10
-0+ NULL +}; + +static struct attribute_group tsl2583_attribute_group = { + .attrs = sysfs_attrs_ctrl, +}; + +/* Use the default register values to identify the Taos device */ +static int taos_skate_device (unsigned char *bufp) +{
return ((bufp[TSL258X_CHIPID] & 0xf0) == 0x90);
Quoted 20 lines
drivers/staging/iio/light/tsl2583.c new file +20
-0+if (((bufp[TSL258X_CHIPID ] &0xf0 ) ==0x90 )) +/* tsl2583 */ +return 1 ; +/* else unknown */ +return 0 ; +} + +/* +* Client probe function - When a valid device is found, the driver's device +* data structure is updated, and initialization completes successfully. +*/ +static int __devinit taos_probe (struct i2c_client *clientp, +const struct i2c_device_id *idp) +{ +int i, ret =0 ; +unsigned char buf[MAX_DEVICE_REGS ]; +static struct tsl2583_chip *chip; + +if (!i2c_check_functionality (clientp->adapter, +I2C_FUNC_SMBUS_BYTE_DATA )) {
drivers/staging/iio/light/tsl2583.c line 818
Quoted 10 lines
drivers/staging/iio/light/tsl2583.c new file +10
-0+dev_err (&clientp->dev, +"taos_probe() - i2c smbus byte data " +"functions unsupported\n" ); +return -EOPNOTSUPP ; + } +if (!i2c_check_functionality (clientp->adapter, +I2C_FUNC_SMBUS_WORD_DATA )) { +dev_warn (&clientp->dev, +"taos_probe() - i2c smbus word data " +"functions unsupported\n" );
Why do you care? I'm not seeing them being used anyway.
drivers/staging/iio/light/tsl2583.c line 824
Quoted 6 lines
drivers/staging/iio/light/tsl2583.c new file +6
-0+ } +if (!i2c_check_functionality (clientp->adapter, +I2C_FUNC_SMBUS_BLOCK_DATA )) { +dev_err (&clientp->dev, +"taos_probe() - i2c smbus block data " +"functions unsupported\n" );
Nor these.
drivers/staging/iio/light/tsl2583.c line 828
Quoted 4 lines
drivers/staging/iio/light/tsl2583.c new file +4
-0+ } + + chip =kzalloc (sizeof (struct tsl2583_chip ),GFP_KERNEL ); +if (!chip) {
Malloc failure would be pretty unusual and knowing what it was probably won't be helpful, so no need to have this err printing here.
Quoted 11 lines
drivers/staging/iio/light/tsl2583.c new file +11
-0+dev_err (&clientp->dev,"taos_device_drvr: kmalloc for " +"struct tsl2583_chip failed in taos_probe()\n" ); +return -ENOMEM ; + } + + chip->client = clientp; +i2c_set_clientdata (clientp, chip); + +mutex_init (&chip->als_mutex); + chip->taos_chip_status =TAOS_CHIP_UNKNOWN ;/* uninitialized to start */ +memcpy (chip->taos_config, taos_config,sizeof (chip->taos_config));
drivers/staging/iio/light/tsl2583.c line 849
Quoted 10 lines
drivers/staging/iio/light/tsl2583.c new file +10
-0+ +for (i =0 ; i <MAX_DEVICE_REGS ; i++) { + ret =i2c_smbus_write_byte (clientp, + (TSL258X_CMD_REG | (TSL258X_CNTRL + i))); +if (ret <0 ) { +dev_err (&clientp->dev,"i2c_smbus_write_byte() to cmd " +"reg failed in taos_probe(), err = %d\n" , ret); + goto fail1; + } + buf[i] =i2c_smbus_read_byte (clientp);
error handling for this read?
drivers/staging/iio/light/tsl2583.c line 855
Quoted 6 lines
drivers/staging/iio/light/tsl2583.c new file +6
-0+ } +if (!taos_skate_device (buf)) { +dev_info (&clientp->dev,"i2c device found but does not match " +"expected id in taos_probe()\n" ); + goto fail1; + }else {
The sort of debug info you want to get rid of for production drivers. Doesn't tell anyone anything helpful.
Quoted 97 lines
drivers/staging/iio/light/tsl2583.c new file +88
-1+dev_info (&clientp->dev,"i2c device match in probe\n" ); + } + ret =i2c_smbus_write_byte (clientp, (TSL258X_CMD_REG |TSL258X_CNTRL )); +if (ret <0 ) { +dev_err (&clientp->dev,"i2c_smbus_write_byte() to cmd reg " +"failed in taos_probe(), err = %d\n" , ret); + goto fail1; + } + chip->valid =0 ; + + chip->iio_dev =iio_allocate_device (); +if (!chip->iio_dev) { + ret = -ENOMEM ; +dev_err (&clientp->dev,"iio allocation failed\n" ); + goto fail1; + } + + chip->iio_dev->attrs = &tsl2583_attribute_group; + chip->iio_dev->dev.parent = &clientp->dev; + chip->iio_dev->dev_data = (void *)(chip); + chip->iio_dev->driver_module =THIS_MODULE ; + chip->iio_dev->modes =INDIO_DIRECT_MODE ; + ret =iio_device_register (chip->iio_dev); +if (ret) { +dev_err (&clientp->dev,"iio registration failed\n" ); + goto fail1; + } + +/* Load up the V2 defaults (these are hard coded defaults for now) */ +taos_defaults (chip); + +/* Make sure the chip is on */ +taos_chip_on (clientp); + +dev_info (&clientp->dev,"Light sensor found.\n" ); +return 0 ; + +fail1: +kfree (chip); + +return ret; +} + +static int __devexit taos_remove(struct i2c_client *client) +{ +struct tsl2583_chip *chip =i2c_get_clientdata (client); + +iio_device_unregister (chip->iio_dev); + +kfree (chip); +return 0 ; +} + +static struct i2c_device_id taos_idtable[] = { + {"tsl2580" ,0 }, + {"tsl2581" ,1 }, + {"tsl2583" ,2 }, + {} +}; +MODULE_DEVICE_TABLE (i2c, taos_idtable); + +/* Driver definition */ +static struct i2c_driver taos_driver = { + .driver = { + .name ="tsl2583" , + }, + .id_table = taos_idtable, + .probe = taos_probe, + .remove =__devexit_p (taos_remove), +}; + +static int __init taos_init (void ) +{ +return i2c_add_driver (&taos_driver); +} + +static void __exit taos_exit(void) +{ +i2c_del_driver (&taos_driver); +} + +module_init (taos_init); +module_exit (taos_exit); + +MODULE_AUTHOR ("J. August Brenner<[email protected]>" ); +MODULE_DESCRIPTION ("TAOS tsl2583 ambient light sensor driver" ); +MODULE_LICENSE ("GPL" ); + --1.7.0.4
--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Sm9uYXRoYW4sIGV0IGFsLA0KDQpBZ2FpbiwgdGhhbmsgeW91IGZvciB0YWtpbmcgdGhlIHRpbWUg dG8gcmV2aWV3IHRoZSBsYXRlc3Qgc3VibWlzc2lvbi4NCkkgaGF2ZSBpbXBsZW1lbnRlZCBhbGwg cmVjb21tZW5kYXRpb25zIG1hZGUgKHdpdGggdGhlIGV4Y2VwdGlvbnMgbm90ZWQgYmVsb3cpLg0K DQpJIGhhdmUgYWxzbyBhZGRlZCB0d28gbmV3IGZ1bmN0aW9ucyAobm90IHNlZW4gaGVyZSk6DQon dGFvc19zdXNwZW5kJywgYW5kICd0YW9zX3Jlc3VtZScNCg0KVGhlc2UgY2hhbmdlcyBhbmQgY29t b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ElGWSBUSEUgSVNT VUUuICANCihJRS4gV0FOVEVEIEEgVEFPUyBBTFMgREVWSUNFIEJVVCBJTlNUQUxMRUQgQSBUQU9T IFBST1gvQUxTIERFVklDRSkNCkZJUlNUIFBBUlQgSU5ESUNBVEVTIFRIQVQuICBTRUNPTkQgUEFS VCBJUyBDT05GSVJNQVRJT04gVEhBVCBERVZJQ0UgV0FTIElERU5USUZJRUQgVE8gU1lTVEVNLg0K DQoNCg0K
Quoted 21 lines · Jon Brenner
Jonathan, et al,
Again, thank you for taking the time to review the latest submission. I have implemented all recommendations made (with the exceptions noted below).
I have also added two new functions (not seen here):
'taos_suspend', and 'taos_resume'These changes and comments will be submitted in the next patch [PATCH V3] submission which I will submit shortly (after testing/verification).
Respectfully,
Jon-----Original Message-----
As I pm'd you the other day, please remember to make version of patch clear in title, and include details of what has changed since previous version. OK - NEXT PATCH WILL INDICATE VERSION 3WILL REMOVE
SENSORS_PREFIX FROM KCONFIG & MAKEFILEADDED/MOVED/CREATED DOCUMENTATION AS RECOMMENDED
Quoted 7 lines
----- snip ------------
Quoted 4 lines
+/*
+ * Provides initial operational parameter defaults.
+ * These defaults may be changed through the device's sysfs files.
+ */How about pasing in
taos_settingsand making all of this func a bit more readable? PREFER TO USE DEFAULTS METHOD
Ah, I didn't make clear what I meant here. It was simply an observation that having
static void taos_defaults(struct taos_settings *settings)
{
settings->als_time = 450;etc.
}
would be easier to read.
Quoted 15 lines
drivers/staging/iio/light/tsl2583.c line 162
Quoted 13 lines
drivers/staging/iio/light/tsl2583.c new file +12
-0+static void taos_defaults (struct tsl2583_chip *chip) { +/* Operational parameters */ + chip->taos_settings.als_time =450 ; +/* must be a multiple of 50mS */ + chip->taos_settings.als_gain =2 ; +/* this is actually an index into the gain table */ +/* assume clear glass as default */ + chip->taos_settings.als_gain_trim =1000 ; +/* default gain trim to account for aperture effects */ + chip->taos_settings.als_cal_target =130 ; +/* Known external ALS reading used for calibration */ } +----- snip ------------
Quoted 6 lines
drivers/staging/iio/light/tsl2583.c line 284
Quoted 1 line
drivers/staging/iio/light/tsl2583.c new file +1
-0+if ((ch0 >= chip->als_saturation) || (ch1 >= chip->als_saturation))would be easier to read if you set ret to lux max here an avoid jumping into the if statement below.
NO -TSL258X_LUX_CALC_OVER_FLOWNEEDS TO PASSED UP.
MUTEX NEEDS TO BE UNLOCKED.
THEN RETURN.
Sorry, should have said jump to out_unlock having set ret = LUX_CALC_OVER_FLOW;
Just makes for marginally cleaner program flow to my mind (though I don't really care about this one).
Quoted 11 lines
drivers/staging/iio/light/tsl2583.c line 285
Quoted 1 line
drivers/staging/iio/light/tsl2583.c new file +1
-0+ goto return_max;----- snip ------------
&taos_device_lux[0] perhaps?
NO - CAST MAKES IT MORE OBVIOUS - at least to me ;-)drivers/staging/iio/light/tsl2583.c line 295
Quoted 1 line
drivers/staging/iio/light/tsl2583.c new file +1
-0+ for (p = (struct taos_lux *) taos_device_lux;----- snip ------------
Quoted 1 line
+
If not time critical lest make that a sleep.
NO - TIME IS REQUIRED FOR DEVICE TO SETTLE BETWEEN POWERON AND ADC ENABLE - DON'T WANT TO MAKE IT ANY LONGER THAN NECESSARY.
But do you want to spin the processor during this time instead of getting on with something useful? I guess it depends on how critical speed is in the taos_chip_on function. I'd say this device is slow enough that a possible extra delay doesn't really matter.
Quoted 10 lines
drivers/staging/iio/light/tsl2583.c line 470
Quoted 2 lines
drivers/staging/iio/light/tsl2583.c new file +2
-0+mdelay (3 ); +/* NOW enable the ADC ----- snip ------------
I still wonder if there isn't a way of avoiding this index issue.
It's horrible and really feels like something we ought to able
to handle reasonably well...
BECAUSE THE CH0 AND CH1 DIVERGE AT HIGH GAINS -- INDEX IS BETTER THAN USING CHO OR CH1 VALUE ( AS EITHER ONE OVER THE OTHER WOULD BE WRONG :-{ )
I can see your point to a certain extent. The counter argument is that doing it with an index precludes ever touching this with any remotely general purpose user space code. Given it's an internal gain anyway is the precise value that critical? Basically is user space ever going to care about the difference between those those values?
Another option would be to have a gain for each channel as separate attributes (clearly writing to one would change the other).
Quoted 14 lines
drivers/staging/iio/light/tsl2583.c line 560
Quoted 8 lines
drivers/staging/iio/light/tsl2583.c new file +8
-0+if (value >3 ) { +dev_err (dev,"Invalid Gain Index: Enter 0-3\n" ); +return -1 ; + }else { + chip->taos_settings.als_gain = value; + } +return len; +}----- snip ------------
Just to confirm, is this a frequency in Hz? If it is can we renaming it totaos_als_frequency_showto avoid confusing me?
Quoted 2 lines
THIS IS THE INTERNAL ALS INTEGRATION TIME FOR THE ADC CHANNELS I SHOE HORNED IT INTO SAMPLING FREQUENCY TO HELP ALEVIATE THE ABI ANGST
That's good but it does have to match the units specified in the ABI as well.
Quoted 32 lines
drivers/staging/iio/light/tsl2583.c line 575
Quoted 9 lines
drivers/staging/iio/light/tsl2583.c new file +8
-0+static ssize_t taos_als_time_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct tsl2583_chip *chip = indio_dev->dev_data; + +return sprintf (buf,"%d\n" , chip->taos_settings.als_time); +}----- snip ------------
scale as a stand alone attribute isn't defined. Please document this. Looking at what you do with it, it's another factor effecting the overal gain on the reading that reaches userspace. Ideally you'd roll this into your calibscale parameter, but I can see that would get complex to manage. Will have a think about this. In devices with a simple conversion function (adc's etc) we handle this by leaving this software value be applied by userspace (and output it asin_scale). The issue here that as far as userspace is concerned both of your scales have been applied before it sees the data and at different more or less random looking points in the calculation.Actually, looking at the calculation you could output
illuminance0_rawand let userspace apply a multiplier based on your trim value and offset +0.5? If you want to hold trim in driver then just implement read and write to
illuminance0_scale
and have read onlyilluminance0_offset(rather tediously for this device, offset is applied before scale, so you'll need to divide 0.5 by whatever your trim is).
Quoted 8 lines
We'll have to do pin down how to do this before moving out of staging so best to get it right now.
CHANGED TO
ILLUMINANCE0_SCALELIFE WOULE BE NICE IF WE COULD JUST PASS THE RAW DATA UP TO USERSPACE BUT WE HAVE CUSTOMERS WHO REQUIRE IT TO COME UP CALCULATED WITH THE MULTIPLIER FACTORED IN
Sure. It's a fiddly calculation so I can kind of see their point. These light sensors are all a pain :)
Quoted 16 lines
----- snip ------------
drivers/staging/iio/light/tsl2583.c line 849
Quoted 9 lines
drivers/staging/iio/light/tsl2583.c new file +9
-0+for (i =0 ; i <MAX_DEVICE_REGS ; i++) { + ret =i2c_smbus_write_byte (clientp, + (TSL258X_CMD_REG | (TSL258X_CNTRL + i))); +if (ret <0 ) { +dev_err (&clientp->dev,"i2c_smbus_write_byte() to cmd " +"reg failed in taos_probe(), err = %d\n" , ret); + goto fail1; + } + buf[i] =i2c_smbus_read_byte (clientp);error handling for this read?
VALUE IS UNIMPORTANT - BUT MAKING SURE WE CAN JUST READ ALL 32 REGISTER LOCATIONS IS..----- snip ------------
Quoted 12 lines
drivers/staging/iio/light/tsl2583.c line 855
Quoted 6 lines
drivers/staging/iio/light/tsl2583.c new file +6
-0+ } +if (!taos_skate_device (buf)) { +dev_info (&clientp->dev,"i2c device found but does not match " +"expected id in taos_probe()\n" ); + goto fail1; + }else {The sort of debug info you want to get rid of for production drivers. Doesn't tell anyone anything helpful.
NO - DO NOT AGREE - IF A CUSTOMER EXPECTS ONE DEVICE BUT HAS SOMEHOW INSTALLED A DIFFERENT ONE AT PRODUCTION TIME, THIS WILL HELP IDENTIFY THE ISSUE.
(IE. WANTED A TAOS ALS DEVICE BUT INSTALLED A TAOS PROX/ALS DEVICE)
FIRST PART INDICATES THAT. SECOND PART IS CONFIRMATION THAT DEVICE WAS IDENTIFIED TO SYSTEM.
I'm happy with the error one. Just don't see the point in saying 'everything is as expected'. The mere absence of the error indicates that just fine!
Jonathan
SGkgSm9uYXRoYW4sDQpCZWxvdyBhcmUgYSBmZXcgY29tbWVudHMvcXVlc3Rpb25zIHRvIHlvdXIg bGF0ZXN0IHJlc3BvbnNlLg0KQW55IGRpcmVjdGlvbiBpcyBncmVhdGx5IGFwcHJlY2lhdGVkLg0K DQpKb24NCg0KDQotLS0tLU9yaWdpbmFsIE1lc3NhZ2UtLS0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 aW9uIGRyaXZlcnMuICANCj4gRG9lc24ndCB0ZWxsIGFueW9uZSBhbnl0aGluZyBoZWxwZnVsLg0K PiBOTyAtIERPIE5PVCBBR1JFRSAtIElGIEEgQ1VTVE9NRVIgRVhQRUNUUyBPTkUgREVWSUNFIEJV VCBIQVMgU09NRUhPVyANCj4gSU5TVEFMTEVEIEEgRElGRkVSRU5UIE9ORSBBVCBQUk9EVUNUSU9O IFRJTUUsIFRISVMgV0lMTCBIRUxQIElERU5USUZZIFRIRSBJU1NVRS4NCj4gKElFLiBXQU5URUQg QSBUQU9TIEFMUyBERVZJQ0UgQlVUIElOU1RBTExFRCBBIFRBT1MgUFJPWC9BTFMgREVWSUNFKSAN Cj4gRklSU1QgUEFSVCBJTkRJQ0FURVMgVEhBVC4gIFNFQ09ORCBQQVJUIElTIENPTkZJUk1BVElP TiBUSEFUIERFVklDRSBXQVMgSURFTlRJRklFRCBUTyBTWVNURU0uDQoNCkknbSBoYXBweSB3aXRo IHRoZSBlcnJvciBvbmUuIEp1c3QgZG9uJ3Qgc2VlIHRoZSBwb2ludCBpbiBzYXlpbmcgJ2V2ZXJ5 dGhpbmcgaXMgYXMgZXhwZWN0ZWQnLg0KVGhlIG1lcmUgYWJzZW5jZSBvZiB0aGUgZXJyb3IgaW5k aWNhdGVzIHRoYXQganVzdCBmaW5lIQ0KQUdSRUVEIC0gUkVNT1ZFRCAyTkQgUEFSVCAoVEhFIE9L IE1FU1NBR0UpDQoNCkpvbmF0aGFuDQoNCg==
Quoted 5 lines · Jon Brenner
Hi Jonathan,
Below are a few comments/questions to your latest response. Any direction is greatly appreciated.Jon
No chance you can persuade your email client to do conventional indenting? Ah well, I guess this works more or less.
Quoted 8 lines
Quoted 8 lines
----- snip ------------
drivers/staging/iio/light/tsl2583.c line 284
Quoted 1 line
drivers/staging/iio/light/tsl2583.c new file +1
-0+if ((ch0 >= chip->als_saturation) || (ch1 >= chip->als_saturation))would be easier to read if you set ret to lux max here an avoid jumping into the if statement below.
NO -TSL258X_LUX_CALC_OVER_FLOWNEEDS TO PASSED UP.
MUTEX NEEDS TO BE UNLOCKED.
THEN RETURN.
Quoted 6 lines
Sorry, should have said jump to
out_unlockhaving set ret =LUX_CALC_OVER_FLOW;Just makes for marginally cleaner program flow to my mind (though I don't really care about this one).
I UNDERSTAND BUT I FORGOT TO MENTION THAT IN ADDITION TO THE ABOVE, ALSO NEEDS TO UPDATE THE
ALS_CUR_INFOSTRUCT. SO, ALL SAID - EASIER TO SIMPLY JUMP TORETURN_MAX, AS THIS IS ALL DONE THERE.
Fair enough. Was just personal preference anyway!
...
Quoted 11 lines
Quoted 11 lines
drivers/staging/iio/light/tsl2583.c line 470
Quoted 2 lines
drivers/staging/iio/light/tsl2583.c new file +1
-0+/* NOW enable the ADC ----- snip ------------
I still wonder if there isn't a way of avoiding this index issue. It's horrible and really feels like something we ought to able to handle reasonably well...
BECAUSE THE CH0 AND CH1 DIVERGE AT HIGH GAINS -- INDEX IS BETTER THAN USING CHO OR CH1 VALUE ( AS EITHER ONE OVER THE OTHER WOULD BE WRONG :-{ )
Quoted 7 lines
I can see your point to a certain extent. The counter argument is that doing it with an index precludes ever touching this with any remotely general purpose user space code. Given it's an internal gain anyway is the precise value that critical? Basically is user space ever going to care about the difference between those those values?
Another option would be to have a gain for each channel as separate attributes (clearly writing to one would change the other).
I SEE YOUR POINT TOO - BUT WHAT ELSE CAN I DO (ASIDE FROM A SEPARATE GAIN FOR EACH CHANNEL - WHICH WOULD BE CONFUSING TO MANAGE)? I GUESS I COULD BUCKETIZE ANYTHING > GAIN 16 - BUT THAT SEEMS RATHER KLUDGED?
AGAIN SEEMS LIKE MOST REASONABLE (FOR NOW ANYWAY) IS AN INDEX.
It may be reasonable, but it isn't generalizable which means it probably isn't viable long term. The parameter simply won't be used by anything that isn't custom coded
for this particular sensor. Even Taos' next generation of sensors probably won't
have an index which has the same effect.
If it can be coherently blugeoned into existing interfaces, then we should do so. There are quite a few other bits of IIO interface where changing one value will effect others. This means (and we could emphasise it more) that there are sets of values user space MUST check after making a given change if it wants to know the full device state. Believe me, things are much more complex with devices that do partial scans of channels only in some combinations!
Quoted 22 lines
Quoted 5 lines
Just to confirm, is this a frequency in Hz? If it is can we renaming it to
taos_als_frequency_showto avoid confusing me?THIS IS THE INTERNAL ALS INTEGRATION TIME FOR THE ADC CHANNELS I SHOE HORNED IT INTO SAMPLING FREQUENCY TO HELP ALEVIATE THE ABI ANGST
That's good but it does have to match the units specified in the ABI as well.
OK - MAYBE I'M MISSING SOME INFO.
ALL I HAVE FOR THE ABI IS THIS:
what:/sys/bus/iio/devices/deviceX/sampling_frequency
KernelVersion: 2.6.35
Contact: [email protected]
Description:
Some devices have internal clocks. This parameter sets the resulting sampling frequency. In many devices this parameter has an effect on input filters etc rather than simply controlling when the input is sampled. As this effects datardy triggers, hardware buffers and the sysfs direct access interfaces, it may be found in any of the relevant directories. If it effects all of the above then it is to be found in the base device directory as here.
Quoted 1 line
SO I AM UNSURE OF WHAT UNITS NEED TO MATCH?
Fair point. That documentation is clearly lacking. One for the TODO list. Anyhow, it does say sampling frequency so the units can't be a measure of time. What it should say is 'in Hz' somewhere.
Quoted 35 lines
Quoted 35 lines
drivers/staging/iio/light/tsl2583.c
Quoted 8 lines
drivers/staging/iio/light/tsl2583.c new file +6
-0+static ssize_t taos_als_time_show (struct device *dev, +struct device_attribute *attr,char *buf) { +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct tsl2583_chip *chip = indio_dev->dev_data; + +return sprintf (buf,"%d\n" , chip->taos_settings.als_time); }----- snip ------------
scale as a stand alone attribute isn't defined. Please document this. Looking at what you do with it, it's another factor effecting the overal gain on the reading that reaches userspace. Ideally you'd roll this into your calibscale parameter, but I can see that would get complex to manage. Will have a think about this. In devices with a simple conversion function (adc's etc) we handle this by leaving this software value be applied by userspace (and output it asin_scale). The issue here that as far as userspace is concerned both of your scales have been applied before it sees the data and at different more or less random looking points in the calculation.Actually, looking at the calculation you could output
illuminance0_rawand let userspace apply a multiplier based on your trim value and offset
+0.5? If you want to hold trim in driver then just implement read and write to
illuminance0_scale
and have read onlyilluminance0_offset(rather tediously for this device, offset is applied before scale, so you'll need to divide 0.5 by whatever your trim is).We'll have to do pin down how to do this before moving out of staging so best to get it right now.
Quoted 8 lines
Quoted 5 lines
CHANGED TO
ILLUMINANCE0_SCALELIFE WOULE BE NICE IF WE COULD JUST PASS THE RAW DATA UP TO USERSPACE BUT WE HAVE CUSTOMERS WHO REQUIRE IT TO COME UP CALCULATED WITH THE MULTIPLIER FACTORED IN
Sure. It's a fiddly calculation so I can kind of see their point. These light sensors are all a pain :)
SO - WE ARE OK?
Err. I've kind of lost track, but I think so. Will take one last look at your next revision! Sounds like it may have some interesting new features anyway given the other thread!
Quoted 13 lines
Quoted 13 lines
----- snip ------------
drivers/staging/iio/light/tsl2583.c line 849
Quoted 9 lines
drivers/staging/iio/light/tsl2583.c new file +9
-0+for (i =0 ; i <MAX_DEVICE_REGS ; i++) { + ret =i2c_smbus_write_byte (clientp, + (TSL258X_CMD_REG | (TSL258X_CNTRL + i))); +if (ret <0 ) { +dev_err (&clientp->dev,"i2c_smbus_write_byte() to cmd " +"reg failed in taos_probe(), err = %d\n" , ret); + goto fail1; + } + buf[i] =i2c_smbus_read_byte (clientp);error handling for this read?
VALUE IS UNIMPORTANT - BUT MAKING SURE WE CAN JUST READ ALL 32 REGISTER LOCATIONS IS..
That's fine, but you haven't verified that if you don't check for a negative return from that read.
Quoted 16 lines
Quoted 15 lines
----- snip ------------
drivers/staging/iio/light/tsl2583.c line 855
Quoted 6 lines
drivers/staging/iio/light/tsl2583.c new file +6
-0+ } +if (!taos_skate_device (buf)) { +dev_info (&clientp->dev,"i2c device found but does not match " +"expected id in taos_probe()\n" ); + goto fail1; + }else {The sort of debug info you want to get rid of for production drivers.
Doesn't tell anyone anything helpful.
NO - DO NOT AGREE - IF A CUSTOMER EXPECTS ONE DEVICE BUT HAS SOMEHOW
INSTALLED A DIFFERENT ONE AT PRODUCTION TIME, THIS WILL HELP IDENTIFY THE ISSUE. (IE. WANTED A TAOS ALS DEVICE BUT INSTALLED A TAOS PROX/ALS DEVICE)
FIRST PART INDICATES THAT. SECOND PART IS CONFIRMATION THAT DEVICE WAS IDENTIFIED TO SYSTEM.
Quoted 3 lines
I'm happy with the error one. Just don't see the point in saying 'everything is as expected'. The mere absence of the error indicates that just fine!
AGREED - REMOVED 2ND PART (THE OK MESSAGE)
Cool
Coming together nicely.
Jonathan
Hi Jonathan,
The remaining issue that I am still trying to resolve is dealing with a proper ABI for the device integration time.
If 'illuminance0_sampling_frequency' is not the proper ABI, should I create a new ABI
called illuminance0_integration_time and add it to the sys-bus-iio-lisgt-tsl2583 document as you had me do with /sys/bus/iio/devices/device[n]/lux_table?
Jon
-----Original Message-----
From: Jonathan Cameron [mailto:[email protected]]
Sent: Thursday, March 24, 2011 6:16 AM
To: Jon Brenner
Cc: [email protected]; [email protected]
Subject: Re: [PATCH 2.6.38-rc7]TAOS 258x: Device Driver
Quoted 5 lines · Jon Brenner
Hi Jonathan,
Below are a few comments/questions to your latest response. Any direction is greatly appreciated.Jon
No chance you can persuade your email client to do conventional indenting? Ah well, I guess this works more or less.
Quoted 9 lines
Quoted 9 lines
----- snip ------------
Review
Quoted 2 lines
(quoted diff) +2
-0+ if ((ch0 >= chip->als_saturation) || (ch1 >= +chip->als_saturation))would be easier to read if you set ret to lux max here an avoid jumping into the if statement below.
NO -TSL258X_LUX_CALC_OVER_FLOWNEEDS TO PASSED UP.
MUTEX NEEDS TO BE UNLOCKED.
THEN RETURN.
Quoted 4 lines
Sorry, should have said jump to
out_unlockhaving set ret =LUX_CALC_OVER_FLOW;Just makes for marginally cleaner program flow to my mind (though I
don't really care about this one).
Quoted 2 lines
I UNDERSTAND BUT I FORGOT TO MENTION THAT IN ADDITION TO THE ABOVE,
ALSO NEEDS TO UPDATE THE ALS_CUR_INFO STRUCT.
Quoted 1 line
SO, ALL SAID - EASIER TO SIMPLY JUMP TO
RETURN_MAX, AS THIS IS ALL
DONE THERE.
Fair enough. Was just personal preference anyway!
...
Quoted 10 lines
Quoted 9 lines
drivers/staging/iio/light/tsl2583.c line 470
Quoted 2 lines
drivers/staging/iio/light/tsl2583.c new file +1
-0+/* NOW enable the ADC ----- snip ------------
I still wonder if there isn't a way of avoiding this index issue. It's horrible and really feels like something we ought to able to handle reasonably well...
BECAUSE THE CH0 AND CH1 DIVERGE AT HIGH GAINS -- INDEX IS BETTER THAN
Quoted 3 lines
Quoted 2 lines
USING CHO OR CH1 VALUE ( AS EITHER ONE OVER THE OTHER WOULD BE WRONG :-{ )
I can see your point to a certain extent. The counter argument is
that doing it with an index precludes ever touching this with any remotely general purpose user space code. Given it's an internal gain anyway is the precise value that critical? Basically is user space ever going to care about the difference between those those values?
Quoted 2 lines
Another option would be to have a gain for each channel as separate
attributes (clearly writing to one would change the other).
Quoted 2 lines
I SEE YOUR POINT TOO - BUT WHAT ELSE CAN I DO (ASIDE FROM A SEPARATE
GAIN FOR EACH CHANNEL - WHICH WOULD BE CONFUSING TO MANAGE)?
Quoted 1 line
I GUESS I COULD BUCKETIZE ANYTHING > GAIN 16 - BUT THAT SEEMS RATHER
KLUDGED?
Quoted 1 line
AGAIN SEEMS LIKE MOST REASONABLE (FOR NOW ANYWAY) IS AN INDEX.
It may be reasonable, but it isn't generalizable which means it probably isn't viable long term. The parameter simply won't be used by anything that isn't custom coded
for this particular sensor. Even Taos' next generation of sensors
probably won't
have an index which has the same effect.
If it can be coherently blugeoned into existing interfaces, then we should do so.
There are quite a few other bits of IIO interface where changing one value will effect others. This means (and we could emphasise it more) that there are sets of values user space MUST check after making a given change if it wants to know the full device state. Believe me, things are much more complex with devices that do partial scans of channels only in some combinations!
Quoted 7 lines
Quoted 6 lines
Just to confirm, is this a frequency in Hz? If it is can we renaming it to
taos_als_frequency_showto avoid confusing me?THIS IS THE INTERNAL ALS INTEGRATION TIME FOR THE ADC CHANNELS I SHOE
HORNED IT INTO SAMPLING FREQUENCY TO HELP ALEVIATE THE ABI ANGST
That's good but it does have to match the units specified in the ABI
as well.
Quoted 8 lines
OK - MAYBE I'M MISSING SOME INFO.
ALL I HAVE FOR THE ABI IS THIS:
what:/sys/bus/iio/devices/deviceX/sampling_frequency
KernelVersion: 2.6.35
Contact: [email protected]
Description:
Some devices have internal clocks. This parameter sets
the
Quoted 7 lines
resulting sampling frequency. In many devices this parameter has an effect on input filters etc rather than simply controlling when the input is sampled. As this effects datardy triggers, hardware buffers and the sysfs direct access interfaces, it may be found in any of the relevant directories. If it effects all of the above then it is to be found in the base device directory as
here.
Quoted 2 lines
SO I AM UNSURE OF WHAT UNITS NEED TO MATCH?
Fair point. That documentation is clearly lacking. One for the TODO list.
Anyhow, it does say sampling frequency so the units can't be a measure of time. What it should say is 'in Hz' somewhere.
Quoted 17 lines
Quoted 17 lines
drivers/staging/iio/light/tsl2583.c
Quoted 8 lines
drivers/staging/iio/light/tsl2583.c new file +6
-0+static ssize_t taos_als_time_show (struct device *dev, +struct device_attribute *attr,char *buf) { +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct tsl2583_chip *chip = indio_dev->dev_data; + +return sprintf (buf,"%d\n" , chip->taos_settings.als_time); }----- snip ------------
scale as a stand alone attribute isn't defined. Please document this. Looking at what you do with it, it's another factor effecting the overal gain on the reading that reaches userspace. Ideally you'd roll this into your calibscale parameter, but I can see that would get complex to manage. Will have a think about this. In devices with a simple conversion function (adc's etc) we handle this by leaving this software value be applied by userspace (and output it as
in_scale).
Quoted 10 lines
Quoted 10 lines
The issue here that as far as userspace is concerned both of your scales have been applied before it sees the data and at different more or less random looking points in the calculation.
Actually, looking at the calculation you could output
illuminance0_rawand let userspace apply a multiplier based on your trim value and offset
+0.5? If you want to hold trim in driver then just implement read and write to
Quoted 4 lines
Quoted 4 lines
illuminance0_scale
and have read onlyilluminance0_offset(rather tediously for this device, offset is applied before scale, so you'll need to divide 0.5 by whatever your
trim is).
Quoted 7 lines
Quoted 7 lines
We'll have to do pin down how to do this before moving out of staging
so best to get it right now.
CHANGED TO
ILLUMINANCE0_SCALE
Quoted 7 lines
Quoted 4 lines
LIFE WOULE BE NICE IF WE COULD JUST PASS THE RAW DATA UP TO USERSPACE
BUT WE HAVE CUSTOMERS WHO REQUIRE IT TO COME UP CALCULATED WITH THE MULTIPLIER FACTORED IN
Sure. It's a fiddly calculation so I can kind of see their point. These light sensors are all a pain :)
SO - WE ARE OK?
Err. I've kind of lost track, but I think so. Will take one last look at your next revision! Sounds like it may have some interesting new features anyway given the other thread!
Quoted 5 lines
Quoted 5 lines
----- snip ------------
drivers/staging/iio/light/tsl2583.c
Quoted 3 lines
drivers/staging/iio/light/tsl2583.c new file +3
-0+for (i =0 ; i <MAX_DEVICE_REGS ; i++) { + ret = i2c_smbus_write_byte(clientp, + (TSL258X_CMD_REG | (TSL258X_CNTRL +
i)));
Quoted 2 lines
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (ret < 0) { + dev_err(&clientp->dev, "i2c_smbus_write_byte()
to cmd "
Quoted 1 line
Quoted 1 line
Review
Quoted 1 line
(quoted diff) +1
-0+ "reg failed in taos_probe(), err =
%d\n", ret);
Quoted 5 lines
Quoted 5 lines
drivers/staging/iio/light/tsl2583.c line 849
Quoted 3 lines
drivers/staging/iio/light/tsl2583.c new file +3
-0+ goto fail1; + } + buf[i] =i2c_smbus_read_byte (clientp);error handling for this read?
VALUE IS UNIMPORTANT - BUT MAKING SURE WE CAN JUST READ ALL 32
REGISTER LOCATIONS IS..
That's fine, but you haven't verified that if you don't check for a negative return from that read.
AGREED - ADDED CHECK FOR NEGATIVE RETURN
Quoted 6 lines
Quoted 6 lines
----- snip ------------
drivers/staging/iio/light/tsl2583.c
Quoted 3 lines
drivers/staging/iio/light/tsl2583.c new file +3
-0+ } +if (!taos_skate_device (buf)) { + dev_info(&clientp->dev, "i2c device found but does not
match "
Quoted 8 lines
Quoted 8 lines
drivers/staging/iio/light/tsl2583.c line 855
Quoted 3 lines
drivers/staging/iio/light/tsl2583.c new file +3
-0+ "expected id in taos_probe()\n"); + goto fail1; + }else {The sort of debug info you want to get rid of for production drivers.
Doesn't tell anyone anything helpful.
NO - DO NOT AGREE - IF A CUSTOMER EXPECTS ONE DEVICE BUT HAS SOMEHOW INSTALLED A DIFFERENT ONE AT PRODUCTION TIME, THIS WILL HELP IDENTIFY
THE ISSUE.
Quoted 2 lines
Quoted 2 lines
(IE. WANTED A TAOS ALS DEVICE BUT INSTALLED A TAOS PROX/ALS DEVICE) FIRST PART INDICATES THAT. SECOND PART IS CONFIRMATION THAT DEVICE
WAS IDENTIFIED TO SYSTEM.
Quoted 2 lines
I'm happy with the error one. Just don't see the point in saying
'everything is as expected'.
Quoted 2 lines
The mere absence of the error indicates that just fine! AGREED - REMOVED 2ND PART (THE OK MESSAGE)
Cool
Coming together nicely.
Jonathan
Quoted 8 lines · Jon Brenner
Hi Jonathan,
The remaining issue that I am still trying to resolve is dealing with a proper ABI for the device integration time.
If 'illuminance0_sampling_frequency' is not the proper ABI, should I create a new ABI
calledilluminance0_integration_timeand add it to the sys-bus-iio-lisgt-tsl2583 document as you had me do with /sys/bus/iio/devices/device[n]/lux_table?
Hmm. It really isn't fitting well in sampling frequency is it? Obviously it is connected to the frequency at which one can sample, but isn't quite the same.
Throw an email to linux-iio proposing such an attribute and lets see what people come back with. This sort of integration time is pretty specific to light sensors so for now add it to the light docs - it is however a general thing on light sensors so we want something that isn't device specific.
Make sure it is in sensible units though (seconds).
Quoted 218 lines
Jon
-----Original Message-----
From: Jonathan Cameron [mailto:[email protected]]
Sent: Thursday, March 24, 2011 6:16 AM
To: Jon Brenner
Cc: [email protected]; [email protected]
Subject: Re: [PATCH 2.6.38-rc7]TAOS 258x: Device DriverQuoted 5 lines · Jon Brenner
Hi Jonathan,
Below are a few comments/questions to your latest response. Any direction is greatly appreciated.Jon
No chance you can persuade your email client to do conventional indenting? Ah well, I guess this works more or less.
Quoted 9 lines
Quoted 9 lines
----- snip ------------
Review
Quoted 2 lines
(quoted diff) +2
-0+ if ((ch0 >= chip->als_saturation) || (ch1 >= +chip->als_saturation))would be easier to read if you set ret to lux max here an avoid jumping into the if statement below.
NO -TSL258X_LUX_CALC_OVER_FLOWNEEDS TO PASSED UP.
MUTEX NEEDS TO BE UNLOCKED.
THEN RETURN.Quoted 4 lines
Sorry, should have said jump to
out_unlockhaving set ret =LUX_CALC_OVER_FLOW;Just makes for marginally cleaner program flow to my mind (though I
don't really care about this one).
Quoted 2 lines
I UNDERSTAND BUT I FORGOT TO MENTION THAT IN ADDITION TO THE ABOVE,
ALSO NEEDS TO UPDATE THE
ALS_CUR_INFOSTRUCT.Quoted 1 line
SO, ALL SAID - EASIER TO SIMPLY JUMP TO
RETURN_MAX, AS THIS IS ALLDONE THERE.
Fair enough. Was just personal preference anyway!
...Quoted 10 lines
Quoted 9 lines
Review
Quoted 2 lines
(quoted diff) +1
-0+ /* NOW enable the ADC----- snip ------------
I still wonder if there isn't a way of avoiding this index issue. It's horrible and really feels like something we ought to able to handle reasonably well...
BECAUSE THE CH0 AND CH1 DIVERGE AT HIGH GAINS -- INDEX IS BETTER THANQuoted 3 lines
Quoted 2 lines
USING CHO OR CH1 VALUE ( AS EITHER ONE OVER THE OTHER WOULD BE WRONG :-{ )
I can see your point to a certain extent. The counter argument is
that doing it with an index precludes ever touching this with any remotely general purpose user space code. Given it's an internal gain anyway is the precise value that critical? Basically is user space ever going to care about the difference between those those values?
Quoted 2 lines
Another option would be to have a gain for each channel as separate
attributes (clearly writing to one would change the other).
Quoted 2 lines
I SEE YOUR POINT TOO - BUT WHAT ELSE CAN I DO (ASIDE FROM A SEPARATE
GAIN FOR EACH CHANNEL - WHICH WOULD BE CONFUSING TO MANAGE)?
Quoted 1 line
I GUESS I COULD BUCKETIZE ANYTHING > GAIN 16 - BUT THAT SEEMS RATHER
KLUDGED?
Quoted 1 line
AGAIN SEEMS LIKE MOST REASONABLE (FOR NOW ANYWAY) IS AN INDEX.
It may be reasonable, but it isn't generalizable which means it probably isn't viable long term. The parameter simply won't be used by anything that isn't custom coded
for this particular sensor. Even Taos' next generation of sensors
probably won't
have an index which has the same effect.If it can be coherently blugeoned into existing interfaces, then we should do so.
There are quite a few other bits of IIO interface where changing one value will effect others. This means (and we could emphasise it more) that there are sets of values user space MUST check after making a given change if it wants to know the full device state. Believe me, things are much more complex with devices that do partial scans of channels only in some combinations!Quoted 7 lines
Quoted 6 lines
Just to confirm, is this a frequency in Hz? If it is can we renaming it to
taos_als_frequency_showto avoid confusing me?THIS IS THE INTERNAL ALS INTEGRATION TIME FOR THE ADC CHANNELS I SHOE
HORNED IT INTO SAMPLING FREQUENCY TO HELP ALEVIATE THE ABI ANGST
That's good but it does have to match the units specified in the ABI
as well.
Quoted 8 lines
OK - MAYBE I'M MISSING SOME INFO.
ALL I HAVE FOR THE ABI IS THIS:
what:/sys/bus/iio/devices/deviceX/sampling_frequency
KernelVersion: 2.6.35
Contact: [email protected]
Description:
Some devices have internal clocks. This parameter setsthe
Quoted 7 lines
resulting sampling frequency. In many devices this parameter has an effect on input filters etc rather than simply controlling when the input is sampled. As this effects datardy triggers, hardware buffers and the sysfs direct access interfaces, it may be found in any of the relevant directories. If it effects all of the above then it is to be found in the base device directory as
here.
Quoted 2 lines
SO I AM UNSURE OF WHAT UNITS NEED TO MATCH?
Fair point. That documentation is clearly lacking. One for the TODO list.
Anyhow, it does say sampling frequency so the units can't be a measure of time. What it should say is 'in Hz' somewhere.Quoted 17 lines
Quoted 17 lines
Review
Quoted 8 lines
(quoted diff) +6
-0+static ssize_t taos_als_time_show(struct device *dev, + struct device_attribute *attr, char *buf) { + struct iio_dev *indio_dev = dev_get_drvdata(dev); + struct tsl2583_chip *chip = indio_dev->dev_data; + + return sprintf(buf, "%d\n", chip->taos_settings.als_time); }----- snip ------------
scale as a stand alone attribute isn't defined. Please document this. Looking at what you do with it, it's another factor effecting the overal gain on the reading that reaches userspace. Ideally you'd roll this into your calibscale parameter, but I can see that would get complex to manage. Will have a think about this. In devices with a simple conversion function (adc's etc) we handle this by leaving this software value be applied by userspace (and output it as
in_scale).Quoted 10 lines
Quoted 10 lines
The issue here that as far as userspace is concerned both of your scales have been applied before it sees the data and at different more or less random looking points in the calculation.
Actually, looking at the calculation you could output
illuminance0_rawand let userspace apply a multiplier based on your trim value and offset
+0.5? If you want to hold trim in driver then just implement read and write toQuoted 4 lines
Quoted 4 lines
illuminance0_scale
and have read onlyilluminance0_offset(rather tediously for this device, offset is applied before scale, so you'll need to divide 0.5 by whatever yourtrim is).
Quoted 7 lines
Quoted 7 lines
We'll have to do pin down how to do this before moving out of staging
so best to get it right now.
CHANGED TO
ILLUMINANCE0_SCALEQuoted 7 lines
Quoted 4 lines
LIFE WOULE BE NICE IF WE COULD JUST PASS THE RAW DATA UP TO USERSPACE
BUT WE HAVE CUSTOMERS WHO REQUIRE IT TO COME UP CALCULATED WITH THE MULTIPLIER FACTORED IN
Sure. It's a fiddly calculation so I can kind of see their point. These light sensors are all a pain :)
SO - WE ARE OK?Err. I've kind of lost track, but I think so. Will take one last look at your next revision! Sounds like it may have some interesting new features anyway given the other thread!
Quoted 5 lines
Quoted 5 lines
----- snip ------------
Review
Quoted 3 lines
(quoted diff) +3
-0+ for (i = 0; i < MAX_DEVICE_REGS; i++) { + ret = i2c_smbus_write_byte(clientp, + (TSL258X_CMD_REG | (TSL258X_CNTRL +i)));
Quoted 2 lines
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (ret < 0) { + dev_err(&clientp->dev, "i2c_smbus_write_byte()to cmd "
Quoted 1 line
Quoted 1 line
Review
Quoted 1 line
(quoted diff) +1
-0+ "reg failed in taos_probe(), err =%d\n", ret);
Quoted 5 lines
Quoted 5 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ goto fail1; + } + buf[i] = i2c_smbus_read_byte(clientp);error handling for this read?
VALUE IS UNIMPORTANT - BUT MAKING SURE WE CAN JUST READ ALL 32REGISTER LOCATIONS IS..
That's fine, but you haven't verified that if you don't check for a negative return from that read.AGREED - ADDED CHECK FOR NEGATIVE RETURN
Quoted 6 lines
Quoted 6 lines
----- snip ------------
Review
Quoted 3 lines
(quoted diff) +3
-0+ } + if (!taos_skate_device(buf)) { + dev_info(&clientp->dev, "i2c device found but does notmatch "
Quoted 8 lines
Quoted 8 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ "expected id in taos_probe()\n"); + goto fail1; + } else {The sort of debug info you want to get rid of for production drivers.
Doesn't tell anyone anything helpful.
NO - DO NOT AGREE - IF A CUSTOMER EXPECTS ONE DEVICE BUT HAS SOMEHOW INSTALLED A DIFFERENT ONE AT PRODUCTION TIME, THIS WILL HELP IDENTIFYTHE ISSUE.
Quoted 2 lines
Quoted 2 lines
(IE. WANTED A TAOS ALS DEVICE BUT INSTALLED A TAOS PROX/ALS DEVICE) FIRST PART INDICATES THAT. SECOND PART IS CONFIRMATION THAT DEVICE
WAS IDENTIFIED TO SYSTEM.
Quoted 2 lines
I'm happy with the error one. Just don't see the point in saying
'everything is as expected'.
Quoted 2 lines
The mere absence of the error indicates that just fine! AGREED - REMOVED 2ND PART (THE OK MESSAGE)
Cool
Coming together nicely.
Jonathan
--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html