linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 00/26] staging: iio: tsl2583: move out of staging
@ 2016-11-12 18:19 Brian Masney
  2016-11-12 18:19 ` [PATCH v4 01/26] staging: iio: tsl2583: check if chip is in a working state in in_illuminance_calibrate_store Brian Masney
                   ` (25 more replies)
  0 siblings, 26 replies; 54+ messages in thread
From: Brian Masney @ 2016-11-12 18:19 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

This patch set continues my work to clean up the tsl2583 driver to move
it out of staging. Some highlights include:

- Eliminated some unnecessary i2c calls to the sensor.
- Fixed issue with changes to calibscale and int_time not being set on
  the chip.
- Moved from a global lux table to a per device lux table.
- Combined redundant sysfs ABI documentation.
- Made log messages clearer.
- Fixes for some return values that were not checked.
- Chip state is now represented as a boolean instead of a tristate.
- Removed unnecessary chip status checks.
- Use a unified prefix for all symbols (tsl2583_).
- Code style and formatting cleanups.
- Comment cleanups.
- Staging graduation.

I verified that the driver functions correctly using a TSL2581 hooked
up to a Raspberry Pi 2.

Changes from V3 to V4
- Fixed patch 03/28 so that it compiles properly. It was fixed later
  in the old series but this needs to be corrected so that people can
  use git bisect. I verified that every patch in this series compiles
  when incrementally applied.
- Clarified comment on patch 14 in this series.
- Use sizeof(value[1]) instead of sizeof(unsigned int) when updating
  the lux table on patch 18 of this series.

Changes from V2 to V3
- Fixed patch #09 to use "%s: <message>", __func__ consistently. Added
  missing terminating "\n" to one of the log messages. Issues reported
  by Joe Perches.
- Fixed issues found by Jonathan Cameron: comment cleanups, improved the
  wording of two log messages, removed an unnecessary memset call,
  removed unnecessary variable initialization, and multiple driver
  authors can be specified with multiple calls to MODULE_AUTHOR().
- Fixed warning found by make C=1 in the per device lux table:
  warning: Variable length array is used.

Changes from V1 to V2
- 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.

Brian Masney (26):
  staging: iio: tsl2583: check if chip is in a working state 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: add tsl2583 to list of supported devices in the
    header
  staging: iio: tsl2583: clarified comment about clearing interrupts
  staging: iio: tsl2583: remove comment for tsl2583_probe()
  staging: iio: tsl2583: remove unnecessary memset call
  staging: iio: tsl2583: remove unnecessary variable initialization
  staging: iio: tsl2583: add 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                        | 913 +++++++++++++++++++++
 .../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                | 896 --------------------
 9 files changed, 941 insertions(+), 930 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

^ permalink raw reply	[flat|nested] 54+ messages in thread

* [PATCH v4 01/26] staging: iio: tsl2583: check if chip is in a working state in in_illuminance_calibrate_store
  2016-11-12 18:19 [PATCH v4 00/26] staging: iio: tsl2583: move out of staging Brian Masney
@ 2016-11-12 18:19 ` Brian Masney
  2016-11-13 11:54   ` Jonathan Cameron
  2016-11-12 18:19 ` [PATCH v4 02/26] staging: iio: tsl2583: remove unnecessary chip status check in taos_get_lux Brian Masney
                   ` (24 subsequent siblings)
  25 siblings, 1 reply; 54+ messages in thread
From: Brian Masney @ 2016-11-12 18:19 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

in_illuminance_calibrate_store() did not check to see if the chip is
in a working state. 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 1a7be12..de54e74 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->taos_chip_status != TSL258X_CHIP_WORKING) {
+		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

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v4 02/26] staging: iio: tsl2583: remove unnecessary chip status check in taos_get_lux
  2016-11-12 18:19 [PATCH v4 00/26] staging: iio: tsl2583: move out of staging Brian Masney
  2016-11-12 18:19 ` [PATCH v4 01/26] staging: iio: tsl2583: check if chip is in a working state in in_illuminance_calibrate_store Brian Masney
@ 2016-11-12 18:19 ` Brian Masney
  2016-11-13 11:55   ` Jonathan Cameron
  2016-11-12 18:19 ` [PATCH v4 03/26] staging: iio: tsl2583: remove unnecessary chip status checks in suspend/resume Brian Masney
                   ` (23 subsequent siblings)
  25 siblings, 1 reply; 54+ messages in thread
From: Brian Masney @ 2016-11-12 18:19 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

taos_get_lux checks to see if the chip is in a working state. This
check is not necessary since it is only called from tsl2583_read_raw
and in_illuminance_calibrate_store (via taos_als_calibrate). The chip
state is already checked by these functions.

Signed-off-by: Brian Masney <masneyb@onstation.org>
---
 drivers/staging/iio/light/tsl2583.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
index de54e74..a550023 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -178,13 +178,6 @@ static int taos_get_lux(struct iio_dev *indio_dev)
 	u32 ch0lux = 0;
 	u32 ch1lux = 0;
 
-	if (chip->taos_chip_status != TSL258X_CHIP_WORKING) {
-		/* device is not enabled */
-		dev_err(&chip->client->dev, "taos_get_lux device is not enabled\n");
-		ret = -EBUSY;
-		goto done;
-	}
-
 	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");
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v4 03/26] staging: iio: tsl2583: remove unnecessary chip status checks in suspend/resume
  2016-11-12 18:19 [PATCH v4 00/26] staging: iio: tsl2583: move out of staging Brian Masney
  2016-11-12 18:19 ` [PATCH v4 01/26] staging: iio: tsl2583: check if chip is in a working state in in_illuminance_calibrate_store Brian Masney
  2016-11-12 18:19 ` [PATCH v4 02/26] staging: iio: tsl2583: remove unnecessary chip status check in taos_get_lux Brian Masney
@ 2016-11-12 18:19 ` Brian Masney
  2016-11-13 11:56   ` Jonathan Cameron
  2016-11-12 18:19 ` [PATCH v4 04/26] staging: iio: tsl2583: change current chip state from a tristate to a bool Brian Masney
                   ` (22 subsequent siblings)
  25 siblings, 1 reply; 54+ messages in thread
From: Brian Masney @ 2016-11-12 18:19 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

The device probing and the suspend/resume code checks a flag internal to
the driver that determines whether or not the chip is in a working
state. These checks are not needed. This patch removes the unnecessary
checks. It will do no harm to the hardware if the chip is
reinitialized if it is already powered on.

Signed-off-by: Brian Masney <masneyb@onstation.org>
---
 drivers/staging/iio/light/tsl2583.c | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
index a550023..40aa78e 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -412,13 +412,6 @@ static int tsl2583_chip_init_and_power_on(struct iio_dev *indio_dev)
 	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) {
-		/* if forcing a register update - turn off, then on */
-		dev_info(&chip->client->dev, "device is already enabled\n");
-		return -EINVAL;
-	}
-
 	/* Power on the device; ADC off. */
 	ret = tsl2583_set_power_state(chip, TSL258X_CNTL_PWR_ON);
 	if (ret < 0)
@@ -841,10 +834,8 @@ static int __maybe_unused taos_suspend(struct device *dev)
 
 	mutex_lock(&chip->als_mutex);
 
-	if (chip->taos_chip_status == TSL258X_CHIP_WORKING) {
-		ret = tsl2583_set_power_state(chip, TSL258X_CNTL_PWR_OFF);
-		chip->taos_chip_status = TSL258X_CHIP_SUSPENDED;
-	}
+	ret = tsl2583_set_power_state(chip, TSL258X_CNTL_PWR_OFF);
+	chip->taos_chip_status = TSL258X_CHIP_SUSPENDED;
 
 	mutex_unlock(&chip->als_mutex);
 	return ret;
@@ -858,8 +849,7 @@ static int __maybe_unused taos_resume(struct device *dev)
 
 	mutex_lock(&chip->als_mutex);
 
-	if (chip->taos_chip_status == TSL258X_CHIP_SUSPENDED)
-		ret = tsl2583_chip_init_and_power_on(indio_dev);
+	ret = tsl2583_chip_init_and_power_on(indio_dev);
 
 	mutex_unlock(&chip->als_mutex);
 	return ret;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v4 04/26] staging: iio: tsl2583: change current chip state from a tristate to a bool
  2016-11-12 18:19 [PATCH v4 00/26] staging: iio: tsl2583: move out of staging Brian Masney
                   ` (2 preceding siblings ...)
  2016-11-12 18:19 ` [PATCH v4 03/26] staging: iio: tsl2583: remove unnecessary chip status checks in suspend/resume Brian Masney
@ 2016-11-12 18:19 ` Brian Masney
  2016-11-13 11:58   ` Jonathan Cameron
  2016-11-12 18:19 ` [PATCH v4 05/26] staging: iio: tsl2583: remove redundant write to the control register in taos_probe() Brian Masney
                   ` (21 subsequent siblings)
  25 siblings, 1 reply; 54+ messages in thread
From: Brian Masney @ 2016-11-12 18:19 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

The current chip state is represented as a tristate (working, suspended,
and unknown). The unknown state was not used. This patch changes the
chip state so that it is now represented as a single boolean value
(suspended).

Signed-off-by: Brian Masney <masneyb@onstation.org>
---
 drivers/staging/iio/light/tsl2583.c | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
index 40aa78e..5a32102 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -67,12 +67,6 @@
 #define TSL2583_CHIP_ID			0x90
 #define TSL2583_CHIP_ID_MASK		0xf0
 
-enum {
-	TSL258X_CHIP_UNKNOWN = 0,
-	TSL258X_CHIP_WORKING = 1,
-	TSL258X_CHIP_SUSPENDED = 2
-};
-
 /* Per-device data */
 struct taos_als_info {
 	u16 als_ch0;
@@ -94,7 +88,7 @@ struct tsl2583_chip {
 	struct taos_settings taos_settings;
 	int als_time_scale;
 	int als_saturation;
-	int taos_chip_status;
+	bool suspended;
 };
 
 struct taos_lux {
@@ -441,7 +435,7 @@ static int tsl2583_chip_init_and_power_on(struct iio_dev *indio_dev)
 	if (ret < 0)
 		return ret;
 
-	chip->taos_chip_status = TSL258X_CHIP_WORKING;
+	chip->suspended = false;
 
 	return ret;
 }
@@ -494,7 +488,7 @@ static ssize_t in_illuminance_calibrate_store(struct device *dev,
 
 	mutex_lock(&chip->als_mutex);
 
-	if (chip->taos_chip_status != TSL258X_CHIP_WORKING) {
+	if (chip->suspended) {
 		ret = -EBUSY;
 		goto done;
 	}
@@ -627,7 +621,7 @@ static int tsl2583_read_raw(struct iio_dev *indio_dev,
 
 	mutex_lock(&chip->als_mutex);
 
-	if (chip->taos_chip_status != TSL258X_CHIP_WORKING) {
+	if (chip->suspended) {
 		ret = -EBUSY;
 		goto read_done;
 	}
@@ -704,7 +698,7 @@ static int tsl2583_write_raw(struct iio_dev *indio_dev,
 
 	mutex_lock(&chip->als_mutex);
 
-	if (chip->taos_chip_status != TSL258X_CHIP_WORKING) {
+	if (chip->suspended) {
 		ret = -EBUSY;
 		goto write_done;
 	}
@@ -778,7 +772,7 @@ static int taos_probe(struct i2c_client *clientp,
 	i2c_set_clientdata(clientp, indio_dev);
 
 	mutex_init(&chip->als_mutex);
-	chip->taos_chip_status = TSL258X_CHIP_UNKNOWN;
+	chip->suspended = true;
 
 	ret = i2c_smbus_read_byte_data(clientp,
 				       TSL258X_CMD_REG | TSL258X_CHIPID);
@@ -835,7 +829,7 @@ static int __maybe_unused taos_suspend(struct device *dev)
 	mutex_lock(&chip->als_mutex);
 
 	ret = tsl2583_set_power_state(chip, TSL258X_CNTL_PWR_OFF);
-	chip->taos_chip_status = TSL258X_CHIP_SUSPENDED;
+	chip->suspended = true;
 
 	mutex_unlock(&chip->als_mutex);
 	return ret;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v4 05/26] staging: iio: tsl2583: remove redundant write to the control register in taos_probe()
  2016-11-12 18:19 [PATCH v4 00/26] staging: iio: tsl2583: move out of staging Brian Masney
                   ` (3 preceding siblings ...)
  2016-11-12 18:19 ` [PATCH v4 04/26] staging: iio: tsl2583: change current chip state from a tristate to a bool Brian Masney
@ 2016-11-12 18:19 ` Brian Masney
  2016-11-13 12:06   ` Jonathan Cameron
  2016-11-12 18:19 ` [PATCH v4 06/26] staging: iio: tsl2583: remove the FSF's mailing address Brian Masney
                   ` (20 subsequent siblings)
  25 siblings, 1 reply; 54+ messages in thread
From: Brian Masney @ 2016-11-12 18:19 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

taos_probe() calls i2c_smbus_write_byte() to select the control
register, however there are no subsequent calls to
i2c_smbus_read_byte(). The write call is unnecessary and is removed by
this patch.

Verified that the driver still functions correctly using a TSL2581
hooked up to a Raspberry Pi 2.

Signed-off-by: Brian Masney <masneyb@onstation.org>
---
 drivers/staging/iio/light/tsl2583.c | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
index 5a32102..449506b 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -788,14 +788,6 @@ static int taos_probe(struct i2c_client *clientp,
 		return -EINVAL;
 	}
 
-	ret = i2c_smbus_write_byte(clientp, (TSL258X_CMD_REG | TSL258X_CNTRL));
-	if (ret < 0) {
-		dev_err(&clientp->dev,
-			"i2c_smbus_write_byte() to cmd reg failed in taos_probe(), err = %d\n",
-			ret);
-		return ret;
-	}
-
 	indio_dev->info = &tsl2583_info;
 	indio_dev->channels = tsl2583_channels;
 	indio_dev->num_channels = ARRAY_SIZE(tsl2583_channels);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v4 06/26] staging: iio: tsl2583: remove the FSF's mailing address
  2016-11-12 18:19 [PATCH v4 00/26] staging: iio: tsl2583: move out of staging Brian Masney
                   ` (4 preceding siblings ...)
  2016-11-12 18:19 ` [PATCH v4 05/26] staging: iio: tsl2583: remove redundant write to the control register in taos_probe() Brian Masney
@ 2016-11-12 18:19 ` Brian Masney
  2016-11-13 12:07   ` Jonathan Cameron
  2016-11-12 18:19 ` [PATCH v4 07/26] staging: iio: tsl2583: cleaned up logging Brian Masney
                   ` (19 subsequent siblings)
  25 siblings, 1 reply; 54+ messages in thread
From: Brian Masney @ 2016-11-12 18:19 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

Address warning from checkpatch:

CHECK: Do not include the paragraph about writing to the Free Software
Foundation's mailing address from the sample GPL notice. The FSF has
changed addresses in the past, and may do so again. Linux already
includes a copy of the GPL.

Signed-off-by: Brian Masney <masneyb@onstation.org>
---
 drivers/staging/iio/light/tsl2583.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
index 449506b..57279f7 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -13,10 +13,6 @@
  * 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.
  */
 
 #include <linux/kernel.h>
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v4 07/26] staging: iio: tsl2583: cleaned up logging
  2016-11-12 18:19 [PATCH v4 00/26] staging: iio: tsl2583: move out of staging Brian Masney
                   ` (5 preceding siblings ...)
  2016-11-12 18:19 ` [PATCH v4 06/26] staging: iio: tsl2583: remove the FSF's mailing address Brian Masney
@ 2016-11-12 18:19 ` Brian Masney
  2016-11-13 12:07   ` Jonathan Cameron
  2016-11-12 18:19 ` [PATCH v4 08/26] staging: iio: tsl2583: unify function and variable prefix to tsl2583_ Brian Masney
                   ` (18 subsequent siblings)
  25 siblings, 1 reply; 54+ messages in thread
From: Brian Masney @ 2016-11-12 18:19 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

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 | 73 ++++++++++++++++++++++---------------
 1 file changed, 43 insertions(+), 30 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
index 57279f7..5d74e0c1 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;
@@ -301,7 +302,7 @@ static int taos_als_calibrate(struct iio_dev *indio_dev)
 				       TSL258X_CMD_REG | TSL258X_CNTRL);
 	if (ret < 0) {
 		dev_err(&chip->client->dev,
-			"%s failed to read from the CNTRL register\n",
+			"%s: failed to read from the CNTRL register\n",
 			__func__);
 		return ret;
 	}
@@ -309,16 +310,19 @@ 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: Device is not powered on and/or ADC is not 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: The two ADC channels have not completed an integration cycle\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 +330,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: 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;
@@ -353,7 +357,7 @@ static int tsl2583_set_als_time(struct tsl2583_chip *chip)
 					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",
+		dev_err(&chip->client->dev, "%s: failed to set the als time to %d\n",
 			__func__, val);
 		return ret;
 	}
@@ -374,8 +378,9 @@ static int tsl2583_set_als_gain(struct tsl2583_chip *chip)
 					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);
+		dev_err(&chip->client->dev,
+			"%s: failed to set the gain to %d\n", __func__,
+			chip->taos_settings.als_gain);
 
 	return ret;
 }
@@ -387,8 +392,9 @@ static int tsl2583_set_power_state(struct tsl2583_chip *chip, u8 state)
 	ret = i2c_smbus_write_byte_data(chip->client,
 					TSL258X_CMD_REG | TSL258X_CNTRL, state);
 	if (ret < 0)
-		dev_err(&chip->client->dev, "%s failed to set the power state to %d\n",
-			__func__, state);
+		dev_err(&chip->client->dev,
+			"%s: failed to set the power state to %d\n", __func__,
+			state);
 
 	return ret;
 }
@@ -411,8 +417,8 @@ static int tsl2583_chip_init_and_power_on(struct iio_dev *indio_dev)
 					TSL258X_CMD_REG | TSL258X_INTERRUPT,
 					TSL2583_INTERRUPT_DISABLED);
 	if (ret < 0) {
-		dev_err(&chip->client->dev, "%s failed to disable interrupts\n",
-			__func__);
+		dev_err(&chip->client->dev,
+			"%s: failed to disable interrupts\n", __func__);
 		return ret;
 	}
 
@@ -526,6 +532,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 +553,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]\n",
+			__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 +767,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;
 	}
 
@@ -774,13 +786,13 @@ static int taos_probe(struct i2c_client *clientp,
 				       TSL258X_CMD_REG | TSL258X_CHIPID);
 	if (ret < 0) {
 		dev_err(&clientp->dev,
-			"%s failed to read the chip ID register\n", __func__);
+			"%s: failed to read the chip ID register\n", __func__);
 		return ret;
 	}
 
 	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 +804,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

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v4 08/26] staging: iio: tsl2583: unify function and variable prefix to tsl2583_
  2016-11-12 18:19 [PATCH v4 00/26] staging: iio: tsl2583: move out of staging Brian Masney
                   ` (6 preceding siblings ...)
  2016-11-12 18:19 ` [PATCH v4 07/26] staging: iio: tsl2583: cleaned up logging Brian Masney
@ 2016-11-12 18:19 ` Brian Masney
  2016-11-13 12:09   ` Jonathan Cameron
  2016-11-12 18:19 ` [PATCH v4 09/26] staging: iio: tsl2583: fix alignment of #define values Brian Masney
                   ` (17 subsequent siblings)
  25 siblings, 1 reply; 54+ messages in thread
From: Brian Masney @ 2016-11-12 18:19 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

Some functions and variables were prefixed with either taos, tsl258x,
taos2583, or tsl2583. Change everything to use the tsl2583 prefix since
that is the name of the .c file. The taos_settings member inside the
taos_settings struct was renamed to als_settings.

Signed-off-by: Brian Masney <masneyb@onstation.org>
---
 drivers/staging/iio/light/tsl2583.c | 214 ++++++++++++++++++------------------
 1 file changed, 107 insertions(+), 107 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
index 5d74e0c1..5a82a26 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -28,35 +28,35 @@
 #include <linux/iio/sysfs.h>
 
 /* Device Registers and Masks */
-#define TSL258X_CNTRL			0x00
-#define TSL258X_ALS_TIME		0X01
-#define TSL258X_INTERRUPT		0x02
-#define TSL258X_GAIN			0x07
-#define TSL258X_REVID			0x11
-#define TSL258X_CHIPID			0x12
-#define TSL258X_ALS_CHAN0LO		0x14
-#define TSL258X_ALS_CHAN0HI		0x15
-#define TSL258X_ALS_CHAN1LO		0x16
-#define TSL258X_ALS_CHAN1HI		0x17
-#define TSL258X_TMR_LO			0x18
-#define TSL258X_TMR_HI			0x19
+#define TSL2583_CNTRL			0x00
+#define TSL2583_ALS_TIME		0X01
+#define TSL2583_INTERRUPT		0x02
+#define TSL2583_GAIN			0x07
+#define TSL2583_REVID			0x11
+#define TSL2583_CHIPID			0x12
+#define TSL2583_ALS_CHAN0LO		0x14
+#define TSL2583_ALS_CHAN0HI		0x15
+#define TSL2583_ALS_CHAN1LO		0x16
+#define TSL2583_ALS_CHAN1HI		0x17
+#define TSL2583_TMR_LO			0x18
+#define TSL2583_TMR_HI			0x19
 
 /* tsl2583 cmd reg masks */
-#define TSL258X_CMD_REG			0x80
-#define TSL258X_CMD_SPL_FN		0x60
-#define TSL258X_CMD_ALS_INT_CLR	0X01
+#define TSL2583_CMD_REG			0x80
+#define TSL2583_CMD_SPL_FN		0x60
+#define TSL2583_CMD_ALS_INT_CLR	0X01
 
 /* tsl2583 cntrl reg masks */
-#define TSL258X_CNTL_ADC_ENBL	0x02
-#define TSL258X_CNTL_PWR_OFF		0x00
-#define TSL258X_CNTL_PWR_ON		0x01
+#define TSL2583_CNTL_ADC_ENBL	0x02
+#define TSL2583_CNTL_PWR_OFF		0x00
+#define TSL2583_CNTL_PWR_ON		0x01
 
 /* tsl2583 status reg masks */
-#define TSL258X_STA_ADC_VALID	0x01
-#define TSL258X_STA_ADC_INTR	0x10
+#define TSL2583_STA_ADC_VALID	0x01
+#define TSL2583_STA_ADC_INTR	0x10
 
 /* Lux calculation constants */
-#define	TSL258X_LUX_CALC_OVER_FLOW		65535
+#define	TSL2583_LUX_CALC_OVER_FLOW		65535
 
 #define TSL2583_INTERRUPT_DISABLED	0x00
 
@@ -64,13 +64,13 @@
 #define TSL2583_CHIP_ID_MASK		0xf0
 
 /* Per-device data */
-struct taos_als_info {
+struct tsl2583_als_info {
 	u16 als_ch0;
 	u16 als_ch1;
 	u16 lux;
 };
 
-struct taos_settings {
+struct tsl2583_settings {
 	int als_time;
 	int als_gain;
 	int als_gain_trim;
@@ -80,14 +80,14 @@ struct taos_settings {
 struct tsl2583_chip {
 	struct mutex als_mutex;
 	struct i2c_client *client;
-	struct taos_als_info als_cur_info;
-	struct taos_settings taos_settings;
+	struct tsl2583_als_info als_cur_info;
+	struct tsl2583_settings als_settings;
 	int als_time_scale;
 	int als_saturation;
 	bool suspended;
 };
 
-struct taos_lux {
+struct tsl2583_lux {
 	unsigned int ratio;
 	unsigned int ch0;
 	unsigned int ch1;
@@ -96,7 +96,7 @@ struct taos_lux {
 /* 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  */
-static struct taos_lux taos_device_lux[11] = {
+static struct tsl2583_lux tsl2583_device_lux[11] = {
 	{  9830,  8520, 15729 },
 	{ 12452, 10807, 23344 },
 	{ 14746,  6383, 11705 },
@@ -121,25 +121,25 @@ static const struct gainadj gainadj[] = {
  * Provides initial operational parameter defaults.
  * These defaults may be changed through the device's sysfs files.
  */
-static void taos_defaults(struct tsl2583_chip *chip)
+static void tsl2583_defaults(struct tsl2583_chip *chip)
 {
 	/*
 	 * The integration time must be a multiple of 50ms and within the
 	 * range [50, 600] ms.
 	 */
-	chip->taos_settings.als_time = 100;
+	chip->als_settings.als_time = 100;
 
 	/*
 	 * This is an index into the gainadj table. Assume clear glass as the
 	 * default.
 	 */
-	chip->taos_settings.als_gain = 0;
+	chip->als_settings.als_gain = 0;
 
 	/* Default gain trim to account for aperture effects */
-	chip->taos_settings.als_gain_trim = 1000;
+	chip->als_settings.als_gain_trim = 1000;
 
 	/* Known external ALS reading used for calibration */
-	chip->taos_settings.als_cal_target = 130;
+	chip->als_settings.als_cal_target = 130;
 }
 
 /*
@@ -149,26 +149,26 @@ static void taos_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 taos_device_lux[]
+ * of ch1 value, to the ch0 value, is calculated. The array tsl2583_device_lux[]
  * declared above is then scanned to find the first ratio value that is just
  * above the ratio we just calculated. The ch0 and ch1 multiplier constants in
  * the array are then used along with the time scale factor array values, to
  * calculate the lux.
  */
-static int taos_get_lux(struct iio_dev *indio_dev)
+static int tsl2583_get_lux(struct iio_dev *indio_dev)
 {
 	u16 ch0, ch1; /* separated ch0/ch1 data from device */
 	u32 lux; /* raw lux calculated from device data */
 	u64 lux64;
 	u32 ratio;
 	u8 buf[5];
-	struct taos_lux *p;
+	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, TSL258X_CMD_REG);
+	ret = i2c_smbus_read_byte_data(chip->client, TSL2583_CMD_REG);
 	if (ret < 0) {
 		dev_err(&chip->client->dev, "%s: failed to read CMD_REG register\n",
 			__func__);
@@ -176,7 +176,7 @@ static int taos_get_lux(struct iio_dev *indio_dev)
 	}
 
 	/* is data new & valid */
-	if (!(ret & TSL258X_STA_ADC_INTR)) {
+	if (!(ret & TSL2583_STA_ADC_INTR)) {
 		dev_err(&chip->client->dev, "%s: data not valid; returning last value\n",
 			__func__);
 		ret = chip->als_cur_info.lux; /* return LAST VALUE */
@@ -184,7 +184,7 @@ static int taos_get_lux(struct iio_dev *indio_dev)
 	}
 
 	for (i = 0; i < 4; i++) {
-		int reg = TSL258X_CMD_REG | (TSL258X_ALS_CHAN0LO + i);
+		int reg = TSL2583_CMD_REG | (TSL2583_ALS_CHAN0LO + i);
 
 		ret = i2c_smbus_read_byte_data(chip->client, reg);
 		if (ret < 0) {
@@ -200,8 +200,8 @@ static int taos_get_lux(struct iio_dev *indio_dev)
 	 * we use the bit anyway - don't forget 0x80 - this is a command
 	 */
 	ret = i2c_smbus_write_byte(chip->client,
-				   (TSL258X_CMD_REG | TSL258X_CMD_SPL_FN |
-				    TSL258X_CMD_ALS_INT_CLR));
+				   (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",
@@ -228,7 +228,7 @@ static int taos_get_lux(struct iio_dev *indio_dev)
 	/* calculate ratio */
 	ratio = (ch1 << 15) / ch0;
 	/* convert to unscaled lux using the pointer to the table */
-	for (p = (struct taos_lux *)taos_device_lux;
+	for (p = (struct tsl2583_lux *)tsl2583_device_lux;
 	     p->ratio != 0 && p->ratio < ratio; p++)
 		;
 
@@ -236,11 +236,11 @@ static int taos_get_lux(struct iio_dev *indio_dev)
 		lux = 0;
 	} else {
 		ch0lux = ((ch0 * p->ch0) +
-			  (gainadj[chip->taos_settings.als_gain].ch0 >> 1))
-			 / gainadj[chip->taos_settings.als_gain].ch0;
+			  (gainadj[chip->als_settings.als_gain].ch0 >> 1))
+			 / gainadj[chip->als_settings.als_gain].ch0;
 		ch1lux = ((ch1 * p->ch1) +
-			  (gainadj[chip->taos_settings.als_gain].ch1 >> 1))
-			 / gainadj[chip->taos_settings.als_gain].ch1;
+			  (gainadj[chip->als_settings.als_gain].ch1 >> 1))
+			 / gainadj[chip->als_settings.als_gain].ch1;
 		lux = ch0lux - ch1lux;
 	}
 
@@ -261,7 +261,7 @@ static int taos_get_lux(struct iio_dev *indio_dev)
 			chip->als_time_scale;
 
 	/* Adjust for active gain scale.
-	 * The taos_device_lux tables above have a factor of 8192 built in,
+	 * 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.
 	 * Apply user-specified gain before shifting right to retain precision.
@@ -269,13 +269,13 @@ static int taos_get_lux(struct iio_dev *indio_dev)
 	 * Then go back to 32 bits before division to avoid using div_u64().
 	 */
 	lux64 = lux;
-	lux64 = lux64 * chip->taos_settings.als_gain_trim;
+	lux64 = lux64 * chip->als_settings.als_gain_trim;
 	lux64 >>= 13;
 	lux = lux64;
 	lux = (lux + 500) / 1000;
-	if (lux > TSL258X_LUX_CALC_OVER_FLOW) { /* check for overflow */
+	if (lux > TSL2583_LUX_CALC_OVER_FLOW) { /* check for overflow */
 return_max:
-		lux = TSL258X_LUX_CALC_OVER_FLOW;
+		lux = TSL2583_LUX_CALC_OVER_FLOW;
 	}
 
 	/* Update the structure with the latest VALID lux. */
@@ -291,7 +291,7 @@ static int taos_get_lux(struct iio_dev *indio_dev)
  * to derive actual lux).
  * Return updated gain_trim value.
  */
-static int taos_als_calibrate(struct iio_dev *indio_dev)
+static int tsl2583_als_calibrate(struct iio_dev *indio_dev)
 {
 	struct tsl2583_chip *chip = iio_priv(indio_dev);
 	unsigned int gain_trim_val;
@@ -299,7 +299,7 @@ static int taos_als_calibrate(struct iio_dev *indio_dev)
 	int lux_val;
 
 	ret = i2c_smbus_read_byte_data(chip->client,
-				       TSL258X_CMD_REG | TSL258X_CNTRL);
+				       TSL2583_CMD_REG | TSL2583_CNTRL);
 	if (ret < 0) {
 		dev_err(&chip->client->dev,
 			"%s: failed to read from the CNTRL register\n",
@@ -307,26 +307,26 @@ static int taos_als_calibrate(struct iio_dev *indio_dev)
 		return ret;
 	}
 
-	if ((ret & (TSL258X_CNTL_ADC_ENBL | TSL258X_CNTL_PWR_ON))
-			!= (TSL258X_CNTL_ADC_ENBL | TSL258X_CNTL_PWR_ON)) {
+	if ((ret & (TSL2583_CNTL_ADC_ENBL | TSL2583_CNTL_PWR_ON))
+			!= (TSL2583_CNTL_ADC_ENBL | TSL2583_CNTL_PWR_ON)) {
 		dev_err(&chip->client->dev,
 			"%s: Device is not powered on and/or ADC is not enabled\n",
 			__func__);
 		return -EINVAL;
-	} else if ((ret & TSL258X_STA_ADC_VALID) != TSL258X_STA_ADC_VALID) {
+	} else if ((ret & TSL2583_STA_ADC_VALID) != TSL2583_STA_ADC_VALID) {
 		dev_err(&chip->client->dev,
 			"%s: The two ADC channels have not completed an integration cycle\n",
 			__func__);
 		return -ENODATA;
 	}
-	lux_val = taos_get_lux(indio_dev);
+	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->taos_settings.als_cal_target)
-			* chip->taos_settings.als_gain_trim) / 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,
@@ -334,7 +334,7 @@ static int taos_als_calibrate(struct iio_dev *indio_dev)
 			__func__, gain_trim_val);
 		return -ENODATA;
 	}
-	chip->taos_settings.als_gain_trim = (int)gain_trim_val;
+	chip->als_settings.als_gain_trim = (int)gain_trim_val;
 
 	return (int)gain_trim_val;
 }
@@ -345,7 +345,7 @@ static int tsl2583_set_als_time(struct tsl2583_chip *chip)
 	u8 val;
 
 	/* determine als integration register */
-	als_count = (chip->taos_settings.als_time * 100 + 135) / 270;
+	als_count = (chip->als_settings.als_time * 100 + 135) / 270;
 	if (!als_count)
 		als_count = 1; /* ensure at least one cycle */
 
@@ -354,7 +354,7 @@ static int tsl2583_set_als_time(struct tsl2583_chip *chip)
 
 	val = 256 - als_count;
 	ret = i2c_smbus_write_byte_data(chip->client,
-					TSL258X_CMD_REG | TSL258X_ALS_TIME,
+					TSL2583_CMD_REG | TSL2583_ALS_TIME,
 					val);
 	if (ret < 0) {
 		dev_err(&chip->client->dev, "%s: failed to set the als time to %d\n",
@@ -373,14 +373,14 @@ static int tsl2583_set_als_gain(struct tsl2583_chip *chip)
 {
 	int ret;
 
-	/* Set the gain based on taos_settings struct */
+	/* Set the gain based on als_settings struct */
 	ret = i2c_smbus_write_byte_data(chip->client,
-					TSL258X_CMD_REG | TSL258X_GAIN,
-					chip->taos_settings.als_gain);
+					TSL2583_CMD_REG | TSL2583_GAIN,
+					chip->als_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);
+			chip->als_settings.als_gain);
 
 	return ret;
 }
@@ -390,7 +390,7 @@ static int tsl2583_set_power_state(struct tsl2583_chip *chip, u8 state)
 	int ret;
 
 	ret = i2c_smbus_write_byte_data(chip->client,
-					TSL258X_CMD_REG | TSL258X_CNTRL, state);
+					TSL2583_CMD_REG | TSL2583_CNTRL, state);
 	if (ret < 0)
 		dev_err(&chip->client->dev,
 			"%s: failed to set the power state to %d\n", __func__,
@@ -409,12 +409,12 @@ static int tsl2583_chip_init_and_power_on(struct iio_dev *indio_dev)
 	int ret;
 
 	/* Power on the device; ADC off. */
-	ret = tsl2583_set_power_state(chip, TSL258X_CNTL_PWR_ON);
+	ret = tsl2583_set_power_state(chip, TSL2583_CNTL_PWR_ON);
 	if (ret < 0)
 		return ret;
 
 	ret = i2c_smbus_write_byte_data(chip->client,
-					TSL258X_CMD_REG | TSL258X_INTERRUPT,
+					TSL2583_CMD_REG | TSL2583_INTERRUPT,
 					TSL2583_INTERRUPT_DISABLED);
 	if (ret < 0) {
 		dev_err(&chip->client->dev,
@@ -432,8 +432,8 @@ static int tsl2583_chip_init_and_power_on(struct iio_dev *indio_dev)
 
 	usleep_range(3000, 3500);
 
-	ret = tsl2583_set_power_state(chip, TSL258X_CNTL_PWR_ON |
-					    TSL258X_CNTL_ADC_ENBL);
+	ret = tsl2583_set_power_state(chip, TSL2583_CNTL_PWR_ON |
+					    TSL2583_CNTL_ADC_ENBL);
 	if (ret < 0)
 		return ret;
 
@@ -453,7 +453,7 @@ static ssize_t in_illuminance_input_target_show(struct device *dev,
 	int ret;
 
 	mutex_lock(&chip->als_mutex);
-	ret = sprintf(buf, "%d\n", chip->taos_settings.als_cal_target);
+	ret = sprintf(buf, "%d\n", chip->als_settings.als_cal_target);
 	mutex_unlock(&chip->als_mutex);
 
 	return ret;
@@ -471,7 +471,7 @@ static ssize_t in_illuminance_input_target_store(struct device *dev,
 		return -EINVAL;
 
 	mutex_lock(&chip->als_mutex);
-	chip->taos_settings.als_cal_target = value;
+	chip->als_settings.als_cal_target = value;
 	mutex_unlock(&chip->als_mutex);
 
 	return len;
@@ -495,7 +495,7 @@ static ssize_t in_illuminance_calibrate_store(struct device *dev,
 		goto done;
 	}
 
-	ret = taos_als_calibrate(indio_dev);
+	ret = tsl2583_als_calibrate(indio_dev);
 	if (ret < 0)
 		goto done;
 
@@ -513,12 +513,12 @@ static ssize_t in_illuminance_lux_table_show(struct device *dev,
 	int i;
 	int offset = 0;
 
-	for (i = 0; i < ARRAY_SIZE(taos_device_lux); i++) {
+	for (i = 0; i < ARRAY_SIZE(tsl2583_device_lux); i++) {
 		offset += sprintf(buf + offset, "%u,%u,%u,",
-				  taos_device_lux[i].ratio,
-				  taos_device_lux[i].ch0,
-				  taos_device_lux[i].ch1);
-		if (taos_device_lux[i].ratio == 0) {
+				  tsl2583_device_lux[i].ratio,
+				  tsl2583_device_lux[i].ch0,
+				  tsl2583_device_lux[i].ch1);
+		if (tsl2583_device_lux[i].ratio == 0) {
 			/*
 			 * We just printed the first "0" entry.
 			 * Now get rid of the extra "," and break.
@@ -532,7 +532,7 @@ 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)
+#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,
@@ -540,7 +540,7 @@ 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(taos_device_lux) * 3 + 1];
+	int value[ARRAY_SIZE(tsl2583_device_lux) * 3 + 1];
 	int n, ret = -EINVAL;
 
 	mutex_lock(&chip->als_mutex);
@@ -566,8 +566,8 @@ static ssize_t in_illuminance_lux_table_store(struct device *dev,
 	}
 
 	/* Zero out the table */
-	memset(taos_device_lux, 0, sizeof(taos_device_lux));
-	memcpy(taos_device_lux, &value[1], (value[0] * 4));
+	memset(tsl2583_device_lux, 0, sizeof(tsl2583_device_lux));
+	memcpy(tsl2583_device_lux, &value[1], (value[0] * 4));
 
 	ret = len;
 
@@ -636,7 +636,7 @@ static int tsl2583_read_raw(struct iio_dev *indio_dev,
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
 		if (chan->type == IIO_LIGHT) {
-			ret = taos_get_lux(indio_dev);
+			ret = tsl2583_get_lux(indio_dev);
 			if (ret < 0)
 				goto read_done;
 
@@ -659,7 +659,7 @@ static int tsl2583_read_raw(struct iio_dev *indio_dev,
 		break;
 	case IIO_CHAN_INFO_PROCESSED:
 		if (chan->type == IIO_LIGHT) {
-			ret = taos_get_lux(indio_dev);
+			ret = tsl2583_get_lux(indio_dev);
 			if (ret < 0)
 				goto read_done;
 
@@ -669,20 +669,20 @@ static int tsl2583_read_raw(struct iio_dev *indio_dev,
 		break;
 	case IIO_CHAN_INFO_CALIBBIAS:
 		if (chan->type == IIO_LIGHT) {
-			*val = chip->taos_settings.als_gain_trim;
+			*val = chip->als_settings.als_gain_trim;
 			ret = IIO_VAL_INT;
 		}
 		break;
 	case IIO_CHAN_INFO_CALIBSCALE:
 		if (chan->type == IIO_LIGHT) {
-			*val = gainadj[chip->taos_settings.als_gain].mean;
+			*val = gainadj[chip->als_settings.als_gain].mean;
 			ret = IIO_VAL_INT;
 		}
 		break;
 	case IIO_CHAN_INFO_INT_TIME:
 		if (chan->type == IIO_LIGHT) {
 			*val = 0;
-			*val2 = chip->taos_settings.als_time;
+			*val2 = chip->als_settings.als_time;
 			ret = IIO_VAL_INT_PLUS_MICRO;
 		}
 		break;
@@ -713,7 +713,7 @@ static int tsl2583_write_raw(struct iio_dev *indio_dev,
 	switch (mask) {
 	case IIO_CHAN_INFO_CALIBBIAS:
 		if (chan->type == IIO_LIGHT) {
-			chip->taos_settings.als_gain_trim = val;
+			chip->als_settings.als_gain_trim = val;
 			ret = 0;
 		}
 		break;
@@ -723,7 +723,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;
+					chip->als_settings.als_gain = i;
 					ret = tsl2583_set_als_gain(chip);
 					break;
 				}
@@ -733,7 +733,7 @@ static int tsl2583_write_raw(struct iio_dev *indio_dev,
 	case IIO_CHAN_INFO_INT_TIME:
 		if (chan->type == IIO_LIGHT && !val && val2 >= 50 &&
 		    val2 <= 650 && !(val2 % 50)) {
-			chip->taos_settings.als_time = val2;
+			chip->als_settings.als_time = val2;
 			ret = tsl2583_set_als_time(chip);
 		}
 		break;
@@ -758,8 +758,8 @@ static const struct iio_info tsl2583_info = {
  * Client probe function - When a valid device is found, the driver's device
  * data structure is updated, and initialization completes successfully.
  */
-static int taos_probe(struct i2c_client *clientp,
-		      const struct i2c_device_id *idp)
+static int tsl2583_probe(struct i2c_client *clientp,
+			 const struct i2c_device_id *idp)
 {
 	int ret;
 	struct tsl2583_chip *chip;
@@ -783,7 +783,7 @@ static int taos_probe(struct i2c_client *clientp,
 	chip->suspended = true;
 
 	ret = i2c_smbus_read_byte_data(clientp,
-				       TSL258X_CMD_REG | TSL258X_CHIPID);
+				       TSL2583_CMD_REG | TSL2583_CHIPID);
 	if (ret < 0) {
 		dev_err(&clientp->dev,
 			"%s: failed to read the chip ID register\n", __func__);
@@ -810,7 +810,7 @@ static int taos_probe(struct i2c_client *clientp,
 	}
 
 	/* Load up the V2 defaults (these are hard coded defaults for now) */
-	taos_defaults(chip);
+	tsl2583_defaults(chip);
 
 	/* Make sure the chip is on */
 	ret = tsl2583_chip_init_and_power_on(indio_dev);
@@ -821,7 +821,7 @@ static int taos_probe(struct i2c_client *clientp,
 	return 0;
 }
 
-static int __maybe_unused taos_suspend(struct device *dev)
+static int __maybe_unused tsl2583_suspend(struct device *dev)
 {
 	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
 	struct tsl2583_chip *chip = iio_priv(indio_dev);
@@ -829,14 +829,14 @@ static int __maybe_unused taos_suspend(struct device *dev)
 
 	mutex_lock(&chip->als_mutex);
 
-	ret = tsl2583_set_power_state(chip, TSL258X_CNTL_PWR_OFF);
+	ret = tsl2583_set_power_state(chip, TSL2583_CNTL_PWR_OFF);
 	chip->suspended = true;
 
 	mutex_unlock(&chip->als_mutex);
 	return ret;
 }
 
-static int __maybe_unused taos_resume(struct device *dev)
+static int __maybe_unused tsl2583_resume(struct device *dev)
 {
 	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
 	struct tsl2583_chip *chip = iio_priv(indio_dev);
@@ -850,35 +850,35 @@ static int __maybe_unused taos_resume(struct device *dev)
 	return ret;
 }
 
-static SIMPLE_DEV_PM_OPS(taos_pm_ops, taos_suspend, taos_resume);
+static SIMPLE_DEV_PM_OPS(tsl2583_pm_ops, tsl2583_suspend, tsl2583_resume);
 
-static struct i2c_device_id taos_idtable[] = {
+static struct i2c_device_id tsl2583_idtable[] = {
 	{ "tsl2580", 0 },
 	{ "tsl2581", 1 },
 	{ "tsl2583", 2 },
 	{}
 };
-MODULE_DEVICE_TABLE(i2c, taos_idtable);
+MODULE_DEVICE_TABLE(i2c, tsl2583_idtable);
 
-static const struct of_device_id taos2583_of_match[] = {
+static const struct of_device_id tsl2583_of_match[] = {
 	{ .compatible = "amstaos,tsl2580", },
 	{ .compatible = "amstaos,tsl2581", },
 	{ .compatible = "amstaos,tsl2583", },
 	{ },
 };
-MODULE_DEVICE_TABLE(of, taos2583_of_match);
+MODULE_DEVICE_TABLE(of, tsl2583_of_match);
 
 /* Driver definition */
-static struct i2c_driver taos_driver = {
+static struct i2c_driver tsl2583_driver = {
 	.driver = {
 		.name = "tsl2583",
-		.pm = &taos_pm_ops,
-		.of_match_table = taos2583_of_match,
+		.pm = &tsl2583_pm_ops,
+		.of_match_table = tsl2583_of_match,
 	},
-	.id_table = taos_idtable,
-	.probe = taos_probe,
+	.id_table = tsl2583_idtable,
+	.probe = tsl2583_probe,
 };
-module_i2c_driver(taos_driver);
+module_i2c_driver(tsl2583_driver);
 
 MODULE_AUTHOR("J. August Brenner<jbrenner@taosinc.com>");
 MODULE_DESCRIPTION("TAOS tsl2583 ambient light sensor driver");
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v4 09/26] staging: iio: tsl2583: fix alignment of #define values
  2016-11-12 18:19 [PATCH v4 00/26] staging: iio: tsl2583: move out of staging Brian Masney
                   ` (7 preceding siblings ...)
  2016-11-12 18:19 ` [PATCH v4 08/26] staging: iio: tsl2583: unify function and variable prefix to tsl2583_ Brian Masney
@ 2016-11-12 18:19 ` Brian Masney
  2016-11-13 12:13   ` Jonathan Cameron
  2016-11-12 18:19 ` [PATCH v4 10/26] staging: iio: tsl2583: fix comparison between signed and unsigned integers Brian Masney
                   ` (16 subsequent siblings)
  25 siblings, 1 reply; 54+ messages in thread
From: Brian Masney @ 2016-11-12 18:19 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

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 5a82a26..d482a84 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

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v4 10/26] staging: iio: tsl2583: fix comparison between signed and unsigned integers
  2016-11-12 18:19 [PATCH v4 00/26] staging: iio: tsl2583: move out of staging Brian Masney
                   ` (8 preceding siblings ...)
  2016-11-12 18:19 ` [PATCH v4 09/26] staging: iio: tsl2583: fix alignment of #define values Brian Masney
@ 2016-11-12 18:19 ` Brian Masney
  2016-11-13 12:14   ` Jonathan Cameron
  2016-11-12 18:19 ` [PATCH v4 11/26] staging: iio: tsl2583: change newlines to improve readability Brian Masney
                   ` (15 subsequent siblings)
  25 siblings, 1 reply; 54+ messages in thread
From: Brian Masney @ 2016-11-12 18:19 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

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 d482a84..be3cbae 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -510,7 +510,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++) {
@@ -541,7 +541,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);
 
@@ -719,7 +720,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

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v4 11/26] staging: iio: tsl2583: change newlines to improve readability
  2016-11-12 18:19 [PATCH v4 00/26] staging: iio: tsl2583: move out of staging Brian Masney
                   ` (9 preceding siblings ...)
  2016-11-12 18:19 ` [PATCH v4 10/26] staging: iio: tsl2583: fix comparison between signed and unsigned integers Brian Masney
@ 2016-11-12 18:19 ` Brian Masney
  2016-11-13 12:15   ` Jonathan Cameron
  2016-11-12 18:19 ` [PATCH v4 12/26] staging: iio: tsl2583: combine sysfs documentation Brian Masney
                   ` (14 subsequent siblings)
  25 siblings, 1 reply; 54+ messages in thread
From: Brian Masney @ 2016-11-12 18:19 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

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 | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
index be3cbae..8303753 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;
@@ -319,21 +321,23 @@ static int tsl2583_als_calibrate(struct iio_dev *indio_dev)
 			__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: 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;
@@ -529,6 +533,7 @@ static ssize_t in_illuminance_lux_table_show(struct device *dev,
 	}
 
 	offset += sprintf(buf + offset, "\n");
+
 	return offset;
 }
 
@@ -776,6 +781,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);
@@ -803,6 +809,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",
@@ -819,6 +826,7 @@ static int tsl2583_probe(struct i2c_client *clientp,
 		return ret;
 
 	dev_info(&clientp->dev, "Light sensor found.\n");
+
 	return 0;
 }
 
@@ -834,6 +842,7 @@ static int __maybe_unused tsl2583_suspend(struct device *dev)
 	chip->suspended = true;
 
 	mutex_unlock(&chip->als_mutex);
+
 	return ret;
 }
 
@@ -848,6 +857,7 @@ static int __maybe_unused tsl2583_resume(struct device *dev)
 	ret = tsl2583_chip_init_and_power_on(indio_dev);
 
 	mutex_unlock(&chip->als_mutex);
+
 	return ret;
 }
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v4 12/26] staging: iio: tsl2583: combine sysfs documentation
  2016-11-12 18:19 [PATCH v4 00/26] staging: iio: tsl2583: move out of staging Brian Masney
                   ` (10 preceding siblings ...)
  2016-11-12 18:19 ` [PATCH v4 11/26] staging: iio: tsl2583: change newlines to improve readability Brian Masney
@ 2016-11-12 18:19 ` Brian Masney
  2016-11-13 12:16   ` Jonathan Cameron
  2016-11-12 18:19 ` [PATCH v4 13/26] staging: iio: tsl2583: fix multiline comment syntax Brian Masney
                   ` (13 subsequent siblings)
  25 siblings, 1 reply; 54+ messages in thread
From: Brian Masney @ 2016-11-12 18:19 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

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

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v4 13/26] staging: iio: tsl2583: fix multiline comment syntax
  2016-11-12 18:19 [PATCH v4 00/26] staging: iio: tsl2583: move out of staging Brian Masney
                   ` (11 preceding siblings ...)
  2016-11-12 18:19 ` [PATCH v4 12/26] staging: iio: tsl2583: combine sysfs documentation Brian Masney
@ 2016-11-12 18:19 ` Brian Masney
  2016-11-13 12:17   ` Jonathan Cameron
  2016-11-12 18:19 ` [PATCH v4 14/26] staging: iio: tsl2583: updated code comment to match what the code does Brian Masney
                   ` (12 subsequent siblings)
  25 siblings, 1 reply; 54+ messages in thread
From: Brian Masney @ 2016-11-12 18:19 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

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 8303753..52a39a6 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.
@@ -553,7 +556,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

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v4 14/26] staging: iio: tsl2583: updated code comment to match what the code does
  2016-11-12 18:19 [PATCH v4 00/26] staging: iio: tsl2583: move out of staging Brian Masney
                   ` (12 preceding siblings ...)
  2016-11-12 18:19 ` [PATCH v4 13/26] staging: iio: tsl2583: fix multiline comment syntax Brian Masney
@ 2016-11-12 18:19 ` Brian Masney
  2016-11-13 12:18   ` Jonathan Cameron
  2016-11-12 18:19 ` [PATCH v4 15/26] staging: iio: tsl2583: moved code block inside else statement Brian Masney
                   ` (11 subsequent siblings)
  25 siblings, 1 reply; 54+ messages in thread
From: Brian Masney @ 2016-11-12 18:19 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

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. It also
clarifies the comment about why 0 is returned.

Signed-off-by: Brian Masney <masneyb@onstation.org>
---
 drivers/staging/iio/light/tsl2583.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
index 52a39a6..dbb7f6a 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -221,7 +221,11 @@ static int tsl2583_get_lux(struct iio_dev *indio_dev)
 		goto return_max;
 
 	if (!ch0) {
-		/* have no data, so return LAST VALUE */
+		/*
+		 * The sensor appears to be in total darkness so set the
+		 * calculated lux to 0 and return early to avoid a division by
+		 * zero below when calculating the ratio.
+		 */
 		ret = 0;
 		chip->als_cur_info.lux = 0;
 		goto done;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v4 15/26] staging: iio: tsl2583: moved code block inside else statement
  2016-11-12 18:19 [PATCH v4 00/26] staging: iio: tsl2583: move out of staging Brian Masney
                   ` (13 preceding siblings ...)
  2016-11-12 18:19 ` [PATCH v4 14/26] staging: iio: tsl2583: updated code comment to match what the code does Brian Masney
@ 2016-11-12 18:19 ` Brian Masney
  2016-11-13 12:20   ` Jonathan Cameron
  2016-11-12 18:19 ` [PATCH v4 16/26] staging: iio: tsl2583: change tsl2583_als_calibrate() to return 0 on success Brian Masney
                   ` (10 subsequent siblings)
  25 siblings, 1 reply; 54+ messages in thread
From: Brian Masney @ 2016-11-12 18:19 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

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 dbb7f6a..bcdf095 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) {
@@ -242,22 +240,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

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v4 16/26] staging: iio: tsl2583: change tsl2583_als_calibrate() to return 0 on success
  2016-11-12 18:19 [PATCH v4 00/26] staging: iio: tsl2583: move out of staging Brian Masney
                   ` (14 preceding siblings ...)
  2016-11-12 18:19 ` [PATCH v4 15/26] staging: iio: tsl2583: moved code block inside else statement Brian Masney
@ 2016-11-12 18:19 ` Brian Masney
  2016-11-13 12:21   ` Jonathan Cameron
  2016-11-12 18:19 ` [PATCH v4 17/26] staging: iio: tsl2583: remove unnecessary parentheses Brian Masney
                   ` (9 subsequent siblings)
  25 siblings, 1 reply; 54+ messages in thread
From: Brian Masney @ 2016-11-12 18:19 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

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 bcdf095..fc58074 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -348,7 +348,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

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v4 17/26] staging: iio: tsl2583: remove unnecessary parentheses
  2016-11-12 18:19 [PATCH v4 00/26] staging: iio: tsl2583: move out of staging Brian Masney
                   ` (15 preceding siblings ...)
  2016-11-12 18:19 ` [PATCH v4 16/26] staging: iio: tsl2583: change tsl2583_als_calibrate() to return 0 on success Brian Masney
@ 2016-11-12 18:19 ` Brian Masney
  2016-11-13 12:22   ` Jonathan Cameron
  2016-11-12 18:19 ` [PATCH v4 18/26] staging: iio: tsl2583: don't assume an unsigned int is 32 bits Brian Masney
                   ` (8 subsequent siblings)
  25 siblings, 1 reply; 54+ messages in thread
From: Brian Masney @ 2016-11-12 18:19 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

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 fc58074..fe9d777 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,
 			__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;
@@ -582,7 +582,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

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v4 18/26] staging: iio: tsl2583: don't assume an unsigned int is 32 bits
  2016-11-12 18:19 [PATCH v4 00/26] staging: iio: tsl2583: move out of staging Brian Masney
                   ` (16 preceding siblings ...)
  2016-11-12 18:19 ` [PATCH v4 17/26] staging: iio: tsl2583: remove unnecessary parentheses Brian Masney
@ 2016-11-12 18:19 ` Brian Masney
  2016-11-13 12:23   ` Jonathan Cameron
  2016-11-12 18:19 ` [PATCH v4 19/26] staging: iio: tsl2583: move from a global to a per device lux table Brian Masney
                   ` (7 subsequent siblings)
  25 siblings, 1 reply; 54+ messages in thread
From: Brian Masney @ 2016-11-12 18:19 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

in_illuminance_lux_table_store assumes that an unsigned int is 32 bits.
Replace this with sizeof(value[1]).

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 fe9d777..78967dc 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -582,7 +582,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(value[1]));
 
 	ret = len;
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v4 19/26] staging: iio: tsl2583: move from a global to a per device lux table
  2016-11-12 18:19 [PATCH v4 00/26] staging: iio: tsl2583: move out of staging Brian Masney
                   ` (17 preceding siblings ...)
  2016-11-12 18:19 ` [PATCH v4 18/26] staging: iio: tsl2583: don't assume an unsigned int is 32 bits Brian Masney
@ 2016-11-12 18:19 ` Brian Masney
  2016-11-13 12:25   ` Jonathan Cameron
  2016-11-12 18:19 ` [PATCH v4 20/26] staging: iio: tsl2583: add tsl2583 to list of supported devices in the header Brian Masney
                   ` (6 subsequent siblings)
  25 siblings, 1 reply; 54+ messages in thread
From: Brian Masney @ 2016-11-12 18:19 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

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>
---
 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 78967dc..3818ffa 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
@@ -233,7 +242,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++)
 		;
 
@@ -270,7 +279,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.
@@ -522,15 +531,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.
@@ -545,15 +556,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;
 
@@ -568,10 +578,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) {
@@ -581,8 +591,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(value[1]));
+	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(value[1]));
 
 	ret = len;
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v4 20/26] staging: iio: tsl2583: add tsl2583 to list of supported devices in the header
  2016-11-12 18:19 [PATCH v4 00/26] staging: iio: tsl2583: move out of staging Brian Masney
                   ` (18 preceding siblings ...)
  2016-11-12 18:19 ` [PATCH v4 19/26] staging: iio: tsl2583: move from a global to a per device lux table Brian Masney
@ 2016-11-12 18:19 ` Brian Masney
  2016-11-13 12:28   ` Jonathan Cameron
  2016-11-12 18:19 ` [PATCH v4 21/26] staging: iio: tsl2583: clarified comment about clearing interrupts Brian Masney
                   ` (5 subsequent siblings)
  25 siblings, 1 reply; 54+ messages in thread
From: Brian Masney @ 2016-11-12 18:19 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

The header only listed the tsl2580 and tsl2581 devices as supported by
this driver. This patch adds the tsl2583 since it is also supported by
this driver.

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 3818ffa..806cb0a 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -1,6 +1,6 @@
 /*
  * Device driver for monitoring ambient light intensity (lux)
- * within the TAOS tsl258x family of devices (tsl2580, tsl2581).
+ * within the TAOS tsl258x family of devices (tsl2580, tsl2581, tsl2583).
  *
  * Copyright (c) 2011, TAOS Corporation.
  *
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v4 21/26] staging: iio: tsl2583: clarified comment about clearing interrupts
  2016-11-12 18:19 [PATCH v4 00/26] staging: iio: tsl2583: move out of staging Brian Masney
                   ` (19 preceding siblings ...)
  2016-11-12 18:19 ` [PATCH v4 20/26] staging: iio: tsl2583: add tsl2583 to list of supported devices in the header Brian Masney
@ 2016-11-12 18:19 ` Brian Masney
  2016-11-13 12:28   ` Jonathan Cameron
  2016-11-12 18:19 ` [PATCH v4 22/26] staging: iio: tsl2583: remove comment for tsl2583_probe() Brian Masney
                   ` (4 subsequent siblings)
  25 siblings, 1 reply; 54+ messages in thread
From: Brian Masney @ 2016-11-12 18:19 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

The comment that describes the code that clears the interrupt bit was
vague and didn't provide much value. This patch adds more detail about
why that bit needs to be cleared.

Signed-off-by: Brian Masney <masneyb@onstation.org>
---
 drivers/staging/iio/light/tsl2583.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
index 806cb0a..727ed49 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -205,8 +205,9 @@ static int tsl2583_get_lux(struct iio_dev *indio_dev)
 	}
 
 	/*
-	 * clear status, really interrupt status (interrupts are off), but
-	 * we use the bit anyway - don't forget 0x80 - this is a command
+	 * Clear the pending interrupt status bit on the chip to allow the next
+	 * integration cycle to start. This has to be done even though this
+	 * driver currently does not support interrupts.
 	 */
 	ret = i2c_smbus_write_byte(chip->client,
 				   (TSL2583_CMD_REG | TSL2583_CMD_SPL_FN |
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v4 22/26] staging: iio: tsl2583: remove comment for tsl2583_probe()
  2016-11-12 18:19 [PATCH v4 00/26] staging: iio: tsl2583: move out of staging Brian Masney
                   ` (20 preceding siblings ...)
  2016-11-12 18:19 ` [PATCH v4 21/26] staging: iio: tsl2583: clarified comment about clearing interrupts Brian Masney
@ 2016-11-12 18:19 ` Brian Masney
  2016-11-13 12:29   ` Jonathan Cameron
  2016-11-12 18:19 ` [PATCH v4 23/26] staging: iio: tsl2583: remove unnecessary memset call Brian Masney
                   ` (3 subsequent siblings)
  25 siblings, 1 reply; 54+ messages in thread
From: Brian Masney @ 2016-11-12 18:19 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

The comment for tsl2583_probe() does not provide any useful value.
This patch removes the comment.

Signed-off-by: Brian Masney <masneyb@onstation.org>
---
 drivers/staging/iio/light/tsl2583.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
index 727ed49..9db191f 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -782,10 +782,6 @@ static const struct iio_info tsl2583_info = {
 	.write_raw = tsl2583_write_raw,
 };
 
-/*
- * Client probe function - When a valid device is found, the driver's device
- * data structure is updated, and initialization completes successfully.
- */
 static int tsl2583_probe(struct i2c_client *clientp,
 			 const struct i2c_device_id *idp)
 {
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v4 23/26] staging: iio: tsl2583: remove unnecessary memset call
  2016-11-12 18:19 [PATCH v4 00/26] staging: iio: tsl2583: move out of staging Brian Masney
                   ` (21 preceding siblings ...)
  2016-11-12 18:19 ` [PATCH v4 22/26] staging: iio: tsl2583: remove comment for tsl2583_probe() Brian Masney
@ 2016-11-12 18:19 ` Brian Masney
  2016-11-13 12:29   ` Jonathan Cameron
  2016-11-12 18:19 ` [PATCH v4 24/26] staging: iio: tsl2583: remove unnecessary variable initialization Brian Masney
                   ` (2 subsequent siblings)
  25 siblings, 1 reply; 54+ messages in thread
From: Brian Masney @ 2016-11-12 18:19 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

The entries in the lux table (als_device_lux) can be updated via sysfs
through the function in_illuminance_lux_table_store(). The last row in
the table must be terminated with values that are zero. The sysfs code
already ensures that the last row is all zeros. The call to memset to
clear out the table is not needed so this patch removes the unnecessary
call.

Signed-off-by: Brian Masney <masneyb@onstation.org>
---
 drivers/staging/iio/light/tsl2583.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
index 9db191f..712f753 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -591,9 +591,6 @@ static ssize_t in_illuminance_lux_table_store(struct device *dev,
 		goto done;
 	}
 
-	/* Zero out the table */
-	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(value[1]));
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v4 24/26] staging: iio: tsl2583: remove unnecessary variable initialization
  2016-11-12 18:19 [PATCH v4 00/26] staging: iio: tsl2583: move out of staging Brian Masney
                   ` (22 preceding siblings ...)
  2016-11-12 18:19 ` [PATCH v4 23/26] staging: iio: tsl2583: remove unnecessary memset call Brian Masney
@ 2016-11-12 18:19 ` Brian Masney
  2016-11-13 12:30   ` Jonathan Cameron
  2016-11-12 18:19 ` [PATCH v4 25/26] staging: iio: tsl2583: add copyright and MODULE_AUTHOR Brian Masney
  2016-11-12 18:19 ` [PATCH v4 26/26] staging: iio: tsl2583: move out of staging Brian Masney
  25 siblings, 1 reply; 54+ messages in thread
From: Brian Masney @ 2016-11-12 18:19 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

The ret variable in tsl2583_suspend() and tsl2583_resume() was
initialized to 0. This is not necessary so this patch removes the
initialization.

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 712f753..b787952 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -849,7 +849,7 @@ static int __maybe_unused tsl2583_suspend(struct device *dev)
 {
 	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
 	struct tsl2583_chip *chip = iio_priv(indio_dev);
-	int ret = 0;
+	int ret;
 
 	mutex_lock(&chip->als_mutex);
 
@@ -865,7 +865,7 @@ static int __maybe_unused tsl2583_resume(struct device *dev)
 {
 	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
 	struct tsl2583_chip *chip = iio_priv(indio_dev);
-	int ret = 0;
+	int ret;
 
 	mutex_lock(&chip->als_mutex);
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v4 25/26] staging: iio: tsl2583: add copyright and MODULE_AUTHOR
  2016-11-12 18:19 [PATCH v4 00/26] staging: iio: tsl2583: move out of staging Brian Masney
                   ` (23 preceding siblings ...)
  2016-11-12 18:19 ` [PATCH v4 24/26] staging: iio: tsl2583: remove unnecessary variable initialization Brian Masney
@ 2016-11-12 18:19 ` Brian Masney
  2016-11-13 12:35   ` Jonathan Cameron
  2016-11-12 18:19 ` [PATCH v4 26/26] staging: iio: tsl2583: move out of staging Brian Masney
  25 siblings, 1 reply; 54+ messages in thread
From: Brian Masney @ 2016-11-12 18:19 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

Add 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.

The original MODULE_AUTHOR() did not have a space between his name and
email address. This patch also adds the missing space.

Signed-off-by: Brian Masney <masneyb@onstation.org>
---
 drivers/staging/iio/light/tsl2583.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
index b787952..ca26444 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, tsl2583).
  *
  * 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
@@ -906,6 +907,7 @@ 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>");
+MODULE_AUTHOR("Brian Masney <masneyb@onstation.org>");
 MODULE_DESCRIPTION("TAOS tsl2583 ambient light sensor driver");
 MODULE_LICENSE("GPL");
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v4 26/26] staging: iio: tsl2583: move out of staging
  2016-11-12 18:19 [PATCH v4 00/26] staging: iio: tsl2583: move out of staging Brian Masney
                   ` (24 preceding siblings ...)
  2016-11-12 18:19 ` [PATCH v4 25/26] staging: iio: tsl2583: add copyright and MODULE_AUTHOR Brian Masney
@ 2016-11-12 18:19 ` Brian Masney
  2016-11-13 12:57   ` Jonathan Cameron
  25 siblings, 1 reply; 54+ messages in thread
From: Brian Masney @ 2016-11-12 18:19 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

Move tsl2580, tsl2581, tsl2583 driver out of staging into mainline.

Signed-off-by: Brian Masney <masneyb@onstation.org>
---
 .../ABI/testing/sysfs-bus-iio-light-tsl2583        |  20 +
 drivers/iio/light/Kconfig                          |   7 +
 drivers/iio/light/Makefile                         |   1 +
 drivers/iio/light/tsl2583.c                        | 913 +++++++++++++++++++++
 .../light/sysfs-bus-iio-light-tsl2583              |  20 -
 drivers/staging/iio/light/Kconfig                  |   7 -
 drivers/staging/iio/light/Makefile                 |   1 -
 drivers/staging/iio/light/tsl2583.c                | 913 ---------------------
 8 files changed, 941 insertions(+), 941 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/light/tsl2583.c

diff --git a/Documentation/ABI/testing/sysfs-bus-iio-light-tsl2583 b/Documentation/ABI/testing/sysfs-bus-iio-light-tsl2583
new file mode 100644
index 0000000..a2e1996
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-bus-iio-light-tsl2583
@@ -0,0 +1,20 @@
+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/iio/light/Kconfig b/drivers/iio/light/Kconfig
index d011720..298ea50 100644
--- a/drivers/iio/light/Kconfig
+++ b/drivers/iio/light/Kconfig
@@ -338,6 +338,13 @@ config SENSORS_TSL2563
 	 This driver can also be built as a module.  If so, the module
 	 will be called tsl2563.
 
+config TSL2583
+	tristate "TAOS TSL2580, TSL2581 and TSL2583 light-to-digital converters"
+	depends on I2C
+	help
+	 Provides support for the TAOS tsl2580, tsl2581 and tsl2583 devices.
+	 Access ALS data via iio, 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 15f24c5..4de5200 100644
--- a/drivers/iio/light/Makefile
+++ b/drivers/iio/light/Makefile
@@ -31,6 +31,7 @@ obj-$(CONFIG_SI1145)		+= si1145.o
 obj-$(CONFIG_STK3310)          += stk3310.o
 obj-$(CONFIG_TCS3414)		+= tcs3414.o
 obj-$(CONFIG_TCS3472)		+= tcs3472.o
+obj-$(CONFIG_TSL2583)		+= tsl2583.o
 obj-$(CONFIG_TSL4531)		+= tsl4531.o
 obj-$(CONFIG_US5182D)		+= us5182d.o
 obj-$(CONFIG_VCNL4000)		+= vcnl4000.o
diff --git a/drivers/iio/light/tsl2583.c b/drivers/iio/light/tsl2583.c
new file mode 100644
index 0000000..ca26444
--- /dev/null
+++ b/drivers/iio/light/tsl2583.c
@@ -0,0 +1,913 @@
+/*
+ * Device driver for monitoring ambient light intensity (lux)
+ * within the TAOS tsl258x family of devices (tsl2580, tsl2581, tsl2583).
+ *
+ * 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
+ * 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 <linux/kernel.h>
+#include <linux/i2c.h>
+#include <linux/errno.h>
+#include <linux/delay.h>
+#include <linux/string.h>
+#include <linux/mutex.h>
+#include <linux/unistd.h>
+#include <linux/slab.h>
+#include <linux/module.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/sysfs.h>
+
+/* Device Registers and Masks */
+#define TSL2583_CNTRL			0x00
+#define TSL2583_ALS_TIME		0X01
+#define TSL2583_INTERRUPT		0x02
+#define TSL2583_GAIN			0x07
+#define TSL2583_REVID			0x11
+#define TSL2583_CHIPID			0x12
+#define TSL2583_ALS_CHAN0LO		0x14
+#define TSL2583_ALS_CHAN0HI		0x15
+#define TSL2583_ALS_CHAN1LO		0x16
+#define TSL2583_ALS_CHAN1HI		0x17
+#define TSL2583_TMR_LO			0x18
+#define TSL2583_TMR_HI			0x19
+
+/* tsl2583 cmd reg masks */
+#define TSL2583_CMD_REG			0x80
+#define TSL2583_CMD_SPL_FN		0x60
+#define TSL2583_CMD_ALS_INT_CLR		0x01
+
+/* tsl2583 cntrl reg masks */
+#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
+
+/* Lux calculation constants */
+#define	TSL2583_LUX_CALC_OVER_FLOW	65535
+
+#define TSL2583_INTERRUPT_DISABLED	0x00
+
+#define TSL2583_CHIP_ID			0x90
+#define TSL2583_CHIP_ID_MASK		0xf0
+
+/* Per-device data */
+struct tsl2583_als_info {
+	u16 als_ch0;
+	u16 als_ch1;
+	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 {
+	struct mutex als_mutex;
+	struct i2c_client *client;
+	struct tsl2583_als_info als_cur_info;
+	struct tsl2583_settings als_settings;
+	int als_time_scale;
+	int als_saturation;
+	bool suspended;
+};
+
+struct gainadj {
+	s16 ch0;
+	s16 ch1;
+	s16 mean;
+};
+
+/* Index = (0 - 3) Used to validate the gain selection index */
+static const struct gainadj gainadj[] = {
+	{ 1, 1, 1 },
+	{ 8, 8, 8 },
+	{ 16, 16, 16 },
+	{ 107, 115, 111 }
+};
+
+/*
+ * Provides initial operational parameter defaults.
+ * These defaults may be changed through the device's sysfs files.
+ */
+static void tsl2583_defaults(struct tsl2583_chip *chip)
+{
+	/*
+	 * The integration time must be a multiple of 50ms and within the
+	 * range [50, 600] ms.
+	 */
+	chip->als_settings.als_time = 100;
+
+	/*
+	 * This is an index into the gainadj table. Assume clear glass as the
+	 * default.
+	 */
+	chip->als_settings.als_gain = 0;
+
+	/* Default gain trim to account for aperture effects */
+	chip->als_settings.als_gain_trim = 1000;
+
+	/* 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));
+}
+
+/*
+ * Reads and calculates current lux value.
+ * The raw ch0 and ch1 values of the ambient light sensed in the last
+ * integration cycle are read from the device.
+ * Time scale factor array values are adjusted based on the integration time.
+ * The raw values are multiplied by a scale factor, and device gain is obtained
+ * using gain index. Limit checks are done next, then the ratio of a multiple
+ * of ch1 value, to the ch0 value, is calculated. The array 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
+ * calculate the lux.
+ */
+static int tsl2583_get_lux(struct iio_dev *indio_dev)
+{
+	u16 ch0, ch1; /* separated ch0/ch1 data from device */
+	u32 lux; /* raw lux calculated from device data */
+	u64 lux64;
+	u32 ratio;
+	u8 buf[5];
+	struct tsl2583_lux *p;
+	struct tsl2583_chip *chip = iio_priv(indio_dev);
+	int i, ret;
+
+	ret = i2c_smbus_read_byte_data(chip->client, TSL2583_CMD_REG);
+	if (ret < 0) {
+		dev_err(&chip->client->dev, "%s: failed to read CMD_REG register\n",
+			__func__);
+		goto done;
+	}
+
+	/* is data new & valid */
+	if (!(ret & TSL2583_STA_ADC_INTR)) {
+		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;
+	}
+
+	for (i = 0; i < 4; i++) {
+		int reg = TSL2583_CMD_REG | (TSL2583_ALS_CHAN0LO + i);
+
+		ret = i2c_smbus_read_byte_data(chip->client, reg);
+		if (ret < 0) {
+			dev_err(&chip->client->dev, "%s: failed to read register %x\n",
+				__func__, reg);
+			goto done;
+		}
+		buf[i] = ret;
+	}
+
+	/*
+	 * Clear the pending interrupt status bit on the chip to allow the next
+	 * integration cycle to start. This has to be done even though this
+	 * driver currently does not support interrupts.
+	 */
+	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__);
+		goto done; /* have no data, so return failure */
+	}
+
+	/* extract ALS/lux data */
+	ch0 = le16_to_cpup((const __le16 *)&buf[0]);
+	ch1 = le16_to_cpup((const __le16 *)&buf[2]);
+
+	chip->als_cur_info.als_ch0 = ch0;
+	chip->als_cur_info.als_ch1 = ch1;
+
+	if ((ch0 >= chip->als_saturation) || (ch1 >= chip->als_saturation))
+		goto return_max;
+
+	if (!ch0) {
+		/*
+		 * The sensor appears to be in total darkness so set the
+		 * calculated lux to 0 and return early to avoid a division by
+		 * zero below when calculating the ratio.
+		 */
+		ret = 0;
+		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 *)chip->als_settings.als_device_lux;
+	     p->ratio != 0 && p->ratio < ratio; p++)
+		;
+
+	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;
+
+		/* 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 */
+	if (chip->als_time_scale == 0)
+		lux = 0;
+	else
+		lux = (lux + (chip->als_time_scale >> 1)) /
+			chip->als_time_scale;
+
+	/*
+	 * Adjust for active gain scale.
+	 * 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.
+	 * Use 64 bits to avoid overflow on multiplication.
+	 * Then go back to 32 bits before division to avoid using div_u64().
+	 */
+	lux64 = lux;
+	lux64 = lux64 * chip->als_settings.als_gain_trim;
+	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;
+	}
+
+	/* Update the structure with the latest VALID lux. */
+	chip->als_cur_info.lux = lux;
+	ret = lux;
+
+done:
+	return ret;
+}
+
+/*
+ * Obtain single reading and calculate the als_gain_trim (later used
+ * to derive actual lux).
+ * Return updated gain_trim value.
+ */
+static int tsl2583_als_calibrate(struct iio_dev *indio_dev)
+{
+	struct tsl2583_chip *chip = iio_priv(indio_dev);
+	unsigned int gain_trim_val;
+	int ret;
+	int lux_val;
+
+	ret = i2c_smbus_read_byte_data(chip->client,
+				       TSL2583_CMD_REG | TSL2583_CNTRL);
+	if (ret < 0) {
+		dev_err(&chip->client->dev,
+			"%s: failed to read from the CNTRL register\n",
+			__func__);
+		return ret;
+	}
+
+	if ((ret & (TSL2583_CNTL_ADC_ENBL | TSL2583_CNTL_PWR_ON))
+			!= (TSL2583_CNTL_ADC_ENBL | TSL2583_CNTL_PWR_ON)) {
+		dev_err(&chip->client->dev,
+			"%s: Device is not powered on and/or ADC is not enabled\n",
+			__func__);
+		return -EINVAL;
+	} else if ((ret & TSL2583_STA_ADC_VALID) != TSL2583_STA_ADC_VALID) {
+		dev_err(&chip->client->dev,
+			"%s: The two ADC channels have not completed an integration cycle\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: 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 0;
+}
+
+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->als_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,
+					TSL2583_CMD_REG | TSL2583_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 als_settings struct */
+	ret = i2c_smbus_write_byte_data(chip->client,
+					TSL2583_CMD_REG | TSL2583_GAIN,
+					chip->als_settings.als_gain);
+	if (ret < 0)
+		dev_err(&chip->client->dev,
+			"%s: failed to set the gain to %d\n", __func__,
+			chip->als_settings.als_gain);
+
+	return ret;
+}
+
+static int tsl2583_set_power_state(struct tsl2583_chip *chip, u8 state)
+{
+	int ret;
+
+	ret = i2c_smbus_write_byte_data(chip->client,
+					TSL2583_CMD_REG | TSL2583_CNTRL, state);
+	if (ret < 0)
+		dev_err(&chip->client->dev,
+			"%s: failed to set the power state to %d\n", __func__,
+			state);
+
+	return ret;
+}
+
+/*
+ * Turn the device on.
+ * Configuration must be set before calling this function.
+ */
+static int tsl2583_chip_init_and_power_on(struct iio_dev *indio_dev)
+{
+	struct tsl2583_chip *chip = iio_priv(indio_dev);
+	int ret;
+
+	/* Power on the device; ADC off. */
+	ret = tsl2583_set_power_state(chip, TSL2583_CNTL_PWR_ON);
+	if (ret < 0)
+		return ret;
+
+	ret = i2c_smbus_write_byte_data(chip->client,
+					TSL2583_CMD_REG | TSL2583_INTERRUPT,
+					TSL2583_INTERRUPT_DISABLED);
+	if (ret < 0) {
+		dev_err(&chip->client->dev,
+			"%s: failed to disable interrupts\n", __func__);
+		return ret;
+	}
+
+	ret = tsl2583_set_als_time(chip);
+	if (ret < 0)
+		return ret;
+
+	ret = tsl2583_set_als_gain(chip);
+	if (ret < 0)
+		return ret;
+
+	usleep_range(3000, 3500);
+
+	ret = tsl2583_set_power_state(chip, TSL2583_CNTL_PWR_ON |
+					    TSL2583_CNTL_ADC_ENBL);
+	if (ret < 0)
+		return ret;
+
+	chip->suspended = false;
+
+	return ret;
+}
+
+/* Sysfs Interface Functions */
+
+static ssize_t in_illuminance_input_target_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);
+	int ret;
+
+	mutex_lock(&chip->als_mutex);
+	ret = sprintf(buf, "%d\n", chip->als_settings.als_cal_target);
+	mutex_unlock(&chip->als_mutex);
+
+	return ret;
+}
+
+static ssize_t in_illuminance_input_target_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;
+
+	if (kstrtoint(buf, 0, &value) || !value)
+		return -EINVAL;
+
+	mutex_lock(&chip->als_mutex);
+	chip->als_settings.als_cal_target = value;
+	mutex_unlock(&chip->als_mutex);
+
+	return len;
+}
+
+static ssize_t in_illuminance_calibrate_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, ret;
+
+	if (kstrtoint(buf, 0, &value) || value != 1)
+		return -EINVAL;
+
+	mutex_lock(&chip->als_mutex);
+
+	if (chip->suspended) {
+		ret = -EBUSY;
+		goto done;
+	}
+
+	ret = tsl2583_als_calibrate(indio_dev);
+	if (ret < 0)
+		goto done;
+
+	ret = len;
+done:
+	mutex_unlock(&chip->als_mutex);
+
+	return ret;
+}
+
+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(chip->als_settings.als_device_lux); i++) {
+		offset += sprintf(buf + offset, "%u,%u,%u,",
+				  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.
+			 */
+			offset--;
+			break;
+		}
+	}
+
+	offset += sprintf(buf + offset, "\n");
+
+	return offset;
+}
+
+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);
+	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;
+
+	mutex_lock(&chip->als_mutex);
+
+	get_options(buf, ARRAY_SIZE(value), value);
+
+	/*
+	 * We now have an array of ints starting at value[1], and
+	 * enumerated by value[0].
+	 * We expect each group of three ints is one table entry,
+	 * and the last table entry is all 0.
+	 */
+	n = value[0];
+	if ((n % 3) || n < 6 || n > 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, %d]\n",
+			__func__, max_ints);
+		goto done;
+	}
+	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;
+	}
+
+	memcpy(chip->als_settings.als_device_lux, &value[1],
+	       value[0] * sizeof(value[1]));
+
+	ret = len;
+
+done:
+	mutex_unlock(&chip->als_mutex);
+
+	return ret;
+}
+
+static IIO_CONST_ATTR(in_illuminance_calibscale_available, "1 8 16 111");
+static IIO_CONST_ATTR(in_illuminance_integration_time_available,
+		      "0.000050 0.000100 0.000150 0.000200 0.000250 0.000300 0.000350 0.000400 0.000450 0.000500 0.000550 0.000600 0.000650");
+static IIO_DEVICE_ATTR_RW(in_illuminance_input_target, 0);
+static IIO_DEVICE_ATTR_WO(in_illuminance_calibrate, 0);
+static IIO_DEVICE_ATTR_RW(in_illuminance_lux_table, 0);
+
+static struct attribute *sysfs_attrs_ctrl[] = {
+	&iio_const_attr_in_illuminance_calibscale_available.dev_attr.attr,
+	&iio_const_attr_in_illuminance_integration_time_available.dev_attr.attr,
+	&iio_dev_attr_in_illuminance_input_target.dev_attr.attr,
+	&iio_dev_attr_in_illuminance_calibrate.dev_attr.attr,
+	&iio_dev_attr_in_illuminance_lux_table.dev_attr.attr,
+	NULL
+};
+
+static const struct attribute_group tsl2583_attribute_group = {
+	.attrs = sysfs_attrs_ctrl,
+};
+
+static const struct iio_chan_spec tsl2583_channels[] = {
+	{
+		.type = IIO_LIGHT,
+		.modified = 1,
+		.channel2 = IIO_MOD_LIGHT_IR,
+		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+	},
+	{
+		.type = IIO_LIGHT,
+		.modified = 1,
+		.channel2 = IIO_MOD_LIGHT_BOTH,
+		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+	},
+	{
+		.type = IIO_LIGHT,
+		.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) |
+				      BIT(IIO_CHAN_INFO_CALIBBIAS) |
+				      BIT(IIO_CHAN_INFO_CALIBSCALE) |
+				      BIT(IIO_CHAN_INFO_INT_TIME),
+	},
+};
+
+static int tsl2583_read_raw(struct iio_dev *indio_dev,
+			    struct iio_chan_spec const *chan,
+			    int *val, int *val2, long mask)
+{
+	struct tsl2583_chip *chip = iio_priv(indio_dev);
+	int ret = -EINVAL;
+
+	mutex_lock(&chip->als_mutex);
+
+	if (chip->suspended) {
+		ret = -EBUSY;
+		goto read_done;
+	}
+
+	switch (mask) {
+	case IIO_CHAN_INFO_RAW:
+		if (chan->type == IIO_LIGHT) {
+			ret = tsl2583_get_lux(indio_dev);
+			if (ret < 0)
+				goto read_done;
+
+			/*
+			 * From page 20 of the TSL2581, TSL2583 data
+			 * sheet (TAOS134 − MARCH 2011):
+			 *
+			 * One of the photodiodes (channel 0) is
+			 * sensitive to both visible and infrared light,
+			 * while the second photodiode (channel 1) is
+			 * sensitive primarily to infrared light.
+			 */
+			if (chan->channel2 == IIO_MOD_LIGHT_BOTH)
+				*val = chip->als_cur_info.als_ch0;
+			else
+				*val = chip->als_cur_info.als_ch1;
+
+			ret = IIO_VAL_INT;
+		}
+		break;
+	case IIO_CHAN_INFO_PROCESSED:
+		if (chan->type == IIO_LIGHT) {
+			ret = tsl2583_get_lux(indio_dev);
+			if (ret < 0)
+				goto read_done;
+
+			*val = ret;
+			ret = IIO_VAL_INT;
+		}
+		break;
+	case IIO_CHAN_INFO_CALIBBIAS:
+		if (chan->type == IIO_LIGHT) {
+			*val = chip->als_settings.als_gain_trim;
+			ret = IIO_VAL_INT;
+		}
+		break;
+	case IIO_CHAN_INFO_CALIBSCALE:
+		if (chan->type == IIO_LIGHT) {
+			*val = gainadj[chip->als_settings.als_gain].mean;
+			ret = IIO_VAL_INT;
+		}
+		break;
+	case IIO_CHAN_INFO_INT_TIME:
+		if (chan->type == IIO_LIGHT) {
+			*val = 0;
+			*val2 = chip->als_settings.als_time;
+			ret = IIO_VAL_INT_PLUS_MICRO;
+		}
+		break;
+	default:
+		break;
+	}
+
+read_done:
+	mutex_unlock(&chip->als_mutex);
+
+	return ret;
+}
+
+static int tsl2583_write_raw(struct iio_dev *indio_dev,
+			     struct iio_chan_spec const *chan,
+			     int val, int val2, long mask)
+{
+	struct tsl2583_chip *chip = iio_priv(indio_dev);
+	int ret = -EINVAL;
+
+	mutex_lock(&chip->als_mutex);
+
+	if (chip->suspended) {
+		ret = -EBUSY;
+		goto write_done;
+	}
+
+	switch (mask) {
+	case IIO_CHAN_INFO_CALIBBIAS:
+		if (chan->type == IIO_LIGHT) {
+			chip->als_settings.als_gain_trim = val;
+			ret = 0;
+		}
+		break;
+	case IIO_CHAN_INFO_CALIBSCALE:
+		if (chan->type == IIO_LIGHT) {
+			unsigned int i;
+
+			for (i = 0; i < ARRAY_SIZE(gainadj); i++) {
+				if (gainadj[i].mean == val) {
+					chip->als_settings.als_gain = i;
+					ret = tsl2583_set_als_gain(chip);
+					break;
+				}
+			}
+		}
+		break;
+	case IIO_CHAN_INFO_INT_TIME:
+		if (chan->type == IIO_LIGHT && !val && val2 >= 50 &&
+		    val2 <= 650 && !(val2 % 50)) {
+			chip->als_settings.als_time = val2;
+			ret = tsl2583_set_als_time(chip);
+		}
+		break;
+	default:
+		break;
+	}
+
+write_done:
+	mutex_unlock(&chip->als_mutex);
+
+	return ret;
+}
+
+static const struct iio_info tsl2583_info = {
+	.attrs = &tsl2583_attribute_group,
+	.driver_module = THIS_MODULE,
+	.read_raw = tsl2583_read_raw,
+	.write_raw = tsl2583_write_raw,
+};
+
+static int tsl2583_probe(struct i2c_client *clientp,
+			 const struct i2c_device_id *idp)
+{
+	int ret;
+	struct tsl2583_chip *chip;
+	struct iio_dev *indio_dev;
+
+	if (!i2c_check_functionality(clientp->adapter,
+				     I2C_FUNC_SMBUS_BYTE_DATA)) {
+		dev_err(&clientp->dev, "%s: i2c smbus byte data functionality is unsupported\n",
+			__func__);
+		return -EOPNOTSUPP;
+	}
+
+	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);
+
+	mutex_init(&chip->als_mutex);
+	chip->suspended = true;
+
+	ret = i2c_smbus_read_byte_data(clientp,
+				       TSL2583_CMD_REG | TSL2583_CHIPID);
+	if (ret < 0) {
+		dev_err(&clientp->dev,
+			"%s: failed to read the chip ID register\n", __func__);
+		return ret;
+	}
+
+	if ((ret & TSL2583_CHIP_ID_MASK) != TSL2583_CHIP_ID) {
+		dev_err(&clientp->dev, "%s: received an unknown chip ID %x\n",
+			__func__, ret);
+		return -EINVAL;
+	}
+
+	indio_dev->info = &tsl2583_info;
+	indio_dev->channels = tsl2583_channels;
+	indio_dev->num_channels = ARRAY_SIZE(tsl2583_channels);
+	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",
+			__func__);
+		return ret;
+	}
+
+	/* Load up the V2 defaults (these are hard coded defaults for now) */
+	tsl2583_defaults(chip);
+
+	/* Make sure the chip is on */
+	ret = tsl2583_chip_init_and_power_on(indio_dev);
+	if (ret < 0)
+		return ret;
+
+	dev_info(&clientp->dev, "Light sensor found.\n");
+
+	return 0;
+}
+
+static int __maybe_unused tsl2583_suspend(struct device *dev)
+{
+	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
+	struct tsl2583_chip *chip = iio_priv(indio_dev);
+	int ret;
+
+	mutex_lock(&chip->als_mutex);
+
+	ret = tsl2583_set_power_state(chip, TSL2583_CNTL_PWR_OFF);
+	chip->suspended = true;
+
+	mutex_unlock(&chip->als_mutex);
+
+	return ret;
+}
+
+static int __maybe_unused tsl2583_resume(struct device *dev)
+{
+	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
+	struct tsl2583_chip *chip = iio_priv(indio_dev);
+	int ret;
+
+	mutex_lock(&chip->als_mutex);
+
+	ret = tsl2583_chip_init_and_power_on(indio_dev);
+
+	mutex_unlock(&chip->als_mutex);
+
+	return ret;
+}
+
+static SIMPLE_DEV_PM_OPS(tsl2583_pm_ops, tsl2583_suspend, tsl2583_resume);
+
+static struct i2c_device_id tsl2583_idtable[] = {
+	{ "tsl2580", 0 },
+	{ "tsl2581", 1 },
+	{ "tsl2583", 2 },
+	{}
+};
+MODULE_DEVICE_TABLE(i2c, tsl2583_idtable);
+
+static const struct of_device_id tsl2583_of_match[] = {
+	{ .compatible = "amstaos,tsl2580", },
+	{ .compatible = "amstaos,tsl2581", },
+	{ .compatible = "amstaos,tsl2583", },
+	{ },
+};
+MODULE_DEVICE_TABLE(of, tsl2583_of_match);
+
+/* Driver definition */
+static struct i2c_driver tsl2583_driver = {
+	.driver = {
+		.name = "tsl2583",
+		.pm = &tsl2583_pm_ops,
+		.of_match_table = tsl2583_of_match,
+	},
+	.id_table = tsl2583_idtable,
+	.probe = tsl2583_probe,
+};
+module_i2c_driver(tsl2583_driver);
+
+MODULE_AUTHOR("J. August Brenner <jbrenner@taosinc.com>");
+MODULE_AUTHOR("Brian Masney <masneyb@onstation.org>");
+MODULE_DESCRIPTION("TAOS tsl2583 ambient light sensor driver");
+MODULE_LICENSE("GPL");
diff --git a/drivers/staging/iio/Documentation/light/sysfs-bus-iio-light-tsl2583 b/drivers/staging/iio/Documentation/light/sysfs-bus-iio-light-tsl2583
deleted file mode 100644
index a2e1996..0000000
--- a/drivers/staging/iio/Documentation/light/sysfs-bus-iio-light-tsl2583
+++ /dev/null
@@ -1,20 +0,0 @@
-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/light/Kconfig b/drivers/staging/iio/light/Kconfig
index dbf22d3..4fbf629 100644
--- a/drivers/staging/iio/light/Kconfig
+++ b/drivers/staging/iio/light/Kconfig
@@ -13,13 +13,6 @@ config SENSORS_ISL29028
 	 Proximity value via iio. The ISL29028 provides the concurrent sensing
 	 of ambient light and proximity.
 
-config TSL2583
-	tristate "TAOS TSL2580, TSL2581 and TSL2583 light-to-digital converters"
-	depends on I2C
-	help
-	 Provides support for the TAOS tsl2580, tsl2581 and tsl2583 devices.
-	 Access ALS data via iio, sysfs.
-
 config TSL2x7x
 	tristate "TAOS TSL/TMD2x71 and TSL/TMD2x72 Family of light and proximity sensors"
 	depends on I2C
diff --git a/drivers/staging/iio/light/Makefile b/drivers/staging/iio/light/Makefile
index 6480856..f8693e9 100644
--- a/drivers/staging/iio/light/Makefile
+++ b/drivers/staging/iio/light/Makefile
@@ -3,5 +3,4 @@
 #
 
 obj-$(CONFIG_SENSORS_ISL29028)	+= isl29028.o
-obj-$(CONFIG_TSL2583)	+= tsl2583.o
 obj-$(CONFIG_TSL2x7x)	+= tsl2x7x_core.o
diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
deleted file mode 100644
index ca26444..0000000
--- a/drivers/staging/iio/light/tsl2583.c
+++ /dev/null
@@ -1,913 +0,0 @@
-/*
- * Device driver for monitoring ambient light intensity (lux)
- * within the TAOS tsl258x family of devices (tsl2580, tsl2581, tsl2583).
- *
- * 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
- * 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 <linux/kernel.h>
-#include <linux/i2c.h>
-#include <linux/errno.h>
-#include <linux/delay.h>
-#include <linux/string.h>
-#include <linux/mutex.h>
-#include <linux/unistd.h>
-#include <linux/slab.h>
-#include <linux/module.h>
-#include <linux/iio/iio.h>
-#include <linux/iio/sysfs.h>
-
-/* Device Registers and Masks */
-#define TSL2583_CNTRL			0x00
-#define TSL2583_ALS_TIME		0X01
-#define TSL2583_INTERRUPT		0x02
-#define TSL2583_GAIN			0x07
-#define TSL2583_REVID			0x11
-#define TSL2583_CHIPID			0x12
-#define TSL2583_ALS_CHAN0LO		0x14
-#define TSL2583_ALS_CHAN0HI		0x15
-#define TSL2583_ALS_CHAN1LO		0x16
-#define TSL2583_ALS_CHAN1HI		0x17
-#define TSL2583_TMR_LO			0x18
-#define TSL2583_TMR_HI			0x19
-
-/* tsl2583 cmd reg masks */
-#define TSL2583_CMD_REG			0x80
-#define TSL2583_CMD_SPL_FN		0x60
-#define TSL2583_CMD_ALS_INT_CLR		0x01
-
-/* tsl2583 cntrl reg masks */
-#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
-
-/* Lux calculation constants */
-#define	TSL2583_LUX_CALC_OVER_FLOW	65535
-
-#define TSL2583_INTERRUPT_DISABLED	0x00
-
-#define TSL2583_CHIP_ID			0x90
-#define TSL2583_CHIP_ID_MASK		0xf0
-
-/* Per-device data */
-struct tsl2583_als_info {
-	u16 als_ch0;
-	u16 als_ch1;
-	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 {
-	struct mutex als_mutex;
-	struct i2c_client *client;
-	struct tsl2583_als_info als_cur_info;
-	struct tsl2583_settings als_settings;
-	int als_time_scale;
-	int als_saturation;
-	bool suspended;
-};
-
-struct gainadj {
-	s16 ch0;
-	s16 ch1;
-	s16 mean;
-};
-
-/* Index = (0 - 3) Used to validate the gain selection index */
-static const struct gainadj gainadj[] = {
-	{ 1, 1, 1 },
-	{ 8, 8, 8 },
-	{ 16, 16, 16 },
-	{ 107, 115, 111 }
-};
-
-/*
- * Provides initial operational parameter defaults.
- * These defaults may be changed through the device's sysfs files.
- */
-static void tsl2583_defaults(struct tsl2583_chip *chip)
-{
-	/*
-	 * The integration time must be a multiple of 50ms and within the
-	 * range [50, 600] ms.
-	 */
-	chip->als_settings.als_time = 100;
-
-	/*
-	 * This is an index into the gainadj table. Assume clear glass as the
-	 * default.
-	 */
-	chip->als_settings.als_gain = 0;
-
-	/* Default gain trim to account for aperture effects */
-	chip->als_settings.als_gain_trim = 1000;
-
-	/* 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));
-}
-
-/*
- * Reads and calculates current lux value.
- * The raw ch0 and ch1 values of the ambient light sensed in the last
- * integration cycle are read from the device.
- * Time scale factor array values are adjusted based on the integration time.
- * The raw values are multiplied by a scale factor, and device gain is obtained
- * using gain index. Limit checks are done next, then the ratio of a multiple
- * of ch1 value, to the ch0 value, is calculated. The array 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
- * calculate the lux.
- */
-static int tsl2583_get_lux(struct iio_dev *indio_dev)
-{
-	u16 ch0, ch1; /* separated ch0/ch1 data from device */
-	u32 lux; /* raw lux calculated from device data */
-	u64 lux64;
-	u32 ratio;
-	u8 buf[5];
-	struct tsl2583_lux *p;
-	struct tsl2583_chip *chip = iio_priv(indio_dev);
-	int i, ret;
-
-	ret = i2c_smbus_read_byte_data(chip->client, TSL2583_CMD_REG);
-	if (ret < 0) {
-		dev_err(&chip->client->dev, "%s: failed to read CMD_REG register\n",
-			__func__);
-		goto done;
-	}
-
-	/* is data new & valid */
-	if (!(ret & TSL2583_STA_ADC_INTR)) {
-		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;
-	}
-
-	for (i = 0; i < 4; i++) {
-		int reg = TSL2583_CMD_REG | (TSL2583_ALS_CHAN0LO + i);
-
-		ret = i2c_smbus_read_byte_data(chip->client, reg);
-		if (ret < 0) {
-			dev_err(&chip->client->dev, "%s: failed to read register %x\n",
-				__func__, reg);
-			goto done;
-		}
-		buf[i] = ret;
-	}
-
-	/*
-	 * Clear the pending interrupt status bit on the chip to allow the next
-	 * integration cycle to start. This has to be done even though this
-	 * driver currently does not support interrupts.
-	 */
-	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__);
-		goto done; /* have no data, so return failure */
-	}
-
-	/* extract ALS/lux data */
-	ch0 = le16_to_cpup((const __le16 *)&buf[0]);
-	ch1 = le16_to_cpup((const __le16 *)&buf[2]);
-
-	chip->als_cur_info.als_ch0 = ch0;
-	chip->als_cur_info.als_ch1 = ch1;
-
-	if ((ch0 >= chip->als_saturation) || (ch1 >= chip->als_saturation))
-		goto return_max;
-
-	if (!ch0) {
-		/*
-		 * The sensor appears to be in total darkness so set the
-		 * calculated lux to 0 and return early to avoid a division by
-		 * zero below when calculating the ratio.
-		 */
-		ret = 0;
-		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 *)chip->als_settings.als_device_lux;
-	     p->ratio != 0 && p->ratio < ratio; p++)
-		;
-
-	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;
-
-		/* 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 */
-	if (chip->als_time_scale == 0)
-		lux = 0;
-	else
-		lux = (lux + (chip->als_time_scale >> 1)) /
-			chip->als_time_scale;
-
-	/*
-	 * Adjust for active gain scale.
-	 * 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.
-	 * Use 64 bits to avoid overflow on multiplication.
-	 * Then go back to 32 bits before division to avoid using div_u64().
-	 */
-	lux64 = lux;
-	lux64 = lux64 * chip->als_settings.als_gain_trim;
-	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;
-	}
-
-	/* Update the structure with the latest VALID lux. */
-	chip->als_cur_info.lux = lux;
-	ret = lux;
-
-done:
-	return ret;
-}
-
-/*
- * Obtain single reading and calculate the als_gain_trim (later used
- * to derive actual lux).
- * Return updated gain_trim value.
- */
-static int tsl2583_als_calibrate(struct iio_dev *indio_dev)
-{
-	struct tsl2583_chip *chip = iio_priv(indio_dev);
-	unsigned int gain_trim_val;
-	int ret;
-	int lux_val;
-
-	ret = i2c_smbus_read_byte_data(chip->client,
-				       TSL2583_CMD_REG | TSL2583_CNTRL);
-	if (ret < 0) {
-		dev_err(&chip->client->dev,
-			"%s: failed to read from the CNTRL register\n",
-			__func__);
-		return ret;
-	}
-
-	if ((ret & (TSL2583_CNTL_ADC_ENBL | TSL2583_CNTL_PWR_ON))
-			!= (TSL2583_CNTL_ADC_ENBL | TSL2583_CNTL_PWR_ON)) {
-		dev_err(&chip->client->dev,
-			"%s: Device is not powered on and/or ADC is not enabled\n",
-			__func__);
-		return -EINVAL;
-	} else if ((ret & TSL2583_STA_ADC_VALID) != TSL2583_STA_ADC_VALID) {
-		dev_err(&chip->client->dev,
-			"%s: The two ADC channels have not completed an integration cycle\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: 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 0;
-}
-
-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->als_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,
-					TSL2583_CMD_REG | TSL2583_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 als_settings struct */
-	ret = i2c_smbus_write_byte_data(chip->client,
-					TSL2583_CMD_REG | TSL2583_GAIN,
-					chip->als_settings.als_gain);
-	if (ret < 0)
-		dev_err(&chip->client->dev,
-			"%s: failed to set the gain to %d\n", __func__,
-			chip->als_settings.als_gain);
-
-	return ret;
-}
-
-static int tsl2583_set_power_state(struct tsl2583_chip *chip, u8 state)
-{
-	int ret;
-
-	ret = i2c_smbus_write_byte_data(chip->client,
-					TSL2583_CMD_REG | TSL2583_CNTRL, state);
-	if (ret < 0)
-		dev_err(&chip->client->dev,
-			"%s: failed to set the power state to %d\n", __func__,
-			state);
-
-	return ret;
-}
-
-/*
- * Turn the device on.
- * Configuration must be set before calling this function.
- */
-static int tsl2583_chip_init_and_power_on(struct iio_dev *indio_dev)
-{
-	struct tsl2583_chip *chip = iio_priv(indio_dev);
-	int ret;
-
-	/* Power on the device; ADC off. */
-	ret = tsl2583_set_power_state(chip, TSL2583_CNTL_PWR_ON);
-	if (ret < 0)
-		return ret;
-
-	ret = i2c_smbus_write_byte_data(chip->client,
-					TSL2583_CMD_REG | TSL2583_INTERRUPT,
-					TSL2583_INTERRUPT_DISABLED);
-	if (ret < 0) {
-		dev_err(&chip->client->dev,
-			"%s: failed to disable interrupts\n", __func__);
-		return ret;
-	}
-
-	ret = tsl2583_set_als_time(chip);
-	if (ret < 0)
-		return ret;
-
-	ret = tsl2583_set_als_gain(chip);
-	if (ret < 0)
-		return ret;
-
-	usleep_range(3000, 3500);
-
-	ret = tsl2583_set_power_state(chip, TSL2583_CNTL_PWR_ON |
-					    TSL2583_CNTL_ADC_ENBL);
-	if (ret < 0)
-		return ret;
-
-	chip->suspended = false;
-
-	return ret;
-}
-
-/* Sysfs Interface Functions */
-
-static ssize_t in_illuminance_input_target_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);
-	int ret;
-
-	mutex_lock(&chip->als_mutex);
-	ret = sprintf(buf, "%d\n", chip->als_settings.als_cal_target);
-	mutex_unlock(&chip->als_mutex);
-
-	return ret;
-}
-
-static ssize_t in_illuminance_input_target_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;
-
-	if (kstrtoint(buf, 0, &value) || !value)
-		return -EINVAL;
-
-	mutex_lock(&chip->als_mutex);
-	chip->als_settings.als_cal_target = value;
-	mutex_unlock(&chip->als_mutex);
-
-	return len;
-}
-
-static ssize_t in_illuminance_calibrate_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, ret;
-
-	if (kstrtoint(buf, 0, &value) || value != 1)
-		return -EINVAL;
-
-	mutex_lock(&chip->als_mutex);
-
-	if (chip->suspended) {
-		ret = -EBUSY;
-		goto done;
-	}
-
-	ret = tsl2583_als_calibrate(indio_dev);
-	if (ret < 0)
-		goto done;
-
-	ret = len;
-done:
-	mutex_unlock(&chip->als_mutex);
-
-	return ret;
-}
-
-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(chip->als_settings.als_device_lux); i++) {
-		offset += sprintf(buf + offset, "%u,%u,%u,",
-				  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.
-			 */
-			offset--;
-			break;
-		}
-	}
-
-	offset += sprintf(buf + offset, "\n");
-
-	return offset;
-}
-
-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);
-	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;
-
-	mutex_lock(&chip->als_mutex);
-
-	get_options(buf, ARRAY_SIZE(value), value);
-
-	/*
-	 * We now have an array of ints starting at value[1], and
-	 * enumerated by value[0].
-	 * We expect each group of three ints is one table entry,
-	 * and the last table entry is all 0.
-	 */
-	n = value[0];
-	if ((n % 3) || n < 6 || n > 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, %d]\n",
-			__func__, max_ints);
-		goto done;
-	}
-	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;
-	}
-
-	memcpy(chip->als_settings.als_device_lux, &value[1],
-	       value[0] * sizeof(value[1]));
-
-	ret = len;
-
-done:
-	mutex_unlock(&chip->als_mutex);
-
-	return ret;
-}
-
-static IIO_CONST_ATTR(in_illuminance_calibscale_available, "1 8 16 111");
-static IIO_CONST_ATTR(in_illuminance_integration_time_available,
-		      "0.000050 0.000100 0.000150 0.000200 0.000250 0.000300 0.000350 0.000400 0.000450 0.000500 0.000550 0.000600 0.000650");
-static IIO_DEVICE_ATTR_RW(in_illuminance_input_target, 0);
-static IIO_DEVICE_ATTR_WO(in_illuminance_calibrate, 0);
-static IIO_DEVICE_ATTR_RW(in_illuminance_lux_table, 0);
-
-static struct attribute *sysfs_attrs_ctrl[] = {
-	&iio_const_attr_in_illuminance_calibscale_available.dev_attr.attr,
-	&iio_const_attr_in_illuminance_integration_time_available.dev_attr.attr,
-	&iio_dev_attr_in_illuminance_input_target.dev_attr.attr,
-	&iio_dev_attr_in_illuminance_calibrate.dev_attr.attr,
-	&iio_dev_attr_in_illuminance_lux_table.dev_attr.attr,
-	NULL
-};
-
-static const struct attribute_group tsl2583_attribute_group = {
-	.attrs = sysfs_attrs_ctrl,
-};
-
-static const struct iio_chan_spec tsl2583_channels[] = {
-	{
-		.type = IIO_LIGHT,
-		.modified = 1,
-		.channel2 = IIO_MOD_LIGHT_IR,
-		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
-	},
-	{
-		.type = IIO_LIGHT,
-		.modified = 1,
-		.channel2 = IIO_MOD_LIGHT_BOTH,
-		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
-	},
-	{
-		.type = IIO_LIGHT,
-		.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) |
-				      BIT(IIO_CHAN_INFO_CALIBBIAS) |
-				      BIT(IIO_CHAN_INFO_CALIBSCALE) |
-				      BIT(IIO_CHAN_INFO_INT_TIME),
-	},
-};
-
-static int tsl2583_read_raw(struct iio_dev *indio_dev,
-			    struct iio_chan_spec const *chan,
-			    int *val, int *val2, long mask)
-{
-	struct tsl2583_chip *chip = iio_priv(indio_dev);
-	int ret = -EINVAL;
-
-	mutex_lock(&chip->als_mutex);
-
-	if (chip->suspended) {
-		ret = -EBUSY;
-		goto read_done;
-	}
-
-	switch (mask) {
-	case IIO_CHAN_INFO_RAW:
-		if (chan->type == IIO_LIGHT) {
-			ret = tsl2583_get_lux(indio_dev);
-			if (ret < 0)
-				goto read_done;
-
-			/*
-			 * From page 20 of the TSL2581, TSL2583 data
-			 * sheet (TAOS134 − MARCH 2011):
-			 *
-			 * One of the photodiodes (channel 0) is
-			 * sensitive to both visible and infrared light,
-			 * while the second photodiode (channel 1) is
-			 * sensitive primarily to infrared light.
-			 */
-			if (chan->channel2 == IIO_MOD_LIGHT_BOTH)
-				*val = chip->als_cur_info.als_ch0;
-			else
-				*val = chip->als_cur_info.als_ch1;
-
-			ret = IIO_VAL_INT;
-		}
-		break;
-	case IIO_CHAN_INFO_PROCESSED:
-		if (chan->type == IIO_LIGHT) {
-			ret = tsl2583_get_lux(indio_dev);
-			if (ret < 0)
-				goto read_done;
-
-			*val = ret;
-			ret = IIO_VAL_INT;
-		}
-		break;
-	case IIO_CHAN_INFO_CALIBBIAS:
-		if (chan->type == IIO_LIGHT) {
-			*val = chip->als_settings.als_gain_trim;
-			ret = IIO_VAL_INT;
-		}
-		break;
-	case IIO_CHAN_INFO_CALIBSCALE:
-		if (chan->type == IIO_LIGHT) {
-			*val = gainadj[chip->als_settings.als_gain].mean;
-			ret = IIO_VAL_INT;
-		}
-		break;
-	case IIO_CHAN_INFO_INT_TIME:
-		if (chan->type == IIO_LIGHT) {
-			*val = 0;
-			*val2 = chip->als_settings.als_time;
-			ret = IIO_VAL_INT_PLUS_MICRO;
-		}
-		break;
-	default:
-		break;
-	}
-
-read_done:
-	mutex_unlock(&chip->als_mutex);
-
-	return ret;
-}
-
-static int tsl2583_write_raw(struct iio_dev *indio_dev,
-			     struct iio_chan_spec const *chan,
-			     int val, int val2, long mask)
-{
-	struct tsl2583_chip *chip = iio_priv(indio_dev);
-	int ret = -EINVAL;
-
-	mutex_lock(&chip->als_mutex);
-
-	if (chip->suspended) {
-		ret = -EBUSY;
-		goto write_done;
-	}
-
-	switch (mask) {
-	case IIO_CHAN_INFO_CALIBBIAS:
-		if (chan->type == IIO_LIGHT) {
-			chip->als_settings.als_gain_trim = val;
-			ret = 0;
-		}
-		break;
-	case IIO_CHAN_INFO_CALIBSCALE:
-		if (chan->type == IIO_LIGHT) {
-			unsigned int i;
-
-			for (i = 0; i < ARRAY_SIZE(gainadj); i++) {
-				if (gainadj[i].mean == val) {
-					chip->als_settings.als_gain = i;
-					ret = tsl2583_set_als_gain(chip);
-					break;
-				}
-			}
-		}
-		break;
-	case IIO_CHAN_INFO_INT_TIME:
-		if (chan->type == IIO_LIGHT && !val && val2 >= 50 &&
-		    val2 <= 650 && !(val2 % 50)) {
-			chip->als_settings.als_time = val2;
-			ret = tsl2583_set_als_time(chip);
-		}
-		break;
-	default:
-		break;
-	}
-
-write_done:
-	mutex_unlock(&chip->als_mutex);
-
-	return ret;
-}
-
-static const struct iio_info tsl2583_info = {
-	.attrs = &tsl2583_attribute_group,
-	.driver_module = THIS_MODULE,
-	.read_raw = tsl2583_read_raw,
-	.write_raw = tsl2583_write_raw,
-};
-
-static int tsl2583_probe(struct i2c_client *clientp,
-			 const struct i2c_device_id *idp)
-{
-	int ret;
-	struct tsl2583_chip *chip;
-	struct iio_dev *indio_dev;
-
-	if (!i2c_check_functionality(clientp->adapter,
-				     I2C_FUNC_SMBUS_BYTE_DATA)) {
-		dev_err(&clientp->dev, "%s: i2c smbus byte data functionality is unsupported\n",
-			__func__);
-		return -EOPNOTSUPP;
-	}
-
-	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);
-
-	mutex_init(&chip->als_mutex);
-	chip->suspended = true;
-
-	ret = i2c_smbus_read_byte_data(clientp,
-				       TSL2583_CMD_REG | TSL2583_CHIPID);
-	if (ret < 0) {
-		dev_err(&clientp->dev,
-			"%s: failed to read the chip ID register\n", __func__);
-		return ret;
-	}
-
-	if ((ret & TSL2583_CHIP_ID_MASK) != TSL2583_CHIP_ID) {
-		dev_err(&clientp->dev, "%s: received an unknown chip ID %x\n",
-			__func__, ret);
-		return -EINVAL;
-	}
-
-	indio_dev->info = &tsl2583_info;
-	indio_dev->channels = tsl2583_channels;
-	indio_dev->num_channels = ARRAY_SIZE(tsl2583_channels);
-	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",
-			__func__);
-		return ret;
-	}
-
-	/* Load up the V2 defaults (these are hard coded defaults for now) */
-	tsl2583_defaults(chip);
-
-	/* Make sure the chip is on */
-	ret = tsl2583_chip_init_and_power_on(indio_dev);
-	if (ret < 0)
-		return ret;
-
-	dev_info(&clientp->dev, "Light sensor found.\n");
-
-	return 0;
-}
-
-static int __maybe_unused tsl2583_suspend(struct device *dev)
-{
-	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
-	struct tsl2583_chip *chip = iio_priv(indio_dev);
-	int ret;
-
-	mutex_lock(&chip->als_mutex);
-
-	ret = tsl2583_set_power_state(chip, TSL2583_CNTL_PWR_OFF);
-	chip->suspended = true;
-
-	mutex_unlock(&chip->als_mutex);
-
-	return ret;
-}
-
-static int __maybe_unused tsl2583_resume(struct device *dev)
-{
-	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
-	struct tsl2583_chip *chip = iio_priv(indio_dev);
-	int ret;
-
-	mutex_lock(&chip->als_mutex);
-
-	ret = tsl2583_chip_init_and_power_on(indio_dev);
-
-	mutex_unlock(&chip->als_mutex);
-
-	return ret;
-}
-
-static SIMPLE_DEV_PM_OPS(tsl2583_pm_ops, tsl2583_suspend, tsl2583_resume);
-
-static struct i2c_device_id tsl2583_idtable[] = {
-	{ "tsl2580", 0 },
-	{ "tsl2581", 1 },
-	{ "tsl2583", 2 },
-	{}
-};
-MODULE_DEVICE_TABLE(i2c, tsl2583_idtable);
-
-static const struct of_device_id tsl2583_of_match[] = {
-	{ .compatible = "amstaos,tsl2580", },
-	{ .compatible = "amstaos,tsl2581", },
-	{ .compatible = "amstaos,tsl2583", },
-	{ },
-};
-MODULE_DEVICE_TABLE(of, tsl2583_of_match);
-
-/* Driver definition */
-static struct i2c_driver tsl2583_driver = {
-	.driver = {
-		.name = "tsl2583",
-		.pm = &tsl2583_pm_ops,
-		.of_match_table = tsl2583_of_match,
-	},
-	.id_table = tsl2583_idtable,
-	.probe = tsl2583_probe,
-};
-module_i2c_driver(tsl2583_driver);
-
-MODULE_AUTHOR("J. August Brenner <jbrenner@taosinc.com>");
-MODULE_AUTHOR("Brian Masney <masneyb@onstation.org>");
-MODULE_DESCRIPTION("TAOS tsl2583 ambient light sensor driver");
-MODULE_LICENSE("GPL");
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 54+ messages in thread

* Re: [PATCH v4 01/26] staging: iio: tsl2583: check if chip is in a working state in in_illuminance_calibrate_store
  2016-11-12 18:19 ` [PATCH v4 01/26] staging: iio: tsl2583: check if chip is in a working state in in_illuminance_calibrate_store Brian Masney
@ 2016-11-13 11:54   ` Jonathan Cameron
  0 siblings, 0 replies; 54+ messages in thread
From: Jonathan Cameron @ 2016-11-13 11:54 UTC (permalink / raw)
  To: Brian Masney, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

On 12/11/16 18:19, Brian Masney wrote:
> in_illuminance_calibrate_store() did not check to see if the chip is
> in a working state. 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>
Applied
> ---
>  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 1a7be12..de54e74 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->taos_chip_status != TSL258X_CHIP_WORKING) {
> +		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,
> 

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v4 02/26] staging: iio: tsl2583: remove unnecessary chip status check in taos_get_lux
  2016-11-12 18:19 ` [PATCH v4 02/26] staging: iio: tsl2583: remove unnecessary chip status check in taos_get_lux Brian Masney
@ 2016-11-13 11:55   ` Jonathan Cameron
  0 siblings, 0 replies; 54+ messages in thread
From: Jonathan Cameron @ 2016-11-13 11:55 UTC (permalink / raw)
  To: Brian Masney, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

On 12/11/16 18:19, Brian Masney wrote:
> taos_get_lux checks to see if the chip is in a working state. This
> check is not necessary since it is only called from tsl2583_read_raw
> and in_illuminance_calibrate_store (via taos_als_calibrate). The chip
> state is already checked by these functions.
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>
Applied.
> ---
>  drivers/staging/iio/light/tsl2583.c | 7 -------
>  1 file changed, 7 deletions(-)
> 
> diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
> index de54e74..a550023 100644
> --- a/drivers/staging/iio/light/tsl2583.c
> +++ b/drivers/staging/iio/light/tsl2583.c
> @@ -178,13 +178,6 @@ static int taos_get_lux(struct iio_dev *indio_dev)
>  	u32 ch0lux = 0;
>  	u32 ch1lux = 0;
>  
> -	if (chip->taos_chip_status != TSL258X_CHIP_WORKING) {
> -		/* device is not enabled */
> -		dev_err(&chip->client->dev, "taos_get_lux device is not enabled\n");
> -		ret = -EBUSY;
> -		goto done;
> -	}
> -
>  	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");
> 

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v4 03/26] staging: iio: tsl2583: remove unnecessary chip status checks in suspend/resume
  2016-11-12 18:19 ` [PATCH v4 03/26] staging: iio: tsl2583: remove unnecessary chip status checks in suspend/resume Brian Masney
@ 2016-11-13 11:56   ` Jonathan Cameron
  0 siblings, 0 replies; 54+ messages in thread
From: Jonathan Cameron @ 2016-11-13 11:56 UTC (permalink / raw)
  To: Brian Masney, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

On 12/11/16 18:19, Brian Masney wrote:
> The device probing and the suspend/resume code checks a flag internal to
> the driver that determines whether or not the chip is in a working
> state. These checks are not needed. This patch removes the unnecessary
> checks. It will do no harm to the hardware if the chip is
> reinitialized if it is already powered on.
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>
Applied.
> ---
>  drivers/staging/iio/light/tsl2583.c | 16 +++-------------
>  1 file changed, 3 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
> index a550023..40aa78e 100644
> --- a/drivers/staging/iio/light/tsl2583.c
> +++ b/drivers/staging/iio/light/tsl2583.c
> @@ -412,13 +412,6 @@ static int tsl2583_chip_init_and_power_on(struct iio_dev *indio_dev)
>  	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) {
> -		/* if forcing a register update - turn off, then on */
> -		dev_info(&chip->client->dev, "device is already enabled\n");
> -		return -EINVAL;
> -	}
> -
>  	/* Power on the device; ADC off. */
>  	ret = tsl2583_set_power_state(chip, TSL258X_CNTL_PWR_ON);
>  	if (ret < 0)
> @@ -841,10 +834,8 @@ static int __maybe_unused taos_suspend(struct device *dev)
>  
>  	mutex_lock(&chip->als_mutex);
>  
> -	if (chip->taos_chip_status == TSL258X_CHIP_WORKING) {
> -		ret = tsl2583_set_power_state(chip, TSL258X_CNTL_PWR_OFF);
> -		chip->taos_chip_status = TSL258X_CHIP_SUSPENDED;
> -	}
> +	ret = tsl2583_set_power_state(chip, TSL258X_CNTL_PWR_OFF);
> +	chip->taos_chip_status = TSL258X_CHIP_SUSPENDED;
>  
>  	mutex_unlock(&chip->als_mutex);
>  	return ret;
> @@ -858,8 +849,7 @@ static int __maybe_unused taos_resume(struct device *dev)
>  
>  	mutex_lock(&chip->als_mutex);
>  
> -	if (chip->taos_chip_status == TSL258X_CHIP_SUSPENDED)
> -		ret = tsl2583_chip_init_and_power_on(indio_dev);
> +	ret = tsl2583_chip_init_and_power_on(indio_dev);
>  
>  	mutex_unlock(&chip->als_mutex);
>  	return ret;
> 

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v4 04/26] staging: iio: tsl2583: change current chip state from a tristate to a bool
  2016-11-12 18:19 ` [PATCH v4 04/26] staging: iio: tsl2583: change current chip state from a tristate to a bool Brian Masney
@ 2016-11-13 11:58   ` Jonathan Cameron
  0 siblings, 0 replies; 54+ messages in thread
From: Jonathan Cameron @ 2016-11-13 11:58 UTC (permalink / raw)
  To: Brian Masney, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

On 12/11/16 18:19, Brian Masney wrote:
> The current chip state is represented as a tristate (working, suspended,
> and unknown). The unknown state was not used. This patch changes the
> chip state so that it is now represented as a single boolean value
> (suspended).
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>
Applied.

> ---
>  drivers/staging/iio/light/tsl2583.c | 20 +++++++-------------
>  1 file changed, 7 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
> index 40aa78e..5a32102 100644
> --- a/drivers/staging/iio/light/tsl2583.c
> +++ b/drivers/staging/iio/light/tsl2583.c
> @@ -67,12 +67,6 @@
>  #define TSL2583_CHIP_ID			0x90
>  #define TSL2583_CHIP_ID_MASK		0xf0
>  
> -enum {
> -	TSL258X_CHIP_UNKNOWN = 0,
> -	TSL258X_CHIP_WORKING = 1,
> -	TSL258X_CHIP_SUSPENDED = 2
> -};
> -
>  /* Per-device data */
>  struct taos_als_info {
>  	u16 als_ch0;
> @@ -94,7 +88,7 @@ struct tsl2583_chip {
>  	struct taos_settings taos_settings;
>  	int als_time_scale;
>  	int als_saturation;
> -	int taos_chip_status;
> +	bool suspended;
>  };
>  
>  struct taos_lux {
> @@ -441,7 +435,7 @@ static int tsl2583_chip_init_and_power_on(struct iio_dev *indio_dev)
>  	if (ret < 0)
>  		return ret;
>  
> -	chip->taos_chip_status = TSL258X_CHIP_WORKING;
> +	chip->suspended = false;
>  
>  	return ret;
>  }
> @@ -494,7 +488,7 @@ static ssize_t in_illuminance_calibrate_store(struct device *dev,
>  
>  	mutex_lock(&chip->als_mutex);
>  
> -	if (chip->taos_chip_status != TSL258X_CHIP_WORKING) {
> +	if (chip->suspended) {
>  		ret = -EBUSY;
>  		goto done;
>  	}
> @@ -627,7 +621,7 @@ static int tsl2583_read_raw(struct iio_dev *indio_dev,
>  
>  	mutex_lock(&chip->als_mutex);
>  
> -	if (chip->taos_chip_status != TSL258X_CHIP_WORKING) {
> +	if (chip->suspended) {
>  		ret = -EBUSY;
>  		goto read_done;
>  	}
> @@ -704,7 +698,7 @@ static int tsl2583_write_raw(struct iio_dev *indio_dev,
>  
>  	mutex_lock(&chip->als_mutex);
>  
> -	if (chip->taos_chip_status != TSL258X_CHIP_WORKING) {
> +	if (chip->suspended) {
>  		ret = -EBUSY;
>  		goto write_done;
>  	}
> @@ -778,7 +772,7 @@ static int taos_probe(struct i2c_client *clientp,
>  	i2c_set_clientdata(clientp, indio_dev);
>  
>  	mutex_init(&chip->als_mutex);
> -	chip->taos_chip_status = TSL258X_CHIP_UNKNOWN;
> +	chip->suspended = true;
>  
>  	ret = i2c_smbus_read_byte_data(clientp,
>  				       TSL258X_CMD_REG | TSL258X_CHIPID);
> @@ -835,7 +829,7 @@ static int __maybe_unused taos_suspend(struct device *dev)
>  	mutex_lock(&chip->als_mutex);
>  
>  	ret = tsl2583_set_power_state(chip, TSL258X_CNTL_PWR_OFF);
> -	chip->taos_chip_status = TSL258X_CHIP_SUSPENDED;
> +	chip->suspended = true;
>  
>  	mutex_unlock(&chip->als_mutex);
>  	return ret;
> 

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v4 05/26] staging: iio: tsl2583: remove redundant write to the control register in taos_probe()
  2016-11-12 18:19 ` [PATCH v4 05/26] staging: iio: tsl2583: remove redundant write to the control register in taos_probe() Brian Masney
@ 2016-11-13 12:06   ` Jonathan Cameron
  0 siblings, 0 replies; 54+ messages in thread
From: Jonathan Cameron @ 2016-11-13 12:06 UTC (permalink / raw)
  To: Brian Masney, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

On 12/11/16 18:19, Brian Masney wrote:
> taos_probe() calls i2c_smbus_write_byte() to select the control
> register, however there are no subsequent calls to
> i2c_smbus_read_byte(). The write call is unnecessary and is removed by
> this patch.
> 
> Verified that the driver still functions correctly using a TSL2581
> hooked up to a Raspberry Pi 2.
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>
Applied.

Thanks,
> ---
>  drivers/staging/iio/light/tsl2583.c | 8 --------
>  1 file changed, 8 deletions(-)
> 
> diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
> index 5a32102..449506b 100644
> --- a/drivers/staging/iio/light/tsl2583.c
> +++ b/drivers/staging/iio/light/tsl2583.c
> @@ -788,14 +788,6 @@ static int taos_probe(struct i2c_client *clientp,
>  		return -EINVAL;
>  	}
>  
> -	ret = i2c_smbus_write_byte(clientp, (TSL258X_CMD_REG | TSL258X_CNTRL));
> -	if (ret < 0) {
> -		dev_err(&clientp->dev,
> -			"i2c_smbus_write_byte() to cmd reg failed in taos_probe(), err = %d\n",
> -			ret);
> -		return ret;
> -	}
> -
>  	indio_dev->info = &tsl2583_info;
>  	indio_dev->channels = tsl2583_channels;
>  	indio_dev->num_channels = ARRAY_SIZE(tsl2583_channels);
> 

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v4 06/26] staging: iio: tsl2583: remove the FSF's mailing address
  2016-11-12 18:19 ` [PATCH v4 06/26] staging: iio: tsl2583: remove the FSF's mailing address Brian Masney
@ 2016-11-13 12:07   ` Jonathan Cameron
  0 siblings, 0 replies; 54+ messages in thread
From: Jonathan Cameron @ 2016-11-13 12:07 UTC (permalink / raw)
  To: Brian Masney, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

On 12/11/16 18:19, Brian Masney wrote:
> Address warning from checkpatch:
> 
> CHECK: Do not include the paragraph about writing to the Free Software
> Foundation's mailing address from the sample GPL notice. The FSF has
> changed addresses in the past, and may do so again. Linux already
> includes a copy of the GPL.
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>
Applied.
> ---
>  drivers/staging/iio/light/tsl2583.c | 4 ----
>  1 file changed, 4 deletions(-)
> 
> diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
> index 449506b..57279f7 100644
> --- a/drivers/staging/iio/light/tsl2583.c
> +++ b/drivers/staging/iio/light/tsl2583.c
> @@ -13,10 +13,6 @@
>   * 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.
>   */
>  
>  #include <linux/kernel.h>
> 

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v4 07/26] staging: iio: tsl2583: cleaned up logging
  2016-11-12 18:19 ` [PATCH v4 07/26] staging: iio: tsl2583: cleaned up logging Brian Masney
@ 2016-11-13 12:07   ` Jonathan Cameron
  0 siblings, 0 replies; 54+ messages in thread
From: Jonathan Cameron @ 2016-11-13 12:07 UTC (permalink / raw)
  To: Brian Masney, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

On 12/11/16 18:19, 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.
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>
Applied.
> ---
>  drivers/staging/iio/light/tsl2583.c | 73 ++++++++++++++++++++++---------------
>  1 file changed, 43 insertions(+), 30 deletions(-)
> 
> diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
> index 57279f7..5d74e0c1 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;
> @@ -301,7 +302,7 @@ static int taos_als_calibrate(struct iio_dev *indio_dev)
>  				       TSL258X_CMD_REG | TSL258X_CNTRL);
>  	if (ret < 0) {
>  		dev_err(&chip->client->dev,
> -			"%s failed to read from the CNTRL register\n",
> +			"%s: failed to read from the CNTRL register\n",
>  			__func__);
>  		return ret;
>  	}
> @@ -309,16 +310,19 @@ 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: Device is not powered on and/or ADC is not 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: The two ADC channels have not completed an integration cycle\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 +330,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: 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;
> @@ -353,7 +357,7 @@ static int tsl2583_set_als_time(struct tsl2583_chip *chip)
>  					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",
> +		dev_err(&chip->client->dev, "%s: failed to set the als time to %d\n",
>  			__func__, val);
>  		return ret;
>  	}
> @@ -374,8 +378,9 @@ static int tsl2583_set_als_gain(struct tsl2583_chip *chip)
>  					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);
> +		dev_err(&chip->client->dev,
> +			"%s: failed to set the gain to %d\n", __func__,
> +			chip->taos_settings.als_gain);
>  
>  	return ret;
>  }
> @@ -387,8 +392,9 @@ static int tsl2583_set_power_state(struct tsl2583_chip *chip, u8 state)
>  	ret = i2c_smbus_write_byte_data(chip->client,
>  					TSL258X_CMD_REG | TSL258X_CNTRL, state);
>  	if (ret < 0)
> -		dev_err(&chip->client->dev, "%s failed to set the power state to %d\n",
> -			__func__, state);
> +		dev_err(&chip->client->dev,
> +			"%s: failed to set the power state to %d\n", __func__,
> +			state);
>  
>  	return ret;
>  }
> @@ -411,8 +417,8 @@ static int tsl2583_chip_init_and_power_on(struct iio_dev *indio_dev)
>  					TSL258X_CMD_REG | TSL258X_INTERRUPT,
>  					TSL2583_INTERRUPT_DISABLED);
>  	if (ret < 0) {
> -		dev_err(&chip->client->dev, "%s failed to disable interrupts\n",
> -			__func__);
> +		dev_err(&chip->client->dev,
> +			"%s: failed to disable interrupts\n", __func__);
>  		return ret;
>  	}
>  
> @@ -526,6 +532,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 +553,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]\n",
> +			__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 +767,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;
>  	}
>  
> @@ -774,13 +786,13 @@ static int taos_probe(struct i2c_client *clientp,
>  				       TSL258X_CMD_REG | TSL258X_CHIPID);
>  	if (ret < 0) {
>  		dev_err(&clientp->dev,
> -			"%s failed to read the chip ID register\n", __func__);
> +			"%s: failed to read the chip ID register\n", __func__);
>  		return ret;
>  	}
>  
>  	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 +804,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;
>  	}
>  
> 

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v4 08/26] staging: iio: tsl2583: unify function and variable prefix to tsl2583_
  2016-11-12 18:19 ` [PATCH v4 08/26] staging: iio: tsl2583: unify function and variable prefix to tsl2583_ Brian Masney
@ 2016-11-13 12:09   ` Jonathan Cameron
  0 siblings, 0 replies; 54+ messages in thread
From: Jonathan Cameron @ 2016-11-13 12:09 UTC (permalink / raw)
  To: Brian Masney, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

On 12/11/16 18:19, Brian Masney wrote:
> Some functions and variables were prefixed with either taos, tsl258x,
> taos2583, or tsl2583. Change everything to use the tsl2583 prefix since
> that is the name of the .c file. The taos_settings member inside the
> taos_settings struct was renamed to als_settings.
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>
Applied.
> ---
>  drivers/staging/iio/light/tsl2583.c | 214 ++++++++++++++++++------------------
>  1 file changed, 107 insertions(+), 107 deletions(-)
> 
> diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
> index 5d74e0c1..5a82a26 100644
> --- a/drivers/staging/iio/light/tsl2583.c
> +++ b/drivers/staging/iio/light/tsl2583.c
> @@ -28,35 +28,35 @@
>  #include <linux/iio/sysfs.h>
>  
>  /* Device Registers and Masks */
> -#define TSL258X_CNTRL			0x00
> -#define TSL258X_ALS_TIME		0X01
> -#define TSL258X_INTERRUPT		0x02
> -#define TSL258X_GAIN			0x07
> -#define TSL258X_REVID			0x11
> -#define TSL258X_CHIPID			0x12
> -#define TSL258X_ALS_CHAN0LO		0x14
> -#define TSL258X_ALS_CHAN0HI		0x15
> -#define TSL258X_ALS_CHAN1LO		0x16
> -#define TSL258X_ALS_CHAN1HI		0x17
> -#define TSL258X_TMR_LO			0x18
> -#define TSL258X_TMR_HI			0x19
> +#define TSL2583_CNTRL			0x00
> +#define TSL2583_ALS_TIME		0X01
> +#define TSL2583_INTERRUPT		0x02
> +#define TSL2583_GAIN			0x07
> +#define TSL2583_REVID			0x11
> +#define TSL2583_CHIPID			0x12
> +#define TSL2583_ALS_CHAN0LO		0x14
> +#define TSL2583_ALS_CHAN0HI		0x15
> +#define TSL2583_ALS_CHAN1LO		0x16
> +#define TSL2583_ALS_CHAN1HI		0x17
> +#define TSL2583_TMR_LO			0x18
> +#define TSL2583_TMR_HI			0x19
>  
>  /* tsl2583 cmd reg masks */
> -#define TSL258X_CMD_REG			0x80
> -#define TSL258X_CMD_SPL_FN		0x60
> -#define TSL258X_CMD_ALS_INT_CLR	0X01
> +#define TSL2583_CMD_REG			0x80
> +#define TSL2583_CMD_SPL_FN		0x60
> +#define TSL2583_CMD_ALS_INT_CLR	0X01
>  
>  /* tsl2583 cntrl reg masks */
> -#define TSL258X_CNTL_ADC_ENBL	0x02
> -#define TSL258X_CNTL_PWR_OFF		0x00
> -#define TSL258X_CNTL_PWR_ON		0x01
> +#define TSL2583_CNTL_ADC_ENBL	0x02
> +#define TSL2583_CNTL_PWR_OFF		0x00
> +#define TSL2583_CNTL_PWR_ON		0x01
>  
>  /* tsl2583 status reg masks */
> -#define TSL258X_STA_ADC_VALID	0x01
> -#define TSL258X_STA_ADC_INTR	0x10
> +#define TSL2583_STA_ADC_VALID	0x01
> +#define TSL2583_STA_ADC_INTR	0x10
>  
>  /* Lux calculation constants */
> -#define	TSL258X_LUX_CALC_OVER_FLOW		65535
> +#define	TSL2583_LUX_CALC_OVER_FLOW		65535
>  
>  #define TSL2583_INTERRUPT_DISABLED	0x00
>  
> @@ -64,13 +64,13 @@
>  #define TSL2583_CHIP_ID_MASK		0xf0
>  
>  /* Per-device data */
> -struct taos_als_info {
> +struct tsl2583_als_info {
>  	u16 als_ch0;
>  	u16 als_ch1;
>  	u16 lux;
>  };
>  
> -struct taos_settings {
> +struct tsl2583_settings {
>  	int als_time;
>  	int als_gain;
>  	int als_gain_trim;
> @@ -80,14 +80,14 @@ struct taos_settings {
>  struct tsl2583_chip {
>  	struct mutex als_mutex;
>  	struct i2c_client *client;
> -	struct taos_als_info als_cur_info;
> -	struct taos_settings taos_settings;
> +	struct tsl2583_als_info als_cur_info;
> +	struct tsl2583_settings als_settings;
>  	int als_time_scale;
>  	int als_saturation;
>  	bool suspended;
>  };
>  
> -struct taos_lux {
> +struct tsl2583_lux {
>  	unsigned int ratio;
>  	unsigned int ch0;
>  	unsigned int ch1;
> @@ -96,7 +96,7 @@ struct taos_lux {
>  /* 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  */
> -static struct taos_lux taos_device_lux[11] = {
> +static struct tsl2583_lux tsl2583_device_lux[11] = {
>  	{  9830,  8520, 15729 },
>  	{ 12452, 10807, 23344 },
>  	{ 14746,  6383, 11705 },
> @@ -121,25 +121,25 @@ static const struct gainadj gainadj[] = {
>   * Provides initial operational parameter defaults.
>   * These defaults may be changed through the device's sysfs files.
>   */
> -static void taos_defaults(struct tsl2583_chip *chip)
> +static void tsl2583_defaults(struct tsl2583_chip *chip)
>  {
>  	/*
>  	 * The integration time must be a multiple of 50ms and within the
>  	 * range [50, 600] ms.
>  	 */
> -	chip->taos_settings.als_time = 100;
> +	chip->als_settings.als_time = 100;
>  
>  	/*
>  	 * This is an index into the gainadj table. Assume clear glass as the
>  	 * default.
>  	 */
> -	chip->taos_settings.als_gain = 0;
> +	chip->als_settings.als_gain = 0;
>  
>  	/* Default gain trim to account for aperture effects */
> -	chip->taos_settings.als_gain_trim = 1000;
> +	chip->als_settings.als_gain_trim = 1000;
>  
>  	/* Known external ALS reading used for calibration */
> -	chip->taos_settings.als_cal_target = 130;
> +	chip->als_settings.als_cal_target = 130;
>  }
>  
>  /*
> @@ -149,26 +149,26 @@ static void taos_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 taos_device_lux[]
> + * of ch1 value, to the ch0 value, is calculated. The array tsl2583_device_lux[]
>   * declared above is then scanned to find the first ratio value that is just
>   * above the ratio we just calculated. The ch0 and ch1 multiplier constants in
>   * the array are then used along with the time scale factor array values, to
>   * calculate the lux.
>   */
> -static int taos_get_lux(struct iio_dev *indio_dev)
> +static int tsl2583_get_lux(struct iio_dev *indio_dev)
>  {
>  	u16 ch0, ch1; /* separated ch0/ch1 data from device */
>  	u32 lux; /* raw lux calculated from device data */
>  	u64 lux64;
>  	u32 ratio;
>  	u8 buf[5];
> -	struct taos_lux *p;
> +	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, TSL258X_CMD_REG);
> +	ret = i2c_smbus_read_byte_data(chip->client, TSL2583_CMD_REG);
>  	if (ret < 0) {
>  		dev_err(&chip->client->dev, "%s: failed to read CMD_REG register\n",
>  			__func__);
> @@ -176,7 +176,7 @@ static int taos_get_lux(struct iio_dev *indio_dev)
>  	}
>  
>  	/* is data new & valid */
> -	if (!(ret & TSL258X_STA_ADC_INTR)) {
> +	if (!(ret & TSL2583_STA_ADC_INTR)) {
>  		dev_err(&chip->client->dev, "%s: data not valid; returning last value\n",
>  			__func__);
>  		ret = chip->als_cur_info.lux; /* return LAST VALUE */
> @@ -184,7 +184,7 @@ static int taos_get_lux(struct iio_dev *indio_dev)
>  	}
>  
>  	for (i = 0; i < 4; i++) {
> -		int reg = TSL258X_CMD_REG | (TSL258X_ALS_CHAN0LO + i);
> +		int reg = TSL2583_CMD_REG | (TSL2583_ALS_CHAN0LO + i);
>  
>  		ret = i2c_smbus_read_byte_data(chip->client, reg);
>  		if (ret < 0) {
> @@ -200,8 +200,8 @@ static int taos_get_lux(struct iio_dev *indio_dev)
>  	 * we use the bit anyway - don't forget 0x80 - this is a command
>  	 */
>  	ret = i2c_smbus_write_byte(chip->client,
> -				   (TSL258X_CMD_REG | TSL258X_CMD_SPL_FN |
> -				    TSL258X_CMD_ALS_INT_CLR));
> +				   (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",
> @@ -228,7 +228,7 @@ static int taos_get_lux(struct iio_dev *indio_dev)
>  	/* calculate ratio */
>  	ratio = (ch1 << 15) / ch0;
>  	/* convert to unscaled lux using the pointer to the table */
> -	for (p = (struct taos_lux *)taos_device_lux;
> +	for (p = (struct tsl2583_lux *)tsl2583_device_lux;
>  	     p->ratio != 0 && p->ratio < ratio; p++)
>  		;
>  
> @@ -236,11 +236,11 @@ static int taos_get_lux(struct iio_dev *indio_dev)
>  		lux = 0;
>  	} else {
>  		ch0lux = ((ch0 * p->ch0) +
> -			  (gainadj[chip->taos_settings.als_gain].ch0 >> 1))
> -			 / gainadj[chip->taos_settings.als_gain].ch0;
> +			  (gainadj[chip->als_settings.als_gain].ch0 >> 1))
> +			 / gainadj[chip->als_settings.als_gain].ch0;
>  		ch1lux = ((ch1 * p->ch1) +
> -			  (gainadj[chip->taos_settings.als_gain].ch1 >> 1))
> -			 / gainadj[chip->taos_settings.als_gain].ch1;
> +			  (gainadj[chip->als_settings.als_gain].ch1 >> 1))
> +			 / gainadj[chip->als_settings.als_gain].ch1;
>  		lux = ch0lux - ch1lux;
>  	}
>  
> @@ -261,7 +261,7 @@ static int taos_get_lux(struct iio_dev *indio_dev)
>  			chip->als_time_scale;
>  
>  	/* Adjust for active gain scale.
> -	 * The taos_device_lux tables above have a factor of 8192 built in,
> +	 * 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.
>  	 * Apply user-specified gain before shifting right to retain precision.
> @@ -269,13 +269,13 @@ static int taos_get_lux(struct iio_dev *indio_dev)
>  	 * Then go back to 32 bits before division to avoid using div_u64().
>  	 */
>  	lux64 = lux;
> -	lux64 = lux64 * chip->taos_settings.als_gain_trim;
> +	lux64 = lux64 * chip->als_settings.als_gain_trim;
>  	lux64 >>= 13;
>  	lux = lux64;
>  	lux = (lux + 500) / 1000;
> -	if (lux > TSL258X_LUX_CALC_OVER_FLOW) { /* check for overflow */
> +	if (lux > TSL2583_LUX_CALC_OVER_FLOW) { /* check for overflow */
>  return_max:
> -		lux = TSL258X_LUX_CALC_OVER_FLOW;
> +		lux = TSL2583_LUX_CALC_OVER_FLOW;
>  	}
>  
>  	/* Update the structure with the latest VALID lux. */
> @@ -291,7 +291,7 @@ static int taos_get_lux(struct iio_dev *indio_dev)
>   * to derive actual lux).
>   * Return updated gain_trim value.
>   */
> -static int taos_als_calibrate(struct iio_dev *indio_dev)
> +static int tsl2583_als_calibrate(struct iio_dev *indio_dev)
>  {
>  	struct tsl2583_chip *chip = iio_priv(indio_dev);
>  	unsigned int gain_trim_val;
> @@ -299,7 +299,7 @@ static int taos_als_calibrate(struct iio_dev *indio_dev)
>  	int lux_val;
>  
>  	ret = i2c_smbus_read_byte_data(chip->client,
> -				       TSL258X_CMD_REG | TSL258X_CNTRL);
> +				       TSL2583_CMD_REG | TSL2583_CNTRL);
>  	if (ret < 0) {
>  		dev_err(&chip->client->dev,
>  			"%s: failed to read from the CNTRL register\n",
> @@ -307,26 +307,26 @@ static int taos_als_calibrate(struct iio_dev *indio_dev)
>  		return ret;
>  	}
>  
> -	if ((ret & (TSL258X_CNTL_ADC_ENBL | TSL258X_CNTL_PWR_ON))
> -			!= (TSL258X_CNTL_ADC_ENBL | TSL258X_CNTL_PWR_ON)) {
> +	if ((ret & (TSL2583_CNTL_ADC_ENBL | TSL2583_CNTL_PWR_ON))
> +			!= (TSL2583_CNTL_ADC_ENBL | TSL2583_CNTL_PWR_ON)) {
>  		dev_err(&chip->client->dev,
>  			"%s: Device is not powered on and/or ADC is not enabled\n",
>  			__func__);
>  		return -EINVAL;
> -	} else if ((ret & TSL258X_STA_ADC_VALID) != TSL258X_STA_ADC_VALID) {
> +	} else if ((ret & TSL2583_STA_ADC_VALID) != TSL2583_STA_ADC_VALID) {
>  		dev_err(&chip->client->dev,
>  			"%s: The two ADC channels have not completed an integration cycle\n",
>  			__func__);
>  		return -ENODATA;
>  	}
> -	lux_val = taos_get_lux(indio_dev);
> +	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->taos_settings.als_cal_target)
> -			* chip->taos_settings.als_gain_trim) / 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,
> @@ -334,7 +334,7 @@ static int taos_als_calibrate(struct iio_dev *indio_dev)
>  			__func__, gain_trim_val);
>  		return -ENODATA;
>  	}
> -	chip->taos_settings.als_gain_trim = (int)gain_trim_val;
> +	chip->als_settings.als_gain_trim = (int)gain_trim_val;
>  
>  	return (int)gain_trim_val;
>  }
> @@ -345,7 +345,7 @@ static int tsl2583_set_als_time(struct tsl2583_chip *chip)
>  	u8 val;
>  
>  	/* determine als integration register */
> -	als_count = (chip->taos_settings.als_time * 100 + 135) / 270;
> +	als_count = (chip->als_settings.als_time * 100 + 135) / 270;
>  	if (!als_count)
>  		als_count = 1; /* ensure at least one cycle */
>  
> @@ -354,7 +354,7 @@ static int tsl2583_set_als_time(struct tsl2583_chip *chip)
>  
>  	val = 256 - als_count;
>  	ret = i2c_smbus_write_byte_data(chip->client,
> -					TSL258X_CMD_REG | TSL258X_ALS_TIME,
> +					TSL2583_CMD_REG | TSL2583_ALS_TIME,
>  					val);
>  	if (ret < 0) {
>  		dev_err(&chip->client->dev, "%s: failed to set the als time to %d\n",
> @@ -373,14 +373,14 @@ static int tsl2583_set_als_gain(struct tsl2583_chip *chip)
>  {
>  	int ret;
>  
> -	/* Set the gain based on taos_settings struct */
> +	/* Set the gain based on als_settings struct */
>  	ret = i2c_smbus_write_byte_data(chip->client,
> -					TSL258X_CMD_REG | TSL258X_GAIN,
> -					chip->taos_settings.als_gain);
> +					TSL2583_CMD_REG | TSL2583_GAIN,
> +					chip->als_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);
> +			chip->als_settings.als_gain);
>  
>  	return ret;
>  }
> @@ -390,7 +390,7 @@ static int tsl2583_set_power_state(struct tsl2583_chip *chip, u8 state)
>  	int ret;
>  
>  	ret = i2c_smbus_write_byte_data(chip->client,
> -					TSL258X_CMD_REG | TSL258X_CNTRL, state);
> +					TSL2583_CMD_REG | TSL2583_CNTRL, state);
>  	if (ret < 0)
>  		dev_err(&chip->client->dev,
>  			"%s: failed to set the power state to %d\n", __func__,
> @@ -409,12 +409,12 @@ static int tsl2583_chip_init_and_power_on(struct iio_dev *indio_dev)
>  	int ret;
>  
>  	/* Power on the device; ADC off. */
> -	ret = tsl2583_set_power_state(chip, TSL258X_CNTL_PWR_ON);
> +	ret = tsl2583_set_power_state(chip, TSL2583_CNTL_PWR_ON);
>  	if (ret < 0)
>  		return ret;
>  
>  	ret = i2c_smbus_write_byte_data(chip->client,
> -					TSL258X_CMD_REG | TSL258X_INTERRUPT,
> +					TSL2583_CMD_REG | TSL2583_INTERRUPT,
>  					TSL2583_INTERRUPT_DISABLED);
>  	if (ret < 0) {
>  		dev_err(&chip->client->dev,
> @@ -432,8 +432,8 @@ static int tsl2583_chip_init_and_power_on(struct iio_dev *indio_dev)
>  
>  	usleep_range(3000, 3500);
>  
> -	ret = tsl2583_set_power_state(chip, TSL258X_CNTL_PWR_ON |
> -					    TSL258X_CNTL_ADC_ENBL);
> +	ret = tsl2583_set_power_state(chip, TSL2583_CNTL_PWR_ON |
> +					    TSL2583_CNTL_ADC_ENBL);
>  	if (ret < 0)
>  		return ret;
>  
> @@ -453,7 +453,7 @@ static ssize_t in_illuminance_input_target_show(struct device *dev,
>  	int ret;
>  
>  	mutex_lock(&chip->als_mutex);
> -	ret = sprintf(buf, "%d\n", chip->taos_settings.als_cal_target);
> +	ret = sprintf(buf, "%d\n", chip->als_settings.als_cal_target);
>  	mutex_unlock(&chip->als_mutex);
>  
>  	return ret;
> @@ -471,7 +471,7 @@ static ssize_t in_illuminance_input_target_store(struct device *dev,
>  		return -EINVAL;
>  
>  	mutex_lock(&chip->als_mutex);
> -	chip->taos_settings.als_cal_target = value;
> +	chip->als_settings.als_cal_target = value;
>  	mutex_unlock(&chip->als_mutex);
>  
>  	return len;
> @@ -495,7 +495,7 @@ static ssize_t in_illuminance_calibrate_store(struct device *dev,
>  		goto done;
>  	}
>  
> -	ret = taos_als_calibrate(indio_dev);
> +	ret = tsl2583_als_calibrate(indio_dev);
>  	if (ret < 0)
>  		goto done;
>  
> @@ -513,12 +513,12 @@ static ssize_t in_illuminance_lux_table_show(struct device *dev,
>  	int i;
>  	int offset = 0;
>  
> -	for (i = 0; i < ARRAY_SIZE(taos_device_lux); i++) {
> +	for (i = 0; i < ARRAY_SIZE(tsl2583_device_lux); i++) {
>  		offset += sprintf(buf + offset, "%u,%u,%u,",
> -				  taos_device_lux[i].ratio,
> -				  taos_device_lux[i].ch0,
> -				  taos_device_lux[i].ch1);
> -		if (taos_device_lux[i].ratio == 0) {
> +				  tsl2583_device_lux[i].ratio,
> +				  tsl2583_device_lux[i].ch0,
> +				  tsl2583_device_lux[i].ch1);
> +		if (tsl2583_device_lux[i].ratio == 0) {
>  			/*
>  			 * We just printed the first "0" entry.
>  			 * Now get rid of the extra "," and break.
> @@ -532,7 +532,7 @@ 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)
> +#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,
> @@ -540,7 +540,7 @@ 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(taos_device_lux) * 3 + 1];
> +	int value[ARRAY_SIZE(tsl2583_device_lux) * 3 + 1];
>  	int n, ret = -EINVAL;
>  
>  	mutex_lock(&chip->als_mutex);
> @@ -566,8 +566,8 @@ static ssize_t in_illuminance_lux_table_store(struct device *dev,
>  	}
>  
>  	/* Zero out the table */
> -	memset(taos_device_lux, 0, sizeof(taos_device_lux));
> -	memcpy(taos_device_lux, &value[1], (value[0] * 4));
> +	memset(tsl2583_device_lux, 0, sizeof(tsl2583_device_lux));
> +	memcpy(tsl2583_device_lux, &value[1], (value[0] * 4));
>  
>  	ret = len;
>  
> @@ -636,7 +636,7 @@ static int tsl2583_read_raw(struct iio_dev *indio_dev,
>  	switch (mask) {
>  	case IIO_CHAN_INFO_RAW:
>  		if (chan->type == IIO_LIGHT) {
> -			ret = taos_get_lux(indio_dev);
> +			ret = tsl2583_get_lux(indio_dev);
>  			if (ret < 0)
>  				goto read_done;
>  
> @@ -659,7 +659,7 @@ static int tsl2583_read_raw(struct iio_dev *indio_dev,
>  		break;
>  	case IIO_CHAN_INFO_PROCESSED:
>  		if (chan->type == IIO_LIGHT) {
> -			ret = taos_get_lux(indio_dev);
> +			ret = tsl2583_get_lux(indio_dev);
>  			if (ret < 0)
>  				goto read_done;
>  
> @@ -669,20 +669,20 @@ static int tsl2583_read_raw(struct iio_dev *indio_dev,
>  		break;
>  	case IIO_CHAN_INFO_CALIBBIAS:
>  		if (chan->type == IIO_LIGHT) {
> -			*val = chip->taos_settings.als_gain_trim;
> +			*val = chip->als_settings.als_gain_trim;
>  			ret = IIO_VAL_INT;
>  		}
>  		break;
>  	case IIO_CHAN_INFO_CALIBSCALE:
>  		if (chan->type == IIO_LIGHT) {
> -			*val = gainadj[chip->taos_settings.als_gain].mean;
> +			*val = gainadj[chip->als_settings.als_gain].mean;
>  			ret = IIO_VAL_INT;
>  		}
>  		break;
>  	case IIO_CHAN_INFO_INT_TIME:
>  		if (chan->type == IIO_LIGHT) {
>  			*val = 0;
> -			*val2 = chip->taos_settings.als_time;
> +			*val2 = chip->als_settings.als_time;
>  			ret = IIO_VAL_INT_PLUS_MICRO;
>  		}
>  		break;
> @@ -713,7 +713,7 @@ static int tsl2583_write_raw(struct iio_dev *indio_dev,
>  	switch (mask) {
>  	case IIO_CHAN_INFO_CALIBBIAS:
>  		if (chan->type == IIO_LIGHT) {
> -			chip->taos_settings.als_gain_trim = val;
> +			chip->als_settings.als_gain_trim = val;
>  			ret = 0;
>  		}
>  		break;
> @@ -723,7 +723,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;
> +					chip->als_settings.als_gain = i;
>  					ret = tsl2583_set_als_gain(chip);
>  					break;
>  				}
> @@ -733,7 +733,7 @@ static int tsl2583_write_raw(struct iio_dev *indio_dev,
>  	case IIO_CHAN_INFO_INT_TIME:
>  		if (chan->type == IIO_LIGHT && !val && val2 >= 50 &&
>  		    val2 <= 650 && !(val2 % 50)) {
> -			chip->taos_settings.als_time = val2;
> +			chip->als_settings.als_time = val2;
>  			ret = tsl2583_set_als_time(chip);
>  		}
>  		break;
> @@ -758,8 +758,8 @@ static const struct iio_info tsl2583_info = {
>   * Client probe function - When a valid device is found, the driver's device
>   * data structure is updated, and initialization completes successfully.
>   */
> -static int taos_probe(struct i2c_client *clientp,
> -		      const struct i2c_device_id *idp)
> +static int tsl2583_probe(struct i2c_client *clientp,
> +			 const struct i2c_device_id *idp)
>  {
>  	int ret;
>  	struct tsl2583_chip *chip;
> @@ -783,7 +783,7 @@ static int taos_probe(struct i2c_client *clientp,
>  	chip->suspended = true;
>  
>  	ret = i2c_smbus_read_byte_data(clientp,
> -				       TSL258X_CMD_REG | TSL258X_CHIPID);
> +				       TSL2583_CMD_REG | TSL2583_CHIPID);
>  	if (ret < 0) {
>  		dev_err(&clientp->dev,
>  			"%s: failed to read the chip ID register\n", __func__);
> @@ -810,7 +810,7 @@ static int taos_probe(struct i2c_client *clientp,
>  	}
>  
>  	/* Load up the V2 defaults (these are hard coded defaults for now) */
> -	taos_defaults(chip);
> +	tsl2583_defaults(chip);
>  
>  	/* Make sure the chip is on */
>  	ret = tsl2583_chip_init_and_power_on(indio_dev);
> @@ -821,7 +821,7 @@ static int taos_probe(struct i2c_client *clientp,
>  	return 0;
>  }
>  
> -static int __maybe_unused taos_suspend(struct device *dev)
> +static int __maybe_unused tsl2583_suspend(struct device *dev)
>  {
>  	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
>  	struct tsl2583_chip *chip = iio_priv(indio_dev);
> @@ -829,14 +829,14 @@ static int __maybe_unused taos_suspend(struct device *dev)
>  
>  	mutex_lock(&chip->als_mutex);
>  
> -	ret = tsl2583_set_power_state(chip, TSL258X_CNTL_PWR_OFF);
> +	ret = tsl2583_set_power_state(chip, TSL2583_CNTL_PWR_OFF);
>  	chip->suspended = true;
>  
>  	mutex_unlock(&chip->als_mutex);
>  	return ret;
>  }
>  
> -static int __maybe_unused taos_resume(struct device *dev)
> +static int __maybe_unused tsl2583_resume(struct device *dev)
>  {
>  	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
>  	struct tsl2583_chip *chip = iio_priv(indio_dev);
> @@ -850,35 +850,35 @@ static int __maybe_unused taos_resume(struct device *dev)
>  	return ret;
>  }
>  
> -static SIMPLE_DEV_PM_OPS(taos_pm_ops, taos_suspend, taos_resume);
> +static SIMPLE_DEV_PM_OPS(tsl2583_pm_ops, tsl2583_suspend, tsl2583_resume);
>  
> -static struct i2c_device_id taos_idtable[] = {
> +static struct i2c_device_id tsl2583_idtable[] = {
>  	{ "tsl2580", 0 },
>  	{ "tsl2581", 1 },
>  	{ "tsl2583", 2 },
>  	{}
>  };
> -MODULE_DEVICE_TABLE(i2c, taos_idtable);
> +MODULE_DEVICE_TABLE(i2c, tsl2583_idtable);
>  
> -static const struct of_device_id taos2583_of_match[] = {
> +static const struct of_device_id tsl2583_of_match[] = {
>  	{ .compatible = "amstaos,tsl2580", },
>  	{ .compatible = "amstaos,tsl2581", },
>  	{ .compatible = "amstaos,tsl2583", },
>  	{ },
>  };
> -MODULE_DEVICE_TABLE(of, taos2583_of_match);
> +MODULE_DEVICE_TABLE(of, tsl2583_of_match);
>  
>  /* Driver definition */
> -static struct i2c_driver taos_driver = {
> +static struct i2c_driver tsl2583_driver = {
>  	.driver = {
>  		.name = "tsl2583",
> -		.pm = &taos_pm_ops,
> -		.of_match_table = taos2583_of_match,
> +		.pm = &tsl2583_pm_ops,
> +		.of_match_table = tsl2583_of_match,
>  	},
> -	.id_table = taos_idtable,
> -	.probe = taos_probe,
> +	.id_table = tsl2583_idtable,
> +	.probe = tsl2583_probe,
>  };
> -module_i2c_driver(taos_driver);
> +module_i2c_driver(tsl2583_driver);
>  
>  MODULE_AUTHOR("J. August Brenner<jbrenner@taosinc.com>");
>  MODULE_DESCRIPTION("TAOS tsl2583 ambient light sensor driver");
> 

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v4 09/26] staging: iio: tsl2583: fix alignment of #define values
  2016-11-12 18:19 ` [PATCH v4 09/26] staging: iio: tsl2583: fix alignment of #define values Brian Masney
@ 2016-11-13 12:13   ` Jonathan Cameron
  0 siblings, 0 replies; 54+ messages in thread
From: Jonathan Cameron @ 2016-11-13 12:13 UTC (permalink / raw)
  To: Brian Masney, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

On 12/11/16 18:19, Brian Masney wrote:
> 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>
Applied.
> ---
>  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 5a82a26..d482a84 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
>  
> 

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v4 10/26] staging: iio: tsl2583: fix comparison between signed and unsigned integers
  2016-11-12 18:19 ` [PATCH v4 10/26] staging: iio: tsl2583: fix comparison between signed and unsigned integers Brian Masney
@ 2016-11-13 12:14   ` Jonathan Cameron
  0 siblings, 0 replies; 54+ messages in thread
From: Jonathan Cameron @ 2016-11-13 12:14 UTC (permalink / raw)
  To: Brian Masney, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

On 12/11/16 18:19, Brian Masney wrote:
> 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>
Applied.
> ---
>  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 d482a84..be3cbae 100644
> --- a/drivers/staging/iio/light/tsl2583.c
> +++ b/drivers/staging/iio/light/tsl2583.c
> @@ -510,7 +510,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++) {
> @@ -541,7 +541,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);
>  
> @@ -719,7 +720,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) {
> 

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v4 11/26] staging: iio: tsl2583: change newlines to improve readability
  2016-11-12 18:19 ` [PATCH v4 11/26] staging: iio: tsl2583: change newlines to improve readability Brian Masney
@ 2016-11-13 12:15   ` Jonathan Cameron
  0 siblings, 0 replies; 54+ messages in thread
From: Jonathan Cameron @ 2016-11-13 12:15 UTC (permalink / raw)
  To: Brian Masney, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

On 12/11/16 18:19, Brian Masney wrote:
> 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>
Applied
> ---
>  drivers/staging/iio/light/tsl2583.c | 14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
> index be3cbae..8303753 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;
> @@ -319,21 +321,23 @@ static int tsl2583_als_calibrate(struct iio_dev *indio_dev)
>  			__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: 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;
> @@ -529,6 +533,7 @@ static ssize_t in_illuminance_lux_table_show(struct device *dev,
>  	}
>  
>  	offset += sprintf(buf + offset, "\n");
> +
>  	return offset;
>  }
>  
> @@ -776,6 +781,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);
> @@ -803,6 +809,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",
> @@ -819,6 +826,7 @@ static int tsl2583_probe(struct i2c_client *clientp,
>  		return ret;
>  
>  	dev_info(&clientp->dev, "Light sensor found.\n");
> +
>  	return 0;
>  }
>  
> @@ -834,6 +842,7 @@ static int __maybe_unused tsl2583_suspend(struct device *dev)
>  	chip->suspended = true;
>  
>  	mutex_unlock(&chip->als_mutex);
> +
>  	return ret;
>  }
>  
> @@ -848,6 +857,7 @@ static int __maybe_unused tsl2583_resume(struct device *dev)
>  	ret = tsl2583_chip_init_and_power_on(indio_dev);
>  
>  	mutex_unlock(&chip->als_mutex);
> +
>  	return ret;
>  }
>  
> 

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v4 12/26] staging: iio: tsl2583: combine sysfs documentation
  2016-11-12 18:19 ` [PATCH v4 12/26] staging: iio: tsl2583: combine sysfs documentation Brian Masney
@ 2016-11-13 12:16   ` Jonathan Cameron
  0 siblings, 0 replies; 54+ messages in thread
From: Jonathan Cameron @ 2016-11-13 12:16 UTC (permalink / raw)
  To: Brian Masney, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

On 12/11/16 18:19, Brian Masney wrote:
> 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>
Applied.
> ---
>  .../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.
> 

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v4 13/26] staging: iio: tsl2583: fix multiline comment syntax
  2016-11-12 18:19 ` [PATCH v4 13/26] staging: iio: tsl2583: fix multiline comment syntax Brian Masney
@ 2016-11-13 12:17   ` Jonathan Cameron
  0 siblings, 0 replies; 54+ messages in thread
From: Jonathan Cameron @ 2016-11-13 12:17 UTC (permalink / raw)
  To: Brian Masney, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

On 12/11/16 18:19, Brian Masney wrote:
> 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>
Applied.
> ---
>  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 8303753..52a39a6 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.
> @@ -553,7 +556,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.
> 

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v4 14/26] staging: iio: tsl2583: updated code comment to match what the code does
  2016-11-12 18:19 ` [PATCH v4 14/26] staging: iio: tsl2583: updated code comment to match what the code does Brian Masney
@ 2016-11-13 12:18   ` Jonathan Cameron
  0 siblings, 0 replies; 54+ messages in thread
From: Jonathan Cameron @ 2016-11-13 12:18 UTC (permalink / raw)
  To: Brian Masney, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

On 12/11/16 18:19, Brian Masney wrote:
> 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. It also
> clarifies the comment about why 0 is returned.
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>
Applied.
> ---
>  drivers/staging/iio/light/tsl2583.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
> index 52a39a6..dbb7f6a 100644
> --- a/drivers/staging/iio/light/tsl2583.c
> +++ b/drivers/staging/iio/light/tsl2583.c
> @@ -221,7 +221,11 @@ static int tsl2583_get_lux(struct iio_dev *indio_dev)
>  		goto return_max;
>  
>  	if (!ch0) {
> -		/* have no data, so return LAST VALUE */
> +		/*
> +		 * The sensor appears to be in total darkness so set the
> +		 * calculated lux to 0 and return early to avoid a division by
> +		 * zero below when calculating the ratio.
> +		 */
>  		ret = 0;
>  		chip->als_cur_info.lux = 0;
>  		goto done;
> 

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v4 15/26] staging: iio: tsl2583: moved code block inside else statement
  2016-11-12 18:19 ` [PATCH v4 15/26] staging: iio: tsl2583: moved code block inside else statement Brian Masney
@ 2016-11-13 12:20   ` Jonathan Cameron
  0 siblings, 0 replies; 54+ messages in thread
From: Jonathan Cameron @ 2016-11-13 12:20 UTC (permalink / raw)
  To: Brian Masney, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

On 12/11/16 18:19, Brian Masney wrote:
> 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>
Applied.
> ---
>  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 dbb7f6a..bcdf095 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) {
> @@ -242,22 +240,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 */
> 

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v4 16/26] staging: iio: tsl2583: change tsl2583_als_calibrate() to return 0 on success
  2016-11-12 18:19 ` [PATCH v4 16/26] staging: iio: tsl2583: change tsl2583_als_calibrate() to return 0 on success Brian Masney
@ 2016-11-13 12:21   ` Jonathan Cameron
  0 siblings, 0 replies; 54+ messages in thread
From: Jonathan Cameron @ 2016-11-13 12:21 UTC (permalink / raw)
  To: Brian Masney, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

On 12/11/16 18:19, Brian Masney wrote:
> 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>
Applied.
> ---
>  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 bcdf095..fc58074 100644
> --- a/drivers/staging/iio/light/tsl2583.c
> +++ b/drivers/staging/iio/light/tsl2583.c
> @@ -348,7 +348,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)
> 

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v4 17/26] staging: iio: tsl2583: remove unnecessary parentheses
  2016-11-12 18:19 ` [PATCH v4 17/26] staging: iio: tsl2583: remove unnecessary parentheses Brian Masney
@ 2016-11-13 12:22   ` Jonathan Cameron
  0 siblings, 0 replies; 54+ messages in thread
From: Jonathan Cameron @ 2016-11-13 12:22 UTC (permalink / raw)
  To: Brian Masney, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

On 12/11/16 18:19, Brian Masney wrote:
> 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>
Applied.
> ---
>  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 fc58074..fe9d777 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,
>  			__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;
> @@ -582,7 +582,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;
>  
> 

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v4 18/26] staging: iio: tsl2583: don't assume an unsigned int is 32 bits
  2016-11-12 18:19 ` [PATCH v4 18/26] staging: iio: tsl2583: don't assume an unsigned int is 32 bits Brian Masney
@ 2016-11-13 12:23   ` Jonathan Cameron
  0 siblings, 0 replies; 54+ messages in thread
From: Jonathan Cameron @ 2016-11-13 12:23 UTC (permalink / raw)
  To: Brian Masney, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

On 12/11/16 18:19, Brian Masney wrote:
> in_illuminance_lux_table_store assumes that an unsigned int is 32 bits.
> Replace this with sizeof(value[1]).
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>
Applied.
> ---
>  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 fe9d777..78967dc 100644
> --- a/drivers/staging/iio/light/tsl2583.c
> +++ b/drivers/staging/iio/light/tsl2583.c
> @@ -582,7 +582,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(value[1]));
>  
>  	ret = len;
>  
> 

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v4 19/26] staging: iio: tsl2583: move from a global to a per device lux table
  2016-11-12 18:19 ` [PATCH v4 19/26] staging: iio: tsl2583: move from a global to a per device lux table Brian Masney
@ 2016-11-13 12:25   ` Jonathan Cameron
  0 siblings, 0 replies; 54+ messages in thread
From: Jonathan Cameron @ 2016-11-13 12:25 UTC (permalink / raw)
  To: Brian Masney, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

On 12/11/16 18:19, 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>
Applied.
> ---
>  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 78967dc..3818ffa 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
> @@ -233,7 +242,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++)
>  		;
>  
> @@ -270,7 +279,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.
> @@ -522,15 +531,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.
> @@ -545,15 +556,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;
>  
> @@ -568,10 +578,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) {
> @@ -581,8 +591,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(value[1]));
> +	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(value[1]));
>  
>  	ret = len;
>  
> 

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v4 20/26] staging: iio: tsl2583: add tsl2583 to list of supported devices in the header
  2016-11-12 18:19 ` [PATCH v4 20/26] staging: iio: tsl2583: add tsl2583 to list of supported devices in the header Brian Masney
@ 2016-11-13 12:28   ` Jonathan Cameron
  0 siblings, 0 replies; 54+ messages in thread
From: Jonathan Cameron @ 2016-11-13 12:28 UTC (permalink / raw)
  To: Brian Masney, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

On 12/11/16 18:19, Brian Masney wrote:
> The header only listed the tsl2580 and tsl2581 devices as supported by
> this driver. This patch adds the tsl2583 since it is also supported by
> this driver.
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>
Applied.
> ---
>  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 3818ffa..806cb0a 100644
> --- a/drivers/staging/iio/light/tsl2583.c
> +++ b/drivers/staging/iio/light/tsl2583.c
> @@ -1,6 +1,6 @@
>  /*
>   * Device driver for monitoring ambient light intensity (lux)
> - * within the TAOS tsl258x family of devices (tsl2580, tsl2581).
> + * within the TAOS tsl258x family of devices (tsl2580, tsl2581, tsl2583).
>   *
>   * Copyright (c) 2011, TAOS Corporation.
>   *
> 

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v4 21/26] staging: iio: tsl2583: clarified comment about clearing interrupts
  2016-11-12 18:19 ` [PATCH v4 21/26] staging: iio: tsl2583: clarified comment about clearing interrupts Brian Masney
@ 2016-11-13 12:28   ` Jonathan Cameron
  0 siblings, 0 replies; 54+ messages in thread
From: Jonathan Cameron @ 2016-11-13 12:28 UTC (permalink / raw)
  To: Brian Masney, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

On 12/11/16 18:19, Brian Masney wrote:
> The comment that describes the code that clears the interrupt bit was
> vague and didn't provide much value. This patch adds more detail about
> why that bit needs to be cleared.
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>
Applied.
> ---
>  drivers/staging/iio/light/tsl2583.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
> index 806cb0a..727ed49 100644
> --- a/drivers/staging/iio/light/tsl2583.c
> +++ b/drivers/staging/iio/light/tsl2583.c
> @@ -205,8 +205,9 @@ static int tsl2583_get_lux(struct iio_dev *indio_dev)
>  	}
>  
>  	/*
> -	 * clear status, really interrupt status (interrupts are off), but
> -	 * we use the bit anyway - don't forget 0x80 - this is a command
> +	 * Clear the pending interrupt status bit on the chip to allow the next
> +	 * integration cycle to start. This has to be done even though this
> +	 * driver currently does not support interrupts.
>  	 */
>  	ret = i2c_smbus_write_byte(chip->client,
>  				   (TSL2583_CMD_REG | TSL2583_CMD_SPL_FN |
> 

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v4 22/26] staging: iio: tsl2583: remove comment for tsl2583_probe()
  2016-11-12 18:19 ` [PATCH v4 22/26] staging: iio: tsl2583: remove comment for tsl2583_probe() Brian Masney
@ 2016-11-13 12:29   ` Jonathan Cameron
  0 siblings, 0 replies; 54+ messages in thread
From: Jonathan Cameron @ 2016-11-13 12:29 UTC (permalink / raw)
  To: Brian Masney, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

On 12/11/16 18:19, Brian Masney wrote:
> The comment for tsl2583_probe() does not provide any useful value.
> This patch removes the comment.
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>
Applied 
> ---
>  drivers/staging/iio/light/tsl2583.c | 4 ----
>  1 file changed, 4 deletions(-)
> 
> diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
> index 727ed49..9db191f 100644
> --- a/drivers/staging/iio/light/tsl2583.c
> +++ b/drivers/staging/iio/light/tsl2583.c
> @@ -782,10 +782,6 @@ static const struct iio_info tsl2583_info = {
>  	.write_raw = tsl2583_write_raw,
>  };
>  
> -/*
> - * Client probe function - When a valid device is found, the driver's device
> - * data structure is updated, and initialization completes successfully.
> - */
>  static int tsl2583_probe(struct i2c_client *clientp,
>  			 const struct i2c_device_id *idp)
>  {
> 

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v4 23/26] staging: iio: tsl2583: remove unnecessary memset call
  2016-11-12 18:19 ` [PATCH v4 23/26] staging: iio: tsl2583: remove unnecessary memset call Brian Masney
@ 2016-11-13 12:29   ` Jonathan Cameron
  0 siblings, 0 replies; 54+ messages in thread
From: Jonathan Cameron @ 2016-11-13 12:29 UTC (permalink / raw)
  To: Brian Masney, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

On 12/11/16 18:19, Brian Masney wrote:
> The entries in the lux table (als_device_lux) can be updated via sysfs
> through the function in_illuminance_lux_table_store(). The last row in
> the table must be terminated with values that are zero. The sysfs code
> already ensures that the last row is all zeros. The call to memset to
> clear out the table is not needed so this patch removes the unnecessary
> call.
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>
Applied.
> ---
>  drivers/staging/iio/light/tsl2583.c | 3 ---
>  1 file changed, 3 deletions(-)
> 
> diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
> index 9db191f..712f753 100644
> --- a/drivers/staging/iio/light/tsl2583.c
> +++ b/drivers/staging/iio/light/tsl2583.c
> @@ -591,9 +591,6 @@ static ssize_t in_illuminance_lux_table_store(struct device *dev,
>  		goto done;
>  	}
>  
> -	/* Zero out the table */
> -	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(value[1]));
>  
> 

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v4 24/26] staging: iio: tsl2583: remove unnecessary variable initialization
  2016-11-12 18:19 ` [PATCH v4 24/26] staging: iio: tsl2583: remove unnecessary variable initialization Brian Masney
@ 2016-11-13 12:30   ` Jonathan Cameron
  0 siblings, 0 replies; 54+ messages in thread
From: Jonathan Cameron @ 2016-11-13 12:30 UTC (permalink / raw)
  To: Brian Masney, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

On 12/11/16 18:19, Brian Masney wrote:
> The ret variable in tsl2583_suspend() and tsl2583_resume() was
> initialized to 0. This is not necessary so this patch removes the
> initialization.
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>
Applied.
> ---
>  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 712f753..b787952 100644
> --- a/drivers/staging/iio/light/tsl2583.c
> +++ b/drivers/staging/iio/light/tsl2583.c
> @@ -849,7 +849,7 @@ static int __maybe_unused tsl2583_suspend(struct device *dev)
>  {
>  	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
>  	struct tsl2583_chip *chip = iio_priv(indio_dev);
> -	int ret = 0;
> +	int ret;
>  
>  	mutex_lock(&chip->als_mutex);
>  
> @@ -865,7 +865,7 @@ static int __maybe_unused tsl2583_resume(struct device *dev)
>  {
>  	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
>  	struct tsl2583_chip *chip = iio_priv(indio_dev);
> -	int ret = 0;
> +	int ret;
>  
>  	mutex_lock(&chip->als_mutex);
>  
> 

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v4 25/26] staging: iio: tsl2583: add copyright and MODULE_AUTHOR
  2016-11-12 18:19 ` [PATCH v4 25/26] staging: iio: tsl2583: add copyright and MODULE_AUTHOR Brian Masney
@ 2016-11-13 12:35   ` Jonathan Cameron
  0 siblings, 0 replies; 54+ messages in thread
From: Jonathan Cameron @ 2016-11-13 12:35 UTC (permalink / raw)
  To: Brian Masney, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

On 12/11/16 18:19, Brian Masney wrote:
> Add 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.
> 
> The original MODULE_AUTHOR() did not have a space between his name and
> email address. This patch also adds the missing space.
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>
Applied.
> ---
>  drivers/staging/iio/light/tsl2583.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
> index b787952..ca26444 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, tsl2583).
>   *
>   * 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
> @@ -906,6 +907,7 @@ 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>");
> +MODULE_AUTHOR("Brian Masney <masneyb@onstation.org>");
>  MODULE_DESCRIPTION("TAOS tsl2583 ambient light sensor driver");
>  MODULE_LICENSE("GPL");
> 

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v4 26/26] staging: iio: tsl2583: move out of staging
  2016-11-12 18:19 ` [PATCH v4 26/26] staging: iio: tsl2583: move out of staging Brian Masney
@ 2016-11-13 12:57   ` Jonathan Cameron
  2016-11-13 16:18     ` Brian Masney
  0 siblings, 1 reply; 54+ messages in thread
From: Jonathan Cameron @ 2016-11-13 12:57 UTC (permalink / raw)
  To: Brian Masney, linux-iio
  Cc: devel, gregkh, lars, pmeerw, knaack.h, linux-kernel, Jon.Brenner

On 12/11/16 18:19, Brian Masney wrote:
> Move tsl2580, tsl2581, tsl2583 driver out of staging into mainline.
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>
I had another read through on this one.  A few oddites.

I fixed up the indentation one way back in your patch fixing alignment.
Made applying this patch more entertaining than it should have been but
I think got that right in the end.

Can't find myself caring enough about the unused data element in that
id table to hold this patch on that so...

Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to play with it.

Thanks for all your hard work on this!

Jonathan
> ---
>  .../ABI/testing/sysfs-bus-iio-light-tsl2583        |  20 +
>  drivers/iio/light/Kconfig                          |   7 +
>  drivers/iio/light/Makefile                         |   1 +
>  drivers/iio/light/tsl2583.c                        | 913 +++++++++++++++++++++
>  .../light/sysfs-bus-iio-light-tsl2583              |  20 -
>  drivers/staging/iio/light/Kconfig                  |   7 -
>  drivers/staging/iio/light/Makefile                 |   1 -
>  drivers/staging/iio/light/tsl2583.c                | 913 ---------------------
>  8 files changed, 941 insertions(+), 941 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/light/tsl2583.c
> 
> diff --git a/Documentation/ABI/testing/sysfs-bus-iio-light-tsl2583 b/Documentation/ABI/testing/sysfs-bus-iio-light-tsl2583
> new file mode 100644
> index 0000000..a2e1996
> --- /dev/null
> +++ b/Documentation/ABI/testing/sysfs-bus-iio-light-tsl2583
> @@ -0,0 +1,20 @@
> +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/iio/light/Kconfig b/drivers/iio/light/Kconfig
> index d011720..298ea50 100644
> --- a/drivers/iio/light/Kconfig
> +++ b/drivers/iio/light/Kconfig
> @@ -338,6 +338,13 @@ config SENSORS_TSL2563
>  	 This driver can also be built as a module.  If so, the module
>  	 will be called tsl2563.
>  
> +config TSL2583
> +	tristate "TAOS TSL2580, TSL2581 and TSL2583 light-to-digital converters"
> +	depends on I2C
> +	help
> +	 Provides support for the TAOS tsl2580, tsl2581 and tsl2583 devices.
> +	 Access ALS data via iio, 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 15f24c5..4de5200 100644
> --- a/drivers/iio/light/Makefile
> +++ b/drivers/iio/light/Makefile
> @@ -31,6 +31,7 @@ obj-$(CONFIG_SI1145)		+= si1145.o
>  obj-$(CONFIG_STK3310)          += stk3310.o
>  obj-$(CONFIG_TCS3414)		+= tcs3414.o
>  obj-$(CONFIG_TCS3472)		+= tcs3472.o
> +obj-$(CONFIG_TSL2583)		+= tsl2583.o
>  obj-$(CONFIG_TSL4531)		+= tsl4531.o
>  obj-$(CONFIG_US5182D)		+= us5182d.o
>  obj-$(CONFIG_VCNL4000)		+= vcnl4000.o
> diff --git a/drivers/iio/light/tsl2583.c b/drivers/iio/light/tsl2583.c
> new file mode 100644
> index 0000000..ca26444
> --- /dev/null
> +++ b/drivers/iio/light/tsl2583.c
> @@ -0,0 +1,913 @@
> +/*
> + * Device driver for monitoring ambient light intensity (lux)
> + * within the TAOS tsl258x family of devices (tsl2580, tsl2581, tsl2583).
> + *
> + * 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
> + * 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 <linux/kernel.h>
> +#include <linux/i2c.h>
> +#include <linux/errno.h>
> +#include <linux/delay.h>
> +#include <linux/string.h>
> +#include <linux/mutex.h>
> +#include <linux/unistd.h>
> +#include <linux/slab.h>
> +#include <linux/module.h>
> +#include <linux/iio/iio.h>
> +#include <linux/iio/sysfs.h>
> +
> +/* Device Registers and Masks */
> +#define TSL2583_CNTRL			0x00
> +#define TSL2583_ALS_TIME		0X01
> +#define TSL2583_INTERRUPT		0x02
> +#define TSL2583_GAIN			0x07
> +#define TSL2583_REVID			0x11
> +#define TSL2583_CHIPID			0x12
> +#define TSL2583_ALS_CHAN0LO		0x14
> +#define TSL2583_ALS_CHAN0HI		0x15
> +#define TSL2583_ALS_CHAN1LO		0x16
> +#define TSL2583_ALS_CHAN1HI		0x17
> +#define TSL2583_TMR_LO			0x18
> +#define TSL2583_TMR_HI			0x19
> +
> +/* tsl2583 cmd reg masks */
> +#define TSL2583_CMD_REG			0x80
> +#define TSL2583_CMD_SPL_FN		0x60
> +#define TSL2583_CMD_ALS_INT_CLR		0x01
> +
> +/* tsl2583 cntrl reg masks */
> +#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
> +
> +/* Lux calculation constants */
> +#define	TSL2583_LUX_CALC_OVER_FLOW	65535
Indentation is a little odd here... Looks like a tab snuck in where
the rest were single spaces.
> +
> +#define TSL2583_INTERRUPT_DISABLED	0x00
> +
> +#define TSL2583_CHIP_ID			0x90
> +#define TSL2583_CHIP_ID_MASK		0xf0
> +
> +/* Per-device data */
> +struct tsl2583_als_info {
> +	u16 als_ch0;
> +	u16 als_ch1;
> +	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 {
> +	struct mutex als_mutex;
> +	struct i2c_client *client;
> +	struct tsl2583_als_info als_cur_info;
> +	struct tsl2583_settings als_settings;
> +	int als_time_scale;
> +	int als_saturation;
> +	bool suspended;
> +};
> +
> +struct gainadj {
> +	s16 ch0;
> +	s16 ch1;
> +	s16 mean;
> +};
> +
> +/* Index = (0 - 3) Used to validate the gain selection index */
> +static const struct gainadj gainadj[] = {
> +	{ 1, 1, 1 },
> +	{ 8, 8, 8 },
> +	{ 16, 16, 16 },
> +	{ 107, 115, 111 }
> +};
> +
> +/*
> + * Provides initial operational parameter defaults.
> + * These defaults may be changed through the device's sysfs files.
> + */
> +static void tsl2583_defaults(struct tsl2583_chip *chip)
> +{
> +	/*
> +	 * The integration time must be a multiple of 50ms and within the
> +	 * range [50, 600] ms.
> +	 */
> +	chip->als_settings.als_time = 100;
> +
> +	/*
> +	 * This is an index into the gainadj table. Assume clear glass as the
> +	 * default.
> +	 */
> +	chip->als_settings.als_gain = 0;
> +
> +	/* Default gain trim to account for aperture effects */
> +	chip->als_settings.als_gain_trim = 1000;
> +
> +	/* 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));
> +}
> +
> +/*
> + * Reads and calculates current lux value.
> + * The raw ch0 and ch1 values of the ambient light sensed in the last
> + * integration cycle are read from the device.
> + * Time scale factor array values are adjusted based on the integration time.
> + * The raw values are multiplied by a scale factor, and device gain is obtained
> + * using gain index. Limit checks are done next, then the ratio of a multiple
> + * of ch1 value, to the ch0 value, is calculated. The array 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
> + * calculate the lux.
> + */
> +static int tsl2583_get_lux(struct iio_dev *indio_dev)
> +{
> +	u16 ch0, ch1; /* separated ch0/ch1 data from device */
> +	u32 lux; /* raw lux calculated from device data */
> +	u64 lux64;
> +	u32 ratio;
> +	u8 buf[5];
> +	struct tsl2583_lux *p;
> +	struct tsl2583_chip *chip = iio_priv(indio_dev);
> +	int i, ret;
> +
> +	ret = i2c_smbus_read_byte_data(chip->client, TSL2583_CMD_REG);
> +	if (ret < 0) {
> +		dev_err(&chip->client->dev, "%s: failed to read CMD_REG register\n",
> +			__func__);
> +		goto done;
> +	}
> +
> +	/* is data new & valid */
> +	if (!(ret & TSL2583_STA_ADC_INTR)) {
> +		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;
> +	}
> +
> +	for (i = 0; i < 4; i++) {
> +		int reg = TSL2583_CMD_REG | (TSL2583_ALS_CHAN0LO + i);
> +
> +		ret = i2c_smbus_read_byte_data(chip->client, reg);
> +		if (ret < 0) {
> +			dev_err(&chip->client->dev, "%s: failed to read register %x\n",
> +				__func__, reg);
> +			goto done;
> +		}
> +		buf[i] = ret;
> +	}
> +
> +	/*
> +	 * Clear the pending interrupt status bit on the chip to allow the next
> +	 * integration cycle to start. This has to be done even though this
> +	 * driver currently does not support interrupts.
> +	 */
> +	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__);
> +		goto done; /* have no data, so return failure */
> +	}
> +
> +	/* extract ALS/lux data */
> +	ch0 = le16_to_cpup((const __le16 *)&buf[0]);
> +	ch1 = le16_to_cpup((const __le16 *)&buf[2]);
> +
> +	chip->als_cur_info.als_ch0 = ch0;
> +	chip->als_cur_info.als_ch1 = ch1;
> +
> +	if ((ch0 >= chip->als_saturation) || (ch1 >= chip->als_saturation))
> +		goto return_max;
> +
> +	if (!ch0) {
> +		/*
> +		 * The sensor appears to be in total darkness so set the
> +		 * calculated lux to 0 and return early to avoid a division by
> +		 * zero below when calculating the ratio.
> +		 */
> +		ret = 0;
> +		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 *)chip->als_settings.als_device_lux;
> +	     p->ratio != 0 && p->ratio < ratio; p++)
> +		;
> +
> +	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;
> +
> +		/* 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 */
> +	if (chip->als_time_scale == 0)
> +		lux = 0;
> +	else
> +		lux = (lux + (chip->als_time_scale >> 1)) /
> +			chip->als_time_scale;
> +
> +	/*
> +	 * Adjust for active gain scale.
> +	 * 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.
> +	 * Use 64 bits to avoid overflow on multiplication.
> +	 * Then go back to 32 bits before division to avoid using div_u64().
> +	 */
> +	lux64 = lux;
> +	lux64 = lux64 * chip->als_settings.als_gain_trim;
> +	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;
> +	}
> +
> +	/* Update the structure with the latest VALID lux. */
> +	chip->als_cur_info.lux = lux;
> +	ret = lux;
> +
> +done:
> +	return ret;
> +}
> +
> +/*
> + * Obtain single reading and calculate the als_gain_trim (later used
> + * to derive actual lux).
> + * Return updated gain_trim value.
> + */
> +static int tsl2583_als_calibrate(struct iio_dev *indio_dev)
> +{
> +	struct tsl2583_chip *chip = iio_priv(indio_dev);
> +	unsigned int gain_trim_val;
> +	int ret;
> +	int lux_val;
> +
> +	ret = i2c_smbus_read_byte_data(chip->client,
> +				       TSL2583_CMD_REG | TSL2583_CNTRL);
> +	if (ret < 0) {
> +		dev_err(&chip->client->dev,
> +			"%s: failed to read from the CNTRL register\n",
> +			__func__);
> +		return ret;
> +	}
> +
> +	if ((ret & (TSL2583_CNTL_ADC_ENBL | TSL2583_CNTL_PWR_ON))
> +			!= (TSL2583_CNTL_ADC_ENBL | TSL2583_CNTL_PWR_ON)) {
> +		dev_err(&chip->client->dev,
> +			"%s: Device is not powered on and/or ADC is not enabled\n",
> +			__func__);
> +		return -EINVAL;
> +	} else if ((ret & TSL2583_STA_ADC_VALID) != TSL2583_STA_ADC_VALID) {
> +		dev_err(&chip->client->dev,
> +			"%s: The two ADC channels have not completed an integration cycle\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: 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 0;
> +}
> +
> +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->als_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,
> +					TSL2583_CMD_REG | TSL2583_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 als_settings struct */
> +	ret = i2c_smbus_write_byte_data(chip->client,
> +					TSL2583_CMD_REG | TSL2583_GAIN,
> +					chip->als_settings.als_gain);
> +	if (ret < 0)
> +		dev_err(&chip->client->dev,
> +			"%s: failed to set the gain to %d\n", __func__,
> +			chip->als_settings.als_gain);
> +
> +	return ret;
> +}
> +
> +static int tsl2583_set_power_state(struct tsl2583_chip *chip, u8 state)
> +{
> +	int ret;
> +
> +	ret = i2c_smbus_write_byte_data(chip->client,
> +					TSL2583_CMD_REG | TSL2583_CNTRL, state);
> +	if (ret < 0)
> +		dev_err(&chip->client->dev,
> +			"%s: failed to set the power state to %d\n", __func__,
> +			state);
> +
> +	return ret;
> +}
> +
> +/*
> + * Turn the device on.
> + * Configuration must be set before calling this function.
> + */
> +static int tsl2583_chip_init_and_power_on(struct iio_dev *indio_dev)
> +{
> +	struct tsl2583_chip *chip = iio_priv(indio_dev);
> +	int ret;
> +
> +	/* Power on the device; ADC off. */
> +	ret = tsl2583_set_power_state(chip, TSL2583_CNTL_PWR_ON);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = i2c_smbus_write_byte_data(chip->client,
> +					TSL2583_CMD_REG | TSL2583_INTERRUPT,
> +					TSL2583_INTERRUPT_DISABLED);
> +	if (ret < 0) {
> +		dev_err(&chip->client->dev,
> +			"%s: failed to disable interrupts\n", __func__);
> +		return ret;
> +	}
> +
> +	ret = tsl2583_set_als_time(chip);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = tsl2583_set_als_gain(chip);
> +	if (ret < 0)
> +		return ret;
> +
> +	usleep_range(3000, 3500);
> +
> +	ret = tsl2583_set_power_state(chip, TSL2583_CNTL_PWR_ON |
> +					    TSL2583_CNTL_ADC_ENBL);
> +	if (ret < 0)
> +		return ret;
> +
> +	chip->suspended = false;
> +
> +	return ret;
> +}
> +
> +/* Sysfs Interface Functions */
> +
> +static ssize_t in_illuminance_input_target_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);
> +	int ret;
> +
> +	mutex_lock(&chip->als_mutex);
> +	ret = sprintf(buf, "%d\n", chip->als_settings.als_cal_target);
> +	mutex_unlock(&chip->als_mutex);
> +
> +	return ret;
> +}
> +
> +static ssize_t in_illuminance_input_target_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;
> +
> +	if (kstrtoint(buf, 0, &value) || !value)
> +		return -EINVAL;
> +
> +	mutex_lock(&chip->als_mutex);
> +	chip->als_settings.als_cal_target = value;
> +	mutex_unlock(&chip->als_mutex);
> +
> +	return len;
> +}
> +
> +static ssize_t in_illuminance_calibrate_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, ret;
> +
> +	if (kstrtoint(buf, 0, &value) || value != 1)
> +		return -EINVAL;
> +
> +	mutex_lock(&chip->als_mutex);
> +
> +	if (chip->suspended) {
> +		ret = -EBUSY;
> +		goto done;
> +	}
> +
> +	ret = tsl2583_als_calibrate(indio_dev);
> +	if (ret < 0)
> +		goto done;
> +
> +	ret = len;
> +done:
> +	mutex_unlock(&chip->als_mutex);
> +
> +	return ret;
> +}
> +
> +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(chip->als_settings.als_device_lux); i++) {
> +		offset += sprintf(buf + offset, "%u,%u,%u,",
> +				  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.
> +			 */
> +			offset--;
> +			break;
> +		}
> +	}
> +
> +	offset += sprintf(buf + offset, "\n");
> +
> +	return offset;
> +}
> +
> +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);
> +	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;
> +
> +	mutex_lock(&chip->als_mutex);
> +
> +	get_options(buf, ARRAY_SIZE(value), value);
> +
> +	/*
> +	 * We now have an array of ints starting at value[1], and
> +	 * enumerated by value[0].
> +	 * We expect each group of three ints is one table entry,
> +	 * and the last table entry is all 0.
> +	 */
> +	n = value[0];
> +	if ((n % 3) || n < 6 || n > 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, %d]\n",
> +			__func__, max_ints);
> +		goto done;
> +	}
> +	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;
> +	}
> +
> +	memcpy(chip->als_settings.als_device_lux, &value[1],
> +	       value[0] * sizeof(value[1]));
> +
> +	ret = len;
> +
> +done:
> +	mutex_unlock(&chip->als_mutex);
> +
> +	return ret;
> +}
> +
> +static IIO_CONST_ATTR(in_illuminance_calibscale_available, "1 8 16 111");
> +static IIO_CONST_ATTR(in_illuminance_integration_time_available,
> +		      "0.000050 0.000100 0.000150 0.000200 0.000250 0.000300 0.000350 0.000400 0.000450 0.000500 0.000550 0.000600 0.000650");
> +static IIO_DEVICE_ATTR_RW(in_illuminance_input_target, 0);
> +static IIO_DEVICE_ATTR_WO(in_illuminance_calibrate, 0);
> +static IIO_DEVICE_ATTR_RW(in_illuminance_lux_table, 0);
> +
> +static struct attribute *sysfs_attrs_ctrl[] = {
> +	&iio_const_attr_in_illuminance_calibscale_available.dev_attr.attr,
> +	&iio_const_attr_in_illuminance_integration_time_available.dev_attr.attr,
> +	&iio_dev_attr_in_illuminance_input_target.dev_attr.attr,
> +	&iio_dev_attr_in_illuminance_calibrate.dev_attr.attr,
> +	&iio_dev_attr_in_illuminance_lux_table.dev_attr.attr,
> +	NULL
> +};
> +
> +static const struct attribute_group tsl2583_attribute_group = {
> +	.attrs = sysfs_attrs_ctrl,
> +};
> +
> +static const struct iio_chan_spec tsl2583_channels[] = {
> +	{
> +		.type = IIO_LIGHT,
> +		.modified = 1,
> +		.channel2 = IIO_MOD_LIGHT_IR,
> +		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> +	},
> +	{
> +		.type = IIO_LIGHT,
> +		.modified = 1,
> +		.channel2 = IIO_MOD_LIGHT_BOTH,
> +		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> +	},
> +	{
> +		.type = IIO_LIGHT,
> +		.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) |
> +				      BIT(IIO_CHAN_INFO_CALIBBIAS) |
> +				      BIT(IIO_CHAN_INFO_CALIBSCALE) |
> +				      BIT(IIO_CHAN_INFO_INT_TIME),
> +	},
> +};
> +
> +static int tsl2583_read_raw(struct iio_dev *indio_dev,
> +			    struct iio_chan_spec const *chan,
> +			    int *val, int *val2, long mask)
> +{
> +	struct tsl2583_chip *chip = iio_priv(indio_dev);
> +	int ret = -EINVAL;
> +
> +	mutex_lock(&chip->als_mutex);
> +
> +	if (chip->suspended) {
> +		ret = -EBUSY;
> +		goto read_done;
> +	}
> +
> +	switch (mask) {
> +	case IIO_CHAN_INFO_RAW:
> +		if (chan->type == IIO_LIGHT) {
> +			ret = tsl2583_get_lux(indio_dev);
> +			if (ret < 0)
> +				goto read_done;
> +
> +			/*
> +			 * From page 20 of the TSL2581, TSL2583 data
> +			 * sheet (TAOS134 − MARCH 2011):
> +			 *
> +			 * One of the photodiodes (channel 0) is
> +			 * sensitive to both visible and infrared light,
> +			 * while the second photodiode (channel 1) is
> +			 * sensitive primarily to infrared light.
> +			 */
> +			if (chan->channel2 == IIO_MOD_LIGHT_BOTH)
> +				*val = chip->als_cur_info.als_ch0;
> +			else
> +				*val = chip->als_cur_info.als_ch1;
> +
> +			ret = IIO_VAL_INT;
> +		}
> +		break;
> +	case IIO_CHAN_INFO_PROCESSED:
> +		if (chan->type == IIO_LIGHT) {
> +			ret = tsl2583_get_lux(indio_dev);
> +			if (ret < 0)
> +				goto read_done;
> +
> +			*val = ret;
> +			ret = IIO_VAL_INT;
> +		}
> +		break;
> +	case IIO_CHAN_INFO_CALIBBIAS:
> +		if (chan->type == IIO_LIGHT) {
> +			*val = chip->als_settings.als_gain_trim;
> +			ret = IIO_VAL_INT;
> +		}
> +		break;
> +	case IIO_CHAN_INFO_CALIBSCALE:
> +		if (chan->type == IIO_LIGHT) {
> +			*val = gainadj[chip->als_settings.als_gain].mean;
> +			ret = IIO_VAL_INT;
> +		}
> +		break;
> +	case IIO_CHAN_INFO_INT_TIME:
> +		if (chan->type == IIO_LIGHT) {
> +			*val = 0;
> +			*val2 = chip->als_settings.als_time;
> +			ret = IIO_VAL_INT_PLUS_MICRO;
> +		}
> +		break;
> +	default:
> +		break;
> +	}
> +
> +read_done:
> +	mutex_unlock(&chip->als_mutex);
> +
> +	return ret;
> +}
> +
> +static int tsl2583_write_raw(struct iio_dev *indio_dev,
> +			     struct iio_chan_spec const *chan,
> +			     int val, int val2, long mask)
> +{
> +	struct tsl2583_chip *chip = iio_priv(indio_dev);
> +	int ret = -EINVAL;
> +
> +	mutex_lock(&chip->als_mutex);
> +
> +	if (chip->suspended) {
> +		ret = -EBUSY;
> +		goto write_done;
> +	}
> +
> +	switch (mask) {
> +	case IIO_CHAN_INFO_CALIBBIAS:
> +		if (chan->type == IIO_LIGHT) {
> +			chip->als_settings.als_gain_trim = val;
> +			ret = 0;
> +		}
> +		break;
> +	case IIO_CHAN_INFO_CALIBSCALE:
> +		if (chan->type == IIO_LIGHT) {
> +			unsigned int i;
> +
> +			for (i = 0; i < ARRAY_SIZE(gainadj); i++) {
> +				if (gainadj[i].mean == val) {
> +					chip->als_settings.als_gain = i;
> +					ret = tsl2583_set_als_gain(chip);
> +					break;
> +				}
> +			}
> +		}
> +		break;
> +	case IIO_CHAN_INFO_INT_TIME:
> +		if (chan->type == IIO_LIGHT && !val && val2 >= 50 &&
> +		    val2 <= 650 && !(val2 % 50)) {
> +			chip->als_settings.als_time = val2;
> +			ret = tsl2583_set_als_time(chip);
> +		}
> +		break;
> +	default:
> +		break;
> +	}
> +
> +write_done:
> +	mutex_unlock(&chip->als_mutex);
> +
> +	return ret;
> +}
> +
> +static const struct iio_info tsl2583_info = {
> +	.attrs = &tsl2583_attribute_group,
> +	.driver_module = THIS_MODULE,
> +	.read_raw = tsl2583_read_raw,
> +	.write_raw = tsl2583_write_raw,
> +};
> +
> +static int tsl2583_probe(struct i2c_client *clientp,
> +			 const struct i2c_device_id *idp)
> +{
> +	int ret;
> +	struct tsl2583_chip *chip;
> +	struct iio_dev *indio_dev;
> +
> +	if (!i2c_check_functionality(clientp->adapter,
> +				     I2C_FUNC_SMBUS_BYTE_DATA)) {
> +		dev_err(&clientp->dev, "%s: i2c smbus byte data functionality is unsupported\n",
> +			__func__);
> +		return -EOPNOTSUPP;
> +	}
> +
> +	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);
> +
> +	mutex_init(&chip->als_mutex);
> +	chip->suspended = true;
> +
> +	ret = i2c_smbus_read_byte_data(clientp,
> +				       TSL2583_CMD_REG | TSL2583_CHIPID);
> +	if (ret < 0) {
> +		dev_err(&clientp->dev,
> +			"%s: failed to read the chip ID register\n", __func__);
> +		return ret;
> +	}
> +
> +	if ((ret & TSL2583_CHIP_ID_MASK) != TSL2583_CHIP_ID) {
> +		dev_err(&clientp->dev, "%s: received an unknown chip ID %x\n",
> +			__func__, ret);
> +		return -EINVAL;
> +	}
> +
> +	indio_dev->info = &tsl2583_info;
> +	indio_dev->channels = tsl2583_channels;
> +	indio_dev->num_channels = ARRAY_SIZE(tsl2583_channels);
> +	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",
> +			__func__);
> +		return ret;
> +	}
> +
> +	/* Load up the V2 defaults (these are hard coded defaults for now) */
> +	tsl2583_defaults(chip);
> +
> +	/* Make sure the chip is on */
> +	ret = tsl2583_chip_init_and_power_on(indio_dev);
> +	if (ret < 0)
> +		return ret;
> +
> +	dev_info(&clientp->dev, "Light sensor found.\n");
> +
> +	return 0;
> +}
> +
> +static int __maybe_unused tsl2583_suspend(struct device *dev)
> +{
> +	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
> +	struct tsl2583_chip *chip = iio_priv(indio_dev);
> +	int ret;
> +
> +	mutex_lock(&chip->als_mutex);
> +
> +	ret = tsl2583_set_power_state(chip, TSL2583_CNTL_PWR_OFF);
> +	chip->suspended = true;
> +
> +	mutex_unlock(&chip->als_mutex);
> +
> +	return ret;
> +}
> +
> +static int __maybe_unused tsl2583_resume(struct device *dev)
> +{
> +	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
> +	struct tsl2583_chip *chip = iio_priv(indio_dev);
> +	int ret;
> +
> +	mutex_lock(&chip->als_mutex);
> +
> +	ret = tsl2583_chip_init_and_power_on(indio_dev);
> +
> +	mutex_unlock(&chip->als_mutex);
> +
> +	return ret;
> +}
> +
> +static SIMPLE_DEV_PM_OPS(tsl2583_pm_ops, tsl2583_suspend, tsl2583_resume);
> +
> +static struct i2c_device_id tsl2583_idtable[] = {
> +	{ "tsl2580", 0 },
> +	{ "tsl2581", 1 },
> +	{ "tsl2583", 2 },
Why the indexes?  Not sure they are used anywhere.
> +	{}
> +};
> +MODULE_DEVICE_TABLE(i2c, tsl2583_idtable);
> +
> +static const struct of_device_id tsl2583_of_match[] = {
> +	{ .compatible = "amstaos,tsl2580", },
> +	{ .compatible = "amstaos,tsl2581", },
> +	{ .compatible = "amstaos,tsl2583", },
> +	{ },
> +};
> +MODULE_DEVICE_TABLE(of, tsl2583_of_match);
> +
> +/* Driver definition */
> +static struct i2c_driver tsl2583_driver = {
> +	.driver = {
> +		.name = "tsl2583",
> +		.pm = &tsl2583_pm_ops,
> +		.of_match_table = tsl2583_of_match,
> +	},
> +	.id_table = tsl2583_idtable,
> +	.probe = tsl2583_probe,
> +};
> +module_i2c_driver(tsl2583_driver);
> +
> +MODULE_AUTHOR("J. August Brenner <jbrenner@taosinc.com>");
> +MODULE_AUTHOR("Brian Masney <masneyb@onstation.org>");
> +MODULE_DESCRIPTION("TAOS tsl2583 ambient light sensor driver");
> +MODULE_LICENSE("GPL");
> diff --git a/drivers/staging/iio/Documentation/light/sysfs-bus-iio-light-tsl2583 b/drivers/staging/iio/Documentation/light/sysfs-bus-iio-light-tsl2583
> deleted file mode 100644
> index a2e1996..0000000
> --- a/drivers/staging/iio/Documentation/light/sysfs-bus-iio-light-tsl2583
> +++ /dev/null
> @@ -1,20 +0,0 @@
> -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/light/Kconfig b/drivers/staging/iio/light/Kconfig
> index dbf22d3..4fbf629 100644
> --- a/drivers/staging/iio/light/Kconfig
> +++ b/drivers/staging/iio/light/Kconfig
> @@ -13,13 +13,6 @@ config SENSORS_ISL29028
>  	 Proximity value via iio. The ISL29028 provides the concurrent sensing
>  	 of ambient light and proximity.
>  
> -config TSL2583
> -	tristate "TAOS TSL2580, TSL2581 and TSL2583 light-to-digital converters"
> -	depends on I2C
> -	help
> -	 Provides support for the TAOS tsl2580, tsl2581 and tsl2583 devices.
> -	 Access ALS data via iio, sysfs.
> -
>  config TSL2x7x
>  	tristate "TAOS TSL/TMD2x71 and TSL/TMD2x72 Family of light and proximity sensors"
>  	depends on I2C
> diff --git a/drivers/staging/iio/light/Makefile b/drivers/staging/iio/light/Makefile
> index 6480856..f8693e9 100644
> --- a/drivers/staging/iio/light/Makefile
> +++ b/drivers/staging/iio/light/Makefile
> @@ -3,5 +3,4 @@
>  #
>  
>  obj-$(CONFIG_SENSORS_ISL29028)	+= isl29028.o
> -obj-$(CONFIG_TSL2583)	+= tsl2583.o
>  obj-$(CONFIG_TSL2x7x)	+= tsl2x7x_core.o
> diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
> deleted file mode 100644
> index ca26444..0000000
> --- a/drivers/staging/iio/light/tsl2583.c
> +++ /dev/null
> @@ -1,913 +0,0 @@
> -/*
> - * Device driver for monitoring ambient light intensity (lux)
> - * within the TAOS tsl258x family of devices (tsl2580, tsl2581, tsl2583).
> - *
> - * 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
> - * 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 <linux/kernel.h>
> -#include <linux/i2c.h>
> -#include <linux/errno.h>
> -#include <linux/delay.h>
> -#include <linux/string.h>
> -#include <linux/mutex.h>
> -#include <linux/unistd.h>
> -#include <linux/slab.h>
> -#include <linux/module.h>
> -#include <linux/iio/iio.h>
> -#include <linux/iio/sysfs.h>
> -
> -/* Device Registers and Masks */
> -#define TSL2583_CNTRL			0x00
> -#define TSL2583_ALS_TIME		0X01
> -#define TSL2583_INTERRUPT		0x02
> -#define TSL2583_GAIN			0x07
> -#define TSL2583_REVID			0x11
> -#define TSL2583_CHIPID			0x12
> -#define TSL2583_ALS_CHAN0LO		0x14
> -#define TSL2583_ALS_CHAN0HI		0x15
> -#define TSL2583_ALS_CHAN1LO		0x16
> -#define TSL2583_ALS_CHAN1HI		0x17
> -#define TSL2583_TMR_LO			0x18
> -#define TSL2583_TMR_HI			0x19
> -
> -/* tsl2583 cmd reg masks */
> -#define TSL2583_CMD_REG			0x80
> -#define TSL2583_CMD_SPL_FN		0x60
> -#define TSL2583_CMD_ALS_INT_CLR		0x01
> -
> -/* tsl2583 cntrl reg masks */
> -#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
> -
> -/* Lux calculation constants */
> -#define	TSL2583_LUX_CALC_OVER_FLOW	65535
> -
> -#define TSL2583_INTERRUPT_DISABLED	0x00
> -
> -#define TSL2583_CHIP_ID			0x90
> -#define TSL2583_CHIP_ID_MASK		0xf0
> -
> -/* Per-device data */
> -struct tsl2583_als_info {
> -	u16 als_ch0;
> -	u16 als_ch1;
> -	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 {
> -	struct mutex als_mutex;
> -	struct i2c_client *client;
> -	struct tsl2583_als_info als_cur_info;
> -	struct tsl2583_settings als_settings;
> -	int als_time_scale;
> -	int als_saturation;
> -	bool suspended;
> -};
> -
> -struct gainadj {
> -	s16 ch0;
> -	s16 ch1;
> -	s16 mean;
> -};
> -
> -/* Index = (0 - 3) Used to validate the gain selection index */
> -static const struct gainadj gainadj[] = {
> -	{ 1, 1, 1 },
> -	{ 8, 8, 8 },
> -	{ 16, 16, 16 },
> -	{ 107, 115, 111 }
> -};
> -
> -/*
> - * Provides initial operational parameter defaults.
> - * These defaults may be changed through the device's sysfs files.
> - */
> -static void tsl2583_defaults(struct tsl2583_chip *chip)
> -{
> -	/*
> -	 * The integration time must be a multiple of 50ms and within the
> -	 * range [50, 600] ms.
> -	 */
> -	chip->als_settings.als_time = 100;
> -
> -	/*
> -	 * This is an index into the gainadj table. Assume clear glass as the
> -	 * default.
> -	 */
> -	chip->als_settings.als_gain = 0;
> -
> -	/* Default gain trim to account for aperture effects */
> -	chip->als_settings.als_gain_trim = 1000;
> -
> -	/* 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));
> -}
> -
> -/*
> - * Reads and calculates current lux value.
> - * The raw ch0 and ch1 values of the ambient light sensed in the last
> - * integration cycle are read from the device.
> - * Time scale factor array values are adjusted based on the integration time.
> - * The raw values are multiplied by a scale factor, and device gain is obtained
> - * using gain index. Limit checks are done next, then the ratio of a multiple
> - * of ch1 value, to the ch0 value, is calculated. The array 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
> - * calculate the lux.
> - */
> -static int tsl2583_get_lux(struct iio_dev *indio_dev)
> -{
> -	u16 ch0, ch1; /* separated ch0/ch1 data from device */
> -	u32 lux; /* raw lux calculated from device data */
> -	u64 lux64;
> -	u32 ratio;
> -	u8 buf[5];
> -	struct tsl2583_lux *p;
> -	struct tsl2583_chip *chip = iio_priv(indio_dev);
> -	int i, ret;
> -
> -	ret = i2c_smbus_read_byte_data(chip->client, TSL2583_CMD_REG);
> -	if (ret < 0) {
> -		dev_err(&chip->client->dev, "%s: failed to read CMD_REG register\n",
> -			__func__);
> -		goto done;
> -	}
> -
> -	/* is data new & valid */
> -	if (!(ret & TSL2583_STA_ADC_INTR)) {
> -		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;
> -	}
> -
> -	for (i = 0; i < 4; i++) {
> -		int reg = TSL2583_CMD_REG | (TSL2583_ALS_CHAN0LO + i);
> -
> -		ret = i2c_smbus_read_byte_data(chip->client, reg);
> -		if (ret < 0) {
> -			dev_err(&chip->client->dev, "%s: failed to read register %x\n",
> -				__func__, reg);
> -			goto done;
> -		}
> -		buf[i] = ret;
> -	}
> -
> -	/*
> -	 * Clear the pending interrupt status bit on the chip to allow the next
> -	 * integration cycle to start. This has to be done even though this
> -	 * driver currently does not support interrupts.
> -	 */
> -	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__);
> -		goto done; /* have no data, so return failure */
> -	}
> -
> -	/* extract ALS/lux data */
> -	ch0 = le16_to_cpup((const __le16 *)&buf[0]);
> -	ch1 = le16_to_cpup((const __le16 *)&buf[2]);
> -
> -	chip->als_cur_info.als_ch0 = ch0;
> -	chip->als_cur_info.als_ch1 = ch1;
> -
> -	if ((ch0 >= chip->als_saturation) || (ch1 >= chip->als_saturation))
> -		goto return_max;
> -
> -	if (!ch0) {
> -		/*
> -		 * The sensor appears to be in total darkness so set the
> -		 * calculated lux to 0 and return early to avoid a division by
> -		 * zero below when calculating the ratio.
> -		 */
> -		ret = 0;
> -		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 *)chip->als_settings.als_device_lux;
> -	     p->ratio != 0 && p->ratio < ratio; p++)
> -		;
> -
> -	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;
> -
> -		/* 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 */
> -	if (chip->als_time_scale == 0)
> -		lux = 0;
> -	else
> -		lux = (lux + (chip->als_time_scale >> 1)) /
> -			chip->als_time_scale;
> -
> -	/*
> -	 * Adjust for active gain scale.
> -	 * 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.
> -	 * Use 64 bits to avoid overflow on multiplication.
> -	 * Then go back to 32 bits before division to avoid using div_u64().
> -	 */
> -	lux64 = lux;
> -	lux64 = lux64 * chip->als_settings.als_gain_trim;
> -	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;
> -	}
> -
> -	/* Update the structure with the latest VALID lux. */
> -	chip->als_cur_info.lux = lux;
> -	ret = lux;
> -
> -done:
> -	return ret;
> -}
> -
> -/*
> - * Obtain single reading and calculate the als_gain_trim (later used
> - * to derive actual lux).
> - * Return updated gain_trim value.
> - */
> -static int tsl2583_als_calibrate(struct iio_dev *indio_dev)
> -{
> -	struct tsl2583_chip *chip = iio_priv(indio_dev);
> -	unsigned int gain_trim_val;
> -	int ret;
> -	int lux_val;
> -
> -	ret = i2c_smbus_read_byte_data(chip->client,
> -				       TSL2583_CMD_REG | TSL2583_CNTRL);
> -	if (ret < 0) {
> -		dev_err(&chip->client->dev,
> -			"%s: failed to read from the CNTRL register\n",
> -			__func__);
> -		return ret;
> -	}
> -
> -	if ((ret & (TSL2583_CNTL_ADC_ENBL | TSL2583_CNTL_PWR_ON))
> -			!= (TSL2583_CNTL_ADC_ENBL | TSL2583_CNTL_PWR_ON)) {
> -		dev_err(&chip->client->dev,
> -			"%s: Device is not powered on and/or ADC is not enabled\n",
> -			__func__);
> -		return -EINVAL;
> -	} else if ((ret & TSL2583_STA_ADC_VALID) != TSL2583_STA_ADC_VALID) {
> -		dev_err(&chip->client->dev,
> -			"%s: The two ADC channels have not completed an integration cycle\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: 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 0;
> -}
> -
> -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->als_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,
> -					TSL2583_CMD_REG | TSL2583_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 als_settings struct */
> -	ret = i2c_smbus_write_byte_data(chip->client,
> -					TSL2583_CMD_REG | TSL2583_GAIN,
> -					chip->als_settings.als_gain);
> -	if (ret < 0)
> -		dev_err(&chip->client->dev,
> -			"%s: failed to set the gain to %d\n", __func__,
> -			chip->als_settings.als_gain);
> -
> -	return ret;
> -}
> -
> -static int tsl2583_set_power_state(struct tsl2583_chip *chip, u8 state)
> -{
> -	int ret;
> -
> -	ret = i2c_smbus_write_byte_data(chip->client,
> -					TSL2583_CMD_REG | TSL2583_CNTRL, state);
> -	if (ret < 0)
> -		dev_err(&chip->client->dev,
> -			"%s: failed to set the power state to %d\n", __func__,
> -			state);
> -
> -	return ret;
> -}
> -
> -/*
> - * Turn the device on.
> - * Configuration must be set before calling this function.
> - */
> -static int tsl2583_chip_init_and_power_on(struct iio_dev *indio_dev)
> -{
> -	struct tsl2583_chip *chip = iio_priv(indio_dev);
> -	int ret;
> -
> -	/* Power on the device; ADC off. */
> -	ret = tsl2583_set_power_state(chip, TSL2583_CNTL_PWR_ON);
> -	if (ret < 0)
> -		return ret;
> -
> -	ret = i2c_smbus_write_byte_data(chip->client,
> -					TSL2583_CMD_REG | TSL2583_INTERRUPT,
> -					TSL2583_INTERRUPT_DISABLED);
> -	if (ret < 0) {
> -		dev_err(&chip->client->dev,
> -			"%s: failed to disable interrupts\n", __func__);
> -		return ret;
> -	}
> -
> -	ret = tsl2583_set_als_time(chip);
> -	if (ret < 0)
> -		return ret;
> -
> -	ret = tsl2583_set_als_gain(chip);
> -	if (ret < 0)
> -		return ret;
> -
> -	usleep_range(3000, 3500);
> -
> -	ret = tsl2583_set_power_state(chip, TSL2583_CNTL_PWR_ON |
> -					    TSL2583_CNTL_ADC_ENBL);
> -	if (ret < 0)
> -		return ret;
> -
> -	chip->suspended = false;
> -
> -	return ret;
> -}
> -
> -/* Sysfs Interface Functions */
> -
> -static ssize_t in_illuminance_input_target_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);
> -	int ret;
> -
> -	mutex_lock(&chip->als_mutex);
> -	ret = sprintf(buf, "%d\n", chip->als_settings.als_cal_target);
> -	mutex_unlock(&chip->als_mutex);
> -
> -	return ret;
> -}
> -
> -static ssize_t in_illuminance_input_target_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;
> -
> -	if (kstrtoint(buf, 0, &value) || !value)
> -		return -EINVAL;
> -
> -	mutex_lock(&chip->als_mutex);
> -	chip->als_settings.als_cal_target = value;
> -	mutex_unlock(&chip->als_mutex);
> -
> -	return len;
> -}
> -
> -static ssize_t in_illuminance_calibrate_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, ret;
> -
> -	if (kstrtoint(buf, 0, &value) || value != 1)
> -		return -EINVAL;
> -
> -	mutex_lock(&chip->als_mutex);
> -
> -	if (chip->suspended) {
> -		ret = -EBUSY;
> -		goto done;
> -	}
> -
> -	ret = tsl2583_als_calibrate(indio_dev);
> -	if (ret < 0)
> -		goto done;
> -
> -	ret = len;
> -done:
> -	mutex_unlock(&chip->als_mutex);
> -
> -	return ret;
> -}
> -
> -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(chip->als_settings.als_device_lux); i++) {
> -		offset += sprintf(buf + offset, "%u,%u,%u,",
> -				  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.
> -			 */
> -			offset--;
> -			break;
> -		}
> -	}
> -
> -	offset += sprintf(buf + offset, "\n");
> -
> -	return offset;
> -}
> -
> -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);
> -	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;
> -
> -	mutex_lock(&chip->als_mutex);
> -
> -	get_options(buf, ARRAY_SIZE(value), value);
> -
> -	/*
> -	 * We now have an array of ints starting at value[1], and
> -	 * enumerated by value[0].
> -	 * We expect each group of three ints is one table entry,
> -	 * and the last table entry is all 0.
> -	 */
> -	n = value[0];
> -	if ((n % 3) || n < 6 || n > 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, %d]\n",
> -			__func__, max_ints);
> -		goto done;
> -	}
> -	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;
> -	}
> -
> -	memcpy(chip->als_settings.als_device_lux, &value[1],
> -	       value[0] * sizeof(value[1]));
> -
> -	ret = len;
> -
> -done:
> -	mutex_unlock(&chip->als_mutex);
> -
> -	return ret;
> -}
> -
> -static IIO_CONST_ATTR(in_illuminance_calibscale_available, "1 8 16 111");
> -static IIO_CONST_ATTR(in_illuminance_integration_time_available,
> -		      "0.000050 0.000100 0.000150 0.000200 0.000250 0.000300 0.000350 0.000400 0.000450 0.000500 0.000550 0.000600 0.000650");
> -static IIO_DEVICE_ATTR_RW(in_illuminance_input_target, 0);
> -static IIO_DEVICE_ATTR_WO(in_illuminance_calibrate, 0);
> -static IIO_DEVICE_ATTR_RW(in_illuminance_lux_table, 0);
> -
> -static struct attribute *sysfs_attrs_ctrl[] = {
> -	&iio_const_attr_in_illuminance_calibscale_available.dev_attr.attr,
> -	&iio_const_attr_in_illuminance_integration_time_available.dev_attr.attr,
> -	&iio_dev_attr_in_illuminance_input_target.dev_attr.attr,
> -	&iio_dev_attr_in_illuminance_calibrate.dev_attr.attr,
> -	&iio_dev_attr_in_illuminance_lux_table.dev_attr.attr,
> -	NULL
> -};
> -
> -static const struct attribute_group tsl2583_attribute_group = {
> -	.attrs = sysfs_attrs_ctrl,
> -};
> -
> -static const struct iio_chan_spec tsl2583_channels[] = {
> -	{
> -		.type = IIO_LIGHT,
> -		.modified = 1,
> -		.channel2 = IIO_MOD_LIGHT_IR,
> -		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> -	},
> -	{
> -		.type = IIO_LIGHT,
> -		.modified = 1,
> -		.channel2 = IIO_MOD_LIGHT_BOTH,
> -		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> -	},
> -	{
> -		.type = IIO_LIGHT,
> -		.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) |
> -				      BIT(IIO_CHAN_INFO_CALIBBIAS) |
> -				      BIT(IIO_CHAN_INFO_CALIBSCALE) |
> -				      BIT(IIO_CHAN_INFO_INT_TIME),
> -	},
> -};
> -
> -static int tsl2583_read_raw(struct iio_dev *indio_dev,
> -			    struct iio_chan_spec const *chan,
> -			    int *val, int *val2, long mask)
> -{
> -	struct tsl2583_chip *chip = iio_priv(indio_dev);
> -	int ret = -EINVAL;
> -
> -	mutex_lock(&chip->als_mutex);
> -
> -	if (chip->suspended) {
> -		ret = -EBUSY;
> -		goto read_done;
> -	}
> -
> -	switch (mask) {
> -	case IIO_CHAN_INFO_RAW:
> -		if (chan->type == IIO_LIGHT) {
> -			ret = tsl2583_get_lux(indio_dev);
> -			if (ret < 0)
> -				goto read_done;
> -
> -			/*
> -			 * From page 20 of the TSL2581, TSL2583 data
> -			 * sheet (TAOS134 − MARCH 2011):
> -			 *
> -			 * One of the photodiodes (channel 0) is
> -			 * sensitive to both visible and infrared light,
> -			 * while the second photodiode (channel 1) is
> -			 * sensitive primarily to infrared light.
> -			 */
> -			if (chan->channel2 == IIO_MOD_LIGHT_BOTH)
> -				*val = chip->als_cur_info.als_ch0;
> -			else
> -				*val = chip->als_cur_info.als_ch1;
> -
> -			ret = IIO_VAL_INT;
> -		}
> -		break;
> -	case IIO_CHAN_INFO_PROCESSED:
> -		if (chan->type == IIO_LIGHT) {
> -			ret = tsl2583_get_lux(indio_dev);
> -			if (ret < 0)
> -				goto read_done;
> -
> -			*val = ret;
> -			ret = IIO_VAL_INT;
> -		}
> -		break;
> -	case IIO_CHAN_INFO_CALIBBIAS:
> -		if (chan->type == IIO_LIGHT) {
> -			*val = chip->als_settings.als_gain_trim;
> -			ret = IIO_VAL_INT;
> -		}
> -		break;
> -	case IIO_CHAN_INFO_CALIBSCALE:
> -		if (chan->type == IIO_LIGHT) {
> -			*val = gainadj[chip->als_settings.als_gain].mean;
> -			ret = IIO_VAL_INT;
> -		}
> -		break;
> -	case IIO_CHAN_INFO_INT_TIME:
> -		if (chan->type == IIO_LIGHT) {
> -			*val = 0;
> -			*val2 = chip->als_settings.als_time;
> -			ret = IIO_VAL_INT_PLUS_MICRO;
> -		}
> -		break;
> -	default:
> -		break;
> -	}
> -
> -read_done:
> -	mutex_unlock(&chip->als_mutex);
> -
> -	return ret;
> -}
> -
> -static int tsl2583_write_raw(struct iio_dev *indio_dev,
> -			     struct iio_chan_spec const *chan,
> -			     int val, int val2, long mask)
> -{
> -	struct tsl2583_chip *chip = iio_priv(indio_dev);
> -	int ret = -EINVAL;
> -
> -	mutex_lock(&chip->als_mutex);
> -
> -	if (chip->suspended) {
> -		ret = -EBUSY;
> -		goto write_done;
> -	}
> -
> -	switch (mask) {
> -	case IIO_CHAN_INFO_CALIBBIAS:
> -		if (chan->type == IIO_LIGHT) {
> -			chip->als_settings.als_gain_trim = val;
> -			ret = 0;
> -		}
> -		break;
> -	case IIO_CHAN_INFO_CALIBSCALE:
> -		if (chan->type == IIO_LIGHT) {
> -			unsigned int i;
> -
> -			for (i = 0; i < ARRAY_SIZE(gainadj); i++) {
> -				if (gainadj[i].mean == val) {
> -					chip->als_settings.als_gain = i;
> -					ret = tsl2583_set_als_gain(chip);
> -					break;
> -				}
> -			}
> -		}
> -		break;
> -	case IIO_CHAN_INFO_INT_TIME:
> -		if (chan->type == IIO_LIGHT && !val && val2 >= 50 &&
> -		    val2 <= 650 && !(val2 % 50)) {
> -			chip->als_settings.als_time = val2;
> -			ret = tsl2583_set_als_time(chip);
> -		}
> -		break;
> -	default:
> -		break;
> -	}
> -
> -write_done:
> -	mutex_unlock(&chip->als_mutex);
> -
> -	return ret;
> -}
> -
> -static const struct iio_info tsl2583_info = {
> -	.attrs = &tsl2583_attribute_group,
> -	.driver_module = THIS_MODULE,
> -	.read_raw = tsl2583_read_raw,
> -	.write_raw = tsl2583_write_raw,
> -};
> -
> -static int tsl2583_probe(struct i2c_client *clientp,
> -			 const struct i2c_device_id *idp)
> -{
> -	int ret;
> -	struct tsl2583_chip *chip;
> -	struct iio_dev *indio_dev;
> -
> -	if (!i2c_check_functionality(clientp->adapter,
> -				     I2C_FUNC_SMBUS_BYTE_DATA)) {
> -		dev_err(&clientp->dev, "%s: i2c smbus byte data functionality is unsupported\n",
> -			__func__);
> -		return -EOPNOTSUPP;
> -	}
> -
> -	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);
> -
> -	mutex_init(&chip->als_mutex);
> -	chip->suspended = true;
> -
> -	ret = i2c_smbus_read_byte_data(clientp,
> -				       TSL2583_CMD_REG | TSL2583_CHIPID);
> -	if (ret < 0) {
> -		dev_err(&clientp->dev,
> -			"%s: failed to read the chip ID register\n", __func__);
> -		return ret;
> -	}
> -
> -	if ((ret & TSL2583_CHIP_ID_MASK) != TSL2583_CHIP_ID) {
> -		dev_err(&clientp->dev, "%s: received an unknown chip ID %x\n",
> -			__func__, ret);
> -		return -EINVAL;
> -	}
> -
> -	indio_dev->info = &tsl2583_info;
> -	indio_dev->channels = tsl2583_channels;
> -	indio_dev->num_channels = ARRAY_SIZE(tsl2583_channels);
> -	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",
> -			__func__);
> -		return ret;
> -	}
> -
> -	/* Load up the V2 defaults (these are hard coded defaults for now) */
> -	tsl2583_defaults(chip);
> -
> -	/* Make sure the chip is on */
> -	ret = tsl2583_chip_init_and_power_on(indio_dev);
> -	if (ret < 0)
> -		return ret;
> -
> -	dev_info(&clientp->dev, "Light sensor found.\n");
> -
> -	return 0;
> -}
> -
> -static int __maybe_unused tsl2583_suspend(struct device *dev)
> -{
> -	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
> -	struct tsl2583_chip *chip = iio_priv(indio_dev);
> -	int ret;
> -
> -	mutex_lock(&chip->als_mutex);
> -
> -	ret = tsl2583_set_power_state(chip, TSL2583_CNTL_PWR_OFF);
> -	chip->suspended = true;
> -
> -	mutex_unlock(&chip->als_mutex);
> -
> -	return ret;
> -}
> -
> -static int __maybe_unused tsl2583_resume(struct device *dev)
> -{
> -	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
> -	struct tsl2583_chip *chip = iio_priv(indio_dev);
> -	int ret;
> -
> -	mutex_lock(&chip->als_mutex);
> -
> -	ret = tsl2583_chip_init_and_power_on(indio_dev);
> -
> -	mutex_unlock(&chip->als_mutex);
> -
> -	return ret;
> -}
> -
> -static SIMPLE_DEV_PM_OPS(tsl2583_pm_ops, tsl2583_suspend, tsl2583_resume);
> -
> -static struct i2c_device_id tsl2583_idtable[] = {
> -	{ "tsl2580", 0 },
> -	{ "tsl2581", 1 },
> -	{ "tsl2583", 2 },
> -	{}
> -};
> -MODULE_DEVICE_TABLE(i2c, tsl2583_idtable);
> -
> -static const struct of_device_id tsl2583_of_match[] = {
> -	{ .compatible = "amstaos,tsl2580", },
> -	{ .compatible = "amstaos,tsl2581", },
> -	{ .compatible = "amstaos,tsl2583", },
> -	{ },
> -};
> -MODULE_DEVICE_TABLE(of, tsl2583_of_match);
> -
> -/* Driver definition */
> -static struct i2c_driver tsl2583_driver = {
> -	.driver = {
> -		.name = "tsl2583",
> -		.pm = &tsl2583_pm_ops,
> -		.of_match_table = tsl2583_of_match,
> -	},
> -	.id_table = tsl2583_idtable,
> -	.probe = tsl2583_probe,
> -};
> -module_i2c_driver(tsl2583_driver);
> -
> -MODULE_AUTHOR("J. August Brenner <jbrenner@taosinc.com>");
> -MODULE_AUTHOR("Brian Masney <masneyb@onstation.org>");
> -MODULE_DESCRIPTION("TAOS tsl2583 ambient light sensor driver");
> -MODULE_LICENSE("GPL");
> 

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v4 26/26] staging: iio: tsl2583: move out of staging
  2016-11-13 12:57   ` Jonathan Cameron
@ 2016-11-13 16:18     ` Brian Masney
  0 siblings, 0 replies; 54+ messages in thread
From: Brian Masney @ 2016-11-13 16:18 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: linux-iio, devel, gregkh, lars, pmeerw, knaack.h, linux-kernel,
	Jon.Brenner

On Sun, Nov 13, 2016 at 12:57:25PM +0000, Jonathan Cameron wrote:
> On 12/11/16 18:19, Brian Masney wrote:
> > Move tsl2580, tsl2581, tsl2583 driver out of staging into mainline.
> > 
> > Signed-off-by: Brian Masney <masneyb@onstation.org>
> I had another read through on this one.  A few oddites.
> 
> I fixed up the indentation one way back in your patch fixing alignment.
> Made applying this patch more entertaining than it should have been but
> I think got that right in the end.
> 
> Can't find myself caring enough about the unused data element in that
> id table to hold this patch on that so...
> 
> Applied to the togreg branch of iio.git and pushed out as testing for
> the autobuilders to play with it.
> 
> Thanks for all your hard work on this!

Thanks Jonathan for all of your feedback and working with me on this. I
learned a lot cleaning up this driver.

I'm going to work on the ISL29028 light driver next since I have one
mounted on a breakout board. The driver appears to not need any major
work so it should be easy.

After that, I'm taking requests for an existing IIO staging driver to
clean up. I'm looking for a driver that needs more than just style
cleanups (like this driver that I just finished). Ideally, one where
a company or person could loan me the sensor. I'll mail it back when
I am finished. Otherwise, I'll see what I can pick up for low cost on
Digikey that has an existing staging driver that meets my criteria.

Brian

^ permalink raw reply	[flat|nested] 54+ messages in thread

end of thread, other threads:[~2016-11-13 16:18 UTC | newest]

Thread overview: 54+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-12 18:19 [PATCH v4 00/26] staging: iio: tsl2583: move out of staging Brian Masney
2016-11-12 18:19 ` [PATCH v4 01/26] staging: iio: tsl2583: check if chip is in a working state in in_illuminance_calibrate_store Brian Masney
2016-11-13 11:54   ` Jonathan Cameron
2016-11-12 18:19 ` [PATCH v4 02/26] staging: iio: tsl2583: remove unnecessary chip status check in taos_get_lux Brian Masney
2016-11-13 11:55   ` Jonathan Cameron
2016-11-12 18:19 ` [PATCH v4 03/26] staging: iio: tsl2583: remove unnecessary chip status checks in suspend/resume Brian Masney
2016-11-13 11:56   ` Jonathan Cameron
2016-11-12 18:19 ` [PATCH v4 04/26] staging: iio: tsl2583: change current chip state from a tristate to a bool Brian Masney
2016-11-13 11:58   ` Jonathan Cameron
2016-11-12 18:19 ` [PATCH v4 05/26] staging: iio: tsl2583: remove redundant write to the control register in taos_probe() Brian Masney
2016-11-13 12:06   ` Jonathan Cameron
2016-11-12 18:19 ` [PATCH v4 06/26] staging: iio: tsl2583: remove the FSF's mailing address Brian Masney
2016-11-13 12:07   ` Jonathan Cameron
2016-11-12 18:19 ` [PATCH v4 07/26] staging: iio: tsl2583: cleaned up logging Brian Masney
2016-11-13 12:07   ` Jonathan Cameron
2016-11-12 18:19 ` [PATCH v4 08/26] staging: iio: tsl2583: unify function and variable prefix to tsl2583_ Brian Masney
2016-11-13 12:09   ` Jonathan Cameron
2016-11-12 18:19 ` [PATCH v4 09/26] staging: iio: tsl2583: fix alignment of #define values Brian Masney
2016-11-13 12:13   ` Jonathan Cameron
2016-11-12 18:19 ` [PATCH v4 10/26] staging: iio: tsl2583: fix comparison between signed and unsigned integers Brian Masney
2016-11-13 12:14   ` Jonathan Cameron
2016-11-12 18:19 ` [PATCH v4 11/26] staging: iio: tsl2583: change newlines to improve readability Brian Masney
2016-11-13 12:15   ` Jonathan Cameron
2016-11-12 18:19 ` [PATCH v4 12/26] staging: iio: tsl2583: combine sysfs documentation Brian Masney
2016-11-13 12:16   ` Jonathan Cameron
2016-11-12 18:19 ` [PATCH v4 13/26] staging: iio: tsl2583: fix multiline comment syntax Brian Masney
2016-11-13 12:17   ` Jonathan Cameron
2016-11-12 18:19 ` [PATCH v4 14/26] staging: iio: tsl2583: updated code comment to match what the code does Brian Masney
2016-11-13 12:18   ` Jonathan Cameron
2016-11-12 18:19 ` [PATCH v4 15/26] staging: iio: tsl2583: moved code block inside else statement Brian Masney
2016-11-13 12:20   ` Jonathan Cameron
2016-11-12 18:19 ` [PATCH v4 16/26] staging: iio: tsl2583: change tsl2583_als_calibrate() to return 0 on success Brian Masney
2016-11-13 12:21   ` Jonathan Cameron
2016-11-12 18:19 ` [PATCH v4 17/26] staging: iio: tsl2583: remove unnecessary parentheses Brian Masney
2016-11-13 12:22   ` Jonathan Cameron
2016-11-12 18:19 ` [PATCH v4 18/26] staging: iio: tsl2583: don't assume an unsigned int is 32 bits Brian Masney
2016-11-13 12:23   ` Jonathan Cameron
2016-11-12 18:19 ` [PATCH v4 19/26] staging: iio: tsl2583: move from a global to a per device lux table Brian Masney
2016-11-13 12:25   ` Jonathan Cameron
2016-11-12 18:19 ` [PATCH v4 20/26] staging: iio: tsl2583: add tsl2583 to list of supported devices in the header Brian Masney
2016-11-13 12:28   ` Jonathan Cameron
2016-11-12 18:19 ` [PATCH v4 21/26] staging: iio: tsl2583: clarified comment about clearing interrupts Brian Masney
2016-11-13 12:28   ` Jonathan Cameron
2016-11-12 18:19 ` [PATCH v4 22/26] staging: iio: tsl2583: remove comment for tsl2583_probe() Brian Masney
2016-11-13 12:29   ` Jonathan Cameron
2016-11-12 18:19 ` [PATCH v4 23/26] staging: iio: tsl2583: remove unnecessary memset call Brian Masney
2016-11-13 12:29   ` Jonathan Cameron
2016-11-12 18:19 ` [PATCH v4 24/26] staging: iio: tsl2583: remove unnecessary variable initialization Brian Masney
2016-11-13 12:30   ` Jonathan Cameron
2016-11-12 18:19 ` [PATCH v4 25/26] staging: iio: tsl2583: add copyright and MODULE_AUTHOR Brian Masney
2016-11-13 12:35   ` Jonathan Cameron
2016-11-12 18:19 ` [PATCH v4 26/26] staging: iio: tsl2583: move out of staging Brian Masney
2016-11-13 12:57   ` Jonathan Cameron
2016-11-13 16:18     ` Brian Masney

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).