From: Jonathan Cameron <jic23@kernel.org>
To: Peter Meerwald <pmeerw@pmeerw.net>
Cc: linux-iio@vger.kernel.org,
Oleksandr Kravchenko <o.v.kravchenko@globallogic.com>
Subject: Re: [PATCH v2 10/11] iio:bma180: Implement _available sysfs attribute dynamically
Date: Sun, 14 Sep 2014 20:26:49 +0100 [thread overview]
Message-ID: <5415EBF9.3050103@kernel.org> (raw)
In-Reply-To: <1408488206-2633-11-git-send-email-pmeerw@pmeerw.net>
On 19/08/14 23:43, Peter Meerwald wrote:
> makes it easier to add more chip variants and removes redundancy:
> scales and frequencies are now stated just once
>
> Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
> Cc: Oleksandr Kravchenko <o.v.kravchenko@globallogic.com>
Applied.
> ---
> drivers/iio/accel/bma180.c | 54 ++++++++++++++++++++++++++++++++++++----------
> 1 file changed, 43 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/iio/accel/bma180.c b/drivers/iio/accel/bma180.c
> index 6e940b0..9fbc81f 100644
> --- a/drivers/iio/accel/bma180.c
> +++ b/drivers/iio/accel/bma180.c
> @@ -83,12 +83,6 @@ struct bma180_part_info {
> #define BMA180_DEF_BW 20
> #define BMA180_DEF_SCALE 2452
>
> -/* Available values for sysfs */
> -#define BMA180_FLP_FREQ_AVAILABLE \
> - "10 20 40 75 150 300"
> -#define BMA180_SCALE_AVAILABLE \
> - "0.001275 0.001863 0.002452 0.003727 0.004903 0.009709 0.019417"
> -
> struct bma180_data {
> struct i2c_client *client;
> struct iio_trigger *trig;
> @@ -347,13 +341,51 @@ err:
> dev_err(&data->client->dev, "failed to disable the chip\n");
> }
>
> -static IIO_CONST_ATTR(in_accel_filter_low_pass_3db_frequency_available,
> - BMA180_FLP_FREQ_AVAILABLE);
> -static IIO_CONST_ATTR(in_accel_scale_available, BMA180_SCALE_AVAILABLE);
> +static ssize_t bma180_show_avail(char *buf, const int *vals, unsigned n,
> + bool micros)
> +{
> + size_t len = 0;
> + int i;
> +
> + for (i = 0; i < n; i++) {
> + if (!vals[i])
> + continue;
> + len += scnprintf(buf + len, PAGE_SIZE - len,
> + micros ? "0.%06d " : "%d ", vals[i]);
> + }
> + buf[len - 1] = '\n';
> +
> + return len;
> +}
> +
> +static ssize_t bma180_show_filter_freq_avail(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct bma180_data *data = iio_priv(dev_to_iio_dev(dev));
> +
> + return bma180_show_avail(buf, data->part_info->bw_table,
> + data->part_info->num_bw, false);
> +}
> +
> +static ssize_t bma180_show_scale_avail(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct bma180_data *data = iio_priv(dev_to_iio_dev(dev));
> +
> + return bma180_show_avail(buf, data->part_info->scale_table,
> + data->part_info->num_scales, true);
> +}
> +
> +static IIO_DEVICE_ATTR(in_accel_filter_low_pass_3db_frequency_available,
> + S_IRUGO, bma180_show_filter_freq_avail, NULL, 0);
> +
> +static IIO_DEVICE_ATTR(in_accel_scale_available,
> + S_IRUGO, bma180_show_scale_avail, NULL, 0);
>
> static struct attribute *bma180_attributes[] = {
> - &iio_const_attr_in_accel_filter_low_pass_3db_frequency_available.dev_attr.attr,
> - &iio_const_attr_in_accel_scale_available.dev_attr.attr,
> + &iio_dev_attr_in_accel_filter_low_pass_3db_frequency_available.
> + dev_attr.attr,
> + &iio_dev_attr_in_accel_scale_available.dev_attr.attr,
> NULL,
> };
>
>
next prev parent reply other threads:[~2014-09-14 19:26 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-19 22:43 [PATCH v2 00/11] iio:bma180: Add BMA250 support v2 Peter Meerwald
2014-08-19 22:43 ` [PATCH v2 01/11] iio:bma180: Enable use of device without IRQ Peter Meerwald
2014-09-14 17:47 ` Jonathan Cameron
2014-08-19 22:43 ` [PATCH v2 02/11] iio:bma180: Prefix remaining tables and functions with bma18_ Peter Meerwald
2014-09-14 17:47 ` Jonathan Cameron
2014-08-19 22:43 ` [PATCH v2 03/11] iio:bma180: Rename BMA_180 to BMA180_ Peter Meerwald
2014-09-14 17:48 ` Jonathan Cameron
2014-08-19 22:43 ` [PATCH v2 04/11] iio:bma180: Use bool instead of int for state Peter Meerwald
2014-09-14 17:48 ` Jonathan Cameron
2014-08-19 22:43 ` [PATCH v2 05/11] iio:bma180: Expose temperature channel Peter Meerwald
2014-08-20 8:56 ` Daniel Baluta
2014-08-19 22:43 ` [PATCH v2 06/11] iio:bma180: Drop _update_scan_mode() Peter Meerwald
2014-09-14 19:20 ` Jonathan Cameron
2014-08-19 22:43 ` [PATCH v2 07/11] iio:bma180: Introduce part_info to differentiate further chip variants Peter Meerwald
2014-09-14 19:20 ` Jonathan Cameron
2014-09-14 19:22 ` Jonathan Cameron
2014-08-19 22:43 ` [PATCH v2 08/11] iio:bma180: Introduce part-specific _config() and disable() code Peter Meerwald
2014-09-14 19:20 ` Jonathan Cameron
2014-09-14 19:25 ` Jonathan Cameron
2014-08-19 22:43 ` [PATCH v2 09/11] iio:bma180: Prepare for accelerometer channels with different resolutions Peter Meerwald
2014-09-14 19:26 ` Jonathan Cameron
2014-08-19 22:43 ` [PATCH v2 10/11] iio:bma180: Implement _available sysfs attribute dynamically Peter Meerwald
2014-09-14 19:26 ` Jonathan Cameron [this message]
2014-08-19 22:43 ` [PATCH v2 11/11] iio:bma180: Add BMA250 chip support Peter Meerwald
2014-09-14 19:28 ` Jonathan Cameron
2014-09-14 20:00 ` Peter Meerwald
2014-09-14 20:41 ` 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=5415EBF9.3050103@kernel.org \
--to=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=o.v.kravchenko@globallogic.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).