All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Staging: IIO: Add tsl2560-2 support to tsl2563 driver + drop tsl2561, driver.
@ 2009-11-20 19:12 Jonathan Cameron
  2009-11-20 19:17 ` Greg KH
  2009-11-20 20:14 ` [PATCH] Staging: IIO: Add tsl2560-2 support to tsl2563 driver + drop tsl2561, driver Amit Kucheria
  0 siblings, 2 replies; 9+ messages in thread
From: Jonathan Cameron @ 2009-11-20 19:12 UTC (permalink / raw)
  To: LKML, Amit Kucheria, Greg Kroah-Hartman

These parts (tsl2560-tsl2563) are identical in interface.
The tsl2563 driver is more advanced so makes sense to drop
the tsl2561 driver.

Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
---
Greg, I've done the changes and driver removal as a single patch.
Can separate into two if you would prefer?

Amit, as promised I have tested against the tsl2561 on an imote2
sensor board (for which the original driver was written). All seems
to work as intended.  Only changes are addition of devices to the
device table and Kconfig comment changes to reflect new support.
Hope you don't mind, but I dropped the N900 reference.  These things
are pretty common (including the new parts) and we don't really
want to encourage people to start listing where they found. I
haven't done any of the other changes I suggested, but can do
those as a follow up patch if you don't mind?

There are a few more similar chips with slightly different conversion
functions.

Thanks,

Jonathan

 drivers/staging/iio/light/Kconfig   |   15 +--
 drivers/staging/iio/light/Makefile  |    1 -
 drivers/staging/iio/light/tsl2561.c |  272 -----------------------------------
 drivers/staging/iio/light/tsl2563.c |   11 +-
 4 files changed, 9 insertions(+), 290 deletions(-)

diff --git a/drivers/staging/iio/light/Kconfig b/drivers/staging/iio/light/Kconfig
index cf0d0d6..cf1d946 100644
--- a/drivers/staging/iio/light/Kconfig
+++ b/drivers/staging/iio/light/Kconfig
@@ -3,21 +3,12 @@
 #
 comment "Light sensors"
 
-config TSL2561
-       tristate "TAOS TSL2561 light-to-digital convertor"
-       depends on I2C
-       help
-	Say yes bere to build support for the TAOS light to digital
-	convertor.  This chip has two light sensors. One is broadband
-	including infrared whilst the other measures only infrared.
-	Provides direct access via sysfs.
-
 config SENSORS_TSL2563
-	tristate "TAOS TSL2563 ambient light sensor"
+	tristate "TAOS TSL256[0-3] ambient light sensors"
 	depends on I2C
 	help
-	 If you say yes here you get support for the Taos TSL2563
-	 ambient light sensor (found in N900).
+	 If you say yes here you get support for the Taos TSL2560,
+	 TSL2561, TSL2562 and TSL2563 ambient light sensors.
 
 	 This driver can also be built as a module.  If so, the module
 	 will be called tsl2563.
diff --git a/drivers/staging/iio/light/Makefile b/drivers/staging/iio/light/Makefile
index 30dbfb1..30f3300 100644
--- a/drivers/staging/iio/light/Makefile
+++ b/drivers/staging/iio/light/Makefile
@@ -2,5 +2,4 @@
 # Makefile for industrial I/O Light sensors
 #
 
-obj-$(CONFIG_TSL2561)   += tsl2561.o
 obj-$(CONFIG_SENSORS_TSL2563)	+= tsl2563.o
diff --git a/drivers/staging/iio/light/tsl2561.c b/drivers/staging/iio/light/tsl2561.c
deleted file mode 100644
index fc2107f..0000000
--- a/drivers/staging/iio/light/tsl2561.c
+++ /dev/null
@@ -1,272 +0,0 @@
-/*
- *  tsl2561.c - Linux kernel modules for light to digital convertor
- *
- *  Copyright (C) 2008-2009 Jonathan Cameron <jic23@cam.ac.uk>
- *
- *  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., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- *  Some portions based upon the tsl2550 driver.
- *
- *  This driver could probably be adapted easily to talk to the tsl2560 (smbus)
- *
- *  Needs some work to support the events this can generate.
- *  Todo: Implement interrupt handling.  Currently a hardware bug means
- *  this isn't available on my test board.
- */
-
-#include <linux/module.h>
-#include <linux/init.h>
-#include <linux/i2c.h>
-#include "../iio.h"
-#include "../sysfs.h"
-#include "light.h"
-
-#define TSL2561_CONTROL_REGISTER 0x00
-#define TSL2561_TIMING_REGISTER 0x01
-#define TSL2561_THRESHLOW_LOW_REGISTER 0x02
-#define TSL2561_THRESHLOW_HIGH_REGISTER 0x03
-#define TSL2561_THRESHHIGH_LOW_REGISTER 0x04
-#define TSL2561_THRESHHIGH_HIGH_REGISTER 0x05
-#define TSL2561_INT_CONTROL_REGISTER 0x06
-
-#define TSL2561_INT_REG_INT_OFF 0x00
-#define TSL2561_INT_REG_INT_LEVEL 0x08
-#define TSL2561_INT_REG_INT_SMBUS 0x10
-#define TSL2561_INT_REG_INT_TEST 0x18
-
-#define TSL2561_ID_REGISTER 0x0A
-
-#define TSL2561_DATA_0_LOW 0x0C
-#define TSL2561_DATA_1_LOW 0x0E
-
-/* Control Register Values */
-#define TSL2561_CONT_REG_PWR_ON 0x03
-#define TSL2561_CONT_REG_PWR_OFF 0x00
-
-/**
- * struct tsl2561_state - device specific state
- * @indio_dev:		the industrialio I/O info structure
- * @client:		i2c client
- * @command_buf:	single command buffer used for all operations
- * @command_buf_lock:	ensure unique access to command_buf
- */
-struct tsl2561_state {
-	struct iio_dev		*indio_dev;
-	struct i2c_client	*client;
-	struct tsl2561_command	*command_buf;
-	struct mutex		command_buf_lock;
-};
-
-/**
- * struct tsl2561_command - command byte for smbus
- * @address:	register address
- * @block:	is this a block r/w
- * @word:	is this a word r/w
- * @clear:	set to 1 to clear pending interrupt
- * @cmd:	select the command register - always 1.
- */
-struct tsl2561_command {
-	unsigned int address:4;
-	unsigned int block:1;
-	unsigned int word:1;
-	unsigned int clear:1;
-	unsigned int cmd:1;
-};
-
-static inline void tsl2561_init_command_buf(struct tsl2561_command *buf)
-{
-	buf->address = 0;
-	buf->block = 0;
-	buf->word = 0;
-	buf->clear = 0;
-	buf->cmd = 1;
-}
-
-static ssize_t tsl2561_read_val(struct device *dev,
-				struct device_attribute *attr,
-				char *buf)
-{
-	int ret = 0, data;
-	ssize_t len = 0;
-	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
-	struct iio_dev *indio_dev = dev_get_drvdata(dev);
-	struct tsl2561_state *st = indio_dev->dev_data;
-
-	mutex_lock(&st->command_buf_lock);
-	st->command_buf->cmd = 1;
-	st->command_buf->word = 1;
-	st->command_buf->address = this_attr->address;
-
-	data = i2c_smbus_read_word_data(st->client, *(char *)(st->command_buf));
-	if (data < 0) {
-		ret = data;
-		goto error_ret;
-	}
-	len = sprintf(buf, "%u\n", data);
-
-error_ret:
-	mutex_unlock(&st->command_buf_lock);
-
-	return ret ? ret : len;
-}
-
-static IIO_DEV_ATTR_LIGHT_INFRARED(0, tsl2561_read_val, TSL2561_DATA_0_LOW);
-static IIO_DEV_ATTR_LIGHT_BROAD(0, tsl2561_read_val, TSL2561_DATA_1_LOW);
-
-static struct attribute *tsl2561_attributes[] = {
-	&iio_dev_attr_light_infrared0.dev_attr.attr,
-	&iio_dev_attr_light_broadspectrum0.dev_attr.attr,
-	NULL,
-};
-
-static const struct attribute_group tsl2561_attribute_group = {
-	.attrs = tsl2561_attributes,
-};
-
-static int tsl2561_initialize(struct tsl2561_state *st)
-{
-	int err;
-
-	mutex_lock(&st->command_buf_lock);
-	st->command_buf->word = 0;
-	st->command_buf->block = 0;
-	st->command_buf->address = TSL2561_CONTROL_REGISTER;
-	err = i2c_smbus_write_byte_data(st->client, *(char *)(st->command_buf),
-					TSL2561_CONT_REG_PWR_ON);
-	if (err)
-		goto error_ret;
-
-	st->command_buf->address = TSL2561_INT_CONTROL_REGISTER;
-	err = i2c_smbus_write_byte_data(st->client, *(char *)(st->command_buf),
-					TSL2561_INT_REG_INT_TEST);
-
-error_ret:
-	mutex_unlock(&st->command_buf_lock);
-
-	return err;
-}
-
-static int tsl2561_powerdown(struct i2c_client *client)
-{
-	int err;
-	struct tsl2561_command Command = {
-		.cmd =  1,
-		.clear = 0,
-		.word = 0,
-		.block = 0,
-		.address = TSL2561_CONTROL_REGISTER,
-	};
-
-	err = i2c_smbus_write_byte_data(client, *(char *)(&Command),
-					TSL2561_CONT_REG_PWR_OFF);
-	return (err < 0) ? err : 0;
-}
-static int __devinit tsl2561_probe(struct i2c_client *client,
-				   const struct i2c_device_id *id)
-{
-	int ret = 0, regdone = 0;
-	struct tsl2561_state *st = kzalloc(sizeof(*st), GFP_KERNEL);
-
-	if (st == NULL) {
-		ret = -ENOMEM;
-		goto error_ret;
-	}
-	i2c_set_clientdata(client, st);
-	st->client = client;
-	mutex_init(&st->command_buf_lock);
-
-	st->command_buf = kmalloc(sizeof(*st->command_buf), GFP_KERNEL);
-	if (st->command_buf == NULL) {
-		ret = -ENOMEM;
-		goto error_free_state;
-	}
-	tsl2561_init_command_buf(st->command_buf);
-
-	st->indio_dev = iio_allocate_device();
-	if (st->indio_dev == NULL) {
-		ret = -ENOMEM;
-		goto error_free_command_buf;
-	}
-	st->indio_dev->attrs = &tsl2561_attribute_group;
-	st->indio_dev->dev.parent = &client->dev;
-	st->indio_dev->dev_data = (void *)(st);
-	st->indio_dev->driver_module = THIS_MODULE;
-	st->indio_dev->modes = INDIO_DIRECT_MODE;
-	ret = iio_device_register(st->indio_dev);
-	if (ret)
-		goto error_free_iiodev;
-	regdone = 1;
-	/* Intialize the chip */
-	ret = tsl2561_initialize(st);
-	if (ret)
-		goto error_unregister_iiodev;
-
-	return 0;
-error_unregister_iiodev:
-error_free_iiodev:
-	if (regdone)
-		iio_device_unregister(st->indio_dev);
-	else
-		iio_free_device(st->indio_dev);
-error_free_command_buf:
-	kfree(st->command_buf);
-error_free_state:
-	kfree(st);
-error_ret:
-	return ret;
-
-}
-
-static int __devexit tsl2561_remove(struct i2c_client *client)
-{
-	struct tsl2561_state *st =  i2c_get_clientdata(client);
-
-	iio_device_unregister(st->indio_dev);
-	kfree(st);
-
-	return tsl2561_powerdown(client);
-}
-
-static const struct i2c_device_id tsl2561_id[] = {
-	{ "tsl2561", 0 },
-	{ }
-};
-MODULE_DEVICE_TABLE(i2c, tsl2561_id);
-
-
-static struct i2c_driver tsl2561_driver = {
-	.driver = {
-		.name = "tsl2561",
-	},
-	.probe = tsl2561_probe,
-	.remove = __devexit_p(tsl2561_remove),
-	.id_table  = tsl2561_id,
-};
-
-static __init int tsl2561_init(void)
-{
-	return i2c_add_driver(&tsl2561_driver);
-}
-module_init(tsl2561_init);
-
-static __exit void tsl2561_exit(void)
-{
-	i2c_del_driver(&tsl2561_driver);
-}
-module_exit(tsl2561_exit);
-
-MODULE_AUTHOR("Jonathan Cameron <jic23@cam.ac.uk>");
-MODULE_DESCRIPTION("TSL2561 light sensor driver");
-MODULE_LICENSE("GPL");
diff --git a/drivers/staging/iio/light/tsl2563.c b/drivers/staging/iio/light/tsl2563.c
index 3e812b2..78b9432 100644
--- a/drivers/staging/iio/light/tsl2563.c
+++ b/drivers/staging/iio/light/tsl2563.c
@@ -38,8 +38,6 @@
 #include "../iio.h"
 #include "tsl2563.h"
 
-#define DRIVER_NAME  "tsl2563"
-
 /* Use this many bits for fraction part. */
 #define ADC_FRAC_BITS		(14)
 
@@ -738,14 +736,17 @@ out:
 }
 
 static const struct i2c_device_id tsl2563_id[] = {
-	{ DRIVER_NAME, 0 },
-	{ },
+	{ "tsl2560", 0 },
+	{ "tsl2561", 1 },
+	{ "tsl2562", 2 },
+	{ "tsl2563", 3 },
+	{}
 };
 MODULE_DEVICE_TABLE(i2c, tsl2563_id);
 
 static struct i2c_driver tsl2563_i2c_driver = {
 	.driver = {
-		.name	 = DRIVER_NAME,
+		.name	 = "tsl2563",
 	},
 	.suspend	= tsl2563_suspend,
 	.resume		= tsl2563_resume,

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

* Re: [PATCH] Staging: IIO: Add tsl2560-2 support to tsl2563 driver + drop tsl2561, driver.
  2009-11-20 19:12 [PATCH] Staging: IIO: Add tsl2560-2 support to tsl2563 driver + drop tsl2561, driver Jonathan Cameron
@ 2009-11-20 19:17 ` Greg KH
  2009-11-22 16:00   ` [PATCH 1/2] Staging: IIO: Remove tsl2561 driver. Support merged with tsl2563 Jonathan Cameron
  2009-11-20 20:14 ` [PATCH] Staging: IIO: Add tsl2560-2 support to tsl2563 driver + drop tsl2561, driver Amit Kucheria
  1 sibling, 1 reply; 9+ messages in thread
From: Greg KH @ 2009-11-20 19:17 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: LKML, Amit Kucheria

On Fri, Nov 20, 2009 at 07:12:59PM +0000, Jonathan Cameron wrote:
> These parts (tsl2560-tsl2563) are identical in interface.
> The tsl2563 driver is more advanced so makes sense to drop
> the tsl2561 driver.
> 
> Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
> ---
> Greg, I've done the changes and driver removal as a single patch.
> Can separate into two if you would prefer?

Yes, please split this into 2 patches, it's easier to review that way.

thanks,

greg k-h

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

* Re: [PATCH] Staging: IIO: Add tsl2560-2 support to tsl2563 driver +  drop tsl2561, driver.
  2009-11-20 19:12 [PATCH] Staging: IIO: Add tsl2560-2 support to tsl2563 driver + drop tsl2561, driver Jonathan Cameron
  2009-11-20 19:17 ` Greg KH
@ 2009-11-20 20:14 ` Amit Kucheria
  2009-11-22 15:45   ` Jonathan Cameron
  1 sibling, 1 reply; 9+ messages in thread
From: Amit Kucheria @ 2009-11-20 20:14 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: LKML, Greg Kroah-Hartman

On Fri, Nov 20, 2009 at 9:12 PM, Jonathan Cameron <jic23@cam.ac.uk> wrote:
> These parts (tsl2560-tsl2563) are identical in interface.
> The tsl2563 driver is more advanced so makes sense to drop
> the tsl2561 driver.
>
> Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
> ---
> Greg, I've done the changes and driver removal as a single patch.
> Can separate into two if you would prefer?
>
> Amit, as promised I have tested against the tsl2561 on an imote2
> sensor board (for which the original driver was written). All seems
> to work as intended.  Only changes are addition of devices to the
> device table and Kconfig comment changes to reflect new support.
> Hope you don't mind, but I dropped the N900 reference.  These things
> are pretty common (including the new parts) and we don't really
> want to encourage people to start listing where they found. I
> haven't done any of the other changes I suggested, but can do
> those as a follow up patch if you don't mind?
>
> There are a few more similar chips with slightly different conversion
> functions.
>
> Thanks,
>
> Jonathan

Jonathan,

Changes looks good. I'll send my acks on the split up patches.

I'm working on moving this driver to the input subsystem as agreed. I
was planning to address your review comments in that rework. I can
defer that work if you want.

Regards,
Amit

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

* Re: [PATCH] Staging: IIO: Add tsl2560-2 support to tsl2563 driver +  drop tsl2561, driver.
  2009-11-20 20:14 ` [PATCH] Staging: IIO: Add tsl2560-2 support to tsl2563 driver + drop tsl2561, driver Amit Kucheria
@ 2009-11-22 15:45   ` Jonathan Cameron
  2009-11-22 19:00     ` Amit Kucheria
  0 siblings, 1 reply; 9+ messages in thread
From: Jonathan Cameron @ 2009-11-22 15:45 UTC (permalink / raw)
  To: Amit Kucheria; +Cc: LKML, Greg Kroah-Hartman

Amit Kucheria wrote:
> On Fri, Nov 20, 2009 at 9:12 PM, Jonathan Cameron <jic23@cam.ac.uk> wrote:
>> These parts (tsl2560-tsl2563) are identical in interface.
>> The tsl2563 driver is more advanced so makes sense to drop
>> the tsl2561 driver.
>>
>> Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
>> ---
>> Greg, I've done the changes and driver removal as a single patch.
>> Can separate into two if you would prefer?
>>
>> Amit, as promised I have tested against the tsl2561 on an imote2
>> sensor board (for which the original driver was written). All seems
>> to work as intended.  Only changes are addition of devices to the
>> device table and Kconfig comment changes to reflect new support.
>> Hope you don't mind, but I dropped the N900 reference.  These things
>> are pretty common (including the new parts) and we don't really
>> want to encourage people to start listing where they found. I
>> haven't done any of the other changes I suggested, but can do
>> those as a follow up patch if you don't mind?
>>
>> There are a few more similar chips with slightly different conversion
>> functions.
>>
>> Thanks,
>>
>> Jonathan
> 
> Jonathan,
> 
> Changes looks good. I'll send my acks on the split up patches.
Cool, I'll do them in a few mins.
> 
> I'm working on moving this driver to the input subsystem as agreed.
Input?  Ambient Light sensors subsystem makes sense. Input certainly 
does not (and will get copious NAKs). I was beginning to doubt that ALS
will get sorted out in time for the next merge window (or that the
various drivers would get moved across in time), hence this patch to
clear up a bit of a mess and a lot of pointless code in IIO as Greg has
already taken your driver into the staging tree.
> I
> was planning to address your review comments in that rework. I can
> defer that work if you want.
Sure, that's fine with me, though given the wonders of staging, you may
well find a 3rd party submits patches for your driver in the meantime ;)

Thanks,

Jonathan


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

* [PATCH 1/2] Staging: IIO: Remove tsl2561 driver. Support merged with tsl2563.
  2009-11-20 19:17 ` Greg KH
@ 2009-11-22 16:00   ` Jonathan Cameron
  2009-11-22 16:03     ` [PATCH 2/2] Staging: IIO: Add tsl2560-2 support to tsl2563 driver Jonathan Cameron
  2009-11-22 19:04     ` [PATCH 1/2] Staging: IIO: Remove tsl2561 driver. Support merged with tsl2563 Amit Kucheria
  0 siblings, 2 replies; 9+ messages in thread
From: Jonathan Cameron @ 2009-11-22 16:00 UTC (permalink / raw)
  To: Greg KH; +Cc: LKML, Amit Kucheria


Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>

---
This patch simply removes the tsl2561 driver.

 drivers/staging/iio/light/Kconfig   |    9 --
 drivers/staging/iio/light/Makefile  |    1 -
 drivers/staging/iio/light/tsl2561.c |  272 -----------------------------------
 3 files changed, 0 insertions(+), 282 deletions(-)

diff --git a/drivers/staging/iio/light/Kconfig b/drivers/staging/iio/light/Kconfig
index cf0d0d6..ab54191 100644
--- a/drivers/staging/iio/light/Kconfig
+++ b/drivers/staging/iio/light/Kconfig
@@ -3,15 +3,6 @@
 #
 comment "Light sensors"
 
-config TSL2561
-       tristate "TAOS TSL2561 light-to-digital convertor"
-       depends on I2C
-       help
-	Say yes bere to build support for the TAOS light to digital
-	convertor.  This chip has two light sensors. One is broadband
-	including infrared whilst the other measures only infrared.
-	Provides direct access via sysfs.
-
 config SENSORS_TSL2563
 	tristate "TAOS TSL2563 ambient light sensor"
 	depends on I2C
diff --git a/drivers/staging/iio/light/Makefile b/drivers/staging/iio/light/Makefile
index 30dbfb1..30f3300 100644
--- a/drivers/staging/iio/light/Makefile
+++ b/drivers/staging/iio/light/Makefile
@@ -2,5 +2,4 @@
 # Makefile for industrial I/O Light sensors
 #
 
-obj-$(CONFIG_TSL2561)   += tsl2561.o
 obj-$(CONFIG_SENSORS_TSL2563)	+= tsl2563.o
diff --git a/drivers/staging/iio/light/tsl2561.c b/drivers/staging/iio/light/tsl2561.c
deleted file mode 100644
index fc2107f..0000000
--- a/drivers/staging/iio/light/tsl2561.c
+++ /dev/null
@@ -1,272 +0,0 @@
-/*
- *  tsl2561.c - Linux kernel modules for light to digital convertor
- *
- *  Copyright (C) 2008-2009 Jonathan Cameron <jic23@cam.ac.uk>
- *
- *  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., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- *  Some portions based upon the tsl2550 driver.
- *
- *  This driver could probably be adapted easily to talk to the tsl2560 (smbus)
- *
- *  Needs some work to support the events this can generate.
- *  Todo: Implement interrupt handling.  Currently a hardware bug means
- *  this isn't available on my test board.
- */
-
-#include <linux/module.h>
-#include <linux/init.h>
-#include <linux/i2c.h>
-#include "../iio.h"
-#include "../sysfs.h"
-#include "light.h"
-
-#define TSL2561_CONTROL_REGISTER 0x00
-#define TSL2561_TIMING_REGISTER 0x01
-#define TSL2561_THRESHLOW_LOW_REGISTER 0x02
-#define TSL2561_THRESHLOW_HIGH_REGISTER 0x03
-#define TSL2561_THRESHHIGH_LOW_REGISTER 0x04
-#define TSL2561_THRESHHIGH_HIGH_REGISTER 0x05
-#define TSL2561_INT_CONTROL_REGISTER 0x06
-
-#define TSL2561_INT_REG_INT_OFF 0x00
-#define TSL2561_INT_REG_INT_LEVEL 0x08
-#define TSL2561_INT_REG_INT_SMBUS 0x10
-#define TSL2561_INT_REG_INT_TEST 0x18
-
-#define TSL2561_ID_REGISTER 0x0A
-
-#define TSL2561_DATA_0_LOW 0x0C
-#define TSL2561_DATA_1_LOW 0x0E
-
-/* Control Register Values */
-#define TSL2561_CONT_REG_PWR_ON 0x03
-#define TSL2561_CONT_REG_PWR_OFF 0x00
-
-/**
- * struct tsl2561_state - device specific state
- * @indio_dev:		the industrialio I/O info structure
- * @client:		i2c client
- * @command_buf:	single command buffer used for all operations
- * @command_buf_lock:	ensure unique access to command_buf
- */
-struct tsl2561_state {
-	struct iio_dev		*indio_dev;
-	struct i2c_client	*client;
-	struct tsl2561_command	*command_buf;
-	struct mutex		command_buf_lock;
-};
-
-/**
- * struct tsl2561_command - command byte for smbus
- * @address:	register address
- * @block:	is this a block r/w
- * @word:	is this a word r/w
- * @clear:	set to 1 to clear pending interrupt
- * @cmd:	select the command register - always 1.
- */
-struct tsl2561_command {
-	unsigned int address:4;
-	unsigned int block:1;
-	unsigned int word:1;
-	unsigned int clear:1;
-	unsigned int cmd:1;
-};
-
-static inline void tsl2561_init_command_buf(struct tsl2561_command *buf)
-{
-	buf->address = 0;
-	buf->block = 0;
-	buf->word = 0;
-	buf->clear = 0;
-	buf->cmd = 1;
-}
-
-static ssize_t tsl2561_read_val(struct device *dev,
-				struct device_attribute *attr,
-				char *buf)
-{
-	int ret = 0, data;
-	ssize_t len = 0;
-	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
-	struct iio_dev *indio_dev = dev_get_drvdata(dev);
-	struct tsl2561_state *st = indio_dev->dev_data;
-
-	mutex_lock(&st->command_buf_lock);
-	st->command_buf->cmd = 1;
-	st->command_buf->word = 1;
-	st->command_buf->address = this_attr->address;
-
-	data = i2c_smbus_read_word_data(st->client, *(char *)(st->command_buf));
-	if (data < 0) {
-		ret = data;
-		goto error_ret;
-	}
-	len = sprintf(buf, "%u\n", data);
-
-error_ret:
-	mutex_unlock(&st->command_buf_lock);
-
-	return ret ? ret : len;
-}
-
-static IIO_DEV_ATTR_LIGHT_INFRARED(0, tsl2561_read_val, TSL2561_DATA_0_LOW);
-static IIO_DEV_ATTR_LIGHT_BROAD(0, tsl2561_read_val, TSL2561_DATA_1_LOW);
-
-static struct attribute *tsl2561_attributes[] = {
-	&iio_dev_attr_light_infrared0.dev_attr.attr,
-	&iio_dev_attr_light_broadspectrum0.dev_attr.attr,
-	NULL,
-};
-
-static const struct attribute_group tsl2561_attribute_group = {
-	.attrs = tsl2561_attributes,
-};
-
-static int tsl2561_initialize(struct tsl2561_state *st)
-{
-	int err;
-
-	mutex_lock(&st->command_buf_lock);
-	st->command_buf->word = 0;
-	st->command_buf->block = 0;
-	st->command_buf->address = TSL2561_CONTROL_REGISTER;
-	err = i2c_smbus_write_byte_data(st->client, *(char *)(st->command_buf),
-					TSL2561_CONT_REG_PWR_ON);
-	if (err)
-		goto error_ret;
-
-	st->command_buf->address = TSL2561_INT_CONTROL_REGISTER;
-	err = i2c_smbus_write_byte_data(st->client, *(char *)(st->command_buf),
-					TSL2561_INT_REG_INT_TEST);
-
-error_ret:
-	mutex_unlock(&st->command_buf_lock);
-
-	return err;
-}
-
-static int tsl2561_powerdown(struct i2c_client *client)
-{
-	int err;
-	struct tsl2561_command Command = {
-		.cmd =  1,
-		.clear = 0,
-		.word = 0,
-		.block = 0,
-		.address = TSL2561_CONTROL_REGISTER,
-	};
-
-	err = i2c_smbus_write_byte_data(client, *(char *)(&Command),
-					TSL2561_CONT_REG_PWR_OFF);
-	return (err < 0) ? err : 0;
-}
-static int __devinit tsl2561_probe(struct i2c_client *client,
-				   const struct i2c_device_id *id)
-{
-	int ret = 0, regdone = 0;
-	struct tsl2561_state *st = kzalloc(sizeof(*st), GFP_KERNEL);
-
-	if (st == NULL) {
-		ret = -ENOMEM;
-		goto error_ret;
-	}
-	i2c_set_clientdata(client, st);
-	st->client = client;
-	mutex_init(&st->command_buf_lock);
-
-	st->command_buf = kmalloc(sizeof(*st->command_buf), GFP_KERNEL);
-	if (st->command_buf == NULL) {
-		ret = -ENOMEM;
-		goto error_free_state;
-	}
-	tsl2561_init_command_buf(st->command_buf);
-
-	st->indio_dev = iio_allocate_device();
-	if (st->indio_dev == NULL) {
-		ret = -ENOMEM;
-		goto error_free_command_buf;
-	}
-	st->indio_dev->attrs = &tsl2561_attribute_group;
-	st->indio_dev->dev.parent = &client->dev;
-	st->indio_dev->dev_data = (void *)(st);
-	st->indio_dev->driver_module = THIS_MODULE;
-	st->indio_dev->modes = INDIO_DIRECT_MODE;
-	ret = iio_device_register(st->indio_dev);
-	if (ret)
-		goto error_free_iiodev;
-	regdone = 1;
-	/* Intialize the chip */
-	ret = tsl2561_initialize(st);
-	if (ret)
-		goto error_unregister_iiodev;
-
-	return 0;
-error_unregister_iiodev:
-error_free_iiodev:
-	if (regdone)
-		iio_device_unregister(st->indio_dev);
-	else
-		iio_free_device(st->indio_dev);
-error_free_command_buf:
-	kfree(st->command_buf);
-error_free_state:
-	kfree(st);
-error_ret:
-	return ret;
-
-}
-
-static int __devexit tsl2561_remove(struct i2c_client *client)
-{
-	struct tsl2561_state *st =  i2c_get_clientdata(client);
-
-	iio_device_unregister(st->indio_dev);
-	kfree(st);
-
-	return tsl2561_powerdown(client);
-}
-
-static const struct i2c_device_id tsl2561_id[] = {
-	{ "tsl2561", 0 },
-	{ }
-};
-MODULE_DEVICE_TABLE(i2c, tsl2561_id);
-
-
-static struct i2c_driver tsl2561_driver = {
-	.driver = {
-		.name = "tsl2561",
-	},
-	.probe = tsl2561_probe,
-	.remove = __devexit_p(tsl2561_remove),
-	.id_table  = tsl2561_id,
-};
-
-static __init int tsl2561_init(void)
-{
-	return i2c_add_driver(&tsl2561_driver);
-}
-module_init(tsl2561_init);
-
-static __exit void tsl2561_exit(void)
-{
-	i2c_del_driver(&tsl2561_driver);
-}
-module_exit(tsl2561_exit);
-
-MODULE_AUTHOR("Jonathan Cameron <jic23@cam.ac.uk>");
-MODULE_DESCRIPTION("TSL2561 light sensor driver");
-MODULE_LICENSE("GPL");
-- 
1.6.4.4


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

* [PATCH 2/2] Staging: IIO: Add tsl2560-2 support to tsl2563 driver.
  2009-11-22 16:00   ` [PATCH 1/2] Staging: IIO: Remove tsl2561 driver. Support merged with tsl2563 Jonathan Cameron
@ 2009-11-22 16:03     ` Jonathan Cameron
  2009-11-22 19:06       ` Amit Kucheria
  2009-11-22 19:04     ` [PATCH 1/2] Staging: IIO: Remove tsl2561 driver. Support merged with tsl2563 Amit Kucheria
  1 sibling, 1 reply; 9+ messages in thread
From: Jonathan Cameron @ 2009-11-22 16:03 UTC (permalink / raw)
  To: Greg KH; +Cc: LKML, Amit Kucheria

Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
---
Minimal changes to driver. Just adds the device to the id
table and adjusts the Kconfig elements appropriately.

Adding further similar chips from TAOS is complicated by their
different conversion functions (and hence left for now).

 drivers/staging/iio/light/Kconfig   |    6 +++---
 drivers/staging/iio/light/tsl2563.c |   11 ++++++-----
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/iio/light/Kconfig b/drivers/staging/iio/light/Kconfig
index ab54191..80cb6e5 100644
--- a/drivers/staging/iio/light/Kconfig
+++ b/drivers/staging/iio/light/Kconfig
@@ -4,11 +4,11 @@
 comment "Light sensors"
 
 config SENSORS_TSL2563
-	tristate "TAOS TSL2563 ambient light sensor"
+	tristate "TAOS TSL256[0-3] ambient light sensor"
 	depends on I2C
 	help
-	 If you say yes here you get support for the Taos TSL2563
-	 ambient light sensor (found in N900).
+	 If you say yes here you get support for the Taos TSL2560,
+	 TSL2561, TSL2562 and TSL2563 ambient light sensors.
 
 	 This driver can also be built as a module.  If so, the module
 	 will be called tsl2563.
diff --git a/drivers/staging/iio/light/tsl2563.c b/drivers/staging/iio/light/tsl2563.c
index 3e812b2..78b9432 100644
--- a/drivers/staging/iio/light/tsl2563.c
+++ b/drivers/staging/iio/light/tsl2563.c
@@ -38,8 +38,6 @@
 #include "../iio.h"
 #include "tsl2563.h"
 
-#define DRIVER_NAME  "tsl2563"
-
 /* Use this many bits for fraction part. */
 #define ADC_FRAC_BITS		(14)
 
@@ -738,14 +736,17 @@ out:
 }
 
 static const struct i2c_device_id tsl2563_id[] = {
-	{ DRIVER_NAME, 0 },
-	{ },
+	{ "tsl2560", 0 },
+	{ "tsl2561", 1 },
+	{ "tsl2562", 2 },
+	{ "tsl2563", 3 },
+	{}
 };
 MODULE_DEVICE_TABLE(i2c, tsl2563_id);
 
 static struct i2c_driver tsl2563_i2c_driver = {
 	.driver = {
-		.name	 = DRIVER_NAME,
+		.name	 = "tsl2563",
 	},
 	.suspend	= tsl2563_suspend,
 	.resume		= tsl2563_resume,
-- 
1.6.4.4


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

* Re: [PATCH] Staging: IIO: Add tsl2560-2 support to tsl2563 driver +  drop tsl2561, driver.
  2009-11-22 15:45   ` Jonathan Cameron
@ 2009-11-22 19:00     ` Amit Kucheria
  0 siblings, 0 replies; 9+ messages in thread
From: Amit Kucheria @ 2009-11-22 19:00 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: LKML

On 09 Nov 22, Jonathan Cameron wrote:
> Amit Kucheria wrote:
> > On Fri, Nov 20, 2009 at 9:12 PM, Jonathan Cameron <jic23@cam.ac.uk> wrote:
> >> These parts (tsl2560-tsl2563) are identical in interface.
> >> The tsl2563 driver is more advanced so makes sense to drop
> >> the tsl2561 driver.
> >>
> >> Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
> >> ---
> >> Greg, I've done the changes and driver removal as a single patch.
> >> Can separate into two if you would prefer?
> >>
> >> Amit, as promised I have tested against the tsl2561 on an imote2
> >> sensor board (for which the original driver was written). All seems
> >> to work as intended.  Only changes are addition of devices to the
> >> device table and Kconfig comment changes to reflect new support.
> >> Hope you don't mind, but I dropped the N900 reference.  These things
> >> are pretty common (including the new parts) and we don't really
> >> want to encourage people to start listing where they found. I
> >> haven't done any of the other changes I suggested, but can do
> >> those as a follow up patch if you don't mind?
> >>
> >> There are a few more similar chips with slightly different conversion
> >> functions.
> >>
> >> Thanks,
> >>
> >> Jonathan
> > 
> > Jonathan,
> > 
> > Changes looks good. I'll send my acks on the split up patches.
> Cool, I'll do them in a few mins.
> > 
> > I'm working on moving this driver to the input subsystem as agreed.
> Input?  Ambient Light sensors subsystem makes sense. Input certainly 
> does not (and will get copious NAKs). I was beginning to doubt that ALS
> will get sorted out in time for the next merge window (or that the
> various drivers would get moved across in time), hence this patch to
> clear up a bit of a mess and a lot of pointless code in IIO as Greg has
> already taken your driver into the staging tree.

Err.. sorry, distracted reply. I meant the ALS subsystem that Rui is sheparding. 

> > I
> > was planning to address your review comments in that rework. I can
> > defer that work if you want.
> Sure, that's fine with me, though given the wonders of staging, you may
> well find a 3rd party submits patches for your driver in the meantime ;)
> 

Less work for me :)


-- 
------------------------------------------------------------
Amit Kucheria, Finland
------------------------------------------------------------

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

* Re: [PATCH 1/2] Staging: IIO: Remove tsl2561 driver. Support merged with tsl2563.
  2009-11-22 16:00   ` [PATCH 1/2] Staging: IIO: Remove tsl2561 driver. Support merged with tsl2563 Jonathan Cameron
  2009-11-22 16:03     ` [PATCH 2/2] Staging: IIO: Add tsl2560-2 support to tsl2563 driver Jonathan Cameron
@ 2009-11-22 19:04     ` Amit Kucheria
  1 sibling, 0 replies; 9+ messages in thread
From: Amit Kucheria @ 2009-11-22 19:04 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: Greg KH, LKML

On 09 Nov 22, Jonathan Cameron wrote:
> 
> Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
> 
> ---
> This patch simply removes the tsl2561 driver.
> 
>  drivers/staging/iio/light/Kconfig   |    9 --
>  drivers/staging/iio/light/Makefile  |    1 -
>  drivers/staging/iio/light/tsl2561.c |  272 -----------------------------------
>  3 files changed, 0 insertions(+), 282 deletions(-)
> 

Acked-by: Amit Kucheria <amit.kucheria@verdurent.com>

-- 
------------------------------------------------------------
Amit Kucheria, Finland
------------------------------------------------------------

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

* Re: [PATCH 2/2] Staging: IIO: Add tsl2560-2 support to tsl2563 driver.
  2009-11-22 16:03     ` [PATCH 2/2] Staging: IIO: Add tsl2560-2 support to tsl2563 driver Jonathan Cameron
@ 2009-11-22 19:06       ` Amit Kucheria
  0 siblings, 0 replies; 9+ messages in thread
From: Amit Kucheria @ 2009-11-22 19:06 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: Greg KH, LKML

On 09 Nov 22, Jonathan Cameron wrote:
> Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
> ---
> Minimal changes to driver. Just adds the device to the id
> table and adjusts the Kconfig elements appropriately.
> 
> Adding further similar chips from TAOS is complicated by their
> different conversion functions (and hence left for now).
> 
>  drivers/staging/iio/light/Kconfig   |    6 +++---
>  drivers/staging/iio/light/tsl2563.c |   11 ++++++-----
>  2 files changed, 9 insertions(+), 8 deletions(-)


Acked-by: Amit Kucheria <amit.kucheria@verdurent.com>

-- 
------------------------------------------------------------
Amit Kucheria, Finland
------------------------------------------------------------

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

end of thread, other threads:[~2009-11-22 19:06 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-20 19:12 [PATCH] Staging: IIO: Add tsl2560-2 support to tsl2563 driver + drop tsl2561, driver Jonathan Cameron
2009-11-20 19:17 ` Greg KH
2009-11-22 16:00   ` [PATCH 1/2] Staging: IIO: Remove tsl2561 driver. Support merged with tsl2563 Jonathan Cameron
2009-11-22 16:03     ` [PATCH 2/2] Staging: IIO: Add tsl2560-2 support to tsl2563 driver Jonathan Cameron
2009-11-22 19:06       ` Amit Kucheria
2009-11-22 19:04     ` [PATCH 1/2] Staging: IIO: Remove tsl2561 driver. Support merged with tsl2563 Amit Kucheria
2009-11-20 20:14 ` [PATCH] Staging: IIO: Add tsl2560-2 support to tsl2563 driver + drop tsl2561, driver Amit Kucheria
2009-11-22 15:45   ` Jonathan Cameron
2009-11-22 19:00     ` Amit Kucheria

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.