summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaxman Dewangan <ldewangan@nvidia.com>2010-09-15 13:29:58 +0530
committerBharat Nihalani <bnihalani@nvidia.com>2010-09-23 20:44:17 -0700
commitf62d5b35d65e87432575a4e637400899cbfbb940 (patch)
tree025ad807798fa55779f63e64681591091909b8aa
parentef2fffe1540044bd2b454997b54058bd727491f3 (diff)
[driver] isl29018: Moving driver from hwmon to iio/light.
Moving the isl29018 from hwmon to the staging/iio/light driver. Replacing the hwmon registration with iio registration and doing required changes to make it iio driver. bug 728678 (cherry picked from commit 2c72f7dff2b74375b35936cd4c94a891f169009d) Change-Id: I223d4451b62f2260cd2f9ee2ed8ba77ec8672b52 Reviewed-on: http://git-master/r/7109 Reviewed-by: Laxman Dewangan <ldewangan@nvidia.com> Tested-by: Laxman Dewangan <ldewangan@nvidia.com> Reviewed-by: Bharat Nihalani <bnihalani@nvidia.com>
-rw-r--r--drivers/hwmon/Kconfig11
-rw-r--r--drivers/hwmon/Makefile1
-rw-r--r--drivers/staging/iio/light/Kconfig26
-rw-r--r--drivers/staging/iio/light/Makefile3
-rwxr-xr-xdrivers/staging/iio/light/isl29018.c (renamed from drivers/hwmon/isl29018.c)203
5 files changed, 132 insertions, 112 deletions
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 84b57fd0d202..1c2d89078d9d 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -1019,17 +1019,6 @@ config SENSORS_AK8975
This driver will provide the measurements of magnetic flux in 3 axis
which can be used for compass application.
-config SENSORS_ISL29018
- tristate "ISL 29018 Ambient light sensor"
- depends on I2C
- default n
- help
- If you say yes here you get support for ambinet light sensor from
- intersil 29018.
- This driver will provide the measurements of ambient light intensity
- in lux.
- Data from sensor is accessible via sysfs.
-
if ACPI
comment "ACPI drivers"
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 92b09dd1fc28..099e8417e8eb 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -52,7 +52,6 @@ obj-$(CONFIG_SENSORS_HDAPS) += hdaps.o
obj-$(CONFIG_SENSORS_I5K_AMB) += i5k_amb.o
obj-$(CONFIG_SENSORS_IBMAEM) += ibmaem.o
obj-$(CONFIG_SENSORS_IBMPEX) += ibmpex.o
-obj-$(CONFIG_SENSORS_ISL29018) += isl29018.o
obj-$(CONFIG_SENSORS_IT87) += it87.o
obj-$(CONFIG_SENSORS_K8TEMP) += k8temp.o
obj-$(CONFIG_SENSORS_LIS3LV02D) += lis3lv02d.o hp_accel.o
diff --git a/drivers/staging/iio/light/Kconfig b/drivers/staging/iio/light/Kconfig
index 12af0c46fe22..4c3b31334276 100644
--- a/drivers/staging/iio/light/Kconfig
+++ b/drivers/staging/iio/light/Kconfig
@@ -4,10 +4,22 @@
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.
+ 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 ISL29018
+ tristate "ISL 29018 light and proximity sensor"
+ depends on I2C
+ default n
+ help
+ If you say yes here you get support for ambient light sensing and
+ proximity ir sensing from intersil ISL29018.
+ This driver will provide the measurements of ambient light intensity
+ in lux, proximity infrared sensing and normal infrared sensing.
+ Data from sensor is accessible via sysfs.
+
diff --git a/drivers/staging/iio/light/Makefile b/drivers/staging/iio/light/Makefile
index ccff15167609..aa8a2938be12 100644
--- a/drivers/staging/iio/light/Makefile
+++ b/drivers/staging/iio/light/Makefile
@@ -2,4 +2,5 @@
# Makefile for industrial I/O Light sensors
#
-obj-$(CONFIG_TSL2561) += tsl2561.o
+obj-$(CONFIG_TSL2561) += tsl2561.o
+obj-$(CONFIG_ISL29018) += isl29018.o
diff --git a/drivers/hwmon/isl29018.c b/drivers/staging/iio/light/isl29018.c
index 3a0c5e177255..5f25043b1f61 100755
--- a/drivers/hwmon/isl29018.c
+++ b/drivers/staging/iio/light/isl29018.c
@@ -1,5 +1,5 @@
/*
- * A hwmon driver for the light sensor ISL 29018.
+ * A iio driver for the light sensor ISL 29018.
*
* Hwmon driver for monitoring ambient light intensity in luxi, proximity
* sensing and infrared sensing.
@@ -23,11 +23,10 @@
#include <linux/module.h>
#include <linux/i2c.h>
-#include <linux/hwmon.h>
-#include <linux/hwmon-sysfs.h>
#include <linux/err.h>
#include <linux/mutex.h>
#include <linux/delay.h>
+#include "../iio.h"
/*#define DEBUG 1*/
/*#define VERBOSE_DEBUG 1*/
@@ -56,9 +55,9 @@
#define ISL29018_REG_ADD_DATA_MSB 0x03
#define ISL29018_MAX_REGS ISL29018_REG_ADD_DATA_MSB
-struct isl29018_data {
- struct device *hwmon_dev;
- struct attribute_group attrs;
+struct isl29018_chip {
+ struct iio_dev *indio_dev;
+ struct i2c_client *client;
struct mutex lock;
unsigned int range;
unsigned int adc_bit;
@@ -71,9 +70,9 @@ static bool isl29018_write_data(struct i2c_client *client, u8 reg,
{
u8 regval;
int ret = 0;
- struct isl29018_data *data = i2c_get_clientdata(client);
+ struct isl29018_chip *chip = i2c_get_clientdata(client);
- regval = data->reg_cache[reg];
+ regval = chip->reg_cache[reg];
regval &= ~mask;
regval |= val << shift;
@@ -82,7 +81,7 @@ static bool isl29018_write_data(struct i2c_client *client, u8 reg,
dev_err(&client->dev, "Write to device fails status %x\n", ret);
return false;
}
- data->reg_cache[reg] = regval;
+ chip->reg_cache[reg] = regval;
return true;
}
@@ -148,11 +147,11 @@ static int isl29018_read_sensor_input(struct i2c_client *client, int mode)
static bool isl29018_read_lux(struct i2c_client *client, int *lux)
{
int lux_data;
- struct isl29018_data *data = i2c_get_clientdata(client);
+ struct isl29018_chip *chip = i2c_get_clientdata(client);
lux_data = isl29018_read_sensor_input(client, COMMMAND1_OPMODE_ALS_ONCE);
if (lux_data > 0) {
- *lux = (lux_data * data->range) >> data->adc_bit;
+ *lux = (lux_data * chip->range) >> chip->adc_bit;
return true;
}
return false;
@@ -207,16 +206,17 @@ static bool isl29018_read_proximity_ir(struct i2c_client *client, int scheme,
static ssize_t get_sensor_data(struct device *dev, char *buf, int mode)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct isl29018_data *data = i2c_get_clientdata(client);
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct isl29018_chip *chip = indio_dev->dev_data;
+ struct i2c_client *client = chip->client;
int value = 0;
bool status;
- mutex_lock(&data->lock);
+ mutex_lock(&chip->lock);
switch (mode) {
case COMMMAND1_OPMODE_PROX_ONCE:
status = isl29018_read_proximity_ir(client,
- data->prox_scheme, &value);
+ chip->prox_scheme, &value);
break;
case COMMMAND1_OPMODE_ALS_ONCE:
@@ -229,16 +229,16 @@ static ssize_t get_sensor_data(struct device *dev, char *buf, int mode)
default:
dev_err(&client->dev,"Mode %d is not supported\n",mode);
- mutex_unlock(&data->lock);
+ mutex_unlock(&chip->lock);
return -EBUSY;
}
if (!status) {
dev_err(&client->dev, "Error in Reading data");
- mutex_unlock(&data->lock);
+ mutex_unlock(&chip->lock);
return -EBUSY;
}
- mutex_unlock(&data->lock);
+ mutex_unlock(&chip->lock);
return sprintf(buf, "%d\n", value);
}
@@ -247,18 +247,19 @@ static ssize_t get_sensor_data(struct device *dev, char *buf, int mode)
static ssize_t show_range(struct device *dev,
struct device_attribute *attr, char *buf)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct isl29018_data *data = i2c_get_clientdata(client);
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct isl29018_chip *chip = indio_dev->dev_data;
dev_vdbg(dev, "%s()\n", __func__);
- return sprintf(buf, "%u\n", data->range);
+ return sprintf(buf, "%u\n", chip->range);
}
static ssize_t store_range(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct isl29018_data *data = i2c_get_clientdata(client);
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct isl29018_chip *chip = indio_dev->dev_data;
+ struct i2c_client *client = chip->client;
bool status;
unsigned long lval;
unsigned int new_range;
@@ -274,15 +275,15 @@ static ssize_t store_range(struct device *dev,
return -EINVAL;
}
- mutex_lock(&data->lock);
+ mutex_lock(&chip->lock);
status = isl29018_set_range(client, lval, &new_range);
if (!status) {
- mutex_unlock(&data->lock);
+ mutex_unlock(&chip->lock);
dev_err(dev, "Error in setting max range\n");
return -EINVAL;
}
- data->range = new_range;
- mutex_unlock(&data->lock);
+ chip->range = new_range;
+ mutex_unlock(&chip->lock);
return count;
}
@@ -290,18 +291,19 @@ static ssize_t store_range(struct device *dev,
static ssize_t show_resolution(struct device *dev,
struct device_attribute *attr, char *buf)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct isl29018_data *data = i2c_get_clientdata(client);
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct isl29018_chip *chip = indio_dev->dev_data;
dev_vdbg(dev, "%s()\n", __func__);
- return sprintf(buf, "%u\n", data->adc_bit);
+ return sprintf(buf, "%u\n", chip->adc_bit);
}
static ssize_t store_resolution(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct isl29018_data *data = i2c_get_clientdata(client);
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct isl29018_chip *chip = indio_dev->dev_data;
+ struct i2c_client *client = chip->client;
bool status;
unsigned long lval;
unsigned int new_adc_bit;
@@ -315,15 +317,15 @@ static ssize_t store_resolution(struct device *dev,
return -EINVAL;
}
- mutex_lock(&data->lock);
+ mutex_lock(&chip->lock);
status = isl29018_set_resolution(client, lval, &new_adc_bit);
if (!status) {
- mutex_unlock(&data->lock);
+ mutex_unlock(&chip->lock);
dev_err(dev, "Error in setting resolution\n");
return -EINVAL;
}
- data->adc_bit = new_adc_bit;
- mutex_unlock(&data->lock);
+ chip->adc_bit = new_adc_bit;
+ mutex_unlock(&chip->lock);
return count;
}
@@ -331,18 +333,18 @@ static ssize_t store_resolution(struct device *dev,
static ssize_t show_prox_scheme(struct device *dev,
struct device_attribute *attr, char *buf)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct isl29018_data *data = i2c_get_clientdata(client);
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct isl29018_chip *chip = indio_dev->dev_data;
dev_vdbg(dev, "%s()\n", __func__);
- return sprintf(buf, "%d\n", data->prox_scheme);
+ return sprintf(buf, "%d\n", chip->prox_scheme);
}
static ssize_t store_prox_scheme(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
- struct i2c_client *client = to_i2c_client(dev);
- struct isl29018_data *data = i2c_get_clientdata(client);
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct isl29018_chip *chip = indio_dev->dev_data;
unsigned long lval;
dev_vdbg(dev, "%s()\n", __func__);
@@ -354,9 +356,9 @@ static ssize_t store_prox_scheme(struct device *dev,
return -EINVAL;
}
- mutex_lock(&data->lock);
- data->prox_scheme = (int)lval;
- mutex_unlock(&data->lock);
+ mutex_lock(&chip->lock);
+ chip->prox_scheme = (int)lval;
+ mutex_unlock(&chip->lock);
return count;
}
@@ -381,42 +383,56 @@ static ssize_t show_proxim_ir(struct device *dev,
return get_sensor_data(dev, buf, COMMMAND1_OPMODE_PROX_ONCE);
}
-static SENSOR_DEVICE_ATTR(range, S_IRUGO | S_IWUSR,
- show_range, store_range, 0);
-static SENSOR_DEVICE_ATTR(resolution, S_IRUGO | S_IWUSR,
- show_resolution, store_resolution, 1);
-static SENSOR_DEVICE_ATTR(proximity_scheme, S_IRUGO | S_IWUSR,
- show_prox_scheme, store_prox_scheme, 2);
-static SENSOR_DEVICE_ATTR(lux, S_IRUGO, show_lux, NULL, 3);
-static SENSOR_DEVICE_ATTR(ir, S_IRUGO, show_ir, NULL, 4);
-static SENSOR_DEVICE_ATTR(proxim_ir, S_IRUGO, show_proxim_ir, NULL, 5);
-
-static struct attribute *isl29018_attr[] = {
- &sensor_dev_attr_range.dev_attr.attr,
- &sensor_dev_attr_resolution.dev_attr.attr,
- &sensor_dev_attr_proximity_scheme.dev_attr.attr,
- &sensor_dev_attr_lux.dev_attr.attr,
- &sensor_dev_attr_ir.dev_attr.attr,
- &sensor_dev_attr_proxim_ir.dev_attr.attr,
+/* Read name */
+static ssize_t show_name(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct isl29018_chip *chip = indio_dev->dev_data;
+ return sprintf(buf, "%s\n", chip->client->name);
+}
+
+static IIO_DEVICE_ATTR(range, S_IRUGO | S_IWUSR, show_range, store_range, 0);
+static IIO_DEVICE_ATTR(resolution, S_IRUGO | S_IWUSR,
+ show_resolution, store_resolution, 0);
+static IIO_DEVICE_ATTR(proximity_scheme, S_IRUGO | S_IWUSR,
+ show_prox_scheme, store_prox_scheme, 0);
+static IIO_DEVICE_ATTR(lux, S_IRUGO, show_lux, NULL, 0);
+static IIO_DEVICE_ATTR(ir, S_IRUGO, show_ir, NULL, 0);
+static IIO_DEVICE_ATTR(proxim_ir, S_IRUGO, show_proxim_ir, NULL, 0);
+static IIO_DEVICE_ATTR(name, S_IRUGO, show_name, NULL, 0);
+
+static struct attribute *isl29018_attributes[] = {
+ &iio_dev_attr_name.dev_attr.attr,
+ &iio_dev_attr_range.dev_attr.attr,
+ &iio_dev_attr_resolution.dev_attr.attr,
+ &iio_dev_attr_proximity_scheme.dev_attr.attr,
+ &iio_dev_attr_lux.dev_attr.attr,
+ &iio_dev_attr_ir.dev_attr.attr,
+ &iio_dev_attr_proxim_ir.dev_attr.attr,
NULL
};
-static int isl29018_init_client(struct i2c_client *client)
+static const struct attribute_group isl29108_group = {
+ .attrs = isl29018_attributes,
+};
+
+static int isl29018_chip_init(struct i2c_client *client)
{
- struct isl29018_data *data = i2c_get_clientdata(client);
+ struct isl29018_chip *chip = i2c_get_clientdata(client);
bool status;
int i;
int new_adc_bit;
unsigned int new_range;
- for (i = 0; i < ARRAY_SIZE(data->reg_cache); i++) {
- data->reg_cache[i] = 0;
+ for (i = 0; i < ARRAY_SIZE(chip->reg_cache); i++) {
+ chip->reg_cache[i] = 0;
}
/* set defaults */
- status = isl29018_set_range(client, data->range, &new_range);
+ status = isl29018_set_range(client, chip->range, &new_range);
if (status)
- status = isl29018_set_resolution(client, data->adc_bit,
+ status = isl29018_set_resolution(client, chip->adc_bit,
&new_adc_bit);
if (!status) {
dev_err(&client->dev, "Init of isl29018 fails\n");
@@ -428,56 +444,59 @@ static int isl29018_init_client(struct i2c_client *client)
static int __devinit isl29018_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
- struct isl29018_data *data;
+ struct isl29018_chip *chip;
int err;
- data = kzalloc(sizeof (struct isl29018_data), GFP_KERNEL);
- if (!data) {
+ chip = kzalloc(sizeof (struct isl29018_chip), GFP_KERNEL);
+ if (!chip) {
dev_err(&client->dev, "Memory allocation fails\n");
err = -ENOMEM;
goto exit;
}
- i2c_set_clientdata(client, data);
- mutex_init(&data->lock);
+ i2c_set_clientdata(client, chip);
+ chip->client = client;
+
+ mutex_init(&chip->lock);
- data->range = 1000;
- data->adc_bit = 16;
+ chip->range = 1000;
+ chip->adc_bit = 16;
- err = isl29018_init_client(client);
+ err = isl29018_chip_init(client);
if (err)
goto exit_free;
- /* Register sysfs hooks */
- data->attrs.attrs = isl29018_attr;
- err = sysfs_create_group(&client->dev.kobj, &data->attrs);
- if (err) {
- dev_err(&client->dev, "Not able to create the sysfs\n");
+ chip->indio_dev = iio_allocate_device();
+ if (!chip->indio_dev) {
+ dev_err(&client->dev, "iio allocation fails\n");
goto exit_free;
}
- data->hwmon_dev = hwmon_device_register(&client->dev);
- if (IS_ERR(data->hwmon_dev)) {
- dev_err(&client->dev, "hwmon registration fails\n");
- err = PTR_ERR(data->hwmon_dev);
- goto exit_remove;
+ chip->indio_dev->attrs = &isl29108_group;
+ chip->indio_dev->dev.parent = &client->dev;
+ chip->indio_dev->dev_data = (void *)(chip);
+ chip->indio_dev->driver_module = THIS_MODULE;
+ chip->indio_dev->modes = INDIO_DIRECT_MODE;
+ err = iio_device_register(chip->indio_dev);
+ if (err) {
+ dev_err(&client->dev, "iio registration fails\n");
+ goto exit_iio_free;
}
return 0;
-exit_remove:
- sysfs_remove_group(&client->dev.kobj, &data->attrs);
+exit_iio_free:
+ iio_free_device(chip->indio_dev);
exit_free:
- kfree(data);
+ kfree(chip);
exit:
return err;
}
static int __devexit isl29018_remove(struct i2c_client *client)
{
- struct isl29018_data *data = i2c_get_clientdata(client);
+ struct isl29018_chip *chip = i2c_get_clientdata(client);
dev_dbg(&client->dev, "%s()\n", __func__);
- hwmon_device_unregister(data->hwmon_dev);
- sysfs_remove_group(&client->dev.kobj, &data->attrs);
- kfree(data);
+ iio_device_unregister(chip->indio_dev);
+ kfree(chip);
return 0;
}