* [PATCH 1/1] iio: vcnl4000: Add IR current adjust support
@ 2016-07-18 14:09 Pratik Prajapati
2016-07-18 22:20 ` Peter Meerwald-Stadler
0 siblings, 1 reply; 8+ messages in thread
From: Pratik Prajapati @ 2016-07-18 14:09 UTC (permalink / raw)
To: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
Peter Meerwald-Stadler
Cc: linux-iio, linux-kernel, Pratik Prajapati
Signed-off-by: Pratik Prajapati <pratik.prajapati12@gmail.com>
---
drivers/iio/light/vcnl4000.c | 119 +++++++++++++++++++++++++++++++++++++++++--
1 file changed, 116 insertions(+), 3 deletions(-)
diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c
index c9d85bb..6b8b223 100644
--- a/drivers/iio/light/vcnl4000.c
+++ b/drivers/iio/light/vcnl4000.c
@@ -11,7 +11,6 @@
* IIO driver for VCNL4000 (7-bit I2C slave address 0x13)
*
* TODO:
- * allow to adjust IR current
* proximity threshold and event handling
*/
@@ -19,6 +18,7 @@
#include <linux/i2c.h>
#include <linux/err.h>
#include <linux/delay.h>
+#include <linux/regmap.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
@@ -42,8 +42,14 @@
#define VCNL4000_AL_OD 0x10 /* start on-demand ALS measurement */
#define VCNL4000_PS_OD 0x08 /* start on-demand proximity measurement */
+/* Bit mask for LED_CURRENT register */
+#define VCNL4000_LED_CURRENT_MASK 0x3F
+#define VCNL4000_LED_CURRENT_MAX 20
+
struct vcnl4000_data {
struct i2c_client *client;
+ struct mutex lock;
+ struct regmap *regmap;
};
static const struct i2c_device_id vcnl4000_id[] = {
@@ -98,9 +104,36 @@ static const struct iio_chan_spec vcnl4000_channels[] = {
}, {
.type = IIO_PROXIMITY,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+ }, {
+ .type = IIO_CURRENT,
+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+ BIT(IIO_CHAN_INFO_SCALE),
+ .extend_name = "led",
+ .output = 1,
+ .scan_index = -1,
}
};
+static int vcnl4000_write_led_current_raw(struct vcnl4000_data *data, int val)
+{
+ if (val < 0 || val > VCNL4000_LED_CURRENT_MAX)
+ return -ERANGE;
+ return regmap_write_bits(data->regmap, VCNL4000_LED_CURRENT,
+ VCNL4000_LED_CURRENT_MASK, val);
+}
+
+static int vcnl4000_read_led_current_raw(struct vcnl4000_data *data)
+{
+ unsigned int regval;
+ int ret;
+
+ ret = regmap_read(data->regmap, VCNL4000_LED_CURRENT, ®val);
+ if (ret < 0)
+ return ret;
+ regval &= VCNL4000_LED_CURRENT_MASK;
+ return regval;
+}
+
static int vcnl4000_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val, int *val2, long mask)
@@ -127,15 +160,31 @@ static int vcnl4000_read_raw(struct iio_dev *indio_dev,
return ret;
ret = IIO_VAL_INT;
break;
+ case IIO_CURRENT:
+ mutex_lock(&data->lock);
+ ret = vcnl4000_read_led_current_raw(data);
+ mutex_unlock(&data->lock);
+ if (ret < 0)
+ return ret;
+ *val = ret;
+ return IIO_VAL_INT;
default:
break;
}
break;
+
case IIO_CHAN_INFO_SCALE:
- if (chan->type == IIO_LIGHT) {
+ switch (chan->type) {
+ case IIO_LIGHT:
*val = 0;
*val2 = 250000;
- ret = IIO_VAL_INT_PLUS_MICRO;
+ return IIO_VAL_INT_PLUS_MICRO;
+ case IIO_CURRENT:
+ /* Output register is in 10s of miliamps */
+ *val = 10;
+ return IIO_VAL_INT;
+ default:
+ break;
}
break;
default:
@@ -145,11 +194,69 @@ static int vcnl4000_read_raw(struct iio_dev *indio_dev,
return ret;
}
+static int vcnl4000_write_raw(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan,
+ int val, int val2, long mask)
+{
+ struct vcnl4000_data *data = iio_priv(indio_dev);
+ int ret;
+
+ if (mask == IIO_CHAN_INFO_RAW && chan->type == IIO_CURRENT) {
+ mutex_lock(&data->lock);
+ ret = vcnl4000_write_led_current_raw(data, val);
+ mutex_unlock(&data->lock);
+ return ret;
+ }
+ return -EINVAL;
+}
+
static const struct iio_info vcnl4000_info = {
.read_raw = vcnl4000_read_raw,
+ .write_raw = vcnl4000_write_raw,
.driver_module = THIS_MODULE,
};
+static bool vcnl4000_readable_reg(struct device *dev, unsigned int reg)
+{
+ switch (reg) {
+ case VCNL4000_COMMAND:
+ case VCNL4000_PROD_REV:
+ case VCNL4000_LED_CURRENT:
+ case VCNL4000_AL_PARAM:
+ case VCNL4000_AL_RESULT_HI:
+ case VCNL4000_AL_RESULT_LO:
+ case VCNL4000_PS_RESULT_HI:
+ case VCNL4000_PS_RESULT_LO:
+ case VCNL4000_PS_MEAS_FREQ:
+ case VCNL4000_PS_MOD_ADJ:
+ return true;
+ default:
+ return false;
+ }
+}
+
+static bool vcnl4000_writeable_reg(struct device *dev, unsigned int reg)
+{
+ switch (reg) {
+ case VCNL4000_COMMAND:
+ case VCNL4000_LED_CURRENT:
+ case VCNL4000_AL_PARAM:
+ case VCNL4000_PS_MEAS_FREQ:
+ case VCNL4000_PS_MOD_ADJ:
+ return true;
+ default:
+ return false;
+ }
+}
+
+static const struct regmap_config vcnl4000_regmap_config = {
+ .reg_bits = 8,
+ .val_bits = 8,
+ .max_register = VCNL4000_PS_MOD_ADJ,
+ .readable_reg = vcnl4000_readable_reg,
+ .writeable_reg = vcnl4000_writeable_reg,
+};
+
static int vcnl4000_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
@@ -162,7 +269,13 @@ static int vcnl4000_probe(struct i2c_client *client,
return -ENOMEM;
data = iio_priv(indio_dev);
+ data->regmap = devm_regmap_init_i2c(client, &vcnl4000_regmap_config);
+ if (IS_ERR(data->regmap)) {
+ dev_err(&client->dev, "regmap_init failed!\n");
+ return PTR_ERR(data->regmap);
+ }
i2c_set_clientdata(client, indio_dev);
+ mutex_init(&data->lock);
data->client = client;
ret = i2c_smbus_read_byte_data(data->client, VCNL4000_PROD_REV);
--
2.6.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/1] iio: vcnl4000: Add IR current adjust support
2016-07-18 14:09 [PATCH 1/1] iio: vcnl4000: Add IR current adjust support Pratik Prajapati
@ 2016-07-18 22:20 ` Peter Meerwald-Stadler
2016-07-19 6:10 ` Pratik Prajapati
0 siblings, 1 reply; 8+ messages in thread
From: Peter Meerwald-Stadler @ 2016-07-18 22:20 UTC (permalink / raw)
To: Pratik Prajapati
Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen, linux-iio,
linux-kernel
> Signed-off-by: Pratik Prajapati <pratik.prajapati12@gmail.com>
comments below; nice addition
it seems this patch clashes with the recent changes to this driver in
iio-testing; can you rebase on top please?
I suggest to split out the transition to regmap in a separate patch
> ---
> drivers/iio/light/vcnl4000.c | 119 +++++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 116 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c
> index c9d85bb..6b8b223 100644
> --- a/drivers/iio/light/vcnl4000.c
> +++ b/drivers/iio/light/vcnl4000.c
> @@ -11,7 +11,6 @@
> * IIO driver for VCNL4000 (7-bit I2C slave address 0x13)
> *
> * TODO:
> - * allow to adjust IR current
> * proximity threshold and event handling
> */
>
> @@ -19,6 +18,7 @@
> #include <linux/i2c.h>
> #include <linux/err.h>
> #include <linux/delay.h>
> +#include <linux/regmap.h>
>
> #include <linux/iio/iio.h>
> #include <linux/iio/sysfs.h>
> @@ -42,8 +42,14 @@
> #define VCNL4000_AL_OD 0x10 /* start on-demand ALS measurement */
> #define VCNL4000_PS_OD 0x08 /* start on-demand proximity measurement */
>
> +/* Bit mask for LED_CURRENT register */
> +#define VCNL4000_LED_CURRENT_MASK 0x3F
> +#define VCNL4000_LED_CURRENT_MAX 20
> +
> struct vcnl4000_data {
> struct i2c_client *client;
> + struct mutex lock;
> + struct regmap *regmap;
> };
>
> static const struct i2c_device_id vcnl4000_id[] = {
> @@ -98,9 +104,36 @@ static const struct iio_chan_spec vcnl4000_channels[] = {
> }, {
> .type = IIO_PROXIMITY,
> .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> + }, {
> + .type = IIO_CURRENT,
> + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> + BIT(IIO_CHAN_INFO_SCALE),
> + .extend_name = "led",
> + .output = 1,
> + .scan_index = -1,
> }
end with a , maybe
> };
>
> +static int vcnl4000_write_led_current_raw(struct vcnl4000_data *data, int val)
> +{
> + if (val < 0 || val > VCNL4000_LED_CURRENT_MAX)
> + return -ERANGE;
> + return regmap_write_bits(data->regmap, VCNL4000_LED_CURRENT,
> + VCNL4000_LED_CURRENT_MASK, val);
> +}
> +
> +static int vcnl4000_read_led_current_raw(struct vcnl4000_data *data)
> +{
> + unsigned int regval;
> + int ret;
> +
> + ret = regmap_read(data->regmap, VCNL4000_LED_CURRENT, ®val);
> + if (ret < 0)
> + return ret;
> + regval &= VCNL4000_LED_CURRENT_MASK;
> + return regval;
> +}
> +
> static int vcnl4000_read_raw(struct iio_dev *indio_dev,
> struct iio_chan_spec const *chan,
> int *val, int *val2, long mask)
> @@ -127,15 +160,31 @@ static int vcnl4000_read_raw(struct iio_dev *indio_dev,
> return ret;
> ret = IIO_VAL_INT;
> break;
> + case IIO_CURRENT:
> + mutex_lock(&data->lock);
> + ret = vcnl4000_read_led_current_raw(data);
> + mutex_unlock(&data->lock);
> + if (ret < 0)
> + return ret;
> + *val = ret;
> + return IIO_VAL_INT;
> default:
> break;
> }
> break;
> +
> case IIO_CHAN_INFO_SCALE:
> - if (chan->type == IIO_LIGHT) {
> + switch (chan->type) {
> + case IIO_LIGHT:
> *val = 0;
> *val2 = 250000;
> - ret = IIO_VAL_INT_PLUS_MICRO;
> + return IIO_VAL_INT_PLUS_MICRO;
> + case IIO_CURRENT:
> + /* Output register is in 10s of miliamps */
milliamps
> + *val = 10;
> + return IIO_VAL_INT;
> + default:
> + break;
> }
> break;
> default:
> @@ -145,11 +194,69 @@ static int vcnl4000_read_raw(struct iio_dev *indio_dev,
> return ret;
> }
>
> +static int vcnl4000_write_raw(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan,
> + int val, int val2, long mask)
> +{
> + struct vcnl4000_data *data = iio_priv(indio_dev);
> + int ret;
> +
> + if (mask == IIO_CHAN_INFO_RAW && chan->type == IIO_CURRENT) {
> + mutex_lock(&data->lock);
> + ret = vcnl4000_write_led_current_raw(data, val);
> + mutex_unlock(&data->lock);
> + return ret;
> + }
> + return -EINVAL;
> +}
> +
> static const struct iio_info vcnl4000_info = {
> .read_raw = vcnl4000_read_raw,
> + .write_raw = vcnl4000_write_raw,
> .driver_module = THIS_MODULE,
> };
>
> +static bool vcnl4000_readable_reg(struct device *dev, unsigned int reg)
> +{
> + switch (reg) {
> + case VCNL4000_COMMAND:
> + case VCNL4000_PROD_REV:
> + case VCNL4000_LED_CURRENT:
> + case VCNL4000_AL_PARAM:
> + case VCNL4000_AL_RESULT_HI:
> + case VCNL4000_AL_RESULT_LO:
> + case VCNL4000_PS_RESULT_HI:
> + case VCNL4000_PS_RESULT_LO:
> + case VCNL4000_PS_MEAS_FREQ:
> + case VCNL4000_PS_MOD_ADJ:
> + return true;
> + default:
> + return false;
> + }
> +}
> +
> +static bool vcnl4000_writeable_reg(struct device *dev, unsigned int reg)
> +{
> + switch (reg) {
> + case VCNL4000_COMMAND:
> + case VCNL4000_LED_CURRENT:
> + case VCNL4000_AL_PARAM:
> + case VCNL4000_PS_MEAS_FREQ:
> + case VCNL4000_PS_MOD_ADJ:
> + return true;
> + default:
> + return false;
> + }
> +}
> +
> +static const struct regmap_config vcnl4000_regmap_config = {
> + .reg_bits = 8,
> + .val_bits = 8,
> + .max_register = VCNL4000_PS_MOD_ADJ,
> + .readable_reg = vcnl4000_readable_reg,
> + .writeable_reg = vcnl4000_writeable_reg,
> +};
> +
> static int vcnl4000_probe(struct i2c_client *client,
> const struct i2c_device_id *id)
> {
> @@ -162,7 +269,13 @@ static int vcnl4000_probe(struct i2c_client *client,
> return -ENOMEM;
>
> data = iio_priv(indio_dev);
> + data->regmap = devm_regmap_init_i2c(client, &vcnl4000_regmap_config);
> + if (IS_ERR(data->regmap)) {
> + dev_err(&client->dev, "regmap_init failed!\n");
> + return PTR_ERR(data->regmap);
> + }
> i2c_set_clientdata(client, indio_dev);
> + mutex_init(&data->lock);
> data->client = client;
>
> ret = i2c_smbus_read_byte_data(data->client, VCNL4000_PROD_REV);
>
--
Peter Meerwald-Stadler
+43-664-2444418 (mobile)
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/1] iio: vcnl4000: Add IR current adjust support
2016-07-18 22:20 ` Peter Meerwald-Stadler
@ 2016-07-19 6:10 ` Pratik Prajapati
2016-07-19 6:21 ` Peter Meerwald-Stadler
0 siblings, 1 reply; 8+ messages in thread
From: Pratik Prajapati @ 2016-07-19 6:10 UTC (permalink / raw)
To: Peter Meerwald-Stadler
Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen, linux-iio,
linux-kernel
On Tue, Jul 19, 2016 at 3:50 AM, Peter Meerwald-Stadler
<pmeerw@pmeerw.net> wrote:
>
>> Signed-off-by: Pratik Prajapati <pratik.prajapati12@gmail.com>
>
> comments below; nice addition
>
> it seems this patch clashes with the recent changes to this driver in
> iio-testing; can you rebase on top please?
Where is iio-testing? I couldn't found it in linux.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/1] iio: vcnl4000: Add IR current adjust support
2016-07-19 6:10 ` Pratik Prajapati
@ 2016-07-19 6:21 ` Peter Meerwald-Stadler
2016-07-21 14:47 ` Pratik Prajapati
2016-07-23 7:29 ` Jonathan Cameron
0 siblings, 2 replies; 8+ messages in thread
From: Peter Meerwald-Stadler @ 2016-07-19 6:21 UTC (permalink / raw)
To: Pratik Prajapati
Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen, linux-iio,
linux-kernel
> > comments below; nice addition
> >
> > it seems this patch clashes with the recent changes to this driver in
> > iio-testing; can you rebase on top please?
>
> Where is iio-testing? I couldn't found it in linux.
https://git.kernel.org/cgit/linux/kernel/git/jic23/iio.git/log/?h=testing
p.
--
Peter Meerwald-Stadler
+43-664-2444418 (mobile)
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/1] iio: vcnl4000: Add IR current adjust support
2016-07-19 6:21 ` Peter Meerwald-Stadler
@ 2016-07-21 14:47 ` Pratik Prajapati
2016-07-21 22:14 ` Peter Meerwald-Stadler
2016-07-23 7:29 ` Jonathan Cameron
1 sibling, 1 reply; 8+ messages in thread
From: Pratik Prajapati @ 2016-07-21 14:47 UTC (permalink / raw)
To: Peter Meerwald-Stadler
Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen, linux-iio,
linux-kernel
On Tue, Jul 19, 2016 at 11:51 AM, Peter Meerwald-Stadler
<pmeerw@pmeerw.net> wrote:
>
>
> > > comments below; nice addition
> > >
> > > it seems this patch clashes with the recent changes to this driver in
> > > iio-testing; can you rebase on top please?
> >
> > Where is iio-testing? I couldn't found it in linux.
>
> https://git.kernel.org/cgit/linux/kernel/git/jic23/iio.git/log/?h=testing
Means we have to do development here and this testing branch will get
merged to main branch later.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/1] iio: vcnl4000: Add IR current adjust support
2016-07-21 14:47 ` Pratik Prajapati
@ 2016-07-21 22:14 ` Peter Meerwald-Stadler
2016-07-23 7:30 ` Jonathan Cameron
0 siblings, 1 reply; 8+ messages in thread
From: Peter Meerwald-Stadler @ 2016-07-21 22:14 UTC (permalink / raw)
To: Pratik Prajapati
Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen, linux-iio,
linux-kernel
> > > > comments below; nice addition
> > > >
> > > > it seems this patch clashes with the recent changes to this driver in
> > > > iio-testing; can you rebase on top please?
> > >
> > > Where is iio-testing? I couldn't found it in linux.
> >
> > https://git.kernel.org/cgit/linux/kernel/git/jic23/iio.git/log/?h=testing
>
> Means we have to do development here and this testing branch will get
> merged to main branch later.
yes, Jonathan will queue up stuff in testing, then send to GregHK, and
then to mainline
p.
--
Peter Meerwald-Stadler
+43-664-2444418 (mobile)
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/1] iio: vcnl4000: Add IR current adjust support
2016-07-19 6:21 ` Peter Meerwald-Stadler
2016-07-21 14:47 ` Pratik Prajapati
@ 2016-07-23 7:29 ` Jonathan Cameron
1 sibling, 0 replies; 8+ messages in thread
From: Jonathan Cameron @ 2016-07-23 7:29 UTC (permalink / raw)
To: Peter Meerwald-Stadler, Pratik Prajapati
Cc: Hartmut Knaack, Lars-Peter Clausen, linux-iio, linux-kernel
On 19/07/16 08:21, Peter Meerwald-Stadler wrote:
>
>>> comments below; nice addition
>>>
>>> it seems this patch clashes with the recent changes to this driver in
>>> iio-testing; can you rebase on top please?
>>
>> Where is iio-testing? I couldn't found it in linux.
>
> https://git.kernel.org/cgit/linux/kernel/git/jic23/iio.git/log/?h=testing
>
In theory stuff only stays in testing (alone) until I get the autobuilder
responses on it. I've had a bit of an 'interesting' few weeks however
so haven't done the usual which is to push it out as togreg (which is the
non rebasing tree) in as timely a fashion as I should.
Worth checking testing to see if there is anything very recent, but better
to base new work on top of togreg.
Thanks
Jonathan
> p.
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/1] iio: vcnl4000: Add IR current adjust support
2016-07-21 22:14 ` Peter Meerwald-Stadler
@ 2016-07-23 7:30 ` Jonathan Cameron
0 siblings, 0 replies; 8+ messages in thread
From: Jonathan Cameron @ 2016-07-23 7:30 UTC (permalink / raw)
To: Peter Meerwald-Stadler, Pratik Prajapati
Cc: Hartmut Knaack, Lars-Peter Clausen, linux-iio, linux-kernel
On 22/07/16 00:14, Peter Meerwald-Stadler wrote:
>
>>>>> comments below; nice addition
>>>>>
>>>>> it seems this patch clashes with the recent changes to this driver in
>>>>> iio-testing; can you rebase on top please?
>>>>
>>>> Where is iio-testing? I couldn't found it in linux.
>>>
>>> https://git.kernel.org/cgit/linux/kernel/git/jic23/iio.git/log/?h=testing
>>
>> Means we have to do development here and this testing branch will get
>> merged to main branch later.
>
> yes, Jonathan will queue up stuff in testing, then send to GregHK, and
> then to mainline
Testing is a special branch for the autobuilders. Except when I'm being
useless, the right branch to use is togreg as that 'never' rebases.
Jonathan
>
> p.
>
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2016-07-23 10:57 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-18 14:09 [PATCH 1/1] iio: vcnl4000: Add IR current adjust support Pratik Prajapati
2016-07-18 22:20 ` Peter Meerwald-Stadler
2016-07-19 6:10 ` Pratik Prajapati
2016-07-19 6:21 ` Peter Meerwald-Stadler
2016-07-21 14:47 ` Pratik Prajapati
2016-07-21 22:14 ` Peter Meerwald-Stadler
2016-07-23 7:30 ` Jonathan Cameron
2016-07-23 7:29 ` Jonathan Cameron
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.