Re: [PATCH 1/3] staging: dgnc: fix camelcase of SerialDriver and

2016-03-22 Thread DaeSeok Youn
2016-03-22 6:02 GMT+09:00 Greg KH :
> On Mon, Mar 14, 2016 at 01:28:01PM +0900, Daeseok Youn wrote:
>> Signed-off-by: Daeseok Youn 
>
> Your subject: does not make sense, and I can't take a patch without any
> changelog entry :(
ok. I will add comment to changelog entry and resend this.

Thanks.

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


Re: [PATCH 2/3] staging: dgnc: use pointer type of tty_struct

2016-03-22 Thread DaeSeok Youn
2016-03-22 6:05 GMT+09:00 Greg KH :
> On Mon, Mar 14, 2016 at 01:28:31PM +0900, Daeseok Youn wrote:
>> For using tty_alloc_driver, SerialDriver has to be pointer type.
>
> Yes, but you aren't calling tty_alloc_driver, so this patch totally
> breaks the working code :(
yes.. my changelog was NOT good enough to explain.
I was tried to make this patch based on "staging-testing branch" of
staging git tree.

Actually, I sent 3 patches
[1/3] staging: dgnc: fix camelcase of SerialDriver and PrintDriver
[2/3] staging: dgnc: use pointer type of tty_struct
[3/3] staging: dgnc: use tty_alloc_driver instead of kcalloc

without 1/3 patch set, it can break the working code..
(you left a comment on 1/3 and also it couldn't be taken.)
>
> Please be more careful...
Yes, I will be..
Sorry. :-(

I will resend a series of patches for this

thanks.
regards,
Daeseok.
>
> greg k-h
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 3/3] staging: dgnc: use tty_alloc_driver instead of kcalloc

2016-03-22 Thread DaeSeok Youn
2016-03-22 6:05 GMT+09:00 Greg KH :
> On Mon, Mar 14, 2016 at 01:29:00PM +0900, Daeseok Youn wrote:
>> the tty_alloc_driver() can allocate memory for ttys and termios.
>> And also it can release allocated memory easly with using
>> put_tty_driver().
>>
>> Signed-off-by: Daeseok Youn 
>
> But you broke the driver in the previous patch, you can't do that, each
> patch has to be 'stand-alone'.
I am not sure about 'stand-alone'. this patch has to have dependency on
previous patch..

I am not sure how to make a series of patches that are related with others.

In this series of patches, 1/3 was failed to merge because changelog entry was
missing. So other patches(2/3, 3/3) was breaking working codes.
I will resend this patch with previous and check more before sending
these patches.
Sorry for the noise..

And I have a question not related this thread,
I had been waiting my patches merged and also have other patches on
same file(in case of dgnc).
I couldn't send next patches until previous patches are taken.
How can I manage my patches for this case?

thanks.

regards,
Daeseok.

>
> thanks,
>
> greg k-h
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


GANJARAN TELEKOM

2016-03-22 Thread Telekom Malaysia Berhad
Telekom Malaysia Berhad
Level 51, North Wing, Menara TM,
Jalan Pantai Baru, 50672,
Kuala Lumpur,
WP Kuala Lumpur,
Malaysia.


Hadiah Bonus Tahun Baru.

Pihak Telekom Malaysia @Program Kemenangan yang telah diadakan pada 9th Mac 
2016 di mana alamat email anda yang disertakan beraama Tiket Kemenangan 
nombor 2 - 4 - 16 -37 - 89 - 40 -85 dengan siri nombor 2268/02 telah 
memenangi loteri kategori hadiah kedua khas keluarga Telekom Malaysia.Untuk 
menuntut hadiah kemenangan ini anda dikehendaki menghubungi melalui e mail 
Bahagian Tuntutan untuk tujuan pemerosesan dan pembayaran hadiah wang tunai 
kepada anda.

Di sepanjang program Khas Keluarga Telekom yang telah diadakan di Ibupejabat 
di Kuala Lumpur sejumlah Rm270,000.00 (Ringgit Malaysia : Dua Ratus Tujuh 
Puluh Ribu) telah dianugerahkan kepada anda oleh Telekom Malaysia Berhad 
kepada anda dan keluarga anda sempena sambutsn Hari Raya 2016 ini.

Program ini turut dibiayai bersama oleh Toyota Malaysia dan Tenaga Nasional 
sebagai pakej istimewa Telekom 2016 dan anda perlu memahami bahawa e mail ini 
adalah 100% sah dan diiktiraf kerana program ini kebiasaannya diadakan sekali 
dalam masa lima tahun.

Sila hubungi agen kami untuk menuntut hadiah ini :

EN SHAFIE BIN HASSAN
Pengarah Bahagian Tuntutan
E-mail: nadia-tele...@outlook.my

Untuk tujuan pemerosesan sila hubungi agen kami dengan maklumat-maklumat 
berikut :
1) Nama Penuh:
2). Umur:
3). Pekerjaan:
4). Telefon:
5). Negeri/Bandar:

Perlu diingatkan bahawa hadiah akhir tahun Telekom Malaysia Berhad 2016 ini 
adalah diberikan khas kepada anda dan keluarga anda dan anda hendaklah 
membuat tunttan ini sebelum 29th Mac 2016.

Terima kasih.

Mrs Nadia binti Rafik
Pengurus Eksekutif
Anugerah Telekom Malaysia
Ibupejabat telekom Malaysia.
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] staging: xgifb: Fix comment style

2016-03-22 Thread Bo Yu

On Mon, Mar 21, 2016 at 03:38:21PM -0400, Kroah-Hartman wrote:
hi,

On Sat, Mar 12, 2016 at 03:40:35AM -0500, YU Bo wrote:

Fix comments to use trailing */ on separste lines.

Signed-off-by: YU BO 
---
drivers/staging/xgifb/vb_init.c|3 ++-
drivers/staging/xgifb/vb_setmode.c |3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)


You sent me 2 different patches with the identical subject: line, which
I can't accept.  Please fix them up and send a patch series, with unique
subjects.

yes, you are right:) I will fix them up and resend a patch series.
Sorry for the noise.
Thanks.


thanks,

greg k-h

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


[PATCH] staging: dgnc: fix camelcase of SerialDriver and PrintDriver

2016-03-22 Thread Daeseok Youn
fix the checkpatch.pl warning about CamelCase.

Signed-off-by: Daeseok Youn 
---
 drivers/staging/dgnc/dgnc_driver.h |   4 +-
 drivers/staging/dgnc/dgnc_tty.c| 118 ++---
 2 files changed, 61 insertions(+), 61 deletions(-)

diff --git a/drivers/staging/dgnc/dgnc_driver.h 
b/drivers/staging/dgnc/dgnc_driver.h
index e4be81b..953c891 100644
--- a/drivers/staging/dgnc/dgnc_driver.h
+++ b/drivers/staging/dgnc/dgnc_driver.h
@@ -202,9 +202,9 @@ struct dgnc_board {
 * to our channels.
 */
 
-   struct tty_driver   SerialDriver;
+   struct tty_driver serial_driver;
charSerialName[200];
-   struct tty_driver   PrintDriver;
+   struct tty_driver print_driver;
charPrintName[200];
 
booldgnc_Major_Serial_Registered;
diff --git a/drivers/staging/dgnc/dgnc_tty.c b/drivers/staging/dgnc/dgnc_tty.c
index bcd2bdf..081ac75 100644
--- a/drivers/staging/dgnc/dgnc_tty.c
+++ b/drivers/staging/dgnc/dgnc_tty.c
@@ -178,20 +178,20 @@ int dgnc_tty_register(struct dgnc_board *brd)
 {
int rc = 0;
 
-   brd->SerialDriver.magic = TTY_DRIVER_MAGIC;
+   brd->serial_driver.magic = TTY_DRIVER_MAGIC;
 
snprintf(brd->SerialName, MAXTTYNAMELEN, "tty_dgnc_%d_", brd->boardnum);
 
-   brd->SerialDriver.name = brd->SerialName;
-   brd->SerialDriver.name_base = 0;
-   brd->SerialDriver.major = 0;
-   brd->SerialDriver.minor_start = 0;
-   brd->SerialDriver.num = brd->maxports;
-   brd->SerialDriver.type = TTY_DRIVER_TYPE_SERIAL;
-   brd->SerialDriver.subtype = SERIAL_TYPE_NORMAL;
-   brd->SerialDriver.init_termios = DgncDefaultTermios;
-   brd->SerialDriver.driver_name = DRVSTR;
-   brd->SerialDriver.flags = (TTY_DRIVER_REAL_RAW |
+   brd->serial_driver.name = brd->SerialName;
+   brd->serial_driver.name_base = 0;
+   brd->serial_driver.major = 0;
+   brd->serial_driver.minor_start = 0;
+   brd->serial_driver.num = brd->maxports;
+   brd->serial_driver.type = TTY_DRIVER_TYPE_SERIAL;
+   brd->serial_driver.subtype = SERIAL_TYPE_NORMAL;
+   brd->serial_driver.init_termios = DgncDefaultTermios;
+   brd->serial_driver.driver_name = DRVSTR;
+   brd->serial_driver.flags = (TTY_DRIVER_REAL_RAW |
   TTY_DRIVER_DYNAMIC_DEV |
   TTY_DRIVER_HARDWARE_BREAK);
 
@@ -199,28 +199,28 @@ int dgnc_tty_register(struct dgnc_board *brd)
 * The kernel wants space to store pointers to
 * tty_struct's and termios's.
 */
-   brd->SerialDriver.ttys = kcalloc(brd->maxports,
-sizeof(*brd->SerialDriver.ttys),
+   brd->serial_driver.ttys = kcalloc(brd->maxports,
+sizeof(*brd->serial_driver.ttys),
 GFP_KERNEL);
-   if (!brd->SerialDriver.ttys)
+   if (!brd->serial_driver.ttys)
return -ENOMEM;
 
-   kref_init(&brd->SerialDriver.kref);
-   brd->SerialDriver.termios = kcalloc(brd->maxports,
-   sizeof(*brd->SerialDriver.termios),
+   kref_init(&brd->serial_driver.kref);
+   brd->serial_driver.termios = kcalloc(brd->maxports,
+   sizeof(*brd->serial_driver.termios),
GFP_KERNEL);
-   if (!brd->SerialDriver.termios)
+   if (!brd->serial_driver.termios)
return -ENOMEM;
 
/*
 * Entry points for driver.  Called by the kernel from
 * tty_io.c and n_tty.c.
 */
-   tty_set_operations(&brd->SerialDriver, &dgnc_tty_ops);
+   tty_set_operations(&brd->serial_driver, &dgnc_tty_ops);
 
if (!brd->dgnc_Major_Serial_Registered) {
/* Register tty devices */
-   rc = tty_register_driver(&brd->SerialDriver);
+   rc = tty_register_driver(&brd->serial_driver);
if (rc < 0) {
dev_dbg(&brd->pdev->dev,
"Can't register tty device (%d)\n", rc);
@@ -234,19 +234,19 @@ int dgnc_tty_register(struct dgnc_board *brd)
 * again, separately so we don't get the LD confused about what major
 * we are when we get into the dgnc_tty_open() routine.
 */
-   brd->PrintDriver.magic = TTY_DRIVER_MAGIC;
+   brd->print_driver.magic = TTY_DRIVER_MAGIC;
snprintf(brd->PrintName, MAXTTYNAMELEN, "pr_dgnc_%d_", brd->boardnum);
 
-   brd->PrintDriver.name = brd->PrintName;
-   brd->PrintDriver.name_base = 0;
-   brd->PrintDriver.major = brd->SerialDriver.major;
-   brd->PrintDriver.minor_start = 0x80;
-   brd->PrintDriver.num = brd->maxports;
-   brd->PrintDriver.type = TTY_DRIVER_TYPE_SERIAL;
-   brd->Prin

Re: [PATCH] Drivers: hv: vmbus: handle various crash scenarios

2016-03-22 Thread Vitaly Kuznetsov
KY Srinivasan  writes:

>> -Original Message-
>> From: Vitaly Kuznetsov [mailto:vkuzn...@redhat.com]
>> Sent: Monday, March 21, 2016 12:52 AM
>> To: KY Srinivasan 
>> Cc: de...@linuxdriverproject.org; linux-ker...@vger.kernel.org; Haiyang
>> Zhang ; Alex Ng (LIS) ;
>> Radim Krcmar ; Cathy Avery 
>> Subject: Re: [PATCH] Drivers: hv: vmbus: handle various crash scenarios
>> 
>> KY Srinivasan  writes:
>> 
>> >> -Original Message-
>> >> From: Vitaly Kuznetsov [mailto:vkuzn...@redhat.com]
>> >> Sent: Friday, March 18, 2016 5:33 AM
>> >> To: de...@linuxdriverproject.org
>> >> Cc: linux-ker...@vger.kernel.org; KY Srinivasan ;
>> >> Haiyang Zhang ; Alex Ng (LIS)
>> >> ; Radim Krcmar ; Cathy
>> >> Avery 
>> >> Subject: [PATCH] Drivers: hv: vmbus: handle various crash scenarios
>> >>
>> >> Kdump keeps biting. Turns out CHANNELMSG_UNLOAD_RESPONSE is
>> always
>> >> delivered to CPU0 regardless of what CPU we're sending
>> >> CHANNELMSG_UNLOAD
>> >> from. vmbus_wait_for_unload() doesn't account for the fact that in case
>> >> we're crashing on some other CPU and CPU0 is still alive and operational
>> >> CHANNELMSG_UNLOAD_RESPONSE will be delivered there completing
>> >> vmbus_connection.unload_event, our wait on the current CPU will never
>> >> end.
>> >
>> > What was the host you were testing on?
>> >
>> 
>> I was testing on both 2012R2 and 2016TP4. The bug is easily reproducible
>> by forcing crash on a secondary CPU, e.g.:
>
> Prior to 2012R2, all messages would be delivered on CPU0 and this includes 
> CHANNELMSG_UNLOAD_RESPONSE.
> For this reason we don't support kexec on pre-2012 R2 hosts. On 2012. From 
> 2012 R2 on, all vmbus 
> messages (responses) will be delivered on  the CPU that we initially set up - 
> look at the code in
> vmbus_negotiate_version().

Ok, missed that. In that case we need to remember which CPU it was --
I'll add this in v2.

> So on post 2012 R2 hosts, the response to CHANNELMSG_UNLOAD_RESPONSE
> will be delivered on the CPU where we initiate the contact with the host - 
> CHANNELMSG_INITIATE_CONTACT message.
> So, maybe we can stash away the CPU on which we made the initial contact and 
> poll the state on that CPU
> to make forward progress in the case of crash.

Yes, we can't have any expectation about other CPUs on crash as they can
be in any state (crashing also, hanging on some mutex/spinlock/...,) so
we need to use current CPU only. I'll fix and resend.

Thanks!

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


Re: [PATCH 3/5] Drivers: hv: vmbus: Fix a bug in hv_need_to_signal_on_read()

2016-03-22 Thread Vitaly Kuznetsov
KY Srinivasan  writes:

>> -Original Message-
>> From: Vitaly Kuznetsov [mailto:vkuzn...@redhat.com]
>> Sent: Monday, March 21, 2016 1:19 AM
>> To: KY Srinivasan 
>> Cc: gre...@linuxfoundation.org; linux-ker...@vger.kernel.org;
>> de...@linuxdriverproject.org; o...@aepfle.de; a...@canonical.com;
>> jasow...@redhat.com; sta...@vger.kernel.org
>> Subject: Re: [PATCH 3/5] Drivers: hv: vmbus: Fix a bug in
>> hv_need_to_signal_on_read()
>> 
>> "K. Y. Srinivasan"  writes:
>> 
>> > We need to issue a full memory barrier prior making a signalling
>> > decision.
>> 
>> Any reason this should be mb()? This is pretty strong and will probably
>> lead to performace regression ... and, btw, we have another mb() in
>> hv_ringbuffer_read().
>> 
>> Could you please describe the scenarion you're trying to protect against
>> so we could search for a better solution?
>
> If the reading of the pend_sz (in the function hv_need_to_signal_on_read)
> were to be reordered and read before we commit the new read index we could 
> have a problem.


If these are two reads we can add a lightweight barrier just preventing
compiler from reordering (e.g. smp_rmb()), right?

> If the host were to set the pending_sz after we have sampled pending_sz
> and go to sleep before we commit the read index, we could miss sending
> the interrupt.

so write and then we read and we need to prevent reordering... not sure
how to get rid on mb() then ...

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


Re: [PATCH] staging: dgnc: fix camelcase of SerialDriver and PrintDriver

2016-03-22 Thread walter harms

You have send this patch before, right ?
then it is a good custom to have something like: [Patch V2] in the
subject line. In the comment you should write somethink like

v2:  fix withspace damage
v1:  fix issue

Otherwise none of the reviewer maintainer will see what was changes.
Sometimes patch run a few rounds before applied.

just my two cents

re,
 wh

Am 22.03.2016 10:20, schrieb Daeseok Youn:
> fix the checkpatch.pl warning about CamelCase.
> 
> Signed-off-by: Daeseok Youn 
> ---
>  drivers/staging/dgnc/dgnc_driver.h |   4 +-
>  drivers/staging/dgnc/dgnc_tty.c| 118 
> ++---
>  2 files changed, 61 insertions(+), 61 deletions(-)
> 
> diff --git a/drivers/staging/dgnc/dgnc_driver.h 
> b/drivers/staging/dgnc/dgnc_driver.h
> index e4be81b..953c891 100644
> --- a/drivers/staging/dgnc/dgnc_driver.h
> +++ b/drivers/staging/dgnc/dgnc_driver.h
> @@ -202,9 +202,9 @@ struct dgnc_board {
>* to our channels.
>*/
>  
> - struct tty_driver   SerialDriver;
> + struct tty_driver serial_driver;
>   charSerialName[200];
> - struct tty_driver   PrintDriver;
> + struct tty_driver print_driver;
>   charPrintName[200];
>  
>   booldgnc_Major_Serial_Registered;
> diff --git a/drivers/staging/dgnc/dgnc_tty.c b/drivers/staging/dgnc/dgnc_tty.c
> index bcd2bdf..081ac75 100644
> --- a/drivers/staging/dgnc/dgnc_tty.c
> +++ b/drivers/staging/dgnc/dgnc_tty.c
> @@ -178,20 +178,20 @@ int dgnc_tty_register(struct dgnc_board *brd)
>  {
>   int rc = 0;
>  
> - brd->SerialDriver.magic = TTY_DRIVER_MAGIC;
> + brd->serial_driver.magic = TTY_DRIVER_MAGIC;
>  
>   snprintf(brd->SerialName, MAXTTYNAMELEN, "tty_dgnc_%d_", brd->boardnum);
>  
> - brd->SerialDriver.name = brd->SerialName;
> - brd->SerialDriver.name_base = 0;
> - brd->SerialDriver.major = 0;
> - brd->SerialDriver.minor_start = 0;
> - brd->SerialDriver.num = brd->maxports;
> - brd->SerialDriver.type = TTY_DRIVER_TYPE_SERIAL;
> - brd->SerialDriver.subtype = SERIAL_TYPE_NORMAL;
> - brd->SerialDriver.init_termios = DgncDefaultTermios;
> - brd->SerialDriver.driver_name = DRVSTR;
> - brd->SerialDriver.flags = (TTY_DRIVER_REAL_RAW |
> + brd->serial_driver.name = brd->SerialName;
> + brd->serial_driver.name_base = 0;
> + brd->serial_driver.major = 0;
> + brd->serial_driver.minor_start = 0;
> + brd->serial_driver.num = brd->maxports;
> + brd->serial_driver.type = TTY_DRIVER_TYPE_SERIAL;
> + brd->serial_driver.subtype = SERIAL_TYPE_NORMAL;
> + brd->serial_driver.init_termios = DgncDefaultTermios;
> + brd->serial_driver.driver_name = DRVSTR;
> + brd->serial_driver.flags = (TTY_DRIVER_REAL_RAW |
>  TTY_DRIVER_DYNAMIC_DEV |
>  TTY_DRIVER_HARDWARE_BREAK);
>  
> @@ -199,28 +199,28 @@ int dgnc_tty_register(struct dgnc_board *brd)
>* The kernel wants space to store pointers to
>* tty_struct's and termios's.
>*/
> - brd->SerialDriver.ttys = kcalloc(brd->maxports,
> -  sizeof(*brd->SerialDriver.ttys),
> + brd->serial_driver.ttys = kcalloc(brd->maxports,
> +  sizeof(*brd->serial_driver.ttys),
>GFP_KERNEL);
> - if (!brd->SerialDriver.ttys)
> + if (!brd->serial_driver.ttys)
>   return -ENOMEM;
>  
> - kref_init(&brd->SerialDriver.kref);
> - brd->SerialDriver.termios = kcalloc(brd->maxports,
> - sizeof(*brd->SerialDriver.termios),
> + kref_init(&brd->serial_driver.kref);
> + brd->serial_driver.termios = kcalloc(brd->maxports,
> + sizeof(*brd->serial_driver.termios),
>   GFP_KERNEL);
> - if (!brd->SerialDriver.termios)
> + if (!brd->serial_driver.termios)
>   return -ENOMEM;
>  
>   /*
>* Entry points for driver.  Called by the kernel from
>* tty_io.c and n_tty.c.
>*/
> - tty_set_operations(&brd->SerialDriver, &dgnc_tty_ops);
> + tty_set_operations(&brd->serial_driver, &dgnc_tty_ops);
>  
>   if (!brd->dgnc_Major_Serial_Registered) {
>   /* Register tty devices */
> - rc = tty_register_driver(&brd->SerialDriver);
> + rc = tty_register_driver(&brd->serial_driver);
>   if (rc < 0) {
>   dev_dbg(&brd->pdev->dev,
>   "Can't register tty device (%d)\n", rc);
> @@ -234,19 +234,19 @@ int dgnc_tty_register(struct dgnc_board *brd)
>* again, separately so we don't get the LD confused about what major
>* we are when we get into the dgnc_tty_open() routine.
>*/
> - brd->PrintDriver.m

[PATCH] Skein:move macros into appropriate header files

2016-03-22 Thread Ming Li
hi, i move macros into appropriate header files.  


regards,


Signed-off-by: Ming Li 

---
 drivers/staging/skein/skein_block.c | 322 
 drivers/staging/skein/skein_block.h | 322 +++-
 2 files changed, 321 insertions(+), 323 deletions(-)

diff --git a/drivers/staging/skein/skein_block.c 
b/drivers/staging/skein/skein_block.c
index 45b4732..74aa490 100644
--- a/drivers/staging/skein/skein_block.c
+++ b/drivers/staging/skein/skein_block.c
@@ -18,328 +18,6 @@
 #include "skein_base.h"
 #include "skein_block.h"
 
-#ifndef SKEIN_USE_ASM
-#define SKEIN_USE_ASM   (0) /* default is all C code (no ASM) */
-#endif
-
-#ifndef SKEIN_LOOP
-#define SKEIN_LOOP 001 /* default: unroll 256 and 512, but not 1024 */
-#endif
-
-#define BLK_BITS(WCNT * 64) /* some useful definitions for code here */
-#define KW_TWK_BASE (0)
-#define KW_KEY_BASE (3)
-#define ks  (kw + KW_KEY_BASE)
-#define ts  (kw + KW_TWK_BASE)
-
-#ifdef SKEIN_DEBUG
-#define debug_save_tweak(ctx)   \
-{   \
-   ctx->h.tweak[0] = ts[0];\
-   ctx->h.tweak[1] = ts[1];\
-}
-#else
-#define debug_save_tweak(ctx)
-#endif
-
-#if !(SKEIN_USE_ASM & 256)
-#undef  RCNT
-#define RCNT (SKEIN_256_ROUNDS_TOTAL / 8)
-#ifdef SKEIN_LOOP /* configure how much to unroll the loop */
-#define SKEIN_UNROLL_256 (((SKEIN_LOOP) / 100) % 10)
-#else
-#define SKEIN_UNROLL_256 (0)
-#endif
-
-#if SKEIN_UNROLL_256
-#if (RCNT % SKEIN_UNROLL_256)
-#error "Invalid SKEIN_UNROLL_256" /* sanity check on unroll count */
-#endif
-#endif
-#define ROUND256(p0, p1, p2, p3, ROT, r_num) \
-   do { \
-   X##p0 += X##p1;  \
-   X##p1 = rotl_64(X##p1, ROT##_0); \
-   X##p1 ^= X##p0;  \
-   X##p2 += X##p3;  \
-   X##p3 = rotl_64(X##p3, ROT##_1); \
-   X##p3 ^= X##p2;  \
-   } while (0)
-
-#if SKEIN_UNROLL_256 == 0
-#define R256(p0, p1, p2, p3, ROT, r_num) /* fully unrolled */ \
-   ROUND256(p0, p1, p2, p3, ROT, r_num)
-
-#define I256(R) \
-   do {\
-   /* inject the key schedule value */ \
-   X0   += ks[((R) + 1) % 5];  \
-   X1   += ks[((R) + 2) % 5] + ts[((R) + 1) % 3];  \
-   X2   += ks[((R) + 3) % 5] + ts[((R) + 2) % 3];  \
-   X3   += ks[((R) + 4) % 5] + (R) + 1;\
-   } while (0)
-#else
-/* looping version */
-#define R256(p0, p1, p2, p3, ROT, r_num) ROUND256(p0, p1, p2, p3, ROT, r_num)
-
-#define I256(R) \
-   do {\
-   /* inject the key schedule value */ \
-   X0 += ks[r + (R) + 0];  \
-   X1 += ks[r + (R) + 1] + ts[r + (R) + 0];\
-   X2 += ks[r + (R) + 2] + ts[r + (R) + 1];\
-   X3 += ks[r + (R) + 3] + r + (R);\
-   /* rotate key schedule */   \
-   ks[r + (R) + 4] = ks[r + (R) - 1];  \
-   ts[r + (R) + 2] = ts[r + (R) - 1];  \
-   } while (0)
-#endif
-#define R256_8_ROUNDS(R)\
-   do {\
-   R256(0, 1, 2, 3, R_256_0, 8 * (R) + 1); \
-   R256(0, 3, 2, 1, R_256_1, 8 * (R) + 2); \
-   R256(0, 1, 2, 3, R_256_2, 8 * (R) + 3); \
-   R256(0, 3, 2, 1, R_256_3, 8 * (R) + 4); \
-   I256(2 * (R));  \
-   R256(0, 1, 2, 3, R_256_4, 8 * (R) + 5); \
-   R256(0, 3, 2, 1, R_256_5, 8 * (R) + 6); \
-   R256(0, 1, 2, 3, R_256_6, 8 * (R) + 7); \
-   R256(0, 3, 2, 1, R_256_7, 8 * (R) + 8); \
-   I256(2 * (R) + 1);  \
-   } while (0)
-
-#define R256_UNROLL_R(NN) \
-   ((SKEIN_UNROLL_256 == 0 &&\
-   SKEIN_256_ROUNDS_TOTAL / 8 > (NN)) || \
-   (SKEIN_UNROLL_256 > (NN)))
-
-#if  (SKEIN_UNROLL_256 > 14)
-#error  "need more unrolling in skein_256_process_block"
-#endif
-#endif
-
-#if !(SKEIN_USE_ASM & 512)
-#undef  RCNT
-#define RCNT  (SKEIN_512_ROUNDS_TOTAL/8)
-
-#ifdef SKEIN_LOOP /* configure how much to unroll the loop */
-#define SKEIN_UNROLL_512 (((SKEIN_LOOP)/10)%10)
-#else
-#define SKEIN_UNROLL_512 (0)
-#endif
-
-#if SKEIN_UNROLL_512
-#if (RCNT % SKEIN_UNROLL_512)
-#error "Invalid SKEIN_UNROLL_512" /* sanity check on unroll count */
-#endif
-#endif
-#define ROUND512(p0, p1, p2, p3, p4, p5, p6, p7, ROT, r_num)\
-   do {  

[PATCH] staging:vt6656:Fixed multiple logical comparisions warnings

2016-03-22 Thread Parth Sane
Using comparison to false and true is error prone. Fixed multiple warnings as
per checkpatch guidelines.
 
Signed-off-by: Parth Sane 
---
 drivers/staging/vt6656/wcmd.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/vt6656/wcmd.c b/drivers/staging/vt6656/wcmd.c
index 4846a89..95faaeb 100644
--- a/drivers/staging/vt6656/wcmd.c
+++ b/drivers/staging/vt6656/wcmd.c
@@ -97,7 +97,7 @@ void vnt_run_command(struct work_struct *work)
if (test_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags))
return;
 
-   if (priv->cmd_running != true)
+   if (!priv->cmd_running)
return;
 
switch (priv->command_state) {
@@ -143,13 +143,13 @@ void vnt_run_command(struct work_struct *work)
 
if (priv->rx_antenna_sel == 0) {
priv->rx_antenna_sel = 1;
-   if (priv->tx_rx_ant_inv == true)
+   if (priv->tx_rx_ant_inv)
vnt_set_antenna_mode(priv, ANT_RXA);
else
vnt_set_antenna_mode(priv, ANT_RXB);
} else {
priv->rx_antenna_sel = 0;
-   if (priv->tx_rx_ant_inv == true)
+   if (priv->tx_rx_ant_inv)
vnt_set_antenna_mode(priv, ANT_RXB);
else
vnt_set_antenna_mode(priv, ANT_RXA);
@@ -174,7 +174,7 @@ int vnt_schedule_command(struct vnt_private *priv, enum 
vnt_cmd command)
ADD_ONE_WITH_WRAP_AROUND(priv->cmd_enqueue_idx, CMD_Q_SIZE);
priv->free_cmd_queue--;
 
-   if (priv->cmd_running == false)
+   if (!priv->cmd_running)
vnt_cmd_complete(priv);
 
return true;
-- 
1.9.1

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


Re: [PATCH 3/3] staging: dgnc: use tty_alloc_driver instead of kcalloc

2016-03-22 Thread Greg KH
On Tue, Mar 22, 2016 at 04:40:24PM +0900, DaeSeok Youn wrote:
> 2016-03-22 6:05 GMT+09:00 Greg KH :
> > On Mon, Mar 14, 2016 at 01:29:00PM +0900, Daeseok Youn wrote:
> >> the tty_alloc_driver() can allocate memory for ttys and termios.
> >> And also it can release allocated memory easly with using
> >> put_tty_driver().
> >>
> >> Signed-off-by: Daeseok Youn 
> >
> > But you broke the driver in the previous patch, you can't do that, each
> > patch has to be 'stand-alone'.
> I am not sure about 'stand-alone'. this patch has to have dependency on
> previous patch..

Yes, that is ok, but your first patch said it was just function
renaming, and then the second patch broke functionality, and the third
fixed it up.  You should have a working kernel at each step in your
patch series, which you did not.

> And I have a question not related this thread,
> I had been waiting my patches merged and also have other patches on
> same file(in case of dgnc).
> I couldn't send next patches until previous patches are taken.
> How can I manage my patches for this case?

Just send your new patches and say they depend on the previous ones.  My
staging patch queue is almost empty at the moment so odds are I have
already applied, or rejected them.

thanks,

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


Re: [PATCH] Staging: wlan-ng: moved memset() calls after copy_from_user() call

2016-03-22 Thread Greg KH
On Tue, Mar 22, 2016 at 03:02:00PM +0200, Claudiu Beznea wrote:
> I was guided by the principle that every instruction counts, no matter the
> execution context.

But you have to be able to actually measure the difference, and here you
can't.

thanks,

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


Re: [PATCH] Drivers: hv: vmbus: handle various crash scenarios

2016-03-22 Thread Vitaly Kuznetsov
KY Srinivasan  writes:

>> -Original Message-
>> From: Vitaly Kuznetsov [mailto:vkuzn...@redhat.com]
>> Sent: Monday, March 21, 2016 12:52 AM
>> To: KY Srinivasan 
>> Cc: de...@linuxdriverproject.org; linux-ker...@vger.kernel.org; Haiyang
>> Zhang ; Alex Ng (LIS) ;
>> Radim Krcmar ; Cathy Avery 
>> Subject: Re: [PATCH] Drivers: hv: vmbus: handle various crash scenarios
>> 
>> KY Srinivasan  writes:
>> 
>> >> -Original Message-
>> >> From: Vitaly Kuznetsov [mailto:vkuzn...@redhat.com]
>> >> Sent: Friday, March 18, 2016 5:33 AM
>> >> To: de...@linuxdriverproject.org
>> >> Cc: linux-ker...@vger.kernel.org; KY Srinivasan ;
>> >> Haiyang Zhang ; Alex Ng (LIS)
>> >> ; Radim Krcmar ; Cathy
>> >> Avery 
>> >> Subject: [PATCH] Drivers: hv: vmbus: handle various crash scenarios
>> >>
>> >> Kdump keeps biting. Turns out CHANNELMSG_UNLOAD_RESPONSE is
>> always
>> >> delivered to CPU0 regardless of what CPU we're sending
>> >> CHANNELMSG_UNLOAD
>> >> from. vmbus_wait_for_unload() doesn't account for the fact that in case
>> >> we're crashing on some other CPU and CPU0 is still alive and operational
>> >> CHANNELMSG_UNLOAD_RESPONSE will be delivered there completing
>> >> vmbus_connection.unload_event, our wait on the current CPU will never
>> >> end.
>> >
>> > What was the host you were testing on?
>> >
>> 
>> I was testing on both 2012R2 and 2016TP4. The bug is easily reproducible
>> by forcing crash on a secondary CPU, e.g.:
>
> Prior to 2012R2, all messages would be delivered on CPU0 and this includes 
> CHANNELMSG_UNLOAD_RESPONSE.
> For this reason we don't support kexec on pre-2012 R2 hosts. On 2012. From 
> 2012 R2 on, all vmbus 
> messages (responses) will be delivered on  the CPU that we initially set up - 
> look at the code in
> vmbus_negotiate_version(). So on post 2012 R2 hosts, the response to 
> CHANNELMSG_UNLOAD_RESPONSE
> will be delivered on the CPU where we initiate the contact with the
> host - CHANNELMSG_INITIATE_CONTACT message.

Unfortunatelly there is a descrepancy between WS2012R2 and WS2016TP4. On
WS2012R2 what you're saying is true and all messages including
CHANNELMSG_UNLOAD_RESPONSE are delivered to the CPU we used for initial
contact. On WS2016TP4 CHANNELMSG_UNLOAD_RESPONSE seems to be a special
case and it is always delivered to CPU0, no matter which CPU we used for
initial contact. This can be a host bug. You can use the attached patch
to see the issue.

For now I can suggest we check message pages for all CPUs from
vmbus_wait_for_unload(). We can race with other CPUs again but we don't
care as we're checking for completion_done() in the loop as well. I'll
try this approach.

-- 
  Vitaly

>From 27170c1bb8f21f7b20c1716c1df65e4812b421f8 Mon Sep 17 00:00:00 2001
From: Vitaly Kuznetsov 
Date: Thu, 17 Mar 2016 14:41:07 +0100
Subject: [PATCH] Drivers: hv: vmbus: handle various crash scenarios

Kdump keeps biting. Turns out CHANNELMSG_UNLOAD_RESPONSE is always
delivered to the cpu which was used to initiate contact regardless of what
CPU we're sending CHANNELMSG_UNLOAD from. vmbus_wait_for_unload() doesn't
account for the fact that in case we're crashing on some other CPU and the
CPU which was used to initate contact is still alive and operational
CHANNELMSG_UNLOAD_RESPONSE will be delivered there completing
vmbus_connection.unload_event, our wait on the current CPU will never
end.

Do the following:
1) Remember the CPU we used to initiate contact in vmbus_connection.

1) Check for completion_done() in the loop. In case interrupt handler is
   still alive we'll get the confirmation we need.

2) Always read the init_cpu's message page as CHANNELMSG_UNLOAD_RESPONSE
   will be delivered there. We can race with still-alive interrupt handler
   doing the same but we don't care as we're checking completion_done()
   now.

3) Cleanup message pages on all CPUs. This is required (at least for the
   current CPU as we're clearing some other CPU's messages now but we may
   want to bring up additional CPUs on crash) as new messages won't be
   delivered till we consume what's pending. On boot we'll place message
   pages somewhere else and we won't be able to read stale messages.

Signed-off-by: Vitaly Kuznetsov 
---
Changes since v1:
- Use init_cpu instead of CPU0 [K. Y. Srinivasan]
- Style changes in vmbus_wait_for_unload [Radim Krcmar]
---
 drivers/hv/channel_mgmt.c | 39 ---
 drivers/hv/connection.c   | 10 +++---
 drivers/hv/hyperv_vmbus.h |  3 +++
 drivers/hv/vmbus_drv.c|  1 +
 4 files changed, 43 insertions(+), 10 deletions(-)

diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c
index 38b682ba..2fa526d 100644
--- a/drivers/hv/channel_mgmt.c
+++ b/drivers/hv/channel_mgmt.c
@@ -597,28 +597,53 @@ static void init_vp_index(struct vmbus_channel *channel, u16 dev_type)
 
 static void vmbus_wait_for_unload(void)
 {
-	int cpu = smp_processor_id();
-	void *page_addr = hv_context.synic_message_page[cpu];
+	int cpu;
+	void *page_addr =
+

RE: [PATCH] Drivers: hv: vmbus: handle various crash scenarios

2016-03-22 Thread KY Srinivasan


> -Original Message-
> From: Vitaly Kuznetsov [mailto:vkuzn...@redhat.com]
> Sent: Tuesday, March 22, 2016 7:01 AM
> To: KY Srinivasan 
> Cc: de...@linuxdriverproject.org; linux-ker...@vger.kernel.org; Haiyang
> Zhang ; Alex Ng (LIS) ;
> Radim Krcmar ; Cathy Avery 
> Subject: Re: [PATCH] Drivers: hv: vmbus: handle various crash scenarios
> 
> KY Srinivasan  writes:
> 
> >> -Original Message-
> >> From: Vitaly Kuznetsov [mailto:vkuzn...@redhat.com]
> >> Sent: Monday, March 21, 2016 12:52 AM
> >> To: KY Srinivasan 
> >> Cc: de...@linuxdriverproject.org; linux-ker...@vger.kernel.org; Haiyang
> >> Zhang ; Alex Ng (LIS)
> ;
> >> Radim Krcmar ; Cathy Avery
> 
> >> Subject: Re: [PATCH] Drivers: hv: vmbus: handle various crash scenarios
> >>
> >> KY Srinivasan  writes:
> >>
> >> >> -Original Message-
> >> >> From: Vitaly Kuznetsov [mailto:vkuzn...@redhat.com]
> >> >> Sent: Friday, March 18, 2016 5:33 AM
> >> >> To: de...@linuxdriverproject.org
> >> >> Cc: linux-ker...@vger.kernel.org; KY Srinivasan ;
> >> >> Haiyang Zhang ; Alex Ng (LIS)
> >> >> ; Radim Krcmar ;
> Cathy
> >> >> Avery 
> >> >> Subject: [PATCH] Drivers: hv: vmbus: handle various crash scenarios
> >> >>
> >> >> Kdump keeps biting. Turns out CHANNELMSG_UNLOAD_RESPONSE is
> >> always
> >> >> delivered to CPU0 regardless of what CPU we're sending
> >> >> CHANNELMSG_UNLOAD
> >> >> from. vmbus_wait_for_unload() doesn't account for the fact that in
> case
> >> >> we're crashing on some other CPU and CPU0 is still alive and
> operational
> >> >> CHANNELMSG_UNLOAD_RESPONSE will be delivered there
> completing
> >> >> vmbus_connection.unload_event, our wait on the current CPU will
> never
> >> >> end.
> >> >
> >> > What was the host you were testing on?
> >> >
> >>
> >> I was testing on both 2012R2 and 2016TP4. The bug is easily reproducible
> >> by forcing crash on a secondary CPU, e.g.:
> >
> > Prior to 2012R2, all messages would be delivered on CPU0 and this includes
> CHANNELMSG_UNLOAD_RESPONSE.
> > For this reason we don't support kexec on pre-2012 R2 hosts. On 2012.
> From 2012 R2 on, all vmbus
> > messages (responses) will be delivered on  the CPU that we initially set up 
> > -
> look at the code in
> > vmbus_negotiate_version(). So on post 2012 R2 hosts, the response to
> CHANNELMSG_UNLOAD_RESPONSE
> > will be delivered on the CPU where we initiate the contact with the
> > host - CHANNELMSG_INITIATE_CONTACT message.
> 
> Unfortunatelly there is a descrepancy between WS2012R2 and WS2016TP4.
> On
> WS2012R2 what you're saying is true and all messages including
> CHANNELMSG_UNLOAD_RESPONSE are delivered to the CPU we used for
> initial
> contact. On WS2016TP4 CHANNELMSG_UNLOAD_RESPONSE seems to be a
> special
> case and it is always delivered to CPU0, no matter which CPU we used for
> initial contact. This can be a host bug. You can use the attached patch
> to see the issue.

This looks like a host bug and I will try to get is addressed before ws2016
ships.
> 
> For now I can suggest we check message pages for all CPUs from
> vmbus_wait_for_unload(). We can race with other CPUs again but we don't
> care as we're checking for completion_done() in the loop as well. I'll
> try this approach.
Thank you.

K. Y

> 
> --
>   Vitaly

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


RE: [PATCH 3/5] Drivers: hv: vmbus: Fix a bug in hv_need_to_signal_on_read()

2016-03-22 Thread KY Srinivasan


> -Original Message-
> From: Vitaly Kuznetsov [mailto:vkuzn...@redhat.com]
> Sent: Tuesday, March 22, 2016 2:56 AM
> To: KY Srinivasan 
> Cc: gre...@linuxfoundation.org; linux-ker...@vger.kernel.org;
> de...@linuxdriverproject.org; o...@aepfle.de; a...@canonical.com;
> jasow...@redhat.com; sta...@vger.kernel.org
> Subject: Re: [PATCH 3/5] Drivers: hv: vmbus: Fix a bug in
> hv_need_to_signal_on_read()
> 
> KY Srinivasan  writes:
> 
> >> -Original Message-
> >> From: Vitaly Kuznetsov [mailto:vkuzn...@redhat.com]
> >> Sent: Monday, March 21, 2016 1:19 AM
> >> To: KY Srinivasan 
> >> Cc: gre...@linuxfoundation.org; linux-ker...@vger.kernel.org;
> >> de...@linuxdriverproject.org; o...@aepfle.de; a...@canonical.com;
> >> jasow...@redhat.com; sta...@vger.kernel.org
> >> Subject: Re: [PATCH 3/5] Drivers: hv: vmbus: Fix a bug in
> >> hv_need_to_signal_on_read()
> >>
> >> "K. Y. Srinivasan"  writes:
> >>
> >> > We need to issue a full memory barrier prior making a signalling
> >> > decision.
> >>
> >> Any reason this should be mb()? This is pretty strong and will probably
> >> lead to performace regression ... and, btw, we have another mb() in
> >> hv_ringbuffer_read().
> >>
> >> Could you please describe the scenarion you're trying to protect against
> >> so we could search for a better solution?
> >
> > If the reading of the pend_sz (in the function
> hv_need_to_signal_on_read)
> > were to be reordered and read before we commit the new read index we
> could
> > have a problem.
> 
> 
> If these are two reads we can add a lightweight barrier just preventing
> compiler from reordering (e.g. smp_rmb()), right?
> 
> > If the host were to set the pending_sz after we have sampled pending_sz
> > and go to sleep before we commit the read index, we could miss sending
> > the interrupt.
> 
> so write and then we read and we need to prevent reordering... not sure
> how to get rid on mb() then ...

The other memory barrier in the function (prior to writing the read index)
has been there forever and I am not sure why that needs to be a full barrier.
I feel a read barrier should suffice.

Regards,

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


Re: When and how to commit kerneldoc comments to staging/unisys/*

2016-03-22 Thread Greg KH
On Tue, Mar 22, 2016 at 03:41:04PM +, Kershner, David A wrote:



Please resend without html so it goes to the mailing list...
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


When and how to commit kerneldoc comments to staging/unisys/*

2016-03-22 Thread Kershner, David A
Greg, we are looking at adding kerneldoc style comments for the drivers in 
staging/unisys/*.

Should we be doing this in staging or outside of it? 

If we should, do we have one commit per file or one commit per function?

Thanks,
David Kershner

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


Re: When and how to commit kerneldoc comments to staging/unisys/*

2016-03-22 Thread Greg KH
On Tue, Mar 22, 2016 at 03:51:59PM +, Kershner, David A wrote:
> Greg, we are looking at adding kerneldoc style comments for the drivers in 
> staging/unisys/*.

First off, why?

> Should we be doing this in staging or outside of it? 

I don't understand what you mean by "outside of it"?

> If we should, do we have one commit per file or one commit per function?

What do you think would be the easiest to review if you were on the
receiving end of such changes?

thanks,

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


[PATCH 2/3] staging: comedi: dt282x: remove redundant comedi_check_trigger_arg_min()

2016-03-22 Thread H Hartley Sweeten
The 'convert_arg' sets the acquisition timing of the analog input command.
The maximum speed (the minimum timing) depends on the board 'ai_speed' which
if always >= 4000. Remove the redundant 'min' check,

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/dt282x.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/staging/comedi/drivers/dt282x.c 
b/drivers/staging/comedi/drivers/dt282x.c
index be6a0bc..68ae9d8 100644
--- a/drivers/staging/comedi/drivers/dt282x.c
+++ b/drivers/staging/comedi/drivers/dt282x.c
@@ -684,11 +684,7 @@ static int dt282x_ai_cmdtest(struct comedi_device *dev,
/* Step 3: check if arguments are trivially valid */
 
err |= comedi_check_trigger_arg_is(&cmd->start_arg, 0);
-
err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, 0);
-
-   err |= comedi_check_trigger_arg_min(&cmd->convert_arg, 4000);
-
err |= comedi_check_trigger_arg_min(&cmd->convert_arg, board->ai_speed);
err |= comedi_check_trigger_arg_is(&cmd->scan_end_arg,
   cmd->chanlist_len);
-- 
2.6.3

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


[PATCH 0/3] staging: comedi: dt282x: minor cleanup

2016-03-22 Thread H Hartley Sweeten
Remove some unnecessary/redundant cruft from this driver.

Patch 3 may have an issue due to the +/- symbols...

H Hartley Sweeten (3):
  staging: comedi: dt282x: remove unnecessary comedi_check_trigger_arg_max()
  staging: comedi: dt282x: remove redundant comedi_check_trigger_arg_min()
  staging: comedi: dt282x: remove unnecessary comment

 drivers/staging/comedi/drivers/dt282x.c | 20 
 1 file changed, 20 deletions(-)

-- 
2.6.3

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


[PATCH 1/3] staging: comedi: dt282x: remove unnecessary comedi_check_trigger_arg_max()

2016-03-22 Thread H Hartley Sweeten
Step 4 of the (*do_cmdtest) calls dt282x_ns_to_timer() to work out the
divisor needed to generate the 'convert_arg' timing. If the 'convert_arg'
timing can not be generated, the function returns the max timing that can
be generated.

The Step 3 'max' check of the 'convert_arg' isn't necessary.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/dt282x.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/staging/comedi/drivers/dt282x.c 
b/drivers/staging/comedi/drivers/dt282x.c
index 06a87a1..be6a0bc 100644
--- a/drivers/staging/comedi/drivers/dt282x.c
+++ b/drivers/staging/comedi/drivers/dt282x.c
@@ -689,8 +689,6 @@ static int dt282x_ai_cmdtest(struct comedi_device *dev,
 
err |= comedi_check_trigger_arg_min(&cmd->convert_arg, 4000);
 
-#define SLOWEST_TIMER  (250*(1<<15)*255)
-   err |= comedi_check_trigger_arg_max(&cmd->convert_arg, SLOWEST_TIMER);
err |= comedi_check_trigger_arg_min(&cmd->convert_arg, board->ai_speed);
err |= comedi_check_trigger_arg_is(&cmd->scan_end_arg,
   cmd->chanlist_len);
-- 
2.6.3

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


[PATCH 3/3] staging: comedi: dt282x: remove unnecessary comment

2016-03-22 Thread H Hartley Sweeten
The "Configuration options" are documented in the comedi driver comment
block. Remove the redundant comment before the drivers (*attach) function.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/dt282x.c | 14 --
 1 file changed, 14 deletions(-)

diff --git a/drivers/staging/comedi/drivers/dt282x.c 
b/drivers/staging/comedi/drivers/dt282x.c
index 68ae9d8..888bf6a 100644
--- a/drivers/staging/comedi/drivers/dt282x.c
+++ b/drivers/staging/comedi/drivers/dt282x.c
@@ -1079,20 +1079,6 @@ static int dt282x_initialize(struct comedi_device *dev)
return 0;
 }
 
-/*
-   options:
-   0   i/o base
-   1   irq
-   2   dma1
-   3   dma2
-   4   0=single ended, 1=differential
-   5   ai 0=straight binary, 1=2's comp
-   6   ao0 0=straight binary, 1=2's comp
-   7   ao1 0=straight binary, 1=2's comp
-   8   ai 0=±10 V, 1=0-10 V, 2=±5 V, 3=0-5 V
-   9   ao0 0=±10 V, 1=0-10 V, 2=±5 V, 3=0-5 V, 4=±2.5 V
-   10  ao1 0=±10 V, 1=0-10 V, 2=±5 V, 3=0-5 V, 4=±2.5 V
- */
 static int dt282x_attach(struct comedi_device *dev, struct comedi_devconfig 
*it)
 {
const struct dt282x_board *board = dev->board_ptr;
-- 
2.6.3

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


Re: [PATCH] Staging: most: Remove volatile usage

2016-03-22 Thread Christian Gromm
On Mon, 21 Mar 2016 15:36:54 -0400
Greg KH  wrote:

> On Mon, Mar 21, 2016 at 03:08:41PM +0530, PrasannaKumar Muralidharan wrote:
> > > Are you sure you can just remove these markings?  Does the code work the
> > > same?  What is properly locking these values?  Why were they marked this
> > > way in the first place?
> > 
> > I could not test the change due to lack of hardware.
> > 
> > Given that the code works without lock and as volatile does not
> > guarantee any sort of locking I understand that lock is not necessary.
> > Please correct me if I am wrong.
> > 
> > Could not find the purpose of 'volatile' in the code,
> > 'request_counter' and 'service_counter' are only accessed by the CPU.
> > So I think it can be removed.
> 
> I will need the maintainers of the code to ack this before I can accept
> it...
> 

Since it is _not_ assured that the code will run under all circumstances,
I don't want this patch to be applied at this point.

To be able to decide on the removal of the volatile keyword, we need to run
some tests on real hardware. This ain't something we can tell by just
looking at the code.

We'll add this to our todo list.

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


[PATCH v2] staging: comedi: ni_mio_common: fix the ni_write[blw]() functions

2016-03-22 Thread H Hartley Sweeten
Memory mapped io (dev->mmio) should not also be writing to the ioport
(dev->iobase) registers. Add the missing 'else' to these functions.

Fixes: 0953ee4acca0 ("staging: comedi: ni_mio_common: checkpatch.pl cleanup 
(else not useful)")
Cc:  # 3.17+
Signed-off-by: H Hartley Sweeten 
Reviewed-by: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
v2: add Ian Abbott's Reviewed-by and Fixes/Cc for stable.

 drivers/staging/comedi/drivers/ni_mio_common.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c 
b/drivers/staging/comedi/drivers/ni_mio_common.c
index d1226c9..dcaf7e8 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -246,24 +246,24 @@ static void ni_writel(struct comedi_device *dev, uint32_t 
data, int reg)
 {
if (dev->mmio)
writel(data, dev->mmio + reg);
-
-   outl(data, dev->iobase + reg);
+   else
+   outl(data, dev->iobase + reg);
 }
 
 static void ni_writew(struct comedi_device *dev, uint16_t data, int reg)
 {
if (dev->mmio)
writew(data, dev->mmio + reg);
-
-   outw(data, dev->iobase + reg);
+   else
+   outw(data, dev->iobase + reg);
 }
 
 static void ni_writeb(struct comedi_device *dev, uint8_t data, int reg)
 {
if (dev->mmio)
writeb(data, dev->mmio + reg);
-
-   outb(data, dev->iobase + reg);
+   else
+   outb(data, dev->iobase + reg);
 }
 
 static uint32_t ni_readl(struct comedi_device *dev, int reg)
-- 
2.6.3

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


RE: [PATCH 3/5] Drivers: hv: vmbus: Fix a bug in hv_need_to_signal_on_read()

2016-03-22 Thread KY Srinivasan


> -Original Message-
> From: KY Srinivasan
> Sent: Tuesday, March 22, 2016 7:37 AM
> To: 'Vitaly Kuznetsov' 
> Cc: gre...@linuxfoundation.org; linux-ker...@vger.kernel.org;
> de...@linuxdriverproject.org; o...@aepfle.de; a...@canonical.com;
> jasow...@redhat.com; sta...@vger.kernel.org
> Subject: RE: [PATCH 3/5] Drivers: hv: vmbus: Fix a bug in
> hv_need_to_signal_on_read()
> 
> 
> 
> > -Original Message-
> > From: Vitaly Kuznetsov [mailto:vkuzn...@redhat.com]
> > Sent: Tuesday, March 22, 2016 2:56 AM
> > To: KY Srinivasan 
> > Cc: gre...@linuxfoundation.org; linux-ker...@vger.kernel.org;
> > de...@linuxdriverproject.org; o...@aepfle.de; a...@canonical.com;
> > jasow...@redhat.com; sta...@vger.kernel.org
> > Subject: Re: [PATCH 3/5] Drivers: hv: vmbus: Fix a bug in
> > hv_need_to_signal_on_read()
> >
> > KY Srinivasan  writes:
> >
> > >> -Original Message-
> > >> From: Vitaly Kuznetsov [mailto:vkuzn...@redhat.com]
> > >> Sent: Monday, March 21, 2016 1:19 AM
> > >> To: KY Srinivasan 
> > >> Cc: gre...@linuxfoundation.org; linux-ker...@vger.kernel.org;
> > >> de...@linuxdriverproject.org; o...@aepfle.de; a...@canonical.com;
> > >> jasow...@redhat.com; sta...@vger.kernel.org
> > >> Subject: Re: [PATCH 3/5] Drivers: hv: vmbus: Fix a bug in
> > >> hv_need_to_signal_on_read()
> > >>
> > >> "K. Y. Srinivasan"  writes:
> > >>
> > >> > We need to issue a full memory barrier prior making a signalling
> > >> > decision.
> > >>
> > >> Any reason this should be mb()? This is pretty strong and will probably
> > >> lead to performace regression ... and, btw, we have another mb() in
> > >> hv_ringbuffer_read().
> > >>
> > >> Could you please describe the scenarion you're trying to protect against
> > >> so we could search for a better solution?
> > >
> > > If the reading of the pend_sz (in the function
> > hv_need_to_signal_on_read)
> > > were to be reordered and read before we commit the new read index
> we
> > could
> > > have a problem.
> >
> >
> > If these are two reads we can add a lightweight barrier just preventing
> > compiler from reordering (e.g. smp_rmb()), right?
> >
> > > If the host were to set the pending_sz after we have sampled
> pending_sz
> > > and go to sleep before we commit the read index, we could miss sending
> > > the interrupt.
> >
> > so write and then we read and we need to prevent reordering... not sure
> > how to get rid on mb() then ...
> 
> The other memory barrier in the function (prior to writing the read index)
> has been there forever and I am not sure why that needs to be a full barrier.
> I feel a read barrier should suffice.

I may also look at restructuring these APIs to not always check for signaling.
I will experiment with that scheme to minimize the barrier calls.

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


RE: When and how to commit kerneldoc comments to staging/unisys/*

2016-03-22 Thread Kershner, David A
> -Original Message-
> From: Greg KH [mailto:gre...@linuxfoundation.org]
> Sent: Tuesday, March 22, 2016 11:59 AM
> To: Kershner, David A 
> Cc: driverdev-devel@linuxdriverproject.org; *S-Par-Maintainer
> 
> Subject: Re: When and how to commit kerneldoc comments to
> staging/unisys/*
> 
> On Tue, Mar 22, 2016 at 03:51:59PM +, Kershner, David A wrote:
> > Greg, we are looking at adding kerneldoc style comments for the drivers in
> staging/unisys/*.
> 
> First off, why?

Cause the current state of the documentation in the tree has something to be
desired and is extremely lacking. I just picked kerneldoc style cause it is
definitely better than what we currently have, should we use some other style
guideline?
> 
> > Should we be doing this in staging or outside of it?
> 
> I don't understand what you mean by "outside of it"?

Is the documentation we have in the code good enough for the drivers to move
beyond the staging directory or should they get updated? 

> 
> > If we should, do we have one commit per file or one commit per function?
> 
> What do you think would be the easiest to review if you were on the
> receiving end of such changes?

Understood. 
 
Thanks,
David Kershner
 
> 
> thanks,
> 
> greg k-h
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: When and how to commit kerneldoc comments to staging/unisys/*

2016-03-22 Thread Greg KH
On Tue, Mar 22, 2016 at 05:18:50PM +, Kershner, David A wrote:
> > -Original Message-
> > From: Greg KH [mailto:gre...@linuxfoundation.org]
> > Sent: Tuesday, March 22, 2016 11:59 AM
> > To: Kershner, David A 
> > Cc: driverdev-devel@linuxdriverproject.org; *S-Par-Maintainer
> > 
> > Subject: Re: When and how to commit kerneldoc comments to
> > staging/unisys/*
> > 
> > On Tue, Mar 22, 2016 at 03:51:59PM +, Kershner, David A wrote:
> > > Greg, we are looking at adding kerneldoc style comments for the drivers in
> > staging/unisys/*.
> > 
> > First off, why?
> 
> Cause the current state of the documentation in the tree has something to be
> desired and is extremely lacking. I just picked kerneldoc style cause it is
> definitely better than what we currently have, should we use some other style
> guideline?

No, that's a great style to use, but what exactly are you wanting to
document?  That format is to explain apis, not design decisions and
overall architecture.

> > > Should we be doing this in staging or outside of it?
> > 
> > I don't understand what you mean by "outside of it"?
> 
> Is the documentation we have in the code good enough for the drivers to move
> beyond the staging directory or should they get updated? 

I don't know, haven't looked at it :)

Again, it comes down to what you think needs to be documented.

thanks,

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


[PATCH v2] Drivers: hv: vmbus: handle various crash scenarios

2016-03-22 Thread Vitaly Kuznetsov
Kdump keeps biting. Turns out CHANNELMSG_UNLOAD_RESPONSE is always
delivered to the CPU which was used for initial contact or to CPU0
depending on host version. vmbus_wait_for_unload() doesn't account for
the fact that in case we're crashing on some other CPU we won't get the
CHANNELMSG_UNLOAD_RESPONSE message and our wait on the current CPU will
never end.

Do the following:
1) Check for completion_done() in the loop. In case interrupt handler is
   still alive we'll get the confirmation we need.

2) Read message pages for all CPUs message page as we're unsure where
   CHANNELMSG_UNLOAD_RESPONSE is going to be delivered to. We can race with
   still-alive interrupt handler doing the same, add cmpxchg() to
   vmbus_signal_eom() to not lose CHANNELMSG_UNLOAD_RESPONSE message.

3) Cleanup message pages on all CPUs. This is required (at least for the
   current CPU as we're clearing CPU0 messages now but we may want to bring
   up additional CPUs on crash) as new messages won't be delivered till we
   consume what's pending. On boot we'll place message pages somewhere else
   and we won't be able to read stale messages.

Signed-off-by: Vitaly Kuznetsov 
---
 drivers/hv/channel_mgmt.c | 58 +++
 drivers/hv/hyperv_vmbus.h | 16 +++--
 drivers/hv/vmbus_drv.c|  7 +++---
 3 files changed, 61 insertions(+), 20 deletions(-)

diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c
index 38b682ba..b6c1211 100644
--- a/drivers/hv/channel_mgmt.c
+++ b/drivers/hv/channel_mgmt.c
@@ -597,27 +597,55 @@ static void init_vp_index(struct vmbus_channel *channel, 
u16 dev_type)
 
 static void vmbus_wait_for_unload(void)
 {
-   int cpu = smp_processor_id();
-   void *page_addr = hv_context.synic_message_page[cpu];
-   struct hv_message *msg = (struct hv_message *)page_addr +
- VMBUS_MESSAGE_SINT;
+   int cpu;
+   void *page_addr;
+   struct hv_message *msg;
struct vmbus_channel_message_header *hdr;
-   bool unloaded = false;
+   u32 message_type;
 
+   /*
+* CHANNELMSG_UNLOAD_RESPONSE is always delivered to the CPU which was
+* used for initial contact or to CPU0 depending on host version. When
+* we're crashing on a different CPU let's hope that IRQ handler on
+* the cpu which receives CHANNELMSG_UNLOAD_RESPONSE is still
+* functional and vmbus_unload_response() will complete
+* vmbus_connection.unload_event. If not, the last thing we can do is
+* read message pages for all CPUs directly.
+*/
while (1) {
-   if (READ_ONCE(msg->header.message_type) == HVMSG_NONE) {
-   mdelay(10);
-   continue;
-   }
+   if (completion_done(&vmbus_connection.unload_event))
+   break;
 
-   hdr = (struct vmbus_channel_message_header *)msg->u.payload;
-   if (hdr->msgtype == CHANNELMSG_UNLOAD_RESPONSE)
-   unloaded = true;
+   for_each_online_cpu(cpu) {
+   page_addr = hv_context.synic_message_page[cpu];
+   msg = (struct hv_message *)page_addr +
+   VMBUS_MESSAGE_SINT;
 
-   vmbus_signal_eom(msg);
+   message_type = READ_ONCE(msg->header.message_type);
+   if (message_type == HVMSG_NONE)
+   continue;
 
-   if (unloaded)
-   break;
+   hdr = (struct vmbus_channel_message_header *)
+   msg->u.payload;
+
+   if (hdr->msgtype == CHANNELMSG_UNLOAD_RESPONSE)
+   complete(&vmbus_connection.unload_event);
+
+   vmbus_signal_eom(msg, message_type);
+   }
+
+   mdelay(10);
+   }
+
+   /*
+* We're crashing and already got the UNLOAD_RESPONSE, cleanup all
+* maybe-pending messages on all CPUs to be able to receive new
+* messages after we reconnect.
+*/
+   for_each_online_cpu(cpu) {
+   page_addr = hv_context.synic_message_page[cpu];
+   msg = (struct hv_message *)page_addr + VMBUS_MESSAGE_SINT;
+   msg->header.message_type = HVMSG_NONE;
}
 }
 
diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
index 12321b9..113a8f5 100644
--- a/drivers/hv/hyperv_vmbus.h
+++ b/drivers/hv/hyperv_vmbus.h
@@ -620,9 +620,21 @@ extern struct vmbus_channel_message_table_entry
channel_message_table[CHANNELMSG_COUNT];
 
 /* Free the message slot and signal end-of-message if required */
-static inline void vmbus_signal_eom(struct hv_message *msg)
+static inline void vmbus_signal_eom(struct hv_message *msg, u32 old_msg_type)
 {
-   msg->header.message_type = HVMSG_NONE;
+   /*
+* On cr

[PATCH 3/6] staging: comedi: ni_labpc_common: tidy up block comments

2016-03-22 Thread H Hartley Sweeten
Fix the checkpatch.pl issues:
WARNING: Block comments use a trailing */ on a separate line

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_labpc_common.c | 59 ++--
 drivers/staging/comedi/drivers/z8536.h   | 89 +---
 2 files changed, 85 insertions(+), 63 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_labpc_common.c 
b/drivers/staging/comedi/drivers/ni_labpc_common.c
index 55ab05e..b0dfb8e 100644
--- a/drivers/staging/comedi/drivers/ni_labpc_common.c
+++ b/drivers/staging/comedi/drivers/ni_labpc_common.c
@@ -84,8 +84,10 @@ static const struct comedi_lrange range_labpc_ao = {
}
 };
 
-/* functions that do inb/outb and readb/writeb so we can use
- * function pointers to decide which to use */
+/*
+ * functions that do inb/outb and readb/writeb so we can use
+ * function pointers to decide which to use
+ */
 static unsigned int labpc_inb(struct comedi_device *dev, unsigned long reg)
 {
return inb(dev->iobase + reg);
@@ -656,19 +658,24 @@ static int labpc_ai_cmd(struct comedi_device *dev, struct 
comedi_subdevice *s)
 
/* figure out what method we will use to transfer data */
if (devpriv->dma &&
-   /* dma unsafe at RT priority,
-* and too much setup time for CMDF_WAKE_EOS */
-   (cmd->flags & (CMDF_WAKE_EOS | CMDF_PRIORITY)) == 0)
+   (cmd->flags & (CMDF_WAKE_EOS | CMDF_PRIORITY)) == 0) {
+   /*
+* dma unsafe at RT priority,
+* and too much setup time for CMDF_WAKE_EOS
+*/
xfer = isa_dma_transfer;
-   else if (/* pc-plus has no fifo-half full interrupt */
-board->is_labpc1200 &&
-/* wake-end-of-scan should interrupt on fifo not empty */
-(cmd->flags & CMDF_WAKE_EOS) == 0 &&
-/* make sure we are taking more than just a few points */
-(cmd->stop_src != TRIG_COUNT || devpriv->count > 256))
+   } else if (board->is_labpc1200 &&
+  (cmd->flags & CMDF_WAKE_EOS) == 0 &&
+  (cmd->stop_src != TRIG_COUNT || devpriv->count > 256)) {
+   /*
+* pc-plus has no fifo-half full interrupt
+* wake-end-of-scan should interrupt on fifo not empty
+* make sure we are taking more than just a few points
+*/
xfer = fifo_half_full_transfer;
-   else
+   } else {
xfer = fifo_not_empty_transfer;
+   }
devpriv->current_transfer = xfer;
 
labpc_ai_set_chan_and_gain(dev, mode, chan, range, aref);
@@ -679,9 +686,11 @@ static int labpc_ai_cmd(struct comedi_device *dev, struct 
comedi_subdevice *s)
/* manual says to set scan enable bit on second pass */
if (mode == MODE_MULT_CHAN_UP || mode == MODE_MULT_CHAN_DOWN) {
devpriv->cmd1 |= CMD1_SCANEN;
-   /* need a brief delay before enabling scan, or scan
-* list will get screwed when you switch
-* between scan up to scan down mode - dunno why */
+   /*
+* Need a brief delay before enabling scan, or scan
+* list will get screwed when you switch between
+* scan up to scan down mode - dunno why.
+*/
udelay(1);
devpriv->write_byte(dev, devpriv->cmd1, CMD1_REG);
}
@@ -728,8 +737,10 @@ static int labpc_ai_cmd(struct comedi_device *dev, struct 
comedi_subdevice *s)
devpriv->cmd4 = 0;
if (cmd->convert_src != TRIG_EXT)
devpriv->cmd4 |= CMD4_ECLKRCV;
-   /* XXX should discard first scan when using interval scanning
-* since manual says it is not synced with scan clock */
+   /*
+* XXX should discard first scan when using interval scanning
+* since manual says it is not synced with scan clock.
+*/
if (!labpc_use_continuous_mode(cmd, mode)) {
devpriv->cmd4 |= CMD4_INTSCAN;
if (cmd->scan_begin_src == TRIG_EXT)
@@ -795,8 +806,10 @@ static int labpc_drain_fifo(struct comedi_device *dev)
return 0;
 }
 
-/* makes sure all data acquired by board is transferred to comedi (used
- * when acquisition is terminated by stop_src == TRIG_EXT). */
+/*
+ * Makes sure all data acquired by board is transferred to comedi (used
+ * when acquisition is terminated by stop_src == TRIG_EXT).
+ */
 static void labpc_drain_dregs(struct comedi_device *dev)
 {
struct labpc_private *devpriv = dev->private;
@@ -907,9 +920,11 @@ static int labpc_ao_insn_write(struct comedi_device *dev,
 
channel = CR_CHAN(insn->chanspec);
 
-   /* turn off pacing of analog output channel */
-   /* note: hardware bug in daqcard-1200 means pacing cannot
-* be independently enabled/disabled for its the two channe

[PATCH 2/6] staging: comedi: ni_labpc_regs.h: tidy up bit defines

2016-03-22 Thread H Hartley Sweeten
As suggested by checkpatch.pl:
CHECK: Prefer using the BIT macro

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_labpc_regs.h | 82 +-
 1 file changed, 41 insertions(+), 41 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_labpc_regs.h 
b/drivers/staging/comedi/drivers/ni_labpc_regs.h
index 2a274a3..8c52179 100644
--- a/drivers/staging/comedi/drivers/ni_labpc_regs.h
+++ b/drivers/staging/comedi/drivers/ni_labpc_regs.h
@@ -9,32 +9,32 @@
  * Register map (all registers are 8-bit)
  */
 #define STAT1_REG  0x00/* R: Status 1 reg */
-#define STAT1_DAVAIL   (1 << 0)
-#define STAT1_OVERRUN  (1 << 1)
-#define STAT1_OVERFLOW (1 << 2)
-#define STAT1_CNTINT   (1 << 3)
-#define STAT1_GATA0(1 << 5)
-#define STAT1_EXTGATA0 (1 << 6)
+#define STAT1_DAVAIL   BIT(0)
+#define STAT1_OVERRUN  BIT(1)
+#define STAT1_OVERFLOW BIT(2)
+#define STAT1_CNTINT   BIT(3)
+#define STAT1_GATA0BIT(5)
+#define STAT1_EXTGATA0 BIT(6)
 #define CMD1_REG   0x00/* W: Command 1 reg */
 #define CMD1_MA(x) (((x) & 0x7) << 0)
-#define CMD1_TWOSCMP   (1 << 3)
+#define CMD1_TWOSCMP   BIT(3)
 #define CMD1_GAIN(x)   (((x) & 0x7) << 4)
-#define CMD1_SCANEN(1 << 7)
+#define CMD1_SCANENBIT(7)
 #define CMD2_REG   0x01/* W: Command 2 reg */
-#define CMD2_PRETRIG   (1 << 0)
-#define CMD2_HWTRIG(1 << 1)
-#define CMD2_SWTRIG(1 << 2)
-#define CMD2_TBSEL (1 << 3)
-#define CMD2_2SDAC0(1 << 4)
-#define CMD2_2SDAC1(1 << 5)
-#define CMD2_LDAC(x)   (1 << (6 + (x)))
+#define CMD2_PRETRIG   BIT(0)
+#define CMD2_HWTRIGBIT(1)
+#define CMD2_SWTRIGBIT(2)
+#define CMD2_TBSEL BIT(3)
+#define CMD2_2SDAC0BIT(4)
+#define CMD2_2SDAC1BIT(5)
+#define CMD2_LDAC(x)   BIT(6 + ((x) & 0x1))
 #define CMD3_REG   0x02/* W: Command 3 reg */
-#define CMD3_DMAEN (1 << 0)
-#define CMD3_DIOINTEN  (1 << 1)
-#define CMD3_DMATCINTEN(1 << 2)
-#define CMD3_CNTINTEN  (1 << 3)
-#define CMD3_ERRINTEN  (1 << 4)
-#define CMD3_FIFOINTEN (1 << 5)
+#define CMD3_DMAEN BIT(0)
+#define CMD3_DIOINTEN  BIT(1)
+#define CMD3_DMATCINTENBIT(2)
+#define CMD3_CNTINTEN  BIT(3)
+#define CMD3_ERRINTEN  BIT(4)
+#define CMD3_FIFOINTEN BIT(5)
 #define ADC_START_CONVERT_REG  0x03/* W: Start Convert reg */
 #define DAC_LSB_REG(x) (0x04 + 2 * (x)) /* W: DAC0/1 LSB reg */
 #define DAC_MSB_REG(x) (0x05 + 2 * (x)) /* W: DAC0/1 MSB reg */
@@ -43,32 +43,32 @@
 #define DMATC_CLEAR_REG0x0a/* W: DMA Interrupt Clear reg */
 #define TIMER_CLEAR_REG0x0c/* W: Timer Interrupt Clear reg 
*/
 #define CMD6_REG   0x0e/* W: Command 6 reg */
-#define CMD6_NRSE  (1 << 0)
-#define CMD6_ADCUNI(1 << 1)
-#define CMD6_DACUNI(x) (1 << (2 + (x)))
-#define CMD6_HFINTEN   (1 << 5)
-#define CMD6_DQINTEN   (1 << 6)
-#define CMD6_SCANUP(1 << 7)
+#define CMD6_NRSE  BIT(0)
+#define CMD6_ADCUNIBIT(1)
+#define CMD6_DACUNI(x) BIT(2 + ((x) & 0x1))
+#define CMD6_HFINTEN   BIT(5)
+#define CMD6_DQINTEN   BIT(6)
+#define CMD6_SCANUPBIT(7)
 #define CMD4_REG   0x0f/* W: Command 3 reg */
-#define CMD4_INTSCAN   (1 << 0)
-#define CMD4_EOIRCV(1 << 1)
-#define CMD4_ECLKDRV   (1 << 2)
-#define CMD4_SEDIFF(1 << 3)
-#define CMD4_ECLKRCV   (1 << 4)
+#define CMD4_INTSCAN   BIT(0)
+#define CMD4_EOIRCVBIT(1)
+#define CMD4_ECLKDRV   BIT(2)
+#define CMD4_SEDIFFBIT(3)
+#define CMD4_ECLKRCV   BIT(4)
 #define DIO_BASE_REG   0x10/* R/W: 8255 DIO base reg */
 #define COUNTER_A_BASE_REG 0x14/* R/W: 8253 Counter A base reg */
 #define COUNTER_B_BASE_REG 0x18/* R/W: 8253 Counter B base reg */
 #define CMD5_REG   0x1c/* W: Command 5 reg */
-#define CMD5_WRTPRT(1 << 2)
-#define CMD5_DITHEREN  (1 << 3)
-#define CMD5_CALDACLD  (1 << 4)
-#define CMD5_SCLK  (1 << 5)
-#define CMD5_SDATA (1 << 6)
-#define CMD5_EEPROMCS  (1 << 7)
+#define CMD5_WRTPRTBIT(2)
+#define CMD5_DITHEREN  BIT(3)
+#define CMD5_CALDACLD  BIT(4)
+#define CMD5_SCLK  BIT(5)
+#define CMD5_SDATA BIT(6)
+#define CMD5_EEPROMCS  BIT(7)
 #define STAT2_REG  0x1d/* R: Status 2 reg */
-#define STAT2_PROMOUT  (1 << 0)
-#define STAT2_OUTA1(1 << 1)
-#define

[PATCH 1/6] staging: comedi: ni_labpc: remove some unnecessary defines

2016-03-22 Thread H Hartley Sweeten
The EEPROM_SIZE and NUM_AO_CHAN defines are only used once and they
don't add any significant clarity to the driver. They are also pretty
generic symbol names. Remove them and just open code the values.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_labpc.h| 3 ---
 drivers/staging/comedi/drivers/ni_labpc_common.c | 6 +++---
 2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_labpc.h 
b/drivers/staging/comedi/drivers/ni_labpc.h
index 83f878a..74db3ba 100644
--- a/drivers/staging/comedi/drivers/ni_labpc.h
+++ b/drivers/staging/comedi/drivers/ni_labpc.h
@@ -19,9 +19,6 @@
 #ifndef _NI_LABPC_H
 #define _NI_LABPC_H
 
-#define EEPROM_SIZE256 /*  256 byte eeprom */
-#define NUM_AO_CHAN2   /*  boards have two analog output channels */
-
 enum transfer_type { fifo_not_empty_transfer, fifo_half_full_transfer,
isa_dma_transfer
 };
diff --git a/drivers/staging/comedi/drivers/ni_labpc_common.c 
b/drivers/staging/comedi/drivers/ni_labpc_common.c
index 863afb2..55ab05e 100644
--- a/drivers/staging/comedi/drivers/ni_labpc_common.c
+++ b/drivers/staging/comedi/drivers/ni_labpc_common.c
@@ -1261,7 +1261,7 @@ int labpc_common_attach(struct comedi_device *dev,
if (board->has_ao) {
s->type = COMEDI_SUBD_AO;
s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_GROUND;
-   s->n_chan   = NUM_AO_CHAN;
+   s->n_chan   = 2;
s->maxdata  = 0x0fff;
s->range_table  = &range_labpc_ao;
s->insn_write   = labpc_ao_insn_write;
@@ -1307,12 +1307,12 @@ int labpc_common_attach(struct comedi_device *dev,
s->type = COMEDI_SUBD_UNUSED;
}
 
-   /* EEPROM */
+   /* EEPROM (256 bytes) */
s = &dev->subdevices[4];
if (board->is_labpc1200) {
s->type = COMEDI_SUBD_MEMORY;
s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL;
-   s->n_chan   = EEPROM_SIZE;
+   s->n_chan   = 256;
s->maxdata  = 0xff;
s->insn_write   = labpc_eeprom_insn_write;
 
-- 
2.6.3

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


[PATCH 6/6] staging: comedi: ni_labpc.h: fix block comment issues

2016-03-22 Thread H Hartley Sweeten
Fix the checkpatch.pl issues:
WARNING: Block comments use * on subsequent lines

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_labpc.h | 30 ++
 1 file changed, 14 insertions(+), 16 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_labpc.h 
b/drivers/staging/comedi/drivers/ni_labpc.h
index 74db3ba..be8d5cd 100644
--- a/drivers/staging/comedi/drivers/ni_labpc.h
+++ b/drivers/staging/comedi/drivers/ni_labpc.h
@@ -1,20 +1,18 @@
 /*
-ni_labpc.h
-
-Header for ni_labpc.c and ni_labpc_cs.c
-
-Copyright (C) 2003 Frank Mori Hess 
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-*/
+ * Header for ni_labpc ISA/PCMCIA/PCI drivers
+ *
+ * Copyright (C) 2003 Frank Mori Hess 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
 
 #ifndef _NI_LABPC_H
 #define _NI_LABPC_H
-- 
2.6.3

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


[PATCH 4/6] staging: comedi: ni_labpc_cs: fix block comment issues

2016-03-22 Thread H Hartley Sweeten
Fix the checkpatch.pl issues:
WARNING: Block comments use * on subsequent lines
WARNING: line over 80 characters

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_labpc_cs.c | 95 +---
 1 file changed, 44 insertions(+), 51 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_labpc_cs.c 
b/drivers/staging/comedi/drivers/ni_labpc_cs.c
index a1c69ac..3d4d0b9 100644
--- a/drivers/staging/comedi/drivers/ni_labpc_cs.c
+++ b/drivers/staging/comedi/drivers/ni_labpc_cs.c
@@ -1,57 +1,50 @@
 /*
-comedi/drivers/ni_labpc_cs.c
-Driver for National Instruments daqcard-1200 boards
-Copyright (C) 2001, 2002, 2003 Frank Mori Hess 

-
-PCMCIA crap is adapted from dummy_cs.c 1.31 2001/08/24 12:13:13
-from the pcmcia package.
-The initial developer of the pcmcia dummy_cs.c code is David A. Hinds
-.  Portions created by David A. Hinds
-are Copyright (C) 1999 David A. Hinds.
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-*/
-/*
-Driver: ni_labpc_cs
-Description: National Instruments Lab-PC (& compatibles)
-Author: Frank Mori Hess 
-Devices: [National Instruments] DAQCard-1200 (daqcard-1200)
-Status: works
-
-Thanks go to Fredrik Lingvall for much testing and perseverance in
-helping to debug daqcard-1200 support.
-
-The 1200 series boards have onboard calibration dacs for correcting
-analog input/output offsets and gains.  The proper settings for these
-caldacs are stored on the board's eeprom.  To read the caldac values
-from the eeprom and store them into a file that can be then be used by
-comedilib, use the comedi_calibrate program.
-
-Configuration options:
-  none
-
-The daqcard-1200 has quirky chanlist requirements
-when scanning multiple channels.  Multiple channel scan
-sequence must start at highest channel, then decrement down to
-channel 0.  Chanlists consisting of all one channel
-are also legal, and allow you to pace conversions in bursts.
-
-*/
+ * Driver for National Instruments daqcard-1200 boards
+ * Copyright (C) 2001, 2002, 2003 Frank Mori Hess 

+ *
+ * PCMCIA crap is adapted from dummy_cs.c 1.31 2001/08/24 12:13:13
+ * from the pcmcia package.
+ * The initial developer of the pcmcia dummy_cs.c code is David A. Hinds
+ * .  Portions created by David A. Hinds
+ * are Copyright (C) 1999 David A. Hinds.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * General Public License for more details.
+ */
 
 /*
-
-NI manuals:
-340988a (daqcard-1200)
-
-*/
+ * Driver: ni_labpc_cs
+ * Description: National Instruments Lab-PC (& compatibles)
+ * Author: Frank Mori Hess 
+ * Devices: [National Instruments] DAQCard-1200 (daqcard-1200)
+ * Status: works
+ *
+ * Thanks go to Fredrik Lingvall for much testing and perseverance in
+ * helping to debug daqcard-1200 support.
+ *
+ * The 1200 series boards have onboard calibration dacs for correcting
+ * analog input/output offsets and gains. The proper settings for these
+ * caldacs are stored on the board's eeprom. To read the caldac values
+ * from the eeprom and store them into a file that can be then be used by
+ * comedilib, use the comedi_calibrate program.
+ *
+ * Configuration options: none
+ *
+ * The daqcard-1200 has quirky chanlist requirements when scanning multiple
+ * channels. Multiple channel scan sequence must start at highest channel,
+ * then decrement down to channel 0.  Chanlists consisting of all one channel
+ * are also legal, and allow you to pace conversions in bursts.
+ *
+ * NI manuals:
+ *   340988a (daqcard-1200)
+ */
 
 #include 
 
-- 
2.6.3

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


[PATCH 0/6] staging: comedi: ni_labpc: minor cleanup

2016-03-22 Thread H Hartley Sweeten
Fix all the checkpatch.pl issues.

H Hartley Sweeten (6):
  staging: comedi: ni_labpc: remove some unnecessary defines
  staging: comedi: ni_labpc_regs.h: tidy up bit defines
  staging: comedi: ni_labpc_common: tidy up block comments
  staging: comedi: ni_labpc_cs: fix block comment issues
  staging: comedi: ni_labpc_pci: tidy up bit define
  staging: comedi: ni_labpc.h: fix block comment issues

 drivers/staging/comedi/drivers/ni_labpc.h| 33 
 drivers/staging/comedi/drivers/ni_labpc_common.c | 65 +---
 drivers/staging/comedi/drivers/ni_labpc_cs.c | 95 +++-
 drivers/staging/comedi/drivers/ni_labpc_pci.c|  4 +-
 drivers/staging/comedi/drivers/ni_labpc_regs.h   | 82 ++--
 drivers/staging/comedi/drivers/z8536.h   | 89 --
 6 files changed, 189 insertions(+), 179 deletions(-)

-- 
2.6.3

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


[PATCH 5/6] staging: comedi: ni_labpc_pci: tidy up bit define

2016-03-22 Thread H Hartley Sweeten
As suggested by checkpatch.pl:
CHECK: Prefer using the BIT macro

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_labpc_pci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_labpc_pci.c 
b/drivers/staging/comedi/drivers/ni_labpc_pci.c
index 77d4038..cac0891 100644
--- a/drivers/staging/comedi/drivers/ni_labpc_pci.c
+++ b/drivers/staging/comedi/drivers/ni_labpc_pci.c
@@ -51,8 +51,8 @@ static const struct labpc_boardinfo labpc_pci_boards[] = {
 };
 
 /* ripped from mite.h and mite_setup2() to avoid mite dependency */
-#define MITE_IODWBSR   0xc0 /* IO Device Window Base Size Register */
-#define WENAB  (1 << 7) /* window enable */
+#define MITE_IODWBSR   0xc0/* IO Device Window Base Size Register */
+#define WENAB  BIT(7)  /* window enable */
 
 static int labpc_pci_mite_init(struct pci_dev *pcidev)
 {
-- 
2.6.3

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


[PATCH v2 01/43] staging: comedi: ni_660x: change IOConfigReg() into a macro

2016-03-22 Thread H Hartley Sweeten
The BUG_ON() in this function is unnecessary. The 'pfi_channel' will
always be in range of the subdevice 'n_chan' (NUM_PFI_CHANNELS) which
will return a valid 'reg'.

Convert the inline function into a simple macro.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 22 --
 1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 46647c6..10db2ff 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -156,13 +156,7 @@ enum ni_660x_register {
NI660X_NUM_REGS,
 };
 
-static inline unsigned IOConfigReg(unsigned pfi_channel)
-{
-   unsigned reg = NI660X_IO_CFG_0_1 + pfi_channel / 2;
-
-   BUG_ON(reg > NI660X_IO_CFG_38_39);
-   return reg;
-}
+#define NI660X_IO_CFG(x)   (NI660X_IO_CFG_0_1 + ((x) / 2))
 
 enum ni_660x_register_width {
DATA_1B,
@@ -893,7 +887,7 @@ static void init_tio_chip(struct comedi_device *dev, int 
chipset)
   devpriv->dma_configuration_soft_copies[chipset],
   NI660X_DMA_CFG);
for (i = 0; i < NUM_PFI_CHANNELS; ++i)
-   ni_660x_write_register(dev, chipset, 0, IOConfigReg(i));
+   ni_660x_write_register(dev, chipset, 0, NI660X_IO_CFG(i));
 }
 
 static int ni_660x_dio_insn_bits(struct comedi_device *dev,
@@ -944,22 +938,22 @@ static void ni_660x_select_pfi_output(struct 
comedi_device *dev,
if (idle_chipset != active_chipset) {
idle_bits =
ni_660x_read_register(dev, idle_chipset,
- IOConfigReg(pfi_channel));
+ NI660X_IO_CFG(pfi_channel));
idle_bits &= ~pfi_output_select_mask(pfi_channel);
idle_bits |=
pfi_output_select_bits(pfi_channel,
   pfi_output_select_high_Z);
ni_660x_write_register(dev, idle_chipset, idle_bits,
-  IOConfigReg(pfi_channel));
+  NI660X_IO_CFG(pfi_channel));
}
 
active_bits =
ni_660x_read_register(dev, active_chipset,
- IOConfigReg(pfi_channel));
+ NI660X_IO_CFG(pfi_channel));
active_bits &= ~pfi_output_select_mask(pfi_channel);
active_bits |= pfi_output_select_bits(pfi_channel, output_select);
ni_660x_write_register(dev, active_chipset, active_bits,
-  IOConfigReg(pfi_channel));
+  NI660X_IO_CFG(pfi_channel));
 }
 
 static int ni_660x_set_pfi_routing(struct comedi_device *dev, unsigned chan,
@@ -1025,10 +1019,10 @@ static int ni_660x_dio_insn_config(struct comedi_device 
*dev,
break;
 
case INSN_CONFIG_FILTER:
-   val = ni_660x_read_register(dev, 0, IOConfigReg(chan));
+   val = ni_660x_read_register(dev, 0, NI660X_IO_CFG(chan));
val &= ~pfi_input_select_mask(chan);
val |= pfi_input_select_bits(chan, data[1]);
-   ni_660x_write_register(dev, 0, val, IOConfigReg(chan));
+   ni_660x_write_register(dev, 0, val, NI660X_IO_CFG(chan));
break;
 
default:
-- 
2.6.3

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


[PATCH v2 20/43] staging: comedi: ni_660x: Prefer kernel type 'u64' over 'uint64_t'

2016-03-22 Thread H Hartley Sweeten
Fix the checkpatch.pl issues.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 6ca5c67..4f7f5ca 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -331,7 +331,7 @@ static const struct ni_660x_board ni_660x_boards[] = {
 struct ni_660x_private {
struct mite_struct *mite;
struct ni_gpct_device *counter_dev;
-   uint64_t pfi_direction_bits;
+   u64 pfi_direction_bits;
struct mite_dma_descriptor_ring
*mite_rings[NI_660X_MAX_NUM_CHIPS][counters_per_chip];
spinlock_t mite_channel_lock;
@@ -854,7 +854,7 @@ static int ni_660x_set_pfi_routing(struct comedi_device 
*dev,
}
 
devpriv->pfi_output_selects[chan] = source;
-   if (devpriv->pfi_direction_bits & (((uint64_t) 1) << chan))
+   if (devpriv->pfi_direction_bits & (1ULL << chan))
ni_660x_select_pfi_output(dev, chan,
  devpriv->pfi_output_selects[chan]);
return 0;
@@ -867,7 +867,7 @@ static int ni_660x_dio_insn_config(struct comedi_device 
*dev,
 {
struct ni_660x_private *devpriv = dev->private;
unsigned int chan = CR_CHAN(insn->chanspec);
-   uint64_t bit = 1ULL << chan;
+   u64 bit = 1ULL << chan;
unsigned int val;
int ret;
 
-- 
2.6.3

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


[PATCH v2 08/43] staging: comedi: ni_660x: remove enum clock_config_register_bits

2016-03-22 Thread H Hartley Sweeten
Remove this enum and add a define for the bit.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index ab761aa..30089cd 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -155,6 +155,8 @@ enum ni_660x_register {
NI660X_NUM_REGS,
 };
 
+#define NI660X_CLK_CFG_COUNTER_SWAPBIT(21)
+
 #define NI660X_IO_CFG(x)   (NI660X_IO_CFG_0_1 + ((x) / 2))
 #define NI660X_IO_CFG_OUT_SEL(_c, _s)  (((_s) & 0x3) << (((_c) % 2) ? 0 : 8))
 #define NI660X_IO_CFG_OUT_SEL_MASK(_c) NI660X_IO_CFG_OUT_SEL((_c), 0x3)
@@ -280,11 +282,6 @@ static const struct ni_660x_register_data 
ni_660x_reg_data[NI660X_NUM_REGS] = {
[NI660X_IO_CFG_38_39]   = { 0x7a2, 2 }  /* read/write */
 };
 
-/* kind of ENABLE for the second counter */
-enum clock_config_register_bits {
-   CounterSwap = 0x1 << 21
-};
-
 /* dma configuration register bits */
 static inline unsigned dma_select_mask(unsigned dma_channel)
 {
@@ -704,7 +701,7 @@ static void set_tio_counterswap(struct comedi_device *dev, 
int chip)
 * first chip.
 */
if (chip)
-   bits = CounterSwap;
+   bits = NI660X_CLK_CFG_COUNTER_SWAP;
 
ni_660x_write_register(dev, chip, bits, NI660X_CLK_CFG);
 }
-- 
2.6.3

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


[PATCH v2 16/43] staging: comedi: ni_660x: fix block comment issues

2016-03-22 Thread H Hartley Sweeten
Fix the checkpatch.pl issues about:

WARNING: Block comments use * on subsequent lines
WARNING: Block comments use a trailing */ on a separate line

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 17 +++--
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 232c897..0183497 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -48,8 +48,7 @@ enum ni_660x_constants {
 };
 
 #define NUM_PFI_CHANNELS 40
-/* really there are only up to 3 dma channels, but the register layout allows
-for 4 */
+/* there are only up to 3 dma channels, but the register layout allows for 4 */
 #define MAX_DMA_CHANNEL 4
 
 /* See Register-Level Programmer Manual page 3.1 */
@@ -985,8 +984,11 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
s->range_table = &range_digital;
s->insn_bits = ni_660x_dio_insn_bits;
s->insn_config = ni_660x_dio_insn_config;
-   /*  we use the ioconfig registers to control dio direction, so zero
-   output enables in stc dio control reg */
+
+   /*
+* We use the ioconfig registers to control dio direction, so zero
+* output enables in stc dio control reg.
+*/
ni_660x_write(dev, 0, 0, NI660X_STC_DIO_CONTROL);
 
devpriv->counter_dev = ni_gpct_device_construct(dev,
@@ -1040,8 +1042,11 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
NI660X_IO_CFG_OUT_SEL_COUNTER);
ni_660x_select_pfi_output(dev, i, NI660X_IO_CFG_OUT_SEL_HIGH_Z);
}
-   /* to be safe, set counterswap bits on tio chips after all the counter
-  outputs have been set to high impedance mode */
+
+   /*
+* To be safe, set counterswap bits on tio chips after all the counter
+* outputs have been set to high impedance mode.
+*/
for (i = 0; i < board->n_chips; ++i)
set_tio_counterswap(dev, i);
 
-- 
2.6.3

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


[PATCH v2 02/43] staging: comedi: ni_660x: remove struct NI_660xRegisterData 'name'

2016-03-22 Thread H Hartley Sweeten
This member of the struct is not used, and just takes up space. Remove it.
Instead, add the enum ni_660x_register indexes to the table to clarify, and
document, the entries.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 197 +++
 1 file changed, 98 insertions(+), 99 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 10db2ff..10bb839 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -187,111 +187,110 @@ static inline unsigned NI_660X_GPCT_SUBDEV(unsigned 
index)
 }
 
 struct NI_660xRegisterData {
-   const char *name;   /*  Register Name */
int offset; /*  Offset from base address from GPCT chip */
enum ni_660x_register_direction direction;
enum ni_660x_register_width size; /* 1 byte, 2 bytes, or 4 bytes */
 };
 
 static const struct NI_660xRegisterData registerData[NI660X_NUM_REGS] = {
-   {"G0 Interrupt Acknowledge", 0x004, NI_660x_WRITE, DATA_2B},
-   {"G0 Status Register", 0x004, NI_660x_READ, DATA_2B},
-   {"G1 Interrupt Acknowledge", 0x006, NI_660x_WRITE, DATA_2B},
-   {"G1 Status Register", 0x006, NI_660x_READ, DATA_2B},
-   {"G01 Status Register ", 0x008, NI_660x_READ, DATA_2B},
-   {"G0 Command Register", 0x00C, NI_660x_WRITE, DATA_2B},
-   {"STC DIO Parallel Input", 0x00E, NI_660x_READ, DATA_2B},
-   {"G1 Command Register", 0x00E, NI_660x_WRITE, DATA_2B},
-   {"G0 HW Save Register", 0x010, NI_660x_READ, DATA_4B},
-   {"G1 HW Save Register", 0x014, NI_660x_READ, DATA_4B},
-   {"STC DIO Output", 0x014, NI_660x_WRITE, DATA_2B},
-   {"STC DIO Control", 0x016, NI_660x_WRITE, DATA_2B},
-   {"G0 SW Save Register", 0x018, NI_660x_READ, DATA_4B},
-   {"G1 SW Save Register", 0x01C, NI_660x_READ, DATA_4B},
-   {"G0 Mode Register", 0x034, NI_660x_WRITE, DATA_2B},
-   {"G01 Joint Status 1 Register", 0x036, NI_660x_READ, DATA_2B},
-   {"G1 Mode Register", 0x036, NI_660x_WRITE, DATA_2B},
-   {"STC DIO Serial Input", 0x038, NI_660x_READ, DATA_2B},
-   {"G0 Load A Register", 0x038, NI_660x_WRITE, DATA_4B},
-   {"G01 Joint Status 2 Register", 0x03A, NI_660x_READ, DATA_2B},
-   {"G0 Load B Register", 0x03C, NI_660x_WRITE, DATA_4B},
-   {"G1 Load A Register", 0x040, NI_660x_WRITE, DATA_4B},
-   {"G1 Load B Register", 0x044, NI_660x_WRITE, DATA_4B},
-   {"G0 Input Select Register", 0x048, NI_660x_WRITE, DATA_2B},
-   {"G1 Input Select Register", 0x04A, NI_660x_WRITE, DATA_2B},
-   {"G0 Autoincrement Register", 0x088, NI_660x_WRITE, DATA_2B},
-   {"G1 Autoincrement Register", 0x08A, NI_660x_WRITE, DATA_2B},
-   {"G01 Joint Reset Register", 0x090, NI_660x_WRITE, DATA_2B},
-   {"G0 Interrupt Enable", 0x092, NI_660x_WRITE, DATA_2B},
-   {"G1 Interrupt Enable", 0x096, NI_660x_WRITE, DATA_2B},
-   {"G0 Counting Mode Register", 0x0B0, NI_660x_WRITE, DATA_2B},
-   {"G1 Counting Mode Register", 0x0B2, NI_660x_WRITE, DATA_2B},
-   {"G0 Second Gate Register", 0x0B4, NI_660x_WRITE, DATA_2B},
-   {"G1 Second Gate Register", 0x0B6, NI_660x_WRITE, DATA_2B},
-   {"G0 DMA Config Register", 0x0B8, NI_660x_WRITE, DATA_2B},
-   {"G0 DMA Status Register", 0x0B8, NI_660x_READ, DATA_2B},
-   {"G1 DMA Config Register", 0x0BA, NI_660x_WRITE, DATA_2B},
-   {"G1 DMA Status Register", 0x0BA, NI_660x_READ, DATA_2B},
-   {"G2 Interrupt Acknowledge", 0x104, NI_660x_WRITE, DATA_2B},
-   {"G2 Status Register", 0x104, NI_660x_READ, DATA_2B},
-   {"G3 Interrupt Acknowledge", 0x106, NI_660x_WRITE, DATA_2B},
-   {"G3 Status Register", 0x106, NI_660x_READ, DATA_2B},
-   {"G23 Status Register", 0x108, NI_660x_READ, DATA_2B},
-   {"G2 Command Register", 0x10C, NI_660x_WRITE, DATA_2B},
-   {"G3 Command Register", 0x10E, NI_660x_WRITE, DATA_2B},
-   {"G2 HW Save Register", 0x110, NI_660x_READ, DATA_4B},
-   {"G3 HW Save Register", 0x114, NI_660x_READ, DATA_4B},
-   {"G2 SW Save Register", 0x118, NI_660x_READ, DATA_4B},
-   {"G3 SW Save Register", 0x11C, NI_660x_READ, DATA_4B},
-   {"G2 Mode Register", 0x134, NI_660x_WRITE, DATA_2B},
-   {"G23 Joint Status 1 Register", 0x136, NI_660x_READ, DATA_2B},
-   {"G3 Mode Register", 0x136, NI_660x_WRITE, DATA_2B},
-   {"G2 Load A Register", 0x138, NI_660x_WRITE, DATA_4B},
-   {"G23 Joint Status 2 Register", 0x13A, NI_660x_READ, DATA_2B},
-   {"G2 Load B Register", 0x13C, NI_660x_WRITE, DATA_4B},
-   {"G3 Load A Register", 0x140, NI_660x_WRITE, DATA_4B},
-   {"G3 Load B Register", 0x144, NI_660x_WRITE, DATA_4B},
-   {"G2 Input Select Register", 0x148, NI_660x_WRITE, DATA_2B},
-   {"G3 Input Select Register", 0x14A, NI_660x_WRITE, DATA_2B},
-   {"G2 Autoincrement Register", 0x188, NI_660x_WRITE, DATA_2B},
-   {"G3 Aut

[PATCH v2 04/43] staging: comedi: ni_660x: remove enum ni_660x_register_direction

2016-03-22 Thread H Hartley Sweeten
This enum is used to define the, unused, 'direction' of each register
in struct NI_660xRegisterData. Remove the unused member, as well as
the enum.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 203 +++
 1 file changed, 98 insertions(+), 105 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index dbbeb96..409a776 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -158,12 +158,6 @@ enum ni_660x_register {
 
 #define NI660X_IO_CFG(x)   (NI660X_IO_CFG_0_1 + ((x) / 2))
 
-enum ni_660x_register_direction {
-   NI_660x_READ,
-   NI_660x_WRITE,
-   NI_660x_READ_WRITE
-};
-
 enum ni_660x_pfi_output_select {
pfi_output_select_high_Z = 0,
pfi_output_select_counter = 1,
@@ -182,109 +176,108 @@ static inline unsigned NI_660X_GPCT_SUBDEV(unsigned 
index)
 
 struct NI_660xRegisterData {
int offset; /*  Offset from base address from GPCT chip */
-   enum ni_660x_register_direction direction;
char size;  /* 2 or 4 bytes */
 };
 
 static const struct NI_660xRegisterData registerData[NI660X_NUM_REGS] = {
-   [NI660X_G0_INT_ACK] = { 0x004, NI_660x_WRITE, 2 },
-   [NI660X_G0_STATUS]  = { 0x004, NI_660x_READ, 2 },
-   [NI660X_G1_INT_ACK] = { 0x006, NI_660x_WRITE, 2 },
-   [NI660X_G1_STATUS]  = { 0x006, NI_660x_READ, 2 },
-   [NI660X_G01_STATUS] = { 0x008, NI_660x_READ, 2 },
-   [NI660X_G0_CMD] = { 0x00c, NI_660x_WRITE, 2 },
-   [NI660X_STC_DIO_PARALLEL_INPUT] = { 0x00e, NI_660x_READ, 2 },
-   [NI660X_G1_CMD] = { 0x00e, NI_660x_WRITE, 2 },
-   [NI660X_G0_HW_SAVE] = { 0x010, NI_660x_READ, 4 },
-   [NI660X_G1_HW_SAVE] = { 0x014, NI_660x_READ, 4 },
-   [NI660X_STC_DIO_OUTPUT] = { 0x014, NI_660x_WRITE, 2 },
-   [NI660X_STC_DIO_CONTROL]= { 0x016, NI_660x_WRITE, 2 },
-   [NI660X_G0_SW_SAVE] = { 0x018, NI_660x_READ, 4 },
-   [NI660X_G1_SW_SAVE] = { 0x01c, NI_660x_READ, 4 },
-   [NI660X_G0_MODE]= { 0x034, NI_660x_WRITE, 2 },
-   [NI660X_G01_STATUS1]= { 0x036, NI_660x_READ, 2 },
-   [NI660X_G1_MODE]= { 0x036, NI_660x_WRITE, 2 },
-   [NI660X_STC_DIO_SERIAL_INPUT]   = { 0x038, NI_660x_READ, 2 },
-   [NI660X_G0_LOADA]   = { 0x038, NI_660x_WRITE, 4 },
-   [NI660X_G01_STATUS2]= { 0x03a, NI_660x_READ, 2 },
-   [NI660X_G0_LOADB]   = { 0x03c, NI_660x_WRITE, 4 },
-   [NI660X_G1_LOADA]   = { 0x040, NI_660x_WRITE, 4 },
-   [NI660X_G1_LOADB]   = { 0x044, NI_660x_WRITE, 4 },
-   [NI660X_G0_INPUT_SEL]   = { 0x048, NI_660x_WRITE, 2 },
-   [NI660X_G1_INPUT_SEL]   = { 0x04a, NI_660x_WRITE, 2 },
-   [NI660X_G0_AUTO_INC]= { 0x088, NI_660x_WRITE, 2 },
-   [NI660X_G1_AUTO_INC]= { 0x08a, NI_660x_WRITE, 2 },
-   [NI660X_G01_RESET]  = { 0x090, NI_660x_WRITE, 2 },
-   [NI660X_G0_INT_ENA] = { 0x092, NI_660x_WRITE, 2 },
-   [NI660X_G1_INT_ENA] = { 0x096, NI_660x_WRITE, 2 },
-   [NI660X_G0_CNT_MODE]= { 0x0b0, NI_660x_WRITE, 2 },
-   [NI660X_G1_CNT_MODE]= { 0x0b2, NI_660x_WRITE, 2 },
-   [NI660X_G0_GATE2]   = { 0x0b4, NI_660x_WRITE, 2 },
-   [NI660X_G1_GATE2]   = { 0x0b6, NI_660x_WRITE, 2 },
-   [NI660X_G0_DMA_CFG] = { 0x0b8, NI_660x_WRITE, 2 },
-   [NI660X_G0_DMA_STATUS]  = { 0x0b8, NI_660x_READ, 2 },
-   [NI660X_G1_DMA_CFG] = { 0x0ba, NI_660x_WRITE, 2 },
-   [NI660X_G1_DMA_STATUS]  = { 0x0ba, NI_660x_READ, 2 },
-   [NI660X_G2_INT_ACK] = { 0x104, NI_660x_WRITE, 2 },
-   [NI660X_G2_STATUS]  = { 0x104, NI_660x_READ, 2 },
-   [NI660X_G3_INT_ACK] = { 0x106, NI_660x_WRITE, 2 },
-   [NI660X_G3_STATUS]  = { 0x106, NI_660x_READ, 2 },
-   [NI660X_G23_STATUS] = { 0x108, NI_660x_READ, 2 },
-   [NI660X_G2_CMD] = { 0x10c, NI_660x_WRITE, 2 },
-   [NI660X_G3_CMD] = { 0x10e, NI_660x_WRITE, 2 },
-   [NI660X_G2_HW_SAVE] = { 0x110, NI_660x_READ, 4 },
-   [NI660X_G3_HW_SAVE] = { 0x114, NI_660x_READ, 4 },
-   [NI660X_G2_SW_SAVE] = { 0x118, NI_660x_READ, 4 },
-   [NI660X_G3_SW_SAVE] = { 0x11c, NI_660x_READ, 4 },
-   [NI660X_G2_MODE]= { 0x134, NI_660x_WRITE, 2 },
-   [NI660X_G23_STATUS1]= { 0x136, NI_660x_READ, 2 },
-   [NI660X_G3_MODE]= { 0x136, NI_660x_WRITE, 2 },
-   [NI660X_G2_LOADA]  

[PATCH v2 35/43] staging: comedi: ni_660x: allocate counters early in (*auto_attach)

2016-03-22 Thread H Hartley Sweeten
The ni_gpct_device_construct() could fail allocating the memory for
device and its counters. For aesthetics, call the function before
initializing the subdevices.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index afe62bf..6366303 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -914,6 +914,16 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
 
ni_660x_init_tio_chips(dev, board->n_chips);
 
+   n_counters = board->n_chips * NI660X_COUNTERS_PER_CHIP;
+   gpct_dev = ni_gpct_device_construct(dev,
+   ni_660x_gpct_write,
+   ni_660x_gpct_read,
+   ni_gpct_variant_660x,
+   n_counters);
+   if (!gpct_dev)
+   return -ENOMEM;
+   devpriv->counter_dev = gpct_dev;
+
ret = comedi_alloc_subdevices(dev, 2 + NI660X_MAX_COUNTERS);
if (ret)
return ret;
@@ -986,16 +996,6 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
s->insn_bits= ni_660x_dio_insn_bits;
s->insn_config  = ni_660x_dio_insn_config;
 
-   n_counters = board->n_chips * NI660X_COUNTERS_PER_CHIP;
-   gpct_dev = ni_gpct_device_construct(dev,
-   ni_660x_gpct_write,
-   ni_660x_gpct_read,
-   ni_gpct_variant_660x,
-   n_counters);
-   if (!gpct_dev)
-   return -ENOMEM;
-   devpriv->counter_dev = gpct_dev;
-
/* Counter subdevices (4 NI TIO General Purpose Counters per chip) */
for (i = 0; i < NI660X_MAX_COUNTERS; ++i) {
s = &dev->subdevices[subdev++];
-- 
2.6.3

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


[PATCH v2 29/43] staging: comedi: ni_660x: tidy up the counter subdevices init

2016-03-22 Thread H Hartley Sweeten
For aesthetics, add some whitespace to the subdevice init and use
a couple local variables to make the code easier to follow.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 59 +---
 1 file changed, 32 insertions(+), 27 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 80499d6..35602cc 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -864,6 +864,7 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
const struct ni_660x_board *board = NULL;
struct ni_660x_private *devpriv;
struct comedi_subdevice *s;
+   struct ni_gpct_device *gpct_dev;
unsigned int n_counters;
int subdev;
int ret;
@@ -977,46 +978,50 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
ni_660x_write(dev, 0, 0, NI660X_STC_DIO_CONTROL);
 
n_counters = board->n_chips * NI660X_COUNTERS_PER_CHIP;
-   devpriv->counter_dev = ni_gpct_device_construct(dev,
-ni_660x_gpct_write,
-ni_660x_gpct_read,
-ni_gpct_variant_660x,
-n_counters);
-   if (!devpriv->counter_dev)
+   gpct_dev = ni_gpct_device_construct(dev,
+   ni_660x_gpct_write,
+   ni_660x_gpct_read,
+   ni_gpct_variant_660x,
+   n_counters);
+   if (!gpct_dev)
return -ENOMEM;
+   devpriv->counter_dev = gpct_dev;
+
+   /* Counter subdevices (4 NI TIO General Purpose Counters per chip) */
for (i = 0; i < NI660X_MAX_COUNTERS; ++i) {
s = &dev->subdevices[subdev++];
if (i < n_counters) {
-   s->type = COMEDI_SUBD_COUNTER;
-   s->subdev_flags = SDF_READABLE | SDF_WRITABLE |
+   struct ni_gpct *counter = &gpct_dev->counters[i];
+
+   counter->chip_index = i / NI660X_COUNTERS_PER_CHIP;
+   counter->counter_index = i % NI660X_COUNTERS_PER_CHIP;
+
+   s->type = COMEDI_SUBD_COUNTER;
+   s->subdev_flags = SDF_READABLE | SDF_WRITABLE |
  SDF_LSAMPL | SDF_CMD_READ;
-   s->n_chan = 3;
-   s->maxdata = 0x;
-   s->insn_read = ni_tio_insn_read;
-   s->insn_write = ni_tio_insn_write;
-   s->insn_config = ni_tio_insn_config;
-   s->do_cmd = &ni_660x_cmd;
-   s->len_chanlist = 1;
-   s->do_cmdtest = ni_tio_cmdtest;
-   s->cancel = &ni_660x_cancel;
-   s->poll = &ni_660x_input_poll;
+   s->n_chan   = 3;
+   s->maxdata  = 0x;
+   s->insn_read= ni_tio_insn_read;
+   s->insn_write   = ni_tio_insn_write;
+   s->insn_config  = ni_tio_insn_config;
+   s->len_chanlist = 1;
+   s->do_cmd   = ni_660x_cmd;
+   s->do_cmdtest   = ni_tio_cmdtest;
+   s->cancel   = ni_660x_cancel;
+   s->poll = ni_660x_input_poll;
+   s->buf_change   = ni_660x_buf_change;
s->async_dma_dir = DMA_BIDIRECTIONAL;
-   s->buf_change = &ni_660x_buf_change;
-   s->private = &devpriv->counter_dev->counters[i];
-
-   devpriv->counter_dev->counters[i].chip_index =
-   i / NI660X_COUNTERS_PER_CHIP;
-   devpriv->counter_dev->counters[i].counter_index =
-   i % NI660X_COUNTERS_PER_CHIP;
+   s->private  = counter;
} else {
-   s->type = COMEDI_SUBD_UNUSED;
+   s->type = COMEDI_SUBD_UNUSED;
}
}
+
for (i = 0; i < board->n_chips; ++i)
init_tio_chip(dev, i);
 
for (i = 0; i < n_counters; ++i)
-   ni_tio_init_counter(&devpriv->counter_dev->counters[i]);
+   ni_tio_init_counter(&gpct_dev->counters[i]);
 
 /*
  * Default the DIO channels as:
-- 
2.6.3

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


[PATCH v2 19/43] staging: comedi: ni_660x: Prefer 'unsigned int' to bare use of 'unsigned'

2016-03-22 Thread H Hartley Sweeten
Fix the checkpatch.pl issues.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 40 
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 6a3a12e..6ca5c67 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -299,7 +299,7 @@ enum ni_660x_boardid {
 
 struct ni_660x_board {
const char *name;
-   unsigned n_chips;   /* total number of TIO chips */
+   unsigned int n_chips;   /* total number of TIO chips */
 };
 
 static const struct ni_660x_board ni_660x_boards[] = {
@@ -337,7 +337,7 @@ struct ni_660x_private {
spinlock_t mite_channel_lock;
/* interrupt_lock prevents races between interrupt and comedi_poll */
spinlock_t interrupt_lock;
-   unsigned dma_cfg[NI_660X_MAX_NUM_CHIPS];
+   unsigned int dma_cfg[NI_660X_MAX_NUM_CHIPS];
spinlock_t soft_reg_copy_lock;
unsigned short pfi_output_selects[NUM_PFI_CHANNELS];
 };
@@ -533,17 +533,17 @@ static inline struct mite_dma_descriptor_ring 
*mite_ring(struct ni_660x_private
 struct ni_gpct
 *counter)
 {
-   unsigned chip = counter->chip_index;
+   unsigned int chip = counter->chip_index;
 
return priv->mite_rings[chip][counter->counter_index];
 }
 
 static inline void ni_660x_set_dma_channel(struct comedi_device *dev,
-  unsigned mite_channel,
+  unsigned int mite_channel,
   struct ni_gpct *counter)
 {
struct ni_660x_private *devpriv = dev->private;
-   unsigned chip = counter->chip_index;
+   unsigned int chip = counter->chip_index;
unsigned long flags;
 
spin_lock_irqsave(&devpriv->soft_reg_copy_lock, flags);
@@ -558,11 +558,11 @@ static inline void ni_660x_set_dma_channel(struct 
comedi_device *dev,
 }
 
 static inline void ni_660x_unset_dma_channel(struct comedi_device *dev,
-unsigned mite_channel,
+unsigned int mite_channel,
 struct ni_gpct *counter)
 {
struct ni_660x_private *devpriv = dev->private;
-   unsigned chip = counter->chip_index;
+   unsigned int chip = counter->chip_index;
unsigned long flags;
 
spin_lock_irqsave(&devpriv->soft_reg_copy_lock, flags);
@@ -642,7 +642,7 @@ static int ni_660x_cancel(struct comedi_device *dev, struct 
comedi_subdevice *s)
 
 static void set_tio_counterswap(struct comedi_device *dev, int chip)
 {
-   unsigned bits = 0;
+   unsigned int bits = 0;
 
/*
 * See P. 3.5 of the Register-Level Programming manual.
@@ -670,7 +670,7 @@ static irqreturn_t ni_660x_interrupt(int irq, void *d)
struct comedi_device *dev = d;
struct ni_660x_private *devpriv = dev->private;
struct comedi_subdevice *s;
-   unsigned i;
+   unsigned int i;
unsigned long flags;
 
if (!dev->attached)
@@ -718,7 +718,7 @@ static int ni_660x_buf_change(struct comedi_device *dev,
 static int ni_660x_allocate_private(struct comedi_device *dev)
 {
struct ni_660x_private *devpriv;
-   unsigned i;
+   unsigned int i;
 
devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
if (!devpriv)
@@ -737,8 +737,8 @@ static int ni_660x_alloc_mite_rings(struct comedi_device 
*dev)
 {
const struct ni_660x_board *board = dev->board_ptr;
struct ni_660x_private *devpriv = dev->private;
-   unsigned i;
-   unsigned j;
+   unsigned int i;
+   unsigned int j;
 
for (i = 0; i < board->n_chips; ++i) {
for (j = 0; j < counters_per_chip; ++j) {
@@ -755,8 +755,8 @@ static void ni_660x_free_mite_rings(struct comedi_device 
*dev)
 {
const struct ni_660x_board *board = dev->board_ptr;
struct ni_660x_private *devpriv = dev->private;
-   unsigned i;
-   unsigned j;
+   unsigned int i;
+   unsigned int j;
 
for (i = 0; i < board->n_chips; ++i) {
for (j = 0; j < counters_per_chip; ++j)
@@ -767,7 +767,7 @@ static void ni_660x_free_mite_rings(struct comedi_device 
*dev)
 static void init_tio_chip(struct comedi_device *dev, int chipset)
 {
struct ni_660x_private *devpriv = dev->private;
-   unsigned i;
+   unsigned int i;
 
/*  init dma configuration register */
devpriv->dma_cfg[chipset] = 0;
@@ -782,7 +782,7 @@ static int ni_660x_dio_insn_bits(struct comedi_device *dev,
 struct comedi_subdevice *s,
 struct comedi_insn *insn, unsigned int *d

[PATCH v2 10/43] staging: comedi: ni_660x: cleanup the NI660X_GLOBAL_INT_{STATUS, CFG}

2016-03-22 Thread H Hartley Sweeten
Remove the enums global_interrupt_{status,config}_register_bits and
add defines for the CamelCase values.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 27 ++-
 1 file changed, 10 insertions(+), 17 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 0b37982..773147a 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -157,6 +157,14 @@ enum ni_660x_register {
 
 #define NI660X_CLK_CFG_COUNTER_SWAPBIT(21)
 
+#define NI660X_GLOBAL_INT_COUNTER0 BIT(8)
+#define NI660X_GLOBAL_INT_COUNTER1 BIT(9)
+#define NI660X_GLOBAL_INT_COUNTER2 BIT(10)
+#define NI660X_GLOBAL_INT_COUNTER3 BIT(11)
+#define NI660X_GLOBAL_INT_CASCADE  BIT(29)
+#define NI660X_GLOBAL_INT_GLOBAL_POL   BIT(30)
+#define NI660X_GLOBAL_INT_GLOBAL   BIT(31)
+
 #define NI660X_DMA_CFG_SEL(_c, _s) (((_s) & 0x1f) << (8 * (_c)))
 #define NI660X_DMA_CFG_SEL_MASK(_c)NI660X_DMA_CFG_SEL((_c), 0x1f)
 #define NI660X_DMA_CFG_SEL_NONE(_c)NI660X_DMA_CFG_SEL((_c), 0x1f)
@@ -287,21 +295,6 @@ static const struct ni_660x_register_data 
ni_660x_reg_data[NI660X_NUM_REGS] = {
[NI660X_IO_CFG_38_39]   = { 0x7a2, 2 }  /* read/write */
 };
 
-enum global_interrupt_status_register_bits {
-   Counter_0_Int_Bit = 0x100,
-   Counter_1_Int_Bit = 0x200,
-   Counter_2_Int_Bit = 0x400,
-   Counter_3_Int_Bit = 0x800,
-   Cascade_Int_Bit = 0x2000,
-   Global_Int_Bit = 0x8000
-};
-
-enum global_interrupt_config_register_bits {
-   Cascade_Int_Enable_Bit = 0x2000,
-   Global_Int_Polarity_Bit = 0x4000,
-   Global_Int_Enable_Bit = 0x8000
-};
-
 /* Offset of the GPCT chips from the base-address of the card */
 /* First chip is at base-address + 0x00, etc. */
 static const unsigned GPCT_OFFSET[2] = { 0x0, 0x800 };
@@ -1072,9 +1065,9 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
return ret;
}
dev->irq = pcidev->irq;
-   global_interrupt_config_bits = Global_Int_Enable_Bit;
+   global_interrupt_config_bits = NI660X_GLOBAL_INT_GLOBAL;
if (board->n_chips > 1)
-   global_interrupt_config_bits |= Cascade_Int_Enable_Bit;
+   global_interrupt_config_bits |= NI660X_GLOBAL_INT_CASCADE;
ni_660x_write_register(dev, 0, global_interrupt_config_bits,
   NI660X_GLOBAL_INT_CFG);
 
-- 
2.6.3

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


[PATCH v2 30/43] staging: comedi: ni_tio: make ni_gpct_device_destroy() NULL pointer safe

2016-03-22 Thread H Hartley Sweeten
Modify the pointer check to make this function NULL pointer safe.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_tio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/comedi/drivers/ni_tio.c 
b/drivers/staging/comedi/drivers/ni_tio.c
index b74e44e..623fc6c 100644
--- a/drivers/staging/comedi/drivers/ni_tio.c
+++ b/drivers/staging/comedi/drivers/ni_tio.c
@@ -1413,7 +1413,7 @@ EXPORT_SYMBOL_GPL(ni_gpct_device_construct);
 
 void ni_gpct_device_destroy(struct ni_gpct_device *counter_dev)
 {
-   if (!counter_dev->counters)
+   if (!counter_dev)
return;
kfree(counter_dev->counters);
kfree(counter_dev);
-- 
2.6.3

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


[PATCH v2 34/43] staging: comedi: ni_660x: init TIO chips before subdevice init

2016-03-22 Thread H Hartley Sweeten
For aesthetics, initialize the TIO chips before the subdevices are
allocated and initialized.

Refactor the function to initialize all the TIO chips and move it
to a better place in the driver.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 52 ++--
 1 file changed, 29 insertions(+), 23 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index c71dae8..afe62bf 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -703,20 +703,6 @@ static void ni_660x_free_mite_rings(struct comedi_device 
*dev)
}
 }
 
-static void init_tio_chip(struct comedi_device *dev, int chipset)
-{
-   struct ni_660x_private *devpriv = dev->private;
-   unsigned int i;
-
-   /*  init dma configuration register */
-   devpriv->dma_cfg[chipset] = 0;
-   for (i = 0; i < NI660X_MAX_DMA_CHANNEL; ++i)
-   devpriv->dma_cfg[chipset] |= NI660X_DMA_CFG_SEL_NONE(i);
-   ni_660x_write(dev, chipset, devpriv->dma_cfg[chipset], NI660X_DMA_CFG);
-   for (i = 0; i < NI660X_NUM_PFI_CHANNELS; ++i)
-   ni_660x_write(dev, chipset, 0, NI660X_IO_CFG(i));
-}
-
 static int ni_660x_dio_insn_bits(struct comedi_device *dev,
 struct comedi_subdevice *s,
 struct comedi_insn *insn,
@@ -857,6 +843,33 @@ static int ni_660x_dio_insn_config(struct comedi_device 
*dev,
return insn->n;
 }
 
+static void ni_660x_init_tio_chips(struct comedi_device *dev,
+  unsigned int n_chips)
+{
+   struct ni_660x_private *devpriv = dev->private;
+   unsigned int chip;
+   unsigned int chan;
+
+   /*
+* We use the ioconfig registers to control dio direction, so zero
+* output enables in stc dio control reg.
+*/
+   ni_660x_write(dev, 0, 0, NI660X_STC_DIO_CONTROL);
+
+   for (chip = 0; chip < n_chips; ++chip) {
+   /* init dma configuration register */
+   devpriv->dma_cfg[chip] = 0;
+   for (chan = 0; chan < NI660X_MAX_DMA_CHANNEL; ++chan)
+   devpriv->dma_cfg[chip] |= NI660X_DMA_CFG_SEL_NONE(chan);
+   ni_660x_write(dev, chip, devpriv->dma_cfg[chip],
+ NI660X_DMA_CFG);
+
+   /* init ioconfig registers */
+   for (chan = 0; chan < NI660X_NUM_PFI_CHANNELS; ++chan)
+   ni_660x_write(dev, chip, 0, NI660X_IO_CFG(chan));
+   }
+}
+
 static int ni_660x_auto_attach(struct comedi_device *dev,
   unsigned long context)
 {
@@ -899,6 +912,8 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
if (ret < 0)
return ret;
 
+   ni_660x_init_tio_chips(dev, board->n_chips);
+
ret = comedi_alloc_subdevices(dev, 2 + NI660X_MAX_COUNTERS);
if (ret)
return ret;
@@ -971,12 +986,6 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
s->insn_bits= ni_660x_dio_insn_bits;
s->insn_config  = ni_660x_dio_insn_config;
 
-   /*
-* We use the ioconfig registers to control dio direction, so zero
-* output enables in stc dio control reg.
-*/
-   ni_660x_write(dev, 0, 0, NI660X_STC_DIO_CONTROL);
-
n_counters = board->n_chips * NI660X_COUNTERS_PER_CHIP;
gpct_dev = ni_gpct_device_construct(dev,
ni_660x_gpct_write,
@@ -1017,9 +1026,6 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
}
}
 
-   for (i = 0; i < board->n_chips; ++i)
-   init_tio_chip(dev, i);
-
for (i = 0; i < n_counters; ++i)
ni_tio_init_counter(&gpct_dev->counters[i]);
 
-- 
2.6.3

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


[PATCH v2 38/43] staging: comedi: ni_660x: remove inline mite_ring()

2016-03-22 Thread H Hartley Sweeten
This fuction just returns a pointer from the private data. The name
might provide some confusion since it appears to be an exported
function from the mite driver.

Just remove it and get the pointer directly where needed.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 21 +++--
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index cf25892..1cca9ea 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -465,16 +465,6 @@ static unsigned int ni_660x_gpct_read(struct ni_gpct 
*counter,
return ni_660x_read(dev, counter->chip_index, ni_660x_register);
 }
 
-static inline struct mite_dma_descriptor_ring *mite_ring(struct ni_660x_private
-*priv,
-struct ni_gpct
-*counter)
-{
-   unsigned int chip = counter->chip_index;
-
-   return priv->mite_rings[chip][counter->counter_index];
-}
-
 static inline void ni_660x_set_dma_channel(struct comedi_device *dev,
   unsigned int mite_channel,
   struct ni_gpct *counter)
@@ -515,12 +505,13 @@ static int ni_660x_request_mite_channel(struct 
comedi_device *dev,
enum comedi_io_direction direction)
 {
struct ni_660x_private *devpriv = dev->private;
-   unsigned long flags;
+   struct mite_dma_descriptor_ring *ring;
struct mite_channel *mite_chan;
+   unsigned long flags;
 
spin_lock_irqsave(&devpriv->mite_channel_lock, flags);
-   mite_chan = mite_request_channel(devpriv->mite,
-mite_ring(devpriv, counter));
+   ring = devpriv->mite_rings[counter->chip_index][counter->counter_index];
+   mite_chan = mite_request_channel(devpriv->mite, ring);
if (!mite_chan) {
spin_unlock_irqrestore(&devpriv->mite_channel_lock, flags);
dev_err(dev->class_dev,
@@ -645,9 +636,11 @@ static int ni_660x_buf_change(struct comedi_device *dev,
 {
struct ni_660x_private *devpriv = dev->private;
struct ni_gpct *counter = s->private;
+   struct mite_dma_descriptor_ring *ring;
int ret;
 
-   ret = mite_buf_change(mite_ring(devpriv, counter), s);
+   ring = devpriv->mite_rings[counter->chip_index][counter->counter_index];
+   ret = mite_buf_change(ring, s);
if (ret < 0)
return ret;
 
-- 
2.6.3

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


[PATCH v2 31/43] staging: comedi: ni_660x: ni_gpct_device_destroy() can handle a NULL pointer

2016-03-22 Thread H Hartley Sweeten
Remove the unnecessary NULL pointer check.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 35602cc..2440cb6 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -1067,8 +1067,7 @@ static void ni_660x_detach(struct comedi_device *dev)
if (dev->irq)
free_irq(dev->irq, dev);
if (devpriv) {
-   if (devpriv->counter_dev)
-   ni_gpct_device_destroy(devpriv->counter_dev);
+   ni_gpct_device_destroy(devpriv->counter_dev);
ni_660x_free_mite_rings(dev);
mite_detach(devpriv->mite);
}
-- 
2.6.3

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


[PATCH v2 23/43] staging: comedi: ni_660x: tidy up ni_660x_set_pfi_routing()

2016-03-22 Thread H Hartley Sweeten
Use the comedi.h provided constants (enum ni_660x_pfi_routing) instead
of defining new ones for the output sources.

Use a switch to clarify the channel/source validation.

For aesthetics, rename the private data members 'pfi_output_selects' and
'pfi_direction_bits'.

Remove the 'min_counter_pfi_chan' and 'max_dio_pfi_chan' from
enum ni_660x_constants. The open coded values make the code easier
to follow.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 65 +---
 1 file changed, 27 insertions(+), 38 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index f614927..3415a15 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -42,8 +42,6 @@
 #include "ni_tio.h"
 
 enum ni_660x_constants {
-   min_counter_pfi_chan = 8,
-   max_dio_pfi_chan = 31,
counters_per_chip = 4
 };
 
@@ -172,10 +170,6 @@ enum ni_660x_register {
 #define NI660X_IO_CFG(x)   (NI660X_IO_CFG_0_1 + ((x) / 2))
 #define NI660X_IO_CFG_OUT_SEL(_c, _s)  (((_s) & 0x3) << (((_c) % 2) ? 0 : 8))
 #define NI660X_IO_CFG_OUT_SEL_MASK(_c) NI660X_IO_CFG_OUT_SEL((_c), 0x3)
-#define NI660X_IO_CFG_OUT_SEL_HIGH_Z   0
-#define NI660X_IO_CFG_OUT_SEL_COUNTER  1
-#define NI660X_IO_CFG_OUT_SEL_DO   2
-#define NI660X_IO_CFG_OUT_SEL_MAX  3
 #define NI660X_IO_CFG_IN_SEL(_c, _s)   (((_s) & 0x7) << (((_c) % 2) ? 4 : 12))
 #define NI660X_IO_CFG_IN_SEL_MASK(_c)  NI660X_IO_CFG_IN_SEL((_c), 0x7)
 
@@ -331,7 +325,6 @@ static const struct ni_660x_board ni_660x_boards[] = {
 struct ni_660x_private {
struct mite_struct *mite;
struct ni_gpct_device *counter_dev;
-   u64 pfi_direction_bits;
struct mite_dma_descriptor_ring
*mite_rings[NI_660X_MAX_NUM_CHIPS][counters_per_chip];
spinlock_t mite_channel_lock;
@@ -339,7 +332,8 @@ struct ni_660x_private {
spinlock_t interrupt_lock;
unsigned int dma_cfg[NI_660X_MAX_NUM_CHIPS];
spinlock_t soft_reg_copy_lock;
-   unsigned short pfi_output_selects[NUM_PFI_CHANNELS];
+   unsigned int io_cfg[NUM_PFI_CHANNELS];
+   u64 io_dir;
 };
 
 static enum ni_660x_register ni_gpct_to_660x_register(enum ni_gpct_register 
reg)
@@ -728,7 +722,7 @@ static int ni_660x_allocate_private(struct comedi_device 
*dev)
spin_lock_init(&devpriv->interrupt_lock);
spin_lock_init(&devpriv->soft_reg_copy_lock);
for (i = 0; i < NUM_PFI_CHANNELS; ++i)
-   devpriv->pfi_output_selects[i] = NI660X_IO_CFG_OUT_SEL_COUNTER;
+   devpriv->io_cfg[i] = NI_660X_PFI_OUTPUT_COUNTER;
 
return 0;
 }
@@ -817,7 +811,7 @@ static void ni_660x_select_pfi_output(struct comedi_device 
*dev,
unsigned int bits;
 
if (board->n_chips > 1) {
-   if (out_sel == NI660X_IO_CFG_OUT_SEL_COUNTER &&
+   if (out_sel == NI_660X_PFI_OUTPUT_COUNTER &&
chan >= 8 && chan <= 23) {
/* counters 4-7 pfi channels */
active_chip = 1;
@@ -833,8 +827,7 @@ static void ni_660x_select_pfi_output(struct comedi_device 
*dev,
/* set the pfi channel to high-z on the inactive chip */
bits = ni_660x_read(dev, idle_chip, NI660X_IO_CFG(chan));
bits &= ~NI660X_IO_CFG_OUT_SEL_MASK(chan);
-   bits |= NI660X_IO_CFG_OUT_SEL(chan,
- NI660X_IO_CFG_OUT_SEL_HIGH_Z);
+   bits |= NI660X_IO_CFG_OUT_SEL(chan, 0); /* high-z */
ni_660x_write(dev, idle_chip, bits, NI660X_IO_CFG(chan));
}
 
@@ -850,22 +843,21 @@ static int ni_660x_set_pfi_routing(struct comedi_device 
*dev,
 {
struct ni_660x_private *devpriv = dev->private;
 
-   if (source > NI660X_IO_CFG_OUT_SEL_MAX)
-   return -EINVAL;
-   if (source == NI660X_IO_CFG_OUT_SEL_HIGH_Z)
-   return -EINVAL;
-   if (chan < min_counter_pfi_chan) {
-   if (source == NI660X_IO_CFG_OUT_SEL_COUNTER)
+   switch (source) {
+   case NI_660X_PFI_OUTPUT_COUNTER:
+   if (chan < 8)
return -EINVAL;
-   } else if (chan > max_dio_pfi_chan) {
-   if (source == NI660X_IO_CFG_OUT_SEL_DO)
+   break;
+   case NI_660X_PFI_OUTPUT_DIO:
+   if (chan > 31)
return -EINVAL;
+   default:
+   return -EINVAL;
}
 
-   devpriv->pfi_output_selects[chan] = source;
-   if (devpriv->pfi_direction_bits & (1ULL << chan))
-   ni_660x_select_pfi_output(dev, chan,
- devpriv->pfi_output_selects[chan]);
+   devpriv->io_cfg[chan] = source;
+   if (devpriv->io_dir & (1ULL << chan))
+   ni_660x_select_pfi_output(dev, chan, devpriv->io_cfg[chan]);
   

[PATCH v2 32/43] staging: comedi: ni_mio_common: ni_gpct_device_destroy() can handle a NULL pointer

2016-03-22 Thread H Hartley Sweeten
Remove the unnecessary NULL pointer check.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_mio_common.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c 
b/drivers/staging/comedi/drivers/ni_mio_common.c
index dcaf7e8..71c8fd2 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -5675,8 +5675,6 @@ static void mio_common_detach(struct comedi_device *dev)
 {
struct ni_private *devpriv = dev->private;
 
-   if (devpriv) {
-   if (devpriv->counter_dev)
-   ni_gpct_device_destroy(devpriv->counter_dev);
-   }
+   if (devpriv)
+   ni_gpct_device_destroy(devpriv->counter_dev);
 }
-- 
2.6.3

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


[PATCH v2 13/43] staging: comedi: ni_660x: tidy up ni_gpct_{write, read}_register()

2016-03-22 Thread H Hartley Sweeten
Rename these functions so they have namespace associated with the
driver.

Fix the checkpatch.pl issues:

WARNING: Prefer 'unsigned int' to bare use of 'unsigned'

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index cd101bb..e0532f4 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -527,24 +527,22 @@ static unsigned int ni_660x_read(struct comedi_device 
*dev,
return readl(dev->mmio + addr);
 }
 
-static void ni_gpct_write_register(struct ni_gpct *counter, unsigned bits,
-  enum ni_gpct_register reg)
+static void ni_660x_gpct_write(struct ni_gpct *counter, unsigned int bits,
+  enum ni_gpct_register reg)
 {
struct comedi_device *dev = counter->counter_dev->dev;
enum ni_660x_register ni_660x_register = ni_gpct_to_660x_register(reg);
-   unsigned chip = counter->chip_index;
 
-   ni_660x_write(dev, chip, bits, ni_660x_register);
+   ni_660x_write(dev, counter->chip_index, bits, ni_660x_register);
 }
 
-static unsigned ni_gpct_read_register(struct ni_gpct *counter,
+static unsigned int ni_660x_gpct_read(struct ni_gpct *counter,
  enum ni_gpct_register reg)
 {
struct comedi_device *dev = counter->counter_dev->dev;
enum ni_660x_register ni_660x_register = ni_gpct_to_660x_register(reg);
-   unsigned chip = counter->chip_index;
 
-   return ni_660x_read(dev, chip, ni_660x_register);
+   return ni_660x_read(dev, counter->chip_index, ni_660x_register);
 }
 
 static inline struct mite_dma_descriptor_ring *mite_ring(struct ni_660x_private
@@ -999,8 +997,8 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
ni_660x_write(dev, 0, 0, NI660X_STC_DIO_CONTROL);
 
devpriv->counter_dev = ni_gpct_device_construct(dev,
-&ni_gpct_write_register,
-&ni_gpct_read_register,
+ni_660x_gpct_write,
+ni_660x_gpct_read,
 ni_gpct_variant_660x,
 ni_660x_num_counters
 (dev));
-- 
2.6.3

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


[PATCH v2 21/43] staging: comedi: ni_660x: tidy up Digital I/O subdevice init

2016-03-22 Thread H Hartley Sweeten
Add some whitespace to the Digital I/O subdevice init and add a
comment about the channels. This driver is a bit goofy, only 32 of
the 40 channels can actually be used for Digital I/Os and 32 of
them can be routed to the counters for alternate use.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 68 
 1 file changed, 60 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 4f7f5ca..f24009c 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -964,15 +964,67 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
/* Old GENERAL-PURPOSE COUNTER/TIME (GPCT) subdevice, no longer used */
s->type = COMEDI_SUBD_UNUSED;
 
+   /*
+* Digital I/O subdevice
+*
+* There are 40 channels but only the first 32 can be digital I/Os.
+* The last 8 are dedicated to counters 0 and 1.
+*
+* Counter 0-3 signals are from the first TIO chip.
+* Counter 4-7 signals are from the second TIO chip.
+*
+* Comedi   External
+* PFI Chan DIO ChanCounter Signal
+* ---  --
+* 00
+* 11
+* 22
+* 33
+* 44
+* 55
+* 66
+* 77
+* 88   CTR 7 OUT
+* 99   CTR 7 AUX
+*10   10   CTR 7 GATE
+*11   11   CTR 7 SOURCE
+*12   12   CTR 6 OUT
+*13   13   CTR 6 AUX
+*14   14   CTR 6 GATE
+*15   15   CTR 6 SOURCE
+*16   16   CTR 5 OUT
+*17   17   CTR 5 AUX
+*18   18   CTR 5 GATE
+*19   19   CTR 5 SOURCE
+*20   20   CTR 4 OUT
+*21   21   CTR 4 AUX
+*22   22   CTR 4 GATE
+*23   23   CTR 4 SOURCE
+*24   24   CTR 3 OUT
+*25   25   CTR 3 AUX
+*26   26   CTR 3 GATE
+*27   27   CTR 3 SOURCE
+*28   28   CTR 2 OUT
+*29   29   CTR 2 AUX
+*30   30   CTR 2 GATE
+*31   31   CTR 2 SOURCE
+*32CTR 1 OUT
+*33CTR 1 AUX
+*34CTR 1 GATE
+*35CTR 1 SOURCE
+*36CTR 0 OUT
+*37CTR 0 AUX
+*38CTR 0 GATE
+*39CTR 0 SOURCE
+*/
s = &dev->subdevices[subdev++];
-   /* DIGITAL I/O SUBDEVICE */
-   s->type = COMEDI_SUBD_DIO;
-   s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
-   s->n_chan = NUM_PFI_CHANNELS;
-   s->maxdata = 1;
-   s->range_table = &range_digital;
-   s->insn_bits = ni_660x_dio_insn_bits;
-   s->insn_config = ni_660x_dio_insn_config;
+   s->type = COMEDI_SUBD_DIO;
+   s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
+   s->n_chan   = NUM_PFI_CHANNELS;
+   s->maxdata  = 1;
+   s->range_table  = &range_digital;
+   s->insn_bits= ni_660x_dio_insn_bits;
+   s->insn_config  = ni_660x_dio_insn_config;
 
/*
 * We use the ioconfig registers to control dio direction, so zero
-- 
2.6.3

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


[PATCH v2 40/43] staging: comedi: ni_660x: remove ni_gpct_to_660x_register[]

2016-03-22 Thread H Hartley Sweeten
enum ni_gpct_register and enum ni_660x_register now have a 1:1
relationship for the NITIO_* registers. The static const array
is no longer necessary to find the proper NI660X_* register for
a given NITIO_*. Remove it and refactor the register read/write
functions.

Use the NITIO_* values to init the ni_660x_reg_data[] array and
remove the unnecessary NI660X_* enum values.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 307 ---
 1 file changed, 74 insertions(+), 233 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index ad67ee5..85c793a 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -43,75 +43,7 @@
 
 /* See Register-Level Programmer Manual page 3.1 */
 enum ni_660x_register {
-   NI660X_G0_AUTO_INC,
-   NI660X_G1_AUTO_INC,
-   NI660X_G2_AUTO_INC,
-   NI660X_G3_AUTO_INC,
-   NI660X_G0_CMD,
-   NI660X_G1_CMD,
-   NI660X_G2_CMD,
-   NI660X_G3_CMD,
-   NI660X_G0_HW_SAVE,
-   NI660X_G1_HW_SAVE,
-   NI660X_G2_HW_SAVE,
-   NI660X_G3_HW_SAVE,
-   NI660X_G0_SW_SAVE,
-   NI660X_G1_SW_SAVE,
-   NI660X_G2_SW_SAVE,
-   NI660X_G3_SW_SAVE,
-   NI660X_G0_MODE,
-   NI660X_G1_MODE,
-   NI660X_G2_MODE,
-   NI660X_G3_MODE,
-   NI660X_G0_LOADA,
-   NI660X_G1_LOADA,
-   NI660X_G2_LOADA,
-   NI660X_G3_LOADA,
-   NI660X_G0_LOADB,
-   NI660X_G1_LOADB,
-   NI660X_G2_LOADB,
-   NI660X_G3_LOADB,
-   NI660X_G0_INPUT_SEL,
-   NI660X_G1_INPUT_SEL,
-   NI660X_G2_INPUT_SEL,
-   NI660X_G3_INPUT_SEL,
-   NI660X_G0_CNT_MODE,
-   NI660X_G1_CNT_MODE,
-   NI660X_G2_CNT_MODE,
-   NI660X_G3_CNT_MODE,
-   NI660X_G0_GATE2,
-   NI660X_G1_GATE2,
-   NI660X_G2_GATE2,
-   NI660X_G3_GATE2,
-   NI660X_G01_STATUS,
-   NI660X_G23_STATUS,
-   NI660X_G01_RESET,
-   NI660X_G23_RESET,
-   NI660X_G01_STATUS1,
-   NI660X_G23_STATUS1,
-   NI660X_G01_STATUS2,
-   NI660X_G23_STATUS2,
-   NI660X_G0_DMA_CFG,
-   NI660X_G1_DMA_CFG,
-   NI660X_G2_DMA_CFG,
-   NI660X_G3_DMA_CFG,
-   NI660X_G0_DMA_STATUS,
-   NI660X_G1_DMA_STATUS,
-   NI660X_G2_DMA_STATUS,
-   NI660X_G3_DMA_STATUS,
-   NI660X_G0_INT_ACK,
-   NI660X_G1_INT_ACK,
-   NI660X_G2_INT_ACK,
-   NI660X_G3_INT_ACK,
-   NI660X_G0_STATUS,
-   NI660X_G1_STATUS,
-   NI660X_G2_STATUS,
-   NI660X_G3_STATUS,
-   NI660X_G0_INT_ENA,
-   NI660X_G1_INT_ENA,
-   NI660X_G2_INT_ENA,
-   NI660X_G3_INT_ENA,
-
+   /* see enum ni_gpct_register */
NI660X_STC_DIO_PARALLEL_INPUT = NITIO_NUM_REGS,
NI660X_STC_DIO_OUTPUT,
NI660X_STC_DIO_CONTROL,
@@ -172,78 +104,78 @@ struct ni_660x_register_data {
 };
 
 static const struct ni_660x_register_data ni_660x_reg_data[NI660X_NUM_REGS] = {
-   [NI660X_G0_INT_ACK] = { 0x004, 2 }, /* write */
-   [NI660X_G0_STATUS]  = { 0x004, 2 }, /* read */
-   [NI660X_G1_INT_ACK] = { 0x006, 2 }, /* write */
-   [NI660X_G1_STATUS]  = { 0x006, 2 }, /* read */
-   [NI660X_G01_STATUS] = { 0x008, 2 }, /* read */
-   [NI660X_G0_CMD] = { 0x00c, 2 }, /* write */
+   [NITIO_G0_INT_ACK]  = { 0x004, 2 }, /* write */
+   [NITIO_G0_STATUS]   = { 0x004, 2 }, /* read */
+   [NITIO_G1_INT_ACK]  = { 0x006, 2 }, /* write */
+   [NITIO_G1_STATUS]   = { 0x006, 2 }, /* read */
+   [NITIO_G01_STATUS]  = { 0x008, 2 }, /* read */
+   [NITIO_G0_CMD]  = { 0x00c, 2 }, /* write */
[NI660X_STC_DIO_PARALLEL_INPUT] = { 0x00e, 2 }, /* read */
-   [NI660X_G1_CMD] = { 0x00e, 2 }, /* write */
-   [NI660X_G0_HW_SAVE] = { 0x010, 4 }, /* read */
-   [NI660X_G1_HW_SAVE] = { 0x014, 4 }, /* read */
+   [NITIO_G1_CMD]  = { 0x00e, 2 }, /* write */
+   [NITIO_G0_HW_SAVE]  = { 0x010, 4 }, /* read */
+   [NITIO_G1_HW_SAVE]  = { 0x014, 4 }, /* read */
[NI660X_STC_DIO_OUTPUT] = { 0x014, 2 }, /* write */
[NI660X_STC_DIO_CONTROL]= { 0x016, 2 }, /* write */
-   [NI660X_G0_SW_SAVE] = { 0x018, 4 }, /* read */
-   [NI660X_G1_SW_SAVE] = { 0x01c, 4 }, /* read */
-   [NI660X_G0_MODE]= { 0x034, 2 }, /* write */
-   [NI660X_G01_STATUS1]= { 0x036, 2 }, /* read */
-   [NI660X_G1_MODE]= { 0x036, 2 }, /* write */
+   [NITIO_G0_SW_SAVE]  = { 0x018, 4 }, /* read */
+   [NITIO_G1_SW_SAVE]  = { 0x01c, 4 }, /* read */
+   [NITIO_G0_MODE] = { 0x034, 2 }, /* write */
+   [NITIO_G01_STATU

[PATCH v2 26/43] staging: comedi: ni_660x: add comments for the spinlock_t definitions

2016-03-22 Thread H Hartley Sweeten
Fix the checkpatch.pl issues:

CHECK: spinlock_t definition without comment

For aesthetics, rename the 'soft_reg_copy_lock' to clarify what it's
used for.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 16 +---
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 3edea99..2926d26 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -398,11 +398,13 @@ struct ni_660x_private {
struct ni_gpct_device *counter_dev;
struct mite_dma_descriptor_ring
*mite_rings[NI_660X_MAX_NUM_CHIPS][counters_per_chip];
+   /* protects mite channel request/release */
spinlock_t mite_channel_lock;
-   /* interrupt_lock prevents races between interrupt and comedi_poll */
+   /* prevents races between interrupt and comedi_poll */
spinlock_t interrupt_lock;
+   /* protects dma_cfg changes */
+   spinlock_t dma_cfg_lock;
unsigned int dma_cfg[NI_660X_MAX_NUM_CHIPS];
-   spinlock_t soft_reg_copy_lock;
unsigned int io_cfg[NUM_PFI_CHANNELS];
u64 io_dir;
 };
@@ -482,7 +484,7 @@ static inline void ni_660x_set_dma_channel(struct 
comedi_device *dev,
unsigned int chip = counter->chip_index;
unsigned long flags;
 
-   spin_lock_irqsave(&devpriv->soft_reg_copy_lock, flags);
+   spin_lock_irqsave(&devpriv->dma_cfg_lock, flags);
devpriv->dma_cfg[chip] &= ~NI660X_DMA_CFG_SEL_MASK(mite_channel);
devpriv->dma_cfg[chip] |= NI660X_DMA_CFG_SEL(mite_channel,
 counter->counter_index);
@@ -490,7 +492,7 @@ static inline void ni_660x_set_dma_channel(struct 
comedi_device *dev,
  NI660X_DMA_CFG_RESET(mite_channel),
  NI660X_DMA_CFG);
mmiowb();
-   spin_unlock_irqrestore(&devpriv->soft_reg_copy_lock, flags);
+   spin_unlock_irqrestore(&devpriv->dma_cfg_lock, flags);
 }
 
 static inline void ni_660x_unset_dma_channel(struct comedi_device *dev,
@@ -501,12 +503,12 @@ static inline void ni_660x_unset_dma_channel(struct 
comedi_device *dev,
unsigned int chip = counter->chip_index;
unsigned long flags;
 
-   spin_lock_irqsave(&devpriv->soft_reg_copy_lock, flags);
+   spin_lock_irqsave(&devpriv->dma_cfg_lock, flags);
devpriv->dma_cfg[chip] &= ~NI660X_DMA_CFG_SEL_MASK(mite_channel);
devpriv->dma_cfg[chip] |= NI660X_DMA_CFG_SEL_NONE(mite_channel);
ni_660x_write(dev, chip, devpriv->dma_cfg[chip], NI660X_DMA_CFG);
mmiowb();
-   spin_unlock_irqrestore(&devpriv->soft_reg_copy_lock, flags);
+   spin_unlock_irqrestore(&devpriv->dma_cfg_lock, flags);
 }
 
 static int ni_660x_request_mite_channel(struct comedi_device *dev,
@@ -662,7 +664,7 @@ static int ni_660x_allocate_private(struct comedi_device 
*dev)
 
spin_lock_init(&devpriv->mite_channel_lock);
spin_lock_init(&devpriv->interrupt_lock);
-   spin_lock_init(&devpriv->soft_reg_copy_lock);
+   spin_lock_init(&devpriv->dma_cfg_lock);
for (i = 0; i < NUM_PFI_CHANNELS; ++i)
devpriv->io_cfg[i] = NI_660X_PFI_OUTPUT_COUNTER;
 
-- 
2.6.3

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


[PATCH v2 06/43] staging: comedi: ni_660x: cleanup the NI660X_IO_CFG register helpers

2016-03-22 Thread H Hartley Sweeten
Convert the inline functions used to set the bits in the NI600X_IO_CFG
registers into macros. Also convert the enum ni_660x_pfi_output_select
into defines. This clarifies the association with the register.

This also fixes a number of checkpatch.pl issues about:

WARNING: Prefer 'unsigned int' to bare use of 'unsigned'

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 81 +++-
 1 file changed, 28 insertions(+), 53 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index d76a5b0..75c6032 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -156,14 +156,15 @@ enum ni_660x_register {
NI660X_NUM_REGS,
 };
 
-#define NI660X_IO_CFG(x)   (NI660X_IO_CFG_0_1 + ((x) / 2))
-
-enum ni_660x_pfi_output_select {
-   pfi_output_select_high_Z = 0,
-   pfi_output_select_counter = 1,
-   pfi_output_select_do = 2,
-   num_pfi_output_selects
-};
+#define NI660X_IO_CFG(x)   (NI660X_IO_CFG_0_1 + ((x) / 2))
+#define NI660X_IO_CFG_OUT_SEL(_c, _s)  (((_s) & 0x3) << (((_c) % 2) ? 0 : 8))
+#define NI660X_IO_CFG_OUT_SEL_MASK(_c) NI660X_IO_CFG_OUT_SEL((_c), 0x3)
+#define NI660X_IO_CFG_OUT_SEL_HIGH_Z   0
+#define NI660X_IO_CFG_OUT_SEL_COUNTER  1
+#define NI660X_IO_CFG_OUT_SEL_DO   2
+#define NI660X_IO_CFG_OUT_SEL_MAX  3
+#define NI660X_IO_CFG_IN_SEL(_c, _s)   (((_s) & 0x7) << (((_c) % 2) ? 4 : 12))
+#define NI660X_IO_CFG_IN_SEL_MASK(_c)  NI660X_IO_CFG_IN_SEL((_c), 0x7)
 
 enum ni_660x_subdevices {
NI_660X_DIO_SUBDEV = 1,
@@ -285,34 +286,6 @@ enum clock_config_register_bits {
CounterSwap = 0x1 << 21
 };
 
-/* ioconfigreg */
-static inline unsigned ioconfig_bitshift(unsigned pfi_channel)
-{
-   return (pfi_channel % 2) ? 0 : 8;
-}
-
-static inline unsigned pfi_output_select_mask(unsigned pfi_channel)
-{
-   return 0x3 << ioconfig_bitshift(pfi_channel);
-}
-
-static inline unsigned pfi_output_select_bits(unsigned pfi_channel,
- unsigned output_select)
-{
-   return (output_select & 0x3) << ioconfig_bitshift(pfi_channel);
-}
-
-static inline unsigned pfi_input_select_mask(unsigned pfi_channel)
-{
-   return 0x7 << (4 + ioconfig_bitshift(pfi_channel));
-}
-
-static inline unsigned pfi_input_select_bits(unsigned pfi_channel,
-unsigned input_select)
-{
-   return (input_select & 0x7) << (4 + ioconfig_bitshift(pfi_channel));
-}
-
 /* dma configuration register bits */
 static inline unsigned dma_select_mask(unsigned dma_channel)
 {
@@ -808,7 +781,7 @@ static int ni_660x_allocate_private(struct comedi_device 
*dev)
spin_lock_init(&devpriv->interrupt_lock);
spin_lock_init(&devpriv->soft_reg_copy_lock);
for (i = 0; i < NUM_PFI_CHANNELS; ++i)
-   devpriv->pfi_output_selects[i] = pfi_output_select_counter;
+   devpriv->pfi_output_selects[i] = NI660X_IO_CFG_OUT_SEL_COUNTER;
 
return 0;
 }
@@ -896,7 +869,7 @@ static void ni_660x_select_pfi_output(struct comedi_device 
*dev,
unsigned idle_bits;
 
if (board->n_chips > 1) {
-   if (output_select == pfi_output_select_counter &&
+   if (output_select == NI660X_IO_CFG_OUT_SEL_COUNTER &&
pfi_channel >= counter_4_7_first_pfi &&
pfi_channel <= counter_4_7_last_pfi) {
active_chipset = 1;
@@ -911,10 +884,10 @@ static void ni_660x_select_pfi_output(struct 
comedi_device *dev,
idle_bits =
ni_660x_read_register(dev, idle_chipset,
  NI660X_IO_CFG(pfi_channel));
-   idle_bits &= ~pfi_output_select_mask(pfi_channel);
+   idle_bits &= ~NI660X_IO_CFG_OUT_SEL_MASK(pfi_channel);
idle_bits |=
-   pfi_output_select_bits(pfi_channel,
-  pfi_output_select_high_Z);
+   NI660X_IO_CFG_OUT_SEL(pfi_channel,
+ NI660X_IO_CFG_OUT_SEL_HIGH_Z);
ni_660x_write_register(dev, idle_chipset, idle_bits,
   NI660X_IO_CFG(pfi_channel));
}
@@ -922,8 +895,8 @@ static void ni_660x_select_pfi_output(struct comedi_device 
*dev,
active_bits =
ni_660x_read_register(dev, active_chipset,
  NI660X_IO_CFG(pfi_channel));
-   active_bits &= ~pfi_output_select_mask(pfi_channel);
-   active_bits |= pfi_output_select_bits(pfi_channel, output_select);
+   active_bits &= ~NI660X_IO_CFG_OUT_SEL_MASK(pfi_channel);
+   active_bits |= NI660X_IO_CFG_OUT_SEL(pfi_channel, output_select);
ni_660x_write_register(dev, active_chipset, active_bits,
   NI66

[PATCH v2 39/43] staging: comedi: ni_660x: sort enum ni_660x_register

2016-03-22 Thread H Hartley Sweeten
Sort this enum so that it has a 1:1 relationship with the ni_tio.h
enum ni_gpct_register.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 95 
 1 file changed, 48 insertions(+), 47 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 1cca9ea..ad67ee5 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -43,78 +43,79 @@
 
 /* See Register-Level Programmer Manual page 3.1 */
 enum ni_660x_register {
-   NI660X_G0_INT_ACK,
-   NI660X_G0_STATUS,
-   NI660X_G1_INT_ACK,
-   NI660X_G1_STATUS,
-   NI660X_G01_STATUS,
+   NI660X_G0_AUTO_INC,
+   NI660X_G1_AUTO_INC,
+   NI660X_G2_AUTO_INC,
+   NI660X_G3_AUTO_INC,
NI660X_G0_CMD,
-   NI660X_STC_DIO_PARALLEL_INPUT,
NI660X_G1_CMD,
+   NI660X_G2_CMD,
+   NI660X_G3_CMD,
NI660X_G0_HW_SAVE,
NI660X_G1_HW_SAVE,
-   NI660X_STC_DIO_OUTPUT,
-   NI660X_STC_DIO_CONTROL,
+   NI660X_G2_HW_SAVE,
+   NI660X_G3_HW_SAVE,
NI660X_G0_SW_SAVE,
NI660X_G1_SW_SAVE,
+   NI660X_G2_SW_SAVE,
+   NI660X_G3_SW_SAVE,
NI660X_G0_MODE,
-   NI660X_G01_STATUS1,
NI660X_G1_MODE,
-   NI660X_STC_DIO_SERIAL_INPUT,
+   NI660X_G2_MODE,
+   NI660X_G3_MODE,
NI660X_G0_LOADA,
-   NI660X_G01_STATUS2,
-   NI660X_G0_LOADB,
NI660X_G1_LOADA,
+   NI660X_G2_LOADA,
+   NI660X_G3_LOADA,
+   NI660X_G0_LOADB,
NI660X_G1_LOADB,
+   NI660X_G2_LOADB,
+   NI660X_G3_LOADB,
NI660X_G0_INPUT_SEL,
NI660X_G1_INPUT_SEL,
-   NI660X_G0_AUTO_INC,
-   NI660X_G1_AUTO_INC,
-   NI660X_G01_RESET,
-   NI660X_G0_INT_ENA,
-   NI660X_G1_INT_ENA,
+   NI660X_G2_INPUT_SEL,
+   NI660X_G3_INPUT_SEL,
NI660X_G0_CNT_MODE,
NI660X_G1_CNT_MODE,
+   NI660X_G2_CNT_MODE,
+   NI660X_G3_CNT_MODE,
NI660X_G0_GATE2,
NI660X_G1_GATE2,
+   NI660X_G2_GATE2,
+   NI660X_G3_GATE2,
+   NI660X_G01_STATUS,
+   NI660X_G23_STATUS,
+   NI660X_G01_RESET,
+   NI660X_G23_RESET,
+   NI660X_G01_STATUS1,
+   NI660X_G23_STATUS1,
+   NI660X_G01_STATUS2,
+   NI660X_G23_STATUS2,
NI660X_G0_DMA_CFG,
-   NI660X_G0_DMA_STATUS,
NI660X_G1_DMA_CFG,
+   NI660X_G2_DMA_CFG,
+   NI660X_G3_DMA_CFG,
+   NI660X_G0_DMA_STATUS,
NI660X_G1_DMA_STATUS,
+   NI660X_G2_DMA_STATUS,
+   NI660X_G3_DMA_STATUS,
+   NI660X_G0_INT_ACK,
+   NI660X_G1_INT_ACK,
NI660X_G2_INT_ACK,
-   NI660X_G2_STATUS,
NI660X_G3_INT_ACK,
+   NI660X_G0_STATUS,
+   NI660X_G1_STATUS,
+   NI660X_G2_STATUS,
NI660X_G3_STATUS,
-   NI660X_G23_STATUS,
-   NI660X_G2_CMD,
-   NI660X_G3_CMD,
-   NI660X_G2_HW_SAVE,
-   NI660X_G3_HW_SAVE,
-   NI660X_G2_SW_SAVE,
-   NI660X_G3_SW_SAVE,
-   NI660X_G2_MODE,
-   NI660X_G23_STATUS1,
-   NI660X_G3_MODE,
-   NI660X_G2_LOADA,
-   NI660X_G23_STATUS2,
-   NI660X_G2_LOADB,
-   NI660X_G3_LOADA,
-   NI660X_G3_LOADB,
-   NI660X_G2_INPUT_SEL,
-   NI660X_G3_INPUT_SEL,
-   NI660X_G2_AUTO_INC,
-   NI660X_G3_AUTO_INC,
-   NI660X_G23_RESET,
+   NI660X_G0_INT_ENA,
+   NI660X_G1_INT_ENA,
NI660X_G2_INT_ENA,
NI660X_G3_INT_ENA,
-   NI660X_G2_CNT_MODE,
-   NI660X_G3_CNT_MODE,
-   NI660X_G3_GATE2,
-   NI660X_G2_GATE2,
-   NI660X_G2_DMA_CFG,
-   NI660X_G2_DMA_STATUS,
-   NI660X_G3_DMA_CFG,
-   NI660X_G3_DMA_STATUS,
+
+   NI660X_STC_DIO_PARALLEL_INPUT = NITIO_NUM_REGS,
+   NI660X_STC_DIO_OUTPUT,
+   NI660X_STC_DIO_CONTROL,
+   NI660X_STC_DIO_SERIAL_INPUT,
NI660X_DIO32_INPUT,
NI660X_DIO32_OUTPUT,
NI660X_CLK_CFG,
-- 
2.6.3

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


[PATCH v2 18/43] staging: comedi: ni_660x: remove ni_660x_num_counters()

2016-03-22 Thread H Hartley Sweeten
This inline function is only used by the (*auto_attach). Remove it
and just use a local variable for the calculation.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 16 +---
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 595c862..6a3a12e 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -342,13 +342,6 @@ struct ni_660x_private {
unsigned short pfi_output_selects[NUM_PFI_CHANNELS];
 };
 
-static inline unsigned ni_660x_num_counters(struct comedi_device *dev)
-{
-   const struct ni_660x_board *board = dev->board_ptr;
-
-   return board->n_chips * counters_per_chip;
-}
-
 static enum ni_660x_register ni_gpct_to_660x_register(enum ni_gpct_register 
reg)
 {
switch (reg) {
@@ -927,6 +920,7 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
const struct ni_660x_board *board = NULL;
struct ni_660x_private *devpriv;
struct comedi_subdevice *s;
+   unsigned int n_counters;
int subdev;
int ret;
unsigned i;
@@ -986,17 +980,17 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
 */
ni_660x_write(dev, 0, 0, NI660X_STC_DIO_CONTROL);
 
+   n_counters = board->n_chips * counters_per_chip;
devpriv->counter_dev = ni_gpct_device_construct(dev,
 ni_660x_gpct_write,
 ni_660x_gpct_read,
 ni_gpct_variant_660x,
-ni_660x_num_counters
-(dev));
+n_counters);
if (!devpriv->counter_dev)
return -ENOMEM;
for (i = 0; i < NI_660X_MAX_NUM_COUNTERS; ++i) {
s = &dev->subdevices[subdev++];
-   if (i < ni_660x_num_counters(dev)) {
+   if (i < n_counters) {
s->type = COMEDI_SUBD_COUNTER;
s->subdev_flags = SDF_READABLE | SDF_WRITABLE |
  SDF_LSAMPL | SDF_CMD_READ;
@@ -1025,7 +1019,7 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
for (i = 0; i < board->n_chips; ++i)
init_tio_chip(dev, i);
 
-   for (i = 0; i < ni_660x_num_counters(dev); ++i)
+   for (i = 0; i < n_counters; ++i)
ni_tio_init_counter(&devpriv->counter_dev->counters[i]);
 
for (i = 0; i < NUM_PFI_CHANNELS; ++i) {
-- 
2.6.3

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


[PATCH v2 33/43] staging: comedi: ni_660x: disable interrupts when detaching driver

2016-03-22 Thread H Hartley Sweeten
Make sure the interrupts are disabled before freeing the irq.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 2440cb6..c71dae8 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -1064,8 +1064,10 @@ static void ni_660x_detach(struct comedi_device *dev)
 {
struct ni_660x_private *devpriv = dev->private;
 
-   if (dev->irq)
+   if (dev->irq) {
+   ni_660x_write(dev, 0, 0, NI660X_GLOBAL_INT_CFG);
free_irq(dev->irq, dev);
+   }
if (devpriv) {
ni_gpct_device_destroy(devpriv->counter_dev);
ni_660x_free_mite_rings(dev);
-- 
2.6.3

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


[PATCH v2 15/43] staging: comedi: ni_660x: remove BUG_ON() in ni_660x_request_mite_channel()

2016-03-22 Thread H Hartley Sweeten
This BUG_ON() happens if a mite DMA channel is already requested when an
ansynchronous command is started for one of the counter subdevices.

The comedi core will only call the (*do_cmd) if the subdevice is not busy.
In this driver, the (*cancel) for the subdevice will always release any
requested mite DMA channel.

Remove the BUG_ON() which can never occur.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 79678af..232c897 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -599,7 +599,6 @@ static int ni_660x_request_mite_channel(struct 
comedi_device *dev,
struct mite_channel *mite_chan;
 
spin_lock_irqsave(&devpriv->mite_channel_lock, flags);
-   BUG_ON(counter->mite_chan);
mite_chan = mite_request_channel(devpriv->mite,
 mite_ring(devpriv, counter));
if (!mite_chan) {
-- 
2.6.3

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


[PATCH v2 11/43] staging: comedi: ni_660x: tidy up ni_660x_write_register()

2016-03-22 Thread H Hartley Sweeten
Rename this function to help shorten some of the long lines.

Remove the inline, let the compiler figure it out.

Change the 'unsigned' parameters to 'unsigned int' to fix the
checkpatch.pl issues:

WARNING: Prefer 'unsigned int' to bare use of 'unsigned'

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 42 +++-
 1 file changed, 20 insertions(+), 22 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 773147a..aa40ab6 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -504,9 +504,9 @@ static enum ni_660x_register ni_gpct_to_660x_register(enum 
ni_gpct_register reg)
}
 }
 
-static inline void ni_660x_write_register(struct comedi_device *dev,
- unsigned chip, unsigned bits,
- enum ni_660x_register reg)
+static void ni_660x_write(struct comedi_device *dev,
+ unsigned int chip, unsigned int bits,
+ enum ni_660x_register reg)
 {
unsigned int addr = GPCT_OFFSET[chip] + ni_660x_reg_data[reg].offset;
 
@@ -534,7 +534,7 @@ static void ni_gpct_write_register(struct ni_gpct *counter, 
unsigned bits,
enum ni_660x_register ni_660x_register = ni_gpct_to_660x_register(reg);
unsigned chip = counter->chip_index;
 
-   ni_660x_write_register(dev, chip, bits, ni_660x_register);
+   ni_660x_write(dev, chip, bits, ni_660x_register);
 }
 
 static unsigned ni_gpct_read_register(struct ni_gpct *counter,
@@ -569,9 +569,9 @@ static inline void ni_660x_set_dma_channel(struct 
comedi_device *dev,
devpriv->dma_cfg[chip] &= ~NI660X_DMA_CFG_SEL_MASK(mite_channel);
devpriv->dma_cfg[chip] |= NI660X_DMA_CFG_SEL(mite_channel,
 counter->counter_index);
-   ni_660x_write_register(dev, chip, devpriv->dma_cfg[chip] |
-  NI660X_DMA_CFG_RESET(mite_channel),
-  NI660X_DMA_CFG);
+   ni_660x_write(dev, chip, devpriv->dma_cfg[chip] |
+ NI660X_DMA_CFG_RESET(mite_channel),
+ NI660X_DMA_CFG);
mmiowb();
spin_unlock_irqrestore(&devpriv->soft_reg_copy_lock, flags);
 }
@@ -587,8 +587,7 @@ static inline void ni_660x_unset_dma_channel(struct 
comedi_device *dev,
spin_lock_irqsave(&devpriv->soft_reg_copy_lock, flags);
devpriv->dma_cfg[chip] &= ~NI660X_DMA_CFG_SEL_MASK(mite_channel);
devpriv->dma_cfg[chip] |= NI660X_DMA_CFG_SEL_NONE(mite_channel);
-   ni_660x_write_register(dev, chip, devpriv->dma_cfg[chip],
-  NI660X_DMA_CFG);
+   ni_660x_write(dev, chip, devpriv->dma_cfg[chip], NI660X_DMA_CFG);
mmiowb();
spin_unlock_irqrestore(&devpriv->soft_reg_copy_lock, flags);
 }
@@ -674,7 +673,7 @@ static void set_tio_counterswap(struct comedi_device *dev, 
int chip)
if (chip)
bits = NI660X_CLK_CFG_COUNTER_SWAP;
 
-   ni_660x_write_register(dev, chip, bits, NI660X_CLK_CFG);
+   ni_660x_write(dev, chip, bits, NI660X_CLK_CFG);
 }
 
 static void ni_660x_handle_gpct_interrupt(struct comedi_device *dev,
@@ -793,10 +792,9 @@ static void init_tio_chip(struct comedi_device *dev, int 
chipset)
devpriv->dma_cfg[chipset] = 0;
for (i = 0; i < MAX_DMA_CHANNEL; ++i)
devpriv->dma_cfg[chipset] |= NI660X_DMA_CFG_SEL_NONE(i);
-   ni_660x_write_register(dev, chipset, devpriv->dma_cfg[chipset],
-  NI660X_DMA_CFG);
+   ni_660x_write(dev, chipset, devpriv->dma_cfg[chipset], NI660X_DMA_CFG);
for (i = 0; i < NUM_PFI_CHANNELS; ++i)
-   ni_660x_write_register(dev, chipset, 0, NI660X_IO_CFG(i));
+   ni_660x_write(dev, chipset, 0, NI660X_IO_CFG(i));
 }
 
 static int ni_660x_dio_insn_bits(struct comedi_device *dev,
@@ -810,7 +808,7 @@ static int ni_660x_dio_insn_bits(struct comedi_device *dev,
s->state &= ~(data[0] << base_bitfield_channel);
s->state |= (data[0] & data[1]) << base_bitfield_channel;
/* Write out the new digital output lines */
-   ni_660x_write_register(dev, 0, s->state, NI660X_DIO32_OUTPUT);
+   ni_660x_write(dev, 0, s->state, NI660X_DIO32_OUTPUT);
}
/* on return, data[1] contains the value of the digital
 * input and output lines. */
@@ -852,8 +850,8 @@ static void ni_660x_select_pfi_output(struct comedi_device 
*dev,
idle_bits |=
NI660X_IO_CFG_OUT_SEL(pfi_channel,
  NI660X_IO_CFG_OUT_SEL_HIGH_Z);
-   ni_660x_write_register(dev, idle_chipset, idle_bits,
-  NI660X_IO_CFG(pfi_channel));
+

[PATCH v2 36/43] staging: comedi: ni_660x: initialize the counter with the subdevice init

2016-03-22 Thread H Hartley Sweeten
Remove the extra for loop and just initialize the counter as the subdevices
are created.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 6366303..5969723 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -1021,14 +1021,13 @@ static int ni_660x_auto_attach(struct comedi_device 
*dev,
s->buf_change   = ni_660x_buf_change;
s->async_dma_dir = DMA_BIDIRECTIONAL;
s->private  = counter;
+
+   ni_tio_init_counter(counter);
} else {
s->type = COMEDI_SUBD_UNUSED;
}
}
 
-   for (i = 0; i < n_counters; ++i)
-   ni_tio_init_counter(&gpct_dev->counters[i]);
-
 /*
  * Default the DIO channels as:
  *   chan 0-7:  DIO inputs
-- 
2.6.3

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


[PATCH v2 28/43] staging: comedi: ni_660x: tidy up the misc. constants

2016-03-22 Thread H Hartley Sweeten
Remove enum ni_660x_constants and just #define the value.

Move all the constant #defines so they are in one place and rename
them so they are more conesistent.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 49 
 1 file changed, 24 insertions(+), 25 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index bb5b5ff..80499d6 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -41,14 +41,6 @@
 #include "mite.h"
 #include "ni_tio.h"
 
-enum ni_660x_constants {
-   counters_per_chip = 4
-};
-
-#define NUM_PFI_CHANNELS 40
-/* there are only up to 3 dma channels, but the register layout allows for 4 */
-#define MAX_DMA_CHANNEL 4
-
 /* See Register-Level Programmer Manual page 3.1 */
 enum ni_660x_register {
NI660X_G0_INT_ACK,
@@ -390,22 +382,29 @@ static const struct ni_660x_board ni_660x_boards[] = {
},
 };
 
-#define NI_660X_MAX_NUM_CHIPS 2
-#define NI_660X_MAX_NUM_COUNTERS (NI_660X_MAX_NUM_CHIPS * counters_per_chip)
+#define NI660X_NUM_PFI_CHANNELS40
+
+/* there are only up to 3 dma channels, but the register layout allows for 4 */
+#define NI660X_MAX_DMA_CHANNEL 4
+
+#define NI660X_COUNTERS_PER_CHIP   4
+#define NI660X_MAX_CHIPS   2
+#define NI660X_MAX_COUNTERS(NI660X_MAX_CHIPS * \
+NI660X_COUNTERS_PER_CHIP)
 
 struct ni_660x_private {
struct mite_struct *mite;
struct ni_gpct_device *counter_dev;
struct mite_dma_descriptor_ring
-   *mite_rings[NI_660X_MAX_NUM_CHIPS][counters_per_chip];
+   *mite_rings[NI660X_MAX_CHIPS][NI660X_COUNTERS_PER_CHIP];
/* protects mite channel request/release */
spinlock_t mite_channel_lock;
/* prevents races between interrupt and comedi_poll */
spinlock_t interrupt_lock;
/* protects dma_cfg changes */
spinlock_t dma_cfg_lock;
-   unsigned int dma_cfg[NI_660X_MAX_NUM_CHIPS];
-   unsigned int io_cfg[NUM_PFI_CHANNELS];
+   unsigned int dma_cfg[NI660X_MAX_CHIPS];
+   unsigned int io_cfg[NI660X_NUM_PFI_CHANNELS];
u64 io_dir;
 };
 
@@ -667,7 +666,7 @@ static int ni_660x_allocate_private(struct comedi_device 
*dev)
spin_lock_init(&devpriv->mite_channel_lock);
spin_lock_init(&devpriv->interrupt_lock);
spin_lock_init(&devpriv->dma_cfg_lock);
-   for (i = 0; i < NUM_PFI_CHANNELS; ++i)
+   for (i = 0; i < NI660X_NUM_PFI_CHANNELS; ++i)
devpriv->io_cfg[i] = NI_660X_PFI_OUTPUT_COUNTER;
 
return 0;
@@ -681,7 +680,7 @@ static int ni_660x_alloc_mite_rings(struct comedi_device 
*dev)
unsigned int j;
 
for (i = 0; i < board->n_chips; ++i) {
-   for (j = 0; j < counters_per_chip; ++j) {
+   for (j = 0; j < NI660X_COUNTERS_PER_CHIP; ++j) {
devpriv->mite_rings[i][j] =
mite_alloc_ring(devpriv->mite);
if (!devpriv->mite_rings[i][j])
@@ -699,7 +698,7 @@ static void ni_660x_free_mite_rings(struct comedi_device 
*dev)
unsigned int j;
 
for (i = 0; i < board->n_chips; ++i) {
-   for (j = 0; j < counters_per_chip; ++j)
+   for (j = 0; j < NI660X_COUNTERS_PER_CHIP; ++j)
mite_free_ring(devpriv->mite_rings[i][j]);
}
 }
@@ -711,10 +710,10 @@ static void init_tio_chip(struct comedi_device *dev, int 
chipset)
 
/*  init dma configuration register */
devpriv->dma_cfg[chipset] = 0;
-   for (i = 0; i < MAX_DMA_CHANNEL; ++i)
+   for (i = 0; i < NI660X_MAX_DMA_CHANNEL; ++i)
devpriv->dma_cfg[chipset] |= NI660X_DMA_CFG_SEL_NONE(i);
ni_660x_write(dev, chipset, devpriv->dma_cfg[chipset], NI660X_DMA_CFG);
-   for (i = 0; i < NUM_PFI_CHANNELS; ++i)
+   for (i = 0; i < NI660X_NUM_PFI_CHANNELS; ++i)
ni_660x_write(dev, chipset, 0, NI660X_IO_CFG(i));
 }
 
@@ -899,7 +898,7 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
if (ret < 0)
return ret;
 
-   ret = comedi_alloc_subdevices(dev, 2 + NI_660X_MAX_NUM_COUNTERS);
+   ret = comedi_alloc_subdevices(dev, 2 + NI660X_MAX_COUNTERS);
if (ret)
return ret;
 
@@ -965,7 +964,7 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
s = &dev->subdevices[subdev++];
s->type = COMEDI_SUBD_DIO;
s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
-   s->n_chan   = NUM_PFI_CHANNELS;
+   s->n_chan   = NI660X_NUM_PFI_CHANNELS;
s->maxdata  = 1;
s->range_table  = &range_digital;
s->insn_bits= ni_660x_dio_insn_bits;
@@ -977,7 +976,7 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
 */
ni

[PATCH v2 03/43] staging: comedi: ni_660x: remove enum ni_register_width

2016-03-22 Thread H Hartley Sweeten
All the registers are defined struct NI_660xRegisterData and they are
either 2 or 4 bytes in size. Remove the enum and just use a char member
to define the size as 2 or 4 bytes.

Simplify the ni_660x_{write,read}_register() functions and remove the
unnecessary BUG() in each.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 226 ++-
 1 file changed, 103 insertions(+), 123 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 10bb839..dbbeb96 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -158,12 +158,6 @@ enum ni_660x_register {
 
 #define NI660X_IO_CFG(x)   (NI660X_IO_CFG_0_1 + ((x) / 2))
 
-enum ni_660x_register_width {
-   DATA_1B,
-   DATA_2B,
-   DATA_4B
-};
-
 enum ni_660x_register_direction {
NI_660x_READ,
NI_660x_WRITE,
@@ -189,108 +183,108 @@ static inline unsigned NI_660X_GPCT_SUBDEV(unsigned 
index)
 struct NI_660xRegisterData {
int offset; /*  Offset from base address from GPCT chip */
enum ni_660x_register_direction direction;
-   enum ni_660x_register_width size; /* 1 byte, 2 bytes, or 4 bytes */
+   char size;  /* 2 or 4 bytes */
 };
 
 static const struct NI_660xRegisterData registerData[NI660X_NUM_REGS] = {
-   [NI660X_G0_INT_ACK] = {0x004, NI_660x_WRITE, DATA_2B},
-   [NI660X_G0_STATUS]  = {0x004, NI_660x_READ, DATA_2B},
-   [NI660X_G1_INT_ACK] = {0x006, NI_660x_WRITE, DATA_2B},
-   [NI660X_G1_STATUS]  = {0x006, NI_660x_READ, DATA_2B},
-   [NI660X_G01_STATUS] = {0x008, NI_660x_READ, DATA_2B},
-   [NI660X_G0_CMD] = {0x00c, NI_660x_WRITE, DATA_2B},
-   [NI660X_STC_DIO_PARALLEL_INPUT] = {0x00e, NI_660x_READ, DATA_2B},
-   [NI660X_G1_CMD] = {0x00e, NI_660x_WRITE, DATA_2B},
-   [NI660X_G0_HW_SAVE] = {0x010, NI_660x_READ, DATA_4B},
-   [NI660X_G1_HW_SAVE] = {0x014, NI_660x_READ, DATA_4B},
-   [NI660X_STC_DIO_OUTPUT] = {0x014, NI_660x_WRITE, DATA_2B},
-   [NI660X_STC_DIO_CONTROL]= {0x016, NI_660x_WRITE, DATA_2B},
-   [NI660X_G0_SW_SAVE] = {0x018, NI_660x_READ, DATA_4B},
-   [NI660X_G1_SW_SAVE] = {0x01c, NI_660x_READ, DATA_4B},
-   [NI660X_G0_MODE]= {0x034, NI_660x_WRITE, DATA_2B},
-   [NI660X_G01_STATUS1]= {0x036, NI_660x_READ, DATA_2B},
-   [NI660X_G1_MODE]= {0x036, NI_660x_WRITE, DATA_2B},
-   [NI660X_STC_DIO_SERIAL_INPUT]   = {0x038, NI_660x_READ, DATA_2B},
-   [NI660X_G0_LOADA]   = {0x038, NI_660x_WRITE, DATA_4B},
-   [NI660X_G01_STATUS2]= {0x03a, NI_660x_READ, DATA_2B},
-   [NI660X_G0_LOADB]   = {0x03c, NI_660x_WRITE, DATA_4B},
-   [NI660X_G1_LOADA]   = {0x040, NI_660x_WRITE, DATA_4B},
-   [NI660X_G1_LOADB]   = {0x044, NI_660x_WRITE, DATA_4B},
-   [NI660X_G0_INPUT_SEL]   = {0x048, NI_660x_WRITE, DATA_2B},
-   [NI660X_G1_INPUT_SEL]   = {0x04a, NI_660x_WRITE, DATA_2B},
-   [NI660X_G0_AUTO_INC]= {0x088, NI_660x_WRITE, DATA_2B},
-   [NI660X_G1_AUTO_INC]= {0x08a, NI_660x_WRITE, DATA_2B},
-   [NI660X_G01_RESET]  = {0x090, NI_660x_WRITE, DATA_2B},
-   [NI660X_G0_INT_ENA] = {0x092, NI_660x_WRITE, DATA_2B},
-   [NI660X_G1_INT_ENA] = {0x096, NI_660x_WRITE, DATA_2B},
-   [NI660X_G0_CNT_MODE]= {0x0b0, NI_660x_WRITE, DATA_2B},
-   [NI660X_G1_CNT_MODE]= {0x0b2, NI_660x_WRITE, DATA_2B},
-   [NI660X_G0_GATE2]   = {0x0b4, NI_660x_WRITE, DATA_2B},
-   [NI660X_G1_GATE2]   = {0x0b6, NI_660x_WRITE, DATA_2B},
-   [NI660X_G0_DMA_CFG] = {0x0b8, NI_660x_WRITE, DATA_2B},
-   [NI660X_G0_DMA_STATUS]  = {0x0b8, NI_660x_READ, DATA_2B},
-   [NI660X_G1_DMA_CFG] = {0x0ba, NI_660x_WRITE, DATA_2B},
-   [NI660X_G1_DMA_STATUS]  = {0x0ba, NI_660x_READ, DATA_2B},
-   [NI660X_G2_INT_ACK] = {0x104, NI_660x_WRITE, DATA_2B},
-   [NI660X_G2_STATUS]  = {0x104, NI_660x_READ, DATA_2B},
-   [NI660X_G3_INT_ACK] = {0x106, NI_660x_WRITE, DATA_2B},
-   [NI660X_G3_STATUS]  = {0x106, NI_660x_READ, DATA_2B},
-   [NI660X_G23_STATUS] = {0x108, NI_660x_READ, DATA_2B},
-   [NI660X_G2_CMD] = {0x10c, NI_660x_WRITE, DATA_2B},
-   [NI660X_G3_CMD] = {0x10e, NI_660x_WRITE, DATA_2B},
-   [NI660X_G2_HW_SAVE] = {0x110, NI_660x_READ, DATA_4B},
-   [NI660X_G3_HW_SAVE] = {0x114, NI_660x_READ, DATA_4B},
-   [NI660X_G2_SW_SAVE] = {0x118,

[PATCH v2 09/43] staging: comedi: ni_660x: cleanup the NI660X_DMA_CFG register helpers

2016-03-22 Thread H Hartley Sweeten
The BUG_ON() checks in the helper functions are not necessary. The mite
driver quiries the PCI chip to determine the number of DMA channels.
This is then used when a DMA channel is requested so the channel will
always be in range.

Convert the inline functions used to set the bits in the NI600X_DMA_CFG
register into macros. Also convert the associated enum dma_selection.
This clarifies the association with the register.

Rename the associated 'dma_configuration_soft_copies' member of the
private data to allow shorting some of the ugly long lines in the
driver.

This also fixes a number of checkpatch.pl issues about:

WARNING: Prefer 'unsigned int' to bare use of 'unsigned'

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 63 ++--
 1 file changed, 19 insertions(+), 44 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 30089cd..0b37982 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -157,6 +157,11 @@ enum ni_660x_register {
 
 #define NI660X_CLK_CFG_COUNTER_SWAPBIT(21)
 
+#define NI660X_DMA_CFG_SEL(_c, _s) (((_s) & 0x1f) << (8 * (_c)))
+#define NI660X_DMA_CFG_SEL_MASK(_c)NI660X_DMA_CFG_SEL((_c), 0x1f)
+#define NI660X_DMA_CFG_SEL_NONE(_c)NI660X_DMA_CFG_SEL((_c), 0x1f)
+#define NI660X_DMA_CFG_RESET(_c)   NI660X_DMA_CFG_SEL((_c), 0x80)
+
 #define NI660X_IO_CFG(x)   (NI660X_IO_CFG_0_1 + ((x) / 2))
 #define NI660X_IO_CFG_OUT_SEL(_c, _s)  (((_s) & 0x3) << (((_c) % 2) ? 0 : 8))
 #define NI660X_IO_CFG_OUT_SEL_MASK(_c) NI660X_IO_CFG_OUT_SEL((_c), 0x3)
@@ -282,29 +287,6 @@ static const struct ni_660x_register_data 
ni_660x_reg_data[NI660X_NUM_REGS] = {
[NI660X_IO_CFG_38_39]   = { 0x7a2, 2 }  /* read/write */
 };
 
-/* dma configuration register bits */
-static inline unsigned dma_select_mask(unsigned dma_channel)
-{
-   BUG_ON(dma_channel >= MAX_DMA_CHANNEL);
-   return 0x1f << (8 * dma_channel);
-}
-
-enum dma_selection {
-   dma_selection_none = 0x1f,
-};
-
-static inline unsigned dma_select_bits(unsigned dma_channel, unsigned 
selection)
-{
-   BUG_ON(dma_channel >= MAX_DMA_CHANNEL);
-   return (selection << (8 * dma_channel)) & dma_select_mask(dma_channel);
-}
-
-static inline unsigned dma_reset_bit(unsigned dma_channel)
-{
-   BUG_ON(dma_channel >= MAX_DMA_CHANNEL);
-   return 0x80 << (8 * dma_channel);
-}
-
 enum global_interrupt_status_register_bits {
Counter_0_Int_Bit = 0x100,
Counter_1_Int_Bit = 0x200,
@@ -372,7 +354,7 @@ struct ni_660x_private {
spinlock_t mite_channel_lock;
/* interrupt_lock prevents races between interrupt and comedi_poll */
spinlock_t interrupt_lock;
-   unsigned dma_configuration_soft_copies[NI_660X_MAX_NUM_CHIPS];
+   unsigned dma_cfg[NI_660X_MAX_NUM_CHIPS];
spinlock_t soft_reg_copy_lock;
unsigned short pfi_output_selects[NUM_PFI_CHANNELS];
 };
@@ -591,13 +573,12 @@ static inline void ni_660x_set_dma_channel(struct 
comedi_device *dev,
unsigned long flags;
 
spin_lock_irqsave(&devpriv->soft_reg_copy_lock, flags);
-   devpriv->dma_configuration_soft_copies[chip] &=
-   ~dma_select_mask(mite_channel);
-   devpriv->dma_configuration_soft_copies[chip] |=
-   dma_select_bits(mite_channel, counter->counter_index);
-   ni_660x_write_register(dev, chip,
-  devpriv->dma_configuration_soft_copies[chip] |
-  dma_reset_bit(mite_channel), NI660X_DMA_CFG);
+   devpriv->dma_cfg[chip] &= ~NI660X_DMA_CFG_SEL_MASK(mite_channel);
+   devpriv->dma_cfg[chip] |= NI660X_DMA_CFG_SEL(mite_channel,
+counter->counter_index);
+   ni_660x_write_register(dev, chip, devpriv->dma_cfg[chip] |
+  NI660X_DMA_CFG_RESET(mite_channel),
+  NI660X_DMA_CFG);
mmiowb();
spin_unlock_irqrestore(&devpriv->soft_reg_copy_lock, flags);
 }
@@ -611,12 +592,9 @@ static inline void ni_660x_unset_dma_channel(struct 
comedi_device *dev,
unsigned long flags;
 
spin_lock_irqsave(&devpriv->soft_reg_copy_lock, flags);
-   devpriv->dma_configuration_soft_copies[chip] &=
-   ~dma_select_mask(mite_channel);
-   devpriv->dma_configuration_soft_copies[chip] |=
-   dma_select_bits(mite_channel, dma_selection_none);
-   ni_660x_write_register(dev, chip,
-  devpriv->dma_configuration_soft_copies[chip],
+   devpriv->dma_cfg[chip] &= ~NI660X_DMA_CFG_SEL_MASK(mite_channel);
+   devpriv->dma_cfg[chip] |= NI660X_DMA_CFG_SEL_NONE(mite_channel);
+   ni_660x_write_register(dev, chip, devpriv->dma_cfg[chip],
   NI660X_DMA_CFG);
mmiowb();
s

[PATCH v2 27/43] staging: comedi: ni_660x: fix memory barrier without comment

2016-03-22 Thread H Hartley Sweeten
Fix the checkpatch.pl issue. Move the memory barrier to a better place.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 2926d26..bb5b5ff 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -613,9 +613,11 @@ static irqreturn_t ni_660x_interrupt(int irq, void *d)
 
if (!dev->attached)
return IRQ_NONE;
+   /* make sure dev->attached is checked before doing anything else */
+   smp_mb();
+
/* lock to avoid race with comedi_poll */
spin_lock_irqsave(&devpriv->interrupt_lock, flags);
-   smp_mb();
for (i = 0; i < dev->n_subdevices; ++i) {
s = &dev->subdevices[i];
if (s->type == COMEDI_SUBD_COUNTER)
-- 
2.6.3

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


[PATCH v2 25/43] staging: comedi: ni_660x: refactor ni_gpct_to_660x_register()

2016-03-22 Thread H Hartley Sweeten
Convert this big switch into an array and refactor ni_660x_gpct_{write,read}()
functions to use the array to find the register offset.

All the TIO (GPCT) registers are included in the array except for NITIO_G0_ABZ
and NITIO_G1_ABZ. These registers only exist on the ni_pcimio m-series boards
and this driver will never read/write them.

Just in case someone adds a new entry to the enum ni_gpct_register in ni_tio.h,
add a dev_warn() for any unhandled registers.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 236 ---
 1 file changed, 89 insertions(+), 147 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 6f84946..3edea99 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -279,6 +279,77 @@ static const struct ni_660x_register_data 
ni_660x_reg_data[NI660X_NUM_REGS] = {
[NI660X_IO_CFG_38_39]   = { 0x7a2, 2 }  /* read/write */
 };
 
+static const enum ni_660x_register ni_gpct_to_660x_register[] = {
+   [NITIO_G0_AUTO_INC] = NI660X_G0_AUTO_INC,
+   [NITIO_G1_AUTO_INC] = NI660X_G1_AUTO_INC,
+   [NITIO_G2_AUTO_INC] = NI660X_G2_AUTO_INC,
+   [NITIO_G3_AUTO_INC] = NI660X_G3_AUTO_INC,
+   [NITIO_G0_CMD]  = NI660X_G0_CMD,
+   [NITIO_G1_CMD]  = NI660X_G1_CMD,
+   [NITIO_G2_CMD]  = NI660X_G2_CMD,
+   [NITIO_G3_CMD]  = NI660X_G3_CMD,
+   [NITIO_G0_HW_SAVE]  = NI660X_G0_HW_SAVE,
+   [NITIO_G1_HW_SAVE]  = NI660X_G1_HW_SAVE,
+   [NITIO_G2_HW_SAVE]  = NI660X_G2_HW_SAVE,
+   [NITIO_G3_HW_SAVE]  = NI660X_G3_HW_SAVE,
+   [NITIO_G0_SW_SAVE]  = NI660X_G0_SW_SAVE,
+   [NITIO_G1_SW_SAVE]  = NI660X_G1_SW_SAVE,
+   [NITIO_G2_SW_SAVE]  = NI660X_G2_SW_SAVE,
+   [NITIO_G3_SW_SAVE]  = NI660X_G3_SW_SAVE,
+   [NITIO_G0_MODE] = NI660X_G0_MODE,
+   [NITIO_G1_MODE] = NI660X_G1_MODE,
+   [NITIO_G2_MODE] = NI660X_G2_MODE,
+   [NITIO_G3_MODE] = NI660X_G3_MODE,
+   [NITIO_G0_LOADA]= NI660X_G0_LOADA,
+   [NITIO_G1_LOADA]= NI660X_G1_LOADA,
+   [NITIO_G2_LOADA]= NI660X_G2_LOADA,
+   [NITIO_G3_LOADA]= NI660X_G3_LOADA,
+   [NITIO_G0_LOADB]= NI660X_G0_LOADB,
+   [NITIO_G1_LOADB]= NI660X_G1_LOADB,
+   [NITIO_G2_LOADB]= NI660X_G2_LOADB,
+   [NITIO_G3_LOADB]= NI660X_G3_LOADB,
+   [NITIO_G0_INPUT_SEL]= NI660X_G0_INPUT_SEL,
+   [NITIO_G1_INPUT_SEL]= NI660X_G1_INPUT_SEL,
+   [NITIO_G2_INPUT_SEL]= NI660X_G2_INPUT_SEL,
+   [NITIO_G3_INPUT_SEL]= NI660X_G3_INPUT_SEL,
+   [NITIO_G0_CNT_MODE] = NI660X_G0_CNT_MODE,
+   [NITIO_G1_CNT_MODE] = NI660X_G1_CNT_MODE,
+   [NITIO_G2_CNT_MODE] = NI660X_G2_CNT_MODE,
+   [NITIO_G3_CNT_MODE] = NI660X_G3_CNT_MODE,
+   [NITIO_G0_GATE2]= NI660X_G0_GATE2,
+   [NITIO_G1_GATE2]= NI660X_G1_GATE2,
+   [NITIO_G2_GATE2]= NI660X_G2_GATE2,
+   [NITIO_G3_GATE2]= NI660X_G3_GATE2,
+   [NITIO_G01_STATUS]  = NI660X_G01_STATUS,
+   [NITIO_G23_STATUS]  = NI660X_G23_STATUS,
+   [NITIO_G01_RESET]   = NI660X_G01_RESET,
+   [NITIO_G23_RESET]   = NI660X_G23_RESET,
+   [NITIO_G01_STATUS1] = NI660X_G01_STATUS1,
+   [NITIO_G23_STATUS1] = NI660X_G23_STATUS1,
+   [NITIO_G01_STATUS2] = NI660X_G01_STATUS2,
+   [NITIO_G23_STATUS2] = NI660X_G23_STATUS2,
+   [NITIO_G0_DMA_CFG]  = NI660X_G0_DMA_CFG,
+   [NITIO_G1_DMA_CFG]  = NI660X_G1_DMA_CFG,
+   [NITIO_G2_DMA_CFG]  = NI660X_G2_DMA_CFG,
+   [NITIO_G3_DMA_CFG]  = NI660X_G3_DMA_CFG,
+   [NITIO_G0_DMA_STATUS]   = NI660X_G0_DMA_STATUS,
+   [NITIO_G1_DMA_STATUS]   = NI660X_G1_DMA_STATUS,
+   [NITIO_G2_DMA_STATUS]   = NI660X_G2_DMA_STATUS,
+   [NITIO_G3_DMA_STATUS]   = NI660X_G3_DMA_STATUS,
+   [NITIO_G0_INT_ACK]  = NI660X_G0_INT_ACK,
+   [NITIO_G1_INT_ACK]  = NI660X_G1_INT_ACK,
+   [NITIO_G2_INT_ACK]  = NI660X_G2_INT_ACK,
+   [NITIO_G3_INT_ACK]  = NI660X_G3_INT_ACK,
+   [NITIO_G0_STATUS]   = NI660X_G0_STATUS,
+   [NITIO_G1_STATUS]   = NI660X_G1_STATUS,
+   [NITIO_G2_STATUS]   = NI660X_G2_STATUS,
+   [NITIO_G3_STATUS]  

[PATCH v2 41/43] staging: comedi: ni_660x: remove spinlock 'dma_cfg_lock'

2016-03-22 Thread H Hartley Sweeten
This spinlock is only used to protect changes to the private data 'dma_cfg'.

Before calling any function that would change the 'dma_cfg' the spinlock
'mite_channel_lock' is also locked. That spinlock is not unlocked until
after the 'dma_cfg' change.

Remove the redundant spinlock.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 9 -
 1 file changed, 9 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 85c793a..3b57ce5 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -263,8 +263,6 @@ struct ni_660x_private {
spinlock_t mite_channel_lock;
/* prevents races between interrupt and comedi_poll */
spinlock_t interrupt_lock;
-   /* protects dma_cfg changes */
-   spinlock_t dma_cfg_lock;
unsigned int dma_cfg[NI660X_MAX_CHIPS];
unsigned int io_cfg[NI660X_NUM_PFI_CHANNELS];
u64 io_dir;
@@ -313,9 +311,7 @@ static inline void ni_660x_set_dma_channel(struct 
comedi_device *dev,
 {
struct ni_660x_private *devpriv = dev->private;
unsigned int chip = counter->chip_index;
-   unsigned long flags;
 
-   spin_lock_irqsave(&devpriv->dma_cfg_lock, flags);
devpriv->dma_cfg[chip] &= ~NI660X_DMA_CFG_SEL_MASK(mite_channel);
devpriv->dma_cfg[chip] |= NI660X_DMA_CFG_SEL(mite_channel,
 counter->counter_index);
@@ -323,7 +319,6 @@ static inline void ni_660x_set_dma_channel(struct 
comedi_device *dev,
  NI660X_DMA_CFG_RESET(mite_channel),
  NI660X_DMA_CFG);
mmiowb();
-   spin_unlock_irqrestore(&devpriv->dma_cfg_lock, flags);
 }
 
 static inline void ni_660x_unset_dma_channel(struct comedi_device *dev,
@@ -332,14 +327,11 @@ static inline void ni_660x_unset_dma_channel(struct 
comedi_device *dev,
 {
struct ni_660x_private *devpriv = dev->private;
unsigned int chip = counter->chip_index;
-   unsigned long flags;
 
-   spin_lock_irqsave(&devpriv->dma_cfg_lock, flags);
devpriv->dma_cfg[chip] &= ~NI660X_DMA_CFG_SEL_MASK(mite_channel);
devpriv->dma_cfg[chip] |= NI660X_DMA_CFG_SEL_NONE(mite_channel);
ni_660x_write(dev, chip, devpriv->dma_cfg[chip], NI660X_DMA_CFG);
mmiowb();
-   spin_unlock_irqrestore(&devpriv->dma_cfg_lock, flags);
 }
 
 static int ni_660x_request_mite_channel(struct comedi_device *dev,
@@ -500,7 +492,6 @@ static int ni_660x_allocate_private(struct comedi_device 
*dev)
 
spin_lock_init(&devpriv->mite_channel_lock);
spin_lock_init(&devpriv->interrupt_lock);
-   spin_lock_init(&devpriv->dma_cfg_lock);
for (i = 0; i < NI660X_NUM_PFI_CHANNELS; ++i)
devpriv->io_cfg[i] = NI_660X_PFI_OUTPUT_COUNTER;
 
-- 
2.6.3

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


[PATCH v2 42/43] staging: comedi: ni_660x: refactor GPCT_OFFSET

2016-03-22 Thread H Hartley Sweeten
This driver supports boards that have 1 or 2 TIO chips with base
addresses 0x800 apart. Replace the static const array 'GPCT_OFFSET'
with a define and calculate the base address based on the chip index.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 3b57ce5..73ccd62 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -204,9 +204,7 @@ static const struct ni_660x_register_data 
ni_660x_reg_data[NI660X_NUM_REGS] = {
[NI660X_IO_CFG_38_39]   = { 0x7a2, 2 }  /* read/write */
 };
 
-/* Offset of the GPCT chips from the base-address of the card */
-/* First chip is at base-address + 0x00, etc. */
-static const unsigned GPCT_OFFSET[2] = { 0x0, 0x800 };
+#define NI660X_CHIP_OFFSET 0x800
 
 enum ni_660x_boardid {
BOARD_PCI6601,
@@ -271,7 +269,8 @@ struct ni_660x_private {
 static void ni_660x_write(struct comedi_device *dev, unsigned int chip,
  unsigned int bits, unsigned int reg)
 {
-   unsigned int addr = GPCT_OFFSET[chip] + ni_660x_reg_data[reg].offset;
+   unsigned int addr = (chip * NI660X_CHIP_OFFSET) +
+   ni_660x_reg_data[reg].offset;
 
if (ni_660x_reg_data[reg].size == 2)
writew(bits, dev->mmio + addr);
@@ -282,7 +281,8 @@ static void ni_660x_write(struct comedi_device *dev, 
unsigned int chip,
 static unsigned int ni_660x_read(struct comedi_device *dev,
 unsigned int chip, unsigned int reg)
 {
-   unsigned int addr = GPCT_OFFSET[chip] + ni_660x_reg_data[reg].offset;
+   unsigned int addr = (chip * NI660X_CHIP_OFFSET) +
+   ni_660x_reg_data[reg].offset;
 
if (ni_660x_reg_data[reg].size == 2)
return readw(dev->mmio + addr);
-- 
2.6.3

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


[PATCH v2 37/43] staging: comedi: ni_660x: default DIO channels with subdevice init

2016-03-22 Thread H Hartley Sweeten
For aesthetics, move the initialization of the default routing for the
DIO channels so it happens when the subdevice is initialized.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 27 +--
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 5969723..cf25892 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -996,6 +996,19 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
s->insn_bits= ni_660x_dio_insn_bits;
s->insn_config  = ni_660x_dio_insn_config;
 
+/*
+ * Default the DIO channels as:
+ *   chan 0-7:  DIO inputs
+ *   chan 8-39: counter signal inputs
+ */
+   for (i = 0; i < s->n_chan; ++i) {
+   unsigned int source = (i < 8) ? NI_660X_PFI_OUTPUT_DIO
+ : NI_660X_PFI_OUTPUT_COUNTER;
+
+   ni_660x_set_pfi_routing(dev, i, source);
+   ni_660x_select_pfi_output(dev, i, 0);   /* high-z */
+   }
+
/* Counter subdevices (4 NI TIO General Purpose Counters per chip) */
for (i = 0; i < NI660X_MAX_COUNTERS; ++i) {
s = &dev->subdevices[subdev++];
@@ -1028,20 +1041,6 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
}
}
 
-/*
- * Default the DIO channels as:
- *   chan 0-7:  DIO inputs
- *   chan 8-39: counter signal inputs
- */
-   for (i = 0; i < NI660X_NUM_PFI_CHANNELS; ++i) {
-   if (i < 8)
-   ni_660x_set_pfi_routing(dev, i, NI_660X_PFI_OUTPUT_DIO);
-   else
-   ni_660x_set_pfi_routing(dev, i,
-   NI_660X_PFI_OUTPUT_COUNTER);
-   ni_660x_select_pfi_output(dev, i, 0);   /* high-z */
-   }
-
/*
 * To be safe, set counterswap bits on tio chips after all the counter
 * outputs have been set to high impedance mode.
-- 
2.6.3

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


[PATCH v2 43/43] staging: comedi: ni_660x: update the MODULE_DESCRIPTION

2016-03-22 Thread H Hartley Sweeten
Change the generic MODULE_DESCRIPTION text to something more useful.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 73ccd62..4345bdc 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -940,5 +940,5 @@ static struct pci_driver ni_660x_pci_driver = {
 module_comedi_pci_driver(ni_660x_driver, ni_660x_pci_driver);
 
 MODULE_AUTHOR("Comedi http://www.comedi.org";);
-MODULE_DESCRIPTION("Comedi low-level driver");
+MODULE_DESCRIPTION("Comedi driver for NI 660x counter/timer boards");
 MODULE_LICENSE("GPL");
-- 
2.6.3

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


[PATCH v2 07/43] staging: comedi: ni_660x: tidy up multi-line comment

2016-03-22 Thread H Hartley Sweeten
Reformat the multi-line comment in the kernel CodingStyle.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 25 -
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 75c6032..ab761aa 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -1,17 +1,16 @@
 /*
-  comedi/drivers/ni_660x.c
-  Hardware driver for NI 660x devices
-
-  This program is free software; you can redistribute it and/or modify
-  it under the terms of the GNU General Public License as published by
-  the Free Software Foundation; either version 2 of the License, or
-  (at your option) any later version.
-
-  This program is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-  GNU General Public License for more details.
-*/
+ * Hardware driver for NI 660x devices
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
 
 /*
  * Driver: ni_660x
-- 
2.6.3

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


RE: [PATCH 3/6] staging: comedi: ni_labpc_common: tidy up block comments

2016-03-22 Thread Hartley Sweeten
On Tuesday, March 22, 2016 10:51 AM, H Hartley Sweeten wrote:
> Fix the checkpatch.pl issues:
> WARNING: Block comments use a trailing */ on a separate line
>
> Signed-off-by: H Hartley Sweeten 
> Cc: Ian Abbott 
> Cc: Greg Kroah-Hartman 
> ---
>  drivers/staging/comedi/drivers/ni_labpc_common.c | 59 ++--
>  drivers/staging/comedi/drivers/z8536.h   | 89 
> +---

Ugh... Just noticed that this included changes to z8636.h.

I'll repost this series as a v2.

Sorry for the noise.

Hartley

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


[PATCH v2 05/43] staging: comedi: ni_660x: rename CamelCase 'NI_660xRegisterData'

2016-03-22 Thread H Hartley Sweeten
Rename this CamelCase struct and the associated 'registerData' variable.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 409a776..d76a5b0 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -174,12 +174,12 @@ static inline unsigned NI_660X_GPCT_SUBDEV(unsigned index)
return NI_660X_GPCT_SUBDEV_0 + index;
 }
 
-struct NI_660xRegisterData {
+struct ni_660x_register_data {
int offset; /*  Offset from base address from GPCT chip */
char size;  /* 2 or 4 bytes */
 };
 
-static const struct NI_660xRegisterData registerData[NI660X_NUM_REGS] = {
+static const struct ni_660x_register_data ni_660x_reg_data[NI660X_NUM_REGS] = {
[NI660X_G0_INT_ACK] = { 0x004, 2 }, /* write */
[NI660X_G0_STATUS]  = { 0x004, 2 }, /* read */
[NI660X_G1_INT_ACK] = { 0x006, 2 }, /* write */
@@ -564,9 +564,9 @@ static inline void ni_660x_write_register(struct 
comedi_device *dev,
  unsigned chip, unsigned bits,
  enum ni_660x_register reg)
 {
-   unsigned int addr = GPCT_OFFSET[chip] + registerData[reg].offset;
+   unsigned int addr = GPCT_OFFSET[chip] + ni_660x_reg_data[reg].offset;
 
-   if (registerData[reg].size == 2)
+   if (ni_660x_reg_data[reg].size == 2)
writew(bits, dev->mmio + addr);
else
writel(bits, dev->mmio + addr);
@@ -576,9 +576,9 @@ static inline unsigned ni_660x_read_register(struct 
comedi_device *dev,
 unsigned chip,
 enum ni_660x_register reg)
 {
-   unsigned int addr = GPCT_OFFSET[chip] + registerData[reg].offset;
+   unsigned int addr = GPCT_OFFSET[chip] + ni_660x_reg_data[reg].offset;
 
-   if (registerData[reg].size == 2)
+   if (ni_660x_reg_data[reg].size == 2)
return readw(dev->mmio + addr);
return readl(dev->mmio + addr);
 }
-- 
2.6.3

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


[PATCH v2 17/43] staging: comedi: ni_660x: remove enum ni_660x_subdevices

2016-03-22 Thread H Hartley Sweeten
Hard-coding the subdevice order is normally a bad idea. If a new subdevice
is added, or removed, it could potentially break pretty badly.

Remove the enum and associated NI_660X_GPCT_SUBDEV() helper that hard-code
the subdevice order.

Fix the (*auto_attach) so it initializes all the subdevices without depending
on the hard-coded order.

Change the interrupt handler so that all the counter subdevices are handled
without depending on the hard-coded order.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 25 ++---
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 0183497..595c862 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -179,15 +179,6 @@ enum ni_660x_register {
 #define NI660X_IO_CFG_IN_SEL(_c, _s)   (((_s) & 0x7) << (((_c) % 2) ? 4 : 12))
 #define NI660X_IO_CFG_IN_SEL_MASK(_c)  NI660X_IO_CFG_IN_SEL((_c), 0x7)
 
-enum ni_660x_subdevices {
-   NI_660X_DIO_SUBDEV = 1,
-   NI_660X_GPCT_SUBDEV_0 = 2
-};
-static inline unsigned NI_660X_GPCT_SUBDEV(unsigned index)
-{
-   return NI_660X_GPCT_SUBDEV_0 + index;
-}
-
 struct ni_660x_register_data {
int offset; /*  Offset from base address from GPCT chip */
char size;  /* 2 or 4 bytes */
@@ -694,9 +685,10 @@ static irqreturn_t ni_660x_interrupt(int irq, void *d)
/* lock to avoid race with comedi_poll */
spin_lock_irqsave(&devpriv->interrupt_lock, flags);
smp_mb();
-   for (i = 0; i < ni_660x_num_counters(dev); ++i) {
-   s = &dev->subdevices[NI_660X_GPCT_SUBDEV(i)];
-   ni_660x_handle_gpct_interrupt(dev, s);
+   for (i = 0; i < dev->n_subdevices; ++i) {
+   s = &dev->subdevices[i];
+   if (s->type == COMEDI_SUBD_COUNTER)
+   ni_660x_handle_gpct_interrupt(dev, s);
}
spin_unlock_irqrestore(&devpriv->interrupt_lock, flags);
return IRQ_HANDLED;
@@ -935,6 +927,7 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
const struct ni_660x_board *board = NULL;
struct ni_660x_private *devpriv;
struct comedi_subdevice *s;
+   int subdev;
int ret;
unsigned i;
unsigned global_interrupt_config_bits;
@@ -971,11 +964,13 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
if (ret)
return ret;
 
-   s = &dev->subdevices[0];
+   subdev = 0;
+
+   s = &dev->subdevices[subdev++];
/* Old GENERAL-PURPOSE COUNTER/TIME (GPCT) subdevice, no longer used */
s->type = COMEDI_SUBD_UNUSED;
 
-   s = &dev->subdevices[NI_660X_DIO_SUBDEV];
+   s = &dev->subdevices[subdev++];
/* DIGITAL I/O SUBDEVICE */
s->type = COMEDI_SUBD_DIO;
s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
@@ -1000,7 +995,7 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
if (!devpriv->counter_dev)
return -ENOMEM;
for (i = 0; i < NI_660X_MAX_NUM_COUNTERS; ++i) {
-   s = &dev->subdevices[NI_660X_GPCT_SUBDEV(i)];
+   s = &dev->subdevices[subdev++];
if (i < ni_660x_num_counters(dev)) {
s->type = COMEDI_SUBD_COUNTER;
s->subdev_flags = SDF_READABLE | SDF_WRITABLE |
-- 
2.6.3

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


[PATCH v2 00/43] staging: comedi: ni_660x: big driver cleanup

2016-03-22 Thread H Hartley Sweeten
This driver has a lot of checkpatch.pl issues:
total: 0 errors, 71 warnings, 27 checks, 1222 lines checked

There is also a lot of cruft that bloats the driver and makes it harder
to follow.

This series fixes all the checkpatch.pl issues:
total: 0 errors, 0 warnings, 0 checks, 944 lines checked

And, even better, removes the cruft:

   textdata bss dec hex filename
  10249 344   0   105932961 ni_660x.o.original
   4719 344   0506313c7 ni_660x.o

v2: add patch to make ni_gpct_device_destroy() NULL pointer safe.

H Hartley Sweeten (43):
  staging: comedi: ni_660x: change IOConfigReg() into a macro
  staging: comedi: ni_660x: remove struct NI_660xRegisterData 'name'
  staging: comedi: ni_660x: remove enum ni_register_width
  staging: comedi: ni_660x: remove enum ni_660x_register_direction
  staging: comedi: ni_660x: rename CamelCase 'NI_660xRegisterData'
  staging: comedi: ni_660x: cleanup the NI660X_IO_CFG register helpers
  staging: comedi: ni_660x: tidy up multi-line comment
  staging: comedi: ni_660x: remove enum clock_config_register_bits
  staging: comedi: ni_660x: cleanup the NI660X_DMA_CFG register helpers
  staging: comedi: ni_660x: cleanup the NI660X_GLOBAL_INT_{STATUS,CFG}
  staging: comedi: ni_660x: tidy up ni_660x_write_register()
  staging: comedi: ni_660x: tidy up ni_660x_read_register()
  staging: comedi: ni_660x: tidy up ni_gpct_{write,read}_register()
  staging: comedi: ni_660x: tidy up ni_660x_select_pfi_output()
  staging: comedi: ni_660x: remove BUG_ON() in ni_660x_request_mite_channel()
  staging: comedi: ni_660x: fix block comment issues
  staging: comedi: ni_660x: remove enum ni_660x_subdevices
  staging: comedi: ni_660x: remove ni_660x_num_counters()
  staging: comedi: ni_660x: Prefer 'unsigned int' to bare use of 'unsigned'
  staging: comedi: ni_660x: Prefer kernel type 'u64' over 'uint64_t'
  staging: comedi: ni_660x: tidy up Digital I/O subdevice init
  staging: comedi: ni_660x: tidy up ni_660x_dio_insn_bits()
  staging: comedi: ni_660x: tidy up ni_660x_set_pfi_routing()
  staging: comedi: ni_660x: add a comment about the initial DIO state
  staging: comedi: ni_660x: refactor ni_gpct_to_660x_register()
  staging: comedi: ni_660x: add comments for the spinlock_t definitions
  staging: comedi: ni_660x: fix memory barrier without comment
  staging: comedi: ni_660x: tidy up the misc. constants
  staging: comedi: ni_660x: tidy up the counter subdevices init
  staging: comedi: ni_tio: make ni_gpct_device_destroy() NULL pointer safe
  staging: comedi: ni_660x: ni_gpct_device_destroy() can handle a NULL pointer
  staging: comedi: ni_mio_common: ni_gpct_device_destroy() can handle a NULL 
pointer
  staging: comedi: ni_660x: disable interrupts when detaching driver
  staging: comedi: ni_660x: init TIO chips before subdevice init
  staging: comedi: ni_660x: allocate counters early in (*auto_attach)
  staging: comedi: ni_660x: initialize the counter with the subdevice init
  staging: comedi: ni_660x: default DIO channels with subdevice init
  staging: comedi: ni_660x: remove inline mite_ring()
  staging: comedi: ni_660x: sort enum ni_660x_register
  staging: comedi: ni_660x: remove ni_gpct_to_660x_register[]
  staging: comedi: ni_660x: remove spinlock 'dma_cfg_lock'
  staging: comedi: ni_660x: refactor GPCT_OFFSET
  staging: comedi: ni_660x: update the MODULE_DESCRIPTION

 drivers/staging/comedi/drivers/ni_660x.c   | 1156 +---
 drivers/staging/comedi/drivers/ni_mio_common.c |6 +-
 drivers/staging/comedi/drivers/ni_tio.c|2 +-
 3 files changed, 442 insertions(+), 722 deletions(-)

-- 
2.6.3

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


[PATCH v2 22/43] staging: comedi: ni_660x: tidy up ni_660x_dio_insn_bits()

2016-03-22 Thread H Hartley Sweeten
Use some local variables to clarify this function.

This (*insn_bits) function is a bit different from most comedi drivers.
Add some comments to clarify why the shifts are used.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 31 ---
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index f24009c..f614927 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -780,21 +780,30 @@ static void init_tio_chip(struct comedi_device *dev, int 
chipset)
 
 static int ni_660x_dio_insn_bits(struct comedi_device *dev,
 struct comedi_subdevice *s,
-struct comedi_insn *insn, unsigned int *data)
+struct comedi_insn *insn,
+unsigned int *data)
 {
-   unsigned int base_bitfield_channel = CR_CHAN(insn->chanspec);
+   unsigned int shift = CR_CHAN(insn->chanspec);
+   unsigned int mask = data[0] << shift;
+   unsigned int bits = data[1] << shift;
 
-   /*  Check if we have to write some bits */
-   if (data[0]) {
-   s->state &= ~(data[0] << base_bitfield_channel);
-   s->state |= (data[0] & data[1]) << base_bitfield_channel;
-   /* Write out the new digital output lines */
+   /*
+* There are 40 channels in this subdevice but only 32 are usable
+* as DIO. The shift adjusts the mask/bits to account for the base
+* channel in insn->chanspec. The state update can then be handled
+* normally for the 32 usable channels.
+*/
+   if (mask) {
+   s->state &= ~mask;
+   s->state |= (bits & mask);
ni_660x_write(dev, 0, s->state, NI660X_DIO32_OUTPUT);
}
-   /* on return, data[1] contains the value of the digital
-* input and output lines. */
-   data[1] = (ni_660x_read(dev, 0, NI660X_DIO32_INPUT) >>
-   base_bitfield_channel);
+
+   /*
+* Return the input channels, shifted back to account for the base
+* channel.
+*/
+   data[1] = ni_660x_read(dev, 0, NI660X_DIO32_INPUT) >> shift;
 
return insn->n;
 }
-- 
2.6.3

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


[PATCH v2 14/43] staging: comedi: ni_660x: tidy up ni_660x_select_pfi_output()

2016-03-22 Thread H Hartley Sweeten
Tidy up this function to fix the checkpatch.pl issues:

WARNING: Prefer 'unsigned int' to bare use of 'unsigned'

For aesthetics, remove the static const local variables.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 54 ++--
 1 file changed, 24 insertions(+), 30 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index e0532f4..79678af 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -817,46 +817,40 @@ static int ni_660x_dio_insn_bits(struct comedi_device 
*dev,
 }
 
 static void ni_660x_select_pfi_output(struct comedi_device *dev,
- unsigned pfi_channel,
- unsigned output_select)
+ unsigned int chan, unsigned int out_sel)
 {
const struct ni_660x_board *board = dev->board_ptr;
-   static const unsigned counter_4_7_first_pfi = 8;
-   static const unsigned counter_4_7_last_pfi = 23;
-   unsigned active_chipset = 0;
-   unsigned idle_chipset = 0;
-   unsigned active_bits;
-   unsigned idle_bits;
+   unsigned int active_chip = 0;
+   unsigned int idle_chip = 0;
+   unsigned int bits;
 
if (board->n_chips > 1) {
-   if (output_select == NI660X_IO_CFG_OUT_SEL_COUNTER &&
-   pfi_channel >= counter_4_7_first_pfi &&
-   pfi_channel <= counter_4_7_last_pfi) {
-   active_chipset = 1;
-   idle_chipset = 0;
+   if (out_sel == NI660X_IO_CFG_OUT_SEL_COUNTER &&
+   chan >= 8 && chan <= 23) {
+   /* counters 4-7 pfi channels */
+   active_chip = 1;
+   idle_chip = 0;
} else {
-   active_chipset = 0;
-   idle_chipset = 1;
+   /* counters 0-3 pfi channels */
+   active_chip = 0;
+   idle_chip = 1;
}
}
 
-   if (idle_chipset != active_chipset) {
-   idle_bits = ni_660x_read(dev, idle_chipset,
-NI660X_IO_CFG(pfi_channel));
-   idle_bits &= ~NI660X_IO_CFG_OUT_SEL_MASK(pfi_channel);
-   idle_bits |=
-   NI660X_IO_CFG_OUT_SEL(pfi_channel,
- NI660X_IO_CFG_OUT_SEL_HIGH_Z);
-   ni_660x_write(dev, idle_chipset, idle_bits,
- NI660X_IO_CFG(pfi_channel));
+   if (idle_chip != active_chip) {
+   /* set the pfi channel to high-z on the inactive chip */
+   bits = ni_660x_read(dev, idle_chip, NI660X_IO_CFG(chan));
+   bits &= ~NI660X_IO_CFG_OUT_SEL_MASK(chan);
+   bits |= NI660X_IO_CFG_OUT_SEL(chan,
+ NI660X_IO_CFG_OUT_SEL_HIGH_Z);
+   ni_660x_write(dev, idle_chip, bits, NI660X_IO_CFG(chan));
}
 
-   active_bits = ni_660x_read(dev, active_chipset,
-  NI660X_IO_CFG(pfi_channel));
-   active_bits &= ~NI660X_IO_CFG_OUT_SEL_MASK(pfi_channel);
-   active_bits |= NI660X_IO_CFG_OUT_SEL(pfi_channel, output_select);
-   ni_660x_write(dev, active_chipset, active_bits,
- NI660X_IO_CFG(pfi_channel));
+   /* set the pfi channel output on the active chip */
+   bits = ni_660x_read(dev, active_chip, NI660X_IO_CFG(chan));
+   bits &= ~NI660X_IO_CFG_OUT_SEL_MASK(chan);
+   bits |= NI660X_IO_CFG_OUT_SEL(chan, out_sel);
+   ni_660x_write(dev, active_chip, bits, NI660X_IO_CFG(chan));
 }
 
 static int ni_660x_set_pfi_routing(struct comedi_device *dev, unsigned chan,
-- 
2.6.3

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


[PATCH v2 24/43] staging: comedi: ni_660x: add a comment about the initial DIO state

2016-03-22 Thread H Hartley Sweeten
The (*auto_attach) initializes all the DIO channels to a default state.
Add a comment for clarity.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 3415a15..6f84946 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -1073,6 +1073,11 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
for (i = 0; i < n_counters; ++i)
ni_tio_init_counter(&devpriv->counter_dev->counters[i]);
 
+/*
+ * Default the DIO channels as:
+ *   chan 0-7:  DIO inputs
+ *   chan 8-39: counter signal inputs
+ */
for (i = 0; i < NUM_PFI_CHANNELS; ++i) {
if (i < 8)
ni_660x_set_pfi_routing(dev, i, NI_660X_PFI_OUTPUT_DIO);
-- 
2.6.3

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


[PATCH v2 12/43] staging: comedi: ni_660x: tidy up ni_660x_read_register()

2016-03-22 Thread H Hartley Sweeten
Rename this function to help shorten some of the long lines.

Remove the inline, let the compiler figure it out.

Change the 'unsigned' parameters to 'unsigned int' to fix the
checkpatch.pl issues:

WARNING: Prefer 'unsigned int' to bare use of 'unsigned'

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 22 ++
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index aa40ab6..cd101bb 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -516,9 +516,9 @@ static void ni_660x_write(struct comedi_device *dev,
writel(bits, dev->mmio + addr);
 }
 
-static inline unsigned ni_660x_read_register(struct comedi_device *dev,
-unsigned chip,
-enum ni_660x_register reg)
+static unsigned int ni_660x_read(struct comedi_device *dev,
+unsigned int chip,
+enum ni_660x_register reg)
 {
unsigned int addr = GPCT_OFFSET[chip] + ni_660x_reg_data[reg].offset;
 
@@ -544,7 +544,7 @@ static unsigned ni_gpct_read_register(struct ni_gpct 
*counter,
enum ni_660x_register ni_660x_register = ni_gpct_to_660x_register(reg);
unsigned chip = counter->chip_index;
 
-   return ni_660x_read_register(dev, chip, ni_660x_register);
+   return ni_660x_read(dev, chip, ni_660x_register);
 }
 
 static inline struct mite_dma_descriptor_ring *mite_ring(struct ni_660x_private
@@ -812,7 +812,7 @@ static int ni_660x_dio_insn_bits(struct comedi_device *dev,
}
/* on return, data[1] contains the value of the digital
 * input and output lines. */
-   data[1] = (ni_660x_read_register(dev, 0, NI660X_DIO32_INPUT) >>
+   data[1] = (ni_660x_read(dev, 0, NI660X_DIO32_INPUT) >>
base_bitfield_channel);
 
return insn->n;
@@ -843,9 +843,8 @@ static void ni_660x_select_pfi_output(struct comedi_device 
*dev,
}
 
if (idle_chipset != active_chipset) {
-   idle_bits =
-   ni_660x_read_register(dev, idle_chipset,
- NI660X_IO_CFG(pfi_channel));
+   idle_bits = ni_660x_read(dev, idle_chipset,
+NI660X_IO_CFG(pfi_channel));
idle_bits &= ~NI660X_IO_CFG_OUT_SEL_MASK(pfi_channel);
idle_bits |=
NI660X_IO_CFG_OUT_SEL(pfi_channel,
@@ -854,9 +853,8 @@ static void ni_660x_select_pfi_output(struct comedi_device 
*dev,
  NI660X_IO_CFG(pfi_channel));
}
 
-   active_bits =
-   ni_660x_read_register(dev, active_chipset,
- NI660X_IO_CFG(pfi_channel));
+   active_bits = ni_660x_read(dev, active_chipset,
+  NI660X_IO_CFG(pfi_channel));
active_bits &= ~NI660X_IO_CFG_OUT_SEL_MASK(pfi_channel);
active_bits |= NI660X_IO_CFG_OUT_SEL(pfi_channel, output_select);
ni_660x_write(dev, active_chipset, active_bits,
@@ -927,7 +925,7 @@ static int ni_660x_dio_insn_config(struct comedi_device 
*dev,
break;
 
case INSN_CONFIG_FILTER:
-   val = ni_660x_read_register(dev, 0, NI660X_IO_CFG(chan));
+   val = ni_660x_read(dev, 0, NI660X_IO_CFG(chan));
val &= ~NI660X_IO_CFG_IN_SEL_MASK(chan);
val |= NI660X_IO_CFG_IN_SEL(chan, data[1]);
ni_660x_write(dev, 0, val, NI660X_IO_CFG(chan));
-- 
2.6.3

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


[PATCH v2 0/6] staging: comedi: ni_labpc: minor cleanup

2016-03-22 Thread H Hartley Sweeten
Fix all the checkpatch.pl issues.

v2: remove the changes to z8536.h

H Hartley Sweeten (6):
  staging: comedi: ni_labpc: remove some unnecessary defines
  staging: comedi: ni_labpc_regs.h: tidy up bit defines
  staging: comedi: ni_labpc_common: tidy up block comments
  staging: comedi: ni_labpc_cs: fix block comment issues
  staging: comedi: ni_labpc_pci: tidy up bit define
  staging: comedi: ni_labpc.h: fix block comment issues

 drivers/staging/comedi/drivers/ni_labpc.h| 33 
 drivers/staging/comedi/drivers/ni_labpc_common.c | 65 +---
 drivers/staging/comedi/drivers/ni_labpc_cs.c | 95 +++-
 drivers/staging/comedi/drivers/ni_labpc_pci.c|  4 +-
 drivers/staging/comedi/drivers/ni_labpc_regs.h   | 82 ++--
 5 files changed, 141 insertions(+), 138 deletions(-)

-- 
2.6.3

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


[PATCH v2 1/6] staging: comedi: ni_labpc: remove some unnecessary defines

2016-03-22 Thread H Hartley Sweeten
The EEPROM_SIZE and NUM_AO_CHAN defines are only used once and they
don't add any significant clarity to the driver. They are also pretty
generic symbol names. Remove them and just open code the values.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_labpc.h| 3 ---
 drivers/staging/comedi/drivers/ni_labpc_common.c | 6 +++---
 2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_labpc.h 
b/drivers/staging/comedi/drivers/ni_labpc.h
index 83f878a..74db3ba 100644
--- a/drivers/staging/comedi/drivers/ni_labpc.h
+++ b/drivers/staging/comedi/drivers/ni_labpc.h
@@ -19,9 +19,6 @@
 #ifndef _NI_LABPC_H
 #define _NI_LABPC_H
 
-#define EEPROM_SIZE256 /*  256 byte eeprom */
-#define NUM_AO_CHAN2   /*  boards have two analog output channels */
-
 enum transfer_type { fifo_not_empty_transfer, fifo_half_full_transfer,
isa_dma_transfer
 };
diff --git a/drivers/staging/comedi/drivers/ni_labpc_common.c 
b/drivers/staging/comedi/drivers/ni_labpc_common.c
index 863afb2..55ab05e 100644
--- a/drivers/staging/comedi/drivers/ni_labpc_common.c
+++ b/drivers/staging/comedi/drivers/ni_labpc_common.c
@@ -1261,7 +1261,7 @@ int labpc_common_attach(struct comedi_device *dev,
if (board->has_ao) {
s->type = COMEDI_SUBD_AO;
s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_GROUND;
-   s->n_chan   = NUM_AO_CHAN;
+   s->n_chan   = 2;
s->maxdata  = 0x0fff;
s->range_table  = &range_labpc_ao;
s->insn_write   = labpc_ao_insn_write;
@@ -1307,12 +1307,12 @@ int labpc_common_attach(struct comedi_device *dev,
s->type = COMEDI_SUBD_UNUSED;
}
 
-   /* EEPROM */
+   /* EEPROM (256 bytes) */
s = &dev->subdevices[4];
if (board->is_labpc1200) {
s->type = COMEDI_SUBD_MEMORY;
s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL;
-   s->n_chan   = EEPROM_SIZE;
+   s->n_chan   = 256;
s->maxdata  = 0xff;
s->insn_write   = labpc_eeprom_insn_write;
 
-- 
2.6.3

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


[PATCH v2 3/6] staging: comedi: ni_labpc_common: tidy up block comments

2016-03-22 Thread H Hartley Sweeten
Fix the checkpatch.pl issues:
WARNING: Block comments use a trailing */ on a separate line

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_labpc_common.c | 59 +++-
 1 file changed, 37 insertions(+), 22 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_labpc_common.c 
b/drivers/staging/comedi/drivers/ni_labpc_common.c
index 55ab05e..b0dfb8e 100644
--- a/drivers/staging/comedi/drivers/ni_labpc_common.c
+++ b/drivers/staging/comedi/drivers/ni_labpc_common.c
@@ -84,8 +84,10 @@ static const struct comedi_lrange range_labpc_ao = {
}
 };
 
-/* functions that do inb/outb and readb/writeb so we can use
- * function pointers to decide which to use */
+/*
+ * functions that do inb/outb and readb/writeb so we can use
+ * function pointers to decide which to use
+ */
 static unsigned int labpc_inb(struct comedi_device *dev, unsigned long reg)
 {
return inb(dev->iobase + reg);
@@ -656,19 +658,24 @@ static int labpc_ai_cmd(struct comedi_device *dev, struct 
comedi_subdevice *s)
 
/* figure out what method we will use to transfer data */
if (devpriv->dma &&
-   /* dma unsafe at RT priority,
-* and too much setup time for CMDF_WAKE_EOS */
-   (cmd->flags & (CMDF_WAKE_EOS | CMDF_PRIORITY)) == 0)
+   (cmd->flags & (CMDF_WAKE_EOS | CMDF_PRIORITY)) == 0) {
+   /*
+* dma unsafe at RT priority,
+* and too much setup time for CMDF_WAKE_EOS
+*/
xfer = isa_dma_transfer;
-   else if (/* pc-plus has no fifo-half full interrupt */
-board->is_labpc1200 &&
-/* wake-end-of-scan should interrupt on fifo not empty */
-(cmd->flags & CMDF_WAKE_EOS) == 0 &&
-/* make sure we are taking more than just a few points */
-(cmd->stop_src != TRIG_COUNT || devpriv->count > 256))
+   } else if (board->is_labpc1200 &&
+  (cmd->flags & CMDF_WAKE_EOS) == 0 &&
+  (cmd->stop_src != TRIG_COUNT || devpriv->count > 256)) {
+   /*
+* pc-plus has no fifo-half full interrupt
+* wake-end-of-scan should interrupt on fifo not empty
+* make sure we are taking more than just a few points
+*/
xfer = fifo_half_full_transfer;
-   else
+   } else {
xfer = fifo_not_empty_transfer;
+   }
devpriv->current_transfer = xfer;
 
labpc_ai_set_chan_and_gain(dev, mode, chan, range, aref);
@@ -679,9 +686,11 @@ static int labpc_ai_cmd(struct comedi_device *dev, struct 
comedi_subdevice *s)
/* manual says to set scan enable bit on second pass */
if (mode == MODE_MULT_CHAN_UP || mode == MODE_MULT_CHAN_DOWN) {
devpriv->cmd1 |= CMD1_SCANEN;
-   /* need a brief delay before enabling scan, or scan
-* list will get screwed when you switch
-* between scan up to scan down mode - dunno why */
+   /*
+* Need a brief delay before enabling scan, or scan
+* list will get screwed when you switch between
+* scan up to scan down mode - dunno why.
+*/
udelay(1);
devpriv->write_byte(dev, devpriv->cmd1, CMD1_REG);
}
@@ -728,8 +737,10 @@ static int labpc_ai_cmd(struct comedi_device *dev, struct 
comedi_subdevice *s)
devpriv->cmd4 = 0;
if (cmd->convert_src != TRIG_EXT)
devpriv->cmd4 |= CMD4_ECLKRCV;
-   /* XXX should discard first scan when using interval scanning
-* since manual says it is not synced with scan clock */
+   /*
+* XXX should discard first scan when using interval scanning
+* since manual says it is not synced with scan clock.
+*/
if (!labpc_use_continuous_mode(cmd, mode)) {
devpriv->cmd4 |= CMD4_INTSCAN;
if (cmd->scan_begin_src == TRIG_EXT)
@@ -795,8 +806,10 @@ static int labpc_drain_fifo(struct comedi_device *dev)
return 0;
 }
 
-/* makes sure all data acquired by board is transferred to comedi (used
- * when acquisition is terminated by stop_src == TRIG_EXT). */
+/*
+ * Makes sure all data acquired by board is transferred to comedi (used
+ * when acquisition is terminated by stop_src == TRIG_EXT).
+ */
 static void labpc_drain_dregs(struct comedi_device *dev)
 {
struct labpc_private *devpriv = dev->private;
@@ -907,9 +920,11 @@ static int labpc_ao_insn_write(struct comedi_device *dev,
 
channel = CR_CHAN(insn->chanspec);
 
-   /* turn off pacing of analog output channel */
-   /* note: hardware bug in daqcard-1200 means pacing cannot
-* be independently enabled/disabled for its the two channels */
+   /*
+* Turn off pacing of analog output channel.
+  

[PATCH v2 5/6] staging: comedi: ni_labpc_pci: tidy up bit define

2016-03-22 Thread H Hartley Sweeten
As suggested by checkpatch.pl:
CHECK: Prefer using the BIT macro

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_labpc_pci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_labpc_pci.c 
b/drivers/staging/comedi/drivers/ni_labpc_pci.c
index 77d4038..cac0891 100644
--- a/drivers/staging/comedi/drivers/ni_labpc_pci.c
+++ b/drivers/staging/comedi/drivers/ni_labpc_pci.c
@@ -51,8 +51,8 @@ static const struct labpc_boardinfo labpc_pci_boards[] = {
 };
 
 /* ripped from mite.h and mite_setup2() to avoid mite dependency */
-#define MITE_IODWBSR   0xc0 /* IO Device Window Base Size Register */
-#define WENAB  (1 << 7) /* window enable */
+#define MITE_IODWBSR   0xc0/* IO Device Window Base Size Register */
+#define WENAB  BIT(7)  /* window enable */
 
 static int labpc_pci_mite_init(struct pci_dev *pcidev)
 {
-- 
2.6.3

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


[PATCH v2 6/6] staging: comedi: ni_labpc.h: fix block comment issues

2016-03-22 Thread H Hartley Sweeten
Fix the checkpatch.pl issues:
WARNING: Block comments use * on subsequent lines

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_labpc.h | 30 ++
 1 file changed, 14 insertions(+), 16 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_labpc.h 
b/drivers/staging/comedi/drivers/ni_labpc.h
index 74db3ba..be8d5cd 100644
--- a/drivers/staging/comedi/drivers/ni_labpc.h
+++ b/drivers/staging/comedi/drivers/ni_labpc.h
@@ -1,20 +1,18 @@
 /*
-ni_labpc.h
-
-Header for ni_labpc.c and ni_labpc_cs.c
-
-Copyright (C) 2003 Frank Mori Hess 
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-*/
+ * Header for ni_labpc ISA/PCMCIA/PCI drivers
+ *
+ * Copyright (C) 2003 Frank Mori Hess 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
 
 #ifndef _NI_LABPC_H
 #define _NI_LABPC_H
-- 
2.6.3

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


[PATCH v2 2/6] staging: comedi: ni_labpc_regs.h: tidy up bit defines

2016-03-22 Thread H Hartley Sweeten
As suggested by checkpatch.pl:
CHECK: Prefer using the BIT macro

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_labpc_regs.h | 82 +-
 1 file changed, 41 insertions(+), 41 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_labpc_regs.h 
b/drivers/staging/comedi/drivers/ni_labpc_regs.h
index 2a274a3..8c52179 100644
--- a/drivers/staging/comedi/drivers/ni_labpc_regs.h
+++ b/drivers/staging/comedi/drivers/ni_labpc_regs.h
@@ -9,32 +9,32 @@
  * Register map (all registers are 8-bit)
  */
 #define STAT1_REG  0x00/* R: Status 1 reg */
-#define STAT1_DAVAIL   (1 << 0)
-#define STAT1_OVERRUN  (1 << 1)
-#define STAT1_OVERFLOW (1 << 2)
-#define STAT1_CNTINT   (1 << 3)
-#define STAT1_GATA0(1 << 5)
-#define STAT1_EXTGATA0 (1 << 6)
+#define STAT1_DAVAIL   BIT(0)
+#define STAT1_OVERRUN  BIT(1)
+#define STAT1_OVERFLOW BIT(2)
+#define STAT1_CNTINT   BIT(3)
+#define STAT1_GATA0BIT(5)
+#define STAT1_EXTGATA0 BIT(6)
 #define CMD1_REG   0x00/* W: Command 1 reg */
 #define CMD1_MA(x) (((x) & 0x7) << 0)
-#define CMD1_TWOSCMP   (1 << 3)
+#define CMD1_TWOSCMP   BIT(3)
 #define CMD1_GAIN(x)   (((x) & 0x7) << 4)
-#define CMD1_SCANEN(1 << 7)
+#define CMD1_SCANENBIT(7)
 #define CMD2_REG   0x01/* W: Command 2 reg */
-#define CMD2_PRETRIG   (1 << 0)
-#define CMD2_HWTRIG(1 << 1)
-#define CMD2_SWTRIG(1 << 2)
-#define CMD2_TBSEL (1 << 3)
-#define CMD2_2SDAC0(1 << 4)
-#define CMD2_2SDAC1(1 << 5)
-#define CMD2_LDAC(x)   (1 << (6 + (x)))
+#define CMD2_PRETRIG   BIT(0)
+#define CMD2_HWTRIGBIT(1)
+#define CMD2_SWTRIGBIT(2)
+#define CMD2_TBSEL BIT(3)
+#define CMD2_2SDAC0BIT(4)
+#define CMD2_2SDAC1BIT(5)
+#define CMD2_LDAC(x)   BIT(6 + ((x) & 0x1))
 #define CMD3_REG   0x02/* W: Command 3 reg */
-#define CMD3_DMAEN (1 << 0)
-#define CMD3_DIOINTEN  (1 << 1)
-#define CMD3_DMATCINTEN(1 << 2)
-#define CMD3_CNTINTEN  (1 << 3)
-#define CMD3_ERRINTEN  (1 << 4)
-#define CMD3_FIFOINTEN (1 << 5)
+#define CMD3_DMAEN BIT(0)
+#define CMD3_DIOINTEN  BIT(1)
+#define CMD3_DMATCINTENBIT(2)
+#define CMD3_CNTINTEN  BIT(3)
+#define CMD3_ERRINTEN  BIT(4)
+#define CMD3_FIFOINTEN BIT(5)
 #define ADC_START_CONVERT_REG  0x03/* W: Start Convert reg */
 #define DAC_LSB_REG(x) (0x04 + 2 * (x)) /* W: DAC0/1 LSB reg */
 #define DAC_MSB_REG(x) (0x05 + 2 * (x)) /* W: DAC0/1 MSB reg */
@@ -43,32 +43,32 @@
 #define DMATC_CLEAR_REG0x0a/* W: DMA Interrupt Clear reg */
 #define TIMER_CLEAR_REG0x0c/* W: Timer Interrupt Clear reg 
*/
 #define CMD6_REG   0x0e/* W: Command 6 reg */
-#define CMD6_NRSE  (1 << 0)
-#define CMD6_ADCUNI(1 << 1)
-#define CMD6_DACUNI(x) (1 << (2 + (x)))
-#define CMD6_HFINTEN   (1 << 5)
-#define CMD6_DQINTEN   (1 << 6)
-#define CMD6_SCANUP(1 << 7)
+#define CMD6_NRSE  BIT(0)
+#define CMD6_ADCUNIBIT(1)
+#define CMD6_DACUNI(x) BIT(2 + ((x) & 0x1))
+#define CMD6_HFINTEN   BIT(5)
+#define CMD6_DQINTEN   BIT(6)
+#define CMD6_SCANUPBIT(7)
 #define CMD4_REG   0x0f/* W: Command 3 reg */
-#define CMD4_INTSCAN   (1 << 0)
-#define CMD4_EOIRCV(1 << 1)
-#define CMD4_ECLKDRV   (1 << 2)
-#define CMD4_SEDIFF(1 << 3)
-#define CMD4_ECLKRCV   (1 << 4)
+#define CMD4_INTSCAN   BIT(0)
+#define CMD4_EOIRCVBIT(1)
+#define CMD4_ECLKDRV   BIT(2)
+#define CMD4_SEDIFFBIT(3)
+#define CMD4_ECLKRCV   BIT(4)
 #define DIO_BASE_REG   0x10/* R/W: 8255 DIO base reg */
 #define COUNTER_A_BASE_REG 0x14/* R/W: 8253 Counter A base reg */
 #define COUNTER_B_BASE_REG 0x18/* R/W: 8253 Counter B base reg */
 #define CMD5_REG   0x1c/* W: Command 5 reg */
-#define CMD5_WRTPRT(1 << 2)
-#define CMD5_DITHEREN  (1 << 3)
-#define CMD5_CALDACLD  (1 << 4)
-#define CMD5_SCLK  (1 << 5)
-#define CMD5_SDATA (1 << 6)
-#define CMD5_EEPROMCS  (1 << 7)
+#define CMD5_WRTPRTBIT(2)
+#define CMD5_DITHEREN  BIT(3)
+#define CMD5_CALDACLD  BIT(4)
+#define CMD5_SCLK  BIT(5)
+#define CMD5_SDATA BIT(6)
+#define CMD5_EEPROMCS  BIT(7)
 #define STAT2_REG  0x1d/* R: Status 2 reg */
-#define STAT2_PROMOUT  (1 << 0)
-#define STAT2_OUTA1(1 << 1)
-#define

[PATCH v2 4/6] staging: comedi: ni_labpc_cs: fix block comment issues

2016-03-22 Thread H Hartley Sweeten
Fix the checkpatch.pl issues:
WARNING: Block comments use * on subsequent lines
WARNING: line over 80 characters

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_labpc_cs.c | 95 +---
 1 file changed, 44 insertions(+), 51 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_labpc_cs.c 
b/drivers/staging/comedi/drivers/ni_labpc_cs.c
index a1c69ac..3d4d0b9 100644
--- a/drivers/staging/comedi/drivers/ni_labpc_cs.c
+++ b/drivers/staging/comedi/drivers/ni_labpc_cs.c
@@ -1,57 +1,50 @@
 /*
-comedi/drivers/ni_labpc_cs.c
-Driver for National Instruments daqcard-1200 boards
-Copyright (C) 2001, 2002, 2003 Frank Mori Hess 

-
-PCMCIA crap is adapted from dummy_cs.c 1.31 2001/08/24 12:13:13
-from the pcmcia package.
-The initial developer of the pcmcia dummy_cs.c code is David A. Hinds
-.  Portions created by David A. Hinds
-are Copyright (C) 1999 David A. Hinds.
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-*/
-/*
-Driver: ni_labpc_cs
-Description: National Instruments Lab-PC (& compatibles)
-Author: Frank Mori Hess 
-Devices: [National Instruments] DAQCard-1200 (daqcard-1200)
-Status: works
-
-Thanks go to Fredrik Lingvall for much testing and perseverance in
-helping to debug daqcard-1200 support.
-
-The 1200 series boards have onboard calibration dacs for correcting
-analog input/output offsets and gains.  The proper settings for these
-caldacs are stored on the board's eeprom.  To read the caldac values
-from the eeprom and store them into a file that can be then be used by
-comedilib, use the comedi_calibrate program.
-
-Configuration options:
-  none
-
-The daqcard-1200 has quirky chanlist requirements
-when scanning multiple channels.  Multiple channel scan
-sequence must start at highest channel, then decrement down to
-channel 0.  Chanlists consisting of all one channel
-are also legal, and allow you to pace conversions in bursts.
-
-*/
+ * Driver for National Instruments daqcard-1200 boards
+ * Copyright (C) 2001, 2002, 2003 Frank Mori Hess 

+ *
+ * PCMCIA crap is adapted from dummy_cs.c 1.31 2001/08/24 12:13:13
+ * from the pcmcia package.
+ * The initial developer of the pcmcia dummy_cs.c code is David A. Hinds
+ * .  Portions created by David A. Hinds
+ * are Copyright (C) 1999 David A. Hinds.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * General Public License for more details.
+ */
 
 /*
-
-NI manuals:
-340988a (daqcard-1200)
-
-*/
+ * Driver: ni_labpc_cs
+ * Description: National Instruments Lab-PC (& compatibles)
+ * Author: Frank Mori Hess 
+ * Devices: [National Instruments] DAQCard-1200 (daqcard-1200)
+ * Status: works
+ *
+ * Thanks go to Fredrik Lingvall for much testing and perseverance in
+ * helping to debug daqcard-1200 support.
+ *
+ * The 1200 series boards have onboard calibration dacs for correcting
+ * analog input/output offsets and gains. The proper settings for these
+ * caldacs are stored on the board's eeprom. To read the caldac values
+ * from the eeprom and store them into a file that can be then be used by
+ * comedilib, use the comedi_calibrate program.
+ *
+ * Configuration options: none
+ *
+ * The daqcard-1200 has quirky chanlist requirements when scanning multiple
+ * channels. Multiple channel scan sequence must start at highest channel,
+ * then decrement down to channel 0.  Chanlists consisting of all one channel
+ * are also legal, and allow you to pace conversions in bursts.
+ *
+ * NI manuals:
+ *   340988a (daqcard-1200)
+ */
 
 #include 
 
-- 
2.6.3

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


[PATCH] staging: comedi: z8536: tidy up bit defines

2016-03-22 Thread H Hartley Sweeten
Fix the checkpatch.pl issues:
CHECK: Prefer using the BIT macro

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/z8536.h | 89 ++
 1 file changed, 48 insertions(+), 41 deletions(-)

diff --git a/drivers/staging/comedi/drivers/z8536.h 
b/drivers/staging/comedi/drivers/z8536.h
index 7be5310..47eadbf 100644
--- a/drivers/staging/comedi/drivers/z8536.h
+++ b/drivers/staging/comedi/drivers/z8536.h
@@ -24,11 +24,12 @@
 #define Z8536_CFG_CTRL_PCE_CT3EBIT(4)  /* Port C & C/T 3 
Enable */
 #define Z8536_CFG_CTRL_PLC BIT(3)  /* Port A/B Link Control */
 #define Z8536_CFG_CTRL_PAE BIT(2)  /* Port A Enable */
-#define Z8536_CFG_CTRL_LC_INDEP(0 << 0)/* C/Ts Independent */
-#define Z8536_CFG_CTRL_LC_GATE (1 << 0)/* C/T 1 Out Gates C/T 2 */
-#define Z8536_CFG_CTRL_LC_TRIG (2 << 0)/* C/T 1 Out Triggers C/T 2 */
-#define Z8536_CFG_CTRL_LC_CLK  (3 << 0)/* C/T 1 Out Clocks C/T 2 */
-#define Z8536_CFG_CTRL_LC_MASK (3 << 0)/* C/T Link Control mask */
+#define Z8536_CFG_CTRL_LC(x)   (((x) & 0x3) << 0)  /* Link Control */
+#define Z8536_CFG_CTRL_LC_INDEPZ8536_CFG_CTRL_LC(0)/* 
Independent */
+#define Z8536_CFG_CTRL_LC_GATE Z8536_CFG_CTRL_LC(1)/* 1 Gates 2 */
+#define Z8536_CFG_CTRL_LC_TRIG Z8536_CFG_CTRL_LC(2)/* 1 Triggers 2 */
+#define Z8536_CFG_CTRL_LC_CLK  Z8536_CFG_CTRL_LC(3)/* 1 Clocks 2 */
+#define Z8536_CFG_CTRL_LC_MASK Z8536_CFG_CTRL_LC(3)
 
 /* Interrupt Vector registers */
 #define Z8536_PA_INT_VECT_REG  0x02
@@ -43,15 +44,16 @@
 #define Z8536_CT2_CMDSTAT_REG  0x0b
 #define Z8536_CT3_CMDSTAT_REG  0x0c
 #define Z8536_CT_CMDSTAT_REG(x)(0x0a + (x))
-#define Z8536_CMD_NULL (0 << 5)/* Null Code */
-#define Z8536_CMD_CLR_IP_IUS   (1 << 5)/* Clear IP & IUS */
-#define Z8536_CMD_SET_IUS  (2 << 5)/* Set IUS */
-#define Z8536_CMD_CLR_IUS  (3 << 5)/* Clear IUS */
-#define Z8536_CMD_SET_IP   (4 << 5)/* Set IP */
-#define Z8536_CMD_CLR_IP   (5 << 5)/* Clear IP */
-#define Z8536_CMD_SET_IE   (6 << 5)/* Set IE */
-#define Z8536_CMD_CLR_IE   (7 << 5)/* Clear IE */
-#define Z8536_CMD_MASK (7 << 5)
+#define Z8536_CMD(x)   (((x) & 0x7) << 5)
+#define Z8536_CMD_NULL Z8536_CMD(0)/* Null Code */
+#define Z8536_CMD_CLR_IP_IUS   Z8536_CMD(1)/* Clear IP & IUS */
+#define Z8536_CMD_SET_IUS  Z8536_CMD(2)/* Set IUS */
+#define Z8536_CMD_CLR_IUS  Z8536_CMD(3)/* Clear IUS */
+#define Z8536_CMD_SET_IP   Z8536_CMD(4)/* Set IP */
+#define Z8536_CMD_CLR_IP   Z8536_CMD(5)/* Clear IP */
+#define Z8536_CMD_SET_IE   Z8536_CMD(6)/* Set IE */
+#define Z8536_CMD_CLR_IE   Z8536_CMD(7)/* Clear IE */
+#define Z8536_CMD_MASK Z8536_CMD(7)
 
 #define Z8536_STAT_IUS BIT(7)  /* Interrupt Under Service */
 #define Z8536_STAT_IE  BIT(6)  /* Interrupt Enable */
@@ -105,46 +107,51 @@
 #define Z8536_CT_MODE_ETE  BIT(4)  /* External Trigger Enable */
 #define Z8536_CT_MODE_EGE  BIT(3)  /* External Gate Enable */
 #define Z8536_CT_MODE_REB  BIT(2)  /* Retrigger Enable Bit */
-#define Z8536_CT_MODE_DCS_PULSE(0 << 0)/* Duty Cycle - Pulse */
-#define Z8536_CT_MODE_DCS_ONESHOT  (1 << 0)/* Duty Cycle - One-Shot */
-#define Z8536_CT_MODE_DCS_SQRWAVE  (2 << 0)/* Duty Cycle - Square Wave */
-#define Z8536_CT_MODE_DCS_DO_NOT_USE   (3 << 0)/* Duty Cycle - Do Not Use */
-#define Z8536_CT_MODE_DCS_MASK (3 << 0)/* Duty Cycle mask */
+#define Z8536_CT_MODE_DCS(x)   (((x) & 0x3) << 0)   /* Duty Cycle */
+#define Z8536_CT_MODE_DCS_PULSEZ8536_CT_MODE_DCS(0) /* Pulse */
+#define Z8536_CT_MODE_DCS_ONESHOT  Z8536_CT_MODE_DCS(1) /* One-Shot */
+#define Z8536_CT_MODE_DCS_SQRWAVE  Z8536_CT_MODE_DCS(2) /* Square Wave */
+#define Z8536_CT_MODE_DCS_DO_NOT_USE   Z8536_CT_MODE_DCS(3) /* Do Not Use */
+#define Z8536_CT_MODE_DCS_MASK Z8536_CT_MODE_DCS(3)
 
 /* Port A/B Mode Specification registers */
 #define Z8536_PA_MODE_REG  0x20
 #define Z8536_PB_MODE_REG  0x28
-#define Z8536_PAB_MODE_PTS_BIT (0 << 6)/* Bit Port */
-#define Z8536_PAB_MODE_PTS_INPUT   (1 << 6)/* Input Port */
-#define Z8536_PAB_MODE_PTS_OUTPUT  (2 << 6)/* Output Port */
-#define Z8536_PAB_MODE_PTS_BIDIR   (3 << 6)/* Bidirectional Port */
-#define Z8536_PAB_MODE_PTS_MASK(3 << 6)/* Port Type Select 
mask */
+#define Z8536_PAB_MODE_PTS(x)  (((x) & 0x3) << 6)  /* Port type */
+#define Z8536_PAB_MODE_PTS_BIT Z8536_PAB_MODE_PTS(0 << 6)/* Bit */
+#define Z8536_PAB_MODE_PTS_INPUT   Z

[PATCH 0/2] staging: comedi: plx9052.h: minor cleanup

2016-03-22 Thread H Hartley Sweeten
Fix the checkpatch.pl issues.

H Hartley Sweeten (2):
  staging: comedi: plx9052.h: tidy up bit defines
  staging: comedi: plx9052.h: fix block comment issues

 drivers/staging/comedi/drivers/plx9052.h | 122 +++
 1 file changed, 61 insertions(+), 61 deletions(-)

-- 
2.6.3

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


[PATCH 1/2] staging: comedi: plx9052.h: tidy up bit defines

2016-03-22 Thread H Hartley Sweeten
Fix the checkpatch.pl issues:
CHECK: Prefer using the BIT macro

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/plx9052.h | 87 
 1 file changed, 44 insertions(+), 43 deletions(-)

diff --git a/drivers/staging/comedi/drivers/plx9052.h 
b/drivers/staging/comedi/drivers/plx9052.h
index fbcf250..131ebff 100644
--- a/drivers/staging/comedi/drivers/plx9052.h
+++ b/drivers/staging/comedi/drivers/plx9052.h
@@ -25,55 +25,56 @@
  * INTCSR - Interrupt Control/Status register
  */
 #define PLX9052_INTCSR 0x4c
-#define PLX9052_INTCSR_LI1ENAB (1 << 0)  /* LI1 enabled */
-#define PLX9052_INTCSR_LI1POL  (1 << 1)  /* LI1 active high */
-#define PLX9052_INTCSR_LI1STAT (1 << 2)  /* LI1 active */
-#define PLX9052_INTCSR_LI2ENAB (1 << 3)  /* LI2 enabled */
-#define PLX9052_INTCSR_LI2POL  (1 << 4)  /* LI2 active high */
-#define PLX9052_INTCSR_LI2STAT (1 << 5)  /* LI2 active */
-#define PLX9052_INTCSR_PCIENAB (1 << 6)  /* PCIINT enabled */
-#define PLX9052_INTCSR_SOFTINT (1 << 7)  /* generate soft int */
-#define PLX9052_INTCSR_LI1SEL  (1 << 8)  /* LI1 edge */
-#define PLX9052_INTCSR_LI2SEL  (1 << 9)  /* LI2 edge */
-#define PLX9052_INTCSR_LI1CLRINT   (1 << 10) /* LI1 clear int */
-#define PLX9052_INTCSR_LI2CLRINT   (1 << 11) /* LI2 clear int */
-#define PLX9052_INTCSR_ISAMODE (1 << 12) /* ISA interface mode */
+#define PLX9052_INTCSR_LI1ENAB BIT(0)  /* LI1 enabled */
+#define PLX9052_INTCSR_LI1POL  BIT(1)  /* LI1 active high */
+#define PLX9052_INTCSR_LI1STAT BIT(2)  /* LI1 active */
+#define PLX9052_INTCSR_LI2ENAB BIT(3)  /* LI2 enabled */
+#define PLX9052_INTCSR_LI2POL  BIT(4)  /* LI2 active high */
+#define PLX9052_INTCSR_LI2STAT BIT(5)  /* LI2 active */
+#define PLX9052_INTCSR_PCIENAB BIT(6)  /* PCIINT enabled */
+#define PLX9052_INTCSR_SOFTINT BIT(7)  /* generate soft int */
+#define PLX9052_INTCSR_LI1SEL  BIT(8)  /* LI1 edge */
+#define PLX9052_INTCSR_LI2SEL  BIT(9)  /* LI2 edge */
+#define PLX9052_INTCSR_LI1CLRINT   BIT(10) /* LI1 clear int */
+#define PLX9052_INTCSR_LI2CLRINT   BIT(11) /* LI2 clear int */
+#define PLX9052_INTCSR_ISAMODE BIT(12) /* ISA interface mode */
 
 /*
  * CNTRL - User I/O, Direct Slave Response, Serial EEPROM, and
  * Initialization Control register
  */
 #define PLX9052_CNTRL  0x50
-#define PLX9052_CNTRL_WAITO(1 << 0)  /* UIO0 or WAITO# select */
-#define PLX9052_CNTRL_UIO0_DIR (1 << 1)  /* UIO0 direction */
-#define PLX9052_CNTRL_UIO0_DATA(1 << 2)  /* UIO0 data */
-#define PLX9052_CNTRL_LLOCKO   (1 << 3)  /* UIO1 or LLOCKo# select */
-#define PLX9052_CNTRL_UIO1_DIR (1 << 4)  /* UIO1 direction */
-#define PLX9052_CNTRL_UIO1_DATA(1 << 5)  /* UIO1 data */
-#define PLX9052_CNTRL_CS2  (1 << 6)  /* UIO2 or CS2# select */
-#define PLX9052_CNTRL_UIO2_DIR (1 << 7)  /* UIO2 direction */
-#define PLX9052_CNTRL_UIO2_DATA(1 << 8)  /* UIO2 data */
-#define PLX9052_CNTRL_CS3  (1 << 9)  /* UIO3 or CS3# select */
-#define PLX9052_CNTRL_UIO3_DIR (1 << 10) /* UIO3 direction */
-#define PLX9052_CNTRL_UIO3_DATA(1 << 11) /* UIO3 data */
-#define PLX9052_CNTRL_PCIBAR01 (0 << 12) /* bar 0 (mem) and 1 (I/O) */
-#define PLX9052_CNTRL_PCIBAR0  (1 << 12) /* bar 0 (mem) only */
-#define PLX9052_CNTRL_PCIBAR1  (2 << 12) /* bar 1 (I/O) only */
-#define PLX9052_CNTRL_PCI2_1_FEATURES  (1 << 14) /* PCI r2.1 features enabled 
*/
-#define PLX9052_CNTRL_PCI_R_W_FLUSH(1 << 15) /* read w/write flush mode */
-#define PLX9052_CNTRL_PCI_R_NO_FLUSH   (1 << 16) /* read no flush mode */
-#define PLX9052_CNTRL_PCI_R_NO_WRITE   (1 << 17) /* read no write mode */
-#define PLX9052_CNTRL_PCI_W_RELEASE(1 << 18) /* write release bus mode */
-#define PLX9052_CNTRL_RETRY_CLKS(x)(((x) & 0xf) << 19) /* slave retry clks 
*/
-#define PLX9052_CNTRL_LOCK_ENAB(1 << 23) /* slave LOCK# enable 
*/
+#define PLX9052_CNTRL_WAITOBIT(0)  /* UIO0 or WAITO# select */
+#define PLX9052_CNTRL_UIO0_DIR BIT(1)  /* UIO0 direction */
+#define PLX9052_CNTRL_UIO0_DATABIT(2)  /* UIO0 data */
+#define PLX9052_CNTRL_LLOCKO   BIT(3)  /* UIO1 or LLOCKo# select */
+#define PLX9052_CNTRL_UIO1_DIR BIT(4)  /* UIO1 direction */
+#define PLX9052_CNTRL_UIO1_DATABIT(5)  /* UIO1 data */
+#define PLX9052_CNTRL_CS2  BIT(6)  /* UIO2 or CS2# select */
+#define PLX9052_CNTRL_UIO2_DIR BIT(7)  /* UIO2 direction */
+#define PLX9052_CNTRL_UIO2_DATABIT(8)  /* UIO2 data */
+#define PLX9052_CNTRL_CS3  BIT(9)  /* UIO3 or CS3# select */
+#define PLX9052_CNTRL_UIO3_DIR BIT(10) 

[PATCH 2/2] staging: comedi: plx9052.h: fix block comment issues

2016-03-22 Thread H Hartley Sweeten
Fix the checkpatch.pl issues:
WARNING: Block comments use * on subsequent lines

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/plx9052.h | 35 
 1 file changed, 17 insertions(+), 18 deletions(-)

diff --git a/drivers/staging/comedi/drivers/plx9052.h 
b/drivers/staging/comedi/drivers/plx9052.h
index 131ebff..2892e65 100644
--- a/drivers/staging/comedi/drivers/plx9052.h
+++ b/drivers/staging/comedi/drivers/plx9052.h
@@ -1,22 +1,21 @@
 /*
-comedi/drivers/plx9052.h
-Definitions for the PLX-9052 PCI interface chip
-
-Copyright (C) 2002 MEV Ltd. 
-
-COMEDI - Linux Control and Measurement Device Interface
-Copyright (C) 2000 David A. Schleef 
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-*/
+ * Definitions for the PLX-9052 PCI interface chip
+ *
+ * Copyright (C) 2002 MEV Ltd. 
+ *
+ * COMEDI - Linux Control and Measurement Device Interface
+ * Copyright (C) 2000 David A. Schleef 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
 
 #ifndef _PLX9052_H_
 #define _PLX9052_H_
-- 
2.6.3

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


RE: [PATCH 1/1] scsi: storvsc: Support manual scan of FC hosts on Hyper-V

2016-03-22 Thread KY Srinivasan


> -Original Message-
> From: KY Srinivasan
> Sent: Sunday, March 20, 2016 11:59 AM
> To: 'James Bottomley' ; Martin
> K. Petersen 
> Cc: Christoph Hellwig ; gre...@linuxfoundation.org;
> linux-ker...@vger.kernel.org; de...@linuxdriverproject.org;
> oher...@suse.com; jbottom...@parallels.com; linux-s...@vger.kernel.org;
> a...@canonical.com; vkuzn...@redhat.com; jasow...@redhat.com;
> h...@suse.de
> Subject: RE: [PATCH 1/1] scsi: storvsc: Support manual scan of FC hosts on
> Hyper-V
> 
> 
> 
> > -Original Message-
> > From: James Bottomley
> [mailto:james.bottom...@hansenpartnership.com]
> > Sent: Friday, March 18, 2016 3:41 PM
> > To: KY Srinivasan ; Martin K. Petersen
> > 
> > Cc: Christoph Hellwig ; gre...@linuxfoundation.org;
> > linux-ker...@vger.kernel.org; de...@linuxdriverproject.org;
> > oher...@suse.com; jbottom...@parallels.com; linux-s...@vger.kernel.org;
> > a...@canonical.com; vkuzn...@redhat.com; jasow...@redhat.com;
> > h...@suse.de
> > Subject: Re: [PATCH 1/1] scsi: storvsc: Support manual scan of FC hosts on
> > Hyper-V
> >
> > On Thu, 2016-03-17 at 00:01 +, KY Srinivasan wrote:
> > > The only attributes I would be interested are:
> > > 1) node name
> > > 2) port name
> > >
> > > Ideally, if this can show under /sys/class/fc_host/hostx/port_name
> > > and node_name,
> > > it will be ideal since all user scripts can work.
> >
> > OK, like this?
> 
> Yes; thank you very much James. Looking at the patch though, it may be an
> overkill considering how much of the code is duplicated. The current fc
> transport
> class does give us the flexibility to control the attributes we want to 
> surface
> (fc_function_template). In any case I will test this code and get back to you
> soon.

Today I got a chance to test this patch. Looks like all the state is not getting
properly set in this new transport class. I am hitting this NULL pointer 
reference fault in
get_device_parent(). Looks like the device class is not properly setup for
this transport class. class_dir_create_and_add() is not called for this class
and so the glue_dirs is NULL.   I fixed the issue:

1) You will need to call the transport_class_register() for this new transport 
class in
fc_transport_init()
2) We cannot use fc_host as the name in this new class since the standard fc 
transport already
Uses that name. I changed the name to get this to work. This will create a new 
directory under /sys/class.
So my original goal of  being compatible with existing scripts that expect to 
find the information under
/sys/class/fc_host will not be met.

Regards,

K. Y


> 
> Regards,
> 
> K. Y
> 
> 
> >
> > From 7af7c428e7e04ddcc87fda12d6571e3dff8ae024 Mon Sep 17 00:00:00
> > 2001
> > From: James Bottomley 
> > Date: Fri, 18 Mar 2016 15:35:45 -0700
> > Subject: scsi_transport_fc: introduce lightweight class for virtualization
> >  systems
> >
> > The FC transport class is very heavily tilted towards helping things
> > which operate a fabric (as it should be).  However, there seems to be
> > a need for a lightweight version for use in virtual systems that
> > simply want to show pass through FC information without making any use
> > of the heavyweight functions.  This is an attempt to give them what
> > they want: the lightweight class has no vports or rports and only two
> > host attributes.  Essentially, it's designed for the HV storvsc
> > driver, but if other virtualizataion systems have similar problems, we
> > can add more attributes.
> >
> > Signed-off-by: James Bottomley 
> > ---
> >  drivers/scsi/scsi_transport_fc.c | 94
> > 
> >  include/scsi/scsi_transport_fc.h |  3 ++
> >  2 files changed, 97 insertions(+)
> >
> > diff --git a/drivers/scsi/scsi_transport_fc.c
> b/drivers/scsi/scsi_transport_fc.c
> > index 8a88226..a9fcb4d 100644
> > --- a/drivers/scsi/scsi_transport_fc.c
> > +++ b/drivers/scsi/scsi_transport_fc.c
> > @@ -351,6 +351,27 @@ struct fc_internal {
> >
> >  #define to_fc_internal(tmpl)   container_of(tmpl, struct fc_internal, 
> > t)
> >
> > +#define FC_LW_HOST_NUM_ATTRS   2
> > +struct fc_lw_internal {
> > +   struct scsi_transport_template t;
> > +   struct fc_function_template *f;
> > +
> > +   /*
> > +* For attributes : each object has :
> > +*   An array of the actual attributes structures
> > +*   An array of null-terminated pointers to the attribute
> > +* structures - used for mid-layer interaction.
> > +*
> > +* The attribute containers for the starget and host are are
> > +* part of the midlayer. As the remote port is specific to the
> > +* fc transport, we must provide the attribute container.
> > +*/
> > +   struct device_attribute
> > private_host_attrs[FC_LW_HOST_NUM_ATTRS];
> > +   struct device_attribute *host_attrs[FC_LW_HOST_NUM_ATTRS + 1];
> > +};
> > +
> > +#define to_fc_lw_internal(tmpl)container_of(tmpl, struct
> > fc_lw_internal, t)
> > +
> >  static int fc_target_setup(struct transport_contai

[PATCH] Revert "Staging: lustre: o2iblnd: Use sizeof type *pointer instead of sizeof type."

2016-03-22 Thread James Simmons
Latest testing fails when using ko2iblnd. It was tracked down
to commit 4671a026616df26000f7d8ad2f2ea4b6de79263c.

This reverts commit 4671a026616df26000f7d8ad2f2ea4b6de79263c.
---
 .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c|4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c 
b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
index 89f9390..0d32e65 100644
--- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
+++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
@@ -1968,7 +1968,7 @@ static int kiblnd_net_init_pools(kib_net_t *net, __u32 
*cpts, int ncpts)
 */
 
net->ibn_fmr_ps = cfs_percpt_alloc(lnet_cpt_table(),
-  sizeof(*net->ibn_fmr_ps));
+  sizeof(kib_fmr_poolset_t));
if (!net->ibn_fmr_ps) {
CERROR("Failed to allocate FMR pool array\n");
rc = -ENOMEM;
@@ -1992,7 +1992,7 @@ static int kiblnd_net_init_pools(kib_net_t *net, __u32 
*cpts, int ncpts)
 
  create_tx_pool:
net->ibn_tx_ps = cfs_percpt_alloc(lnet_cpt_table(),
- sizeof(*net->ibn_tx_ps));
+ sizeof(kib_tx_poolset_t));
if (!net->ibn_tx_ps) {
CERROR("Failed to allocate tx pool array\n");
rc = -ENOMEM;
-- 
1.7.1

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


[PATCH] staging: android: ion_test: fix check of platform_device_register_simple() error code

2016-03-22 Thread Vladimir Zapolskiy
On error platform_device_register_simple() returns ERR_PTR() value,
check for NULL always fails. The change corrects the check itself and
propagates the returned error upwards.

Fixes: 81fb0b901397 ("staging: android: ion_test: unregister the platform 
device")
Signed-off-by: Vladimir Zapolskiy 
---
 drivers/staging/android/ion/ion_test.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/android/ion/ion_test.c 
b/drivers/staging/android/ion/ion_test.c
index da34bc12..83a3af0 100644
--- a/drivers/staging/android/ion/ion_test.c
+++ b/drivers/staging/android/ion/ion_test.c
@@ -285,8 +285,8 @@ static int __init ion_test_init(void)
 {
ion_test_pdev = platform_device_register_simple("ion-test",
-1, NULL, 0);
-   if (!ion_test_pdev)
-   return -ENODEV;
+   if (IS_ERR(ion_test_pdev))
+   return PTR_ERR(ion_test_pdev);
 
return platform_driver_probe(&ion_test_platform_driver, ion_test_probe);
 }
-- 
2.1.4

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


[RFC 0/2] staging: ion: of_ion_device_get

2016-03-22 Thread Moritz Fischer
Hi all,

probably I'm doing this all wrong. I'm playing around with a bunch of 
accelerators
and I need to share buffers between them. I have my heaps implemented as a
platform device and from what I understand I'll need a reference to the
struct ion_device in each of them.
I couldn't find a way to get to that via devicetree, though. I'll admit that 
hacking
up miscdevice is quite hacky, maybe I should add a foo_get_ion_device() to my
heap implementing platform device?
If someone can explain me how to correctly do that with what we currently have,
even better.

Cheers,

   Moritz

Moritz Fischer (2):
  misc: Add of_get_misc get a reference from devicetree
  staging: android: ion: Add of_ion_device_get function

 drivers/char/misc.c   | 38 ++
 drivers/staging/android/ion/ion.c | 10 ++
 include/linux/miscdevice.h|  3 +++
 3 files changed, 51 insertions(+)

-- 
2.7.4

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


[RFC 1/2] misc: Add of_get_misc get a reference from devicetree

2016-03-22 Thread Moritz Fischer
This commit enables access to a miscdevice via a reference
obtained from devicetree.
This allows to implement a of_ion_device_get() in the next step.

Signed-off-by: Moritz Fischer 
---
 drivers/char/misc.c| 38 ++
 include/linux/miscdevice.h |  3 +++
 2 files changed, 41 insertions(+)

diff --git a/drivers/char/misc.c b/drivers/char/misc.c
index 8069b36..0623834 100644
--- a/drivers/char/misc.c
+++ b/drivers/char/misc.c
@@ -275,6 +275,44 @@ static char *misc_devnode(struct device *dev, umode_t 
*mode)
return NULL;
 }
 
+#ifdef CONFIG_OF
+static int misc_of_node_match(struct device *dev, const void *data)
+{
+   return dev->of_node == data;
+}
+
+struct miscdevice *of_misc_get(struct device_node *node)
+{
+   struct miscdevice *m;
+   struct device *dev;
+   int ret = -ENODEV;
+
+   dev = class_find_device(misc_class, NULL, node,
+   misc_of_node_match);
+   if (!dev)
+   return ERR_PTR(-ENODEV);
+
+   m = dev_get_drvdata(dev);
+   if (!m)
+   goto err_dev;
+
+   if (!try_module_get(dev->parent->driver->owner))
+   goto err_dev;
+
+   return m;
+
+err_dev:
+   put_device(dev);
+   return ERR_PTR(ret);
+}
+#else
+struct misc_device *of_misc_get(struct device_node *)
+{
+   return ERR_PTR(-ENODEV);
+}
+#endif
+EXPORT_SYMBOL(of_misc_get);
+
 static int __init misc_init(void)
 {
int err;
diff --git a/include/linux/miscdevice.h b/include/linux/miscdevice.h
index 5430374..a4b605c 100644
--- a/include/linux/miscdevice.h
+++ b/include/linux/miscdevice.h
@@ -53,6 +53,7 @@
 #define MISC_DYNAMIC_MINOR 255
 
 struct device;
+struct device_node;
 struct attribute_group;
 
 struct miscdevice  {
@@ -70,6 +71,8 @@ struct miscdevice  {
 extern int misc_register(struct miscdevice *misc);
 extern void misc_deregister(struct miscdevice *misc);
 
+extern struct miscdevice *of_misc_get(struct device_node *node);
+
 #define MODULE_ALIAS_MISCDEV(minor)\
MODULE_ALIAS("char-major-" __stringify(MISC_MAJOR)  \
"-" __stringify(minor))
-- 
2.7.4

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


[RFC 2/2] staging: android: ion: Add of_ion_device_get function

2016-03-22 Thread Moritz Fischer
Allows to obtain a reference to the global /dev/ion backing
struct ion_device via devicetree.

Signed-off-by: Moritz Fischer 
---
 drivers/staging/android/ion/ion.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/drivers/staging/android/ion/ion.c 
b/drivers/staging/android/ion/ion.c
index e237e9f..cea264e0 100644
--- a/drivers/staging/android/ion/ion.c
+++ b/drivers/staging/android/ion/ion.c
@@ -64,6 +64,16 @@ struct ion_device {
struct dentry *clients_debug_root;
 };
 
+struct ion_device *of_ion_device_get(struct device_node *node)
+{
+   struct miscdevice *mdev = of_misc_get(node);
+
+   if (IS_ERR(mdev))
+   return ERR_PTR(PTR_ERR(mdev));
+
+   return container_of(mdev, struct ion_device, dev);
+}
+
 /**
  * struct ion_client - a process/hw block local address space
  * @node:  node in the tree of all clients
-- 
2.7.4

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


Re: [RFC 0/2] staging: ion: of_ion_device_get

2016-03-22 Thread Laura Abbott

On 03/22/2016 03:33 PM, Moritz Fischer wrote:

Hi all,

probably I'm doing this all wrong. I'm playing around with a bunch of 
accelerators
and I need to share buffers between them. I have my heaps implemented as a
platform device and from what I understand I'll need a reference to the
struct ion_device in each of them.
I couldn't find a way to get to that via devicetree, though. I'll admit that 
hacking
up miscdevice is quite hacky, maybe I should add a foo_get_ion_device() to my
heap implementing platform device?
If someone can explain me how to correctly do that with what we currently have,
even better.

Cheers,

Moritz

Moritz Fischer (2):
   misc: Add of_get_misc get a reference from devicetree
   staging: android: ion: Add of_ion_device_get function

  drivers/char/misc.c   | 38 ++
  drivers/staging/android/ion/ion.c | 10 ++
  include/linux/miscdevice.h|  3 +++
  3 files changed, 51 insertions(+)



In the past what drivers have done is a foo_ion_client_create which has the 
reference
to the ion_device created from ion_device_create. Drivers then call the
foo_ion_client_create function.

Can you elaborate more on your sharing and allocation flow? This might suggest
another idea.

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


Re: [RFC 2/2] staging: android: ion: Add of_ion_device_get function

2016-03-22 Thread Moritz Fischer
Derp,

On Tue, Mar 22, 2016 at 3:33 PM, Moritz Fischer
 wrote:
> Allows to obtain a reference to the global /dev/ion backing
> struct ion_device via devicetree.
>
> Signed-off-by: Moritz Fischer 
> ---
>  drivers/staging/android/ion/ion.c | 10 ++
>  1 file changed, 10 insertions(+)
>
> diff --git a/drivers/staging/android/ion/ion.c 
> b/drivers/staging/android/ion/ion.c
> index e237e9f..cea264e0 100644
> --- a/drivers/staging/android/ion/ion.c
> +++ b/drivers/staging/android/ion/ion.c
> @@ -64,6 +64,16 @@ struct ion_device {
> struct dentry *clients_debug_root;
>  };
>
> +struct ion_device *of_ion_device_get(struct device_node *node)
> +{
> +   struct miscdevice *mdev = of_misc_get(node);
> +
> +   if (IS_ERR(mdev))
> +   return ERR_PTR(PTR_ERR(mdev));
> +
> +   return container_of(mdev, struct ion_device, dev);
> +}
> +
>  /**
>   * struct ion_client - a process/hw block local address space
>   * @node:  node in the tree of all clients
> --
> 2.7.4
>

It's missing the header file ... if it's deemed useful at all I'll
clean up and resubmit.

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


  1   2   >