Re: [PATCH 1/2] staging:iio:accel:adis16203: add SPDX license identifier tag

2019-04-03 Thread Himanshu Jha
On Wed, Apr 03, 2019 at 11:41:28AM +0200, Nicholas Mc Guire wrote:
> Pop in the SPDX tag as the license is clearly indicated
> as GPL V2 or later this should also be indicated with a SPDX license
> identifier tag.
> 
> Signed-off-by: Nicholas Mc Guire 
> ---
> 
> chackpatch.pl was warning:
> WARNING: Missing or malformed SPDX-License-Identifier tag in line 1
> 
> Patch was compile tested with: X86_64_defconfig + SPI=y, IIO=m
> STAGING=y, ADIS16203=m
> 
> Patch is against 5.1-rc3 (localversion-next is next-20190403)
> 
>  drivers/staging/iio/accel/adis16203.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/staging/iio/accel/adis16203.c 
> b/drivers/staging/iio/accel/adis16203.c
> index 5cc96c80..cf9d41a 100644
> --- a/drivers/staging/iio/accel/adis16203.c
> +++ b/drivers/staging/iio/accel/adis16203.c
> @@ -1,3 +1,4 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later

SPDX-License-Identifier: GPL-2.0+ ?

Documentation/process/license-rules.rst

 For 'GNU General Public License (GPL) version 2 or any later version' use:
   SPDX-License-Identifier: GPL-2.0+

The following should also be removed in this same patch:

* Licensed under the GPL-2 or later.

And lastly, MODULE_LICENSE() should also be checked, which appear
to be correct in its current form.

>  /*
>   * ADIS16203 Programmable 360 Degrees Inclinometer
>   *
> -- 
> 2.1.4
> 

-- 
Himanshu Jha
Undergraduate Student
Department of Electronics & Communication
Guru Tegh Bahadur Institute of Technology
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] Staging: iio: ad7192: replaced bool in struct

2019-01-07 Thread Himanshu Jha
On Wed, Jan 02, 2019 at 01:25:27PM -0800, Matt Ranostay wrote:
> 
> > On Dec 24, 2018, at 01:58, Himanshu Jha  wrote:
> > 
> >> On Fri, Dec 21, 2018 at 03:26:26PM -0800, Amir Mahdi Ghorbanian wrote:
> >> Replaced bool in struct with unsigned int bitfield to conserve space and
> >> more clearly define size of varibales
> 
> Important thing to note is depending on padding, alignment, and position of 
> field it probably won’t save any space.

Well, then what do you say about the following results ;-)

Before:
--

himanshu@himanshu-Vostro-3559:~/gsoc/linux$ pahole -C ad7192_platform_data 
drivers/staging/iio/adc/ad7192.o
struct ad7192_platform_data {
u16vref_mv;  /* 0 2 */
u8 clock_source_sel; /* 2 1 */

/* XXX 1 byte hole, try to pack */

u32ext_clk_hz;   /* 4 4 */
bool   refin2_en;/* 8 1 */
bool   rej60_en; /* 9 1 */
bool   sinc3_en; /*10 1 */
bool   chop_en;  /*11 1 */
bool   buf_en;   /*12 1 */
bool   unipolar_en;  /*13 1 */
bool   burnout_curr_en;  /*14 1 */

/* size: 16, cachelines: 1, members: 10 */
/* sum members: 14, holes: 1, sum holes: 1 */
/* padding: 1 */
/* last cacheline: 16 bytes */
};

After:
-

himanshu@himanshu-Vostro-3559:~/gsoc/linux$ pahole -C ad7192_platform_data 
drivers/staging/iio/adc/ad7192.o
struct ad7192_platform_data {
u16vref_mv;  /* 0 2 */
u8 clock_source_sel; /* 2 1 */

/* XXX 1 byte hole, try to pack */

u32ext_clk_hz;   /* 4 4 */
unsigned int   refin2_en:1;  /* 8:31  4 */
unsigned int   rej60_en:1;   /* 8:30  4 */
unsigned int   sinc3_en:1;   /* 8:29  4 */
unsigned int   chop_en:1;/* 8:28  4 */
unsigned int   buf_en:1; /* 8:27  4 */
unsigned int   unipolar_en:1;/* 8:26  4 */
unsigned int   burnout_curr_en:1;/* 8:25  4 */

/* size: 12, cachelines: 1, members: 10 */
/* sum members: 11, holes: 1, sum holes: 1 */
/* bit_padding: 25 bits */
/* last cacheline: 12 bytes */
};

> Also for internal unpacked structures it really makes little sense to save a 
> few bytes of data. Don’t read into that packed structures are good.. they 
> usually aren’t :)

Yes, agreed, but I often see patches to save few bytes by marking
array as static.

There is some effort in this direction:
https://lore.kernel.org/lkml/20181221235230.gc13...@ziepe.ca/

Very likely to get more patches if the above patch gets merged.


-- 
Himanshu Jha
Undergraduate Student
Department of Electronics & Communication
Guru Tegh Bahadur Institute of Technology
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] Staging: iio: ad7192: replaced bool in struct

2018-12-24 Thread Himanshu Jha
On Fri, Dec 21, 2018 at 03:26:26PM -0800, Amir Mahdi Ghorbanian wrote:
> Replaced bool in struct with unsigned int bitfield to conserve space and
> more clearly define size of varibales
> 
> Signed-off-by: Amir Mahdi Ghorbanian 
> ---

There was some discussion on this at Outreachy list:
https://groups.google.com/d/msg/outreachy-kernel/xpQAl-Gn8HA/yqcQRG_qBgAJ

I think unless you post some statistics about 'conserving' space, 
it is unlikely that maintainers will apply it.

This idea was originally given by Linus and that thread of discussion 
is worth reading too.

>  drivers/staging/iio/adc/ad7192.h | 14 +++---
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/staging/iio/adc/ad7192.h 
> b/drivers/staging/iio/adc/ad7192.h
> index 7433a43..7d3e62f 100644
> --- a/drivers/staging/iio/adc/ad7192.h
> +++ b/drivers/staging/iio/adc/ad7192.h
> @@ -35,13 +35,13 @@ struct ad7192_platform_data {
>   u16 vref_mv;
>   u8  clock_source_sel;
>   u32 ext_clk_hz;
> - boolrefin2_en;
> - boolrej60_en;
> - boolsinc3_en;
> - boolchop_en;
> - boolbuf_en;
> - boolunipolar_en;
> - boolburnout_curr_en;
> + unsigned intrefin2_en : 1;
> + unsigned intrej60_en : 1;
> + unsigned intsinc3_en : 1;
> + unsigned intchop_en : 1;
> + unsigned intbuf_en : 1;
> + unsigned intunipolar_en : 1;
> + unsigned intburnout_curr_en : 1;
>  };
>  
>  #endif /* IIO_ADC_AD7192_H_ */
> -- 
> 2.7.4
> 

Goodluck!

-- 
Himanshu Jha
Undergraduate Student
Department of Electronics & Communication
Guru Tegh Bahadur Institute of Technology
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] staging: iio: ad5933: add binding doc for ad5933

2018-12-02 Thread Himanshu Jha
On Sun, Dec 02, 2018 at 02:57:12PM -0200, Marcelo Schmitt wrote:
> Add a devicetree documentation for the ad5933 and ad5934 impedance
> converter, network analyzer.
> 
> Co-Developed-by: Gabriel Capella 

checkpatch spits out:

WARNING: Non-standard signature: Co-Developed-by:

Co-developed-by Vs Co-Developed-by ?

Documentation/process/5.Posting.rst: - Co-developed-by: states that the patch 
was also created by another developer
Documentation/process/submitting-patches.rst:12) When to use Acked-by:, Cc:, 
and Co-Developed-by:

Confusing! Don't know which one is correct.

> Signed-off-by: Marcelo Schmitt 
> Signed-off-by: Gabriel Capella 
> ---

Use `./scripts/get_maintainer.pl ` to list the DT
maintainers and the relevant mailing list.


-- 
Himanshu Jha
Undergraduate Student
Department of Electronics & Communication
Guru Tegh Bahadur Institute of Technology
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v7 3/3] staging: iio: ad2s1210: Add device tree table.

2018-11-01 Thread Himanshu Jha
On Wed, Oct 31, 2018 at 09:30:36PM +0530, Nishad Kamdar wrote:
> Add device tree table for matching vendor ID.
> 
> Signed-off-by: Nishad Kamdar 
> ---
>  drivers/staging/iio/resolver/ad2s1210.c | 7 +++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/drivers/staging/iio/resolver/ad2s1210.c 
> b/drivers/staging/iio/resolver/ad2s1210.c
> index d3e7d5aad2c8..7c50def91a2b 100644
> --- a/drivers/staging/iio/resolver/ad2s1210.c
> +++ b/drivers/staging/iio/resolver/ad2s1210.c
> @@ -701,6 +701,12 @@ static int ad2s1210_remove(struct spi_device *spi)
>   return 0;
>  }
>  
> +static const struct of_device_id ad2s1210_of_match[] = {
> + { .compatible = "adi,ad2s1210", },
> + { }
> +};
> +MODULE_DEVICE_TABLE(of, ad2s1210_of_match);

I believe this needs to be documented at:

Documentation/devicetree/bindings/iio/resolver/ad2s1210.txt

Cc'ed to devictree list + Rob(DT Maintainer).

Just wondering why didn't it came up till now from the IIO reviewers ? v7!!


-- 
Himanshu Jha
Undergraduate Student
Department of Electronics & Communication
Guru Tegh Bahadur Institute of Technology
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [Outreachy kernel] [RESEND PATCH 2/2] staging: vboxvideo: Use unsigned int instead bool

2018-10-28 Thread Himanshu Jha
On Sun, Oct 28, 2018 at 09:47:15AM +0100, Julia Lawall wrote:
> > The "possible alignement issues" in CHECK report is difficult to figure
> > out by just doing a glance analysis. :)
> >
> > Linus also suggested to use bool as the base type i.e., `bool x:1` but
> > again sizeof(_Bool) is implementation defined ranging from 1-4 bytes.
> 
> If bool x:1 has the size of bool, then wouldn't int x:1 have the size of
> int?  But my little experiments suggest that the size is the smallest that
> fits the requested bits and alignment chosen by the compiler, regardless of
> the type.

Yes, correct!
And we can't use sizeof on bitfields *directly*, nor reference it using a
pointer.

It can be applied only when these bitfields are wrapped in a structure.

Testing:

#include 
#include 

struct S {
bool a:1;
bool b:1;
bool c:1;
bool d:1;
};

int main(void)
{
printf("%zu\n", sizeof(struct S));
}

Output: 1

If I change all bool to unsigned int, output is: *4*.

So, conclusion is compiler doesn't squeeze the size less than
native size of the datatype i.e., if we changed all members to
unsigned int:1, 
total width = 4 bits
padding = 4 bits

Therefore, total size should have been = 1 byte!
But since sizeof(unsigned int) == 4, it can't be squeezed to
less than it.


> bool x:1 has the advantage that anything that is not 0 is considered true.

Yes, implicit conversion rules for boolean.

> So for bool x:1, x = 4 is true, while for int x:1, x = 4 is false.

Well, int x:1 can either have 0..1 or -1..0 range due implementation
defined behavior as I said in the previous reply.

If you really want to consider negative values, then make it explicit
using `signed int x:1` which make range guaranteed to be -1..0

Regardless, integer conversion rules will kick in.

> But the :1 adds instructions, so at least for only one bool, where little
> space is saved, it is probably not worth it.

True, we should reply on a promised guideline rather than possibility.


-- 
Himanshu Jha
Undergraduate Student
Department of Electronics & Communication
Guru Tegh Bahadur Institute of Technology
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [Outreachy kernel] [RESEND PATCH 2/2] staging: vboxvideo: Use unsigned int instead bool

2018-10-28 Thread Himanshu Jha
Hi Sasha,

On Fri, Oct 26, 2018 at 04:42:25PM -0400, Sasha Levin wrote:
> On Fri, Oct 26, 2018 at 04:04:45PM -0300, Shayenne da Luz Moura wrote:
> > This change was suggested by checkpath.pl. Use unsigned int with bitfield
> > allocate only one bit to the boolean variable.
> > 
> > CHECK: Avoid using bool structure members because of possible alignment
> > issues
> > 
> > Signed-off-by: Shayenne da Luz Moura 
> > ---
> > drivers/staging/vboxvideo/vbox_drv.h| 14 +++---
> > drivers/staging/vboxvideo/vboxvideo_guest.h |  2 +-
> > 2 files changed, 8 insertions(+), 8 deletions(-)
> > 
> > diff --git a/drivers/staging/vboxvideo/vbox_drv.h 
> > b/drivers/staging/vboxvideo/vbox_drv.h
> > index 594f84272957..7d3e329a6b1c 100644
> > --- a/drivers/staging/vboxvideo/vbox_drv.h
> > +++ b/drivers/staging/vboxvideo/vbox_drv.h
> > @@ -81,7 +81,7 @@ struct vbox_private {
> > u8 __iomem *vbva_buffers;
> > struct gen_pool *guest_pool;
> > struct vbva_buf_ctx *vbva_info;
> > -   bool any_pitch;
> > +   unsigned int any_pitch:1;
> > u32 num_crtcs;
> > /** Amount of available VRAM, including space used for buffers. */
> > u32 full_vram_size;
> 
> Using bitfields for booleans in these cases is less efficient than just
> using "regular" booleans for two reasons:
> 
> 1. It will use the same amount of space. Due to alignment requirements,
> the compiler can't squeeze in anything into the 7 bits that are now
> "free". Each member, unless it's another bitfield, must start at a whole
> byte.

Agreed!

FYI original thread of discussion: https://lkml.org/lkml/2017/11/21/207

As Steve says:

"Thus, changing:

 int  a : 1;
 int  b : 1;
 int  c : 1;
 int  d : 1;

to

 bool a;
 bool b;
 bool c;
 bool d;

at best increases the size required from 1 byte to 4 bytes, and at
worse, it increases it from one byte to 16 bytes."

In the above cases, we have all bitfields members and no non-bitfields
members.

But before playing with these bitfields there are some points to be
noted:
https://port70.net/~nsz/c/c11/n1570.html#J.3.9

Implementation Defined
--

* Whether a ''plain'' int bit-field is treated as a signed int 
  bit-field or as an unsigned int bit-field.

eg: `int foo:3` may have a range from 0..7 or -4..3

So, changing `int foo:3` to `unsigned int foo:3` might be a sane
change to remove the ambiguity and make sure range is 0..7.

Also, such an change can also handle unsigned overflow
or better said "wrapping".

* Whether a bit-field can straddle a storage-unit boundary.

So, you can't guess what could be the possible unless you're familiar
or tested the change for different arch.

* The alignment of non-bit-field members of structures.

...

The "possible alignement issues" in CHECK report is difficult to figure
out by just doing a glance analysis. :)

Linus also suggested to use bool as the base type i.e., `bool x:1` but
again sizeof(_Bool) is implementation defined ranging from 1-4 bytes.

And since this issue is added to checkpatch now, very likely there would
be blast of patches sent on the same.

Not everyone who sends checkpatch would be able to disassemble or test
on different implementations.

But if anyone is interested check this:
https://godbolt.org/


-- 
Himanshu Jha
Undergraduate Student
Department of Electronics & Communication
Guru Tegh Bahadur Institute of Technology
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] staging: iio: ad7780: update voltage on read

2018-10-25 Thread Himanshu Jha
On Thu, Oct 25, 2018 at 11:26:36AM -0300, Renato Lui Geh wrote:
> Hi,
> 
> Thanks for the quick review. :)
> 
> > But please create one patch per issue and do not put unrelated changes into
> > the same patch.
> 
> Should I resend this patch as a patchset containing the two changes?

Yes! "One patch per change policy"

> > Also your mail client seems to have replaced tabs in the patch with spaces,
> > this means the patch will not apply cleanly. Check the
> > Documentation/email-clients.txt file for some hints how to configure your
> > mail client so it will not break patches.
> 
> From my end my original email patch appears to have tabs instead of
> spaces. I redownloaded my email and vim shows that the indentation has
> the ^I tab characters. But when downloading your reply it was converted
> to spaces. Am I missing something?

Your patch applies fine.

I think the problem is on Lars end due to Thunderbird.

In the meantime, you can verify the patch using:

$ git am 

Also, you can try to use `git send-email` to send patches.


-- 
Himanshu Jha
Undergraduate Student
Department of Electronics & Communication
Guru Tegh Bahadur Institute of Technology
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] staging: iio: ad2s1210: fix 'assignment operator' style checks

2018-10-07 Thread Himanshu Jha
On Fri, Oct 05, 2018 at 10:24:26PM -0300, Matheus Tavares Bernardino wrote:
> This patch fixes all "Assignment operator '=' should be on the previous
> line" checks found in ad2s1210.c by checkpatch.pl.
> 
> Signed-off-by: Matheus Tavares 
> ---

As already pointed out tabs -> whitespace issue.

I assume you attached or copied the patch into your email
client and sent it. Usually, these clients wrap the message
which leads to patch corruption and hence it would apply
to the maintainer's git tree cleanly.

Therefore, I would suggest using `git send-email`.

Also, as a safety measure you may use the `--dry-run` flag
of `git send-email` to see how it would look like when you
send the patch.


Thanks
-- 
Himanshu Jha
Undergraduate Student
Department of Electronics & Communication
Guru Tegh Bahadur Institute of Technology
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] staging: gasket: remove null ptr check before kfree

2018-08-12 Thread Himanshu Jha
On Sun, Aug 12, 2018 at 12:28:37PM +0530, Sumit Kumar wrote:
> Remove null ptr check before kfree because kfree is null ptr safe.
> Issue found by checkpatch.
> 
> Signed-off-by: Sumit Kumar 

Hmm. Victim of copy-paste I guess.
No worries. Next time just use:

$  git commit -s

To understand what -s flag does, refer `man git commit`.

> ---

Now, this where you should have put versions just below the '---':

v2:
   - corrected email address.

And yes, the subject should be:

"Subject: [PATCH v2] staging: gasket: remove null ptr check before kfree"

https://www.kernel.org/doc/html/latest/process/submitting-patches.html#the-canonical-patch-format

Hope that helps!

-- 
Himanshu Jha
Undergraduate Student
Department of Electronics & Communication
Guru Tegh Bahadur Institute of Technology
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 1/4] Staging: iio: accel: adis16201: Remove unused headers

2018-03-22 Thread Himanshu Jha
Remove few unused headers files since the adis core handles the buffer and
sysfs support.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/staging/iio/accel/adis16201.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/staging/iio/accel/adis16201.c 
b/drivers/staging/iio/accel/adis16201.c
index 97e25a3..b04dbb3 100644
--- a/drivers/staging/iio/accel/adis16201.c
+++ b/drivers/staging/iio/accel/adis16201.c
@@ -6,7 +6,6 @@
  * Licensed under the GPL-2 or later.
  */
 
-#include 
 #include 
 #include 
 #include 
@@ -16,8 +15,6 @@
 #include 
 
 #include 
-#include 
-#include 
 #include 
 
 #define ADIS16201_STARTUP_DELAY_MS 220
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 2/4] Staging: iio: accel: adis16201: Use GENMASK

2018-03-22 Thread Himanshu Jha
Use GENMASK to improve readability and remove the local variables used to
store intermediate data.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/staging/iio/accel/adis16201.c | 34 +++---
 1 file changed, 15 insertions(+), 19 deletions(-)

diff --git a/drivers/staging/iio/accel/adis16201.c 
b/drivers/staging/iio/accel/adis16201.c
index b04dbb3..e7593fa 100644
--- a/drivers/staging/iio/accel/adis16201.c
+++ b/drivers/staging/iio/accel/adis16201.c
@@ -185,28 +185,24 @@ static int adis16201_write_raw(struct iio_dev *indio_dev,
   long mask)
 {
struct adis *st = iio_priv(indio_dev);
-   int bits;
-   s16 val16;
-   u8 addr;
+   int m;
 
-   switch (mask) {
-   case IIO_CHAN_INFO_CALIBBIAS:
-   switch (chan->type) {
-   case IIO_ACCEL:
-   bits = 12;
-   break;
-   case IIO_INCLI:
-   bits = 9;
-   break;
-   default:
-   return -EINVAL;
+   if (mask != IIO_CHAN_INFO_CALIBBIAS)
+   return -EINVAL;
+
+   switch (chan->type) {
+   case IIO_ACCEL:
+   m = GENMASK(11, 0);
+   break;
+   case IIO_INCLI:
+   m = GENMASK(8, 0);
+   break;
+   default:
+   return -EINVAL;
}
-   val16 = val & ((1 << bits) - 1);
-   addr = adis16201_addresses[chan->scan_index];
-   return adis_write_reg_16(st, addr, val16);
-   }
 
-   return -EINVAL;
+   return adis_write_reg_16(st, adis16201_addresses[chan->scan_index],
+val & m);
 }
 
 static const struct iio_chan_spec adis16201_channels[] = {
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 4/4] Staging: iio: accel: adis16201: Move adis16201 driver out of staging

2018-03-22 Thread Himanshu Jha
Move adis16201 driver out of staging and merge into mainline
IIO subsystem.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/iio/accel/Kconfig |  12 ++
 drivers/iio/accel/Makefile|   1 +
 drivers/iio/accel/adis16201.c | 321 ++
 drivers/staging/iio/accel/Kconfig |  12 --
 drivers/staging/iio/accel/Makefile|   1 -
 drivers/staging/iio/accel/adis16201.c | 321 --
 6 files changed, 334 insertions(+), 334 deletions(-)
 create mode 100644 drivers/iio/accel/adis16201.c
 delete mode 100644 drivers/staging/iio/accel/adis16201.c

diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig
index c6d9517..9416c6f 100644
--- a/drivers/iio/accel/Kconfig
+++ b/drivers/iio/accel/Kconfig
@@ -5,6 +5,18 @@
 
 menu "Accelerometers"
 
+config ADIS16201
+tristate "Analog Devices ADIS16201 Dual-Axis Digital Inclinometer and 
Accelerometer"
+depends on SPI
+select IIO_ADIS_LIB
+select IIO_ADIS_LIB_BUFFER if IIO_BUFFER
+help
+  Say Y here to build support for Analog Devices adis16201 dual-axis
+  digital inclinometer and accelerometer.
+
+  To compile this driver as a module, say M here: the module will
+  be called adis16201.
+
 config ADXL345
tristate
 
diff --git a/drivers/iio/accel/Makefile b/drivers/iio/accel/Makefile
index 368aedb..7832ec9 100644
--- a/drivers/iio/accel/Makefile
+++ b/drivers/iio/accel/Makefile
@@ -4,6 +4,7 @@
 #
 
 # When adding new entries keep the list in alphabetical order
+obj-$(CONFIG_ADIS16201) += adis16201.o
 obj-$(CONFIG_ADXL345) += adxl345_core.o
 obj-$(CONFIG_ADXL345_I2C) += adxl345_i2c.o
 obj-$(CONFIG_ADXL345_SPI) += adxl345_spi.o
diff --git a/drivers/iio/accel/adis16201.c b/drivers/iio/accel/adis16201.c
new file mode 100644
index 000..51e1afb
--- /dev/null
+++ b/drivers/iio/accel/adis16201.c
@@ -0,0 +1,321 @@
+/*
+ * ADIS16201 Dual-Axis Digital Inclinometer and Accelerometer
+ *
+ * Copyright 2010 Analog Devices Inc.
+ *
+ * Licensed under the GPL-2 or later.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#define ADIS16201_STARTUP_DELAY_MS 220
+#define ADIS16201_FLASH_CNT0x00
+
+/* Data Output Register Information */
+#define ADIS16201_SUPPLY_OUT_REG   0x02
+#define ADIS16201_XACCL_OUT_REG0x04
+#define ADIS16201_YACCL_OUT_REG0x06
+#define ADIS16201_AUX_ADC_REG  0x08
+#define ADIS16201_TEMP_OUT_REG 0x0A
+#define ADIS16201_XINCL_OUT_REG0x0C
+#define ADIS16201_YINCL_OUT_REG0x0E
+
+/* Calibration Register Definition */
+#define ADIS16201_XACCL_OFFS_REG   0x10
+#define ADIS16201_YACCL_OFFS_REG   0x12
+#define ADIS16201_XACCL_SCALE_REG  0x14
+#define ADIS16201_YACCL_SCALE_REG  0x16
+#define ADIS16201_XINCL_OFFS_REG   0x18
+#define ADIS16201_YINCL_OFFS_REG   0x1A
+#define ADIS16201_XINCL_SCALE_REG  0x1C
+#define ADIS16201_YINCL_SCALE_REG  0x1E
+
+/* Alarm Register Definition */
+#define ADIS16201_ALM_MAG1_REG 0x20
+#define ADIS16201_ALM_MAG2_REG 0x22
+#define ADIS16201_ALM_SMPL1_REG0x24
+#define ADIS16201_ALM_SMPL2_REG0x26
+#define ADIS16201_ALM_CTRL_REG 0x28
+
+#define ADIS16201_AUX_DAC_REG  0x30
+#define ADIS16201_GPIO_CTRL_REG0x32
+#define ADIS16201_SMPL_PRD_REG 0x36
+/* Operation, filter configuration */
+#define ADIS16201_AVG_CNT_REG  0x38
+#define ADIS16201_SLP_CNT_REG  0x3A
+
+/* Miscellaneous Control Register Definition */
+#define ADIS16201_MSC_CTRL_REG 0x34
+#define  ADIS16201_MSC_CTRL_SELF_TEST_EN   BIT(8)
+/* Data-ready enable: 1 = enabled, 0 = disabled */
+#define  ADIS16201_MSC_CTRL_DATA_RDY_ENBIT(2)
+/* Data-ready polarity: 1 = active high, 0 = active low */
+#define  ADIS16201_MSC_CTRL_ACTIVE_DATA_RDY_HIGH   BIT(1)
+/* Data-ready line selection: 1 = DIO1, 0 = DIO0 */
+#define  ADIS16201_MSC_CTRL_DATA_RDY_DIO1  BIT(0)
+
+/* Diagnostics System Status Register Definition */
+#define ADIS16201_DIAG_STAT_REG0x3C
+#define  ADIS16201_DIAG_STAT_ALARM2BIT(9)
+#define  ADIS16201_DIAG_STAT_ALARM1BIT(8)
+#define  ADIS16201_DIAG_STAT_SPI_FAIL_BIT  3
+#define  ADIS16201_DI

[PATCH v2 9/9] Staging: iio: accel: adis16201: Move adis16201 driver out of staging

2018-03-16 Thread Himanshu Jha
Move the adis16201 driver out of staging directory and merge to the
mainline IIO subsystem.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
v2:
   -no change in this patch.

 drivers/iio/accel/Kconfig |  12 ++
 drivers/iio/accel/Makefile|   1 +
 drivers/iio/accel/adis16201.c | 327 ++
 drivers/staging/iio/accel/Kconfig |  12 --
 drivers/staging/iio/accel/Makefile|   1 -
 drivers/staging/iio/accel/adis16201.c | 327 --
 6 files changed, 340 insertions(+), 340 deletions(-)
 create mode 100644 drivers/iio/accel/adis16201.c
 delete mode 100644 drivers/staging/iio/accel/adis16201.c

diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig
index c6d9517..9416c6f 100644
--- a/drivers/iio/accel/Kconfig
+++ b/drivers/iio/accel/Kconfig
@@ -5,6 +5,18 @@
 
 menu "Accelerometers"
 
+config ADIS16201
+tristate "Analog Devices ADIS16201 Dual-Axis Digital Inclinometer and 
Accelerometer"
+depends on SPI
+select IIO_ADIS_LIB
+select IIO_ADIS_LIB_BUFFER if IIO_BUFFER
+help
+  Say Y here to build support for Analog Devices adis16201 dual-axis
+  digital inclinometer and accelerometer.
+
+  To compile this driver as a module, say M here: the module will
+  be called adis16201.
+
 config ADXL345
tristate
 
diff --git a/drivers/iio/accel/Makefile b/drivers/iio/accel/Makefile
index 368aedb..7832ec9 100644
--- a/drivers/iio/accel/Makefile
+++ b/drivers/iio/accel/Makefile
@@ -4,6 +4,7 @@
 #
 
 # When adding new entries keep the list in alphabetical order
+obj-$(CONFIG_ADIS16201) += adis16201.o
 obj-$(CONFIG_ADXL345) += adxl345_core.o
 obj-$(CONFIG_ADXL345_I2C) += adxl345_i2c.o
 obj-$(CONFIG_ADXL345_SPI) += adxl345_spi.o
diff --git a/drivers/iio/accel/adis16201.c b/drivers/iio/accel/adis16201.c
new file mode 100644
index 000..e439cf7
--- /dev/null
+++ b/drivers/iio/accel/adis16201.c
@@ -0,0 +1,327 @@
+/*
+ * ADIS16201 Dual-Axis Digital Inclinometer and Accelerometer
+ *
+ * Copyright 2010 Analog Devices Inc.
+ *
+ * Licensed under the GPL-2 or later.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#define ADIS16201_STARTUP_DELAY_MS 220
+#define ADIS16201_FLASH_CNT0x00
+
+/* Data Output Register Information */
+#define ADIS16201_SUPPLY_OUT_REG   0x02
+#define ADIS16201_XACCL_OUT_REG0x04
+#define ADIS16201_YACCL_OUT_REG0x06
+#define ADIS16201_AUX_ADC_REG  0x08
+#define ADIS16201_TEMP_OUT_REG 0x0A
+#define ADIS16201_XINCL_OUT_REG0x0C
+#define ADIS16201_YINCL_OUT_REG0x0E
+
+/* Calibration Register Definition */
+#define ADIS16201_XACCL_OFFS_REG   0x10
+#define ADIS16201_YACCL_OFFS_REG   0x12
+#define ADIS16201_XACCL_SCALE_REG  0x14
+#define ADIS16201_YACCL_SCALE_REG  0x16
+#define ADIS16201_XINCL_OFFS_REG   0x18
+#define ADIS16201_YINCL_OFFS_REG   0x1A
+#define ADIS16201_XINCL_SCALE_REG  0x1C
+#define ADIS16201_YINCL_SCALE_REG  0x1E
+
+/* Alarm Register Definition */
+#define ADIS16201_ALM_MAG1_REG 0x20
+#define ADIS16201_ALM_MAG2_REG 0x22
+#define ADIS16201_ALM_SMPL1_REG0x24
+#define ADIS16201_ALM_SMPL2_REG0x26
+#define ADIS16201_ALM_CTRL_REG 0x28
+
+#define ADIS16201_AUX_DAC_REG  0x30
+#define ADIS16201_GPIO_CTRL_REG0x32
+#define ADIS16201_SMPL_PRD_REG 0x36
+/* Operation, filter configuration */
+#define ADIS16201_AVG_CNT_REG  0x38
+#define ADIS16201_SLP_CNT_REG  0x3A
+
+/* Miscellaneous Control Register Definition */
+#define ADIS16201_MSC_CTRL_REG 0x34
+#define  ADIS16201_MSC_CTRL_SELF_TEST_EN   BIT(8)
+/* Data-ready enable: 1 = enabled, 0 = disabled */
+#define  ADIS16201_MSC_CTRL_DATA_RDY_ENBIT(2)
+/* Data-ready polarity: 1 = active high, 0 = active low */
+#define  ADIS16201_MSC_CTRL_ACTIVE_DATA_RDY_HIGH   BIT(1)
+/* Data-ready line selection: 1 = DIO1, 0 = DIO0 */
+#define  ADIS16201_MSC_CTRL_DATA_RDY_DIO1  BIT(0)
+
+/* Diagnostics System Status Register Definition */
+#define ADIS16201_DIAG_STAT_REG0x3C
+#define  ADIS16201_DIAG_STAT_ALARM2BIT(9)
+#define  ADIS16201_DIAG_STAT_ALARM1 

[PATCH v2 7/9] Staging: iio: accel: adis16201: Prefer reverse christmas tree ordering

2018-03-16 Thread Himanshu Jha
Prefer reverse christmas tree ordering of declarations to improve
readability.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
v2:
   -no change in this patch.

 drivers/staging/iio/accel/adis16201.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/iio/accel/adis16201.c 
b/drivers/staging/iio/accel/adis16201.c
index 298bf90..00e944e 100644
--- a/drivers/staging/iio/accel/adis16201.c
+++ b/drivers/staging/iio/accel/adis16201.c
@@ -259,9 +259,9 @@ static const struct adis_data adis16201_data = {
 
 static int adis16201_probe(struct spi_device *spi)
 {
-   int ret;
-   struct adis *st;
struct iio_dev *indio_dev;
+   struct adis *st;
+   int ret;
 
indio_dev = devm_iio_device_alloc(>dev, sizeof(*st));
if (!indio_dev)
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 6/9] Staging: iio: accel: adis16201: Use sign_extend32 function

2018-03-16 Thread Himanshu Jha
Use sign_extned32() for 32 bit sign extending rather than hard coding.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
v2:
   -no change in this patch.

 drivers/staging/iio/accel/adis16201.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/iio/accel/adis16201.c 
b/drivers/staging/iio/accel/adis16201.c
index 97150ea..298bf90 100644
--- a/drivers/staging/iio/accel/adis16201.c
+++ b/drivers/staging/iio/accel/adis16201.c
@@ -173,9 +173,8 @@ static int adis16201_read_raw(struct iio_dev *indio_dev,
ret = adis_read_reg_16(st, addr, );
if (ret)
return ret;
-   val16 &= (1 << bits) - 1;
-   val16 = (s16)(val16 << (16 - bits)) >> (16 - bits);
-   *val = val16;
+
+   *val = sign_extend32(val16, bits - 1);
return IIO_VAL_INT;
}
 
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 8/9] Staging: iio: accel: adis16201: Adjust argument to match open parentheses

2018-03-16 Thread Himanshu Jha
In adis16201_read_raw() adjust an argument to match an open parentheses
using tabs and spaces.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
v2:
   -aligned perfectly to match open parentheses.

 drivers/staging/iio/accel/adis16201.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/iio/accel/adis16201.c 
b/drivers/staging/iio/accel/adis16201.c
index 00e944e..e439cf7 100644
--- a/drivers/staging/iio/accel/adis16201.c
+++ b/drivers/staging/iio/accel/adis16201.c
@@ -115,7 +115,7 @@ static int adis16201_read_raw(struct iio_dev *indio_dev,
switch (mask) {
case IIO_CHAN_INFO_RAW:
return adis_single_conversion(indio_dev, chan,
-   ADIS16201_ERROR_ACTIVE, val);
+ ADIS16201_ERROR_ACTIVE, val);
case IIO_CHAN_INFO_SCALE:
switch (chan->type) {
case IIO_VOLTAGE:
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 5/9] Staging: iio: accel: adis16201: Add comments about units in read_raw()

2018-03-16 Thread Himanshu Jha
Clarify the conversion and formation of resultant data in the
adis16201_read_raw() with sufficient comments and remove the unnecessary
comments.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
v2:
   -clarify voltage base conversions.

 drivers/staging/iio/accel/adis16201.c | 27 ++-
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/iio/accel/adis16201.c 
b/drivers/staging/iio/accel/adis16201.c
index 8de3f27..97150ea 100644
--- a/drivers/staging/iio/accel/adis16201.c
+++ b/drivers/staging/iio/accel/adis16201.c
@@ -120,31 +120,43 @@ static int adis16201_read_raw(struct iio_dev *indio_dev,
switch (chan->type) {
case IIO_VOLTAGE:
if (chan->channel == 0) {
+   /* Voltage base units are mV hence 1.22 mV */
*val = 1;
-   *val2 = 22; /* 1.22 mV */
+   *val2 = 22;
} else {
+   /* Voltage base units are mV hence 0.61 mV */
*val = 0;
-   *val2 = 61; /* 0.610 mV */
+   *val2 = 61;
}
return IIO_VAL_INT_PLUS_MICRO;
case IIO_TEMP:
-   *val = -470; /* 0.47 C */
+   *val = -470;
*val2 = 0;
return IIO_VAL_INT_PLUS_MICRO;
case IIO_ACCEL:
+   /*
+* IIO base unit for sensitivity of accelerometer
+* is milli g.
+* 1 LSB represents 0.244 mg.
+*/
*val = 0;
-   *val2 = IIO_G_TO_M_S_2(462400); /* 0.4624 mg */
+   *val2 = IIO_G_TO_M_S_2(462400);
return IIO_VAL_INT_PLUS_NANO;
case IIO_INCLI:
*val = 0;
-   *val2 = 10; /* 0.1 degree */
+   *val2 = 10;
return IIO_VAL_INT_PLUS_MICRO;
default:
return -EINVAL;
}
break;
case IIO_CHAN_INFO_OFFSET:
-   *val = 25000 / -470 - 1278; /* 25 C = 1278 */
+   /*
+* The raw ADC value is 1278 when the temperature
+* is 25 degrees and the scale factor per milli
+* degree celcius is -470.
+*/
+   *val = 25000 / -470 - 1278;
return IIO_VAL_INT;
case IIO_CHAN_INFO_CALIBBIAS:
switch (chan->type) {
@@ -252,13 +264,11 @@ static int adis16201_probe(struct spi_device *spi)
struct adis *st;
struct iio_dev *indio_dev;
 
-   /* setup the industrialio driver allocated elements */
indio_dev = devm_iio_device_alloc(>dev, sizeof(*st));
if (!indio_dev)
return -ENOMEM;
 
st = iio_priv(indio_dev);
-   /* this is only used for removal purposes */
spi_set_drvdata(spi, indio_dev);
 
indio_dev->name = spi->dev.driver->name;
@@ -277,7 +287,6 @@ static int adis16201_probe(struct spi_device *spi)
if (ret)
return ret;
 
-   /* Get the device into a sane initial state */
ret = adis_initial_startup(st);
if (ret)
goto error_cleanup_buffer_trigger;
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 2/9] Staging: iio: accel: adis16201: Remove unnecessary comments

2018-03-16 Thread Himanshu Jha
Remove few unnecessary comments since the macro definitions clearly
justify their purpose.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
v2:
   -reodered patch series.

 drivers/staging/iio/accel/adis16201.c | 36 ---
 1 file changed, 36 deletions(-)

diff --git a/drivers/staging/iio/accel/adis16201.c 
b/drivers/staging/iio/accel/adis16201.c
index 767ebf0..6c06c0d 100644
--- a/drivers/staging/iio/accel/adis16201.c
+++ b/drivers/staging/iio/accel/adis16201.c
@@ -22,96 +22,66 @@
 
 #define ADIS16201_STARTUP_DELAY_MS 220
 
-/* Flash memory write count */
 #define ADIS16201_FLASH_CNT  0x00
 
-/* Output, power supply */
 #define ADIS16201_SUPPLY_OUT 0x02
 
-/* Output, x-axis accelerometer */
 #define ADIS16201_XACCL_OUT  0x04
 
-/* Output, y-axis accelerometer */
 #define ADIS16201_YACCL_OUT  0x06
 
-/* Output, auxiliary ADC input */
 #define ADIS16201_AUX_ADC0x08
 
-/* Output, temperature */
 #define ADIS16201_TEMP_OUT   0x0A
 
-/* Output, x-axis inclination */
 #define ADIS16201_XINCL_OUT  0x0C
 
-/* Output, y-axis inclination */
 #define ADIS16201_YINCL_OUT  0x0E
 
-/* Calibration, x-axis acceleration offset */
 #define ADIS16201_XACCL_OFFS 0x10
 
-/* Calibration, y-axis acceleration offset */
 #define ADIS16201_YACCL_OFFS 0x12
 
-/* x-axis acceleration scale factor */
 #define ADIS16201_XACCL_SCALE0x14
 
-/* y-axis acceleration scale factor */
 #define ADIS16201_YACCL_SCALE0x16
 
-/* Calibration, x-axis inclination offset */
 #define ADIS16201_XINCL_OFFS 0x18
 
-/* Calibration, y-axis inclination offset */
 #define ADIS16201_YINCL_OFFS 0x1A
 
-/* x-axis inclination scale factor */
 #define ADIS16201_XINCL_SCALE0x1C
 
-/* y-axis inclination scale factor */
 #define ADIS16201_YINCL_SCALE0x1E
 
-/* Alarm 1 amplitude threshold */
 #define ADIS16201_ALM_MAG1   0x20
 
-/* Alarm 2 amplitude threshold */
 #define ADIS16201_ALM_MAG2   0x22
 
-/* Alarm 1, sample period */
 #define ADIS16201_ALM_SMPL1  0x24
 
-/* Alarm 2, sample period */
 #define ADIS16201_ALM_SMPL2  0x26
 
-/* Alarm control */
 #define ADIS16201_ALM_CTRL   0x28
 
-/* Auxiliary DAC data */
 #define ADIS16201_AUX_DAC0x30
 
-/* General-purpose digital input/output control */
 #define ADIS16201_GPIO_CTRL  0x32
 
-/* Miscellaneous control */
 #define ADIS16201_MSC_CTRL   0x34
 
-/* Internal sample period (rate) control */
 #define ADIS16201_SMPL_PRD   0x36
 
 /* Operation, filter configuration */
 #define ADIS16201_AVG_CNT0x38
 
-/* Operation, sleep mode control */
 #define ADIS16201_SLP_CNT0x3A
 
-/* Diagnostics, system status register */
 #define ADIS16201_DIAG_STAT  0x3C
 
-/* Operation, system command register */
 #define ADIS16201_GLOB_CMD   0x3E
 
-/* MSC_CTRL */
 
-/* Self-test enable */
 #define ADIS16201_MSC_CTRL_SELF_TEST_ENBIT(8)
 
 /* Data-ready enable: 1 = enabled, 0 = disabled */
@@ -123,18 +93,13 @@
 /* Data-ready line selection: 1 = DIO1, 0 = DIO0 */
 #define ADIS16201_MSC_CTRL_DATA_RDY_DIO1   BIT(0)
 
-/* DIAG_STAT */
 
-/* Alarm 2 status: 1 = alarm active, 0 = alarm inactive */
 #define ADIS16201_DIAG_STAT_ALARM2BIT(9)
 
-/* Alarm 1 status: 1 = alarm active, 0 = alarm inactive */
 #define ADIS16201_DIAG_STAT_ALARM1BIT(8)
 
-/* SPI communications failure */
 #define ADIS16201_DIAG_STAT_SPI_FAIL_BIT   3
 
-/* Flash update failure */
 #define ADIS16201_DIAG_STAT_FLASH_UPT_FAIL_BIT  2
 
 /* Power supply above 3.625 V */
@@ -143,7 +108,6 @@
 /* Power supply below 3.15 V */
 #define ADIS16201_DIAG_STAT_POWER_LOW_BIT  0
 
-/* GLOB_CMD */
 
 #define ADIS16201_GLOB_CMD_SW_RESETBIT(7)
 #define ADIS16201_GLOB_CMD_FACTORY_RESET   BIT(1)
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 3/9] Staging: iio: accel: adis16201: Add _REG suffix to reisters

2018-03-16 Thread Himanshu Jha
Add a _REG suffix to distinguish between registers and the register bit
fileds.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
v2:
   -reordered patch series.

 drivers/staging/iio/accel/adis16201.c | 84 +--
 1 file changed, 42 insertions(+), 42 deletions(-)

diff --git a/drivers/staging/iio/accel/adis16201.c 
b/drivers/staging/iio/accel/adis16201.c
index 6c06c0d..0c63cd0 100644
--- a/drivers/staging/iio/accel/adis16201.c
+++ b/drivers/staging/iio/accel/adis16201.c
@@ -24,62 +24,62 @@
 
 #define ADIS16201_FLASH_CNT  0x00
 
-#define ADIS16201_SUPPLY_OUT 0x02
+#define ADIS16201_SUPPLY_OUT_REG 0x02
 
-#define ADIS16201_XACCL_OUT  0x04
+#define ADIS16201_XACCL_OUT_REG  0x04
 
-#define ADIS16201_YACCL_OUT  0x06
+#define ADIS16201_YACCL_OUT_REG  0x06
 
-#define ADIS16201_AUX_ADC0x08
+#define ADIS16201_AUX_ADC_REG0x08
 
-#define ADIS16201_TEMP_OUT   0x0A
+#define ADIS16201_TEMP_OUT_REG   0x0A
 
-#define ADIS16201_XINCL_OUT  0x0C
+#define ADIS16201_XINCL_OUT_REG  0x0C
 
-#define ADIS16201_YINCL_OUT  0x0E
+#define ADIS16201_YINCL_OUT_REG  0x0E
 
-#define ADIS16201_XACCL_OFFS 0x10
+#define ADIS16201_XACCL_OFFS_REG 0x10
 
-#define ADIS16201_YACCL_OFFS 0x12
+#define ADIS16201_YACCL_OFFS_REG 0x12
 
-#define ADIS16201_XACCL_SCALE0x14
+#define ADIS16201_XACCL_SCALE_REG0x14
 
-#define ADIS16201_YACCL_SCALE0x16
+#define ADIS16201_YACCL_SCALE_REG0x16
 
-#define ADIS16201_XINCL_OFFS 0x18
+#define ADIS16201_XINCL_OFFS_REG 0x18
 
-#define ADIS16201_YINCL_OFFS 0x1A
+#define ADIS16201_YINCL_OFFS_REG 0x1A
 
-#define ADIS16201_XINCL_SCALE0x1C
+#define ADIS16201_XINCL_SCALE_REG0x1C
 
-#define ADIS16201_YINCL_SCALE0x1E
+#define ADIS16201_YINCL_SCALE_REG0x1E
 
-#define ADIS16201_ALM_MAG1   0x20
+#define ADIS16201_ALM_MAG1_REG   0x20
 
-#define ADIS16201_ALM_MAG2   0x22
+#define ADIS16201_ALM_MAG2_REG   0x22
 
-#define ADIS16201_ALM_SMPL1  0x24
+#define ADIS16201_ALM_SMPL1_REG  0x24
 
-#define ADIS16201_ALM_SMPL2  0x26
+#define ADIS16201_ALM_SMPL2_REG  0x26
 
-#define ADIS16201_ALM_CTRL   0x28
+#define ADIS16201_ALM_CTRL_REG   0x28
 
-#define ADIS16201_AUX_DAC0x30
+#define ADIS16201_AUX_DAC_REG0x30
 
-#define ADIS16201_GPIO_CTRL  0x32
+#define ADIS16201_GPIO_CTRL_REG  0x32
 
-#define ADIS16201_MSC_CTRL   0x34
+#define ADIS16201_MSC_CTRL_REG   0x34
 
-#define ADIS16201_SMPL_PRD   0x36
+#define ADIS16201_SMPL_PRD_REG   0x36
 
 /* Operation, filter configuration */
-#define ADIS16201_AVG_CNT0x38
+#define ADIS16201_AVG_CNT_REG0x38
 
-#define ADIS16201_SLP_CNT0x3A
+#define ADIS16201_SLP_CNT_REG0x3A
 
-#define ADIS16201_DIAG_STAT  0x3C
+#define ADIS16201_DIAG_STAT_REG  0x3C
 
-#define ADIS16201_GLOB_CMD   0x3E
+#define ADIS16201_GLOB_CMD_REG   0x3E
 
 
 #define ADIS16201_MSC_CTRL_SELF_TEST_ENBIT(8)
@@ -125,10 +125,10 @@ enum adis16201_scan {
 };
 
 static const u8 adis16201_addresses[] = {
-   [ADIS16201_SCAN_ACC_X] = ADIS16201_XACCL_OFFS,
-   [ADIS16201_SCAN_ACC_Y] = ADIS16201_YACCL_OFFS,
-   [ADIS16201_SCAN_INCLI_X] = ADIS16201_XINCL_OFFS,
-   [ADIS16201_SCAN_INCLI_Y] = ADIS16201_YINCL_OFFS,
+   [ADIS16201_SCAN_ACC_X] = ADIS16201_XACCL_OFFS_REG,
+   [ADIS16201_SCAN_ACC_Y] = ADIS16201_YACCL_OFFS_REG,
+   [ADIS16201_SCAN_INCLI_X] = ADIS16201_XINCL_OFFS_REG,
+   [ADIS16201_SCAN_INCLI_Y] = ADIS16201_YINCL_OFFS_REG,
 };
 
 static int adis16201_read_raw(struct iio_dev *indio_dev,
@@ -232,16 +232,16 @@ static int adis16201_write_raw(struct iio_dev *indio_dev,
 }
 
 static const struct iio_chan_spec adis16201_channels[] = {
-   ADIS_SUPPLY_CHAN(ADIS16201_SUPPLY_OUT, ADIS16201_SCAN_SUPPLY, 0, 12),
-   ADIS_TEMP_CHAN(ADIS16201_TEMP_OUT, ADIS16201_SCAN_TEMP, 0, 12),
-   ADIS_ACCEL_CHAN(X, ADIS16201_XACCL_OUT, ADIS16201_SCAN_ACC_X,
+   ADIS_SUPPLY_CHAN(ADIS16201_SUPPLY_OUT_REG, ADIS16201_SCAN_SUPPLY, 0, 
12),
+   ADIS_TEMP_CHAN(ADIS16201_TEMP_OUT_REG, ADIS16201_SCAN_TEMP, 0, 12),
+   ADIS_ACCEL_CHAN(X, ADIS16201_XACCL_OUT_REG, ADIS16201_SCAN_ACC_X,
BIT(IIO_CHAN_INFO_CALIBBIAS), 0, 14),
-   ADIS_ACCEL_CHAN(Y, ADIS16201_YACCL_OUT, ADIS16201_SCAN_ACC_Y,
+   ADIS_ACCEL_CHAN(Y, ADIS16201_YACCL_OUT_REG, ADIS16201_SCAN_ACC_Y,
BIT(IIO_CHAN_INFO_CALIBBIAS), 0, 14),
-   ADIS_AUX_ADC_CHAN(ADIS16201_AUX_ADC, ADIS16201_SCAN_AUX_ADC, 0, 12),
-   ADIS_INCLI_CHAN(X, ADIS16201_XINCL_OUT, ADIS16201_SCAN_INCLI_X,
+   ADIS_AUX_ADC_CHAN(ADIS16201_AUX_ADC_REG, ADIS16201_SCAN_AUX_ADC, 0, 12),
+   ADIS_INCLI_CHAN(X, ADIS16201_XINCL_OUT_REG, ADIS16201_SCAN_INCLI_X,
BIT(IIO_CHAN_INFO_CALIBBIAS), 0, 14),
-   ADIS_INCLI_CHAN(X, ADIS16201_YINCL_OUT, ADIS16201_SCAN_INCLI_Y,
+   ADIS_INCLI_

[PATCH v2 0/9] Staging: iio: accel: adis16201 driver cleanup

2018-03-16 Thread Himanshu Jha
The following patch series cleans up miscellaneous code fragments and 
then the driver is moved from staging to mainline IIO subsytem directory.
Note that the last patch to move driver is *not* generated using '-M' flag,
which is used for detecting renames, since it may help reviewers to
suggest more cleanups/fix while pointing inline to the patch, the 
necessary changes. The framing of patch is made consistent with the
datasheet naming where possible.

For all the patches:
Suggested-by: Jonathan Cameron <ji...@kernel.org>
https://marc.info/?l=linux-iio=151775804702998=2

Himanshu Jha (9):
  Staging: iio: accel: adis16201: Rename few macro definitions
  Staging: iio: accel: adis16201: Remove unnecessary comments
  Staging: iio: accel: adis16201: Add _REG suffix to reisters
  Staging: iio: accel: adis16201: Group register definitions
  Staging: iio: accel: adis16201: Add comments about units in read_raw()
  Staging: iio: accel: adis16201: Use sign_extend32 function
  Staging: iio: accel: adis16201: Prefer reverse christmas tree ordering
  Staging: iio: accel: adis16201: Adjust argument to match open
parentheses
  Staging: iio: accel: adis16201: Move adis16201 driver out of staging

 drivers/iio/accel/Kconfig |  12 ++
 drivers/iio/accel/Makefile|   1 +
 drivers/iio/accel/adis16201.c | 327 +
 drivers/staging/iio/accel/Kconfig |  12 --
 drivers/staging/iio/accel/Makefile|   1 -
 drivers/staging/iio/accel/adis16201.c | 385 --
 6 files changed, 340 insertions(+), 398 deletions(-)
 create mode 100644 drivers/iio/accel/adis16201.c
 delete mode 100644 drivers/staging/iio/accel/adis16201.c

-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 1/9] Staging: iio: accel: adis16201: Rename few macro definitions

2018-03-16 Thread Himanshu Jha
Rename the macro definitions with suitable names specifying their
purpose.

* ADIS16201_STARTUP_DELAY_MS: Remove the comment specifying the delay in
  microseconds and rename it with addtition of _MS suffix.

* ADIS16201_MSC_CTRL_ACTIVE_DATA_RDY_HIGH: Rename the macro to make it
  similar to other misc control registers which denotes the data ready
  polarity.

* ADIS16201_DIAG_STAT_FLASH_UPT_FAIL_BIT: Rename to denote it is a
  failure bit.

* ADIS16201_GLOB_CMD_FACTORY_RESET: Remove ambiguous _CAL suffix and add
  _RESET suffix instead to denote factory reset command.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
v2:
   -explained every change in the process of renaming macros. 

 drivers/staging/iio/accel/adis16201.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/iio/accel/adis16201.c 
b/drivers/staging/iio/accel/adis16201.c
index 0fae8aa..767ebf0 100644
--- a/drivers/staging/iio/accel/adis16201.c
+++ b/drivers/staging/iio/accel/adis16201.c
@@ -20,7 +20,7 @@
 #include 
 #include 
 
-#define ADIS16201_STARTUP_DELAY220 /* ms */
+#define ADIS16201_STARTUP_DELAY_MS 220
 
 /* Flash memory write count */
 #define ADIS16201_FLASH_CNT  0x00
@@ -118,7 +118,7 @@
 #define ADIS16201_MSC_CTRL_DATA_RDY_EN BIT(2)
 
 /* Data-ready polarity: 1 = active high, 0 = active low */
-#define ADIS16201_MSC_CTRL_ACTIVE_HIGH BIT(1)
+#define ADIS16201_MSC_CTRL_ACTIVE_DATA_RDY_HIGHBIT(1)
 
 /* Data-ready line selection: 1 = DIO1, 0 = DIO0 */
 #define ADIS16201_MSC_CTRL_DATA_RDY_DIO1   BIT(0)
@@ -135,7 +135,7 @@
 #define ADIS16201_DIAG_STAT_SPI_FAIL_BIT   3
 
 /* Flash update failure */
-#define ADIS16201_DIAG_STAT_FLASH_UPT_BIT  2
+#define ADIS16201_DIAG_STAT_FLASH_UPT_FAIL_BIT  2
 
 /* Power supply above 3.625 V */
 #define ADIS16201_DIAG_STAT_POWER_HIGH_BIT 1
@@ -146,7 +146,7 @@
 /* GLOB_CMD */
 
 #define ADIS16201_GLOB_CMD_SW_RESETBIT(7)
-#define ADIS16201_GLOB_CMD_FACTORY_CAL BIT(1)
+#define ADIS16201_GLOB_CMD_FACTORY_RESET   BIT(1)
 
 #define ADIS16201_ERROR_ACTIVE  BIT(14)
 
@@ -290,7 +290,7 @@ static const struct iio_info adis16201_info = {
 
 static const char * const adis16201_status_error_msgs[] = {
[ADIS16201_DIAG_STAT_SPI_FAIL_BIT] = "SPI failure",
-   [ADIS16201_DIAG_STAT_FLASH_UPT_BIT] = "Flash update failed",
+   [ADIS16201_DIAG_STAT_FLASH_UPT_FAIL_BIT] = "Flash update failed",
[ADIS16201_DIAG_STAT_POWER_HIGH_BIT] = "Power supply above 3.625V",
[ADIS16201_DIAG_STAT_POWER_LOW_BIT] = "Power supply below 3.15V",
 };
@@ -303,11 +303,11 @@ static const struct adis_data adis16201_data = {
 
.self_test_mask = ADIS16201_MSC_CTRL_SELF_TEST_EN,
.self_test_no_autoclear = true,
-   .startup_delay = ADIS16201_STARTUP_DELAY,
+   .startup_delay = ADIS16201_STARTUP_DELAY_MS,
 
.status_error_msgs = adis16201_status_error_msgs,
.status_error_mask = BIT(ADIS16201_DIAG_STAT_SPI_FAIL_BIT) |
-   BIT(ADIS16201_DIAG_STAT_FLASH_UPT_BIT) |
+   BIT(ADIS16201_DIAG_STAT_FLASH_UPT_FAIL_BIT) |
BIT(ADIS16201_DIAG_STAT_POWER_HIGH_BIT) |
BIT(ADIS16201_DIAG_STAT_POWER_LOW_BIT),
 };
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v4] Staging: iio: adis16209: Change some macro names

2018-03-08 Thread Himanshu Jha
On Thu, Mar 08, 2018 at 11:46:17PM +0530, Shreeya Patel wrote:
> Make some of the macro names according to the names
> given in the datasheet of the adis16209 driver and
> have slight indentation in field definitions to make
> them clearly different from the register addresses.
> 
> Signed-off-by: Shreeya Patel <shreeya.patel23...@gmail.com>
> ---
> 
> Changes in v4
>   -Have slight indentation in field definitions.
> 
>  drivers/staging/iio/accel/adis16209.c | 48 
> +--
>  1 file changed, 24 insertions(+), 24 deletions(-)
> 
> diff --git a/drivers/staging/iio/accel/adis16209.c 
> b/drivers/staging/iio/accel/adis16209.c
> index eb5c878..19636e2 100644
> --- a/drivers/staging/iio/accel/adis16209.c
> +++ b/drivers/staging/iio/accel/adis16209.c
> @@ -68,21 +68,21 @@
>  #define  ADIS16209_MSC_CTRL_ACTIVE_HIGH  BIT(1)
>  #define  ADIS16209_MSC_CTRL_DATA_RDY_DIO2BIT(0)
>  
> -#define ADIS16209_STAT_REG   0x3C
> -#define  ADIS16209_STAT_ALARM2   BIT(9)
> -#define  ADIS16209_STAT_ALARM1   BIT(8)
> -#define ADIS16209_STAT_SELFTEST_FAIL_BIT 5
> -#define ADIS16209_STAT_SPI_FAIL_BIT  3
> -#define ADIS16209_STAT_FLASH_UPT_FAIL_BIT2
> +#define ADIS16209_DIAG_STAT_REG  0x3C
> +#define  ADIS16209_DIAG_STAT_ALARM2  BIT(9)
> +#define  ADIS16209_DIAG_STAT_ALARM1  BIT(8)
> +#define  ADIS16209_DIAG_STAT_SELFTEST_FAIL_BIT   5
> +#define  ADIS16209_DIAG_STAT_SPI_FAIL_BIT3
> +#define  ADIS16209_DIAG_STAT_FLASH_UPT_BIT   2

#define ADIS16209_STAT_FLASH_UPT_FAIL_BIT2
?
It represents flash update fail bit!

-- 
Thanks
Himanshu Jha
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 10/11] Staging: iio: accel: Add comments about units in data read function

2018-03-07 Thread Himanshu Jha
On Wed, Mar 07, 2018 at 08:50:30PM +, Jonathan Cameron wrote:
> On Mon,  5 Mar 2018 13:19:29 +0530
> Himanshu Jha <himanshujha199...@gmail.com> wrote:
> 
> > Clarify the conversion and formation of resultant data in the
> > adis16201_read_raw() with sufficient comments.
> > 
> > Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
> This is fine but it needs to be in the original comment changing patch
> rather than removing the comments first then a few patches later putting
> back a different version.
> 
> So good change but in the wrong place in the series.  Learning to reorder
> a series and merge down multiple patches into one is very useful when
> working with git.

I will send v2 with all the updates!

What about sign_extend32 & reverse christmas ordering patch ? Will you
pick that up or shall I send them again ?

-- 
Thanks
Himanshu Jha
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 03/11] Staging: iio: accel: Remove unnecessary comments

2018-03-06 Thread Himanshu Jha
Hi Shreeya,

> I was just going through your patch for giving myself 
> a habit of reading patches.

Great!

> I see here that there are many comments which are necessary
> have also been removed.
> Jonathan told that some of the names do not explain
> much about the how registers are related to the orientation.
> So it is necessary for some comments to be there here.
> 
> I saw your next patch too, in which you are changing some of the
> names for betterment, but again, that doesn't cover everything which
> was told by Jonathan.
> 
> Here is the link to the patch where Jonathan had given detailed 
> description
> 
> Just sharing this information so in case if Jonathan agrees with
> this then he will not have to explain it all again :)
> 
> https://lkml.org/lkml/2018/3/3/104

Well, the naming of macros is debatable as Jonathan pointed out[1] and
the unusual/odd naming pointed to you was for rotation registers

#define ADIS16209_ROT_OUT_REG   0x10

I renamed the unusual/odd naming macros for eg
#define ADIS16209_DIAG_STAT_FLASH_UPT_BIT

to

#define ADIS16201_DIAG_STAT_FLASH_UPT_FAIL_BIT

as it didn't look like a failure bit address for which I consulted Jonathan to 
which
he agreed. Also, *DIAG_STAT* seems like a good name since these status registers
are serving the purpose of diagnosing the device behavior. Again, GLOB_CMD 
stands
for Global Command register for controlling the deivce operation such as
Fatory Reset, Software Reset, etc.

See, it is difficult to point the perfect names than the suitable ones!
And let's just leave these *bikeshedding* ;-)

-- 
Thanks
Himanshu Jha
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 11/11] Staging: iio: accel: Move adis16201 driver out of staging subsystem

2018-03-04 Thread Himanshu Jha
Move the adis16201 driver out of staging directory and merge to the
mainline IIO subsystem.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/iio/accel/Kconfig |  12 ++
 drivers/iio/accel/Makefile|   1 +
 drivers/iio/accel/adis16201.c | 323 ++
 drivers/staging/iio/accel/Kconfig |  12 --
 drivers/staging/iio/accel/Makefile|   1 -
 drivers/staging/iio/accel/adis16201.c | 323 --
 6 files changed, 336 insertions(+), 336 deletions(-)
 create mode 100644 drivers/iio/accel/adis16201.c
 delete mode 100644 drivers/staging/iio/accel/adis16201.c

diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig
index c6d9517..9416c6f 100644
--- a/drivers/iio/accel/Kconfig
+++ b/drivers/iio/accel/Kconfig
@@ -5,6 +5,18 @@
 
 menu "Accelerometers"
 
+config ADIS16201
+tristate "Analog Devices ADIS16201 Dual-Axis Digital Inclinometer and 
Accelerometer"
+depends on SPI
+select IIO_ADIS_LIB
+select IIO_ADIS_LIB_BUFFER if IIO_BUFFER
+help
+  Say Y here to build support for Analog Devices adis16201 dual-axis
+  digital inclinometer and accelerometer.
+
+  To compile this driver as a module, say M here: the module will
+  be called adis16201.
+
 config ADXL345
tristate
 
diff --git a/drivers/iio/accel/Makefile b/drivers/iio/accel/Makefile
index 368aedb..7832ec9 100644
--- a/drivers/iio/accel/Makefile
+++ b/drivers/iio/accel/Makefile
@@ -4,6 +4,7 @@
 #
 
 # When adding new entries keep the list in alphabetical order
+obj-$(CONFIG_ADIS16201) += adis16201.o
 obj-$(CONFIG_ADXL345) += adxl345_core.o
 obj-$(CONFIG_ADXL345_I2C) += adxl345_i2c.o
 obj-$(CONFIG_ADXL345_SPI) += adxl345_spi.o
diff --git a/drivers/iio/accel/adis16201.c b/drivers/iio/accel/adis16201.c
new file mode 100644
index 000..946c7b1
--- /dev/null
+++ b/drivers/iio/accel/adis16201.c
@@ -0,0 +1,323 @@
+/*
+ * ADIS16201 Dual-Axis Digital Inclinometer and Accelerometer
+ *
+ * Copyright 2010 Analog Devices Inc.
+ *
+ * Licensed under the GPL-2 or later.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#define ADIS16201_STARTUP_DELAY_MS 220
+#define ADIS16201_FLASH_CNT0x00
+
+/* Data Output Register Information */
+#define ADIS16201_SUPPLY_OUT_REG   0x02
+#define ADIS16201_XACCL_OUT_REG0x04
+#define ADIS16201_YACCL_OUT_REG0x06
+#define ADIS16201_AUX_ADC_REG  0x08
+#define ADIS16201_TEMP_OUT_REG 0x0A
+#define ADIS16201_XINCL_OUT_REG0x0C
+#define ADIS16201_YINCL_OUT_REG0x0E
+
+/* Calibration Register Definition */
+#define ADIS16201_XACCL_OFFS_REG   0x10
+#define ADIS16201_YACCL_OFFS_REG   0x12
+#define ADIS16201_XACCL_SCALE_REG  0x14
+#define ADIS16201_YACCL_SCALE_REG  0x16
+#define ADIS16201_XINCL_OFFS_REG   0x18
+#define ADIS16201_YINCL_OFFS_REG   0x1A
+#define ADIS16201_XINCL_SCALE_REG  0x1C
+#define ADIS16201_YINCL_SCALE_REG  0x1E
+
+/* Alarm Register Definition */
+#define ADIS16201_ALM_MAG1_REG 0x20
+#define ADIS16201_ALM_MAG2_REG 0x22
+#define ADIS16201_ALM_SMPL1_REG0x24
+#define ADIS16201_ALM_SMPL2_REG0x26
+#define ADIS16201_ALM_CTRL_REG 0x28
+
+#define ADIS16201_AUX_DAC_REG  0x30
+#define ADIS16201_GPIO_CTRL_REG0x32
+#define ADIS16201_MSC_CTRL_REG 0x34
+#define ADIS16201_SMPL_PRD_REG 0x36
+#define ADIS16201_AVG_CNT_REG  0x38
+#define ADIS16201_SLP_CNT_REG  0x3A
+
+/* Miscellaneous Control Register Definition */
+#define ADIS16201_MSC_CTRL_REG 0x34
+#define  ADIS16201_MSC_CTRL_SELF_TEST_EN   BIT(8)
+#define  ADIS16201_MSC_CTRL_DATA_RDY_ENBIT(2)
+#define  ADIS16201_MSC_CTRL_ACTIVE_DATA_RDY_HIGH   BIT(1)
+#define  ADIS16201_MSC_CTRL_DATA_RDY_DIO1  BIT(0)
+
+/* Diagnostics, system status register */
+#define ADIS16201_DIAG_STAT_REG0x3C
+#define  ADIS16201_DIAG_STAT_ALARM2   

[PATCH 08/11] Staging: iio: accel: Use switch statement than if-else

2018-03-04 Thread Himanshu Jha
Use switch statement instead of if-else pair to explicitly match
the only two channels present.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/staging/iio/accel/adis16201.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/iio/accel/adis16201.c 
b/drivers/staging/iio/accel/adis16201.c
index 1737708..307d4ab 100644
--- a/drivers/staging/iio/accel/adis16201.c
+++ b/drivers/staging/iio/accel/adis16201.c
@@ -114,12 +114,15 @@ static int adis16201_read_raw(struct iio_dev *indio_dev,
case IIO_CHAN_INFO_SCALE:
switch (chan->type) {
case IIO_VOLTAGE:
-   if (chan->channel == 0) {
+   switch (chan->channel) {
+   case 0:
*val = 1;
*val2 = 22;
-   } else {
+   break;
+   case 1:
*val = 0;
*val2 = 61;
+   break;
}
return IIO_VAL_INT_PLUS_MICRO;
case IIO_TEMP:
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 10/11] Staging: iio: accel: Add comments about units in data read function

2018-03-04 Thread Himanshu Jha
Clarify the conversion and formation of resultant data in the
adis16201_read_raw() with sufficient comments.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/staging/iio/accel/adis16201.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/drivers/staging/iio/accel/adis16201.c 
b/drivers/staging/iio/accel/adis16201.c
index 8d795e2..946c7b1 100644
--- a/drivers/staging/iio/accel/adis16201.c
+++ b/drivers/staging/iio/accel/adis16201.c
@@ -130,6 +130,11 @@ static int adis16201_read_raw(struct iio_dev *indio_dev,
*val2 = 0;
return IIO_VAL_INT_PLUS_MICRO;
case IIO_ACCEL:
+  /*
+   * IIO base unit for sensitivity of accelerometer
+   * is milli g.
+   * 1 LSB represents 0.244 mg.
+   */
*val = 0;
*val2 = IIO_G_TO_M_S_2(462400);
return IIO_VAL_INT_PLUS_NANO;
@@ -142,6 +147,11 @@ static int adis16201_read_raw(struct iio_dev *indio_dev,
}
break;
case IIO_CHAN_INFO_OFFSET:
+  /*
+   * The raw ADC value is 0x4FE when the temperature
+   * is 25 degrees and the scale factor per milli
+   * degree celcius is -470.
+   */
*val = 25000 / -470 - 1278;
return IIO_VAL_INT;
case IIO_CHAN_INFO_CALIBBIAS:
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 09/11] Staging: iio: accel: Use sign_extend32 function

2018-03-04 Thread Himanshu Jha
Use sign_extned32() for 32 bit sign extending rather than hard coding the
same.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/staging/iio/accel/adis16201.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/iio/accel/adis16201.c 
b/drivers/staging/iio/accel/adis16201.c
index 307d4ab..8d795e2 100644
--- a/drivers/staging/iio/accel/adis16201.c
+++ b/drivers/staging/iio/accel/adis16201.c
@@ -159,9 +159,8 @@ static int adis16201_read_raw(struct iio_dev *indio_dev,
ret = adis_read_reg_16(st, addr, );
if (ret)
return ret;
-   val16 &= (1 << bits) - 1;
-   val16 = (s16)(val16 << (16 - bits)) >> (16 - bits);
-   *val = val16;
+
+   *val = sign_extend32(val16, bits - 1);
return IIO_VAL_INT;
}
 
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 06/11] Staging: iio: accel: Reverse christmas tree

2018-03-04 Thread Himanshu Jha
Prefer reverse christmas tree ordering of declarations to improve
readability.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/staging/iio/accel/adis16201.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/iio/accel/adis16201.c 
b/drivers/staging/iio/accel/adis16201.c
index 476b1c3..907fb85 100644
--- a/drivers/staging/iio/accel/adis16201.c
+++ b/drivers/staging/iio/accel/adis16201.c
@@ -243,9 +243,9 @@ static const struct adis_data adis16201_data = {
 
 static int adis16201_probe(struct spi_device *spi)
 {
-   int ret;
-   struct adis *st;
struct iio_dev *indio_dev;
+   struct adis *st;
+   int ret;
 
indio_dev = devm_iio_device_alloc(>dev, sizeof(*st));
if (!indio_dev)
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 07/11] Staging: iio: accel: Adjust arguments to match open parentheses

2018-03-04 Thread Himanshu Jha
In adis16201_read_raw() adjust an argument to match an open parentheses
using tabs.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/staging/iio/accel/adis16201.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/iio/accel/adis16201.c 
b/drivers/staging/iio/accel/adis16201.c
index 907fb85..1737708 100644
--- a/drivers/staging/iio/accel/adis16201.c
+++ b/drivers/staging/iio/accel/adis16201.c
@@ -110,7 +110,7 @@ static int adis16201_read_raw(struct iio_dev *indio_dev,
switch (mask) {
case IIO_CHAN_INFO_RAW:
return adis_single_conversion(indio_dev, chan,
-   ADIS16201_ERROR_ACTIVE, val);
+   ADIS16201_ERROR_ACTIVE, val);
case IIO_CHAN_INFO_SCALE:
switch (chan->type) {
case IIO_VOLTAGE:
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 05/11] Staging: iio: accel: Add _REG suffix to registers

2018-03-04 Thread Himanshu Jha
Addition of _REG suffix to the register definitions allows a distinction
between registers and register fields. The various registers and its field
bits are grouped together to improve readability and easy indentification.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/staging/iio/accel/adis16201.c | 133 --
 1 file changed, 61 insertions(+), 72 deletions(-)

diff --git a/drivers/staging/iio/accel/adis16201.c 
b/drivers/staging/iio/accel/adis16201.c
index 445cb56..476b1c3 100644
--- a/drivers/staging/iio/accel/adis16201.c
+++ b/drivers/staging/iio/accel/adis16201.c
@@ -20,75 +20,64 @@
 #include 
 #include 
 
-#define ADIS16201_STARTUP_DELAY_MS 220
-#define ADIS16201_FLASH_CNT0x00
+#define ADIS16201_STARTUP_DELAY_MS 220
+#define ADIS16201_FLASH_CNT0x00
 
 /* Data Output Register Information */
-#define ADIS16201_SUPPLY_OUT 0x02
-#define ADIS16201_XACCL_OUT  0x04
-#define ADIS16201_YACCL_OUT  0x06
-#define ADIS16201_AUX_ADC0x08
-#define ADIS16201_TEMP_OUT   0x0A
-#define ADIS16201_XINCL_OUT  0x0C
-#define ADIS16201_YINCL_OUT  0x0E
+#define ADIS16201_SUPPLY_OUT_REG   0x02
+#define ADIS16201_XACCL_OUT_REG0x04
+#define ADIS16201_YACCL_OUT_REG0x06
+#define ADIS16201_AUX_ADC_REG  0x08
+#define ADIS16201_TEMP_OUT_REG 0x0A
+#define ADIS16201_XINCL_OUT_REG0x0C
+#define ADIS16201_YINCL_OUT_REG0x0E
 
 /* Calibration Register Definition */
-#define ADIS16201_XACCL_OFFS 0x10
-#define ADIS16201_YACCL_OFFS 0x12
-#define ADIS16201_XACCL_SCALE0x14
-#define ADIS16201_YACCL_SCALE0x16
-#define ADIS16201_XINCL_OFFS 0x18
-#define ADIS16201_YINCL_OFFS 0x1A
-#define ADIS16201_XINCL_SCALE0x1C
-#define ADIS16201_YINCL_SCALE0x1E
+#define ADIS16201_XACCL_OFFS_REG   0x10
+#define ADIS16201_YACCL_OFFS_REG   0x12
+#define ADIS16201_XACCL_SCALE_REG  0x14
+#define ADIS16201_YACCL_SCALE_REG  0x16
+#define ADIS16201_XINCL_OFFS_REG   0x18
+#define ADIS16201_YINCL_OFFS_REG   0x1A
+#define ADIS16201_XINCL_SCALE_REG  0x1C
+#define ADIS16201_YINCL_SCALE_REG  0x1E
 
 /* Alarm Register Definition */
-#define ADIS16201_ALM_MAG1   0x20
-#define ADIS16201_ALM_MAG2   0x22
-#define ADIS16201_ALM_SMPL1  0x24
-#define ADIS16201_ALM_SMPL2  0x26
-#define ADIS16201_ALM_CTRL   0x28
-
-#define ADIS16201_AUX_DAC0x30
-#define ADIS16201_GPIO_CTRL  0x32
-#define ADIS16201_MSC_CTRL   0x34
-
-#define ADIS16201_SMPL_PRD   0x36
-#define ADIS16201_AVG_CNT0x38
-#define ADIS16201_SLP_CNT0x3A
+#define ADIS16201_ALM_MAG1_REG 0x20
+#define ADIS16201_ALM_MAG2_REG 0x22
+#define ADIS16201_ALM_SMPL1_REG0x24
+#define ADIS16201_ALM_SMPL2_REG0x26
+#define ADIS16201_ALM_CTRL_REG 0x28
+
+#define ADIS16201_AUX_DAC_REG  0x30
+#define ADIS16201_GPIO_CTRL_REG0x32
+#define ADIS16201_MSC_CTRL_REG 0x34
+#define ADIS16201_SMPL_PRD_REG 0x36
+#define ADIS16201_AVG_CNT_REG  0x38
+#define ADIS16201_SLP_CNT_REG  0x3A
+
+/* Miscellaneous Control Register Definition */
+#define ADIS16201_MSC_CTRL_REG 0x34
+#define  ADIS16201_MSC_CTRL_SELF_TEST_EN   BIT(8)
+#define  ADIS16201_MSC_CTRL_DATA_RDY_ENBIT(2)
+#define  ADIS16201_MSC_CTRL_ACTIVE_DATA_RDY_HIGH   BIT(1)
+#define  ADIS16201_MSC_CTRL_DATA_RDY_DIO1  BIT(0)
 
 /* Diagnostics, system status register */
-#define ADIS16201_DIAG_STAT  0x3C
+#define ADIS16201_DIAG_STAT_REG0x3C
+#define  ADIS16201_DIAG_STAT_ALARM2BIT(9)
+#define  ADIS16201_DIAG_STAT_ALARM1BIT(8)
+#define  ADIS16201_DIAG_STAT_SPI_FAIL_BIT  3
+#define  ADIS16201_DIAG_STAT_FLASH_UPT_FAIL_BIT2
+#define  ADIS16201_DIAG_STAT_POWER_HIGH_BIT1
+#define  ADIS16201_DIAG_STAT_POWER_LOW_BIT 0
 
 /* Operation, system command register */
-#define ADIS16201_GLOB_CMD   0x3E
-
-
-#

[PATCH 01/11] Staging: iio: accel: Prefer alphabetical sequence of header files

2018-03-04 Thread Himanshu Jha
Arrange header files in alphabetical sequence to improve readability.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/staging/iio/accel/adis16201.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/iio/accel/adis16201.c 
b/drivers/staging/iio/accel/adis16201.c
index 2ebd275..0f6a204 100644
--- a/drivers/staging/iio/accel/adis16201.c
+++ b/drivers/staging/iio/accel/adis16201.c
@@ -7,13 +7,13 @@
  */
 
 #include 
-#include 
 #include 
 #include 
-#include 
+#include 
+#include 
 #include 
+#include 
 #include 
-#include 
 
 #include 
 #include 
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 00/11] staging: iio: accel: adis16201 driver cleanup

2018-03-04 Thread Himanshu Jha
The following patch series cleans up miscellaneous code fragments and
then the driver is moved from staging to mainline IIO subsytem directory.
Note that the last patch to move driver is *not* generated using '-M' flag,
which is used for detecting renames, since it may help reviewers to
suggest more cleanups/fix while pointing inline to the patch, the
necessary changes. The framing of patch is made consistent with the datasheet
naming where possible.

For all the patches:
Suggested-by: Jonathan Cameron <ji...@kernel.org>
https://marc.info/?l=linux-iio=151775804702998=2

All the patches have been tested using 0-day test service with success.

Himanshu Jha (11):
  Staging: iio: accel: Prefer alphabetical sequence of header files
  Staging: iio: accel: Add a blank space before returns
  Staging: iio: accel: Remove unnecessary comments
  Staging: iio: accel: Rename few macro definitions
  Staging: iio: accel: Add _REG suffix to registers
  Staging: iio: accel: Reverse christmas tree
  Staging: iio: accel: Adjust arguments to match open parentheses
  Staging: iio: accel: Use switch statement than if-else
  Staging: iio: accel: Use sign_extend32 function
  Staging: iio: accel: Add comments about units in data read function
  Staging: iio: accel: Move adis16201 driver out of staging subsystem

 drivers/iio/accel/Kconfig |  12 ++
 drivers/iio/accel/Makefile|   1 +
 drivers/iio/accel/adis16201.c | 323 
 drivers/staging/iio/accel/Kconfig |  12 --
 drivers/staging/iio/accel/Makefile|   1 -
 drivers/staging/iio/accel/adis16201.c | 381 --
 6 files changed, 336 insertions(+), 394 deletions(-)
 create mode 100644 drivers/iio/accel/adis16201.c
 delete mode 100644 drivers/staging/iio/accel/adis16201.c

-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 04/11] Staging: iio: accel: Rename few macro definitions

2018-03-04 Thread Himanshu Jha
Rename few macros with appropriate names specifying their usage/function.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/staging/iio/accel/adis16201.c | 17 -
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/iio/accel/adis16201.c 
b/drivers/staging/iio/accel/adis16201.c
index 59c1166..445cb56 100644
--- a/drivers/staging/iio/accel/adis16201.c
+++ b/drivers/staging/iio/accel/adis16201.c
@@ -20,9 +20,8 @@
 #include 
 #include 
 
-#define ADIS16201_STARTUP_DELAY220
-
-#define ADIS16201_FLASH_CNT  0x00
+#define ADIS16201_STARTUP_DELAY_MS 220
+#define ADIS16201_FLASH_CNT0x00
 
 /* Data Output Register Information */
 #define ADIS16201_SUPPLY_OUT 0x02
@@ -69,7 +68,7 @@
 
 #define ADIS16201_MSC_CTRL_DATA_RDY_EN BIT(2)
 
-#define ADIS16201_MSC_CTRL_ACTIVE_HIGH BIT(1)
+#define ADIS16201_MSC_CTRL_ACTIVE_DATA_RDY_HIGHBIT(1)
 
 #define ADIS16201_MSC_CTRL_DATA_RDY_DIO1   BIT(0)
 
@@ -80,14 +79,14 @@
 
 #define ADIS16201_DIAG_STAT_SPI_FAIL_BIT   3
 
-#define ADIS16201_DIAG_STAT_FLASH_UPT_BIT  2
+#define ADIS16201_DIAG_STAT_FLASH_UPT_FAIL_BIT  2
 
 #define ADIS16201_DIAG_STAT_POWER_HIGH_BIT 1
 
 #define ADIS16201_DIAG_STAT_POWER_LOW_BIT  0
 
 #define ADIS16201_GLOB_CMD_SW_RESETBIT(7)
-#define ADIS16201_GLOB_CMD_FACTORY_CAL BIT(1)
+#define ADIS16201_GLOB_CMD_FACTORY BIT(1)
 
 #define ADIS16201_ERROR_ACTIVE  BIT(14)
 
@@ -231,7 +230,7 @@ static const struct iio_info adis16201_info = {
 
 static const char * const adis16201_status_error_msgs[] = {
[ADIS16201_DIAG_STAT_SPI_FAIL_BIT] = "SPI failure",
-   [ADIS16201_DIAG_STAT_FLASH_UPT_BIT] = "Flash update failed",
+   [ADIS16201_DIAG_STAT_FLASH_UPT_FAIL_BIT] = "Flash update failed",
[ADIS16201_DIAG_STAT_POWER_HIGH_BIT] = "Power supply above 3.625V",
[ADIS16201_DIAG_STAT_POWER_LOW_BIT] = "Power supply below 3.15V",
 };
@@ -244,11 +243,11 @@ static const struct adis_data adis16201_data = {
 
.self_test_mask = ADIS16201_MSC_CTRL_SELF_TEST_EN,
.self_test_no_autoclear = true,
-   .startup_delay = ADIS16201_STARTUP_DELAY,
+   .startup_delay = ADIS16201_STARTUP_DELAY_MS,
 
.status_error_msgs = adis16201_status_error_msgs,
.status_error_mask = BIT(ADIS16201_DIAG_STAT_SPI_FAIL_BIT) |
-   BIT(ADIS16201_DIAG_STAT_FLASH_UPT_BIT) |
+   BIT(ADIS16201_DIAG_STAT_FLASH_UPT_FAIL_BIT) |
BIT(ADIS16201_DIAG_STAT_POWER_HIGH_BIT) |
BIT(ADIS16201_DIAG_STAT_POWER_LOW_BIT),
 };
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 03/11] Staging: iio: accel: Remove unnecessary comments

2018-03-04 Thread Himanshu Jha
Remove unnecessary comments since the definitions are pretty clear
with their macro names.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/staging/iio/accel/adis16201.c | 82 +--
 1 file changed, 10 insertions(+), 72 deletions(-)

diff --git a/drivers/staging/iio/accel/adis16201.c 
b/drivers/staging/iio/accel/adis16201.c
index 0fae8aa..59c1166 100644
--- a/drivers/staging/iio/accel/adis16201.c
+++ b/drivers/staging/iio/accel/adis16201.c
@@ -20,87 +20,42 @@
 #include 
 #include 
 
-#define ADIS16201_STARTUP_DELAY220 /* ms */
+#define ADIS16201_STARTUP_DELAY220
 
-/* Flash memory write count */
 #define ADIS16201_FLASH_CNT  0x00
 
-/* Output, power supply */
+/* Data Output Register Information */
 #define ADIS16201_SUPPLY_OUT 0x02
-
-/* Output, x-axis accelerometer */
 #define ADIS16201_XACCL_OUT  0x04
-
-/* Output, y-axis accelerometer */
 #define ADIS16201_YACCL_OUT  0x06
-
-/* Output, auxiliary ADC input */
 #define ADIS16201_AUX_ADC0x08
-
-/* Output, temperature */
 #define ADIS16201_TEMP_OUT   0x0A
-
-/* Output, x-axis inclination */
 #define ADIS16201_XINCL_OUT  0x0C
-
-/* Output, y-axis inclination */
 #define ADIS16201_YINCL_OUT  0x0E
 
-/* Calibration, x-axis acceleration offset */
+/* Calibration Register Definition */
 #define ADIS16201_XACCL_OFFS 0x10
-
-/* Calibration, y-axis acceleration offset */
 #define ADIS16201_YACCL_OFFS 0x12
-
-/* x-axis acceleration scale factor */
 #define ADIS16201_XACCL_SCALE0x14
-
-/* y-axis acceleration scale factor */
 #define ADIS16201_YACCL_SCALE0x16
-
-/* Calibration, x-axis inclination offset */
 #define ADIS16201_XINCL_OFFS 0x18
-
-/* Calibration, y-axis inclination offset */
 #define ADIS16201_YINCL_OFFS 0x1A
-
-/* x-axis inclination scale factor */
 #define ADIS16201_XINCL_SCALE0x1C
-
-/* y-axis inclination scale factor */
 #define ADIS16201_YINCL_SCALE0x1E
 
-/* Alarm 1 amplitude threshold */
+/* Alarm Register Definition */
 #define ADIS16201_ALM_MAG1   0x20
-
-/* Alarm 2 amplitude threshold */
 #define ADIS16201_ALM_MAG2   0x22
-
-/* Alarm 1, sample period */
 #define ADIS16201_ALM_SMPL1  0x24
-
-/* Alarm 2, sample period */
 #define ADIS16201_ALM_SMPL2  0x26
-
-/* Alarm control */
 #define ADIS16201_ALM_CTRL   0x28
 
-/* Auxiliary DAC data */
 #define ADIS16201_AUX_DAC0x30
-
-/* General-purpose digital input/output control */
 #define ADIS16201_GPIO_CTRL  0x32
-
-/* Miscellaneous control */
 #define ADIS16201_MSC_CTRL   0x34
 
-/* Internal sample period (rate) control */
 #define ADIS16201_SMPL_PRD   0x36
-
-/* Operation, filter configuration */
 #define ADIS16201_AVG_CNT0x38
-
-/* Operation, sleep mode control */
 #define ADIS16201_SLP_CNT0x3A
 
 /* Diagnostics, system status register */
@@ -109,42 +64,28 @@
 /* Operation, system command register */
 #define ADIS16201_GLOB_CMD   0x3E
 
-/* MSC_CTRL */
 
-/* Self-test enable */
 #define ADIS16201_MSC_CTRL_SELF_TEST_ENBIT(8)
 
-/* Data-ready enable: 1 = enabled, 0 = disabled */
 #define ADIS16201_MSC_CTRL_DATA_RDY_EN BIT(2)
 
-/* Data-ready polarity: 1 = active high, 0 = active low */
 #define ADIS16201_MSC_CTRL_ACTIVE_HIGH BIT(1)
 
-/* Data-ready line selection: 1 = DIO1, 0 = DIO0 */
 #define ADIS16201_MSC_CTRL_DATA_RDY_DIO1   BIT(0)
 
-/* DIAG_STAT */
 
-/* Alarm 2 status: 1 = alarm active, 0 = alarm inactive */
 #define ADIS16201_DIAG_STAT_ALARM2BIT(9)
 
-/* Alarm 1 status: 1 = alarm active, 0 = alarm inactive */
 #define ADIS16201_DIAG_STAT_ALARM1BIT(8)
 
-/* SPI communications failure */
 #define ADIS16201_DIAG_STAT_SPI_FAIL_BIT   3
 
-/* Flash update failure */
 #define ADIS16201_DIAG_STAT_FLASH_UPT_BIT  2
 
-/* Power supply above 3.625 V */
 #define ADIS16201_DIAG_STAT_POWER_HIGH_BIT 1
 
-/* Power supply below 3.15 V */
 #define ADIS16201_DIAG_STAT_POWER_LOW_BIT  0
 
-/* GLOB_CMD */
-
 #define ADIS16201_GLOB_CMD_SW_RESETBIT(7)
 #define ADIS16201_GLOB_CMD_FACTORY_CAL BIT(1)
 
@@ -187,30 +128,30 @@ static int adis16201_read_raw(struct iio_dev *indio_dev,
case IIO_VOLTAGE:
if (chan->channel == 0) {
*val = 1;
-   *val2 = 22; /* 1.22 mV */
+   *val2 = 22;
} else {
*val = 0;
-   *val2 = 61; /* 0.610 mV */
+   *val2 = 61;
}
return IIO_VAL_INT_PLUS_MICRO;
case IIO_TEMP:
-   *val = -470; /* 0.47 C */
+   *val = -470;
*val2 = 0;
return IIO_VAL_INT_PLUS_MICRO;
case IIO_ACCEL:
   

[PATCH 02/11] Staging: iio: accel: Add a blank space before returns

2018-03-04 Thread Himanshu Jha
Adding a blank space before/after some returns improves readability.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/staging/iio/accel/adis16201.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/staging/iio/accel/adis16201.c 
b/drivers/staging/iio/accel/adis16201.c
index 0f6a204..0fae8aa 100644
--- a/drivers/staging/iio/accel/adis16201.c
+++ b/drivers/staging/iio/accel/adis16201.c
@@ -232,6 +232,7 @@ static int adis16201_read_raw(struct iio_dev *indio_dev,
*val = val16;
return IIO_VAL_INT;
}
+
return -EINVAL;
 }
 
@@ -262,6 +263,7 @@ static int adis16201_write_raw(struct iio_dev *indio_dev,
addr = adis16201_addresses[chan->scan_index];
return adis_write_reg_16(st, addr, val16);
}
+
return -EINVAL;
 }
 
@@ -336,6 +338,7 @@ static int adis16201_probe(struct spi_device *spi)
ret = adis_init(st, indio_dev, spi, _data);
if (ret)
return ret;
+
ret = adis_setup_buffer_and_trigger(st, indio_dev, NULL);
if (ret)
return ret;
@@ -348,6 +351,7 @@ static int adis16201_probe(struct spi_device *spi)
ret = iio_device_register(indio_dev);
if (ret < 0)
goto error_cleanup_buffer_trigger;
+
return 0;
 
 error_cleanup_buffer_trigger:
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v3 1/4] Staging: iio: adis16209: Remove and add some comments and group the definitions

2018-03-04 Thread Himanshu Jha
C_CTRL_ACTIVE_HIGH   BIT(1)
> +#define  ADIS16209_MSC_CTRL_ACTIVE_HIGH  BIT(1)
> +#define  ADIS16209_MSC_CTRL_DATA_RDY_DIO2BIT(0)
>  
> -/* Data-ready line selection: 1 = DIO2, 0 = DIO1 */
> -#define ADIS16209_MSC_CTRL_DATA_RDY_DIO2 BIT(0)
> -
> -/* DIAG_STAT */
> -
> -/* Alarm 2 status: 1 = alarm active, 0 = alarm inactive */
> -#define ADIS16209_DIAG_STAT_ALARM2BIT(9)
> -
> -/* Alarm 1 status: 1 = alarm active, 0 = alarm inactive */
> -#define ADIS16209_DIAG_STAT_ALARM1BIT(8)
> -
> -/* Self-test diagnostic error flag: 1 = error condition, 0 = normal 
> operation */
> +#define ADIS16209_DIAG_STAT_REG  0x3C
> +#define  ADIS16209_DIAG_STAT_ALARM2  BIT(9)
> +#define  ADIS16209_DIAG_STAT_ALARM1  BIT(8)
>  #define ADIS16209_DIAG_STAT_SELFTEST_FAIL_BIT5
> -
> -/* SPI communications failure */
>  #define ADIS16209_DIAG_STAT_SPI_FAIL_BIT 3
> -
> -/* Flash update failure */
>  #define ADIS16209_DIAG_STAT_FLASH_UPT_BIT2
> -
>  /* Power supply above 3.625 V */
>  #define ADIS16209_DIAG_STAT_POWER_HIGH_BIT   1
> -
>  /* Power supply below 3.15 V */
>  #define ADIS16209_DIAG_STAT_POWER_LOW_BIT0
>  
> -/* GLOB_CMD */
> -
> -#define ADIS16209_GLOB_CMD_SW_RESET  BIT(7)
> -#define ADIS16209_GLOB_CMD_CLEAR_STATBIT(4)
> -#define ADIS16209_GLOB_CMD_FACTORY_CAL   BIT(1)
> +#define ADIS16209_GLOB_CMD_REG   0x3E
> +#define  ADIS16209_GLOB_CMD_SW_RESET BIT(7)
> +#define  ADIS16209_GLOB_CMD_CLEAR_STAT   BIT(4)
> +#define  ADIS16209_GLOB_CMD_FACTORY_CAL  BIT(1)
>  
> -#define ADIS16209_ERROR_ACTIVE  BIT(14)
> +#define ADIS16209_ERROR_ACTIVE   BIT(14)
>  
>  enum adis16209_scan {
>   ADIS16209_SCAN_SUPPLY,
> @@ -226,24 +161,38 @@ static int adis16209_read_raw(struct iio_dev *indio_dev,
>   *val2 = 610500; /* 0.6105 mV */
>   return IIO_VAL_INT_PLUS_MICRO;
>   case IIO_TEMP:
> - *val = -470; /* -0.47 C */
> + *val = -470;
>   *val2 = 0;
>   return IIO_VAL_INT_PLUS_MICRO;
>   case IIO_ACCEL:
> + /*
> +  * IIO base unit for sensitivity of accelerometer
> +  * is milli g.
> +  * 1 LSB represents 0.244 mg.
> +  */
>   *val = 0;
> - *val2 = IIO_G_TO_M_S_2(244140); /* 0.244140 mg */
> + *val2 = IIO_G_TO_M_S_2(244140);
>   return IIO_VAL_INT_PLUS_NANO;
>   case IIO_INCLI:
>   case IIO_ROT:
> + /*
> +  * IIO base units for rotation are degrees.
> +  * 1 LSB represents 0.025 milli degrees.
> +  */
>   *val = 0;
> - *val2 = 25000; /* 0.025 degree */
> + *val2 = 25000;
>   return IIO_VAL_INT_PLUS_MICRO;
>   default:
>   return -EINVAL;
>   }
>   break;
>   case IIO_CHAN_INFO_OFFSET:
> - *val = 25000 / -470 - 0x4FE; /* 25 C = 0x4FE */
> + /*
> +  * The raw ADC value is 0x4FE when the temperature
> +  * is 45 degrees and the scale factor per milli
> +  * degree celcius is -470.

Are you sure it is *45 degrees* and not *25 degrees* instead ?

As I can clearly see from the datasheet :

"sensitivity = −0.47°/LSB, 25°C = 1278 LSB = 0x04FE"

Please check it :)

I found this because I'm also doing a similar cleanup for adis16201.

-- 
Thanks
Himanshu Jha
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 1/3] Staging: iio: adis16209: Use SPDX identifier

2018-02-18 Thread Himanshu Jha
Hi Shreeya,

On Sat, Feb 17, 2018 at 09:34:56PM +0530, Shreeya Patel wrote:
> Use SPDX identifier format instead of GPLv2. Also rearrange the
> headers in alphabetical order.
> 
> Signed-off-by: Shreeya Patel <shreeya.patel23...@gmail.com>
> ---
>  drivers/staging/iio/accel/adis16209.c | 7 +++
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/staging/iio/accel/adis16209.c 
> b/drivers/staging/iio/accel/adis16209.c
> index 7fcef9a..e3d9f80 100644
> --- a/drivers/staging/iio/accel/adis16209.c
> +++ b/drivers/staging/iio/accel/adis16209.c
> @@ -1,19 +1,18 @@
> +// SPDX-License-Identifier: GPL-2.0+
>  /*
>   * ADIS16209 Dual-Axis Digital Inclinometer and Accelerometer
>   *
>   * Copyright 2010 Analog Devices Inc.
> - *
> - * Licensed under the GPL-2 or later.

I see that you too are doing similar cleanup which I did a while ago
https://lkml.org/lkml/2018/2/12/255
where I got some update suggestions for the patch series. It would be
great if you could update this patch series consistent with the
reviewers.

For eg: in this patch you changed 

+// SPDX-License-Identifier: GPL-2.0+

and therefore

MODULE_LICENSE("GPL v2");

should also be changed to 

MODULE_LICENSE("GPL"); 

as explained by Philippe Ombredanne to me in my patch series.

I am not sure if you're subscribed to the IIO mailing list but you can find
all the update suggestions from the above link. :)

-- 
Thanks
Himanshu Jha
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 2/4] staging: iio: accel: Remove unnecessary comments and add suitable suffix

2018-02-12 Thread Himanshu Jha
On Mon, Feb 12, 2018 at 05:57:31PM +0300, Dan Carpenter wrote:
> On Mon, Feb 12, 2018 at 08:05:22PM +0530, Himanshu Jha wrote:
> > But these should be done when we have *more* instances.
> > 
> > For eg: 
> > I added a tab space in function static int adis16201_read_raw() argument
> > to match open parentheses in this patch. But I also added tabs while
> > removing and adding suitable suffix to the macros. So, should it also be
> > done in a separate patch ?
> 
> If you're changing a line of code and you fix a white space issue on
> that same line, then that's fine.  If it's just in the same function,
> then do it in a separate patch.  In other words, adding tabs when you're
> moving around macros is fine, but adding it to the arguments is
> unrelated.

I will try and divide my patches next time :)

> This patch was honestly pretty tricky to review.

I am sorry for that. Might be easy for IIO reviewers ;)

> Jonathan assumes reviewers have the datasheet in front of them and I
> assume that that they don't.  He's probably right...  But especially
> comments like this:
> 
>   *val2 = 22; /* 1.22 mV */

They are pretty obvious as you can see from the return statements
just below that which is :

return IIO_VAL_INT_PLUS_MICRO;

These comments are obvious because we know 'val1' will be responsible
for Integer part(1.0) and 'val2' for the Micro part(22 * 10^-6 = 0.22).
Isn't it ?

Although I am new to IIO please correct if I'm wrong.

-- 
Thanks
Himanshu Jha
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 4/4] staging: iio: accel: Move adis16201 driver out of staging

2018-02-12 Thread Himanshu Jha
On Mon, Feb 12, 2018 at 04:18:26PM +0300, Dan Carpenter wrote:
> I think -M is prefered for these types of diffs?  Not sure.

I wrote about that in the cover letter if you missed. :)

> On Mon, Feb 12, 2018 at 05:24:59PM +0530, Himanshu Jha wrote:
> > +static int adis16201_probe(struct spi_device *spi)
> > +{
> > +   struct iio_dev *indio_dev;
> > +   struct adis *st;
> > +   int ret;
> > +
> > +   indio_dev = devm_iio_device_alloc(>dev, sizeof(*st));
> > +   if (!indio_dev)
> > +   return -ENOMEM;
> > +
> > +   st = iio_priv(indio_dev);
> > +   spi_set_drvdata(spi, indio_dev);
> > +
> > +   indio_dev->name = spi->dev.driver->name;
> > +   indio_dev->dev.parent = >dev;
> > +   indio_dev->info = _info;
> > +
> > +   indio_dev->channels = adis16201_channels;
> > +   indio_dev->num_channels = ARRAY_SIZE(adis16201_channels);
> > +   indio_dev->modes = INDIO_DIRECT_MODE;
> > +
> > +   ret = adis_init(st, indio_dev, spi, _data);
> > +   if (ret)
> > +   return ret;
> > +
> > +   ret = adis_setup_buffer_and_trigger(st, indio_dev, NULL);
> > +   if (ret)
> > +   return ret;
> 
> We should clean up the IRQ which we enabled in adis_init() instead of
> returning directly.

I'm not sure about how to do that.

-- 
Thanks
Himanshu Jha
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 4/4] staging: iio: accel: Move adis16201 driver out of staging

2018-02-12 Thread Himanshu Jha
On Mon, Feb 12, 2018 at 03:10:56PM +0100, Philippe Ombredanne wrote:
> On Mon, Feb 12, 2018 at 12:54 PM, Himanshu Jha
> <himanshujha199...@gmail.com> wrote:
> > Move the adis16201 driver out of staging directory and merge to the
> > mainline IIO directory.
> >
> > Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
> 
> 
> > --- /dev/null
> > +++ b/drivers/iio/accel/adis16201.c
> > @@ -0,0 +1,315 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> 
> 
> 
> > +MODULE_AUTHOR("Barry Song <21cn...@gmail.com>");
> > +MODULE_DESCRIPTION("Analog Devices ADIS16201 Dual-Axis Digital 
> > Inclinometer and Accelerometer");
> > +MODULE_LICENSE("GPL v2");
> > +MODULE_ALIAS("spi:adis16201");
> 
> Your MODULE_LICENSE does not match your SPDX license id.
> MODULE_LICENSE("GPL v2"); means SPDX GPL-2.0
> MODULE_LICENSE("GPL"); means SPDX GPL-2.0+
> 

I didn't knew about that! Thanks for pointing.

-- 
Thanks
Himanshu Jha
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 2/4] staging: iio: accel: Remove unnecessary comments and add suitable suffix

2018-02-12 Thread Himanshu Jha
Hi Dan,

On Mon, Feb 12, 2018 at 03:53:12PM +0300, Dan Carpenter wrote:
> On Mon, Feb 12, 2018 at 05:24:57PM +0530, Himanshu Jha wrote:
> > Remove some unnecessary comments by giving appropriate name to macros.
> > Therefore, add _REG suffix for control registers. Also, align function
> > arguments to match open parentheses using tabs.
> > Group the control register and register field macros together.
> > 
> > Blank line before some returns improves code readability.
> > 
> > Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
> 
> The most obvious response is that this needs to be broken up into
> multiple patches.
> 
> I think I liked almost all the comments...

Please note that all the changes are suggested by Joanathan in his TODO
https://marc.info/?l=linux-iio=151775804702998=2
I think it far more commenting as compared to other drivers in the
mainline IIO drivers. I grouped all the relevant control registers
together at one place with suitable comment.
For eg:

+/* Data Output Register Definitions */

The macro names are identical to the names in the datasheet if you can
look and one could easily refer to the datasheet easily. Also, I
grouped the control registers and their fields together make it more readable.
For eg:

+#define ADIS16201_MSC_CTRL_REG 0x34
+#define ADIS16201_MSC_CTRL_SELF_TEST_ENBIT(8)
+#define ADIS16201_MSC_CTRL_DATA_RDY_EN BIT(2)


> > -/* Output, power supply */
> > -#define ADIS16201_SUPPLY_OUT 0x02
> > +#define ADIS16201_SUPPLY_OUT_REG   0x02
> 
> To me it seems useful to know that we're talking about the power supply.

For that purpose I already grouped data output register definitions.

> Adding _REG to the name seems not terribly useful and it makes the name
> longer so we're going to run into the 80 character limit.  I just
> checked and this patch does add some checkpatch warnings.

_REG prefix is used to differentiate between registers addresses and the
fields in the register as pointed in the above MSC_CTRL_REG and
MSC_CTRL_SELF_TEST_EN.

Yes by doing this it triggered 2 I think 80 character warning. For eg:

ADIS_SUPPLY_CHAN(ADIS16201_SUPPLY_OUT_REG, ADIS16201_SCAN_SUPPLY, 0, 
12),

But you know with 81 characters so I neglected it because it looked more
readable without breaking into lines IMHO.

> But aligning the arguments is fine, deleting unused macros is fine,
> adding blank lines is fine.
> 
> >  static int adis16201_probe(struct spi_device *spi)
> >  {
> > -   int ret;
> > -   struct adis *st;
> > struct iio_dev *indio_dev;
> > +   struct adis *st;
> > +   int ret;
> 
> Making this reverse Christmas tree is fine.  But these things should all
> be done in separate patches.

I am sometimes confused in dividing the patches. As per your advice I
should make separate patch for :

1. remove unnecessary comments.
2. add suitable suffix.
3. add tabs instead of space.
4. reverse christmas tree.

But these should be done when we have *more* instances.

For eg: 
I added a tab space in function static int adis16201_read_raw() argument
to match open parentheses in this patch. But I also added tabs while
removing and adding suitable suffix to the macros. So, should it also be
done in a separate patch ? Since there was only one instance of adding tabs
therefore I did it here without framing another patch for that purpose
while saving my time to plan 'what to include/exclude in the patch ?'

Also, given the above queries I was clueless as what to do first! Since
sometimes it happens that the patch series doesn't apply cleanly because
of incorrect ordering for framing the patches.

Thanks for taking your time to review the patch series.

-- 
Thanks
Himanshu Jha
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 2/4] staging: iio: accel: Remove unnecessary comments and add suitable suffix

2018-02-12 Thread Himanshu Jha
Remove some unnecessary comments by giving appropriate name to macros.
Therefore, add _REG suffix for control registers. Also, align function
arguments to match open parentheses using tabs.
Group the control register and register field macros together.

Blank line before some returns improves code readability.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/staging/iio/accel/adis16201.c | 226 --
 1 file changed, 79 insertions(+), 147 deletions(-)

diff --git a/drivers/staging/iio/accel/adis16201.c 
b/drivers/staging/iio/accel/adis16201.c
index b2145c9..011d2c5 100644
--- a/drivers/staging/iio/accel/adis16201.c
+++ b/drivers/staging/iio/accel/adis16201.c
@@ -19,135 +19,63 @@
 #include 
 #include 
 
-#define ADIS16201_STARTUP_DELAY220 /* ms */
-
-/* Flash memory write count */
-#define ADIS16201_FLASH_CNT  0x00
-
-/* Output, power supply */
-#define ADIS16201_SUPPLY_OUT 0x02
-
-/* Output, x-axis accelerometer */
-#define ADIS16201_XACCL_OUT  0x04
-
-/* Output, y-axis accelerometer */
-#define ADIS16201_YACCL_OUT  0x06
-
-/* Output, auxiliary ADC input */
-#define ADIS16201_AUX_ADC0x08
-
-/* Output, temperature */
-#define ADIS16201_TEMP_OUT   0x0A
-
-/* Output, x-axis inclination */
-#define ADIS16201_XINCL_OUT  0x0C
-
-/* Output, y-axis inclination */
-#define ADIS16201_YINCL_OUT  0x0E
-
-/* Calibration, x-axis acceleration offset */
-#define ADIS16201_XACCL_OFFS 0x10
-
-/* Calibration, y-axis acceleration offset */
-#define ADIS16201_YACCL_OFFS 0x12
-
-/* x-axis acceleration scale factor */
-#define ADIS16201_XACCL_SCALE0x14
-
-/* y-axis acceleration scale factor */
-#define ADIS16201_YACCL_SCALE0x16
-
-/* Calibration, x-axis inclination offset */
-#define ADIS16201_XINCL_OFFS 0x18
-
-/* Calibration, y-axis inclination offset */
-#define ADIS16201_YINCL_OFFS 0x1A
-
-/* x-axis inclination scale factor */
-#define ADIS16201_XINCL_SCALE0x1C
-
-/* y-axis inclination scale factor */
-#define ADIS16201_YINCL_SCALE0x1E
-
-/* Alarm 1 amplitude threshold */
-#define ADIS16201_ALM_MAG1   0x20
-
-/* Alarm 2 amplitude threshold */
-#define ADIS16201_ALM_MAG2   0x22
-
-/* Alarm 1, sample period */
-#define ADIS16201_ALM_SMPL1  0x24
-
-/* Alarm 2, sample period */
-#define ADIS16201_ALM_SMPL2  0x26
-
-/* Alarm control */
-#define ADIS16201_ALM_CTRL   0x28
-
-/* Auxiliary DAC data */
-#define ADIS16201_AUX_DAC0x30
-
-/* General-purpose digital input/output control */
-#define ADIS16201_GPIO_CTRL  0x32
-
-/* Miscellaneous control */
-#define ADIS16201_MSC_CTRL   0x34
-
-/* Internal sample period (rate) control */
-#define ADIS16201_SMPL_PRD   0x36
-
-/* Operation, filter configuration */
-#define ADIS16201_AVG_CNT0x38
-
-/* Operation, sleep mode control */
-#define ADIS16201_SLP_CNT0x3A
-
-/* Diagnostics, system status register */
-#define ADIS16201_DIAG_STAT  0x3C
-
-/* Operation, system command register */
-#define ADIS16201_GLOB_CMD   0x3E
+#define ADIS16201_STARTUP_DELAY_MS 220
+#define ADIS16201_FLASH_CNT_REG0x00
+
+/* Data Output Register Definitions */
+#define ADIS16201_SUPPLY_OUT_REG   0x02
+#define ADIS16201_XACCL_OUT_REG0x04
+#define ADIS16201_YACCL_OUT_REG0x06
+#define ADIS16201_AUX_ADC_REG  0x08
+#define ADIS16201_TEMP_OUT_REG 0x0A
+#define ADIS16201_XINCL_OUT_REG0x0C
+#define ADIS16201_YINCL_OUT_REG0x0E
+
+/* Calibration Register Definitions */
+#define ADIS16201_XACCL_OFFS_REG   0x10
+#define ADIS16201_YACCL_OFFS_REG   0x12
+#define ADIS16201_XACCL_SCALE_REG  0x14
+#define ADIS16201_YACCL_SCALE_REG  0x16
+#define ADIS16201_XINCL_OFFS_REG   0x18
+#define ADIS16201_YINCL_OFFS_REG   0x1A
+#define ADIS16201_XINCL_SCALE_REG  0x1C
+#define ADIS16201_YINCL_SCALE_REG  0x1E
+
+/* Alarm Register Definitions */
+#define ADIS16201_ALM_MAG1_REG 0x20
+#define ADIS16201_ALM_MAG2_REG 0x22
+#define ADIS16201_ALM_SMPL1_REG0x24
+#define ADIS16201_ALM_SMPL2_REG0x26
+#define ADIS16201_ALM_CTRL_REG 0x28
+
+#define ADIS16201_AUX_DAC_REG  0x30
+#define ADIS16201_GPIO_CTRL_REG0x32
+#define ADIS16201_SMPL_PRD_REG 0x36
+#define ADIS16201_AVG_CNT_REG  0x38
+#define ADIS16201_SLP_CNT_REG  0x3A
 
 /* MSC_CTRL */
-
-/* Self-test enable */
-#define ADIS16201_MSC_CTRL_SELF_TEST_ENBIT(8)
-
-/* Data-ready enable: 1 = enabled, 0 = disabled */
-#define ADIS16201_MSC_CTRL_DATA_RDY_EN BIT(2)
-
-/* Data-ready polarity: 1 = active high, 0 = active low */
-#

[PATCH 1/4] staging: iio: accel: adis16201: Use SPDX identifier

2018-02-12 Thread Himanshu Jha
Use SPDX identifier format instead of GPLv2. Also, rearrange the headers
in the alphabetical order.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/staging/iio/accel/adis16201.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/iio/accel/adis16201.c 
b/drivers/staging/iio/accel/adis16201.c
index 2ebd275..b2145c9 100644
--- a/drivers/staging/iio/accel/adis16201.c
+++ b/drivers/staging/iio/accel/adis16201.c
@@ -1,19 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * ADIS16201 Dual-Axis Digital Inclinometer and Accelerometer
  *
  * Copyright 2010 Analog Devices Inc.
- *
- * Licensed under the GPL-2 or later.
  */
 
 #include 
-#include 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
-#include 
 
 #include 
 #include 
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 3/4] staging: iio: accel: Use sign_extend32 and adjust a switch statement

2018-02-12 Thread Himanshu Jha
Use sign_extend32 function instead of manually coding it. Also, adjust a
switch block to explicitly match channels and return -EINVAL as default
case which improves code readability.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/staging/iio/accel/adis16201.c | 13 -
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/iio/accel/adis16201.c 
b/drivers/staging/iio/accel/adis16201.c
index 011d2c5..6800347 100644
--- a/drivers/staging/iio/accel/adis16201.c
+++ b/drivers/staging/iio/accel/adis16201.c
@@ -112,12 +112,17 @@ static int adis16201_read_raw(struct iio_dev *indio_dev,
case IIO_CHAN_INFO_SCALE:
switch (chan->type) {
case IIO_VOLTAGE:
-   if (chan->channel == 0) {
+   switch (chan->channel) {
+   case 0:
*val = 1;
*val2 = 22;
-   } else {
+   break;
+   case 1:
*val = 0;
*val2 = 61;
+   break;
+   default:
+   return -EINVAL;
}
return IIO_VAL_INT_PLUS_MICRO;
case IIO_TEMP:
@@ -155,9 +160,7 @@ static int adis16201_read_raw(struct iio_dev *indio_dev,
if (ret)
return ret;
 
-   val16 &= (1 << bits) - 1;
-   val16 = (s16)(val16 << (16 - bits)) >> (16 - bits);
-   *val = val16;
+   *val = sign_extend32(val16, bits - 1);
return IIO_VAL_INT;
}
 
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 4/4] staging: iio: accel: Move adis16201 driver out of staging

2018-02-12 Thread Himanshu Jha
Move the adis16201 driver out of staging directory and merge to the
mainline IIO directory.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/iio/accel/Kconfig |  12 ++
 drivers/iio/accel/Makefile|   1 +
 drivers/iio/accel/adis16201.c | 315 ++
 drivers/staging/iio/accel/Kconfig |  12 --
 drivers/staging/iio/accel/Makefile|   1 -
 drivers/staging/iio/accel/adis16201.c | 315 --
 6 files changed, 328 insertions(+), 328 deletions(-)
 create mode 100644 drivers/iio/accel/adis16201.c
 delete mode 100644 drivers/staging/iio/accel/adis16201.c

diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig
index c6d9517..9416c6f 100644
--- a/drivers/iio/accel/Kconfig
+++ b/drivers/iio/accel/Kconfig
@@ -5,6 +5,18 @@
 
 menu "Accelerometers"
 
+config ADIS16201
+tristate "Analog Devices ADIS16201 Dual-Axis Digital Inclinometer and 
Accelerometer"
+depends on SPI
+select IIO_ADIS_LIB
+select IIO_ADIS_LIB_BUFFER if IIO_BUFFER
+help
+  Say Y here to build support for Analog Devices adis16201 dual-axis
+  digital inclinometer and accelerometer.
+
+  To compile this driver as a module, say M here: the module will
+  be called adis16201.
+
 config ADXL345
tristate
 
diff --git a/drivers/iio/accel/Makefile b/drivers/iio/accel/Makefile
index 368aedb..7832ec9 100644
--- a/drivers/iio/accel/Makefile
+++ b/drivers/iio/accel/Makefile
@@ -4,6 +4,7 @@
 #
 
 # When adding new entries keep the list in alphabetical order
+obj-$(CONFIG_ADIS16201) += adis16201.o
 obj-$(CONFIG_ADXL345) += adxl345_core.o
 obj-$(CONFIG_ADXL345_I2C) += adxl345_i2c.o
 obj-$(CONFIG_ADXL345_SPI) += adxl345_spi.o
diff --git a/drivers/iio/accel/adis16201.c b/drivers/iio/accel/adis16201.c
new file mode 100644
index 000..6800347
--- /dev/null
+++ b/drivers/iio/accel/adis16201.c
@@ -0,0 +1,315 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * ADIS16201 Dual-Axis Digital Inclinometer and Accelerometer
+ *
+ * Copyright 2010 Analog Devices Inc.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#define ADIS16201_STARTUP_DELAY_MS 220
+#define ADIS16201_FLASH_CNT_REG0x00
+
+/* Data Output Register Definitions */
+#define ADIS16201_SUPPLY_OUT_REG   0x02
+#define ADIS16201_XACCL_OUT_REG0x04
+#define ADIS16201_YACCL_OUT_REG0x06
+#define ADIS16201_AUX_ADC_REG  0x08
+#define ADIS16201_TEMP_OUT_REG 0x0A
+#define ADIS16201_XINCL_OUT_REG0x0C
+#define ADIS16201_YINCL_OUT_REG0x0E
+
+/* Calibration Register Definitions */
+#define ADIS16201_XACCL_OFFS_REG   0x10
+#define ADIS16201_YACCL_OFFS_REG   0x12
+#define ADIS16201_XACCL_SCALE_REG  0x14
+#define ADIS16201_YACCL_SCALE_REG  0x16
+#define ADIS16201_XINCL_OFFS_REG   0x18
+#define ADIS16201_YINCL_OFFS_REG   0x1A
+#define ADIS16201_XINCL_SCALE_REG  0x1C
+#define ADIS16201_YINCL_SCALE_REG  0x1E
+
+/* Alarm Register Definitions */
+#define ADIS16201_ALM_MAG1_REG 0x20
+#define ADIS16201_ALM_MAG2_REG 0x22
+#define ADIS16201_ALM_SMPL1_REG0x24
+#define ADIS16201_ALM_SMPL2_REG0x26
+#define ADIS16201_ALM_CTRL_REG 0x28
+
+#define ADIS16201_AUX_DAC_REG  0x30
+#define ADIS16201_GPIO_CTRL_REG0x32
+#define ADIS16201_SMPL_PRD_REG 0x36
+#define ADIS16201_AVG_CNT_REG  0x38
+#define ADIS16201_SLP_CNT_REG  0x3A
+
+/* MSC_CTRL */
+#define ADIS16201_MSC_CTRL_REG 0x34
+#define ADIS16201_MSC_CTRL_SELF_TEST_ENBIT(8)
+#define ADIS16201_MSC_CTRL_DATA_RDY_EN BIT(2)
+#define ADIS16201_MSC_CTRL_ACTIVE_HIGH BIT(1)
+#define ADIS16201_MSC_CTRL_DATA_RDY_DIO1   BIT(0)
+
+/* DIAG_STAT */
+#define ADIS16201_DIAG_STAT_REG0x3C
+#define ADIS16201_DIAG_STAT_ALARM2 BIT(9)
+#define ADIS16201_DIAG_STAT_ALARM1 BIT(8)
+#define ADIS16201_DIAG_STAT_SPI_FAIL_BIT   3
+#define ADIS16201_DIAG_STAT_FLASH_UPT_BIT  2
+#define ADIS16201_DIAG_STAT_POWER_HIGH_BIT 1
+#define ADIS16201_DIAG_STAT_POWER_LOW_BIT  0
+
+/* GLOB_CMD */
+#define ADIS16201_GLOB_CMD_REG 0x3E
+#define ADIS16201_GLOB_CMD_SW_RESETBIT(7)
+#define ADIS16201_GLOB_CMD_FACTORY_CAL BIT(1)
+
+#define ADIS16201_ERROR_ACTIVE BIT(14)
+
+enum adis16201_scan {
+   ADIS16201_SCAN_ACC_X,
+   ADIS16201_SCAN_ACC_Y,
+   ADIS16201_SCAN_INCLI_X,
+   ADIS16201_SCAN_INCLI_Y,
+  

[PATCH 0/4] staging: iio: accel: adis16201 driver cleanup

2018-02-12 Thread Himanshu Jha
The following patch series cleans up miscellaneous code fragments and
then the driver is moved from staging to mainline IIO subsytem directory.
Note that the last patch to move driver is *not* generated using '-M' flag,
which is used for detecting renames, since it may help reviewers to
suggest more cleanups/fix while pointing inline to the patch the
necessary changes.

All the patches have been tested using 0-day test service with success.

For all the patches:
Suggested-by: Jonathan Cameron <ji...@kernel.org>

Himanshu Jha (4):
  staging: iio: accel: adis16201: Use SPDX identifier
  staging: iio: accel: Remove unnecessary comments and add suitable
suffix
  staging: iio: accel: Use sign_extend32 and adjust a switch statement
  staging: iio: accel: Move adis16201 driver out of staging

 drivers/iio/accel/Kconfig |  12 ++
 drivers/iio/accel/Makefile|   1 +
 drivers/iio/accel/adis16201.c | 315 
 drivers/staging/iio/accel/Kconfig |  12 --
 drivers/staging/iio/accel/Makefile|   1 -
 drivers/staging/iio/accel/adis16201.c | 381 --
 6 files changed, 328 insertions(+), 394 deletions(-)
 create mode 100644 drivers/iio/accel/adis16201.c
 delete mode 100644 drivers/staging/iio/accel/adis16201.c

-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: rtl8723bs: hal: remove cast to void pointer

2017-08-28 Thread Himanshu Jha
casting to void pointer from any pointer type and vice-versa is done
implicitly and therefore casting is not needed in such a case.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/staging/rtl8723bs/hal/hal_btcoex.c| 14 +++
 drivers/staging/rtl8723bs/hal/hal_com.c   |  4 +-
 drivers/staging/rtl8723bs/hal/odm.c   | 46 +++
 drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c | 20 +-
 drivers/staging/rtl8723bs/hal/rtl8723b_rxdesc.c   |  2 +-
 drivers/staging/rtl8723bs/hal/rtl8723bs_recv.c|  2 +-
 drivers/staging/rtl8723bs/hal/rtl8723bs_xmit.c|  2 +-
 drivers/staging/rtl8723bs/hal/sdio_ops.c  |  2 +-
 8 files changed, 46 insertions(+), 46 deletions(-)

diff --git a/drivers/staging/rtl8723bs/hal/hal_btcoex.c 
b/drivers/staging/rtl8723bs/hal/hal_btcoex.c
index 9e08a4d..86fee10 100644
--- a/drivers/staging/rtl8723bs/hal/hal_btcoex.c
+++ b/drivers/staging/rtl8723bs/hal/hal_btcoex.c
@@ -419,10 +419,10 @@ static u8 halbtcoutsrc_Get(void *pBtcContext, u8 getType, 
void *pOutBuf)
padapter = pBtCoexist->Adapter;
pHalData = GET_HAL_DATA(padapter);
mlmeext = >mlmeextpriv;
-   pu8 = (u8 *)pOutBuf;
-   pS4Tmp = (s32 *)pOutBuf;
-   pU4Tmp = (u32 *)pOutBuf;
-   pU1Tmp = (u8 *)pOutBuf;
+   pu8 = pOutBuf;
+   pS4Tmp = pOutBuf;
+   pU4Tmp = pOutBuf;
+   pU1Tmp = pOutBuf;
ret = true;
 
switch (getType) {
@@ -585,9 +585,9 @@ static u8 halbtcoutsrc_Set(void *pBtcContext, u8 setType, 
void *pInBuf)
pBtCoexist = (PBTC_COEXIST)pBtcContext;
padapter = pBtCoexist->Adapter;
pHalData = GET_HAL_DATA(padapter);
-   pu8 = (u8 *)pInBuf;
-   pU1Tmp = (u8 *)pInBuf;
-   pU4Tmp = (u32 *)pInBuf;
+   pu8 = pInBuf;
+   pU1Tmp = pInBuf;
+   pU4Tmp = pInBuf;
ret = true;
 
if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
diff --git a/drivers/staging/rtl8723bs/hal/hal_com.c 
b/drivers/staging/rtl8723bs/hal/hal_com.c
index e3a9832..3e63b6d 100644
--- a/drivers/staging/rtl8723bs/hal/hal_com.c
+++ b/drivers/staging/rtl8723bs/hal/hal_com.c
@@ -1311,7 +1311,7 @@ void SetHalODMVar(
switch (eVariable) {
case HAL_ODM_STA_INFO:
{
-   struct sta_info *psta = (struct sta_info *)pValue1;
+   struct sta_info *psta = pValue1;
if (bSet) {
DBG_8192C("### Set STA_(%d) info ###\n", 
psta->mac_id);
ODM_CmnInfoPtrArrayHook(podmpriv, 
ODM_CMNINFO_STA_STATUS, psta->mac_id, psta);
@@ -1333,7 +1333,7 @@ void SetHalODMVar(
#if defined(CONFIG_SIGNAL_DISPLAY_DBM) && 
defined(CONFIG_BACKGROUND_NOISE_MONITOR)
case HAL_ODM_NOISE_MONITOR:
{
-   struct noise_info *pinfo = (struct noise_info *)pValue1;
+   struct noise_info *pinfo = pValue1;
 
#ifdef DBG_NOISE_MONITOR
DBG_8192C("### Noise monitor chan(%d)-bPauseDIG:%d, 
IGIValue:0x%02x, max_time:%d (ms) ###\n",
diff --git a/drivers/staging/rtl8723bs/hal/odm.c 
b/drivers/staging/rtl8723bs/hal/odm.c
index 2dbf199..ff43bb2 100644
--- a/drivers/staging/rtl8723bs/hal/odm.c
+++ b/drivers/staging/rtl8723bs/hal/odm.c
@@ -592,95 +592,95 @@ void ODM_CmnInfoHook(PDM_ODM_T pDM_Odm, ODM_CMNINFO_E 
CmnInfo, void *pValue)
/*  Dynamic call by reference pointer. */
/*  */
case ODM_CMNINFO_MAC_PHY_MODE:
-   pDM_Odm->pMacPhyMode = (u8 *)pValue;
+   pDM_Odm->pMacPhyMode = pValue;
break;
 
case ODM_CMNINFO_TX_UNI:
-   pDM_Odm->pNumTxBytesUnicast = (u64 *)pValue;
+   pDM_Odm->pNumTxBytesUnicast = pValue;
break;
 
case ODM_CMNINFO_RX_UNI:
-   pDM_Odm->pNumRxBytesUnicast = (u64 *)pValue;
+   pDM_Odm->pNumRxBytesUnicast = pValue;
break;
 
case ODM_CMNINFO_WM_MODE:
-   pDM_Odm->pwirelessmode = (u8 *)pValue;
+   pDM_Odm->pwirelessmode = pValue;
break;
 
case ODM_CMNINFO_BAND:
-   pDM_Odm->pBandType = (u8 *)pValue;
+   pDM_Odm->pBandType = pValue;
break;
 
case ODM_CMNINFO_SEC_CHNL_OFFSET:
-   pDM_Odm->pSecChOffset = (u8 *)pValue;
+   pDM_Odm->pSecChOffset = pValue;
break;
 
case ODM_CMNINFO_SEC_MODE:
-   pDM_Odm->pSecurity = (u8 *)pValue;
+   pDM_Odm->pSecurity = pValue;
break;
 
case ODM_CMNINFO_BW:
-   pDM_Odm->pBandWidth = (u8 *)pValue;
+   pDM_Odm->pBandWidth = pValue;
break;
 
case ODM_CMNINFO_CHNL:
-   pDM_Odm->pChann

[PATCH] staging: rtl8723bs: os_dep: remove cast to void pointer

2017-08-28 Thread Himanshu Jha
casting to void pointer from any pointer type and vice-versa is done
implicitly and therefore casting is not needed in such a case.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/staging/rtl8723bs/os_dep/mlme_linux.c | 4 ++--
 drivers/staging/rtl8723bs/os_dep/osdep_service.c  | 2 +-
 drivers/staging/rtl8723bs/os_dep/sdio_intf.c  | 2 +-
 drivers/staging/rtl8723bs/os_dep/sdio_ops_linux.c | 4 ++--
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/rtl8723bs/os_dep/mlme_linux.c 
b/drivers/staging/rtl8723bs/os_dep/mlme_linux.c
index 3e29df0..80ca2d7 100644
--- a/drivers/staging/rtl8723bs/os_dep/mlme_linux.c
+++ b/drivers/staging/rtl8723bs/os_dep/mlme_linux.c
@@ -21,7 +21,7 @@
 
 static void _dynamic_check_timer_handlder (void *FunctionContext)
 {
-   struct adapter *adapter = (struct adapter *)FunctionContext;
+   struct adapter *adapter = FunctionContext;
 
rtw_dynamic_check_timer_handlder(adapter);
 
@@ -30,7 +30,7 @@ static void _dynamic_check_timer_handlder (void 
*FunctionContext)
 
 static void _rtw_set_scan_deny_timer_hdl(void *FunctionContext)
 {
-   struct adapter *adapter = (struct adapter *)FunctionContext;
+   struct adapter *adapter = FunctionContext;
rtw_set_scan_deny_timer_hdl(adapter);
 }
 
diff --git a/drivers/staging/rtl8723bs/os_dep/osdep_service.c 
b/drivers/staging/rtl8723bs/os_dep/osdep_service.c
index aa16d1a..a05daf0 100644
--- a/drivers/staging/rtl8723bs/os_dep/osdep_service.c
+++ b/drivers/staging/rtl8723bs/os_dep/osdep_service.c
@@ -73,7 +73,7 @@ inline int _rtw_netif_rx(_nic_hdl ndev, struct sk_buff *skb)
 
 void rtw_init_timer(_timer *ptimer, void *padapter, void *pfunc)
 {
-   struct adapter *adapter = (struct adapter *)padapter;
+   struct adapter *adapter = padapter;
 
_init_timer(ptimer, adapter->pnetdev, pfunc, adapter);
 }
diff --git a/drivers/staging/rtl8723bs/os_dep/sdio_intf.c 
b/drivers/staging/rtl8723bs/os_dep/sdio_intf.c
index d2fb489..94332487 100644
--- a/drivers/staging/rtl8723bs/os_dep/sdio_intf.c
+++ b/drivers/staging/rtl8723bs/os_dep/sdio_intf.c
@@ -138,7 +138,7 @@ static void sdio_free_irq(struct dvobj_priv *dvobj)
 extern unsigned int oob_irq;
 static irqreturn_t gpio_hostwakeup_irq_thread(int irq, void *data)
 {
-   struct adapter *padapter = (struct adapter *)data;
+   struct adapter *padapter = data;
DBG_871X_LEVEL(_drv_always_, "gpio_hostwakeup_irq_thread\n");
/* Disable interrupt before calling handler */
/* disable_irq_nosync(oob_irq); */
diff --git a/drivers/staging/rtl8723bs/os_dep/sdio_ops_linux.c 
b/drivers/staging/rtl8723bs/os_dep/sdio_ops_linux.c
index 3aa3e65..3108a62 100644
--- a/drivers/staging/rtl8723bs/os_dep/sdio_ops_linux.c
+++ b/drivers/staging/rtl8723bs/os_dep/sdio_ops_linux.c
@@ -431,7 +431,7 @@ s32 _sd_read(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, 
void *pdata)
if (unlikely((cnt == 1) || (cnt == 2)))
{
int i;
-   u8 *pbuf = (u8 *)pdata;
+   u8 *pbuf = pdata;
 
for (i = 0; i < cnt; i++)
{
@@ -534,7 +534,7 @@ s32 _sd_write(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, 
void *pdata)
if (unlikely((cnt == 1) || (cnt == 2)))
{
int i;
-   u8 *pbuf = (u8 *)pdata;
+   u8 *pbuf = pdata;
 
for (i = 0; i < cnt; i++)
{
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: rtl8723bs: core: remove cast to void pointer

2017-08-28 Thread Himanshu Jha
casting to void pointer from any pointer type and vice-versa is done
implicitly and therefore casting is not needed in such a case.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/staging/rtl8723bs/core/rtw_cmd.c  | 2 +-
 drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 2 +-
 drivers/staging/rtl8723bs/core/rtw_pwrctrl.c  | 2 +-
 drivers/staging/rtl8723bs/core/rtw_recv.c | 2 +-
 drivers/staging/rtl8723bs/core/rtw_xmit.c | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/rtl8723bs/core/rtw_cmd.c 
b/drivers/staging/rtl8723bs/core/rtw_cmd.c
index 080c81b..d381827 100644
--- a/drivers/staging/rtl8723bs/core/rtw_cmd.c
+++ b/drivers/staging/rtl8723bs/core/rtw_cmd.c
@@ -432,7 +432,7 @@ int rtw_cmd_thread(void *context)
unsigned long cmd_process_time;
u8 (*cmd_hdl)(struct adapter *padapter, u8 *pbuf);
void (*pcmd_callback)(struct adapter *dev, struct cmd_obj *pcmd);
-   struct adapter *padapter = (struct adapter *)context;
+   struct adapter *padapter = context;
struct cmd_priv *pcmdpriv = &(padapter->cmdpriv);
struct drvextra_cmd_parm *extra_parm = NULL;
 
diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c 
b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
index 99e3b68..b6d137f 100644
--- a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
+++ b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
@@ -1228,7 +1228,7 @@ unsigned int OnAssocReq(struct adapter *padapter, union 
recv_frame *precv_frame)
}
 
pstat = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
-   if (pstat == (struct sta_info *)NULL) {
+   if (pstat == NULL) {
status = _RSON_CLS2_;
goto asoc_class2_error;
}
diff --git a/drivers/staging/rtl8723bs/core/rtw_pwrctrl.c 
b/drivers/staging/rtl8723bs/core/rtw_pwrctrl.c
index f060e54..aabdaaf 100644
--- a/drivers/staging/rtl8723bs/core/rtw_pwrctrl.c
+++ b/drivers/staging/rtl8723bs/core/rtw_pwrctrl.c
@@ -829,7 +829,7 @@ static void pwr_rpwm_timeout_handler(void *FunctionContext)
struct pwrctrl_priv *pwrpriv;
 
 
-   padapter = (struct adapter *)FunctionContext;
+   padapter = FunctionContext;
pwrpriv = adapter_to_pwrctl(padapter);
DBG_871X("+%s: rpwm = 0x%02X cpwm = 0x%02X\n", __func__, pwrpriv->rpwm, 
pwrpriv->cpwm);
 
diff --git a/drivers/staging/rtl8723bs/core/rtw_recv.c 
b/drivers/staging/rtl8723bs/core/rtw_recv.c
index c6018f0..68a6303 100644
--- a/drivers/staging/rtl8723bs/core/rtw_recv.c
+++ b/drivers/staging/rtl8723bs/core/rtw_recv.c
@@ -2360,7 +2360,7 @@ int recv_indicatepkt_reorder(struct adapter *padapter, 
union recv_frame *prframe
 
 void rtw_reordering_ctrl_timeout_handler(void *pcontext)
 {
-   struct recv_reorder_ctrl *preorder_ctrl = (struct recv_reorder_ctrl 
*)pcontext;
+   struct recv_reorder_ctrl *preorder_ctrl = pcontext;
struct adapter *padapter = preorder_ctrl->padapter;
struct __queue *ppending_recvframe_queue = 
_ctrl->pending_recvframe_queue;
 
diff --git a/drivers/staging/rtl8723bs/core/rtw_xmit.c 
b/drivers/staging/rtl8723bs/core/rtw_xmit.c
index a0d79985..022f654 100644
--- a/drivers/staging/rtl8723bs/core/rtw_xmit.c
+++ b/drivers/staging/rtl8723bs/core/rtw_xmit.c
@@ -3002,7 +3002,7 @@ int rtw_xmit_thread(void *context)
 
 
err = _SUCCESS;
-   padapter = (struct adapter *)context;
+   padapter = context;
 
thread_enter("RTW_XMIT_THREAD");
 
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: rtl8188eu: remove unnecessary call to memset

2017-08-28 Thread Himanshu Jha
call to memset to assign 0 value immediately after allocating
memory with kzalloc is unnecesaary as kzalloc allocates the memory
filled with 0 value.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/staging/rtl8188eu/core/rtw_mlme.c  | 3 ---
 drivers/staging/rtl8188eu/os_dep/ioctl_linux.c | 2 --
 2 files changed, 5 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme.c 
b/drivers/staging/rtl8188eu/core/rtw_mlme.c
index fde3060..7397167 100644
--- a/drivers/staging/rtl8188eu/core/rtw_mlme.c
+++ b/drivers/staging/rtl8188eu/core/rtw_mlme.c
@@ -1566,7 +1566,6 @@ int rtw_set_auth(struct adapter *adapter, struct 
security_priv *psecuritypriv)
res = _FAIL;
goto exit;
}
-   memset(psetauthparm, 0, sizeof(struct setauth_parm));
psetauthparm->mode = (unsigned char)psecuritypriv->dot11AuthAlgrthm;
pcmd->cmdcode = _SetAuth_CMD_;
pcmd->parmbuf = (unsigned char *)psetauthparm;
@@ -1601,8 +1600,6 @@ int rtw_set_key(struct adapter *adapter, struct 
security_priv *psecuritypriv, in
goto err_free_cmd;
}
 
-   memset(psetkeyparm, 0, sizeof(struct setkey_parm));
-
if (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) {
psetkeyparm->algorithm = (unsigned 
char)psecuritypriv->dot118021XGrpPrivacy;
RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_,
diff --git a/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c 
b/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c
index 763eccd..c0664dc 100644
--- a/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c
+++ b/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c
@@ -2166,8 +2166,6 @@ static int set_group_key(struct adapter *padapter, u8 
*key, u8 alg, int keyid)
goto exit;
}
 
-   memset(psetkeyparm, 0, sizeof(struct setkey_parm));
-
psetkeyparm->keyid = (u8)keyid;
 
psetkeyparm->algorithm = alg;
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: rtlwifi: remove memset before memcpy

2017-08-28 Thread Himanshu Jha
calling memcpy immediately after memset with the same region of memory
makes memset redundant.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/staging/rtlwifi/base.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/staging/rtlwifi/base.c b/drivers/staging/rtlwifi/base.c
index b81f0a9..63ce708 100644
--- a/drivers/staging/rtlwifi/base.c
+++ b/drivers/staging/rtlwifi/base.c
@@ -2554,7 +2554,6 @@ bool rtl_check_beacon_key(struct ieee80211_hw *hw, void 
*data, unsigned int len)
 
if (!cur_bcn_key->valid) {
/* update cur_beacon_keys */
-   memset(cur_bcn_key, 0, sizeof(bcn_key));
memcpy(cur_bcn_key, _key, sizeof(bcn_key));
cur_bcn_key->valid = true;
 
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] staging: rtl8723bs: remove memset before memcpy

2017-08-28 Thread Himanshu Jha
On Mon, Aug 28, 2017 at 09:19:06AM +0300, Dan Carpenter wrote:
> On Mon, Aug 28, 2017 at 01:43:31AM +0530, Himanshu Jha wrote:
> > calling memcpy immediately after memset with the same region of memory
> > makes memset redundant.
> > 
> > Build successfully.
> > 
> 
> Thanks for the patch, it looks good.  You don't need to say that it
> builds successfully, because we already assume that's true.
> 
> > Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
> > ---
> 
> Sometimes I put a comment here under the cut off line if I want people
> to know that I haven't tested a patch.
> 
> Anyway, don't resend the patch.  It's fine as-is (unless Greg
> complains) but it's just for future reference.

Thanks for the feedback and i will keep that in mind for future patches.
Himanshu Jha
> 
> regards,
> dan carpenter
> 
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: rtl8723bs: remove memset before memcpy

2017-08-27 Thread Himanshu Jha
calling memcpy immediately after memset with the same region of memory
makes memset redundant.

Build successfully.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/staging/rtl8723bs/core/rtw_ioctl_set.c | 1 -
 drivers/staging/rtl8723bs/core/rtw_mlme.c  | 2 --
 drivers/staging/rtl8723bs/os_dep/mlme_linux.c  | 2 --
 3 files changed, 5 deletions(-)

diff --git a/drivers/staging/rtl8723bs/core/rtw_ioctl_set.c 
b/drivers/staging/rtl8723bs/core/rtw_ioctl_set.c
index e0793f8..d815a69 100644
--- a/drivers/staging/rtl8723bs/core/rtw_ioctl_set.c
+++ b/drivers/staging/rtl8723bs/core/rtw_ioctl_set.c
@@ -127,7 +127,6 @@ u8 rtw_do_join(struct adapter *padapter)
 
pibss = 
padapter->registrypriv.dev_network.MacAddress;
 
-   memset(_network->Ssid, 0, sizeof(struct 
ndis_802_11_ssid));
memcpy(_network->Ssid, 
>assoc_ssid, sizeof(struct ndis_802_11_ssid));
 
rtw_update_registrypriv_dev_network(padapter);
diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme.c 
b/drivers/staging/rtl8723bs/core/rtw_mlme.c
index 9f44dd0..6b77820 100644
--- a/drivers/staging/rtl8723bs/core/rtw_mlme.c
+++ b/drivers/staging/rtl8723bs/core/rtw_mlme.c
@@ -922,7 +922,6 @@ void rtw_surveydone_event_callback(struct adapter   
*adapter, u8 *pbuf)
 
RT_TRACE(_module_rtl871x_mlme_c_, 
_drv_err_, ("switching to adhoc master\n"));
 
-   memset(_network->Ssid, 0, 
sizeof(struct ndis_802_11_ssid));
memcpy(_network->Ssid, 
>assoc_ssid, sizeof(struct ndis_802_11_ssid));
 

rtw_update_registrypriv_dev_network(adapter);
@@ -1774,7 +1773,6 @@ void rtw_stadel_event_callback(struct adapter *adapter, 
u8 *pbuf)
 
memcpy(pdev_network, _network->network, 
get_wlan_bssid_ex_sz(_network->network));
 
-   memset(_network->Ssid, 0, sizeof(struct 
ndis_802_11_ssid));
memcpy(_network->Ssid, >assoc_ssid, 
sizeof(struct ndis_802_11_ssid));
 
rtw_update_registrypriv_dev_network(adapter);
diff --git a/drivers/staging/rtl8723bs/os_dep/mlme_linux.c 
b/drivers/staging/rtl8723bs/os_dep/mlme_linux.c
index 46315d1..3e29df0 100644
--- a/drivers/staging/rtl8723bs/os_dep/mlme_linux.c
+++ b/drivers/staging/rtl8723bs/os_dep/mlme_linux.c
@@ -91,8 +91,6 @@ void rtw_reset_securitypriv(struct adapter *adapter)
/*  Backup the btkip_countermeasure information. */
/*  When the countermeasure is trigger, the driver have to 
disconnect with AP for 60 seconds. */
 
-   memset([ 0 ], 0x00, sizeof(RT_PMKID_LIST) * 
NUM_PMKID_CACHE);
-
memcpy([ 0 ], >securitypriv.PMKIDList[ 
0 ], sizeof(RT_PMKID_LIST) * NUM_PMKID_CACHE);
backupPMKIDIndex = adapter->securitypriv.PMKIDIndex;
backupTKIPCountermeasure = 
adapter->securitypriv.btkip_countermeasure;
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] staging: rtl8723bs: remove null check before kfree

2017-08-27 Thread Himanshu Jha
On Sun, Aug 27, 2017 at 10:06:47AM -0500, Larry Finger wrote:
> On 08/26/2017 03:47 PM, Himanshu Jha wrote:
> >Kfree on NULL pointer is a no-op and therefore checking is redundant.
> >
> >Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
> >---
> 
> Acked-by: Larry Finger <larry.fin...@lwfinger.net>
> 
> For some reason not fully explained, gmail is placing ALL your E-mails in my
> spam folder. You might wish to explore that situation.
> 
Yes, that's because there was some problem with account that i don't
know. I got a email from Gmail:
"Hi Himanshu,
 We’ve detected unusual activity in your Google Account
 himanshujha199...@gmail.com and locked it to protect your information."

So, after that i changed my password and now everythings fine!!

Himanshu Jha

> Larry
> 
> >  drivers/staging/rtl8723bs/os_dep/ioctl_linux.c | 18 ++
> >  1 file changed, 6 insertions(+), 12 deletions(-)
> >
> >diff --git a/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c 
> >b/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
> >index c7bad64..d5e5f83 100644
> >--- a/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
> >+++ b/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
> >@@ -4120,10 +4120,8 @@ static int rtw_set_wps_beacon(struct net_device *dev, 
> >struct ieee_param *param,
> > ie_len = len-12-2;/*  12 = param header, 2:no packed */
> >-if (pmlmepriv->wps_beacon_ie) {
> >-kfree(pmlmepriv->wps_beacon_ie);
> >-pmlmepriv->wps_beacon_ie = NULL;
> >-}
> >+kfree(pmlmepriv->wps_beacon_ie);
> >+pmlmepriv->wps_beacon_ie = NULL;
> > if (ie_len>0) {
> > pmlmepriv->wps_beacon_ie = rtw_malloc(ie_len);
> >@@ -4160,10 +4158,8 @@ static int rtw_set_wps_probe_resp(struct net_device 
> >*dev, struct ieee_param *par
> > ie_len = len-12-2;/*  12 = param header, 2:no packed */
> >-if (pmlmepriv->wps_probe_resp_ie) {
> >-kfree(pmlmepriv->wps_probe_resp_ie);
> >-pmlmepriv->wps_probe_resp_ie = NULL;
> >-}
> >+kfree(pmlmepriv->wps_probe_resp_ie);
> >+pmlmepriv->wps_probe_resp_ie = NULL;
> > if (ie_len>0) {
> > pmlmepriv->wps_probe_resp_ie = rtw_malloc(ie_len);
> >@@ -4195,10 +4191,8 @@ static int rtw_set_wps_assoc_resp(struct net_device 
> >*dev, struct ieee_param *par
> > ie_len = len-12-2;/*  12 = param header, 2:no packed */
> >-if (pmlmepriv->wps_assoc_resp_ie) {
> >-kfree(pmlmepriv->wps_assoc_resp_ie);
> >-pmlmepriv->wps_assoc_resp_ie = NULL;
> >-}
> >+kfree(pmlmepriv->wps_assoc_resp_ie);
> >+pmlmepriv->wps_assoc_resp_ie = NULL;
> > if (ie_len>0) {
> > pmlmepriv->wps_assoc_resp_ie = rtw_malloc(ie_len);
> >
> 
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: r8822be: remove unnecessary call to memset

2017-08-27 Thread Himanshu Jha
call to memset to assign 0 value immediately after allocating
memory with kzalloc is unnecesaary as kzalloc allocates the memory
filled with 0 value.

Build and tested it.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_api_88xx.c  | 2 --
 drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_func_88xx.c | 5 -
 2 files changed, 7 deletions(-)

diff --git a/drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_api_88xx.c 
b/drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_api_88xx.c
index ee7c3d0..0551c47 100644
--- a/drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_api_88xx.c
+++ b/drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_api_88xx.c
@@ -5308,7 +5308,6 @@ halmac_write_cam_88xx(struct halmac_adapter 
*halmac_adapter, u32 entry_index,
cam_entry_format = kzalloc(sizeof(*cam_entry_format), GFP_KERNEL);
if (!cam_entry_format)
return HALMAC_RET_NULL_POINTER;
-   memset(cam_entry_format, 0x00, sizeof(*cam_entry_format));
 
cam_entry_format->key_id = cam_entry_info->key_id;
cam_entry_format->valid = cam_entry_info->valid;
@@ -5461,7 +5460,6 @@ halmac_clear_cam_entry_88xx(struct halmac_adapter 
*halmac_adapter,
cam_entry_format = kzalloc(sizeof(*cam_entry_format), GFP_KERNEL);
if (!cam_entry_format)
return HALMAC_RET_NULL_POINTER;
-   memset(cam_entry_format, 0x00, sizeof(*cam_entry_format));
 
for (i = 0; i < 8; i++) {
HALMAC_REG_WRITE_32(halmac_adapter, REG_CAMWRITE,
diff --git a/drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_func_88xx.c 
b/drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_func_88xx.c
index 50f6f25..f33024e 100644
--- a/drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_func_88xx.c
+++ b/drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_func_88xx.c
@@ -691,7 +691,6 @@ halmac_func_pg_efuse_by_map_88xx(struct halmac_adapter 
*halmac_adapter,
/* out of memory */
return HALMAC_RET_MALLOC_FAIL;
}
-   memset(eeprom_mask_updated, 0x00, eeprom_mask_size);
 
status = halmac_update_eeprom_mask_88xx(halmac_adapter, pg_efuse_info,
eeprom_mask_updated);
@@ -3604,10 +3603,6 @@ halmac_verify_send_rsvd_page_88xx(struct halmac_adapter 
*halmac_adapter)
return HALMAC_RET_MALLOC_FAIL;
}
 
-   memset(rsvd_page, 0x00,
-  h2c_pkt_verify_size +
-  halmac_adapter->hw_config_info.txdesc_size);
-
ret_status = halmac_dump_fifo_88xx(
halmac_adapter, HAL_FIFO_SEL_RSVD_PAGE, 0,
h2c_pkt_verify_size +
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] [media] atomisp2: Remove null check before kfree

2017-08-26 Thread Himanshu Jha
Kfree on NULL pointer is a no-op and therefore checking is redundant.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 .../staging/media/atomisp/pci/atomisp2/css2400/sh_css_firmware.c| 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git 
a/drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css_firmware.c 
b/drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css_firmware.c
index 6358216..451c76e 100644
--- a/drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css_firmware.c
+++ b/drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css_firmware.c
@@ -295,10 +295,8 @@ void sh_css_unload_firmware(void)
}
 
memset(_css_sp_fw, 0, sizeof(sh_css_sp_fw));
-   if (sh_css_blob_info) {
-   kfree(sh_css_blob_info);
-   sh_css_blob_info = NULL;
-   }
+   kfree(sh_css_blob_info);
+   sh_css_blob_info = NULL;
sh_css_num_binaries = 0;
 }
 
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: rtl8723bs: remove null check before kfree

2017-08-26 Thread Himanshu Jha
Kfree on NULL pointer is a no-op and therefore checking is redundant.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/staging/rtl8723bs/os_dep/ioctl_linux.c | 18 ++
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c 
b/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
index c7bad64..d5e5f83 100644
--- a/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
+++ b/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
@@ -4120,10 +4120,8 @@ static int rtw_set_wps_beacon(struct net_device *dev, 
struct ieee_param *param,
ie_len = len-12-2;/*  12 = param header, 2:no packed */
 
 
-   if (pmlmepriv->wps_beacon_ie) {
-   kfree(pmlmepriv->wps_beacon_ie);
-   pmlmepriv->wps_beacon_ie = NULL;
-   }
+   kfree(pmlmepriv->wps_beacon_ie);
+   pmlmepriv->wps_beacon_ie = NULL;
 
if (ie_len>0) {
pmlmepriv->wps_beacon_ie = rtw_malloc(ie_len);
@@ -4160,10 +4158,8 @@ static int rtw_set_wps_probe_resp(struct net_device 
*dev, struct ieee_param *par
ie_len = len-12-2;/*  12 = param header, 2:no packed */
 
 
-   if (pmlmepriv->wps_probe_resp_ie) {
-   kfree(pmlmepriv->wps_probe_resp_ie);
-   pmlmepriv->wps_probe_resp_ie = NULL;
-   }
+   kfree(pmlmepriv->wps_probe_resp_ie);
+   pmlmepriv->wps_probe_resp_ie = NULL;
 
if (ie_len>0) {
pmlmepriv->wps_probe_resp_ie = rtw_malloc(ie_len);
@@ -4195,10 +4191,8 @@ static int rtw_set_wps_assoc_resp(struct net_device 
*dev, struct ieee_param *par
ie_len = len-12-2;/*  12 = param header, 2:no packed */
 
 
-   if (pmlmepriv->wps_assoc_resp_ie) {
-   kfree(pmlmepriv->wps_assoc_resp_ie);
-   pmlmepriv->wps_assoc_resp_ie = NULL;
-   }
+   kfree(pmlmepriv->wps_assoc_resp_ie);
+   pmlmepriv->wps_assoc_resp_ie = NULL;
 
if (ie_len>0) {
pmlmepriv->wps_assoc_resp_ie = rtw_malloc(ie_len);
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] Staging : unisys : visorbus : visorbus_main: Fixed a brace cdoing style issue

2017-07-23 Thread Himanshu Jha
Fixed coding style issue for function declaration.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/staging/unisys/visorbus/visorbus_main.c | 18 --
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/unisys/visorbus/visorbus_main.c 
b/drivers/staging/unisys/visorbus/visorbus_main.c
index 1c785dd..c564962 100644
--- a/drivers/staging/unisys/visorbus/visorbus_main.c
+++ b/drivers/staging/unisys/visorbus/visorbus_main.c
@@ -270,7 +270,8 @@ static const struct attribute_group 
*visorbus_channel_groups[] = {
 
 static ssize_t partition_handle_show(struct device *dev,
 struct device_attribute *attr,
-char *buf) {
+char *buf)
+{
struct visor_device *vdev = to_visor_device(dev);
u64 handle = visorchannel_get_clientpartition(vdev->visorchannel);
 
@@ -280,7 +281,8 @@ static DEVICE_ATTR_RO(partition_handle);
 
 static ssize_t partition_guid_show(struct device *dev,
   struct device_attribute *attr,
-  char *buf) {
+  char *buf)
+{
struct visor_device *vdev = to_visor_device(dev);
 
return sprintf(buf, "{%pUb}\n", >partition_uuid);
@@ -289,7 +291,8 @@ static DEVICE_ATTR_RO(partition_guid);
 
 static ssize_t partition_name_show(struct device *dev,
   struct device_attribute *attr,
-  char *buf) {
+  char *buf)
+{
struct visor_device *vdev = to_visor_device(dev);
 
return sprintf(buf, "%s\n", vdev->name);
@@ -298,7 +301,8 @@ static DEVICE_ATTR_RO(partition_name);
 
 static ssize_t channel_addr_show(struct device *dev,
 struct device_attribute *attr,
-char *buf) {
+char *buf)
+{
struct visor_device *vdev = to_visor_device(dev);
u64 addr = visorchannel_get_physaddr(vdev->visorchannel);
 
@@ -308,7 +312,8 @@ static DEVICE_ATTR_RO(channel_addr);
 
 static ssize_t channel_bytes_show(struct device *dev,
  struct device_attribute *attr,
- char *buf) {
+ char *buf)
+{
struct visor_device *vdev = to_visor_device(dev);
u64 nbytes = visorchannel_get_nbytes(vdev->visorchannel);
 
@@ -318,7 +323,8 @@ static DEVICE_ATTR_RO(channel_bytes);
 
 static ssize_t channel_id_show(struct device *dev,
   struct device_attribute *attr,
-  char *buf) {
+  char *buf)
+{
struct visor_device *vdev = to_visor_device(dev);
int len = 0;
 
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel