Skip to contentSkip to conversation

ALS: TSL2550 driver move from i2c/chips

PATCH In review Jonathan Cameron 3 participants 3 messages Oct 17, 2009 I2C subsystem host drivers

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ALS: TSL2550 driver move from i2c/chips

---
This is not a finished patch. We still need to resolve the debate on naming conventions with ALS. Basically is there are a pressing reason for not having /sys/class/als/als0/ etc and moving management into the core? Otherwise we end up with every driver having to implement their own management systems and a lot of code replication.

This will however work with current ALS patch set.

Additions since previous V1:
Removed set operating mode sysfs and replaced with an illuminance0_range_max. If requested max is in low range it will go with that, otherwise maximum range is selected.

For now I've left the device id code etc alone, as moving this into the ALS core is still under debate.

Couple of trivial style fixes thrown up by checkpatch in the original driver that we might was well fix during this move.

V1:

Minimal changes made. Untested due to lack of hardware.

Full patch this time rather than move one.

 Documentation/ABI/testing/sysfs-class-als |    9 +
 drivers/als/Kconfig                       |   14 +
 drivers/als/Makefile                      |    2 +
 drivers/als/tsl2550.c                     |  535 +++++++++++++++++++++++++++++
 drivers/i2c/chips/Kconfig                 |   10 -
 drivers/i2c/chips/Makefile                |    1 -
 drivers/i2c/chips/tsl2550.c               |  470 -------------------------
 7 files changed, 560 insertions(+), 481 deletions(-)
Documentation/ABI/testing/sysfs-class-als +9 -0
index d3b33f3..9db1936 100644
@@ -7,3 +7,12 @@ Description:	Current Ambient Light Illuminance reported by
 		Unit: lux (lumens per square meter)
 		RO
 
+What:		/sys/class/als/.../illuminance[n]_range_max
+Date:		Oct. 2009
+KernelVersion:	2.6.32
+Contact:	Jonathan Cameron <[email protected]>
+Description:	Maximum value of Ambient Light Illuminance as
+		reported by ALS driver. Used when a device
+		has a multiple operating ranges.
+		Unit: lux (lumens per square meter)
+		RW
drivers/als/Kconfig +14 -0
index 200c52b..1564ffc 100644
@@ -8,3 +8,17 @@ menuconfig ALS
 	  This framework provides a generic sysfs I/F for Ambient Light
 	  Sensor devices.
 	  If you want this support, you should say Y or M here.
+
+if ALS
+
+config ALS_TSL2550
+	tristate "Taos TSL2550 ambient light sensor"
+	depends on EXPERIMENTAL && I2C
+	help
+	  If you say yes here you get support for the Taos TSL2550
+	  ambient light sensor.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called tsl2550.
+
+endif #ALS
drivers/als/Makefile +2 -0
index a527197..7be5631 100644
@@ -3,3 +3,5 @@
 #
 
 obj-$(CONFIG_ALS)		+= als_sys.o
+
+obj-$(CONFIG_ALS_TSL2550)	+= tsl2550.o
\ No newline at end of file
drivers/als/tsl2550.c new file +535 -0

535 lines not on this page · raw message

drivers/i2c/chips/Kconfig +0 -10
index f9618f4..626bfcf 100644
@@ -16,14 +16,4 @@ config DS1682
 	  This driver can also be built as a module.  If so, the module
 	  will be called ds1682.
 
-config SENSORS_TSL2550
-	tristate "Taos TSL2550 ambient light sensor"
-	depends on EXPERIMENTAL
-	help
-	  If you say yes here you get support for the Taos TSL2550
-	  ambient light sensor.
-
-	  This driver can also be built as a module.  If so, the module
-	  will be called tsl2550.
-
 endmenu
drivers/i2c/chips/Makefile +0 -1
index 749cf36..d309782 100644
@@ -11,7 +11,6 @@
 #
 
 obj-$(CONFIG_DS1682)		+= ds1682.o
-obj-$(CONFIG_SENSORS_TSL2550)	+= tsl2550.o
 
 ifeq ($(CONFIG_I2C_DEBUG_CHIP),y)
 EXTRA_CFLAGS += -DDEBUG
drivers/i2c/chips/tsl2550.c deleted +0 -470

470 lines not on this page · raw message

Signature · 1 line
1.6.3.3
#1 lore raw

drivers/als/tsl2550.c line 88

Quoted 11 lines · Jonathan Cameron
drivers/als/tsl2550.c new file +11 -0
+static int tsl2550_get_id(void)
+{
+	int ret, val;
+
+idr_again:
+	if (unlikely(idr_pre_get(&tsl2550_idr, GFP_KERNEL) == 0))
+		return -ENOMEM;
+	spin_lock(&tsl2550_idr_lock);
+	ret = idr_get_new(&tsl2550_idr, NULL, &val);
+	if (unlikely(ret == -EAGAIN))
+		goto idr_again;

That looks like a fair chance to produce a deadlock by reacquiring the above spinlock.

Also I never see the above lock released later from this function or its caller.

#2 lore raw

---
Since V2:

Fix of silly idr allocation code mistake. Illustrated Jean's point that someone would muck this up rather too well. (thanks Frederick!)

Additions since previous V1:
Removed set operating mode sysfs and replaced with an illuminance0_range_max. If requested max is in low range it will go with that, otherwise maximum range is selected.

For now I've left the device id code etc alone, as moving this into the ALS core is still under debate.

Couple of trivial style fixes.

V1:

Minimal changes made. Untested due to lack of hardware.

---
 Documentation/ABI/testing/sysfs-class-als |    9 +
 drivers/als/Kconfig                       |   14 +
 drivers/als/Makefile                      |    2 +
 drivers/als/tsl2550.c                     |  536
+++++++++++++++++++++++++++++
 drivers/i2c/chips/Kconfig                 |   10 -
 drivers/i2c/chips/Makefile                |    1 -
 drivers/i2c/chips/tsl2550.c               |  470 -------------------------
 7 files changed, 561 insertions(+), 481 deletions(-)
(quoted diff) +0 -0

b/Documentation/ABI/testing/sysfs-class-als
index d3b33f3..9db1936 100644

Documentation/ABI/testing/sysfs-class-als +0 -0
@@ -7,3 +7,12 @@ Description:    Current Ambient Light Illuminance

reported by
Unit: lux (lumens per square meter)
RO

+What: /sys/class/als/.../illuminance[n]_range_max
+Date: Oct. 2009
+KernelVersion: 2.6.32
+Contact: Jonathan Cameron <[email protected]>
+Description: Maximum value of Ambient Light Illuminance as

+        reported by ALS driver. Used when a device
+        has a multiple operating ranges.
+        Unit: lux (lumens per square meter)
+        RW
drivers/als/Kconfig +14 -0
index 200c52b..1564ffc 100644
@@ -8,3 +8,17 @@ menuconfig ALS
       This framework provides a generic sysfs I/F for Ambient Light
       Sensor devices.
       If you want this support, you should say Y or M here.
+
+if ALS
+
+config ALS_TSL2550
+    tristate "Taos TSL2550 ambient light sensor"
+    depends on EXPERIMENTAL && I2C
+    help
+      If you say yes here you get support for the Taos TSL2550
+      ambient light sensor.
+
+      This driver can also be built as a module.  If so, the module
+      will be called tsl2550.
+
+endif #ALS
drivers/als/Makefile +2 -0
index a527197..7be5631 100644
@@ -3,3 +3,5 @@
 #
 
 obj-$(CONFIG_ALS)        += als_sys.o
+
+obj-$(CONFIG_ALS_TSL2550)    += tsl2550.o
\ No newline at end of file
drivers/als/tsl2550.c new file +536 -0

536 lines not on this page · raw message

drivers/i2c/chips/Kconfig +0 -10
index f9618f4..626bfcf 100644
@@ -16,14 +16,4 @@ config DS1682
       This driver can also be built as a module.  If so, the module
       will be called ds1682.
 
-config SENSORS_TSL2550
-    tristate "Taos TSL2550 ambient light sensor"
-    depends on EXPERIMENTAL
-    help
-      If you say yes here you get support for the Taos TSL2550
-      ambient light sensor.
-
-      This driver can also be built as a module.  If so, the module
-      will be called tsl2550.
-
 endmenu
drivers/i2c/chips/Makefile +0 -1
index 749cf36..d309782 100644
@@ -11,7 +11,6 @@
 #
 
 obj-$(CONFIG_DS1682)        += ds1682.o
-obj-$(CONFIG_SENSORS_TSL2550)    += tsl2550.o
 
 ifeq ($(CONFIG_I2C_DEBUG_CHIP),y)
 EXTRA_CFLAGS += -DDEBUG
drivers/i2c/chips/tsl2550.c deleted +0 -470

470 lines not on this page · raw message

Signature · 1 line
1.6.3.3