Message ID | 20220108205319.2046348-7-liambeguin@gmail.com (mailing list archive) |
---|---|
State | Changes Requested |
Headers | show |
Series | iio: afe: add temperature rescaling support | expand |
On Sat, Jan 8, 2022 at 10:53 PM Liam Beguin <liambeguin@gmail.com> wrote: > > In preparation for the addition of kunit tests, expose the logic > responsible for combining channel scales. ... > +/* > + * Copyright (C) 2021 Liam Beguin <liambeguin@gmail.com> > + */ Despite the Rb tag by the author of the code the above is wrong. Please do not steal others work :-) (The smiley due to my believe that you have done this undeliberately) * IIO rescale driver * * Copyright (C) 2018 Axentia Technologies AB * * Author: Peter Rosin <peda@axentia.se>
On 2022-01-09 14:07, Andy Shevchenko wrote: > On Sat, Jan 8, 2022 at 10:53 PM Liam Beguin <liambeguin@gmail.com> wrote: >> >> In preparation for the addition of kunit tests, expose the logic >> responsible for combining channel scales. > > ... > >> +/* >> + * Copyright (C) 2021 Liam Beguin <liambeguin@gmail.com> >> + */ > > Despite the Rb tag by the author of the code the above is wrong. > Please do not steal others work :-) (The smiley due to my believe that > you have done this undeliberately) > > * IIO rescale driver > * > * Copyright (C) 2018 Axentia Technologies AB > * > * Author: Peter Rosin <peda@axentia.se> > For the record, I did notice this myself but did let it slide. It's only a trivial header, and is it even copyrightable? Shrug... Cheers, Peter
On 2022-01-09 21:19, Peter Rosin wrote: > On 2022-01-09 14:07, Andy Shevchenko wrote: >> On Sat, Jan 8, 2022 at 10:53 PM Liam Beguin <liambeguin@gmail.com> wrote: >>> >>> In preparation for the addition of kunit tests, expose the logic >>> responsible for combining channel scales. >> >> ... >> >>> +/* >>> + * Copyright (C) 2021 Liam Beguin <liambeguin@gmail.com> >>> + */ >> >> Despite the Rb tag by the author of the code the above is wrong. >> Please do not steal others work :-) (The smiley due to my believe that >> you have done this undeliberately) >> >> * IIO rescale driver >> * >> * Copyright (C) 2018 Axentia Technologies AB >> * >> * Author: Peter Rosin <peda@axentia.se> >> > > For the record, I did notice this myself but did let it slide. It's only > a trivial header, and is it even copyrightable? Shrug... Oh, and by the way Liam, feel free to add a copyright line to the iio-rescale.c file somewhere in the series if you like (if you didn't already). You've certainly deserved it... Cheers, Peter
On Sun, Jan 09, 2022 at 03:07:58PM +0200, Andy Shevchenko wrote: > On Sat, Jan 8, 2022 at 10:53 PM Liam Beguin <liambeguin@gmail.com> wrote: > > > > In preparation for the addition of kunit tests, expose the logic > > responsible for combining channel scales. > > ... > > > +/* > > + * Copyright (C) 2021 Liam Beguin <liambeguin@gmail.com> > > + */ > > Despite the Rb tag by the author of the code the above is wrong. > Please do not steal others work :-) (The smiley due to my believe that > you have done this undeliberately) Sorry about that was not my intention. I'll replace with Peter's original copyright. Cheers, Liam > * IIO rescale driver > * > * Copyright (C) 2018 Axentia Technologies AB > * > * Author: Peter Rosin <peda@axentia.se> > > -- > With Best Regards, > Andy Shevchenko
On Sun, Jan 09, 2022 at 09:25:53PM +0100, Peter Rosin wrote: > > > On 2022-01-09 21:19, Peter Rosin wrote: > > On 2022-01-09 14:07, Andy Shevchenko wrote: > >> On Sat, Jan 8, 2022 at 10:53 PM Liam Beguin <liambeguin@gmail.com> wrote: > >>> > >>> In preparation for the addition of kunit tests, expose the logic > >>> responsible for combining channel scales. > >> > >> ... > >> > >>> +/* > >>> + * Copyright (C) 2021 Liam Beguin <liambeguin@gmail.com> > >>> + */ > >> > >> Despite the Rb tag by the author of the code the above is wrong. > >> Please do not steal others work :-) (The smiley due to my believe that > >> you have done this undeliberately) > >> > >> * IIO rescale driver > >> * > >> * Copyright (C) 2018 Axentia Technologies AB > >> * > >> * Author: Peter Rosin <peda@axentia.se> > >> > > > > For the record, I did notice this myself but did let it slide. It's only > > a trivial header, and is it even copyrightable? Shrug... > > Oh, and by the way Liam, feel free to add a copyright line to the > iio-rescale.c file somewhere in the series if you like (if you didn't > already). You've certainly deserved it... Thanks Peter! Sure, I'll add it somewhere in the series. Cheers, Liam > Cheers, > Peter
diff --git a/drivers/iio/afe/iio-rescale.c b/drivers/iio/afe/iio-rescale.c index 69710c481376..65832dd09249 100644 --- a/drivers/iio/afe/iio-rescale.c +++ b/drivers/iio/afe/iio-rescale.c @@ -15,32 +15,43 @@ #include <linux/platform_device.h> #include <linux/property.h> +#include <linux/iio/afe/rescale.h> #include <linux/iio/consumer.h> #include <linux/iio/iio.h> -struct rescale; - -struct rescale_cfg { - enum iio_chan_type type; - int (*props)(struct device *dev, struct rescale *rescale); -}; +int rescale_process_scale(struct rescale *rescale, int scale_type, + int *val, int *val2) +{ + s64 tmp; -struct rescale { - const struct rescale_cfg *cfg; - struct iio_channel *source; - struct iio_chan_spec chan; - struct iio_chan_spec_ext_info *ext_info; - bool chan_processed; - s32 numerator; - s32 denominator; -}; + switch (scale_type) { + case IIO_VAL_FRACTIONAL: + *val *= rescale->numerator; + *val2 *= rescale->denominator; + return scale_type; + case IIO_VAL_INT: + *val *= rescale->numerator; + if (rescale->denominator == 1) + return scale_type; + *val2 = rescale->denominator; + return IIO_VAL_FRACTIONAL; + case IIO_VAL_FRACTIONAL_LOG2: + tmp = (s64)*val * 1000000000LL; + tmp = div_s64(tmp, rescale->denominator); + tmp *= rescale->numerator; + tmp = div_s64(tmp, 1000000000LL); + *val = tmp; + return scale_type; + default: + return -EOPNOTSUPP; + } +} static int rescale_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) { struct rescale *rescale = iio_priv(indio_dev); - s64 tmp; int ret; switch (mask) { @@ -66,27 +77,7 @@ static int rescale_read_raw(struct iio_dev *indio_dev, } else { ret = iio_read_channel_scale(rescale->source, val, val2); } - switch (ret) { - case IIO_VAL_FRACTIONAL: - *val *= rescale->numerator; - *val2 *= rescale->denominator; - return ret; - case IIO_VAL_INT: - *val *= rescale->numerator; - if (rescale->denominator == 1) - return ret; - *val2 = rescale->denominator; - return IIO_VAL_FRACTIONAL; - case IIO_VAL_FRACTIONAL_LOG2: - tmp = (s64)*val * 1000000000LL; - tmp = div_s64(tmp, rescale->denominator); - tmp *= rescale->numerator; - tmp = div_s64(tmp, 1000000000LL); - *val = tmp; - return ret; - default: - return -EOPNOTSUPP; - } + return rescale_process_scale(rescale, ret, val, val2); default: return -EINVAL; } diff --git a/include/linux/iio/afe/rescale.h b/include/linux/iio/afe/rescale.h new file mode 100644 index 000000000000..698092b6cbb1 --- /dev/null +++ b/include/linux/iio/afe/rescale.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2021 Liam Beguin <liambeguin@gmail.com> + */ + +#ifndef __IIO_RESCALE_H__ +#define __IIO_RESCALE_H__ + +#include <linux/types.h> +#include <linux/iio/iio.h> + +struct device; +struct rescale; + +struct rescale_cfg { + enum iio_chan_type type; + int (*props)(struct device *dev, struct rescale *rescale); +}; + +struct rescale { + const struct rescale_cfg *cfg; + struct iio_channel *source; + struct iio_chan_spec chan; + struct iio_chan_spec_ext_info *ext_info; + bool chan_processed; + s32 numerator; + s32 denominator; +}; + +int rescale_process_scale(struct rescale *rescale, int scale_type, + int *val, int *val2); +#endif /* __IIO_RESCALE_H__ */