From: Jonathan Cameron <jic23@kernel.org>
To: Brian Masney <masneyb@onstation.org>, linux-iio@vger.kernel.org
Cc: devel@driverdev.osuosl.org, gregkh@linuxfoundation.org,
lars@metafoo.de, pmeerw@pmeerw.net, knaack.h@gmx.de,
linux-kernel@vger.kernel.org, Jon.Brenner@ams.com
Subject: Re: [PATCH v3 21/28] staging: iio: tsl2583: move from a global to a per device lux table
Date: Sat, 12 Nov 2016 16:44:23 +0000 [thread overview]
Message-ID: <6877298c-7ef2-fba1-117a-0dd381e9ce6b@kernel.org> (raw)
In-Reply-To: <1478769964-7065-22-git-send-email-masneyb@onstation.org>
On 10/11/16 09:25, Brian Masney wrote:
> 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>
A follow through comment to make sure you carry over a change suggested
for an earlier patch.
Otherwise, looks good.
Jonathan
> ---
> 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 | 80 +++++++++++++++++++++----------------
> 1 file changed, 46 insertions(+), 34 deletions(-)
>
> diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
> index bcee31b..c9635e3 100644
> --- a/drivers/staging/iio/light/tsl2583.c
> +++ b/drivers/staging/iio/light/tsl2583.c
> @@ -70,11 +70,34 @@ 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 */
> +};
> +
> +#define TSL2583_MAX_LUX_TABLE_ENTRIES 11
> +
> 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[TSL2583_MAX_LUX_TABLE_ENTRIES];
> };
>
> struct tsl2583_chip {
> @@ -87,24 +110,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 +147,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 +160,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 +238,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 +275,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.
> @@ -518,15 +527,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.
> @@ -541,15 +552,14 @@ 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 = TSL2583_MAX_LUX_TABLE_ENTRIES * 3;
> + int value[TSL2583_MAX_LUX_TABLE_ENTRIES * 3];
> int ret = -EINVAL;
> unsigned int n;
>
> @@ -564,10 +574,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]\n",
> - __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]\n",
> + __func__, max_ints);
> goto done;
> }
> if ((value[n - 2] | value[n - 1] | value[n]) != 0) {
> @@ -577,8 +587,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));
The sizeof(value[0]) applies in the updated code as well.
(actually come to think of it value[1] makes slightly better logical sense.)
>
> ret = len;
>
>
next prev parent reply other threads:[~2016-11-12 16:45 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-10 9:25 [PATCH v3 00/28] staging: iio: tsl2583: move out of staging Brian Masney
2016-11-10 9:25 ` [PATCH v3 01/28] staging: iio: tsl2583: split out functionality of taos_chip_on() Brian Masney
2016-11-12 16:17 ` Jonathan Cameron
2016-11-10 9:25 ` [PATCH v3 02/28] staging: iio: tsl2583: fix issue with changes to calibscale and int_time not being set on the chip Brian Masney
2016-11-12 16:23 ` Jonathan Cameron
2016-11-10 9:25 ` [PATCH v3 03/28] staging: iio: tsl2583: check if chip is suspended in in_illuminance_calibrate_store Brian Masney
2016-11-12 16:24 ` Jonathan Cameron
2016-11-12 16:27 ` Jonathan Cameron
2016-11-12 16:37 ` Brian Masney
2016-11-10 9:25 ` [PATCH v3 04/28] staging: iio: tsl2583: remove unnecessary chip status check in taos_get_lux Brian Masney
2016-11-12 16:28 ` Jonathan Cameron
2016-11-10 9:25 ` [PATCH v3 05/28] staging: iio: tsl2583: remove unnecessary chip status checks in suspend/resume Brian Masney
2016-11-12 16:31 ` Jonathan Cameron
2016-11-10 9:25 ` [PATCH v3 06/28] staging: iio: tsl2583: change current chip state from a tristate to a bool Brian Masney
2016-11-10 9:25 ` [PATCH v3 07/28] staging: iio: tsl2583: remove redundant write to the control register in taos_probe() Brian Masney
2016-11-10 9:25 ` [PATCH v3 08/28] staging: iio: tsl2583: remove the FSF's mailing address Brian Masney
2016-11-10 9:25 ` [PATCH v3 09/28] staging: iio: tsl2583: cleaned up logging Brian Masney
2016-11-10 9:25 ` [PATCH v3 10/28] staging: iio: tsl2583: unify function and variable prefix to tsl2583_ Brian Masney
2016-11-10 9:25 ` [PATCH v3 11/28] staging: iio: tsl2583: fix alignment of #define values Brian Masney
2016-11-10 9:25 ` [PATCH v3 12/28] staging: iio: tsl2583: fix comparison between signed and unsigned integers Brian Masney
2016-11-10 9:25 ` [PATCH v3 13/28] staging: iio: tsl2583: change newlines to improve readability Brian Masney
2016-11-10 9:25 ` [PATCH v3 14/28] staging: iio: tsl2583: combine sysfs documentation Brian Masney
2016-11-10 9:25 ` [PATCH v3 15/28] staging: iio: tsl2583: fix multiline comment syntax Brian Masney
2016-11-10 9:25 ` [PATCH v3 16/28] staging: iio: tsl2583: updated code comment to match what the code does Brian Masney
2016-11-12 16:36 ` Jonathan Cameron
2016-11-12 16:59 ` Brian Masney
2016-11-12 17:10 ` Jonathan Cameron
2016-11-10 9:25 ` [PATCH v3 17/28] staging: iio: tsl2583: moved code block inside else statement Brian Masney
2016-11-10 9:25 ` [PATCH v3 18/28] staging: iio: tsl2583: change tsl2583_als_calibrate() to return 0 on success Brian Masney
2016-11-10 9:25 ` [PATCH v3 19/28] staging: iio: tsl2583: remove unnecessary parentheses Brian Masney
2016-11-10 9:25 ` [PATCH v3 20/28] staging: iio: tsl2583: don't assume an unsigned int is 32 bits Brian Masney
2016-11-12 16:38 ` Jonathan Cameron
2016-12-05 20:55 ` Dan Carpenter
2016-11-10 9:25 ` [PATCH v3 21/28] staging: iio: tsl2583: move from a global to a per device lux table Brian Masney
2016-11-12 16:44 ` Jonathan Cameron [this message]
2016-11-10 9:25 ` [PATCH v3 22/28] staging: iio: tsl2583: add tsl2583 to list of supported devices in the header Brian Masney
2016-11-10 9:25 ` [PATCH v3 23/28] staging: iio: tsl2583: clarified comment about clearing interrupts Brian Masney
2016-11-10 9:26 ` [PATCH v3 24/28] staging: iio: tsl2583: remove comment for tsl2583_probe() Brian Masney
2016-11-10 9:26 ` [PATCH v3 25/28] staging: iio: tsl2583: remove unnecessary memset call Brian Masney
2016-11-10 9:26 ` [PATCH v3 26/28] staging: iio: tsl2583: remove unnecessary variable initialization Brian Masney
2016-11-10 9:26 ` [PATCH v3 27/28] staging: iio: tsl2583: add copyright and MODULE_AUTHOR Brian Masney
2016-11-10 9:26 ` [PATCH v3 28/28] staging: iio: tsl2583: move out of staging Brian Masney
2016-11-12 16:47 ` Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6877298c-7ef2-fba1-117a-0dd381e9ce6b@kernel.org \
--to=jic23@kernel.org \
--cc=Jon.Brenner@ams.com \
--cc=devel@driverdev.osuosl.org \
--cc=gregkh@linuxfoundation.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=masneyb@onstation.org \
--cc=pmeerw@pmeerw.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).