From: sandhya bankar <bankarsandhya512@gmail.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: Lars-Peter Clausen <lars@metafoo.de>,
Michael.Hennerich@analog.com, knaack.h@gmx.de,
Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
Greg KH <gregkh@linuxfoundation.org>,
outreachy-kernel@googlegroups.com, linux-iio@vger.kernel.org
Subject: Re: [PATCH v2] Staging: iio: meter: ade7753: Replace IIO_DEV_ATTR_SAMP_FREQ attribute with IIO_CHAN_INFO_SAMP_FREQ handlers.
Date: Sun, 2 Oct 2016 03:59:17 +0530 [thread overview]
Message-ID: <CAA3ASznew0CCzJaPMG00MDeDpHdAVLouuae2NObD6B2KcP+ZDw@mail.gmail.com> (raw)
In-Reply-To: <737de70d-80e5-a9b5-4522-8b66e6cd8ca6@kernel.org>
On Sat, Oct 1, 2016 at 6:45 PM, Jonathan Cameron <jic23@kernel.org> wrote:
> On 29/09/16 17:01, Sandhya Bankar wrote:
>> Moved functionality from IIO_DEV_ATTR_SAMP_FREQ attribute into
>> IIO_CHAN_INFO_SAMP_FREQ handlers. Added ade7753_read_raw() and
>> ade7753_write_raw() to allow reading/writing the element as well.
>>
>> Signed-off-by: Sandhya Bankar <bankarsandhya512@gmail.com>
> I'd forgotten this driver existed. There are a lot of similar
> elements in here that can be cleaned up if you want to take
> this further.
>
> Step 1. Convert all the attrs that are actually standard IIO abi.
> Step 2. Start looking at the custom ABI in here and consider what
> to do about it. (might be a job for someone familiar with the
> hardware!)
>
> Anyhow, this doesn't actually work.
>
> Take a look at what calls the read_raw and write_raw functions
> and how the relevant sysfs attributes are instantiated.
>
> Lars, I think any major ABI work on this is going to need
> some input from Analog (or someone who actually has one of
> these!)...
>
> The energy meter drivers are somewhat of an open space when
> it comes to ABI definitions (there aren't really any yet!)
Hello,
It doesn't work because I have not defined the attribute
IIO_CHAN_INFO* for sysfs. So, the attribute won't get exposed as a
sysfs file. Right ?
We typically use it as a channel attribute.
So, in this case, Should I create a channel, or is there another
possible way to do it ?
I am just curious to know that why the channel for this driver is not defined ?
Please suggest on same.
Thanks,
Sandhya
> Jonathan
>> ---
>> Changes in v2:
>> * Adding "Staging" keyword in subject line.
>>
>> drivers/staging/iio/meter/ade7753.c | 155 +++++++++++++++++++++---------------
>> 1 file changed, 90 insertions(+), 65 deletions(-)
>>
>> diff --git a/drivers/staging/iio/meter/ade7753.c b/drivers/staging/iio/meter/ade7753.c
>> index 4b5f05f..a2b4a18 100644
>> --- a/drivers/staging/iio/meter/ade7753.c
>> +++ b/drivers/staging/iio/meter/ade7753.c
>> @@ -98,6 +98,94 @@ static int ade7753_spi_read_reg_16(struct device *dev,
>> return 0;
>> }
>>
>> +static int ade7753_read_raw_samp_freq(struct device *dev, int *val)
>> +{
>> + int ret;
>> + u16 t;
>> +
>> + ret = ade7753_spi_read_reg_16(dev, ADE7753_MODE, &t);
>> + if (ret)
>> + return ret;
>> + t = (t >> 11) & 0x3;
>> + *val = 27900 / (1 + t);
>> +
>> + return 0;
>> +}
>> +
>> +static int ade7753_write_raw_samp_freq(struct device *dev, int val)
>> +{
>> + struct iio_dev *indio_dev = dev_to_iio_dev(dev);
>> + struct ade7753_state *st = iio_priv(indio_dev);
>> + int ret;
>> + u16 reg, t;
>> +
>> + if (!val)
>> + return -EINVAL;
>> +
>> + t = 27900 / val;
>> + if (t > 0)
>> + t--;
>> +
>> + if (t > 1)
>> + st->us->max_speed_hz = ADE7753_SPI_SLOW;
>> + else
>> + st->us->max_speed_hz = ADE7753_SPI_FAST;
>> +
>> + ret = ade7753_spi_read_reg_16(dev, ADE7753_MODE, ®);
>> + if (ret)
>> + goto out;
>> +
>> + reg &= ~(3 << 11);
>> + reg |= t << 11;
>> +
>> + ret = ade7753_spi_write_reg_16(dev, ADE7753_MODE, reg);
>> +
>> +out:
>> + return ret;
>> +}
>> +
>> +static int ade7753_write_raw(struct iio_dev *indio_dev,
>> + struct iio_chan_spec const *chan,
>> + int val, int val2, long mask)
>> +{
>> + int ret;
>> +
>> + switch (mask) {
>> + case IIO_CHAN_INFO_SAMP_FREQ:
>> + if (val2)
>> + return -EINVAL;
>> + mutex_lock(&indio_dev->mlock);
>> + ret = ade7753_write_raw_samp_freq(&indio_dev->dev, val);
>> + mutex_unlock(&indio_dev->mlock);
>> + return ret;
>> + default:
>> + return -EINVAL;
>> + }
>> +
>> + return ret;
>> +}
>> +
>> +static int ade7753_read_raw(struct iio_dev *indio_dev,
>> + struct iio_chan_spec const *chan,
>> + int *val,
>> + int *val2,
>> + long mask)
>> +{
>> + int ret;
>> +
>> + switch (mask) {
>> + case IIO_CHAN_INFO_SAMP_FREQ:
>> + mutex_lock(&indio_dev->mlock);
>> + ret = ade7753_read_raw_samp_freq(&indio_dev->dev, val);
>> + mutex_unlock(&indio_dev->mlock);
>> + return ret;
>> + default:
>> + return -EINVAL;
>> + }
>> +
>> + return ret;
>> +}
>> +
>> static int ade7753_spi_read_reg_24(struct device *dev,
>> u8 reg_address,
>> u32 *val)
>> @@ -383,82 +471,17 @@ err_ret:
>> return ret;
>> }
>>
>> -static ssize_t ade7753_read_frequency(struct device *dev,
>> - struct device_attribute *attr,
>> - char *buf)
>> -{
>> - int ret;
>> - u16 t;
>> - int sps;
>> -
>> - ret = ade7753_spi_read_reg_16(dev, ADE7753_MODE, &t);
>> - if (ret)
>> - return ret;
>> -
>> - t = (t >> 11) & 0x3;
>> - sps = 27900 / (1 + t);
>> -
>> - return sprintf(buf, "%d\n", sps);
>> -}
>> -
>> -static ssize_t ade7753_write_frequency(struct device *dev,
>> - struct device_attribute *attr,
>> - const char *buf,
>> - size_t len)
>> -{
>> - struct iio_dev *indio_dev = dev_to_iio_dev(dev);
>> - struct ade7753_state *st = iio_priv(indio_dev);
>> - u16 val;
>> - int ret;
>> - u16 reg, t;
>> -
>> - ret = kstrtou16(buf, 10, &val);
>> - if (ret)
>> - return ret;
>> - if (!val)
>> - return -EINVAL;
>> -
>> - mutex_lock(&indio_dev->mlock);
>> -
>> - t = 27900 / val;
>> - if (t > 0)
>> - t--;
>> -
>> - if (t > 1)
>> - st->us->max_speed_hz = ADE7753_SPI_SLOW;
>> - else
>> - st->us->max_speed_hz = ADE7753_SPI_FAST;
>> -
>> - ret = ade7753_spi_read_reg_16(dev, ADE7753_MODE, ®);
>> - if (ret)
>> - goto out;
>> -
>> - reg &= ~(3 << 11);
>> - reg |= t << 11;
>> -
>> - ret = ade7753_spi_write_reg_16(dev, ADE7753_MODE, reg);
>> -
>> -out:
>> - mutex_unlock(&indio_dev->mlock);
>> -
>> - return ret ? ret : len;
>> -}
>>
>> static IIO_DEV_ATTR_TEMP_RAW(ade7753_read_8bit);
>> static IIO_CONST_ATTR(in_temp_offset, "-25 C");
>> static IIO_CONST_ATTR(in_temp_scale, "0.67 C");
>>
>> -static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO,
>> - ade7753_read_frequency,
>> - ade7753_write_frequency);
>> -
>> static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("27900 14000 7000 3500");
>>
>> static struct attribute *ade7753_attributes[] = {
>> &iio_dev_attr_in_temp_raw.dev_attr.attr,
>> &iio_const_attr_in_temp_offset.dev_attr.attr,
>> &iio_const_attr_in_temp_scale.dev_attr.attr,
>> - &iio_dev_attr_sampling_frequency.dev_attr.attr,
>> &iio_const_attr_sampling_frequency_available.dev_attr.attr,
>> &iio_dev_attr_phcal.dev_attr.attr,
>> &iio_dev_attr_cfden.dev_attr.attr,
>> @@ -496,6 +519,8 @@ static const struct attribute_group ade7753_attribute_group = {
>>
>> static const struct iio_info ade7753_info = {
>> .attrs = &ade7753_attribute_group,
>> + .read_raw = &ade7753_read_raw,
>> + .write_raw = &ade7753_write_raw,
>> .driver_module = THIS_MODULE,
>> };
>>
>>
>
next parent reply other threads:[~2016-10-01 22:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20160929160133.GA5460@localhost.localdomain>
[not found] ` <737de70d-80e5-a9b5-4522-8b66e6cd8ca6@kernel.org>
2016-10-01 22:29 ` sandhya bankar [this message]
2016-10-03 20:25 ` [PATCH v2] Staging: iio: meter: ade7753: Replace IIO_DEV_ATTR_SAMP_FREQ attribute with IIO_CHAN_INFO_SAMP_FREQ handlers 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=CAA3ASznew0CCzJaPMG00MDeDpHdAVLouuae2NObD6B2KcP+ZDw@mail.gmail.com \
--to=bankarsandhya512@gmail.com \
--cc=Michael.Hennerich@analog.com \
--cc=gregkh@linuxfoundation.org \
--cc=jic23@kernel.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=outreachy-kernel@googlegroups.com \
--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).