Re: [PATCH 2/4] isl29020: ambient light sensor

2010-04-15 Thread Jonathan Cameron
On 04/15/10 07:20, Daniel Mack wrote:
 On Wed, Apr 14, 2010 at 11:35:54PM +0100, Alan Cox wrote:
 Would it be possible to make the existing driver for the ISL29003
 support the ISL29020 as well?

 I dug the manuals out for these to take a look - the answer is they are
 quite different chips. 
 
 Hmm, sad :(
 
 However, the driver should be applied to the ALS tree after all, unless
 Jonathan plans to drop the whole thing, which I doubt.
Sadly ALS is dead.  Linus made it pretty clear he wasn't going to pull it.

Hence currently either ALS drivers are going into misc (and can be moved
elsewhere later), or we are taking them into IIO (and hence staging)
where they fit fine and we can sort out a bridge to input to answer Linus'
issue with the original patch set.

In the thread following Alan's repost (having moved this driver to misc)
Greg just pointed out the sysfs interface needed documenting, and I've
suggested that we sort out the naming properly (in a way compliant with
hwmon and the new IIO abi.  90% of what the ALS subsystem contributed was
defining the ABI anyway!

Jonathan
--
To unsubscribe from this list: send the line unsubscribe linux-i2c in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/4] isl29020: ambient light sensor

2010-04-14 Thread Alan Cox
From: Kalhan Trisal kalhan.tri...@intel.com

The LS driver will read the latest Lux measurement based upon the
light brightness and will report the LUX output through sysfs interface.

Signed-off-by: Kalhan Trisal kalhan.tri...@intel.com
Signed-off-by: Alan Cox a...@linux.intel.com
---

 drivers/hwmon/Kconfig|9 ++
 drivers/hwmon/Makefile   |1 
 drivers/hwmon/isl29020.c |  243 ++
 3 files changed, 253 insertions(+), 0 deletions(-)
 create mode 100644 drivers/hwmon/isl29020.c


diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 74f672d..1fa2533 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -1095,6 +1095,15 @@ config SENSORS_HMC6352
  This driver provides support for the Honeywell HMC6352 compass,
  providing configuration and heading data via sysfs.
 
+config SENSORS_ISL29020
+   tristate Intersil ISL29020 ALS
+   depends on I2C
+   help
+ If you say yes here you get support for the ALS Devices
+ Ambient Light Sensor monitoring chip.
+ Range values can be configured using sysfs.
+ Lux data is accessible via sysfs.
+
 if ACPI
 
 comment ACPI drivers
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index ad2ed36..13d6832 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -53,6 +53,7 @@ obj-$(CONFIG_SENSORS_HMC6352) += hmc6352.o
 obj-$(CONFIG_SENSORS_I5K_AMB)  += i5k_amb.o
 obj-$(CONFIG_SENSORS_IBMAEM)   += ibmaem.o
 obj-$(CONFIG_SENSORS_IBMPEX)   += ibmpex.o
+obj-$(CONFIG_SENSORS_ISL29020) += isl29020.o
 obj-$(CONFIG_SENSORS_IT87) += it87.o
 obj-$(CONFIG_SENSORS_K8TEMP)   += k8temp.o
 obj-$(CONFIG_SENSORS_K10TEMP)  += k10temp.o
diff --git a/drivers/hwmon/isl29020.c b/drivers/hwmon/isl29020.c
new file mode 100644
index 000..458140d
--- /dev/null
+++ b/drivers/hwmon/isl29020.c
@@ -0,0 +1,243 @@
+/*
+ * isl29020.c - Intersil  ALS Driver
+ *
+ * Copyright (C) 2008 Intel Corp
+ *
+ *  ~~
+ *
+ * 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; version 2 of the License.
+ *
+ * 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.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ * ~~
+ *
+ */
+
+#include linux/module.h
+#include linux/init.h
+#include linux/slab.h
+#include linux/i2c.h
+#include linux/hwmon.h
+#include linux/hwmon-sysfs.h
+#include linux/hwmon-vid.h
+#include linux/err.h
+#include linux/delay.h
+#include linux/mutex.h
+#include linux/sysfs.h
+
+
+#define ALS_MIN_RANGE_VAL 0
+#define ALS_MAX_RANGE_VAL 5
+
+struct als_data {
+   struct device *hwmon_dev;
+};
+
+static unsigned int i2c_write_current_data(struct i2c_client *client,
+   unsigned int reg, unsigned int value)
+{
+   int ret_val;
+
+   ret_val = i2c_smbus_write_byte_data(client, reg, value);
+   return ret_val;
+}
+
+static ssize_t als_sensing_range_show(struct device *dev,
+   struct device_attribute *attr,  char *buf)
+{
+   struct i2c_client *client = to_i2c_client(dev);
+   int  val;
+
+   val = i2c_smbus_read_byte_data(client, 0x00);
+   return sprintf(buf, %d000\n, 1  (2 * (val  3)));
+
+}
+
+static ssize_t als_lux_output_data_show(struct device *dev,
+   struct device_attribute *attr, char *buf)
+{
+   struct i2c_client *client = to_i2c_client(dev);
+   unsigned int ret_val, val;
+   unsigned long int lux, max_count;
+   int tempv1, tempv2;
+
+   max_count = 65535;
+   tempv1 = i2c_smbus_read_byte_data(client, 0x02); /* MSB data */
+   tempv2 = i2c_smbus_read_byte_data(client, 0x01); /* LSB data */
+   ret_val = tempv1;
+   ret_val = (ret_val  8 | tempv2);
+   val = i2c_smbus_read_byte_data(client, 0x00);
+   lux = 1  (2 * (val  3*1000) * ret_val) / max_count;
+   return sprintf(buf, %ld\n, lux);
+}
+
+static ssize_t als_sensing_range_store(struct device *dev,
+   struct device_attribute *attr, const  char *buf, size_t count)
+{
+   struct i2c_client *client = to_i2c_client(dev);
+   unsigned int ret_val, set_val = 0;
+   unsigned long val;
+
+   if (strict_strtoul(buf, 10, val))
+   return -EINVAL;
+   ret_val = i2c_smbus_read_byte_data(client, 0x00);
+   ret_val = ret_val  0xFC; /*reset the bit before setting them */
+

Re: [PATCH 2/4] isl29020: ambient light sensor

2010-04-14 Thread Daniel Mack
On Wed, Apr 14, 2010 at 01:51:49PM +0100, Alan Cox wrote:
 The LS driver will read the latest Lux measurement based upon the
 light brightness and will report the LUX output through sysfs interface.
 
 Signed-off-by: Kalhan Trisal kalhan.tri...@intel.com
 Signed-off-by: Alan Cox a...@linux.intel.com
 ---
 
  drivers/hwmon/Kconfig|9 ++
  drivers/hwmon/Makefile   |1 
  drivers/hwmon/isl29020.c |  243 
 ++
  3 files changed, 253 insertions(+), 0 deletions(-)
  create mode 100644 drivers/hwmon/isl29020.c

Would it be possible to make the existing driver for the ISL29003
support the ISL29020 as well?

Also note that there is a ALS (ambient light sensor) framework pending.
So patches against the 29003 driver should apply to this tree:

  git://git.kernel.org/pub/scm/linux/kernel/git/jic23/als.git

I copied the maintainer to this mail. Jonathan, any plans when ALS will
be merged?

Thanks,
Daniel



 diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
 index 74f672d..1fa2533 100644
 --- a/drivers/hwmon/Kconfig
 +++ b/drivers/hwmon/Kconfig
 @@ -1095,6 +1095,15 @@ config SENSORS_HMC6352
 This driver provides support for the Honeywell HMC6352 compass,
 providing configuration and heading data via sysfs.
  
 +config SENSORS_ISL29020
 + tristate Intersil ISL29020 ALS
 + depends on I2C
 + help
 +   If you say yes here you get support for the ALS Devices
 +   Ambient Light Sensor monitoring chip.
 +   Range values can be configured using sysfs.
 +   Lux data is accessible via sysfs.
 +
  if ACPI
  
  comment ACPI drivers
 diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
 index ad2ed36..13d6832 100644
 --- a/drivers/hwmon/Makefile
 +++ b/drivers/hwmon/Makefile
 @@ -53,6 +53,7 @@ obj-$(CONFIG_SENSORS_HMC6352)   += hmc6352.o
  obj-$(CONFIG_SENSORS_I5K_AMB)+= i5k_amb.o
  obj-$(CONFIG_SENSORS_IBMAEM) += ibmaem.o
  obj-$(CONFIG_SENSORS_IBMPEX) += ibmpex.o
 +obj-$(CONFIG_SENSORS_ISL29020)   += isl29020.o
  obj-$(CONFIG_SENSORS_IT87)   += it87.o
  obj-$(CONFIG_SENSORS_K8TEMP) += k8temp.o
  obj-$(CONFIG_SENSORS_K10TEMP)+= k10temp.o
 diff --git a/drivers/hwmon/isl29020.c b/drivers/hwmon/isl29020.c
 new file mode 100644
 index 000..458140d
 --- /dev/null
 +++ b/drivers/hwmon/isl29020.c
 @@ -0,0 +1,243 @@
 +/*
 + * isl29020.c - Intersil  ALS Driver
 + *
 + * Copyright (C) 2008 Intel Corp
 + *
 + *  
 ~~
 + *
 + * 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; version 2 of the License.
 + *
 + * 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.,
 + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 + * ~~
 + *
 + */
 +
 +#include linux/module.h
 +#include linux/init.h
 +#include linux/slab.h
 +#include linux/i2c.h
 +#include linux/hwmon.h
 +#include linux/hwmon-sysfs.h
 +#include linux/hwmon-vid.h
 +#include linux/err.h
 +#include linux/delay.h
 +#include linux/mutex.h
 +#include linux/sysfs.h
 +
 +
 +#define ALS_MIN_RANGE_VAL 0
 +#define ALS_MAX_RANGE_VAL 5
 +
 +struct als_data {
 + struct device *hwmon_dev;
 +};
 +
 +static unsigned int i2c_write_current_data(struct i2c_client *client,
 + unsigned int reg, unsigned int value)
 +{
 + int ret_val;
 +
 + ret_val = i2c_smbus_write_byte_data(client, reg, value);
 + return ret_val;
 +}
 +
 +static ssize_t als_sensing_range_show(struct device *dev,
 + struct device_attribute *attr,  char *buf)
 +{
 + struct i2c_client *client = to_i2c_client(dev);
 + int  val;
 +
 + val = i2c_smbus_read_byte_data(client, 0x00);
 + return sprintf(buf, %d000\n, 1  (2 * (val  3)));
 +
 +}
 +
 +static ssize_t als_lux_output_data_show(struct device *dev,
 + struct device_attribute *attr, char *buf)
 +{
 + struct i2c_client *client = to_i2c_client(dev);
 + unsigned int ret_val, val;
 + unsigned long int lux, max_count;
 + int tempv1, tempv2;
 +
 + max_count = 65535;
 + tempv1 = i2c_smbus_read_byte_data(client, 0x02); /* MSB data */
 + tempv2 = i2c_smbus_read_byte_data(client, 0x01); /* LSB data */
 + ret_val = tempv1;
 + ret_val = (ret_val  8 | tempv2);
 + val = i2c_smbus_read_byte_data(client, 0x00);
 + lux = 1  (2 * (val  3*1000) * ret_val) / max_count;
 + return sprintf(buf,