From: Jonathan Cameron <jic23@kernel.org>
To: Crestez Dan Leonard <leonard.crestez@intel.com>,
linux-iio@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Hartmut Knaack <knaack.h@gmx.de>,
Lars-Peter Clausen <lars@metafoo.de>,
Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
Daniel Baluta <daniel.baluta@intel.com>
Subject: Re: [PATCH 3/5] max44000: Support controlling LED current output
Date: Sun, 10 Apr 2016 14:16:09 +0100 [thread overview]
Message-ID: <570A5219.9040802@kernel.org> (raw)
In-Reply-To: <1f9ec5350bd3349236887ed89378c319eddc005f.1460045763.git.leonard.crestez@intel.com>
On 07/04/16 17:21, Crestez Dan Leonard wrote:
> This is exposed as an output channel with "led" as an extend_name.
>
> Other sensors also have support for controlling an external LED. It's
> not clear that simply exposing an undecorated output channel is the
> correct approach.
Agreed that this is less than ideal. Other suggestions welcome.
It gets complicated as some devices have multiple LEDs and they aren't
necessarily directly associated with a particular sensor.
>
> Signed-off-by: Crestez Dan Leonard <leonard.crestez@intel.com>
> ---
> drivers/iio/light/max44000.c | 53 ++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 53 insertions(+)
>
> diff --git a/drivers/iio/light/max44000.c b/drivers/iio/light/max44000.c
> index 10a0fe8..1dc10b9 100644
> --- a/drivers/iio/light/max44000.c
> +++ b/drivers/iio/light/max44000.c
> @@ -85,6 +85,13 @@ static const struct iio_chan_spec max44000_channels[] = {
> .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
> },
> + {
> + .type = IIO_CURRENT,
> + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> + BIT(IIO_CHAN_INFO_SCALE),
> + .extend_name = "led",
> + .output = 1,
> + },
> };
>
> static inline int max44000_read_alsval(struct max44000_data *data)
> @@ -124,6 +131,20 @@ static inline int max44000_write_led_current_raw(struct max44000_data *data, int
> MAX44000_LED_CURRENT_MASK, val);
> }
>
> +static inline int max44000_read_led_current_raw(struct max44000_data *data)
> +{
> + unsigned int regval;
> + int ret;
> +
> + ret = regmap_read(data->regmap, MAX44000_REG_CFG_TX, ®val);
> + if (ret < 0)
> + return ret;
> + regval &= MAX44000_LED_CURRENT_MASK;
> + if (regval >= 8)
> + regval -= 4;
> + return regval;
> +}
> +
> static int max44000_read_raw(struct iio_dev *indio_dev,
> struct iio_chan_spec const *chan,
> int *val, int *val2, long mask)
> @@ -153,12 +174,26 @@ static int max44000_read_raw(struct iio_dev *indio_dev,
> *val = regval;
> return IIO_VAL_INT;
>
> + case IIO_CURRENT:
> + mutex_lock(&data->lock);
> + ret = max44000_read_led_current_raw(data);
> + mutex_unlock(&data->lock);
> + if (ret < 0)
> + return ret;
> + *val = ret;
> + return IIO_VAL_INT;
> +
> default:
> return -EINVAL;
> }
>
> case IIO_CHAN_INFO_SCALE:
> switch (chan->type) {
> + case IIO_CURRENT:
> + /* Output register is in 10s of miliamps */
> + *val = 10;
> + return IIO_VAL_INT;
> +
> case IIO_LIGHT:
> *val = 1;
> *val2 = MAX44000_ALS_TO_LUX_DEFAULT_FRACTION_LOG2;
> @@ -173,9 +208,27 @@ static int max44000_read_raw(struct iio_dev *indio_dev,
> }
> }
>
> +static int max44000_write_raw(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan,
> + int val, int val2, long mask)
> +{
> + struct max44000_data *data = iio_priv(indio_dev);
> + int ret;
> +
> + if (mask == IIO_CHAN_INFO_RAW && chan->type == IIO_CURRENT) {
> + mutex_lock(&data->lock);
> + ret = max44000_write_led_current_raw(data, val);
> + mutex_unlock(&data->lock);
> + return ret;
> + }
> +
> + return -EINVAL;
> +}
> +
> static const struct iio_info max44000_info = {
> .driver_module = THIS_MODULE,
> .read_raw = max44000_read_raw,
> + .write_raw = max44000_write_raw,
> };
>
> static bool max44000_readable_reg(struct device *dev, unsigned int reg)
>
next prev parent reply other threads:[~2016-04-10 13:16 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-07 16:21 [PATCH 0/5] Support for max44000 Ambient and Infrared Proximity Sensor Crestez Dan Leonard
2016-04-07 16:21 ` [PATCH 1/5] max44000: Initial commit Crestez Dan Leonard
2016-04-07 19:48 ` Peter Meerwald-Stadler
2016-04-10 13:12 ` Jonathan Cameron
2016-04-11 15:08 ` Crestez Dan Leonard
2016-04-17 8:36 ` Jonathan Cameron
2016-04-18 10:32 ` Mark Brown
2016-04-18 10:59 ` Lars-Peter Clausen
2016-04-18 12:15 ` Crestez Dan Leonard
2016-04-18 12:34 ` Mark Brown
[not found] ` <57153733.1070605@kernel.org>
2016-04-19 9:06 ` Mark Brown
2016-04-18 19:38 ` Jonathan Cameron
2016-04-07 16:21 ` [PATCH 2/5] max44000: Initial support for proximity reading Crestez Dan Leonard
2016-04-10 13:14 ` Jonathan Cameron
2016-04-07 16:21 ` [PATCH 3/5] max44000: Support controlling LED current output Crestez Dan Leonard
2016-04-10 13:16 ` Jonathan Cameron [this message]
2016-04-07 16:21 ` [PATCH 4/5] max44000: Expose ambient sensor scaling Crestez Dan Leonard
2016-04-10 13:20 ` Jonathan Cameron
2016-04-07 16:21 ` [PATCH 5/5] max44000: Initial triggered buffer support Crestez Dan Leonard
2016-04-07 19:59 ` Peter Meerwald-Stadler
2016-04-11 16:11 ` Crestez Dan Leonard
2016-04-17 8:41 ` Jonathan Cameron
2016-04-07 21:56 ` kbuild test robot
2016-04-10 13:24 ` Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=570A5219.9040802@kernel.org \
--to=jic23@kernel.org \
--cc=daniel.baluta@intel.com \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=leonard.crestez@intel.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pmeerw@pmeerw.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).