isl29020: ambient light sensor
PATCH 1/1 isl29020: ambient light sensor
From: Kalhan Trisal <[email protected]>
The LS driver will read the latest Lux measurement based upon the light brightness and will report the LUX output through sysfs interface.
This hardware isn't quite the same as the ISL29003 so has a different driver.
[Cleanups and added checks for I²C errors, reworked the API to match the
saner one agreed for other sensors]
---
drivers/misc/Kconfig | 10 ++ drivers/misc/Makefile | 1 drivers/misc/isl29020.c | 241 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 252 insertions(+), 0 deletions(-) create mode 100644 drivers/misc/isl29020.c
drivers/misc/Kconfig +10 -0
@@ -303,6 +303,16 @@ config ISL29003 This driver can also be built as a module. If so, the module will be called isl29003. +config ISL29020 + tristate "Intersil ISL29020 ambient light sensor" + depends on I2C + help + If you say yes here you get support for the Intersil ISL29020 + ambient light sensor. + + This driver can also be built as a module. If so, the module + will be called isl29020. + config SENSORS_TSL2550 tristate "Taos TSL2550 ambient light sensor" depends on I2C && SYSFS
drivers/misc/Makefile +1 -0
@@ -24,6 +24,7 @@ obj-$(CONFIG_SGI_GRU) += sgi-gru/ obj-$(CONFIG_CS5535_MFGPT) += cs5535-mfgpt.o obj-$(CONFIG_HP_ILO) += hpilo.o obj-$(CONFIG_ISL29003) += isl29003.o +obj-$(CONFIG_ISL29020) += isl29020.o obj-$(CONFIG_SENSORS_TSL2550) += tsl2550.o obj-$(CONFIG_EP93XX_PWM) += ep93xx_pwm.o obj-$(CONFIG_DS1682) += ds1682.o
drivers/misc/isl29020.c new file +241 -0
241 lines not on this page · raw message
Quoted 10 lines · On Fri, 22 Oct 2010 13:46:07 +0100 Alan Cox <[email protected]> wrote:
From: Kalhan Trisal <[email protected]>
The LS driver will read the latest Lux measurement based upon the light brightness and will report the LUX output through sysfs interface.
This hardware isn't quite the same as the ISL29003 so has a different driver.
...
Review
Quoted 10 lines
(quoted diff) +10
-0+static ssize_t als_lux_input_data_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct i2c_client *client = to_i2c_client(dev); + int ret_val, val; + unsigned long int lux; + int temp; + + pm_runtime_get_sync(dev); + msleep(100);
The msleep() is a bit mysterious. And long! A little code comment explaining why it's here would illuminate things (heh, I kill me).
Quoted 48 lines
(quoted diff) +45
-0+ mutex_lock(&mutex); + temp = i2c_smbus_read_byte_data(client, 0x02); /* MSB data */ + if (temp < 0) { + pm_runtime_put_sync(dev); + mutex_unlock(&mutex); + return temp; + } + + ret_val = i2c_smbus_read_byte_data(client, 0x01); /* LSB data */ + mutex_unlock(&mutex); + + if (ret_val < 0) { + pm_runtime_put_sync(dev); + return ret_val; + } + + ret_val |= temp << 8; + val = i2c_smbus_read_byte_data(client, 0x00); + pm_runtime_put_sync(dev); + if (val < 0) + return val; + lux = ((((1 << (2 * (val & 3))))*1000) * ret_val) / 65536; + return sprintf(buf, "%ld\n", lux); +} + +static int isl29020_runtime_suspend(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + als_set_power_state(client, 0); + return 0; +} + +static int isl29020_runtime_resume(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + als_set_power_state(client, 1); + return 0; +} + +MODULE_DEVICE_TABLE(i2c, isl29020_id); + +static const struct dev_pm_ops isl29020_pm_ops = { + .runtime_suspend = isl29020_runtime_suspend, + .runtime_resume = isl29020_runtime_resume, +};
Review
Quoted 10 lines
(quoted diff) +9
-0+static struct i2c_driver isl29020_driver = { + .driver = { + .name = "isl29020", + .pm = &isl29020_pm_ops, + }, + .probe = isl29020_probe, + .remove = isl29020_remove, + .id_table = isl29020_id, +};
Could/should we make the PM code disappear if !CONFIG_PM? Such as
drivers/misc/isl29020.c renamed from drivers/misc/isl29020.c~isl29020-ambient-light-sensor-fix +10 -3
@@ -192,6 +192,10 @@ static struct i2c_device_id isl29020_id[ { } }; +MODULE_DEVICE_TABLE (i2c, isl29020_id); + +#ifdef CONFIG_PM +static int isl29020_runtime_suspend (struct device *dev) {struct i2c_client *client =to_i2c_client (dev);
@@ -206,17 +210,20 @@ static int isl29020_runtime_resume(strucreturn 0 ; } -MODULE_DEVICE_TABLE (i2c, isl29020_id); -static const struct dev_pm_ops isl29020_pm_ops = { .runtime_suspend = isl29020_runtime_suspend, .runtime_resume = isl29020_runtime_resume, }; +#define ISL29020_PM_OPS (&isl29020_pm_ops) +#else /* CONFIG_PM */ +#define ISL29020_PM_OPS NULL +#endif /* CONFIG_PM */ +static struct i2c_driver isl29020_driver = { .driver = { .name ="isl29020" , - .pm = &isl29020_pm_ops, + .pm =ISL29020_PM_OPS , }, .probe = isl29020_probe, .remove = isl29020_remove,
_
before: 3066 bytes, after: 2705 bytes.
Quoted 13 lines · On Fri, 22 Oct 2010 12:51:30 -0700 Andrew Morton <[email protected]>…
Quoted 10 lines · On Fri, 22 Oct 2010 13:46:07 +0100 Alan Cox <[email protected]> wrote:
From: Kalhan Trisal <[email protected]>
The LS driver will read the latest Lux measurement based upon the light brightness and will report the LUX output through sysfs interface.
This hardware isn't quite the same as the ISL29003 so has a different driver.
...
Quoted 13 lines
Review
Quoted 10 lines
(quoted diff) +10
-0+static ssize_t als_lux_input_data_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct i2c_client *client = to_i2c_client(dev); + int ret_val, val; + unsigned long int lux; + int temp; + + pm_runtime_get_sync(dev); + msleep(100);The
msleep()is a bit mysterious. And long! A little code comment explaining why it's here would illuminate things (heh, I kill me).
It takes that long to get a sensible answer from the device after you power it up and sysfs doesn't keep enough context around to do poll etc.
It may be possible to shorten it if we've not been suspended but there isn't a sane way I've found to track last suspended time nicely and race free in the runtime_pm layer.
Quoted 1 line
Could/should we make the PM code disappear if !CONFIG_PM? Such as
Looks sensible. Will add to it.
Alan