Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1517037 > unrolled thread
| Started by | Brian Masney <masneyb@onstation.org> |
|---|---|
| First post | 2016-11-08 11:20 +0100 |
| Last post | 2016-11-08 11:40 +0100 |
| Articles | 19 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH v2 00/23] staging: iio: tsl2583: move out of staging Brian Masney <masneyb@onstation.org> - 2016-11-08 11:20 +0100
[PATCH v2 02/23] staging: iio: tsl2583: fix issue with changes to calibscale and int_time not being set on the chip Brian Masney <masneyb@onstation.org> - 2016-11-08 11:20 +0100
[PATCH v2 09/23] staging: iio: tsl2583: cleaned up logging Brian Masney <masneyb@onstation.org> - 2016-11-08 11:20 +0100
Re: [PATCH v2 09/23] staging: iio: tsl2583: cleaned up logging Joe Perches <joe@perches.com> - 2016-11-08 11:30 +0100
Re: [PATCH v2 09/23] staging: iio: tsl2583: cleaned up logging Brian Masney <masneyb@onstation.org> - 2016-11-08 17:00 +0100
[PATCH v2 03/23] staging: iio: tsl2583: check if chip is suspended in in_illuminance_calibrate_store Brian Masney <masneyb@onstation.org> - 2016-11-08 11:20 +0100
[PATCH v2 15/23] staging: iio: tsl2583: fix multiline comment syntax Brian Masney <masneyb@onstation.org> - 2016-11-08 11:30 +0100
[PATCH v2 12/23] staging: iio: tsl2583: fix comparison between signed and unsigned integers Brian Masney <masneyb@onstation.org> - 2016-11-08 11:30 +0100
[PATCH v2 18/23] staging: iio: tsl2583: change tsl2583_als_calibrate() to return 0 on success Brian Masney <masneyb@onstation.org> - 2016-11-08 11:30 +0100
[PATCH v2 20/23] staging: iio: tsl2583: don't assume an unsigned int is 32 bits Brian Masney <masneyb@onstation.org> - 2016-11-08 11:30 +0100
[PATCH v2 22/23] staging: iio: tsl2583: updated copyright and MODULE_AUTHOR Brian Masney <masneyb@onstation.org> - 2016-11-08 11:30 +0100
Re: [PATCH v2 22/23] staging: iio: tsl2583: updated copyright and MODULE_AUTHOR Jonathan Cameron <jic23@kernel.org> - 2016-11-08 21:50 +0100
[PATCH v2 19/23] staging: iio: tsl2583: remove unnecessary parentheses Brian Masney <masneyb@onstation.org> - 2016-11-08 11:30 +0100
[PATCH v2 14/23] staging: iio: tsl2583: combine sysfs documentation Brian Masney <masneyb@onstation.org> - 2016-11-08 11:30 +0100
[PATCH v2 16/23] staging: iio: tsl2583: updated code comment to match what the code does Brian Masney <masneyb@onstation.org> - 2016-11-08 11:30 +0100
[PATCH v2 11/23] staging: iio: tsl2583: fix alignment of #define values Brian Masney <masneyb@onstation.org> - 2016-11-08 11:30 +0100
[PATCH v2 17/23] staging: iio: tsl2583: moved code block inside else statement Brian Masney <masneyb@onstation.org> - 2016-11-08 11:40 +0100
[PATCH v2 21/23] staging: iio: tsl2583: move from a global to a per device lux table Brian Masney <masneyb@onstation.org> - 2016-11-08 11:40 +0100
[PATCH v2 13/23] staging: iio: tsl2583: change newlines to improve readability Brian Masney <masneyb@onstation.org> - 2016-11-08 11:40 +0100
| From | Brian Masney <masneyb@onstation.org> |
|---|---|
| Date | 2016-11-08 11:20 +0100 |
| Subject | [PATCH v2 00/23] staging: iio: tsl2583: move out of staging |
| Message-ID | <sBbFv-84M-3@gated-at.bofh.it> |
The first 7 patches in this series contains version 2 of the patches
7-9 that I sent out on 2016-11-03. The only change is that the patches
are split up further to make the code review easier.
Patches 8-23 in this series are new and some of the highlights include:
- Moved from a global lux table to a per device lux table.
- Combined redundant sysfs ABI documentation
- Made log messages clearer
- Code style and formatting cleanups
- Staging graduation
I verified that the driver functions correctly using a TSL2581 hooked up
to a Raspberry Pi 2.
Brian Masney (23):
staging: iio: tsl2583: split out functionality of taos_chip_on()
staging: iio: tsl2583: fix issue with changes to calibscale and
int_time not being set on the chip
staging: iio: tsl2583: check if chip is suspended in
in_illuminance_calibrate_store
staging: iio: tsl2583: remove unnecessary chip status check in
taos_get_lux
staging: iio: tsl2583: remove unnecessary chip status checks in
suspend/resume
staging: iio: tsl2583: change current chip state from a tristate to a
bool
staging: iio: tsl2583: remove redundant write to the control register
in taos_probe()
staging: iio: tsl2583: remove the FSF's mailing address
staging: iio: tsl2583: cleaned up logging
staging: iio: tsl2583: unify function and variable prefix to tsl2583_
staging: iio: tsl2583: fix alignment of #define values
staging: iio: tsl2583: fix comparison between signed and unsigned
integers
staging: iio: tsl2583: change newlines to improve readability
staging: iio: tsl2583: combine sysfs documentation
staging: iio: tsl2583: fix multiline comment syntax
staging: iio: tsl2583: updated code comment to match what the code
does
staging: iio: tsl2583: moved code block inside else statement
staging: iio: tsl2583: change tsl2583_als_calibrate() to return 0 on
success
staging: iio: tsl2583: remove unnecessary parentheses
staging: iio: tsl2583: don't assume an unsigned int is 32 bits
staging: iio: tsl2583: move from a global to a per device lux table
staging: iio: tsl2583: updated copyright and MODULE_AUTHOR
staging: iio: tsl2583: move out of staging
.../ABI/testing/sysfs-bus-iio-light-tsl2583 | 20 +
drivers/iio/light/Kconfig | 7 +
drivers/iio/light/Makefile | 1 +
drivers/iio/light/tsl2583.c | 916 +++++++++++++++++++++
.../light/sysfs-bus-iio-light-tsl2583 | 6 -
.../iio/Documentation/sysfs-bus-iio-light-tsl2583 | 20 -
drivers/staging/iio/light/Kconfig | 7 -
drivers/staging/iio/light/Makefile | 1 -
drivers/staging/iio/light/tsl2583.c | 892 --------------------
9 files changed, 944 insertions(+), 926 deletions(-)
create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-light-tsl2583
create mode 100644 drivers/iio/light/tsl2583.c
delete mode 100644 drivers/staging/iio/Documentation/light/sysfs-bus-iio-light-tsl2583
delete mode 100644 drivers/staging/iio/Documentation/sysfs-bus-iio-light-tsl2583
delete mode 100644 drivers/staging/iio/light/tsl2583.c
--
2.7.4
[toc] | [next] | [standalone]
| From | Brian Masney <masneyb@onstation.org> |
|---|---|
| Date | 2016-11-08 11:20 +0100 |
| Subject | [PATCH v2 02/23] staging: iio: tsl2583: fix issue with changes to calibscale and int_time not being set on the chip |
| Message-ID | <sBbFw-84M-33@gated-at.bofh.it> |
| In reply to | #1517037 |
When updating the in_illuminance_calibscale and
in_illuminance_integration_time sysfs attributes, these values were not
actually written to the chip. The chip would continue to use the old
parameters. Extracted out tsl2583_set_als_gain() and
tsl2583_set_als_time() functions that are now called when these sysfs
attributes are updated. The chip initialization also calls these these
new functions.
Signed-off-by: Brian Masney <masneyb@onstation.org>
---
drivers/staging/iio/light/tsl2583.c | 85 +++++++++++++++++++++++--------------
1 file changed, 52 insertions(+), 33 deletions(-)
diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
index f17f919..cf5fd5f 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -352,6 +352,51 @@ static int taos_als_calibrate(struct iio_dev *indio_dev)
return (int)gain_trim_val;
}
+static int tsl2583_set_als_time(struct tsl2583_chip *chip)
+{
+ int als_count, als_time, ret;
+ u8 val;
+
+ /* determine als integration register */
+ als_count = (chip->taos_settings.als_time * 100 + 135) / 270;
+ if (!als_count)
+ als_count = 1; /* ensure at least one cycle */
+
+ /* convert back to time (encompasses overrides) */
+ als_time = (als_count * 27 + 5) / 10;
+
+ val = 256 - als_count;
+ ret = i2c_smbus_write_byte_data(chip->client,
+ TSL258X_CMD_REG | TSL258X_ALS_TIME,
+ val);
+ if (ret < 0) {
+ dev_err(&chip->client->dev, "%s failed to set the als time to %d\n",
+ __func__, val);
+ return ret;
+ }
+
+ /* set chip struct re scaling and saturation */
+ chip->als_saturation = als_count * 922; /* 90% of full scale */
+ chip->als_time_scale = (als_time + 25) / 50;
+
+ return ret;
+}
+
+static int tsl2583_set_als_gain(struct tsl2583_chip *chip)
+{
+ int ret;
+
+ /* Set the gain based on taos_settings struct */
+ ret = i2c_smbus_write_byte_data(chip->client,
+ TSL258X_CMD_REG | TSL258X_GAIN,
+ chip->taos_settings.als_gain);
+ if (ret < 0)
+ dev_err(&chip->client->dev, "%s failed to set the gain to %d\n",
+ __func__, chip->taos_settings.als_gain);
+
+ return ret;
+}
+
static int tsl2583_set_power_state(struct tsl2583_chip *chip, u8 state)
{
int ret;
@@ -371,10 +416,8 @@ static int tsl2583_set_power_state(struct tsl2583_chip *chip, u8 state)
*/
static int tsl2583_chip_init_and_power_on(struct iio_dev *indio_dev)
{
- int ret, val;
- int als_count;
- int als_time;
struct tsl2583_chip *chip = iio_priv(indio_dev);
+ int ret;
/* and make sure we're not already on */
if (chip->taos_chip_status == TSL258X_CHIP_WORKING) {
@@ -397,37 +440,13 @@ static int tsl2583_chip_init_and_power_on(struct iio_dev *indio_dev)
return ret;
}
- /* determine als integration register */
- als_count = (chip->taos_settings.als_time * 100 + 135) / 270;
- if (!als_count)
- als_count = 1; /* ensure at least one cycle */
-
- /* convert back to time (encompasses overrides) */
- als_time = (als_count * 27 + 5) / 10;
-
- val = 256 - als_count;
- ret = i2c_smbus_write_byte_data(chip->client,
- TSL258X_CMD_REG | TSL258X_ALS_TIME,
- val);
- if (ret < 0) {
- dev_err(&chip->client->dev, "%s failed to set the als time to %d\n",
- __func__, val);
+ ret = tsl2583_set_als_time(chip);
+ if (ret < 0)
return ret;
- }
- /* Set the gain based on taos_settings struct */
- ret = i2c_smbus_write_byte_data(chip->client,
- TSL258X_CMD_REG | TSL258X_GAIN,
- chip->taos_settings.als_gain);
- if (ret < 0) {
- dev_err(&chip->client->dev, "%s failed to set the gain to %d\n",
- __func__, chip->taos_settings.als_gain);
+ ret = tsl2583_set_als_gain(chip);
+ if (ret < 0)
return ret;
- }
-
- /* set chip struct re scaling and saturation */
- chip->als_saturation = als_count * 922; /* 90% of full scale */
- chip->als_time_scale = (als_time + 25) / 50;
usleep_range(3000, 3500);
@@ -707,7 +726,7 @@ static int tsl2583_write_raw(struct iio_dev *indio_dev,
for (i = 0; i < ARRAY_SIZE(gainadj); i++) {
if (gainadj[i].mean == val) {
chip->taos_settings.als_gain = i;
- ret = 0;
+ ret = tsl2583_set_als_gain(chip);
break;
}
}
@@ -717,7 +736,7 @@ static int tsl2583_write_raw(struct iio_dev *indio_dev,
if (chan->type == IIO_LIGHT && !val && val2 >= 50 &&
val2 <= 650 && !(val2 % 50)) {
chip->taos_settings.als_time = val2;
- ret = 0;
+ ret = tsl2583_set_als_time(chip);
}
break;
default:
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Brian Masney <masneyb@onstation.org> |
|---|---|
| Date | 2016-11-08 11:20 +0100 |
| Subject | [PATCH v2 09/23] staging: iio: tsl2583: cleaned up logging |
| Message-ID | <sBbFw-84M-35@gated-at.bofh.it> |
| In reply to | #1517037 |
There are several places in the code where the function name is
hardcoded in the log message. Use the __func__ constant string to build
the log message. This also clarifies some of the error messages to match
the code and ensures that the correct priority is used since the message
is already being changed.
Signed-off-by: Brian Masney <masneyb@onstation.org>
---
drivers/staging/iio/light/tsl2583.c | 51 ++++++++++++++++++++++---------------
1 file changed, 30 insertions(+), 21 deletions(-)
diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
index a03f845..c797ab0 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -170,13 +170,15 @@ static int taos_get_lux(struct iio_dev *indio_dev)
ret = i2c_smbus_read_byte_data(chip->client, TSL258X_CMD_REG);
if (ret < 0) {
- dev_err(&chip->client->dev, "taos_get_lux failed to read CMD_REG\n");
+ dev_err(&chip->client->dev, "%s failed to read CMD_REG register\n",
+ __func__);
goto done;
}
/* is data new & valid */
if (!(ret & TSL258X_STA_ADC_INTR)) {
- dev_err(&chip->client->dev, "taos_get_lux data not valid\n");
+ dev_err(&chip->client->dev, "%s: data not valid; returning last value\n",
+ __func__);
ret = chip->als_cur_info.lux; /* return LAST VALUE */
goto done;
}
@@ -186,9 +188,8 @@ static int taos_get_lux(struct iio_dev *indio_dev)
ret = i2c_smbus_read_byte_data(chip->client, reg);
if (ret < 0) {
- dev_err(&chip->client->dev,
- "taos_get_lux failed to read register %x\n",
- reg);
+ dev_err(&chip->client->dev, "%s failed to read register %x\n",
+ __func__, reg);
goto done;
}
buf[i] = ret;
@@ -203,9 +204,8 @@ static int taos_get_lux(struct iio_dev *indio_dev)
TSL258X_CMD_ALS_INT_CLR));
if (ret < 0) {
- dev_err(&chip->client->dev,
- "taos_i2c_write_command failed in taos_get_lux, err = %d\n",
- ret);
+ dev_err(&chip->client->dev, "%s failed to clear the interrupt bit\n",
+ __func__);
goto done; /* have no data, so return failure */
}
@@ -246,7 +246,8 @@ static int taos_get_lux(struct iio_dev *indio_dev)
/* note: lux is 31 bit max at this point */
if (ch1lux > ch0lux) {
- dev_dbg(&chip->client->dev, "No Data - Return last value\n");
+ dev_dbg(&chip->client->dev, "%s: No Data - Returning 0\n",
+ __func__);
ret = 0;
chip->als_cur_info.lux = 0;
goto done;
@@ -309,16 +310,17 @@ static int taos_als_calibrate(struct iio_dev *indio_dev)
if ((ret & (TSL258X_CNTL_ADC_ENBL | TSL258X_CNTL_PWR_ON))
!= (TSL258X_CNTL_ADC_ENBL | TSL258X_CNTL_PWR_ON)) {
dev_err(&chip->client->dev,
- "taos_als_calibrate failed: device not powered on with ADC enabled\n");
+ "%s failed: device not powered on with ADC enabled\n",
+ __func__);
return -EINVAL;
} else if ((ret & TSL258X_STA_ADC_VALID) != TSL258X_STA_ADC_VALID) {
dev_err(&chip->client->dev,
- "taos_als_calibrate failed: STATUS - ADC not valid.\n");
+ "%s failed: STATUS - ADC not valid.\n", __func__);
return -ENODATA;
}
lux_val = taos_get_lux(indio_dev);
if (lux_val < 0) {
- dev_err(&chip->client->dev, "taos_als_calibrate failed to get lux\n");
+ dev_err(&chip->client->dev, "%s failed to get lux\n", __func__);
return lux_val;
}
gain_trim_val = (unsigned int)(((chip->taos_settings.als_cal_target)
@@ -326,8 +328,8 @@ static int taos_als_calibrate(struct iio_dev *indio_dev)
if ((gain_trim_val < 250) || (gain_trim_val > 4000)) {
dev_err(&chip->client->dev,
- "taos_als_calibrate failed: trim_val of %d is out of range\n",
- gain_trim_val);
+ "%s failed: trim_val of %d is not within the range [250, 4000]\n",
+ __func__, gain_trim_val);
return -ENODATA;
}
chip->taos_settings.als_gain_trim = (int)gain_trim_val;
@@ -526,6 +528,8 @@ static ssize_t in_illuminance_lux_table_show(struct device *dev,
return offset;
}
+#define TSL2583_MAX_LUX_INTS ((ARRAY_SIZE(taos_device_lux) - 1) * 3)
+
static ssize_t in_illuminance_lux_table_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t len)
@@ -545,12 +549,15 @@ static ssize_t in_illuminance_lux_table_store(struct device *dev,
* and the last table entry is all 0.
*/
n = value[0];
- if ((n % 3) || n < 6 || n > ((ARRAY_SIZE(taos_device_lux) - 1) * 3)) {
- dev_info(dev, "LUX TABLE INPUT ERROR 1 Value[0]=%d\n", n);
+ if ((n % 3) || n < 6 || n > TSL2583_MAX_LUX_INTS) {
+ dev_err(dev,
+ "%s: The number of entries in the lux table must be a multiple of 3 and within the range [6, %zu]",
+ __func__, TSL2583_MAX_LUX_INTS);
goto done;
}
if ((value[(n - 2)] | value[(n - 1)] | value[n]) != 0) {
- dev_info(dev, "LUX TABLE INPUT ERROR 2 Value[0]=%d\n", n);
+ dev_err(dev, "%s: The last 3 entries in the lux table must be zeros.\n",
+ __func__);
goto done;
}
@@ -756,7 +763,8 @@ static int taos_probe(struct i2c_client *clientp,
if (!i2c_check_functionality(clientp->adapter,
I2C_FUNC_SMBUS_BYTE_DATA)) {
- dev_err(&clientp->dev, "taos_probe() - i2c smbus byte data func unsupported\n");
+ dev_err(&clientp->dev, "%s: i2c smbus byte data functionality is unsupported\n",
+ __func__);
return -EOPNOTSUPP;
}
@@ -779,8 +787,8 @@ static int taos_probe(struct i2c_client *clientp,
}
if ((ret & TSL2583_CHIP_ID_MASK) != TSL2583_CHIP_ID) {
- dev_info(&clientp->dev, "%s received an unknown chip ID %x\n",
- __func__, ret);
+ dev_err(&clientp->dev, "%s received an unknown chip ID %x\n",
+ __func__, ret);
return -EINVAL;
}
@@ -792,7 +800,8 @@ static int taos_probe(struct i2c_client *clientp,
indio_dev->name = chip->client->name;
ret = devm_iio_device_register(indio_dev->dev.parent, indio_dev);
if (ret) {
- dev_err(&clientp->dev, "iio registration failed\n");
+ dev_err(&clientp->dev, "%s: iio registration failed\n",
+ __func__);
return ret;
}
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Joe Perches <joe@perches.com> |
|---|---|
| Date | 2016-11-08 11:30 +0100 |
| Subject | Re: [PATCH v2 09/23] staging: iio: tsl2583: cleaned up logging |
| Message-ID | <sBbPc-88c-43@gated-at.bofh.it> |
| In reply to | #1517040 |
On Tue, 2016-11-08 at 05:16 -0500, Brian Masney wrote:
> There are several places in the code where the function name is
> hardcoded in the log message. Use the __func__ constant string to build
> the log message. This also clarifies some of the error messages to match
> the code and ensures that the correct priority is used since the message
> is already being changed.
[]
> diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
[]
> @@ -170,13 +170,15 @@ static int taos_get_lux(struct iio_dev *indio_dev)
>
> ret = i2c_smbus_read_byte_data(chip->client, TSL258X_CMD_REG);
> if (ret < 0) {
> - dev_err(&chip->client->dev, "taos_get_lux failed to read CMD_REG\n");
> + dev_err(&chip->client->dev, "%s failed to read CMD_REG register\n",
> + __func__);
Please use "%s: <message>", __func__ consistently
> @@ -545,12 +549,15 @@ static ssize_t in_illuminance_lux_table_store(struct device *dev,
> * and the last table entry is all 0.
> */
> n = value[0];
> - if ((n % 3) || n < 6 || n > ((ARRAY_SIZE(taos_device_lux) - 1) * 3)) {
> - dev_info(dev, "LUX TABLE INPUT ERROR 1 Value[0]=%d\n", n);
> + if ((n % 3) || n < 6 || n > TSL2583_MAX_LUX_INTS) {
> + dev_err(dev,
> + "%s: The number of entries in the lux table must be a multiple of 3 and within the range [6, %zu]",
> + __func__, TSL2583_MAX_LUX_INTS);
Missing terminating '\n"
[toc] | [prev] | [next] | [standalone]
| From | Brian Masney <masneyb@onstation.org> |
|---|---|
| Date | 2016-11-08 17:00 +0100 |
| Subject | Re: [PATCH v2 09/23] staging: iio: tsl2583: cleaned up logging |
| Message-ID | <sBgYy-2MM-47@gated-at.bofh.it> |
| In reply to | #1517054 |
On Tue, Nov 08, 2016 at 02:29:20AM -0800, Joe Perches wrote:
> On Tue, 2016-11-08 at 05:16 -0500, Brian Masney wrote:
> > There are several places in the code where the function name is
> > hardcoded in the log message. Use the __func__ constant string to build
> > the log message. This also clarifies some of the error messages to match
> > the code and ensures that the correct priority is used since the message
> > is already being changed.
> []
> > diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
> []
> > @@ -170,13 +170,15 @@ static int taos_get_lux(struct iio_dev *indio_dev)
> >
> > ret = i2c_smbus_read_byte_data(chip->client, TSL258X_CMD_REG);
> > if (ret < 0) {
> > - dev_err(&chip->client->dev, "taos_get_lux failed to read CMD_REG\n");
> > + dev_err(&chip->client->dev, "%s failed to read CMD_REG register\n",
> > + __func__);
>
> Please use "%s: <message>", __func__ consistently
>
> > @@ -545,12 +549,15 @@ static ssize_t in_illuminance_lux_table_store(struct device *dev,
> > * and the last table entry is all 0.
> > */
> > n = value[0];
> > - if ((n % 3) || n < 6 || n > ((ARRAY_SIZE(taos_device_lux) - 1) * 3)) {
> > - dev_info(dev, "LUX TABLE INPUT ERROR 1 Value[0]=%d\n", n);
> > + if ((n % 3) || n < 6 || n > TSL2583_MAX_LUX_INTS) {
> > + dev_err(dev,
> > + "%s: The number of entries in the lux table must be a multiple of 3 and within the range [6, %zu]",
> > + __func__, TSL2583_MAX_LUX_INTS);
>
> Missing terminating '\n"
Thanks for the feedback Joe. I'll send out an updated patch series on
Friday.
Brian
[toc] | [prev] | [next] | [standalone]
| From | Brian Masney <masneyb@onstation.org> |
|---|---|
| Date | 2016-11-08 11:20 +0100 |
| Subject | [PATCH v2 03/23] staging: iio: tsl2583: check if chip is suspended in in_illuminance_calibrate_store |
| Message-ID | <sBbFw-84M-37@gated-at.bofh.it> |
| In reply to | #1517037 |
in_illuminance_calibrate_store() did not check to see if the chip is
suspended. This patch adds the proper check. The return value from
taos_als_calibrate() was also not checked in this function, so the
proper check was also added while changes are being made here.
Signed-off-by: Brian Masney <masneyb@onstation.org>
---
drivers/staging/iio/light/tsl2583.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
index cf5fd5f..6c46253 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -501,16 +501,27 @@ static ssize_t in_illuminance_calibrate_store(struct device *dev,
{
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
struct tsl2583_chip *chip = iio_priv(indio_dev);
- int value;
+ int value, ret;
if (kstrtoint(buf, 0, &value) || value != 1)
return -EINVAL;
mutex_lock(&chip->als_mutex);
- taos_als_calibrate(indio_dev);
+
+ if (chip->suspended) {
+ ret = -EBUSY;
+ goto done;
+ }
+
+ ret = taos_als_calibrate(indio_dev);
+ if (ret < 0)
+ goto done;
+
+ ret = len;
+done:
mutex_unlock(&chip->als_mutex);
- return len;
+ return ret;
}
static ssize_t in_illuminance_lux_table_show(struct device *dev,
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Brian Masney <masneyb@onstation.org> |
|---|---|
| Date | 2016-11-08 11:30 +0100 |
| Subject | [PATCH v2 15/23] staging: iio: tsl2583: fix multiline comment syntax |
| Message-ID | <sBbPb-88c-1@gated-at.bofh.it> |
| In reply to | #1517037 |
The definition of the tsl2583_device_lux struct has a series of single
line comments. There are two other cases where the multiline comments
did not have an initial blank line. Change these comments to use the
proper multiline syntax.
Signed-off-by: Brian Masney <masneyb@onstation.org>
---
drivers/staging/iio/light/tsl2583.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
index eff59f37..5ef403c 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -93,9 +93,11 @@ struct tsl2583_lux {
unsigned int ch1;
};
-/* This structure is intentionally large to accommodate updates via sysfs. */
-/* Sized to 11 = max 10 segments + 1 termination segment */
-/* Assumption is one and only one type of glass used */
+/*
+ * This structure is intentionally large to accommodate updates via sysfs.
+ * Sized to 11 = max 10 segments + 1 termination segment. Assumption is that
+ * one and only one type of glass used.
+ */
static struct tsl2583_lux tsl2583_device_lux[11] = {
{ 9830, 8520, 15729 },
{ 12452, 10807, 23344 },
@@ -261,7 +263,8 @@ static int tsl2583_get_lux(struct iio_dev *indio_dev)
lux = (lux + (chip->als_time_scale >> 1)) /
chip->als_time_scale;
- /* Adjust for active gain scale.
+ /*
+ * Adjust for active gain scale.
* The tsl2583_device_lux tables above have a factor of 8192 built in,
* so we need to shift right.
* User-specified gain provides a multiplier.
@@ -549,7 +552,8 @@ static ssize_t in_illuminance_lux_table_store(struct device *dev,
get_options(buf, ARRAY_SIZE(value), value);
- /* We now have an array of ints starting at value[1], and
+ /*
+ * We now have an array of ints starting at value[1], and
* enumerated by value[0].
* We expect each group of three ints is one table entry,
* and the last table entry is all 0.
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Brian Masney <masneyb@onstation.org> |
|---|---|
| Date | 2016-11-08 11:30 +0100 |
| Subject | [PATCH v2 12/23] staging: iio: tsl2583: fix comparison between signed and unsigned integers |
| Message-ID | <sBbPb-88c-7@gated-at.bofh.it> |
| In reply to | #1517037 |
Fixed warning found by make W=2:
warning: comparison between signed and unsigned integer expressions
[-Wsign-compare]
Signed-off-by: Brian Masney <masneyb@onstation.org>
---
drivers/staging/iio/light/tsl2583.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
index ad6866a..8be135b 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -506,7 +506,7 @@ static ssize_t in_illuminance_lux_table_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
- int i;
+ unsigned int i;
int offset = 0;
for (i = 0; i < ARRAY_SIZE(tsl2583_device_lux); i++) {
@@ -537,7 +537,8 @@ static ssize_t in_illuminance_lux_table_store(struct device *dev,
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
struct tsl2583_chip *chip = iio_priv(indio_dev);
int value[ARRAY_SIZE(tsl2583_device_lux) * 3 + 1];
- int n, ret = -EINVAL;
+ int ret = -EINVAL;
+ unsigned int n;
mutex_lock(&chip->als_mutex);
@@ -715,7 +716,7 @@ static int tsl2583_write_raw(struct iio_dev *indio_dev,
break;
case IIO_CHAN_INFO_CALIBSCALE:
if (chan->type == IIO_LIGHT) {
- int i;
+ unsigned int i;
for (i = 0; i < ARRAY_SIZE(gainadj); i++) {
if (gainadj[i].mean == val) {
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Brian Masney <masneyb@onstation.org> |
|---|---|
| Date | 2016-11-08 11:30 +0100 |
| Subject | [PATCH v2 18/23] staging: iio: tsl2583: change tsl2583_als_calibrate() to return 0 on success |
| Message-ID | <sBbPb-88c-9@gated-at.bofh.it> |
| In reply to | #1517037 |
tsl2583_als_calibrate() returns the newly computed gain_trim if the calibration was successful. This function is only called by in_illuminance_calibrate_store() and the return value inside that sysfs attribute is only checked to see if an error was returned. This patch changes tsl2583_als_calibrate() to return 0 on success. Signed-off-by: Brian Masney <masneyb@onstation.org> --- drivers/staging/iio/light/tsl2583.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c index 5cdfe06..f1c9bb9 100644 --- a/drivers/staging/iio/light/tsl2583.c +++ b/drivers/staging/iio/light/tsl2583.c @@ -342,7 +342,7 @@ static int tsl2583_als_calibrate(struct iio_dev *indio_dev) chip->als_settings.als_gain_trim = (int)gain_trim_val; - return (int)gain_trim_val; + return 0; } static int tsl2583_set_als_time(struct tsl2583_chip *chip) -- 2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Brian Masney <masneyb@onstation.org> |
|---|---|
| Date | 2016-11-08 11:30 +0100 |
| Subject | [PATCH v2 20/23] staging: iio: tsl2583: don't assume an unsigned int is 32 bits |
| Message-ID | <sBbPc-88c-27@gated-at.bofh.it> |
| In reply to | #1517037 |
in_illuminance_lux_table_store assumes that an unsigned int is 32 bits. Replace this with sizeof(unsigned int). Signed-off-by: Brian Masney <masneyb@onstation.org> --- drivers/staging/iio/light/tsl2583.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c index 29153fa..6644374 100644 --- a/drivers/staging/iio/light/tsl2583.c +++ b/drivers/staging/iio/light/tsl2583.c @@ -574,7 +574,7 @@ static ssize_t in_illuminance_lux_table_store(struct device *dev, /* Zero out the table */ memset(tsl2583_device_lux, 0, sizeof(tsl2583_device_lux)); - memcpy(tsl2583_device_lux, &value[1], value[0] * 4); + memcpy(tsl2583_device_lux, &value[1], value[0] * sizeof(unsigned int)); ret = len; -- 2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Brian Masney <masneyb@onstation.org> |
|---|---|
| Date | 2016-11-08 11:30 +0100 |
| Subject | [PATCH v2 22/23] staging: iio: tsl2583: updated copyright and MODULE_AUTHOR |
| Message-ID | <sBbPc-88c-19@gated-at.bofh.it> |
| In reply to | #1517037 |
Added Brian Masney's copyright to the header and to the MODULE_AUTHOR
for all of the staging cleanups that has been done to this driver.
Signed-off-by: Brian Masney <masneyb@onstation.org>
---
drivers/staging/iio/light/tsl2583.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
index 013e7f6..5cb4ae3 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -3,6 +3,7 @@
* within the TAOS tsl258x family of devices (tsl2580, tsl2581).
*
* Copyright (c) 2011, TAOS Corporation.
+ * Copyright (c) 2016 Brian Masney <masneyb@onstation.org>
*
* 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
@@ -910,6 +911,6 @@ static struct i2c_driver tsl2583_driver = {
};
module_i2c_driver(tsl2583_driver);
-MODULE_AUTHOR("J. August Brenner<jbrenner@taosinc.com>");
+MODULE_AUTHOR("J. August Brenner <jbrenner@taosinc.com> and Brian Masney <masneyb@onstation.org>");
MODULE_DESCRIPTION("TAOS tsl2583 ambient light sensor driver");
MODULE_LICENSE("GPL");
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Jonathan Cameron <jic23@kernel.org> |
|---|---|
| Date | 2016-11-08 21:50 +0100 |
| Subject | Re: [PATCH v2 22/23] staging: iio: tsl2583: updated copyright and MODULE_AUTHOR |
| Message-ID | <sBlvb-5XM-25@gated-at.bofh.it> |
| In reply to | #1517049 |
On 08/11/16 10:16, Brian Masney wrote:
> Added Brian Masney's copyright to the header and to the MODULE_AUTHOR
> for all of the staging cleanups that has been done to this driver.
>
> Signed-off-by: Brian Masney <masneyb@onstation.org>
> ---
> drivers/staging/iio/light/tsl2583.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
> index 013e7f6..5cb4ae3 100644
> --- a/drivers/staging/iio/light/tsl2583.c
> +++ b/drivers/staging/iio/light/tsl2583.c
> @@ -3,6 +3,7 @@
> * within the TAOS tsl258x family of devices (tsl2580, tsl2581).
> *
> * Copyright (c) 2011, TAOS Corporation.
> + * Copyright (c) 2016 Brian Masney <masneyb@onstation.org>
> *
> * 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
> @@ -910,6 +911,6 @@ static struct i2c_driver tsl2583_driver = {
> };
> module_i2c_driver(tsl2583_driver);
>
> -MODULE_AUTHOR("J. August Brenner<jbrenner@taosinc.com>");
> +MODULE_AUTHOR("J. August Brenner <jbrenner@taosinc.com> and Brian Masney <masneyb@onstation.org>");
IIRC preferred method is multiple MODULE_AUTHOR statements.
> MODULE_DESCRIPTION("TAOS tsl2583 ambient light sensor driver");
> MODULE_LICENSE("GPL");
>
[toc] | [prev] | [next] | [standalone]
| From | Brian Masney <masneyb@onstation.org> |
|---|---|
| Date | 2016-11-08 11:30 +0100 |
| Subject | [PATCH v2 19/23] staging: iio: tsl2583: remove unnecessary parentheses |
| Message-ID | <sBbPc-88c-23@gated-at.bofh.it> |
| In reply to | #1517037 |
in_illuminance_lux_table_store() contains some unnecessary parentheses.
This patch removes them since they provide no value.
Signed-off-by: Brian Masney <masneyb@onstation.org>
---
drivers/staging/iio/light/tsl2583.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
index f1c9bb9..29153fa 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -566,7 +566,7 @@ static ssize_t in_illuminance_lux_table_store(struct device *dev,
__func__, TSL2583_MAX_LUX_INTS);
goto done;
}
- if ((value[(n - 2)] | value[(n - 1)] | value[n]) != 0) {
+ if ((value[n - 2] | value[n - 1] | value[n]) != 0) {
dev_err(dev, "%s: The last 3 entries in the lux table must be zeros.\n",
__func__);
goto done;
@@ -574,7 +574,7 @@ static ssize_t in_illuminance_lux_table_store(struct device *dev,
/* Zero out the table */
memset(tsl2583_device_lux, 0, sizeof(tsl2583_device_lux));
- memcpy(tsl2583_device_lux, &value[1], (value[0] * 4));
+ memcpy(tsl2583_device_lux, &value[1], value[0] * 4);
ret = len;
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Brian Masney <masneyb@onstation.org> |
|---|---|
| Date | 2016-11-08 11:30 +0100 |
| Subject | [PATCH v2 14/23] staging: iio: tsl2583: combine sysfs documentation |
| Message-ID | <sBbPc-88c-35@gated-at.bofh.it> |
| In reply to | #1517037 |
There are two separate files describing the tsl2583 sysfs attributes. Combine the two files into one. Updated the name of the sysfs attributes to match the current ABI. Signed-off-by: Brian Masney <masneyb@onstation.org> Suggested-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net> --- .../Documentation/light/sysfs-bus-iio-light-tsl2583 | 16 +++++++++++++++- .../iio/Documentation/sysfs-bus-iio-light-tsl2583 | 20 -------------------- 2 files changed, 15 insertions(+), 21 deletions(-) delete mode 100644 drivers/staging/iio/Documentation/sysfs-bus-iio-light-tsl2583 diff --git a/drivers/staging/iio/Documentation/light/sysfs-bus-iio-light-tsl2583 b/drivers/staging/iio/Documentation/light/sysfs-bus-iio-light-tsl2583 index 470f7ad..a2e1996 100644 --- a/drivers/staging/iio/Documentation/light/sysfs-bus-iio-light-tsl2583 +++ b/drivers/staging/iio/Documentation/light/sysfs-bus-iio-light-tsl2583 @@ -1,6 +1,20 @@ -What: /sys/bus/iio/devices/device[n]/in_illuminance0_calibrate +What: /sys/bus/iio/devices/device[n]/in_illuminance_calibrate KernelVersion: 2.6.37 Contact: linux-iio@vger.kernel.org Description: This property causes an internal calibration of the als gain trim value which is later used in calculating illuminance in lux. + +What: /sys/bus/iio/devices/device[n]/in_illuminance_lux_table +KernelVersion: 2.6.37 +Contact: linux-iio@vger.kernel.org +Description: + This property gets/sets the table of coefficients + used in calculating illuminance in lux. + +What: /sys/bus/iio/devices/device[n]/in_illuminance_input_target +KernelVersion: 2.6.37 +Contact: linux-iio@vger.kernel.org +Description: + This property is the known externally illuminance (in lux). + It is used in the process of calibrating the device accuracy. diff --git a/drivers/staging/iio/Documentation/sysfs-bus-iio-light-tsl2583 b/drivers/staging/iio/Documentation/sysfs-bus-iio-light-tsl2583 deleted file mode 100644 index 660781d..0000000 --- a/drivers/staging/iio/Documentation/sysfs-bus-iio-light-tsl2583 +++ /dev/null @@ -1,20 +0,0 @@ -What: /sys/bus/iio/devices/device[n]/lux_table -KernelVersion: 2.6.37 -Contact: linux-iio@vger.kernel.org -Description: - This property gets/sets the table of coefficients - used in calculating illuminance in lux. - -What: /sys/bus/iio/devices/device[n]/illuminance0_calibrate -KernelVersion: 2.6.37 -Contact: linux-iio@vger.kernel.org -Description: - This property causes an internal calibration of the als gain trim - value which is later used in calculating illuminance in lux. - -What: /sys/bus/iio/devices/device[n]/illuminance0_input_target -KernelVersion: 2.6.37 -Contact: linux-iio@vger.kernel.org -Description: - This property is the known externally illuminance (in lux). - It is used in the process of calibrating the device accuracy. -- 2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Brian Masney <masneyb@onstation.org> |
|---|---|
| Date | 2016-11-08 11:30 +0100 |
| Subject | [PATCH v2 16/23] staging: iio: tsl2583: updated code comment to match what the code does |
| Message-ID | <sBbPc-88c-41@gated-at.bofh.it> |
| In reply to | #1517037 |
If channel 0 does not have any data, then the code sets the lux to zero.
The corresponding comment says that the last value is returned. This
updates the comment to correctly reflect what the code does.
Signed-off-by: Brian Masney <masneyb@onstation.org>
---
drivers/staging/iio/light/tsl2583.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
index 5ef403c..8d9176d 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -221,7 +221,7 @@ static int tsl2583_get_lux(struct iio_dev *indio_dev)
goto return_max;
if (!ch0) {
- /* have no data, so return LAST VALUE */
+ /* have no data, so return 0 */
ret = 0;
chip->als_cur_info.lux = 0;
goto done;
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Brian Masney <masneyb@onstation.org> |
|---|---|
| Date | 2016-11-08 11:30 +0100 |
| Subject | [PATCH v2 11/23] staging: iio: tsl2583: fix alignment of #define values |
| Message-ID | <sBbPc-88c-39@gated-at.bofh.it> |
| In reply to | #1517037 |
Most of the values in the #defines have their values aligned on a single column, but some do not. This changes the remaining defines to use consistent alignment with the majority to improve code readability. Signed-off-by: Brian Masney <masneyb@onstation.org> --- drivers/staging/iio/light/tsl2583.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c index d4cd143..ad6866a 100644 --- a/drivers/staging/iio/light/tsl2583.c +++ b/drivers/staging/iio/light/tsl2583.c @@ -44,19 +44,19 @@ /* tsl2583 cmd reg masks */ #define TSL2583_CMD_REG 0x80 #define TSL2583_CMD_SPL_FN 0x60 -#define TSL2583_CMD_ALS_INT_CLR 0X01 +#define TSL2583_CMD_ALS_INT_CLR 0x01 /* tsl2583 cntrl reg masks */ -#define TSL2583_CNTL_ADC_ENBL 0x02 +#define TSL2583_CNTL_ADC_ENBL 0x02 #define TSL2583_CNTL_PWR_OFF 0x00 #define TSL2583_CNTL_PWR_ON 0x01 /* tsl2583 status reg masks */ -#define TSL2583_STA_ADC_VALID 0x01 -#define TSL2583_STA_ADC_INTR 0x10 +#define TSL2583_STA_ADC_VALID 0x01 +#define TSL2583_STA_ADC_INTR 0x10 /* Lux calculation constants */ -#define TSL2583_LUX_CALC_OVER_FLOW 65535 +#define TSL2583_LUX_CALC_OVER_FLOW 65535 #define TSL2583_INTERRUPT_DISABLED 0x00 -- 2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Brian Masney <masneyb@onstation.org> |
|---|---|
| Date | 2016-11-08 11:40 +0100 |
| Subject | [PATCH v2 17/23] staging: iio: tsl2583: moved code block inside else statement |
| Message-ID | <sBbYR-8bd-7@gated-at.bofh.it> |
| In reply to | #1517037 |
The check for ch1lux > ch0lux inside tsl2583_get_lux is only valid if
the ratio is not equal to zero. Move the code block inside the else
statement. This does away with the need to initialize the variables to
zero.
Signed-off-by: Brian Masney <masneyb@onstation.org>
---
drivers/staging/iio/light/tsl2583.c | 23 ++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)
diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
index 8d9176d..5cdfe06 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -167,8 +167,6 @@ static int tsl2583_get_lux(struct iio_dev *indio_dev)
struct tsl2583_lux *p;
struct tsl2583_chip *chip = iio_priv(indio_dev);
int i, ret;
- u32 ch0lux = 0;
- u32 ch1lux = 0;
ret = i2c_smbus_read_byte_data(chip->client, TSL2583_CMD_REG);
if (ret < 0) {
@@ -238,22 +236,25 @@ static int tsl2583_get_lux(struct iio_dev *indio_dev)
if (p->ratio == 0) {
lux = 0;
} else {
+ u32 ch0lux, ch1lux;
+
ch0lux = ((ch0 * p->ch0) +
(gainadj[chip->als_settings.als_gain].ch0 >> 1))
/ gainadj[chip->als_settings.als_gain].ch0;
ch1lux = ((ch1 * p->ch1) +
(gainadj[chip->als_settings.als_gain].ch1 >> 1))
/ gainadj[chip->als_settings.als_gain].ch1;
- lux = ch0lux - ch1lux;
- }
- /* note: lux is 31 bit max at this point */
- if (ch1lux > ch0lux) {
- dev_dbg(&chip->client->dev, "%s: No Data - Returning 0\n",
- __func__);
- ret = 0;
- chip->als_cur_info.lux = 0;
- goto done;
+ /* note: lux is 31 bit max at this point */
+ if (ch1lux > ch0lux) {
+ dev_dbg(&chip->client->dev, "%s: No Data - Returning 0\n",
+ __func__);
+ ret = 0;
+ chip->als_cur_info.lux = 0;
+ goto done;
+ }
+
+ lux = ch0lux - ch1lux;
}
/* adjust for active time scale */
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Brian Masney <masneyb@onstation.org> |
|---|---|
| Date | 2016-11-08 11:40 +0100 |
| Subject | [PATCH v2 21/23] staging: iio: tsl2583: move from a global to a per device lux table |
| Message-ID | <sBbYS-8bd-9@gated-at.bofh.it> |
| In reply to | #1517037 |
The driver contains a global lux table that can be updated via sysfs.
Change this to a per device lux table so that multiple devices can be
hooked up to the same system with different lux tables.
There are 10 entries, plus 1 for the termination segment, set aside for
the entries in the lux table. When updating the lux table via sysfs,
only 9 entries, plus the terminator, could be added. This changes
the code to allow for the 10 entries, plus the terminator.
Signed-off-by: Brian Masney <masneyb@onstation.org>
---
I also included the change for the lux table size since I feel that it will
make the review of the overall change easier.
drivers/staging/iio/light/tsl2583.c | 79 +++++++++++++++++++++----------------
1 file changed, 45 insertions(+), 34 deletions(-)
diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
index 6644374..013e7f6 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -70,11 +70,32 @@ struct tsl2583_als_info {
u16 lux;
};
+struct tsl2583_lux {
+ unsigned int ratio;
+ unsigned int ch0;
+ unsigned int ch1;
+};
+
+static const struct tsl2583_lux tsl2583_default_lux[] = {
+ { 9830, 8520, 15729 },
+ { 12452, 10807, 23344 },
+ { 14746, 6383, 11705 },
+ { 17695, 4063, 6554 },
+ { 0, 0, 0 } /* Termination segment */
+};
+
struct tsl2583_settings {
int als_time;
int als_gain;
int als_gain_trim;
int als_cal_target;
+
+ /*
+ * This structure is intentionally large to accommodate updates via
+ * sysfs. Sized to 11 = max 10 segments + 1 termination segment.
+ * Assumption is that one and only one type of glass used.
+ */
+ struct tsl2583_lux als_device_lux[11];
};
struct tsl2583_chip {
@@ -87,24 +108,6 @@ struct tsl2583_chip {
bool suspended;
};
-struct tsl2583_lux {
- unsigned int ratio;
- unsigned int ch0;
- unsigned int ch1;
-};
-
-/*
- * This structure is intentionally large to accommodate updates via sysfs.
- * Sized to 11 = max 10 segments + 1 termination segment. Assumption is that
- * one and only one type of glass used.
- */
-static struct tsl2583_lux tsl2583_device_lux[11] = {
- { 9830, 8520, 15729 },
- { 12452, 10807, 23344 },
- { 14746, 6383, 11705 },
- { 17695, 4063, 6554 },
-};
-
struct gainadj {
s16 ch0;
s16 ch1;
@@ -142,6 +145,10 @@ static void tsl2583_defaults(struct tsl2583_chip *chip)
/* Known external ALS reading used for calibration */
chip->als_settings.als_cal_target = 130;
+
+ /* Default lux table. */
+ memcpy(chip->als_settings.als_device_lux, tsl2583_default_lux,
+ sizeof(tsl2583_default_lux));
}
/*
@@ -151,7 +158,7 @@ static void tsl2583_defaults(struct tsl2583_chip *chip)
* Time scale factor array values are adjusted based on the integration time.
* The raw values are multiplied by a scale factor, and device gain is obtained
* using gain index. Limit checks are done next, then the ratio of a multiple
- * of ch1 value, to the ch0 value, is calculated. The array tsl2583_device_lux[]
+ * of ch1 value, to the ch0 value, is calculated. The array als_device_lux[]
* declared above is then scanned to find the first ratio value that is just
* above the ratio we just calculated. The ch0 and ch1 multiplier constants in
* the array are then used along with the time scale factor array values, to
@@ -229,7 +236,7 @@ static int tsl2583_get_lux(struct iio_dev *indio_dev)
ratio = (ch1 << 15) / ch0;
/* convert to unscaled lux using the pointer to the table */
- for (p = (struct tsl2583_lux *)tsl2583_device_lux;
+ for (p = (struct tsl2583_lux *)chip->als_settings.als_device_lux;
p->ratio != 0 && p->ratio < ratio; p++)
;
@@ -266,7 +273,7 @@ static int tsl2583_get_lux(struct iio_dev *indio_dev)
/*
* Adjust for active gain scale.
- * The tsl2583_device_lux tables above have a factor of 8192 built in,
+ * The tsl2583_default_lux tables above have a factor of 8192 built in,
* so we need to shift right.
* User-specified gain provides a multiplier.
* Apply user-specified gain before shifting right to retain precision.
@@ -514,15 +521,17 @@ static ssize_t in_illuminance_lux_table_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
+ struct iio_dev *indio_dev = dev_to_iio_dev(dev);
+ struct tsl2583_chip *chip = iio_priv(indio_dev);
unsigned int i;
int offset = 0;
- for (i = 0; i < ARRAY_SIZE(tsl2583_device_lux); i++) {
+ for (i = 0; i < ARRAY_SIZE(chip->als_settings.als_device_lux); i++) {
offset += sprintf(buf + offset, "%u,%u,%u,",
- tsl2583_device_lux[i].ratio,
- tsl2583_device_lux[i].ch0,
- tsl2583_device_lux[i].ch1);
- if (tsl2583_device_lux[i].ratio == 0) {
+ chip->als_settings.als_device_lux[i].ratio,
+ chip->als_settings.als_device_lux[i].ch0,
+ chip->als_settings.als_device_lux[i].ch1);
+ if (chip->als_settings.als_device_lux[i].ratio == 0) {
/*
* We just printed the first "0" entry.
* Now get rid of the extra "," and break.
@@ -537,15 +546,15 @@ static ssize_t in_illuminance_lux_table_show(struct device *dev,
return offset;
}
-#define TSL2583_MAX_LUX_INTS ((ARRAY_SIZE(tsl2583_device_lux) - 1) * 3)
-
static ssize_t in_illuminance_lux_table_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 tsl2583_chip *chip = iio_priv(indio_dev);
- int value[ARRAY_SIZE(tsl2583_device_lux) * 3 + 1];
+ const unsigned int max_ints =
+ ARRAY_SIZE(chip->als_settings.als_device_lux) * 3;
+ int value[max_ints];
int ret = -EINVAL;
unsigned int n;
@@ -560,10 +569,10 @@ static ssize_t in_illuminance_lux_table_store(struct device *dev,
* and the last table entry is all 0.
*/
n = value[0];
- if ((n % 3) || n < 6 || n > TSL2583_MAX_LUX_INTS) {
+ if ((n % 3) || n < 6 || n > max_ints) {
dev_err(dev,
- "%s: The number of entries in the lux table must be a multiple of 3 and within the range [6, %zu]",
- __func__, TSL2583_MAX_LUX_INTS);
+ "%s: The number of entries in the lux table must be a multiple of 3 and within the range [6, %d]",
+ __func__, max_ints);
goto done;
}
if ((value[n - 2] | value[n - 1] | value[n]) != 0) {
@@ -573,8 +582,10 @@ static ssize_t in_illuminance_lux_table_store(struct device *dev,
}
/* Zero out the table */
- memset(tsl2583_device_lux, 0, sizeof(tsl2583_device_lux));
- memcpy(tsl2583_device_lux, &value[1], value[0] * sizeof(unsigned int));
+ memset(chip->als_settings.als_device_lux, 0,
+ sizeof(chip->als_settings.als_device_lux));
+ memcpy(chip->als_settings.als_device_lux, &value[1],
+ value[0] * sizeof(unsigned int));
ret = len;
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Brian Masney <masneyb@onstation.org> |
|---|---|
| Date | 2016-11-08 11:40 +0100 |
| Subject | [PATCH v2 13/23] staging: iio: tsl2583: change newlines to improve readability |
| Message-ID | <sBbYS-8bd-23@gated-at.bofh.it> |
| In reply to | #1517037 |
Add and remove newlines to improve code readability in preparation for
moving the driver out of staging.
Signed-off-by: Brian Masney <masneyb@onstation.org>
---
drivers/staging/iio/light/tsl2583.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
index 8be135b..eff59f37 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -202,7 +202,6 @@ static int tsl2583_get_lux(struct iio_dev *indio_dev)
ret = i2c_smbus_write_byte(chip->client,
(TSL2583_CMD_REG | TSL2583_CMD_SPL_FN |
TSL2583_CMD_ALS_INT_CLR));
-
if (ret < 0) {
dev_err(&chip->client->dev, "%s failed to clear the interrupt bit\n",
__func__);
@@ -225,8 +224,10 @@ static int tsl2583_get_lux(struct iio_dev *indio_dev)
chip->als_cur_info.lux = 0;
goto done;
}
+
/* calculate ratio */
ratio = (ch1 << 15) / ch0;
+
/* convert to unscaled lux using the pointer to the table */
for (p = (struct tsl2583_lux *)tsl2583_device_lux;
p->ratio != 0 && p->ratio < ratio; p++)
@@ -273,6 +274,7 @@ static int tsl2583_get_lux(struct iio_dev *indio_dev)
lux64 >>= 13;
lux = lux64;
lux = (lux + 500) / 1000;
+
if (lux > TSL2583_LUX_CALC_OVER_FLOW) { /* check for overflow */
return_max:
lux = TSL2583_LUX_CALC_OVER_FLOW;
@@ -318,20 +320,22 @@ static int tsl2583_als_calibrate(struct iio_dev *indio_dev)
"%s failed: STATUS - ADC not valid.\n", __func__);
return -ENODATA;
}
+
lux_val = tsl2583_get_lux(indio_dev);
if (lux_val < 0) {
dev_err(&chip->client->dev, "%s failed to get lux\n", __func__);
return lux_val;
}
+
gain_trim_val = (unsigned int)(((chip->als_settings.als_cal_target)
* chip->als_settings.als_gain_trim) / lux_val);
-
if ((gain_trim_val < 250) || (gain_trim_val > 4000)) {
dev_err(&chip->client->dev,
"%s failed: trim_val of %d is not within the range [250, 4000]\n",
__func__, gain_trim_val);
return -ENODATA;
}
+
chip->als_settings.als_gain_trim = (int)gain_trim_val;
return (int)gain_trim_val;
@@ -525,6 +529,7 @@ static ssize_t in_illuminance_lux_table_show(struct device *dev,
}
offset += sprintf(buf + offset, "\n");
+
return offset;
}
@@ -772,6 +777,7 @@ static int tsl2583_probe(struct i2c_client *clientp,
indio_dev = devm_iio_device_alloc(&clientp->dev, sizeof(*chip));
if (!indio_dev)
return -ENOMEM;
+
chip = iio_priv(indio_dev);
chip->client = clientp;
i2c_set_clientdata(clientp, indio_dev);
@@ -799,6 +805,7 @@ static int tsl2583_probe(struct i2c_client *clientp,
indio_dev->dev.parent = &clientp->dev;
indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->name = chip->client->name;
+
ret = devm_iio_device_register(indio_dev->dev.parent, indio_dev);
if (ret) {
dev_err(&clientp->dev, "%s: iio registration failed\n",
@@ -815,6 +822,7 @@ static int tsl2583_probe(struct i2c_client *clientp,
return ret;
dev_info(&clientp->dev, "Light sensor found.\n");
+
return 0;
}
--
2.7.4
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web