Re: [PATCH v5 11/14] iio: magnetometer: yas530: Add IIO scaling to "chip_info"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Aug 8, 2022 at 1:07 AM Jakob Hauser <jahau@xxxxxxxxxxxxxx> wrote:
>
> Add IIO scaling to the "chip_info" structure to ease the handling to
> different YAS variants.

Reviewed-by: Andy Shevchenko <andy.shevchenko@xxxxxxxxx>

> Signed-off-by: Jakob Hauser <jahau@xxxxxxxxxxxxxx>
> ---
>  drivers/iio/magnetometer/yamaha-yas530.c | 28 ++++++------------------
>  1 file changed, 7 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c
> index 914f7f0a243e..262a36c31616 100644
> --- a/drivers/iio/magnetometer/yamaha-yas530.c
> +++ b/drivers/iio/magnetometer/yamaha-yas530.c
> @@ -142,6 +142,7 @@ struct yas5xx;
>   * @version_name: version letter or naming
>   * @volatile_reg: device-specific volatile registers
>   * @volatile_reg_qty: quantity of device-specific volatile registers
> + * @scaling_val2: scaling value for IIO_CHAN_INFO_SCALE
>   */
>  struct yas5xx_chip_info {
>         unsigned int devid;
> @@ -149,6 +150,7 @@ struct yas5xx_chip_info {
>         const char * const *version_name;
>         const int *volatile_reg;
>         int volatile_reg_qty;
> +       u32 scaling_val2;
>  };
>
>  /**
> @@ -514,27 +516,8 @@ static int yas5xx_read_raw(struct iio_dev *indio_dev,
>                 }
>                 return IIO_VAL_INT;
>         case IIO_CHAN_INFO_SCALE:
> -               switch (yas5xx->chip_info->devid) {
> -               case YAS530_DEVICE_ID:
> -                       /*
> -                        * Raw values of YAS530 are in picotesla. Divide by
> -                        * 100000000 (10^8) to get Gauss.
> -                        */
> -                       *val = 1;
> -                       *val2 = 100000000;
> -                       break;
> -               case YAS532_DEVICE_ID:
> -                       /*
> -                        * Raw values of YAS532 are in nanotesla. Divide by
> -                        * 100000 (10^5) to get Gauss.
> -                        */
> -                       *val = 1;
> -                       *val2 = 100000;
> -                       break;
> -               default:
> -                       dev_err(yas5xx->dev, "unknown device type\n");
> -                       return -EINVAL;
> -               }
> +               *val = 1;
> +               *val2 = yas5xx->chip_info->scaling_val2;
>                 return IIO_VAL_FRACTIONAL;
>         default:
>                 /* Unknown request */
> @@ -959,6 +942,7 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = {
>                 .version_name = yas5xx_version_names[yas530],
>                 .volatile_reg = yas530_volatile_reg,
>                 .volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg),
> +               .scaling_val2 = 100000000, /* picotesla to Gauss */
>         },
>         [yas532] = {
>                 .devid = YAS532_DEVICE_ID,
> @@ -966,6 +950,7 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = {
>                 .version_name = yas5xx_version_names[yas532],
>                 .volatile_reg = yas530_volatile_reg,
>                 .volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg),
> +               .scaling_val2 = 100000, /* nanotesla to Gauss */
>         },
>         [yas533] = {
>                 .devid = YAS532_DEVICE_ID,
> @@ -973,6 +958,7 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = {
>                 .version_name = yas5xx_version_names[yas533],
>                 .volatile_reg = yas530_volatile_reg,
>                 .volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg),
> +               .scaling_val2 = 100000, /* nanotesla to Gauss */
>         },
>  };
>
> --
> 2.35.1
>


-- 
With Best Regards,
Andy Shevchenko



[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux