RE: Adding custom functional callbacks to IIO driver

2021-02-12 Thread Anand Ashok Dumbre
Thanks a lot I will go through it. 

> -Original Message-
> From: Lars-Peter Clausen 
> Sent: Friday 12 February 2021 5:06 PM
> To: Anand Ashok Dumbre ; Jonathan Cameron
> ; knaac...@gmx.de; Peter Meerwald-Stadler
> ; Michal Simek ; linux-
> i...@vger.kernel.org; linux-arm-ker...@lists.infradead.org; linux-
> ker...@vger.kernel.org
> Subject: Re: Adding custom functional callbacks to IIO driver
> 
> On 2/12/21 12:07 PM, Anand Ashok Dumbre wrote:
> > Hello,
> >
> > I have an IIO adc driver that measures temperatures and voltages on the
> SOC.
> > There are other kernel modules interested in the temperature and voltage
> event information.
> >
> > Would using a custom callback registration mechanism be advisable?
> > Is there something similar done already in IIO that can be leveraged?
> 
> Hi,
> 
> Have a look at the IIO consumer API that allows other kernel modules to
> subscribe to the output of an IIO device.
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/inclu
> de/linux/iio/consumer.h
> 
> 
> - Lars



RE: [PATH v3 0/3] iio: adc: xilinx: use even more devres

2020-12-11 Thread Anand Ashok Dumbre
> -Original Message-
> From: Jonathan Cameron 
> Sent: Monday 30 November 2020 8:21 PM
> To: Bartosz Golaszewski 
> Cc: Lars-Peter Clausen ; Peter Meerwald-Stadler
> ; Michal Simek ; linux-
> i...@vger.kernel.org; linux-arm-ker...@lists.infradead.org; linux-
> ker...@vger.kernel.org; Bartosz Golaszewski
> ; Anand Ashok Dumbre
> 
> Subject: Re: [PATH v3 0/3] iio: adc: xilinx: use even more devres
> 
> On Mon, 30 Nov 2020 15:27:56 +0100
> Bartosz Golaszewski  wrote:
> 
> > From: Bartosz Golaszewski 
> >
> > This is a follow-up to commit 750628c79bb1 ("iio: adc: xilinx-xadc:
> > use devm_krealloc()"). I noticed we can use even more devres helpers
> > and entirely drop the remove() callback.
> >
> > v1 -> v2:
> > - squash three patches adding more devres calls into one for easier
> > review
> > - don't insist on the 80 characters limit
> > - add a new helper: devm_krealloc_array() and use it
> >
> > v2 -> v3:
> > - drop the devm_krealloc_array() helper
> >
> > Bartosz Golaszewski (3):
> >   iio: adc: xilinx: use helper variable for >dev
> >   iio: adc: xilinx: use devm_krealloc() instead of kfree() + kcalloc()
> >   iio: adc: xilinx: use more devres helpers and remove remove()
> >
> >  drivers/iio/adc/xilinx-xadc-core.c | 157
> > ++---
> >  1 file changed, 74 insertions(+), 83 deletions(-)
> >
> 
> Series looks good to me but would like to leave it a little longer to let 
> others
> take a look at it. That will probably mean it falls into next cycle now.
> 
> +CC Anand who is looking at another series touching this driver and
> +might
> give this one a spin as well.
> 
> Thanks,
> 
> Jonathan

Hi Jonathan, Bartosz,

I have tested and reviewed the patch and everything looks good.
I have another patch series on the same files that might cause conflicts.

Reviewed-by: Anand Ashok Dumbre 
Tested-by: Anand Ashok Dumbre 

Thanks,
Anand


[LINUX PATCH v3] iio: core: Fix IIO_VAL_FRACTIONAL calculation for negative values

2020-10-05 Thread Anand Ashok Dumbre
Fixes IIO_VAL_FRACTIONAL for case when the result is negative and
exponent is 0.

example: if the result is -0.75, tmp0 will be 0 and tmp1 = 75
This causes the output to lose sign because of %d in snprintf
which works for tmp0 <= -1.

Signed-off-by: Anand Ashok Dumbre 
Reported-by: kernel test robot  #error: uninitialized symbol tmp
Reported-by: Dan Carpenter 
---

Changes in v3:
Fixed a bug caught by kernel test robot and used correct variable

---
 drivers/iio/industrialio-core.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index cdcd16f1..ffd5176 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -592,6 +592,7 @@ static ssize_t __iio_format_value(char *buf, size_t len, 
unsigned int type,
 {
unsigned long long tmp;
int tmp0, tmp1;
+   s64 tmp2;
bool scale_db = false;
 
switch (type) {
@@ -614,10 +615,13 @@ static ssize_t __iio_format_value(char *buf, size_t len, 
unsigned int type,
else
return scnprintf(buf, len, "%d.%09u", vals[0], vals[1]);
case IIO_VAL_FRACTIONAL:
-   tmp = div_s64((s64)vals[0] * 10LL, vals[1]);
+   tmp2 = div_s64((s64)vals[0] * 10LL, vals[1]);
tmp1 = vals[1];
-   tmp0 = (int)div_s64_rem(tmp, 10, );
-   return scnprintf(buf, len, "%d.%09u", tmp0, abs(tmp1));
+   tmp0 = (int)div_s64_rem(tmp2, 10, );
+   if ((tmp2 < 0) && (tmp0 == 0))
+   return snprintf(buf, len, "-0.%09u", abs(tmp1));
+   else
+   return snprintf(buf, len, "%d.%09u", tmp0, abs(tmp1));
case IIO_VAL_FRACTIONAL_LOG2:
tmp = shift_right((s64)vals[0] * 10LL, vals[1]);
tmp0 = (int)div_s64_rem(tmp, 10LL, );
-- 
2.7.4



RE: [PATCH v2] iio: core: Fix IIO_VAL_FRACTIONAL calculation for negative values

2020-08-31 Thread Anand Ashok Dumbre
Hi Jonathan,

I encountered this when I was developing a new driver.
If you look at the function where this is used, all other IIO_VAL_MICRO and NANO
have this fix added at some point.

Thanks,
Anand

> -Original Message-
> From: Jonathan Cameron 
> Sent: Saturday, August 29, 2020 4:19 PM
> To: Anand Ashok Dumbre 
> Cc: knaac...@gmx.de; l...@metafoo.de; pme...@pmeerw.net; Michal
> Simek ; git ; linux-
> i...@vger.kernel.org; linux-arm-ker...@lists.infradead.org; linux-
> ker...@vger.kernel.org; Anand Ashok Dumbre 
> Subject: Re: [PATCH v2] iio: core: Fix IIO_VAL_FRACTIONAL calculation for
> negative values
> 
> On Wed, 26 Aug 2020 11:14:36 -0700
> Anand Ashok Dumbre  wrote:
> 
> > Fixes IIO_VAL_FRACTIONAL for case when the result is negative and
> > exponent is 0.
> >
> > example: if the result is -0.75, tmp0 will be 0 and tmp1 = 75 This
> > causes the output to lose sign because of %d in snprintf which works
> > for tmp0 <= -1.
> >
> > Signed-off-by: Anand Ashok Dumbre 
> 
> Looks good.  Just one last thing.
> 
> Is this actually hit in an existing driver?  I'm just wondering how far back 
> we
> need to push it in stable etc.
> 
> Thanks,
> 
> Jonathan
> 
> > ---
> > changes since v1:
> > Changed -%d to -0 to make the fix clearer.
> > Removed the email footer.
> > Updated the commit description with an example
> > --
> >  drivers/iio/industrialio-core.c | 8 ++--
> >  1 file changed, 6 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/iio/industrialio-core.c
> > b/drivers/iio/industrialio-core.c index cdcd16f1..a239fa2 100644
> > --- a/drivers/iio/industrialio-core.c
> > +++ b/drivers/iio/industrialio-core.c
> > @@ -592,6 +592,7 @@ static ssize_t __iio_format_value(char *buf,
> > size_t len, unsigned int type,  {
> > unsigned long long tmp;
> > int tmp0, tmp1;
> > +   s64 tmp2;
> > bool scale_db = false;
> >
> > switch (type) {
> > @@ -614,10 +615,13 @@ static ssize_t __iio_format_value(char *buf,
> size_t len, unsigned int type,
> > else
> > return scnprintf(buf, len, "%d.%09u", vals[0], vals[1]);
> > case IIO_VAL_FRACTIONAL:
> > -   tmp = div_s64((s64)vals[0] * 10LL, vals[1]);
> > +   tmp2 = div_s64((s64)vals[0] * 10LL, vals[1]);
> > tmp1 = vals[1];
> > tmp0 = (int)div_s64_rem(tmp, 10, );
> > -   return scnprintf(buf, len, "%d.%09u", tmp0, abs(tmp1));
> > +   if ((tmp2 < 0) && (tmp0 == 0))
> > +   return snprintf(buf, len, "-0.%09u", abs(tmp1));
> > +   else
> > +   return snprintf(buf, len, "%d.%09u", tmp0,
> abs(tmp1));
> > case IIO_VAL_FRACTIONAL_LOG2:
> > tmp = shift_right((s64)vals[0] * 10LL, vals[1]);
> > tmp0 = (int)div_s64_rem(tmp, 10LL, );



[PATCH v2] iio: core: Fix IIO_VAL_FRACTIONAL calculation for negative values

2020-08-26 Thread Anand Ashok Dumbre
Fixes IIO_VAL_FRACTIONAL for case when the result is negative and
exponent is 0.

example: if the result is -0.75, tmp0 will be 0 and tmp1 = 75
This causes the output to lose sign because of %d in snprintf
which works for tmp0 <= -1.

Signed-off-by: Anand Ashok Dumbre 
---
changes since v1:
Changed -%d to -0 to make the fix clearer.
Removed the email footer.
Updated the commit description with an example
--
 drivers/iio/industrialio-core.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index cdcd16f1..a239fa2 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -592,6 +592,7 @@ static ssize_t __iio_format_value(char *buf, size_t len, 
unsigned int type,
 {
unsigned long long tmp;
int tmp0, tmp1;
+   s64 tmp2;
bool scale_db = false;
 
switch (type) {
@@ -614,10 +615,13 @@ static ssize_t __iio_format_value(char *buf, size_t len, 
unsigned int type,
else
return scnprintf(buf, len, "%d.%09u", vals[0], vals[1]);
case IIO_VAL_FRACTIONAL:
-   tmp = div_s64((s64)vals[0] * 10LL, vals[1]);
+   tmp2 = div_s64((s64)vals[0] * 10LL, vals[1]);
tmp1 = vals[1];
tmp0 = (int)div_s64_rem(tmp, 10, );
-   return scnprintf(buf, len, "%d.%09u", tmp0, abs(tmp1));
+   if ((tmp2 < 0) && (tmp0 == 0))
+   return snprintf(buf, len, "-0.%09u", abs(tmp1));
+   else
+   return snprintf(buf, len, "%d.%09u", tmp0, abs(tmp1));
case IIO_VAL_FRACTIONAL_LOG2:
tmp = shift_right((s64)vals[0] * 10LL, vals[1]);
tmp0 = (int)div_s64_rem(tmp, 10LL, );
-- 
2.7.4



[PATCH] iio: Fixed IIO_VAL_FRACTIONAL calcuation for negative values

2020-08-20 Thread Anand Ashok Dumbre
This patch fixes IIO_VAL_FRACTIONAL calculation for negative
values where the exponent is 0.

Signed-off-by: Anand Ashok Dumbre 
---
 drivers/iio/industrialio-core.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index f72c2dc..cd43b17 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -554,6 +554,7 @@ static ssize_t __iio_format_value(char *buf, size_t len, 
unsigned int type,
 {
unsigned long long tmp;
int tmp0, tmp1;
+   s64 tmp2;
bool scale_db = false;

switch (type) {
@@ -576,10 +577,13 @@ static ssize_t __iio_format_value(char *buf, size_t len, 
unsigned int type,
else
return snprintf(buf, len, "%d.%09u", vals[0], vals[1]);
case IIO_VAL_FRACTIONAL:
-   tmp = div_s64((s64)vals[0] * 10LL, vals[1]);
+   tmp2 = div_s64((s64)vals[0] * 10LL, vals[1]);
tmp1 = vals[1];
-   tmp0 = (int)div_s64_rem(tmp, 10, );
-   return snprintf(buf, len, "%d.%09u", tmp0, abs(tmp1));
+   tmp0 = (int)div_s64_rem(tmp2, 10, );
+   if ((tmp2 < 0) && (tmp0 == 0))
+   return snprintf(buf, len, "-%d.%09u", tmp0, abs(tmp1));
+   else
+   return snprintf(buf, len, "%d.%09u", tmp0, abs(tmp1));
case IIO_VAL_FRACTIONAL_LOG2:
tmp = shift_right((s64)vals[0] * 10LL, vals[1]);
tmp0 = (int)div_s64_rem(tmp, 10LL, );
--
2.7.4

This email and any attachments are intended for the sole use of the named 
recipient(s) and contain(s) confidential information that may be proprietary, 
privileged or copyrighted under applicable law. If you are not the intended 
recipient, do not read, copy, or forward this email message or any attachments. 
Delete this email message and any attachments immediately.


[PATCH] iio: Fixed IIO_VAL_FRACTIONAL calcuation for negative values

2020-08-20 Thread Anand Ashok Dumbre
This patch fixes IIO_VAL_FRACTIONAL calculation for negative
values where the exponent is 0.

Signed-off-by: Anand Ashok Dumbre 
---
 drivers/iio/industrialio-core.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index f72c2dc..cd43b17 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -554,6 +554,7 @@ static ssize_t __iio_format_value(char *buf, size_t len, 
unsigned int type,
 {
unsigned long long tmp;
int tmp0, tmp1;
+   s64 tmp2;
bool scale_db = false;

switch (type) {
@@ -576,10 +577,13 @@ static ssize_t __iio_format_value(char *buf, size_t len, 
unsigned int type,
else
return snprintf(buf, len, "%d.%09u", vals[0], vals[1]);
case IIO_VAL_FRACTIONAL:
-   tmp = div_s64((s64)vals[0] * 10LL, vals[1]);
+   tmp2 = div_s64((s64)vals[0] * 10LL, vals[1]);
tmp1 = vals[1];
-   tmp0 = (int)div_s64_rem(tmp, 10, );
-   return snprintf(buf, len, "%d.%09u", tmp0, abs(tmp1));
+   tmp0 = (int)div_s64_rem(tmp2, 10, );
+   if ((tmp2 < 0) && (tmp0 == 0))
+   return snprintf(buf, len, "-%d.%09u", tmp0, abs(tmp1));
+   else
+   return snprintf(buf, len, "%d.%09u", tmp0, abs(tmp1));
case IIO_VAL_FRACTIONAL_LOG2:
tmp = shift_right((s64)vals[0] * 10LL, vals[1]);
tmp0 = (int)div_s64_rem(tmp, 10LL, );
--
2.7.4

This email and any attachments are intended for the sole use of the named 
recipient(s) and contain(s) confidential information that may be proprietary, 
privileged or copyrighted under applicable law. If you are not the intended 
recipient, do not read, copy, or forward this email message or any attachments. 
Delete this email message and any attachments immediately.