diff mbox series

[v1,2/8] iio: accel: bma220: Convert to use ->read_avail()

Message ID 20200831090813.78841-2-andriy.shevchenko@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series [v1,1/8] iio: accel: bma220: Fix returned codes from bma220_init(), bma220_deinit() | expand

Commit Message

Andy Shevchenko Aug. 31, 2020, 9:08 a.m. UTC
Convert to use ->read_avail() instead of open-coded attribute handling.

While here, fix the typo in array definition and append comma in case of
the future extension.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/iio/accel/bma220_spi.c | 36 ++++++++++++++++++++--------------
 1 file changed, 21 insertions(+), 15 deletions(-)

Comments

Jonathan Cameron Sept. 3, 2020, 6:35 p.m. UTC | #1
On Mon, 31 Aug 2020 12:08:07 +0300
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> Convert to use ->read_avail() instead of open-coded attribute handling.
> 
> While here, fix the typo in array definition and append comma in case of
> the future extension.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

I missed a build warning inline. Now fixed.

> ---
>  drivers/iio/accel/bma220_spi.c | 36 ++++++++++++++++++++--------------
>  1 file changed, 21 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/iio/accel/bma220_spi.c b/drivers/iio/accel/bma220_spi.c
> index 3247b9c8abcb..cb634a3a995d 100644
> --- a/drivers/iio/accel/bma220_spi.c
> +++ b/drivers/iio/accel/bma220_spi.c
> @@ -30,7 +30,6 @@
>  #define BMA220_SUSPEND_WAKE			0x00
>  
>  #define BMA220_DEVICE_NAME			"bma220"
> -#define BMA220_SCALE_AVAILABLE			"0.623 1.248 2.491 4.983"
>  
>  #define BMA220_ACCEL_CHANNEL(index, reg, axis) {			\
>  	.type = IIO_ACCEL,						\
> @@ -55,19 +54,8 @@ enum bma220_axis {
>  	AXIS_Z,
>  };
>  
> -static IIO_CONST_ATTR(in_accel_scale_available, BMA220_SCALE_AVAILABLE);
> -
> -static struct attribute *bma220_attributes[] = {
> -	&iio_const_attr_in_accel_scale_available.dev_attr.attr,
> -	NULL,
> -};
> -
> -static const struct attribute_group bma220_attribute_group = {
> -	.attrs = bma220_attributes,
> -};
> -
> -static const int bma220_scale_table[][4] = {
> -	{0, 623000}, {1, 248000}, {2, 491000}, {4, 983000}
> +static const int bma220_scale_table[][2] = {
> +	{0, 623000}, {1, 248000}, {2, 491000}, {4, 983000},
>  };
>  
>  struct bma220_data {
> @@ -182,10 +170,28 @@ static int bma220_write_raw(struct iio_dev *indio_dev,
>  	return -EINVAL;
>  }
>  
> +static int bma220_read_avail(struct iio_dev *indio_dev,
> +			     struct iio_chan_spec const *chan,
> +			     const int **vals, int *type, int *length,
> +			     long mask)
> +{
> +	struct bma220_data *data = iio_priv(indio_dev);
Not used.

> +
> +	switch (mask) {
> +	case IIO_CHAN_INFO_SCALE:
> +		*vals = (int *)bma220_scale_table;
> +		*type = IIO_VAL_INT_PLUS_MICRO;
> +		*length = ARRAY_SIZE(bma220_scale_table) * 2;
> +		return IIO_AVAIL_LIST;
> +	default:
> +		return -EINVAL;
> +	}
> +}
> +
>  static const struct iio_info bma220_info = {
>  	.read_raw		= bma220_read_raw,
>  	.write_raw		= bma220_write_raw,
> -	.attrs			= &bma220_attribute_group,
> +	.read_avail		= bma220_read_avail,
>  };
>  
>  static int bma220_init(struct spi_device *spi)
Andy Shevchenko Sept. 3, 2020, 7:33 p.m. UTC | #2
On Thu, Sep 3, 2020 at 9:36 PM Jonathan Cameron <jic23@kernel.org> wrote:
>
> On Mon, 31 Aug 2020 12:08:07 +0300
> Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
>
> > Convert to use ->read_avail() instead of open-coded attribute handling.
> >
> > While here, fix the typo in array definition and append comma in case of
> > the future extension.
> >
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>
> I missed a build warning inline. Now fixed.

Thanks!
diff mbox series

Patch

diff --git a/drivers/iio/accel/bma220_spi.c b/drivers/iio/accel/bma220_spi.c
index 3247b9c8abcb..cb634a3a995d 100644
--- a/drivers/iio/accel/bma220_spi.c
+++ b/drivers/iio/accel/bma220_spi.c
@@ -30,7 +30,6 @@ 
 #define BMA220_SUSPEND_WAKE			0x00
 
 #define BMA220_DEVICE_NAME			"bma220"
-#define BMA220_SCALE_AVAILABLE			"0.623 1.248 2.491 4.983"
 
 #define BMA220_ACCEL_CHANNEL(index, reg, axis) {			\
 	.type = IIO_ACCEL,						\
@@ -55,19 +54,8 @@  enum bma220_axis {
 	AXIS_Z,
 };
 
-static IIO_CONST_ATTR(in_accel_scale_available, BMA220_SCALE_AVAILABLE);
-
-static struct attribute *bma220_attributes[] = {
-	&iio_const_attr_in_accel_scale_available.dev_attr.attr,
-	NULL,
-};
-
-static const struct attribute_group bma220_attribute_group = {
-	.attrs = bma220_attributes,
-};
-
-static const int bma220_scale_table[][4] = {
-	{0, 623000}, {1, 248000}, {2, 491000}, {4, 983000}
+static const int bma220_scale_table[][2] = {
+	{0, 623000}, {1, 248000}, {2, 491000}, {4, 983000},
 };
 
 struct bma220_data {
@@ -182,10 +170,28 @@  static int bma220_write_raw(struct iio_dev *indio_dev,
 	return -EINVAL;
 }
 
+static int bma220_read_avail(struct iio_dev *indio_dev,
+			     struct iio_chan_spec const *chan,
+			     const int **vals, int *type, int *length,
+			     long mask)
+{
+	struct bma220_data *data = iio_priv(indio_dev);
+
+	switch (mask) {
+	case IIO_CHAN_INFO_SCALE:
+		*vals = (int *)bma220_scale_table;
+		*type = IIO_VAL_INT_PLUS_MICRO;
+		*length = ARRAY_SIZE(bma220_scale_table) * 2;
+		return IIO_AVAIL_LIST;
+	default:
+		return -EINVAL;
+	}
+}
+
 static const struct iio_info bma220_info = {
 	.read_raw		= bma220_read_raw,
 	.write_raw		= bma220_write_raw,
-	.attrs			= &bma220_attribute_group,
+	.read_avail		= bma220_read_avail,
 };
 
 static int bma220_init(struct spi_device *spi)