* [PATCH 1/3] staging:iio:light:tsl2583 use read_raw, write_raw hooks.
2013-01-06 16:23 [PATCH 0/3] staging:iio:tsl2583 update interfaces Jonathan Cameron
@ 2013-01-06 16:23 ` Jonathan Cameron
2013-01-06 16:23 ` [PATCH 2/3] staging:iio:light:tsl2583 apply in_ prefix to attributes Jonathan Cameron
2013-01-06 16:23 ` [PATCH 3/3] staging:iio:light:tsl2583 switch to kstrto and strtobool Jonathan Cameron
2 siblings, 0 replies; 6+ messages in thread
From: Jonathan Cameron @ 2013-01-06 16:23 UTC (permalink / raw)
To: linux-iio; +Cc: jbrenner, Jonathan Cameron
This driver predates the introduction of these hooks that both reduce
the amount of code needed to provide basic interfaces and allow for
inkernel access to these values from other drivers.
This will change a few interfaces by applying an in_ prefix.
The rest of the driver will be brought in line with this convention
in a follow up patch.
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
drivers/staging/iio/light/tsl2583.c | 187 ++++++++++++++++--------------------
1 file changed, 85 insertions(+), 102 deletions(-)
diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
index b377dd3..30c1a36 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -506,62 +506,6 @@ static ssize_t taos_power_state_store(struct device *dev,
return len;
}
-static ssize_t taos_gain_show(struct device *dev,
- struct device_attribute *attr, char *buf)
-{
- struct iio_dev *indio_dev = dev_to_iio_dev(dev);
- struct tsl2583_chip *chip = iio_priv(indio_dev);
- char gain[4] = {0};
-
- switch (chip->taos_settings.als_gain) {
- case 0:
- strcpy(gain, "001");
- break;
- case 1:
- strcpy(gain, "008");
- break;
- case 2:
- strcpy(gain, "016");
- break;
- case 3:
- strcpy(gain, "111");
- break;
- }
-
- return sprintf(buf, "%s\n", gain);
-}
-
-static ssize_t taos_gain_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t len)
-{
- struct iio_dev *indio_dev = dev_to_iio_dev(dev);
- struct tsl2583_chip *chip = iio_priv(indio_dev);
- unsigned long value;
-
- if (strict_strtoul(buf, 0, &value))
- return -EINVAL;
-
- switch (value) {
- case 1:
- chip->taos_settings.als_gain = 0;
- break;
- case 8:
- chip->taos_settings.als_gain = 1;
- break;
- case 16:
- chip->taos_settings.als_gain = 2;
- break;
- case 111:
- chip->taos_settings.als_gain = 3;
- break;
- default:
- dev_err(dev, "Invalid Gain Index (must be 1,8,16,111)\n");
- return -1;
- }
-
- return len;
-}
-
static ssize_t taos_gain_available_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
@@ -605,31 +549,6 @@ static ssize_t taos_als_time_available_show(struct device *dev,
"50 100 150 200 250 300 350 400 450 500 550 600 650");
}
-static ssize_t taos_als_trim_show(struct device *dev,
- struct device_attribute *attr, char *buf)
-{
- struct iio_dev *indio_dev = dev_to_iio_dev(dev);
- struct tsl2583_chip *chip = iio_priv(indio_dev);
-
- return sprintf(buf, "%d\n", chip->taos_settings.als_gain_trim);
-}
-
-static ssize_t taos_als_trim_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t len)
-{
- struct iio_dev *indio_dev = dev_to_iio_dev(dev);
- struct tsl2583_chip *chip = iio_priv(indio_dev);
- unsigned long value;
-
- if (strict_strtoul(buf, 0, &value))
- return -EINVAL;
-
- if (value)
- chip->taos_settings.als_gain_trim = value;
-
- return len;
-}
-
static ssize_t taos_als_cal_target_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
@@ -655,18 +574,6 @@ static ssize_t taos_als_cal_target_store(struct device *dev,
return len;
}
-static ssize_t taos_lux_show(struct device *dev, struct device_attribute *attr,
- char *buf)
-{
- int ret;
-
- ret = taos_get_lux(dev_to_iio_dev(dev));
- if (ret < 0)
- return ret;
-
- return sprintf(buf, "%d\n", ret);
-}
-
static ssize_t taos_do_calibrate(struct device *dev,
struct device_attribute *attr, const char *buf, size_t len)
{
@@ -745,8 +652,6 @@ static ssize_t taos_luxtable_store(struct device *dev,
static DEVICE_ATTR(power_state, S_IRUGO | S_IWUSR,
taos_power_state_show, taos_power_state_store);
-static DEVICE_ATTR(illuminance0_calibscale, S_IRUGO | S_IWUSR,
- taos_gain_show, taos_gain_store);
static DEVICE_ATTR(illuminance0_calibscale_available, S_IRUGO,
taos_gain_available_show, NULL);
@@ -755,26 +660,19 @@ static DEVICE_ATTR(illuminance0_integration_time, S_IRUGO | S_IWUSR,
static DEVICE_ATTR(illuminance0_integration_time_available, S_IRUGO,
taos_als_time_available_show, NULL);
-static DEVICE_ATTR(illuminance0_calibbias, S_IRUGO | S_IWUSR,
- taos_als_trim_show, taos_als_trim_store);
-
static DEVICE_ATTR(illuminance0_input_target, S_IRUGO | S_IWUSR,
taos_als_cal_target_show, taos_als_cal_target_store);
-static DEVICE_ATTR(illuminance0_input, S_IRUGO, taos_lux_show, NULL);
static DEVICE_ATTR(illuminance0_calibrate, S_IWUSR, NULL, taos_do_calibrate);
static DEVICE_ATTR(illuminance0_lux_table, S_IRUGO | S_IWUSR,
taos_luxtable_show, taos_luxtable_store);
static struct attribute *sysfs_attrs_ctrl[] = {
&dev_attr_power_state.attr,
- &dev_attr_illuminance0_calibscale.attr, /* Gain */
&dev_attr_illuminance0_calibscale_available.attr,
&dev_attr_illuminance0_integration_time.attr, /* I time*/
&dev_attr_illuminance0_integration_time_available.attr,
- &dev_attr_illuminance0_calibbias.attr, /* trim */
&dev_attr_illuminance0_input_target.attr,
- &dev_attr_illuminance0_input.attr,
&dev_attr_illuminance0_calibrate.attr,
&dev_attr_illuminance0_lux_table.attr,
NULL
@@ -790,9 +688,92 @@ static int taos_tsl258x_device(unsigned char *bufp)
return ((bufp[TSL258X_CHIPID] & 0xf0) == 0x90);
}
+static const int tsl2583_scales[] = {1, 8, 16, 111 };
+
+static int tsl2583_write_raw(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan,
+ int val,
+ int val2,
+ long m)
+{
+ struct tsl2583_chip *chip = iio_priv(indio_dev);
+ int ret = 0;
+
+ switch (m) {
+ case IIO_CHAN_INFO_CALIBBIAS:
+ chip->taos_settings.als_gain_trim = val;
+ break;
+ case IIO_CHAN_INFO_CALIBSCALE:
+ switch (val) {
+ case 1:
+ chip->taos_settings.als_gain = 0;
+ break;
+ case 8:
+ chip->taos_settings.als_gain = 1;
+ break;
+ case 16:
+ chip->taos_settings.als_gain = 2;
+ break;
+ case 111:
+ chip->taos_settings.als_gain = 3;
+ break;
+ default:
+ ret = -EINVAL;
+ }
+ default:
+ ret = -EINVAL;
+ }
+ return ret;
+}
+
+static int tsl2583_read_raw(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan,
+ int *val,
+ int *val2,
+ long m)
+{
+ struct tsl2583_chip *chip = iio_priv(indio_dev);
+ int ret;
+
+ switch (m) {
+ case IIO_CHAN_INFO_PROCESSED:
+ ret = taos_get_lux(indio_dev);
+ if (ret < 0)
+ return ret;
+ *val = ret;
+ ret = IIO_VAL_INT;
+ break;
+ case IIO_CHAN_INFO_CALIBBIAS:
+ *val = chip->taos_settings.als_gain_trim;
+ ret = IIO_VAL_INT;
+ break;
+ case IIO_CHAN_INFO_CALIBSCALE:
+ *val = tsl2583_scales[chip->taos_settings.als_gain];
+ ret = IIO_VAL_INT;
+ break;
+ default:
+ ret = -EINVAL;
+ }
+
+ return ret;
+}
+
+static const struct iio_chan_spec tsl2583_channels[] = {
+ {
+ .type = IIO_LIGHT,
+ .indexed = 1,
+ .info_mask = IIO_CHAN_INFO_PROCESSED_SEPARATE_BIT |
+ IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT |
+ IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT,
+ .channel = 0,
+ },
+};
+
static const struct iio_info tsl2583_info = {
.attrs = &tsl2583_attribute_group,
.driver_module = THIS_MODULE,
+ .read_raw = &tsl2583_read_raw,
+ .write_raw = &tsl2583_write_raw,
};
/*
@@ -863,6 +844,8 @@ static int taos_probe(struct i2c_client *clientp,
indio_dev->info = &tsl2583_info;
indio_dev->dev.parent = &clientp->dev;
indio_dev->modes = INDIO_DIRECT_MODE;
+ indio_dev->channels = tsl2583_channels;
+ indio_dev->num_channels = ARRAY_SIZE(tsl2583_channels);
indio_dev->name = chip->client->name;
ret = iio_device_register(indio_dev);
if (ret) {
--
1.8.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 2/3] staging:iio:light:tsl2583 apply in_ prefix to attributes.
2013-01-06 16:23 [PATCH 0/3] staging:iio:tsl2583 update interfaces Jonathan Cameron
2013-01-06 16:23 ` [PATCH 1/3] staging:iio:light:tsl2583 use read_raw, write_raw hooks Jonathan Cameron
@ 2013-01-06 16:23 ` Jonathan Cameron
2013-01-06 16:23 ` [PATCH 3/3] staging:iio:light:tsl2583 switch to kstrto and strtobool Jonathan Cameron
2 siblings, 0 replies; 6+ messages in thread
From: Jonathan Cameron @ 2013-01-06 16:23 UTC (permalink / raw)
To: linux-iio; +Cc: jbrenner, Jonathan Cameron
Bring the naming of remaining attributes in line with those
created via the channel spec.
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
drivers/staging/iio/light/tsl2583.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
index 30c1a36..944db26 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -652,29 +652,29 @@ static ssize_t taos_luxtable_store(struct device *dev,
static DEVICE_ATTR(power_state, S_IRUGO | S_IWUSR,
taos_power_state_show, taos_power_state_store);
-static DEVICE_ATTR(illuminance0_calibscale_available, S_IRUGO,
+static DEVICE_ATTR(in_illuminance0_calibscale_available, S_IRUGO,
taos_gain_available_show, NULL);
-static DEVICE_ATTR(illuminance0_integration_time, S_IRUGO | S_IWUSR,
+static DEVICE_ATTR(in_illuminance0_integration_time, S_IRUGO | S_IWUSR,
taos_als_time_show, taos_als_time_store);
-static DEVICE_ATTR(illuminance0_integration_time_available, S_IRUGO,
+static DEVICE_ATTR(in_illuminance0_integration_time_available, S_IRUGO,
taos_als_time_available_show, NULL);
-static DEVICE_ATTR(illuminance0_input_target, S_IRUGO | S_IWUSR,
+static DEVICE_ATTR(in_illuminance0_input_target, S_IRUGO | S_IWUSR,
taos_als_cal_target_show, taos_als_cal_target_store);
-static DEVICE_ATTR(illuminance0_calibrate, S_IWUSR, NULL, taos_do_calibrate);
-static DEVICE_ATTR(illuminance0_lux_table, S_IRUGO | S_IWUSR,
+static DEVICE_ATTR(in_illuminance0_calibrate, S_IWUSR, NULL, taos_do_calibrate);
+static DEVICE_ATTR(in_illuminance0_lux_table, S_IRUGO | S_IWUSR,
taos_luxtable_show, taos_luxtable_store);
static struct attribute *sysfs_attrs_ctrl[] = {
&dev_attr_power_state.attr,
- &dev_attr_illuminance0_calibscale_available.attr,
- &dev_attr_illuminance0_integration_time.attr, /* I time*/
- &dev_attr_illuminance0_integration_time_available.attr,
- &dev_attr_illuminance0_input_target.attr,
- &dev_attr_illuminance0_calibrate.attr,
- &dev_attr_illuminance0_lux_table.attr,
+ &dev_attr_in_illuminance0_calibscale_available.attr,
+ &dev_attr_in_illuminance0_integration_time.attr, /* I time*/
+ &dev_attr_in_illuminance0_integration_time_available.attr,
+ &dev_attr_in_illuminance0_input_target.attr,
+ &dev_attr_in_illuminance0_calibrate.attr,
+ &dev_attr_in_illuminance0_lux_table.attr,
NULL
};
--
1.8.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 3/3] staging:iio:light:tsl2583 switch to kstrto and strtobool
2013-01-06 16:23 [PATCH 0/3] staging:iio:tsl2583 update interfaces Jonathan Cameron
2013-01-06 16:23 ` [PATCH 1/3] staging:iio:light:tsl2583 use read_raw, write_raw hooks Jonathan Cameron
2013-01-06 16:23 ` [PATCH 2/3] staging:iio:light:tsl2583 apply in_ prefix to attributes Jonathan Cameron
@ 2013-01-06 16:23 ` Jonathan Cameron
2013-01-12 10:31 ` Jonathan Cameron
2 siblings, 1 reply; 6+ messages in thread
From: Jonathan Cameron @ 2013-01-06 16:23 UTC (permalink / raw)
To: linux-iio; +Cc: jbrenner, Jonathan Cameron
Doing this results in cleaner code and better error handling.
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
drivers/staging/iio/light/tsl2583.c | 36 ++++++++++++++++++++++--------------
1 file changed, 22 insertions(+), 14 deletions(-)
diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
index 944db26..f45114f 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -493,15 +493,17 @@ static ssize_t taos_power_state_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t len)
{
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
- unsigned long value;
+ bool state;
+ int ret;
- if (strict_strtoul(buf, 0, &value))
- return -EINVAL;
+ ret = strtobool(buf, &state);
+ if (ret < 0)
+ return ret;
- if (value == 0)
- taos_chip_off(indio_dev);
- else
+ if (state)
taos_chip_on(indio_dev);
+ else
+ taos_chip_off(indio_dev);
return len;
}
@@ -527,9 +529,11 @@ static ssize_t taos_als_time_store(struct device *dev,
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
struct tsl2583_chip *chip = iio_priv(indio_dev);
unsigned long value;
+ int ret;
- if (strict_strtoul(buf, 0, &value))
- return -EINVAL;
+ ret = kstrtoul(buf, 0, &value);
+ if (ret < 0)
+ return ret;
if ((value < 50) || (value > 650))
return -EINVAL;
@@ -564,9 +568,11 @@ static ssize_t taos_als_cal_target_store(struct device *dev,
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
struct tsl2583_chip *chip = iio_priv(indio_dev);
unsigned long value;
+ int ret;
- if (strict_strtoul(buf, 0, &value))
- return -EINVAL;
+ ret = kstrotoul(buf, 0, &value);
+ if (ret < 0)
+ return ret;
if (value)
chip->taos_settings.als_cal_target = value;
@@ -578,12 +584,14 @@ static ssize_t taos_do_calibrate(struct device *dev,
struct device_attribute *attr, const char *buf, size_t len)
{
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
- unsigned long value;
+ bool cal;
+ int ret;
- if (strict_strtoul(buf, 0, &value))
- return -EINVAL;
+ ret = strtobool(buf, &cal);
+ if (ret < 0)
+ return ret;
- if (value == 1)
+ if (cal)
taos_als_calibrate(indio_dev);
return len;
--
1.8.1
^ permalink raw reply related [flat|nested] 6+ messages in thread