Re: [PATCH v2] staging: iio: tsl2x7x: clean up limit checks
On Fri, Sep 08, 2017 at 01:53:43PM +0300, Dan Carpenter wrote: > The background of this code is that we can either use the default > tables or load our own table with sysfs. The default tables are three > element arrays of struct tsl2x7x_lux. If we load the table with sysfs > then we can have as many as nine elements. Which ever way we do it, the > last element is always zeroed out. > > The most interesting part of this patch is in the > in_illuminance0_lux_table_show() function. We were using the wrong > limit, "TSL2X7X_MAX_LUX_TABLE_SIZE * 3", when it should have been just > "TSL2X7X_MAX_LUX_TABLE_SIZE". This creates a static checker warning > that we are going of of bounds. However, since the last element is > always zeroed out, that means we hit the break statement and the code > works correctly despite the wrong limit check. > > I made several related readability changes. The most notable that I > changed the MAX_DEFAULT_TABLE_BYTES define which was: > > #define MAX_DEFAULT_TABLE_BYTES (sizeof(int) * TSL2X7X_MAX_LUX_TABLE_SIZE) > > I renamed the define to TSL2X7X_DEFAULT_TABLE_BYTES because it's not the > max size, it's the only size. Also the size should really be expressed > as sizeof(struct tsl2x7x_lux) * 3. In other words, 12 * 3 instead of > 4 * 9. It's 36 bytes either way, so this doesn't change the behavior. > > Finally, I created the TSL2X7X_DEF_LUX_TABLE_SZ define instead of using > the magic number 3. I declared the default tables using that define > to hopefully signal to future programmers that if they want to use a > different size they have to update all the related code. > > Signed-off-by: Dan Carpenter Acked-by: Brian Masney Brian ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 1/3] staging: iio: tsl2x7x: rename tsl2x7x_settings variable to settings
The length of the 'tsl2x7x_settings' variable within the tsl2X7X_chip structure makes some of the line lengths greater than 80 characters for upcoming patches. This patch shortens the name of the 'tsl2x7x_settings' variable in this structure to just 'settings' to improve code readability. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 183 +--- 1 file changed, 85 insertions(+), 98 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index d9defc8ece83..e340ea624e5c 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -174,7 +174,7 @@ struct tsl2X7X_chip { struct i2c_client *client; u16 prox_data; struct tsl2x7x_als_info als_cur_info; - struct tsl2x7x_settings tsl2x7x_settings; + struct tsl2x7x_settings settings; struct tsl2X7X_platform_data *pdata; int als_time_scale; int als_saturation; @@ -390,9 +390,9 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev) lux = 0; } else { ch0lux = DIV_ROUND_UP(ch0 * p->ch0, - tsl2X7X_als_gainadj[chip->tsl2x7x_settings.als_gain]); + tsl2X7X_als_gainadj[chip->settings.als_gain]); ch1lux = DIV_ROUND_UP(ch1 * p->ch1, - tsl2X7X_als_gainadj[chip->tsl2x7x_settings.als_gain]); + tsl2X7X_als_gainadj[chip->settings.als_gain]); lux = ch0lux - ch1lux; } @@ -419,7 +419,7 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev) */ lux64 = lux; - lux64 = lux64 * chip->tsl2x7x_settings.als_gain_trim; + lux64 = lux64 * chip->settings.als_gain_trim; lux64 >>= 8; lux = lux64; lux = (lux + 500) / 1000; @@ -514,12 +514,10 @@ static void tsl2x7x_defaults(struct tsl2X7X_chip *chip) { /* If Operational settings defined elsewhere.. */ if (chip->pdata && chip->pdata->platform_default_settings) - memcpy(&chip->tsl2x7x_settings, - chip->pdata->platform_default_settings, + memcpy(&chip->settings, chip->pdata->platform_default_settings, sizeof(tsl2x7x_default_settings)); else - memcpy(&chip->tsl2x7x_settings, - &tsl2x7x_default_settings, + memcpy(&chip->settings, &tsl2x7x_default_settings, sizeof(tsl2x7x_default_settings)); /* Load up the proper lux table. */ @@ -542,9 +540,7 @@ static void tsl2x7x_defaults(struct tsl2X7X_chip *chip) static int tsl2x7x_als_calibrate(struct iio_dev *indio_dev) { struct tsl2X7X_chip *chip = iio_priv(indio_dev); - int gain_trim_val; - int ret; - int lux_val; + int ret, lux_val; ret = i2c_smbus_read_byte_data(chip->client, TSL2X7X_CMD_REG | TSL2X7X_CNTRL); @@ -575,16 +571,16 @@ static int tsl2x7x_als_calibrate(struct iio_dev *indio_dev) return lux_val; } - gain_trim_val = ((chip->tsl2x7x_settings.als_cal_target) - * chip->tsl2x7x_settings.als_gain_trim) / lux_val; - if ((gain_trim_val < 250) || (gain_trim_val > 4000)) + ret = (chip->settings.als_cal_target * chip->settings.als_gain_trim) / + lux_val; + if (ret < 250 || ret > 4000) return -ERANGE; - chip->tsl2x7x_settings.als_gain_trim = gain_trim_val; + chip->settings.als_gain_trim = ret; dev_info(&chip->client->dev, "%s als_calibrate completed\n", chip->client->name); - return (int)gain_trim_val; + return ret; } static int tsl2x7x_chip_on(struct iio_dev *indio_dev) @@ -602,34 +598,30 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev) chip->pdata->power_on(indio_dev); /* Non calculated parameters */ - chip->tsl2x7x_config[TSL2X7X_PRX_TIME] = - chip->tsl2x7x_settings.prx_time; - chip->tsl2x7x_config[TSL2X7X_WAIT_TIME] = - chip->tsl2x7x_settings.wait_time; - chip->tsl2x7x_config[TSL2X7X_PRX_CONFIG] = - chip->tsl2x7x_settings.prox_config; + chip->tsl2x7x_config[TSL2X7X_PRX_TIME] = chip->settings.prx_time; + chip->tsl2x7x_config[TSL2X7X_WAIT_TIME] = chip->settings.wait_time; + chip->tsl2x7x_config[TSL2X7X_PRX_CONFIG] = chip->settings.prox_config; chip->tsl2x7x_config[TSL2X7X_ALS_MINTHRESHLO] = - (chip->tsl2x7x_settings.als_thresh_low) & 0xFF; + (chip->settings
[PATCH 3/3] staging: iio: tsl2x7x: migrate *_thresh_period sysfs attributes to iio_event_spec
The sysfs attributes in_intensity0_thresh_period and in_proximity0_thresh_period are currently directly created by the driver. This patch migrates the creation of these sysfs attributes from the driver to using the IIO core via iio_event_spec. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 196 ++-- 1 file changed, 52 insertions(+), 144 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index e6a71f5fc9cb..be2806593e59 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -932,108 +932,6 @@ static ssize_t in_illuminance0_target_input_store(struct device *dev, return len; } -/* persistence settings */ -static ssize_t in_intensity0_thresh_period_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev)); - int y, z, filter_delay; - - /* Determine integration time */ - y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->settings.als_time) + 1; - z = y * TSL2X7X_MIN_ITIME; - filter_delay = z * (chip->settings.persistence & 0x0F); - y = filter_delay / 1000; - z = filter_delay % 1000; - - return snprintf(buf, PAGE_SIZE, "%d.%03d\n", y, z); -} - -static ssize_t in_intensity0_thresh_period_store(struct device *dev, -struct device_attribute *attr, -const char *buf, size_t len) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct tsl2X7X_chip *chip = iio_priv(indio_dev); - struct tsl2x7x_parse_result result; - int y, z, filter_delay; - int ret; - - ret = iio_str_to_fixpoint(buf, 100, &result.integer, &result.fract); - if (ret) - return ret; - - y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->settings.als_time) + 1; - z = y * TSL2X7X_MIN_ITIME; - - filter_delay = - DIV_ROUND_UP((result.integer * 1000) + result.fract, z); - - chip->settings.persistence &= 0xF0; - chip->settings.persistence |= (filter_delay & 0x0F); - - dev_info(&chip->client->dev, "%s: als persistence = %d", -__func__, filter_delay); - - ret = tsl2x7x_invoke_change(indio_dev); - if (ret < 0) - return ret; - - return IIO_VAL_INT_PLUS_MICRO; -} - -static ssize_t in_proximity0_thresh_period_show(struct device *dev, -struct device_attribute *attr, -char *buf) -{ - struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev)); - int y, z, filter_delay; - - /* Determine integration time */ - y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->settings.prx_time) + 1; - z = y * TSL2X7X_MIN_ITIME; - filter_delay = z * ((chip->settings.persistence & 0xF0) >> 4); - y = filter_delay / 1000; - z = filter_delay % 1000; - - return snprintf(buf, PAGE_SIZE, "%d.%03d\n", y, z); -} - -static ssize_t in_proximity0_thresh_period_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct tsl2X7X_chip *chip = iio_priv(indio_dev); - struct tsl2x7x_parse_result result; - int y, z, filter_delay; - int ret; - - ret = iio_str_to_fixpoint(buf, 100, &result.integer, &result.fract); - if (ret) - return ret; - - y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->settings.prx_time) + 1; - z = y * TSL2X7X_MIN_ITIME; - - filter_delay = - DIV_ROUND_UP((result.integer * 1000) + result.fract, z); - - chip->settings.persistence &= 0x0F; - chip->settings.persistence |= ((filter_delay << 4) & 0xF0); - - dev_info(&chip->client->dev, "%s: prox persistence = %d", -__func__, filter_delay); - - ret = tsl2x7x_invoke_change(indio_dev); - if (ret < 0) - return ret; - - - return IIO_VAL_INT_PLUS_MICRO; -} - static ssize_t in_illuminance0_calibrate_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) @@ -1198,7 +1096,8 @@ static int tsl2x7x_write_event_value(struct iio_dev *indio_dev, int val, int val2) { struct tsl2X7X_chip *chip = iio_priv(indio_dev); - int ret = -EINVAL; + int ret = -EINVAL, y, z, filter_delay; + u8 ti
[PATCH 0/3] staging: iio: tsl2x7x: staging cleanups
This patch set converts several sysfs attributes from directly being created by the driver to be created by iio_chan_spec and iio_event_spec. There is also a patch to shorten the length of a variable to fix an issue that I encountered with some lines that were over 80 characters with this refactoring. Driver tested using a TSL2771 hooked up to a Raspberry Pi 2. List of sysfs attributes before and after my changes: raspberrypi:/sys/bus/iio/devices/iio:device0$ find . -type f | sort ./dev ./events/in_intensity0_thresh_falling_en ./events/in_intensity0_thresh_falling_value ./events/in_intensity0_thresh_period ./events/in_intensity0_thresh_rising_en ./events/in_intensity0_thresh_rising_value ./events/in_proximity0_thresh_falling_en ./events/in_proximity0_thresh_falling_value ./events/in_proximity0_thresh_period ./events/in_proximity0_thresh_rising_en ./events/in_proximity0_thresh_rising_value ./in_illuminance0_calibrate ./in_illuminance0_calibscale_available ./in_illuminance0_input ./in_illuminance0_integration_time ./in_illuminance0_integration_time_available ./in_illuminance0_lux_table ./in_illuminance0_target_input ./in_intensity0_calibbias ./in_intensity0_calibscale ./in_intensity0_raw ./in_intensity1_raw ./in_proximity0_calibrate ./in_proximity0_raw ./name ./power/autosuspend_delay_ms ./power/control ./power/runtime_active_time ./power/runtime_status ./power/runtime_suspended_time ./uevent Brian Masney (3): staging: iio: tsl2x7x: rename tsl2x7x_settings variable to settings staging: iio: tsl2x7x: migrate in_illuminance0_integration_time sysfs attribute to iio_chan_spec staging: iio: tsl2x7x: migrate *_thresh_period sysfs attributes to iio_event_spec drivers/staging/iio/light/tsl2x7x.c | 418 1 file changed, 141 insertions(+), 277 deletions(-) -- 2.13.5 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 2/3] staging: iio: tsl2x7x: migrate in_illuminance0_integration_time sysfs attribute to iio_chan_spec
The driver explicitly creates the in_illuminance0_integration_time sysfs attribute outside the IIO core. This attribute is available in the IIO core so this patches migrates the attribute to be created by the iio_chan_spec. Signed-off-by: Brian Masney --- Changes since v1 (Jul 9 2017): - Use MIN_ITIME instead of hardcoded 3 in tsl2x7x_write_raw() drivers/staging/iio/light/tsl2x7x.c | 65 ++--- 1 file changed, 17 insertions(+), 48 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index e340ea624e5c..e6a71f5fc9cb 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -898,45 +898,6 @@ static ssize_t in_proximity0_calibscale_available_show(struct device *dev, return snprintf(buf, PAGE_SIZE, "%s\n", "1 2 4 8"); } -static ssize_t in_illuminance0_integration_time_show(struct device *dev, -struct device_attribute *attr, -char *buf) -{ - struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev)); - int y, z; - - y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->settings.als_time) + 1; - z = y * TSL2X7X_MIN_ITIME; - y /= 1000; - z %= 1000; - - return snprintf(buf, PAGE_SIZE, "%d.%03d\n", y, z); -} - -static ssize_t in_illuminance0_integration_time_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct tsl2X7X_chip *chip = iio_priv(indio_dev); - struct tsl2x7x_parse_result result; - int ret; - - ret = iio_str_to_fixpoint(buf, 100, &result.integer, &result.fract); - if (ret) - return ret; - - result.fract /= 3; - chip->settings.als_time = TSL2X7X_MAX_TIMER_CNT - (u8)result.fract; - - dev_info(&chip->client->dev, "%s: als time = %d", -__func__, chip->settings.als_time); - - tsl2x7x_invoke_change(indio_dev); - - return IIO_VAL_INT_PLUS_MICRO; -} - static IIO_CONST_ATTR(in_illuminance0_integration_time_available, ".00272 - .696"); @@ -1377,7 +1338,11 @@ static int tsl2x7x_read_raw(struct iio_dev *indio_dev, *val = chip->settings.als_gain_trim; ret = IIO_VAL_INT; break; - + case IIO_CHAN_INFO_INT_TIME: + *val = (TSL2X7X_MAX_TIMER_CNT - chip->settings.als_time) + 1; + *val2 = ((*val * TSL2X7X_MIN_ITIME) % 1000) / 1000; + ret = IIO_VAL_INT_PLUS_MICRO; + break; default: ret = -EINVAL; } @@ -1453,7 +1418,13 @@ static int tsl2x7x_write_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_CALIBBIAS: chip->settings.als_gain_trim = val; break; + case IIO_CHAN_INFO_INT_TIME: + chip->settings.als_time = + TSL2X7X_MAX_TIMER_CNT - (val2 / TSL2X7X_MIN_ITIME); + dev_info(&chip->client->dev, "%s: als time = %d", +__func__, chip->settings.als_time); + break; default: return -EINVAL; } @@ -1465,8 +1436,6 @@ static DEVICE_ATTR_RO(in_proximity0_calibscale_available); static DEVICE_ATTR_RO(in_illuminance0_calibscale_available); -static DEVICE_ATTR_RW(in_illuminance0_integration_time); - static DEVICE_ATTR_RW(in_illuminance0_target_input); static DEVICE_ATTR_WO(in_illuminance0_calibrate); @@ -1546,7 +1515,6 @@ static irqreturn_t tsl2x7x_event_handler(int irq, void *private) static struct attribute *tsl2x7x_ALS_device_attrs[] = { &dev_attr_in_illuminance0_calibscale_available.attr, - &dev_attr_in_illuminance0_integration_time.attr, &iio_const_attr_in_illuminance0_integration_time_available.dev_attr.attr, &dev_attr_in_illuminance0_target_input.attr, &dev_attr_in_illuminance0_calibrate.attr, @@ -1561,7 +1529,6 @@ static struct attribute *tsl2x7x_PRX_device_attrs[] = { static struct attribute *tsl2x7x_ALSPRX_device_attrs[] = { &dev_attr_in_illuminance0_calibscale_available.attr, - &dev_attr_in_illuminance0_integration_time.attr, &iio_const_attr_in_illuminance0_integration_time_available.dev_attr.attr, &dev_attr_in_illuminance0_target_input.attr, &dev_attr_in_illuminance0_calibrate.attr, @@ -1578,7 +1545,6 @@ static struct attribute *tsl2x7x_PRX2_device_attrs[] = { static struct attribute *tsl2x7x_ALSPRX2_device_attrs[] = { &dev_attr_in_illuminance0_calibscale_available.attr, - &dev_attr_in_illuminance0_integration_time.attr, &iio_const_
Re: [PATCH 3/3] staging: iio: tsl2x7x: migrate *_thresh_period sysfs attributes to iio_event_spec
On Sun, Oct 01, 2017 at 11:14:46AM +0100, Jonathan Cameron wrote: > On Fri, 29 Sep 2017 21:09:21 -0400 > Brian Masney wrote: > > > The sysfs attributes in_intensity0_thresh_period and > > in_proximity0_thresh_period are currently directly created by the driver. > > This patch migrates the creation of these sysfs attributes from the driver > > to using the IIO core via iio_event_spec. > > > > Signed-off-by: Brian Masney > > One question down the end about whether we should be using IIO_EV_DIR_EITHER > rather than IIO_EV_DIR_NONE > > NONE is only really for thing where a direction makes not sense rather > than to remove the direction be specified for a particular element. > > Otherwise looks good. I'd just have changed this, but wasn't sure if > there was deeper logic behind your choice that I was missing! There wasn't any deeper logic to this. :) I'll test it with IIO_EV_DIR_EITHER and send v2 with my next batch of cleanups unless you change it before then. Thanks, Brian ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 02/13] staging: iio: tsl2x7x: remove unused tsl2x7x_parse_result structure
The structure tsl2x7x_parse_result is not used so this patch removes its definition. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 5 - 1 file changed, 5 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index 2dd8c502fd7a..094ab76b5d60 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -142,11 +142,6 @@ enum { TSL2X7X_CHIP_SUSPENDED = 2 }; -struct tsl2x7x_parse_result { - int integer; - int fract; -}; - /* Per-device data */ struct tsl2x7x_als_info { u16 als_ch0; -- 2.13.6 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 06/13] staging: iio: tsl2x7x: convert in_proximity0_calibscale_available to use IIO_CONST_ATTR
The sysfs attribute in_proximity0_calibscale_available is currently created by using DEVICE_ATTR_RO(). Convert this over to use IIO_CONST_ATTR(). Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 15 --- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index 3a3340aadc1a..80968dd456a0 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -886,12 +886,7 @@ static ssize_t in_illuminance0_calibscale_available_show(struct device *dev, return snprintf(buf, PAGE_SIZE, "%s\n", "1 8 16 120"); } -static ssize_t in_proximity0_calibscale_available_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - return snprintf(buf, PAGE_SIZE, "%s\n", "1 2 4 8"); -} +static IIO_CONST_ATTR(in_proximity0_calibscale_available, "1 2 4 8"); static IIO_CONST_ATTR(in_illuminance0_integration_time_available, ".00272 - .696"); @@ -1371,8 +1366,6 @@ static int tsl2x7x_write_raw(struct iio_dev *indio_dev, return tsl2x7x_invoke_change(indio_dev); } -static DEVICE_ATTR_RO(in_proximity0_calibscale_available); - static DEVICE_ATTR_RO(in_illuminance0_calibscale_available); static DEVICE_ATTR_RW(in_illuminance0_target_input); @@ -1468,13 +1461,13 @@ static struct attribute *tsl2x7x_ALSPRX_device_attrs[] = { &dev_attr_in_illuminance0_target_input.attr, &dev_attr_in_illuminance0_calibrate.attr, &dev_attr_in_illuminance0_lux_table.attr, - &dev_attr_in_proximity0_calibrate.attr, + &iio_const_attr_in_proximity0_calibscale_available.dev_attr.attr, NULL }; static struct attribute *tsl2x7x_PRX2_device_attrs[] = { &dev_attr_in_proximity0_calibrate.attr, - &dev_attr_in_proximity0_calibscale_available.attr, + &iio_const_attr_in_proximity0_calibscale_available.dev_attr.attr, NULL }; @@ -1485,7 +1478,7 @@ static struct attribute *tsl2x7x_ALSPRX2_device_attrs[] = { &dev_attr_in_illuminance0_calibrate.attr, &dev_attr_in_illuminance0_lux_table.attr, &dev_attr_in_proximity0_calibrate.attr, - &dev_attr_in_proximity0_calibscale_available.attr, + &iio_const_attr_in_proximity0_calibscale_available.dev_attr.attr, NULL }; -- 2.13.6 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 13/13] staging: iio: tsl2x7x: add goto for TSL2X7X_LUX_CALC_OVER_FLOW
This patch adds a return_max label for the two cases that need to set the lux to TSL2X7X_LUX_CALC_OVER_FLOW and return. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 9 - 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index 42ed9c015aaf..898304d65f64 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -364,10 +364,8 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev) chip->als_cur_info.als_ch0 = ch0; chip->als_cur_info.als_ch1 = ch1; - if (ch0 >= chip->als_saturation || ch1 >= chip->als_saturation) { - lux = TSL2X7X_LUX_CALC_OVER_FLOW; + if (ch0 >= chip->als_saturation || ch1 >= chip->als_saturation) goto return_max; - } if (!ch0) { /* have no data, so return LAST VALUE */ @@ -418,11 +416,12 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev) lux = lux64; lux = (lux + 500) / 1000; - if (lux > TSL2X7X_LUX_CALC_OVER_FLOW) /* check for overflow */ + if (lux > TSL2X7X_LUX_CALC_OVER_FLOW) { /* check for overflow */ +return_max: lux = TSL2X7X_LUX_CALC_OVER_FLOW; + } /* Update the structure with the latest lux. */ -return_max: chip->als_cur_info.lux = lux; ret = lux; -- 2.13.6 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 12/13] staging: iio: tsl2x7x: put function definitions on a single line
The functions tsl2x7x_invoke_change() and tsl2x7x_prox_calculate() are short enough that the return value and static declaration can be moved onto the same line with the function name. This patch makes that change to increase code readability. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 8 +++- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index f12ab1239a46..42ed9c015aaf 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -752,8 +752,7 @@ static int tsl2x7x_chip_off(struct iio_dev *indio_dev) * put device back into proper state, and unlock * resource. */ -static -int tsl2x7x_invoke_change(struct iio_dev *indio_dev) +static int tsl2x7x_invoke_change(struct iio_dev *indio_dev) { struct tsl2X7X_chip *chip = iio_priv(indio_dev); int device_status = chip->tsl2x7x_chip_status; @@ -777,9 +776,8 @@ int tsl2x7x_invoke_change(struct iio_dev *indio_dev) return ret; } -static -void tsl2x7x_prox_calculate(int *data, int length, - struct tsl2x7x_prox_stat *statP) +static void tsl2x7x_prox_calculate(int *data, int length, + struct tsl2x7x_prox_stat *statP) { int i; int sample_sum; -- 2.13.6 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 08/13] staging: iio: tsl2x7x: correct alignment of parenthesis
Correct error from checkpatch.pl to improve code readibility: Alignment should match open parenthesis. This involved shortening the name of tsl2x7x_als_gainadj and tsl2x7x_prx_gainadj to tsl2x7x_als_gain and tsl2x7x_prx_gain respectively. This also required removing the ch0lux and ch1lux local variables in order to get the line short enough. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 17 - 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index 6cc89cd6505e..886be9aa3c0f 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -243,14 +243,14 @@ static const struct tsl2x7x_settings tsl2x7x_default_settings = { .prox_pulse_count = 8 }; -static const s16 tsl2X7X_als_gainadj[] = { +static const s16 tsl2x7x_als_gain[] = { 1, 8, 16, 120 }; -static const s16 tsl2X7X_prx_gainadj[] = { +static const s16 tsl2x7x_prx_gain[] = { 1, 2, 4, @@ -384,11 +384,10 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev) if (p->ratio == 0) { lux = 0; } else { - ch0lux = DIV_ROUND_UP(ch0 * p->ch0, - tsl2X7X_als_gainadj[chip->settings.als_gain]); - ch1lux = DIV_ROUND_UP(ch1 * p->ch1, - tsl2X7X_als_gainadj[chip->settings.als_gain]); - lux = ch0lux - ch1lux; + lux = DIV_ROUND_UP(ch0 * p->ch0, + tsl2x7x_als_gain[chip->settings.als_gain]) - + DIV_ROUND_UP(ch1 * p->ch1, + tsl2x7x_als_gain[chip->settings.als_gain]); } /* note: lux is 31 bit max at this point */ @@ -1263,9 +1262,9 @@ static int tsl2x7x_read_raw(struct iio_dev *indio_dev, break; case IIO_CHAN_INFO_CALIBSCALE: if (chan->type == IIO_LIGHT) - *val = tsl2X7X_als_gainadj[chip->settings.als_gain]; + *val = tsl2x7x_als_gain[chip->settings.als_gain]; else - *val = tsl2X7X_prx_gainadj[chip->settings.prox_gain]; + *val = tsl2x7x_prx_gain[chip->settings.prox_gain]; ret = IIO_VAL_INT; break; case IIO_CHAN_INFO_CALIBBIAS: -- 2.13.6 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 07/13] staging: iio: tsl2x7x: remove unnecessary parentheses
This patch fixes the error 'Unnecessary parentheses around 'XXX' from checkpatch.pl. It also fixes several other places with unnecessary parentheses that checkpatch.pl did not detect. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 16 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index 80968dd456a0..6cc89cd6505e 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -348,9 +348,9 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev) /* clear any existing interrupt status */ ret = i2c_smbus_write_byte(chip->client, - (TSL2X7X_CMD_REG | + TSL2X7X_CMD_REG | TSL2X7X_CMD_SPL_FN | - TSL2X7X_CMD_ALS_INT_CLR)); + TSL2X7X_CMD_ALS_INT_CLR); if (ret < 0) { dev_err(&chip->client->dev, "i2c_write_command failed - err = %d\n", ret); @@ -364,7 +364,7 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev) chip->als_cur_info.als_ch0 = ch0; chip->als_cur_info.als_ch1 = ch1; - if ((ch0 >= chip->als_saturation) || (ch1 >= chip->als_saturation)) { + if (ch0 >= chip->als_saturation || ch1 >= chip->als_saturation) { lux = TSL2X7X_LUX_CALC_OVER_FLOW; goto return_max; } @@ -697,14 +697,14 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev) dev_info(&chip->client->dev, "Setting Up Interrupt(s)\n"); reg_val = TSL2X7X_CNTL_PWR_ON | TSL2X7X_CNTL_ADC_ENBL; - if ((chip->settings.interrupts_en == 0x20) || - (chip->settings.interrupts_en == 0x30)) + if (chip->settings.interrupts_en == 0x20 || + chip->settings.interrupts_en == 0x30) reg_val |= TSL2X7X_CNTL_PROX_DET_ENBL; reg_val |= chip->settings.interrupts_en; ret = i2c_smbus_write_byte_data(chip->client, - (TSL2X7X_CMD_REG | - TSL2X7X_CNTRL), reg_val); + TSL2X7X_CMD_REG | TSL2X7X_CNTRL, + reg_val); if (ret < 0) dev_err(&chip->client->dev, "%s: failed in tsl2x7x_IOCTL_INT_SET.\n", @@ -1721,7 +1721,7 @@ static int tsl2x7x_probe(struct i2c_client *clientp, return -EINVAL; } - ret = i2c_smbus_write_byte(clientp, (TSL2X7X_CMD_REG | TSL2X7X_CNTRL)); + ret = i2c_smbus_write_byte(clientp, TSL2X7X_CMD_REG | TSL2X7X_CNTRL); if (ret < 0) { dev_err(&clientp->dev, "write to cmd reg failed. err = %d\n", ret); -- 2.13.6 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 11/13] staging: iio: tsl2x7x: fix alignment of break statements
Correct the alignment of the break statements to match the alignment of the rest of the code within the case statements. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index bb9fb60509cf..f12ab1239a46 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -466,7 +466,7 @@ static int tsl2x7x_get_prox(struct iio_dev *indio_dev) case tmd2771: if (!(ret & TSL2X7X_STA_ADC_VALID)) goto prox_poll_err; - break; + break; case tsl2572: case tsl2672: case tmd2672: @@ -474,7 +474,7 @@ static int tsl2x7x_get_prox(struct iio_dev *indio_dev) case tmd2772: if (!(ret & TSL2X7X_STA_PRX_VALID)) goto prox_poll_err; - break; + break; } for (i = 0; i < 2; i++) { -- 2.13.6 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 04/13] staging: iio: tsl2x7x: remove unnecessary struct iio_dev definition
tsl2x7x.h has a blank definition for 'struct iio_dev' that is not needed. This patch removes that definition. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.h b/drivers/staging/iio/light/tsl2x7x.h index a216c6943a84..df00f2ec1719 100644 --- a/drivers/staging/iio/light/tsl2x7x.h +++ b/drivers/staging/iio/light/tsl2x7x.h @@ -23,8 +23,6 @@ #define __TSL2X7X_H #include -struct iio_dev; - struct tsl2x7x_lux { unsigned int ratio; unsigned int ch0; -- 2.13.6 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 01/13] staging: iio: tsl2x7x: migrate *_thresh_period sysfs attributes to iio_event_spec
The sysfs attributes in_intensity0_thresh_period and in_proximity0_thresh_period are currently directly created by the driver. This patch migrates the creation of these sysfs attributes from the driver to using the IIO core via iio_event_spec. Signed-off-by: Brian Masney --- Changes since v1: - Use IIO_EV_DIR_EITHER instead of IIO_EV_DIR_NONE drivers/staging/iio/light/tsl2x7x.c | 196 ++-- 1 file changed, 52 insertions(+), 144 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index e6a71f5fc9cb..2dd8c502fd7a 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -932,108 +932,6 @@ static ssize_t in_illuminance0_target_input_store(struct device *dev, return len; } -/* persistence settings */ -static ssize_t in_intensity0_thresh_period_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev)); - int y, z, filter_delay; - - /* Determine integration time */ - y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->settings.als_time) + 1; - z = y * TSL2X7X_MIN_ITIME; - filter_delay = z * (chip->settings.persistence & 0x0F); - y = filter_delay / 1000; - z = filter_delay % 1000; - - return snprintf(buf, PAGE_SIZE, "%d.%03d\n", y, z); -} - -static ssize_t in_intensity0_thresh_period_store(struct device *dev, -struct device_attribute *attr, -const char *buf, size_t len) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct tsl2X7X_chip *chip = iio_priv(indio_dev); - struct tsl2x7x_parse_result result; - int y, z, filter_delay; - int ret; - - ret = iio_str_to_fixpoint(buf, 100, &result.integer, &result.fract); - if (ret) - return ret; - - y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->settings.als_time) + 1; - z = y * TSL2X7X_MIN_ITIME; - - filter_delay = - DIV_ROUND_UP((result.integer * 1000) + result.fract, z); - - chip->settings.persistence &= 0xF0; - chip->settings.persistence |= (filter_delay & 0x0F); - - dev_info(&chip->client->dev, "%s: als persistence = %d", -__func__, filter_delay); - - ret = tsl2x7x_invoke_change(indio_dev); - if (ret < 0) - return ret; - - return IIO_VAL_INT_PLUS_MICRO; -} - -static ssize_t in_proximity0_thresh_period_show(struct device *dev, -struct device_attribute *attr, -char *buf) -{ - struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev)); - int y, z, filter_delay; - - /* Determine integration time */ - y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->settings.prx_time) + 1; - z = y * TSL2X7X_MIN_ITIME; - filter_delay = z * ((chip->settings.persistence & 0xF0) >> 4); - y = filter_delay / 1000; - z = filter_delay % 1000; - - return snprintf(buf, PAGE_SIZE, "%d.%03d\n", y, z); -} - -static ssize_t in_proximity0_thresh_period_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct tsl2X7X_chip *chip = iio_priv(indio_dev); - struct tsl2x7x_parse_result result; - int y, z, filter_delay; - int ret; - - ret = iio_str_to_fixpoint(buf, 100, &result.integer, &result.fract); - if (ret) - return ret; - - y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->settings.prx_time) + 1; - z = y * TSL2X7X_MIN_ITIME; - - filter_delay = - DIV_ROUND_UP((result.integer * 1000) + result.fract, z); - - chip->settings.persistence &= 0x0F; - chip->settings.persistence |= ((filter_delay << 4) & 0xF0); - - dev_info(&chip->client->dev, "%s: prox persistence = %d", -__func__, filter_delay); - - ret = tsl2x7x_invoke_change(indio_dev); - if (ret < 0) - return ret; - - - return IIO_VAL_INT_PLUS_MICRO; -} - static ssize_t in_illuminance0_calibrate_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) @@ -1198,7 +1096,8 @@ static int tsl2x7x_write_event_value(struct iio_dev *indio_dev, int val, int val2) { struct tsl2X7X_chip *chip = iio_priv(indio_dev); - int ret = -EINVAL; +
[PATCH 05/13] staging: iio: tsl2x7x: changed #defines to be aligned on the same column
Some of the existing #defines have tabs between the name, and the value, while others have spaces. The alignment of the values mostly has a consistent layout, but there are some that don't. Change all of the defines so that the name and value is separated by tabs and all of the values start on the same column to increase code readability. This patch also removes the unnecessary parentheses around the value of TSL2X7X_MAX_TIMER_CNT. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 132 ++-- 1 file changed, 66 insertions(+), 66 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index d407c3ad7e2f..3a3340aadc1a 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -29,98 +29,98 @@ #include "tsl2x7x.h" /* Cal defs*/ -#define PROX_STAT_CAL0 -#define PROX_STAT_SAMP 1 -#define MAX_SAMPLES_CAL 200 +#define PROX_STAT_CAL 0 +#define PROX_STAT_SAMP 1 +#define MAX_SAMPLES_CAL200 /* TSL2X7X Device ID */ -#define TRITON_ID0x00 -#define SWORDFISH_ID 0x30 -#define HALIBUT_ID 0x20 +#define TRITON_ID 0x00 +#define SWORDFISH_ID 0x30 +#define HALIBUT_ID 0x20 /* Lux calculation constants */ -#define TSL2X7X_LUX_CALC_OVER_FLOW 65535 +#define TSL2X7X_LUX_CALC_OVER_FLOW 65535 /* TAOS Register definitions - note: * depending on device, some of these register are not used and the * register address is benign. */ /* 2X7X register offsets */ -#define TSL2X7X_MAX_CONFIG_REG 16 +#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_MINTHRESHLO0X04 -#define TSL2X7X_ALS_MINTHRESHHI0X05 -#define TSL2X7X_ALS_MAXTHRESHLO0X06 -#define TSL2X7X_ALS_MAXTHRESHHI0X07 -#define TSL2X7X_PRX_MINTHRESHLO0X08 -#define TSL2X7X_PRX_MINTHRESHHI0X09 -#define TSL2X7X_PRX_MAXTHRESHLO0X0A -#define TSL2X7X_PRX_MAXTHRESHHI0X0B -#define TSL2X7X_PERSISTENCE0x0C -#define TSL2X7X_PRX_CONFIG 0x0D -#define TSL2X7X_PRX_COUNT 0x0E -#define TSL2X7X_GAIN 0x0F -#define TSL2X7X_NOTUSED0x10 -#define TSL2X7X_REVID 0x11 -#define TSL2X7X_CHIPID 0x12 -#define TSL2X7X_STATUS 0x13 -#define TSL2X7X_ALS_CHAN0LO0x14 -#define TSL2X7X_ALS_CHAN0HI0x15 -#define TSL2X7X_ALS_CHAN1LO0x16 -#define TSL2X7X_ALS_CHAN1HI0x17 -#define TSL2X7X_PRX_LO 0x18 -#define TSL2X7X_PRX_HI 0x19 +#define TSL2X7X_CNTRL 0x00 +#define TSL2X7X_ALS_TIME 0X01 +#define TSL2X7X_PRX_TIME 0x02 +#define TSL2X7X_WAIT_TIME 0x03 +#define TSL2X7X_ALS_MINTHRESHLO0X04 +#define TSL2X7X_ALS_MINTHRESHHI0X05 +#define TSL2X7X_ALS_MAXTHRESHLO0X06 +#define TSL2X7X_ALS_MAXTHRESHHI0X07 +#define TSL2X7X_PRX_MINTHRESHLO0X08 +#define TSL2X7X_PRX_MINTHRESHHI0X09 +#define TSL2X7X_PRX_MAXTHRESHLO0X0A +#define TSL2X7X_PRX_MAXTHRESHHI0X0B +#define TSL2X7X_PERSISTENCE0x0C +#define TSL2X7X_PRX_CONFIG 0x0D +#define TSL2X7X_PRX_COUNT 0x0E +#define TSL2X7X_GAIN 0x0F +#define TSL2X7X_NOTUSED0x10 +#define TSL2X7X_REVID 0x11 +#define TSL2X7X_CHIPID 0x12 +#define TSL2X7X_STATUS 0x13 +#define TSL2X7X_ALS_CHAN0LO0x14 +#define TSL2X7X_ALS_CHAN0HI0x15 +#define TSL2X7X_ALS_CHAN1LO0x16 +#define TSL2X7X_ALS_CHAN1HI0x17 +#define TSL2X7X_PRX_LO 0x18 +#define TSL2X7X_PRX_HI 0x19 /* tsl2X7X cmd reg masks */ -#define TSL2X7X_CMD_REG0x80 -#define TSL2X7X_CMD_SPL_FN 0x60 +#define TSL2X7X_CMD_REG0x80 +#define TSL2X7X_CMD_SPL_FN 0x60 -#define TSL2X7X_CMD_PROX_INT_CLR 0X05 -#define TSL2X7X_CMD_ALS_INT_CLR0x06 -#define TSL2X7X_CMD_PROXALS_INT_CLR0X07 +#define TSL2X7X_CMD_PROX_INT_CLR 0X05 +#define TSL2X7X_CMD_ALS_INT_CLR0x06 +#define TSL2X7X_CMD_PROXALS_INT_CLR0X07 /* tsl2X7X cntrl reg masks */ -#define TSL2X7X_CNTL_ADC_ENBL 0x02 -#define TSL2X7X_CNTL_PWR_ON0x01 +#define TSL2X7X_CNTL_ADC_ENBL 0x02 +#define TSL2X7X_CNTL_PWR_ON0x01 /* tsl2X7X status reg masks */ -#define TSL2X7X_STA_ADC_VALID
[PATCH 00/13] staging: iio: tsl2x7x: staging cleanups
Here are some cleanup patches to work towards eventually moving this driver out of staging. The most interesting changes are converting in_intensity0_thresh_period and in_proximity0_thresh_period to be created by the IIO core instead of directly by the driver. The rest of the changes are trivial code cleanups to improve code readability that will be required for a staging graduation: - Convert in_proximity0_calibscale_available to IIO_CONST_ATTR - Remove unused structures - Sort #includes - Remove unnecessary parentheses - Code alignment cleanups Brian Masney (13): staging: iio: tsl2x7x: migrate *_thresh_period sysfs attributes to iio_event_spec staging: iio: tsl2x7x: remove unused tsl2x7x_parse_result structure staging: iio: tsl2x7x: sort #includes staging: iio: tsl2x7x: remove unnecessary struct iio_dev definition staging: iio: tsl2x7x: changed #defines to be aligned on the same column staging: iio: tsl2x7x: convert in_proximity0_calibscale_available to use IIO_CONST_ATTR staging: iio: tsl2x7x: remove unnecessary parentheses staging: iio: tsl2x7x: correct alignment of parenthesis staging: iio: tsl2x7x: correct alignment of parenthesis staging: iio: tsl2x7x: rename power defines to improve code readability staging: iio: tsl2x7x: fix alignment of break statements staging: iio: tsl2x7x: put function definitions on a single line staging: iio: tsl2x7x: add goto for TSL2X7X_LUX_CALC_OVER_FLOW drivers/staging/iio/light/tsl2x7x.c | 447 ++-- drivers/staging/iio/light/tsl2x7x.h | 2 - 2 files changed, 170 insertions(+), 279 deletions(-) -- 2.13.6 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 10/13] staging: iio: tsl2x7x: rename power defines to improve code readability
The LED power defines are named like TSL2X7X_mAXXX. Rename these values to TSL2X7X_XXX_mA to improve code readability. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index 70007117d985..bb9fb60509cf 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -114,10 +114,10 @@ #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_100_mA 0x00 +#define TSL2X7X_50_mA 0x40 +#define TSL2X7X_25_mA 0x80 +#define TSL2X7X_13_mA 0xD0 #define TSL2X7X_MAX_TIMER_CNT 0xFF #define TSL2X7X_MIN_ITIME 3 @@ -636,7 +636,7 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev) /* Set the gain based on tsl2x7x_settings struct */ chip->tsl2x7x_config[TSL2X7X_GAIN] = chip->settings.als_gain | - (TSL2X7X_mA100 | TSL2X7X_DIODE1) | + (TSL2X7X_100_mA | TSL2X7X_DIODE1) | (chip->settings.prox_gain << 2); /* set chip struct re scaling and saturation */ -- 2.13.6 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 09/13] staging: iio: tsl2x7x: correct alignment of parenthesis
Correct error from checkpatch.pl to improve code readibility: Alignment should match open parenthesis. An unnecessary cast to 'struct tsl2x7x_lux *' was removed and the return value of static definition of in_illuminance0_calibscale_available_show() was put on its own line due to the length of that sysfs attribute. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 35 ++- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index 886be9aa3c0f..70007117d985 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -521,8 +521,8 @@ static void tsl2x7x_defaults(struct tsl2X7X_chip *chip) sizeof(chip->pdata->platform_lux_table)); else memcpy(chip->tsl2x7x_device_lux, - (struct tsl2x7x_lux *)tsl2x7x_default_lux_table_group[chip->id], - TSL2X7X_DEFAULT_TABLE_BYTES); + tsl2x7x_default_lux_table_group[chip->id], + TSL2X7X_DEFAULT_TABLE_BYTES); } /** @@ -867,9 +867,10 @@ static void tsl2x7x_prox_cal(struct iio_dev *indio_dev) tsl2x7x_chip_on(indio_dev); } -static ssize_t in_illuminance0_calibscale_available_show(struct device *dev, - struct device_attribute *attr, - char *buf) +static ssize_t +in_illuminance0_calibscale_available_show(struct device *dev, + struct device_attribute *attr, + char *buf) { struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev)); @@ -891,8 +892,8 @@ static IIO_CONST_ATTR(in_illuminance0_integration_time_available, ".00272 - .696"); static ssize_t in_illuminance0_target_input_show(struct device *dev, - struct device_attribute *attr, - char *buf) +struct device_attribute *attr, +char *buf) { struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev)); @@ -900,8 +901,8 @@ static ssize_t in_illuminance0_target_input_show(struct device *dev, } static ssize_t in_illuminance0_target_input_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len) + struct device_attribute *attr, + const char *buf, size_t len) { struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct tsl2X7X_chip *chip = iio_priv(indio_dev); @@ -922,8 +923,8 @@ static ssize_t in_illuminance0_target_input_store(struct device *dev, } static ssize_t in_illuminance0_calibrate_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len) + struct device_attribute *attr, + const char *buf, size_t len) { struct iio_dev *indio_dev = dev_to_iio_dev(dev); bool value; @@ -943,8 +944,8 @@ static ssize_t in_illuminance0_calibrate_store(struct device *dev, } static ssize_t in_illuminance0_lux_table_show(struct device *dev, -struct device_attribute *attr, -char *buf) + struct device_attribute *attr, + char *buf) { struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev)); int i = 0; @@ -971,8 +972,8 @@ static ssize_t in_illuminance0_lux_table_show(struct device *dev, } static ssize_t in_illuminance0_lux_table_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len) + struct device_attribute *attr, + const char *buf, size_t len) { struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct tsl2X7X_chip *chip = iio_priv(indio_dev); @@ -1013,8 +1014,8 @@ static ssize_t in_illuminance0_lux_table_store(struct device *dev, } static ssize_t in_proximity0_calibrate_store(struct device *dev, -struct device_attribute *attr, -const char *buf, size_t len) +struct device_attribute *attr, +const char *buf, size_t len)
[PATCH 03/13] staging: iio: tsl2x7x: sort #includes
Sort the #include statements for increased code readability. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index 094ab76b5d60..d407c3ad7e2f 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -15,14 +15,14 @@ * more details. */ -#include -#include -#include #include -#include +#include +#include #include -#include +#include #include +#include +#include #include #include #include -- 2.13.6 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 00/13] iio: tsl2x7x: staging cleanups
Here is another round of staging cleanups for this driver mostly based on Jonathon's feedback. We're very close to a staging graduation and I only have a few items remaining on my todo list: - Remove wildcards from the driver name. Jonathan suggested tsl2571. - Don't make the events/ directory available to user space via sysfs if an interrupt pin is not configured. - Go through the newer ALS part numbers on AMS's site and see if there are other part numbers that can be added to this driver. - I found this week an issue with the integration_time sysfs attribute. Hopefully I'll have time to wrap this up next week. Brian Masney (13): staging: iio: tsl2x7x: move integration_time* attributes to IIO_INTENSITY channel staging: iio: tsl2x7x: use GPL-2.0+ SPDX license identifier staging: iio: tsl2x7x: don't return error in IRQ handler staging: iio: tsl2x7x: simplify tsl2x7x_clear_interrupts function staging: iio: tsl2x7x: remove unnecessary chip status checks in suspend/resume staging: iio: tsl2x7x: simplify tsl2x7x_write_interrupt_config return staging: iio: tsl2x7x: simplify device id verification staging: iio: tsl2x7x: add range checking to three sysfs attributes staging: iio: tsl2x7x: move power and diode settings into header file staging: iio: tsl2x7x: rename prx to prox for consistency staging: iio: tsl2x7x: use device defaults for als_time, prox_time and wait_time staging: iio: tsl2x7x: various comment cleanups staging: iio: tsl2x7x: rename prox_config to als_prox_config drivers/staging/iio/light/tsl2x7x.c | 217 ++-- drivers/staging/iio/light/tsl2x7x.h | 81 +++--- 2 files changed, 125 insertions(+), 173 deletions(-) -- 2.14.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 06/13] staging: iio: tsl2x7x: simplify tsl2x7x_write_interrupt_config return
tsl2x7x_write_interrupt_config() has an unnecessary return value check at the end of the function. This patch changes the function to just return the value from the call to tsl2x7x_invoke_change(). Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 7 +-- 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index 8d8af0cf9768..d202bc7e1f4f 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -982,18 +982,13 @@ static int tsl2x7x_write_interrupt_config(struct iio_dev *indio_dev, int val) { struct tsl2X7X_chip *chip = iio_priv(indio_dev); - int ret; if (chan->type == IIO_INTENSITY) chip->settings.als_interrupt_en = val ? true : false; else chip->settings.prox_interrupt_en = val ? true : false; - ret = tsl2x7x_invoke_change(indio_dev); - if (ret < 0) - return ret; - - return 0; + return tsl2x7x_invoke_change(indio_dev); } static int tsl2x7x_write_event_value(struct iio_dev *indio_dev, -- 2.14.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 03/13] staging: iio: tsl2x7x: don't return error in IRQ handler
tsl2x7x_event_handler() could return an error and this could cause the interrupt to remain masked. We shouldn't return an error in the interrupt handler so this patch always returns IRQ_HANDLED. An error will be logged if one occurs. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 6 ++ 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index 9cdcc8c9e812..95a00b965c5e 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -1320,7 +1320,7 @@ static irqreturn_t tsl2x7x_event_handler(int irq, void *private) ret = tsl2x7x_read_status(chip); if (ret < 0) - return ret; + return IRQ_HANDLED; /* What type of interrupt do we need to process */ if (ret & TSL2X7X_STA_PRX_INTR) { @@ -1341,9 +1341,7 @@ static irqreturn_t tsl2x7x_event_handler(int irq, void *private) timestamp); } - ret = tsl2x7x_clear_interrupts(chip, TSL2X7X_CMD_PROXALS_INT_CLR); - if (ret < 0) - return ret; + tsl2x7x_clear_interrupts(chip, TSL2X7X_CMD_PROXALS_INT_CLR); return IRQ_HANDLED; } -- 2.14.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 02/13] staging: iio: tsl2x7x: use GPL-2.0+ SPDX license identifier
The summary text for the GPL is not needed since the SPDX identifier is a legally binding shorthand that can be used instead. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 10 +- drivers/staging/iio/light/tsl2x7x.h | 14 +- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index eeccfbb0eb1f..9cdcc8c9e812 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -5,15 +5,7 @@ * Copyright (c) 2012, TAOS Corporation. * Copyright (c) 2017-2018 Brian Masney * - * 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. + * SPDX-License-Identifier: GPL-2.0+ */ #include diff --git a/drivers/staging/iio/light/tsl2x7x.h b/drivers/staging/iio/light/tsl2x7x.h index d382cdbb976e..992ee2465609 100644 --- a/drivers/staging/iio/light/tsl2x7x.h +++ b/drivers/staging/iio/light/tsl2x7x.h @@ -4,19 +4,7 @@ * * Copyright (c) 2012, 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. + * SPDX-License-Identifier: GPL-2.0+ */ #ifndef __TSL2X7X_H -- 2.14.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 01/13] staging: iio: tsl2x7x: move integration_time* attributes to IIO_INTENSITY channel
The integration_time* attributes are currently associated with the IIO_LIGHT channel but should be associated with the IIO_INTENSITY channel. Directory listing of the sysfs attributes for a TSL2772 with this patch applied: dev events in_illuminance0_calibrate in_illuminance0_calibscale_available in_illuminance0_input in_illuminance0_lux_table in_illuminance0_target_input in_intensity0_calibbias in_intensity0_calibscale in_intensity0_integration_time in_intensity0_integration_time_available in_intensity0_raw in_intensity1_raw in_proximity0_calibrate in_proximity0_calibscale in_proximity0_calibscale_available in_proximity0_raw name of_node power subsystem uevent Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 20 ++-- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index 9991b0483956..eeccfbb0eb1f 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -827,7 +827,7 @@ in_illuminance0_calibscale_available_show(struct device *dev, static IIO_CONST_ATTR(in_proximity0_calibscale_available, "1 2 4 8"); -static IIO_CONST_ATTR(in_illuminance0_integration_time_available, +static IIO_CONST_ATTR(in_intensity0_integration_time_available, ".00272 - .696"); static ssize_t in_illuminance0_target_input_show(struct device *dev, @@ -1358,7 +1358,7 @@ static irqreturn_t tsl2x7x_event_handler(int irq, void *private) static struct attribute *tsl2x7x_ALS_device_attrs[] = { &dev_attr_in_illuminance0_calibscale_available.attr, - &iio_const_attr_in_illuminance0_integration_time_available + &iio_const_attr_in_intensity0_integration_time_available .dev_attr.attr, &dev_attr_in_illuminance0_target_input.attr, &dev_attr_in_illuminance0_calibrate.attr, @@ -1373,7 +1373,7 @@ static struct attribute *tsl2x7x_PRX_device_attrs[] = { static struct attribute *tsl2x7x_ALSPRX_device_attrs[] = { &dev_attr_in_illuminance0_calibscale_available.attr, - &iio_const_attr_in_illuminance0_integration_time_available + &iio_const_attr_in_intensity0_integration_time_available .dev_attr.attr, &dev_attr_in_illuminance0_target_input.attr, &dev_attr_in_illuminance0_calibrate.attr, @@ -1389,7 +1389,7 @@ static struct attribute *tsl2x7x_PRX2_device_attrs[] = { static struct attribute *tsl2x7x_ALSPRX2_device_attrs[] = { &dev_attr_in_illuminance0_calibscale_available.attr, - &iio_const_attr_in_illuminance0_integration_time_available + &iio_const_attr_in_intensity0_integration_time_available .dev_attr.attr, &dev_attr_in_illuminance0_target_input.attr, &dev_attr_in_illuminance0_calibrate.attr, @@ -1489,13 +1489,13 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = { .type = IIO_LIGHT, .indexed = 1, .channel = 0, - .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | - BIT(IIO_CHAN_INFO_INT_TIME), + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), }, { .type = IIO_INTENSITY, .indexed = 1, .channel = 0, .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_INT_TIME) | BIT(IIO_CHAN_INFO_CALIBSCALE) | BIT(IIO_CHAN_INFO_CALIBBIAS), .event_spec = tsl2x7x_events, @@ -1529,13 +1529,13 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = { .type = IIO_LIGHT, .indexed = 1, .channel = 0, - .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | - BIT(IIO_CHAN_INFO_INT_TIME), + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), }, { .type = IIO_INTENSITY, .indexed = 1, .channel = 0, .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_INT_TIME) | BIT(IIO_CHAN_INFO_CALIBSCALE) | BIT(IIO_CHAN_INFO_CALIBBIAS), .event_spec = tsl2x7x_events, @@ -1578,13 +1578,13 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = { .type = IIO_LIGHT, .indexed = 1, .channel = 0, - .info_mask_separate =
[PATCH 07/13] staging: iio: tsl2x7x: simplify device id verification
This patch renames tsl2x7x_device_id() to tsl2x7x_device_id_verif(), removes the unnecessary pointer on the id parameter, and only calls the verification function once. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 11 +-- 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index d202bc7e1f4f..56730baea927 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -1277,22 +1277,22 @@ static DEVICE_ATTR_WO(in_proximity0_calibrate); static DEVICE_ATTR_RW(in_illuminance0_lux_table); /* Use the default register values to identify the Taos device */ -static int tsl2x7x_device_id(int *id, int target) +static int tsl2x7x_device_id_verif(int id, int target) { switch (target) { case tsl2571: case tsl2671: case tsl2771: - return (*id & 0xf0) == TRITON_ID; + return (id & 0xf0) == TRITON_ID; case tmd2671: case tmd2771: - return (*id & 0xf0) == HALIBUT_ID; + return (id & 0xf0) == HALIBUT_ID; case tsl2572: case tsl2672: case tmd2672: case tsl2772: case tmd2772: - return (*id & 0xf0) == SWORDFISH_ID; + return (id & 0xf0) == SWORDFISH_ID; } return -EINVAL; @@ -1612,8 +1612,7 @@ static int tsl2x7x_probe(struct i2c_client *clientp, if (ret < 0) return ret; - if ((!tsl2x7x_device_id(&ret, id->driver_data)) || - (tsl2x7x_device_id(&ret, id->driver_data) == -EINVAL)) { + if (tsl2x7x_device_id_verif(ret, id->driver_data) <= 0) { dev_info(&chip->client->dev, "%s: i2c device found does not match expected id\n", __func__); -- 2.14.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 09/13] staging: iio: tsl2x7x: move power and diode settings into header file
The power and diode defines are needed for the platform data so this patch moves the defines out of the .c file and into the header file. A comment for the diode is also cleaned up while this code is touched. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 12 drivers/staging/iio/light/tsl2x7x.h | 12 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index 15bc0af1bb6c..87b99deef7a8 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -103,18 +103,6 @@ #define TSL2X7X_CNTL_PROXPON_ENBL 0x0F #define TSL2X7X_CNTL_INTPROXPON_ENBL 0x2F -/*Prox diode to use */ -#define TSL2X7X_DIODE0 0x01 -#define TSL2X7X_DIODE1 0x02 -#define TSL2X7X_DIODE_BOTH 0x03 - -/* LED Power */ -#define TSL2X7X_100_mA 0x00 -#define TSL2X7X_50_mA 0x01 -#define TSL2X7X_25_mA 0x02 -#define TSL2X7X_13_mA 0x03 -#define TSL2X7X_MAX_TIMER_CNT 0xFF - #define TSL2X7X_MIN_ITIME 3 /* TAOS txx2x7x Device family members */ diff --git a/drivers/staging/iio/light/tsl2x7x.h b/drivers/staging/iio/light/tsl2x7x.h index 992ee2465609..2c96f0b39b1e 100644 --- a/drivers/staging/iio/light/tsl2x7x.h +++ b/drivers/staging/iio/light/tsl2x7x.h @@ -23,6 +23,18 @@ struct tsl2x7x_lux { #define TSL2X7X_DEFAULT_TABLE_BYTES (sizeof(struct tsl2x7x_lux) * \ TSL2X7X_DEF_LUX_TABLE_SZ) +/* Proximity diode to use */ +#define TSL2X7X_DIODE0 0x01 +#define TSL2X7X_DIODE1 0x02 +#define TSL2X7X_DIODE_BOTH 0x03 + +/* LED Power */ +#define TSL2X7X_100_mA 0x00 +#define TSL2X7X_50_mA 0x01 +#define TSL2X7X_25_mA 0x02 +#define TSL2X7X_13_mA 0x03 +#define TSL2X7X_MAX_TIMER_CNT 0xFF + /** * struct tsl2x7x_default_settings - power on defaults unless * overridden by platform data. -- 2.14.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 12/13] staging: iio: tsl2x7x: various comment cleanups
This patch removes several unnecessary comments, changes some comments so that the use as much of the allowable 80 characters as possible, adds the proper whitespace, removes some structure members from the kernel docs that are no longer present, and improves the existing kernel doc information for some existing structure members. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 59 + drivers/staging/iio/light/tsl2x7x.h | 48 +++--- 2 files changed, 51 insertions(+), 56 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index 293810ff11b9..05c0f3d5fac0 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -1,6 +1,6 @@ /* - * Device driver for monitoring ambient light intensity in (lux) - * and proximity detection (prox) within the TAOS TSL2X7X family of devices. + * Device driver for monitoring ambient light intensity in (lux) and proximity + * detection (prox) within the TAOS TSL2X7X family of devices. * * Copyright (c) 2012, TAOS Corporation. * Copyright (c) 2017-2018 Brian Masney @@ -21,7 +21,7 @@ #include #include "tsl2x7x.h" -/* Cal defs*/ +/* Cal defs */ #define PROX_STAT_CAL 0 #define PROX_STAT_SAMP 1 #define MAX_SAMPLES_CAL200 @@ -34,10 +34,11 @@ /* 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 - * register address is benign. +/* + * TAOS Register definitions - Note: depending on device, some of these register + * are not used and the register address is benign. */ + /* 2X7X register offsets */ #define TSL2X7X_MAX_CONFIG_REG 16 @@ -342,15 +343,14 @@ static int tsl2x7x_read_autoinc_regs(struct tsl2X7X_chip *chip, int lower_reg, * @indio_dev: pointer to IIO device * * 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. Array tsl2x7x_device_lux[] - * 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. + * 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. Array tsl2x7x_device_lux[] 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 tsl2x7x_get_lux(struct iio_dev *indio_dev) { @@ -363,7 +363,6 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev) mutex_lock(&chip->als_mutex); 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; @@ -374,7 +373,6 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev) if (ret < 0) goto out_unlock; - /* is data new & valid */ if (!(ret & TSL2X7X_STA_ADC_VALID)) { dev_err(&chip->client->dev, "%s: data not valid yet\n", __func__); @@ -430,12 +428,12 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev) 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. + /* +* 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. -* Use 64 bits to avoid overflow on multiplication. -* Then go back to 32 bits before division to avoid using div_u64(). +* Use 64 bits to avoid overflow on multiplication. Then go back to +* 32 bits before division to avoid using div_u64().
[PATCH 11/13] staging: iio: tsl2x7x: use device defaults for als_time, prox_time and wait_time
This patch changes the defaults of the als_time, prox_time and wait_time to match the defaults according to the TSL2772 datasheet. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index a7b4fcba7935..293810ff11b9 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -201,11 +201,11 @@ static const struct tsl2x7x_lux *tsl2x7x_default_lux_table_group[] = { }; static const struct tsl2x7x_settings tsl2x7x_default_settings = { - .als_time = 219, /* 101 ms */ + .als_time = 255, /* 2.73 ms */ .als_gain = 0, - .prox_time = 254, /* 5.4 ms */ + .prox_time = 255, /* 2.73 ms */ .prox_gain = 0, - .wait_time = 245, + .wait_time = 255, .prox_config = 0, .als_gain_trim = 1000, .als_cal_target = 150, -- 2.14.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 05/13] staging: iio: tsl2x7x: remove unnecessary chip status checks in suspend/resume
tsl2x7x_suspend() and tsl2x7x_resume() both check to see what the current chip status is. These checks are not necessary so this patch removes those checks. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 16 ++-- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index f37fc74b8fbc..8d8af0cf9768 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -1682,27 +1682,15 @@ static int tsl2x7x_probe(struct i2c_client *clientp, static int tsl2x7x_suspend(struct device *dev) { struct iio_dev *indio_dev = dev_get_drvdata(dev); - struct tsl2X7X_chip *chip = iio_priv(indio_dev); - int ret = 0; - - if (chip->tsl2x7x_chip_status == TSL2X7X_CHIP_WORKING) { - ret = tsl2x7x_chip_off(indio_dev); - chip->tsl2x7x_chip_status = TSL2X7X_CHIP_SUSPENDED; - } - return ret; + return tsl2x7x_chip_off(indio_dev); } static int tsl2x7x_resume(struct device *dev) { struct iio_dev *indio_dev = dev_get_drvdata(dev); - struct tsl2X7X_chip *chip = iio_priv(indio_dev); - int ret = 0; - if (chip->tsl2x7x_chip_status == TSL2X7X_CHIP_SUSPENDED) - ret = tsl2x7x_chip_on(indio_dev); - - return ret; + return tsl2x7x_chip_on(indio_dev); } static int tsl2x7x_remove(struct i2c_client *client) -- 2.14.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 04/13] staging: iio: tsl2x7x: simplify tsl2x7x_clear_interrupts function
tsl2x7x_clear_interrupts() takes a reg argument but there are only two callers to this function and both callers pass the same value. Since this function was introduced, interrupts are now working properly for this driver, and several unnecessary calls to tsl2x7x_clear_interrupts() were removed. This patch removes the tsl2x7x_clear_interrupts() function and replaces the two callers with the i2c_smbus_write_byte() call instead. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 32 +++- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index 95a00b965c5e..f37fc74b8fbc 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -271,20 +271,6 @@ static const u8 device_channel_config[] = { ALSPRX2 }; -static int tsl2x7x_clear_interrupts(struct tsl2X7X_chip *chip, int reg) -{ - int ret; - - ret = i2c_smbus_write_byte(chip->client, - TSL2X7X_CMD_REG | TSL2X7X_CMD_SPL_FN | reg); - if (ret < 0) - dev_err(&chip->client->dev, - "%s: failed to clear interrupt status %x: %d\n", - __func__, reg, ret); - - return ret; -} - static int tsl2x7x_read_status(struct tsl2X7X_chip *chip) { int ret; @@ -714,9 +700,15 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev) if (ret < 0) return ret; - ret = tsl2x7x_clear_interrupts(chip, TSL2X7X_CMD_PROXALS_INT_CLR); - if (ret < 0) + ret = i2c_smbus_write_byte(chip->client, + TSL2X7X_CMD_REG | TSL2X7X_CMD_SPL_FN | + TSL2X7X_CMD_PROXALS_INT_CLR); + if (ret < 0) { + dev_err(&chip->client->dev, + "%s: failed to clear interrupt status: %d\n", + __func__, ret); return ret; + } chip->tsl2x7x_chip_status = TSL2X7X_CHIP_WORKING; @@ -1341,7 +1333,13 @@ static irqreturn_t tsl2x7x_event_handler(int irq, void *private) timestamp); } - tsl2x7x_clear_interrupts(chip, TSL2X7X_CMD_PROXALS_INT_CLR); + ret = i2c_smbus_write_byte(chip->client, + TSL2X7X_CMD_REG | TSL2X7X_CMD_SPL_FN | + TSL2X7X_CMD_PROXALS_INT_CLR); + if (ret < 0) + dev_err(&chip->client->dev, + "%s: failed to clear interrupt status: %d\n", + __func__, ret); return IRQ_HANDLED; } -- 2.14.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 10/13] staging: iio: tsl2x7x: rename prx to prox for consistency
The driver mostly uses the 'prox' naming convention for most of the proximity settings, however prx_time and tsl2x7x_prx_gain was present. This patch renames these to prox_time and tsl2x7x_prox_gain for consistency with everything else in the driver. The kernel documentation for prx_gain is corrected to prox_gain so that it matches what is actually in the structure. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 12 ++-- drivers/staging/iio/light/tsl2x7x.h | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index 87b99deef7a8..a7b4fcba7935 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -203,7 +203,7 @@ static const struct tsl2x7x_lux *tsl2x7x_default_lux_table_group[] = { static const struct tsl2x7x_settings tsl2x7x_default_settings = { .als_time = 219, /* 101 ms */ .als_gain = 0, - .prx_time = 254, /* 5.4 ms */ + .prox_time = 254, /* 5.4 ms */ .prox_gain = 0, .wait_time = 245, .prox_config = 0, @@ -230,7 +230,7 @@ static const s16 tsl2x7x_als_gain[] = { 120 }; -static const s16 tsl2x7x_prx_gain[] = { +static const s16 tsl2x7x_prox_gain[] = { 1, 2, 4, @@ -594,7 +594,7 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev) u8 *dev_reg, reg_val; /* Non calculated parameters */ - chip->tsl2x7x_config[TSL2X7X_PRX_TIME] = chip->settings.prx_time; + chip->tsl2x7x_config[TSL2X7X_PRX_TIME] = chip->settings.prox_time; chip->tsl2x7x_config[TSL2X7X_WAIT_TIME] = chip->settings.wait_time; chip->tsl2x7x_config[TSL2X7X_PRX_CONFIG] = chip->settings.prox_config; @@ -1021,7 +1021,7 @@ static int tsl2x7x_write_event_value(struct iio_dev *indio_dev, if (chan->type == IIO_INTENSITY) time = chip->settings.als_time; else - time = chip->settings.prx_time; + time = chip->settings.prox_time; y = (TSL2X7X_MAX_TIMER_CNT - time) + 1; z = y * TSL2X7X_MIN_ITIME; @@ -1090,7 +1090,7 @@ static int tsl2x7x_read_event_value(struct iio_dev *indio_dev, time = chip->settings.als_time; mult = chip->settings.als_persistence; } else { - time = chip->settings.prx_time; + time = chip->settings.prox_time; mult = chip->settings.prox_persistence; } @@ -1153,7 +1153,7 @@ static int tsl2x7x_read_raw(struct iio_dev *indio_dev, if (chan->type == IIO_LIGHT) *val = tsl2x7x_als_gain[chip->settings.als_gain]; else - *val = tsl2x7x_prx_gain[chip->settings.prox_gain]; + *val = tsl2x7x_prox_gain[chip->settings.prox_gain]; ret = IIO_VAL_INT; break; case IIO_CHAN_INFO_CALIBBIAS: diff --git a/drivers/staging/iio/light/tsl2x7x.h b/drivers/staging/iio/light/tsl2x7x.h index 2c96f0b39b1e..408e5a89edb1 100644 --- a/drivers/staging/iio/light/tsl2x7x.h +++ b/drivers/staging/iio/light/tsl2x7x.h @@ -44,9 +44,9 @@ struct tsl2x7x_lux { * aperture effects. * @wait_time: Time between PRX and ALS cycles * in 2.7 periods - * @prx_time: 5.2ms prox integration time - + * @prox_time: 5.2ms prox integration time - * decrease in 2.7ms periods - * @prx_gain: Proximity gain index + * @prox_gain: Proximity gain index * @prox_config: Prox configuration filters. * @als_cal_target:Known external ALS reading for * calibration. @@ -68,7 +68,7 @@ struct tsl2x7x_settings { int als_gain; int als_gain_trim; int wait_time; - int prx_time; + int prox_time; int prox_gain; int prox_config; int als_cal_target; -- 2.14.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 13/13] staging: iio: tsl2x7x: rename prox_config to als_prox_config
The configuration register on the device is represented with the prox_config member on the tsl2x7x_settings structure. According to the TSL2772 data sheet, this register can hold: 1) the proximity drive level, 2) ALS/Proximity long wait, and 3) the ALS gain level. This patch renames prox_config to als_prox_config since ALS settings can be stored here as well. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 7 --- drivers/staging/iio/light/tsl2x7x.h | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index 05c0f3d5fac0..708b2c6bdf4b 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -56,7 +56,7 @@ #define TSL2X7X_PRX_MAXTHRESHLO0X0A #define TSL2X7X_PRX_MAXTHRESHHI0X0B #define TSL2X7X_PERSISTENCE0x0C -#define TSL2X7X_PRX_CONFIG 0x0D +#define TSL2X7X_ALS_PRX_CONFIG 0x0D #define TSL2X7X_PRX_COUNT 0x0E #define TSL2X7X_GAIN 0x0F #define TSL2X7X_NOTUSED0x10 @@ -207,7 +207,7 @@ static const struct tsl2x7x_settings tsl2x7x_default_settings = { .prox_time = 255, /* 2.73 ms */ .prox_gain = 0, .wait_time = 255, - .prox_config = 0, + .als_prox_config = 0, .als_gain_trim = 1000, .als_cal_target = 150, .als_persistence = 1, @@ -594,7 +594,8 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev) /* Non calculated parameters */ chip->tsl2x7x_config[TSL2X7X_PRX_TIME] = chip->settings.prox_time; chip->tsl2x7x_config[TSL2X7X_WAIT_TIME] = chip->settings.wait_time; - chip->tsl2x7x_config[TSL2X7X_PRX_CONFIG] = chip->settings.prox_config; + chip->tsl2x7x_config[TSL2X7X_ALS_PRX_CONFIG] = + chip->settings.als_prox_config; chip->tsl2x7x_config[TSL2X7X_ALS_MINTHRESHLO] = (chip->settings.als_thresh_low) & 0xFF; diff --git a/drivers/staging/iio/light/tsl2x7x.h b/drivers/staging/iio/light/tsl2x7x.h index 85d8fe7a94c8..6e30e71a2127 100644 --- a/drivers/staging/iio/light/tsl2x7x.h +++ b/drivers/staging/iio/light/tsl2x7x.h @@ -48,7 +48,8 @@ struct tsl2x7x_lux { * increments. Total integration time is * (256 - prx_time) * 2.73. * @prox_gain: Index into the tsl2x7x_prx_gain array. - * @prox_config: Prox configuration filters. + * @als_prox_config: The value of the ALS / Proximity configuration + * register. * @als_cal_target:Known external ALS reading for calibration. * @als_persistence: H/W Filters, Number of 'out of limits' ALS readings. * @als_interrupt_en: Enable/Disable ALS interrupts @@ -73,7 +74,7 @@ struct tsl2x7x_settings { int wait_time; int prox_time; int prox_gain; - int prox_config; + int als_prox_config; int als_cal_target; u8 als_persistence; bool als_interrupt_en; -- 2.14.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 08/13] staging: iio: tsl2x7x: add range checking to three sysfs attributes
The sysfs attributes in_illuminance0_target_input, in_illuminance0_calibrate, and in_proximity0_calibrate did not have proper range checking in place so this patch adds the correct range checks. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 25 +++-- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index 56730baea927..15bc0af1bb6c 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -835,9 +835,10 @@ static ssize_t in_illuminance0_target_input_store(struct device *dev, if (kstrtoul(buf, 0, &value)) return -EINVAL; - if (value) - chip->settings.als_cal_target = value; + if (value < 0 || value > 65535) + return -ERANGE; + chip->settings.als_cal_target = value; ret = tsl2x7x_invoke_change(indio_dev); if (ret < 0) return ret; @@ -853,14 +854,12 @@ static ssize_t in_illuminance0_calibrate_store(struct device *dev, bool value; int ret; - if (strtobool(buf, &value)) + if (kstrtobool(buf, &value) || !value) return -EINVAL; - if (value) { - ret = tsl2x7x_als_calibrate(indio_dev); - if (ret < 0) - return ret; - } + ret = tsl2x7x_als_calibrate(indio_dev); + if (ret < 0) + return ret; ret = tsl2x7x_invoke_change(indio_dev); if (ret < 0) @@ -946,14 +945,12 @@ static ssize_t in_proximity0_calibrate_store(struct device *dev, bool value; int ret; - if (strtobool(buf, &value)) + if (kstrtobool(buf, &value) || !value) return -EINVAL; - if (value) { - ret = tsl2x7x_prox_cal(indio_dev); - if (ret < 0) - return ret; - } + ret = tsl2x7x_prox_cal(indio_dev); + if (ret < 0) + return ret; ret = tsl2x7x_invoke_change(indio_dev); if (ret < 0) -- 2.14.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
Re: [PATCH 02/13] staging: iio: tsl2x7x: use GPL-2.0+ SPDX license identifier
On Sat, Apr 21, 2018 at 05:16:38PM +0100, Jonathan Cameron wrote: > On Fri, 20 Apr 2018 20:41:42 -0400 > Brian Masney wrote: > > > The summary text for the GPL is not needed since the SPDX identifier > > is a legally binding shorthand that can be used instead. > > > > Signed-off-by: Brian Masney > I sanity checked against other drivers because I wasn't 100% sure > this wasn't a valid formatting for SPDX. It doesn't seem to be. > Normally convention is > //SPDX... > On the first line of the file. > C style comments also fine, but it needs to be a comment line on it's > own. This is all about making it trivial for automated tools to find. The style that you referenced is the most common style, however I saw quite a few places in the kernel use the style used by this patch so I thought that it may be acceptable. $ grep -r SPDX arch/ drivers/ include/ | grep \* | grep -v ":\/" I'll resubmit the patch next week with hopefully the last bit of cleanups to get this driver out of staging. Brian > > --- > > drivers/staging/iio/light/tsl2x7x.c | 10 +- > > drivers/staging/iio/light/tsl2x7x.h | 14 +- > > 2 files changed, 2 insertions(+), 22 deletions(-) > > > > diff --git a/drivers/staging/iio/light/tsl2x7x.c > > b/drivers/staging/iio/light/tsl2x7x.c > > index eeccfbb0eb1f..9cdcc8c9e812 100644 > > --- a/drivers/staging/iio/light/tsl2x7x.c > > +++ b/drivers/staging/iio/light/tsl2x7x.c > > @@ -5,15 +5,7 @@ > > * Copyright (c) 2012, TAOS Corporation. > > * Copyright (c) 2017-2018 Brian Masney > > * > > - * 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. > > + * SPDX-License-Identifier: GPL-2.0+ > > */ > > > > #include > > diff --git a/drivers/staging/iio/light/tsl2x7x.h > > b/drivers/staging/iio/light/tsl2x7x.h > > index d382cdbb976e..992ee2465609 100644 > > --- a/drivers/staging/iio/light/tsl2x7x.h > > +++ b/drivers/staging/iio/light/tsl2x7x.h > > @@ -4,19 +4,7 @@ > > * > > * Copyright (c) 2012, 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. > > + * SPDX-License-Identifier: GPL-2.0+ > > */ > > > > #ifndef __TSL2X7X_H ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH v2 01/11] staging: iio: tsl2x7x: use GPL-2.0+ SPDX license identifier
The summary text for the GPL is not needed since the SPDX identifier is a legally binding shorthand that can be used instead. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 11 +-- drivers/staging/iio/light/tsl2x7x.h | 15 +-- 2 files changed, 2 insertions(+), 24 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index e65621948cf8..01bff4593640 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -1,19 +1,10 @@ +// SPDX-License-Identifier: GPL-2.0+ /* * Device driver for monitoring ambient light intensity in (lux) and proximity * detection (prox) within the TAOS TSL2X7X family of devices. * * Copyright (c) 2012, TAOS Corporation. * Copyright (c) 2017-2018 Brian Masney - * - * 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. */ #include diff --git a/drivers/staging/iio/light/tsl2x7x.h b/drivers/staging/iio/light/tsl2x7x.h index 91ce8f98982e..8eb7f4749ea7 100644 --- a/drivers/staging/iio/light/tsl2x7x.h +++ b/drivers/staging/iio/light/tsl2x7x.h @@ -1,22 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ /* * 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 - * 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. */ #ifndef __TSL2X7X_H -- 2.14.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH v2 05/11] staging: iio: tsl2x7x: use IIO_CONST_ATTR for calibscale_available
The in_intensity0_calibscale_available sysfs attribute has code that checks the device type to determine which calibration scales are available. This check is not necessary since all of the supported ALS device types use the scales 1 8 16 120. This patch converts the sysfs attribute to use IIO_CONST_ATTR. The following device datasheets were checked: tsl2571, tsl2771, tmd2771, tsl2572, tsl2772, tmd2772. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 46 - 1 file changed, 4 insertions(+), 42 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index 9aee04fb4168..cf582a2e3633 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -776,24 +776,7 @@ static int tsl2x7x_prox_cal(struct iio_dev *indio_dev) return tsl2x7x_invoke_change(indio_dev); } -static ssize_t -in_intensity0_calibscale_available_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev)); - - switch (chip->id) { - case tsl2571: - case tsl2671: - case tmd2671: - case tsl2771: - case tmd2771: - return snprintf(buf, PAGE_SIZE, "%s\n", "1 8 16 128"); - } - - return snprintf(buf, PAGE_SIZE, "%s\n", "1 8 16 120"); -} +static IIO_CONST_ATTR(in_intensity0_calibscale_available, "1 8 16 120"); static IIO_CONST_ATTR(in_proximity0_calibscale_available, "1 2 4 8"); @@ -1190,25 +1173,6 @@ static int tsl2x7x_write_raw(struct iio_dev *indio_dev, chip->settings.als_gain = 2; break; case 120: - switch (chip->id) { - case tsl2572: - case tsl2672: - case tmd2672: - case tsl2772: - case tmd2772: - return -EINVAL; - } - chip->settings.als_gain = 3; - break; - case 128: - switch (chip->id) { - case tsl2571: - case tsl2671: - case tmd2671: - case tsl2771: - case tmd2771: - return -EINVAL; - } chip->settings.als_gain = 3; break; default: @@ -1247,8 +1211,6 @@ static int tsl2x7x_write_raw(struct iio_dev *indio_dev, return tsl2x7x_invoke_change(indio_dev); } -static DEVICE_ATTR_RO(in_intensity0_calibscale_available); - static DEVICE_ATTR_RW(in_illuminance0_target_input); static DEVICE_ATTR_WO(in_illuminance0_calibrate); @@ -1321,7 +1283,7 @@ static irqreturn_t tsl2x7x_event_handler(int irq, void *private) } static struct attribute *tsl2x7x_ALS_device_attrs[] = { - &dev_attr_in_intensity0_calibscale_available.attr, + &iio_const_attr_in_intensity0_calibscale_available.dev_attr.attr, &iio_const_attr_in_intensity0_integration_time_available.dev_attr.attr, &dev_attr_in_illuminance0_target_input.attr, &dev_attr_in_illuminance0_calibrate.attr, @@ -1335,7 +1297,7 @@ static struct attribute *tsl2x7x_PRX_device_attrs[] = { }; static struct attribute *tsl2x7x_ALSPRX_device_attrs[] = { - &dev_attr_in_intensity0_calibscale_available.attr, + &iio_const_attr_in_intensity0_calibscale_available.dev_attr.attr, &iio_const_attr_in_intensity0_integration_time_available.dev_attr.attr, &dev_attr_in_illuminance0_target_input.attr, &dev_attr_in_illuminance0_calibrate.attr, @@ -1350,7 +1312,7 @@ static struct attribute *tsl2x7x_PRX2_device_attrs[] = { }; static struct attribute *tsl2x7x_ALSPRX2_device_attrs[] = { - &dev_attr_in_intensity0_calibscale_available.attr, + &iio_const_attr_in_intensity0_calibscale_available.dev_attr.attr, &iio_const_attr_in_intensity0_integration_time_available.dev_attr.attr, &dev_attr_in_illuminance0_target_input.attr, &dev_attr_in_illuminance0_calibrate.attr, -- 2.14.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH v2 03/11] staging: iio: tsl2x7x: don't setup event handlers if interrupts are not configured
The driver would expose to userspace the events directory even if the interrupts were not configured. This patch changes the driver so that the events directory is not exposed to user space if interrupts are not configured. This patch also corrects the indentation of the chan_table_elements and info structure members. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 130 +++- 1 file changed, 112 insertions(+), 18 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index b4d77f65ca12..7e8db5178a2c 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -134,8 +134,9 @@ struct tsl2x7x_als_info { struct tsl2x7x_chip_info { int chan_table_elements; - struct iio_chan_specchannel[4]; - const struct iio_info *info; + struct iio_chan_spec channel_with_events[4]; + struct iio_chan_spec channel_without_events[4]; + const struct iio_info *info; }; struct tsl2X7X_chip { @@ -1447,7 +1448,7 @@ static const struct iio_event_spec tsl2x7x_events[] = { static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = { [ALS] = { - .channel = { + .channel_with_events = { { .type = IIO_LIGHT, .indexed = 1, @@ -1469,11 +1470,31 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = { .channel = 1, }, }, - .chan_table_elements = 3, - .info = &tsl2X7X_device_info[ALS], + .channel_without_events = { + { + .type = IIO_LIGHT, + .indexed = 1, + .channel = 0, + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), + }, { + .type = IIO_INTENSITY, + .indexed = 1, + .channel = 0, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_INT_TIME) | + BIT(IIO_CHAN_INFO_CALIBSCALE) | + BIT(IIO_CHAN_INFO_CALIBBIAS), + }, { + .type = IIO_INTENSITY, + .indexed = 1, + .channel = 1, + }, + }, + .chan_table_elements = 3, + .info = &tsl2X7X_device_info[ALS], }, [PRX] = { - .channel = { + .channel_with_events = { { .type = IIO_PROXIMITY, .indexed = 1, @@ -1483,11 +1504,19 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = { .num_event_specs = ARRAY_SIZE(tsl2x7x_events), }, }, - .chan_table_elements = 1, - .info = &tsl2X7X_device_info[PRX], + .channel_without_events = { + { + .type = IIO_PROXIMITY, + .indexed = 1, + .channel = 0, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + }, + }, + .chan_table_elements = 1, + .info = &tsl2X7X_device_info[PRX], }, [ALSPRX] = { - .channel = { + .channel_with_events = { { .type = IIO_LIGHT, .indexed = 1, @@ -1517,11 +1546,37 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = { .num_event_specs = ARRAY_SIZE(tsl2x7x_events), }, }, - .chan_table_elements = 4, - .info = &tsl2X7X_device_info[ALSPRX], + .channel_without_events = { + { + .type = IIO_LIGHT, + .indexed = 1, + .channel = 0, + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), + }, { + .type = IIO_INTENSITY, + .indexed = 1, + .channel = 0, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_INT_TIME) | + BIT(IIO_CHAN_INFO_CALIBSCALE) | + BIT(IIO_CHAN_INFO_CALIBBIAS), + }, { + .type = IIO_INTENSITY, + .indexed = 1, + .channel = 1, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + }, { +
[PATCH v2 04/11] staging: iio: tsl2x7x: move calibscale_available attribute to IIO_INTENSITY channel
The calibscale_available attribute is currently associated with the IIO_LIGHT channel but should be associated with the IIO_INTENSITY channel. This patch corrects that association and it also corrects lines that were unnecessarily split for the in_intensity0_integration_time sysfs attribute. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 23 ++- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index 7e8db5178a2c..9aee04fb4168 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -777,9 +777,9 @@ static int tsl2x7x_prox_cal(struct iio_dev *indio_dev) } static ssize_t -in_illuminance0_calibscale_available_show(struct device *dev, - struct device_attribute *attr, - char *buf) +in_intensity0_calibscale_available_show(struct device *dev, + struct device_attribute *attr, + char *buf) { struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev)); @@ -1247,7 +1247,7 @@ static int tsl2x7x_write_raw(struct iio_dev *indio_dev, return tsl2x7x_invoke_change(indio_dev); } -static DEVICE_ATTR_RO(in_illuminance0_calibscale_available); +static DEVICE_ATTR_RO(in_intensity0_calibscale_available); static DEVICE_ATTR_RW(in_illuminance0_target_input); @@ -1321,9 +1321,8 @@ static irqreturn_t tsl2x7x_event_handler(int irq, void *private) } static struct attribute *tsl2x7x_ALS_device_attrs[] = { - &dev_attr_in_illuminance0_calibscale_available.attr, - &iio_const_attr_in_intensity0_integration_time_available - .dev_attr.attr, + &dev_attr_in_intensity0_calibscale_available.attr, + &iio_const_attr_in_intensity0_integration_time_available.dev_attr.attr, &dev_attr_in_illuminance0_target_input.attr, &dev_attr_in_illuminance0_calibrate.attr, &dev_attr_in_illuminance0_lux_table.attr, @@ -1336,9 +1335,8 @@ static struct attribute *tsl2x7x_PRX_device_attrs[] = { }; static struct attribute *tsl2x7x_ALSPRX_device_attrs[] = { - &dev_attr_in_illuminance0_calibscale_available.attr, - &iio_const_attr_in_intensity0_integration_time_available - .dev_attr.attr, + &dev_attr_in_intensity0_calibscale_available.attr, + &iio_const_attr_in_intensity0_integration_time_available.dev_attr.attr, &dev_attr_in_illuminance0_target_input.attr, &dev_attr_in_illuminance0_calibrate.attr, &dev_attr_in_illuminance0_lux_table.attr, @@ -1352,9 +1350,8 @@ static struct attribute *tsl2x7x_PRX2_device_attrs[] = { }; static struct attribute *tsl2x7x_ALSPRX2_device_attrs[] = { - &dev_attr_in_illuminance0_calibscale_available.attr, - &iio_const_attr_in_intensity0_integration_time_available - .dev_attr.attr, + &dev_attr_in_intensity0_calibscale_available.attr, + &iio_const_attr_in_intensity0_integration_time_available.dev_attr.attr, &dev_attr_in_illuminance0_target_input.attr, &dev_attr_in_illuminance0_calibrate.attr, &dev_attr_in_illuminance0_lux_table.attr, -- 2.14.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH v2 02/11] staging: iio: tsl2x7x: add range checking to three sysfs attributes
The sysfs attributes in_illuminance0_target_input, in_illuminance0_calibrate, and in_proximity0_calibrate did not have proper range checking in place so this patch adds the correct range checks. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 28 +++- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index 01bff4593640..b4d77f65ca12 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -814,15 +814,13 @@ static ssize_t in_illuminance0_target_input_store(struct device *dev, { struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct tsl2X7X_chip *chip = iio_priv(indio_dev); - unsigned long value; + u16 value; int ret; - if (kstrtoul(buf, 0, &value)) + if (kstrtou16(buf, 0, &value)) return -EINVAL; - if (value) - chip->settings.als_cal_target = value; - + chip->settings.als_cal_target = value; ret = tsl2x7x_invoke_change(indio_dev); if (ret < 0) return ret; @@ -838,14 +836,12 @@ static ssize_t in_illuminance0_calibrate_store(struct device *dev, bool value; int ret; - if (strtobool(buf, &value)) + if (kstrtobool(buf, &value) || !value) return -EINVAL; - if (value) { - ret = tsl2x7x_als_calibrate(indio_dev); - if (ret < 0) - return ret; - } + ret = tsl2x7x_als_calibrate(indio_dev); + if (ret < 0) + return ret; ret = tsl2x7x_invoke_change(indio_dev); if (ret < 0) @@ -932,14 +928,12 @@ static ssize_t in_proximity0_calibrate_store(struct device *dev, bool value; int ret; - if (strtobool(buf, &value)) + if (kstrtobool(buf, &value) || !value) return -EINVAL; - if (value) { - ret = tsl2x7x_prox_cal(indio_dev); - if (ret < 0) - return ret; - } + ret = tsl2x7x_prox_cal(indio_dev); + if (ret < 0) + return ret; ret = tsl2x7x_invoke_change(indio_dev); if (ret < 0) -- 2.14.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH v2 00/11] staging: iio: tsl2x7x: move out of staging
Here is a patch set that should hopefully be the last of the changes required for a staging graduation. Changes since v1: - Use correct syntax for SPDX license identifier - Use kstrtou16 for range checking - Correct integration time sysfs attribute. This fix required correcting all of the equations and coefficients. Fortunately TAOS / AMS has really good documentation available. - Rename driver from tsl2x7x to tsl2772. Datasheet for TSL2772 https://ams.com/eng/content/download/291503/1066377/file/TSL2772_DS000181_2-00.pdf Other datasheets: ALS only - https://ams.com/eng/content/download/250043/975277/file/TSL2571_DS000114_2-00.pdf - https://ams.com/eng/content/download/291224/1065822/file/TSL2572_DS000178_2-00.pdf Proximity Only - https://ams.com/eng/content/download/250323/976177/file/TSL2671_DS000111_2-00.pdf - https://ams.com/eng/content/download/250304/976107/file/TMD2671_DS000176_2-00.pdf - https://ams.com/eng/content/download/291443/1066277/file/TSL2672_Datasheet_EN_v1.pdf - https://ams.com/eng/content/download/364923/1210537/file/TMD2672_Datasheet_EN_v1.pdf ALS / Proximity - https://ams.com/eng/content/download/250264/976045/file/TSL2771_DS000105_3-00.pdf - https://ams.com/eng/content/download/250283/976077/file/TMD2771_DS000177_2-00.pdf - https://ams.com/eng/content/download/365023/1210677/file/TMD2772-E.pdf Brian Masney (11): staging: iio: tsl2x7x: use GPL-2.0+ SPDX license identifier staging: iio: tsl2x7x: add range checking to three sysfs attributes staging: iio: tsl2x7x: don't setup event handlers if interrupts are not configured staging: iio: tsl2x7x: move calibscale_available attribute to IIO_INTENSITY channel staging: iio: tsl2x7x: use IIO_CONST_ATTR for calibscale_available staging: iio: tsl2x7x: correct integration time and lux equation staging: iio: tsl2x7x: support 2.72 and 2.73 ALS increments staging: iio: tsl2x7x: add device ids for code readability staging: iio: tsl2x7x: correct IIO_EV_INFO_PERIOD values staging: iio: tsl2x7x: rename driver to tsl2772 staging: iio: tsl2x7x/tsl2772: move out of staging drivers/iio/light/Kconfig |8 + drivers/iio/light/Makefile |1 + .../iio/light/tsl2x7x.c => iio/light/tsl2772.c}| 1137 ++-- drivers/staging/iio/Kconfig|1 - drivers/staging/iio/Makefile |1 - drivers/staging/iio/light/Kconfig | 14 - drivers/staging/iio/light/Makefile |5 - .../linux/platform_data/tsl2772.h | 65 +- 8 files changed, 631 insertions(+), 601 deletions(-) rename drivers/{staging/iio/light/tsl2x7x.c => iio/light/tsl2772.c} (50%) delete mode 100644 drivers/staging/iio/light/Kconfig delete mode 100644 drivers/staging/iio/light/Makefile rename drivers/staging/iio/light/tsl2x7x.h => include/linux/platform_data/tsl2772.h (58%) -- 2.14.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH v2 07/11] staging: iio: tsl2x7x: support 2.72 and 2.73 ALS increments
The driver assumed that the ALS increment was 2.72 ms, and the upper range was 696 ms. Some other supported devices use 2.73 ms - 699 ms. This patch adds support for the multiple ranges. Signed-off-by: Brian Masney --- I debated whether or not this change should even be included. I feel pretty confident that I can cleanly fold the tsl2583 driver into this driver once the staging graduation is done. Those devices have an ALS range of 2.7 ms - 688.5 ms. drivers/staging/iio/light/tsl2x7x.c | 50 + 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index 9b32054713fb..e3e37501829f 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -209,9 +209,9 @@ static const struct tsl2x7x_lux *tsl2x7x_default_lux_table_group[] = { }; static const struct tsl2x7x_settings tsl2x7x_default_settings = { - .als_time = 255, /* 2.73 ms */ + .als_time = 255, /* 2.72 / 2.73 ms */ .als_gain = 0, - .prox_time = 255, /* 2.73 ms */ + .prox_time = 255, /* 2.72 / 2.73 ms */ .prox_gain = 0, .wait_time = 255, .als_prox_config = 0, @@ -245,6 +245,24 @@ static const s16 tsl2x7x_prox_gain[] = { 8 }; +struct tsl2x7x_int_time { + int increment_us; + char *display_range; +}; + +static const struct tsl2x7x_int_time tsl2x7x_int_time[] = { + [tsl2571] = { 2720, "0.00272 - 0.696" }, + [tsl2671] = { 2720, "0.00272 - 0.696" }, + [tmd2671] = { 2720, "0.00272 - 0.696" }, + [tsl2771] = { 2720, "0.00272 - 0.696" }, + [tmd2771] = { 2720, "0.00272 - 0.696" }, + [tsl2572] = { 2730, "0.00273 - 0.699" }, + [tsl2672] = { 2730, "0.00273 - 0.699" }, + [tmd2672] = { 2730, "0.00273 - 0.699" }, + [tsl2772] = { 2730, "0.00273 - 0.699" }, + [tmd2772] = { 2730, "0.00273 - 0.699" }, +}; + /* Channel variations */ enum { ALS, @@ -626,7 +644,7 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev) /* set chip time scaling and saturation */ als_count = 256 - chip->settings.als_time; - als_time_us = als_count * 2720; + als_time_us = als_count * tsl2x7x_int_time[chip->id].increment_us; chip->als_saturation = als_count * 768; /* 75% of full scale */ chip->als_gain_time_scale = als_time_us * tsl2x7x_als_gain[chip->settings.als_gain]; @@ -764,8 +782,16 @@ static IIO_CONST_ATTR(in_intensity0_calibscale_available, "1 8 16 120"); static IIO_CONST_ATTR(in_proximity0_calibscale_available, "1 2 4 8"); -static IIO_CONST_ATTR(in_intensity0_integration_time_available, - ".00272 - .696"); +static ssize_t +in_intensity0_integration_time_available_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev)); + + return snprintf(buf, PAGE_SIZE, "%s\n", + tsl2x7x_int_time[chip->id].display_range); +} static ssize_t in_illuminance0_target_input_show(struct device *dev, struct device_attribute *attr, @@ -1124,7 +1150,8 @@ static int tsl2x7x_read_raw(struct iio_dev *indio_dev, break; case IIO_CHAN_INFO_INT_TIME: *val = 0; - *val2 = (256 - chip->settings.als_time) * 2720; + *val2 = (256 - chip->settings.als_time) * + tsl2x7x_int_time[chip->id].increment_us; ret = IIO_VAL_INT_PLUS_MICRO; break; default: @@ -1184,7 +1211,8 @@ static int tsl2x7x_write_raw(struct iio_dev *indio_dev, chip->settings.als_gain_trim = val; break; case IIO_CHAN_INFO_INT_TIME: - chip->settings.als_time = 256 - (val2 / 2720); + chip->settings.als_time = 256 - + (val2 / tsl2x7x_int_time[chip->id].increment_us); break; default: return -EINVAL; @@ -1193,6 +1221,8 @@ static int tsl2x7x_write_raw(struct iio_dev *indio_dev, return tsl2x7x_invoke_change(indio_dev); } +static DEVICE_ATTR_RO(in_intensity0_integration_time_available); + static DEVICE_ATTR_RW(in_illuminance0_target_input); static DEVICE_ATTR_WO(in_illuminance0_calibrate); @@ -1266,7 +1296,7 @@ static irqreturn_t tsl2x7x_event_handler(int irq, void *private) static struct attribute *tsl2x7x_ALS_device_attrs[] = { &iio_const_attr_in_intensity0_calibscale_available.dev_attr.attr, - &iio_const_attr_in_intensity0_integration_time_avai
[PATCH v2 11/11] staging: iio: tsl2x7x/tsl2772: move out of staging
Move the tsl2772 driver out of staging and into mainline. Signed-off-by: Brian Masney --- drivers/iio/light/Kconfig | 8 drivers/iio/light/Makefile | 1 + drivers/{staging => }/iio/light/tsl2772.c | 2 +- drivers/staging/iio/Kconfig| 1 - drivers/staging/iio/Makefile | 1 - drivers/staging/iio/light/Kconfig | 14 -- drivers/staging/iio/light/Makefile | 5 - .../iio/light => include/linux/platform_data}/tsl2772.h| 0 8 files changed, 10 insertions(+), 22 deletions(-) rename drivers/{staging => }/iio/light/tsl2772.c (99%) delete mode 100644 drivers/staging/iio/light/Kconfig delete mode 100644 drivers/staging/iio/light/Makefile rename {drivers/staging/iio/light => include/linux/platform_data}/tsl2772.h (100%) diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig index 074e50657366..c7ef8d1862d6 100644 --- a/drivers/iio/light/Kconfig +++ b/drivers/iio/light/Kconfig @@ -409,6 +409,14 @@ config TSL2583 Provides support for the TAOS tsl2580, tsl2581 and tsl2583 devices. Access ALS data via iio, sysfs. +config TSL2772 + 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. + config TSL4531 tristate "TAOS TSL4531 ambient light sensors" depends on I2C diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile index f1777036d4f8..80943af5d627 100644 --- a/drivers/iio/light/Makefile +++ b/drivers/iio/light/Makefile @@ -40,6 +40,7 @@ obj-$(CONFIG_ST_UVIS25_SPI) += st_uvis25_spi.o obj-$(CONFIG_TCS3414) += tcs3414.o obj-$(CONFIG_TCS3472) += tcs3472.o obj-$(CONFIG_TSL2583) += tsl2583.o +obj-$(CONFIG_TSL2772) += tsl2772.o obj-$(CONFIG_TSL4531) += tsl4531.o obj-$(CONFIG_US5182D) += us5182d.o obj-$(CONFIG_VCNL4000) += vcnl4000.o diff --git a/drivers/staging/iio/light/tsl2772.c b/drivers/iio/light/tsl2772.c similarity index 99% rename from drivers/staging/iio/light/tsl2772.c rename to drivers/iio/light/tsl2772.c index 146527e41969..7ed72c98ce1a 100644 --- a/drivers/staging/iio/light/tsl2772.c +++ b/drivers/iio/light/tsl2772.c @@ -19,7 +19,7 @@ #include #include #include -#include "tsl2772.h" +#include /* Cal defs */ #define PROX_STAT_CAL 0 diff --git a/drivers/staging/iio/Kconfig b/drivers/staging/iio/Kconfig index 8abc1ab3c0c7..ca001510782d 100644 --- a/drivers/staging/iio/Kconfig +++ b/drivers/staging/iio/Kconfig @@ -11,7 +11,6 @@ source "drivers/staging/iio/cdc/Kconfig" source "drivers/staging/iio/frequency/Kconfig" source "drivers/staging/iio/gyro/Kconfig" source "drivers/staging/iio/impedance-analyzer/Kconfig" -source "drivers/staging/iio/light/Kconfig" source "drivers/staging/iio/meter/Kconfig" source "drivers/staging/iio/resolver/Kconfig" source "drivers/staging/iio/trigger/Kconfig" diff --git a/drivers/staging/iio/Makefile b/drivers/staging/iio/Makefile index 455bffc29649..5c168403b873 100644 --- a/drivers/staging/iio/Makefile +++ b/drivers/staging/iio/Makefile @@ -10,7 +10,6 @@ obj-y += cdc/ obj-y += frequency/ obj-y += gyro/ obj-y += impedance-analyzer/ -obj-y += light/ obj-y += meter/ obj-y += resolver/ obj-y += trigger/ diff --git a/drivers/staging/iio/light/Kconfig b/drivers/staging/iio/light/Kconfig deleted file mode 100644 index dfa37386ad2c.. --- a/drivers/staging/iio/light/Kconfig +++ /dev/null @@ -1,14 +0,0 @@ -# -# Light sensors -# -menu "Light sensors" - -config TSL2772 - 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 diff --git a/drivers/staging/iio/light/Makefile b/drivers/staging/iio/light/Makefile deleted file mode 100644 index e7e77a11f02a.. --- a/drivers/staging/iio/light/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -# -# Makefile for industrial I/O Light sensors -# - -obj-$(CONFIG_TSL2772) += tsl2772.o diff --git a/drivers/staging/iio/light/tsl2772.h b/include/linux/platform_data/tsl2772.h similarity index 100% rename from drivers/staging/iio/light/tsl2772.h rename to include/linux/platform_data/tsl2772.h -- 2.14.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH v2 08/11] staging: iio: tsl2x7x: add device ids for code readability
This patch adds the device IDs to the device_channel_config array to improve code readability. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 20 ++-- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index e3e37501829f..39de5e60fd33 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -273,16 +273,16 @@ enum { }; static const u8 device_channel_config[] = { - ALS, - PRX, - PRX, - ALSPRX, - ALSPRX, - ALS, - PRX2, - PRX2, - ALSPRX2, - ALSPRX2 + [tsl2571] = ALS, + [tsl2671] = PRX, + [tmd2671] = PRX, + [tsl2771] = ALSPRX, + [tmd2771] = ALSPRX, + [tsl2572] = ALS, + [tsl2672] = PRX2, + [tmd2672] = PRX2, + [tsl2772] = ALSPRX2, + [tmd2772] = ALSPRX2 }; static int tsl2x7x_read_status(struct tsl2X7X_chip *chip) -- 2.14.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH v2 09/11] staging: iio: tsl2x7x: correct IIO_EV_INFO_PERIOD values
The thresh periods assumed an integration time of 3ms. This patch adds support for the correct integration time (2.72ms or 2.73ms). The code had the ALS filter values as going up to 15, however the values actually went up to 60 since the values scaled in increments of 5 once the persistence value went above 3. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 44 + drivers/staging/iio/light/tsl2x7x.h | 1 - 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index 39de5e60fd33..f912f4bc61c4 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -103,8 +103,6 @@ #define TSL2X7X_CNTL_PROXPON_ENBL 0x0F #define TSL2X7X_CNTL_INTPROXPON_ENBL 0x2F -#define TSL2X7X_MIN_ITIME 3 - /* TAOS txx2x7x Device family members */ enum { tsl2571, @@ -972,7 +970,7 @@ static int tsl2x7x_write_event_value(struct iio_dev *indio_dev, int val, int val2) { struct tsl2X7X_chip *chip = iio_priv(indio_dev); - int ret = -EINVAL, y, z, filter_delay; + int ret = -EINVAL, count, persistence; u8 time; switch (info) { @@ -1011,15 +1009,20 @@ static int tsl2x7x_write_event_value(struct iio_dev *indio_dev, else time = chip->settings.prox_time; - y = (TSL2X7X_MAX_TIMER_CNT - time) + 1; - z = y * TSL2X7X_MIN_ITIME; + count = 256 - time; + persistence = ((val * 100) + val2) / + (count * tsl2x7x_int_time[chip->id].increment_us); - filter_delay = DIV_ROUND_UP((val * 1000) + val2, z); + if (chan->type == IIO_INTENSITY) { + /* ALS filter values are 1, 2, 3, 5, 10, 15, ..., 60 */ + if (persistence > 3) + persistence = (persistence / 5) + 3; + + chip->settings.als_persistence = persistence; + } else { + chip->settings.prox_persistence = persistence; + } - if (chan->type == IIO_INTENSITY) - chip->settings.als_persistence = filter_delay; - else - chip->settings.prox_persistence = filter_delay; ret = 0; break; default: @@ -1040,7 +1043,7 @@ static int tsl2x7x_read_event_value(struct iio_dev *indio_dev, int *val, int *val2) { struct tsl2X7X_chip *chip = iio_priv(indio_dev); - int ret = -EINVAL, filter_delay, mult; + int ret = -EINVAL, filter_delay, persistence; u8 time; switch (info) { @@ -1076,18 +1079,21 @@ static int tsl2x7x_read_event_value(struct iio_dev *indio_dev, case IIO_EV_INFO_PERIOD: if (chan->type == IIO_INTENSITY) { time = chip->settings.als_time; - mult = chip->settings.als_persistence; + persistence = chip->settings.als_persistence; + + /* ALS filter values are 1, 2, 3, 5, 10, 15, ..., 60 */ + if (persistence > 3) + persistence = (persistence - 3) * 5; } else { time = chip->settings.prox_time; - mult = chip->settings.prox_persistence; + persistence = chip->settings.prox_persistence; } - /* Determine integration time */ - *val = (TSL2X7X_MAX_TIMER_CNT - time) + 1; - *val2 = *val * TSL2X7X_MIN_ITIME; - filter_delay = *val2 * mult; - *val = filter_delay / 1000; - *val2 = filter_delay % 1000; + filter_delay = persistence * (256 - time) * + tsl2x7x_int_time[chip->id].increment_us; + + *val = filter_delay / 100; + *val2 = filter_delay % 100; ret = IIO_VAL_INT_PLUS_MICRO; break; default: diff --git a/drivers/staging/iio/light/tsl2x7x.h b/drivers/staging/iio/light/tsl2x7x.h index 1097ee890ce2..f74427f4ab6e 100644 --- a/drivers/staging/iio/light/tsl2x7x.h +++ b/drivers/staging/iio/light/tsl2x7x.h @@ -31,7 +31,6 @@ struct tsl2x7x_lux { #define TSL2X7X_50_mA 0x01 #define TSL2X7X_25_mA 0x02 #define TSL2X7X_13_mA 0x03 -#define TSL2X7X_MAX_TIMER_CNT 0xFF /** * struct tsl2x7x_settings - Settings for the tsl2x7x driver -- 2.14.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH v2 06/11] staging: iio: tsl2x7x: correct integration time and lux equation
The integration_time sysfs attribute did not report the correct time. Changing the integration time would cause the reported lux to change wildly. Once the integration time was corrected, all of the equations, and lux tables needed to be corrected to match what the data sheets expected. This patch corrects all of this, and adds some more comments about how some of the constants were derived. Here are the results from testing a TSL2772 hooked up to a Raspberry Pi 2: # cat in_intensity0_integration_time 0.002730 # watch -n .1 cat in_illuminance0_input ; Lux hovers around 55 # echo 0.65 > in_intensity0_integration_time # cat in_intensity0_integration_time 0.649740 # watch -n .1 cat in_illuminance0_input ; Lux hovers around 55 with noticeable lag to lux changes in watch ; process. ; Now test the ALS calibration routine. # cat in_intensity0_calibbias 1000 # cat in_illuminance0_target_input 150 # echo 1 > in_illuminance0_calibrate # cat in_intensity0_calibbias 2777 # watch -n .1 cat in_illuminance0_input ; Lux now hovers around 150-155 The returned lux values were tested on a TSL2772 in various lighting conditions and the results are within the lux ranges described at https://en.wikipedia.org/wiki/Lux. The driver was primarily tested using a TSL2772, however some quick tests were also ran against the devices TSL2771, TSL2572, and TMD2772. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 174 drivers/staging/iio/light/tsl2x7x.h | 3 +- 2 files changed, 79 insertions(+), 98 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index cf582a2e3633..9b32054713fb 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -148,7 +148,7 @@ struct tsl2X7X_chip { struct tsl2x7x_als_info als_cur_info; struct tsl2x7x_settings settings; struct tsl2X7X_platform_data *pdata; - int als_time_scale; + int als_gain_time_scale; int als_saturation; int tsl2x7x_chip_status; u8 tsl2x7x_config[TSL2X7X_MAX_CONFIG_REG]; @@ -163,29 +163,36 @@ struct tsl2X7X_chip { struct tsl2x7x_lux tsl2x7x_device_lux[TSL2X7X_MAX_LUX_TABLE_SIZE]; }; -/* Different devices require different coefficents */ +/* + * Different devices require different coefficents, and these numbers were + * derived from the 'Lux Equation' section of the various device datasheets. + * All of these coefficients assume a Glass Attenuation (GA) factor of 1. + * The coefficients are multiplied by 1000 to avoid floating point operations. + * The two rows in each table correspond to the Lux1 and Lux2 equations from + * the datasheets. + */ static const struct tsl2x7x_lux tsl2x71_lux_table[TSL2X7X_DEF_LUX_TABLE_SZ] = { - { 14461, 611, 1211 }, - { 18540, 352,623 }, - { 0, 0, 0 }, + { 53000, 106000 }, + { 31800, 53000 }, + { 0, 0 }, }; static const struct tsl2x7x_lux tmd2x71_lux_table[TSL2X7X_DEF_LUX_TABLE_SZ] = { - { 11635, 115,256 }, - { 15536,87,179 }, - { 0, 0, 0 }, + { 24000, 48000 }, + { 14400, 24000 }, + { 0, 0 }, }; static const struct tsl2x7x_lux tsl2x72_lux_table[TSL2X7X_DEF_LUX_TABLE_SZ] = { - { 14013, 466, 917 }, - { 18222, 310, 552 }, - { 0, 0, 0 }, + { 6, 112200 }, + { 37800, 6 }, + { 0, 0 }, }; static const struct tsl2x7x_lux tmd2x72_lux_table[TSL2X7X_DEF_LUX_TABLE_SZ] = { - { 13218, 130, 262 }, - { 17592, 92,169 }, - { 0, 0, 0 }, + { 2, 35000 }, + { 12600, 2 }, + { 0, 0 }, }; static const struct tsl2x7x_lux *tsl2x7x_default_lux_table_group[] = { @@ -343,22 +350,18 @@ static int tsl2x7x_read_autoinc_regs(struct tsl2X7X_chip *chip, int lower_reg, * @indio_dev: pointer to IIO device * * 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. Array tsl2x7x_device_lux[] 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. + * integration cycle are read from the device. The raw values are multiplied + * by a device-specific scale factor, and divided by the integration time and + * device gain. The code supports multiple lux equations through the lux table + * coefficients. A lux gain trim is applied to e
[PATCH v2 10/11] staging: iio: tsl2x7x: rename driver to tsl2772
This patch renames this driver from tsl2x7x to tsl2772 since it is highly likely that additional devices will be added to this driver that do not match that wildcard. The tsl2772 driver name was selected since that is currently the device with the most features that are supported by this driver. Signed-off-by: Brian Masney --- drivers/staging/iio/light/Kconfig | 2 +- drivers/staging/iio/light/Makefile | 2 +- drivers/staging/iio/light/{tsl2x7x.c => tsl2772.c} | 691 +++-- drivers/staging/iio/light/{tsl2x7x.h => tsl2772.h} | 48 +- 4 files changed, 372 insertions(+), 371 deletions(-) rename drivers/staging/iio/light/{tsl2x7x.c => tsl2772.c} (66%) rename drivers/staging/iio/light/{tsl2x7x.h => tsl2772.h} (71%) diff --git a/drivers/staging/iio/light/Kconfig b/drivers/staging/iio/light/Kconfig index aacb0ae58c0e..dfa37386ad2c 100644 --- a/drivers/staging/iio/light/Kconfig +++ b/drivers/staging/iio/light/Kconfig @@ -3,7 +3,7 @@ # menu "Light sensors" -config TSL2x7x +config TSL2772 tristate "TAOS TSL/TMD2x71 and TSL/TMD2x72 Family of light and proximity sensors" depends on I2C help diff --git a/drivers/staging/iio/light/Makefile b/drivers/staging/iio/light/Makefile index ab8dc3a3d10b..e7e77a11f02a 100644 --- a/drivers/staging/iio/light/Makefile +++ b/drivers/staging/iio/light/Makefile @@ -2,4 +2,4 @@ # Makefile for industrial I/O Light sensors # -obj-$(CONFIG_TSL2x7x) += tsl2x7x.o +obj-$(CONFIG_TSL2772) += tsl2772.o diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2772.c similarity index 66% rename from drivers/staging/iio/light/tsl2x7x.c rename to drivers/staging/iio/light/tsl2772.c index f912f4bc61c4..146527e41969 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2772.c @@ -1,7 +1,8 @@ // SPDX-License-Identifier: GPL-2.0+ /* * Device driver for monitoring ambient light intensity in (lux) and proximity - * detection (prox) within the TAOS TSL2X7X family of devices. + * detection (prox) for the TAOS TSL2571, TSL2671, TMD2671, TSL2771, TMD2771, + * TSL2572, TSL2672, TMD2672, TSL2772, and TMD2772 devices. * * Copyright (c) 2012, TAOS Corporation. * Copyright (c) 2017-2018 Brian Masney @@ -18,92 +19,92 @@ #include #include #include -#include "tsl2x7x.h" +#include "tsl2772.h" /* Cal defs */ #define PROX_STAT_CAL 0 #define PROX_STAT_SAMP 1 #define MAX_SAMPLES_CAL200 -/* TSL2X7X Device ID */ +/* TSL2772 Device ID */ #define TRITON_ID 0x00 #define SWORDFISH_ID 0x30 #define HALIBUT_ID 0x20 /* Lux calculation constants */ -#define TSL2X7X_LUX_CALC_OVER_FLOW 65535 +#define TSL2772_LUX_CALC_OVER_FLOW 65535 /* * TAOS Register definitions - Note: depending on device, some of these register * are not used and the register address is benign. */ -/* 2X7X register offsets */ -#define TSL2X7X_MAX_CONFIG_REG 16 +/* Register offsets */ +#define TSL2772_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_MINTHRESHLO0X04 -#define TSL2X7X_ALS_MINTHRESHHI0X05 -#define TSL2X7X_ALS_MAXTHRESHLO0X06 -#define TSL2X7X_ALS_MAXTHRESHHI0X07 -#define TSL2X7X_PRX_MINTHRESHLO0X08 -#define TSL2X7X_PRX_MINTHRESHHI0X09 -#define TSL2X7X_PRX_MAXTHRESHLO0X0A -#define TSL2X7X_PRX_MAXTHRESHHI0X0B -#define TSL2X7X_PERSISTENCE0x0C -#define TSL2X7X_ALS_PRX_CONFIG 0x0D -#define TSL2X7X_PRX_COUNT 0x0E -#define TSL2X7X_GAIN 0x0F -#define TSL2X7X_NOTUSED0x10 -#define TSL2X7X_REVID 0x11 -#define TSL2X7X_CHIPID 0x12 -#define TSL2X7X_STATUS 0x13 -#define TSL2X7X_ALS_CHAN0LO0x14 -#define TSL2X7X_ALS_CHAN0HI0x15 -#define TSL2X7X_ALS_CHAN1LO0x16 -#define TSL2X7X_ALS_CHAN1HI0x17 -#define TSL2X7X_PRX_LO 0x18 -#define TSL2X7X_PRX_HI 0x19 - -/* tsl2X7X cmd reg masks */ -#define TSL2X7X_CMD_REG0x80 -#define TSL2X7X_CMD_SPL_FN 0x60 -#define TSL2X7X_CMD_REPEAT_PROTO 0x00 -#define TSL2X7X_CMD_AUTOINC_PROTO 0x20 - -#define TSL2X7X_CMD_PROX_INT_CLR 0X05 -#define TSL2X7X_CMD_ALS_INT_CLR0x06 -#define TSL2X7X_CMD_PROXALS_INT_CLR0X07 - -/* tsl2X7X cntrl reg masks */ -#define TSL2X7X_CNTL_ADC_ENBL 0x02 -#define TSL2X7X_CNTL_PWR_ON0x01 - -/* tsl2X7X status reg masks */ -
Re: [PATCH v2 11/11] staging: iio: tsl2x7x/tsl2772: move out of staging
Hey Jonathan, I intentionally didn't run git format-patch with the --no-renames since patch 10 renamed the driver. Here is the .[ch] files included inline to make your review easier. Brian tsl2772.c: // SPDX-License-Identifier: GPL-2.0+ /* * Device driver for monitoring ambient light intensity in (lux) and proximity * detection (prox) for the TAOS TSL2571, TSL2671, TMD2671, TSL2771, TMD2771, * TSL2572, TSL2672, TMD2672, TSL2772, and TMD2772 devices. * * Copyright (c) 2012, TAOS Corporation. * Copyright (c) 2017-2018 Brian Masney */ #include #include #include #include #include #include #include #include #include #include #include #include /* Cal defs */ #define PROX_STAT_CAL 0 #define PROX_STAT_SAMP 1 #define MAX_SAMPLES_CAL 200 /* TSL2772 Device ID */ #define TRITON_ID 0x00 #define SWORDFISH_ID0x30 #define HALIBUT_ID 0x20 /* Lux calculation constants */ #define TSL2772_LUX_CALC_OVER_FLOW 65535 /* * TAOS Register definitions - Note: depending on device, some of these register * are not used and the register address is benign. */ /* Register offsets */ #define TSL2772_MAX_CONFIG_REG 16 /* Device Registers and Masks */ #define TSL2772_CNTRL 0x00 #define TSL2772_ALS_TIME0X01 #define TSL2772_PRX_TIME0x02 #define TSL2772_WAIT_TIME 0x03 #define TSL2772_ALS_MINTHRESHLO 0X04 #define TSL2772_ALS_MINTHRESHHI 0X05 #define TSL2772_ALS_MAXTHRESHLO 0X06 #define TSL2772_ALS_MAXTHRESHHI 0X07 #define TSL2772_PRX_MINTHRESHLO 0X08 #define TSL2772_PRX_MINTHRESHHI 0X09 #define TSL2772_PRX_MAXTHRESHLO 0X0A #define TSL2772_PRX_MAXTHRESHHI 0X0B #define TSL2772_PERSISTENCE 0x0C #define TSL2772_ALS_PRX_CONFIG 0x0D #define TSL2772_PRX_COUNT 0x0E #define TSL2772_GAIN0x0F #define TSL2772_NOTUSED 0x10 #define TSL2772_REVID 0x11 #define TSL2772_CHIPID 0x12 #define TSL2772_STATUS 0x13 #define TSL2772_ALS_CHAN0LO 0x14 #define TSL2772_ALS_CHAN0HI 0x15 #define TSL2772_ALS_CHAN1LO 0x16 #define TSL2772_ALS_CHAN1HI 0x17 #define TSL2772_PRX_LO 0x18 #define TSL2772_PRX_HI 0x19 /* tsl2772 cmd reg masks */ #define TSL2772_CMD_REG 0x80 #define TSL2772_CMD_SPL_FN 0x60 #define TSL2772_CMD_REPEAT_PROTO0x00 #define TSL2772_CMD_AUTOINC_PROTO 0x20 #define TSL2772_CMD_PROX_INT_CLR0X05 #define TSL2772_CMD_ALS_INT_CLR 0x06 #define TSL2772_CMD_PROXALS_INT_CLR 0X07 /* tsl2772 cntrl reg masks */ #define TSL2772_CNTL_ADC_ENBL 0x02 #define TSL2772_CNTL_PWR_ON 0x01 /* tsl2772 status reg masks */ #define TSL2772_STA_ADC_VALID 0x01 #define TSL2772_STA_PRX_VALID 0x02 #define TSL2772_STA_ADC_PRX_VALID (TSL2772_STA_ADC_VALID | \ TSL2772_STA_PRX_VALID) #define TSL2772_STA_ALS_INTR0x10 #define TSL2772_STA_PRX_INTR0x20 /* tsl2772 cntrl reg masks */ #define TSL2772_CNTL_REG_CLEAR 0x00 #define TSL2772_CNTL_PROX_INT_ENBL 0X20 #define TSL2772_CNTL_ALS_INT_ENBL 0X10 #define TSL2772_CNTL_WAIT_TMR_ENBL 0X08 #define TSL2772_CNTL_PROX_DET_ENBL 0X04 #define TSL2772_CNTL_PWRON 0x01 #define TSL2772_CNTL_ALSPON_ENBL0x03 #define TSL2772_CNTL_INTALSPON_ENBL 0x13 #define TSL2772_CNTL_PROXPON_ENBL 0x0F #define TSL2772_CNTL_INTPROXPON_ENBL0x2F /* TAOS Device family members */ enum { tsl2571, tsl2671, tmd2671, tsl2771, tmd2771, tsl2572, tsl2672, tmd2672, tsl2772, tmd2772 }; enum { TSL2772_CHIP_UNKNOWN = 0, TSL2772_CHIP_WORKING = 1, TSL2772_CHIP_SUSPENDED = 2 }; /* Per-device data */ struct tsl2772_als_info { u16 als_ch0; u16 als_ch1; u16 lux; }; struct tsl2772_chip_info { int chan_table_elements; struct iio_chan_spec channel_with_events[4]; struct iio_chan_spec channel_without_events[4]; const struct iio_info *info; }; struct tsl2772_chip { kernel_ulong_t id; struct mutex prox_mutex; struct mutex als_mutex; struct i2c_client *client; u16 prox_data; struct tsl2772_als_info als_cur_info; struct tsl2772_settings settings; struct tsl2772_platform_data *pdata; int als_gain_time_scale; int als_saturation; int tsl2772_chip_status; u8 tsl2772_config[TSL2772_MAX_CONFIG_REG]; const struct tsl2772_chip_info *chip_info; const struct iio_info *info; s64 event_time
[PATCH v3 5/9] staging: iio: tsl2x7x: convert to use read_avail
Make the sysfs attributes in_proximity0_calibscale_available, and in_intensity0_{calibscale,integration_time}_available be created using info_mask_separate_available on the channel configuration. The driver assumed that the ALS increment was 2.72 ms, and the upper range was 696 ms. Some other supported devices use 2.73 ms - 699 ms. This patch adds support for the multiple ranges. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 93 ++--- 1 file changed, 76 insertions(+), 17 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index 51c1a90cb592..2d713d3c7c7b 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -209,9 +209,9 @@ static const struct tsl2x7x_lux *tsl2x7x_default_lux_table_group[] = { }; static const struct tsl2x7x_settings tsl2x7x_default_settings = { - .als_time = 255, /* 2.73 ms */ + .als_time = 255, /* 2.72 / 2.73 ms */ .als_gain = 0, - .prox_time = 255, /* 2.73 ms */ + .prox_time = 255, /* 2.72 / 2.73 ms */ .prox_gain = 0, .wait_time = 255, .als_prox_config = 0, @@ -245,6 +245,23 @@ static const s16 tsl2x7x_prox_gain[] = { 8 }; +static const int tsl2x7x_int_time_avail[][6] = { + [tsl2571] = { 0, 2720, 0, 2720, 0, 696000 }, + [tsl2671] = { 0, 2720, 0, 2720, 0, 696000 }, + [tmd2671] = { 0, 2720, 0, 2720, 0, 696000 }, + [tsl2771] = { 0, 2720, 0, 2720, 0, 696000 }, + [tmd2771] = { 0, 2720, 0, 2720, 0, 696000 }, + [tsl2572] = { 0, 2730, 0, 2730, 0, 699000 }, + [tsl2672] = { 0, 2730, 0, 2730, 0, 699000 }, + [tmd2672] = { 0, 2730, 0, 2730, 0, 699000 }, + [tsl2772] = { 0, 2730, 0, 2730, 0, 699000 }, + [tmd2772] = { 0, 2730, 0, 2730, 0, 699000 }, +}; + +static int tsl2x7x_int_calibscale_avail[] = { 1, 8, 16, 120 }; + +static int tsl2x7x_prox_calibscale_avail[] = { 1, 2, 4, 8 }; + /* Channel variations */ enum { ALS, @@ -626,7 +643,7 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev) /* set chip time scaling and saturation */ als_count = 256 - chip->settings.als_time; - als_time_us = als_count * 2720; + als_time_us = als_count * tsl2x7x_int_time_avail[chip->id][3]; chip->als_saturation = als_count * 768; /* 75% of full scale */ chip->als_gain_time_scale = als_time_us * tsl2x7x_als_gain[chip->settings.als_gain]; @@ -760,12 +777,33 @@ static int tsl2x7x_prox_cal(struct iio_dev *indio_dev) return tsl2x7x_invoke_change(indio_dev); } -static IIO_CONST_ATTR(in_intensity0_calibscale_available, "1 8 16 120"); +static int tsl2x7x_read_avail(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + const int **vals, int *type, int *length, + long mask) +{ + struct tsl2X7X_chip *chip = iio_priv(indio_dev); -static IIO_CONST_ATTR(in_proximity0_calibscale_available, "1 2 4 8"); + switch (mask) { + case IIO_CHAN_INFO_CALIBSCALE: + if (chan->type == IIO_INTENSITY) { + *length = ARRAY_SIZE(tsl2x7x_int_calibscale_avail); + *vals = tsl2x7x_int_calibscale_avail; + } else { + *length = ARRAY_SIZE(tsl2x7x_prox_calibscale_avail); + *vals = tsl2x7x_prox_calibscale_avail; + } + *type = IIO_VAL_INT; + return IIO_AVAIL_LIST; + case IIO_CHAN_INFO_INT_TIME: + *length = ARRAY_SIZE(tsl2x7x_int_time_avail[chip->id]); + *vals = tsl2x7x_int_time_avail[chip->id]; + *type = IIO_VAL_INT_PLUS_MICRO; + return IIO_AVAIL_RANGE; + } -static IIO_CONST_ATTR(in_intensity0_integration_time_available, - ".00272 - .696"); + return -EINVAL; +} static ssize_t in_illuminance0_target_input_show(struct device *dev, struct device_attribute *attr, @@ -1110,7 +1148,8 @@ static int tsl2x7x_read_raw(struct iio_dev *indio_dev, return IIO_VAL_INT; case IIO_CHAN_INFO_INT_TIME: *val = 0; - *val2 = (256 - chip->settings.als_time) * 2720; + *val2 = (256 - chip->settings.als_time) * + tsl2x7x_int_time_avail[chip->id][3]; return IIO_VAL_INT_PLUS_MICRO; default: return -EINVAL; @@ -1167,7 +1206,8 @@ static int tsl2x7x_write_raw(struct iio_dev *indio_dev, chip->settings.als_gain_trim = val; break; case IIO_CHAN_INFO_INT_TIME: - chip->settings.als_time = 256 - (val2 / 2720); + chip->settings.als_time = 256 - +
[PATCH v3 0/9] staging: iio: tsl2x7x: move out of staging
Hopefully this is the last of the changes that are required for a staging graduation. Changes since v2: - Correct values returned in in_intensity0_integration_time_available so that it doesn't break expected ABI. The driver now uses the read_avail for all three *_available sysfs attributes. - Remove unnecessary whitespace - Direct returns - Turn chip off if IIO registration fails - Add range checking to tsl2x7x_write_raw Datasheet for TSL2772 https://ams.com/eng/content/download/291503/1066377/file/TSL2772_DS000181_2-00.pdf Other datasheets: ALS only - https://ams.com/eng/content/download/250043/975277/file/TSL2571_DS000114_2-00.pdf - https://ams.com/eng/content/download/291224/1065822/file/TSL2572_DS000178_2-00.pdf Proximity Only - https://ams.com/eng/content/download/250323/976177/file/TSL2671_DS000111_2-00.pdf - https://ams.com/eng/content/download/250304/976107/file/TMD2671_DS000176_2-00.pdf - https://ams.com/eng/content/download/291443/1066277/file/TSL2672_Datasheet_EN_v1.pdf - https://ams.com/eng/content/download/364923/1210537/file/TMD2672_Datasheet_EN_v1.pdf ALS / Proximity - https://ams.com/eng/content/download/250264/976045/file/TSL2771_DS000105_3-00.pdf - https://ams.com/eng/content/download/250283/976077/file/TMD2771_DS000177_2-00.pdf - https://ams.com/eng/content/download/365023/1210677/file/TMD2772-E.pdf Brian Masney (9): staging: iio: tsl2x7x: remove unnecessary whitespace staging: iio: tsl2x7x: use direct returns staging: iio: tsl2x7x: turn chip off if IIO device registration fails staging: iio: tsl2x7x: use macro to populate tsl2X7X_device_info staging: iio: tsl2x7x: convert to use read_avail staging: iio: tsl2x7x: correct IIO_EV_INFO_PERIOD values staging: iio: tsl2x7x: add range checking to tsl2x7x_write_raw staging: iio: tsl2x7x: rename driver to tsl2772 staging: iio: tsl2x7x/tsl2772: move out of staging drivers/iio/light/Kconfig | 8 + drivers/iio/light/Makefile | 1 + .../iio/light/tsl2x7x.c => iio/light/tsl2772.c}| 886 +++-- drivers/staging/iio/Kconfig| 1 - drivers/staging/iio/Makefile | 1 - drivers/staging/iio/light/Kconfig | 14 - drivers/staging/iio/light/Makefile | 5 - .../linux/platform_data/tsl2772.h | 51 +- 8 files changed, 494 insertions(+), 473 deletions(-) rename drivers/{staging/iio/light/tsl2x7x.c => iio/light/tsl2772.c} (59%) delete mode 100644 drivers/staging/iio/light/Kconfig delete mode 100644 drivers/staging/iio/light/Makefile rename drivers/staging/iio/light/tsl2x7x.h => include/linux/platform_data/tsl2772.h (70%) -- 2.14.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH v3 1/9] staging: iio: tsl2x7x: remove unnecessary whitespace
This patch removes unnecessary whitespace in preparation for moving this driver out of staging. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 22 +++--- drivers/staging/iio/light/tsl2x7x.h | 1 - 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index cc863e8927f5..3ae2fd19ae9c 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -196,16 +196,16 @@ static const struct tsl2x7x_lux tmd2x72_lux_table[TSL2X7X_DEF_LUX_TABLE_SZ] = { }; static const struct tsl2x7x_lux *tsl2x7x_default_lux_table_group[] = { - [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, + [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 = { @@ -1241,7 +1241,7 @@ static irqreturn_t tsl2x7x_event_handler(int irq, void *private) 0, IIO_EV_TYPE_THRESH, IIO_EV_DIR_EITHER), - timestamp); + timestamp); } if (ret & TSL2X7X_STA_ALS_INTR) { diff --git a/drivers/staging/iio/light/tsl2x7x.h b/drivers/staging/iio/light/tsl2x7x.h index 1097ee890ce2..db344796fc1b 100644 --- a/drivers/staging/iio/light/tsl2x7x.h +++ b/drivers/staging/iio/light/tsl2x7x.h @@ -92,7 +92,6 @@ struct tsl2x7x_settings { * struct tsl2X7X_platform_data - Platform callback, glass and defaults * @platform_lux_table:Device specific glass coefficents * @platform_default_settings: Device specific power on defaults - * */ struct tsl2X7X_platform_data { struct tsl2x7x_lux platform_lux_table[TSL2X7X_MAX_LUX_TABLE_SIZE]; -- 2.14.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH v3 7/9] staging: iio: tsl2x7x: add range checking to tsl2x7x_write_raw
The CALIBBIAS and INT_TIME masks in tsl2x7x_write_raw did not have any range checking in place so this patch adds the appropriate range checking. The defines TSL2X7X_ALS_GAIN_TRIM_{MIN,MAX} are also introduced by this patch. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 13 - 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index 0218eabcd6d7..f9500afab30c 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -103,6 +103,9 @@ #define TSL2X7X_CNTL_PROXPON_ENBL 0x0F #define TSL2X7X_CNTL_INTPROXPON_ENBL 0x2F +#define TSL2X7X_ALS_GAIN_TRIM_MIN 250 +#define TSL2X7X_ALS_GAIN_TRIM_MAX 4000 + /* TAOS txx2x7x Device family members */ enum { tsl2571, @@ -581,7 +584,7 @@ static int tsl2x7x_als_calibrate(struct iio_dev *indio_dev) ret = (chip->settings.als_cal_target * chip->settings.als_gain_trim) / lux_val; - if (ret < 250 || ret > 4000) + if (ret < TSL2X7X_ALS_GAIN_TRIM_MIN || ret > TSL2X7X_ALS_GAIN_TRIM_MAX) return -ERANGE; chip->settings.als_gain_trim = ret; @@ -1209,9 +1212,17 @@ static int tsl2x7x_write_raw(struct iio_dev *indio_dev, } break; case IIO_CHAN_INFO_CALIBBIAS: + if (val < TSL2X7X_ALS_GAIN_TRIM_MIN || + val > TSL2X7X_ALS_GAIN_TRIM_MAX) + return -EINVAL; + chip->settings.als_gain_trim = val; break; case IIO_CHAN_INFO_INT_TIME: + if (val != 0 || val2 < tsl2x7x_int_time_avail[chip->id][1] || + val2 > tsl2x7x_int_time_avail[chip->id][5]) + return -EINVAL; + chip->settings.als_time = 256 - (val2 / tsl2x7x_int_time_avail[chip->id][3]); break; -- 2.14.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH v3 3/9] staging: iio: tsl2x7x: turn chip off if IIO device registration fails
This patch turns the chip off if IIO device registration fails so that the error handling mirrors the device remove to make review easier in preparation for moving this driver out of staging. This patch also adds a missing error check in the call to tsl2x7x_chip_on() in tsl2x7x_probe(). Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 5 - 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index c1e726fc87b7..f5ca5ada0358 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -1657,10 +1657,13 @@ static int tsl2x7x_probe(struct i2c_client *clientp, } tsl2x7x_defaults(chip); - tsl2x7x_chip_on(indio_dev); + ret = tsl2x7x_chip_on(indio_dev); + if (ret < 0) + return ret; ret = iio_device_register(indio_dev); if (ret) { + tsl2x7x_chip_off(indio_dev); dev_err(&clientp->dev, "%s: iio registration failed\n", __func__); return ret; -- 2.14.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH v3 2/9] staging: iio: tsl2x7x: use direct returns
This patch changes the functions tsl2x7x_read_event_value() and tsl2x7x_read_raw() to use direct returns to simplify the code. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 49 - 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index 3ae2fd19ae9c..c1e726fc87b7 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -1014,7 +1014,7 @@ static int tsl2x7x_read_event_value(struct iio_dev *indio_dev, int *val, int *val2) { struct tsl2X7X_chip *chip = iio_priv(indio_dev); - int ret = -EINVAL, filter_delay, mult; + int filter_delay, mult; u8 time; switch (info) { @@ -1023,27 +1023,23 @@ static int tsl2x7x_read_event_value(struct iio_dev *indio_dev, switch (dir) { case IIO_EV_DIR_RISING: *val = chip->settings.als_thresh_high; - ret = IIO_VAL_INT; - break; + return IIO_VAL_INT; case IIO_EV_DIR_FALLING: *val = chip->settings.als_thresh_low; - ret = IIO_VAL_INT; - break; + return IIO_VAL_INT; default: - break; + return -EINVAL; } } else { switch (dir) { case IIO_EV_DIR_RISING: *val = chip->settings.prox_thres_high; - ret = IIO_VAL_INT; - break; + return IIO_VAL_INT; case IIO_EV_DIR_FALLING: *val = chip->settings.prox_thres_low; - ret = IIO_VAL_INT; - break; + return IIO_VAL_INT; default: - break; + return -EINVAL; } } break; @@ -1062,13 +1058,10 @@ static int tsl2x7x_read_event_value(struct iio_dev *indio_dev, filter_delay = *val2 * mult; *val = filter_delay / 1000; *val2 = filter_delay % 1000; - ret = IIO_VAL_INT_PLUS_MICRO; - break; + return IIO_VAL_INT_PLUS_MICRO; default: - break; + return -EINVAL; } - - return ret; } static int tsl2x7x_read_raw(struct iio_dev *indio_dev, @@ -1078,7 +1071,6 @@ static int tsl2x7x_read_raw(struct iio_dev *indio_dev, long mask) { struct tsl2X7X_chip *chip = iio_priv(indio_dev); - int ret = -EINVAL; switch (mask) { case IIO_CHAN_INFO_PROCESSED: @@ -1086,12 +1078,10 @@ static int tsl2x7x_read_raw(struct iio_dev *indio_dev, case IIO_LIGHT: tsl2x7x_get_lux(indio_dev); *val = chip->als_cur_info.lux; - ret = IIO_VAL_INT; - break; + return IIO_VAL_INT; default: return -EINVAL; } - break; case IIO_CHAN_INFO_RAW: switch (chan->type) { case IIO_INTENSITY: @@ -1100,13 +1090,11 @@ static int tsl2x7x_read_raw(struct iio_dev *indio_dev, *val = chip->als_cur_info.als_ch0; else *val = chip->als_cur_info.als_ch1; - ret = IIO_VAL_INT; - break; + return IIO_VAL_INT; case IIO_PROXIMITY: tsl2x7x_get_prox(indio_dev); *val = chip->prox_data; - ret = IIO_VAL_INT; - break; + return IIO_VAL_INT; default: return -EINVAL; } @@ -1116,22 +1104,17 @@ static int tsl2x7x_read_raw(struct iio_dev *indio_dev, *val = tsl2x7x_als_gain[chip->settings.als_gain]; else *val = tsl2x7x_prox_gain[chip->settings.prox_gain]; - ret = IIO_VAL_INT; - break; + return IIO_VAL_INT; case IIO_CHAN_INFO_CALIBBIAS: *val = chip->settings.als_gain_trim; - ret = IIO_VAL_INT; - break; + return IIO_VAL_INT;
[PATCH v3 6/9] staging: iio: tsl2x7x: correct IIO_EV_INFO_PERIOD values
The thresh periods assumed an integration time of 3ms. This patch adds support for the correct integration time (2.72ms or 2.73ms). The code had the ALS filter values as going up to 15, however the values actually went up to 60 since the values scaled in increments of 5 once the persistence value went above 3. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 44 + drivers/staging/iio/light/tsl2x7x.h | 1 - 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index 2d713d3c7c7b..0218eabcd6d7 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -103,8 +103,6 @@ #define TSL2X7X_CNTL_PROXPON_ENBL 0x0F #define TSL2X7X_CNTL_INTPROXPON_ENBL 0x2F -#define TSL2X7X_MIN_ITIME 3 - /* TAOS txx2x7x Device family members */ enum { tsl2571, @@ -984,7 +982,7 @@ static int tsl2x7x_write_event_value(struct iio_dev *indio_dev, int val, int val2) { struct tsl2X7X_chip *chip = iio_priv(indio_dev); - int ret = -EINVAL, y, z, filter_delay; + int ret = -EINVAL, count, persistence; u8 time; switch (info) { @@ -1023,15 +1021,20 @@ static int tsl2x7x_write_event_value(struct iio_dev *indio_dev, else time = chip->settings.prox_time; - y = (TSL2X7X_MAX_TIMER_CNT - time) + 1; - z = y * TSL2X7X_MIN_ITIME; + count = 256 - time; + persistence = ((val * 100) + val2) / + (count * tsl2x7x_int_time_avail[chip->id][3]); - filter_delay = DIV_ROUND_UP((val * 1000) + val2, z); + if (chan->type == IIO_INTENSITY) { + /* ALS filter values are 1, 2, 3, 5, 10, 15, ..., 60 */ + if (persistence > 3) + persistence = (persistence / 5) + 3; + + chip->settings.als_persistence = persistence; + } else { + chip->settings.prox_persistence = persistence; + } - if (chan->type == IIO_INTENSITY) - chip->settings.als_persistence = filter_delay; - else - chip->settings.prox_persistence = filter_delay; ret = 0; break; default: @@ -1052,7 +1055,7 @@ static int tsl2x7x_read_event_value(struct iio_dev *indio_dev, int *val, int *val2) { struct tsl2X7X_chip *chip = iio_priv(indio_dev); - int filter_delay, mult; + int filter_delay, persistence; u8 time; switch (info) { @@ -1084,18 +1087,21 @@ static int tsl2x7x_read_event_value(struct iio_dev *indio_dev, case IIO_EV_INFO_PERIOD: if (chan->type == IIO_INTENSITY) { time = chip->settings.als_time; - mult = chip->settings.als_persistence; + persistence = chip->settings.als_persistence; + + /* ALS filter values are 1, 2, 3, 5, 10, 15, ..., 60 */ + if (persistence > 3) + persistence = (persistence - 3) * 5; } else { time = chip->settings.prox_time; - mult = chip->settings.prox_persistence; + persistence = chip->settings.prox_persistence; } - /* Determine integration time */ - *val = (TSL2X7X_MAX_TIMER_CNT - time) + 1; - *val2 = *val * TSL2X7X_MIN_ITIME; - filter_delay = *val2 * mult; - *val = filter_delay / 1000; - *val2 = filter_delay % 1000; + filter_delay = persistence * (256 - time) * + tsl2x7x_int_time_avail[chip->id][3]; + + *val = filter_delay / 100; + *val2 = filter_delay % 100; return IIO_VAL_INT_PLUS_MICRO; default: return -EINVAL; diff --git a/drivers/staging/iio/light/tsl2x7x.h b/drivers/staging/iio/light/tsl2x7x.h index db344796fc1b..b86f6b260f9f 100644 --- a/drivers/staging/iio/light/tsl2x7x.h +++ b/drivers/staging/iio/light/tsl2x7x.h @@ -31,7 +31,6 @@ struct tsl2x7x_lux { #define TSL2X7X_50_mA 0x01 #define TSL2X7X_25_mA 0x02 #define TSL2X7X_13_mA 0x03 -#define TSL2X7X_MAX_TIMER_CNT 0xFF /** * struct tsl2x7x_settings - Settings for the tsl2x7x driver -- 2.14.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH v3 4/9] staging: iio: tsl2x7x: use macro to populate tsl2X7X_device_info
This patch creates a macro that populates the tsl2X7X_device_info structure to reduce duplicated code in the driver. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 61 ++--- 1 file changed, 16 insertions(+), 45 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index f5ca5ada0358..51c1a90cb592 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -1305,52 +1305,23 @@ static const struct attribute_group tsl2X7X_device_attr_group_tbl[] = { }, }; +#define TSL2X7X_DEVICE_INFO(type)[type] = \ + { \ + .attrs = &tsl2X7X_device_attr_group_tbl[type], \ + .read_raw = &tsl2x7x_read_raw, \ + .write_raw = &tsl2x7x_write_raw, \ + .read_event_value = &tsl2x7x_read_event_value, \ + .write_event_value = &tsl2x7x_write_event_value, \ + .read_event_config = &tsl2x7x_read_interrupt_config, \ + .write_event_config = &tsl2x7x_write_interrupt_config, \ + } + static const struct iio_info tsl2X7X_device_info[] = { - [ALS] = { - .attrs = &tsl2X7X_device_attr_group_tbl[ALS], - .read_raw = &tsl2x7x_read_raw, - .write_raw = &tsl2x7x_write_raw, - .read_event_value = &tsl2x7x_read_event_value, - .write_event_value = &tsl2x7x_write_event_value, - .read_event_config = &tsl2x7x_read_interrupt_config, - .write_event_config = &tsl2x7x_write_interrupt_config, - }, - [PRX] = { - .attrs = &tsl2X7X_device_attr_group_tbl[PRX], - .read_raw = &tsl2x7x_read_raw, - .write_raw = &tsl2x7x_write_raw, - .read_event_value = &tsl2x7x_read_event_value, - .write_event_value = &tsl2x7x_write_event_value, - .read_event_config = &tsl2x7x_read_interrupt_config, - .write_event_config = &tsl2x7x_write_interrupt_config, - }, - [ALSPRX] = { - .attrs = &tsl2X7X_device_attr_group_tbl[ALSPRX], - .read_raw = &tsl2x7x_read_raw, - .write_raw = &tsl2x7x_write_raw, - .read_event_value = &tsl2x7x_read_event_value, - .write_event_value = &tsl2x7x_write_event_value, - .read_event_config = &tsl2x7x_read_interrupt_config, - .write_event_config = &tsl2x7x_write_interrupt_config, - }, - [PRX2] = { - .attrs = &tsl2X7X_device_attr_group_tbl[PRX2], - .read_raw = &tsl2x7x_read_raw, - .write_raw = &tsl2x7x_write_raw, - .read_event_value = &tsl2x7x_read_event_value, - .write_event_value = &tsl2x7x_write_event_value, - .read_event_config = &tsl2x7x_read_interrupt_config, - .write_event_config = &tsl2x7x_write_interrupt_config, - }, - [ALSPRX2] = { - .attrs = &tsl2X7X_device_attr_group_tbl[ALSPRX2], - .read_raw = &tsl2x7x_read_raw, - .write_raw = &tsl2x7x_write_raw, - .read_event_value = &tsl2x7x_read_event_value, - .write_event_value = &tsl2x7x_write_event_value, - .read_event_config = &tsl2x7x_read_interrupt_config, - .write_event_config = &tsl2x7x_write_interrupt_config, - }, + TSL2X7X_DEVICE_INFO(ALS), + TSL2X7X_DEVICE_INFO(PRX), + TSL2X7X_DEVICE_INFO(ALSPRX), + TSL2X7X_DEVICE_INFO(PRX2), + TSL2X7X_DEVICE_INFO(ALSPRX2), }; static const struct iio_event_spec tsl2x7x_events[] = { -- 2.14.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH v3 8/9] staging: iio: tsl2x7x: rename driver to tsl2772
This patch renames this driver from tsl2x7x to tsl2772 since it is highly likely that additional devices will be added to this driver that do not match that wildcard. The tsl2772 driver name was selected since that is currently the device with the most features that are supported by this driver. This patch also adds Brian Masney's copyright to tsl2772.h for all of the work that has been done to move this driver out of staging. Signed-off-by: Brian Masney --- drivers/staging/iio/light/Kconfig | 2 +- drivers/staging/iio/light/Makefile | 2 +- drivers/staging/iio/light/{tsl2x7x.c => tsl2772.c} | 681 +++-- drivers/staging/iio/light/{tsl2x7x.h => tsl2772.h} | 49 +- 4 files changed, 368 insertions(+), 366 deletions(-) rename drivers/staging/iio/light/{tsl2x7x.c => tsl2772.c} (67%) rename drivers/staging/iio/light/{tsl2x7x.h => tsl2772.h} (70%) diff --git a/drivers/staging/iio/light/Kconfig b/drivers/staging/iio/light/Kconfig index aacb0ae58c0e..dfa37386ad2c 100644 --- a/drivers/staging/iio/light/Kconfig +++ b/drivers/staging/iio/light/Kconfig @@ -3,7 +3,7 @@ # menu "Light sensors" -config TSL2x7x +config TSL2772 tristate "TAOS TSL/TMD2x71 and TSL/TMD2x72 Family of light and proximity sensors" depends on I2C help diff --git a/drivers/staging/iio/light/Makefile b/drivers/staging/iio/light/Makefile index ab8dc3a3d10b..e7e77a11f02a 100644 --- a/drivers/staging/iio/light/Makefile +++ b/drivers/staging/iio/light/Makefile @@ -2,4 +2,4 @@ # Makefile for industrial I/O Light sensors # -obj-$(CONFIG_TSL2x7x) += tsl2x7x.o +obj-$(CONFIG_TSL2772) += tsl2772.o diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2772.c similarity index 67% rename from drivers/staging/iio/light/tsl2x7x.c rename to drivers/staging/iio/light/tsl2772.c index f9500afab30c..a59bf39c28d4 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2772.c @@ -1,7 +1,8 @@ // SPDX-License-Identifier: GPL-2.0+ /* * Device driver for monitoring ambient light intensity in (lux) and proximity - * detection (prox) within the TAOS TSL2X7X family of devices. + * detection (prox) within the TAOS TSL2571, TSL2671, TMD2671, TSL2771, TMD2771, + * TSL2572, TSL2672, TMD2672, TSL2772, and TMD2772 devices. * * Copyright (c) 2012, TAOS Corporation. * Copyright (c) 2017-2018 Brian Masney @@ -18,95 +19,95 @@ #include #include #include -#include "tsl2x7x.h" +#include "tsl2772.h" /* Cal defs */ #define PROX_STAT_CAL 0 #define PROX_STAT_SAMP 1 #define MAX_SAMPLES_CAL200 -/* TSL2X7X Device ID */ +/* TSL2772 Device ID */ #define TRITON_ID 0x00 #define SWORDFISH_ID 0x30 #define HALIBUT_ID 0x20 /* Lux calculation constants */ -#define TSL2X7X_LUX_CALC_OVER_FLOW 65535 +#define TSL2772_LUX_CALC_OVER_FLOW 65535 /* * TAOS Register definitions - Note: depending on device, some of these register * are not used and the register address is benign. */ -/* 2X7X register offsets */ -#define TSL2X7X_MAX_CONFIG_REG 16 +/* Register offsets */ +#define TSL2772_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_MINTHRESHLO0X04 -#define TSL2X7X_ALS_MINTHRESHHI0X05 -#define TSL2X7X_ALS_MAXTHRESHLO0X06 -#define TSL2X7X_ALS_MAXTHRESHHI0X07 -#define TSL2X7X_PRX_MINTHRESHLO0X08 -#define TSL2X7X_PRX_MINTHRESHHI0X09 -#define TSL2X7X_PRX_MAXTHRESHLO0X0A -#define TSL2X7X_PRX_MAXTHRESHHI0X0B -#define TSL2X7X_PERSISTENCE0x0C -#define TSL2X7X_ALS_PRX_CONFIG 0x0D -#define TSL2X7X_PRX_COUNT 0x0E -#define TSL2X7X_GAIN 0x0F -#define TSL2X7X_NOTUSED0x10 -#define TSL2X7X_REVID 0x11 -#define TSL2X7X_CHIPID 0x12 -#define TSL2X7X_STATUS 0x13 -#define TSL2X7X_ALS_CHAN0LO0x14 -#define TSL2X7X_ALS_CHAN0HI0x15 -#define TSL2X7X_ALS_CHAN1LO0x16 -#define TSL2X7X_ALS_CHAN1HI0x17 -#define TSL2X7X_PRX_LO 0x18 -#define TSL2X7X_PRX_HI 0x19 - -/* tsl2X7X cmd reg masks */ -#define TSL2X7X_CMD_REG0x80 -#define TSL2X7X_CMD_SPL_FN 0x60 -#define TSL2X7X_CMD_REPEAT_PROTO 0x00 -#define TSL2X7X_CMD_AUTOINC_PROTO 0x20 - -#define TSL2X7X_CMD_PROX_INT_CLR 0X05 -#define TSL2X7X_CMD_ALS_INT_CLR0x06 -#define TSL2X7X_CMD_PROXALS_INT_CLR0X07 - -/*
[PATCH v3 9/9] staging: iio: tsl2x7x/tsl2772: move out of staging
Move the tsl2772 driver out of staging and into mainline. Signed-off-by: Brian Masney --- drivers/iio/light/Kconfig | 8 drivers/iio/light/Makefile | 1 + drivers/{staging => }/iio/light/tsl2772.c | 2 +- drivers/staging/iio/Kconfig| 1 - drivers/staging/iio/Makefile | 1 - drivers/staging/iio/light/Kconfig | 14 -- drivers/staging/iio/light/Makefile | 5 - .../iio/light => include/linux/platform_data}/tsl2772.h| 0 8 files changed, 10 insertions(+), 22 deletions(-) rename drivers/{staging => }/iio/light/tsl2772.c (99%) delete mode 100644 drivers/staging/iio/light/Kconfig delete mode 100644 drivers/staging/iio/light/Makefile rename {drivers/staging/iio/light => include/linux/platform_data}/tsl2772.h (100%) diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig index 074e50657366..c7ef8d1862d6 100644 --- a/drivers/iio/light/Kconfig +++ b/drivers/iio/light/Kconfig @@ -409,6 +409,14 @@ config TSL2583 Provides support for the TAOS tsl2580, tsl2581 and tsl2583 devices. Access ALS data via iio, sysfs. +config TSL2772 + 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. + config TSL4531 tristate "TAOS TSL4531 ambient light sensors" depends on I2C diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile index f1777036d4f8..80943af5d627 100644 --- a/drivers/iio/light/Makefile +++ b/drivers/iio/light/Makefile @@ -40,6 +40,7 @@ obj-$(CONFIG_ST_UVIS25_SPI) += st_uvis25_spi.o obj-$(CONFIG_TCS3414) += tcs3414.o obj-$(CONFIG_TCS3472) += tcs3472.o obj-$(CONFIG_TSL2583) += tsl2583.o +obj-$(CONFIG_TSL2772) += tsl2772.o obj-$(CONFIG_TSL4531) += tsl4531.o obj-$(CONFIG_US5182D) += us5182d.o obj-$(CONFIG_VCNL4000) += vcnl4000.o diff --git a/drivers/staging/iio/light/tsl2772.c b/drivers/iio/light/tsl2772.c similarity index 99% rename from drivers/staging/iio/light/tsl2772.c rename to drivers/iio/light/tsl2772.c index a59bf39c28d4..34d42a2504c9 100644 --- a/drivers/staging/iio/light/tsl2772.c +++ b/drivers/iio/light/tsl2772.c @@ -19,7 +19,7 @@ #include #include #include -#include "tsl2772.h" +#include /* Cal defs */ #define PROX_STAT_CAL 0 diff --git a/drivers/staging/iio/Kconfig b/drivers/staging/iio/Kconfig index 8abc1ab3c0c7..ca001510782d 100644 --- a/drivers/staging/iio/Kconfig +++ b/drivers/staging/iio/Kconfig @@ -11,7 +11,6 @@ source "drivers/staging/iio/cdc/Kconfig" source "drivers/staging/iio/frequency/Kconfig" source "drivers/staging/iio/gyro/Kconfig" source "drivers/staging/iio/impedance-analyzer/Kconfig" -source "drivers/staging/iio/light/Kconfig" source "drivers/staging/iio/meter/Kconfig" source "drivers/staging/iio/resolver/Kconfig" source "drivers/staging/iio/trigger/Kconfig" diff --git a/drivers/staging/iio/Makefile b/drivers/staging/iio/Makefile index 455bffc29649..5c168403b873 100644 --- a/drivers/staging/iio/Makefile +++ b/drivers/staging/iio/Makefile @@ -10,7 +10,6 @@ obj-y += cdc/ obj-y += frequency/ obj-y += gyro/ obj-y += impedance-analyzer/ -obj-y += light/ obj-y += meter/ obj-y += resolver/ obj-y += trigger/ diff --git a/drivers/staging/iio/light/Kconfig b/drivers/staging/iio/light/Kconfig deleted file mode 100644 index dfa37386ad2c.. --- a/drivers/staging/iio/light/Kconfig +++ /dev/null @@ -1,14 +0,0 @@ -# -# Light sensors -# -menu "Light sensors" - -config TSL2772 - 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 diff --git a/drivers/staging/iio/light/Makefile b/drivers/staging/iio/light/Makefile deleted file mode 100644 index e7e77a11f02a.. --- a/drivers/staging/iio/light/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -# -# Makefile for industrial I/O Light sensors -# - -obj-$(CONFIG_TSL2772) += tsl2772.o diff --git a/drivers/staging/iio/light/tsl2772.h b/include/linux/platform_data/tsl2772.h similarity index 100% rename from drivers/staging/iio/light/tsl2772.h rename to include/linux/platform_data/tsl2772.h -- 2.14.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
Re: [PATCH v3 9/9] staging: iio: tsl2x7x/tsl2772: move out of staging
On Thu, May 10, 2018 at 08:12:23PM -0400, Brian Masney wrote: > Move the tsl2772 driver out of staging and into mainline. Hey Jonathan, Here is the .c and .h file to make your review easier. Thanks for all your feedback on all of these changes to this driver plus the other 3 that I've already moved out of staging. I've learned a lot going through this process. Brian // SPDX-License-Identifier: GPL-2.0+ /* * Device driver for monitoring ambient light intensity in (lux) and proximity * detection (prox) within the TAOS TSL2571, TSL2671, TMD2671, TSL2771, TMD2771, * TSL2572, TSL2672, TMD2672, TSL2772, and TMD2772 devices. * * Copyright (c) 2012, TAOS Corporation. * Copyright (c) 2017-2018 Brian Masney */ #include #include #include #include #include #include #include #include #include #include #include #include /* Cal defs */ #define PROX_STAT_CAL 0 #define PROX_STAT_SAMP 1 #define MAX_SAMPLES_CAL 200 /* TSL2772 Device ID */ #define TRITON_ID 0x00 #define SWORDFISH_ID0x30 #define HALIBUT_ID 0x20 /* Lux calculation constants */ #define TSL2772_LUX_CALC_OVER_FLOW 65535 /* * TAOS Register definitions - Note: depending on device, some of these register * are not used and the register address is benign. */ /* Register offsets */ #define TSL2772_MAX_CONFIG_REG 16 /* Device Registers and Masks */ #define TSL2772_CNTRL 0x00 #define TSL2772_ALS_TIME0X01 #define TSL2772_PRX_TIME0x02 #define TSL2772_WAIT_TIME 0x03 #define TSL2772_ALS_MINTHRESHLO 0X04 #define TSL2772_ALS_MINTHRESHHI 0X05 #define TSL2772_ALS_MAXTHRESHLO 0X06 #define TSL2772_ALS_MAXTHRESHHI 0X07 #define TSL2772_PRX_MINTHRESHLO 0X08 #define TSL2772_PRX_MINTHRESHHI 0X09 #define TSL2772_PRX_MAXTHRESHLO 0X0A #define TSL2772_PRX_MAXTHRESHHI 0X0B #define TSL2772_PERSISTENCE 0x0C #define TSL2772_ALS_PRX_CONFIG 0x0D #define TSL2772_PRX_COUNT 0x0E #define TSL2772_GAIN0x0F #define TSL2772_NOTUSED 0x10 #define TSL2772_REVID 0x11 #define TSL2772_CHIPID 0x12 #define TSL2772_STATUS 0x13 #define TSL2772_ALS_CHAN0LO 0x14 #define TSL2772_ALS_CHAN0HI 0x15 #define TSL2772_ALS_CHAN1LO 0x16 #define TSL2772_ALS_CHAN1HI 0x17 #define TSL2772_PRX_LO 0x18 #define TSL2772_PRX_HI 0x19 /* tsl2772 cmd reg masks */ #define TSL2772_CMD_REG 0x80 #define TSL2772_CMD_SPL_FN 0x60 #define TSL2772_CMD_REPEAT_PROTO0x00 #define TSL2772_CMD_AUTOINC_PROTO 0x20 #define TSL2772_CMD_PROX_INT_CLR0X05 #define TSL2772_CMD_ALS_INT_CLR 0x06 #define TSL2772_CMD_PROXALS_INT_CLR 0X07 /* tsl2772 cntrl reg masks */ #define TSL2772_CNTL_ADC_ENBL 0x02 #define TSL2772_CNTL_PWR_ON 0x01 /* tsl2772 status reg masks */ #define TSL2772_STA_ADC_VALID 0x01 #define TSL2772_STA_PRX_VALID 0x02 #define TSL2772_STA_ADC_PRX_VALID (TSL2772_STA_ADC_VALID | \ TSL2772_STA_PRX_VALID) #define TSL2772_STA_ALS_INTR0x10 #define TSL2772_STA_PRX_INTR0x20 /* tsl2772 cntrl reg masks */ #define TSL2772_CNTL_REG_CLEAR 0x00 #define TSL2772_CNTL_PROX_INT_ENBL 0X20 #define TSL2772_CNTL_ALS_INT_ENBL 0X10 #define TSL2772_CNTL_WAIT_TMR_ENBL 0X08 #define TSL2772_CNTL_PROX_DET_ENBL 0X04 #define TSL2772_CNTL_PWRON 0x01 #define TSL2772_CNTL_ALSPON_ENBL0x03 #define TSL2772_CNTL_INTALSPON_ENBL 0x13 #define TSL2772_CNTL_PROXPON_ENBL 0x0F #define TSL2772_CNTL_INTPROXPON_ENBL0x2F #define TSL2772_ALS_GAIN_TRIM_MIN 250 #define TSL2772_ALS_GAIN_TRIM_MAX 4000 /* Device family members */ enum { tsl2571, tsl2671, tmd2671, tsl2771, tmd2771, tsl2572, tsl2672, tmd2672, tsl2772, tmd2772 }; enum { TSL2772_CHIP_UNKNOWN = 0, TSL2772_CHIP_WORKING = 1, TSL2772_CHIP_SUSPENDED = 2 }; /* Per-device data */ struct tsl2772_als_info { u16 als_ch0; u16 als_ch1; u16 lux; }; struct tsl2772_chip_info { int chan_table_elements; struct iio_chan_spec channel_with_events[4]; struct iio_chan_spec channel_without_events[4]; const struct iio_info *info; }; struct tsl2772_chip { kernel_ulong_t id; struct mutex prox_mutex; struct mutex als_mutex; struct i2c_client *client; u16 prox_data; struct tsl2772_als_info als_cur_info; struct tsl2772_settings settings; struct tsl2772_platform_data *pdata
Re: [PATCH v3 9/9] staging: iio: tsl2x7x/tsl2772: move out of staging
On Sat, May 12, 2018 at 12:44:37PM +0100, Jonathan Cameron wrote: > On Thu, 10 May 2018 20:32:06 -0400 > Brian Masney wrote: > > > On Thu, May 10, 2018 at 08:12:23PM -0400, Brian Masney wrote: > > > Move the tsl2772 driver out of staging and into mainline. > > > > Hey Jonathan, > > > > Here is the .c and .h file to make your review easier. Thanks for all > > your feedback on all of these changes to this driver plus the other 3 > > that I've already moved out of staging. I've learned a lot going through > > this process. > > I have the great pleasure to say APPLIED! > Congratulations Brian. This has been the longest and most complex driver > cleanup I think we have ever had. > > 64? patches > > 930 (+ 366) insertions, 710(+ 368) deletions (brackets for the driver rename > which only sort of counts. > > + this is the 4th driver as you say. > > Particularly pleasing is that we no longer have any light sensors in iio > staging. > > So what's next? Great! Thank you! I have two things that I'm planning to do next: 1) See if the tsl2583 driver can be cleanly folded into tsl2772. 2) I have a Google Nexus 5 phone and I'm going to work towards being able to run an upstream kernel on the device. There has already been some work on this so looking to join forces: https://github.com/flto/linux/wiki/hammerhead-upstream Brian ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH v3 0/2] staging: iio: isl29028: move out of staging
Minor cleanup to the proximity sampling to move this driver out of staging. Datasheet: http://www.intersil.com/content/dam/Intersil/documents/isl2/isl29028.pdf Changes since v2: - Reject any value that is not in the in_proximity_sampling_frequency_available sysfs attribute. - Changed the sampling frequency 83.3 to 80. The data sheet lists 12.5 ms, but the original code listed 12 ms, which was the cause of the discrepancy. Changes since v1: - in_proximity_sampling_frequency_available sysfs attribute now shows decimals. Jonathan: Sorry it took me a little over two months to get back to you on this driver. I got side tracked with other projects. Brian Masney (2): staging: iio: isl29028: correct proximity sleep times staging: iio: isl29028: move out of staging drivers/iio/light/Kconfig| 10 + drivers/iio/light/Makefile | 1 + drivers/iio/light/isl29028.c | 723 +++ drivers/staging/iio/light/Kconfig| 10 - drivers/staging/iio/light/Makefile | 1 - drivers/staging/iio/light/isl29028.c | 693 - 6 files changed, 734 insertions(+), 704 deletions(-) create mode 100644 drivers/iio/light/isl29028.c delete mode 100644 drivers/staging/iio/light/isl29028.c -- 2.9.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH v3 1/2] staging: iio: isl29028: correct proximity sleep times
The sysfs attribute in_proximity_sampling_frequency_available currently shows the values 1 3 5 10 13 20 83 100. These values are supposed to correspond to the sleep values 800 400 200 100 75 50 12.5 0 (all in ms). When passing in a sampling frequency of 3, it actually uses a sleep time of 200ms instead of the expected 400ms value. This patch changes the value shown by this sysfs attribute to use fixed-point numbers so that the correct sampling frequency is shown to the user. This patch also changes the code that updates the proximity sampling frequency to only allow values that are shown in the _available sysfs attribute. The original code showed the value 83 that corresponds to the sleep time 12 ms. The data sheet actually lists 12.5 ms as the sleep time, so the proximity frequency was updated to 80. Signed-off-by: Brian Masney --- drivers/staging/iio/light/isl29028.c | 70 +--- 1 file changed, 50 insertions(+), 20 deletions(-) diff --git a/drivers/staging/iio/light/isl29028.c b/drivers/staging/iio/light/isl29028.c index 5375e7a..aeb5082 100644 --- a/drivers/staging/iio/light/isl29028.c +++ b/drivers/staging/iio/light/isl29028.c @@ -64,8 +64,25 @@ #define ISL29028_POWER_OFF_DELAY_MS2000 -static const unsigned int isl29028_prox_sleep_time[] = {800, 400, 200, 100, 75, - 50, 12, 0}; +struct isl29028_prox_data { + int sampling_int; + int sampling_fract; + int sleep_time; +}; + +static const struct isl29028_prox_data isl29028_prox_data[] = { + { 1, 25, 800 }, + { 2, 50, 400 }, + { 5, 0, 200 }, + { 10, 0, 100 }, + { 13, 30, 75 }, + { 20, 0, 50 }, + { 80, 0, 13 }, /* + * Note: Data sheet lists 12.5 ms sleep time. + * Round up a half millisecond for msleep(). + */ + { 100, 0, 0 } +}; enum isl29028_als_ir_mode { ISL29028_MODE_NONE = 0, @@ -76,32 +93,37 @@ enum isl29028_als_ir_mode { struct isl29028_chip { struct mutexlock; struct regmap *regmap; - unsigned intprox_sampling; + int prox_sampling_int; + int prox_sampling_frac; boolenable_prox; int lux_scale; enum isl29028_als_ir_mode als_ir_mode; }; -static int isl29028_find_prox_sleep_time_index(int sampling) +static int isl29028_find_prox_sleep_index(int sampling_int, int sampling_fract) { - unsigned int period = DIV_ROUND_UP(1000, sampling); int i; - for (i = 0; i < ARRAY_SIZE(isl29028_prox_sleep_time); ++i) { - if (period >= isl29028_prox_sleep_time[i]) - break; + for (i = 0; i < ARRAY_SIZE(isl29028_prox_data); ++i) { + if (isl29028_prox_data[i].sampling_int == sampling_int && + isl29028_prox_data[i].sampling_fract == sampling_fract) + return i; } - return i; + return -EINVAL; } static int isl29028_set_proxim_sampling(struct isl29028_chip *chip, - unsigned int sampling) + int sampling_int, int sampling_fract) { struct device *dev = regmap_get_device(chip->regmap); int sleep_index, ret; - sleep_index = isl29028_find_prox_sleep_time_index(sampling); + sleep_index = isl29028_find_prox_sleep_index(sampling_int, +sampling_fract); + if (sleep_index < 0) + return sleep_index; + ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, ISL29028_CONF_PROX_SLP_MASK, sleep_index << ISL29028_CONF_PROX_SLP_SH); @@ -112,16 +134,18 @@ static int isl29028_set_proxim_sampling(struct isl29028_chip *chip, return ret; } - chip->prox_sampling = sampling; + chip->prox_sampling_int = sampling_int; + chip->prox_sampling_frac = sampling_fract; return ret; } static int isl29028_enable_proximity(struct isl29028_chip *chip) { - int sleep_index, ret; + int prox_index, ret; - ret = isl29028_set_proxim_sampling(chip, chip->prox_sampling); + ret = isl29028_set_proxim_sampling(chip, chip->prox_sampling_int, + chip->prox_sampling_frac); if (ret < 0) return ret; @@ -132,8 +156,12 @@ static int isl29028_enable_proximity(struct isl29028_chip *chip) return ret; /* Wait for conversion to be complete for first sample */ - s
[PATCH v3 2/2] staging: iio: isl29028: move out of staging
Move ISL29028 ALS / Proximity Sensor out of staging and into mainline. Signed-off-by: Brian Masney --- drivers/iio/light/Kconfig| 10 + drivers/iio/light/Makefile | 1 + drivers/iio/light/isl29028.c | 723 +++ drivers/staging/iio/light/Kconfig| 10 - drivers/staging/iio/light/Makefile | 1 - drivers/staging/iio/light/isl29028.c | 723 --- 6 files changed, 734 insertions(+), 734 deletions(-) create mode 100644 drivers/iio/light/isl29028.c delete mode 100644 drivers/staging/iio/light/isl29028.c diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig index 33e755d..2356ed9 100644 --- a/drivers/iio/light/Kconfig +++ b/drivers/iio/light/Kconfig @@ -172,6 +172,16 @@ config SENSORS_ISL29018 in lux, proximity infrared sensing and normal infrared sensing. Data from sensor is accessible via sysfs. +config SENSORS_ISL29028 + tristate "Intersil ISL29028 Concurrent Light and Proximity Sensor" + depends on I2C + select REGMAP_I2C + help +Provides driver for the Intersil's ISL29028 device. +This driver supports the sysfs interface to get the ALS, IR intensity, +Proximity value via iio. The ISL29028 provides the concurrent sensing +of ambient light and proximity. + config ISL29125 tristate "Intersil ISL29125 digital color light sensor" depends on I2C diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile index 681363c..fa32fa4 100644 --- a/drivers/iio/light/Makefile +++ b/drivers/iio/light/Makefile @@ -20,6 +20,7 @@ obj-$(CONFIG_GP2AP020A00F)+= gp2ap020a00f.o obj-$(CONFIG_HID_SENSOR_ALS) += hid-sensor-als.o obj-$(CONFIG_HID_SENSOR_PROX) += hid-sensor-prox.o obj-$(CONFIG_SENSORS_ISL29018) += isl29018.o +obj-$(CONFIG_SENSORS_ISL29028) += isl29028.o obj-$(CONFIG_ISL29125) += isl29125.o obj-$(CONFIG_JSA1212) += jsa1212.o obj-$(CONFIG_SENSORS_LM3533) += lm3533-als.o diff --git a/drivers/iio/light/isl29028.c b/drivers/iio/light/isl29028.c new file mode 100644 index 000..aeb5082 --- /dev/null +++ b/drivers/iio/light/isl29028.c @@ -0,0 +1,723 @@ +/* + * IIO driver for the light sensor ISL29028. + * ISL29028 is Concurrent Ambient Light and Proximity Sensor + * + * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2016-2017 Brian Masney + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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, see <http://www.gnu.org/licenses/>. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define ISL29028_CONV_TIME_MS 100 + +#define ISL29028_REG_CONFIGURE 0x01 + +#define ISL29028_CONF_ALS_IR_MODE_ALS 0 +#define ISL29028_CONF_ALS_IR_MODE_IR BIT(0) +#define ISL29028_CONF_ALS_IR_MODE_MASK BIT(0) + +#define ISL29028_CONF_ALS_RANGE_LOW_LUX0 +#define ISL29028_CONF_ALS_RANGE_HIGH_LUX BIT(1) +#define ISL29028_CONF_ALS_RANGE_MASK BIT(1) + +#define ISL29028_CONF_ALS_DIS 0 +#define ISL29028_CONF_ALS_EN BIT(2) +#define ISL29028_CONF_ALS_EN_MASK BIT(2) + +#define ISL29028_CONF_PROX_SLP_SH 4 +#define ISL29028_CONF_PROX_SLP_MASK(7 << ISL29028_CONF_PROX_SLP_SH) + +#define ISL29028_CONF_PROX_EN BIT(7) +#define ISL29028_CONF_PROX_EN_MASK BIT(7) + +#define ISL29028_REG_INTERRUPT 0x02 + +#define ISL29028_REG_PROX_DATA 0x08 +#define ISL29028_REG_ALSIR_L 0x09 +#define ISL29028_REG_ALSIR_U 0x0A + +#define ISL29028_REG_TEST1_MODE0x0E +#define ISL29028_REG_TEST2_MODE0x0F + +#define ISL29028_NUM_REGS (ISL29028_REG_TEST2_MODE + 1) + +#define ISL29028_POWER_OFF_DELAY_MS2000 + +struct isl29028_prox_data { + int sampling_int; + int sampling_fract; + int sleep_time; +}; + +static const struct isl29028_prox_data isl29028_prox_data[] = { + { 1, 25, 800 }, + { 2, 50, 400 }, + { 5, 0, 200 }, + { 10, 0, 100 }, + { 13, 30, 75 }, + { 20, 0, 50 }, + { 80, 0, 13 }, /* + * Note
Re: [PATCH] staging: iio: isl29028: add isl29030 support
On Fri, Apr 28, 2017 at 05:55:58PM +0200, Sebastian Reichel wrote: > isl29030 is basically the same chip. The only difference > is the chip's first pin. For isl29028 its named ADDR0 and > can be used to change the chip's i2c address. For isl29030 > on the other hand that pin is named Ials and is an analog > current output proportional to ALS/IR. This change is > irrelevant for the Linux driver. > > This has been tested on Motorola Droid 4. > > Signed-off-by: Sebastian Reichel > --- > Documentation/devicetree/bindings/i2c/trivial-devices.txt | 1 + > drivers/staging/iio/light/isl29028.c | 6 ++ > 2 files changed, 7 insertions(+) Hi Sebastian, I moved this driver out of the staging directory earlier this week. You'll need to base your patch off of IIO testing: https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git/log/?h=testing Your patch should apply cleanly once you update the file path. Brian ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 1/2] staging: iio: tsl2x7x: rename driver for consistency with other IIO light drivers
This patch renames the tsl2x7x_core.c file to tsl2x7x.c so that the naming convention is consistent with other IIO light drivers outside of staging. Signed-off-by: Brian Masney --- drivers/staging/iio/light/Makefile | 2 +- drivers/staging/iio/light/{tsl2x7x_core.c => tsl2x7x.c} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename drivers/staging/iio/light/{tsl2x7x_core.c => tsl2x7x.c} (100%) diff --git a/drivers/staging/iio/light/Makefile b/drivers/staging/iio/light/Makefile index 10286c3..ab8dc3a 100644 --- a/drivers/staging/iio/light/Makefile +++ b/drivers/staging/iio/light/Makefile @@ -2,4 +2,4 @@ # Makefile for industrial I/O Light sensors # -obj-$(CONFIG_TSL2x7x) += tsl2x7x_core.o +obj-$(CONFIG_TSL2x7x) += tsl2x7x.o diff --git a/drivers/staging/iio/light/tsl2x7x_core.c b/drivers/staging/iio/light/tsl2x7x.c similarity index 100% rename from drivers/staging/iio/light/tsl2x7x_core.c rename to drivers/staging/iio/light/tsl2x7x.c -- 2.9.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 2/2] staging: iio: tsl2x7x: remove header file
There is a tsl2x7x.h header that is only used by tsl2x7x.c. This patch moves the contents of the header file into the C code with the driver. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 76 ++- drivers/staging/iio/light/tsl2x7x.h | 100 2 files changed, 75 insertions(+), 101 deletions(-) delete mode 100644 drivers/staging/iio/light/tsl2x7x.h diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index 8121a51..cd66c9f 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -30,7 +30,7 @@ #include #include #include -#include "tsl2x7x.h" +#include /* Cal defs*/ #define PROX_STAT_CAL0 @@ -126,6 +126,80 @@ #define TSL2X7X_MIN_ITIME 3 +/* 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) + +struct iio_dev; + +struct tsl2x7x_lux { + unsigned int ratio; + 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 + * @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 + * 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, + * 0x20 = prx, 0x30 = bth + * @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; + 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 + * @platform_power:Suspend/resume platform callback + * @power_on: Power on callback + * @power_off: Power off callback + * @platform_lux_table:Device specific glass coefficents + * @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]; + struct tsl2x7x_settings *platform_default_settings; +}; + /* TAOS txx2x7x Device family members */ enum { tsl2571, diff --git a/drivers/staging/iio/light/tsl2x7x.h b/drivers/staging/iio/light/tsl2x7x.h deleted file mode 100644 index ecae922..000 --- a/drivers/staging/iio/light/tsl2x7x.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - * 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 - * 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. - */ - -
[PATCH 0/2] staging: iio: tsl2x7x: staging cleanups
The two patches in this series begin my work to move this driver out of staging. Before I start working on the meat of the changes that are necessary for a staging graduation, I want to get these two trivial patches out and merged first in case there are any concerns with these changes. Brian Masney (2): staging: iio: tsl2x7x: rename driver for consistency with other IIO light drivers staging: iio: tsl2x7x: remove header file drivers/staging/iio/light/Makefile | 2 +- .../iio/light/{tsl2x7x_core.c => tsl2x7x.c}| 76 +++- drivers/staging/iio/light/tsl2x7x.h| 100 - 3 files changed, 76 insertions(+), 102 deletions(-) rename drivers/staging/iio/light/{tsl2x7x_core.c => tsl2x7x.c} (95%) delete mode 100644 drivers/staging/iio/light/tsl2x7x.h -- 2.9.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
Re: [PATCH v3] staging: iio: light: Replace symbolic permissions as per coding style
On Sat, May 20, 2017 at 06:55:02PM +0100, Jonathan Cameron wrote: > On 19/05/17 10:37, surenderpols...@gmail.com wrote: > >From: Surender Polsani > > > >Fixed the following checkpatch.pl warnings: > >octal permissions are more preferable than symbolic permissions > > > >Replaced DEVICE_ATTR family macros with DEVICE_ATTR_RW family > >as suggested by Greg K-H. Changed attributes and function > >names where ever required to satisfy internal macro definitions > >like __ATTR__RW(). > > > >Signed-off-by: Surender Polsani > Nicely presented patch, but it runs into the fact that some of these > shouldn't exist as hand rolled attrs in the first place. > > Some of theses should be handled through the various info_mask and > event_info_mask bitmaps + read_raw etc. > > This would be a much less mechanical change however... > > See inline and I'll try and pick out which ones. > > Brian is working on this driver as well at the moment so there may > well be some clashes. > > Perhaps you two could confer on who will target what? Saves > everyone time to work together! You can apply this if you'd like. I just got 7 different hardware samples from Jon this week that are supported by this driver. I haven't gotten far yet with coding since I'm currently working on getting them all setup so that it will be easy for me to test my upcoming driver changes. For my first patch series, I'm planning to migrate the driver to use IIO channels, cleaning up the I2C calls, and runtime power management support. Hopefully I'll have this to you for next weekend. Brian ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
Re: ks7010 firmware upload fail
On Mon, Jun 05, 2017 at 08:24:44PM +1000, Tobin C. Harding wrote: > On Mon, Jun 05, 2017 at 09:22:12AM +0200, Wolfram Sang wrote: > > Tobin, > > > > > My question is should I be digging further into the MMC code or be doing > > > something else with the driver code? > > > > So, you haven't found any branch that worked? No plain v4.9 or the > > gen3-sdio branch from my tree? > > I have not tried cloning your tree. I am using the Rasperry Pi kernel > source > > https://github.com/raspberrypi/linux > > which is v4.9.29 Hi Tobin, Here are some instructions on how to compile an upstream kernel for a Raspberry Pi: http://elinux.org/RPi_Upstream_Kernel_Compilation. It describes setting up u-boot as the boot loader instead of the boot loader that the Raspberry Pi kernel uses. One gotcha to be aware of is that the config.txt file on the sd card won't be used. Brian ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 01/19] staging: iio: isl29028: remove nested if statements
There are two callers to the function isl29028_set_als_ir_mode() and both instances use a nested if statement to only change the chip state if it is not in the proper mode. This patch moves this check into the isl29028_set_als_ir_mode() function to remove the nested if statements. Signed-off-by: Brian Masney --- drivers/staging/iio/light/isl29028.c | 30 ++ 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/drivers/staging/iio/light/isl29028.c b/drivers/staging/iio/light/isl29028.c index aa413e5..4e35d00 100644 --- a/drivers/staging/iio/light/isl29028.c +++ b/drivers/staging/iio/light/isl29028.c @@ -124,6 +124,9 @@ static int isl29028_set_als_ir_mode(struct isl29028_chip *chip, { int ret = 0; + if (chip->als_ir_mode == mode) + return 0; + switch (mode) { case ISL29028_MODE_ALS: ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, @@ -160,6 +163,9 @@ static int isl29028_set_als_ir_mode(struct isl29028_chip *chip, /* Need to wait for conversion time if ALS/IR mode enabled */ mdelay(ISL29028_CONV_TIME_MS); + + chip->als_ir_mode = mode; + return 0; } @@ -223,14 +229,10 @@ static int isl29028_als_get(struct isl29028_chip *chip, int *als_data) int ret; int als_ir_data; - if (chip->als_ir_mode != ISL29028_MODE_ALS) { - ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_ALS); - if (ret < 0) { - dev_err(dev, - "Error in enabling ALS mode err %d\n", ret); - return ret; - } - chip->als_ir_mode = ISL29028_MODE_ALS; + ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_ALS); + if (ret < 0) { + dev_err(dev, "Error in enabling ALS mode err %d\n", ret); + return ret; } ret = isl29028_read_als_ir(chip, &als_ir_data); @@ -256,14 +258,10 @@ static int isl29028_ir_get(struct isl29028_chip *chip, int *ir_data) struct device *dev = regmap_get_device(chip->regmap); int ret; - if (chip->als_ir_mode != ISL29028_MODE_IR) { - ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_IR); - if (ret < 0) { - dev_err(dev, - "Error in enabling IR mode err %d\n", ret); - return ret; - } - chip->als_ir_mode = ISL29028_MODE_IR; + ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_IR); + if (ret < 0) { + dev_err(dev, "Error in enabling IR mode err %d\n", ret); + return ret; } return isl29028_read_als_ir(chip, ir_data); } -- 2.7.4 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 02/19] staging: iio: isl29028: remove enable flag from isl29028_enable_proximity()
isl29028_enable_proximity() has a boolean argument named enable. This function is only called once and the enable flag is set to true in that call. This patch removes the enable parameter from that function. Signed-off-by: Brian Masney --- drivers/staging/iio/light/isl29028.c | 10 -- 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/staging/iio/light/isl29028.c b/drivers/staging/iio/light/isl29028.c index 4e35d00..c8e234d 100644 --- a/drivers/staging/iio/light/isl29028.c +++ b/drivers/staging/iio/light/isl29028.c @@ -93,15 +93,13 @@ static int isl29028_set_proxim_sampling(struct isl29028_chip *chip, sel << ISL29028_CONF_PROX_SLP_SH); } -static int isl29028_enable_proximity(struct isl29028_chip *chip, bool enable) +static int isl29028_enable_proximity(struct isl29028_chip *chip) { int ret; - int val = 0; - if (enable) - val = ISL29028_CONF_PROX_EN; ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, -ISL29028_CONF_PROX_EN_MASK, val); +ISL29028_CONF_PROX_EN_MASK, +ISL29028_CONF_PROX_EN); if (ret < 0) return ret; @@ -215,7 +213,7 @@ static int isl29028_proxim_get(struct isl29028_chip *chip, int *prox_data) int ret; if (!chip->enable_prox) { - ret = isl29028_enable_proximity(chip, true); + ret = isl29028_enable_proximity(chip); if (ret < 0) return ret; chip->enable_prox = true; -- 2.7.4 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 05/19] staging: iio: isl29028: made alignment of #defines consistent
The alignment of the #defines at the top of the file is not consistent. This changes all of the defines to use consistent alignment to improve the code readability. Signed-off-by: Brian Masney --- drivers/staging/iio/light/isl29028.c | 42 ++-- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/drivers/staging/iio/light/isl29028.c b/drivers/staging/iio/light/isl29028.c index e96a8cb..d5b069e 100644 --- a/drivers/staging/iio/light/isl29028.c +++ b/drivers/staging/iio/light/isl29028.c @@ -27,38 +27,38 @@ #include #include -#define ISL29028_CONV_TIME_MS 100 +#define ISL29028_CONV_TIME_MS 100 -#define ISL29028_REG_CONFIGURE 0x01 +#define ISL29028_REG_CONFIGURE 0x01 -#define ISL29028_CONF_ALS_IR_MODE_ALS 0 -#define ISL29028_CONF_ALS_IR_MODE_IR BIT(0) -#define ISL29028_CONF_ALS_IR_MODE_MASK BIT(0) +#define ISL29028_CONF_ALS_IR_MODE_ALS 0 +#define ISL29028_CONF_ALS_IR_MODE_IR BIT(0) +#define ISL29028_CONF_ALS_IR_MODE_MASK BIT(0) -#define ISL29028_CONF_ALS_RANGE_LOW_LUX0 +#define ISL29028_CONF_ALS_RANGE_LOW_LUX0 #define ISL29028_CONF_ALS_RANGE_HIGH_LUX BIT(1) -#define ISL29028_CONF_ALS_RANGE_MASK BIT(1) +#define ISL29028_CONF_ALS_RANGE_MASK BIT(1) -#define ISL29028_CONF_ALS_DIS 0 -#define ISL29028_CONF_ALS_EN BIT(2) -#define ISL29028_CONF_ALS_EN_MASK BIT(2) +#define ISL29028_CONF_ALS_DIS 0 +#define ISL29028_CONF_ALS_EN BIT(2) +#define ISL29028_CONF_ALS_EN_MASK BIT(2) -#define ISL29028_CONF_PROX_SLP_SH 4 -#define ISL29028_CONF_PROX_SLP_MASK(7 << ISL29028_CONF_PROX_SLP_SH) +#define ISL29028_CONF_PROX_SLP_SH 4 +#define ISL29028_CONF_PROX_SLP_MASK(7 << ISL29028_CONF_PROX_SLP_SH) -#define ISL29028_CONF_PROX_EN BIT(7) -#define ISL29028_CONF_PROX_EN_MASK BIT(7) +#define ISL29028_CONF_PROX_EN BIT(7) +#define ISL29028_CONF_PROX_EN_MASK BIT(7) -#define ISL29028_REG_INTERRUPT 0x02 +#define ISL29028_REG_INTERRUPT 0x02 -#define ISL29028_REG_PROX_DATA 0x08 -#define ISL29028_REG_ALSIR_L 0x09 -#define ISL29028_REG_ALSIR_U 0x0A +#define ISL29028_REG_PROX_DATA 0x08 +#define ISL29028_REG_ALSIR_L 0x09 +#define ISL29028_REG_ALSIR_U 0x0A -#define ISL29028_REG_TEST1_MODE0x0E -#define ISL29028_REG_TEST2_MODE0x0F +#define ISL29028_REG_TEST1_MODE0x0E +#define ISL29028_REG_TEST2_MODE0x0F -#define ISL29028_NUM_REGS (ISL29028_REG_TEST2_MODE + 1) +#define ISL29028_NUM_REGS (ISL29028_REG_TEST2_MODE + 1) enum isl29028_als_ir_mode { ISL29028_MODE_NONE = 0, -- 2.7.4 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 04/19] staging: iio: isl29028: add power management support
This patch adds power management support to the isl29028 driver. Signed-off-by: Brian Masney --- drivers/staging/iio/light/isl29028.c | 59 1 file changed, 59 insertions(+) diff --git a/drivers/staging/iio/light/isl29028.c b/drivers/staging/iio/light/isl29028.c index 4f819a8..e96a8cb 100644 --- a/drivers/staging/iio/light/isl29028.c +++ b/drivers/staging/iio/light/isl29028.c @@ -75,6 +75,7 @@ struct isl29028_chip { int lux_scale; enum isl29028_als_ir_mode als_ir_mode; + boolsuspended; }; static int isl29028_set_proxim_sampling(struct isl29028_chip *chip, @@ -274,6 +275,12 @@ static int isl29028_write_raw(struct iio_dev *indio_dev, int ret = -EINVAL; mutex_lock(&chip->lock); + + if (chip->suspended) { + ret = -EBUSY; + goto write_done; + } + switch (chan->type) { case IIO_PROXIMITY: if (mask != IIO_CHAN_INFO_SAMP_FREQ) { @@ -322,6 +329,8 @@ static int isl29028_write_raw(struct iio_dev *indio_dev, dev_err(dev, "Unsupported channel type\n"); break; } + +write_done: mutex_unlock(&chip->lock); return ret; } @@ -335,6 +344,12 @@ static int isl29028_read_raw(struct iio_dev *indio_dev, int ret = -EINVAL; mutex_lock(&chip->lock); + + if (chip->suspended) { + ret = -EBUSY; + goto read_done; + } + switch (mask) { case IIO_CHAN_INFO_RAW: case IIO_CHAN_INFO_PROCESSED: @@ -374,6 +389,8 @@ static int isl29028_read_raw(struct iio_dev *indio_dev, dev_err(dev, "mask value 0x%08lx not supported\n", mask); break; } + +read_done: mutex_unlock(&chip->lock); return ret; } @@ -437,6 +454,9 @@ static int isl29028_chip_init_and_power_on(struct isl29028_chip *chip) ret = isl29028_set_als_scale(chip, chip->lux_scale); if (ret < 0) dev_err(dev, "setting als scale failed, err = %d\n", ret); + + chip->suspended = false; + return ret; } @@ -479,6 +499,7 @@ static int isl29028_probe(struct i2c_client *client, i2c_set_clientdata(client, indio_dev); mutex_init(&chip->lock); + chip->suspended = true; chip->regmap = devm_regmap_init_i2c(client, &isl29028_regmap_config); if (IS_ERR(chip->regmap)) { @@ -530,6 +551,43 @@ static int isl29028_probe(struct i2c_client *client, return 0; } +static int __maybe_unused isl29028_suspend(struct device *dev) +{ + struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); + struct isl29028_chip *chip = iio_priv(indio_dev); + int ret; + + mutex_lock(&chip->lock); + + ret = regmap_write(chip->regmap, ISL29028_REG_CONFIGURE, 0x0); + if (ret < 0) + dev_err(dev, "%s(): Error %d turning off chip\n", __func__, + ret); + + chip->suspended = true; + + mutex_unlock(&chip->lock); + + return ret; +} + +static int __maybe_unused isl29028_resume(struct device *dev) +{ + struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); + struct isl29028_chip *chip = iio_priv(indio_dev); + int ret; + + mutex_lock(&chip->lock); + + ret = isl29028_chip_init_and_power_on(chip); + + mutex_unlock(&chip->lock); + + return ret; +} + +static SIMPLE_DEV_PM_OPS(isl29028_pm_ops, isl29028_suspend, isl29028_resume); + static const struct i2c_device_id isl29028_id[] = { {"isl29028", 0}, {} @@ -546,6 +604,7 @@ MODULE_DEVICE_TABLE(of, isl29028_of_match); static struct i2c_driver isl29028_driver = { .driver = { .name = "isl29028", + .pm = &isl29028_pm_ops, .of_match_table = isl29028_of_match, }, .probe = isl29028_probe, -- 2.7.4 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 00/19] staging: iio: isl29028: staging cleanups
This is my first round of cleanups to the isl29028 light driver in preparation for moving the driver out of staging. The main feature introduced by this patch set is support for power management. The rest of the patches are minor improvements, mostly style. I have one of these devices from https://www.digikey.com/product-detail/en/intersil/ISL29028AIROZ-T7/ISL29028AIROZ-T7CT-ND/2639604 mounted on a breakout board hooked up to a Raspberry Pi 2. The IR and light sensor are functioning, however I can't get the proximity sensor to work. I hooked an oscilloscope up to the IRDR pin and +3V to verify that the pin state begins pulsing when proximity mode is enabled on the chip. According to page 9 of the datasheet http://www.intersil.com/content/dam/Intersil/documents/isl2/isl29028.pdf, the chip has a noise reduction feature where it will take an IR reading with the IR LED off to get the baseline, drive the IR LED for 0.1ms, take another IR reading, and subtract the two readings. My hunch about the cause of my issue is the 5mm IR LED that I am using is still emitting IR light during the brief time that the IRDR has no power. The LED is huge size wise compared to the size of the chip. Replacing the IR LED with a visible light LED causes the visible light LED to become illuminated dimly when the IRDR pin begins pulsing. Any suggestions are welcome. Ideally, I'd like to verify that the proximity sensing works before submitting a patch moving the driver out of staging. Looking through the data sheet, and the git commits since the driver was first introduced into staging, everything in the driver looks correct so I think this is operator error on my part. Brian Masney (19): staging: iio: isl29028: remove nested if statements staging: iio: isl29028: remove enable flag from isl29028_enable_proximity() staging: iio: isl29028: remove chip test and defaults from isl29028_chip_init() staging: iio: isl29028: add power management support staging: iio: isl29028: made alignment of #defines consistent staging: iio: isl29028: made alignment of variables in struct isl29028_chip consistent staging: iio: isl29028: fix alignment of function arguments staging: iio: isl29028: combine isl29028_proxim_get() and isl29028_read_proxim() staging: iio: isl29028: change newlines to improve readability staging: iio: isl29028: remove unused define ISL29028_DEV_ATTR staging: iio: isl29028: made column alignment in isl29028_channels consistent staging: iio: isl29028: fix comparison between signed and unsigned integers staging: iio: isl29028: move failure logging into isl29028_set_proxim_sampling() staging: iio: isl29028: move failure logging into isl29028_set_als_scale() staging: iio: isl29028: made error messages consistent staging: iio: isl29028: remove unnecessary error logging in isl29028_chip_init_and_power_on() staging: iio: isl29028: remove out of memory log message staging: iio: isl29028: remove unnecessary parenthesis staging: iio: isl29028: remove legacy device tree binding drivers/staging/iio/light/isl29028.c | 358 +-- 1 file changed, 215 insertions(+), 143 deletions(-) -- 2.7.4 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 06/19] staging: iio: isl29028: made alignment of variables in struct isl29028_chip consistent
The alignment of the variables in the struct isl29028_chip is not consistent. This changes all of the variables to use consistent alignment to improve the code readability. Signed-off-by: Brian Masney --- drivers/staging/iio/light/isl29028.c | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/staging/iio/light/isl29028.c b/drivers/staging/iio/light/isl29028.c index d5b069e..fe8814b 100644 --- a/drivers/staging/iio/light/isl29028.c +++ b/drivers/staging/iio/light/isl29028.c @@ -67,13 +67,13 @@ enum isl29028_als_ir_mode { }; struct isl29028_chip { - struct mutexlock; - struct regmap *regmap; + struct mutexlock; + struct regmap *regmap; - unsigned intprox_sampling; - boolenable_prox; + unsigned intprox_sampling; + boolenable_prox; - int lux_scale; + int lux_scale; enum isl29028_als_ir_mode als_ir_mode; boolsuspended; }; -- 2.7.4 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 03/19] staging: iio: isl29028: remove chip test and defaults from isl29028_chip_init()
isl29028_chip_init() contains the device driver defaults and two I2C calls that detect the presence of the chip. This patch moves these into isl29028_probe() so that this function can be used by the power management runtinme in a followup patch. This patch also renames isl29028_chip_init() to isl29028_chip_init_and_power_on(). Signed-off-by: Brian Masney --- drivers/staging/iio/light/isl29028.c | 42 +++- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/drivers/staging/iio/light/isl29028.c b/drivers/staging/iio/light/isl29028.c index c8e234d..4f819a8 100644 --- a/drivers/staging/iio/light/isl29028.c +++ b/drivers/staging/iio/light/isl29028.c @@ -416,29 +416,11 @@ static const struct iio_info isl29028_info = { .write_raw = isl29028_write_raw, }; -static int isl29028_chip_init(struct isl29028_chip *chip) +static int isl29028_chip_init_and_power_on(struct isl29028_chip *chip) { struct device *dev = regmap_get_device(chip->regmap); int ret; - chip->enable_prox = false; - chip->prox_sampling = 20; - chip->lux_scale = 2000; - chip->als_ir_mode = ISL29028_MODE_NONE; - - ret = regmap_write(chip->regmap, ISL29028_REG_TEST1_MODE, 0x0); - if (ret < 0) { - dev_err(dev, "%s(): write to reg %d failed, err = %d\n", - __func__, ISL29028_REG_TEST1_MODE, ret); - return ret; - } - ret = regmap_write(chip->regmap, ISL29028_REG_TEST2_MODE, 0x0); - if (ret < 0) { - dev_err(dev, "%s(): write to reg %d failed, err = %d\n", - __func__, ISL29028_REG_TEST2_MODE, ret); - return ret; - } - ret = regmap_write(chip->regmap, ISL29028_REG_CONFIGURE, 0x0); if (ret < 0) { dev_err(dev, "%s(): write to reg %d failed, err = %d\n", @@ -506,7 +488,27 @@ static int isl29028_probe(struct i2c_client *client, return ret; } - ret = isl29028_chip_init(chip); + chip->enable_prox = false; + chip->prox_sampling = 20; + chip->lux_scale = 2000; + chip->als_ir_mode = ISL29028_MODE_NONE; + + ret = regmap_write(chip->regmap, ISL29028_REG_TEST1_MODE, 0x0); + if (ret < 0) { + dev_err(&client->dev, + "%s(): write to reg %d failed, err = %d\n", __func__, + ISL29028_REG_TEST1_MODE, ret); + return ret; + } + ret = regmap_write(chip->regmap, ISL29028_REG_TEST2_MODE, 0x0); + if (ret < 0) { + dev_err(&client->dev, + "%s(): write to reg %d failed, err = %d\n", __func__, + ISL29028_REG_TEST2_MODE, ret); + return ret; + } + + ret = isl29028_chip_init_and_power_on(chip); if (ret < 0) { dev_err(&client->dev, "chip initialization failed: %d\n", ret); return ret; -- 2.7.4 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 13/19] staging: iio: isl29028: move failure logging into isl29028_set_proxim_sampling()
When isl29028_set_proxim_sampling() fails, it was up to both callers to log the failure message. This patch moves the logging into isl29028_set_proxim_sampling() to reduce the overall amount of code in the driver. Signed-off-by: Brian Masney --- drivers/staging/iio/light/isl29028.c | 28 ++-- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/drivers/staging/iio/light/isl29028.c b/drivers/staging/iio/light/isl29028.c index 23a4db8..0c8a878 100644 --- a/drivers/staging/iio/light/isl29028.c +++ b/drivers/staging/iio/light/isl29028.c @@ -79,18 +79,28 @@ struct isl29028_chip { static int isl29028_set_proxim_sampling(struct isl29028_chip *chip, unsigned int sampling) { + struct device *dev = regmap_get_device(chip->regmap); static unsigned int prox_period[] = {800, 400, 200, 100, 75, 50, 12, 0}; unsigned int sel; unsigned int period = DIV_ROUND_UP(1000, sampling); + int ret; for (sel = 0; sel < ARRAY_SIZE(prox_period); ++sel) { if (period >= prox_period[sel]) break; } - return regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, - ISL29028_CONF_PROX_SLP_MASK, - sel << ISL29028_CONF_PROX_SLP_SH); + ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, +ISL29028_CONF_PROX_SLP_MASK, +sel << ISL29028_CONF_PROX_SLP_SH); + if (ret < 0) + dev_err(dev, + "%s(): Error %d setting the proximity sampling\n", + __func__, ret); + else + chip->prox_sampling = sampling; + + return ret; } static int isl29028_enable_proximity(struct isl29028_chip *chip) @@ -296,14 +306,6 @@ static int isl29028_write_raw(struct iio_dev *indio_dev, } ret = isl29028_set_proxim_sampling(chip, val); - if (ret < 0) { - dev_err(dev, - "Setting proximity samp_freq fail, err %d\n", - ret); - break; - } - - chip->prox_sampling = val; break; case IIO_LIGHT: if (mask != IIO_CHAN_INFO_SCALE) { @@ -452,10 +454,8 @@ static int isl29028_chip_init_and_power_on(struct isl29028_chip *chip) } ret = isl29028_set_proxim_sampling(chip, chip->prox_sampling); - if (ret < 0) { - dev_err(dev, "setting the proximity, err = %d\n", ret); + if (ret < 0) return ret; - } ret = isl29028_set_als_scale(chip, chip->lux_scale); if (ret < 0) -- 2.7.4 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 07/19] staging: iio: isl29028: fix alignment of function arguments
Two separate calls to regmap_update_bits() in isl29028_set_als_scale() and isl29028_set_als_ir_mode() did not have their function arguments on the next line aligned correctly to the open parenthesis. This patch corrects the alignment. Signed-off-by: Brian Masney --- drivers/staging/iio/light/isl29028.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/staging/iio/light/isl29028.c b/drivers/staging/iio/light/isl29028.c index fe8814b..38027ee 100644 --- a/drivers/staging/iio/light/isl29028.c +++ b/drivers/staging/iio/light/isl29028.c @@ -115,7 +115,7 @@ static int isl29028_set_als_scale(struct isl29028_chip *chip, int lux_scale) ISL29028_CONF_ALS_RANGE_LOW_LUX; return regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, - ISL29028_CONF_ALS_RANGE_MASK, val); + ISL29028_CONF_ALS_RANGE_MASK, val); } static int isl29028_set_als_ir_mode(struct isl29028_chip *chip, @@ -147,7 +147,8 @@ static int isl29028_set_als_ir_mode(struct isl29028_chip *chip, case ISL29028_MODE_NONE: return regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, - ISL29028_CONF_ALS_EN_MASK, ISL29028_CONF_ALS_DIS); + ISL29028_CONF_ALS_EN_MASK, + ISL29028_CONF_ALS_DIS); } if (ret < 0) -- 2.7.4 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 17/19] staging: iio: isl29028: remove out of memory log message
If the call to devm_iio_device_alloc() fails, then isl29028_probe() logs a message saying that memory cannot be allocated. The user's system most likely has larger issues at this point. This patch removes that error message since the error code is passed on and the message is not necessary. Signed-off-by: Brian Masney --- drivers/staging/iio/light/isl29028.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/staging/iio/light/isl29028.c b/drivers/staging/iio/light/isl29028.c index 3f01ad1..bda5183 100644 --- a/drivers/staging/iio/light/isl29028.c +++ b/drivers/staging/iio/light/isl29028.c @@ -507,10 +507,8 @@ static int isl29028_probe(struct i2c_client *client, int ret; indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip)); - if (!indio_dev) { - dev_err(&client->dev, "iio allocation fails\n"); + if (!indio_dev) return -ENOMEM; - } chip = iio_priv(indio_dev); -- 2.7.4 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 19/19] staging: iio: isl29028: remove legacy device tree binding
The isl29028 staging driver contains a legacy binding of "isl,isl29028" that is marked as legacy and to not use. There are no in tree references to that binding. This patch removes the legacy binding in preparation for moving the driver out of staging. Otherwise, we will have to support this binding indefinitely. Signed-off-by: Brian Masney Cc: devicet...@vger.kernel.org Cc: Rob Herring Cc: Mark Rutland --- drivers/staging/iio/light/isl29028.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/staging/iio/light/isl29028.c b/drivers/staging/iio/light/isl29028.c index ae6896f..6be9aa7 100644 --- a/drivers/staging/iio/light/isl29028.c +++ b/drivers/staging/iio/light/isl29028.c @@ -611,7 +611,6 @@ static const struct i2c_device_id isl29028_id[] = { MODULE_DEVICE_TABLE(i2c, isl29028_id); static const struct of_device_id isl29028_of_match[] = { - { .compatible = "isl,isl29028", }, /* for backward compat., don't use */ { .compatible = "isil,isl29028", }, { }, }; -- 2.7.4 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 12/19] staging: iio: isl29028: fix comparison between signed and unsigned integers
Fixed warning found by make W=2 to reduce the amount of build noise: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] Signed-off-by: Brian Masney --- drivers/staging/iio/light/isl29028.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/staging/iio/light/isl29028.c b/drivers/staging/iio/light/isl29028.c index 218d165..23a4db8 100644 --- a/drivers/staging/iio/light/isl29028.c +++ b/drivers/staging/iio/light/isl29028.c @@ -80,7 +80,7 @@ static int isl29028_set_proxim_sampling(struct isl29028_chip *chip, unsigned int sampling) { static unsigned int prox_period[] = {800, 400, 200, 100, 75, 50, 12, 0}; - int sel; + unsigned int sel; unsigned int period = DIV_ROUND_UP(1000, sampling); for (sel = 0; sel < ARRAY_SIZE(prox_period); ++sel) { -- 2.7.4 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 14/19] staging: iio: isl29028: move failure logging into isl29028_set_als_scale()
When isl29028_set_als_scale() fails, it was up to both callers to log the failure message. This patch moves the logging into isl29028_set_als_scale() to reduce the overall amount of code in the driver. Signed-off-by: Brian Masney --- drivers/staging/iio/light/isl29028.c | 23 +-- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/drivers/staging/iio/light/isl29028.c b/drivers/staging/iio/light/isl29028.c index 0c8a878..11e1673 100644 --- a/drivers/staging/iio/light/isl29028.c +++ b/drivers/staging/iio/light/isl29028.c @@ -121,11 +121,21 @@ static int isl29028_enable_proximity(struct isl29028_chip *chip) static int isl29028_set_als_scale(struct isl29028_chip *chip, int lux_scale) { + struct device *dev = regmap_get_device(chip->regmap); int val = (lux_scale == 2000) ? ISL29028_CONF_ALS_RANGE_HIGH_LUX : ISL29028_CONF_ALS_RANGE_LOW_LUX; + int ret; + + ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, +ISL29028_CONF_ALS_RANGE_MASK, val); + if (ret < 0) + dev_err(dev, + "%s(): Error %d setting the ALS scale\n", __func__, + ret); + else + chip->lux_scale = lux_scale; - return regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, - ISL29028_CONF_ALS_RANGE_MASK, val); + return ret; } static int isl29028_set_als_ir_mode(struct isl29028_chip *chip, @@ -322,13 +332,6 @@ static int isl29028_write_raw(struct iio_dev *indio_dev, } ret = isl29028_set_als_scale(chip, val); - if (ret < 0) { - dev_err(dev, - "Setting lux scale fail with error %d\n", ret); - break; - } - - chip->lux_scale = val; break; default: dev_err(dev, "Unsupported channel type\n"); @@ -459,7 +462,7 @@ static int isl29028_chip_init_and_power_on(struct isl29028_chip *chip) ret = isl29028_set_als_scale(chip, chip->lux_scale); if (ret < 0) - dev_err(dev, "setting als scale failed, err = %d\n", ret); + return ret; chip->suspended = false; -- 2.7.4 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 10/19] staging: iio: isl29028: remove unused define ISL29028_DEV_ATTR
The #define ISL29028_DEV_ATTR was not used so this patch removes the unnecessary code. Signed-off-by: Brian Masney --- drivers/staging/iio/light/isl29028.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/staging/iio/light/isl29028.c b/drivers/staging/iio/light/isl29028.c index 8f9295f..0e727ba 100644 --- a/drivers/staging/iio/light/isl29028.c +++ b/drivers/staging/iio/light/isl29028.c @@ -404,7 +404,6 @@ static IIO_CONST_ATTR(in_proximity_sampling_frequency_available, "1 3 5 10 13 20 83 100"); static IIO_CONST_ATTR(in_illuminance_scale_available, "125 2000"); -#define ISL29028_DEV_ATTR(name) (&iio_dev_attr_##name.dev_attr.attr) #define ISL29028_CONST_ATTR(name) (&iio_const_attr_##name.dev_attr.attr) static struct attribute *isl29028_attributes[] = { ISL29028_CONST_ATTR(in_proximity_sampling_frequency_available), -- 2.7.4 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 09/19] staging: iio: isl29028: change newlines to improve readability
Add and remove newlines to improve code readability in preparation for moving the driver out of staging. Signed-off-by: Brian Masney --- drivers/staging/iio/light/isl29028.c | 31 ++- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/drivers/staging/iio/light/isl29028.c b/drivers/staging/iio/light/isl29028.c index fa2b283..8f9295f 100644 --- a/drivers/staging/iio/light/isl29028.c +++ b/drivers/staging/iio/light/isl29028.c @@ -69,10 +69,8 @@ enum isl29028_als_ir_mode { struct isl29028_chip { struct mutexlock; struct regmap *regmap; - unsigned intprox_sampling; boolenable_prox; - int lux_scale; enum isl29028_als_ir_mode als_ir_mode; boolsuspended; @@ -89,6 +87,7 @@ static int isl29028_set_proxim_sampling(struct isl29028_chip *chip, if (period >= prox_period[sel]) break; } + return regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, ISL29028_CONF_PROX_SLP_MASK, sel << ISL29028_CONF_PROX_SLP_SH); @@ -106,6 +105,7 @@ static int isl29028_enable_proximity(struct isl29028_chip *chip) /* Wait for conversion to be complete for first sample */ mdelay(DIV_ROUND_UP(1000, chip->prox_sampling)); + return 0; } @@ -138,13 +138,11 @@ static int isl29028_set_als_ir_mode(struct isl29028_chip *chip, ISL29028_CONF_ALS_RANGE_MASK, ISL29028_CONF_ALS_RANGE_HIGH_LUX); break; - case ISL29028_MODE_IR: ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, ISL29028_CONF_ALS_IR_MODE_MASK, ISL29028_CONF_ALS_IR_MODE_IR); break; - case ISL29028_MODE_NONE: return regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, ISL29028_CONF_ALS_EN_MASK, @@ -191,6 +189,7 @@ static int isl29028_read_als_ir(struct isl29028_chip *chip, int *als_ir) } *als_ir = ((msb & 0xF) << 8) | (lsb & 0xFF); + return 0; } @@ -204,6 +203,7 @@ static int isl29028_read_proxim(struct isl29028_chip *chip, int *prox) ret = isl29028_enable_proximity(chip); if (ret < 0) return ret; + chip->enable_prox = true; } @@ -213,7 +213,9 @@ static int isl29028_read_proxim(struct isl29028_chip *chip, int *prox) ISL29028_REG_PROX_DATA, ret); return ret; } + *prox = data; + return 0; } @@ -244,6 +246,7 @@ static int isl29028_als_get(struct isl29028_chip *chip, int *als_data) als_ir_data = (als_ir_data * 49) / 100; *als_data = als_ir_data; + return 0; } @@ -257,6 +260,7 @@ static int isl29028_ir_get(struct isl29028_chip *chip, int *ir_data) dev_err(dev, "Error in enabling IR mode err %d\n", ret); return ret; } + return isl29028_read_als_ir(chip, ir_data); } @@ -284,11 +288,13 @@ static int isl29028_write_raw(struct iio_dev *indio_dev, mask); break; } + if (val < 1 || val > 100) { dev_err(dev, "Samp_freq %d is not in range[1:100]\n", val); break; } + ret = isl29028_set_proxim_sampling(chip, val); if (ret < 0) { dev_err(dev, @@ -296,9 +302,9 @@ static int isl29028_write_raw(struct iio_dev *indio_dev, ret); break; } + chip->prox_sampling = val; break; - case IIO_LIGHT: if (mask != IIO_CHAN_INFO_SCALE) { dev_err(dev, @@ -306,20 +312,22 @@ static int isl29028_write_raw(struct iio_dev *indio_dev, mask); break; } + if ((val != 125) && (val != 2000)) { dev_err(dev, "lux scale %d is invalid [125, 2000]\n", val); break; } + ret = isl29028_set_als_scale(chip, val); if (ret < 0) { dev_err(dev, "Setting lux scale fail with error %d\n", ret); br
[PATCH 16/19] staging: iio: isl29028: remove unnecessary error logging in isl29028_chip_init_and_power_on()
If the call to isl29028_chip_init_and_power_on() in isl29028_probe() fails, then isl29028_probe() will log an error message. All of the error paths in that call path already have error logging in place. This patch removes the unnecessary logging. Signed-off-by: Brian Masney --- drivers/staging/iio/light/isl29028.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/staging/iio/light/isl29028.c b/drivers/staging/iio/light/isl29028.c index a45d57c..3f01ad1 100644 --- a/drivers/staging/iio/light/isl29028.c +++ b/drivers/staging/iio/light/isl29028.c @@ -548,10 +548,8 @@ static int isl29028_probe(struct i2c_client *client, } ret = isl29028_chip_init_and_power_on(chip); - if (ret < 0) { - dev_err(&client->dev, "chip initialization failed: %d\n", ret); + if (ret < 0) return ret; - } indio_dev->info = &isl29028_info; indio_dev->channels = isl29028_channels; -- 2.7.4 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 08/19] staging: iio: isl29028: combine isl29028_proxim_get() and isl29028_read_proxim()
isl29028_proxim_get() checks to see if the promixity needs to be enabled on the chip and then calls isl29028_read_proxim(). There are no other callers of isl29028_read_proxim(). The naming between these two functions can be confusing so this patch combines the two to avoid the confusion. Signed-off-by: Brian Masney --- drivers/staging/iio/light/isl29028.c | 22 -- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/drivers/staging/iio/light/isl29028.c b/drivers/staging/iio/light/isl29028.c index 38027ee..fa2b283 100644 --- a/drivers/staging/iio/light/isl29028.c +++ b/drivers/staging/iio/light/isl29028.c @@ -200,6 +200,13 @@ static int isl29028_read_proxim(struct isl29028_chip *chip, int *prox) unsigned int data; int ret; + if (!chip->enable_prox) { + ret = isl29028_enable_proximity(chip); + if (ret < 0) + return ret; + chip->enable_prox = true; + } + ret = regmap_read(chip->regmap, ISL29028_REG_PROX_DATA, &data); if (ret < 0) { dev_err(dev, "Error in reading register %d, error %d\n", @@ -210,19 +217,6 @@ static int isl29028_read_proxim(struct isl29028_chip *chip, int *prox) return 0; } -static int isl29028_proxim_get(struct isl29028_chip *chip, int *prox_data) -{ - int ret; - - if (!chip->enable_prox) { - ret = isl29028_enable_proximity(chip); - if (ret < 0) - return ret; - chip->enable_prox = true; - } - return isl29028_read_proxim(chip, prox_data); -} - static int isl29028_als_get(struct isl29028_chip *chip, int *als_data) { struct device *dev = regmap_get_device(chip->regmap); @@ -362,7 +356,7 @@ static int isl29028_read_raw(struct iio_dev *indio_dev, ret = isl29028_ir_get(chip, val); break; case IIO_PROXIMITY: - ret = isl29028_proxim_get(chip, val); + ret = isl29028_read_proxim(chip, val); break; default: break; -- 2.7.4 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 15/19] staging: iio: isl29028: made error messages consistent
The wording and style of the different error messages was not consistent. This patches makes the wording and style consistent throughout the driver. Signed-off-by: Brian Masney --- drivers/staging/iio/light/isl29028.c | 56 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/drivers/staging/iio/light/isl29028.c b/drivers/staging/iio/light/isl29028.c index 11e1673..a45d57c 100644 --- a/drivers/staging/iio/light/isl29028.c +++ b/drivers/staging/iio/light/isl29028.c @@ -197,14 +197,16 @@ static int isl29028_read_als_ir(struct isl29028_chip *chip, int *als_ir) ret = regmap_read(chip->regmap, ISL29028_REG_ALSIR_L, &lsb); if (ret < 0) { dev_err(dev, - "Error in reading register ALSIR_L err %d\n", ret); + "%s(): Error %d reading register ALSIR_L\n", + __func__, ret); return ret; } ret = regmap_read(chip->regmap, ISL29028_REG_ALSIR_U, &msb); if (ret < 0) { dev_err(dev, - "Error in reading register ALSIR_U err %d\n", ret); + "%s(): Error %d reading register ALSIR_U\n", + __func__, ret); return ret; } @@ -229,8 +231,8 @@ static int isl29028_read_proxim(struct isl29028_chip *chip, int *prox) ret = regmap_read(chip->regmap, ISL29028_REG_PROX_DATA, &data); if (ret < 0) { - dev_err(dev, "Error in reading register %d, error %d\n", - ISL29028_REG_PROX_DATA, ret); + dev_err(dev, "%s(): Error %d reading register PROX_DATA\n", + __func__, ret); return ret; } @@ -247,7 +249,8 @@ static int isl29028_als_get(struct isl29028_chip *chip, int *als_data) ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_ALS); if (ret < 0) { - dev_err(dev, "Error in enabling ALS mode err %d\n", ret); + dev_err(dev, "%s(): Error %d enabling ALS mode\n", __func__, + ret); return ret; } @@ -277,7 +280,8 @@ static int isl29028_ir_get(struct isl29028_chip *chip, int *ir_data) ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_IR); if (ret < 0) { - dev_err(dev, "Error in enabling IR mode err %d\n", ret); + dev_err(dev, "%s(): Error %d enabling IR mode\n", __func__, + ret); return ret; } @@ -304,14 +308,15 @@ static int isl29028_write_raw(struct iio_dev *indio_dev, case IIO_PROXIMITY: if (mask != IIO_CHAN_INFO_SAMP_FREQ) { dev_err(dev, - "proximity: mask value 0x%08lx not supported\n", - mask); + "%s(): proximity: Mask value 0x%08lx is not supported\n", + __func__, mask); break; } if (val < 1 || val > 100) { dev_err(dev, - "Samp_freq %d is not in range[1:100]\n", val); + "%s(): proximity: Sampling frequency %d is not in the range [1:100]\n", + __func__, val); break; } @@ -320,21 +325,23 @@ static int isl29028_write_raw(struct iio_dev *indio_dev, case IIO_LIGHT: if (mask != IIO_CHAN_INFO_SCALE) { dev_err(dev, - "light: mask value 0x%08lx not supported\n", - mask); + "%s(): light: Mask value 0x%08lx is not supported\n", + __func__, mask); break; } if ((val != 125) && (val != 2000)) { dev_err(dev, - "lux scale %d is invalid [125, 2000]\n", val); + "%s(): light: Lux scale %d is not in the set {125, 2000}\n", + __func__, val); break; } ret = isl29028_set_als_scale(chip, val); break; default: - dev_err(dev, "Unsupported channel type\n"); + dev_err(dev, "%s(): Unsupported channel type %x\n", + __func__, chan->type); break; } @@ -395,7 +402,8 @@ static int isl29028_read_raw(struct iio_dev *indio_dev, ret = IIO_VAL_INT;
[PATCH 18/19] staging: iio: isl29028: remove unnecessary parenthesis
isl29028_write_raw() contains unnecessary parenthesis when checking to see if the passed in lux scale is valid. This patch removes the unnecessary parenthesis. Signed-off-by: Brian Masney --- drivers/staging/iio/light/isl29028.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/staging/iio/light/isl29028.c b/drivers/staging/iio/light/isl29028.c index bda5183..ae6896f 100644 --- a/drivers/staging/iio/light/isl29028.c +++ b/drivers/staging/iio/light/isl29028.c @@ -330,7 +330,7 @@ static int isl29028_write_raw(struct iio_dev *indio_dev, break; } - if ((val != 125) && (val != 2000)) { + if (val != 125 && val != 2000) { dev_err(dev, "%s(): light: Lux scale %d is not in the set {125, 2000}\n", __func__, val); -- 2.7.4 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 11/19] staging: iio: isl29028: made column alignment in isl29028_channels consistent
The three info_mask_separate members OR several BIT(xxx) fields together. This patch changes the column alignment of these fields to be aligned at the same column to improve the overall code readability. It also moves the { for the next channel to the next line to improve code readability. Signed-off-by: Brian Masney --- drivers/staging/iio/light/isl29028.c | 10 ++ 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/staging/iio/light/isl29028.c b/drivers/staging/iio/light/isl29028.c index 0e727ba..218d165 100644 --- a/drivers/staging/iio/light/isl29028.c +++ b/drivers/staging/iio/light/isl29028.c @@ -419,14 +419,16 @@ static const struct iio_chan_spec isl29028_channels[] = { { .type = IIO_LIGHT, .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | - BIT(IIO_CHAN_INFO_SCALE), - }, { + BIT(IIO_CHAN_INFO_SCALE), + }, + { .type = IIO_INTENSITY, .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - }, { + }, + { .type = IIO_PROXIMITY, .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | - BIT(IIO_CHAN_INFO_SAMP_FREQ), + BIT(IIO_CHAN_INFO_SAMP_FREQ), } }; -- 2.7.4 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
Re: [PATCH 12/19] staging: iio: isl29028: fix comparison between signed and unsigned integers
On Mon, Dec 05, 2016 at 11:53:39PM +0300, Dan Carpenter wrote: > On Sat, Dec 03, 2016 at 09:19:36PM -0500, Brian Masney wrote: > > Fixed warning found by make W=2 to reduce the amount of build noise: > > > > warning: comparison between signed and unsigned integer expressions > > [-Wsign-compare] > > Ugh... Please don't do work arounds for nonsense warnings. W=2 is so > stupid. Better to just grep -v this warning instead of trying to please > a broken static analysis. Warnings like this are why it's disabled by > default. Hi Dan, I would normally agree, however there could be a case where this warning flags a legitimate issue. It is obviously not an issue in this case. Since I'm already working on cleaning up this driver to move it out of staging, I figured that I would make sure that it builds cleanly with W=2. This was the only warning found in that driver. The change is harmless in my opinion and it may eliminate a nonsense warning for someone else down the road when doing security audits. This driver doesn't need much to move it out of staging. Most of the patches in this series were trivial cleanups and not interesting at all. Since I already have one of these devices, I figured that I'd do the grunt work to get it out of staging. My goal with the upcoming final patch that moves it out of staging is to reduce the amount of code churn in the driver once it graduates from staging. Brian ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
Re: [PATCH 02/19] staging: iio: isl29028: remove enable flag from isl29028_enable_proximity()
On Sun, Dec 04, 2016 at 11:16:04AM +, Jonathan Cameron wrote: > On 04/12/16 02:19, Brian Masney wrote: > > isl29028_enable_proximity() has a boolean argument named enable. This > > function is only called once and the enable flag is set to true in that > > call. This patch removes the enable parameter from that function. > > > > Signed-off-by: Brian Masney > > The first thing that strikes me about this, is why do we have an enable > only function? > > I think the intention was probably that we also disable the proximity > sensing after the > reading was done... Ideally we'd do this a little more cleverly, > perhaps using runtime > pm so that if someone is requesting a stream of proximity measurements, > we won't end up > powering up and down each time. > > It's a little 'interesting' as we would want to power this element down > even if we do > have a continuous stream of reads on the ALS. As such we may need to > roll our own > equivalent of runtime pm. > > In the first instance, I'd just put a disable after the reading is > taken. This will > make a bit of a mockery of the faster sampling frequencies but there we > are! > > - > > On second thoughts (stupid email is hiding somewhere to be sent when I > have wifi so can't reply to it) perhaps this is a coarse way of only > turning proximity on if the LED is present? Not sure... Hi Jonathan, I chained your two replies together above. I am probably stating the obvious here, but I've verified with an oscilloscope that the IRDR pin that drives the external LED is off when the chip is first initialized and ALS readings are taken. The IRDR pin fluctuates between high and low every 100us (if memory serves me right) once the first proximity reading is taken until the chip is suspended. What do you think about enabling runtime auto suspend after say 2 seconds for the whole device? There is the situation that you describe where if someone is continuously polling the ALS but asks for a single proximity reading. The external LED will stay on in that case. Once the chip is suspended, and later resumes, the IRDR pin that drives the external LED will be off until the user asks for another proximity reading. That would allow for the faster sampling frequency. If you still prefer, I'll go the route of shutting down the IRDR pin after a proximity reading is taken. Brian ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH v2 07/15] staging: iio: isl29028: move failure logging into isl29028_set_als_scale()
When isl29028_set_als_scale() fails, it was up to both callers to log the failure message. This patch moves the logging into isl29028_set_als_scale() to reduce the overall amount of code in the driver. Signed-off-by: Brian Masney --- drivers/staging/iio/light/isl29028.c | 27 ++- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/drivers/staging/iio/light/isl29028.c b/drivers/staging/iio/light/isl29028.c index bd85ccb..8e7b3db 100644 --- a/drivers/staging/iio/light/isl29028.c +++ b/drivers/staging/iio/light/isl29028.c @@ -123,11 +123,22 @@ static int isl29028_enable_proximity(struct isl29028_chip *chip, bool enable) static int isl29028_set_als_scale(struct isl29028_chip *chip, int lux_scale) { + struct device *dev = regmap_get_device(chip->regmap); int val = (lux_scale == 2000) ? ISL29028_CONF_ALS_RANGE_HIGH_LUX : ISL29028_CONF_ALS_RANGE_LOW_LUX; + int ret; + + ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, +ISL29028_CONF_ALS_RANGE_MASK, val); + if (ret < 0) { + dev_err(dev, "%s(): Error %d setting the ALS scale\n", __func__, + ret); + return ret; + } - return regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, - ISL29028_CONF_ALS_RANGE_MASK, val); + chip->lux_scale = lux_scale; + + return ret; } static int isl29028_set_als_ir_mode(struct isl29028_chip *chip, @@ -318,13 +329,6 @@ static int isl29028_write_raw(struct iio_dev *indio_dev, } ret = isl29028_set_als_scale(chip, val); - if (ret < 0) { - dev_err(dev, - "Setting lux scale fail with error %d\n", ret); - break; - } - - chip->lux_scale = val; break; default: dev_err(dev, "Unsupported channel type\n"); @@ -443,10 +447,7 @@ static int isl29028_chip_init_and_power_on(struct isl29028_chip *chip) if (ret < 0) return ret; - ret = isl29028_set_als_scale(chip, chip->lux_scale); - if (ret < 0) - dev_err(dev, "setting als scale failed, err = %d\n", ret); - return ret; + return isl29028_set_als_scale(chip, chip->lux_scale); } static bool isl29028_is_volatile_reg(struct device *dev, unsigned int reg) -- 2.9.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH v2 03/15] staging: iio: isl29028: combine isl29028_proxim_get() and isl29028_read_proxim()
isl29028_proxim_get() checks to see if the promixity needs to be enabled on the chip and then calls isl29028_read_proxim(). There are no other callers of isl29028_read_proxim(). The naming between these two functions can be confusing so this patch combines the two to avoid the confusion. Signed-off-by: Brian Masney --- drivers/staging/iio/light/isl29028.c | 22 -- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/drivers/staging/iio/light/isl29028.c b/drivers/staging/iio/light/isl29028.c index 74eb736..a13c8db 100644 --- a/drivers/staging/iio/light/isl29028.c +++ b/drivers/staging/iio/light/isl29028.c @@ -201,6 +201,13 @@ static int isl29028_read_proxim(struct isl29028_chip *chip, int *prox) unsigned int data; int ret; + if (!chip->enable_prox) { + ret = isl29028_enable_proximity(chip, true); + if (ret < 0) + return ret; + chip->enable_prox = true; + } + ret = regmap_read(chip->regmap, ISL29028_REG_PROX_DATA, &data); if (ret < 0) { dev_err(dev, "Error in reading register %d, error %d\n", @@ -211,19 +218,6 @@ static int isl29028_read_proxim(struct isl29028_chip *chip, int *prox) return 0; } -static int isl29028_proxim_get(struct isl29028_chip *chip, int *prox_data) -{ - int ret; - - if (!chip->enable_prox) { - ret = isl29028_enable_proximity(chip, true); - if (ret < 0) - return ret; - chip->enable_prox = true; - } - return isl29028_read_proxim(chip, prox_data); -} - static int isl29028_als_get(struct isl29028_chip *chip, int *als_data) { struct device *dev = regmap_get_device(chip->regmap); @@ -349,7 +343,7 @@ static int isl29028_read_raw(struct iio_dev *indio_dev, ret = isl29028_ir_get(chip, val); break; case IIO_PROXIMITY: - ret = isl29028_proxim_get(chip, val); + ret = isl29028_read_proxim(chip, val); break; default: break; -- 2.9.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH v2 00/15] staging cleanups
This patch set contains more of my cleanups to the isl29028 light driver in preparation for moving the driver out of staging. The main feature introduced by this patch set is support for runtime power management and autosuspend after two seconds. The rest of the patches are minor code improvements, mostly style. The ALS and IR portion of the sensor was tested using an ISL29028 hooked up to a Raspberry Pi 2. In my v1 submission cover letter, I mention that I am not able to use the proximity sensing function on my sensor. (This is before any of my code changes.) I'm going to look into that issue next. I suspect that it is a hardware issue on my local setup. I verified with a visible light LED that the IRDR pin continues to be driven as expected when a proximity reading is requested and is turned off after two seconds of inactivity. The pin is driven the next time a proximity reading is requested. Datasheet: http://www.intersil.com/content/dam/Intersil/documents/isl2/isl29028.pdf Changes since version 1: - Suggestions from Jonathan Cameron - In v1 patch #4 (#15 in this series), remove suspended flag. Added support for runtime power management support and autosuspend. - Dropped v1 patch #19 (remove legacy device tree binding) - Dropped v1 patch #11 (made column alignment in isl29028_channels consistent) - In v1 patches #13 and #14, if there is an error, return inside the error check. - It was suggested to drop the v1 #2 patch that removes the enable flag from isl29028_enable_proximity(). I think that we can apply that patch now that the driver has runtime power management support. - Suggestions from Dan Carpenter - Dropped v1 patch #12 (fix comparison between signed and unsigned integers) Brian Masney (15): staging: iio: isl29028: made alignment of variables in struct isl29028_chip consistent staging: iio: isl29028: fix alignment of function arguments staging: iio: isl29028: combine isl29028_proxim_get() and isl29028_read_proxim() staging: iio: isl29028: change newlines to improve readability staging: iio: isl29028: remove unused define ISL29028_DEV_ATTR staging: iio: isl29028: move failure logging into isl29028_set_proxim_sampling() staging: iio: isl29028: move failure logging into isl29028_set_als_scale() staging: iio: isl29028: made error messages consistent staging: iio: isl29028: remove unnecessary error logging in isl29028_chip_init_and_power_on() staging: iio: isl29028: remove out of memory log message staging: iio: isl29028: remove unnecessary parenthesis staging: iio: isl29028: remove enable flag from isl29028_enable_proximity() staging: iio: isl29028: only set proximity sampling rate when proximity is enabled staging: iio: isl29028: only set ALS scale when ALS sensing is enabled staging: iio: isl29028: add runtime power management support drivers/staging/iio/light/isl29028.c | 323 --- 1 file changed, 221 insertions(+), 102 deletions(-) -- 2.9.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH v2 02/15] staging: iio: isl29028: fix alignment of function arguments
Two separate calls to regmap_update_bits() in isl29028_set_als_scale() and isl29028_set_als_ir_mode() did not have their function arguments on the next line aligned correctly to the open parenthesis. This patch corrects the alignment. Signed-off-by: Brian Masney --- drivers/staging/iio/light/isl29028.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/staging/iio/light/isl29028.c b/drivers/staging/iio/light/isl29028.c index 4cce663..74eb736 100644 --- a/drivers/staging/iio/light/isl29028.c +++ b/drivers/staging/iio/light/isl29028.c @@ -116,7 +116,7 @@ static int isl29028_set_als_scale(struct isl29028_chip *chip, int lux_scale) ISL29028_CONF_ALS_RANGE_LOW_LUX; return regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, - ISL29028_CONF_ALS_RANGE_MASK, val); + ISL29028_CONF_ALS_RANGE_MASK, val); } static int isl29028_set_als_ir_mode(struct isl29028_chip *chip, @@ -148,7 +148,8 @@ static int isl29028_set_als_ir_mode(struct isl29028_chip *chip, case ISL29028_MODE_NONE: return regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, - ISL29028_CONF_ALS_EN_MASK, ISL29028_CONF_ALS_DIS); + ISL29028_CONF_ALS_EN_MASK, + ISL29028_CONF_ALS_DIS); } if (ret < 0) -- 2.9.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH v2 09/15] staging: iio: isl29028: remove unnecessary error logging in isl29028_chip_init_and_power_on()
If the call to isl29028_chip_init_and_power_on() in isl29028_probe() fails, then isl29028_probe() will log an error message. All of the error paths in that call path already have error logging in place. This patch removes the unnecessary logging. Signed-off-by: Brian Masney --- drivers/staging/iio/light/isl29028.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/staging/iio/light/isl29028.c b/drivers/staging/iio/light/isl29028.c index cffecf9..be1fc4a 100644 --- a/drivers/staging/iio/light/isl29028.c +++ b/drivers/staging/iio/light/isl29028.c @@ -528,10 +528,8 @@ static int isl29028_probe(struct i2c_client *client, } ret = isl29028_chip_init_and_power_on(chip); - if (ret < 0) { - dev_err(&client->dev, "chip initialization failed: %d\n", ret); + if (ret < 0) return ret; - } indio_dev->info = &isl29028_info; indio_dev->channels = isl29028_channels; -- 2.9.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH v2 12/15] staging: iio: isl29028: remove enable flag from isl29028_enable_proximity()
isl29028_enable_proximity() has a boolean argument named enable. This function is only called once and the enable flag is set to true in that call. This patch removes the enable parameter from that function. Signed-off-by: Brian Masney --- The device gets runtime power management support in the next patch in this set and autosuspends after two seconds of inactivity. Once the device suspends, the pin that drives the external LED for proximity sensing will only go high the next time that the user asks for a reading from the proximity sensor. This patch also sets the stage for additional cleanups prior to the introduction of runtime power management support. drivers/staging/iio/light/isl29028.c | 10 -- 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/staging/iio/light/isl29028.c b/drivers/staging/iio/light/isl29028.c index bc9c01d..f1b3651 100644 --- a/drivers/staging/iio/light/isl29028.c +++ b/drivers/staging/iio/light/isl29028.c @@ -103,15 +103,13 @@ static int isl29028_set_proxim_sampling(struct isl29028_chip *chip, return ret; } -static int isl29028_enable_proximity(struct isl29028_chip *chip, bool enable) +static int isl29028_enable_proximity(struct isl29028_chip *chip) { int ret; - int val = 0; - if (enable) - val = ISL29028_CONF_PROX_EN; ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, -ISL29028_CONF_PROX_EN_MASK, val); +ISL29028_CONF_PROX_EN_MASK, +ISL29028_CONF_PROX_EN); if (ret < 0) return ret; @@ -225,7 +223,7 @@ static int isl29028_read_proxim(struct isl29028_chip *chip, int *prox) int ret; if (!chip->enable_prox) { - ret = isl29028_enable_proximity(chip, true); + ret = isl29028_enable_proximity(chip); if (ret < 0) return ret; -- 2.9.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH v2 08/15] staging: iio: isl29028: made error messages consistent
The wording and style of the different error messages was not consistent. This patch makes the wording and style consistent throughout the driver. Signed-off-by: Brian Masney --- drivers/staging/iio/light/isl29028.c | 56 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/drivers/staging/iio/light/isl29028.c b/drivers/staging/iio/light/isl29028.c index 8e7b3db..cffecf9 100644 --- a/drivers/staging/iio/light/isl29028.c +++ b/drivers/staging/iio/light/isl29028.c @@ -200,14 +200,16 @@ static int isl29028_read_als_ir(struct isl29028_chip *chip, int *als_ir) ret = regmap_read(chip->regmap, ISL29028_REG_ALSIR_L, &lsb); if (ret < 0) { dev_err(dev, - "Error in reading register ALSIR_L err %d\n", ret); + "%s(): Error %d reading register ALSIR_L\n", + __func__, ret); return ret; } ret = regmap_read(chip->regmap, ISL29028_REG_ALSIR_U, &msb); if (ret < 0) { dev_err(dev, - "Error in reading register ALSIR_U err %d\n", ret); + "%s(): Error %d reading register ALSIR_U\n", + __func__, ret); return ret; } @@ -232,8 +234,8 @@ static int isl29028_read_proxim(struct isl29028_chip *chip, int *prox) ret = regmap_read(chip->regmap, ISL29028_REG_PROX_DATA, &data); if (ret < 0) { - dev_err(dev, "Error in reading register %d, error %d\n", - ISL29028_REG_PROX_DATA, ret); + dev_err(dev, "%s(): Error %d reading register PROX_DATA\n", + __func__, ret); return ret; } @@ -250,7 +252,8 @@ static int isl29028_als_get(struct isl29028_chip *chip, int *als_data) ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_ALS); if (ret < 0) { - dev_err(dev, "Error in enabling ALS mode err %d\n", ret); + dev_err(dev, "%s(): Error %d enabling ALS mode\n", __func__, + ret); return ret; } @@ -280,7 +283,8 @@ static int isl29028_ir_get(struct isl29028_chip *chip, int *ir_data) ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_IR); if (ret < 0) { - dev_err(dev, "Error in enabling IR mode err %d\n", ret); + dev_err(dev, "%s(): Error %d enabling IR mode\n", __func__, + ret); return ret; } @@ -301,14 +305,15 @@ static int isl29028_write_raw(struct iio_dev *indio_dev, case IIO_PROXIMITY: if (mask != IIO_CHAN_INFO_SAMP_FREQ) { dev_err(dev, - "proximity: mask value 0x%08lx not supported\n", - mask); + "%s(): proximity: Mask value 0x%08lx is not supported\n", + __func__, mask); break; } if (val < 1 || val > 100) { dev_err(dev, - "Samp_freq %d is not in range[1:100]\n", val); + "%s(): proximity: Sampling frequency %d is not in the range [1:100]\n", + __func__, val); break; } @@ -317,21 +322,23 @@ static int isl29028_write_raw(struct iio_dev *indio_dev, case IIO_LIGHT: if (mask != IIO_CHAN_INFO_SCALE) { dev_err(dev, - "light: mask value 0x%08lx not supported\n", - mask); + "%s(): light: Mask value 0x%08lx is not supported\n", + __func__, mask); break; } if ((val != 125) && (val != 2000)) { dev_err(dev, - "lux scale %d is invalid [125, 2000]\n", val); + "%s(): light: Lux scale %d is not in the set {125, 2000}\n", + __func__, val); break; } ret = isl29028_set_als_scale(chip, val); break; default: - dev_err(dev, "Unsupported channel type\n"); + dev_err(dev, "%s(): Unsupported channel type %x\n", + __func__, chan->type); break; } @@ -385,7 +392,8 @@ static int isl29028_read_raw(struct iio_dev *indio_dev, ret = IIO_VAL_INT;
[PATCH v2 06/15] staging: iio: isl29028: move failure logging into isl29028_set_proxim_sampling()
When isl29028_set_proxim_sampling() fails, it was up to both callers to log the failure message. This patch moves the logging into isl29028_set_proxim_sampling() to reduce the overall amount of code in the driver. Signed-off-by: Brian Masney --- drivers/staging/iio/light/isl29028.c | 31 --- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/drivers/staging/iio/light/isl29028.c b/drivers/staging/iio/light/isl29028.c index 7074e62..bd85ccb 100644 --- a/drivers/staging/iio/light/isl29028.c +++ b/drivers/staging/iio/light/isl29028.c @@ -78,18 +78,29 @@ struct isl29028_chip { static int isl29028_set_proxim_sampling(struct isl29028_chip *chip, unsigned int sampling) { + struct device *dev = regmap_get_device(chip->regmap); static unsigned int prox_period[] = {800, 400, 200, 100, 75, 50, 12, 0}; - int sel; unsigned int period = DIV_ROUND_UP(1000, sampling); + int sel, ret; for (sel = 0; sel < ARRAY_SIZE(prox_period); ++sel) { if (period >= prox_period[sel]) break; } - return regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, - ISL29028_CONF_PROX_SLP_MASK, - sel << ISL29028_CONF_PROX_SLP_SH); + ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, +ISL29028_CONF_PROX_SLP_MASK, +sel << ISL29028_CONF_PROX_SLP_SH); + + if (ret < 0) { + dev_err(dev, "%s(): Error %d setting the proximity sampling\n", + __func__, ret); + return ret; + } + + chip->prox_sampling = sampling; + + return ret; } static int isl29028_enable_proximity(struct isl29028_chip *chip, bool enable) @@ -291,14 +302,6 @@ static int isl29028_write_raw(struct iio_dev *indio_dev, } ret = isl29028_set_proxim_sampling(chip, val); - if (ret < 0) { - dev_err(dev, - "Setting proximity samp_freq fail, err %d\n", - ret); - break; - } - - chip->prox_sampling = val; break; case IIO_LIGHT: if (mask != IIO_CHAN_INFO_SCALE) { @@ -437,10 +440,8 @@ static int isl29028_chip_init_and_power_on(struct isl29028_chip *chip) } ret = isl29028_set_proxim_sampling(chip, chip->prox_sampling); - if (ret < 0) { - dev_err(dev, "setting the proximity, err = %d\n", ret); + if (ret < 0) return ret; - } ret = isl29028_set_als_scale(chip, chip->lux_scale); if (ret < 0) -- 2.9.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH v2 01/15] staging: iio: isl29028: made alignment of variables in struct isl29028_chip consistent
The alignment of the variables in the struct isl29028_chip is not consistent. This changes all of the variables to use consistent alignment to improve the code readability. Signed-off-by: Brian Masney --- drivers/staging/iio/light/isl29028.c | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/staging/iio/light/isl29028.c b/drivers/staging/iio/light/isl29028.c index 1de81f5..4cce663 100644 --- a/drivers/staging/iio/light/isl29028.c +++ b/drivers/staging/iio/light/isl29028.c @@ -67,13 +67,13 @@ enum isl29028_als_ir_mode { }; struct isl29028_chip { - struct mutexlock; - struct regmap *regmap; + struct mutexlock; + struct regmap *regmap; - unsigned intprox_sampling; - boolenable_prox; + unsigned intprox_sampling; + boolenable_prox; - int lux_scale; + int lux_scale; enum isl29028_als_ir_mode als_ir_mode; }; -- 2.9.3 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel