LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH v2 00/11] staging: iio: tsl2x7x: move out of staging
@ 2018-05-04  2:53 Brian Masney
  2018-05-04  2:53 ` [PATCH v2 01/11] staging: iio: tsl2x7x: use GPL-2.0+ SPDX license identifier Brian Masney
                   ` (10 more replies)
  0 siblings, 11 replies; 24+ messages in thread
From: Brian Masney @ 2018-05-04  2:53 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, lars, gregkh, linux-kernel, pmeerw, knaack.h, drew.paterson

Here is a patch set that should hopefully be the last of the changes
required for a staging graduation. Changes since v1:

- Use correct syntax for SPDX license identifier
- Use kstrtou16 for range checking
- Correct integration time sysfs attribute. This fix required correcting
  all of the equations and coefficients. Fortunately TAOS / AMS has
  really good documentation available.
- Rename driver from tsl2x7x to tsl2772.

Datasheet for TSL2772
https://ams.com/eng/content/download/291503/1066377/file/TSL2772_DS000181_2-00.pdf

Other datasheets:

ALS only
- https://ams.com/eng/content/download/250043/975277/file/TSL2571_DS000114_2-00.pdf
- https://ams.com/eng/content/download/291224/1065822/file/TSL2572_DS000178_2-00.pdf

Proximity Only
- https://ams.com/eng/content/download/250323/976177/file/TSL2671_DS000111_2-00.pdf
- https://ams.com/eng/content/download/250304/976107/file/TMD2671_DS000176_2-00.pdf
- https://ams.com/eng/content/download/291443/1066277/file/TSL2672_Datasheet_EN_v1.pdf
- https://ams.com/eng/content/download/364923/1210537/file/TMD2672_Datasheet_EN_v1.pdf

ALS / Proximity
- https://ams.com/eng/content/download/250264/976045/file/TSL2771_DS000105_3-00.pdf
- https://ams.com/eng/content/download/250283/976077/file/TMD2771_DS000177_2-00.pdf
- https://ams.com/eng/content/download/365023/1210677/file/TMD2772-E.pdf

Brian Masney (11):
  staging: iio: tsl2x7x: use GPL-2.0+ SPDX license identifier
  staging: iio: tsl2x7x: add range checking to three sysfs attributes
  staging: iio: tsl2x7x: don't setup event handlers if interrupts are
    not configured
  staging: iio: tsl2x7x: move calibscale_available attribute to
    IIO_INTENSITY channel
  staging: iio: tsl2x7x: use IIO_CONST_ATTR for calibscale_available
  staging: iio: tsl2x7x: correct integration time and lux equation
  staging: iio: tsl2x7x: support 2.72 and 2.73 ALS increments
  staging: iio: tsl2x7x: add device ids for code readability
  staging: iio: tsl2x7x: correct IIO_EV_INFO_PERIOD values
  staging: iio: tsl2x7x: rename driver to tsl2772
  staging: iio: tsl2x7x/tsl2772: move out of staging

 drivers/iio/light/Kconfig                          |    8 +
 drivers/iio/light/Makefile                         |    1 +
 .../iio/light/tsl2x7x.c => iio/light/tsl2772.c}    | 1137 ++++++++++----------
 drivers/staging/iio/Kconfig                        |    1 -
 drivers/staging/iio/Makefile                       |    1 -
 drivers/staging/iio/light/Kconfig                  |   14 -
 drivers/staging/iio/light/Makefile                 |    5 -
 .../linux/platform_data/tsl2772.h                  |   65 +-
 8 files changed, 631 insertions(+), 601 deletions(-)
 rename drivers/{staging/iio/light/tsl2x7x.c => iio/light/tsl2772.c} (50%)
 delete mode 100644 drivers/staging/iio/light/Kconfig
 delete mode 100644 drivers/staging/iio/light/Makefile
 rename drivers/staging/iio/light/tsl2x7x.h => include/linux/platform_data/tsl2772.h (58%)

-- 
2.14.3

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

* [PATCH v2 01/11] staging: iio: tsl2x7x: use GPL-2.0+ SPDX license identifier
  2018-05-04  2:53 [PATCH v2 00/11] staging: iio: tsl2x7x: move out of staging Brian Masney
@ 2018-05-04  2:53 ` Brian Masney
  2018-05-06 17:59   ` Jonathan Cameron
  2018-05-04  2:53 ` [PATCH v2 02/11] staging: iio: tsl2x7x: add range checking to three sysfs attributes Brian Masney
                   ` (9 subsequent siblings)
  10 siblings, 1 reply; 24+ messages in thread
From: Brian Masney @ 2018-05-04  2:53 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, lars, gregkh, linux-kernel, pmeerw, knaack.h, drew.paterson

The summary text for the GPL is not needed since the SPDX identifier
is a legally binding shorthand that can be used instead.

Signed-off-by: Brian Masney <masneyb@onstation.org>
---
 drivers/staging/iio/light/tsl2x7x.c | 11 +----------
 drivers/staging/iio/light/tsl2x7x.h | 15 +--------------
 2 files changed, 2 insertions(+), 24 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c
index e65621948cf8..01bff4593640 100644
--- a/drivers/staging/iio/light/tsl2x7x.c
+++ b/drivers/staging/iio/light/tsl2x7x.c
@@ -1,19 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Device driver for monitoring ambient light intensity in (lux) and proximity
  * detection (prox) within the TAOS TSL2X7X family of devices.
  *
  * Copyright (c) 2012, TAOS Corporation.
  * Copyright (c) 2017-2018 Brian Masney <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/delay.h>
diff --git a/drivers/staging/iio/light/tsl2x7x.h b/drivers/staging/iio/light/tsl2x7x.h
index 91ce8f98982e..8eb7f4749ea7 100644
--- a/drivers/staging/iio/light/tsl2x7x.h
+++ b/drivers/staging/iio/light/tsl2x7x.h
@@ -1,22 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
 /*
  * Device driver for monitoring ambient light intensity (lux)
  * and proximity (prox) within the TAOS TSL2X7X family of devices.
  *
  * Copyright (c) 2012, TAOS Corporation.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA	02110-1301, USA.
  */
 
 #ifndef __TSL2X7X_H
-- 
2.14.3

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

* [PATCH v2 02/11] staging: iio: tsl2x7x: add range checking to three sysfs attributes
  2018-05-04  2:53 [PATCH v2 00/11] staging: iio: tsl2x7x: move out of staging Brian Masney
  2018-05-04  2:53 ` [PATCH v2 01/11] staging: iio: tsl2x7x: use GPL-2.0+ SPDX license identifier Brian Masney
@ 2018-05-04  2:53 ` Brian Masney
  2018-05-06 18:01   ` Jonathan Cameron
  2018-05-04  2:53 ` [PATCH v2 03/11] staging: iio: tsl2x7x: don't setup event handlers if interrupts are not configured Brian Masney
                   ` (8 subsequent siblings)
  10 siblings, 1 reply; 24+ messages in thread
From: Brian Masney @ 2018-05-04  2:53 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, lars, gregkh, linux-kernel, pmeerw, knaack.h, drew.paterson

The sysfs attributes in_illuminance0_target_input,
in_illuminance0_calibrate, and in_proximity0_calibrate did not have
proper range checking in place so this patch adds the correct range
checks.

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

diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c
index 01bff4593640..b4d77f65ca12 100644
--- a/drivers/staging/iio/light/tsl2x7x.c
+++ b/drivers/staging/iio/light/tsl2x7x.c
@@ -814,15 +814,13 @@ static ssize_t in_illuminance0_target_input_store(struct device *dev,
 {
 	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
 	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
-	unsigned long value;
+	u16 value;
 	int ret;
 
-	if (kstrtoul(buf, 0, &value))
+	if (kstrtou16(buf, 0, &value))
 		return -EINVAL;
 
-	if (value)
-		chip->settings.als_cal_target = value;
-
+	chip->settings.als_cal_target = value;
 	ret = tsl2x7x_invoke_change(indio_dev);
 	if (ret < 0)
 		return ret;
@@ -838,14 +836,12 @@ static ssize_t in_illuminance0_calibrate_store(struct device *dev,
 	bool value;
 	int ret;
 
-	if (strtobool(buf, &value))
+	if (kstrtobool(buf, &value) || !value)
 		return -EINVAL;
 
-	if (value) {
-		ret = tsl2x7x_als_calibrate(indio_dev);
-		if (ret < 0)
-			return ret;
-	}
+	ret = tsl2x7x_als_calibrate(indio_dev);
+	if (ret < 0)
+		return ret;
 
 	ret = tsl2x7x_invoke_change(indio_dev);
 	if (ret < 0)
@@ -932,14 +928,12 @@ static ssize_t in_proximity0_calibrate_store(struct device *dev,
 	bool value;
 	int ret;
 
-	if (strtobool(buf, &value))
+	if (kstrtobool(buf, &value) || !value)
 		return -EINVAL;
 
-	if (value) {
-		ret = tsl2x7x_prox_cal(indio_dev);
-		if (ret < 0)
-			return ret;
-	}
+	ret = tsl2x7x_prox_cal(indio_dev);
+	if (ret < 0)
+		return ret;
 
 	ret = tsl2x7x_invoke_change(indio_dev);
 	if (ret < 0)
-- 
2.14.3

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

* [PATCH v2 03/11] staging: iio: tsl2x7x: don't setup event handlers if interrupts are not configured
  2018-05-04  2:53 [PATCH v2 00/11] staging: iio: tsl2x7x: move out of staging Brian Masney
  2018-05-04  2:53 ` [PATCH v2 01/11] staging: iio: tsl2x7x: use GPL-2.0+ SPDX license identifier Brian Masney
  2018-05-04  2:53 ` [PATCH v2 02/11] staging: iio: tsl2x7x: add range checking to three sysfs attributes Brian Masney
@ 2018-05-04  2:53 ` Brian Masney
  2018-05-06 18:05   ` Jonathan Cameron
  2018-05-04  2:53 ` [PATCH v2 04/11] staging: iio: tsl2x7x: move calibscale_available attribute to IIO_INTENSITY channel Brian Masney
                   ` (7 subsequent siblings)
  10 siblings, 1 reply; 24+ messages in thread
From: Brian Masney @ 2018-05-04  2:53 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, lars, gregkh, linux-kernel, pmeerw, knaack.h, drew.paterson

The driver would expose to userspace the events directory even if the
interrupts were not configured. This patch changes the driver so that
the events directory is not exposed to user space if interrupts are
not configured. This patch also corrects the indentation of the
chan_table_elements and info structure members.

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

diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c
index b4d77f65ca12..7e8db5178a2c 100644
--- a/drivers/staging/iio/light/tsl2x7x.c
+++ b/drivers/staging/iio/light/tsl2x7x.c
@@ -134,8 +134,9 @@ struct tsl2x7x_als_info {
 
 struct tsl2x7x_chip_info {
 	int chan_table_elements;
-	struct iio_chan_spec		channel[4];
-	const struct iio_info		*info;
+	struct iio_chan_spec channel_with_events[4];
+	struct iio_chan_spec channel_without_events[4];
+	const struct iio_info *info;
 };
 
 struct tsl2X7X_chip {
@@ -1447,7 +1448,7 @@ static const struct iio_event_spec tsl2x7x_events[] = {
 
 static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
 	[ALS] = {
-		.channel = {
+		.channel_with_events = {
 			{
 			.type = IIO_LIGHT,
 			.indexed = 1,
@@ -1469,11 +1470,31 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
 			.channel = 1,
 			},
 		},
-	.chan_table_elements = 3,
-	.info = &tsl2X7X_device_info[ALS],
+		.channel_without_events = {
+			{
+			.type = IIO_LIGHT,
+			.indexed = 1,
+			.channel = 0,
+			.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
+			}, {
+			.type = IIO_INTENSITY,
+			.indexed = 1,
+			.channel = 0,
+			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+				BIT(IIO_CHAN_INFO_INT_TIME) |
+				BIT(IIO_CHAN_INFO_CALIBSCALE) |
+				BIT(IIO_CHAN_INFO_CALIBBIAS),
+			}, {
+			.type = IIO_INTENSITY,
+			.indexed = 1,
+			.channel = 1,
+			},
+		},
+		.chan_table_elements = 3,
+		.info = &tsl2X7X_device_info[ALS],
 	},
 	[PRX] = {
-		.channel = {
+		.channel_with_events = {
 			{
 			.type = IIO_PROXIMITY,
 			.indexed = 1,
@@ -1483,11 +1504,19 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
 			.num_event_specs = ARRAY_SIZE(tsl2x7x_events),
 			},
 		},
-	.chan_table_elements = 1,
-	.info = &tsl2X7X_device_info[PRX],
+		.channel_without_events = {
+			{
+			.type = IIO_PROXIMITY,
+			.indexed = 1,
+			.channel = 0,
+			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+			},
+		},
+		.chan_table_elements = 1,
+		.info = &tsl2X7X_device_info[PRX],
 	},
 	[ALSPRX] = {
-		.channel = {
+		.channel_with_events = {
 			{
 			.type = IIO_LIGHT,
 			.indexed = 1,
@@ -1517,11 +1546,37 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
 			.num_event_specs = ARRAY_SIZE(tsl2x7x_events),
 			},
 		},
-	.chan_table_elements = 4,
-	.info = &tsl2X7X_device_info[ALSPRX],
+		.channel_without_events = {
+			{
+			.type = IIO_LIGHT,
+			.indexed = 1,
+			.channel = 0,
+			.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
+			}, {
+			.type = IIO_INTENSITY,
+			.indexed = 1,
+			.channel = 0,
+			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+				BIT(IIO_CHAN_INFO_INT_TIME) |
+				BIT(IIO_CHAN_INFO_CALIBSCALE) |
+				BIT(IIO_CHAN_INFO_CALIBBIAS),
+			}, {
+			.type = IIO_INTENSITY,
+			.indexed = 1,
+			.channel = 1,
+			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+			}, {
+			.type = IIO_PROXIMITY,
+			.indexed = 1,
+			.channel = 0,
+			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+			},
+		},
+		.chan_table_elements = 4,
+		.info = &tsl2X7X_device_info[ALSPRX],
 	},
 	[PRX2] = {
-		.channel = {
+		.channel_with_events = {
 			{
 			.type = IIO_PROXIMITY,
 			.indexed = 1,
@@ -1532,11 +1587,20 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
 			.num_event_specs = ARRAY_SIZE(tsl2x7x_events),
 			},
 		},
-	.chan_table_elements = 1,
-	.info = &tsl2X7X_device_info[PRX2],
+		.channel_without_events = {
+			{
+			.type = IIO_PROXIMITY,
+			.indexed = 1,
+			.channel = 0,
+			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+				BIT(IIO_CHAN_INFO_CALIBSCALE),
+			},
+		},
+		.chan_table_elements = 1,
+		.info = &tsl2X7X_device_info[PRX2],
 	},
 	[ALSPRX2] = {
-		.channel = {
+		.channel_with_events = {
 			{
 			.type = IIO_LIGHT,
 			.indexed = 1,
@@ -1567,8 +1631,35 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
 			.num_event_specs = ARRAY_SIZE(tsl2x7x_events),
 			},
 		},
-	.chan_table_elements = 4,
-	.info = &tsl2X7X_device_info[ALSPRX2],
+		.channel_without_events = {
+			{
+			.type = IIO_LIGHT,
+			.indexed = 1,
+			.channel = 0,
+			.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
+			}, {
+			.type = IIO_INTENSITY,
+			.indexed = 1,
+			.channel = 0,
+			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+				BIT(IIO_CHAN_INFO_INT_TIME) |
+				BIT(IIO_CHAN_INFO_CALIBSCALE) |
+				BIT(IIO_CHAN_INFO_CALIBBIAS),
+			}, {
+			.type = IIO_INTENSITY,
+			.indexed = 1,
+			.channel = 1,
+			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+			}, {
+			.type = IIO_PROXIMITY,
+			.indexed = 1,
+			.channel = 0,
+			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+				BIT(IIO_CHAN_INFO_CALIBSCALE),
+			},
+		},
+		.chan_table_elements = 4,
+		.info = &tsl2X7X_device_info[ALSPRX2],
 	},
 };
 
@@ -1620,10 +1711,11 @@ static int tsl2x7x_probe(struct i2c_client *clientp,
 	indio_dev->dev.parent = &clientp->dev;
 	indio_dev->modes = INDIO_DIRECT_MODE;
 	indio_dev->name = chip->client->name;
-	indio_dev->channels = chip->chip_info->channel;
 	indio_dev->num_channels = chip->chip_info->chan_table_elements;
 
 	if (clientp->irq) {
+		indio_dev->channels = chip->chip_info->channel_with_events;
+
 		ret = devm_request_threaded_irq(&clientp->dev, clientp->irq,
 						NULL,
 						&tsl2x7x_event_handler,
@@ -1636,6 +1728,8 @@ static int tsl2x7x_probe(struct i2c_client *clientp,
 				"%s: irq request failed\n", __func__);
 			return ret;
 		}
+	} else {
+		indio_dev->channels = chip->chip_info->channel_without_events;
 	}
 
 	tsl2x7x_defaults(chip);
-- 
2.14.3

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

* [PATCH v2 04/11] staging: iio: tsl2x7x: move calibscale_available attribute to IIO_INTENSITY channel
  2018-05-04  2:53 [PATCH v2 00/11] staging: iio: tsl2x7x: move out of staging Brian Masney
                   ` (2 preceding siblings ...)
  2018-05-04  2:53 ` [PATCH v2 03/11] staging: iio: tsl2x7x: don't setup event handlers if interrupts are not configured Brian Masney
@ 2018-05-04  2:53 ` Brian Masney
  2018-05-06 18:06   ` Jonathan Cameron
  2018-05-04  2:53 ` [PATCH v2 05/11] staging: iio: tsl2x7x: use IIO_CONST_ATTR for calibscale_available Brian Masney
                   ` (6 subsequent siblings)
  10 siblings, 1 reply; 24+ messages in thread
From: Brian Masney @ 2018-05-04  2:53 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, lars, gregkh, linux-kernel, pmeerw, knaack.h, drew.paterson

The calibscale_available attribute is currently associated with the
IIO_LIGHT channel but should be associated with the IIO_INTENSITY
channel. This patch corrects that association and it also corrects
lines that were unnecessarily split for the
in_intensity0_integration_time sysfs attribute.

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

diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c
index 7e8db5178a2c..9aee04fb4168 100644
--- a/drivers/staging/iio/light/tsl2x7x.c
+++ b/drivers/staging/iio/light/tsl2x7x.c
@@ -777,9 +777,9 @@ static int tsl2x7x_prox_cal(struct iio_dev *indio_dev)
 }
 
 static ssize_t
-in_illuminance0_calibscale_available_show(struct device *dev,
-					  struct device_attribute *attr,
-					  char *buf)
+in_intensity0_calibscale_available_show(struct device *dev,
+					struct device_attribute *attr,
+					char *buf)
 {
 	struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev));
 
@@ -1247,7 +1247,7 @@ static int tsl2x7x_write_raw(struct iio_dev *indio_dev,
 	return tsl2x7x_invoke_change(indio_dev);
 }
 
-static DEVICE_ATTR_RO(in_illuminance0_calibscale_available);
+static DEVICE_ATTR_RO(in_intensity0_calibscale_available);
 
 static DEVICE_ATTR_RW(in_illuminance0_target_input);
 
@@ -1321,9 +1321,8 @@ static irqreturn_t tsl2x7x_event_handler(int irq, void *private)
 }
 
 static struct attribute *tsl2x7x_ALS_device_attrs[] = {
-	&dev_attr_in_illuminance0_calibscale_available.attr,
-	&iio_const_attr_in_intensity0_integration_time_available
-		.dev_attr.attr,
+	&dev_attr_in_intensity0_calibscale_available.attr,
+	&iio_const_attr_in_intensity0_integration_time_available.dev_attr.attr,
 	&dev_attr_in_illuminance0_target_input.attr,
 	&dev_attr_in_illuminance0_calibrate.attr,
 	&dev_attr_in_illuminance0_lux_table.attr,
@@ -1336,9 +1335,8 @@ static struct attribute *tsl2x7x_PRX_device_attrs[] = {
 };
 
 static struct attribute *tsl2x7x_ALSPRX_device_attrs[] = {
-	&dev_attr_in_illuminance0_calibscale_available.attr,
-	&iio_const_attr_in_intensity0_integration_time_available
-		.dev_attr.attr,
+	&dev_attr_in_intensity0_calibscale_available.attr,
+	&iio_const_attr_in_intensity0_integration_time_available.dev_attr.attr,
 	&dev_attr_in_illuminance0_target_input.attr,
 	&dev_attr_in_illuminance0_calibrate.attr,
 	&dev_attr_in_illuminance0_lux_table.attr,
@@ -1352,9 +1350,8 @@ static struct attribute *tsl2x7x_PRX2_device_attrs[] = {
 };
 
 static struct attribute *tsl2x7x_ALSPRX2_device_attrs[] = {
-	&dev_attr_in_illuminance0_calibscale_available.attr,
-	&iio_const_attr_in_intensity0_integration_time_available
-		.dev_attr.attr,
+	&dev_attr_in_intensity0_calibscale_available.attr,
+	&iio_const_attr_in_intensity0_integration_time_available.dev_attr.attr,
 	&dev_attr_in_illuminance0_target_input.attr,
 	&dev_attr_in_illuminance0_calibrate.attr,
 	&dev_attr_in_illuminance0_lux_table.attr,
-- 
2.14.3

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

* [PATCH v2 05/11] staging: iio: tsl2x7x: use IIO_CONST_ATTR for calibscale_available
  2018-05-04  2:53 [PATCH v2 00/11] staging: iio: tsl2x7x: move out of staging Brian Masney
                   ` (3 preceding siblings ...)
  2018-05-04  2:53 ` [PATCH v2 04/11] staging: iio: tsl2x7x: move calibscale_available attribute to IIO_INTENSITY channel Brian Masney
@ 2018-05-04  2:53 ` Brian Masney
  2018-05-06 18:07   ` Jonathan Cameron
  2018-05-04  2:53 ` [PATCH v2 06/11] staging: iio: tsl2x7x: correct integration time and lux equation Brian Masney
                   ` (5 subsequent siblings)
  10 siblings, 1 reply; 24+ messages in thread
From: Brian Masney @ 2018-05-04  2:53 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, lars, gregkh, linux-kernel, pmeerw, knaack.h, drew.paterson

The in_intensity0_calibscale_available sysfs attribute has code that
checks the device type to determine which calibration scales are
available. This check is not necessary since all of the supported
ALS device types use the scales 1 8 16 120. This patch converts the
sysfs attribute to use IIO_CONST_ATTR. The following device datasheets
were checked: tsl2571, tsl2771, tmd2771, tsl2572, tsl2772, tmd2772.

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

diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c
index 9aee04fb4168..cf582a2e3633 100644
--- a/drivers/staging/iio/light/tsl2x7x.c
+++ b/drivers/staging/iio/light/tsl2x7x.c
@@ -776,24 +776,7 @@ static int tsl2x7x_prox_cal(struct iio_dev *indio_dev)
 	return tsl2x7x_invoke_change(indio_dev);
 }
 
-static ssize_t
-in_intensity0_calibscale_available_show(struct device *dev,
-					struct device_attribute *attr,
-					char *buf)
-{
-	struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev));
-
-	switch (chip->id) {
-	case tsl2571:
-	case tsl2671:
-	case tmd2671:
-	case tsl2771:
-	case tmd2771:
-		return snprintf(buf, PAGE_SIZE, "%s\n", "1 8 16 128");
-	}
-
-	return snprintf(buf, PAGE_SIZE, "%s\n", "1 8 16 120");
-}
+static IIO_CONST_ATTR(in_intensity0_calibscale_available, "1 8 16 120");
 
 static IIO_CONST_ATTR(in_proximity0_calibscale_available, "1 2 4 8");
 
@@ -1190,25 +1173,6 @@ static int tsl2x7x_write_raw(struct iio_dev *indio_dev,
 				chip->settings.als_gain = 2;
 				break;
 			case 120:
-				switch (chip->id) {
-				case tsl2572:
-				case tsl2672:
-				case tmd2672:
-				case tsl2772:
-				case tmd2772:
-					return -EINVAL;
-				}
-				chip->settings.als_gain = 3;
-				break;
-			case 128:
-				switch (chip->id) {
-				case tsl2571:
-				case tsl2671:
-				case tmd2671:
-				case tsl2771:
-				case tmd2771:
-					return -EINVAL;
-				}
 				chip->settings.als_gain = 3;
 				break;
 			default:
@@ -1247,8 +1211,6 @@ static int tsl2x7x_write_raw(struct iio_dev *indio_dev,
 	return tsl2x7x_invoke_change(indio_dev);
 }
 
-static DEVICE_ATTR_RO(in_intensity0_calibscale_available);
-
 static DEVICE_ATTR_RW(in_illuminance0_target_input);
 
 static DEVICE_ATTR_WO(in_illuminance0_calibrate);
@@ -1321,7 +1283,7 @@ static irqreturn_t tsl2x7x_event_handler(int irq, void *private)
 }
 
 static struct attribute *tsl2x7x_ALS_device_attrs[] = {
-	&dev_attr_in_intensity0_calibscale_available.attr,
+	&iio_const_attr_in_intensity0_calibscale_available.dev_attr.attr,
 	&iio_const_attr_in_intensity0_integration_time_available.dev_attr.attr,
 	&dev_attr_in_illuminance0_target_input.attr,
 	&dev_attr_in_illuminance0_calibrate.attr,
@@ -1335,7 +1297,7 @@ static struct attribute *tsl2x7x_PRX_device_attrs[] = {
 };
 
 static struct attribute *tsl2x7x_ALSPRX_device_attrs[] = {
-	&dev_attr_in_intensity0_calibscale_available.attr,
+	&iio_const_attr_in_intensity0_calibscale_available.dev_attr.attr,
 	&iio_const_attr_in_intensity0_integration_time_available.dev_attr.attr,
 	&dev_attr_in_illuminance0_target_input.attr,
 	&dev_attr_in_illuminance0_calibrate.attr,
@@ -1350,7 +1312,7 @@ static struct attribute *tsl2x7x_PRX2_device_attrs[] = {
 };
 
 static struct attribute *tsl2x7x_ALSPRX2_device_attrs[] = {
-	&dev_attr_in_intensity0_calibscale_available.attr,
+	&iio_const_attr_in_intensity0_calibscale_available.dev_attr.attr,
 	&iio_const_attr_in_intensity0_integration_time_available.dev_attr.attr,
 	&dev_attr_in_illuminance0_target_input.attr,
 	&dev_attr_in_illuminance0_calibrate.attr,
-- 
2.14.3

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

* [PATCH v2 06/11] staging: iio: tsl2x7x: correct integration time and lux equation
  2018-05-04  2:53 [PATCH v2 00/11] staging: iio: tsl2x7x: move out of staging Brian Masney
                   ` (4 preceding siblings ...)
  2018-05-04  2:53 ` [PATCH v2 05/11] staging: iio: tsl2x7x: use IIO_CONST_ATTR for calibscale_available Brian Masney
@ 2018-05-04  2:53 ` Brian Masney
  2018-05-06 18:11   ` Jonathan Cameron
  2018-05-04  2:53 ` [PATCH v2 07/11] staging: iio: tsl2x7x: support 2.72 and 2.73 ALS increments Brian Masney
                   ` (4 subsequent siblings)
  10 siblings, 1 reply; 24+ messages in thread
From: Brian Masney @ 2018-05-04  2:53 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, lars, gregkh, linux-kernel, pmeerw, knaack.h, drew.paterson

The integration_time sysfs attribute did not report the correct
time. Changing the integration time would cause the reported lux to
change wildly. Once the integration time was corrected, all of the
equations, and lux tables needed to be corrected to match what the
data sheets expected. This patch corrects all of this, and adds some
more comments about how some of the constants were derived. Here are
the results from testing a TSL2772 hooked up to a Raspberry Pi 2:

# cat in_intensity0_integration_time
0.002730
# watch -n .1 cat in_illuminance0_input
; Lux hovers around 55
# echo 0.65 > in_intensity0_integration_time
# cat in_intensity0_integration_time
0.649740
# watch -n .1 cat in_illuminance0_input
; Lux hovers around 55 with noticeable lag to lux changes in watch
; process.

; Now test the ALS calibration routine.
# cat in_intensity0_calibbias
1000
# cat in_illuminance0_target_input
150
# echo 1 > in_illuminance0_calibrate
# cat in_intensity0_calibbias
2777
# watch -n .1 cat in_illuminance0_input
; Lux now hovers around 150-155

The returned lux values were tested on a TSL2772 in various lighting
conditions and the results are within the lux ranges described at
https://en.wikipedia.org/wiki/Lux.

The driver was primarily tested using a TSL2772, however some quick tests
were also ran against the devices TSL2771, TSL2572, and TMD2772.

Signed-off-by: Brian Masney <masneyb@onstation.org>
---
 drivers/staging/iio/light/tsl2x7x.c | 174 ++++++++++++++++--------------------
 drivers/staging/iio/light/tsl2x7x.h |   3 +-
 2 files changed, 79 insertions(+), 98 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c
index cf582a2e3633..9b32054713fb 100644
--- a/drivers/staging/iio/light/tsl2x7x.c
+++ b/drivers/staging/iio/light/tsl2x7x.c
@@ -148,7 +148,7 @@ struct tsl2X7X_chip {
 	struct tsl2x7x_als_info als_cur_info;
 	struct tsl2x7x_settings settings;
 	struct tsl2X7X_platform_data *pdata;
-	int als_time_scale;
+	int als_gain_time_scale;
 	int als_saturation;
 	int tsl2x7x_chip_status;
 	u8 tsl2x7x_config[TSL2X7X_MAX_CONFIG_REG];
@@ -163,29 +163,36 @@ struct tsl2X7X_chip {
 	struct tsl2x7x_lux tsl2x7x_device_lux[TSL2X7X_MAX_LUX_TABLE_SIZE];
 };
 
-/* Different devices require different coefficents */
+/*
+ * Different devices require different coefficents, and these numbers were
+ * derived from the 'Lux Equation' section of the various device datasheets.
+ * All of these coefficients assume a Glass Attenuation (GA) factor of 1.
+ * The coefficients are multiplied by 1000 to avoid floating point operations.
+ * The two rows in each table correspond to the Lux1 and Lux2 equations from
+ * the datasheets.
+ */
 static const struct tsl2x7x_lux tsl2x71_lux_table[TSL2X7X_DEF_LUX_TABLE_SZ] = {
-	{ 14461,   611,   1211 },
-	{ 18540,   352,    623 },
-	{     0,     0,      0 },
+	{ 53000, 106000 },
+	{ 31800,  53000 },
+	{ 0,          0 },
 };
 
 static const struct tsl2x7x_lux tmd2x71_lux_table[TSL2X7X_DEF_LUX_TABLE_SZ] = {
-	{ 11635,   115,    256 },
-	{ 15536,    87,    179 },
-	{     0,     0,      0 },
+	{ 24000,  48000 },
+	{ 14400,  24000 },
+	{ 0,          0 },
 };
 
 static const struct tsl2x7x_lux tsl2x72_lux_table[TSL2X7X_DEF_LUX_TABLE_SZ] = {
-	{ 14013,   466,   917 },
-	{ 18222,   310,   552 },
-	{     0,     0,     0 },
+	{ 60000, 112200 },
+	{ 37800,  60000 },
+	{     0,      0 },
 };
 
 static const struct tsl2x7x_lux tmd2x72_lux_table[TSL2X7X_DEF_LUX_TABLE_SZ] = {
-	{ 13218,   130,   262 },
-	{ 17592,   92,    169 },
-	{     0,     0,     0 },
+	{ 20000,  35000 },
+	{ 12600,  20000 },
+	{     0,      0 },
 };
 
 static const struct tsl2x7x_lux *tsl2x7x_default_lux_table_group[] = {
@@ -343,22 +350,18 @@ static int tsl2x7x_read_autoinc_regs(struct tsl2X7X_chip *chip, int lower_reg,
  * @indio_dev:	pointer to IIO device
  *
  * The raw ch0 and ch1 values of the ambient light sensed in the last
- * integration cycle are read from the device. Time scale factor array values
- * are adjusted based on the integration time. The raw values are multiplied
- * by a scale factor, and device gain is obtained using gain index. Limit
- * checks are done next, then the ratio of a multiple of ch1 value, to the
- * ch0 value, is calculated. Array tsl2x7x_device_lux[] is then scanned to
- * find the first ratio value that is just above the ratio we just calculated.
- * The ch0 and ch1 multiplier constants in the array are then used along with
- * the time scale factor array values, to calculate the lux.
+ * integration cycle are read from the device. The raw values are multiplied
+ * by a device-specific scale factor, and divided by the integration time and
+ * device gain. The code supports multiple lux equations through the lux table
+ * coefficients. A lux gain trim is applied to each lux equation, and then the
+ * maximum lux within the interval 0..65535 is selected.
  */
 static int tsl2x7x_get_lux(struct iio_dev *indio_dev)
 {
 	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
 	struct tsl2x7x_lux *p;
-	u32 lux, ratio;
-	u64 lux64;
-	int ret;
+	int max_lux, ret;
+	bool overflow;
 
 	mutex_lock(&chip->als_mutex);
 
@@ -392,10 +395,9 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev)
 		goto out_unlock;
 	chip->als_cur_info.als_ch1 = ret;
 
-	if (chip->als_cur_info.als_ch0 >= chip->als_saturation ||
-	    chip->als_cur_info.als_ch1 >= chip->als_saturation) {
-		lux = TSL2X7X_LUX_CALC_OVER_FLOW;
-		goto return_max;
+	if (chip->als_cur_info.als_ch0 >= chip->als_saturation) {
+		max_lux = TSL2X7X_LUX_CALC_OVER_FLOW;
+		goto update_struct_with_max_lux;
 	}
 
 	if (!chip->als_cur_info.als_ch0) {
@@ -404,51 +406,38 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev)
 		goto out_unlock;
 	}
 
-	/* calculate ratio */
-	ratio = (chip->als_cur_info.als_ch1 << 15) / chip->als_cur_info.als_ch0;
-
-	/* convert to unscaled lux using the pointer to the table */
-	p = (struct tsl2x7x_lux *)chip->tsl2x7x_device_lux;
-	while (p->ratio != 0 && p->ratio < ratio)
-		p++;
+	max_lux = 0;
+	overflow = false;
+	for (p = (struct tsl2x7x_lux *)chip->tsl2x7x_device_lux; p->ch0 != 0;
+	     p++) {
+		int lux;
+
+		lux = ((chip->als_cur_info.als_ch0 * p->ch0) -
+		       (chip->als_cur_info.als_ch1 * p->ch1)) /
+			chip->als_gain_time_scale;
+
+		/*
+		 * The als_gain_trim can have a value within the range 250..4000
+		 * and is a multiplier for the lux. A trim of 1000 makes no
+		 * changes to the lux, less than 1000 scales it down, and
+		 * greater than 1000 scales it up.
+		 */
+		lux = (lux * chip->settings.als_gain_trim) / 1000;
+
+		if (lux > TSL2X7X_LUX_CALC_OVER_FLOW) {
+			overflow = true;
+			continue;
+		}
 
-	if (p->ratio == 0) {
-		lux = 0;
-	} else {
-		lux = DIV_ROUND_UP(chip->als_cur_info.als_ch0 * p->ch0,
-				   tsl2x7x_als_gain[chip->settings.als_gain]) -
-		      DIV_ROUND_UP(chip->als_cur_info.als_ch1 * p->ch1,
-				   tsl2x7x_als_gain[chip->settings.als_gain]);
+		max_lux = max(max_lux, lux);
 	}
 
-	/* 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 tsl2x7x_device_lux tables have a
-	 * factor of 256 built-in. User-specified gain provides a multiplier.
-	 * Apply user-specified gain before shifting right to retain precision.
-	 * Use 64 bits to avoid overflow on multiplication. Then go back to
-	 * 32 bits before division to avoid using div_u64().
-	 */
-
-	lux64 = lux;
-	lux64 = lux64 * chip->settings.als_gain_trim;
-	lux64 >>= 8;
-	lux = lux64;
-	lux = (lux + 500) / 1000;
+	if (overflow && max_lux == 0)
+		max_lux = TSL2X7X_LUX_CALC_OVER_FLOW;
 
-	if (lux > TSL2X7X_LUX_CALC_OVER_FLOW) /* check for overflow */
-		lux = TSL2X7X_LUX_CALC_OVER_FLOW;
-
-	/* Update the structure with the latest lux. */
-return_max:
-	chip->als_cur_info.lux = lux;
-	ret = lux;
+update_struct_with_max_lux:
+	chip->als_cur_info.lux = max_lux;
+	ret = max_lux;
 
 out_unlock:
 	mutex_unlock(&chip->als_mutex);
@@ -525,7 +514,7 @@ static void tsl2x7x_defaults(struct tsl2X7X_chip *chip)
 		       sizeof(tsl2x7x_default_settings));
 
 	/* Load up the proper lux table. */
-	if (chip->pdata && chip->pdata->platform_lux_table[0].ratio != 0)
+	if (chip->pdata && chip->pdata->platform_lux_table[0].ch0 != 0)
 		memcpy(chip->tsl2x7x_device_lux,
 		       chip->pdata->platform_lux_table,
 		       sizeof(chip->pdata->platform_lux_table));
@@ -588,10 +577,11 @@ static int tsl2x7x_als_calibrate(struct iio_dev *indio_dev)
 static int tsl2x7x_chip_on(struct iio_dev *indio_dev)
 {
 	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
-	int ret, i, als_count, als_time;
+	int ret, i, als_count, als_time_us;
 	u8 *dev_reg, reg_val;
 
 	/* Non calculated parameters */
+	chip->tsl2x7x_config[TSL2X7X_ALS_TIME] = chip->settings.als_time;
 	chip->tsl2x7x_config[TSL2X7X_PRX_TIME] = chip->settings.prox_time;
 	chip->tsl2x7x_config[TSL2X7X_WAIT_TIME] = chip->settings.wait_time;
 	chip->tsl2x7x_config[TSL2X7X_ALS_PRX_CONFIG] =
@@ -627,15 +617,6 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev)
 		return -EINVAL;
 	}
 
-	/* determine als integration register */
-	als_count = (chip->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;
-	chip->tsl2x7x_config[TSL2X7X_ALS_TIME] = 256 - als_count;
-
 	/* Set the gain based on tsl2x7x_settings struct */
 	chip->tsl2x7x_config[TSL2X7X_GAIN] =
 		(chip->settings.als_gain & 0xFF) |
@@ -643,9 +624,12 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev)
 		(chip->settings.prox_diode << 4) |
 		(chip->settings.prox_power << 6);
 
-	/* 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;
+	/* set chip time scaling and saturation */
+	als_count = 256 - chip->settings.als_time;
+	als_time_us = als_count * 2720;
+	chip->als_saturation = als_count * 768; /* 75% of full scale */
+	chip->als_gain_time_scale = als_time_us *
+		tsl2x7x_als_gain[chip->settings.als_gain];
 
 	/*
 	 * TSL2X7X Specific power-on / adc enable sequence
@@ -843,11 +827,10 @@ static ssize_t in_illuminance0_lux_table_show(struct device *dev,
 	int offset = 0;
 
 	while (i < TSL2X7X_MAX_LUX_TABLE_SIZE) {
-		offset += snprintf(buf + offset, PAGE_SIZE, "%u,%u,%u,",
-			chip->tsl2x7x_device_lux[i].ratio,
+		offset += snprintf(buf + offset, PAGE_SIZE, "%u,%u,",
 			chip->tsl2x7x_device_lux[i].ch0,
 			chip->tsl2x7x_device_lux[i].ch1);
-		if (chip->tsl2x7x_device_lux[i].ratio == 0) {
+		if (chip->tsl2x7x_device_lux[i].ch0 == 0) {
 			/*
 			 * We just printed the first "0" entry.
 			 * Now get rid of the extra "," and break.
@@ -868,7 +851,7 @@ static ssize_t in_illuminance0_lux_table_store(struct device *dev,
 {
 	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
 	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
-	int value[ARRAY_SIZE(chip->tsl2x7x_device_lux) * 3 + 1];
+	int value[ARRAY_SIZE(chip->tsl2x7x_device_lux) * 2 + 1];
 	int n, ret;
 
 	get_options(buf, ARRAY_SIZE(value), value);
@@ -876,15 +859,15 @@ static ssize_t in_illuminance0_lux_table_store(struct device *dev,
 	/*
 	 * 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,
+	 * We expect each group of two ints to be one table entry,
 	 * and the last table entry is all 0.
 	 */
 	n = value[0];
-	if ((n % 3) || n < 6 ||
-	    n > ((ARRAY_SIZE(chip->tsl2x7x_device_lux) - 1) * 3))
+	if ((n % 2) || n < 4 ||
+	    n > ((ARRAY_SIZE(chip->tsl2x7x_device_lux) - 1) * 2))
 		return -EINVAL;
 
-	if ((value[(n - 2)] | value[(n - 1)] | value[n]) != 0)
+	if ((value[(n - 1)] | value[n]) != 0)
 		return -EINVAL;
 
 	if (chip->tsl2x7x_chip_status == TSL2X7X_CHIP_WORKING) {
@@ -1140,8 +1123,8 @@ static int tsl2x7x_read_raw(struct iio_dev *indio_dev,
 		ret = IIO_VAL_INT;
 		break;
 	case IIO_CHAN_INFO_INT_TIME:
-		*val = (TSL2X7X_MAX_TIMER_CNT - chip->settings.als_time) + 1;
-		*val2 = ((*val * TSL2X7X_MIN_ITIME) % 1000) / 1000;
+		*val = 0;
+		*val2 = (256 - chip->settings.als_time) * 2720;
 		ret = IIO_VAL_INT_PLUS_MICRO;
 		break;
 	default:
@@ -1201,8 +1184,7 @@ static int tsl2x7x_write_raw(struct iio_dev *indio_dev,
 		chip->settings.als_gain_trim = val;
 		break;
 	case IIO_CHAN_INFO_INT_TIME:
-		chip->settings.als_time =
-			TSL2X7X_MAX_TIMER_CNT - (val2 / TSL2X7X_MIN_ITIME);
+		chip->settings.als_time = 256 - (val2 / 2720);
 		break;
 	default:
 		return -EINVAL;
diff --git a/drivers/staging/iio/light/tsl2x7x.h b/drivers/staging/iio/light/tsl2x7x.h
index 8eb7f4749ea7..1097ee890ce2 100644
--- a/drivers/staging/iio/light/tsl2x7x.h
+++ b/drivers/staging/iio/light/tsl2x7x.h
@@ -10,13 +10,12 @@
 #define __TSL2X7X_H
 
 struct tsl2x7x_lux {
-	unsigned int ratio;
 	unsigned int ch0;
 	unsigned int ch1;
 };
 
 /* Max number of segments allowable in LUX table */
-#define TSL2X7X_MAX_LUX_TABLE_SIZE		9
+#define TSL2X7X_MAX_LUX_TABLE_SIZE		6
 /* The default LUX tables all have 3 elements.  */
 #define TSL2X7X_DEF_LUX_TABLE_SZ		3
 #define TSL2X7X_DEFAULT_TABLE_BYTES (sizeof(struct tsl2x7x_lux) * \
-- 
2.14.3

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

* [PATCH v2 07/11] staging: iio: tsl2x7x: support 2.72 and 2.73 ALS increments
  2018-05-04  2:53 [PATCH v2 00/11] staging: iio: tsl2x7x: move out of staging Brian Masney
                   ` (5 preceding siblings ...)
  2018-05-04  2:53 ` [PATCH v2 06/11] staging: iio: tsl2x7x: correct integration time and lux equation Brian Masney
@ 2018-05-04  2:53 ` Brian Masney
  2018-05-06 18:19   ` Jonathan Cameron
  2018-05-04  2:53 ` [PATCH v2 08/11] staging: iio: tsl2x7x: add device ids for code readability Brian Masney
                   ` (3 subsequent siblings)
  10 siblings, 1 reply; 24+ messages in thread
From: Brian Masney @ 2018-05-04  2:53 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, lars, gregkh, linux-kernel, pmeerw, knaack.h, drew.paterson

The driver assumed that the ALS increment was 2.72 ms, and the upper
range was 696 ms. Some other supported devices use 2.73 ms - 699 ms.
This patch adds support for the multiple ranges.

Signed-off-by: Brian Masney <masneyb@onstation.org>
---
I debated whether or not this change should even be included. I feel
pretty confident that I can cleanly fold the tsl2583 driver into this
driver once the staging graduation is done. Those devices have an ALS
range of 2.7 ms - 688.5 ms.

 drivers/staging/iio/light/tsl2x7x.c | 50 +++++++++++++++++++++++++++++--------
 1 file changed, 40 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c
index 9b32054713fb..e3e37501829f 100644
--- a/drivers/staging/iio/light/tsl2x7x.c
+++ b/drivers/staging/iio/light/tsl2x7x.c
@@ -209,9 +209,9 @@ static const struct tsl2x7x_lux *tsl2x7x_default_lux_table_group[] = {
 };
 
 static const struct tsl2x7x_settings tsl2x7x_default_settings = {
-	.als_time = 255, /* 2.73 ms */
+	.als_time = 255, /* 2.72 / 2.73 ms */
 	.als_gain = 0,
-	.prox_time = 255, /* 2.73 ms */
+	.prox_time = 255, /* 2.72 / 2.73 ms */
 	.prox_gain = 0,
 	.wait_time = 255,
 	.als_prox_config = 0,
@@ -245,6 +245,24 @@ static const s16 tsl2x7x_prox_gain[] = {
 	8
 };
 
+struct tsl2x7x_int_time {
+	int increment_us;
+	char *display_range;
+};
+
+static const struct tsl2x7x_int_time tsl2x7x_int_time[] = {
+	[tsl2571] = { 2720, "0.00272 - 0.696" },
+	[tsl2671] = { 2720, "0.00272 - 0.696" },
+	[tmd2671] = { 2720, "0.00272 - 0.696" },
+	[tsl2771] = { 2720, "0.00272 - 0.696" },
+	[tmd2771] = { 2720, "0.00272 - 0.696" },
+	[tsl2572] = { 2730, "0.00273 - 0.699" },
+	[tsl2672] = { 2730, "0.00273 - 0.699" },
+	[tmd2672] = { 2730, "0.00273 - 0.699" },
+	[tsl2772] = { 2730, "0.00273 - 0.699" },
+	[tmd2772] = { 2730, "0.00273 - 0.699" },
+};
+
 /* Channel variations */
 enum {
 	ALS,
@@ -626,7 +644,7 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev)
 
 	/* set chip time scaling and saturation */
 	als_count = 256 - chip->settings.als_time;
-	als_time_us = als_count * 2720;
+	als_time_us = als_count * tsl2x7x_int_time[chip->id].increment_us;
 	chip->als_saturation = als_count * 768; /* 75% of full scale */
 	chip->als_gain_time_scale = als_time_us *
 		tsl2x7x_als_gain[chip->settings.als_gain];
@@ -764,8 +782,16 @@ static IIO_CONST_ATTR(in_intensity0_calibscale_available, "1 8 16 120");
 
 static IIO_CONST_ATTR(in_proximity0_calibscale_available, "1 2 4 8");
 
-static IIO_CONST_ATTR(in_intensity0_integration_time_available,
-		".00272 - .696");
+static ssize_t
+in_intensity0_integration_time_available_show(struct device *dev,
+					      struct device_attribute *attr,
+					      char *buf)
+{
+	struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev));
+
+	return snprintf(buf, PAGE_SIZE, "%s\n",
+			tsl2x7x_int_time[chip->id].display_range);
+}
 
 static ssize_t in_illuminance0_target_input_show(struct device *dev,
 						 struct device_attribute *attr,
@@ -1124,7 +1150,8 @@ static int tsl2x7x_read_raw(struct iio_dev *indio_dev,
 		break;
 	case IIO_CHAN_INFO_INT_TIME:
 		*val = 0;
-		*val2 = (256 - chip->settings.als_time) * 2720;
+		*val2 = (256 - chip->settings.als_time) *
+			tsl2x7x_int_time[chip->id].increment_us;
 		ret = IIO_VAL_INT_PLUS_MICRO;
 		break;
 	default:
@@ -1184,7 +1211,8 @@ static int tsl2x7x_write_raw(struct iio_dev *indio_dev,
 		chip->settings.als_gain_trim = val;
 		break;
 	case IIO_CHAN_INFO_INT_TIME:
-		chip->settings.als_time = 256 - (val2 / 2720);
+		chip->settings.als_time = 256 -
+			(val2 / tsl2x7x_int_time[chip->id].increment_us);
 		break;
 	default:
 		return -EINVAL;
@@ -1193,6 +1221,8 @@ static int tsl2x7x_write_raw(struct iio_dev *indio_dev,
 	return tsl2x7x_invoke_change(indio_dev);
 }
 
+static DEVICE_ATTR_RO(in_intensity0_integration_time_available);
+
 static DEVICE_ATTR_RW(in_illuminance0_target_input);
 
 static DEVICE_ATTR_WO(in_illuminance0_calibrate);
@@ -1266,7 +1296,7 @@ static irqreturn_t tsl2x7x_event_handler(int irq, void *private)
 
 static struct attribute *tsl2x7x_ALS_device_attrs[] = {
 	&iio_const_attr_in_intensity0_calibscale_available.dev_attr.attr,
-	&iio_const_attr_in_intensity0_integration_time_available.dev_attr.attr,
+	&dev_attr_in_intensity0_integration_time_available.attr,
 	&dev_attr_in_illuminance0_target_input.attr,
 	&dev_attr_in_illuminance0_calibrate.attr,
 	&dev_attr_in_illuminance0_lux_table.attr,
@@ -1280,7 +1310,7 @@ static struct attribute *tsl2x7x_PRX_device_attrs[] = {
 
 static struct attribute *tsl2x7x_ALSPRX_device_attrs[] = {
 	&iio_const_attr_in_intensity0_calibscale_available.dev_attr.attr,
-	&iio_const_attr_in_intensity0_integration_time_available.dev_attr.attr,
+	&dev_attr_in_intensity0_integration_time_available.attr,
 	&dev_attr_in_illuminance0_target_input.attr,
 	&dev_attr_in_illuminance0_calibrate.attr,
 	&dev_attr_in_illuminance0_lux_table.attr,
@@ -1295,7 +1325,7 @@ static struct attribute *tsl2x7x_PRX2_device_attrs[] = {
 
 static struct attribute *tsl2x7x_ALSPRX2_device_attrs[] = {
 	&iio_const_attr_in_intensity0_calibscale_available.dev_attr.attr,
-	&iio_const_attr_in_intensity0_integration_time_available.dev_attr.attr,
+	&dev_attr_in_intensity0_integration_time_available.attr,
 	&dev_attr_in_illuminance0_target_input.attr,
 	&dev_attr_in_illuminance0_calibrate.attr,
 	&dev_attr_in_illuminance0_lux_table.attr,
-- 
2.14.3

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

* [PATCH v2 08/11] staging: iio: tsl2x7x: add device ids for code readability
  2018-05-04  2:53 [PATCH v2 00/11] staging: iio: tsl2x7x: move out of staging Brian Masney
                   ` (6 preceding siblings ...)
  2018-05-04  2:53 ` [PATCH v2 07/11] staging: iio: tsl2x7x: support 2.72 and 2.73 ALS increments Brian Masney
@ 2018-05-04  2:53 ` Brian Masney
  2018-05-06 18:26   ` Jonathan Cameron
  2018-05-04  2:53 ` [PATCH v2 09/11] staging: iio: tsl2x7x: correct IIO_EV_INFO_PERIOD values Brian Masney
                   ` (2 subsequent siblings)
  10 siblings, 1 reply; 24+ messages in thread
From: Brian Masney @ 2018-05-04  2:53 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, lars, gregkh, linux-kernel, pmeerw, knaack.h, drew.paterson

This patch adds the device IDs to the device_channel_config array to
improve code readability.

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

diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c
index e3e37501829f..39de5e60fd33 100644
--- a/drivers/staging/iio/light/tsl2x7x.c
+++ b/drivers/staging/iio/light/tsl2x7x.c
@@ -273,16 +273,16 @@ enum {
 };
 
 static const u8 device_channel_config[] = {
-	ALS,
-	PRX,
-	PRX,
-	ALSPRX,
-	ALSPRX,
-	ALS,
-	PRX2,
-	PRX2,
-	ALSPRX2,
-	ALSPRX2
+	[tsl2571] = ALS,
+	[tsl2671] = PRX,
+	[tmd2671] = PRX,
+	[tsl2771] = ALSPRX,
+	[tmd2771] = ALSPRX,
+	[tsl2572] = ALS,
+	[tsl2672] = PRX2,
+	[tmd2672] = PRX2,
+	[tsl2772] = ALSPRX2,
+	[tmd2772] = ALSPRX2
 };
 
 static int tsl2x7x_read_status(struct tsl2X7X_chip *chip)
-- 
2.14.3

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

* [PATCH v2 09/11] staging: iio: tsl2x7x: correct IIO_EV_INFO_PERIOD values
  2018-05-04  2:53 [PATCH v2 00/11] staging: iio: tsl2x7x: move out of staging Brian Masney
                   ` (7 preceding siblings ...)
  2018-05-04  2:53 ` [PATCH v2 08/11] staging: iio: tsl2x7x: add device ids for code readability Brian Masney
@ 2018-05-04  2:53 ` Brian Masney
  2018-05-06 18:27   ` Jonathan Cameron
  2018-05-04  2:53 ` [PATCH v2 10/11] staging: iio: tsl2x7x: rename driver to tsl2772 Brian Masney
  2018-05-04  2:53 ` [PATCH v2 11/11] staging: iio: tsl2x7x/tsl2772: move out of staging Brian Masney
  10 siblings, 1 reply; 24+ messages in thread
From: Brian Masney @ 2018-05-04  2:53 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, lars, gregkh, linux-kernel, pmeerw, knaack.h, drew.paterson

The thresh periods assumed an integration time of 3ms. This patch adds
support for the correct integration time (2.72ms or 2.73ms). The code
had the ALS filter values as going up to 15, however the values actually
went up to 60 since the values scaled in increments of 5 once the
persistence value went above 3.

Signed-off-by: Brian Masney <masneyb@onstation.org>
---
 drivers/staging/iio/light/tsl2x7x.c | 44 +++++++++++++++++++++----------------
 drivers/staging/iio/light/tsl2x7x.h |  1 -
 2 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c
index 39de5e60fd33..f912f4bc61c4 100644
--- a/drivers/staging/iio/light/tsl2x7x.c
+++ b/drivers/staging/iio/light/tsl2x7x.c
@@ -103,8 +103,6 @@
 #define TSL2X7X_CNTL_PROXPON_ENBL	0x0F
 #define TSL2X7X_CNTL_INTPROXPON_ENBL	0x2F
 
-#define TSL2X7X_MIN_ITIME		3
-
 /* TAOS txx2x7x Device family members */
 enum {
 	tsl2571,
@@ -972,7 +970,7 @@ static int tsl2x7x_write_event_value(struct iio_dev *indio_dev,
 				     int val, int val2)
 {
 	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
-	int ret = -EINVAL, y, z, filter_delay;
+	int ret = -EINVAL, count, persistence;
 	u8 time;
 
 	switch (info) {
@@ -1011,15 +1009,20 @@ static int tsl2x7x_write_event_value(struct iio_dev *indio_dev,
 		else
 			time = chip->settings.prox_time;
 
-		y = (TSL2X7X_MAX_TIMER_CNT - time) + 1;
-		z = y * TSL2X7X_MIN_ITIME;
+		count = 256 - time;
+		persistence = ((val * 1000000) + val2) /
+			(count * tsl2x7x_int_time[chip->id].increment_us);
 
-		filter_delay = DIV_ROUND_UP((val * 1000) + val2, z);
+		if (chan->type == IIO_INTENSITY) {
+			/* ALS filter values are 1, 2, 3, 5, 10, 15, ..., 60 */
+			if (persistence > 3)
+				persistence = (persistence / 5) + 3;
+
+			chip->settings.als_persistence = persistence;
+		} else {
+			chip->settings.prox_persistence = persistence;
+		}
 
-		if (chan->type == IIO_INTENSITY)
-			chip->settings.als_persistence = filter_delay;
-		else
-			chip->settings.prox_persistence = filter_delay;
 		ret = 0;
 		break;
 	default:
@@ -1040,7 +1043,7 @@ static int tsl2x7x_read_event_value(struct iio_dev *indio_dev,
 				    int *val, int *val2)
 {
 	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
-	int ret = -EINVAL, filter_delay, mult;
+	int ret = -EINVAL, filter_delay, persistence;
 	u8 time;
 
 	switch (info) {
@@ -1076,18 +1079,21 @@ static int tsl2x7x_read_event_value(struct iio_dev *indio_dev,
 	case IIO_EV_INFO_PERIOD:
 		if (chan->type == IIO_INTENSITY) {
 			time = chip->settings.als_time;
-			mult = chip->settings.als_persistence;
+			persistence = chip->settings.als_persistence;
+
+			/* ALS filter values are 1, 2, 3, 5, 10, 15, ..., 60 */
+			if (persistence > 3)
+				persistence = (persistence - 3) * 5;
 		} else {
 			time = chip->settings.prox_time;
-			mult = chip->settings.prox_persistence;
+			persistence = chip->settings.prox_persistence;
 		}
 
-		/* Determine integration time */
-		*val = (TSL2X7X_MAX_TIMER_CNT - time) + 1;
-		*val2 = *val * TSL2X7X_MIN_ITIME;
-		filter_delay = *val2 * mult;
-		*val = filter_delay / 1000;
-		*val2 = filter_delay % 1000;
+		filter_delay = persistence * (256 - time) *
+			tsl2x7x_int_time[chip->id].increment_us;
+
+		*val = filter_delay / 1000000;
+		*val2 = filter_delay % 1000000;
 		ret = IIO_VAL_INT_PLUS_MICRO;
 		break;
 	default:
diff --git a/drivers/staging/iio/light/tsl2x7x.h b/drivers/staging/iio/light/tsl2x7x.h
index 1097ee890ce2..f74427f4ab6e 100644
--- a/drivers/staging/iio/light/tsl2x7x.h
+++ b/drivers/staging/iio/light/tsl2x7x.h
@@ -31,7 +31,6 @@ struct tsl2x7x_lux {
 #define TSL2X7X_50_mA                   0x01
 #define TSL2X7X_25_mA                   0x02
 #define TSL2X7X_13_mA                   0x03
-#define TSL2X7X_MAX_TIMER_CNT           0xFF
 
 /**
  * struct tsl2x7x_settings - Settings for the tsl2x7x driver
-- 
2.14.3

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

* [PATCH v2 10/11] staging: iio: tsl2x7x: rename driver to tsl2772
  2018-05-04  2:53 [PATCH v2 00/11] staging: iio: tsl2x7x: move out of staging Brian Masney
                   ` (8 preceding siblings ...)
  2018-05-04  2:53 ` [PATCH v2 09/11] staging: iio: tsl2x7x: correct IIO_EV_INFO_PERIOD values Brian Masney
@ 2018-05-04  2:53 ` Brian Masney
  2018-05-06 18:29   ` Jonathan Cameron
  2018-05-04  2:53 ` [PATCH v2 11/11] staging: iio: tsl2x7x/tsl2772: move out of staging Brian Masney
  10 siblings, 1 reply; 24+ messages in thread
From: Brian Masney @ 2018-05-04  2:53 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, lars, gregkh, linux-kernel, pmeerw, knaack.h, drew.paterson

This patch renames this driver from tsl2x7x to tsl2772 since it is
highly likely that additional devices will be added to this driver that
do not match that wildcard. The tsl2772 driver name was selected since
that is currently the device with the most features that are supported
by this driver.

Signed-off-by: Brian Masney <masneyb@onstation.org>
---
 drivers/staging/iio/light/Kconfig                  |   2 +-
 drivers/staging/iio/light/Makefile                 |   2 +-
 drivers/staging/iio/light/{tsl2x7x.c => tsl2772.c} | 691 +++++++++++----------
 drivers/staging/iio/light/{tsl2x7x.h => tsl2772.h} |  48 +-
 4 files changed, 372 insertions(+), 371 deletions(-)
 rename drivers/staging/iio/light/{tsl2x7x.c => tsl2772.c} (66%)
 rename drivers/staging/iio/light/{tsl2x7x.h => tsl2772.h} (71%)

diff --git a/drivers/staging/iio/light/Kconfig b/drivers/staging/iio/light/Kconfig
index aacb0ae58c0e..dfa37386ad2c 100644
--- a/drivers/staging/iio/light/Kconfig
+++ b/drivers/staging/iio/light/Kconfig
@@ -3,7 +3,7 @@
 #
 menu "Light sensors"
 
-config TSL2x7x
+config TSL2772
 	tristate "TAOS TSL/TMD2x71 and TSL/TMD2x72 Family of light and proximity sensors"
 	depends on I2C
 	help
diff --git a/drivers/staging/iio/light/Makefile b/drivers/staging/iio/light/Makefile
index ab8dc3a3d10b..e7e77a11f02a 100644
--- a/drivers/staging/iio/light/Makefile
+++ b/drivers/staging/iio/light/Makefile
@@ -2,4 +2,4 @@
 # Makefile for industrial I/O Light sensors
 #
 
-obj-$(CONFIG_TSL2x7x)	+= tsl2x7x.o
+obj-$(CONFIG_TSL2772)	+= tsl2772.o
diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2772.c
similarity index 66%
rename from drivers/staging/iio/light/tsl2x7x.c
rename to drivers/staging/iio/light/tsl2772.c
index f912f4bc61c4..146527e41969 100644
--- a/drivers/staging/iio/light/tsl2x7x.c
+++ b/drivers/staging/iio/light/tsl2772.c
@@ -1,7 +1,8 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
  * Device driver for monitoring ambient light intensity in (lux) and proximity
- * detection (prox) within the TAOS TSL2X7X family of devices.
+ * detection (prox) for the TAOS TSL2571, TSL2671, TMD2671, TSL2771, TMD2771,
+ * TSL2572, TSL2672, TMD2672, TSL2772, and TMD2772 devices.
  *
  * Copyright (c) 2012, TAOS Corporation.
  * Copyright (c) 2017-2018 Brian Masney <masneyb@onstation.org>
@@ -18,92 +19,92 @@
 #include <linux/iio/events.h>
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
-#include "tsl2x7x.h"
+#include "tsl2772.h"
 
 /* Cal defs */
 #define PROX_STAT_CAL			0
 #define PROX_STAT_SAMP			1
 #define MAX_SAMPLES_CAL			200
 
-/* TSL2X7X Device ID */
+/* TSL2772 Device ID */
 #define TRITON_ID			0x00
 #define SWORDFISH_ID			0x30
 #define HALIBUT_ID			0x20
 
 /* Lux calculation constants */
-#define TSL2X7X_LUX_CALC_OVER_FLOW	65535
+#define TSL2772_LUX_CALC_OVER_FLOW	65535
 
 /*
  * TAOS Register definitions - Note: depending on device, some of these register
  * are not used and the register address is benign.
  */
 
-/* 2X7X register offsets */
-#define TSL2X7X_MAX_CONFIG_REG		16
+/* Register offsets */
+#define TSL2772_MAX_CONFIG_REG		16
 
 /* Device Registers and Masks */
-#define TSL2X7X_CNTRL			0x00
-#define TSL2X7X_ALS_TIME		0X01
-#define TSL2X7X_PRX_TIME		0x02
-#define TSL2X7X_WAIT_TIME		0x03
-#define TSL2X7X_ALS_MINTHRESHLO		0X04
-#define TSL2X7X_ALS_MINTHRESHHI		0X05
-#define TSL2X7X_ALS_MAXTHRESHLO		0X06
-#define TSL2X7X_ALS_MAXTHRESHHI		0X07
-#define TSL2X7X_PRX_MINTHRESHLO		0X08
-#define TSL2X7X_PRX_MINTHRESHHI		0X09
-#define TSL2X7X_PRX_MAXTHRESHLO		0X0A
-#define TSL2X7X_PRX_MAXTHRESHHI		0X0B
-#define TSL2X7X_PERSISTENCE		0x0C
-#define TSL2X7X_ALS_PRX_CONFIG		0x0D
-#define TSL2X7X_PRX_COUNT		0x0E
-#define TSL2X7X_GAIN			0x0F
-#define TSL2X7X_NOTUSED			0x10
-#define TSL2X7X_REVID			0x11
-#define TSL2X7X_CHIPID			0x12
-#define TSL2X7X_STATUS			0x13
-#define TSL2X7X_ALS_CHAN0LO		0x14
-#define TSL2X7X_ALS_CHAN0HI		0x15
-#define TSL2X7X_ALS_CHAN1LO		0x16
-#define TSL2X7X_ALS_CHAN1HI		0x17
-#define TSL2X7X_PRX_LO			0x18
-#define TSL2X7X_PRX_HI			0x19
-
-/* tsl2X7X cmd reg masks */
-#define TSL2X7X_CMD_REG			0x80
-#define TSL2X7X_CMD_SPL_FN		0x60
-#define TSL2X7X_CMD_REPEAT_PROTO	0x00
-#define TSL2X7X_CMD_AUTOINC_PROTO	0x20
-
-#define TSL2X7X_CMD_PROX_INT_CLR	0X05
-#define TSL2X7X_CMD_ALS_INT_CLR		0x06
-#define TSL2X7X_CMD_PROXALS_INT_CLR	0X07
-
-/* tsl2X7X cntrl reg masks */
-#define TSL2X7X_CNTL_ADC_ENBL		0x02
-#define TSL2X7X_CNTL_PWR_ON		0x01
-
-/* tsl2X7X status reg masks */
-#define TSL2X7X_STA_ADC_VALID		0x01
-#define TSL2X7X_STA_PRX_VALID		0x02
-#define TSL2X7X_STA_ADC_PRX_VALID	(TSL2X7X_STA_ADC_VALID | \
-					 TSL2X7X_STA_PRX_VALID)
-#define TSL2X7X_STA_ALS_INTR		0x10
-#define TSL2X7X_STA_PRX_INTR		0x20
-
-/* tsl2X7X cntrl reg masks */
-#define TSL2X7X_CNTL_REG_CLEAR		0x00
-#define TSL2X7X_CNTL_PROX_INT_ENBL	0X20
-#define TSL2X7X_CNTL_ALS_INT_ENBL	0X10
-#define TSL2X7X_CNTL_WAIT_TMR_ENBL	0X08
-#define TSL2X7X_CNTL_PROX_DET_ENBL	0X04
-#define TSL2X7X_CNTL_PWRON		0x01
-#define TSL2X7X_CNTL_ALSPON_ENBL	0x03
-#define TSL2X7X_CNTL_INTALSPON_ENBL	0x13
-#define TSL2X7X_CNTL_PROXPON_ENBL	0x0F
-#define TSL2X7X_CNTL_INTPROXPON_ENBL	0x2F
-
-/* TAOS txx2x7x Device family members */
+#define TSL2772_CNTRL			0x00
+#define TSL2772_ALS_TIME		0X01
+#define TSL2772_PRX_TIME		0x02
+#define TSL2772_WAIT_TIME		0x03
+#define TSL2772_ALS_MINTHRESHLO		0X04
+#define TSL2772_ALS_MINTHRESHHI		0X05
+#define TSL2772_ALS_MAXTHRESHLO		0X06
+#define TSL2772_ALS_MAXTHRESHHI		0X07
+#define TSL2772_PRX_MINTHRESHLO		0X08
+#define TSL2772_PRX_MINTHRESHHI		0X09
+#define TSL2772_PRX_MAXTHRESHLO		0X0A
+#define TSL2772_PRX_MAXTHRESHHI		0X0B
+#define TSL2772_PERSISTENCE		0x0C
+#define TSL2772_ALS_PRX_CONFIG		0x0D
+#define TSL2772_PRX_COUNT		0x0E
+#define TSL2772_GAIN			0x0F
+#define TSL2772_NOTUSED			0x10
+#define TSL2772_REVID			0x11
+#define TSL2772_CHIPID			0x12
+#define TSL2772_STATUS			0x13
+#define TSL2772_ALS_CHAN0LO		0x14
+#define TSL2772_ALS_CHAN0HI		0x15
+#define TSL2772_ALS_CHAN1LO		0x16
+#define TSL2772_ALS_CHAN1HI		0x17
+#define TSL2772_PRX_LO			0x18
+#define TSL2772_PRX_HI			0x19
+
+/* tsl2772 cmd reg masks */
+#define TSL2772_CMD_REG			0x80
+#define TSL2772_CMD_SPL_FN		0x60
+#define TSL2772_CMD_REPEAT_PROTO	0x00
+#define TSL2772_CMD_AUTOINC_PROTO	0x20
+
+#define TSL2772_CMD_PROX_INT_CLR	0X05
+#define TSL2772_CMD_ALS_INT_CLR		0x06
+#define TSL2772_CMD_PROXALS_INT_CLR	0X07
+
+/* tsl2772 cntrl reg masks */
+#define TSL2772_CNTL_ADC_ENBL		0x02
+#define TSL2772_CNTL_PWR_ON		0x01
+
+/* tsl2772 status reg masks */
+#define TSL2772_STA_ADC_VALID		0x01
+#define TSL2772_STA_PRX_VALID		0x02
+#define TSL2772_STA_ADC_PRX_VALID	(TSL2772_STA_ADC_VALID | \
+					 TSL2772_STA_PRX_VALID)
+#define TSL2772_STA_ALS_INTR		0x10
+#define TSL2772_STA_PRX_INTR		0x20
+
+/* tsl2772 cntrl reg masks */
+#define TSL2772_CNTL_REG_CLEAR		0x00
+#define TSL2772_CNTL_PROX_INT_ENBL	0X20
+#define TSL2772_CNTL_ALS_INT_ENBL	0X10
+#define TSL2772_CNTL_WAIT_TMR_ENBL	0X08
+#define TSL2772_CNTL_PROX_DET_ENBL	0X04
+#define TSL2772_CNTL_PWRON		0x01
+#define TSL2772_CNTL_ALSPON_ENBL	0x03
+#define TSL2772_CNTL_INTALSPON_ENBL	0x13
+#define TSL2772_CNTL_PROXPON_ENBL	0x0F
+#define TSL2772_CNTL_INTPROXPON_ENBL	0x2F
+
+/* TAOS Device family members */
 enum {
 	tsl2571,
 	tsl2671,
@@ -118,39 +119,39 @@ enum {
 };
 
 enum {
-	TSL2X7X_CHIP_UNKNOWN = 0,
-	TSL2X7X_CHIP_WORKING = 1,
-	TSL2X7X_CHIP_SUSPENDED = 2
+	TSL2772_CHIP_UNKNOWN = 0,
+	TSL2772_CHIP_WORKING = 1,
+	TSL2772_CHIP_SUSPENDED = 2
 };
 
 /* Per-device data */
-struct tsl2x7x_als_info {
+struct tsl2772_als_info {
 	u16 als_ch0;
 	u16 als_ch1;
 	u16 lux;
 };
 
-struct tsl2x7x_chip_info {
+struct tsl2772_chip_info {
 	int chan_table_elements;
 	struct iio_chan_spec channel_with_events[4];
 	struct iio_chan_spec channel_without_events[4];
 	const struct iio_info *info;
 };
 
-struct tsl2X7X_chip {
+struct tsl2772_chip {
 	kernel_ulong_t id;
 	struct mutex prox_mutex;
 	struct mutex als_mutex;
 	struct i2c_client *client;
 	u16 prox_data;
-	struct tsl2x7x_als_info als_cur_info;
-	struct tsl2x7x_settings settings;
-	struct tsl2X7X_platform_data *pdata;
+	struct tsl2772_als_info als_cur_info;
+	struct tsl2772_settings settings;
+	struct tsl2772_platform_data *pdata;
 	int als_gain_time_scale;
 	int als_saturation;
-	int tsl2x7x_chip_status;
-	u8 tsl2x7x_config[TSL2X7X_MAX_CONFIG_REG];
-	const struct tsl2x7x_chip_info	*chip_info;
+	int tsl2772_chip_status;
+	u8 tsl2772_config[TSL2772_MAX_CONFIG_REG];
+	const struct tsl2772_chip_info	*chip_info;
 	const struct iio_info *info;
 	s64 event_timestamp;
 	/*
@@ -158,7 +159,7 @@ struct tsl2X7X_chip {
 	 * updates via sysfs.
 	 * Sized to 9 = max 8 segments + 1 termination segment
 	 */
-	struct tsl2x7x_lux tsl2x7x_device_lux[TSL2X7X_MAX_LUX_TABLE_SIZE];
+	struct tsl2772_lux tsl2772_device_lux[TSL2772_MAX_LUX_TABLE_SIZE];
 };
 
 /*
@@ -169,31 +170,31 @@ struct tsl2X7X_chip {
  * The two rows in each table correspond to the Lux1 and Lux2 equations from
  * the datasheets.
  */
-static const struct tsl2x7x_lux tsl2x71_lux_table[TSL2X7X_DEF_LUX_TABLE_SZ] = {
+static const struct tsl2772_lux tsl2x71_lux_table[TSL2772_DEF_LUX_TABLE_SZ] = {
 	{ 53000, 106000 },
 	{ 31800,  53000 },
 	{ 0,          0 },
 };
 
-static const struct tsl2x7x_lux tmd2x71_lux_table[TSL2X7X_DEF_LUX_TABLE_SZ] = {
+static const struct tsl2772_lux tmd2x71_lux_table[TSL2772_DEF_LUX_TABLE_SZ] = {
 	{ 24000,  48000 },
 	{ 14400,  24000 },
 	{ 0,          0 },
 };
 
-static const struct tsl2x7x_lux tsl2x72_lux_table[TSL2X7X_DEF_LUX_TABLE_SZ] = {
+static const struct tsl2772_lux tsl2x72_lux_table[TSL2772_DEF_LUX_TABLE_SZ] = {
 	{ 60000, 112200 },
 	{ 37800,  60000 },
 	{     0,      0 },
 };
 
-static const struct tsl2x7x_lux tmd2x72_lux_table[TSL2X7X_DEF_LUX_TABLE_SZ] = {
+static const struct tsl2772_lux tmd2x72_lux_table[TSL2772_DEF_LUX_TABLE_SZ] = {
 	{ 20000,  35000 },
 	{ 12600,  20000 },
 	{     0,      0 },
 };
 
-static const struct tsl2x7x_lux *tsl2x7x_default_lux_table_group[] = {
+static const struct tsl2772_lux *tsl2772_default_lux_table_group[] = {
 	[tsl2571] =	tsl2x71_lux_table,
 	[tsl2671] =	tsl2x71_lux_table,
 	[tmd2671] =	tmd2x71_lux_table,
@@ -206,7 +207,7 @@ static const struct tsl2x7x_lux *tsl2x7x_default_lux_table_group[] = {
 	[tmd2772] =	tmd2x72_lux_table,
 };
 
-static const struct tsl2x7x_settings tsl2x7x_default_settings = {
+static const struct tsl2772_settings tsl2772_default_settings = {
 	.als_time = 255, /* 2.72 / 2.73 ms */
 	.als_gain = 0,
 	.prox_time = 255, /* 2.72 / 2.73 ms */
@@ -225,30 +226,30 @@ static const struct tsl2x7x_settings tsl2x7x_default_settings = {
 	.prox_thres_high = 512,
 	.prox_max_samples_cal = 30,
 	.prox_pulse_count = 8,
-	.prox_diode = TSL2X7X_DIODE1,
-	.prox_power = TSL2X7X_100_mA
+	.prox_diode = TSL2772_DIODE1,
+	.prox_power = TSL2772_100_mA
 };
 
-static const s16 tsl2x7x_als_gain[] = {
+static const s16 tsl2772_als_gain[] = {
 	1,
 	8,
 	16,
 	120
 };
 
-static const s16 tsl2x7x_prox_gain[] = {
+static const s16 tsl2772_prox_gain[] = {
 	1,
 	2,
 	4,
 	8
 };
 
-struct tsl2x7x_int_time {
+struct tsl2772_int_time {
 	int increment_us;
 	char *display_range;
 };
 
-static const struct tsl2x7x_int_time tsl2x7x_int_time[] = {
+static const struct tsl2772_int_time tsl2772_int_time[] = {
 	[tsl2571] = { 2720, "0.00272 - 0.696" },
 	[tsl2671] = { 2720, "0.00272 - 0.696" },
 	[tmd2671] = { 2720, "0.00272 - 0.696" },
@@ -283,12 +284,12 @@ static const u8 device_channel_config[] = {
 	[tmd2772] = ALSPRX2
 };
 
-static int tsl2x7x_read_status(struct tsl2X7X_chip *chip)
+static int tsl2772_read_status(struct tsl2772_chip *chip)
 {
 	int ret;
 
 	ret = i2c_smbus_read_byte_data(chip->client,
-				       TSL2X7X_CMD_REG | TSL2X7X_STATUS);
+				       TSL2772_CMD_REG | TSL2772_STATUS);
 	if (ret < 0)
 		dev_err(&chip->client->dev,
 			"%s: failed to read STATUS register: %d\n", __func__,
@@ -297,12 +298,12 @@ static int tsl2x7x_read_status(struct tsl2X7X_chip *chip)
 	return ret;
 }
 
-static int tsl2x7x_write_control_reg(struct tsl2X7X_chip *chip, u8 data)
+static int tsl2772_write_control_reg(struct tsl2772_chip *chip, u8 data)
 {
 	int ret;
 
 	ret = i2c_smbus_write_byte_data(chip->client,
-					TSL2X7X_CMD_REG | TSL2X7X_CNTRL, data);
+					TSL2772_CMD_REG | TSL2772_CNTRL, data);
 	if (ret < 0) {
 		dev_err(&chip->client->dev,
 			"%s: failed to write to control register %x: %d\n",
@@ -312,14 +313,14 @@ static int tsl2x7x_write_control_reg(struct tsl2X7X_chip *chip, u8 data)
 	return ret;
 }
 
-static int tsl2x7x_read_autoinc_regs(struct tsl2X7X_chip *chip, int lower_reg,
+static int tsl2772_read_autoinc_regs(struct tsl2772_chip *chip, int lower_reg,
 				     int upper_reg)
 {
 	u8 buf[2];
 	int ret;
 
 	ret = i2c_smbus_write_byte(chip->client,
-				   TSL2X7X_CMD_REG | TSL2X7X_CMD_AUTOINC_PROTO |
+				   TSL2772_CMD_REG | TSL2772_CMD_AUTOINC_PROTO |
 				   lower_reg);
 	if (ret < 0) {
 		dev_err(&chip->client->dev,
@@ -329,7 +330,7 @@ static int tsl2x7x_read_autoinc_regs(struct tsl2X7X_chip *chip, int lower_reg,
 	}
 
 	ret = i2c_smbus_read_byte_data(chip->client,
-				       TSL2X7X_CMD_REG | lower_reg);
+				       TSL2772_CMD_REG | lower_reg);
 	if (ret < 0) {
 		dev_err(&chip->client->dev,
 			"%s: failed to read from register %x: %d\n", __func__,
@@ -339,7 +340,7 @@ static int tsl2x7x_read_autoinc_regs(struct tsl2X7X_chip *chip, int lower_reg,
 	buf[0] = ret;
 
 	ret = i2c_smbus_read_byte_data(chip->client,
-				       TSL2X7X_CMD_REG | upper_reg);
+				       TSL2772_CMD_REG | upper_reg);
 	if (ret < 0) {
 		dev_err(&chip->client->dev,
 			"%s: failed to read from register %x: %d\n", __func__,
@@ -349,7 +350,7 @@ static int tsl2x7x_read_autoinc_regs(struct tsl2X7X_chip *chip, int lower_reg,
 	buf[1] = ret;
 
 	ret = i2c_smbus_write_byte(chip->client,
-				   TSL2X7X_CMD_REG | TSL2X7X_CMD_REPEAT_PROTO |
+				   TSL2772_CMD_REG | TSL2772_CMD_REPEAT_PROTO |
 				   lower_reg);
 	if (ret < 0) {
 		dev_err(&chip->client->dev,
@@ -362,7 +363,7 @@ static int tsl2x7x_read_autoinc_regs(struct tsl2X7X_chip *chip, int lower_reg,
 }
 
 /**
- * tsl2x7x_get_lux() - Reads and calculates current lux value.
+ * tsl2772_get_lux() - Reads and calculates current lux value.
  * @indio_dev:	pointer to IIO device
  *
  * The raw ch0 and ch1 values of the ambient light sensed in the last
@@ -372,47 +373,47 @@ static int tsl2x7x_read_autoinc_regs(struct tsl2X7X_chip *chip, int lower_reg,
  * coefficients. A lux gain trim is applied to each lux equation, and then the
  * maximum lux within the interval 0..65535 is selected.
  */
-static int tsl2x7x_get_lux(struct iio_dev *indio_dev)
+static int tsl2772_get_lux(struct iio_dev *indio_dev)
 {
-	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
-	struct tsl2x7x_lux *p;
+	struct tsl2772_chip *chip = iio_priv(indio_dev);
+	struct tsl2772_lux *p;
 	int max_lux, ret;
 	bool overflow;
 
 	mutex_lock(&chip->als_mutex);
 
-	if (chip->tsl2x7x_chip_status != TSL2X7X_CHIP_WORKING) {
+	if (chip->tsl2772_chip_status != TSL2772_CHIP_WORKING) {
 		dev_err(&chip->client->dev, "%s: device is not enabled\n",
 			__func__);
 		ret = -EBUSY;
 		goto out_unlock;
 	}
 
-	ret = tsl2x7x_read_status(chip);
+	ret = tsl2772_read_status(chip);
 	if (ret < 0)
 		goto out_unlock;
 
-	if (!(ret & TSL2X7X_STA_ADC_VALID)) {
+	if (!(ret & TSL2772_STA_ADC_VALID)) {
 		dev_err(&chip->client->dev,
 			"%s: data not valid yet\n", __func__);
 		ret = chip->als_cur_info.lux; /* return LAST VALUE */
 		goto out_unlock;
 	}
 
-	ret = tsl2x7x_read_autoinc_regs(chip, TSL2X7X_ALS_CHAN0LO,
-					TSL2X7X_ALS_CHAN0HI);
+	ret = tsl2772_read_autoinc_regs(chip, TSL2772_ALS_CHAN0LO,
+					TSL2772_ALS_CHAN0HI);
 	if (ret < 0)
 		goto out_unlock;
 	chip->als_cur_info.als_ch0 = ret;
 
-	ret = tsl2x7x_read_autoinc_regs(chip, TSL2X7X_ALS_CHAN1LO,
-					TSL2X7X_ALS_CHAN1HI);
+	ret = tsl2772_read_autoinc_regs(chip, TSL2772_ALS_CHAN1LO,
+					TSL2772_ALS_CHAN1HI);
 	if (ret < 0)
 		goto out_unlock;
 	chip->als_cur_info.als_ch1 = ret;
 
 	if (chip->als_cur_info.als_ch0 >= chip->als_saturation) {
-		max_lux = TSL2X7X_LUX_CALC_OVER_FLOW;
+		max_lux = TSL2772_LUX_CALC_OVER_FLOW;
 		goto update_struct_with_max_lux;
 	}
 
@@ -424,7 +425,7 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev)
 
 	max_lux = 0;
 	overflow = false;
-	for (p = (struct tsl2x7x_lux *)chip->tsl2x7x_device_lux; p->ch0 != 0;
+	for (p = (struct tsl2772_lux *)chip->tsl2772_device_lux; p->ch0 != 0;
 	     p++) {
 		int lux;
 
@@ -440,7 +441,7 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev)
 		 */
 		lux = (lux * chip->settings.als_gain_trim) / 1000;
 
-		if (lux > TSL2X7X_LUX_CALC_OVER_FLOW) {
+		if (lux > TSL2772_LUX_CALC_OVER_FLOW) {
 			overflow = true;
 			continue;
 		}
@@ -449,7 +450,7 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev)
 	}
 
 	if (overflow && max_lux == 0)
-		max_lux = TSL2X7X_LUX_CALC_OVER_FLOW;
+		max_lux = TSL2772_LUX_CALC_OVER_FLOW;
 
 update_struct_with_max_lux:
 	chip->als_cur_info.lux = max_lux;
@@ -462,19 +463,19 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev)
 }
 
 /**
- * tsl2x7x_get_prox() - Reads proximity data registers and updates
+ * tsl2772_get_prox() - Reads proximity data registers and updates
  *                      chip->prox_data.
  *
  * @indio_dev:	pointer to IIO device
  */
-static int tsl2x7x_get_prox(struct iio_dev *indio_dev)
+static int tsl2772_get_prox(struct iio_dev *indio_dev)
 {
-	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
+	struct tsl2772_chip *chip = iio_priv(indio_dev);
 	int ret;
 
 	mutex_lock(&chip->prox_mutex);
 
-	ret = tsl2x7x_read_status(chip);
+	ret = tsl2772_read_status(chip);
 	if (ret < 0)
 		goto prox_poll_err;
 
@@ -484,7 +485,7 @@ static int tsl2x7x_get_prox(struct iio_dev *indio_dev)
 	case tmd2671:
 	case tsl2771:
 	case tmd2771:
-		if (!(ret & TSL2X7X_STA_ADC_VALID)) {
+		if (!(ret & TSL2772_STA_ADC_VALID)) {
 			ret = -EINVAL;
 			goto prox_poll_err;
 		}
@@ -494,14 +495,14 @@ static int tsl2x7x_get_prox(struct iio_dev *indio_dev)
 	case tmd2672:
 	case tsl2772:
 	case tmd2772:
-		if (!(ret & TSL2X7X_STA_PRX_VALID)) {
+		if (!(ret & TSL2772_STA_PRX_VALID)) {
 			ret = -EINVAL;
 			goto prox_poll_err;
 		}
 		break;
 	}
 
-	ret = tsl2x7x_read_autoinc_regs(chip, TSL2X7X_PRX_LO, TSL2X7X_PRX_HI);
+	ret = tsl2772_read_autoinc_regs(chip, TSL2772_PRX_LO, TSL2772_PRX_HI);
 	if (ret < 0)
 		goto prox_poll_err;
 	chip->prox_data = ret;
@@ -513,46 +514,46 @@ static int tsl2x7x_get_prox(struct iio_dev *indio_dev)
 }
 
 /**
- * tsl2x7x_defaults() - Populates the device nominal operating parameters
+ * tsl2772_defaults() - Populates the device nominal operating parameters
  *                      with those provided by a 'platform' data struct or
  *                      with prefined defaults.
  *
  * @chip:               pointer to device structure.
  */
-static void tsl2x7x_defaults(struct tsl2X7X_chip *chip)
+static void tsl2772_defaults(struct tsl2772_chip *chip)
 {
 	/* If Operational settings defined elsewhere.. */
 	if (chip->pdata && chip->pdata->platform_default_settings)
 		memcpy(&chip->settings, chip->pdata->platform_default_settings,
-		       sizeof(tsl2x7x_default_settings));
+		       sizeof(tsl2772_default_settings));
 	else
-		memcpy(&chip->settings, &tsl2x7x_default_settings,
-		       sizeof(tsl2x7x_default_settings));
+		memcpy(&chip->settings, &tsl2772_default_settings,
+		       sizeof(tsl2772_default_settings));
 
 	/* Load up the proper lux table. */
 	if (chip->pdata && chip->pdata->platform_lux_table[0].ch0 != 0)
-		memcpy(chip->tsl2x7x_device_lux,
+		memcpy(chip->tsl2772_device_lux,
 		       chip->pdata->platform_lux_table,
 		       sizeof(chip->pdata->platform_lux_table));
 	else
-		memcpy(chip->tsl2x7x_device_lux,
-		       tsl2x7x_default_lux_table_group[chip->id],
-		       TSL2X7X_DEFAULT_TABLE_BYTES);
+		memcpy(chip->tsl2772_device_lux,
+		       tsl2772_default_lux_table_group[chip->id],
+		       TSL2772_DEFAULT_TABLE_BYTES);
 }
 
 /**
- * tsl2x7x_als_calibrate() -	Obtain single reading and calculate
+ * tsl2772_als_calibrate() -	Obtain single reading and calculate
  *                              the als_gain_trim.
  *
  * @indio_dev:	pointer to IIO device
  */
-static int tsl2x7x_als_calibrate(struct iio_dev *indio_dev)
+static int tsl2772_als_calibrate(struct iio_dev *indio_dev)
 {
-	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
+	struct tsl2772_chip *chip = iio_priv(indio_dev);
 	int ret, lux_val;
 
 	ret = i2c_smbus_read_byte_data(chip->client,
-				       TSL2X7X_CMD_REG | TSL2X7X_CNTRL);
+				       TSL2772_CMD_REG | TSL2772_CNTRL);
 	if (ret < 0) {
 		dev_err(&chip->client->dev,
 			"%s: failed to read from the CNTRL register\n",
@@ -560,20 +561,20 @@ static int tsl2x7x_als_calibrate(struct iio_dev *indio_dev)
 		return ret;
 	}
 
-	if ((ret & (TSL2X7X_CNTL_ADC_ENBL | TSL2X7X_CNTL_PWR_ON))
-			!= (TSL2X7X_CNTL_ADC_ENBL | TSL2X7X_CNTL_PWR_ON)) {
+	if ((ret & (TSL2772_CNTL_ADC_ENBL | TSL2772_CNTL_PWR_ON))
+			!= (TSL2772_CNTL_ADC_ENBL | TSL2772_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 & TSL2X7X_STA_ADC_VALID) != TSL2X7X_STA_ADC_VALID) {
+	} else if ((ret & TSL2772_STA_ADC_VALID) != TSL2772_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 = tsl2x7x_get_lux(indio_dev);
+	lux_val = tsl2772_get_lux(indio_dev);
 	if (lux_val < 0) {
 		dev_err(&chip->client->dev,
 			"%s: failed to get lux\n", __func__);
@@ -590,51 +591,51 @@ static int tsl2x7x_als_calibrate(struct iio_dev *indio_dev)
 	return ret;
 }
 
-static int tsl2x7x_chip_on(struct iio_dev *indio_dev)
+static int tsl2772_chip_on(struct iio_dev *indio_dev)
 {
-	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
+	struct tsl2772_chip *chip = iio_priv(indio_dev);
 	int ret, i, als_count, als_time_us;
 	u8 *dev_reg, reg_val;
 
 	/* Non calculated parameters */
-	chip->tsl2x7x_config[TSL2X7X_ALS_TIME] = chip->settings.als_time;
-	chip->tsl2x7x_config[TSL2X7X_PRX_TIME] = chip->settings.prox_time;
-	chip->tsl2x7x_config[TSL2X7X_WAIT_TIME] = chip->settings.wait_time;
-	chip->tsl2x7x_config[TSL2X7X_ALS_PRX_CONFIG] =
+	chip->tsl2772_config[TSL2772_ALS_TIME] = chip->settings.als_time;
+	chip->tsl2772_config[TSL2772_PRX_TIME] = chip->settings.prox_time;
+	chip->tsl2772_config[TSL2772_WAIT_TIME] = chip->settings.wait_time;
+	chip->tsl2772_config[TSL2772_ALS_PRX_CONFIG] =
 		chip->settings.als_prox_config;
 
-	chip->tsl2x7x_config[TSL2X7X_ALS_MINTHRESHLO] =
+	chip->tsl2772_config[TSL2772_ALS_MINTHRESHLO] =
 		(chip->settings.als_thresh_low) & 0xFF;
-	chip->tsl2x7x_config[TSL2X7X_ALS_MINTHRESHHI] =
+	chip->tsl2772_config[TSL2772_ALS_MINTHRESHHI] =
 		(chip->settings.als_thresh_low >> 8) & 0xFF;
-	chip->tsl2x7x_config[TSL2X7X_ALS_MAXTHRESHLO] =
+	chip->tsl2772_config[TSL2772_ALS_MAXTHRESHLO] =
 		(chip->settings.als_thresh_high) & 0xFF;
-	chip->tsl2x7x_config[TSL2X7X_ALS_MAXTHRESHHI] =
+	chip->tsl2772_config[TSL2772_ALS_MAXTHRESHHI] =
 		(chip->settings.als_thresh_high >> 8) & 0xFF;
-	chip->tsl2x7x_config[TSL2X7X_PERSISTENCE] =
+	chip->tsl2772_config[TSL2772_PERSISTENCE] =
 		(chip->settings.prox_persistence & 0xFF) << 4 |
 		(chip->settings.als_persistence & 0xFF);
 
-	chip->tsl2x7x_config[TSL2X7X_PRX_COUNT] =
+	chip->tsl2772_config[TSL2772_PRX_COUNT] =
 			chip->settings.prox_pulse_count;
-	chip->tsl2x7x_config[TSL2X7X_PRX_MINTHRESHLO] =
+	chip->tsl2772_config[TSL2772_PRX_MINTHRESHLO] =
 			(chip->settings.prox_thres_low) & 0xFF;
-	chip->tsl2x7x_config[TSL2X7X_PRX_MINTHRESHHI] =
+	chip->tsl2772_config[TSL2772_PRX_MINTHRESHHI] =
 			(chip->settings.prox_thres_low >> 8) & 0xFF;
-	chip->tsl2x7x_config[TSL2X7X_PRX_MAXTHRESHLO] =
+	chip->tsl2772_config[TSL2772_PRX_MAXTHRESHLO] =
 			(chip->settings.prox_thres_high) & 0xFF;
-	chip->tsl2x7x_config[TSL2X7X_PRX_MAXTHRESHHI] =
+	chip->tsl2772_config[TSL2772_PRX_MAXTHRESHHI] =
 			(chip->settings.prox_thres_high >> 8) & 0xFF;
 
 	/* and make sure we're not already on */
-	if (chip->tsl2x7x_chip_status == TSL2X7X_CHIP_WORKING) {
+	if (chip->tsl2772_chip_status == TSL2772_CHIP_WORKING) {
 		/* if forcing a register update - turn off, then on */
 		dev_info(&chip->client->dev, "device is already enabled\n");
 		return -EINVAL;
 	}
 
-	/* Set the gain based on tsl2x7x_settings struct */
-	chip->tsl2x7x_config[TSL2X7X_GAIN] =
+	/* Set the gain based on tsl2772_settings struct */
+	chip->tsl2772_config[TSL2772_GAIN] =
 		(chip->settings.als_gain & 0xFF) |
 		((chip->settings.prox_gain & 0xFF) << 2) |
 		(chip->settings.prox_diode << 4) |
@@ -642,16 +643,16 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev)
 
 	/* set chip time scaling and saturation */
 	als_count = 256 - chip->settings.als_time;
-	als_time_us = als_count * tsl2x7x_int_time[chip->id].increment_us;
+	als_time_us = als_count * tsl2772_int_time[chip->id].increment_us;
 	chip->als_saturation = als_count * 768; /* 75% of full scale */
 	chip->als_gain_time_scale = als_time_us *
-		tsl2x7x_als_gain[chip->settings.als_gain];
+		tsl2772_als_gain[chip->settings.als_gain];
 
 	/*
-	 * TSL2X7X Specific power-on / adc enable sequence
+	 * TSL2772 Specific power-on / adc enable sequence
 	 * Power on the device 1st.
 	 */
-	ret = tsl2x7x_write_control_reg(chip, TSL2X7X_CNTL_PWR_ON);
+	ret = tsl2772_write_control_reg(chip, TSL2772_CNTL_PWR_ON);
 	if (ret < 0)
 		return ret;
 
@@ -659,9 +660,9 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev)
 	 * Use the following shadow copy for our delay before enabling ADC.
 	 * Write all the registers.
 	 */
-	for (i = 0, dev_reg = chip->tsl2x7x_config;
-			i < TSL2X7X_MAX_CONFIG_REG; i++) {
-		int reg = TSL2X7X_CMD_REG + i;
+	for (i = 0, dev_reg = chip->tsl2772_config;
+			i < TSL2772_MAX_CONFIG_REG; i++) {
+		int reg = TSL2772_CMD_REG + i;
 
 		ret = i2c_smbus_write_byte_data(chip->client, reg,
 						*dev_reg++);
@@ -676,20 +677,20 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev)
 	/* Power-on settling time */
 	usleep_range(3000, 3500);
 
-	reg_val = TSL2X7X_CNTL_PWR_ON | TSL2X7X_CNTL_ADC_ENBL |
-		  TSL2X7X_CNTL_PROX_DET_ENBL;
+	reg_val = TSL2772_CNTL_PWR_ON | TSL2772_CNTL_ADC_ENBL |
+		  TSL2772_CNTL_PROX_DET_ENBL;
 	if (chip->settings.als_interrupt_en)
-		reg_val |= TSL2X7X_CNTL_ALS_INT_ENBL;
+		reg_val |= TSL2772_CNTL_ALS_INT_ENBL;
 	if (chip->settings.prox_interrupt_en)
-		reg_val |= TSL2X7X_CNTL_PROX_INT_ENBL;
+		reg_val |= TSL2772_CNTL_PROX_INT_ENBL;
 
-	ret = tsl2x7x_write_control_reg(chip, reg_val);
+	ret = tsl2772_write_control_reg(chip, reg_val);
 	if (ret < 0)
 		return ret;
 
 	ret = i2c_smbus_write_byte(chip->client,
-				   TSL2X7X_CMD_REG | TSL2X7X_CMD_SPL_FN |
-				   TSL2X7X_CMD_PROXALS_INT_CLR);
+				   TSL2772_CMD_REG | TSL2772_CMD_SPL_FN |
+				   TSL2772_CMD_PROXALS_INT_CLR);
 	if (ret < 0) {
 		dev_err(&chip->client->dev,
 			"%s: failed to clear interrupt status: %d\n",
@@ -697,22 +698,22 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev)
 		return ret;
 	}
 
-	chip->tsl2x7x_chip_status = TSL2X7X_CHIP_WORKING;
+	chip->tsl2772_chip_status = TSL2772_CHIP_WORKING;
 
 	return ret;
 }
 
-static int tsl2x7x_chip_off(struct iio_dev *indio_dev)
+static int tsl2772_chip_off(struct iio_dev *indio_dev)
 {
-	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
+	struct tsl2772_chip *chip = iio_priv(indio_dev);
 
 	/* turn device off */
-	chip->tsl2x7x_chip_status = TSL2X7X_CHIP_SUSPENDED;
-	return tsl2x7x_write_control_reg(chip, 0x00);
+	chip->tsl2772_chip_status = TSL2772_CHIP_SUSPENDED;
+	return tsl2772_write_control_reg(chip, 0x00);
 }
 
 /**
- * tsl2x7x_invoke_change - power cycle the device to implement the user
+ * tsl2772_invoke_change - power cycle the device to implement the user
  *                         parameters
  * @indio_dev:	pointer to IIO device
  *
@@ -720,22 +721,22 @@ static int tsl2x7x_chip_off(struct iio_dev *indio_dev)
  * (On/Off), cycle device to implement updated parameter, put device back into
  * proper state, and unlock resource.
  */
-static int tsl2x7x_invoke_change(struct iio_dev *indio_dev)
+static int tsl2772_invoke_change(struct iio_dev *indio_dev)
 {
-	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
-	int device_status = chip->tsl2x7x_chip_status;
+	struct tsl2772_chip *chip = iio_priv(indio_dev);
+	int device_status = chip->tsl2772_chip_status;
 	int ret;
 
 	mutex_lock(&chip->als_mutex);
 	mutex_lock(&chip->prox_mutex);
 
-	if (device_status == TSL2X7X_CHIP_WORKING) {
-		ret = tsl2x7x_chip_off(indio_dev);
+	if (device_status == TSL2772_CHIP_WORKING) {
+		ret = tsl2772_chip_off(indio_dev);
 		if (ret < 0)
 			goto unlock;
 	}
 
-	ret = tsl2x7x_chip_on(indio_dev);
+	ret = tsl2772_chip_on(indio_dev);
 
 unlock:
 	mutex_unlock(&chip->prox_mutex);
@@ -744,9 +745,9 @@ static int tsl2x7x_invoke_change(struct iio_dev *indio_dev)
 	return ret;
 }
 
-static int tsl2x7x_prox_cal(struct iio_dev *indio_dev)
+static int tsl2772_prox_cal(struct iio_dev *indio_dev)
 {
-	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
+	struct tsl2772_chip *chip = iio_priv(indio_dev);
 	int prox_history[MAX_SAMPLES_CAL + 1];
 	int i, ret, mean, max, sample_sum;
 
@@ -756,7 +757,7 @@ static int tsl2x7x_prox_cal(struct iio_dev *indio_dev)
 
 	for (i = 0; i < chip->settings.prox_max_samples_cal; i++) {
 		usleep_range(15000, 17500);
-		ret = tsl2x7x_get_prox(indio_dev);
+		ret = tsl2772_get_prox(indio_dev);
 		if (ret < 0)
 			return ret;
 
@@ -773,7 +774,7 @@ static int tsl2x7x_prox_cal(struct iio_dev *indio_dev)
 
 	chip->settings.prox_thres_high = (max << 1) - mean;
 
-	return tsl2x7x_invoke_change(indio_dev);
+	return tsl2772_invoke_change(indio_dev);
 }
 
 static IIO_CONST_ATTR(in_intensity0_calibscale_available, "1 8 16 120");
@@ -785,17 +786,17 @@ in_intensity0_integration_time_available_show(struct device *dev,
 					      struct device_attribute *attr,
 					      char *buf)
 {
-	struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev));
+	struct tsl2772_chip *chip = iio_priv(dev_to_iio_dev(dev));
 
 	return snprintf(buf, PAGE_SIZE, "%s\n",
-			tsl2x7x_int_time[chip->id].display_range);
+			tsl2772_int_time[chip->id].display_range);
 }
 
 static ssize_t in_illuminance0_target_input_show(struct device *dev,
 						 struct device_attribute *attr,
 						 char *buf)
 {
-	struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev));
+	struct tsl2772_chip *chip = iio_priv(dev_to_iio_dev(dev));
 
 	return snprintf(buf, PAGE_SIZE, "%d\n", chip->settings.als_cal_target);
 }
@@ -805,7 +806,7 @@ static ssize_t in_illuminance0_target_input_store(struct device *dev,
 						  const char *buf, size_t len)
 {
 	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
-	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
+	struct tsl2772_chip *chip = iio_priv(indio_dev);
 	u16 value;
 	int ret;
 
@@ -813,7 +814,7 @@ static ssize_t in_illuminance0_target_input_store(struct device *dev,
 		return -EINVAL;
 
 	chip->settings.als_cal_target = value;
-	ret = tsl2x7x_invoke_change(indio_dev);
+	ret = tsl2772_invoke_change(indio_dev);
 	if (ret < 0)
 		return ret;
 
@@ -831,11 +832,11 @@ static ssize_t in_illuminance0_calibrate_store(struct device *dev,
 	if (kstrtobool(buf, &value) || !value)
 		return -EINVAL;
 
-	ret = tsl2x7x_als_calibrate(indio_dev);
+	ret = tsl2772_als_calibrate(indio_dev);
 	if (ret < 0)
 		return ret;
 
-	ret = tsl2x7x_invoke_change(indio_dev);
+	ret = tsl2772_invoke_change(indio_dev);
 	if (ret < 0)
 		return ret;
 
@@ -846,15 +847,15 @@ static ssize_t in_illuminance0_lux_table_show(struct device *dev,
 					      struct device_attribute *attr,
 					      char *buf)
 {
-	struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev));
+	struct tsl2772_chip *chip = iio_priv(dev_to_iio_dev(dev));
 	int i = 0;
 	int offset = 0;
 
-	while (i < TSL2X7X_MAX_LUX_TABLE_SIZE) {
+	while (i < TSL2772_MAX_LUX_TABLE_SIZE) {
 		offset += snprintf(buf + offset, PAGE_SIZE, "%u,%u,",
-			chip->tsl2x7x_device_lux[i].ch0,
-			chip->tsl2x7x_device_lux[i].ch1);
-		if (chip->tsl2x7x_device_lux[i].ch0 == 0) {
+			chip->tsl2772_device_lux[i].ch0,
+			chip->tsl2772_device_lux[i].ch1);
+		if (chip->tsl2772_device_lux[i].ch0 == 0) {
 			/*
 			 * We just printed the first "0" entry.
 			 * Now get rid of the extra "," and break.
@@ -874,8 +875,8 @@ static ssize_t in_illuminance0_lux_table_store(struct device *dev,
 					       const char *buf, size_t len)
 {
 	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
-	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
-	int value[ARRAY_SIZE(chip->tsl2x7x_device_lux) * 2 + 1];
+	struct tsl2772_chip *chip = iio_priv(indio_dev);
+	int value[ARRAY_SIZE(chip->tsl2772_device_lux) * 2 + 1];
 	int n, ret;
 
 	get_options(buf, ARRAY_SIZE(value), value);
@@ -888,23 +889,23 @@ static ssize_t in_illuminance0_lux_table_store(struct device *dev,
 	 */
 	n = value[0];
 	if ((n % 2) || n < 4 ||
-	    n > ((ARRAY_SIZE(chip->tsl2x7x_device_lux) - 1) * 2))
+	    n > ((ARRAY_SIZE(chip->tsl2772_device_lux) - 1) * 2))
 		return -EINVAL;
 
 	if ((value[(n - 1)] | value[n]) != 0)
 		return -EINVAL;
 
-	if (chip->tsl2x7x_chip_status == TSL2X7X_CHIP_WORKING) {
-		ret = tsl2x7x_chip_off(indio_dev);
+	if (chip->tsl2772_chip_status == TSL2772_CHIP_WORKING) {
+		ret = tsl2772_chip_off(indio_dev);
 		if (ret < 0)
 			return ret;
 	}
 
 	/* Zero out the table */
-	memset(chip->tsl2x7x_device_lux, 0, sizeof(chip->tsl2x7x_device_lux));
-	memcpy(chip->tsl2x7x_device_lux, &value[1], (value[0] * 4));
+	memset(chip->tsl2772_device_lux, 0, sizeof(chip->tsl2772_device_lux));
+	memcpy(chip->tsl2772_device_lux, &value[1], (value[0] * 4));
 
-	ret = tsl2x7x_invoke_change(indio_dev);
+	ret = tsl2772_invoke_change(indio_dev);
 	if (ret < 0)
 		return ret;
 
@@ -922,23 +923,23 @@ static ssize_t in_proximity0_calibrate_store(struct device *dev,
 	if (kstrtobool(buf, &value) || !value)
 		return -EINVAL;
 
-	ret = tsl2x7x_prox_cal(indio_dev);
+	ret = tsl2772_prox_cal(indio_dev);
 	if (ret < 0)
 		return ret;
 
-	ret = tsl2x7x_invoke_change(indio_dev);
+	ret = tsl2772_invoke_change(indio_dev);
 	if (ret < 0)
 		return ret;
 
 	return len;
 }
 
-static int tsl2x7x_read_interrupt_config(struct iio_dev *indio_dev,
+static int tsl2772_read_interrupt_config(struct iio_dev *indio_dev,
 					 const struct iio_chan_spec *chan,
 					 enum iio_event_type type,
 					 enum iio_event_direction dir)
 {
-	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
+	struct tsl2772_chip *chip = iio_priv(indio_dev);
 
 	if (chan->type == IIO_INTENSITY)
 		return chip->settings.als_interrupt_en;
@@ -946,30 +947,30 @@ static int tsl2x7x_read_interrupt_config(struct iio_dev *indio_dev,
 		return chip->settings.prox_interrupt_en;
 }
 
-static int tsl2x7x_write_interrupt_config(struct iio_dev *indio_dev,
+static int tsl2772_write_interrupt_config(struct iio_dev *indio_dev,
 					  const struct iio_chan_spec *chan,
 					  enum iio_event_type type,
 					  enum iio_event_direction dir,
 					  int val)
 {
-	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
+	struct tsl2772_chip *chip = iio_priv(indio_dev);
 
 	if (chan->type == IIO_INTENSITY)
 		chip->settings.als_interrupt_en = val ? true : false;
 	else
 		chip->settings.prox_interrupt_en = val ? true : false;
 
-	return tsl2x7x_invoke_change(indio_dev);
+	return tsl2772_invoke_change(indio_dev);
 }
 
-static int tsl2x7x_write_event_value(struct iio_dev *indio_dev,
+static int tsl2772_write_event_value(struct iio_dev *indio_dev,
 				     const struct iio_chan_spec *chan,
 				     enum iio_event_type type,
 				     enum iio_event_direction dir,
 				     enum iio_event_info info,
 				     int val, int val2)
 {
-	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
+	struct tsl2772_chip *chip = iio_priv(indio_dev);
 	int ret = -EINVAL, count, persistence;
 	u8 time;
 
@@ -1011,7 +1012,7 @@ static int tsl2x7x_write_event_value(struct iio_dev *indio_dev,
 
 		count = 256 - time;
 		persistence = ((val * 1000000) + val2) /
-			(count * tsl2x7x_int_time[chip->id].increment_us);
+			(count * tsl2772_int_time[chip->id].increment_us);
 
 		if (chan->type == IIO_INTENSITY) {
 			/* ALS filter values are 1, 2, 3, 5, 10, 15, ..., 60 */
@@ -1032,17 +1033,17 @@ static int tsl2x7x_write_event_value(struct iio_dev *indio_dev,
 	if (ret < 0)
 		return ret;
 
-	return tsl2x7x_invoke_change(indio_dev);
+	return tsl2772_invoke_change(indio_dev);
 }
 
-static int tsl2x7x_read_event_value(struct iio_dev *indio_dev,
+static int tsl2772_read_event_value(struct iio_dev *indio_dev,
 				    const struct iio_chan_spec *chan,
 				    enum iio_event_type type,
 				    enum iio_event_direction dir,
 				    enum iio_event_info info,
 				    int *val, int *val2)
 {
-	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
+	struct tsl2772_chip *chip = iio_priv(indio_dev);
 	int ret = -EINVAL, filter_delay, persistence;
 	u8 time;
 
@@ -1090,7 +1091,7 @@ static int tsl2x7x_read_event_value(struct iio_dev *indio_dev,
 		}
 
 		filter_delay = persistence * (256 - time) *
-			tsl2x7x_int_time[chip->id].increment_us;
+			tsl2772_int_time[chip->id].increment_us;
 
 		*val = filter_delay / 1000000;
 		*val2 = filter_delay % 1000000;
@@ -1103,20 +1104,20 @@ static int tsl2x7x_read_event_value(struct iio_dev *indio_dev,
 	return ret;
 }
 
-static int tsl2x7x_read_raw(struct iio_dev *indio_dev,
+static int tsl2772_read_raw(struct iio_dev *indio_dev,
 			    struct iio_chan_spec const *chan,
 			    int *val,
 			    int *val2,
 			    long mask)
 {
-	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
+	struct tsl2772_chip *chip = iio_priv(indio_dev);
 	int ret = -EINVAL;
 
 	switch (mask) {
 	case IIO_CHAN_INFO_PROCESSED:
 		switch (chan->type) {
 		case IIO_LIGHT:
-			tsl2x7x_get_lux(indio_dev);
+			tsl2772_get_lux(indio_dev);
 			*val = chip->als_cur_info.lux;
 			ret = IIO_VAL_INT;
 			break;
@@ -1127,7 +1128,7 @@ static int tsl2x7x_read_raw(struct iio_dev *indio_dev,
 	case IIO_CHAN_INFO_RAW:
 		switch (chan->type) {
 		case IIO_INTENSITY:
-			tsl2x7x_get_lux(indio_dev);
+			tsl2772_get_lux(indio_dev);
 			if (chan->channel == 0)
 				*val = chip->als_cur_info.als_ch0;
 			else
@@ -1135,7 +1136,7 @@ static int tsl2x7x_read_raw(struct iio_dev *indio_dev,
 			ret = IIO_VAL_INT;
 			break;
 		case IIO_PROXIMITY:
-			tsl2x7x_get_prox(indio_dev);
+			tsl2772_get_prox(indio_dev);
 			*val = chip->prox_data;
 			ret = IIO_VAL_INT;
 			break;
@@ -1145,9 +1146,9 @@ static int tsl2x7x_read_raw(struct iio_dev *indio_dev,
 		break;
 	case IIO_CHAN_INFO_CALIBSCALE:
 		if (chan->type == IIO_LIGHT)
-			*val = tsl2x7x_als_gain[chip->settings.als_gain];
+			*val = tsl2772_als_gain[chip->settings.als_gain];
 		else
-			*val = tsl2x7x_prox_gain[chip->settings.prox_gain];
+			*val = tsl2772_prox_gain[chip->settings.prox_gain];
 		ret = IIO_VAL_INT;
 		break;
 	case IIO_CHAN_INFO_CALIBBIAS:
@@ -1157,7 +1158,7 @@ static int tsl2x7x_read_raw(struct iio_dev *indio_dev,
 	case IIO_CHAN_INFO_INT_TIME:
 		*val = 0;
 		*val2 = (256 - chip->settings.als_time) *
-			tsl2x7x_int_time[chip->id].increment_us;
+			tsl2772_int_time[chip->id].increment_us;
 		ret = IIO_VAL_INT_PLUS_MICRO;
 		break;
 	default:
@@ -1167,13 +1168,13 @@ static int tsl2x7x_read_raw(struct iio_dev *indio_dev,
 	return ret;
 }
 
-static int tsl2x7x_write_raw(struct iio_dev *indio_dev,
+static int tsl2772_write_raw(struct iio_dev *indio_dev,
 			     struct iio_chan_spec const *chan,
 			     int val,
 			     int val2,
 			     long mask)
 {
-	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
+	struct tsl2772_chip *chip = iio_priv(indio_dev);
 
 	switch (mask) {
 	case IIO_CHAN_INFO_CALIBSCALE:
@@ -1218,13 +1219,13 @@ static int tsl2x7x_write_raw(struct iio_dev *indio_dev,
 		break;
 	case IIO_CHAN_INFO_INT_TIME:
 		chip->settings.als_time = 256 -
-			(val2 / tsl2x7x_int_time[chip->id].increment_us);
+			(val2 / tsl2772_int_time[chip->id].increment_us);
 		break;
 	default:
 		return -EINVAL;
 	}
 
-	return tsl2x7x_invoke_change(indio_dev);
+	return tsl2772_invoke_change(indio_dev);
 }
 
 static DEVICE_ATTR_RO(in_intensity0_integration_time_available);
@@ -1238,7 +1239,7 @@ static DEVICE_ATTR_WO(in_proximity0_calibrate);
 static DEVICE_ATTR_RW(in_illuminance0_lux_table);
 
 /* Use the default register values to identify the Taos device */
-static int tsl2x7x_device_id_verif(int id, int target)
+static int tsl2772_device_id_verif(int id, int target)
 {
 	switch (target) {
 	case tsl2571:
@@ -1259,19 +1260,19 @@ static int tsl2x7x_device_id_verif(int id, int target)
 	return -EINVAL;
 }
 
-static irqreturn_t tsl2x7x_event_handler(int irq, void *private)
+static irqreturn_t tsl2772_event_handler(int irq, void *private)
 {
 	struct iio_dev *indio_dev = private;
-	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
+	struct tsl2772_chip *chip = iio_priv(indio_dev);
 	s64 timestamp = iio_get_time_ns(indio_dev);
 	int ret;
 
-	ret = tsl2x7x_read_status(chip);
+	ret = tsl2772_read_status(chip);
 	if (ret < 0)
 		return IRQ_HANDLED;
 
 	/* What type of interrupt do we need to process */
-	if (ret & TSL2X7X_STA_PRX_INTR) {
+	if (ret & TSL2772_STA_PRX_INTR) {
 		iio_push_event(indio_dev,
 			       IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY,
 						    0,
@@ -1280,7 +1281,7 @@ static irqreturn_t tsl2x7x_event_handler(int irq, void *private)
 						    timestamp);
 	}
 
-	if (ret & TSL2X7X_STA_ALS_INTR) {
+	if (ret & TSL2772_STA_ALS_INTR) {
 		iio_push_event(indio_dev,
 			       IIO_UNMOD_EVENT_CODE(IIO_LIGHT,
 						    0,
@@ -1290,8 +1291,8 @@ static irqreturn_t tsl2x7x_event_handler(int irq, void *private)
 	}
 
 	ret = i2c_smbus_write_byte(chip->client,
-				   TSL2X7X_CMD_REG | TSL2X7X_CMD_SPL_FN |
-				   TSL2X7X_CMD_PROXALS_INT_CLR);
+				   TSL2772_CMD_REG | TSL2772_CMD_SPL_FN |
+				   TSL2772_CMD_PROXALS_INT_CLR);
 	if (ret < 0)
 		dev_err(&chip->client->dev,
 			"%s: failed to clear interrupt status: %d\n",
@@ -1300,7 +1301,7 @@ static irqreturn_t tsl2x7x_event_handler(int irq, void *private)
 	return IRQ_HANDLED;
 }
 
-static struct attribute *tsl2x7x_ALS_device_attrs[] = {
+static struct attribute *tsl2772_ALS_device_attrs[] = {
 	&iio_const_attr_in_intensity0_calibscale_available.dev_attr.attr,
 	&dev_attr_in_intensity0_integration_time_available.attr,
 	&dev_attr_in_illuminance0_target_input.attr,
@@ -1309,12 +1310,12 @@ static struct attribute *tsl2x7x_ALS_device_attrs[] = {
 	NULL
 };
 
-static struct attribute *tsl2x7x_PRX_device_attrs[] = {
+static struct attribute *tsl2772_PRX_device_attrs[] = {
 	&dev_attr_in_proximity0_calibrate.attr,
 	NULL
 };
 
-static struct attribute *tsl2x7x_ALSPRX_device_attrs[] = {
+static struct attribute *tsl2772_ALSPRX_device_attrs[] = {
 	&iio_const_attr_in_intensity0_calibscale_available.dev_attr.attr,
 	&dev_attr_in_intensity0_integration_time_available.attr,
 	&dev_attr_in_illuminance0_target_input.attr,
@@ -1323,13 +1324,13 @@ static struct attribute *tsl2x7x_ALSPRX_device_attrs[] = {
 	NULL
 };
 
-static struct attribute *tsl2x7x_PRX2_device_attrs[] = {
+static struct attribute *tsl2772_PRX2_device_attrs[] = {
 	&dev_attr_in_proximity0_calibrate.attr,
 	&iio_const_attr_in_proximity0_calibscale_available.dev_attr.attr,
 	NULL
 };
 
-static struct attribute *tsl2x7x_ALSPRX2_device_attrs[] = {
+static struct attribute *tsl2772_ALSPRX2_device_attrs[] = {
 	&iio_const_attr_in_intensity0_calibscale_available.dev_attr.attr,
 	&dev_attr_in_intensity0_integration_time_available.attr,
 	&dev_attr_in_illuminance0_target_input.attr,
@@ -1340,73 +1341,73 @@ static struct attribute *tsl2x7x_ALSPRX2_device_attrs[] = {
 	NULL
 };
 
-static const struct attribute_group tsl2X7X_device_attr_group_tbl[] = {
+static const struct attribute_group tsl2772_device_attr_group_tbl[] = {
 	[ALS] = {
-		.attrs = tsl2x7x_ALS_device_attrs,
+		.attrs = tsl2772_ALS_device_attrs,
 	},
 	[PRX] = {
-		.attrs = tsl2x7x_PRX_device_attrs,
+		.attrs = tsl2772_PRX_device_attrs,
 	},
 	[ALSPRX] = {
-		.attrs = tsl2x7x_ALSPRX_device_attrs,
+		.attrs = tsl2772_ALSPRX_device_attrs,
 	},
 	[PRX2] = {
-		.attrs = tsl2x7x_PRX2_device_attrs,
+		.attrs = tsl2772_PRX2_device_attrs,
 	},
 	[ALSPRX2] = {
-		.attrs = tsl2x7x_ALSPRX2_device_attrs,
+		.attrs = tsl2772_ALSPRX2_device_attrs,
 	},
 };
 
-static const struct iio_info tsl2X7X_device_info[] = {
+static const struct iio_info tsl2772_device_info[] = {
 	[ALS] = {
-		.attrs = &tsl2X7X_device_attr_group_tbl[ALS],
-		.read_raw = &tsl2x7x_read_raw,
-		.write_raw = &tsl2x7x_write_raw,
-		.read_event_value = &tsl2x7x_read_event_value,
-		.write_event_value = &tsl2x7x_write_event_value,
-		.read_event_config = &tsl2x7x_read_interrupt_config,
-		.write_event_config = &tsl2x7x_write_interrupt_config,
+		.attrs = &tsl2772_device_attr_group_tbl[ALS],
+		.read_raw = &tsl2772_read_raw,
+		.write_raw = &tsl2772_write_raw,
+		.read_event_value = &tsl2772_read_event_value,
+		.write_event_value = &tsl2772_write_event_value,
+		.read_event_config = &tsl2772_read_interrupt_config,
+		.write_event_config = &tsl2772_write_interrupt_config,
 	},
 	[PRX] = {
-		.attrs = &tsl2X7X_device_attr_group_tbl[PRX],
-		.read_raw = &tsl2x7x_read_raw,
-		.write_raw = &tsl2x7x_write_raw,
-		.read_event_value = &tsl2x7x_read_event_value,
-		.write_event_value = &tsl2x7x_write_event_value,
-		.read_event_config = &tsl2x7x_read_interrupt_config,
-		.write_event_config = &tsl2x7x_write_interrupt_config,
+		.attrs = &tsl2772_device_attr_group_tbl[PRX],
+		.read_raw = &tsl2772_read_raw,
+		.write_raw = &tsl2772_write_raw,
+		.read_event_value = &tsl2772_read_event_value,
+		.write_event_value = &tsl2772_write_event_value,
+		.read_event_config = &tsl2772_read_interrupt_config,
+		.write_event_config = &tsl2772_write_interrupt_config,
 	},
 	[ALSPRX] = {
-		.attrs = &tsl2X7X_device_attr_group_tbl[ALSPRX],
-		.read_raw = &tsl2x7x_read_raw,
-		.write_raw = &tsl2x7x_write_raw,
-		.read_event_value = &tsl2x7x_read_event_value,
-		.write_event_value = &tsl2x7x_write_event_value,
-		.read_event_config = &tsl2x7x_read_interrupt_config,
-		.write_event_config = &tsl2x7x_write_interrupt_config,
+		.attrs = &tsl2772_device_attr_group_tbl[ALSPRX],
+		.read_raw = &tsl2772_read_raw,
+		.write_raw = &tsl2772_write_raw,
+		.read_event_value = &tsl2772_read_event_value,
+		.write_event_value = &tsl2772_write_event_value,
+		.read_event_config = &tsl2772_read_interrupt_config,
+		.write_event_config = &tsl2772_write_interrupt_config,
 	},
 	[PRX2] = {
-		.attrs = &tsl2X7X_device_attr_group_tbl[PRX2],
-		.read_raw = &tsl2x7x_read_raw,
-		.write_raw = &tsl2x7x_write_raw,
-		.read_event_value = &tsl2x7x_read_event_value,
-		.write_event_value = &tsl2x7x_write_event_value,
-		.read_event_config = &tsl2x7x_read_interrupt_config,
-		.write_event_config = &tsl2x7x_write_interrupt_config,
+		.attrs = &tsl2772_device_attr_group_tbl[PRX2],
+		.read_raw = &tsl2772_read_raw,
+		.write_raw = &tsl2772_write_raw,
+		.read_event_value = &tsl2772_read_event_value,
+		.write_event_value = &tsl2772_write_event_value,
+		.read_event_config = &tsl2772_read_interrupt_config,
+		.write_event_config = &tsl2772_write_interrupt_config,
 	},
 	[ALSPRX2] = {
-		.attrs = &tsl2X7X_device_attr_group_tbl[ALSPRX2],
-		.read_raw = &tsl2x7x_read_raw,
-		.write_raw = &tsl2x7x_write_raw,
-		.read_event_value = &tsl2x7x_read_event_value,
-		.write_event_value = &tsl2x7x_write_event_value,
-		.read_event_config = &tsl2x7x_read_interrupt_config,
-		.write_event_config = &tsl2x7x_write_interrupt_config,
+		.attrs = &tsl2772_device_attr_group_tbl[ALSPRX2],
+		.read_raw = &tsl2772_read_raw,
+		.write_raw = &tsl2772_write_raw,
+		.read_event_value = &tsl2772_read_event_value,
+		.write_event_value = &tsl2772_write_event_value,
+		.read_event_config = &tsl2772_read_interrupt_config,
+		.write_event_config = &tsl2772_write_interrupt_config,
 	},
 };
 
-static const struct iio_event_spec tsl2x7x_events[] = {
+static const struct iio_event_spec tsl2772_events[] = {
 	{
 		.type = IIO_EV_TYPE_THRESH,
 		.dir = IIO_EV_DIR_RISING,
@@ -1423,7 +1424,7 @@ static const struct iio_event_spec tsl2x7x_events[] = {
 	},
 };
 
-static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
+static const struct tsl2772_chip_info tsl2772_chip_info_tbl[] = {
 	[ALS] = {
 		.channel_with_events = {
 			{
@@ -1439,8 +1440,8 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
 				BIT(IIO_CHAN_INFO_INT_TIME) |
 				BIT(IIO_CHAN_INFO_CALIBSCALE) |
 				BIT(IIO_CHAN_INFO_CALIBBIAS),
-			.event_spec = tsl2x7x_events,
-			.num_event_specs = ARRAY_SIZE(tsl2x7x_events),
+			.event_spec = tsl2772_events,
+			.num_event_specs = ARRAY_SIZE(tsl2772_events),
 			}, {
 			.type = IIO_INTENSITY,
 			.indexed = 1,
@@ -1468,7 +1469,7 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
 			},
 		},
 		.chan_table_elements = 3,
-		.info = &tsl2X7X_device_info[ALS],
+		.info = &tsl2772_device_info[ALS],
 	},
 	[PRX] = {
 		.channel_with_events = {
@@ -1477,8 +1478,8 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
 			.indexed = 1,
 			.channel = 0,
 			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
-			.event_spec = tsl2x7x_events,
-			.num_event_specs = ARRAY_SIZE(tsl2x7x_events),
+			.event_spec = tsl2772_events,
+			.num_event_specs = ARRAY_SIZE(tsl2772_events),
 			},
 		},
 		.channel_without_events = {
@@ -1490,7 +1491,7 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
 			},
 		},
 		.chan_table_elements = 1,
-		.info = &tsl2X7X_device_info[PRX],
+		.info = &tsl2772_device_info[PRX],
 	},
 	[ALSPRX] = {
 		.channel_with_events = {
@@ -1507,8 +1508,8 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
 				BIT(IIO_CHAN_INFO_INT_TIME) |
 				BIT(IIO_CHAN_INFO_CALIBSCALE) |
 				BIT(IIO_CHAN_INFO_CALIBBIAS),
-			.event_spec = tsl2x7x_events,
-			.num_event_specs = ARRAY_SIZE(tsl2x7x_events),
+			.event_spec = tsl2772_events,
+			.num_event_specs = ARRAY_SIZE(tsl2772_events),
 			}, {
 			.type = IIO_INTENSITY,
 			.indexed = 1,
@@ -1519,8 +1520,8 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
 			.indexed = 1,
 			.channel = 0,
 			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
-			.event_spec = tsl2x7x_events,
-			.num_event_specs = ARRAY_SIZE(tsl2x7x_events),
+			.event_spec = tsl2772_events,
+			.num_event_specs = ARRAY_SIZE(tsl2772_events),
 			},
 		},
 		.channel_without_events = {
@@ -1550,7 +1551,7 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
 			},
 		},
 		.chan_table_elements = 4,
-		.info = &tsl2X7X_device_info[ALSPRX],
+		.info = &tsl2772_device_info[ALSPRX],
 	},
 	[PRX2] = {
 		.channel_with_events = {
@@ -1560,8 +1561,8 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
 			.channel = 0,
 			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
 				BIT(IIO_CHAN_INFO_CALIBSCALE),
-			.event_spec = tsl2x7x_events,
-			.num_event_specs = ARRAY_SIZE(tsl2x7x_events),
+			.event_spec = tsl2772_events,
+			.num_event_specs = ARRAY_SIZE(tsl2772_events),
 			},
 		},
 		.channel_without_events = {
@@ -1574,7 +1575,7 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
 			},
 		},
 		.chan_table_elements = 1,
-		.info = &tsl2X7X_device_info[PRX2],
+		.info = &tsl2772_device_info[PRX2],
 	},
 	[ALSPRX2] = {
 		.channel_with_events = {
@@ -1591,8 +1592,8 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
 				BIT(IIO_CHAN_INFO_INT_TIME) |
 				BIT(IIO_CHAN_INFO_CALIBSCALE) |
 				BIT(IIO_CHAN_INFO_CALIBBIAS),
-			.event_spec = tsl2x7x_events,
-			.num_event_specs = ARRAY_SIZE(tsl2x7x_events),
+			.event_spec = tsl2772_events,
+			.num_event_specs = ARRAY_SIZE(tsl2772_events),
 			}, {
 			.type = IIO_INTENSITY,
 			.indexed = 1,
@@ -1604,8 +1605,8 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
 			.channel = 0,
 			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
 				BIT(IIO_CHAN_INFO_CALIBSCALE),
-			.event_spec = tsl2x7x_events,
-			.num_event_specs = ARRAY_SIZE(tsl2x7x_events),
+			.event_spec = tsl2772_events,
+			.num_event_specs = ARRAY_SIZE(tsl2772_events),
 			},
 		},
 		.channel_without_events = {
@@ -1636,15 +1637,15 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
 			},
 		},
 		.chan_table_elements = 4,
-		.info = &tsl2X7X_device_info[ALSPRX2],
+		.info = &tsl2772_device_info[ALSPRX2],
 	},
 };
 
-static int tsl2x7x_probe(struct i2c_client *clientp,
+static int tsl2772_probe(struct i2c_client *clientp,
 			 const struct i2c_device_id *id)
 {
 	struct iio_dev *indio_dev;
-	struct tsl2X7X_chip *chip;
+	struct tsl2772_chip *chip;
 	int ret;
 
 	indio_dev = devm_iio_device_alloc(&clientp->dev, sizeof(*chip));
@@ -1656,18 +1657,18 @@ static int tsl2x7x_probe(struct i2c_client *clientp,
 	i2c_set_clientdata(clientp, indio_dev);
 
 	ret = i2c_smbus_read_byte_data(chip->client,
-				       TSL2X7X_CMD_REG | TSL2X7X_CHIPID);
+				       TSL2772_CMD_REG | TSL2772_CHIPID);
 	if (ret < 0)
 		return ret;
 
-	if (tsl2x7x_device_id_verif(ret, id->driver_data) <= 0) {
+	if (tsl2772_device_id_verif(ret, id->driver_data) <= 0) {
 		dev_info(&chip->client->dev,
 			 "%s: i2c device found does not match expected id\n",
 				__func__);
 		return -EINVAL;
 	}
 
-	ret = i2c_smbus_write_byte(clientp, TSL2X7X_CMD_REG | TSL2X7X_CNTRL);
+	ret = i2c_smbus_write_byte(clientp, TSL2772_CMD_REG | TSL2772_CNTRL);
 	if (ret < 0) {
 		dev_err(&clientp->dev,
 			"%s: Failed to write to CMD register: %d\n",
@@ -1678,11 +1679,11 @@ static int tsl2x7x_probe(struct i2c_client *clientp,
 	mutex_init(&chip->als_mutex);
 	mutex_init(&chip->prox_mutex);
 
-	chip->tsl2x7x_chip_status = TSL2X7X_CHIP_UNKNOWN;
+	chip->tsl2772_chip_status = TSL2772_CHIP_UNKNOWN;
 	chip->pdata = dev_get_platdata(&clientp->dev);
 	chip->id = id->driver_data;
 	chip->chip_info =
-		&tsl2x7x_chip_info_tbl[device_channel_config[id->driver_data]];
+		&tsl2772_chip_info_tbl[device_channel_config[id->driver_data]];
 
 	indio_dev->info = chip->chip_info->info;
 	indio_dev->dev.parent = &clientp->dev;
@@ -1695,10 +1696,10 @@ static int tsl2x7x_probe(struct i2c_client *clientp,
 
 		ret = devm_request_threaded_irq(&clientp->dev, clientp->irq,
 						NULL,
-						&tsl2x7x_event_handler,
+						&tsl2772_event_handler,
 						IRQF_TRIGGER_FALLING |
 						IRQF_ONESHOT,
-						"TSL2X7X_event",
+						"TSL2772_event",
 						indio_dev);
 		if (ret) {
 			dev_err(&clientp->dev,
@@ -1709,8 +1710,8 @@ static int tsl2x7x_probe(struct i2c_client *clientp,
 		indio_dev->channels = chip->chip_info->channel_without_events;
 	}
 
-	tsl2x7x_defaults(chip);
-	tsl2x7x_chip_on(indio_dev);
+	tsl2772_defaults(chip);
+	tsl2772_chip_on(indio_dev);
 
 	ret = iio_device_register(indio_dev);
 	if (ret) {
@@ -1722,32 +1723,32 @@ static int tsl2x7x_probe(struct i2c_client *clientp,
 	return 0;
 }
 
-static int tsl2x7x_suspend(struct device *dev)
+static int tsl2772_suspend(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 
-	return tsl2x7x_chip_off(indio_dev);
+	return tsl2772_chip_off(indio_dev);
 }
 
-static int tsl2x7x_resume(struct device *dev)
+static int tsl2772_resume(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 
-	return tsl2x7x_chip_on(indio_dev);
+	return tsl2772_chip_on(indio_dev);
 }
 
-static int tsl2x7x_remove(struct i2c_client *client)
+static int tsl2772_remove(struct i2c_client *client)
 {
 	struct iio_dev *indio_dev = i2c_get_clientdata(client);
 
-	tsl2x7x_chip_off(indio_dev);
+	tsl2772_chip_off(indio_dev);
 
 	iio_device_unregister(indio_dev);
 
 	return 0;
 }
 
-static const struct i2c_device_id tsl2x7x_idtable[] = {
+static const struct i2c_device_id tsl2772_idtable[] = {
 	{ "tsl2571", tsl2571 },
 	{ "tsl2671", tsl2671 },
 	{ "tmd2671", tmd2671 },
@@ -1761,9 +1762,9 @@ static const struct i2c_device_id tsl2x7x_idtable[] = {
 	{}
 };
 
-MODULE_DEVICE_TABLE(i2c, tsl2x7x_idtable);
+MODULE_DEVICE_TABLE(i2c, tsl2772_idtable);
 
-static const struct of_device_id tsl2x7x_of_match[] = {
+static const struct of_device_id tsl2772_of_match[] = {
 	{ .compatible = "amstaos,tsl2571" },
 	{ .compatible = "amstaos,tsl2671" },
 	{ .compatible = "amstaos,tmd2671" },
@@ -1776,27 +1777,27 @@ static const struct of_device_id tsl2x7x_of_match[] = {
 	{ .compatible = "amstaos,tmd2772" },
 	{}
 };
-MODULE_DEVICE_TABLE(of, tsl2x7x_of_match);
+MODULE_DEVICE_TABLE(of, tsl2772_of_match);
 
-static const struct dev_pm_ops tsl2x7x_pm_ops = {
-	.suspend = tsl2x7x_suspend,
-	.resume  = tsl2x7x_resume,
+static const struct dev_pm_ops tsl2772_pm_ops = {
+	.suspend = tsl2772_suspend,
+	.resume  = tsl2772_resume,
 };
 
-static struct i2c_driver tsl2x7x_driver = {
+static struct i2c_driver tsl2772_driver = {
 	.driver = {
-		.name = "tsl2x7x",
-		.of_match_table = tsl2x7x_of_match,
-		.pm = &tsl2x7x_pm_ops,
+		.name = "tsl2772",
+		.of_match_table = tsl2772_of_match,
+		.pm = &tsl2772_pm_ops,
 	},
-	.id_table = tsl2x7x_idtable,
-	.probe = tsl2x7x_probe,
-	.remove = tsl2x7x_remove,
+	.id_table = tsl2772_idtable,
+	.probe = tsl2772_probe,
+	.remove = tsl2772_remove,
 };
 
-module_i2c_driver(tsl2x7x_driver);
+module_i2c_driver(tsl2772_driver);
 
 MODULE_AUTHOR("J. August Brenner <Jon.Brenner@ams.com>");
 MODULE_AUTHOR("Brian Masney <masneyb@onstation.org>");
-MODULE_DESCRIPTION("TAOS tsl2x7x ambient and proximity light sensor driver");
+MODULE_DESCRIPTION("TAOS tsl2772 ambient and proximity light sensor driver");
 MODULE_LICENSE("GPL");
diff --git a/drivers/staging/iio/light/tsl2x7x.h b/drivers/staging/iio/light/tsl2772.h
similarity index 71%
rename from drivers/staging/iio/light/tsl2x7x.h
rename to drivers/staging/iio/light/tsl2772.h
index f74427f4ab6e..cc14422f85a6 100644
--- a/drivers/staging/iio/light/tsl2x7x.h
+++ b/drivers/staging/iio/light/tsl2772.h
@@ -1,50 +1,50 @@
 /* SPDX-License-Identifier: GPL-2.0+ */
 /*
  * Device driver for monitoring ambient light intensity (lux)
- * and proximity (prox) within the TAOS TSL2X7X family of devices.
+ * and proximity (prox) within the TAOS TSL2772 family of devices.
  *
  * Copyright (c) 2012, TAOS Corporation.
  */
 
-#ifndef __TSL2X7X_H
-#define __TSL2X7X_H
+#ifndef __TSL2772_H
+#define __TSL2772_H
 
-struct tsl2x7x_lux {
+struct tsl2772_lux {
 	unsigned int ch0;
 	unsigned int ch1;
 };
 
 /* Max number of segments allowable in LUX table */
-#define TSL2X7X_MAX_LUX_TABLE_SIZE		6
+#define TSL2772_MAX_LUX_TABLE_SIZE		6
 /* The default LUX tables all have 3 elements.  */
-#define TSL2X7X_DEF_LUX_TABLE_SZ		3
-#define TSL2X7X_DEFAULT_TABLE_BYTES (sizeof(struct tsl2x7x_lux) * \
-				     TSL2X7X_DEF_LUX_TABLE_SZ)
+#define TSL2772_DEF_LUX_TABLE_SZ		3
+#define TSL2772_DEFAULT_TABLE_BYTES (sizeof(struct tsl2772_lux) * \
+				     TSL2772_DEF_LUX_TABLE_SZ)
 
 /* Proximity diode to use */
-#define TSL2X7X_DIODE0                  0x01
-#define TSL2X7X_DIODE1                  0x02
-#define TSL2X7X_DIODE_BOTH              0x03
+#define TSL2772_DIODE0                  0x01
+#define TSL2772_DIODE1                  0x02
+#define TSL2772_DIODE_BOTH              0x03
 
 /* LED Power */
-#define TSL2X7X_100_mA                  0x00
-#define TSL2X7X_50_mA                   0x01
-#define TSL2X7X_25_mA                   0x02
-#define TSL2X7X_13_mA                   0x03
+#define TSL2772_100_mA                  0x00
+#define TSL2772_50_mA                   0x01
+#define TSL2772_25_mA                   0x02
+#define TSL2772_13_mA                   0x03
 
 /**
- * struct tsl2x7x_settings - Settings for the tsl2x7x driver
+ * struct tsl2772_settings - Settings for the tsl2772 driver
  *  @als_time:              Integration time of the ALS channel ADCs in 2.73 ms
  *                          increments. Total integration time is
  *                          (256 - als_time) * 2.73.
- *  @als_gain:              Index into the tsl2x7x_als_gain array.
+ *  @als_gain:              Index into the tsl2772_als_gain array.
  *  @als_gain_trim:         Default gain trim to account for aperture effects.
  *  @wait_time:             Time between proximity and ALS cycles in 2.73
  *                          periods.
  *  @prox_time:             Integration time of the proximity ADC in 2.73 ms
  *                          increments. Total integration time is
  *                          (256 - prx_time) * 2.73.
- *  @prox_gain:             Index into the tsl2x7x_prx_gain array.
+ *  @prox_gain:             Index into the tsl2772_prx_gain array.
  *  @als_prox_config:       The value of the ALS / Proximity configuration
  *                          register.
  *  @als_cal_target:        Known external ALS reading for calibration.
@@ -64,7 +64,7 @@ struct tsl2x7x_lux {
  *                          LED(s) for proximity sensing.
  *  @prox_power             The amount of power to use for the external LED(s).
  */
-struct tsl2x7x_settings {
+struct tsl2772_settings {
 	int als_time;
 	int als_gain;
 	int als_gain_trim;
@@ -88,14 +88,14 @@ struct tsl2x7x_settings {
 };
 
 /**
- * struct tsl2X7X_platform_data - Platform callback, glass and defaults
+ * struct tsl2772_platform_data - Platform callback, glass and defaults
  * @platform_lux_table:        Device specific glass coefficents
  * @platform_default_settings: Device specific power on defaults
  *
  */
-struct tsl2X7X_platform_data {
-	struct tsl2x7x_lux platform_lux_table[TSL2X7X_MAX_LUX_TABLE_SIZE];
-	struct tsl2x7x_settings *platform_default_settings;
+struct tsl2772_platform_data {
+	struct tsl2772_lux platform_lux_table[TSL2772_MAX_LUX_TABLE_SIZE];
+	struct tsl2772_settings *platform_default_settings;
 };
 
-#endif /* __TSL2X7X_H */
+#endif /* __TSL2772_H */
-- 
2.14.3

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

* [PATCH v2 11/11] staging: iio: tsl2x7x/tsl2772: move out of staging
  2018-05-04  2:53 [PATCH v2 00/11] staging: iio: tsl2x7x: move out of staging Brian Masney
                   ` (9 preceding siblings ...)
  2018-05-04  2:53 ` [PATCH v2 10/11] staging: iio: tsl2x7x: rename driver to tsl2772 Brian Masney
@ 2018-05-04  2:53 ` Brian Masney
  2018-05-04  2:56   ` Brian Masney
  10 siblings, 1 reply; 24+ messages in thread
From: Brian Masney @ 2018-05-04  2:53 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, lars, gregkh, linux-kernel, pmeerw, knaack.h, drew.paterson

Move the tsl2772 driver out of staging and into mainline.

Signed-off-by: Brian Masney <masneyb@onstation.org>
---
 drivers/iio/light/Kconfig                                  |  8 ++++++++
 drivers/iio/light/Makefile                                 |  1 +
 drivers/{staging => }/iio/light/tsl2772.c                  |  2 +-
 drivers/staging/iio/Kconfig                                |  1 -
 drivers/staging/iio/Makefile                               |  1 -
 drivers/staging/iio/light/Kconfig                          | 14 --------------
 drivers/staging/iio/light/Makefile                         |  5 -----
 .../iio/light => include/linux/platform_data}/tsl2772.h    |  0
 8 files changed, 10 insertions(+), 22 deletions(-)
 rename drivers/{staging => }/iio/light/tsl2772.c (99%)
 delete mode 100644 drivers/staging/iio/light/Kconfig
 delete mode 100644 drivers/staging/iio/light/Makefile
 rename {drivers/staging/iio/light => include/linux/platform_data}/tsl2772.h (100%)

diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig
index 074e50657366..c7ef8d1862d6 100644
--- a/drivers/iio/light/Kconfig
+++ b/drivers/iio/light/Kconfig
@@ -409,6 +409,14 @@ config TSL2583
 	 Provides support for the TAOS tsl2580, tsl2581 and tsl2583 devices.
 	 Access ALS data via iio, sysfs.
 
+config TSL2772
+	tristate "TAOS TSL/TMD2x71 and TSL/TMD2x72 Family of light and proximity sensors"
+	depends on I2C
+	help
+	 Support for: tsl2571, tsl2671, tmd2671, tsl2771, tmd2771, tsl2572, tsl2672,
+	 tmd2672, tsl2772, tmd2772 devices.
+	 Provides iio_events and direct access via sysfs.
+
 config TSL4531
 	tristate "TAOS TSL4531 ambient light sensors"
 	depends on I2C
diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile
index f1777036d4f8..80943af5d627 100644
--- a/drivers/iio/light/Makefile
+++ b/drivers/iio/light/Makefile
@@ -40,6 +40,7 @@ obj-$(CONFIG_ST_UVIS25_SPI)	+= st_uvis25_spi.o
 obj-$(CONFIG_TCS3414)		+= tcs3414.o
 obj-$(CONFIG_TCS3472)		+= tcs3472.o
 obj-$(CONFIG_TSL2583)		+= tsl2583.o
+obj-$(CONFIG_TSL2772)		+= tsl2772.o
 obj-$(CONFIG_TSL4531)		+= tsl4531.o
 obj-$(CONFIG_US5182D)		+= us5182d.o
 obj-$(CONFIG_VCNL4000)		+= vcnl4000.o
diff --git a/drivers/staging/iio/light/tsl2772.c b/drivers/iio/light/tsl2772.c
similarity index 99%
rename from drivers/staging/iio/light/tsl2772.c
rename to drivers/iio/light/tsl2772.c
index 146527e41969..7ed72c98ce1a 100644
--- a/drivers/staging/iio/light/tsl2772.c
+++ b/drivers/iio/light/tsl2772.c
@@ -19,7 +19,7 @@
 #include <linux/iio/events.h>
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
-#include "tsl2772.h"
+#include <linux/platform_data/tsl2772.h>
 
 /* Cal defs */
 #define PROX_STAT_CAL			0
diff --git a/drivers/staging/iio/Kconfig b/drivers/staging/iio/Kconfig
index 8abc1ab3c0c7..ca001510782d 100644
--- a/drivers/staging/iio/Kconfig
+++ b/drivers/staging/iio/Kconfig
@@ -11,7 +11,6 @@ source "drivers/staging/iio/cdc/Kconfig"
 source "drivers/staging/iio/frequency/Kconfig"
 source "drivers/staging/iio/gyro/Kconfig"
 source "drivers/staging/iio/impedance-analyzer/Kconfig"
-source "drivers/staging/iio/light/Kconfig"
 source "drivers/staging/iio/meter/Kconfig"
 source "drivers/staging/iio/resolver/Kconfig"
 source "drivers/staging/iio/trigger/Kconfig"
diff --git a/drivers/staging/iio/Makefile b/drivers/staging/iio/Makefile
index 455bffc29649..5c168403b873 100644
--- a/drivers/staging/iio/Makefile
+++ b/drivers/staging/iio/Makefile
@@ -10,7 +10,6 @@ obj-y += cdc/
 obj-y += frequency/
 obj-y += gyro/
 obj-y += impedance-analyzer/
-obj-y += light/
 obj-y += meter/
 obj-y += resolver/
 obj-y += trigger/
diff --git a/drivers/staging/iio/light/Kconfig b/drivers/staging/iio/light/Kconfig
deleted file mode 100644
index dfa37386ad2c..000000000000
--- a/drivers/staging/iio/light/Kconfig
+++ /dev/null
@@ -1,14 +0,0 @@
-#
-# Light sensors
-#
-menu "Light sensors"
-
-config TSL2772
-	tristate "TAOS TSL/TMD2x71 and TSL/TMD2x72 Family of light and proximity sensors"
-	depends on I2C
-	help
-	 Support for: tsl2571, tsl2671, tmd2671, tsl2771, tmd2771, tsl2572, tsl2672,
-	 tmd2672, tsl2772, tmd2772 devices.
-	 Provides iio_events and direct access via sysfs.
-
-endmenu
diff --git a/drivers/staging/iio/light/Makefile b/drivers/staging/iio/light/Makefile
deleted file mode 100644
index e7e77a11f02a..000000000000
--- a/drivers/staging/iio/light/Makefile
+++ /dev/null
@@ -1,5 +0,0 @@
-#
-# Makefile for industrial I/O Light sensors
-#
-
-obj-$(CONFIG_TSL2772)	+= tsl2772.o
diff --git a/drivers/staging/iio/light/tsl2772.h b/include/linux/platform_data/tsl2772.h
similarity index 100%
rename from drivers/staging/iio/light/tsl2772.h
rename to include/linux/platform_data/tsl2772.h
-- 
2.14.3

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

* Re: [PATCH v2 11/11] staging: iio: tsl2x7x/tsl2772: move out of staging
  2018-05-04  2:53 ` [PATCH v2 11/11] staging: iio: tsl2x7x/tsl2772: move out of staging Brian Masney
@ 2018-05-04  2:56   ` Brian Masney
  2018-05-06 19:00     ` Jonathan Cameron
  0 siblings, 1 reply; 24+ messages in thread
From: Brian Masney @ 2018-05-04  2:56 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: devel, lars, gregkh, linux-kernel, pmeerw, knaack.h, drew.paterson

Hey Jonathan,

I intentionally didn't run git format-patch with the --no-renames since
patch 10 renamed the driver. Here is the .[ch] files included inline to
make your review easier.

Brian


tsl2772.c:

// SPDX-License-Identifier: GPL-2.0+
/*
 * Device driver for monitoring ambient light intensity in (lux) and proximity
 * detection (prox) for the TAOS TSL2571, TSL2671, TMD2671, TSL2771, TMD2771,
 * TSL2572, TSL2672, TMD2672, TSL2772, and TMD2772 devices.
 *
 * Copyright (c) 2012, TAOS Corporation.
 * Copyright (c) 2017-2018 Brian Masney <masneyb@onstation.org>
 */

#include <linux/delay.h>
#include <linux/errno.h>
#include <linux/i2c.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/iio/events.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
#include <linux/platform_data/tsl2772.h>

/* Cal defs */
#define PROX_STAT_CAL			0
#define PROX_STAT_SAMP			1
#define MAX_SAMPLES_CAL			200

/* TSL2772 Device ID */
#define TRITON_ID			0x00
#define SWORDFISH_ID			0x30
#define HALIBUT_ID			0x20

/* Lux calculation constants */
#define TSL2772_LUX_CALC_OVER_FLOW	65535

/*
 * TAOS Register definitions - Note: depending on device, some of these register
 * are not used and the register address is benign.
 */

/* Register offsets */
#define TSL2772_MAX_CONFIG_REG		16

/* Device Registers and Masks */
#define TSL2772_CNTRL			0x00
#define TSL2772_ALS_TIME		0X01
#define TSL2772_PRX_TIME		0x02
#define TSL2772_WAIT_TIME		0x03
#define TSL2772_ALS_MINTHRESHLO		0X04
#define TSL2772_ALS_MINTHRESHHI		0X05
#define TSL2772_ALS_MAXTHRESHLO		0X06
#define TSL2772_ALS_MAXTHRESHHI		0X07
#define TSL2772_PRX_MINTHRESHLO		0X08
#define TSL2772_PRX_MINTHRESHHI		0X09
#define TSL2772_PRX_MAXTHRESHLO		0X0A
#define TSL2772_PRX_MAXTHRESHHI		0X0B
#define TSL2772_PERSISTENCE		0x0C
#define TSL2772_ALS_PRX_CONFIG		0x0D
#define TSL2772_PRX_COUNT		0x0E
#define TSL2772_GAIN			0x0F
#define TSL2772_NOTUSED			0x10
#define TSL2772_REVID			0x11
#define TSL2772_CHIPID			0x12
#define TSL2772_STATUS			0x13
#define TSL2772_ALS_CHAN0LO		0x14
#define TSL2772_ALS_CHAN0HI		0x15
#define TSL2772_ALS_CHAN1LO		0x16
#define TSL2772_ALS_CHAN1HI		0x17
#define TSL2772_PRX_LO			0x18
#define TSL2772_PRX_HI			0x19

/* tsl2772 cmd reg masks */
#define TSL2772_CMD_REG			0x80
#define TSL2772_CMD_SPL_FN		0x60
#define TSL2772_CMD_REPEAT_PROTO	0x00
#define TSL2772_CMD_AUTOINC_PROTO	0x20

#define TSL2772_CMD_PROX_INT_CLR	0X05
#define TSL2772_CMD_ALS_INT_CLR		0x06
#define TSL2772_CMD_PROXALS_INT_CLR	0X07

/* tsl2772 cntrl reg masks */
#define TSL2772_CNTL_ADC_ENBL		0x02
#define TSL2772_CNTL_PWR_ON		0x01

/* tsl2772 status reg masks */
#define TSL2772_STA_ADC_VALID		0x01
#define TSL2772_STA_PRX_VALID		0x02
#define TSL2772_STA_ADC_PRX_VALID	(TSL2772_STA_ADC_VALID | \
					 TSL2772_STA_PRX_VALID)
#define TSL2772_STA_ALS_INTR		0x10
#define TSL2772_STA_PRX_INTR		0x20

/* tsl2772 cntrl reg masks */
#define TSL2772_CNTL_REG_CLEAR		0x00
#define TSL2772_CNTL_PROX_INT_ENBL	0X20
#define TSL2772_CNTL_ALS_INT_ENBL	0X10
#define TSL2772_CNTL_WAIT_TMR_ENBL	0X08
#define TSL2772_CNTL_PROX_DET_ENBL	0X04
#define TSL2772_CNTL_PWRON		0x01
#define TSL2772_CNTL_ALSPON_ENBL	0x03
#define TSL2772_CNTL_INTALSPON_ENBL	0x13
#define TSL2772_CNTL_PROXPON_ENBL	0x0F
#define TSL2772_CNTL_INTPROXPON_ENBL	0x2F

/* TAOS Device family members */
enum {
	tsl2571,
	tsl2671,
	tmd2671,
	tsl2771,
	tmd2771,
	tsl2572,
	tsl2672,
	tmd2672,
	tsl2772,
	tmd2772
};

enum {
	TSL2772_CHIP_UNKNOWN = 0,
	TSL2772_CHIP_WORKING = 1,
	TSL2772_CHIP_SUSPENDED = 2
};

/* Per-device data */
struct tsl2772_als_info {
	u16 als_ch0;
	u16 als_ch1;
	u16 lux;
};

struct tsl2772_chip_info {
	int chan_table_elements;
	struct iio_chan_spec channel_with_events[4];
	struct iio_chan_spec channel_without_events[4];
	const struct iio_info *info;
};

struct tsl2772_chip {
	kernel_ulong_t id;
	struct mutex prox_mutex;
	struct mutex als_mutex;
	struct i2c_client *client;
	u16 prox_data;
	struct tsl2772_als_info als_cur_info;
	struct tsl2772_settings settings;
	struct tsl2772_platform_data *pdata;
	int als_gain_time_scale;
	int als_saturation;
	int tsl2772_chip_status;
	u8 tsl2772_config[TSL2772_MAX_CONFIG_REG];
	const struct tsl2772_chip_info	*chip_info;
	const struct iio_info *info;
	s64 event_timestamp;
	/*
	 * This structure is intentionally large to accommodate
	 * updates via sysfs.
	 * Sized to 9 = max 8 segments + 1 termination segment
	 */
	struct tsl2772_lux tsl2772_device_lux[TSL2772_MAX_LUX_TABLE_SIZE];
};

/*
 * Different devices require different coefficents, and these numbers were
 * derived from the 'Lux Equation' section of the various device datasheets.
 * All of these coefficients assume a Glass Attenuation (GA) factor of 1.
 * The coefficients are multiplied by 1000 to avoid floating point operations.
 * The two rows in each table correspond to the Lux1 and Lux2 equations from
 * the datasheets.
 */
static const struct tsl2772_lux tsl2x71_lux_table[TSL2772_DEF_LUX_TABLE_SZ] = {
	{ 53000, 106000 },
	{ 31800,  53000 },
	{ 0,          0 },
};

static const struct tsl2772_lux tmd2x71_lux_table[TSL2772_DEF_LUX_TABLE_SZ] = {
	{ 24000,  48000 },
	{ 14400,  24000 },
	{ 0,          0 },
};

static const struct tsl2772_lux tsl2x72_lux_table[TSL2772_DEF_LUX_TABLE_SZ] = {
	{ 60000, 112200 },
	{ 37800,  60000 },
	{     0,      0 },
};

static const struct tsl2772_lux tmd2x72_lux_table[TSL2772_DEF_LUX_TABLE_SZ] = {
	{ 20000,  35000 },
	{ 12600,  20000 },
	{     0,      0 },
};

static const struct tsl2772_lux *tsl2772_default_lux_table_group[] = {
	[tsl2571] =	tsl2x71_lux_table,
	[tsl2671] =	tsl2x71_lux_table,
	[tmd2671] =	tmd2x71_lux_table,
	[tsl2771] =	tsl2x71_lux_table,
	[tmd2771] =	tmd2x71_lux_table,
	[tsl2572] =	tsl2x72_lux_table,
	[tsl2672] =	tsl2x72_lux_table,
	[tmd2672] =	tmd2x72_lux_table,
	[tsl2772] =	tsl2x72_lux_table,
	[tmd2772] =	tmd2x72_lux_table,
};

static const struct tsl2772_settings tsl2772_default_settings = {
	.als_time = 255, /* 2.72 / 2.73 ms */
	.als_gain = 0,
	.prox_time = 255, /* 2.72 / 2.73 ms */
	.prox_gain = 0,
	.wait_time = 255,
	.als_prox_config = 0,
	.als_gain_trim = 1000,
	.als_cal_target = 150,
	.als_persistence = 1,
	.als_interrupt_en = false,
	.als_thresh_low = 200,
	.als_thresh_high = 256,
	.prox_persistence = 1,
	.prox_interrupt_en = false,
	.prox_thres_low  = 0,
	.prox_thres_high = 512,
	.prox_max_samples_cal = 30,
	.prox_pulse_count = 8,
	.prox_diode = TSL2772_DIODE1,
	.prox_power = TSL2772_100_mA
};

static const s16 tsl2772_als_gain[] = {
	1,
	8,
	16,
	120
};

static const s16 tsl2772_prox_gain[] = {
	1,
	2,
	4,
	8
};

struct tsl2772_int_time {
	int increment_us;
	char *display_range;
};

static const struct tsl2772_int_time tsl2772_int_time[] = {
	[tsl2571] = { 2720, "0.00272 - 0.696" },
	[tsl2671] = { 2720, "0.00272 - 0.696" },
	[tmd2671] = { 2720, "0.00272 - 0.696" },
	[tsl2771] = { 2720, "0.00272 - 0.696" },
	[tmd2771] = { 2720, "0.00272 - 0.696" },
	[tsl2572] = { 2730, "0.00273 - 0.699" },
	[tsl2672] = { 2730, "0.00273 - 0.699" },
	[tmd2672] = { 2730, "0.00273 - 0.699" },
	[tsl2772] = { 2730, "0.00273 - 0.699" },
	[tmd2772] = { 2730, "0.00273 - 0.699" },
};

/* Channel variations */
enum {
	ALS,
	PRX,
	ALSPRX,
	PRX2,
	ALSPRX2,
};

static const u8 device_channel_config[] = {
	[tsl2571] = ALS,
	[tsl2671] = PRX,
	[tmd2671] = PRX,
	[tsl2771] = ALSPRX,
	[tmd2771] = ALSPRX,
	[tsl2572] = ALS,
	[tsl2672] = PRX2,
	[tmd2672] = PRX2,
	[tsl2772] = ALSPRX2,
	[tmd2772] = ALSPRX2
};

static int tsl2772_read_status(struct tsl2772_chip *chip)
{
	int ret;

	ret = i2c_smbus_read_byte_data(chip->client,
				       TSL2772_CMD_REG | TSL2772_STATUS);
	if (ret < 0)
		dev_err(&chip->client->dev,
			"%s: failed to read STATUS register: %d\n", __func__,
			ret);

	return ret;
}

static int tsl2772_write_control_reg(struct tsl2772_chip *chip, u8 data)
{
	int ret;

	ret = i2c_smbus_write_byte_data(chip->client,
					TSL2772_CMD_REG | TSL2772_CNTRL, data);
	if (ret < 0) {
		dev_err(&chip->client->dev,
			"%s: failed to write to control register %x: %d\n",
			__func__, data, ret);
	}

	return ret;
}

static int tsl2772_read_autoinc_regs(struct tsl2772_chip *chip, int lower_reg,
				     int upper_reg)
{
	u8 buf[2];
	int ret;

	ret = i2c_smbus_write_byte(chip->client,
				   TSL2772_CMD_REG | TSL2772_CMD_AUTOINC_PROTO |
				   lower_reg);
	if (ret < 0) {
		dev_err(&chip->client->dev,
			"%s: failed to enable auto increment protocol: %d\n",
			__func__, ret);
		return ret;
	}

	ret = i2c_smbus_read_byte_data(chip->client,
				       TSL2772_CMD_REG | lower_reg);
	if (ret < 0) {
		dev_err(&chip->client->dev,
			"%s: failed to read from register %x: %d\n", __func__,
			lower_reg, ret);
		return ret;
	}
	buf[0] = ret;

	ret = i2c_smbus_read_byte_data(chip->client,
				       TSL2772_CMD_REG | upper_reg);
	if (ret < 0) {
		dev_err(&chip->client->dev,
			"%s: failed to read from register %x: %d\n", __func__,
			upper_reg, ret);
		return ret;
	}
	buf[1] = ret;

	ret = i2c_smbus_write_byte(chip->client,
				   TSL2772_CMD_REG | TSL2772_CMD_REPEAT_PROTO |
				   lower_reg);
	if (ret < 0) {
		dev_err(&chip->client->dev,
			"%s: failed to enable repeated byte protocol: %d\n",
			__func__, ret);
		return ret;
	}

	return le16_to_cpup((const __le16 *)&buf[0]);
}

/**
 * tsl2772_get_lux() - Reads and calculates current lux value.
 * @indio_dev:	pointer to IIO device
 *
 * The raw ch0 and ch1 values of the ambient light sensed in the last
 * integration cycle are read from the device. The raw values are multiplied
 * by a device-specific scale factor, and divided by the integration time and
 * device gain. The code supports multiple lux equations through the lux table
 * coefficients. A lux gain trim is applied to each lux equation, and then the
 * maximum lux within the interval 0..65535 is selected.
 */
static int tsl2772_get_lux(struct iio_dev *indio_dev)
{
	struct tsl2772_chip *chip = iio_priv(indio_dev);
	struct tsl2772_lux *p;
	int max_lux, ret;
	bool overflow;

	mutex_lock(&chip->als_mutex);

	if (chip->tsl2772_chip_status != TSL2772_CHIP_WORKING) {
		dev_err(&chip->client->dev, "%s: device is not enabled\n",
			__func__);
		ret = -EBUSY;
		goto out_unlock;
	}

	ret = tsl2772_read_status(chip);
	if (ret < 0)
		goto out_unlock;

	if (!(ret & TSL2772_STA_ADC_VALID)) {
		dev_err(&chip->client->dev,
			"%s: data not valid yet\n", __func__);
		ret = chip->als_cur_info.lux; /* return LAST VALUE */
		goto out_unlock;
	}

	ret = tsl2772_read_autoinc_regs(chip, TSL2772_ALS_CHAN0LO,
					TSL2772_ALS_CHAN0HI);
	if (ret < 0)
		goto out_unlock;
	chip->als_cur_info.als_ch0 = ret;

	ret = tsl2772_read_autoinc_regs(chip, TSL2772_ALS_CHAN1LO,
					TSL2772_ALS_CHAN1HI);
	if (ret < 0)
		goto out_unlock;
	chip->als_cur_info.als_ch1 = ret;

	if (chip->als_cur_info.als_ch0 >= chip->als_saturation) {
		max_lux = TSL2772_LUX_CALC_OVER_FLOW;
		goto update_struct_with_max_lux;
	}

	if (!chip->als_cur_info.als_ch0) {
		/* have no data, so return LAST VALUE */
		ret = chip->als_cur_info.lux;
		goto out_unlock;
	}

	max_lux = 0;
	overflow = false;
	for (p = (struct tsl2772_lux *)chip->tsl2772_device_lux; p->ch0 != 0;
	     p++) {
		int lux;

		lux = ((chip->als_cur_info.als_ch0 * p->ch0) -
		       (chip->als_cur_info.als_ch1 * p->ch1)) /
			chip->als_gain_time_scale;

		/*
		 * The als_gain_trim can have a value within the range 250..4000
		 * and is a multiplier for the lux. A trim of 1000 makes no
		 * changes to the lux, less than 1000 scales it down, and
		 * greater than 1000 scales it up.
		 */
		lux = (lux * chip->settings.als_gain_trim) / 1000;

		if (lux > TSL2772_LUX_CALC_OVER_FLOW) {
			overflow = true;
			continue;
		}

		max_lux = max(max_lux, lux);
	}

	if (overflow && max_lux == 0)
		max_lux = TSL2772_LUX_CALC_OVER_FLOW;

update_struct_with_max_lux:
	chip->als_cur_info.lux = max_lux;
	ret = max_lux;

out_unlock:
	mutex_unlock(&chip->als_mutex);

	return ret;
}

/**
 * tsl2772_get_prox() - Reads proximity data registers and updates
 *                      chip->prox_data.
 *
 * @indio_dev:	pointer to IIO device
 */
static int tsl2772_get_prox(struct iio_dev *indio_dev)
{
	struct tsl2772_chip *chip = iio_priv(indio_dev);
	int ret;

	mutex_lock(&chip->prox_mutex);

	ret = tsl2772_read_status(chip);
	if (ret < 0)
		goto prox_poll_err;

	switch (chip->id) {
	case tsl2571:
	case tsl2671:
	case tmd2671:
	case tsl2771:
	case tmd2771:
		if (!(ret & TSL2772_STA_ADC_VALID)) {
			ret = -EINVAL;
			goto prox_poll_err;
		}
		break;
	case tsl2572:
	case tsl2672:
	case tmd2672:
	case tsl2772:
	case tmd2772:
		if (!(ret & TSL2772_STA_PRX_VALID)) {
			ret = -EINVAL;
			goto prox_poll_err;
		}
		break;
	}

	ret = tsl2772_read_autoinc_regs(chip, TSL2772_PRX_LO, TSL2772_PRX_HI);
	if (ret < 0)
		goto prox_poll_err;
	chip->prox_data = ret;

prox_poll_err:
	mutex_unlock(&chip->prox_mutex);

	return ret;
}

/**
 * tsl2772_defaults() - Populates the device nominal operating parameters
 *                      with those provided by a 'platform' data struct or
 *                      with prefined defaults.
 *
 * @chip:               pointer to device structure.
 */
static void tsl2772_defaults(struct tsl2772_chip *chip)
{
	/* If Operational settings defined elsewhere.. */
	if (chip->pdata && chip->pdata->platform_default_settings)
		memcpy(&chip->settings, chip->pdata->platform_default_settings,
		       sizeof(tsl2772_default_settings));
	else
		memcpy(&chip->settings, &tsl2772_default_settings,
		       sizeof(tsl2772_default_settings));

	/* Load up the proper lux table. */
	if (chip->pdata && chip->pdata->platform_lux_table[0].ch0 != 0)
		memcpy(chip->tsl2772_device_lux,
		       chip->pdata->platform_lux_table,
		       sizeof(chip->pdata->platform_lux_table));
	else
		memcpy(chip->tsl2772_device_lux,
		       tsl2772_default_lux_table_group[chip->id],
		       TSL2772_DEFAULT_TABLE_BYTES);
}

/**
 * tsl2772_als_calibrate() -	Obtain single reading and calculate
 *                              the als_gain_trim.
 *
 * @indio_dev:	pointer to IIO device
 */
static int tsl2772_als_calibrate(struct iio_dev *indio_dev)
{
	struct tsl2772_chip *chip = iio_priv(indio_dev);
	int ret, lux_val;

	ret = i2c_smbus_read_byte_data(chip->client,
				       TSL2772_CMD_REG | TSL2772_CNTRL);
	if (ret < 0) {
		dev_err(&chip->client->dev,
			"%s: failed to read from the CNTRL register\n",
			__func__);
		return ret;
	}

	if ((ret & (TSL2772_CNTL_ADC_ENBL | TSL2772_CNTL_PWR_ON))
			!= (TSL2772_CNTL_ADC_ENBL | TSL2772_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 & TSL2772_STA_ADC_VALID) != TSL2772_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 = tsl2772_get_lux(indio_dev);
	if (lux_val < 0) {
		dev_err(&chip->client->dev,
			"%s: failed to get lux\n", __func__);
		return lux_val;
	}

	ret = (chip->settings.als_cal_target * chip->settings.als_gain_trim) /
			lux_val;
	if (ret < 250 || ret > 4000)
		return -ERANGE;

	chip->settings.als_gain_trim = ret;

	return ret;
}

static int tsl2772_chip_on(struct iio_dev *indio_dev)
{
	struct tsl2772_chip *chip = iio_priv(indio_dev);
	int ret, i, als_count, als_time_us;
	u8 *dev_reg, reg_val;

	/* Non calculated parameters */
	chip->tsl2772_config[TSL2772_ALS_TIME] = chip->settings.als_time;
	chip->tsl2772_config[TSL2772_PRX_TIME] = chip->settings.prox_time;
	chip->tsl2772_config[TSL2772_WAIT_TIME] = chip->settings.wait_time;
	chip->tsl2772_config[TSL2772_ALS_PRX_CONFIG] =
		chip->settings.als_prox_config;

	chip->tsl2772_config[TSL2772_ALS_MINTHRESHLO] =
		(chip->settings.als_thresh_low) & 0xFF;
	chip->tsl2772_config[TSL2772_ALS_MINTHRESHHI] =
		(chip->settings.als_thresh_low >> 8) & 0xFF;
	chip->tsl2772_config[TSL2772_ALS_MAXTHRESHLO] =
		(chip->settings.als_thresh_high) & 0xFF;
	chip->tsl2772_config[TSL2772_ALS_MAXTHRESHHI] =
		(chip->settings.als_thresh_high >> 8) & 0xFF;
	chip->tsl2772_config[TSL2772_PERSISTENCE] =
		(chip->settings.prox_persistence & 0xFF) << 4 |
		(chip->settings.als_persistence & 0xFF);

	chip->tsl2772_config[TSL2772_PRX_COUNT] =
			chip->settings.prox_pulse_count;
	chip->tsl2772_config[TSL2772_PRX_MINTHRESHLO] =
			(chip->settings.prox_thres_low) & 0xFF;
	chip->tsl2772_config[TSL2772_PRX_MINTHRESHHI] =
			(chip->settings.prox_thres_low >> 8) & 0xFF;
	chip->tsl2772_config[TSL2772_PRX_MAXTHRESHLO] =
			(chip->settings.prox_thres_high) & 0xFF;
	chip->tsl2772_config[TSL2772_PRX_MAXTHRESHHI] =
			(chip->settings.prox_thres_high >> 8) & 0xFF;

	/* and make sure we're not already on */
	if (chip->tsl2772_chip_status == TSL2772_CHIP_WORKING) {
		/* if forcing a register update - turn off, then on */
		dev_info(&chip->client->dev, "device is already enabled\n");
		return -EINVAL;
	}

	/* Set the gain based on tsl2772_settings struct */
	chip->tsl2772_config[TSL2772_GAIN] =
		(chip->settings.als_gain & 0xFF) |
		((chip->settings.prox_gain & 0xFF) << 2) |
		(chip->settings.prox_diode << 4) |
		(chip->settings.prox_power << 6);

	/* set chip time scaling and saturation */
	als_count = 256 - chip->settings.als_time;
	als_time_us = als_count * tsl2772_int_time[chip->id].increment_us;
	chip->als_saturation = als_count * 768; /* 75% of full scale */
	chip->als_gain_time_scale = als_time_us *
		tsl2772_als_gain[chip->settings.als_gain];

	/*
	 * TSL2772 Specific power-on / adc enable sequence
	 * Power on the device 1st.
	 */
	ret = tsl2772_write_control_reg(chip, TSL2772_CNTL_PWR_ON);
	if (ret < 0)
		return ret;

	/*
	 * Use the following shadow copy for our delay before enabling ADC.
	 * Write all the registers.
	 */
	for (i = 0, dev_reg = chip->tsl2772_config;
			i < TSL2772_MAX_CONFIG_REG; i++) {
		int reg = TSL2772_CMD_REG + i;

		ret = i2c_smbus_write_byte_data(chip->client, reg,
						*dev_reg++);
		if (ret < 0) {
			dev_err(&chip->client->dev,
				"%s: failed to write to register %x: %d\n",
				__func__, reg, ret);
			return ret;
		}
	}

	/* Power-on settling time */
	usleep_range(3000, 3500);

	reg_val = TSL2772_CNTL_PWR_ON | TSL2772_CNTL_ADC_ENBL |
		  TSL2772_CNTL_PROX_DET_ENBL;
	if (chip->settings.als_interrupt_en)
		reg_val |= TSL2772_CNTL_ALS_INT_ENBL;
	if (chip->settings.prox_interrupt_en)
		reg_val |= TSL2772_CNTL_PROX_INT_ENBL;

	ret = tsl2772_write_control_reg(chip, reg_val);
	if (ret < 0)
		return ret;

	ret = i2c_smbus_write_byte(chip->client,
				   TSL2772_CMD_REG | TSL2772_CMD_SPL_FN |
				   TSL2772_CMD_PROXALS_INT_CLR);
	if (ret < 0) {
		dev_err(&chip->client->dev,
			"%s: failed to clear interrupt status: %d\n",
			__func__, ret);
		return ret;
	}

	chip->tsl2772_chip_status = TSL2772_CHIP_WORKING;

	return ret;
}

static int tsl2772_chip_off(struct iio_dev *indio_dev)
{
	struct tsl2772_chip *chip = iio_priv(indio_dev);

	/* turn device off */
	chip->tsl2772_chip_status = TSL2772_CHIP_SUSPENDED;
	return tsl2772_write_control_reg(chip, 0x00);
}

/**
 * tsl2772_invoke_change - power cycle the device to implement the user
 *                         parameters
 * @indio_dev:	pointer to IIO device
 *
 * Obtain and lock both ALS and PROX resources, determine and save device state
 * (On/Off), cycle device to implement updated parameter, put device back into
 * proper state, and unlock resource.
 */
static int tsl2772_invoke_change(struct iio_dev *indio_dev)
{
	struct tsl2772_chip *chip = iio_priv(indio_dev);
	int device_status = chip->tsl2772_chip_status;
	int ret;

	mutex_lock(&chip->als_mutex);
	mutex_lock(&chip->prox_mutex);

	if (device_status == TSL2772_CHIP_WORKING) {
		ret = tsl2772_chip_off(indio_dev);
		if (ret < 0)
			goto unlock;
	}

	ret = tsl2772_chip_on(indio_dev);

unlock:
	mutex_unlock(&chip->prox_mutex);
	mutex_unlock(&chip->als_mutex);

	return ret;
}

static int tsl2772_prox_cal(struct iio_dev *indio_dev)
{
	struct tsl2772_chip *chip = iio_priv(indio_dev);
	int prox_history[MAX_SAMPLES_CAL + 1];
	int i, ret, mean, max, sample_sum;

	if (chip->settings.prox_max_samples_cal < 1 ||
	    chip->settings.prox_max_samples_cal > MAX_SAMPLES_CAL)
		return -EINVAL;

	for (i = 0; i < chip->settings.prox_max_samples_cal; i++) {
		usleep_range(15000, 17500);
		ret = tsl2772_get_prox(indio_dev);
		if (ret < 0)
			return ret;

		prox_history[i] = chip->prox_data;
	}

	sample_sum = 0;
	max = INT_MIN;
	for (i = 0; i < chip->settings.prox_max_samples_cal; i++) {
		sample_sum += prox_history[i];
		max = max(max, prox_history[i]);
	}
	mean = sample_sum / chip->settings.prox_max_samples_cal;

	chip->settings.prox_thres_high = (max << 1) - mean;

	return tsl2772_invoke_change(indio_dev);
}

static IIO_CONST_ATTR(in_intensity0_calibscale_available, "1 8 16 120");

static IIO_CONST_ATTR(in_proximity0_calibscale_available, "1 2 4 8");

static ssize_t
in_intensity0_integration_time_available_show(struct device *dev,
					      struct device_attribute *attr,
					      char *buf)
{
	struct tsl2772_chip *chip = iio_priv(dev_to_iio_dev(dev));

	return snprintf(buf, PAGE_SIZE, "%s\n",
			tsl2772_int_time[chip->id].display_range);
}

static ssize_t in_illuminance0_target_input_show(struct device *dev,
						 struct device_attribute *attr,
						 char *buf)
{
	struct tsl2772_chip *chip = iio_priv(dev_to_iio_dev(dev));

	return snprintf(buf, PAGE_SIZE, "%d\n", chip->settings.als_cal_target);
}

static ssize_t in_illuminance0_target_input_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 tsl2772_chip *chip = iio_priv(indio_dev);
	u16 value;
	int ret;

	if (kstrtou16(buf, 0, &value))
		return -EINVAL;

	chip->settings.als_cal_target = value;
	ret = tsl2772_invoke_change(indio_dev);
	if (ret < 0)
		return ret;

	return len;
}

static ssize_t in_illuminance0_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);
	bool value;
	int ret;

	if (kstrtobool(buf, &value) || !value)
		return -EINVAL;

	ret = tsl2772_als_calibrate(indio_dev);
	if (ret < 0)
		return ret;

	ret = tsl2772_invoke_change(indio_dev);
	if (ret < 0)
		return ret;

	return len;
}

static ssize_t in_illuminance0_lux_table_show(struct device *dev,
					      struct device_attribute *attr,
					      char *buf)
{
	struct tsl2772_chip *chip = iio_priv(dev_to_iio_dev(dev));
	int i = 0;
	int offset = 0;

	while (i < TSL2772_MAX_LUX_TABLE_SIZE) {
		offset += snprintf(buf + offset, PAGE_SIZE, "%u,%u,",
			chip->tsl2772_device_lux[i].ch0,
			chip->tsl2772_device_lux[i].ch1);
		if (chip->tsl2772_device_lux[i].ch0 == 0) {
			/*
			 * We just printed the first "0" entry.
			 * Now get rid of the extra "," and break.
			 */
			offset--;
			break;
		}
		i++;
	}

	offset += snprintf(buf + offset, PAGE_SIZE, "\n");
	return offset;
}

static ssize_t in_illuminance0_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 tsl2772_chip *chip = iio_priv(indio_dev);
	int value[ARRAY_SIZE(chip->tsl2772_device_lux) * 2 + 1];
	int n, ret;

	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 two ints to be one table entry,
	 * and the last table entry is all 0.
	 */
	n = value[0];
	if ((n % 2) || n < 4 ||
	    n > ((ARRAY_SIZE(chip->tsl2772_device_lux) - 1) * 2))
		return -EINVAL;

	if ((value[(n - 1)] | value[n]) != 0)
		return -EINVAL;

	if (chip->tsl2772_chip_status == TSL2772_CHIP_WORKING) {
		ret = tsl2772_chip_off(indio_dev);
		if (ret < 0)
			return ret;
	}

	/* Zero out the table */
	memset(chip->tsl2772_device_lux, 0, sizeof(chip->tsl2772_device_lux));
	memcpy(chip->tsl2772_device_lux, &value[1], (value[0] * 4));

	ret = tsl2772_invoke_change(indio_dev);
	if (ret < 0)
		return ret;

	return len;
}

static ssize_t in_proximity0_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);
	bool value;
	int ret;

	if (kstrtobool(buf, &value) || !value)
		return -EINVAL;

	ret = tsl2772_prox_cal(indio_dev);
	if (ret < 0)
		return ret;

	ret = tsl2772_invoke_change(indio_dev);
	if (ret < 0)
		return ret;

	return len;
}

static int tsl2772_read_interrupt_config(struct iio_dev *indio_dev,
					 const struct iio_chan_spec *chan,
					 enum iio_event_type type,
					 enum iio_event_direction dir)
{
	struct tsl2772_chip *chip = iio_priv(indio_dev);

	if (chan->type == IIO_INTENSITY)
		return chip->settings.als_interrupt_en;
	else
		return chip->settings.prox_interrupt_en;
}

static int tsl2772_write_interrupt_config(struct iio_dev *indio_dev,
					  const struct iio_chan_spec *chan,
					  enum iio_event_type type,
					  enum iio_event_direction dir,
					  int val)
{
	struct tsl2772_chip *chip = iio_priv(indio_dev);

	if (chan->type == IIO_INTENSITY)
		chip->settings.als_interrupt_en = val ? true : false;
	else
		chip->settings.prox_interrupt_en = val ? true : false;

	return tsl2772_invoke_change(indio_dev);
}

static int tsl2772_write_event_value(struct iio_dev *indio_dev,
				     const struct iio_chan_spec *chan,
				     enum iio_event_type type,
				     enum iio_event_direction dir,
				     enum iio_event_info info,
				     int val, int val2)
{
	struct tsl2772_chip *chip = iio_priv(indio_dev);
	int ret = -EINVAL, count, persistence;
	u8 time;

	switch (info) {
	case IIO_EV_INFO_VALUE:
		if (chan->type == IIO_INTENSITY) {
			switch (dir) {
			case IIO_EV_DIR_RISING:
				chip->settings.als_thresh_high = val;
				ret = 0;
				break;
			case IIO_EV_DIR_FALLING:
				chip->settings.als_thresh_low = val;
				ret = 0;
				break;
			default:
				break;
			}
		} else {
			switch (dir) {
			case IIO_EV_DIR_RISING:
				chip->settings.prox_thres_high = val;
				ret = 0;
				break;
			case IIO_EV_DIR_FALLING:
				chip->settings.prox_thres_low = val;
				ret = 0;
				break;
			default:
				break;
			}
		}
		break;
	case IIO_EV_INFO_PERIOD:
		if (chan->type == IIO_INTENSITY)
			time = chip->settings.als_time;
		else
			time = chip->settings.prox_time;

		count = 256 - time;
		persistence = ((val * 1000000) + val2) /
			(count * tsl2772_int_time[chip->id].increment_us);

		if (chan->type == IIO_INTENSITY) {
			/* ALS filter values are 1, 2, 3, 5, 10, 15, ..., 60 */
			if (persistence > 3)
				persistence = (persistence / 5) + 3;

			chip->settings.als_persistence = persistence;
		} else {
			chip->settings.prox_persistence = persistence;
		}

		ret = 0;
		break;
	default:
		break;
	}

	if (ret < 0)
		return ret;

	return tsl2772_invoke_change(indio_dev);
}

static int tsl2772_read_event_value(struct iio_dev *indio_dev,
				    const struct iio_chan_spec *chan,
				    enum iio_event_type type,
				    enum iio_event_direction dir,
				    enum iio_event_info info,
				    int *val, int *val2)
{
	struct tsl2772_chip *chip = iio_priv(indio_dev);
	int ret = -EINVAL, filter_delay, persistence;
	u8 time;

	switch (info) {
	case IIO_EV_INFO_VALUE:
		if (chan->type == IIO_INTENSITY) {
			switch (dir) {
			case IIO_EV_DIR_RISING:
				*val = chip->settings.als_thresh_high;
				ret = IIO_VAL_INT;
				break;
			case IIO_EV_DIR_FALLING:
				*val = chip->settings.als_thresh_low;
				ret = IIO_VAL_INT;
				break;
			default:
				break;
			}
		} else {
			switch (dir) {
			case IIO_EV_DIR_RISING:
				*val = chip->settings.prox_thres_high;
				ret = IIO_VAL_INT;
				break;
			case IIO_EV_DIR_FALLING:
				*val = chip->settings.prox_thres_low;
				ret = IIO_VAL_INT;
				break;
			default:
				break;
			}
		}
		break;
	case IIO_EV_INFO_PERIOD:
		if (chan->type == IIO_INTENSITY) {
			time = chip->settings.als_time;
			persistence = chip->settings.als_persistence;

			/* ALS filter values are 1, 2, 3, 5, 10, 15, ..., 60 */
			if (persistence > 3)
				persistence = (persistence - 3) * 5;
		} else {
			time = chip->settings.prox_time;
			persistence = chip->settings.prox_persistence;
		}

		filter_delay = persistence * (256 - time) *
			tsl2772_int_time[chip->id].increment_us;

		*val = filter_delay / 1000000;
		*val2 = filter_delay % 1000000;
		ret = IIO_VAL_INT_PLUS_MICRO;
		break;
	default:
		break;
	}

	return ret;
}

static int tsl2772_read_raw(struct iio_dev *indio_dev,
			    struct iio_chan_spec const *chan,
			    int *val,
			    int *val2,
			    long mask)
{
	struct tsl2772_chip *chip = iio_priv(indio_dev);
	int ret = -EINVAL;

	switch (mask) {
	case IIO_CHAN_INFO_PROCESSED:
		switch (chan->type) {
		case IIO_LIGHT:
			tsl2772_get_lux(indio_dev);
			*val = chip->als_cur_info.lux;
			ret = IIO_VAL_INT;
			break;
		default:
			return -EINVAL;
		}
		break;
	case IIO_CHAN_INFO_RAW:
		switch (chan->type) {
		case IIO_INTENSITY:
			tsl2772_get_lux(indio_dev);
			if (chan->channel == 0)
				*val = chip->als_cur_info.als_ch0;
			else
				*val = chip->als_cur_info.als_ch1;
			ret = IIO_VAL_INT;
			break;
		case IIO_PROXIMITY:
			tsl2772_get_prox(indio_dev);
			*val = chip->prox_data;
			ret = IIO_VAL_INT;
			break;
		default:
			return -EINVAL;
		}
		break;
	case IIO_CHAN_INFO_CALIBSCALE:
		if (chan->type == IIO_LIGHT)
			*val = tsl2772_als_gain[chip->settings.als_gain];
		else
			*val = tsl2772_prox_gain[chip->settings.prox_gain];
		ret = IIO_VAL_INT;
		break;
	case IIO_CHAN_INFO_CALIBBIAS:
		*val = chip->settings.als_gain_trim;
		ret = IIO_VAL_INT;
		break;
	case IIO_CHAN_INFO_INT_TIME:
		*val = 0;
		*val2 = (256 - chip->settings.als_time) *
			tsl2772_int_time[chip->id].increment_us;
		ret = IIO_VAL_INT_PLUS_MICRO;
		break;
	default:
		ret = -EINVAL;
	}

	return ret;
}

static int tsl2772_write_raw(struct iio_dev *indio_dev,
			     struct iio_chan_spec const *chan,
			     int val,
			     int val2,
			     long mask)
{
	struct tsl2772_chip *chip = iio_priv(indio_dev);

	switch (mask) {
	case IIO_CHAN_INFO_CALIBSCALE:
		if (chan->type == IIO_INTENSITY) {
			switch (val) {
			case 1:
				chip->settings.als_gain = 0;
				break;
			case 8:
				chip->settings.als_gain = 1;
				break;
			case 16:
				chip->settings.als_gain = 2;
				break;
			case 120:
				chip->settings.als_gain = 3;
				break;
			default:
				return -EINVAL;
			}
		} else {
			switch (val) {
			case 1:
				chip->settings.prox_gain = 0;
				break;
			case 2:
				chip->settings.prox_gain = 1;
				break;
			case 4:
				chip->settings.prox_gain = 2;
				break;
			case 8:
				chip->settings.prox_gain = 3;
				break;
			default:
				return -EINVAL;
			}
		}
		break;
	case IIO_CHAN_INFO_CALIBBIAS:
		chip->settings.als_gain_trim = val;
		break;
	case IIO_CHAN_INFO_INT_TIME:
		chip->settings.als_time = 256 -
			(val2 / tsl2772_int_time[chip->id].increment_us);
		break;
	default:
		return -EINVAL;
	}

	return tsl2772_invoke_change(indio_dev);
}

static DEVICE_ATTR_RO(in_intensity0_integration_time_available);

static DEVICE_ATTR_RW(in_illuminance0_target_input);

static DEVICE_ATTR_WO(in_illuminance0_calibrate);

static DEVICE_ATTR_WO(in_proximity0_calibrate);

static DEVICE_ATTR_RW(in_illuminance0_lux_table);

/* Use the default register values to identify the Taos device */
static int tsl2772_device_id_verif(int id, int target)
{
	switch (target) {
	case tsl2571:
	case tsl2671:
	case tsl2771:
		return (id & 0xf0) == TRITON_ID;
	case tmd2671:
	case tmd2771:
		return (id & 0xf0) == HALIBUT_ID;
	case tsl2572:
	case tsl2672:
	case tmd2672:
	case tsl2772:
	case tmd2772:
		return (id & 0xf0) == SWORDFISH_ID;
	}

	return -EINVAL;
}

static irqreturn_t tsl2772_event_handler(int irq, void *private)
{
	struct iio_dev *indio_dev = private;
	struct tsl2772_chip *chip = iio_priv(indio_dev);
	s64 timestamp = iio_get_time_ns(indio_dev);
	int ret;

	ret = tsl2772_read_status(chip);
	if (ret < 0)
		return IRQ_HANDLED;

	/* What type of interrupt do we need to process */
	if (ret & TSL2772_STA_PRX_INTR) {
		iio_push_event(indio_dev,
			       IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY,
						    0,
						    IIO_EV_TYPE_THRESH,
						    IIO_EV_DIR_EITHER),
						    timestamp);
	}

	if (ret & TSL2772_STA_ALS_INTR) {
		iio_push_event(indio_dev,
			       IIO_UNMOD_EVENT_CODE(IIO_LIGHT,
						    0,
						    IIO_EV_TYPE_THRESH,
						    IIO_EV_DIR_EITHER),
			       timestamp);
	}

	ret = i2c_smbus_write_byte(chip->client,
				   TSL2772_CMD_REG | TSL2772_CMD_SPL_FN |
				   TSL2772_CMD_PROXALS_INT_CLR);
	if (ret < 0)
		dev_err(&chip->client->dev,
			"%s: failed to clear interrupt status: %d\n",
			__func__, ret);

	return IRQ_HANDLED;
}

static struct attribute *tsl2772_ALS_device_attrs[] = {
	&iio_const_attr_in_intensity0_calibscale_available.dev_attr.attr,
	&dev_attr_in_intensity0_integration_time_available.attr,
	&dev_attr_in_illuminance0_target_input.attr,
	&dev_attr_in_illuminance0_calibrate.attr,
	&dev_attr_in_illuminance0_lux_table.attr,
	NULL
};

static struct attribute *tsl2772_PRX_device_attrs[] = {
	&dev_attr_in_proximity0_calibrate.attr,
	NULL
};

static struct attribute *tsl2772_ALSPRX_device_attrs[] = {
	&iio_const_attr_in_intensity0_calibscale_available.dev_attr.attr,
	&dev_attr_in_intensity0_integration_time_available.attr,
	&dev_attr_in_illuminance0_target_input.attr,
	&dev_attr_in_illuminance0_calibrate.attr,
	&dev_attr_in_illuminance0_lux_table.attr,
	NULL
};

static struct attribute *tsl2772_PRX2_device_attrs[] = {
	&dev_attr_in_proximity0_calibrate.attr,
	&iio_const_attr_in_proximity0_calibscale_available.dev_attr.attr,
	NULL
};

static struct attribute *tsl2772_ALSPRX2_device_attrs[] = {
	&iio_const_attr_in_intensity0_calibscale_available.dev_attr.attr,
	&dev_attr_in_intensity0_integration_time_available.attr,
	&dev_attr_in_illuminance0_target_input.attr,
	&dev_attr_in_illuminance0_calibrate.attr,
	&dev_attr_in_illuminance0_lux_table.attr,
	&dev_attr_in_proximity0_calibrate.attr,
	&iio_const_attr_in_proximity0_calibscale_available.dev_attr.attr,
	NULL
};

static const struct attribute_group tsl2772_device_attr_group_tbl[] = {
	[ALS] = {
		.attrs = tsl2772_ALS_device_attrs,
	},
	[PRX] = {
		.attrs = tsl2772_PRX_device_attrs,
	},
	[ALSPRX] = {
		.attrs = tsl2772_ALSPRX_device_attrs,
	},
	[PRX2] = {
		.attrs = tsl2772_PRX2_device_attrs,
	},
	[ALSPRX2] = {
		.attrs = tsl2772_ALSPRX2_device_attrs,
	},
};

static const struct iio_info tsl2772_device_info[] = {
	[ALS] = {
		.attrs = &tsl2772_device_attr_group_tbl[ALS],
		.read_raw = &tsl2772_read_raw,
		.write_raw = &tsl2772_write_raw,
		.read_event_value = &tsl2772_read_event_value,
		.write_event_value = &tsl2772_write_event_value,
		.read_event_config = &tsl2772_read_interrupt_config,
		.write_event_config = &tsl2772_write_interrupt_config,
	},
	[PRX] = {
		.attrs = &tsl2772_device_attr_group_tbl[PRX],
		.read_raw = &tsl2772_read_raw,
		.write_raw = &tsl2772_write_raw,
		.read_event_value = &tsl2772_read_event_value,
		.write_event_value = &tsl2772_write_event_value,
		.read_event_config = &tsl2772_read_interrupt_config,
		.write_event_config = &tsl2772_write_interrupt_config,
	},
	[ALSPRX] = {
		.attrs = &tsl2772_device_attr_group_tbl[ALSPRX],
		.read_raw = &tsl2772_read_raw,
		.write_raw = &tsl2772_write_raw,
		.read_event_value = &tsl2772_read_event_value,
		.write_event_value = &tsl2772_write_event_value,
		.read_event_config = &tsl2772_read_interrupt_config,
		.write_event_config = &tsl2772_write_interrupt_config,
	},
	[PRX2] = {
		.attrs = &tsl2772_device_attr_group_tbl[PRX2],
		.read_raw = &tsl2772_read_raw,
		.write_raw = &tsl2772_write_raw,
		.read_event_value = &tsl2772_read_event_value,
		.write_event_value = &tsl2772_write_event_value,
		.read_event_config = &tsl2772_read_interrupt_config,
		.write_event_config = &tsl2772_write_interrupt_config,
	},
	[ALSPRX2] = {
		.attrs = &tsl2772_device_attr_group_tbl[ALSPRX2],
		.read_raw = &tsl2772_read_raw,
		.write_raw = &tsl2772_write_raw,
		.read_event_value = &tsl2772_read_event_value,
		.write_event_value = &tsl2772_write_event_value,
		.read_event_config = &tsl2772_read_interrupt_config,
		.write_event_config = &tsl2772_write_interrupt_config,
	},
};

static const struct iio_event_spec tsl2772_events[] = {
	{
		.type = IIO_EV_TYPE_THRESH,
		.dir = IIO_EV_DIR_RISING,
		.mask_separate = BIT(IIO_EV_INFO_VALUE),
	}, {
		.type = IIO_EV_TYPE_THRESH,
		.dir = IIO_EV_DIR_FALLING,
		.mask_separate = BIT(IIO_EV_INFO_VALUE),
	}, {
		.type = IIO_EV_TYPE_THRESH,
		.dir = IIO_EV_DIR_EITHER,
		.mask_separate = BIT(IIO_EV_INFO_PERIOD) |
			BIT(IIO_EV_INFO_ENABLE),
	},
};

static const struct tsl2772_chip_info tsl2772_chip_info_tbl[] = {
	[ALS] = {
		.channel_with_events = {
			{
			.type = IIO_LIGHT,
			.indexed = 1,
			.channel = 0,
			.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
			}, {
			.type = IIO_INTENSITY,
			.indexed = 1,
			.channel = 0,
			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
				BIT(IIO_CHAN_INFO_INT_TIME) |
				BIT(IIO_CHAN_INFO_CALIBSCALE) |
				BIT(IIO_CHAN_INFO_CALIBBIAS),
			.event_spec = tsl2772_events,
			.num_event_specs = ARRAY_SIZE(tsl2772_events),
			}, {
			.type = IIO_INTENSITY,
			.indexed = 1,
			.channel = 1,
			},
		},
		.channel_without_events = {
			{
			.type = IIO_LIGHT,
			.indexed = 1,
			.channel = 0,
			.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
			}, {
			.type = IIO_INTENSITY,
			.indexed = 1,
			.channel = 0,
			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
				BIT(IIO_CHAN_INFO_INT_TIME) |
				BIT(IIO_CHAN_INFO_CALIBSCALE) |
				BIT(IIO_CHAN_INFO_CALIBBIAS),
			}, {
			.type = IIO_INTENSITY,
			.indexed = 1,
			.channel = 1,
			},
		},
		.chan_table_elements = 3,
		.info = &tsl2772_device_info[ALS],
	},
	[PRX] = {
		.channel_with_events = {
			{
			.type = IIO_PROXIMITY,
			.indexed = 1,
			.channel = 0,
			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
			.event_spec = tsl2772_events,
			.num_event_specs = ARRAY_SIZE(tsl2772_events),
			},
		},
		.channel_without_events = {
			{
			.type = IIO_PROXIMITY,
			.indexed = 1,
			.channel = 0,
			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
			},
		},
		.chan_table_elements = 1,
		.info = &tsl2772_device_info[PRX],
	},
	[ALSPRX] = {
		.channel_with_events = {
			{
			.type = IIO_LIGHT,
			.indexed = 1,
			.channel = 0,
			.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
			}, {
			.type = IIO_INTENSITY,
			.indexed = 1,
			.channel = 0,
			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
				BIT(IIO_CHAN_INFO_INT_TIME) |
				BIT(IIO_CHAN_INFO_CALIBSCALE) |
				BIT(IIO_CHAN_INFO_CALIBBIAS),
			.event_spec = tsl2772_events,
			.num_event_specs = ARRAY_SIZE(tsl2772_events),
			}, {
			.type = IIO_INTENSITY,
			.indexed = 1,
			.channel = 1,
			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
			}, {
			.type = IIO_PROXIMITY,
			.indexed = 1,
			.channel = 0,
			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
			.event_spec = tsl2772_events,
			.num_event_specs = ARRAY_SIZE(tsl2772_events),
			},
		},
		.channel_without_events = {
			{
			.type = IIO_LIGHT,
			.indexed = 1,
			.channel = 0,
			.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
			}, {
			.type = IIO_INTENSITY,
			.indexed = 1,
			.channel = 0,
			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
				BIT(IIO_CHAN_INFO_INT_TIME) |
				BIT(IIO_CHAN_INFO_CALIBSCALE) |
				BIT(IIO_CHAN_INFO_CALIBBIAS),
			}, {
			.type = IIO_INTENSITY,
			.indexed = 1,
			.channel = 1,
			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
			}, {
			.type = IIO_PROXIMITY,
			.indexed = 1,
			.channel = 0,
			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
			},
		},
		.chan_table_elements = 4,
		.info = &tsl2772_device_info[ALSPRX],
	},
	[PRX2] = {
		.channel_with_events = {
			{
			.type = IIO_PROXIMITY,
			.indexed = 1,
			.channel = 0,
			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
				BIT(IIO_CHAN_INFO_CALIBSCALE),
			.event_spec = tsl2772_events,
			.num_event_specs = ARRAY_SIZE(tsl2772_events),
			},
		},
		.channel_without_events = {
			{
			.type = IIO_PROXIMITY,
			.indexed = 1,
			.channel = 0,
			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
				BIT(IIO_CHAN_INFO_CALIBSCALE),
			},
		},
		.chan_table_elements = 1,
		.info = &tsl2772_device_info[PRX2],
	},
	[ALSPRX2] = {
		.channel_with_events = {
			{
			.type = IIO_LIGHT,
			.indexed = 1,
			.channel = 0,
			.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
			}, {
			.type = IIO_INTENSITY,
			.indexed = 1,
			.channel = 0,
			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
				BIT(IIO_CHAN_INFO_INT_TIME) |
				BIT(IIO_CHAN_INFO_CALIBSCALE) |
				BIT(IIO_CHAN_INFO_CALIBBIAS),
			.event_spec = tsl2772_events,
			.num_event_specs = ARRAY_SIZE(tsl2772_events),
			}, {
			.type = IIO_INTENSITY,
			.indexed = 1,
			.channel = 1,
			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
			}, {
			.type = IIO_PROXIMITY,
			.indexed = 1,
			.channel = 0,
			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
				BIT(IIO_CHAN_INFO_CALIBSCALE),
			.event_spec = tsl2772_events,
			.num_event_specs = ARRAY_SIZE(tsl2772_events),
			},
		},
		.channel_without_events = {
			{
			.type = IIO_LIGHT,
			.indexed = 1,
			.channel = 0,
			.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
			}, {
			.type = IIO_INTENSITY,
			.indexed = 1,
			.channel = 0,
			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
				BIT(IIO_CHAN_INFO_INT_TIME) |
				BIT(IIO_CHAN_INFO_CALIBSCALE) |
				BIT(IIO_CHAN_INFO_CALIBBIAS),
			}, {
			.type = IIO_INTENSITY,
			.indexed = 1,
			.channel = 1,
			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
			}, {
			.type = IIO_PROXIMITY,
			.indexed = 1,
			.channel = 0,
			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
				BIT(IIO_CHAN_INFO_CALIBSCALE),
			},
		},
		.chan_table_elements = 4,
		.info = &tsl2772_device_info[ALSPRX2],
	},
};

static int tsl2772_probe(struct i2c_client *clientp,
			 const struct i2c_device_id *id)
{
	struct iio_dev *indio_dev;
	struct tsl2772_chip *chip;
	int ret;

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

	ret = i2c_smbus_read_byte_data(chip->client,
				       TSL2772_CMD_REG | TSL2772_CHIPID);
	if (ret < 0)
		return ret;

	if (tsl2772_device_id_verif(ret, id->driver_data) <= 0) {
		dev_info(&chip->client->dev,
			 "%s: i2c device found does not match expected id\n",
				__func__);
		return -EINVAL;
	}

	ret = i2c_smbus_write_byte(clientp, TSL2772_CMD_REG | TSL2772_CNTRL);
	if (ret < 0) {
		dev_err(&clientp->dev,
			"%s: Failed to write to CMD register: %d\n",
			__func__, ret);
		return ret;
	}

	mutex_init(&chip->als_mutex);
	mutex_init(&chip->prox_mutex);

	chip->tsl2772_chip_status = TSL2772_CHIP_UNKNOWN;
	chip->pdata = dev_get_platdata(&clientp->dev);
	chip->id = id->driver_data;
	chip->chip_info =
		&tsl2772_chip_info_tbl[device_channel_config[id->driver_data]];

	indio_dev->info = chip->chip_info->info;
	indio_dev->dev.parent = &clientp->dev;
	indio_dev->modes = INDIO_DIRECT_MODE;
	indio_dev->name = chip->client->name;
	indio_dev->num_channels = chip->chip_info->chan_table_elements;

	if (clientp->irq) {
		indio_dev->channels = chip->chip_info->channel_with_events;

		ret = devm_request_threaded_irq(&clientp->dev, clientp->irq,
						NULL,
						&tsl2772_event_handler,
						IRQF_TRIGGER_FALLING |
						IRQF_ONESHOT,
						"TSL2772_event",
						indio_dev);
		if (ret) {
			dev_err(&clientp->dev,
				"%s: irq request failed\n", __func__);
			return ret;
		}
	} else {
		indio_dev->channels = chip->chip_info->channel_without_events;
	}

	tsl2772_defaults(chip);
	tsl2772_chip_on(indio_dev);

	ret = iio_device_register(indio_dev);
	if (ret) {
		dev_err(&clientp->dev,
			"%s: iio registration failed\n", __func__);
		return ret;
	}

	return 0;
}

static int tsl2772_suspend(struct device *dev)
{
	struct iio_dev *indio_dev = dev_get_drvdata(dev);

	return tsl2772_chip_off(indio_dev);
}

static int tsl2772_resume(struct device *dev)
{
	struct iio_dev *indio_dev = dev_get_drvdata(dev);

	return tsl2772_chip_on(indio_dev);
}

static int tsl2772_remove(struct i2c_client *client)
{
	struct iio_dev *indio_dev = i2c_get_clientdata(client);

	tsl2772_chip_off(indio_dev);

	iio_device_unregister(indio_dev);

	return 0;
}

static const struct i2c_device_id tsl2772_idtable[] = {
	{ "tsl2571", tsl2571 },
	{ "tsl2671", tsl2671 },
	{ "tmd2671", tmd2671 },
	{ "tsl2771", tsl2771 },
	{ "tmd2771", tmd2771 },
	{ "tsl2572", tsl2572 },
	{ "tsl2672", tsl2672 },
	{ "tmd2672", tmd2672 },
	{ "tsl2772", tsl2772 },
	{ "tmd2772", tmd2772 },
	{}
};

MODULE_DEVICE_TABLE(i2c, tsl2772_idtable);

static const struct of_device_id tsl2772_of_match[] = {
	{ .compatible = "amstaos,tsl2571" },
	{ .compatible = "amstaos,tsl2671" },
	{ .compatible = "amstaos,tmd2671" },
	{ .compatible = "amstaos,tsl2771" },
	{ .compatible = "amstaos,tmd2771" },
	{ .compatible = "amstaos,tsl2572" },
	{ .compatible = "amstaos,tsl2672" },
	{ .compatible = "amstaos,tmd2672" },
	{ .compatible = "amstaos,tsl2772" },
	{ .compatible = "amstaos,tmd2772" },
	{}
};
MODULE_DEVICE_TABLE(of, tsl2772_of_match);

static const struct dev_pm_ops tsl2772_pm_ops = {
	.suspend = tsl2772_suspend,
	.resume  = tsl2772_resume,
};

static struct i2c_driver tsl2772_driver = {
	.driver = {
		.name = "tsl2772",
		.of_match_table = tsl2772_of_match,
		.pm = &tsl2772_pm_ops,
	},
	.id_table = tsl2772_idtable,
	.probe = tsl2772_probe,
	.remove = tsl2772_remove,
};

module_i2c_driver(tsl2772_driver);

MODULE_AUTHOR("J. August Brenner <Jon.Brenner@ams.com>");
MODULE_AUTHOR("Brian Masney <masneyb@onstation.org>");
MODULE_DESCRIPTION("TAOS tsl2772 ambient and proximity light sensor driver");
MODULE_LICENSE("GPL");

-----------------------------------------------------------------------

tsl2772.h:

/* SPDX-License-Identifier: GPL-2.0+ */
/*
 * Device driver for monitoring ambient light intensity (lux)
 * and proximity (prox) within the TAOS TSL2772 family of devices.
 *
 * Copyright (c) 2012, TAOS Corporation.
 */

#ifndef __TSL2772_H
#define __TSL2772_H

struct tsl2772_lux {
	unsigned int ch0;
	unsigned int ch1;
};

/* Max number of segments allowable in LUX table */
#define TSL2772_MAX_LUX_TABLE_SIZE		6
/* The default LUX tables all have 3 elements.  */
#define TSL2772_DEF_LUX_TABLE_SZ		3
#define TSL2772_DEFAULT_TABLE_BYTES (sizeof(struct tsl2772_lux) * \
				     TSL2772_DEF_LUX_TABLE_SZ)

/* Proximity diode to use */
#define TSL2772_DIODE0                  0x01
#define TSL2772_DIODE1                  0x02
#define TSL2772_DIODE_BOTH              0x03

/* LED Power */
#define TSL2772_100_mA                  0x00
#define TSL2772_50_mA                   0x01
#define TSL2772_25_mA                   0x02
#define TSL2772_13_mA                   0x03

/**
 * struct tsl2772_settings - Settings for the tsl2772 driver
 *  @als_time:              Integration time of the ALS channel ADCs in 2.73 ms
 *                          increments. Total integration time is
 *                          (256 - als_time) * 2.73.
 *  @als_gain:              Index into the tsl2772_als_gain array.
 *  @als_gain_trim:         Default gain trim to account for aperture effects.
 *  @wait_time:             Time between proximity and ALS cycles in 2.73
 *                          periods.
 *  @prox_time:             Integration time of the proximity ADC in 2.73 ms
 *                          increments. Total integration time is
 *                          (256 - prx_time) * 2.73.
 *  @prox_gain:             Index into the tsl2772_prx_gain array.
 *  @als_prox_config:       The value of the ALS / Proximity configuration
 *                          register.
 *  @als_cal_target:        Known external ALS reading for calibration.
 *  @als_persistence:       H/W Filters, Number of 'out of limits' ALS readings.
 *  @als_interrupt_en:      Enable/Disable ALS interrupts
 *  @als_thresh_low:        CH0 'low' count to trigger interrupt.
 *  @als_thresh_high:       CH0 'high' count to trigger interrupt.
 *  @prox_persistence:      H/W Filters, Number of 'out of limits' proximity
 *                          readings.
 *  @prox_interrupt_en:     Enable/Disable proximity interrupts.
 *  @prox_thres_low:        Low threshold proximity detection.
 *  @prox_thres_high:       High threshold proximity detection.
 *  @prox_pulse_count:      Number if proximity emitter pulses.
 *  @prox_max_samples_cal:  The number of samples that are taken when performing
 *                          a proximity calibration.
 *  @prox_diode             Which diode(s) to use for driving the external
 *                          LED(s) for proximity sensing.
 *  @prox_power             The amount of power to use for the external LED(s).
 */
struct tsl2772_settings {
	int als_time;
	int als_gain;
	int als_gain_trim;
	int wait_time;
	int prox_time;
	int prox_gain;
	int als_prox_config;
	int als_cal_target;
	u8 als_persistence;
	bool als_interrupt_en;
	int als_thresh_low;
	int als_thresh_high;
	u8 prox_persistence;
	bool prox_interrupt_en;
	int prox_thres_low;
	int prox_thres_high;
	int prox_pulse_count;
	int prox_max_samples_cal;
	int prox_diode;
	int prox_power;
};

/**
 * struct tsl2772_platform_data - Platform callback, glass and defaults
 * @platform_lux_table:        Device specific glass coefficents
 * @platform_default_settings: Device specific power on defaults
 *
 */
struct tsl2772_platform_data {
	struct tsl2772_lux platform_lux_table[TSL2772_MAX_LUX_TABLE_SIZE];
	struct tsl2772_settings *platform_default_settings;
};

#endif /* __TSL2772_H */
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

* Re: [PATCH v2 01/11] staging: iio: tsl2x7x: use GPL-2.0+ SPDX license identifier
  2018-05-04  2:53 ` [PATCH v2 01/11] staging: iio: tsl2x7x: use GPL-2.0+ SPDX license identifier Brian Masney
@ 2018-05-06 17:59   ` Jonathan Cameron
  0 siblings, 0 replies; 24+ messages in thread
From: Jonathan Cameron @ 2018-05-06 17:59 UTC (permalink / raw)
  To: Brian Masney
  Cc: devel, lars, linux-iio, gregkh, linux-kernel, pmeerw, knaack.h,
	drew.paterson

On Thu,  3 May 2018 22:53:09 -0400
Brian Masney <masneyb@onstation.org> wrote:

> The summary text for the GPL is not needed since the SPDX identifier
> is a legally binding shorthand that can be used instead.
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>
I'm always less than totally keen on these patches not coming from the
copyright holder, but is is probably fine.  If taos is unhappy we
can always switch back again.

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

Thanks,

Jonathan

> ---
>  drivers/staging/iio/light/tsl2x7x.c | 11 +----------
>  drivers/staging/iio/light/tsl2x7x.h | 15 +--------------
>  2 files changed, 2 insertions(+), 24 deletions(-)
> 
> diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c
> index e65621948cf8..01bff4593640 100644
> --- a/drivers/staging/iio/light/tsl2x7x.c
> +++ b/drivers/staging/iio/light/tsl2x7x.c
> @@ -1,19 +1,10 @@
> +// SPDX-License-Identifier: GPL-2.0+
>  /*
>   * Device driver for monitoring ambient light intensity in (lux) and proximity
>   * detection (prox) within the TAOS TSL2X7X family of devices.
>   *
>   * Copyright (c) 2012, TAOS Corporation.
>   * Copyright (c) 2017-2018 Brian Masney <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/delay.h>
> diff --git a/drivers/staging/iio/light/tsl2x7x.h b/drivers/staging/iio/light/tsl2x7x.h
> index 91ce8f98982e..8eb7f4749ea7 100644
> --- a/drivers/staging/iio/light/tsl2x7x.h
> +++ b/drivers/staging/iio/light/tsl2x7x.h
> @@ -1,22 +1,9 @@
> +/* SPDX-License-Identifier: GPL-2.0+ */
>  /*
>   * Device driver for monitoring ambient light intensity (lux)
>   * and proximity (prox) within the TAOS TSL2X7X family of devices.
>   *
>   * Copyright (c) 2012, TAOS Corporation.
> - *
> - * This program is free software; you can redistribute it and/or modify
> - * it under the terms of the GNU General Public License as published by
> - * the Free Software Foundation; either version 2 of the License, or
> - * (at your option) any later version.
> - *
> - * This program is distributed in the hope that it will be useful, but WITHOUT
> - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
> - * more details.
> - *
> - * You should have received a copy of the GNU General Public License along
> - * with this program; if not, write to the Free Software Foundation, Inc.,
> - * 51 Franklin Street, Fifth Floor, Boston, MA	02110-1301, USA.
>   */
>  
>  #ifndef __TSL2X7X_H

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

* Re: [PATCH v2 02/11] staging: iio: tsl2x7x: add range checking to three sysfs attributes
  2018-05-04  2:53 ` [PATCH v2 02/11] staging: iio: tsl2x7x: add range checking to three sysfs attributes Brian Masney
@ 2018-05-06 18:01   ` Jonathan Cameron
  0 siblings, 0 replies; 24+ messages in thread
From: Jonathan Cameron @ 2018-05-06 18:01 UTC (permalink / raw)
  To: Brian Masney
  Cc: devel, lars, linux-iio, gregkh, linux-kernel, pmeerw, knaack.h,
	drew.paterson

On Thu,  3 May 2018 22:53:10 -0400
Brian Masney <masneyb@onstation.org> wrote:

> The sysfs attributes in_illuminance0_target_input,
> in_illuminance0_calibrate, and in_proximity0_calibrate did not have
> proper range checking in place so this patch adds the correct range
> checks.
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>
Applied to the togreg branch of iio.git and pushed out as testing.

Thanks,

Jonathan

> ---
>  drivers/staging/iio/light/tsl2x7x.c | 28 +++++++++++-----------------
>  1 file changed, 11 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c
> index 01bff4593640..b4d77f65ca12 100644
> --- a/drivers/staging/iio/light/tsl2x7x.c
> +++ b/drivers/staging/iio/light/tsl2x7x.c
> @@ -814,15 +814,13 @@ static ssize_t in_illuminance0_target_input_store(struct device *dev,
>  {
>  	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
>  	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
> -	unsigned long value;
> +	u16 value;
>  	int ret;
>  
> -	if (kstrtoul(buf, 0, &value))
> +	if (kstrtou16(buf, 0, &value))
>  		return -EINVAL;
>  
> -	if (value)
> -		chip->settings.als_cal_target = value;
> -
> +	chip->settings.als_cal_target = value;
>  	ret = tsl2x7x_invoke_change(indio_dev);
>  	if (ret < 0)
>  		return ret;
> @@ -838,14 +836,12 @@ static ssize_t in_illuminance0_calibrate_store(struct device *dev,
>  	bool value;
>  	int ret;
>  
> -	if (strtobool(buf, &value))
> +	if (kstrtobool(buf, &value) || !value)
>  		return -EINVAL;
>  
> -	if (value) {
> -		ret = tsl2x7x_als_calibrate(indio_dev);
> -		if (ret < 0)
> -			return ret;
> -	}
> +	ret = tsl2x7x_als_calibrate(indio_dev);
> +	if (ret < 0)
> +		return ret;
>  
>  	ret = tsl2x7x_invoke_change(indio_dev);
>  	if (ret < 0)
> @@ -932,14 +928,12 @@ static ssize_t in_proximity0_calibrate_store(struct device *dev,
>  	bool value;
>  	int ret;
>  
> -	if (strtobool(buf, &value))
> +	if (kstrtobool(buf, &value) || !value)
>  		return -EINVAL;
>  
> -	if (value) {
> -		ret = tsl2x7x_prox_cal(indio_dev);
> -		if (ret < 0)
> -			return ret;
> -	}
> +	ret = tsl2x7x_prox_cal(indio_dev);
> +	if (ret < 0)
> +		return ret;
>  
>  	ret = tsl2x7x_invoke_change(indio_dev);
>  	if (ret < 0)

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

* Re: [PATCH v2 03/11] staging: iio: tsl2x7x: don't setup event handlers if interrupts are not configured
  2018-05-04  2:53 ` [PATCH v2 03/11] staging: iio: tsl2x7x: don't setup event handlers if interrupts are not configured Brian Masney
@ 2018-05-06 18:05   ` Jonathan Cameron
  0 siblings, 0 replies; 24+ messages in thread
From: Jonathan Cameron @ 2018-05-06 18:05 UTC (permalink / raw)
  To: Brian Masney
  Cc: devel, lars, linux-iio, gregkh, linux-kernel, pmeerw, knaack.h,
	drew.paterson

On Thu,  3 May 2018 22:53:11 -0400
Brian Masney <masneyb@onstation.org> wrote:

> The driver would expose to userspace the events directory even if the
> interrupts were not configured. This patch changes the driver so that
> the events directory is not exposed to user space if interrupts are
> not configured. This patch also corrects the indentation of the
> chan_table_elements and info structure members.
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>
Applied

Thanks,

Jonathan

> ---
>  drivers/staging/iio/light/tsl2x7x.c | 130 +++++++++++++++++++++++++++++++-----
>  1 file changed, 112 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c
> index b4d77f65ca12..7e8db5178a2c 100644
> --- a/drivers/staging/iio/light/tsl2x7x.c
> +++ b/drivers/staging/iio/light/tsl2x7x.c
> @@ -134,8 +134,9 @@ struct tsl2x7x_als_info {
>  
>  struct tsl2x7x_chip_info {
>  	int chan_table_elements;
> -	struct iio_chan_spec		channel[4];
> -	const struct iio_info		*info;
> +	struct iio_chan_spec channel_with_events[4];
> +	struct iio_chan_spec channel_without_events[4];
> +	const struct iio_info *info;
>  };
>  
>  struct tsl2X7X_chip {
> @@ -1447,7 +1448,7 @@ static const struct iio_event_spec tsl2x7x_events[] = {
>  
>  static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
>  	[ALS] = {
> -		.channel = {
> +		.channel_with_events = {
>  			{
>  			.type = IIO_LIGHT,
>  			.indexed = 1,
> @@ -1469,11 +1470,31 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
>  			.channel = 1,
>  			},
>  		},
> -	.chan_table_elements = 3,
> -	.info = &tsl2X7X_device_info[ALS],
> +		.channel_without_events = {
> +			{
> +			.type = IIO_LIGHT,
> +			.indexed = 1,
> +			.channel = 0,
> +			.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
> +			}, {
> +			.type = IIO_INTENSITY,
> +			.indexed = 1,
> +			.channel = 0,
> +			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> +				BIT(IIO_CHAN_INFO_INT_TIME) |
> +				BIT(IIO_CHAN_INFO_CALIBSCALE) |
> +				BIT(IIO_CHAN_INFO_CALIBBIAS),
> +			}, {
> +			.type = IIO_INTENSITY,
> +			.indexed = 1,
> +			.channel = 1,
> +			},
> +		},
> +		.chan_table_elements = 3,
> +		.info = &tsl2X7X_device_info[ALS],
>  	},
>  	[PRX] = {
> -		.channel = {
> +		.channel_with_events = {
>  			{
>  			.type = IIO_PROXIMITY,
>  			.indexed = 1,
> @@ -1483,11 +1504,19 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
>  			.num_event_specs = ARRAY_SIZE(tsl2x7x_events),
>  			},
>  		},
> -	.chan_table_elements = 1,
> -	.info = &tsl2X7X_device_info[PRX],
> +		.channel_without_events = {
> +			{
> +			.type = IIO_PROXIMITY,
> +			.indexed = 1,
> +			.channel = 0,
> +			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> +			},
> +		},
> +		.chan_table_elements = 1,
> +		.info = &tsl2X7X_device_info[PRX],
>  	},
>  	[ALSPRX] = {
> -		.channel = {
> +		.channel_with_events = {
>  			{
>  			.type = IIO_LIGHT,
>  			.indexed = 1,
> @@ -1517,11 +1546,37 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
>  			.num_event_specs = ARRAY_SIZE(tsl2x7x_events),
>  			},
>  		},
> -	.chan_table_elements = 4,
> -	.info = &tsl2X7X_device_info[ALSPRX],
> +		.channel_without_events = {
> +			{
> +			.type = IIO_LIGHT,
> +			.indexed = 1,
> +			.channel = 0,
> +			.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
> +			}, {
> +			.type = IIO_INTENSITY,
> +			.indexed = 1,
> +			.channel = 0,
> +			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> +				BIT(IIO_CHAN_INFO_INT_TIME) |
> +				BIT(IIO_CHAN_INFO_CALIBSCALE) |
> +				BIT(IIO_CHAN_INFO_CALIBBIAS),
> +			}, {
> +			.type = IIO_INTENSITY,
> +			.indexed = 1,
> +			.channel = 1,
> +			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> +			}, {
> +			.type = IIO_PROXIMITY,
> +			.indexed = 1,
> +			.channel = 0,
> +			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> +			},
> +		},
> +		.chan_table_elements = 4,
> +		.info = &tsl2X7X_device_info[ALSPRX],
>  	},
>  	[PRX2] = {
> -		.channel = {
> +		.channel_with_events = {
>  			{
>  			.type = IIO_PROXIMITY,
>  			.indexed = 1,
> @@ -1532,11 +1587,20 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
>  			.num_event_specs = ARRAY_SIZE(tsl2x7x_events),
>  			},
>  		},
> -	.chan_table_elements = 1,
> -	.info = &tsl2X7X_device_info[PRX2],
> +		.channel_without_events = {
> +			{
> +			.type = IIO_PROXIMITY,
> +			.indexed = 1,
> +			.channel = 0,
> +			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> +				BIT(IIO_CHAN_INFO_CALIBSCALE),
> +			},
> +		},
> +		.chan_table_elements = 1,
> +		.info = &tsl2X7X_device_info[PRX2],
>  	},
>  	[ALSPRX2] = {
> -		.channel = {
> +		.channel_with_events = {
>  			{
>  			.type = IIO_LIGHT,
>  			.indexed = 1,
> @@ -1567,8 +1631,35 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
>  			.num_event_specs = ARRAY_SIZE(tsl2x7x_events),
>  			},
>  		},
> -	.chan_table_elements = 4,
> -	.info = &tsl2X7X_device_info[ALSPRX2],
> +		.channel_without_events = {
> +			{
> +			.type = IIO_LIGHT,
> +			.indexed = 1,
> +			.channel = 0,
> +			.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
> +			}, {
> +			.type = IIO_INTENSITY,
> +			.indexed = 1,
> +			.channel = 0,
> +			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> +				BIT(IIO_CHAN_INFO_INT_TIME) |
> +				BIT(IIO_CHAN_INFO_CALIBSCALE) |
> +				BIT(IIO_CHAN_INFO_CALIBBIAS),
> +			}, {
> +			.type = IIO_INTENSITY,
> +			.indexed = 1,
> +			.channel = 1,
> +			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> +			}, {
> +			.type = IIO_PROXIMITY,
> +			.indexed = 1,
> +			.channel = 0,
> +			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> +				BIT(IIO_CHAN_INFO_CALIBSCALE),
> +			},
> +		},
> +		.chan_table_elements = 4,
> +		.info = &tsl2X7X_device_info[ALSPRX2],
>  	},
>  };
>  
> @@ -1620,10 +1711,11 @@ static int tsl2x7x_probe(struct i2c_client *clientp,
>  	indio_dev->dev.parent = &clientp->dev;
>  	indio_dev->modes = INDIO_DIRECT_MODE;
>  	indio_dev->name = chip->client->name;
> -	indio_dev->channels = chip->chip_info->channel;
>  	indio_dev->num_channels = chip->chip_info->chan_table_elements;
>  
>  	if (clientp->irq) {
> +		indio_dev->channels = chip->chip_info->channel_with_events;
> +
>  		ret = devm_request_threaded_irq(&clientp->dev, clientp->irq,
>  						NULL,
>  						&tsl2x7x_event_handler,
> @@ -1636,6 +1728,8 @@ static int tsl2x7x_probe(struct i2c_client *clientp,
>  				"%s: irq request failed\n", __func__);
>  			return ret;
>  		}
> +	} else {
> +		indio_dev->channels = chip->chip_info->channel_without_events;
>  	}
>  
>  	tsl2x7x_defaults(chip);

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

* Re: [PATCH v2 04/11] staging: iio: tsl2x7x: move calibscale_available attribute to IIO_INTENSITY channel
  2018-05-04  2:53 ` [PATCH v2 04/11] staging: iio: tsl2x7x: move calibscale_available attribute to IIO_INTENSITY channel Brian Masney
@ 2018-05-06 18:06   ` Jonathan Cameron
  0 siblings, 0 replies; 24+ messages in thread
From: Jonathan Cameron @ 2018-05-06 18:06 UTC (permalink / raw)
  To: Brian Masney
  Cc: devel, lars, linux-iio, gregkh, linux-kernel, pmeerw, knaack.h,
	drew.paterson

On Thu,  3 May 2018 22:53:12 -0400
Brian Masney <masneyb@onstation.org> wrote:

> The calibscale_available attribute is currently associated with the
> IIO_LIGHT channel but should be associated with the IIO_INTENSITY
> channel. This patch corrects that association and it also corrects
> lines that were unnecessarily split for the
> in_intensity0_integration_time sysfs attribute.
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>
Applied,

Thanks,

Jonathan

> ---
>  drivers/staging/iio/light/tsl2x7x.c | 23 ++++++++++-------------
>  1 file changed, 10 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c
> index 7e8db5178a2c..9aee04fb4168 100644
> --- a/drivers/staging/iio/light/tsl2x7x.c
> +++ b/drivers/staging/iio/light/tsl2x7x.c
> @@ -777,9 +777,9 @@ static int tsl2x7x_prox_cal(struct iio_dev *indio_dev)
>  }
>  
>  static ssize_t
> -in_illuminance0_calibscale_available_show(struct device *dev,
> -					  struct device_attribute *attr,
> -					  char *buf)
> +in_intensity0_calibscale_available_show(struct device *dev,
> +					struct device_attribute *attr,
> +					char *buf)
>  {
>  	struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev));
>  
> @@ -1247,7 +1247,7 @@ static int tsl2x7x_write_raw(struct iio_dev *indio_dev,
>  	return tsl2x7x_invoke_change(indio_dev);
>  }
>  
> -static DEVICE_ATTR_RO(in_illuminance0_calibscale_available);
> +static DEVICE_ATTR_RO(in_intensity0_calibscale_available);
>  
>  static DEVICE_ATTR_RW(in_illuminance0_target_input);
>  
> @@ -1321,9 +1321,8 @@ static irqreturn_t tsl2x7x_event_handler(int irq, void *private)
>  }
>  
>  static struct attribute *tsl2x7x_ALS_device_attrs[] = {
> -	&dev_attr_in_illuminance0_calibscale_available.attr,
> -	&iio_const_attr_in_intensity0_integration_time_available
> -		.dev_attr.attr,
> +	&dev_attr_in_intensity0_calibscale_available.attr,
> +	&iio_const_attr_in_intensity0_integration_time_available.dev_attr.attr,
>  	&dev_attr_in_illuminance0_target_input.attr,
>  	&dev_attr_in_illuminance0_calibrate.attr,
>  	&dev_attr_in_illuminance0_lux_table.attr,
> @@ -1336,9 +1335,8 @@ static struct attribute *tsl2x7x_PRX_device_attrs[] = {
>  };
>  
>  static struct attribute *tsl2x7x_ALSPRX_device_attrs[] = {
> -	&dev_attr_in_illuminance0_calibscale_available.attr,
> -	&iio_const_attr_in_intensity0_integration_time_available
> -		.dev_attr.attr,
> +	&dev_attr_in_intensity0_calibscale_available.attr,
> +	&iio_const_attr_in_intensity0_integration_time_available.dev_attr.attr,
>  	&dev_attr_in_illuminance0_target_input.attr,
>  	&dev_attr_in_illuminance0_calibrate.attr,
>  	&dev_attr_in_illuminance0_lux_table.attr,
> @@ -1352,9 +1350,8 @@ static struct attribute *tsl2x7x_PRX2_device_attrs[] = {
>  };
>  
>  static struct attribute *tsl2x7x_ALSPRX2_device_attrs[] = {
> -	&dev_attr_in_illuminance0_calibscale_available.attr,
> -	&iio_const_attr_in_intensity0_integration_time_available
> -		.dev_attr.attr,
> +	&dev_attr_in_intensity0_calibscale_available.attr,
> +	&iio_const_attr_in_intensity0_integration_time_available.dev_attr.attr,
>  	&dev_attr_in_illuminance0_target_input.attr,
>  	&dev_attr_in_illuminance0_calibrate.attr,
>  	&dev_attr_in_illuminance0_lux_table.attr,

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

* Re: [PATCH v2 05/11] staging: iio: tsl2x7x: use IIO_CONST_ATTR for calibscale_available
  2018-05-04  2:53 ` [PATCH v2 05/11] staging: iio: tsl2x7x: use IIO_CONST_ATTR for calibscale_available Brian Masney
@ 2018-05-06 18:07   ` Jonathan Cameron
  0 siblings, 0 replies; 24+ messages in thread
From: Jonathan Cameron @ 2018-05-06 18:07 UTC (permalink / raw)
  To: Brian Masney
  Cc: devel, lars, linux-iio, gregkh, linux-kernel, pmeerw, knaack.h,
	drew.paterson

On Thu,  3 May 2018 22:53:13 -0400
Brian Masney <masneyb@onstation.org> wrote:

> The in_intensity0_calibscale_available sysfs attribute has code that
> checks the device type to determine which calibration scales are
> available. This check is not necessary since all of the supported
> ALS device types use the scales 1 8 16 120. This patch converts the
> sysfs attribute to use IIO_CONST_ATTR. The following device datasheets
> were checked: tsl2571, tsl2771, tmd2771, tsl2572, tsl2772, tmd2772.
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>
Applied to the togreg branch of iio.git and pushed out as testing
for the autobuilders to play with.

Jonathan

> ---
>  drivers/staging/iio/light/tsl2x7x.c | 46 ++++---------------------------------
>  1 file changed, 4 insertions(+), 42 deletions(-)
> 
> diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c
> index 9aee04fb4168..cf582a2e3633 100644
> --- a/drivers/staging/iio/light/tsl2x7x.c
> +++ b/drivers/staging/iio/light/tsl2x7x.c
> @@ -776,24 +776,7 @@ static int tsl2x7x_prox_cal(struct iio_dev *indio_dev)
>  	return tsl2x7x_invoke_change(indio_dev);
>  }
>  
> -static ssize_t
> -in_intensity0_calibscale_available_show(struct device *dev,
> -					struct device_attribute *attr,
> -					char *buf)
> -{
> -	struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev));
> -
> -	switch (chip->id) {
> -	case tsl2571:
> -	case tsl2671:
> -	case tmd2671:
> -	case tsl2771:
> -	case tmd2771:
> -		return snprintf(buf, PAGE_SIZE, "%s\n", "1 8 16 128");
> -	}
> -
> -	return snprintf(buf, PAGE_SIZE, "%s\n", "1 8 16 120");
> -}
> +static IIO_CONST_ATTR(in_intensity0_calibscale_available, "1 8 16 120");
>  
>  static IIO_CONST_ATTR(in_proximity0_calibscale_available, "1 2 4 8");
>  
> @@ -1190,25 +1173,6 @@ static int tsl2x7x_write_raw(struct iio_dev *indio_dev,
>  				chip->settings.als_gain = 2;
>  				break;
>  			case 120:
> -				switch (chip->id) {
> -				case tsl2572:
> -				case tsl2672:
> -				case tmd2672:
> -				case tsl2772:
> -				case tmd2772:
> -					return -EINVAL;
> -				}
> -				chip->settings.als_gain = 3;
> -				break;
> -			case 128:
> -				switch (chip->id) {
> -				case tsl2571:
> -				case tsl2671:
> -				case tmd2671:
> -				case tsl2771:
> -				case tmd2771:
> -					return -EINVAL;
> -				}
>  				chip->settings.als_gain = 3;
>  				break;
>  			default:
> @@ -1247,8 +1211,6 @@ static int tsl2x7x_write_raw(struct iio_dev *indio_dev,
>  	return tsl2x7x_invoke_change(indio_dev);
>  }
>  
> -static DEVICE_ATTR_RO(in_intensity0_calibscale_available);
> -
>  static DEVICE_ATTR_RW(in_illuminance0_target_input);
>  
>  static DEVICE_ATTR_WO(in_illuminance0_calibrate);
> @@ -1321,7 +1283,7 @@ static irqreturn_t tsl2x7x_event_handler(int irq, void *private)
>  }
>  
>  static struct attribute *tsl2x7x_ALS_device_attrs[] = {
> -	&dev_attr_in_intensity0_calibscale_available.attr,
> +	&iio_const_attr_in_intensity0_calibscale_available.dev_attr.attr,
>  	&iio_const_attr_in_intensity0_integration_time_available.dev_attr.attr,
>  	&dev_attr_in_illuminance0_target_input.attr,
>  	&dev_attr_in_illuminance0_calibrate.attr,
> @@ -1335,7 +1297,7 @@ static struct attribute *tsl2x7x_PRX_device_attrs[] = {
>  };
>  
>  static struct attribute *tsl2x7x_ALSPRX_device_attrs[] = {
> -	&dev_attr_in_intensity0_calibscale_available.attr,
> +	&iio_const_attr_in_intensity0_calibscale_available.dev_attr.attr,
>  	&iio_const_attr_in_intensity0_integration_time_available.dev_attr.attr,
>  	&dev_attr_in_illuminance0_target_input.attr,
>  	&dev_attr_in_illuminance0_calibrate.attr,
> @@ -1350,7 +1312,7 @@ static struct attribute *tsl2x7x_PRX2_device_attrs[] = {
>  };
>  
>  static struct attribute *tsl2x7x_ALSPRX2_device_attrs[] = {
> -	&dev_attr_in_intensity0_calibscale_available.attr,
> +	&iio_const_attr_in_intensity0_calibscale_available.dev_attr.attr,
>  	&iio_const_attr_in_intensity0_integration_time_available.dev_attr.attr,
>  	&dev_attr_in_illuminance0_target_input.attr,
>  	&dev_attr_in_illuminance0_calibrate.attr,

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

* Re: [PATCH v2 06/11] staging: iio: tsl2x7x: correct integration time and lux equation
  2018-05-04  2:53 ` [PATCH v2 06/11] staging: iio: tsl2x7x: correct integration time and lux equation Brian Masney
@ 2018-05-06 18:11   ` Jonathan Cameron
  0 siblings, 0 replies; 24+ messages in thread
From: Jonathan Cameron @ 2018-05-06 18:11 UTC (permalink / raw)
  To: Brian Masney
  Cc: devel, lars, linux-iio, gregkh, linux-kernel, pmeerw, knaack.h,
	drew.paterson

On Thu,  3 May 2018 22:53:14 -0400
Brian Masney <masneyb@onstation.org> wrote:

> The integration_time sysfs attribute did not report the correct
> time. Changing the integration time would cause the reported lux to
> change wildly. Once the integration time was corrected, all of the
> equations, and lux tables needed to be corrected to match what the
> data sheets expected. This patch corrects all of this, and adds some
> more comments about how some of the constants were derived. Here are
> the results from testing a TSL2772 hooked up to a Raspberry Pi 2:
> 
> # cat in_intensity0_integration_time
> 0.002730
> # watch -n .1 cat in_illuminance0_input
> ; Lux hovers around 55
> # echo 0.65 > in_intensity0_integration_time
> # cat in_intensity0_integration_time
> 0.649740
> # watch -n .1 cat in_illuminance0_input
> ; Lux hovers around 55 with noticeable lag to lux changes in watch
> ; process.
> 
> ; Now test the ALS calibration routine.
> # cat in_intensity0_calibbias
> 1000
> # cat in_illuminance0_target_input
> 150
> # echo 1 > in_illuminance0_calibrate
> # cat in_intensity0_calibbias
> 2777
> # watch -n .1 cat in_illuminance0_input
> ; Lux now hovers around 150-155
> 
> The returned lux values were tested on a TSL2772 in various lighting
> conditions and the results are within the lux ranges described at
> https://en.wikipedia.org/wiki/Lux.
> 
> The driver was primarily tested using a TSL2772, however some quick tests
> were also ran against the devices TSL2771, TSL2572, and TMD2772.
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>
Yikes.  I'm not going to try and repeat your checking of the various data
sheets so I'll just assume the numbers are right!

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

Thanks,

Jonathan

> ---
>  drivers/staging/iio/light/tsl2x7x.c | 174 ++++++++++++++++--------------------
>  drivers/staging/iio/light/tsl2x7x.h |   3 +-
>  2 files changed, 79 insertions(+), 98 deletions(-)
> 
> diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c
> index cf582a2e3633..9b32054713fb 100644
> --- a/drivers/staging/iio/light/tsl2x7x.c
> +++ b/drivers/staging/iio/light/tsl2x7x.c
> @@ -148,7 +148,7 @@ struct tsl2X7X_chip {
>  	struct tsl2x7x_als_info als_cur_info;
>  	struct tsl2x7x_settings settings;
>  	struct tsl2X7X_platform_data *pdata;
> -	int als_time_scale;
> +	int als_gain_time_scale;
>  	int als_saturation;
>  	int tsl2x7x_chip_status;
>  	u8 tsl2x7x_config[TSL2X7X_MAX_CONFIG_REG];
> @@ -163,29 +163,36 @@ struct tsl2X7X_chip {
>  	struct tsl2x7x_lux tsl2x7x_device_lux[TSL2X7X_MAX_LUX_TABLE_SIZE];
>  };
>  
> -/* Different devices require different coefficents */
> +/*
> + * Different devices require different coefficents, and these numbers were
> + * derived from the 'Lux Equation' section of the various device datasheets.
> + * All of these coefficients assume a Glass Attenuation (GA) factor of 1.
> + * The coefficients are multiplied by 1000 to avoid floating point operations.
> + * The two rows in each table correspond to the Lux1 and Lux2 equations from
> + * the datasheets.
> + */
>  static const struct tsl2x7x_lux tsl2x71_lux_table[TSL2X7X_DEF_LUX_TABLE_SZ] = {
> -	{ 14461,   611,   1211 },
> -	{ 18540,   352,    623 },
> -	{     0,     0,      0 },
> +	{ 53000, 106000 },
> +	{ 31800,  53000 },
> +	{ 0,          0 },
>  };
>  
>  static const struct tsl2x7x_lux tmd2x71_lux_table[TSL2X7X_DEF_LUX_TABLE_SZ] = {
> -	{ 11635,   115,    256 },
> -	{ 15536,    87,    179 },
> -	{     0,     0,      0 },
> +	{ 24000,  48000 },
> +	{ 14400,  24000 },
> +	{ 0,          0 },
>  };
>  
>  static const struct tsl2x7x_lux tsl2x72_lux_table[TSL2X7X_DEF_LUX_TABLE_SZ] = {
> -	{ 14013,   466,   917 },
> -	{ 18222,   310,   552 },
> -	{     0,     0,     0 },
> +	{ 60000, 112200 },
> +	{ 37800,  60000 },
> +	{     0,      0 },
>  };
>  
>  static const struct tsl2x7x_lux tmd2x72_lux_table[TSL2X7X_DEF_LUX_TABLE_SZ] = {
> -	{ 13218,   130,   262 },
> -	{ 17592,   92,    169 },
> -	{     0,     0,     0 },
> +	{ 20000,  35000 },
> +	{ 12600,  20000 },
> +	{     0,      0 },
>  };
>  
>  static const struct tsl2x7x_lux *tsl2x7x_default_lux_table_group[] = {
> @@ -343,22 +350,18 @@ static int tsl2x7x_read_autoinc_regs(struct tsl2X7X_chip *chip, int lower_reg,
>   * @indio_dev:	pointer to IIO device
>   *
>   * The raw ch0 and ch1 values of the ambient light sensed in the last
> - * integration cycle are read from the device. Time scale factor array values
> - * are adjusted based on the integration time. The raw values are multiplied
> - * by a scale factor, and device gain is obtained using gain index. Limit
> - * checks are done next, then the ratio of a multiple of ch1 value, to the
> - * ch0 value, is calculated. Array tsl2x7x_device_lux[] is then scanned to
> - * find the first ratio value that is just above the ratio we just calculated.
> - * The ch0 and ch1 multiplier constants in the array are then used along with
> - * the time scale factor array values, to calculate the lux.
> + * integration cycle are read from the device. The raw values are multiplied
> + * by a device-specific scale factor, and divided by the integration time and
> + * device gain. The code supports multiple lux equations through the lux table
> + * coefficients. A lux gain trim is applied to each lux equation, and then the
> + * maximum lux within the interval 0..65535 is selected.
>   */
>  static int tsl2x7x_get_lux(struct iio_dev *indio_dev)
>  {
>  	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
>  	struct tsl2x7x_lux *p;
> -	u32 lux, ratio;
> -	u64 lux64;
> -	int ret;
> +	int max_lux, ret;
> +	bool overflow;
>  
>  	mutex_lock(&chip->als_mutex);
>  
> @@ -392,10 +395,9 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev)
>  		goto out_unlock;
>  	chip->als_cur_info.als_ch1 = ret;
>  
> -	if (chip->als_cur_info.als_ch0 >= chip->als_saturation ||
> -	    chip->als_cur_info.als_ch1 >= chip->als_saturation) {
> -		lux = TSL2X7X_LUX_CALC_OVER_FLOW;
> -		goto return_max;
> +	if (chip->als_cur_info.als_ch0 >= chip->als_saturation) {
> +		max_lux = TSL2X7X_LUX_CALC_OVER_FLOW;
> +		goto update_struct_with_max_lux;
>  	}
>  
>  	if (!chip->als_cur_info.als_ch0) {
> @@ -404,51 +406,38 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev)
>  		goto out_unlock;
>  	}
>  
> -	/* calculate ratio */
> -	ratio = (chip->als_cur_info.als_ch1 << 15) / chip->als_cur_info.als_ch0;
> -
> -	/* convert to unscaled lux using the pointer to the table */
> -	p = (struct tsl2x7x_lux *)chip->tsl2x7x_device_lux;
> -	while (p->ratio != 0 && p->ratio < ratio)
> -		p++;
> +	max_lux = 0;
> +	overflow = false;
> +	for (p = (struct tsl2x7x_lux *)chip->tsl2x7x_device_lux; p->ch0 != 0;
> +	     p++) {
> +		int lux;
> +
> +		lux = ((chip->als_cur_info.als_ch0 * p->ch0) -
> +		       (chip->als_cur_info.als_ch1 * p->ch1)) /
> +			chip->als_gain_time_scale;
> +
> +		/*
> +		 * The als_gain_trim can have a value within the range 250..4000
> +		 * and is a multiplier for the lux. A trim of 1000 makes no
> +		 * changes to the lux, less than 1000 scales it down, and
> +		 * greater than 1000 scales it up.
> +		 */
> +		lux = (lux * chip->settings.als_gain_trim) / 1000;
> +
> +		if (lux > TSL2X7X_LUX_CALC_OVER_FLOW) {
> +			overflow = true;
> +			continue;
> +		}
>  
> -	if (p->ratio == 0) {
> -		lux = 0;
> -	} else {
> -		lux = DIV_ROUND_UP(chip->als_cur_info.als_ch0 * p->ch0,
> -				   tsl2x7x_als_gain[chip->settings.als_gain]) -
> -		      DIV_ROUND_UP(chip->als_cur_info.als_ch1 * p->ch1,
> -				   tsl2x7x_als_gain[chip->settings.als_gain]);
> +		max_lux = max(max_lux, lux);
>  	}
>  
> -	/* 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 tsl2x7x_device_lux tables have a
> -	 * factor of 256 built-in. User-specified gain provides a multiplier.
> -	 * Apply user-specified gain before shifting right to retain precision.
> -	 * Use 64 bits to avoid overflow on multiplication. Then go back to
> -	 * 32 bits before division to avoid using div_u64().
> -	 */
> -
> -	lux64 = lux;
> -	lux64 = lux64 * chip->settings.als_gain_trim;
> -	lux64 >>= 8;
> -	lux = lux64;
> -	lux = (lux + 500) / 1000;
> +	if (overflow && max_lux == 0)
> +		max_lux = TSL2X7X_LUX_CALC_OVER_FLOW;
>  
> -	if (lux > TSL2X7X_LUX_CALC_OVER_FLOW) /* check for overflow */
> -		lux = TSL2X7X_LUX_CALC_OVER_FLOW;
> -
> -	/* Update the structure with the latest lux. */
> -return_max:
> -	chip->als_cur_info.lux = lux;
> -	ret = lux;
> +update_struct_with_max_lux:
> +	chip->als_cur_info.lux = max_lux;
> +	ret = max_lux;
>  
>  out_unlock:
>  	mutex_unlock(&chip->als_mutex);
> @@ -525,7 +514,7 @@ static void tsl2x7x_defaults(struct tsl2X7X_chip *chip)
>  		       sizeof(tsl2x7x_default_settings));
>  
>  	/* Load up the proper lux table. */
> -	if (chip->pdata && chip->pdata->platform_lux_table[0].ratio != 0)
> +	if (chip->pdata && chip->pdata->platform_lux_table[0].ch0 != 0)
>  		memcpy(chip->tsl2x7x_device_lux,
>  		       chip->pdata->platform_lux_table,
>  		       sizeof(chip->pdata->platform_lux_table));
> @@ -588,10 +577,11 @@ static int tsl2x7x_als_calibrate(struct iio_dev *indio_dev)
>  static int tsl2x7x_chip_on(struct iio_dev *indio_dev)
>  {
>  	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
> -	int ret, i, als_count, als_time;
> +	int ret, i, als_count, als_time_us;
>  	u8 *dev_reg, reg_val;
>  
>  	/* Non calculated parameters */
> +	chip->tsl2x7x_config[TSL2X7X_ALS_TIME] = chip->settings.als_time;
>  	chip->tsl2x7x_config[TSL2X7X_PRX_TIME] = chip->settings.prox_time;
>  	chip->tsl2x7x_config[TSL2X7X_WAIT_TIME] = chip->settings.wait_time;
>  	chip->tsl2x7x_config[TSL2X7X_ALS_PRX_CONFIG] =
> @@ -627,15 +617,6 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev)
>  		return -EINVAL;
>  	}
>  
> -	/* determine als integration register */
> -	als_count = (chip->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;
> -	chip->tsl2x7x_config[TSL2X7X_ALS_TIME] = 256 - als_count;
> -
>  	/* Set the gain based on tsl2x7x_settings struct */
>  	chip->tsl2x7x_config[TSL2X7X_GAIN] =
>  		(chip->settings.als_gain & 0xFF) |
> @@ -643,9 +624,12 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev)
>  		(chip->settings.prox_diode << 4) |
>  		(chip->settings.prox_power << 6);
>  
> -	/* 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;
> +	/* set chip time scaling and saturation */
> +	als_count = 256 - chip->settings.als_time;
> +	als_time_us = als_count * 2720;
> +	chip->als_saturation = als_count * 768; /* 75% of full scale */
> +	chip->als_gain_time_scale = als_time_us *
> +		tsl2x7x_als_gain[chip->settings.als_gain];
>  
>  	/*
>  	 * TSL2X7X Specific power-on / adc enable sequence
> @@ -843,11 +827,10 @@ static ssize_t in_illuminance0_lux_table_show(struct device *dev,
>  	int offset = 0;
>  
>  	while (i < TSL2X7X_MAX_LUX_TABLE_SIZE) {
> -		offset += snprintf(buf + offset, PAGE_SIZE, "%u,%u,%u,",
> -			chip->tsl2x7x_device_lux[i].ratio,
> +		offset += snprintf(buf + offset, PAGE_SIZE, "%u,%u,",
>  			chip->tsl2x7x_device_lux[i].ch0,
>  			chip->tsl2x7x_device_lux[i].ch1);
> -		if (chip->tsl2x7x_device_lux[i].ratio == 0) {
> +		if (chip->tsl2x7x_device_lux[i].ch0 == 0) {
>  			/*
>  			 * We just printed the first "0" entry.
>  			 * Now get rid of the extra "," and break.
> @@ -868,7 +851,7 @@ static ssize_t in_illuminance0_lux_table_store(struct device *dev,
>  {
>  	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
>  	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
> -	int value[ARRAY_SIZE(chip->tsl2x7x_device_lux) * 3 + 1];
> +	int value[ARRAY_SIZE(chip->tsl2x7x_device_lux) * 2 + 1];
>  	int n, ret;
>  
>  	get_options(buf, ARRAY_SIZE(value), value);
> @@ -876,15 +859,15 @@ static ssize_t in_illuminance0_lux_table_store(struct device *dev,
>  	/*
>  	 * 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,
> +	 * We expect each group of two ints to be one table entry,
>  	 * and the last table entry is all 0.
>  	 */
>  	n = value[0];
> -	if ((n % 3) || n < 6 ||
> -	    n > ((ARRAY_SIZE(chip->tsl2x7x_device_lux) - 1) * 3))
> +	if ((n % 2) || n < 4 ||
> +	    n > ((ARRAY_SIZE(chip->tsl2x7x_device_lux) - 1) * 2))
>  		return -EINVAL;
>  
> -	if ((value[(n - 2)] | value[(n - 1)] | value[n]) != 0)
> +	if ((value[(n - 1)] | value[n]) != 0)
>  		return -EINVAL;
>  
>  	if (chip->tsl2x7x_chip_status == TSL2X7X_CHIP_WORKING) {
> @@ -1140,8 +1123,8 @@ static int tsl2x7x_read_raw(struct iio_dev *indio_dev,
>  		ret = IIO_VAL_INT;
>  		break;
>  	case IIO_CHAN_INFO_INT_TIME:
> -		*val = (TSL2X7X_MAX_TIMER_CNT - chip->settings.als_time) + 1;
> -		*val2 = ((*val * TSL2X7X_MIN_ITIME) % 1000) / 1000;
> +		*val = 0;
> +		*val2 = (256 - chip->settings.als_time) * 2720;
>  		ret = IIO_VAL_INT_PLUS_MICRO;
>  		break;
>  	default:
> @@ -1201,8 +1184,7 @@ static int tsl2x7x_write_raw(struct iio_dev *indio_dev,
>  		chip->settings.als_gain_trim = val;
>  		break;
>  	case IIO_CHAN_INFO_INT_TIME:
> -		chip->settings.als_time =
> -			TSL2X7X_MAX_TIMER_CNT - (val2 / TSL2X7X_MIN_ITIME);
> +		chip->settings.als_time = 256 - (val2 / 2720);
>  		break;
>  	default:
>  		return -EINVAL;
> diff --git a/drivers/staging/iio/light/tsl2x7x.h b/drivers/staging/iio/light/tsl2x7x.h
> index 8eb7f4749ea7..1097ee890ce2 100644
> --- a/drivers/staging/iio/light/tsl2x7x.h
> +++ b/drivers/staging/iio/light/tsl2x7x.h
> @@ -10,13 +10,12 @@
>  #define __TSL2X7X_H
>  
>  struct tsl2x7x_lux {
> -	unsigned int ratio;
>  	unsigned int ch0;
>  	unsigned int ch1;
>  };
>  
>  /* Max number of segments allowable in LUX table */
> -#define TSL2X7X_MAX_LUX_TABLE_SIZE		9
> +#define TSL2X7X_MAX_LUX_TABLE_SIZE		6
>  /* The default LUX tables all have 3 elements.  */
>  #define TSL2X7X_DEF_LUX_TABLE_SZ		3
>  #define TSL2X7X_DEFAULT_TABLE_BYTES (sizeof(struct tsl2x7x_lux) * \

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

* Re: [PATCH v2 07/11] staging: iio: tsl2x7x: support 2.72 and 2.73 ALS increments
  2018-05-04  2:53 ` [PATCH v2 07/11] staging: iio: tsl2x7x: support 2.72 and 2.73 ALS increments Brian Masney
@ 2018-05-06 18:19   ` Jonathan Cameron
  0 siblings, 0 replies; 24+ messages in thread
From: Jonathan Cameron @ 2018-05-06 18:19 UTC (permalink / raw)
  To: Brian Masney
  Cc: linux-iio, gregkh, devel, knaack.h, lars, pmeerw, linux-kernel,
	drew.paterson

On Thu,  3 May 2018 22:53:15 -0400
Brian Masney <masneyb@onstation.org> wrote:

> The driver assumed that the ALS increment was 2.72 ms, and the upper
> range was 696 ms. Some other supported devices use 2.73 ms - 699 ms.
> This patch adds support for the multiple ranges.
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>

My problem here is that this isn't compatible with the ABI for
available.   Originally it could only be used if we had short
list of possible values.  We did add the (currently poorly documented
which is my fault ;() option of defining it with limits and
interval, but this doesn't obey that format either.
see iio_format_avail_range
[min step max]

Ideally perhaps actually set it up to use read_avail callback
as then you'll get that for free.  I've not pushed it that heavily
as a way to do things because we obviously have a 'lot' of driver
that predate that core support and I don't want a rush to move
them over where it isn't useful.

Jonathan
> ---
> I debated whether or not this change should even be included. I feel
> pretty confident that I can cleanly fold the tsl2583 driver into this
> driver once the staging graduation is done. Those devices have an ALS
> range of 2.7 ms - 688.5 ms.
> 
>  drivers/staging/iio/light/tsl2x7x.c | 50 +++++++++++++++++++++++++++++--------
>  1 file changed, 40 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c
> index 9b32054713fb..e3e37501829f 100644
> --- a/drivers/staging/iio/light/tsl2x7x.c
> +++ b/drivers/staging/iio/light/tsl2x7x.c
> @@ -209,9 +209,9 @@ static const struct tsl2x7x_lux *tsl2x7x_default_lux_table_group[] = {
>  };
>  
>  static const struct tsl2x7x_settings tsl2x7x_default_settings = {
> -	.als_time = 255, /* 2.73 ms */
> +	.als_time = 255, /* 2.72 / 2.73 ms */
>  	.als_gain = 0,
> -	.prox_time = 255, /* 2.73 ms */
> +	.prox_time = 255, /* 2.72 / 2.73 ms */
>  	.prox_gain = 0,
>  	.wait_time = 255,
>  	.als_prox_config = 0,
> @@ -245,6 +245,24 @@ static const s16 tsl2x7x_prox_gain[] = {
>  	8
>  };
>  
> +struct tsl2x7x_int_time {
> +	int increment_us;
> +	char *display_range;
> +};
> +
> +static const struct tsl2x7x_int_time tsl2x7x_int_time[] = {
> +	[tsl2571] = { 2720, "0.00272 - 0.696" },
> +	[tsl2671] = { 2720, "0.00272 - 0.696" },
> +	[tmd2671] = { 2720, "0.00272 - 0.696" },
> +	[tsl2771] = { 2720, "0.00272 - 0.696" },
> +	[tmd2771] = { 2720, "0.00272 - 0.696" },
> +	[tsl2572] = { 2730, "0.00273 - 0.699" },
> +	[tsl2672] = { 2730, "0.00273 - 0.699" },
> +	[tmd2672] = { 2730, "0.00273 - 0.699" },
> +	[tsl2772] = { 2730, "0.00273 - 0.699" },
> +	[tmd2772] = { 2730, "0.00273 - 0.699" },
> +};
> +
>  /* Channel variations */
>  enum {
>  	ALS,
> @@ -626,7 +644,7 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev)
>  
>  	/* set chip time scaling and saturation */
>  	als_count = 256 - chip->settings.als_time;
> -	als_time_us = als_count * 2720;
> +	als_time_us = als_count * tsl2x7x_int_time[chip->id].increment_us;
>  	chip->als_saturation = als_count * 768; /* 75% of full scale */
>  	chip->als_gain_time_scale = als_time_us *
>  		tsl2x7x_als_gain[chip->settings.als_gain];
> @@ -764,8 +782,16 @@ static IIO_CONST_ATTR(in_intensity0_calibscale_available, "1 8 16 120");
>  
>  static IIO_CONST_ATTR(in_proximity0_calibscale_available, "1 2 4 8");
>  
> -static IIO_CONST_ATTR(in_intensity0_integration_time_available,
> -		".00272 - .696");
> +static ssize_t
> +in_intensity0_integration_time_available_show(struct device *dev,
> +					      struct device_attribute *attr,
> +					      char *buf)
> +{
> +	struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev));
> +
> +	return snprintf(buf, PAGE_SIZE, "%s\n",
> +			tsl2x7x_int_time[chip->id].display_range);
> +}
>  
>  static ssize_t in_illuminance0_target_input_show(struct device *dev,
>  						 struct device_attribute *attr,
> @@ -1124,7 +1150,8 @@ static int tsl2x7x_read_raw(struct iio_dev *indio_dev,
>  		break;
>  	case IIO_CHAN_INFO_INT_TIME:
>  		*val = 0;
> -		*val2 = (256 - chip->settings.als_time) * 2720;
> +		*val2 = (256 - chip->settings.als_time) *
> +			tsl2x7x_int_time[chip->id].increment_us;
>  		ret = IIO_VAL_INT_PLUS_MICRO;
>  		break;
>  	default:
> @@ -1184,7 +1211,8 @@ static int tsl2x7x_write_raw(struct iio_dev *indio_dev,
>  		chip->settings.als_gain_trim = val;
>  		break;
>  	case IIO_CHAN_INFO_INT_TIME:
> -		chip->settings.als_time = 256 - (val2 / 2720);
> +		chip->settings.als_time = 256 -
> +			(val2 / tsl2x7x_int_time[chip->id].increment_us);
>  		break;
>  	default:
>  		return -EINVAL;
> @@ -1193,6 +1221,8 @@ static int tsl2x7x_write_raw(struct iio_dev *indio_dev,
>  	return tsl2x7x_invoke_change(indio_dev);
>  }
>  
> +static DEVICE_ATTR_RO(in_intensity0_integration_time_available);
> +
>  static DEVICE_ATTR_RW(in_illuminance0_target_input);
>  
>  static DEVICE_ATTR_WO(in_illuminance0_calibrate);
> @@ -1266,7 +1296,7 @@ static irqreturn_t tsl2x7x_event_handler(int irq, void *private)
>  
>  static struct attribute *tsl2x7x_ALS_device_attrs[] = {
>  	&iio_const_attr_in_intensity0_calibscale_available.dev_attr.attr,
> -	&iio_const_attr_in_intensity0_integration_time_available.dev_attr.attr,
> +	&dev_attr_in_intensity0_integration_time_available.attr,
>  	&dev_attr_in_illuminance0_target_input.attr,
>  	&dev_attr_in_illuminance0_calibrate.attr,
>  	&dev_attr_in_illuminance0_lux_table.attr,
> @@ -1280,7 +1310,7 @@ static struct attribute *tsl2x7x_PRX_device_attrs[] = {
>  
>  static struct attribute *tsl2x7x_ALSPRX_device_attrs[] = {
>  	&iio_const_attr_in_intensity0_calibscale_available.dev_attr.attr,
> -	&iio_const_attr_in_intensity0_integration_time_available.dev_attr.attr,
> +	&dev_attr_in_intensity0_integration_time_available.attr,
>  	&dev_attr_in_illuminance0_target_input.attr,
>  	&dev_attr_in_illuminance0_calibrate.attr,
>  	&dev_attr_in_illuminance0_lux_table.attr,
> @@ -1295,7 +1325,7 @@ static struct attribute *tsl2x7x_PRX2_device_attrs[] = {
>  
>  static struct attribute *tsl2x7x_ALSPRX2_device_attrs[] = {
>  	&iio_const_attr_in_intensity0_calibscale_available.dev_attr.attr,
> -	&iio_const_attr_in_intensity0_integration_time_available.dev_attr.attr,
> +	&dev_attr_in_intensity0_integration_time_available.attr,
>  	&dev_attr_in_illuminance0_target_input.attr,
>  	&dev_attr_in_illuminance0_calibrate.attr,
>  	&dev_attr_in_illuminance0_lux_table.attr,

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

* Re: [PATCH v2 08/11] staging: iio: tsl2x7x: add device ids for code readability
  2018-05-04  2:53 ` [PATCH v2 08/11] staging: iio: tsl2x7x: add device ids for code readability Brian Masney
@ 2018-05-06 18:26   ` Jonathan Cameron
  0 siblings, 0 replies; 24+ messages in thread
From: Jonathan Cameron @ 2018-05-06 18:26 UTC (permalink / raw)
  To: Brian Masney
  Cc: devel, lars, linux-iio, gregkh, linux-kernel, pmeerw, knaack.h,
	drew.paterson

On Thu,  3 May 2018 22:53:16 -0400
Brian Masney <masneyb@onstation.org> wrote:

> This patch adds the device IDs to the device_channel_config array to
> improve code readability.
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>
Applied to the togreg branch of iio.git and pushed out as testing
for the autobuilders to play with it.

Thanks,

Jonathan

> ---
>  drivers/staging/iio/light/tsl2x7x.c | 20 ++++++++++----------
>  1 file changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c
> index e3e37501829f..39de5e60fd33 100644
> --- a/drivers/staging/iio/light/tsl2x7x.c
> +++ b/drivers/staging/iio/light/tsl2x7x.c
> @@ -273,16 +273,16 @@ enum {
>  };
>  
>  static const u8 device_channel_config[] = {
> -	ALS,
> -	PRX,
> -	PRX,
> -	ALSPRX,
> -	ALSPRX,
> -	ALS,
> -	PRX2,
> -	PRX2,
> -	ALSPRX2,
> -	ALSPRX2
> +	[tsl2571] = ALS,
> +	[tsl2671] = PRX,
> +	[tmd2671] = PRX,
> +	[tsl2771] = ALSPRX,
> +	[tmd2771] = ALSPRX,
> +	[tsl2572] = ALS,
> +	[tsl2672] = PRX2,
> +	[tmd2672] = PRX2,
> +	[tsl2772] = ALSPRX2,
> +	[tmd2772] = ALSPRX2
>  };
>  
>  static int tsl2x7x_read_status(struct tsl2X7X_chip *chip)

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

* Re: [PATCH v2 09/11] staging: iio: tsl2x7x: correct IIO_EV_INFO_PERIOD values
  2018-05-04  2:53 ` [PATCH v2 09/11] staging: iio: tsl2x7x: correct IIO_EV_INFO_PERIOD values Brian Masney
@ 2018-05-06 18:27   ` Jonathan Cameron
  0 siblings, 0 replies; 24+ messages in thread
From: Jonathan Cameron @ 2018-05-06 18:27 UTC (permalink / raw)
  To: Brian Masney
  Cc: devel, lars, linux-iio, gregkh, linux-kernel, pmeerw, knaack.h,
	drew.paterson

On Thu,  3 May 2018 22:53:17 -0400
Brian Masney <masneyb@onstation.org> wrote:

> The thresh periods assumed an integration time of 3ms. This patch adds
> support for the correct integration time (2.72ms or 2.73ms). The code
> had the ALS filter values as going up to 15, however the values actually
> went up to 60 since the values scaled in increments of 5 once the
> persistence value went above 3.
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>
Looks fine, but dependent on earlier patch so I can't take it yet.

Thanks,

Jonathan

> ---
>  drivers/staging/iio/light/tsl2x7x.c | 44 +++++++++++++++++++++----------------
>  drivers/staging/iio/light/tsl2x7x.h |  1 -
>  2 files changed, 25 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c
> index 39de5e60fd33..f912f4bc61c4 100644
> --- a/drivers/staging/iio/light/tsl2x7x.c
> +++ b/drivers/staging/iio/light/tsl2x7x.c
> @@ -103,8 +103,6 @@
>  #define TSL2X7X_CNTL_PROXPON_ENBL	0x0F
>  #define TSL2X7X_CNTL_INTPROXPON_ENBL	0x2F
>  
> -#define TSL2X7X_MIN_ITIME		3
> -
>  /* TAOS txx2x7x Device family members */
>  enum {
>  	tsl2571,
> @@ -972,7 +970,7 @@ static int tsl2x7x_write_event_value(struct iio_dev *indio_dev,
>  				     int val, int val2)
>  {
>  	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
> -	int ret = -EINVAL, y, z, filter_delay;
> +	int ret = -EINVAL, count, persistence;
>  	u8 time;
>  
>  	switch (info) {
> @@ -1011,15 +1009,20 @@ static int tsl2x7x_write_event_value(struct iio_dev *indio_dev,
>  		else
>  			time = chip->settings.prox_time;
>  
> -		y = (TSL2X7X_MAX_TIMER_CNT - time) + 1;
> -		z = y * TSL2X7X_MIN_ITIME;
> +		count = 256 - time;
> +		persistence = ((val * 1000000) + val2) /
> +			(count * tsl2x7x_int_time[chip->id].increment_us);
>  
> -		filter_delay = DIV_ROUND_UP((val * 1000) + val2, z);
> +		if (chan->type == IIO_INTENSITY) {
> +			/* ALS filter values are 1, 2, 3, 5, 10, 15, ..., 60 */
> +			if (persistence > 3)
> +				persistence = (persistence / 5) + 3;
> +
> +			chip->settings.als_persistence = persistence;
> +		} else {
> +			chip->settings.prox_persistence = persistence;
> +		}
>  
> -		if (chan->type == IIO_INTENSITY)
> -			chip->settings.als_persistence = filter_delay;
> -		else
> -			chip->settings.prox_persistence = filter_delay;
>  		ret = 0;
>  		break;
>  	default:
> @@ -1040,7 +1043,7 @@ static int tsl2x7x_read_event_value(struct iio_dev *indio_dev,
>  				    int *val, int *val2)
>  {
>  	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
> -	int ret = -EINVAL, filter_delay, mult;
> +	int ret = -EINVAL, filter_delay, persistence;
>  	u8 time;
>  
>  	switch (info) {
> @@ -1076,18 +1079,21 @@ static int tsl2x7x_read_event_value(struct iio_dev *indio_dev,
>  	case IIO_EV_INFO_PERIOD:
>  		if (chan->type == IIO_INTENSITY) {
>  			time = chip->settings.als_time;
> -			mult = chip->settings.als_persistence;
> +			persistence = chip->settings.als_persistence;
> +
> +			/* ALS filter values are 1, 2, 3, 5, 10, 15, ..., 60 */
> +			if (persistence > 3)
> +				persistence = (persistence - 3) * 5;
>  		} else {
>  			time = chip->settings.prox_time;
> -			mult = chip->settings.prox_persistence;
> +			persistence = chip->settings.prox_persistence;
>  		}
>  
> -		/* Determine integration time */
> -		*val = (TSL2X7X_MAX_TIMER_CNT - time) + 1;
> -		*val2 = *val * TSL2X7X_MIN_ITIME;
> -		filter_delay = *val2 * mult;
> -		*val = filter_delay / 1000;
> -		*val2 = filter_delay % 1000;
> +		filter_delay = persistence * (256 - time) *
> +			tsl2x7x_int_time[chip->id].increment_us;
> +
> +		*val = filter_delay / 1000000;
> +		*val2 = filter_delay % 1000000;
>  		ret = IIO_VAL_INT_PLUS_MICRO;
>  		break;
>  	default:
> diff --git a/drivers/staging/iio/light/tsl2x7x.h b/drivers/staging/iio/light/tsl2x7x.h
> index 1097ee890ce2..f74427f4ab6e 100644
> --- a/drivers/staging/iio/light/tsl2x7x.h
> +++ b/drivers/staging/iio/light/tsl2x7x.h
> @@ -31,7 +31,6 @@ struct tsl2x7x_lux {
>  #define TSL2X7X_50_mA                   0x01
>  #define TSL2X7X_25_mA                   0x02
>  #define TSL2X7X_13_mA                   0x03
> -#define TSL2X7X_MAX_TIMER_CNT           0xFF
>  
>  /**
>   * struct tsl2x7x_settings - Settings for the tsl2x7x driver

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

* Re: [PATCH v2 10/11] staging: iio: tsl2x7x: rename driver to tsl2772
  2018-05-04  2:53 ` [PATCH v2 10/11] staging: iio: tsl2x7x: rename driver to tsl2772 Brian Masney
@ 2018-05-06 18:29   ` Jonathan Cameron
  0 siblings, 0 replies; 24+ messages in thread
From: Jonathan Cameron @ 2018-05-06 18:29 UTC (permalink / raw)
  To: Brian Masney
  Cc: devel, lars, linux-iio, gregkh, linux-kernel, pmeerw, knaack.h,
	drew.paterson

On Thu,  3 May 2018 22:53:18 -0400
Brian Masney <masneyb@onstation.org> wrote:

> This patch renames this driver from tsl2x7x to tsl2772 since it is
> highly likely that additional devices will be added to this driver that
> do not match that wildcard. The tsl2772 driver name was selected since
> that is currently the device with the most features that are supported
> by this driver.
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>
Good change to make.  Normally changing Kconfig symbols etc can
cause problems, but I think for a staging driver we are probably
fine.

Thanks,

Jonathan

> ---
>  drivers/staging/iio/light/Kconfig                  |   2 +-
>  drivers/staging/iio/light/Makefile                 |   2 +-
>  drivers/staging/iio/light/{tsl2x7x.c => tsl2772.c} | 691 +++++++++++----------
>  drivers/staging/iio/light/{tsl2x7x.h => tsl2772.h} |  48 +-
>  4 files changed, 372 insertions(+), 371 deletions(-)
>  rename drivers/staging/iio/light/{tsl2x7x.c => tsl2772.c} (66%)
>  rename drivers/staging/iio/light/{tsl2x7x.h => tsl2772.h} (71%)
> 
> diff --git a/drivers/staging/iio/light/Kconfig b/drivers/staging/iio/light/Kconfig
> index aacb0ae58c0e..dfa37386ad2c 100644
> --- a/drivers/staging/iio/light/Kconfig
> +++ b/drivers/staging/iio/light/Kconfig
> @@ -3,7 +3,7 @@
>  #
>  menu "Light sensors"
>  
> -config TSL2x7x
> +config TSL2772
>  	tristate "TAOS TSL/TMD2x71 and TSL/TMD2x72 Family of light and proximity sensors"
>  	depends on I2C
>  	help
> diff --git a/drivers/staging/iio/light/Makefile b/drivers/staging/iio/light/Makefile
> index ab8dc3a3d10b..e7e77a11f02a 100644
> --- a/drivers/staging/iio/light/Makefile
> +++ b/drivers/staging/iio/light/Makefile
> @@ -2,4 +2,4 @@
>  # Makefile for industrial I/O Light sensors
>  #
>  
> -obj-$(CONFIG_TSL2x7x)	+= tsl2x7x.o
> +obj-$(CONFIG_TSL2772)	+= tsl2772.o
> diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2772.c
> similarity index 66%
> rename from drivers/staging/iio/light/tsl2x7x.c
> rename to drivers/staging/iio/light/tsl2772.c
> index f912f4bc61c4..146527e41969 100644
> --- a/drivers/staging/iio/light/tsl2x7x.c
> +++ b/drivers/staging/iio/light/tsl2772.c
> @@ -1,7 +1,8 @@
>  // SPDX-License-Identifier: GPL-2.0+
>  /*
>   * Device driver for monitoring ambient light intensity in (lux) and proximity
> - * detection (prox) within the TAOS TSL2X7X family of devices.
> + * detection (prox) for the TAOS TSL2571, TSL2671, TMD2671, TSL2771, TMD2771,
> + * TSL2572, TSL2672, TMD2672, TSL2772, and TMD2772 devices.
>   *
>   * Copyright (c) 2012, TAOS Corporation.
>   * Copyright (c) 2017-2018 Brian Masney <masneyb@onstation.org>
> @@ -18,92 +19,92 @@
>  #include <linux/iio/events.h>
>  #include <linux/iio/iio.h>
>  #include <linux/iio/sysfs.h>
> -#include "tsl2x7x.h"
> +#include "tsl2772.h"
>  
>  /* Cal defs */
>  #define PROX_STAT_CAL			0
>  #define PROX_STAT_SAMP			1
>  #define MAX_SAMPLES_CAL			200
>  
> -/* TSL2X7X Device ID */
> +/* TSL2772 Device ID */
>  #define TRITON_ID			0x00
>  #define SWORDFISH_ID			0x30
>  #define HALIBUT_ID			0x20
>  
>  /* Lux calculation constants */
> -#define TSL2X7X_LUX_CALC_OVER_FLOW	65535
> +#define TSL2772_LUX_CALC_OVER_FLOW	65535
>  
>  /*
>   * TAOS Register definitions - Note: depending on device, some of these register
>   * are not used and the register address is benign.
>   */
>  
> -/* 2X7X register offsets */
> -#define TSL2X7X_MAX_CONFIG_REG		16
> +/* Register offsets */
> +#define TSL2772_MAX_CONFIG_REG		16
>  
>  /* Device Registers and Masks */
> -#define TSL2X7X_CNTRL			0x00
> -#define TSL2X7X_ALS_TIME		0X01
> -#define TSL2X7X_PRX_TIME		0x02
> -#define TSL2X7X_WAIT_TIME		0x03
> -#define TSL2X7X_ALS_MINTHRESHLO		0X04
> -#define TSL2X7X_ALS_MINTHRESHHI		0X05
> -#define TSL2X7X_ALS_MAXTHRESHLO		0X06
> -#define TSL2X7X_ALS_MAXTHRESHHI		0X07
> -#define TSL2X7X_PRX_MINTHRESHLO		0X08
> -#define TSL2X7X_PRX_MINTHRESHHI		0X09
> -#define TSL2X7X_PRX_MAXTHRESHLO		0X0A
> -#define TSL2X7X_PRX_MAXTHRESHHI		0X0B
> -#define TSL2X7X_PERSISTENCE		0x0C
> -#define TSL2X7X_ALS_PRX_CONFIG		0x0D
> -#define TSL2X7X_PRX_COUNT		0x0E
> -#define TSL2X7X_GAIN			0x0F
> -#define TSL2X7X_NOTUSED			0x10
> -#define TSL2X7X_REVID			0x11
> -#define TSL2X7X_CHIPID			0x12
> -#define TSL2X7X_STATUS			0x13
> -#define TSL2X7X_ALS_CHAN0LO		0x14
> -#define TSL2X7X_ALS_CHAN0HI		0x15
> -#define TSL2X7X_ALS_CHAN1LO		0x16
> -#define TSL2X7X_ALS_CHAN1HI		0x17
> -#define TSL2X7X_PRX_LO			0x18
> -#define TSL2X7X_PRX_HI			0x19
> -
> -/* tsl2X7X cmd reg masks */
> -#define TSL2X7X_CMD_REG			0x80
> -#define TSL2X7X_CMD_SPL_FN		0x60
> -#define TSL2X7X_CMD_REPEAT_PROTO	0x00
> -#define TSL2X7X_CMD_AUTOINC_PROTO	0x20
> -
> -#define TSL2X7X_CMD_PROX_INT_CLR	0X05
> -#define TSL2X7X_CMD_ALS_INT_CLR		0x06
> -#define TSL2X7X_CMD_PROXALS_INT_CLR	0X07
> -
> -/* tsl2X7X cntrl reg masks */
> -#define TSL2X7X_CNTL_ADC_ENBL		0x02
> -#define TSL2X7X_CNTL_PWR_ON		0x01
> -
> -/* tsl2X7X status reg masks */
> -#define TSL2X7X_STA_ADC_VALID		0x01
> -#define TSL2X7X_STA_PRX_VALID		0x02
> -#define TSL2X7X_STA_ADC_PRX_VALID	(TSL2X7X_STA_ADC_VALID | \
> -					 TSL2X7X_STA_PRX_VALID)
> -#define TSL2X7X_STA_ALS_INTR		0x10
> -#define TSL2X7X_STA_PRX_INTR		0x20
> -
> -/* tsl2X7X cntrl reg masks */
> -#define TSL2X7X_CNTL_REG_CLEAR		0x00
> -#define TSL2X7X_CNTL_PROX_INT_ENBL	0X20
> -#define TSL2X7X_CNTL_ALS_INT_ENBL	0X10
> -#define TSL2X7X_CNTL_WAIT_TMR_ENBL	0X08
> -#define TSL2X7X_CNTL_PROX_DET_ENBL	0X04
> -#define TSL2X7X_CNTL_PWRON		0x01
> -#define TSL2X7X_CNTL_ALSPON_ENBL	0x03
> -#define TSL2X7X_CNTL_INTALSPON_ENBL	0x13
> -#define TSL2X7X_CNTL_PROXPON_ENBL	0x0F
> -#define TSL2X7X_CNTL_INTPROXPON_ENBL	0x2F
> -
> -/* TAOS txx2x7x Device family members */
> +#define TSL2772_CNTRL			0x00
> +#define TSL2772_ALS_TIME		0X01
> +#define TSL2772_PRX_TIME		0x02
> +#define TSL2772_WAIT_TIME		0x03
> +#define TSL2772_ALS_MINTHRESHLO		0X04
> +#define TSL2772_ALS_MINTHRESHHI		0X05
> +#define TSL2772_ALS_MAXTHRESHLO		0X06
> +#define TSL2772_ALS_MAXTHRESHHI		0X07
> +#define TSL2772_PRX_MINTHRESHLO		0X08
> +#define TSL2772_PRX_MINTHRESHHI		0X09
> +#define TSL2772_PRX_MAXTHRESHLO		0X0A
> +#define TSL2772_PRX_MAXTHRESHHI		0X0B
> +#define TSL2772_PERSISTENCE		0x0C
> +#define TSL2772_ALS_PRX_CONFIG		0x0D
> +#define TSL2772_PRX_COUNT		0x0E
> +#define TSL2772_GAIN			0x0F
> +#define TSL2772_NOTUSED			0x10
> +#define TSL2772_REVID			0x11
> +#define TSL2772_CHIPID			0x12
> +#define TSL2772_STATUS			0x13
> +#define TSL2772_ALS_CHAN0LO		0x14
> +#define TSL2772_ALS_CHAN0HI		0x15
> +#define TSL2772_ALS_CHAN1LO		0x16
> +#define TSL2772_ALS_CHAN1HI		0x17
> +#define TSL2772_PRX_LO			0x18
> +#define TSL2772_PRX_HI			0x19
> +
> +/* tsl2772 cmd reg masks */
> +#define TSL2772_CMD_REG			0x80
> +#define TSL2772_CMD_SPL_FN		0x60
> +#define TSL2772_CMD_REPEAT_PROTO	0x00
> +#define TSL2772_CMD_AUTOINC_PROTO	0x20
> +
> +#define TSL2772_CMD_PROX_INT_CLR	0X05
> +#define TSL2772_CMD_ALS_INT_CLR		0x06
> +#define TSL2772_CMD_PROXALS_INT_CLR	0X07
> +
> +/* tsl2772 cntrl reg masks */
> +#define TSL2772_CNTL_ADC_ENBL		0x02
> +#define TSL2772_CNTL_PWR_ON		0x01
> +
> +/* tsl2772 status reg masks */
> +#define TSL2772_STA_ADC_VALID		0x01
> +#define TSL2772_STA_PRX_VALID		0x02
> +#define TSL2772_STA_ADC_PRX_VALID	(TSL2772_STA_ADC_VALID | \
> +					 TSL2772_STA_PRX_VALID)
> +#define TSL2772_STA_ALS_INTR		0x10
> +#define TSL2772_STA_PRX_INTR		0x20
> +
> +/* tsl2772 cntrl reg masks */
> +#define TSL2772_CNTL_REG_CLEAR		0x00
> +#define TSL2772_CNTL_PROX_INT_ENBL	0X20
> +#define TSL2772_CNTL_ALS_INT_ENBL	0X10
> +#define TSL2772_CNTL_WAIT_TMR_ENBL	0X08
> +#define TSL2772_CNTL_PROX_DET_ENBL	0X04
> +#define TSL2772_CNTL_PWRON		0x01
> +#define TSL2772_CNTL_ALSPON_ENBL	0x03
> +#define TSL2772_CNTL_INTALSPON_ENBL	0x13
> +#define TSL2772_CNTL_PROXPON_ENBL	0x0F
> +#define TSL2772_CNTL_INTPROXPON_ENBL	0x2F
> +
> +/* TAOS Device family members */
>  enum {
>  	tsl2571,
>  	tsl2671,
> @@ -118,39 +119,39 @@ enum {
>  };
>  
>  enum {
> -	TSL2X7X_CHIP_UNKNOWN = 0,
> -	TSL2X7X_CHIP_WORKING = 1,
> -	TSL2X7X_CHIP_SUSPENDED = 2
> +	TSL2772_CHIP_UNKNOWN = 0,
> +	TSL2772_CHIP_WORKING = 1,
> +	TSL2772_CHIP_SUSPENDED = 2
>  };
>  
>  /* Per-device data */
> -struct tsl2x7x_als_info {
> +struct tsl2772_als_info {
>  	u16 als_ch0;
>  	u16 als_ch1;
>  	u16 lux;
>  };
>  
> -struct tsl2x7x_chip_info {
> +struct tsl2772_chip_info {
>  	int chan_table_elements;
>  	struct iio_chan_spec channel_with_events[4];
>  	struct iio_chan_spec channel_without_events[4];
>  	const struct iio_info *info;
>  };
>  
> -struct tsl2X7X_chip {
> +struct tsl2772_chip {
>  	kernel_ulong_t id;
>  	struct mutex prox_mutex;
>  	struct mutex als_mutex;
>  	struct i2c_client *client;
>  	u16 prox_data;
> -	struct tsl2x7x_als_info als_cur_info;
> -	struct tsl2x7x_settings settings;
> -	struct tsl2X7X_platform_data *pdata;
> +	struct tsl2772_als_info als_cur_info;
> +	struct tsl2772_settings settings;
> +	struct tsl2772_platform_data *pdata;
>  	int als_gain_time_scale;
>  	int als_saturation;
> -	int tsl2x7x_chip_status;
> -	u8 tsl2x7x_config[TSL2X7X_MAX_CONFIG_REG];
> -	const struct tsl2x7x_chip_info	*chip_info;
> +	int tsl2772_chip_status;
> +	u8 tsl2772_config[TSL2772_MAX_CONFIG_REG];
> +	const struct tsl2772_chip_info	*chip_info;
>  	const struct iio_info *info;
>  	s64 event_timestamp;
>  	/*
> @@ -158,7 +159,7 @@ struct tsl2X7X_chip {
>  	 * updates via sysfs.
>  	 * Sized to 9 = max 8 segments + 1 termination segment
>  	 */
> -	struct tsl2x7x_lux tsl2x7x_device_lux[TSL2X7X_MAX_LUX_TABLE_SIZE];
> +	struct tsl2772_lux tsl2772_device_lux[TSL2772_MAX_LUX_TABLE_SIZE];
>  };
>  
>  /*
> @@ -169,31 +170,31 @@ struct tsl2X7X_chip {
>   * The two rows in each table correspond to the Lux1 and Lux2 equations from
>   * the datasheets.
>   */
> -static const struct tsl2x7x_lux tsl2x71_lux_table[TSL2X7X_DEF_LUX_TABLE_SZ] = {
> +static const struct tsl2772_lux tsl2x71_lux_table[TSL2772_DEF_LUX_TABLE_SZ] = {
>  	{ 53000, 106000 },
>  	{ 31800,  53000 },
>  	{ 0,          0 },
>  };
>  
> -static const struct tsl2x7x_lux tmd2x71_lux_table[TSL2X7X_DEF_LUX_TABLE_SZ] = {
> +static const struct tsl2772_lux tmd2x71_lux_table[TSL2772_DEF_LUX_TABLE_SZ] = {
>  	{ 24000,  48000 },
>  	{ 14400,  24000 },
>  	{ 0,          0 },
>  };
>  
> -static const struct tsl2x7x_lux tsl2x72_lux_table[TSL2X7X_DEF_LUX_TABLE_SZ] = {
> +static const struct tsl2772_lux tsl2x72_lux_table[TSL2772_DEF_LUX_TABLE_SZ] = {
>  	{ 60000, 112200 },
>  	{ 37800,  60000 },
>  	{     0,      0 },
>  };
>  
> -static const struct tsl2x7x_lux tmd2x72_lux_table[TSL2X7X_DEF_LUX_TABLE_SZ] = {
> +static const struct tsl2772_lux tmd2x72_lux_table[TSL2772_DEF_LUX_TABLE_SZ] = {
>  	{ 20000,  35000 },
>  	{ 12600,  20000 },
>  	{     0,      0 },
>  };
>  
> -static const struct tsl2x7x_lux *tsl2x7x_default_lux_table_group[] = {
> +static const struct tsl2772_lux *tsl2772_default_lux_table_group[] = {
>  	[tsl2571] =	tsl2x71_lux_table,
>  	[tsl2671] =	tsl2x71_lux_table,
>  	[tmd2671] =	tmd2x71_lux_table,
> @@ -206,7 +207,7 @@ static const struct tsl2x7x_lux *tsl2x7x_default_lux_table_group[] = {
>  	[tmd2772] =	tmd2x72_lux_table,
>  };
>  
> -static const struct tsl2x7x_settings tsl2x7x_default_settings = {
> +static const struct tsl2772_settings tsl2772_default_settings = {
>  	.als_time = 255, /* 2.72 / 2.73 ms */
>  	.als_gain = 0,
>  	.prox_time = 255, /* 2.72 / 2.73 ms */
> @@ -225,30 +226,30 @@ static const struct tsl2x7x_settings tsl2x7x_default_settings = {
>  	.prox_thres_high = 512,
>  	.prox_max_samples_cal = 30,
>  	.prox_pulse_count = 8,
> -	.prox_diode = TSL2X7X_DIODE1,
> -	.prox_power = TSL2X7X_100_mA
> +	.prox_diode = TSL2772_DIODE1,
> +	.prox_power = TSL2772_100_mA
>  };
>  
> -static const s16 tsl2x7x_als_gain[] = {
> +static const s16 tsl2772_als_gain[] = {
>  	1,
>  	8,
>  	16,
>  	120
>  };
>  
> -static const s16 tsl2x7x_prox_gain[] = {
> +static const s16 tsl2772_prox_gain[] = {
>  	1,
>  	2,
>  	4,
>  	8
>  };
>  
> -struct tsl2x7x_int_time {
> +struct tsl2772_int_time {
>  	int increment_us;
>  	char *display_range;
>  };
>  
> -static const struct tsl2x7x_int_time tsl2x7x_int_time[] = {
> +static const struct tsl2772_int_time tsl2772_int_time[] = {
>  	[tsl2571] = { 2720, "0.00272 - 0.696" },
>  	[tsl2671] = { 2720, "0.00272 - 0.696" },
>  	[tmd2671] = { 2720, "0.00272 - 0.696" },
> @@ -283,12 +284,12 @@ static const u8 device_channel_config[] = {
>  	[tmd2772] = ALSPRX2
>  };
>  
> -static int tsl2x7x_read_status(struct tsl2X7X_chip *chip)
> +static int tsl2772_read_status(struct tsl2772_chip *chip)
>  {
>  	int ret;
>  
>  	ret = i2c_smbus_read_byte_data(chip->client,
> -				       TSL2X7X_CMD_REG | TSL2X7X_STATUS);
> +				       TSL2772_CMD_REG | TSL2772_STATUS);
>  	if (ret < 0)
>  		dev_err(&chip->client->dev,
>  			"%s: failed to read STATUS register: %d\n", __func__,
> @@ -297,12 +298,12 @@ static int tsl2x7x_read_status(struct tsl2X7X_chip *chip)
>  	return ret;
>  }
>  
> -static int tsl2x7x_write_control_reg(struct tsl2X7X_chip *chip, u8 data)
> +static int tsl2772_write_control_reg(struct tsl2772_chip *chip, u8 data)
>  {
>  	int ret;
>  
>  	ret = i2c_smbus_write_byte_data(chip->client,
> -					TSL2X7X_CMD_REG | TSL2X7X_CNTRL, data);
> +					TSL2772_CMD_REG | TSL2772_CNTRL, data);
>  	if (ret < 0) {
>  		dev_err(&chip->client->dev,
>  			"%s: failed to write to control register %x: %d\n",
> @@ -312,14 +313,14 @@ static int tsl2x7x_write_control_reg(struct tsl2X7X_chip *chip, u8 data)
>  	return ret;
>  }
>  
> -static int tsl2x7x_read_autoinc_regs(struct tsl2X7X_chip *chip, int lower_reg,
> +static int tsl2772_read_autoinc_regs(struct tsl2772_chip *chip, int lower_reg,
>  				     int upper_reg)
>  {
>  	u8 buf[2];
>  	int ret;
>  
>  	ret = i2c_smbus_write_byte(chip->client,
> -				   TSL2X7X_CMD_REG | TSL2X7X_CMD_AUTOINC_PROTO |
> +				   TSL2772_CMD_REG | TSL2772_CMD_AUTOINC_PROTO |
>  				   lower_reg);
>  	if (ret < 0) {
>  		dev_err(&chip->client->dev,
> @@ -329,7 +330,7 @@ static int tsl2x7x_read_autoinc_regs(struct tsl2X7X_chip *chip, int lower_reg,
>  	}
>  
>  	ret = i2c_smbus_read_byte_data(chip->client,
> -				       TSL2X7X_CMD_REG | lower_reg);
> +				       TSL2772_CMD_REG | lower_reg);
>  	if (ret < 0) {
>  		dev_err(&chip->client->dev,
>  			"%s: failed to read from register %x: %d\n", __func__,
> @@ -339,7 +340,7 @@ static int tsl2x7x_read_autoinc_regs(struct tsl2X7X_chip *chip, int lower_reg,
>  	buf[0] = ret;
>  
>  	ret = i2c_smbus_read_byte_data(chip->client,
> -				       TSL2X7X_CMD_REG | upper_reg);
> +				       TSL2772_CMD_REG | upper_reg);
>  	if (ret < 0) {
>  		dev_err(&chip->client->dev,
>  			"%s: failed to read from register %x: %d\n", __func__,
> @@ -349,7 +350,7 @@ static int tsl2x7x_read_autoinc_regs(struct tsl2X7X_chip *chip, int lower_reg,
>  	buf[1] = ret;
>  
>  	ret = i2c_smbus_write_byte(chip->client,
> -				   TSL2X7X_CMD_REG | TSL2X7X_CMD_REPEAT_PROTO |
> +				   TSL2772_CMD_REG | TSL2772_CMD_REPEAT_PROTO |
>  				   lower_reg);
>  	if (ret < 0) {
>  		dev_err(&chip->client->dev,
> @@ -362,7 +363,7 @@ static int tsl2x7x_read_autoinc_regs(struct tsl2X7X_chip *chip, int lower_reg,
>  }
>  
>  /**
> - * tsl2x7x_get_lux() - Reads and calculates current lux value.
> + * tsl2772_get_lux() - Reads and calculates current lux value.
>   * @indio_dev:	pointer to IIO device
>   *
>   * The raw ch0 and ch1 values of the ambient light sensed in the last
> @@ -372,47 +373,47 @@ static int tsl2x7x_read_autoinc_regs(struct tsl2X7X_chip *chip, int lower_reg,
>   * coefficients. A lux gain trim is applied to each lux equation, and then the
>   * maximum lux within the interval 0..65535 is selected.
>   */
> -static int tsl2x7x_get_lux(struct iio_dev *indio_dev)
> +static int tsl2772_get_lux(struct iio_dev *indio_dev)
>  {
> -	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
> -	struct tsl2x7x_lux *p;
> +	struct tsl2772_chip *chip = iio_priv(indio_dev);
> +	struct tsl2772_lux *p;
>  	int max_lux, ret;
>  	bool overflow;
>  
>  	mutex_lock(&chip->als_mutex);
>  
> -	if (chip->tsl2x7x_chip_status != TSL2X7X_CHIP_WORKING) {
> +	if (chip->tsl2772_chip_status != TSL2772_CHIP_WORKING) {
>  		dev_err(&chip->client->dev, "%s: device is not enabled\n",
>  			__func__);
>  		ret = -EBUSY;
>  		goto out_unlock;
>  	}
>  
> -	ret = tsl2x7x_read_status(chip);
> +	ret = tsl2772_read_status(chip);
>  	if (ret < 0)
>  		goto out_unlock;
>  
> -	if (!(ret & TSL2X7X_STA_ADC_VALID)) {
> +	if (!(ret & TSL2772_STA_ADC_VALID)) {
>  		dev_err(&chip->client->dev,
>  			"%s: data not valid yet\n", __func__);
>  		ret = chip->als_cur_info.lux; /* return LAST VALUE */
>  		goto out_unlock;
>  	}
>  
> -	ret = tsl2x7x_read_autoinc_regs(chip, TSL2X7X_ALS_CHAN0LO,
> -					TSL2X7X_ALS_CHAN0HI);
> +	ret = tsl2772_read_autoinc_regs(chip, TSL2772_ALS_CHAN0LO,
> +					TSL2772_ALS_CHAN0HI);
>  	if (ret < 0)
>  		goto out_unlock;
>  	chip->als_cur_info.als_ch0 = ret;
>  
> -	ret = tsl2x7x_read_autoinc_regs(chip, TSL2X7X_ALS_CHAN1LO,
> -					TSL2X7X_ALS_CHAN1HI);
> +	ret = tsl2772_read_autoinc_regs(chip, TSL2772_ALS_CHAN1LO,
> +					TSL2772_ALS_CHAN1HI);
>  	if (ret < 0)
>  		goto out_unlock;
>  	chip->als_cur_info.als_ch1 = ret;
>  
>  	if (chip->als_cur_info.als_ch0 >= chip->als_saturation) {
> -		max_lux = TSL2X7X_LUX_CALC_OVER_FLOW;
> +		max_lux = TSL2772_LUX_CALC_OVER_FLOW;
>  		goto update_struct_with_max_lux;
>  	}
>  
> @@ -424,7 +425,7 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev)
>  
>  	max_lux = 0;
>  	overflow = false;
> -	for (p = (struct tsl2x7x_lux *)chip->tsl2x7x_device_lux; p->ch0 != 0;
> +	for (p = (struct tsl2772_lux *)chip->tsl2772_device_lux; p->ch0 != 0;
>  	     p++) {
>  		int lux;
>  
> @@ -440,7 +441,7 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev)
>  		 */
>  		lux = (lux * chip->settings.als_gain_trim) / 1000;
>  
> -		if (lux > TSL2X7X_LUX_CALC_OVER_FLOW) {
> +		if (lux > TSL2772_LUX_CALC_OVER_FLOW) {
>  			overflow = true;
>  			continue;
>  		}
> @@ -449,7 +450,7 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev)
>  	}
>  
>  	if (overflow && max_lux == 0)
> -		max_lux = TSL2X7X_LUX_CALC_OVER_FLOW;
> +		max_lux = TSL2772_LUX_CALC_OVER_FLOW;
>  
>  update_struct_with_max_lux:
>  	chip->als_cur_info.lux = max_lux;
> @@ -462,19 +463,19 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev)
>  }
>  
>  /**
> - * tsl2x7x_get_prox() - Reads proximity data registers and updates
> + * tsl2772_get_prox() - Reads proximity data registers and updates
>   *                      chip->prox_data.
>   *
>   * @indio_dev:	pointer to IIO device
>   */
> -static int tsl2x7x_get_prox(struct iio_dev *indio_dev)
> +static int tsl2772_get_prox(struct iio_dev *indio_dev)
>  {
> -	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
> +	struct tsl2772_chip *chip = iio_priv(indio_dev);
>  	int ret;
>  
>  	mutex_lock(&chip->prox_mutex);
>  
> -	ret = tsl2x7x_read_status(chip);
> +	ret = tsl2772_read_status(chip);
>  	if (ret < 0)
>  		goto prox_poll_err;
>  
> @@ -484,7 +485,7 @@ static int tsl2x7x_get_prox(struct iio_dev *indio_dev)
>  	case tmd2671:
>  	case tsl2771:
>  	case tmd2771:
> -		if (!(ret & TSL2X7X_STA_ADC_VALID)) {
> +		if (!(ret & TSL2772_STA_ADC_VALID)) {
>  			ret = -EINVAL;
>  			goto prox_poll_err;
>  		}
> @@ -494,14 +495,14 @@ static int tsl2x7x_get_prox(struct iio_dev *indio_dev)
>  	case tmd2672:
>  	case tsl2772:
>  	case tmd2772:
> -		if (!(ret & TSL2X7X_STA_PRX_VALID)) {
> +		if (!(ret & TSL2772_STA_PRX_VALID)) {
>  			ret = -EINVAL;
>  			goto prox_poll_err;
>  		}
>  		break;
>  	}
>  
> -	ret = tsl2x7x_read_autoinc_regs(chip, TSL2X7X_PRX_LO, TSL2X7X_PRX_HI);
> +	ret = tsl2772_read_autoinc_regs(chip, TSL2772_PRX_LO, TSL2772_PRX_HI);
>  	if (ret < 0)
>  		goto prox_poll_err;
>  	chip->prox_data = ret;
> @@ -513,46 +514,46 @@ static int tsl2x7x_get_prox(struct iio_dev *indio_dev)
>  }
>  
>  /**
> - * tsl2x7x_defaults() - Populates the device nominal operating parameters
> + * tsl2772_defaults() - Populates the device nominal operating parameters
>   *                      with those provided by a 'platform' data struct or
>   *                      with prefined defaults.
>   *
>   * @chip:               pointer to device structure.
>   */
> -static void tsl2x7x_defaults(struct tsl2X7X_chip *chip)
> +static void tsl2772_defaults(struct tsl2772_chip *chip)
>  {
>  	/* If Operational settings defined elsewhere.. */
>  	if (chip->pdata && chip->pdata->platform_default_settings)
>  		memcpy(&chip->settings, chip->pdata->platform_default_settings,
> -		       sizeof(tsl2x7x_default_settings));
> +		       sizeof(tsl2772_default_settings));
>  	else
> -		memcpy(&chip->settings, &tsl2x7x_default_settings,
> -		       sizeof(tsl2x7x_default_settings));
> +		memcpy(&chip->settings, &tsl2772_default_settings,
> +		       sizeof(tsl2772_default_settings));
>  
>  	/* Load up the proper lux table. */
>  	if (chip->pdata && chip->pdata->platform_lux_table[0].ch0 != 0)
> -		memcpy(chip->tsl2x7x_device_lux,
> +		memcpy(chip->tsl2772_device_lux,
>  		       chip->pdata->platform_lux_table,
>  		       sizeof(chip->pdata->platform_lux_table));
>  	else
> -		memcpy(chip->tsl2x7x_device_lux,
> -		       tsl2x7x_default_lux_table_group[chip->id],
> -		       TSL2X7X_DEFAULT_TABLE_BYTES);
> +		memcpy(chip->tsl2772_device_lux,
> +		       tsl2772_default_lux_table_group[chip->id],
> +		       TSL2772_DEFAULT_TABLE_BYTES);
>  }
>  
>  /**
> - * tsl2x7x_als_calibrate() -	Obtain single reading and calculate
> + * tsl2772_als_calibrate() -	Obtain single reading and calculate
>   *                              the als_gain_trim.
>   *
>   * @indio_dev:	pointer to IIO device
>   */
> -static int tsl2x7x_als_calibrate(struct iio_dev *indio_dev)
> +static int tsl2772_als_calibrate(struct iio_dev *indio_dev)
>  {
> -	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
> +	struct tsl2772_chip *chip = iio_priv(indio_dev);
>  	int ret, lux_val;
>  
>  	ret = i2c_smbus_read_byte_data(chip->client,
> -				       TSL2X7X_CMD_REG | TSL2X7X_CNTRL);
> +				       TSL2772_CMD_REG | TSL2772_CNTRL);
>  	if (ret < 0) {
>  		dev_err(&chip->client->dev,
>  			"%s: failed to read from the CNTRL register\n",
> @@ -560,20 +561,20 @@ static int tsl2x7x_als_calibrate(struct iio_dev *indio_dev)
>  		return ret;
>  	}
>  
> -	if ((ret & (TSL2X7X_CNTL_ADC_ENBL | TSL2X7X_CNTL_PWR_ON))
> -			!= (TSL2X7X_CNTL_ADC_ENBL | TSL2X7X_CNTL_PWR_ON)) {
> +	if ((ret & (TSL2772_CNTL_ADC_ENBL | TSL2772_CNTL_PWR_ON))
> +			!= (TSL2772_CNTL_ADC_ENBL | TSL2772_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 & TSL2X7X_STA_ADC_VALID) != TSL2X7X_STA_ADC_VALID) {
> +	} else if ((ret & TSL2772_STA_ADC_VALID) != TSL2772_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 = tsl2x7x_get_lux(indio_dev);
> +	lux_val = tsl2772_get_lux(indio_dev);
>  	if (lux_val < 0) {
>  		dev_err(&chip->client->dev,
>  			"%s: failed to get lux\n", __func__);
> @@ -590,51 +591,51 @@ static int tsl2x7x_als_calibrate(struct iio_dev *indio_dev)
>  	return ret;
>  }
>  
> -static int tsl2x7x_chip_on(struct iio_dev *indio_dev)
> +static int tsl2772_chip_on(struct iio_dev *indio_dev)
>  {
> -	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
> +	struct tsl2772_chip *chip = iio_priv(indio_dev);
>  	int ret, i, als_count, als_time_us;
>  	u8 *dev_reg, reg_val;
>  
>  	/* Non calculated parameters */
> -	chip->tsl2x7x_config[TSL2X7X_ALS_TIME] = chip->settings.als_time;
> -	chip->tsl2x7x_config[TSL2X7X_PRX_TIME] = chip->settings.prox_time;
> -	chip->tsl2x7x_config[TSL2X7X_WAIT_TIME] = chip->settings.wait_time;
> -	chip->tsl2x7x_config[TSL2X7X_ALS_PRX_CONFIG] =
> +	chip->tsl2772_config[TSL2772_ALS_TIME] = chip->settings.als_time;
> +	chip->tsl2772_config[TSL2772_PRX_TIME] = chip->settings.prox_time;
> +	chip->tsl2772_config[TSL2772_WAIT_TIME] = chip->settings.wait_time;
> +	chip->tsl2772_config[TSL2772_ALS_PRX_CONFIG] =
>  		chip->settings.als_prox_config;
>  
> -	chip->tsl2x7x_config[TSL2X7X_ALS_MINTHRESHLO] =
> +	chip->tsl2772_config[TSL2772_ALS_MINTHRESHLO] =
>  		(chip->settings.als_thresh_low) & 0xFF;
> -	chip->tsl2x7x_config[TSL2X7X_ALS_MINTHRESHHI] =
> +	chip->tsl2772_config[TSL2772_ALS_MINTHRESHHI] =
>  		(chip->settings.als_thresh_low >> 8) & 0xFF;
> -	chip->tsl2x7x_config[TSL2X7X_ALS_MAXTHRESHLO] =
> +	chip->tsl2772_config[TSL2772_ALS_MAXTHRESHLO] =
>  		(chip->settings.als_thresh_high) & 0xFF;
> -	chip->tsl2x7x_config[TSL2X7X_ALS_MAXTHRESHHI] =
> +	chip->tsl2772_config[TSL2772_ALS_MAXTHRESHHI] =
>  		(chip->settings.als_thresh_high >> 8) & 0xFF;
> -	chip->tsl2x7x_config[TSL2X7X_PERSISTENCE] =
> +	chip->tsl2772_config[TSL2772_PERSISTENCE] =
>  		(chip->settings.prox_persistence & 0xFF) << 4 |
>  		(chip->settings.als_persistence & 0xFF);
>  
> -	chip->tsl2x7x_config[TSL2X7X_PRX_COUNT] =
> +	chip->tsl2772_config[TSL2772_PRX_COUNT] =
>  			chip->settings.prox_pulse_count;
> -	chip->tsl2x7x_config[TSL2X7X_PRX_MINTHRESHLO] =
> +	chip->tsl2772_config[TSL2772_PRX_MINTHRESHLO] =
>  			(chip->settings.prox_thres_low) & 0xFF;
> -	chip->tsl2x7x_config[TSL2X7X_PRX_MINTHRESHHI] =
> +	chip->tsl2772_config[TSL2772_PRX_MINTHRESHHI] =
>  			(chip->settings.prox_thres_low >> 8) & 0xFF;
> -	chip->tsl2x7x_config[TSL2X7X_PRX_MAXTHRESHLO] =
> +	chip->tsl2772_config[TSL2772_PRX_MAXTHRESHLO] =
>  			(chip->settings.prox_thres_high) & 0xFF;
> -	chip->tsl2x7x_config[TSL2X7X_PRX_MAXTHRESHHI] =
> +	chip->tsl2772_config[TSL2772_PRX_MAXTHRESHHI] =
>  			(chip->settings.prox_thres_high >> 8) & 0xFF;
>  
>  	/* and make sure we're not already on */
> -	if (chip->tsl2x7x_chip_status == TSL2X7X_CHIP_WORKING) {
> +	if (chip->tsl2772_chip_status == TSL2772_CHIP_WORKING) {
>  		/* if forcing a register update - turn off, then on */
>  		dev_info(&chip->client->dev, "device is already enabled\n");
>  		return -EINVAL;
>  	}
>  
> -	/* Set the gain based on tsl2x7x_settings struct */
> -	chip->tsl2x7x_config[TSL2X7X_GAIN] =
> +	/* Set the gain based on tsl2772_settings struct */
> +	chip->tsl2772_config[TSL2772_GAIN] =
>  		(chip->settings.als_gain & 0xFF) |
>  		((chip->settings.prox_gain & 0xFF) << 2) |
>  		(chip->settings.prox_diode << 4) |
> @@ -642,16 +643,16 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev)
>  
>  	/* set chip time scaling and saturation */
>  	als_count = 256 - chip->settings.als_time;
> -	als_time_us = als_count * tsl2x7x_int_time[chip->id].increment_us;
> +	als_time_us = als_count * tsl2772_int_time[chip->id].increment_us;
>  	chip->als_saturation = als_count * 768; /* 75% of full scale */
>  	chip->als_gain_time_scale = als_time_us *
> -		tsl2x7x_als_gain[chip->settings.als_gain];
> +		tsl2772_als_gain[chip->settings.als_gain];
>  
>  	/*
> -	 * TSL2X7X Specific power-on / adc enable sequence
> +	 * TSL2772 Specific power-on / adc enable sequence
>  	 * Power on the device 1st.
>  	 */
> -	ret = tsl2x7x_write_control_reg(chip, TSL2X7X_CNTL_PWR_ON);
> +	ret = tsl2772_write_control_reg(chip, TSL2772_CNTL_PWR_ON);
>  	if (ret < 0)
>  		return ret;
>  
> @@ -659,9 +660,9 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev)
>  	 * Use the following shadow copy for our delay before enabling ADC.
>  	 * Write all the registers.
>  	 */
> -	for (i = 0, dev_reg = chip->tsl2x7x_config;
> -			i < TSL2X7X_MAX_CONFIG_REG; i++) {
> -		int reg = TSL2X7X_CMD_REG + i;
> +	for (i = 0, dev_reg = chip->tsl2772_config;
> +			i < TSL2772_MAX_CONFIG_REG; i++) {
> +		int reg = TSL2772_CMD_REG + i;
>  
>  		ret = i2c_smbus_write_byte_data(chip->client, reg,
>  						*dev_reg++);
> @@ -676,20 +677,20 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev)
>  	/* Power-on settling time */
>  	usleep_range(3000, 3500);
>  
> -	reg_val = TSL2X7X_CNTL_PWR_ON | TSL2X7X_CNTL_ADC_ENBL |
> -		  TSL2X7X_CNTL_PROX_DET_ENBL;
> +	reg_val = TSL2772_CNTL_PWR_ON | TSL2772_CNTL_ADC_ENBL |
> +		  TSL2772_CNTL_PROX_DET_ENBL;
>  	if (chip->settings.als_interrupt_en)
> -		reg_val |= TSL2X7X_CNTL_ALS_INT_ENBL;
> +		reg_val |= TSL2772_CNTL_ALS_INT_ENBL;
>  	if (chip->settings.prox_interrupt_en)
> -		reg_val |= TSL2X7X_CNTL_PROX_INT_ENBL;
> +		reg_val |= TSL2772_CNTL_PROX_INT_ENBL;
>  
> -	ret = tsl2x7x_write_control_reg(chip, reg_val);
> +	ret = tsl2772_write_control_reg(chip, reg_val);
>  	if (ret < 0)
>  		return ret;
>  
>  	ret = i2c_smbus_write_byte(chip->client,
> -				   TSL2X7X_CMD_REG | TSL2X7X_CMD_SPL_FN |
> -				   TSL2X7X_CMD_PROXALS_INT_CLR);
> +				   TSL2772_CMD_REG | TSL2772_CMD_SPL_FN |
> +				   TSL2772_CMD_PROXALS_INT_CLR);
>  	if (ret < 0) {
>  		dev_err(&chip->client->dev,
>  			"%s: failed to clear interrupt status: %d\n",
> @@ -697,22 +698,22 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev)
>  		return ret;
>  	}
>  
> -	chip->tsl2x7x_chip_status = TSL2X7X_CHIP_WORKING;
> +	chip->tsl2772_chip_status = TSL2772_CHIP_WORKING;
>  
>  	return ret;
>  }
>  
> -static int tsl2x7x_chip_off(struct iio_dev *indio_dev)
> +static int tsl2772_chip_off(struct iio_dev *indio_dev)
>  {
> -	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
> +	struct tsl2772_chip *chip = iio_priv(indio_dev);
>  
>  	/* turn device off */
> -	chip->tsl2x7x_chip_status = TSL2X7X_CHIP_SUSPENDED;
> -	return tsl2x7x_write_control_reg(chip, 0x00);
> +	chip->tsl2772_chip_status = TSL2772_CHIP_SUSPENDED;
> +	return tsl2772_write_control_reg(chip, 0x00);
>  }
>  
>  /**
> - * tsl2x7x_invoke_change - power cycle the device to implement the user
> + * tsl2772_invoke_change - power cycle the device to implement the user
>   *                         parameters
>   * @indio_dev:	pointer to IIO device
>   *
> @@ -720,22 +721,22 @@ static int tsl2x7x_chip_off(struct iio_dev *indio_dev)
>   * (On/Off), cycle device to implement updated parameter, put device back into
>   * proper state, and unlock resource.
>   */
> -static int tsl2x7x_invoke_change(struct iio_dev *indio_dev)
> +static int tsl2772_invoke_change(struct iio_dev *indio_dev)
>  {
> -	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
> -	int device_status = chip->tsl2x7x_chip_status;
> +	struct tsl2772_chip *chip = iio_priv(indio_dev);
> +	int device_status = chip->tsl2772_chip_status;
>  	int ret;
>  
>  	mutex_lock(&chip->als_mutex);
>  	mutex_lock(&chip->prox_mutex);
>  
> -	if (device_status == TSL2X7X_CHIP_WORKING) {
> -		ret = tsl2x7x_chip_off(indio_dev);
> +	if (device_status == TSL2772_CHIP_WORKING) {
> +		ret = tsl2772_chip_off(indio_dev);
>  		if (ret < 0)
>  			goto unlock;
>  	}
>  
> -	ret = tsl2x7x_chip_on(indio_dev);
> +	ret = tsl2772_chip_on(indio_dev);
>  
>  unlock:
>  	mutex_unlock(&chip->prox_mutex);
> @@ -744,9 +745,9 @@ static int tsl2x7x_invoke_change(struct iio_dev *indio_dev)
>  	return ret;
>  }
>  
> -static int tsl2x7x_prox_cal(struct iio_dev *indio_dev)
> +static int tsl2772_prox_cal(struct iio_dev *indio_dev)
>  {
> -	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
> +	struct tsl2772_chip *chip = iio_priv(indio_dev);
>  	int prox_history[MAX_SAMPLES_CAL + 1];
>  	int i, ret, mean, max, sample_sum;
>  
> @@ -756,7 +757,7 @@ static int tsl2x7x_prox_cal(struct iio_dev *indio_dev)
>  
>  	for (i = 0; i < chip->settings.prox_max_samples_cal; i++) {
>  		usleep_range(15000, 17500);
> -		ret = tsl2x7x_get_prox(indio_dev);
> +		ret = tsl2772_get_prox(indio_dev);
>  		if (ret < 0)
>  			return ret;
>  
> @@ -773,7 +774,7 @@ static int tsl2x7x_prox_cal(struct iio_dev *indio_dev)
>  
>  	chip->settings.prox_thres_high = (max << 1) - mean;
>  
> -	return tsl2x7x_invoke_change(indio_dev);
> +	return tsl2772_invoke_change(indio_dev);
>  }
>  
>  static IIO_CONST_ATTR(in_intensity0_calibscale_available, "1 8 16 120");
> @@ -785,17 +786,17 @@ in_intensity0_integration_time_available_show(struct device *dev,
>  					      struct device_attribute *attr,
>  					      char *buf)
>  {
> -	struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev));
> +	struct tsl2772_chip *chip = iio_priv(dev_to_iio_dev(dev));
>  
>  	return snprintf(buf, PAGE_SIZE, "%s\n",
> -			tsl2x7x_int_time[chip->id].display_range);
> +			tsl2772_int_time[chip->id].display_range);
>  }
>  
>  static ssize_t in_illuminance0_target_input_show(struct device *dev,
>  						 struct device_attribute *attr,
>  						 char *buf)
>  {
> -	struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev));
> +	struct tsl2772_chip *chip = iio_priv(dev_to_iio_dev(dev));
>  
>  	return snprintf(buf, PAGE_SIZE, "%d\n", chip->settings.als_cal_target);
>  }
> @@ -805,7 +806,7 @@ static ssize_t in_illuminance0_target_input_store(struct device *dev,
>  						  const char *buf, size_t len)
>  {
>  	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> -	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
> +	struct tsl2772_chip *chip = iio_priv(indio_dev);
>  	u16 value;
>  	int ret;
>  
> @@ -813,7 +814,7 @@ static ssize_t in_illuminance0_target_input_store(struct device *dev,
>  		return -EINVAL;
>  
>  	chip->settings.als_cal_target = value;
> -	ret = tsl2x7x_invoke_change(indio_dev);
> +	ret = tsl2772_invoke_change(indio_dev);
>  	if (ret < 0)
>  		return ret;
>  
> @@ -831,11 +832,11 @@ static ssize_t in_illuminance0_calibrate_store(struct device *dev,
>  	if (kstrtobool(buf, &value) || !value)
>  		return -EINVAL;
>  
> -	ret = tsl2x7x_als_calibrate(indio_dev);
> +	ret = tsl2772_als_calibrate(indio_dev);
>  	if (ret < 0)
>  		return ret;
>  
> -	ret = tsl2x7x_invoke_change(indio_dev);
> +	ret = tsl2772_invoke_change(indio_dev);
>  	if (ret < 0)
>  		return ret;
>  
> @@ -846,15 +847,15 @@ static ssize_t in_illuminance0_lux_table_show(struct device *dev,
>  					      struct device_attribute *attr,
>  					      char *buf)
>  {
> -	struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev));
> +	struct tsl2772_chip *chip = iio_priv(dev_to_iio_dev(dev));
>  	int i = 0;
>  	int offset = 0;
>  
> -	while (i < TSL2X7X_MAX_LUX_TABLE_SIZE) {
> +	while (i < TSL2772_MAX_LUX_TABLE_SIZE) {
>  		offset += snprintf(buf + offset, PAGE_SIZE, "%u,%u,",
> -			chip->tsl2x7x_device_lux[i].ch0,
> -			chip->tsl2x7x_device_lux[i].ch1);
> -		if (chip->tsl2x7x_device_lux[i].ch0 == 0) {
> +			chip->tsl2772_device_lux[i].ch0,
> +			chip->tsl2772_device_lux[i].ch1);
> +		if (chip->tsl2772_device_lux[i].ch0 == 0) {
>  			/*
>  			 * We just printed the first "0" entry.
>  			 * Now get rid of the extra "," and break.
> @@ -874,8 +875,8 @@ static ssize_t in_illuminance0_lux_table_store(struct device *dev,
>  					       const char *buf, size_t len)
>  {
>  	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> -	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
> -	int value[ARRAY_SIZE(chip->tsl2x7x_device_lux) * 2 + 1];
> +	struct tsl2772_chip *chip = iio_priv(indio_dev);
> +	int value[ARRAY_SIZE(chip->tsl2772_device_lux) * 2 + 1];
>  	int n, ret;
>  
>  	get_options(buf, ARRAY_SIZE(value), value);
> @@ -888,23 +889,23 @@ static ssize_t in_illuminance0_lux_table_store(struct device *dev,
>  	 */
>  	n = value[0];
>  	if ((n % 2) || n < 4 ||
> -	    n > ((ARRAY_SIZE(chip->tsl2x7x_device_lux) - 1) * 2))
> +	    n > ((ARRAY_SIZE(chip->tsl2772_device_lux) - 1) * 2))
>  		return -EINVAL;
>  
>  	if ((value[(n - 1)] | value[n]) != 0)
>  		return -EINVAL;
>  
> -	if (chip->tsl2x7x_chip_status == TSL2X7X_CHIP_WORKING) {
> -		ret = tsl2x7x_chip_off(indio_dev);
> +	if (chip->tsl2772_chip_status == TSL2772_CHIP_WORKING) {
> +		ret = tsl2772_chip_off(indio_dev);
>  		if (ret < 0)
>  			return ret;
>  	}
>  
>  	/* Zero out the table */
> -	memset(chip->tsl2x7x_device_lux, 0, sizeof(chip->tsl2x7x_device_lux));
> -	memcpy(chip->tsl2x7x_device_lux, &value[1], (value[0] * 4));
> +	memset(chip->tsl2772_device_lux, 0, sizeof(chip->tsl2772_device_lux));
> +	memcpy(chip->tsl2772_device_lux, &value[1], (value[0] * 4));
>  
> -	ret = tsl2x7x_invoke_change(indio_dev);
> +	ret = tsl2772_invoke_change(indio_dev);
>  	if (ret < 0)
>  		return ret;
>  
> @@ -922,23 +923,23 @@ static ssize_t in_proximity0_calibrate_store(struct device *dev,
>  	if (kstrtobool(buf, &value) || !value)
>  		return -EINVAL;
>  
> -	ret = tsl2x7x_prox_cal(indio_dev);
> +	ret = tsl2772_prox_cal(indio_dev);
>  	if (ret < 0)
>  		return ret;
>  
> -	ret = tsl2x7x_invoke_change(indio_dev);
> +	ret = tsl2772_invoke_change(indio_dev);
>  	if (ret < 0)
>  		return ret;
>  
>  	return len;
>  }
>  
> -static int tsl2x7x_read_interrupt_config(struct iio_dev *indio_dev,
> +static int tsl2772_read_interrupt_config(struct iio_dev *indio_dev,
>  					 const struct iio_chan_spec *chan,
>  					 enum iio_event_type type,
>  					 enum iio_event_direction dir)
>  {
> -	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
> +	struct tsl2772_chip *chip = iio_priv(indio_dev);
>  
>  	if (chan->type == IIO_INTENSITY)
>  		return chip->settings.als_interrupt_en;
> @@ -946,30 +947,30 @@ static int tsl2x7x_read_interrupt_config(struct iio_dev *indio_dev,
>  		return chip->settings.prox_interrupt_en;
>  }
>  
> -static int tsl2x7x_write_interrupt_config(struct iio_dev *indio_dev,
> +static int tsl2772_write_interrupt_config(struct iio_dev *indio_dev,
>  					  const struct iio_chan_spec *chan,
>  					  enum iio_event_type type,
>  					  enum iio_event_direction dir,
>  					  int val)
>  {
> -	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
> +	struct tsl2772_chip *chip = iio_priv(indio_dev);
>  
>  	if (chan->type == IIO_INTENSITY)
>  		chip->settings.als_interrupt_en = val ? true : false;
>  	else
>  		chip->settings.prox_interrupt_en = val ? true : false;
>  
> -	return tsl2x7x_invoke_change(indio_dev);
> +	return tsl2772_invoke_change(indio_dev);
>  }
>  
> -static int tsl2x7x_write_event_value(struct iio_dev *indio_dev,
> +static int tsl2772_write_event_value(struct iio_dev *indio_dev,
>  				     const struct iio_chan_spec *chan,
>  				     enum iio_event_type type,
>  				     enum iio_event_direction dir,
>  				     enum iio_event_info info,
>  				     int val, int val2)
>  {
> -	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
> +	struct tsl2772_chip *chip = iio_priv(indio_dev);
>  	int ret = -EINVAL, count, persistence;
>  	u8 time;
>  
> @@ -1011,7 +1012,7 @@ static int tsl2x7x_write_event_value(struct iio_dev *indio_dev,
>  
>  		count = 256 - time;
>  		persistence = ((val * 1000000) + val2) /
> -			(count * tsl2x7x_int_time[chip->id].increment_us);
> +			(count * tsl2772_int_time[chip->id].increment_us);
>  
>  		if (chan->type == IIO_INTENSITY) {
>  			/* ALS filter values are 1, 2, 3, 5, 10, 15, ..., 60 */
> @@ -1032,17 +1033,17 @@ static int tsl2x7x_write_event_value(struct iio_dev *indio_dev,
>  	if (ret < 0)
>  		return ret;
>  
> -	return tsl2x7x_invoke_change(indio_dev);
> +	return tsl2772_invoke_change(indio_dev);
>  }
>  
> -static int tsl2x7x_read_event_value(struct iio_dev *indio_dev,
> +static int tsl2772_read_event_value(struct iio_dev *indio_dev,
>  				    const struct iio_chan_spec *chan,
>  				    enum iio_event_type type,
>  				    enum iio_event_direction dir,
>  				    enum iio_event_info info,
>  				    int *val, int *val2)
>  {
> -	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
> +	struct tsl2772_chip *chip = iio_priv(indio_dev);
>  	int ret = -EINVAL, filter_delay, persistence;
>  	u8 time;
>  
> @@ -1090,7 +1091,7 @@ static int tsl2x7x_read_event_value(struct iio_dev *indio_dev,
>  		}
>  
>  		filter_delay = persistence * (256 - time) *
> -			tsl2x7x_int_time[chip->id].increment_us;
> +			tsl2772_int_time[chip->id].increment_us;
>  
>  		*val = filter_delay / 1000000;
>  		*val2 = filter_delay % 1000000;
> @@ -1103,20 +1104,20 @@ static int tsl2x7x_read_event_value(struct iio_dev *indio_dev,
>  	return ret;
>  }
>  
> -static int tsl2x7x_read_raw(struct iio_dev *indio_dev,
> +static int tsl2772_read_raw(struct iio_dev *indio_dev,
>  			    struct iio_chan_spec const *chan,
>  			    int *val,
>  			    int *val2,
>  			    long mask)
>  {
> -	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
> +	struct tsl2772_chip *chip = iio_priv(indio_dev);
>  	int ret = -EINVAL;
>  
>  	switch (mask) {
>  	case IIO_CHAN_INFO_PROCESSED:
>  		switch (chan->type) {
>  		case IIO_LIGHT:
> -			tsl2x7x_get_lux(indio_dev);
> +			tsl2772_get_lux(indio_dev);
>  			*val = chip->als_cur_info.lux;
>  			ret = IIO_VAL_INT;
>  			break;
> @@ -1127,7 +1128,7 @@ static int tsl2x7x_read_raw(struct iio_dev *indio_dev,
>  	case IIO_CHAN_INFO_RAW:
>  		switch (chan->type) {
>  		case IIO_INTENSITY:
> -			tsl2x7x_get_lux(indio_dev);
> +			tsl2772_get_lux(indio_dev);
>  			if (chan->channel == 0)
>  				*val = chip->als_cur_info.als_ch0;
>  			else
> @@ -1135,7 +1136,7 @@ static int tsl2x7x_read_raw(struct iio_dev *indio_dev,
>  			ret = IIO_VAL_INT;
>  			break;
>  		case IIO_PROXIMITY:
> -			tsl2x7x_get_prox(indio_dev);
> +			tsl2772_get_prox(indio_dev);
>  			*val = chip->prox_data;
>  			ret = IIO_VAL_INT;
>  			break;
> @@ -1145,9 +1146,9 @@ static int tsl2x7x_read_raw(struct iio_dev *indio_dev,
>  		break;
>  	case IIO_CHAN_INFO_CALIBSCALE:
>  		if (chan->type == IIO_LIGHT)
> -			*val = tsl2x7x_als_gain[chip->settings.als_gain];
> +			*val = tsl2772_als_gain[chip->settings.als_gain];
>  		else
> -			*val = tsl2x7x_prox_gain[chip->settings.prox_gain];
> +			*val = tsl2772_prox_gain[chip->settings.prox_gain];
>  		ret = IIO_VAL_INT;
>  		break;
>  	case IIO_CHAN_INFO_CALIBBIAS:
> @@ -1157,7 +1158,7 @@ static int tsl2x7x_read_raw(struct iio_dev *indio_dev,
>  	case IIO_CHAN_INFO_INT_TIME:
>  		*val = 0;
>  		*val2 = (256 - chip->settings.als_time) *
> -			tsl2x7x_int_time[chip->id].increment_us;
> +			tsl2772_int_time[chip->id].increment_us;
>  		ret = IIO_VAL_INT_PLUS_MICRO;
>  		break;
>  	default:
> @@ -1167,13 +1168,13 @@ static int tsl2x7x_read_raw(struct iio_dev *indio_dev,
>  	return ret;
>  }
>  
> -static int tsl2x7x_write_raw(struct iio_dev *indio_dev,
> +static int tsl2772_write_raw(struct iio_dev *indio_dev,
>  			     struct iio_chan_spec const *chan,
>  			     int val,
>  			     int val2,
>  			     long mask)
>  {
> -	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
> +	struct tsl2772_chip *chip = iio_priv(indio_dev);
>  
>  	switch (mask) {
>  	case IIO_CHAN_INFO_CALIBSCALE:
> @@ -1218,13 +1219,13 @@ static int tsl2x7x_write_raw(struct iio_dev *indio_dev,
>  		break;
>  	case IIO_CHAN_INFO_INT_TIME:
>  		chip->settings.als_time = 256 -
> -			(val2 / tsl2x7x_int_time[chip->id].increment_us);
> +			(val2 / tsl2772_int_time[chip->id].increment_us);
>  		break;
>  	default:
>  		return -EINVAL;
>  	}
>  
> -	return tsl2x7x_invoke_change(indio_dev);
> +	return tsl2772_invoke_change(indio_dev);
>  }
>  
>  static DEVICE_ATTR_RO(in_intensity0_integration_time_available);
> @@ -1238,7 +1239,7 @@ static DEVICE_ATTR_WO(in_proximity0_calibrate);
>  static DEVICE_ATTR_RW(in_illuminance0_lux_table);
>  
>  /* Use the default register values to identify the Taos device */
> -static int tsl2x7x_device_id_verif(int id, int target)
> +static int tsl2772_device_id_verif(int id, int target)
>  {
>  	switch (target) {
>  	case tsl2571:
> @@ -1259,19 +1260,19 @@ static int tsl2x7x_device_id_verif(int id, int target)
>  	return -EINVAL;
>  }
>  
> -static irqreturn_t tsl2x7x_event_handler(int irq, void *private)
> +static irqreturn_t tsl2772_event_handler(int irq, void *private)
>  {
>  	struct iio_dev *indio_dev = private;
> -	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
> +	struct tsl2772_chip *chip = iio_priv(indio_dev);
>  	s64 timestamp = iio_get_time_ns(indio_dev);
>  	int ret;
>  
> -	ret = tsl2x7x_read_status(chip);
> +	ret = tsl2772_read_status(chip);
>  	if (ret < 0)
>  		return IRQ_HANDLED;
>  
>  	/* What type of interrupt do we need to process */
> -	if (ret & TSL2X7X_STA_PRX_INTR) {
> +	if (ret & TSL2772_STA_PRX_INTR) {
>  		iio_push_event(indio_dev,
>  			       IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY,
>  						    0,
> @@ -1280,7 +1281,7 @@ static irqreturn_t tsl2x7x_event_handler(int irq, void *private)
>  						    timestamp);
>  	}
>  
> -	if (ret & TSL2X7X_STA_ALS_INTR) {
> +	if (ret & TSL2772_STA_ALS_INTR) {
>  		iio_push_event(indio_dev,
>  			       IIO_UNMOD_EVENT_CODE(IIO_LIGHT,
>  						    0,
> @@ -1290,8 +1291,8 @@ static irqreturn_t tsl2x7x_event_handler(int irq, void *private)
>  	}
>  
>  	ret = i2c_smbus_write_byte(chip->client,
> -				   TSL2X7X_CMD_REG | TSL2X7X_CMD_SPL_FN |
> -				   TSL2X7X_CMD_PROXALS_INT_CLR);
> +				   TSL2772_CMD_REG | TSL2772_CMD_SPL_FN |
> +				   TSL2772_CMD_PROXALS_INT_CLR);
>  	if (ret < 0)
>  		dev_err(&chip->client->dev,
>  			"%s: failed to clear interrupt status: %d\n",
> @@ -1300,7 +1301,7 @@ static irqreturn_t tsl2x7x_event_handler(int irq, void *private)
>  	return IRQ_HANDLED;
>  }
>  
> -static struct attribute *tsl2x7x_ALS_device_attrs[] = {
> +static struct attribute *tsl2772_ALS_device_attrs[] = {
>  	&iio_const_attr_in_intensity0_calibscale_available.dev_attr.attr,
>  	&dev_attr_in_intensity0_integration_time_available.attr,
>  	&dev_attr_in_illuminance0_target_input.attr,
> @@ -1309,12 +1310,12 @@ static struct attribute *tsl2x7x_ALS_device_attrs[] = {
>  	NULL
>  };
>  
> -static struct attribute *tsl2x7x_PRX_device_attrs[] = {
> +static struct attribute *tsl2772_PRX_device_attrs[] = {
>  	&dev_attr_in_proximity0_calibrate.attr,
>  	NULL
>  };
>  
> -static struct attribute *tsl2x7x_ALSPRX_device_attrs[] = {
> +static struct attribute *tsl2772_ALSPRX_device_attrs[] = {
>  	&iio_const_attr_in_intensity0_calibscale_available.dev_attr.attr,
>  	&dev_attr_in_intensity0_integration_time_available.attr,
>  	&dev_attr_in_illuminance0_target_input.attr,
> @@ -1323,13 +1324,13 @@ static struct attribute *tsl2x7x_ALSPRX_device_attrs[] = {
>  	NULL
>  };
>  
> -static struct attribute *tsl2x7x_PRX2_device_attrs[] = {
> +static struct attribute *tsl2772_PRX2_device_attrs[] = {
>  	&dev_attr_in_proximity0_calibrate.attr,
>  	&iio_const_attr_in_proximity0_calibscale_available.dev_attr.attr,
>  	NULL
>  };
>  
> -static struct attribute *tsl2x7x_ALSPRX2_device_attrs[] = {
> +static struct attribute *tsl2772_ALSPRX2_device_attrs[] = {
>  	&iio_const_attr_in_intensity0_calibscale_available.dev_attr.attr,
>  	&dev_attr_in_intensity0_integration_time_available.attr,
>  	&dev_attr_in_illuminance0_target_input.attr,
> @@ -1340,73 +1341,73 @@ static struct attribute *tsl2x7x_ALSPRX2_device_attrs[] = {
>  	NULL
>  };
>  
> -static const struct attribute_group tsl2X7X_device_attr_group_tbl[] = {
> +static const struct attribute_group tsl2772_device_attr_group_tbl[] = {
>  	[ALS] = {
> -		.attrs = tsl2x7x_ALS_device_attrs,
> +		.attrs = tsl2772_ALS_device_attrs,
>  	},
>  	[PRX] = {
> -		.attrs = tsl2x7x_PRX_device_attrs,
> +		.attrs = tsl2772_PRX_device_attrs,
>  	},
>  	[ALSPRX] = {
> -		.attrs = tsl2x7x_ALSPRX_device_attrs,
> +		.attrs = tsl2772_ALSPRX_device_attrs,
>  	},
>  	[PRX2] = {
> -		.attrs = tsl2x7x_PRX2_device_attrs,
> +		.attrs = tsl2772_PRX2_device_attrs,
>  	},
>  	[ALSPRX2] = {
> -		.attrs = tsl2x7x_ALSPRX2_device_attrs,
> +		.attrs = tsl2772_ALSPRX2_device_attrs,
>  	},
>  };
>  
> -static const struct iio_info tsl2X7X_device_info[] = {
> +static const struct iio_info tsl2772_device_info[] = {
>  	[ALS] = {
> -		.attrs = &tsl2X7X_device_attr_group_tbl[ALS],
> -		.read_raw = &tsl2x7x_read_raw,
> -		.write_raw = &tsl2x7x_write_raw,
> -		.read_event_value = &tsl2x7x_read_event_value,
> -		.write_event_value = &tsl2x7x_write_event_value,
> -		.read_event_config = &tsl2x7x_read_interrupt_config,
> -		.write_event_config = &tsl2x7x_write_interrupt_config,
> +		.attrs = &tsl2772_device_attr_group_tbl[ALS],
> +		.read_raw = &tsl2772_read_raw,
> +		.write_raw = &tsl2772_write_raw,
> +		.read_event_value = &tsl2772_read_event_value,
> +		.write_event_value = &tsl2772_write_event_value,
> +		.read_event_config = &tsl2772_read_interrupt_config,
> +		.write_event_config = &tsl2772_write_interrupt_config,
>  	},
>  	[PRX] = {
> -		.attrs = &tsl2X7X_device_attr_group_tbl[PRX],
> -		.read_raw = &tsl2x7x_read_raw,
> -		.write_raw = &tsl2x7x_write_raw,
> -		.read_event_value = &tsl2x7x_read_event_value,
> -		.write_event_value = &tsl2x7x_write_event_value,
> -		.read_event_config = &tsl2x7x_read_interrupt_config,
> -		.write_event_config = &tsl2x7x_write_interrupt_config,
> +		.attrs = &tsl2772_device_attr_group_tbl[PRX],
> +		.read_raw = &tsl2772_read_raw,
> +		.write_raw = &tsl2772_write_raw,
> +		.read_event_value = &tsl2772_read_event_value,
> +		.write_event_value = &tsl2772_write_event_value,
> +		.read_event_config = &tsl2772_read_interrupt_config,
> +		.write_event_config = &tsl2772_write_interrupt_config,
>  	},
>  	[ALSPRX] = {
> -		.attrs = &tsl2X7X_device_attr_group_tbl[ALSPRX],
> -		.read_raw = &tsl2x7x_read_raw,
> -		.write_raw = &tsl2x7x_write_raw,
> -		.read_event_value = &tsl2x7x_read_event_value,
> -		.write_event_value = &tsl2x7x_write_event_value,
> -		.read_event_config = &tsl2x7x_read_interrupt_config,
> -		.write_event_config = &tsl2x7x_write_interrupt_config,
> +		.attrs = &tsl2772_device_attr_group_tbl[ALSPRX],
> +		.read_raw = &tsl2772_read_raw,
> +		.write_raw = &tsl2772_write_raw,
> +		.read_event_value = &tsl2772_read_event_value,
> +		.write_event_value = &tsl2772_write_event_value,
> +		.read_event_config = &tsl2772_read_interrupt_config,
> +		.write_event_config = &tsl2772_write_interrupt_config,
>  	},
>  	[PRX2] = {
> -		.attrs = &tsl2X7X_device_attr_group_tbl[PRX2],
> -		.read_raw = &tsl2x7x_read_raw,
> -		.write_raw = &tsl2x7x_write_raw,
> -		.read_event_value = &tsl2x7x_read_event_value,
> -		.write_event_value = &tsl2x7x_write_event_value,
> -		.read_event_config = &tsl2x7x_read_interrupt_config,
> -		.write_event_config = &tsl2x7x_write_interrupt_config,
> +		.attrs = &tsl2772_device_attr_group_tbl[PRX2],
> +		.read_raw = &tsl2772_read_raw,
> +		.write_raw = &tsl2772_write_raw,
> +		.read_event_value = &tsl2772_read_event_value,
> +		.write_event_value = &tsl2772_write_event_value,
> +		.read_event_config = &tsl2772_read_interrupt_config,
> +		.write_event_config = &tsl2772_write_interrupt_config,
>  	},
>  	[ALSPRX2] = {
> -		.attrs = &tsl2X7X_device_attr_group_tbl[ALSPRX2],
> -		.read_raw = &tsl2x7x_read_raw,
> -		.write_raw = &tsl2x7x_write_raw,
> -		.read_event_value = &tsl2x7x_read_event_value,
> -		.write_event_value = &tsl2x7x_write_event_value,
> -		.read_event_config = &tsl2x7x_read_interrupt_config,
> -		.write_event_config = &tsl2x7x_write_interrupt_config,
> +		.attrs = &tsl2772_device_attr_group_tbl[ALSPRX2],
> +		.read_raw = &tsl2772_read_raw,
> +		.write_raw = &tsl2772_write_raw,
> +		.read_event_value = &tsl2772_read_event_value,
> +		.write_event_value = &tsl2772_write_event_value,
> +		.read_event_config = &tsl2772_read_interrupt_config,
> +		.write_event_config = &tsl2772_write_interrupt_config,
>  	},
>  };
>  
> -static const struct iio_event_spec tsl2x7x_events[] = {
> +static const struct iio_event_spec tsl2772_events[] = {
>  	{
>  		.type = IIO_EV_TYPE_THRESH,
>  		.dir = IIO_EV_DIR_RISING,
> @@ -1423,7 +1424,7 @@ static const struct iio_event_spec tsl2x7x_events[] = {
>  	},
>  };
>  
> -static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
> +static const struct tsl2772_chip_info tsl2772_chip_info_tbl[] = {
>  	[ALS] = {
>  		.channel_with_events = {
>  			{
> @@ -1439,8 +1440,8 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
>  				BIT(IIO_CHAN_INFO_INT_TIME) |
>  				BIT(IIO_CHAN_INFO_CALIBSCALE) |
>  				BIT(IIO_CHAN_INFO_CALIBBIAS),
> -			.event_spec = tsl2x7x_events,
> -			.num_event_specs = ARRAY_SIZE(tsl2x7x_events),
> +			.event_spec = tsl2772_events,
> +			.num_event_specs = ARRAY_SIZE(tsl2772_events),
>  			}, {
>  			.type = IIO_INTENSITY,
>  			.indexed = 1,
> @@ -1468,7 +1469,7 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
>  			},
>  		},
>  		.chan_table_elements = 3,
> -		.info = &tsl2X7X_device_info[ALS],
> +		.info = &tsl2772_device_info[ALS],
>  	},
>  	[PRX] = {
>  		.channel_with_events = {
> @@ -1477,8 +1478,8 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
>  			.indexed = 1,
>  			.channel = 0,
>  			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> -			.event_spec = tsl2x7x_events,
> -			.num_event_specs = ARRAY_SIZE(tsl2x7x_events),
> +			.event_spec = tsl2772_events,
> +			.num_event_specs = ARRAY_SIZE(tsl2772_events),
>  			},
>  		},
>  		.channel_without_events = {
> @@ -1490,7 +1491,7 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
>  			},
>  		},
>  		.chan_table_elements = 1,
> -		.info = &tsl2X7X_device_info[PRX],
> +		.info = &tsl2772_device_info[PRX],
>  	},
>  	[ALSPRX] = {
>  		.channel_with_events = {
> @@ -1507,8 +1508,8 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
>  				BIT(IIO_CHAN_INFO_INT_TIME) |
>  				BIT(IIO_CHAN_INFO_CALIBSCALE) |
>  				BIT(IIO_CHAN_INFO_CALIBBIAS),
> -			.event_spec = tsl2x7x_events,
> -			.num_event_specs = ARRAY_SIZE(tsl2x7x_events),
> +			.event_spec = tsl2772_events,
> +			.num_event_specs = ARRAY_SIZE(tsl2772_events),
>  			}, {
>  			.type = IIO_INTENSITY,
>  			.indexed = 1,
> @@ -1519,8 +1520,8 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
>  			.indexed = 1,
>  			.channel = 0,
>  			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> -			.event_spec = tsl2x7x_events,
> -			.num_event_specs = ARRAY_SIZE(tsl2x7x_events),
> +			.event_spec = tsl2772_events,
> +			.num_event_specs = ARRAY_SIZE(tsl2772_events),
>  			},
>  		},
>  		.channel_without_events = {
> @@ -1550,7 +1551,7 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
>  			},
>  		},
>  		.chan_table_elements = 4,
> -		.info = &tsl2X7X_device_info[ALSPRX],
> +		.info = &tsl2772_device_info[ALSPRX],
>  	},
>  	[PRX2] = {
>  		.channel_with_events = {
> @@ -1560,8 +1561,8 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
>  			.channel = 0,
>  			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
>  				BIT(IIO_CHAN_INFO_CALIBSCALE),
> -			.event_spec = tsl2x7x_events,
> -			.num_event_specs = ARRAY_SIZE(tsl2x7x_events),
> +			.event_spec = tsl2772_events,
> +			.num_event_specs = ARRAY_SIZE(tsl2772_events),
>  			},
>  		},
>  		.channel_without_events = {
> @@ -1574,7 +1575,7 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
>  			},
>  		},
>  		.chan_table_elements = 1,
> -		.info = &tsl2X7X_device_info[PRX2],
> +		.info = &tsl2772_device_info[PRX2],
>  	},
>  	[ALSPRX2] = {
>  		.channel_with_events = {
> @@ -1591,8 +1592,8 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
>  				BIT(IIO_CHAN_INFO_INT_TIME) |
>  				BIT(IIO_CHAN_INFO_CALIBSCALE) |
>  				BIT(IIO_CHAN_INFO_CALIBBIAS),
> -			.event_spec = tsl2x7x_events,
> -			.num_event_specs = ARRAY_SIZE(tsl2x7x_events),
> +			.event_spec = tsl2772_events,
> +			.num_event_specs = ARRAY_SIZE(tsl2772_events),
>  			}, {
>  			.type = IIO_INTENSITY,
>  			.indexed = 1,
> @@ -1604,8 +1605,8 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
>  			.channel = 0,
>  			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
>  				BIT(IIO_CHAN_INFO_CALIBSCALE),
> -			.event_spec = tsl2x7x_events,
> -			.num_event_specs = ARRAY_SIZE(tsl2x7x_events),
> +			.event_spec = tsl2772_events,
> +			.num_event_specs = ARRAY_SIZE(tsl2772_events),
>  			},
>  		},
>  		.channel_without_events = {
> @@ -1636,15 +1637,15 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
>  			},
>  		},
>  		.chan_table_elements = 4,
> -		.info = &tsl2X7X_device_info[ALSPRX2],
> +		.info = &tsl2772_device_info[ALSPRX2],
>  	},
>  };
>  
> -static int tsl2x7x_probe(struct i2c_client *clientp,
> +static int tsl2772_probe(struct i2c_client *clientp,
>  			 const struct i2c_device_id *id)
>  {
>  	struct iio_dev *indio_dev;
> -	struct tsl2X7X_chip *chip;
> +	struct tsl2772_chip *chip;
>  	int ret;
>  
>  	indio_dev = devm_iio_device_alloc(&clientp->dev, sizeof(*chip));
> @@ -1656,18 +1657,18 @@ static int tsl2x7x_probe(struct i2c_client *clientp,
>  	i2c_set_clientdata(clientp, indio_dev);
>  
>  	ret = i2c_smbus_read_byte_data(chip->client,
> -				       TSL2X7X_CMD_REG | TSL2X7X_CHIPID);
> +				       TSL2772_CMD_REG | TSL2772_CHIPID);
>  	if (ret < 0)
>  		return ret;
>  
> -	if (tsl2x7x_device_id_verif(ret, id->driver_data) <= 0) {
> +	if (tsl2772_device_id_verif(ret, id->driver_data) <= 0) {
>  		dev_info(&chip->client->dev,
>  			 "%s: i2c device found does not match expected id\n",
>  				__func__);
>  		return -EINVAL;
>  	}
>  
> -	ret = i2c_smbus_write_byte(clientp, TSL2X7X_CMD_REG | TSL2X7X_CNTRL);
> +	ret = i2c_smbus_write_byte(clientp, TSL2772_CMD_REG | TSL2772_CNTRL);
>  	if (ret < 0) {
>  		dev_err(&clientp->dev,
>  			"%s: Failed to write to CMD register: %d\n",
> @@ -1678,11 +1679,11 @@ static int tsl2x7x_probe(struct i2c_client *clientp,
>  	mutex_init(&chip->als_mutex);
>  	mutex_init(&chip->prox_mutex);
>  
> -	chip->tsl2x7x_chip_status = TSL2X7X_CHIP_UNKNOWN;
> +	chip->tsl2772_chip_status = TSL2772_CHIP_UNKNOWN;
>  	chip->pdata = dev_get_platdata(&clientp->dev);
>  	chip->id = id->driver_data;
>  	chip->chip_info =
> -		&tsl2x7x_chip_info_tbl[device_channel_config[id->driver_data]];
> +		&tsl2772_chip_info_tbl[device_channel_config[id->driver_data]];
>  
>  	indio_dev->info = chip->chip_info->info;
>  	indio_dev->dev.parent = &clientp->dev;
> @@ -1695,10 +1696,10 @@ static int tsl2x7x_probe(struct i2c_client *clientp,
>  
>  		ret = devm_request_threaded_irq(&clientp->dev, clientp->irq,
>  						NULL,
> -						&tsl2x7x_event_handler,
> +						&tsl2772_event_handler,
>  						IRQF_TRIGGER_FALLING |
>  						IRQF_ONESHOT,
> -						"TSL2X7X_event",
> +						"TSL2772_event",
>  						indio_dev);
>  		if (ret) {
>  			dev_err(&clientp->dev,
> @@ -1709,8 +1710,8 @@ static int tsl2x7x_probe(struct i2c_client *clientp,
>  		indio_dev->channels = chip->chip_info->channel_without_events;
>  	}
>  
> -	tsl2x7x_defaults(chip);
> -	tsl2x7x_chip_on(indio_dev);
> +	tsl2772_defaults(chip);
> +	tsl2772_chip_on(indio_dev);
>  
>  	ret = iio_device_register(indio_dev);
>  	if (ret) {
> @@ -1722,32 +1723,32 @@ static int tsl2x7x_probe(struct i2c_client *clientp,
>  	return 0;
>  }
>  
> -static int tsl2x7x_suspend(struct device *dev)
> +static int tsl2772_suspend(struct device *dev)
>  {
>  	struct iio_dev *indio_dev = dev_get_drvdata(dev);
>  
> -	return tsl2x7x_chip_off(indio_dev);
> +	return tsl2772_chip_off(indio_dev);
>  }
>  
> -static int tsl2x7x_resume(struct device *dev)
> +static int tsl2772_resume(struct device *dev)
>  {
>  	struct iio_dev *indio_dev = dev_get_drvdata(dev);
>  
> -	return tsl2x7x_chip_on(indio_dev);
> +	return tsl2772_chip_on(indio_dev);
>  }
>  
> -static int tsl2x7x_remove(struct i2c_client *client)
> +static int tsl2772_remove(struct i2c_client *client)
>  {
>  	struct iio_dev *indio_dev = i2c_get_clientdata(client);
>  
> -	tsl2x7x_chip_off(indio_dev);
> +	tsl2772_chip_off(indio_dev);
>  
>  	iio_device_unregister(indio_dev);
>  
>  	return 0;
>  }
>  
> -static const struct i2c_device_id tsl2x7x_idtable[] = {
> +static const struct i2c_device_id tsl2772_idtable[] = {
>  	{ "tsl2571", tsl2571 },
>  	{ "tsl2671", tsl2671 },
>  	{ "tmd2671", tmd2671 },
> @@ -1761,9 +1762,9 @@ static const struct i2c_device_id tsl2x7x_idtable[] = {
>  	{}
>  };
>  
> -MODULE_DEVICE_TABLE(i2c, tsl2x7x_idtable);
> +MODULE_DEVICE_TABLE(i2c, tsl2772_idtable);
>  
> -static const struct of_device_id tsl2x7x_of_match[] = {
> +static const struct of_device_id tsl2772_of_match[] = {
>  	{ .compatible = "amstaos,tsl2571" },
>  	{ .compatible = "amstaos,tsl2671" },
>  	{ .compatible = "amstaos,tmd2671" },
> @@ -1776,27 +1777,27 @@ static const struct of_device_id tsl2x7x_of_match[] = {
>  	{ .compatible = "amstaos,tmd2772" },
>  	{}
>  };
> -MODULE_DEVICE_TABLE(of, tsl2x7x_of_match);
> +MODULE_DEVICE_TABLE(of, tsl2772_of_match);
>  
> -static const struct dev_pm_ops tsl2x7x_pm_ops = {
> -	.suspend = tsl2x7x_suspend,
> -	.resume  = tsl2x7x_resume,
> +static const struct dev_pm_ops tsl2772_pm_ops = {
> +	.suspend = tsl2772_suspend,
> +	.resume  = tsl2772_resume,
>  };
>  
> -static struct i2c_driver tsl2x7x_driver = {
> +static struct i2c_driver tsl2772_driver = {
>  	.driver = {
> -		.name = "tsl2x7x",
> -		.of_match_table = tsl2x7x_of_match,
> -		.pm = &tsl2x7x_pm_ops,
> +		.name = "tsl2772",
> +		.of_match_table = tsl2772_of_match,
> +		.pm = &tsl2772_pm_ops,
>  	},
> -	.id_table = tsl2x7x_idtable,
> -	.probe = tsl2x7x_probe,
> -	.remove = tsl2x7x_remove,
> +	.id_table = tsl2772_idtable,
> +	.probe = tsl2772_probe,
> +	.remove = tsl2772_remove,
>  };
>  
> -module_i2c_driver(tsl2x7x_driver);
> +module_i2c_driver(tsl2772_driver);
>  
>  MODULE_AUTHOR("J. August Brenner <Jon.Brenner@ams.com>");
>  MODULE_AUTHOR("Brian Masney <masneyb@onstation.org>");
> -MODULE_DESCRIPTION("TAOS tsl2x7x ambient and proximity light sensor driver");
> +MODULE_DESCRIPTION("TAOS tsl2772 ambient and proximity light sensor driver");
>  MODULE_LICENSE("GPL");
> diff --git a/drivers/staging/iio/light/tsl2x7x.h b/drivers/staging/iio/light/tsl2772.h
> similarity index 71%
> rename from drivers/staging/iio/light/tsl2x7x.h
> rename to drivers/staging/iio/light/tsl2772.h
> index f74427f4ab6e..cc14422f85a6 100644
> --- a/drivers/staging/iio/light/tsl2x7x.h
> +++ b/drivers/staging/iio/light/tsl2772.h
> @@ -1,50 +1,50 @@
>  /* SPDX-License-Identifier: GPL-2.0+ */
>  /*
>   * Device driver for monitoring ambient light intensity (lux)
> - * and proximity (prox) within the TAOS TSL2X7X family of devices.
> + * and proximity (prox) within the TAOS TSL2772 family of devices.
>   *
>   * Copyright (c) 2012, TAOS Corporation.
>   */
>  
> -#ifndef __TSL2X7X_H
> -#define __TSL2X7X_H
> +#ifndef __TSL2772_H
> +#define __TSL2772_H
>  
> -struct tsl2x7x_lux {
> +struct tsl2772_lux {
>  	unsigned int ch0;
>  	unsigned int ch1;
>  };
>  
>  /* Max number of segments allowable in LUX table */
> -#define TSL2X7X_MAX_LUX_TABLE_SIZE		6
> +#define TSL2772_MAX_LUX_TABLE_SIZE		6
>  /* The default LUX tables all have 3 elements.  */
> -#define TSL2X7X_DEF_LUX_TABLE_SZ		3
> -#define TSL2X7X_DEFAULT_TABLE_BYTES (sizeof(struct tsl2x7x_lux) * \
> -				     TSL2X7X_DEF_LUX_TABLE_SZ)
> +#define TSL2772_DEF_LUX_TABLE_SZ		3
> +#define TSL2772_DEFAULT_TABLE_BYTES (sizeof(struct tsl2772_lux) * \
> +				     TSL2772_DEF_LUX_TABLE_SZ)
>  
>  /* Proximity diode to use */
> -#define TSL2X7X_DIODE0                  0x01
> -#define TSL2X7X_DIODE1                  0x02
> -#define TSL2X7X_DIODE_BOTH              0x03
> +#define TSL2772_DIODE0                  0x01
> +#define TSL2772_DIODE1                  0x02
> +#define TSL2772_DIODE_BOTH              0x03
>  
>  /* LED Power */
> -#define TSL2X7X_100_mA                  0x00
> -#define TSL2X7X_50_mA                   0x01
> -#define TSL2X7X_25_mA                   0x02
> -#define TSL2X7X_13_mA                   0x03
> +#define TSL2772_100_mA                  0x00
> +#define TSL2772_50_mA                   0x01
> +#define TSL2772_25_mA                   0x02
> +#define TSL2772_13_mA                   0x03
>  
>  /**
> - * struct tsl2x7x_settings - Settings for the tsl2x7x driver
> + * struct tsl2772_settings - Settings for the tsl2772 driver
>   *  @als_time:              Integration time of the ALS channel ADCs in 2.73 ms
>   *                          increments. Total integration time is
>   *                          (256 - als_time) * 2.73.
> - *  @als_gain:              Index into the tsl2x7x_als_gain array.
> + *  @als_gain:              Index into the tsl2772_als_gain array.
>   *  @als_gain_trim:         Default gain trim to account for aperture effects.
>   *  @wait_time:             Time between proximity and ALS cycles in 2.73
>   *                          periods.
>   *  @prox_time:             Integration time of the proximity ADC in 2.73 ms
>   *                          increments. Total integration time is
>   *                          (256 - prx_time) * 2.73.
> - *  @prox_gain:             Index into the tsl2x7x_prx_gain array.
> + *  @prox_gain:             Index into the tsl2772_prx_gain array.
>   *  @als_prox_config:       The value of the ALS / Proximity configuration
>   *                          register.
>   *  @als_cal_target:        Known external ALS reading for calibration.
> @@ -64,7 +64,7 @@ struct tsl2x7x_lux {
>   *                          LED(s) for proximity sensing.
>   *  @prox_power             The amount of power to use for the external LED(s).
>   */
> -struct tsl2x7x_settings {
> +struct tsl2772_settings {
>  	int als_time;
>  	int als_gain;
>  	int als_gain_trim;
> @@ -88,14 +88,14 @@ struct tsl2x7x_settings {
>  };
>  
>  /**
> - * struct tsl2X7X_platform_data - Platform callback, glass and defaults
> + * struct tsl2772_platform_data - Platform callback, glass and defaults
>   * @platform_lux_table:        Device specific glass coefficents
>   * @platform_default_settings: Device specific power on defaults
>   *
>   */
> -struct tsl2X7X_platform_data {
> -	struct tsl2x7x_lux platform_lux_table[TSL2X7X_MAX_LUX_TABLE_SIZE];
> -	struct tsl2x7x_settings *platform_default_settings;
> +struct tsl2772_platform_data {
> +	struct tsl2772_lux platform_lux_table[TSL2772_MAX_LUX_TABLE_SIZE];
> +	struct tsl2772_settings *platform_default_settings;
>  };
>  
> -#endif /* __TSL2X7X_H */
> +#endif /* __TSL2772_H */

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

* Re: [PATCH v2 11/11] staging: iio: tsl2x7x/tsl2772: move out of staging
  2018-05-04  2:56   ` Brian Masney
@ 2018-05-06 19:00     ` Jonathan Cameron
  0 siblings, 0 replies; 24+ messages in thread
From: Jonathan Cameron @ 2018-05-06 19:00 UTC (permalink / raw)
  To: Brian Masney
  Cc: devel, lars, linux-iio, gregkh, linux-kernel, pmeerw, knaack.h,
	drew.paterson

On Thu, 3 May 2018 22:56:54 -0400
Brian Masney <masneyb@onstation.org> wrote:

> Hey Jonathan,
> 
> I intentionally didn't run git format-patch with the --no-renames since
> patch 10 renamed the driver. Here is the .[ch] files included inline to
> make your review easier.
Thanks :)

A few really minor things beyond that issue with the way the range
is defined which came up in the earlier patch.

So very nearly there!

Jonathan
> 
> Brian
> 
> 
> tsl2772.c:
> 
> // SPDX-License-Identifier: GPL-2.0+
> /*
>  * Device driver for monitoring ambient light intensity in (lux) and proximity
>  * detection (prox) for the TAOS TSL2571, TSL2671, TMD2671, TSL2771, TMD2771,
>  * TSL2572, TSL2672, TMD2672, TSL2772, and TMD2772 devices.
>  *
>  * Copyright (c) 2012, TAOS Corporation.
>  * Copyright (c) 2017-2018 Brian Masney <masneyb@onstation.org>
>  */
> 
> #include <linux/delay.h>
> #include <linux/errno.h>
> #include <linux/i2c.h>
> #include <linux/interrupt.h>
> #include <linux/kernel.h>
> #include <linux/module.h>
> #include <linux/mutex.h>
> #include <linux/slab.h>
> #include <linux/iio/events.h>
> #include <linux/iio/iio.h>
> #include <linux/iio/sysfs.h>
> #include <linux/platform_data/tsl2772.h>
> 
> /* Cal defs */
> #define PROX_STAT_CAL			0
> #define PROX_STAT_SAMP			1
> #define MAX_SAMPLES_CAL			200
> 
> /* TSL2772 Device ID */
> #define TRITON_ID			0x00
> #define SWORDFISH_ID			0x30
> #define HALIBUT_ID			0x20
> 
> /* Lux calculation constants */
> #define TSL2772_LUX_CALC_OVER_FLOW	65535
> 
> /*
>  * TAOS Register definitions - Note: depending on device, some of these register
>  * are not used and the register address is benign.
>  */
> 
> /* Register offsets */
> #define TSL2772_MAX_CONFIG_REG		16
> 
> /* Device Registers and Masks */
> #define TSL2772_CNTRL			0x00
> #define TSL2772_ALS_TIME		0X01
> #define TSL2772_PRX_TIME		0x02
> #define TSL2772_WAIT_TIME		0x03
> #define TSL2772_ALS_MINTHRESHLO		0X04
> #define TSL2772_ALS_MINTHRESHHI		0X05
> #define TSL2772_ALS_MAXTHRESHLO		0X06
> #define TSL2772_ALS_MAXTHRESHHI		0X07
> #define TSL2772_PRX_MINTHRESHLO		0X08
> #define TSL2772_PRX_MINTHRESHHI		0X09
> #define TSL2772_PRX_MAXTHRESHLO		0X0A
> #define TSL2772_PRX_MAXTHRESHHI		0X0B
> #define TSL2772_PERSISTENCE		0x0C
> #define TSL2772_ALS_PRX_CONFIG		0x0D
> #define TSL2772_PRX_COUNT		0x0E
> #define TSL2772_GAIN			0x0F
> #define TSL2772_NOTUSED			0x10
> #define TSL2772_REVID			0x11
> #define TSL2772_CHIPID			0x12
> #define TSL2772_STATUS			0x13
> #define TSL2772_ALS_CHAN0LO		0x14
> #define TSL2772_ALS_CHAN0HI		0x15
> #define TSL2772_ALS_CHAN1LO		0x16
> #define TSL2772_ALS_CHAN1HI		0x17
> #define TSL2772_PRX_LO			0x18
> #define TSL2772_PRX_HI			0x19
> 
> /* tsl2772 cmd reg masks */
> #define TSL2772_CMD_REG			0x80
> #define TSL2772_CMD_SPL_FN		0x60
> #define TSL2772_CMD_REPEAT_PROTO	0x00
> #define TSL2772_CMD_AUTOINC_PROTO	0x20
> 
> #define TSL2772_CMD_PROX_INT_CLR	0X05
> #define TSL2772_CMD_ALS_INT_CLR		0x06
> #define TSL2772_CMD_PROXALS_INT_CLR	0X07
> 
> /* tsl2772 cntrl reg masks */
> #define TSL2772_CNTL_ADC_ENBL		0x02
> #define TSL2772_CNTL_PWR_ON		0x01
> 
> /* tsl2772 status reg masks */
> #define TSL2772_STA_ADC_VALID		0x01
> #define TSL2772_STA_PRX_VALID		0x02
> #define TSL2772_STA_ADC_PRX_VALID	(TSL2772_STA_ADC_VALID | \
> 					 TSL2772_STA_PRX_VALID)
> #define TSL2772_STA_ALS_INTR		0x10
> #define TSL2772_STA_PRX_INTR		0x20
> 
> /* tsl2772 cntrl reg masks */
> #define TSL2772_CNTL_REG_CLEAR		0x00
> #define TSL2772_CNTL_PROX_INT_ENBL	0X20
> #define TSL2772_CNTL_ALS_INT_ENBL	0X10
> #define TSL2772_CNTL_WAIT_TMR_ENBL	0X08
> #define TSL2772_CNTL_PROX_DET_ENBL	0X04
> #define TSL2772_CNTL_PWRON		0x01
> #define TSL2772_CNTL_ALSPON_ENBL	0x03
> #define TSL2772_CNTL_INTALSPON_ENBL	0x13
> #define TSL2772_CNTL_PROXPON_ENBL	0x0F
> #define TSL2772_CNTL_INTPROXPON_ENBL	0x2F
> 
> /* TAOS Device family members */
> enum {
> 	tsl2571,
> 	tsl2671,
> 	tmd2671,
> 	tsl2771,
> 	tmd2771,
> 	tsl2572,
> 	tsl2672,
> 	tmd2672,
> 	tsl2772,
> 	tmd2772
> };
> 
> enum {
> 	TSL2772_CHIP_UNKNOWN = 0,
> 	TSL2772_CHIP_WORKING = 1,
> 	TSL2772_CHIP_SUSPENDED = 2
> };
> 
> /* Per-device data */
> struct tsl2772_als_info {
> 	u16 als_ch0;
> 	u16 als_ch1;
> 	u16 lux;
> };
> 
> struct tsl2772_chip_info {
> 	int chan_table_elements;
> 	struct iio_chan_spec channel_with_events[4];
> 	struct iio_chan_spec channel_without_events[4];
> 	const struct iio_info *info;
> };
> 
> struct tsl2772_chip {
> 	kernel_ulong_t id;
> 	struct mutex prox_mutex;
> 	struct mutex als_mutex;
> 	struct i2c_client *client;
> 	u16 prox_data;
> 	struct tsl2772_als_info als_cur_info;
> 	struct tsl2772_settings settings;
> 	struct tsl2772_platform_data *pdata;
> 	int als_gain_time_scale;
> 	int als_saturation;
> 	int tsl2772_chip_status;
> 	u8 tsl2772_config[TSL2772_MAX_CONFIG_REG];
> 	const struct tsl2772_chip_info	*chip_info;
> 	const struct iio_info *info;
> 	s64 event_timestamp;
> 	/*
> 	 * This structure is intentionally large to accommodate
> 	 * updates via sysfs.
> 	 * Sized to 9 = max 8 segments + 1 termination segment
> 	 */
> 	struct tsl2772_lux tsl2772_device_lux[TSL2772_MAX_LUX_TABLE_SIZE];
> };
> 
> /*
>  * Different devices require different coefficents, and these numbers were
>  * derived from the 'Lux Equation' section of the various device datasheets.
>  * All of these coefficients assume a Glass Attenuation (GA) factor of 1.
>  * The coefficients are multiplied by 1000 to avoid floating point operations.
>  * The two rows in each table correspond to the Lux1 and Lux2 equations from
>  * the datasheets.
>  */
> static const struct tsl2772_lux tsl2x71_lux_table[TSL2772_DEF_LUX_TABLE_SZ] = {
> 	{ 53000, 106000 },
> 	{ 31800,  53000 },
> 	{ 0,          0 },
> };
> 
> static const struct tsl2772_lux tmd2x71_lux_table[TSL2772_DEF_LUX_TABLE_SZ] = {
> 	{ 24000,  48000 },
> 	{ 14400,  24000 },
> 	{ 0,          0 },
> };
> 
> static const struct tsl2772_lux tsl2x72_lux_table[TSL2772_DEF_LUX_TABLE_SZ] = {
> 	{ 60000, 112200 },
> 	{ 37800,  60000 },
> 	{     0,      0 },
> };
> 
> static const struct tsl2772_lux tmd2x72_lux_table[TSL2772_DEF_LUX_TABLE_SZ] = {
> 	{ 20000,  35000 },
> 	{ 12600,  20000 },
> 	{     0,      0 },
> };
> 
> static const struct tsl2772_lux *tsl2772_default_lux_table_group[] = {
> 	[tsl2571] =	tsl2x71_lux_table,
> 	[tsl2671] =	tsl2x71_lux_table,
> 	[tmd2671] =	tmd2x71_lux_table,
> 	[tsl2771] =	tsl2x71_lux_table,
> 	[tmd2771] =	tmd2x71_lux_table,
> 	[tsl2572] =	tsl2x72_lux_table,
> 	[tsl2672] =	tsl2x72_lux_table,
> 	[tmd2672] =	tmd2x72_lux_table,
> 	[tsl2772] =	tsl2x72_lux_table,
> 	[tmd2772] =	tmd2x72_lux_table,
Really minor, but the tab before the value really doesn't add anything.

> };
> 
> static const struct tsl2772_settings tsl2772_default_settings = {
> 	.als_time = 255, /* 2.72 / 2.73 ms */
> 	.als_gain = 0,
> 	.prox_time = 255, /* 2.72 / 2.73 ms */
> 	.prox_gain = 0,
> 	.wait_time = 255,
> 	.als_prox_config = 0,
> 	.als_gain_trim = 1000,
> 	.als_cal_target = 150,
> 	.als_persistence = 1,
> 	.als_interrupt_en = false,
> 	.als_thresh_low = 200,
> 	.als_thresh_high = 256,
> 	.prox_persistence = 1,
> 	.prox_interrupt_en = false,
> 	.prox_thres_low  = 0,
> 	.prox_thres_high = 512,
> 	.prox_max_samples_cal = 30,
> 	.prox_pulse_count = 8,
> 	.prox_diode = TSL2772_DIODE1,
> 	.prox_power = TSL2772_100_mA
> };
> 
> static const s16 tsl2772_als_gain[] = {
> 	1,
> 	8,
> 	16,
> 	120
> };
> 
> static const s16 tsl2772_prox_gain[] = {
> 	1,
> 	2,
> 	4,
> 	8
> };
> 
> struct tsl2772_int_time {
> 	int increment_us;
> 	char *display_range;
> };
> 
> static const struct tsl2772_int_time tsl2772_int_time[] = {
> 	[tsl2571] = { 2720, "0.00272 - 0.696" },
> 	[tsl2671] = { 2720, "0.00272 - 0.696" },
> 	[tmd2671] = { 2720, "0.00272 - 0.696" },
> 	[tsl2771] = { 2720, "0.00272 - 0.696" },
> 	[tmd2771] = { 2720, "0.00272 - 0.696" },
> 	[tsl2572] = { 2730, "0.00273 - 0.699" },
> 	[tsl2672] = { 2730, "0.00273 - 0.699" },
> 	[tmd2672] = { 2730, "0.00273 - 0.699" },
> 	[tsl2772] = { 2730, "0.00273 - 0.699" },
> 	[tmd2772] = { 2730, "0.00273 - 0.699" },
> };
> 
> /* Channel variations */
> enum {
> 	ALS,
> 	PRX,
> 	ALSPRX,
> 	PRX2,
> 	ALSPRX2,
> };
> 
> static const u8 device_channel_config[] = {
> 	[tsl2571] = ALS,
> 	[tsl2671] = PRX,
> 	[tmd2671] = PRX,
> 	[tsl2771] = ALSPRX,
> 	[tmd2771] = ALSPRX,
> 	[tsl2572] = ALS,
> 	[tsl2672] = PRX2,
> 	[tmd2672] = PRX2,
> 	[tsl2772] = ALSPRX2,
> 	[tmd2772] = ALSPRX2
> };
> 
> static int tsl2772_read_status(struct tsl2772_chip *chip)
> {
> 	int ret;
> 
> 	ret = i2c_smbus_read_byte_data(chip->client,
> 				       TSL2772_CMD_REG | TSL2772_STATUS);
> 	if (ret < 0)
> 		dev_err(&chip->client->dev,
> 			"%s: failed to read STATUS register: %d\n", __func__,
> 			ret);
> 
> 	return ret;
> }
> 
> static int tsl2772_write_control_reg(struct tsl2772_chip *chip, u8 data)
> {
> 	int ret;
> 
> 	ret = i2c_smbus_write_byte_data(chip->client,
> 					TSL2772_CMD_REG | TSL2772_CNTRL, data);
> 	if (ret < 0) {
> 		dev_err(&chip->client->dev,
> 			"%s: failed to write to control register %x: %d\n",
> 			__func__, data, ret);
> 	}
> 
> 	return ret;
> }
> 
> static int tsl2772_read_autoinc_regs(struct tsl2772_chip *chip, int lower_reg,
> 				     int upper_reg)
> {
> 	u8 buf[2];
> 	int ret;
> 
> 	ret = i2c_smbus_write_byte(chip->client,
> 				   TSL2772_CMD_REG | TSL2772_CMD_AUTOINC_PROTO |
> 				   lower_reg);
> 	if (ret < 0) {
> 		dev_err(&chip->client->dev,
> 			"%s: failed to enable auto increment protocol: %d\n",
> 			__func__, ret);
> 		return ret;
> 	}
> 
> 	ret = i2c_smbus_read_byte_data(chip->client,
> 				       TSL2772_CMD_REG | lower_reg);
> 	if (ret < 0) {
> 		dev_err(&chip->client->dev,
> 			"%s: failed to read from register %x: %d\n", __func__,
> 			lower_reg, ret);
> 		return ret;
> 	}
> 	buf[0] = ret;
> 
> 	ret = i2c_smbus_read_byte_data(chip->client,
> 				       TSL2772_CMD_REG | upper_reg);
> 	if (ret < 0) {
> 		dev_err(&chip->client->dev,
> 			"%s: failed to read from register %x: %d\n", __func__,
> 			upper_reg, ret);
> 		return ret;
> 	}
> 	buf[1] = ret;
> 
> 	ret = i2c_smbus_write_byte(chip->client,
> 				   TSL2772_CMD_REG | TSL2772_CMD_REPEAT_PROTO |
> 				   lower_reg);
> 	if (ret < 0) {
> 		dev_err(&chip->client->dev,
> 			"%s: failed to enable repeated byte protocol: %d\n",
> 			__func__, ret);
> 		return ret;
> 	}
> 
> 	return le16_to_cpup((const __le16 *)&buf[0]);
> }
> 
> /**
>  * tsl2772_get_lux() - Reads and calculates current lux value.
>  * @indio_dev:	pointer to IIO device
>  *
>  * The raw ch0 and ch1 values of the ambient light sensed in the last
>  * integration cycle are read from the device. The raw values are multiplied
>  * by a device-specific scale factor, and divided by the integration time and
>  * device gain. The code supports multiple lux equations through the lux table
>  * coefficients. A lux gain trim is applied to each lux equation, and then the
>  * maximum lux within the interval 0..65535 is selected.
>  */
> static int tsl2772_get_lux(struct iio_dev *indio_dev)
> {
> 	struct tsl2772_chip *chip = iio_priv(indio_dev);
> 	struct tsl2772_lux *p;
> 	int max_lux, ret;
> 	bool overflow;
> 
> 	mutex_lock(&chip->als_mutex);
> 
> 	if (chip->tsl2772_chip_status != TSL2772_CHIP_WORKING) {
> 		dev_err(&chip->client->dev, "%s: device is not enabled\n",
> 			__func__);
> 		ret = -EBUSY;
> 		goto out_unlock;
> 	}
> 
> 	ret = tsl2772_read_status(chip);
> 	if (ret < 0)
> 		goto out_unlock;
> 
> 	if (!(ret & TSL2772_STA_ADC_VALID)) {
> 		dev_err(&chip->client->dev,
> 			"%s: data not valid yet\n", __func__);
> 		ret = chip->als_cur_info.lux; /* return LAST VALUE */
> 		goto out_unlock;
> 	}
> 
> 	ret = tsl2772_read_autoinc_regs(chip, TSL2772_ALS_CHAN0LO,
> 					TSL2772_ALS_CHAN0HI);
> 	if (ret < 0)
> 		goto out_unlock;
> 	chip->als_cur_info.als_ch0 = ret;
> 
> 	ret = tsl2772_read_autoinc_regs(chip, TSL2772_ALS_CHAN1LO,
> 					TSL2772_ALS_CHAN1HI);
> 	if (ret < 0)
> 		goto out_unlock;
> 	chip->als_cur_info.als_ch1 = ret;
> 
> 	if (chip->als_cur_info.als_ch0 >= chip->als_saturation) {
> 		max_lux = TSL2772_LUX_CALC_OVER_FLOW;
> 		goto update_struct_with_max_lux;
> 	}
> 
> 	if (!chip->als_cur_info.als_ch0) {
> 		/* have no data, so return LAST VALUE */
> 		ret = chip->als_cur_info.lux;
> 		goto out_unlock;
> 	}
> 
> 	max_lux = 0;
> 	overflow = false;
> 	for (p = (struct tsl2772_lux *)chip->tsl2772_device_lux; p->ch0 != 0;
> 	     p++) {
> 		int lux;
> 
> 		lux = ((chip->als_cur_info.als_ch0 * p->ch0) -
> 		       (chip->als_cur_info.als_ch1 * p->ch1)) /
> 			chip->als_gain_time_scale;
> 
> 		/*
> 		 * The als_gain_trim can have a value within the range 250..4000
> 		 * and is a multiplier for the lux. A trim of 1000 makes no
> 		 * changes to the lux, less than 1000 scales it down, and
> 		 * greater than 1000 scales it up.
> 		 */
> 		lux = (lux * chip->settings.als_gain_trim) / 1000;
> 
> 		if (lux > TSL2772_LUX_CALC_OVER_FLOW) {
> 			overflow = true;
> 			continue;
> 		}
> 
> 		max_lux = max(max_lux, lux);
> 	}
> 
> 	if (overflow && max_lux == 0)
> 		max_lux = TSL2772_LUX_CALC_OVER_FLOW;
> 
> update_struct_with_max_lux:
> 	chip->als_cur_info.lux = max_lux;
> 	ret = max_lux;
> 
> out_unlock:
> 	mutex_unlock(&chip->als_mutex);
> 
> 	return ret;
> }
> 
> /**
>  * tsl2772_get_prox() - Reads proximity data registers and updates
>  *                      chip->prox_data.
>  *
>  * @indio_dev:	pointer to IIO device
>  */
> static int tsl2772_get_prox(struct iio_dev *indio_dev)
> {
> 	struct tsl2772_chip *chip = iio_priv(indio_dev);
> 	int ret;
> 
> 	mutex_lock(&chip->prox_mutex);
> 
> 	ret = tsl2772_read_status(chip);
> 	if (ret < 0)
> 		goto prox_poll_err;
> 
> 	switch (chip->id) {
> 	case tsl2571:
> 	case tsl2671:
> 	case tmd2671:
> 	case tsl2771:
> 	case tmd2771:
> 		if (!(ret & TSL2772_STA_ADC_VALID)) {
> 			ret = -EINVAL;
> 			goto prox_poll_err;
> 		}
> 		break;
> 	case tsl2572:
> 	case tsl2672:
> 	case tmd2672:
> 	case tsl2772:
> 	case tmd2772:
> 		if (!(ret & TSL2772_STA_PRX_VALID)) {
> 			ret = -EINVAL;
> 			goto prox_poll_err;
> 		}
> 		break;
> 	}
> 
> 	ret = tsl2772_read_autoinc_regs(chip, TSL2772_PRX_LO, TSL2772_PRX_HI);
> 	if (ret < 0)
> 		goto prox_poll_err;
> 	chip->prox_data = ret;
> 
> prox_poll_err:
> 	mutex_unlock(&chip->prox_mutex);
> 
> 	return ret;
> }
> 
> /**
>  * tsl2772_defaults() - Populates the device nominal operating parameters
>  *                      with those provided by a 'platform' data struct or
>  *                      with prefined defaults.
>  *
>  * @chip:               pointer to device structure.
>  */
> static void tsl2772_defaults(struct tsl2772_chip *chip)
> {
> 	/* If Operational settings defined elsewhere.. */
> 	if (chip->pdata && chip->pdata->platform_default_settings)
> 		memcpy(&chip->settings, chip->pdata->platform_default_settings,
> 		       sizeof(tsl2772_default_settings));
> 	else
> 		memcpy(&chip->settings, &tsl2772_default_settings,
> 		       sizeof(tsl2772_default_settings));
> 
> 	/* Load up the proper lux table. */
> 	if (chip->pdata && chip->pdata->platform_lux_table[0].ch0 != 0)
> 		memcpy(chip->tsl2772_device_lux,
> 		       chip->pdata->platform_lux_table,
> 		       sizeof(chip->pdata->platform_lux_table));
> 	else
> 		memcpy(chip->tsl2772_device_lux,
> 		       tsl2772_default_lux_table_group[chip->id],
> 		       TSL2772_DEFAULT_TABLE_BYTES);
> }
> 
> /**
>  * tsl2772_als_calibrate() -	Obtain single reading and calculate
>  *                              the als_gain_trim.
>  *
>  * @indio_dev:	pointer to IIO device
>  */
> static int tsl2772_als_calibrate(struct iio_dev *indio_dev)
> {
> 	struct tsl2772_chip *chip = iio_priv(indio_dev);
> 	int ret, lux_val;
> 
> 	ret = i2c_smbus_read_byte_data(chip->client,
> 				       TSL2772_CMD_REG | TSL2772_CNTRL);
> 	if (ret < 0) {
> 		dev_err(&chip->client->dev,
> 			"%s: failed to read from the CNTRL register\n",
> 			__func__);
> 		return ret;
> 	}
> 
> 	if ((ret & (TSL2772_CNTL_ADC_ENBL | TSL2772_CNTL_PWR_ON))
> 			!= (TSL2772_CNTL_ADC_ENBL | TSL2772_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 & TSL2772_STA_ADC_VALID) != TSL2772_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 = tsl2772_get_lux(indio_dev);
> 	if (lux_val < 0) {
> 		dev_err(&chip->client->dev,
> 			"%s: failed to get lux\n", __func__);
> 		return lux_val;
> 	}
> 
> 	ret = (chip->settings.als_cal_target * chip->settings.als_gain_trim) /
> 			lux_val;
> 	if (ret < 250 || ret > 4000)
> 		return -ERANGE;
> 
> 	chip->settings.als_gain_trim = ret;
> 
> 	return ret;
> }
> 
> static int tsl2772_chip_on(struct iio_dev *indio_dev)
> {
> 	struct tsl2772_chip *chip = iio_priv(indio_dev);
> 	int ret, i, als_count, als_time_us;
> 	u8 *dev_reg, reg_val;
> 
> 	/* Non calculated parameters */
> 	chip->tsl2772_config[TSL2772_ALS_TIME] = chip->settings.als_time;
> 	chip->tsl2772_config[TSL2772_PRX_TIME] = chip->settings.prox_time;
> 	chip->tsl2772_config[TSL2772_WAIT_TIME] = chip->settings.wait_time;
> 	chip->tsl2772_config[TSL2772_ALS_PRX_CONFIG] =
> 		chip->settings.als_prox_config;
> 
> 	chip->tsl2772_config[TSL2772_ALS_MINTHRESHLO] =
> 		(chip->settings.als_thresh_low) & 0xFF;
> 	chip->tsl2772_config[TSL2772_ALS_MINTHRESHHI] =
> 		(chip->settings.als_thresh_low >> 8) & 0xFF;
> 	chip->tsl2772_config[TSL2772_ALS_MAXTHRESHLO] =
> 		(chip->settings.als_thresh_high) & 0xFF;
> 	chip->tsl2772_config[TSL2772_ALS_MAXTHRESHHI] =
> 		(chip->settings.als_thresh_high >> 8) & 0xFF;
> 	chip->tsl2772_config[TSL2772_PERSISTENCE] =
> 		(chip->settings.prox_persistence & 0xFF) << 4 |
> 		(chip->settings.als_persistence & 0xFF);
> 
> 	chip->tsl2772_config[TSL2772_PRX_COUNT] =
> 			chip->settings.prox_pulse_count;
> 	chip->tsl2772_config[TSL2772_PRX_MINTHRESHLO] =
> 			(chip->settings.prox_thres_low) & 0xFF;
> 	chip->tsl2772_config[TSL2772_PRX_MINTHRESHHI] =
> 			(chip->settings.prox_thres_low >> 8) & 0xFF;
> 	chip->tsl2772_config[TSL2772_PRX_MAXTHRESHLO] =
> 			(chip->settings.prox_thres_high) & 0xFF;
> 	chip->tsl2772_config[TSL2772_PRX_MAXTHRESHHI] =
> 			(chip->settings.prox_thres_high >> 8) & 0xFF;
> 
> 	/* and make sure we're not already on */
> 	if (chip->tsl2772_chip_status == TSL2772_CHIP_WORKING) {
> 		/* if forcing a register update - turn off, then on */
> 		dev_info(&chip->client->dev, "device is already enabled\n");
> 		return -EINVAL;
> 	}
> 
> 	/* Set the gain based on tsl2772_settings struct */
> 	chip->tsl2772_config[TSL2772_GAIN] =
> 		(chip->settings.als_gain & 0xFF) |
> 		((chip->settings.prox_gain & 0xFF) << 2) |
> 		(chip->settings.prox_diode << 4) |
> 		(chip->settings.prox_power << 6);
> 
> 	/* set chip time scaling and saturation */
> 	als_count = 256 - chip->settings.als_time;
> 	als_time_us = als_count * tsl2772_int_time[chip->id].increment_us;
> 	chip->als_saturation = als_count * 768; /* 75% of full scale */
> 	chip->als_gain_time_scale = als_time_us *
> 		tsl2772_als_gain[chip->settings.als_gain];
> 
> 	/*
> 	 * TSL2772 Specific power-on / adc enable sequence
> 	 * Power on the device 1st.
> 	 */
> 	ret = tsl2772_write_control_reg(chip, TSL2772_CNTL_PWR_ON);
> 	if (ret < 0)
> 		return ret;
> 
> 	/*
> 	 * Use the following shadow copy for our delay before enabling ADC.
> 	 * Write all the registers.
> 	 */
> 	for (i = 0, dev_reg = chip->tsl2772_config;
> 			i < TSL2772_MAX_CONFIG_REG; i++) {
> 		int reg = TSL2772_CMD_REG + i;
> 
> 		ret = i2c_smbus_write_byte_data(chip->client, reg,
> 						*dev_reg++);
> 		if (ret < 0) {
> 			dev_err(&chip->client->dev,
> 				"%s: failed to write to register %x: %d\n",
> 				__func__, reg, ret);
> 			return ret;
> 		}
> 	}
> 
> 	/* Power-on settling time */
> 	usleep_range(3000, 3500);
> 
> 	reg_val = TSL2772_CNTL_PWR_ON | TSL2772_CNTL_ADC_ENBL |
> 		  TSL2772_CNTL_PROX_DET_ENBL;
> 	if (chip->settings.als_interrupt_en)
> 		reg_val |= TSL2772_CNTL_ALS_INT_ENBL;
> 	if (chip->settings.prox_interrupt_en)
> 		reg_val |= TSL2772_CNTL_PROX_INT_ENBL;
> 
> 	ret = tsl2772_write_control_reg(chip, reg_val);
> 	if (ret < 0)
> 		return ret;
> 
> 	ret = i2c_smbus_write_byte(chip->client,
> 				   TSL2772_CMD_REG | TSL2772_CMD_SPL_FN |
> 				   TSL2772_CMD_PROXALS_INT_CLR);
> 	if (ret < 0) {
> 		dev_err(&chip->client->dev,
> 			"%s: failed to clear interrupt status: %d\n",
> 			__func__, ret);
> 		return ret;
> 	}
> 
> 	chip->tsl2772_chip_status = TSL2772_CHIP_WORKING;
> 
> 	return ret;
> }
> 
> static int tsl2772_chip_off(struct iio_dev *indio_dev)
> {
> 	struct tsl2772_chip *chip = iio_priv(indio_dev);
> 
> 	/* turn device off */
> 	chip->tsl2772_chip_status = TSL2772_CHIP_SUSPENDED;
> 	return tsl2772_write_control_reg(chip, 0x00);
> }
> 
> /**
>  * tsl2772_invoke_change - power cycle the device to implement the user
>  *                         parameters
>  * @indio_dev:	pointer to IIO device
>  *
>  * Obtain and lock both ALS and PROX resources, determine and save device state
>  * (On/Off), cycle device to implement updated parameter, put device back into
>  * proper state, and unlock resource.
>  */
> static int tsl2772_invoke_change(struct iio_dev *indio_dev)
> {
> 	struct tsl2772_chip *chip = iio_priv(indio_dev);
> 	int device_status = chip->tsl2772_chip_status;
> 	int ret;
> 
> 	mutex_lock(&chip->als_mutex);
> 	mutex_lock(&chip->prox_mutex);
> 
> 	if (device_status == TSL2772_CHIP_WORKING) {
> 		ret = tsl2772_chip_off(indio_dev);
> 		if (ret < 0)
> 			goto unlock;
> 	}
> 
> 	ret = tsl2772_chip_on(indio_dev);
> 
> unlock:
> 	mutex_unlock(&chip->prox_mutex);
> 	mutex_unlock(&chip->als_mutex);
> 
> 	return ret;
> }
> 
> static int tsl2772_prox_cal(struct iio_dev *indio_dev)
> {
> 	struct tsl2772_chip *chip = iio_priv(indio_dev);
> 	int prox_history[MAX_SAMPLES_CAL + 1];
> 	int i, ret, mean, max, sample_sum;
> 
> 	if (chip->settings.prox_max_samples_cal < 1 ||
> 	    chip->settings.prox_max_samples_cal > MAX_SAMPLES_CAL)
> 		return -EINVAL;
> 
> 	for (i = 0; i < chip->settings.prox_max_samples_cal; i++) {
> 		usleep_range(15000, 17500);
> 		ret = tsl2772_get_prox(indio_dev);
> 		if (ret < 0)
> 			return ret;
> 
> 		prox_history[i] = chip->prox_data;
> 	}
> 
> 	sample_sum = 0;
> 	max = INT_MIN;
> 	for (i = 0; i < chip->settings.prox_max_samples_cal; i++) {
> 		sample_sum += prox_history[i];
> 		max = max(max, prox_history[i]);
> 	}
> 	mean = sample_sum / chip->settings.prox_max_samples_cal;
> 
> 	chip->settings.prox_thres_high = (max << 1) - mean;
> 
> 	return tsl2772_invoke_change(indio_dev);
> }
> 
> static IIO_CONST_ATTR(in_intensity0_calibscale_available, "1 8 16 120");
> 
> static IIO_CONST_ATTR(in_proximity0_calibscale_available, "1 2 4 8");
> 
> static ssize_t
> in_intensity0_integration_time_available_show(struct device *dev,
> 					      struct device_attribute *attr,
> 					      char *buf)
> {
> 	struct tsl2772_chip *chip = iio_priv(dev_to_iio_dev(dev));
> 
> 	return snprintf(buf, PAGE_SIZE, "%s\n",
> 			tsl2772_int_time[chip->id].display_range);
> }
> 
> static ssize_t in_illuminance0_target_input_show(struct device *dev,
> 						 struct device_attribute *attr,
> 						 char *buf)
> {
> 	struct tsl2772_chip *chip = iio_priv(dev_to_iio_dev(dev));
> 
> 	return snprintf(buf, PAGE_SIZE, "%d\n", chip->settings.als_cal_target);
> }
> 
> static ssize_t in_illuminance0_target_input_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 tsl2772_chip *chip = iio_priv(indio_dev);
> 	u16 value;
> 	int ret;
> 
> 	if (kstrtou16(buf, 0, &value))
> 		return -EINVAL;
> 
> 	chip->settings.als_cal_target = value;
> 	ret = tsl2772_invoke_change(indio_dev);
> 	if (ret < 0)
> 		return ret;
> 
> 	return len;
> }
> 
> static ssize_t in_illuminance0_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);
> 	bool value;
> 	int ret;
> 
> 	if (kstrtobool(buf, &value) || !value)
> 		return -EINVAL;
> 
> 	ret = tsl2772_als_calibrate(indio_dev);
> 	if (ret < 0)
> 		return ret;
> 
> 	ret = tsl2772_invoke_change(indio_dev);
> 	if (ret < 0)
> 		return ret;
> 
> 	return len;
> }
> 
> static ssize_t in_illuminance0_lux_table_show(struct device *dev,
> 					      struct device_attribute *attr,
> 					      char *buf)
> {
> 	struct tsl2772_chip *chip = iio_priv(dev_to_iio_dev(dev));
> 	int i = 0;
> 	int offset = 0;
> 
> 	while (i < TSL2772_MAX_LUX_TABLE_SIZE) {
> 		offset += snprintf(buf + offset, PAGE_SIZE, "%u,%u,",
> 			chip->tsl2772_device_lux[i].ch0,
> 			chip->tsl2772_device_lux[i].ch1);
> 		if (chip->tsl2772_device_lux[i].ch0 == 0) {
> 			/*
> 			 * We just printed the first "0" entry.
> 			 * Now get rid of the extra "," and break.
> 			 */
> 			offset--;
> 			break;
> 		}
> 		i++;
> 	}
> 
> 	offset += snprintf(buf + offset, PAGE_SIZE, "\n");
> 	return offset;
> }
> 
> static ssize_t in_illuminance0_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 tsl2772_chip *chip = iio_priv(indio_dev);
> 	int value[ARRAY_SIZE(chip->tsl2772_device_lux) * 2 + 1];
> 	int n, ret;
> 
> 	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 two ints to be one table entry,
> 	 * and the last table entry is all 0.
> 	 */
> 	n = value[0];
> 	if ((n % 2) || n < 4 ||
> 	    n > ((ARRAY_SIZE(chip->tsl2772_device_lux) - 1) * 2))
> 		return -EINVAL;
> 
> 	if ((value[(n - 1)] | value[n]) != 0)
> 		return -EINVAL;
> 
> 	if (chip->tsl2772_chip_status == TSL2772_CHIP_WORKING) {
> 		ret = tsl2772_chip_off(indio_dev);
> 		if (ret < 0)
> 			return ret;
> 	}
> 
> 	/* Zero out the table */
> 	memset(chip->tsl2772_device_lux, 0, sizeof(chip->tsl2772_device_lux));
> 	memcpy(chip->tsl2772_device_lux, &value[1], (value[0] * 4));
> 
> 	ret = tsl2772_invoke_change(indio_dev);
> 	if (ret < 0)
> 		return ret;
> 
> 	return len;
> }
> 
> static ssize_t in_proximity0_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);
> 	bool value;
> 	int ret;
> 
> 	if (kstrtobool(buf, &value) || !value)
> 		return -EINVAL;
> 
> 	ret = tsl2772_prox_cal(indio_dev);
> 	if (ret < 0)
> 		return ret;
> 
> 	ret = tsl2772_invoke_change(indio_dev);
> 	if (ret < 0)
> 		return ret;
> 
> 	return len;
> }
> 
> static int tsl2772_read_interrupt_config(struct iio_dev *indio_dev,
> 					 const struct iio_chan_spec *chan,
> 					 enum iio_event_type type,
> 					 enum iio_event_direction dir)
> {
> 	struct tsl2772_chip *chip = iio_priv(indio_dev);
> 
> 	if (chan->type == IIO_INTENSITY)
> 		return chip->settings.als_interrupt_en;
> 	else
> 		return chip->settings.prox_interrupt_en;
> }
> 
> static int tsl2772_write_interrupt_config(struct iio_dev *indio_dev,
> 					  const struct iio_chan_spec *chan,
> 					  enum iio_event_type type,
> 					  enum iio_event_direction dir,
> 					  int val)
> {
> 	struct tsl2772_chip *chip = iio_priv(indio_dev);
> 
> 	if (chan->type == IIO_INTENSITY)
> 		chip->settings.als_interrupt_en = val ? true : false;
> 	else
> 		chip->settings.prox_interrupt_en = val ? true : false;
> 
> 	return tsl2772_invoke_change(indio_dev);
> }
> 
> static int tsl2772_write_event_value(struct iio_dev *indio_dev,
> 				     const struct iio_chan_spec *chan,
> 				     enum iio_event_type type,
> 				     enum iio_event_direction dir,
> 				     enum iio_event_info info,
> 				     int val, int val2)
> {
> 	struct tsl2772_chip *chip = iio_priv(indio_dev);
> 	int ret = -EINVAL, count, persistence;
> 	u8 time;
> 
> 	switch (info) {
> 	case IIO_EV_INFO_VALUE:
> 		if (chan->type == IIO_INTENSITY) {
> 			switch (dir) {
> 			case IIO_EV_DIR_RISING:
> 				chip->settings.als_thresh_high = val;
> 				ret = 0;
> 				break;
> 			case IIO_EV_DIR_FALLING:
> 				chip->settings.als_thresh_low = val;
> 				ret = 0;
> 				break;
> 			default:
> 				break;
> 			}
> 		} else {
> 			switch (dir) {
> 			case IIO_EV_DIR_RISING:
> 				chip->settings.prox_thres_high = val;
> 				ret = 0;
> 				break;
> 			case IIO_EV_DIR_FALLING:
> 				chip->settings.prox_thres_low = val;
> 				ret = 0;
> 				break;
> 			default:
> 				break;
> 			}
> 		}
> 		break;
> 	case IIO_EV_INFO_PERIOD:
> 		if (chan->type == IIO_INTENSITY)
> 			time = chip->settings.als_time;
> 		else
> 			time = chip->settings.prox_time;
> 
> 		count = 256 - time;
> 		persistence = ((val * 1000000) + val2) /
> 			(count * tsl2772_int_time[chip->id].increment_us);
> 
> 		if (chan->type == IIO_INTENSITY) {
> 			/* ALS filter values are 1, 2, 3, 5, 10, 15, ..., 60 */
> 			if (persistence > 3)
> 				persistence = (persistence / 5) + 3;
> 
> 			chip->settings.als_persistence = persistence;
> 		} else {
> 			chip->settings.prox_persistence = persistence;
> 		}
> 
> 		ret = 0;
> 		break;
> 	default:
> 		break;
> 	}
> 
> 	if (ret < 0)
> 		return ret;
> 
> 	return tsl2772_invoke_change(indio_dev);
> }
> 
> static int tsl2772_read_event_value(struct iio_dev *indio_dev,
> 				    const struct iio_chan_spec *chan,
> 				    enum iio_event_type type,
> 				    enum iio_event_direction dir,
> 				    enum iio_event_info info,
> 				    int *val, int *val2)
> {
> 	struct tsl2772_chip *chip = iio_priv(indio_dev);
> 	int ret = -EINVAL, filter_delay, persistence;
> 	u8 time;
> 
> 	switch (info) {
> 	case IIO_EV_INFO_VALUE:
> 		if (chan->type == IIO_INTENSITY) {
> 			switch (dir) {
> 			case IIO_EV_DIR_RISING:
> 				*val = chip->settings.als_thresh_high;
> 				ret = IIO_VAL_INT;
> 				break;
> 			case IIO_EV_DIR_FALLING:
> 				*val = chip->settings.als_thresh_low;
> 				ret = IIO_VAL_INT;
> 				break;
> 			default:
> 				break;
> 			}
> 		} else {
> 			switch (dir) {
> 			case IIO_EV_DIR_RISING:
> 				*val = chip->settings.prox_thres_high;
> 				ret = IIO_VAL_INT;
> 				break;
> 			case IIO_EV_DIR_FALLING:
> 				*val = chip->settings.prox_thres_low;
> 				ret = IIO_VAL_INT;
> 				break;
> 			default:
> 				break;
> 			}
> 		}
> 		break;
> 	case IIO_EV_INFO_PERIOD:
> 		if (chan->type == IIO_INTENSITY) {
> 			time = chip->settings.als_time;
> 			persistence = chip->settings.als_persistence;
> 
> 			/* ALS filter values are 1, 2, 3, 5, 10, 15, ..., 60 */
> 			if (persistence > 3)
> 				persistence = (persistence - 3) * 5;
> 		} else {
> 			time = chip->settings.prox_time;
> 			persistence = chip->settings.prox_persistence;
> 		}
> 
> 		filter_delay = persistence * (256 - time) *
> 			tsl2772_int_time[chip->id].increment_us;
> 
> 		*val = filter_delay / 1000000;
> 		*val2 = filter_delay % 1000000;
> 		ret = IIO_VAL_INT_PLUS_MICRO;

Direct returns would be neater in here than break then return.

> 		break;
> 	default:
> 		break;
> 	}
> 
> 	return ret;
> }
> 
> static int tsl2772_read_raw(struct iio_dev *indio_dev,
> 			    struct iio_chan_spec const *chan,
> 			    int *val,
> 			    int *val2,
> 			    long mask)
> {
> 	struct tsl2772_chip *chip = iio_priv(indio_dev);
> 	int ret = -EINVAL;
> 
> 	switch (mask) {
> 	case IIO_CHAN_INFO_PROCESSED:
> 		switch (chan->type) {
> 		case IIO_LIGHT:
> 			tsl2772_get_lux(indio_dev);
> 			*val = chip->als_cur_info.lux;
> 			ret = IIO_VAL_INT;
> 			break;
> 		default:
> 			return -EINVAL;
> 		}
> 		break;
> 	case IIO_CHAN_INFO_RAW:
> 		switch (chan->type) {
> 		case IIO_INTENSITY:
> 			tsl2772_get_lux(indio_dev);
> 			if (chan->channel == 0)
> 				*val = chip->als_cur_info.als_ch0;
> 			else
> 				*val = chip->als_cur_info.als_ch1;
> 			ret = IIO_VAL_INT;
> 			break;
> 		case IIO_PROXIMITY:
> 			tsl2772_get_prox(indio_dev);
> 			*val = chip->prox_data;
> 			ret = IIO_VAL_INT;
> 			break;
> 		default:
> 			return -EINVAL;
> 		}
> 		break;
> 	case IIO_CHAN_INFO_CALIBSCALE:
> 		if (chan->type == IIO_LIGHT)
> 			*val = tsl2772_als_gain[chip->settings.als_gain];
> 		else
> 			*val = tsl2772_prox_gain[chip->settings.prox_gain];
> 		ret = IIO_VAL_INT;
> 		break;
> 	case IIO_CHAN_INFO_CALIBBIAS:
> 		*val = chip->settings.als_gain_trim;
> 		ret = IIO_VAL_INT;
> 		break;
> 	case IIO_CHAN_INFO_INT_TIME:
> 		*val = 0;
> 		*val2 = (256 - chip->settings.als_time) *
> 			tsl2772_int_time[chip->id].increment_us;
> 		ret = IIO_VAL_INT_PLUS_MICRO;
> 		break;
> 	default:
> 		ret = -EINVAL;
> 	}
> 
> 	return ret;
> }
> 
> static int tsl2772_write_raw(struct iio_dev *indio_dev,
> 			     struct iio_chan_spec const *chan,
> 			     int val,
> 			     int val2,
> 			     long mask)
> {
> 	struct tsl2772_chip *chip = iio_priv(indio_dev);
> 
> 	switch (mask) {
> 	case IIO_CHAN_INFO_CALIBSCALE:
> 		if (chan->type == IIO_INTENSITY) {
> 			switch (val) {
> 			case 1:
> 				chip->settings.als_gain = 0;
> 				break;
> 			case 8:
> 				chip->settings.als_gain = 1;
> 				break;
> 			case 16:
> 				chip->settings.als_gain = 2;
> 				break;
> 			case 120:
> 				chip->settings.als_gain = 3;
> 				break;
> 			default:
> 				return -EINVAL;
> 			}
> 		} else {
> 			switch (val) {
> 			case 1:
> 				chip->settings.prox_gain = 0;
> 				break;
> 			case 2:
> 				chip->settings.prox_gain = 1;
> 				break;
> 			case 4:
> 				chip->settings.prox_gain = 2;
> 				break;
> 			case 8:
> 				chip->settings.prox_gain = 3;
> 				break;
> 			default:
> 				return -EINVAL;
> 			}
> 		}
> 		break;
> 	case IIO_CHAN_INFO_CALIBBIAS:
> 		chip->settings.als_gain_trim = val;
> 		break;
> 	case IIO_CHAN_INFO_INT_TIME:
> 		chip->settings.als_time = 256 -
> 			(val2 / tsl2772_int_time[chip->id].increment_us);
> 		break;
> 	default:
> 		return -EINVAL;
> 	}
> 
> 	return tsl2772_invoke_change(indio_dev);
> }
> 
> static DEVICE_ATTR_RO(in_intensity0_integration_time_available);
> 
> static DEVICE_ATTR_RW(in_illuminance0_target_input);
> 
> static DEVICE_ATTR_WO(in_illuminance0_calibrate);
> 
> static DEVICE_ATTR_WO(in_proximity0_calibrate);
> 
> static DEVICE_ATTR_RW(in_illuminance0_lux_table);
> 
> /* Use the default register values to identify the Taos device */
> static int tsl2772_device_id_verif(int id, int target)
> {
> 	switch (target) {
> 	case tsl2571:
> 	case tsl2671:
> 	case tsl2771:
> 		return (id & 0xf0) == TRITON_ID;
> 	case tmd2671:
> 	case tmd2771:
> 		return (id & 0xf0) == HALIBUT_ID;
> 	case tsl2572:
> 	case tsl2672:
> 	case tmd2672:
> 	case tsl2772:
> 	case tmd2772:
> 		return (id & 0xf0) == SWORDFISH_ID;
> 	}
> 
> 	return -EINVAL;
> }
> 
> static irqreturn_t tsl2772_event_handler(int irq, void *private)
> {
> 	struct iio_dev *indio_dev = private;
> 	struct tsl2772_chip *chip = iio_priv(indio_dev);
> 	s64 timestamp = iio_get_time_ns(indio_dev);
> 	int ret;
> 
> 	ret = tsl2772_read_status(chip);
> 	if (ret < 0)
> 		return IRQ_HANDLED;
> 
> 	/* What type of interrupt do we need to process */
> 	if (ret & TSL2772_STA_PRX_INTR) {
> 		iio_push_event(indio_dev,
> 			       IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY,
> 						    0,
> 						    IIO_EV_TYPE_THRESH,
> 						    IIO_EV_DIR_EITHER),
> 						    timestamp);
> 	}
> 
> 	if (ret & TSL2772_STA_ALS_INTR) {
> 		iio_push_event(indio_dev,
> 			       IIO_UNMOD_EVENT_CODE(IIO_LIGHT,
> 						    0,
> 						    IIO_EV_TYPE_THRESH,
> 						    IIO_EV_DIR_EITHER),
> 			       timestamp);
> 	}
> 
> 	ret = i2c_smbus_write_byte(chip->client,
> 				   TSL2772_CMD_REG | TSL2772_CMD_SPL_FN |
> 				   TSL2772_CMD_PROXALS_INT_CLR);
> 	if (ret < 0)
> 		dev_err(&chip->client->dev,
> 			"%s: failed to clear interrupt status: %d\n",
> 			__func__, ret);
> 
> 	return IRQ_HANDLED;
> }
> 
> static struct attribute *tsl2772_ALS_device_attrs[] = {
> 	&iio_const_attr_in_intensity0_calibscale_available.dev_attr.attr,
> 	&dev_attr_in_intensity0_integration_time_available.attr,
> 	&dev_attr_in_illuminance0_target_input.attr,
> 	&dev_attr_in_illuminance0_calibrate.attr,
> 	&dev_attr_in_illuminance0_lux_table.attr,
> 	NULL
> };
> 
> static struct attribute *tsl2772_PRX_device_attrs[] = {
> 	&dev_attr_in_proximity0_calibrate.attr,
> 	NULL
> };
> 
> static struct attribute *tsl2772_ALSPRX_device_attrs[] = {
> 	&iio_const_attr_in_intensity0_calibscale_available.dev_attr.attr,
> 	&dev_attr_in_intensity0_integration_time_available.attr,
> 	&dev_attr_in_illuminance0_target_input.attr,
> 	&dev_attr_in_illuminance0_calibrate.attr,
> 	&dev_attr_in_illuminance0_lux_table.attr,
> 	NULL
> };
> 
> static struct attribute *tsl2772_PRX2_device_attrs[] = {
> 	&dev_attr_in_proximity0_calibrate.attr,
> 	&iio_const_attr_in_proximity0_calibscale_available.dev_attr.attr,
> 	NULL
> };
> 
> static struct attribute *tsl2772_ALSPRX2_device_attrs[] = {
> 	&iio_const_attr_in_intensity0_calibscale_available.dev_attr.attr,
> 	&dev_attr_in_intensity0_integration_time_available.attr,
> 	&dev_attr_in_illuminance0_target_input.attr,
> 	&dev_attr_in_illuminance0_calibrate.attr,
> 	&dev_attr_in_illuminance0_lux_table.attr,
> 	&dev_attr_in_proximity0_calibrate.attr,
> 	&iio_const_attr_in_proximity0_calibscale_available.dev_attr.attr,
> 	NULL
> };
> 
> static const struct attribute_group tsl2772_device_attr_group_tbl[] = {
> 	[ALS] = {
> 		.attrs = tsl2772_ALS_device_attrs,
> 	},
> 	[PRX] = {
> 		.attrs = tsl2772_PRX_device_attrs,
> 	},
> 	[ALSPRX] = {
> 		.attrs = tsl2772_ALSPRX_device_attrs,
> 	},
> 	[PRX2] = {
> 		.attrs = tsl2772_PRX2_device_attrs,
> 	},
> 	[ALSPRX2] = {
> 		.attrs = tsl2772_ALSPRX2_device_attrs,
> 	},
> };
> 
> static const struct iio_info tsl2772_device_info[] = {
> 	[ALS] = {

These blocks would perhaps benefit from a macro as the only
difference (at first glance anyway) is the array index.

> 		.attrs = &tsl2772_device_attr_group_tbl[ALS],
> 		.read_raw = &tsl2772_read_raw,
> 		.write_raw = &tsl2772_write_raw,
> 		.read_event_value = &tsl2772_read_event_value,
> 		.write_event_value = &tsl2772_write_event_value,
> 		.read_event_config = &tsl2772_read_interrupt_config,
> 		.write_event_config = &tsl2772_write_interrupt_config,
> 	},
> 	[PRX] = {
> 		.attrs = &tsl2772_device_attr_group_tbl[PRX],
> 		.read_raw = &tsl2772_read_raw,
> 		.write_raw = &tsl2772_write_raw,
> 		.read_event_value = &tsl2772_read_event_value,
> 		.write_event_value = &tsl2772_write_event_value,
> 		.read_event_config = &tsl2772_read_interrupt_config,
> 		.write_event_config = &tsl2772_write_interrupt_config,
> 	},
> 	[ALSPRX] = {
> 		.attrs = &tsl2772_device_attr_group_tbl[ALSPRX],
> 		.read_raw = &tsl2772_read_raw,
> 		.write_raw = &tsl2772_write_raw,
> 		.read_event_value = &tsl2772_read_event_value,
> 		.write_event_value = &tsl2772_write_event_value,
> 		.read_event_config = &tsl2772_read_interrupt_config,
> 		.write_event_config = &tsl2772_write_interrupt_config,
> 	},
> 	[PRX2] = {
> 		.attrs = &tsl2772_device_attr_group_tbl[PRX2],
> 		.read_raw = &tsl2772_read_raw,
> 		.write_raw = &tsl2772_write_raw,
> 		.read_event_value = &tsl2772_read_event_value,
> 		.write_event_value = &tsl2772_write_event_value,
> 		.read_event_config = &tsl2772_read_interrupt_config,
> 		.write_event_config = &tsl2772_write_interrupt_config,
> 	},
> 	[ALSPRX2] = {
> 		.attrs = &tsl2772_device_attr_group_tbl[ALSPRX2],
> 		.read_raw = &tsl2772_read_raw,
> 		.write_raw = &tsl2772_write_raw,
> 		.read_event_value = &tsl2772_read_event_value,
> 		.write_event_value = &tsl2772_write_event_value,
> 		.read_event_config = &tsl2772_read_interrupt_config,
> 		.write_event_config = &tsl2772_write_interrupt_config,
> 	},
> };
> 
> static const struct iio_event_spec tsl2772_events[] = {
> 	{
> 		.type = IIO_EV_TYPE_THRESH,
> 		.dir = IIO_EV_DIR_RISING,
> 		.mask_separate = BIT(IIO_EV_INFO_VALUE),
> 	}, {
> 		.type = IIO_EV_TYPE_THRESH,
> 		.dir = IIO_EV_DIR_FALLING,
> 		.mask_separate = BIT(IIO_EV_INFO_VALUE),
> 	}, {
> 		.type = IIO_EV_TYPE_THRESH,
> 		.dir = IIO_EV_DIR_EITHER,
> 		.mask_separate = BIT(IIO_EV_INFO_PERIOD) |
> 			BIT(IIO_EV_INFO_ENABLE),
> 	},
> };
> 
> static const struct tsl2772_chip_info tsl2772_chip_info_tbl[] = {
> 	[ALS] = {
> 		.channel_with_events = {
> 			{
> 			.type = IIO_LIGHT,
> 			.indexed = 1,
> 			.channel = 0,
> 			.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
> 			}, {
> 			.type = IIO_INTENSITY,
> 			.indexed = 1,
> 			.channel = 0,
> 			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> 				BIT(IIO_CHAN_INFO_INT_TIME) |
> 				BIT(IIO_CHAN_INFO_CALIBSCALE) |
> 				BIT(IIO_CHAN_INFO_CALIBBIAS),
> 			.event_spec = tsl2772_events,
> 			.num_event_specs = ARRAY_SIZE(tsl2772_events),
> 			}, {
> 			.type = IIO_INTENSITY,
> 			.indexed = 1,
> 			.channel = 1,
> 			},
> 		},
> 		.channel_without_events = {
> 			{
> 			.type = IIO_LIGHT,
> 			.indexed = 1,
> 			.channel = 0,
> 			.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
> 			}, {
> 			.type = IIO_INTENSITY,
> 			.indexed = 1,
> 			.channel = 0,
> 			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> 				BIT(IIO_CHAN_INFO_INT_TIME) |
> 				BIT(IIO_CHAN_INFO_CALIBSCALE) |
> 				BIT(IIO_CHAN_INFO_CALIBBIAS),
> 			}, {
> 			.type = IIO_INTENSITY,
> 			.indexed = 1,
> 			.channel = 1,
> 			},
> 		},
> 		.chan_table_elements = 3,
> 		.info = &tsl2772_device_info[ALS],
> 	},
> 	[PRX] = {
> 		.channel_with_events = {
> 			{
> 			.type = IIO_PROXIMITY,
> 			.indexed = 1,
> 			.channel = 0,
> 			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> 			.event_spec = tsl2772_events,
> 			.num_event_specs = ARRAY_SIZE(tsl2772_events),
> 			},
> 		},
> 		.channel_without_events = {
> 			{
> 			.type = IIO_PROXIMITY,
> 			.indexed = 1,
> 			.channel = 0,
> 			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> 			},
> 		},
> 		.chan_table_elements = 1,
> 		.info = &tsl2772_device_info[PRX],
> 	},
> 	[ALSPRX] = {
> 		.channel_with_events = {
> 			{
> 			.type = IIO_LIGHT,
> 			.indexed = 1,
> 			.channel = 0,
> 			.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
> 			}, {
> 			.type = IIO_INTENSITY,
> 			.indexed = 1,
> 			.channel = 0,
> 			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> 				BIT(IIO_CHAN_INFO_INT_TIME) |
> 				BIT(IIO_CHAN_INFO_CALIBSCALE) |
> 				BIT(IIO_CHAN_INFO_CALIBBIAS),
> 			.event_spec = tsl2772_events,
> 			.num_event_specs = ARRAY_SIZE(tsl2772_events),
> 			}, {
> 			.type = IIO_INTENSITY,
> 			.indexed = 1,
> 			.channel = 1,
> 			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> 			}, {
> 			.type = IIO_PROXIMITY,
> 			.indexed = 1,
> 			.channel = 0,
> 			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> 			.event_spec = tsl2772_events,
> 			.num_event_specs = ARRAY_SIZE(tsl2772_events),
> 			},
> 		},
> 		.channel_without_events = {
> 			{
> 			.type = IIO_LIGHT,
> 			.indexed = 1,
> 			.channel = 0,
> 			.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
> 			}, {
> 			.type = IIO_INTENSITY,
> 			.indexed = 1,
> 			.channel = 0,
> 			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> 				BIT(IIO_CHAN_INFO_INT_TIME) |
> 				BIT(IIO_CHAN_INFO_CALIBSCALE) |
> 				BIT(IIO_CHAN_INFO_CALIBBIAS),
> 			}, {
> 			.type = IIO_INTENSITY,
> 			.indexed = 1,
> 			.channel = 1,
> 			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> 			}, {
> 			.type = IIO_PROXIMITY,
> 			.indexed = 1,
> 			.channel = 0,
> 			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> 			},
> 		},
> 		.chan_table_elements = 4,
> 		.info = &tsl2772_device_info[ALSPRX],
> 	},
> 	[PRX2] = {
> 		.channel_with_events = {
> 			{
> 			.type = IIO_PROXIMITY,
> 			.indexed = 1,
> 			.channel = 0,
> 			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> 				BIT(IIO_CHAN_INFO_CALIBSCALE),
> 			.event_spec = tsl2772_events,
> 			.num_event_specs = ARRAY_SIZE(tsl2772_events),
> 			},
> 		},
> 		.channel_without_events = {
> 			{
> 			.type = IIO_PROXIMITY,
> 			.indexed = 1,
> 			.channel = 0,
> 			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> 				BIT(IIO_CHAN_INFO_CALIBSCALE),
> 			},
> 		},
> 		.chan_table_elements = 1,
> 		.info = &tsl2772_device_info[PRX2],
> 	},
> 	[ALSPRX2] = {
> 		.channel_with_events = {
> 			{
> 			.type = IIO_LIGHT,
> 			.indexed = 1,
> 			.channel = 0,
> 			.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
> 			}, {
> 			.type = IIO_INTENSITY,
> 			.indexed = 1,
> 			.channel = 0,
> 			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> 				BIT(IIO_CHAN_INFO_INT_TIME) |
> 				BIT(IIO_CHAN_INFO_CALIBSCALE) |
> 				BIT(IIO_CHAN_INFO_CALIBBIAS),
> 			.event_spec = tsl2772_events,
> 			.num_event_specs = ARRAY_SIZE(tsl2772_events),
> 			}, {
> 			.type = IIO_INTENSITY,
> 			.indexed = 1,
> 			.channel = 1,
> 			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> 			}, {
> 			.type = IIO_PROXIMITY,
> 			.indexed = 1,
> 			.channel = 0,
> 			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> 				BIT(IIO_CHAN_INFO_CALIBSCALE),
> 			.event_spec = tsl2772_events,
> 			.num_event_specs = ARRAY_SIZE(tsl2772_events),
> 			},
> 		},
> 		.channel_without_events = {
> 			{
> 			.type = IIO_LIGHT,
> 			.indexed = 1,
> 			.channel = 0,
> 			.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
> 			}, {
> 			.type = IIO_INTENSITY,
> 			.indexed = 1,
> 			.channel = 0,
> 			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> 				BIT(IIO_CHAN_INFO_INT_TIME) |
> 				BIT(IIO_CHAN_INFO_CALIBSCALE) |
> 				BIT(IIO_CHAN_INFO_CALIBBIAS),
> 			}, {
> 			.type = IIO_INTENSITY,
> 			.indexed = 1,
> 			.channel = 1,
> 			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> 			}, {
> 			.type = IIO_PROXIMITY,
> 			.indexed = 1,
> 			.channel = 0,
> 			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> 				BIT(IIO_CHAN_INFO_CALIBSCALE),
> 			},
> 		},
> 		.chan_table_elements = 4,
> 		.info = &tsl2772_device_info[ALSPRX2],
> 	},
> };
> 
> static int tsl2772_probe(struct i2c_client *clientp,
> 			 const struct i2c_device_id *id)
> {
> 	struct iio_dev *indio_dev;
> 	struct tsl2772_chip *chip;
> 	int ret;
> 
> 	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);
> 
> 	ret = i2c_smbus_read_byte_data(chip->client,
> 				       TSL2772_CMD_REG | TSL2772_CHIPID);
> 	if (ret < 0)
> 		return ret;
> 
> 	if (tsl2772_device_id_verif(ret, id->driver_data) <= 0) {
> 		dev_info(&chip->client->dev,
> 			 "%s: i2c device found does not match expected id\n",
> 				__func__);
> 		return -EINVAL;
> 	}
> 
> 	ret = i2c_smbus_write_byte(clientp, TSL2772_CMD_REG | TSL2772_CNTRL);
> 	if (ret < 0) {
> 		dev_err(&clientp->dev,
> 			"%s: Failed to write to CMD register: %d\n",
> 			__func__, ret);
> 		return ret;
> 	}
> 
> 	mutex_init(&chip->als_mutex);
> 	mutex_init(&chip->prox_mutex);
> 
> 	chip->tsl2772_chip_status = TSL2772_CHIP_UNKNOWN;
> 	chip->pdata = dev_get_platdata(&clientp->dev);
> 	chip->id = id->driver_data;
> 	chip->chip_info =
> 		&tsl2772_chip_info_tbl[device_channel_config[id->driver_data]];
> 
> 	indio_dev->info = chip->chip_info->info;
> 	indio_dev->dev.parent = &clientp->dev;
> 	indio_dev->modes = INDIO_DIRECT_MODE;
> 	indio_dev->name = chip->client->name;
> 	indio_dev->num_channels = chip->chip_info->chan_table_elements;
> 
> 	if (clientp->irq) {
> 		indio_dev->channels = chip->chip_info->channel_with_events;
> 
> 		ret = devm_request_threaded_irq(&clientp->dev, clientp->irq,
> 						NULL,
> 						&tsl2772_event_handler,
> 						IRQF_TRIGGER_FALLING |
> 						IRQF_ONESHOT,
> 						"TSL2772_event",
> 						indio_dev);
> 		if (ret) {
> 			dev_err(&clientp->dev,
> 				"%s: irq request failed\n", __func__);
> 			return ret;
> 		}
> 	} else {
> 		indio_dev->channels = chip->chip_info->channel_without_events;
> 	}
> 
> 	tsl2772_defaults(chip);
> 	tsl2772_chip_on(indio_dev);
> 
> 	ret = iio_device_register(indio_dev);
> 	if (ret) {
> 		dev_err(&clientp->dev,
> 			"%s: iio registration failed\n", __func__);
> 		return ret;

Should probably turn the chip off if this fails...  At least
that way it would look like error handling mirrors the remove
which makes for easy review.

> 	}
> 
> 	return 0;
> }
> 
> static int tsl2772_suspend(struct device *dev)
> {
> 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
> 
> 	return tsl2772_chip_off(indio_dev);
> }
> 
> static int tsl2772_resume(struct device *dev)
> {
> 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
> 
> 	return tsl2772_chip_on(indio_dev);
> }
> 
> static int tsl2772_remove(struct i2c_client *client)
> {
> 	struct iio_dev *indio_dev = i2c_get_clientdata(client);
> 
> 	tsl2772_chip_off(indio_dev);
> 
> 	iio_device_unregister(indio_dev);
> 
> 	return 0;
> }
> 
> static const struct i2c_device_id tsl2772_idtable[] = {
> 	{ "tsl2571", tsl2571 },
> 	{ "tsl2671", tsl2671 },
> 	{ "tmd2671", tmd2671 },
> 	{ "tsl2771", tsl2771 },
> 	{ "tmd2771", tmd2771 },
> 	{ "tsl2572", tsl2572 },
> 	{ "tsl2672", tsl2672 },
> 	{ "tmd2672", tmd2672 },
> 	{ "tsl2772", tsl2772 },
> 	{ "tmd2772", tmd2772 },
> 	{}
> };
> 
> MODULE_DEVICE_TABLE(i2c, tsl2772_idtable);
> 
> static const struct of_device_id tsl2772_of_match[] = {
> 	{ .compatible = "amstaos,tsl2571" },
> 	{ .compatible = "amstaos,tsl2671" },
> 	{ .compatible = "amstaos,tmd2671" },
> 	{ .compatible = "amstaos,tsl2771" },
> 	{ .compatible = "amstaos,tmd2771" },
> 	{ .compatible = "amstaos,tsl2572" },
> 	{ .compatible = "amstaos,tsl2672" },
> 	{ .compatible = "amstaos,tmd2672" },
> 	{ .compatible = "amstaos,tsl2772" },
> 	{ .compatible = "amstaos,tmd2772" },
> 	{}
> };
> MODULE_DEVICE_TABLE(of, tsl2772_of_match);
> 
> static const struct dev_pm_ops tsl2772_pm_ops = {
> 	.suspend = tsl2772_suspend,
> 	.resume  = tsl2772_resume,
> };
> 
> static struct i2c_driver tsl2772_driver = {
> 	.driver = {
> 		.name = "tsl2772",
> 		.of_match_table = tsl2772_of_match,
> 		.pm = &tsl2772_pm_ops,
> 	},
> 	.id_table = tsl2772_idtable,
> 	.probe = tsl2772_probe,
> 	.remove = tsl2772_remove,
> };
> 
> module_i2c_driver(tsl2772_driver);
> 
> MODULE_AUTHOR("J. August Brenner <Jon.Brenner@ams.com>");
> MODULE_AUTHOR("Brian Masney <masneyb@onstation.org>");
> MODULE_DESCRIPTION("TAOS tsl2772 ambient and proximity light sensor driver");
> MODULE_LICENSE("GPL");
> 
> -----------------------------------------------------------------------
> 
> tsl2772.h:
> 
> /* SPDX-License-Identifier: GPL-2.0+ */
> /*
>  * Device driver for monitoring ambient light intensity (lux)
>  * and proximity (prox) within the TAOS TSL2772 family of devices.
>  *
>  * Copyright (c) 2012, TAOS Corporation.
>  */
> 
> #ifndef __TSL2772_H
> #define __TSL2772_H
> 
> struct tsl2772_lux {
> 	unsigned int ch0;
> 	unsigned int ch1;
> };
> 
> /* Max number of segments allowable in LUX table */
> #define TSL2772_MAX_LUX_TABLE_SIZE		6
> /* The default LUX tables all have 3 elements.  */
> #define TSL2772_DEF_LUX_TABLE_SZ		3
> #define TSL2772_DEFAULT_TABLE_BYTES (sizeof(struct tsl2772_lux) * \
> 				     TSL2772_DEF_LUX_TABLE_SZ)
> 
> /* Proximity diode to use */
> #define TSL2772_DIODE0                  0x01
> #define TSL2772_DIODE1                  0x02
> #define TSL2772_DIODE_BOTH              0x03
> 
> /* LED Power */
> #define TSL2772_100_mA                  0x00
> #define TSL2772_50_mA                   0x01
> #define TSL2772_25_mA                   0x02
> #define TSL2772_13_mA                   0x03
> 
> /**
>  * struct tsl2772_settings - Settings for the tsl2772 driver
>  *  @als_time:              Integration time of the ALS channel ADCs in 2.73 ms
>  *                          increments. Total integration time is
>  *                          (256 - als_time) * 2.73.
>  *  @als_gain:              Index into the tsl2772_als_gain array.
>  *  @als_gain_trim:         Default gain trim to account for aperture effects.
>  *  @wait_time:             Time between proximity and ALS cycles in 2.73
>  *                          periods.
>  *  @prox_time:             Integration time of the proximity ADC in 2.73 ms
>  *                          increments. Total integration time is
>  *                          (256 - prx_time) * 2.73.
>  *  @prox_gain:             Index into the tsl2772_prx_gain array.
>  *  @als_prox_config:       The value of the ALS / Proximity configuration
>  *                          register.
>  *  @als_cal_target:        Known external ALS reading for calibration.
>  *  @als_persistence:       H/W Filters, Number of 'out of limits' ALS readings.
>  *  @als_interrupt_en:      Enable/Disable ALS interrupts
>  *  @als_thresh_low:        CH0 'low' count to trigger interrupt.
>  *  @als_thresh_high:       CH0 'high' count to trigger interrupt.
>  *  @prox_persistence:      H/W Filters, Number of 'out of limits' proximity
>  *                          readings.
>  *  @prox_interrupt_en:     Enable/Disable proximity interrupts.
>  *  @prox_thres_low:        Low threshold proximity detection.
>  *  @prox_thres_high:       High threshold proximity detection.
>  *  @prox_pulse_count:      Number if proximity emitter pulses.
>  *  @prox_max_samples_cal:  The number of samples that are taken when performing
>  *                          a proximity calibration.
>  *  @prox_diode             Which diode(s) to use for driving the external
>  *                          LED(s) for proximity sensing.
>  *  @prox_power             The amount of power to use for the external LED(s).
>  */
> struct tsl2772_settings {
> 	int als_time;
> 	int als_gain;
> 	int als_gain_trim;
> 	int wait_time;
> 	int prox_time;
> 	int prox_gain;
> 	int als_prox_config;
> 	int als_cal_target;
> 	u8 als_persistence;
> 	bool als_interrupt_en;
> 	int als_thresh_low;
> 	int als_thresh_high;
> 	u8 prox_persistence;
> 	bool prox_interrupt_en;
> 	int prox_thres_low;
> 	int prox_thres_high;
> 	int prox_pulse_count;
> 	int prox_max_samples_cal;
> 	int prox_diode;
> 	int prox_power;
> };
> 
> /**
>  * struct tsl2772_platform_data - Platform callback, glass and defaults
>  * @platform_lux_table:        Device specific glass coefficents
>  * @platform_default_settings: Device specific power on defaults

This blank line is pointless - be nice to get rid of it.

>  *
>  */
> struct tsl2772_platform_data {
> 	struct tsl2772_lux platform_lux_table[TSL2772_MAX_LUX_TABLE_SIZE];
> 	struct tsl2772_settings *platform_default_settings;
> };
> 
> #endif /* __TSL2772_H */

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

end of thread, other threads:[~2018-05-06 19:00 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-04  2:53 [PATCH v2 00/11] staging: iio: tsl2x7x: move out of staging Brian Masney
2018-05-04  2:53 ` [PATCH v2 01/11] staging: iio: tsl2x7x: use GPL-2.0+ SPDX license identifier Brian Masney
2018-05-06 17:59   ` Jonathan Cameron
2018-05-04  2:53 ` [PATCH v2 02/11] staging: iio: tsl2x7x: add range checking to three sysfs attributes Brian Masney
2018-05-06 18:01   ` Jonathan Cameron
2018-05-04  2:53 ` [PATCH v2 03/11] staging: iio: tsl2x7x: don't setup event handlers if interrupts are not configured Brian Masney
2018-05-06 18:05   ` Jonathan Cameron
2018-05-04  2:53 ` [PATCH v2 04/11] staging: iio: tsl2x7x: move calibscale_available attribute to IIO_INTENSITY channel Brian Masney
2018-05-06 18:06   ` Jonathan Cameron
2018-05-04  2:53 ` [PATCH v2 05/11] staging: iio: tsl2x7x: use IIO_CONST_ATTR for calibscale_available Brian Masney
2018-05-06 18:07   ` Jonathan Cameron
2018-05-04  2:53 ` [PATCH v2 06/11] staging: iio: tsl2x7x: correct integration time and lux equation Brian Masney
2018-05-06 18:11   ` Jonathan Cameron
2018-05-04  2:53 ` [PATCH v2 07/11] staging: iio: tsl2x7x: support 2.72 and 2.73 ALS increments Brian Masney
2018-05-06 18:19   ` Jonathan Cameron
2018-05-04  2:53 ` [PATCH v2 08/11] staging: iio: tsl2x7x: add device ids for code readability Brian Masney
2018-05-06 18:26   ` Jonathan Cameron
2018-05-04  2:53 ` [PATCH v2 09/11] staging: iio: tsl2x7x: correct IIO_EV_INFO_PERIOD values Brian Masney
2018-05-06 18:27   ` Jonathan Cameron
2018-05-04  2:53 ` [PATCH v2 10/11] staging: iio: tsl2x7x: rename driver to tsl2772 Brian Masney
2018-05-06 18:29   ` Jonathan Cameron
2018-05-04  2:53 ` [PATCH v2 11/11] staging: iio: tsl2x7x/tsl2772: move out of staging Brian Masney
2018-05-04  2:56   ` Brian Masney
2018-05-06 19:00     ` Jonathan Cameron

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