Re: [PATCH 8/8] staging: dgap: fix memory leak in dgap_parsefile()

2014-07-14 Thread Dan Carpenter
On Tue, Jul 15, 2014 at 12:05:14PM +0900, Daeseok Youn wrote:
> The p->u.board.status is allocated and set a string as
> "No" once within allocating a node of BNODE type.
> But it also set again with kstrdup() in case of "STATUS"
> or "ID". If it is not allocated yet, use kstrdup().
> If not, use just memcpy().

I don't think a 2 char buffer is always large enough to hold the new
strings.

Just free it and allocate again.

regards,
dan carpenter

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


Re: [PATCH 6/8] staging: dgap: remove unneeded dgap_err()

2014-07-14 Thread Dan Carpenter
On Tue, Jul 15, 2014 at 12:02:23PM +0900, Daeseok Youn wrote:
> The dgap_err() is printing a message with pr_err(),
> so all those are replaced.
> 

Take a look at how pr_fmt works.

#define pr_fmt(fmt) "dgap: " fmt

Then you can remove the "dgap: " from the beginning of each line.

Also all the "out of memory" messages can be removed because the kernel
prints its own message for that.

regards,
dan carpenter

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


Re: [PATCH 7/8] staging: dgap: introduce dgap_cleanup_nodes()

2014-07-14 Thread Dan Carpenter
On Tue, Jul 15, 2014 at 12:04:02PM +0900, Daeseok Youn wrote:
> When a configration file is parsed with dgap_parsefile(),
> makes nodes for saving configrations for board.
> 
> Making a node will allocate node memory and strings for saving
> configrations with kstrdup().
> 
> So these are freed when dgap is unloaded or failed to initialize.
> 
> Signed-off-by: Daeseok Youn 
> ---
> It MUST be needed to prevent memory leaks but
> I'm not sure that I fix properly.
> 
> Please review.

This thread doesn't have Mark on the CC list and he's the only person
who can actually test it properly.  Resend it and CC Mark
Hounschell .

regards,
dan carpenter

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


Re: [PATCH v4] staging: android: Clean up else statement from binder_send_failed_reply

2014-07-14 Thread Dan Carpenter
On Mon, Jul 14, 2014 at 04:38:43PM -0300, Lucas Tanure wrote:
> Hi,
> 
> This patch got accepted ?
>

It looks ok.  You will get an automated email when the patch is merged
into Greg's tree.  It can take 2 weeks or longer depending on merge
window timing or Greg's travel schedule.

Anyway, your patch is not lost.  Email again in 2 weeks if you haven't
heard anything.

regards,
dan carpenter

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


Re: [BISECTED][REGRESSION] Loading Hyper-V network drivers is racy in 3.14+ on Hyper-V 2012 R2

2014-07-14 Thread Sitsofe Wheeler
On Mon, Jul 14, 2014 at 10:39:48PM +, Haiyang Zhang wrote:
> > -Original Message-
> > From: Sitsofe Wheeler [mailto:sits...@gmail.com]
> > Sent: Monday, July 14, 2014 5:31 PM
> > To: Haiyang Zhang
> > Cc: KY Srinivasan; David S. Miller; de...@linuxdriverproject.org; linux-
> > ker...@vger.kernel.org; net...@vger.kernel.org
> > Subject: Re: [BISECTED][REGRESSION] Loading Hyper-V network drivers is
> > racy in 3.14+ on Hyper-V 2012 R2
> 
> Thanks for the tests! I will make a patch that can automatically retry
> smaller memory allocs when memory is insufficient.

This concerns me a bit - why would there be insufficient memory on a 64
bit VM with 4 GBytes of RAM just after startup (presumably the host's
memory isn't the issue)? Additionally, while things might fail just when
things are starting up, doing ifup eth0 at some point later succeeds so
whatever issue it had seems temporary.

Perhaps it would be wise to adding some debugging output to see if the
allocation really failed and why...

-- 
Sitsofe | http://sucs.org/~sits/
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 2/2] staging: comedi: addi_apci_1564: use addi_watchdog module to init watchdog subdevice

2014-07-14 Thread Chase Southwood
On Mon, Jul 14, 2014 at 4:22 AM, Ian Abbott  wrote:
> On 2014-07-12 23:44, Chase Southwood wrote:
>>
>> Use the addi_watchdog module to provide support for the watchdog
>> subdevice.
>>
>> Also, rearrange the subdevice init blocks so that the order makes sense.
>> Digital input/output subdevices and subdevices for DI/DO interrupt
>> support, followed by timer/counter/watchdog subdevices is the new order.
>>
>> Signed-off-by: Chase Southwood 
>> Cc: Ian Abbott 
>> Cc: H Hartley Sweeten 
>> ---
>>   drivers/staging/comedi/drivers/addi_apci_1564.c | 34
>> +++--
>>   1 file changed, 20 insertions(+), 14 deletions(-)
>
>
> I don't think the subdevice order matters that much, and I prefer to keep
> them stable, but since this driver is in such a state of flux, it doesn't
> really matter.
>

Hi Ian!
Quick question here about this.  First off, duly noted that grouping
subdevices by function isn't necessary and I won't shuffle them around
like this in the future.  Second, the reason I stuck the watchdog at
the end is because it causes an early return if addi_watchdog_init()
returns an error and it seemed  appropriate at the end so it doesn't
prevent the initialization of any other subdevices if that call should
fail.  Now I realize that it is very unlikely that that call fails,
but in any case should I put future subdevice inits above the watchdog
for the same reason (so they aren't at risk of not getting
initialized), or does that count for subdevice order not being stable
and you would prefer them all to go at the end?

Thanks,
Chase

> Reviewed-by: Ian Abbott 
>
> --
> -=( Ian Abbott @ MEV Ltd.E-mail: )=-
> -=( Tel: +44 (0)161 477 1898   FAX: +44 (0)161 718 3587 )=-
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: rtl8192ee: Fix setting highest n rate

2014-07-14 Thread Larry Finger
Commit 4fb6a37c3f94c1cb4b828bfcc4347771e1628f88 by Andrey Utkin
 and entitled "staging: rtl8192ee:
"Correct bitmask in comparsion" fixed what appeared to be a typo. After
consultation with the Realtek engineers, merely testing for a 2T2R device
is sufficient to ensure that the TX MCS map will equal 0x0c, thus the second
test can be ignored.

Signed-off-by: Larry Finger 
---
 drivers/staging/rtl8192ee/base.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/rtl8192ee/base.c b/drivers/staging/rtl8192ee/base.c
index 71ed12e..b8b897a 100644
--- a/drivers/staging/rtl8192ee/base.c
+++ b/drivers/staging/rtl8192ee/base.c
@@ -826,8 +826,7 @@ static u8 _rtl_get_vht_highest_n_rate(struct ieee80211_hw 
*hw,
u8 hw_rate;
u16 map = le16_to_cpu(sta->vht_cap.vht_mcs.tx_mcs_map);
 
-   if ((get_rf_type(rtlphy) == RF_2T2R) &&
-   (map & 0x000c) != 0x000c) {
+   if ((get_rf_type(rtlphy) == RF_2T2R) {
if ((map & 0x000c) >> 2 == IEEE80211_VHT_MCS_SUPPORT_0_7)
hw_rate =
rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS7];
-- 
1.8.4.5

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


Re: [PATCH v2] drivers: staging: lustre: Use 'force_die' instead of 'die' to avoid compiling issue

2014-07-14 Thread Chen Gang

在 2014年7月15日,上午9:40,Greg Kroah-Hartman  写道:

> On Mon, Jul 14, 2014 at 08:04:15PM +0800, Chen Gang wrote:
>> 
>> For drivers/staging/lustre/lustre/include/lustre_sec.h:391:
>> 
>> - staging tree: use '\t   ' between 'die' and '('.
>> 
>> - linux-next tree: use '   ' between 'die' and '('.
>> 
>> So the patch made under linux-next tree, can not apply to staging-next
>> or staging tree.
> 
> It seems to work just fine here, I don't see a problem...
> 


Yeah, the latest linux-next tree also uses ‘\t   “,  but the previous one not. 
:-)

Thanks.
—
Chen Gang
Open, share, and attitude like air, water, and life which God blessed
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: android: Clean up else statement from sync_fence_poll()

2014-07-14 Thread Lucas Tanure
Kernel coding style. Remove useless else statement after return.

Signed-off-by: Lucas Tanure 
---
 drivers/staging/android/sync.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index c9a0c2c..e7b2e02 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -555,8 +555,7 @@ static unsigned int sync_fence_poll(struct file *file, 
poll_table *wait)
return POLLIN;
else if (status < 0)
return POLLERR;
-   else
-   return 0;
+   return 0;
 }
 
 static long sync_fence_ioctl_wait(struct sync_fence *fence, unsigned long arg)
-- 
2.0.1

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


[PATCH 93/93] Staging: comedi: adl_pci9118: fixed style issues

2014-07-14 Thread sam-the-6
From: Sam Asadi 

several style issues fixed.

Signed-off-by: Sam Asadi 

modified:   drivers/staging/comedi/drivers/adl_pci9118.c
---
 drivers/staging/comedi/drivers/adl_pci9118.c |  124 +-
 1 file changed, 62 insertions(+), 62 deletions(-)

diff --git a/drivers/staging/comedi/drivers/adl_pci9118.c 
b/drivers/staging/comedi/drivers/adl_pci9118.c
index 59a65cb..7139f87 100644
--- a/drivers/staging/comedi/drivers/adl_pci9118.c
+++ b/drivers/staging/comedi/drivers/adl_pci9118.c
@@ -8,59 +8,63 @@
  * Author: Michal Dobes 
  *
 */
-/*
-Driver: adl_pci9118
-Description: Adlink PCI-9118DG, PCI-9118HG, PCI-9118HR
-Author: Michal Dobes 
-Devices: [ADLink] PCI-9118DG (pci9118dg), PCI-9118HG (pci9118hg),
-  PCI-9118HR (pci9118hr)
-Status: works
-
-This driver supports AI, AO, DI and DO subdevices.
-AI subdevice supports cmd and insn interface,
-other subdevices support only insn interface.
-For AI:
-- If cmd->scan_begin_src=TRIG_EXT then trigger input is TGIN (pin 46).
-- If cmd->convert_src=TRIG_EXT then trigger input is EXTTRG (pin 44).
-- If cmd->start_src/stop_src=TRIG_EXT then trigger input is TGIN (pin 46).
-- It is not necessary to have cmd.scan_end_arg=cmd.chanlist_len but
-  cmd.scan_end_arg modulo cmd.chanlist_len must by 0.
-- If return value of cmdtest is 5 then you've bad channel list
-  (it isn't possible mixture S.E. and DIFF inputs or bipolar and unipolar
-  ranges).
-
-There are some hardware limitations:
-a) You cann't use mixture of unipolar/bipoar ranges or differencial/single
-   ended inputs.
-b) DMA transfers must have the length aligned to two samples (32 bit),
-   so there is some problems if cmd->chanlist_len is odd. This driver tries
-   bypass this with adding one sample to the end of the every scan and discard
-   it on output but this cann't be used if cmd->scan_begin_src=TRIG_FOLLOW
-   and is used flag TRIG_WAKE_EOS, then driver switch to interrupt driven mode
-   with interrupt after every sample.
-c) If isn't used DMA then you can use only mode where
-   cmd->scan_begin_src=TRIG_FOLLOW.
-
-Configuration options:
-  [0] - PCI bus of device (optional)
-  [1] - PCI slot of device (optional)
-   If bus/slot is not specified, then first available PCI
-   card will be used.
-  [2] - 0= standard 8 DIFF/16 SE channels configuration
-   n = external multiplexer connected, 1 <= n <= 256
-  [3] - 0=autoselect DMA or EOC interrupts operation
-   1 = disable DMA mode
-   3 = disable DMA and INT, only insn interface will work
-  [4] - sample&hold signal - card can generate signal for external S&H board
-   0 = use SSHO(pin 45) signal is generated in onboard hardware S&H logic
-   0 != use ADCHN7(pin 23) signal is generated from driver, number say how
-   long delay is requested in ns and sign polarity of the hold
-   (in this case external multiplexor can serve only 128 channels)
-  [5] - 0=stop measure on all hardware errors
-   2 | = ignore ADOR - A/D Overrun status
-   8|=ignore Bover - A/D Burst Mode Overrun status
-   256|=ignore nFull - A/D FIFO Full status
 
+/*
+ Driver: adl_pci9118
+ Description: Adlink PCI-9118DG, PCI-9118HG, PCI-9118HR
+ Author: Michal Dobes 
+ Devices: [ADLink] PCI-9118DG (pci9118dg), PCI-9118HG (pci9118hg),
+ PCI-9118HR (pci9118hr)
+ Status: works
+
+ This driver supports AI, AO, DI and DO subdevices.
+ AI subdevice supports cmd and insn interface,
+ other subdevices support only insn interface.
+ For AI:
+ - If cmd->scan_begin_src=TRIG_EXT then trigger input is TGIN (pin 46).
+ - If cmd->convert_src=TRIG_EXT then trigger input is EXTTRG (pin 44).
+ - If cmd->start_src/stop_src=TRIG_EXT then trigger input is TGIN (pin 46).
+ - It is not necessary to have cmd.scan_end_arg=cmd.chanlist_len but
+   cmd.scan_end_arg modulo cmd.chanlist_len must by 0.
+ - If return value of cmdtest is 5 then you've bad channel list
+   (it isn't possible mixture S.E. and DIFF inputs or bipolar and unipolar
+   ranges).
+
+ There are some hardware limitations:
+ a) You cann't use mixture of unipolar/bipoar ranges or differencial/single
+   ended inputs.
+ b) DMA transfers must have the length aligned to two samples (32 bit),
+   so there is some problems if cmd->chanlist_len is odd. This driver
+   tries bypass this with adding one sample to the end of the every scan
+   and discard it on output but this cann't be used if
+   cmd->scan_begin_src=TRIG_FOLLOW and is used flag TRIG_WAKE_EOS, then
+   driver switch to interrupt driven mode with interrupt after every
+   sample.
+ c) If isn't used DMA then you can use only mode where
+   cmd->scan_begin_src=TRIG_FOLLOW.
+
+ Configuration options:
+   [0] - PCI bus of device (optional)
+   [1] - PCI slot of device (optional)
+If bus/slot is not specified, then first available PCI
+card will be used

[PATCH 92/93] Staging: comedi: 8255: fixed by adding an empthy line

2014-07-14 Thread sam-the-6
From: Sam Asadi 

fixed a coding style issue.

Signed-off-by: Sam Asadi 
modified:   drivers/staging/comedi/drivers/8255.c
---
 drivers/staging/comedi/drivers/8255.c |  150 -
 1 file changed, 74 insertions(+), 76 deletions(-)

diff --git a/drivers/staging/comedi/drivers/8255.c 
b/drivers/staging/comedi/drivers/8255.c
index 46113a3..de273c7 100644
--- a/drivers/staging/comedi/drivers/8255.c
+++ b/drivers/staging/comedi/drivers/8255.c
@@ -1,77 +1,73 @@
 /*
-comedi/drivers/8255.c
-Driver for 8255
-
-COMEDI - Linux Control and Measurement Device Interface
-Copyright (C) 1998 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.
+   comedi/drivers/8255.c
+   Driver for 8255
+
+   COMEDI - Linux Control and Measurement Device Interface
+   Copyright (C) 1998 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.
+
+   Driver: 8255
+   Description: generic 8255 support
+   Devices: [standard] 8255 (8255)
+   Author: ds
+   Status: works
+   Updated: Fri,  7 Jun 2002 12:56:45 -0700
+
+   The classic in digital I/O.  The 8255 appears in Comedi as a single
+   digital I/O subdevice with 24 channels.  The channel 0 corresponds
+   to the 8255's port A, bit 0; channel 23 corresponds to port C, bit
+   7.  Direction configuration is done in blocks, with channels 0-7,
+   8-15, 16-19, and 20-23 making up the 4 blocks.  The only 8255 mode
+   supported is mode 0.
+
+   You should enable compilation this driver if you plan to use a board
+   that has an 8255 chip.  For multifunction boards, the main driver will
+   configure the 8255 subdevice automatically.
+
+   This driver also works independently with ISA and PCI cards that
+   directly map the 8255 registers to I/O ports, including cards with
+   multiple 8255 chips.  To configure the driver for such a card, the
+   option list should be a list of the I/O port bases for each of the
+   8255 chips.  For example,
+
+   comedi_config /dev/comedi0 8255 0x200,0x204,0x208,0x20c
+
+   Note that most PCI 8255 boards do NOT work with this driver, and
+   need a separate driver as a wrapper.  For those that do work, the
+   I/O port base address can be found in the output of 'lspci -v'.
+
+   This file contains an exported subdevice for driving an 8255.
+
+   To use this subdevice as part of another driver, you need to
+   set up the subdevice in the attach function of the driver by
+   calling:
+
+   subdev_8255_init(device, subdevice, io_function, iobase)
+
+   device and subdevice are pointers to the device and subdevice
+   structures.  io_function will be called to provide the
+   low-level input/output to the device, i.e., actual register
+   access.  io_function will be called with the value of iobase
+   as the last parameter.  If the 8255 device is mapped as 4
+   consecutive I/O ports, you can use NULL for io_function
+   and the I/O port base for iobase, and an internal function will
+   handle the register access.
+
+   In addition, if the main driver handles interrupts, you can
+   enable commands on the subdevice by calling subdev_8255_init_irq()
+   instead.  Then, when you get an interrupt that is likely to be
+   from the 8255, you should call subdev_8255_interrupt(), which
+   will copy the latched value to a Comedi buffer.
 */
-/*
-Driver: 8255
-Description: generic 8255 support
-Devices: [standard] 8255 (8255)
-Author: ds
-Status: works
-Updated: Fri,  7 Jun 2002 12:56:45 -0700
-
-The classic in digital I/O.  The 8255 appears in Comedi as a single
-digital I/O subdevice with 24 channels.  The channel 0 corresponds
-to the 8255's port A, bit 0; channel 23 corresponds to port C, bit
-7.  Direction configuration is done in blocks, with channels 0-7,
-8-15, 16-19, and 20-23 making up the 4 blocks.  The only 8255 mode
-supported is mode 0.
-
-You should enabl

[PATCH 91/93] Staging: comedi: 8253.h fixed by removing 'return' from generic func

2014-07-14 Thread sam-the-6
From: Sam Asadi 

Signed-off-by: Sam Asadi 

modified:   drivers/staging/comedi/drivers/8253.h
---
 drivers/staging/comedi/drivers/8253.h |3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/comedi/drivers/8253.h 
b/drivers/staging/comedi/drivers/8253.h
index 5829b46..f6b8607 100644
--- a/drivers/staging/comedi/drivers/8253.h
+++ b/drivers/staging/comedi/drivers/8253.h
@@ -55,7 +55,7 @@ static inline void i8253_cascade_ns_to_timer(int 
i8253_osc_base,
/* check for overflow */
divider > div1 && divider > div2 &&
divider * i8253_osc_base > divider &&
-   divider * i8253_osc_base > i8253_osc_base) {
+   divider * i8253_osc_base > i8253_osc_base)  {
return;
}
 
@@ -118,7 +118,6 @@ static inline void i8253_cascade_ns_to_timer(int 
i8253_osc_base,
/*  masking is done since counter maps zero to 0x1 */
*d1 = div1 & 0x;
*d2 = div2 & 0x;
-   return;
 }
 
 #ifndef CMDTEST
-- 
1.7.10.4

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


[PATCH 8/8] staging: dgap: fix memory leak in dgap_parsefile()

2014-07-14 Thread Daeseok Youn
The p->u.board.status is allocated and set a string as
"No" once within allocating a node of BNODE type.
But it also set again with kstrdup() in case of "STATUS"
or "ID". If it is not allocated yet, use kstrdup().
If not, use just memcpy().

Signed-off-by: Daeseok Youn 
---
 drivers/staging/dgap/dgap.c |   11 +--
 1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/dgap/dgap.c b/drivers/staging/dgap/dgap.c
index a207bd7..cedf4b3 100644
--- a/drivers/staging/dgap/dgap.c
+++ b/drivers/staging/dgap/dgap.c
@@ -6598,7 +6598,11 @@ static int dgap_parsefile(char **in)
pr_err("dgap: parse: unexpected end of file\n");
return -1;
}
-   p->u.board.status = kstrdup(s, GFP_KERNEL);
+
+   if (p->u.board.status)
+   memcpy(p->u.board.status, s, strlen(s) + 1);
+   else
+   p->u.board.status = kstrdup(s, GFP_KERNEL);
break;
 
case NPORTS:/* number of ports */
@@ -6648,7 +6652,10 @@ static int dgap_parsefile(char **in)
return -1;
}
 
-   p->u.board.status = kstrdup(s, GFP_KERNEL);
+   if (p->u.board.status)
+   memcpy(p->u.board.status, s, strlen(s) + 1);
+   else
+   p->u.board.status = kstrdup(s, GFP_KERNEL);
 
if (p->type == CNODE) {
p->u.conc.id = kstrdup(s, GFP_KERNEL);
-- 
1.7.1

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


[PATCH 7/8] staging: dgap: introduce dgap_cleanup_nodes()

2014-07-14 Thread Daeseok Youn
When a configration file is parsed with dgap_parsefile(),
makes nodes for saving configrations for board.

Making a node will allocate node memory and strings for saving
configrations with kstrdup().

So these are freed when dgap is unloaded or failed to initialize.

Signed-off-by: Daeseok Youn 
---
It MUST be needed to prevent memory leaks but
I'm not sure that I fix properly.

Please review.

 drivers/staging/dgap/dgap.c |   47 +++
 1 files changed, 47 insertions(+), 0 deletions(-)

diff --git a/drivers/staging/dgap/dgap.c b/drivers/staging/dgap/dgap.c
index 61baee1..a207bd7 100644
--- a/drivers/staging/dgap/dgap.c
+++ b/drivers/staging/dgap/dgap.c
@@ -200,6 +200,7 @@ static int dgap_test_fep(struct board_t *brd);
 static int dgap_tty_register_ports(struct board_t *brd);
 static int dgap_firmware_load(struct pci_dev *pdev, int card_type,
  struct board_t *brd);
+static void dgap_cleanup_nodes(void);
 
 static void dgap_cleanup_module(void);
 
@@ -618,6 +619,7 @@ unregister_tty:
 free_flipbuf:
dgap_free_flipbuf(brd);
 cleanup_brd:
+   dgap_cleanup_nodes();
dgap_release_remap(brd);
kfree(brd);
 
@@ -658,6 +660,8 @@ static void dgap_cleanup_module(void)
dgap_cleanup_board(dgap_board[i]);
}
 
+   dgap_cleanup_nodes();
+
if (dgap_numboards)
pci_unregister_driver(&dgap_driver);
 }
@@ -6322,6 +6326,49 @@ static void dgap_remove_tty_sysfs(struct device *c)
sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
 }
 
+static void dgap_cleanup_nodes(void)
+{
+   struct cnode *p;
+
+   p = &dgap_head;
+
+   while (p) {
+   struct cnode *tmp = p->next;
+
+   switch (p->type) {
+   case BNODE:
+   kfree(p->u.board.portstr);
+   kfree(p->u.board.addrstr);
+   kfree(p->u.board.pcibusstr);
+   kfree(p->u.board.pcislotstr);
+   kfree(p->u.board.method);
+   break;
+   case CNODE:
+   kfree(p->u.conc.id);
+   kfree(p->u.conc.connect);
+   break;
+   case MNODE:
+   kfree(p->u.module.id);
+   break;
+   case TNODE:
+   kfree(p->u.ttyname);
+   break;
+   case CUNODE:
+   kfree(p->u.cuname);
+   break;
+   case LNODE:
+   kfree(p->u.line.cable);
+   break;
+   case PNODE:
+   kfree(p->u.printname);
+   break;
+   }
+
+   kfree(p->u.board.status);
+   kfree(p);
+   p = tmp;
+   }
+}
 /*
  * Parse a configuration file read into memory as a string.
  */
-- 
1.7.1

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


[PATCH 6/8] staging: dgap: remove unneeded dgap_err()

2014-07-14 Thread Daeseok Youn
The dgap_err() is printing a message with pr_err(),
so all those are replaced.

Signed-off-by: Daeseok Youn 
---
 drivers/staging/dgap/dgap.c |  226 --
 1 files changed, 108 insertions(+), 118 deletions(-)

diff --git a/drivers/staging/dgap/dgap.c b/drivers/staging/dgap/dgap.c
index 06c55cb..61baee1 100644
--- a/drivers/staging/dgap/dgap.c
+++ b/drivers/staging/dgap/dgap.c
@@ -153,7 +153,6 @@ static void dgap_firmware_reset_port(struct channel_t *ch);
 static int dgap_gettok(char **in);
 static char *dgap_getword(char **in);
 static int dgap_checknode(struct cnode *p);
-static void dgap_err(char *s);
 
 /*
  * Function prototypes from dgap_sysfs.h
@@ -6343,7 +6342,7 @@ static int dgap_parsefile(char **in)
/* file must start with a BEGIN */
while ((rc = dgap_gettok(in)) != BEGIN) {
if (rc == 0) {
-   dgap_err("unexpected EOF");
+   pr_err("dgap: parse: unexpected EOF\n");
return -1;
}
}
@@ -6351,13 +6350,13 @@ static int dgap_parsefile(char **in)
for (; ;) {
rc = dgap_gettok(in);
if (rc == 0) {
-   dgap_err("unexpected EOF");
+   pr_err("dgap: parse: unexpected EOF\n");
return -1;
}
 
switch (rc) {
case BEGIN: /* should only be 1 begin */
-   dgap_err("unexpected config_begin\n");
+   pr_err("dgap: parse: unexpected config_begin\n");
return -1;
 
case END:
@@ -6369,7 +6368,7 @@ static int dgap_parsefile(char **in)
 
p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
if (!p->next) {
-   dgap_err("out of memory");
+   pr_err("dgap: parse: out of memory\n");
return -1;
}
p = p->next;
@@ -6383,7 +6382,7 @@ static int dgap_parsefile(char **in)
 
case APORT2_920P:   /* AccelePort_4 */
if (p->type != BNODE) {
-   dgap_err("unexpected Digi_2r_920 string");
+   pr_err("dgap: parse: unexpected Digi_2r_920 
string\n");
return -1;
}
p->u.board.type = APORT2_920P;
@@ -6392,7 +6391,7 @@ static int dgap_parsefile(char **in)
 
case APORT4_920P:   /* AccelePort_4 */
if (p->type != BNODE) {
-   dgap_err("unexpected Digi_4r_920 string");
+   pr_err("dgap: parse: unexpected Digi_4r_920 
string\n");
return -1;
}
p->u.board.type = APORT4_920P;
@@ -6401,7 +6400,7 @@ static int dgap_parsefile(char **in)
 
case APORT8_920P:   /* AccelePort_8 */
if (p->type != BNODE) {
-   dgap_err("unexpected Digi_8r_920 string");
+   pr_err("dgap: parse: unexpected Digi_8r_920 
string\n");
return -1;
}
p->u.board.type = APORT8_920P;
@@ -6410,7 +6409,7 @@ static int dgap_parsefile(char **in)
 
case PAPORT4:   /* AccelePort_4 PCI */
if (p->type != BNODE) {
-   dgap_err("unexpected Digi_4r(PCI) string");
+   pr_err("dgap: parse: unexpected Digi_4r(PCI) 
string\n");
return -1;
}
p->u.board.type = PAPORT4;
@@ -6419,7 +6418,7 @@ static int dgap_parsefile(char **in)
 
case PAPORT8:   /* AccelePort_8 PCI */
if (p->type != BNODE) {
-   dgap_err("unexpected Digi_8r string");
+   pr_err("dgap: parse: unexpected Digi_8r 
string\n");
return -1;
}
p->u.board.type = PAPORT8;
@@ -6428,7 +6427,7 @@ static int dgap_parsefile(char **in)
 
case PCX:   /* PCI C/X */
if (p->type != BNODE) {
-   dgap_err("unexpected Digi_C/X_(PCI) string");
+   pr_err("dgap: parse: unexpected Digi_C/X_(PCI) 
string\n");
return -1;
}
p->u.board.type = PCX;
@@ -6441,7 +6440,7 @@ static int dgap_parsefile(char **in)
 
case PEPC:  /* PCI EPC/X */
if (p->type != BNODE) {
-   dgap_err("unexpected \"D

[PATCH 5/8] staging: dgap: remove dgap_newnode()

2014-07-14 Thread Daeseok Youn
The dgap_newnode() is useless for creating new node.
So just use kzalloc and set a type in case statement.

Signed-off-by: Daeseok Youn 
---
 drivers/staging/dgap/dgap.c |  104 ++
 1 files changed, 74 insertions(+), 30 deletions(-)

diff --git a/drivers/staging/dgap/dgap.c b/drivers/staging/dgap/dgap.c
index 1e52092..06c55cb 100644
--- a/drivers/staging/dgap/dgap.c
+++ b/drivers/staging/dgap/dgap.c
@@ -152,7 +152,6 @@ static void dgap_firmware_reset_port(struct channel_t *ch);
  */
 static int dgap_gettok(char **in);
 static char *dgap_getword(char **in);
-static struct cnode *dgap_newnode(int t);
 static int dgap_checknode(struct cnode *p);
 static void dgap_err(char *s);
 
@@ -6367,13 +6366,15 @@ static int dgap_parsefile(char **in)
case BOARD: /* board info */
if (dgap_checknode(p))
return -1;
-   p->next = dgap_newnode(BNODE);
+
+   p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
if (!p->next) {
dgap_err("out of memory");
return -1;
}
p = p->next;
 
+   p->type = BNODE;
p->u.board.status = kstrdup("No", GFP_KERNEL);
line = conc = NULL;
brd = p;
@@ -6658,12 +6659,16 @@ static int dgap_parsefile(char **in)
case TTYN:  /* tty name prefix */
if (dgap_checknode(p))
return -1;
-   p->next = dgap_newnode(TNODE);
+
+   p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
if (!p->next) {
dgap_err("out of memory");
return -1;
}
+
p = p->next;
+   p->type = TNODE;
+
s = dgap_getword(in);
if (!s) {
dgap_err("unexpeced end of file");
@@ -6679,12 +6684,16 @@ static int dgap_parsefile(char **in)
case CU:/* cu name prefix */
if (dgap_checknode(p))
return -1;
-   p->next = dgap_newnode(CUNODE);
+
+   p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
if (!p->next) {
dgap_err("out of memory");
return -1;
}
+
p = p->next;
+   p->type = CUNODE;
+
s = dgap_getword(in);
if (!s) {
dgap_err("unexpeced end of file");
@@ -6709,12 +6718,15 @@ static int dgap_parsefile(char **in)
dgap_err("line not vaild for PC/em");
return -1;
}
-   p->next = dgap_newnode(LNODE);
+
+   p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
if (!p->next) {
dgap_err("out of memory");
return -1;
}
+
p = p->next;
+   p->type = LNODE;
conc = NULL;
line = p;
linecnt++;
@@ -6727,13 +6739,17 @@ static int dgap_parsefile(char **in)
dgap_err("must specify line info before 
concentrator");
return -1;
}
-   p->next = dgap_newnode(CNODE);
+
+   p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
if (!p->next) {
dgap_err("out of memory");
return -1;
}
+
p = p->next;
+   p->type = CNODE;
conc = p;
+
if (linecnt)
brd->u.board.conc2++;
else
@@ -6776,12 +6792,15 @@ static int dgap_parsefile(char **in)
return -1;
}
}
-   p->next = dgap_newnode(MNODE);
+
+   p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
if (!p->next) {
dgap_err("out of memory");
return -1;
}
p = p->next;
+   p->type = MNODE;
+
if (linecnt)
brd-

[PATCH 4/8] staging: dgap: remove unused a parameter in dgap_gettok()

2014-07-14 Thread Daeseok Youn
The "p" as parameter is unused.

Signed-off-by: Daeseok Youn 
---
 drivers/staging/dgap/dgap.c |8 
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/dgap/dgap.c b/drivers/staging/dgap/dgap.c
index 17514c8..1e52092 100644
--- a/drivers/staging/dgap/dgap.c
+++ b/drivers/staging/dgap/dgap.c
@@ -150,7 +150,7 @@ static void dgap_firmware_reset_port(struct channel_t *ch);
 /*
  * Function prototypes from dgap_parse.c.
  */
-static int dgap_gettok(char **in, struct cnode *p);
+static int dgap_gettok(char **in);
 static char *dgap_getword(char **in);
 static struct cnode *dgap_newnode(int t);
 static int dgap_checknode(struct cnode *p);
@@ -6342,7 +6342,7 @@ static int dgap_parsefile(char **in)
p = p->next;
 
/* file must start with a BEGIN */
-   while ((rc = dgap_gettok(in, p)) != BEGIN) {
+   while ((rc = dgap_gettok(in)) != BEGIN) {
if (rc == 0) {
dgap_err("unexpected EOF");
return -1;
@@ -6350,7 +6350,7 @@ static int dgap_parsefile(char **in)
}
 
for (; ;) {
-   rc = dgap_gettok(in, p);
+   rc = dgap_gettok(in);
if (rc == 0) {
dgap_err("unexpected EOF");
return -1;
@@ -7100,7 +7100,7 @@ static char *dgap_sindex(char *string, char *group)
 /*
  * Get a token from the input file; return 0 if end of file is reached
  */
-static int dgap_gettok(char **in, struct cnode *p)
+static int dgap_gettok(char **in)
 {
char *w;
struct toklist *t;
-- 
1.7.1

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


[PATCH 3/8] staging: dgap: fix a typo in dgap_gettok()

2014-07-14 Thread Daeseok Youn
The "boar" should be "board".

Signed-off-by: Daeseok Youn 
---
 drivers/staging/dgap/dgap.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/staging/dgap/dgap.c b/drivers/staging/dgap/dgap.c
index 470ae7b..17514c8 100644
--- a/drivers/staging/dgap/dgap.c
+++ b/drivers/staging/dgap/dgap.c
@@ -7105,7 +7105,7 @@ static int dgap_gettok(char **in, struct cnode *p)
char *w;
struct toklist *t;
 
-   if (strstr(dgap_cword, "boar")) {
+   if (strstr(dgap_cword, "board")) {
w = dgap_getword(in);
snprintf(dgap_cword, MAXCWORD, "%s", w);
for (t = dgap_tlist; t->token != 0; t++) {
-- 
1.7.1

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


[PATCH 2/8] staging: dgap: remove unused case value in dgap_parsefile()

2014-07-14 Thread Daeseok Youn
If rc is zero, this function will returns with an error and
cannot reach switch-case statement.

Signed-off-by: Daeseok Youn 
---
 drivers/staging/dgap/dgap.c |4 
 1 files changed, 0 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/dgap/dgap.c b/drivers/staging/dgap/dgap.c
index 10bd0f2..470ae7b 100644
--- a/drivers/staging/dgap/dgap.c
+++ b/drivers/staging/dgap/dgap.c
@@ -6357,10 +6357,6 @@ static int dgap_parsefile(char **in)
}
 
switch (rc) {
-   case 0:
-   dgap_err("unexpected end of file");
-   return -1;
-
case BEGIN: /* should only be 1 begin */
dgap_err("unexpected config_begin\n");
return -1;
-- 
1.7.1

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


[PATCH 1/8] staging: dgap: remove redundant error value check

2014-07-14 Thread Daeseok Youn
The retval in dgap_block_til_ready() is initialized to zero,
and if no error has occurred in this function, the retval has a zero.
So it doesn't need to check "retval" itself.

Signed-off-by: Daeseok Youn 
---
 drivers/staging/dgap/dgap.c |5 +
 1 files changed, 1 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/dgap/dgap.c b/drivers/staging/dgap/dgap.c
index 32988a8..10bd0f2 100644
--- a/drivers/staging/dgap/dgap.c
+++ b/drivers/staging/dgap/dgap.c
@@ -2181,10 +2181,7 @@ static int dgap_block_til_ready(struct tty_struct *tty, 
struct file *file,
 
spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
 
-   if (retval)
-   return retval;
-
-   return 0;
+   return retval;
 }
 
 /*
-- 
1.7.1

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


Re: [PATCH v2] drivers: staging: lustre: Use 'force_die' instead of 'die' to avoid compiling issue

2014-07-14 Thread Greg Kroah-Hartman
On Mon, Jul 14, 2014 at 08:04:15PM +0800, Chen Gang wrote:
> 
> For drivers/staging/lustre/lustre/include/lustre_sec.h:391:
> 
>  - staging tree: use '\t   ' between 'die' and '('.
> 
>  - linux-next tree: use '   ' between 'die' and '('.
> 
> So the patch made under linux-next tree, can not apply to staging-next
> or staging tree.

It seems to work just fine here, I don't see a problem...

thanks,

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


Re: [PATCH] drivers: Let several drivers depends on HAS_IOMEM for 'devm_ioremap_resource'

2014-07-14 Thread Chen Gang


On 07/15/2014 08:53 AM, Guenter Roeck wrote:
> On 07/14/2014 05:34 PM, Chen Gang wrote:
>> On 07/14/2014 05:22 PM, Chen Gang wrote:
>>>
>>> 在 2014年7月14日,下午4:57,Richard Weinberger  写道:
>>>
 Am 14.07.2014 10:48, schrieb Lars-Peter Clausen:
> On 07/14/2014 10:31 AM, Richard Weinberger wrote:
>> Am 13.07.2014 22:17, schrieb Greg Kroah-Hartman:
>>> On Sun, Jul 13, 2014 at 09:33:38PM +0200, Richard Weinberger wrote:
 Maybe we could add COMPILE_TEST to the version string too?
 Just to detect such kernels fast in user bug reports...
>>>
>>> What kind of bug report are you going to get?
>>
>> User manages to enable CONFIG_FOO by selecting COMPILE_TEST and
>> complains that it does not work. :)
>
> These drivers are typically drivers for some SoC peripheral and the
> device will simply physically not exist on a platform that does not
> provide HAS_IOMEM. This is not really any
> different from making the driver selectable via COMPILE_TEST for
> any other platform. To hit the issue you'd have to instantiate a
> device driver instance for a device that
> physically does not exist. This will always result in a failure.

 Okay, you have convinced me. :)

>>
>> After search the history patches, I found one related patch which made
>> by myself (when I am in Asianux):
>>
>>"https://lkml.org/lkml/2013/7/1/641";
>>
>> For me, it is a long discussion, and forced many members have to join
>> in. Please help check again.
>>
> 
> One thing you could try would be to return NULL (or where appropriate
> an error) in the #else case of CONFIG_HAS_IOMEM and CONFIG_HAS_IOPORT,
> ie dont take COMPILE_TEST into account at all. Obviously that means
> you won't be able to dump a warning message in the COMPILE_TEST
> case, but at least the code would compile. The rejection of above patch
> would make a good case for this approach.
> 

OK, thanks: at least, it can be improved.  But still welcome any other
opinions of another related members.

Thanks.
-- 
Chen Gang

Open, share, and attitude like air, water, and life which God blessed
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] drivers: Let several drivers depends on HAS_IOMEM for 'devm_ioremap_resource'

2014-07-14 Thread Guenter Roeck

On 07/14/2014 05:34 PM, Chen Gang wrote:

On 07/14/2014 05:22 PM, Chen Gang wrote:


在 2014年7月14日,下午4:57,Richard Weinberger  写道:


Am 14.07.2014 10:48, schrieb Lars-Peter Clausen:

On 07/14/2014 10:31 AM, Richard Weinberger wrote:

Am 13.07.2014 22:17, schrieb Greg Kroah-Hartman:

On Sun, Jul 13, 2014 at 09:33:38PM +0200, Richard Weinberger wrote:

Maybe we could add COMPILE_TEST to the version string too?
Just to detect such kernels fast in user bug reports...


What kind of bug report are you going to get?


User manages to enable CONFIG_FOO by selecting COMPILE_TEST and
complains that it does not work. :)


These drivers are typically drivers for some SoC peripheral and the device will 
simply physically not exist on a platform that does not provide HAS_IOMEM. This 
is not really any
different from making the driver selectable via COMPILE_TEST for any other 
platform. To hit the issue you'd have to instantiate a device driver instance 
for a device that
physically does not exist. This will always result in a failure.


Okay, you have convinced me. :)



After search the history patches, I found one related patch which made
by myself (when I am in Asianux):

   "https://lkml.org/lkml/2013/7/1/641";

For me, it is a long discussion, and forced many members have to join
in. Please help check again.



One thing you could try would be to return NULL (or where appropriate
an error) in the #else case of CONFIG_HAS_IOMEM and CONFIG_HAS_IOPORT,
ie dont take COMPILE_TEST into account at all. Obviously that means
you won't be able to dump a warning message in the COMPILE_TEST
case, but at least the code would compile. The rejection of above patch
would make a good case for this approach.

Guenter

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


Re: [PATCH] drivers: Let several drivers depends on HAS_IOMEM for 'devm_ioremap_resource'

2014-07-14 Thread Chen Gang
On 07/14/2014 05:22 PM, Chen Gang wrote:
> 
> 在 2014年7月14日,下午4:57,Richard Weinberger  写道:
> 
>> Am 14.07.2014 10:48, schrieb Lars-Peter Clausen:
>>> On 07/14/2014 10:31 AM, Richard Weinberger wrote:
 Am 13.07.2014 22:17, schrieb Greg Kroah-Hartman:
> On Sun, Jul 13, 2014 at 09:33:38PM +0200, Richard Weinberger wrote:
>> Maybe we could add COMPILE_TEST to the version string too?
>> Just to detect such kernels fast in user bug reports...
>
> What kind of bug report are you going to get?

 User manages to enable CONFIG_FOO by selecting COMPILE_TEST and
 complains that it does not work. :)
>>>
>>> These drivers are typically drivers for some SoC peripheral and the device 
>>> will simply physically not exist on a platform that does not provide 
>>> HAS_IOMEM. This is not really any
>>> different from making the driver selectable via COMPILE_TEST for any other 
>>> platform. To hit the issue you'd have to instantiate a device driver 
>>> instance for a device that
>>> physically does not exist. This will always result in a failure.
>>
>> Okay, you have convinced me. :)
>>

After search the history patches, I found one related patch which made
by myself (when I am in Asianux):

  "https://lkml.org/lkml/2013/7/1/641";

For me, it is a long discussion, and forced many members have to join
in. Please help check again.

Thanks.

> 
> OK, thank all of you, and I shall send the related patch for it. 
> 
> I will try to finish it within this week.
> 

-- 
Chen Gang

Open, share, and attitude like air, water, and life which God blessed
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] drivers: Let several drivers depends on HAS_IOMEM for 'devm_ioremap_resource'

2014-07-14 Thread Chen Gang
On 07/14/2014 05:22 PM, Chen Gang wrote:
> 
> 在 2014年7月14日,下午4:57,Richard Weinberger  写道:
> 
>> Am 14.07.2014 10:48, schrieb Lars-Peter Clausen:
>>> On 07/14/2014 10:31 AM, Richard Weinberger wrote:
 Am 13.07.2014 22:17, schrieb Greg Kroah-Hartman:
> On Sun, Jul 13, 2014 at 09:33:38PM +0200, Richard Weinberger wrote:
>> Maybe we could add COMPILE_TEST to the version string too?
>> Just to detect such kernels fast in user bug reports...
>
> What kind of bug report are you going to get?

 User manages to enable CONFIG_FOO by selecting COMPILE_TEST and
 complains that it does not work. :)
>>>
>>> These drivers are typically drivers for some SoC peripheral and the device 
>>> will simply physically not exist on a platform that does not provide 
>>> HAS_IOMEM. This is not really any
>>> different from making the driver selectable via COMPILE_TEST for any other 
>>> platform. To hit the issue you'd have to instantiate a device driver 
>>> instance for a device that
>>> physically does not exist. This will always result in a failure.
>>
>> Okay, you have convinced me. :)
>>

After search the history patches, I found one related patch which made
by myself (when I am in Asianux):

  "https://lkml.org/lkml/2013/7/1/641";

For me, it is a long discussion, and forced many members have to join
in. Please help check again.

Thanks.

> 
> OK, thank all of you, and I shall send the related patch for it. 
> 
> I will try to finish it within this week.
> 

-- 
Chen Gang

Open, share, and attitude like air, water, and life which God blessed
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 15/15] staging: comedi: ni_daq_700: update the comedi driver comment

2014-07-14 Thread H Hartley Sweeten
Update the comment block that comedilib uses to automatically
generate documentation so that it matches the drivers new
functionality.

Remove the Version information. The git history provides better
information.

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

diff --git a/drivers/staging/comedi/drivers/ni_daq_700.c 
b/drivers/staging/comedi/drivers/ni_daq_700.c
index 4ff3556..a321774 100644
--- a/drivers/staging/comedi/drivers/ni_daq_700.c
+++ b/drivers/staging/comedi/drivers/ni_daq_700.c
@@ -26,22 +26,44 @@
  * Status: works
  * Updated: Wed, 21 May 2014 12:07:20 +
  *
- * The daqcard-700 appears in Comedi as a  digital I/O subdevice (0) with
- * 16 channels and a analog input subdevice (1) with 16 single-ended channels
- * or 8 differential channels, and three input ranges.
+ * Configuration Options: not applicable, uses PCMCIA auto config
  *
- * Digital:  The channel 0 corresponds to the daqcard-700's output
- * port, bit 0; channel 8 corresponds to the input port, bit 0.
+ * The daqcard-700 appears in Comedi as a three subdevices:
  *
- * Digital direction configuration: channels 0-7 output, 8-15 input.
+ * Subdevice 0: Digital I/O - 16 channels (fixed direction)
+ * 
+ * Channels 0-7 are the output port 0-7 signals
+ * Channels 8-15 are the input port 0-7 signals
  *
- * Analog: The input  range is 0 to 4095 with a default of -10 to +10 volts.
- * Valid ranges:
- *   0 for -10 to 10V bipolar
- *   1 for -5 to 5V bipolar
- *   2 for -2.5 to 2.5V bipolar
+ * Subdevice 1: Analog Input - 16 single-ended / 8 differential channels
+ * -
+ * Input range is 0 - 4095 with programmable gain
+ * 0 for -10 to 10V bipolar (default)
+ * 1 for -5 to 5V bipolar
+ * 2 for -2.5 to 2.5V bipolar
  *
- * IRQ is assigned but not used.
+ * In differential mode, the channels are paired as:
+ * channels 0-7positive inputs
+ * channels 8-15   negative inputs
+ *
+ * Subdevice 2: Counter - 3 channels (8254 timer/counter)
+ * --
+ * Channel 0 is can be used for timed AI acquisitions, all three timers
+ * can also be used for general-purpose timing functions.
+ *
+ * The clock source for channel 0 is fixed to the internal 1MHz clock.
+ * Channel 1 can be configured to use the intenal 1MHz clock or an
+ * external clock. Channel 2 always uses an external clock source.
+ *
+ * Async command support (requires an IRQ assigned by the PCMCIA subsystem)
+ * 
+ * The Analog Input subdevice can do timed acquisitions using counter 0.
+ * Sample interval must be between 10 and 65535 ns. Acquisitions can also
+ * be triggered externally using the EXTCONV signal.
+ *
+ * All channels in the scan list must have the same range and aref. The
+ * channels must also be sequential and count down to 0 or the scan list
+ * must only have a single channel.
  *
  * Manuals:Register level: http://www.ni.com/pdf/manuals/340698.pdf
  * User Manual:http://www.ni.com/pdf/manuals/320676d.pdf
-- 
1.9.3

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


[PATCH 07/15] staging: comedi: ni_daq_700: tidy up the remaining register defines

2014-07-14 Thread H Hartley Sweeten
For aesthetics, rename these register defines to give them namespace
associated with the driver and define the bits in the registers.

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

diff --git a/drivers/staging/comedi/drivers/ni_daq_700.c 
b/drivers/staging/comedi/drivers/ni_daq_700.c
index 106fd51..bde5996 100644
--- a/drivers/staging/comedi/drivers/ni_daq_700.c
+++ b/drivers/staging/comedi/drivers/ni_daq_700.c
@@ -78,6 +78,9 @@
 #define DAQ700_STATUS2_REG 0x01
 #define DAQ700_STATUS2_OVERFLOW(1 << 1)
 #define DAQ700_STATUS2_OVERRUN (1 << 0)
+#define DAQ700_AI_CLR_REG  0x01
+#define DAQ700_AI_CLR_FIFO (0 << 0)
+#define DAQ700_AI_FIFO_REG 0x02/* 16-bit */
 #define DAQ700_DO_REG  0x04
 #define DAQ700_DI_REG  0x05
 #define DAQ700_CMD3_REG0x05
@@ -85,16 +88,13 @@
 #define DAQ700_CMD3_CLK1SRC(1 << 3)
 #define DAQ700_CMD3_DIFF   (1 << 2)
 #define DAQ700_CMD3_ARNG(x)((x) << 0)
+#define DAQ700_TIC_REG 0x06
+#define DAQ700_TIC_CLR_INT (0 << 0)
 #define DAQ700_CMD2_REG0x07
 #define DAQ700_CMD2_ENADAQ (0 << 1)
 #define DAQ700_CMD2_DISABDAQ   (1 << 1)
 #define DAQ700_TIMER_BASE  0x08
 
-/* daqcard700 registers */
-#define ADFIFO_R   0x02/* RO 16bit */
-#define ADCLEAR_R  0x01/* WO 8bit */
-#define TIC_R  0x06/* WO 8bit */
-
 static const struct comedi_lrange range_daq700_ai = {
3,
{
@@ -220,7 +220,7 @@ static int daq700_ai_rinsn(struct comedi_device *dev,
return ret;
 
/* read data */
-   d = inw(dev->iobase + ADFIFO_R);
+   d = inw(dev->iobase + DAQ700_AI_FIFO_REG);
/* mangle the data as necessary */
/* Bipolar Offset Binary: 0 to 4095 for -10 to +10 */
d &= 0x0fff;
@@ -252,9 +252,9 @@ static void daq700_ai_config(struct comedi_device *dev,
outb(DAQ700_CMD3_ARNG(0), iobase + DAQ700_CMD3_REG);
i8254_set_mode(iobase + DAQ700_TIMER_BASE, 0,
   0, I8254_MODE1 | I8254_BINARY);  /* OUT0 high */
-   outb(0x00, iobase + TIC_R); /* clear counter interrupt */
-   outb(0x00, iobase + ADCLEAR_R); /* clear the ADC FIFO */
-   inw(iobase + ADFIFO_R); /* read 16bit junk from FIFO to clear */
+   outb(DAQ700_TIC_CLR_INT, iobase + DAQ700_TIC_REG);
+   outb(DAQ700_AI_CLR_FIFO, iobase + DAQ700_AI_CLR_REG);
+   inw(iobase + DAQ700_AI_FIFO_REG);
 }
 
 static int daq700_auto_attach(struct comedi_device *dev,
-- 
1.9.3

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


[PATCH 13/15] staging: comedi: ni_daq_700: add ai async command support

2014-07-14 Thread H Hartley Sweeten
Add support for async commands with the Analog Input subdevice.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/Kconfig  |   1 +
 drivers/staging/comedi/drivers/ni_daq_700.c | 401 ++--
 2 files changed, 385 insertions(+), 17 deletions(-)

diff --git a/drivers/staging/comedi/Kconfig b/drivers/staging/comedi/Kconfig
index 341fc07..5523d14 100644
--- a/drivers/staging/comedi/Kconfig
+++ b/drivers/staging/comedi/Kconfig
@@ -1144,6 +1144,7 @@ config COMEDI_DAS08_CS
 
 config COMEDI_NI_DAQ_700_CS
tristate "NI DAQCard-700 PCMCIA support"
+   select COMEDI_FC
---help---
  Enable support for the National Instruments PCMCIA DAQCard-700 DIO
 
diff --git a/drivers/staging/comedi/drivers/ni_daq_700.c 
b/drivers/staging/comedi/drivers/ni_daq_700.c
index 2a474b0..e1e7ba7 100644
--- a/drivers/staging/comedi/drivers/ni_daq_700.c
+++ b/drivers/staging/comedi/drivers/ni_daq_700.c
@@ -56,6 +56,7 @@
 
 #include "../comedidev.h"
 
+#include "comedi_fc.h"
 #include "8253.h"
 
 /*
@@ -95,6 +96,8 @@
 #define DAQ700_CMD2_DISABDAQ   (1 << 1)
 #define DAQ700_TIMER_BASE  0x08
 
+#define DAQ700_FIFO_SIZE   512 /* samples */
+
 static const struct comedi_lrange range_daq700_ai = {
3,
{
@@ -104,6 +107,14 @@ static const struct comedi_lrange range_daq700_ai = {
}
 };
 
+struct daq700_private {
+   unsigned int divisor;
+   unsigned int scans_done;
+   unsigned int samples_left;
+   unsigned char cmd1;
+   unsigned char cmd3;
+};
+
 static int daq700_dio_insn_bits(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn,
@@ -151,8 +162,10 @@ static int daq700_dio_insn_config(struct comedi_device 
*dev,
 }
 
 static void daq700_ai_set_chanspec(struct comedi_device *dev,
-  unsigned int chanspec)
+  unsigned int chanspec,
+  bool scan)
 {
+   struct daq700_private *devpriv = dev->private;
unsigned int chan = CR_CHAN(chanspec);
unsigned int range = CR_RANGE(chanspec);
unsigned int aref = CR_AREF(chanspec);
@@ -164,13 +177,25 @@ static void daq700_ai_set_chanspec(struct comedi_device 
*dev,
val = DAQ700_CMD3_ARNG(range);
if (aref == AREF_DIFF)
val |= DAQ700_CMD3_DIFF;
-   outb(val, dev->iobase + DAQ700_CMD3_REG);
+   if (val != devpriv->cmd3) {
+   outb(val, dev->iobase + DAQ700_CMD3_REG);
+   devpriv->cmd3 = val;
+   }
 
/* set multiplexer for single-channel scan */
-   outb(DAQ700_CMD1_SCANDISAB | DAQ700_CMD1_MA(chan),
-dev->iobase + DAQ700_CMD1_REG);
-   /* mux needs 2us to really settle [Fred Brooks]. */
-   udelay(2);
+   val = DAQ700_CMD1_SCANDISAB | DAQ700_CMD1_MA(chan);
+   if (val != devpriv->cmd1) {
+   outb(val, dev->iobase + DAQ700_CMD1_REG);
+   devpriv->cmd1 = val;
+   /* mux needs 2us to really settle [Fred Brooks] */
+   udelay(2);
+   }
+
+   /* enable multi-channel scanning */
+   if (scan) {
+   devpriv->cmd1 &= ~DAQ700_CMD1_SCANDISAB;
+   outb(devpriv->cmd1, dev->iobase + DAQ700_CMD1_REG);
+   }
 }
 
 static void daq700_ai_start_conv(struct comedi_device *dev)
@@ -185,6 +210,15 @@ static void daq700_ai_start_conv(struct comedi_device *dev)
   0, I8254_MODE2 | I8254_BINARY);  /* OUT0 high */
 }
 
+static void daq700_ai_stop_conv(struct comedi_device *dev)
+{
+   /*
+* Stop A/D conversions by forcing OUT0 high.
+*/
+   i8254_set_mode(dev->iobase + DAQ700_TIMER_BASE, 0,
+  0, I8254_MODE2 | I8254_BINARY);  /* OUT0 high */
+}
+
 static void daq700_ai_flush_fifo(struct comedi_device *dev)
 {
outb(DAQ700_AI_CLR_FIFO, dev->iobase + DAQ700_AI_CLR_REG);
@@ -222,7 +256,7 @@ static int daq700_ai_insn_read(struct comedi_device *dev,
int ret;
int i;
 
-   daq700_ai_set_chanspec(dev, insn->chanspec);
+   daq700_ai_set_chanspec(dev, insn->chanspec, false);
 
for (i = 0; i < insn->n; i++) {
daq700_ai_start_conv(dev);
@@ -241,6 +275,320 @@ static int daq700_ai_insn_read(struct comedi_device *dev,
return insn->n;
 }
 
+static bool daq700_interrupts_enabled(struct comedi_device *dev)
+{
+   struct daq700_private *devpriv = dev->private;
+
+   if (devpriv->cmd1 & (DAQ700_CMD1_CNTINTEN |
+DAQ700_CMD1_EXTINTEN |
+DAQ700_CMD1_FIFOINTEN))
+   return true;
+   else
+   return false;
+}
+
+static void daq700_ai_read_fifo(struct comedi_device *dev,
+   struct comedi_subdevice *s)
+{
+   struct daq700_private *

[PATCH 05/15] staging: comedi: ni_daq_700: tidy up the command register defines

2014-07-14 Thread H Hartley Sweeten
For aesthetics, rename these register defines to give them namespace
associated with the driver and define the bits in the registers.

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

diff --git a/drivers/staging/comedi/drivers/ni_daq_700.c 
b/drivers/staging/comedi/drivers/ni_daq_700.c
index 1798b47..3ba4da6 100644
--- a/drivers/staging/comedi/drivers/ni_daq_700.c
+++ b/drivers/staging/comedi/drivers/ni_daq_700.c
@@ -61,21 +61,31 @@
 /*
  * Regsiter I/O map
  */
+#define DAQ700_CMD1_REG0x00
+#define DAQ700_CMD1_SCANEN (0 << 7)
+#define DAQ700_CMD1_SCANDISAB  (1 << 7)
+#define DAQ700_CMD1_CNTINTEN   (1 << 6)
+#define DAQ700_CMD1_EXTINTEN   (1 << 5)
+#define DAQ700_CMD1_FIFOINTEN  (1 << 4)
+#define DAQ700_CMD1_MA(x)  ((x) << 0)
 #define DAQ700_DO_REG  0x04
 #define DAQ700_DI_REG  0x05
+#define DAQ700_CMD3_REG0x05
+#define DAQ700_CMD3_FIFOHFINT  (1 << 5)
+#define DAQ700_CMD3_CLK1SRC(1 << 3)
+#define DAQ700_CMD3_DIFF   (1 << 2)
+#define DAQ700_CMD3_ARNG(x)((x) << 0)
+#define DAQ700_CMD2_REG0x07
+#define DAQ700_CMD2_ENADAQ (0 << 1)
+#define DAQ700_CMD2_DISABDAQ   (1 << 1)
 #define DAQ700_TIMER_BASE  0x08
 
 /* daqcard700 registers */
-#define CMD_R1 0x00/* WO 8bit */
-#define CMD_R2 0x07/* RW 8bit */
-#define CMD_R3 0x05/* W0 8bit */
 #define STA_R1 0x00/* RO 8bit */
 #define STA_R2 0x01/* RO 8bit */
 #define ADFIFO_R   0x02/* RO 16bit */
 #define ADCLEAR_R  0x01/* WO 8bit */
 #define TIC_R  0x06/* WO 8bit */
-/* daqcard700 modes */
-#define CMD_R3_DIFF 0x04/* diff mode */
 
 static const struct comedi_lrange range_daq700_ai = {
3,
@@ -176,15 +186,15 @@ static int daq700_ai_rinsn(struct comedi_device *dev,
 
/* set channel input modes */
if (aref == AREF_DIFF)
-   r3_bits |= CMD_R3_DIFF;
+   r3_bits |= DAQ700_CMD3_DIFF;
/* write channel mode/range */
if (range >= 1)
range++;/* convert range to hardware value */
-   outb(r3_bits | (range & 0x03), dev->iobase + CMD_R3);
+   outb(r3_bits | DAQ700_CMD3_ARNG(range), dev->iobase + DAQ700_CMD3_REG);
 
-   /* write channel to multiplexer */
-   /* set mask scan bit high to disable scanning */
-   outb(chan | 0x80, dev->iobase + CMD_R1);
+   /* set multiplexer for single-channel scan */
+   outb(DAQ700_CMD1_SCANDISAB | DAQ700_CMD1_MA(chan),
+dev->iobase + DAQ700_CMD1_REG);
/* mux needs 2us to really settle [Fred Brooks]. */
udelay(2);
 
@@ -224,9 +234,10 @@ static void daq700_ai_config(struct comedi_device *dev,
 {
unsigned long iobase = dev->iobase;
 
-   outb(0x80, iobase + CMD_R1);/* disable scanning, ADC to chan 0 */
-   outb(0x00, iobase + CMD_R2);/* clear all bits */
-   outb(0x00, iobase + CMD_R3);/* set +-10 range */
+   outb(DAQ700_CMD1_SCANDISAB | DAQ700_CMD1_MA(0),
+iobase + DAQ700_CMD1_REG);
+   outb(DAQ700_CMD2_ENADAQ, iobase + DAQ700_CMD2_REG);
+   outb(DAQ700_CMD3_ARNG(0), iobase + DAQ700_CMD3_REG);
i8254_set_mode(iobase + DAQ700_TIMER_BASE, 0,
   0, I8254_MODE1 | I8254_BINARY);  /* OUT0 high */
outb(0x00, iobase + TIC_R); /* clear counter interrupt */
-- 
1.9.3

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


[PATCH 06/15] staging: comedi: ni_daq_700: tidy up the status register defines

2014-07-14 Thread H Hartley Sweeten
For aesthetics, rename these register defines to give them namespace
associated with the driver and define the bits in the registers.

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

diff --git a/drivers/staging/comedi/drivers/ni_daq_700.c 
b/drivers/staging/comedi/drivers/ni_daq_700.c
index 3ba4da6..106fd51 100644
--- a/drivers/staging/comedi/drivers/ni_daq_700.c
+++ b/drivers/staging/comedi/drivers/ni_daq_700.c
@@ -68,6 +68,16 @@
 #define DAQ700_CMD1_EXTINTEN   (1 << 5)
 #define DAQ700_CMD1_FIFOINTEN  (1 << 4)
 #define DAQ700_CMD1_MA(x)  ((x) << 0)
+#define DAQ700_STATUS1_REG 0x00
+#define DAQ700_STATUS1_FIFOHF  (1 << 6)
+#define DAQ700_STATUS1_CONVPROG(1 << 4)
+#define DAQ700_STATUS1_EXTINT  (1 << 3)
+#define DAQ700_STATUS1_CNTINT  (1 << 2)
+#define DAQ700_STATUS1_DATAERR (1 << 1)
+#define DAQ700_STATUS1_DAVAIL  (1 << 0)
+#define DAQ700_STATUS2_REG 0x01
+#define DAQ700_STATUS2_OVERFLOW(1 << 1)
+#define DAQ700_STATUS2_OVERRUN (1 << 0)
 #define DAQ700_DO_REG  0x04
 #define DAQ700_DI_REG  0x05
 #define DAQ700_CMD3_REG0x05
@@ -81,8 +91,6 @@
 #define DAQ700_TIMER_BASE  0x08
 
 /* daqcard700 registers */
-#define STA_R1 0x00/* RO 8bit */
-#define STA_R2 0x01/* RO 8bit */
 #define ADFIFO_R   0x02/* RO 16bit */
 #define ADCLEAR_R  0x01/* WO 8bit */
 #define TIC_R  0x06/* WO 8bit */
@@ -161,14 +169,18 @@ static int daq700_ai_eoc(struct comedi_device *dev,
 {
unsigned int status;
 
-   status = inb(dev->iobase + STA_R2);
-   if ((status & 0x03))
+   status = inb(dev->iobase + DAQ700_STATUS2_REG);
+   if (status & (DAQ700_STATUS2_OVERFLOW | DAQ700_STATUS2_OVERRUN))
return -EOVERFLOW;
-   status = inb(dev->iobase + STA_R1);
-   if ((status & 0x02))
+
+   status = inb(dev->iobase + DAQ700_STATUS1_REG);
+   if (status & DAQ700_STATUS1_DATAERR)
return -ENODATA;
-   if ((status & 0x11) == 0x01)
+
+   status &= (DAQ700_STATUS1_CONVPROG | DAQ700_STATUS1_DAVAIL);
+   if (status == DAQ700_STATUS1_DAVAIL)
return 0;
+
return -EBUSY;
 }
 
-- 
1.9.3

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


[PATCH 09/15] staging: comedi: ni_daq_700: tidy up daq700_ai_rinsn()

2014-07-14 Thread H Hartley Sweeten
For aesthetics, rename this function to follow the norm for (*insn_read)
operations.

Refactor the code to use a common local variable to set the channel
mode/range and read the A/D samples.

Use the comedi_offset_munge() helper to munge the 2's complement values
from the hardware to the offset binary values that the comedi core uses.

Change the final return to clarify that the return value is the number
of samples (insn->n).

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

diff --git a/drivers/staging/comedi/drivers/ni_daq_700.c 
b/drivers/staging/comedi/drivers/ni_daq_700.c
index 295b14a..ad6e404 100644
--- a/drivers/staging/comedi/drivers/ni_daq_700.c
+++ b/drivers/staging/comedi/drivers/ni_daq_700.c
@@ -190,25 +190,25 @@ static int daq700_ai_eoc(struct comedi_device *dev,
return -EBUSY;
 }
 
-static int daq700_ai_rinsn(struct comedi_device *dev,
-  struct comedi_subdevice *s,
-  struct comedi_insn *insn, unsigned int *data)
+static int daq700_ai_insn_read(struct comedi_device *dev,
+  struct comedi_subdevice *s,
+  struct comedi_insn *insn,
+  unsigned int *data)
 {
-   int n;
-   int d;
+   unsigned int chan = CR_CHAN(insn->chanspec);
+   unsigned int range = CR_RANGE(insn->chanspec);
+   unsigned int aref = CR_AREF(insn->chanspec);
+   unsigned int val;
int ret;
-   unsigned int chan   = CR_CHAN(insn->chanspec);
-   unsigned int aref   = CR_AREF(insn->chanspec);
-   unsigned int range  = CR_RANGE(insn->chanspec);
-   unsigned int r3_bits= 0;
+   int i;
 
-   /* set channel input modes */
-   if (aref == AREF_DIFF)
-   r3_bits |= DAQ700_CMD3_DIFF;
-   /* write channel mode/range */
+   /* set channel mode/range */
if (range >= 1)
-   range++;/* convert range to hardware value */
-   outb(r3_bits | DAQ700_CMD3_ARNG(range), dev->iobase + DAQ700_CMD3_REG);
+   range++;/* convert range to hardware value */
+   val = DAQ700_CMD3_ARNG(range);
+   if (aref == AREF_DIFF)
+   val |= DAQ700_CMD3_DIFF;
+   outb(val, dev->iobase + DAQ700_CMD3_REG);
 
/* set multiplexer for single-channel scan */
outb(DAQ700_CMD1_SCANDISAB | DAQ700_CMD1_MA(chan),
@@ -216,26 +216,21 @@ static int daq700_ai_rinsn(struct comedi_device *dev,
/* mux needs 2us to really settle [Fred Brooks]. */
udelay(2);
 
-   /* convert n samples */
-   for (n = 0; n < insn->n; n++) {
+   for (i = 0; i < insn->n; i++) {
daq700_ai_start_conv(dev);
 
-   /* wait for conversion to end */
ret = comedi_timeout(dev, s, insn, daq700_ai_eoc, 0);
if (ret) {
daq700_ai_flush_fifo(dev);
return ret;
}
 
-   /* read data */
-   d = inw(dev->iobase + DAQ700_AI_FIFO_REG);
-   /* mangle the data as necessary */
-   /* Bipolar Offset Binary: 0 to 4095 for -10 to +10 */
-   d &= 0x0fff;
-   d ^= 0x0800;
-   data[n] = d;
+   /* get sample and munge 2's complement value to offset binary */
+   val = inw(dev->iobase + DAQ700_AI_FIFO_REG);
+   data[i] = comedi_offset_munge(s, val);
}
-   return n;
+
+   return insn->n;
 }
 
 /*
@@ -299,7 +294,7 @@ static int daq700_auto_attach(struct comedi_device *dev,
s->n_chan = 16;
s->maxdata = (1 << 12) - 1;
s->range_table = &range_daq700_ai;
-   s->insn_read = daq700_ai_rinsn;
+   s->insn_read = daq700_ai_insn_read;
daq700_ai_config(dev, s);
 
return 0;
-- 
1.9.3

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


[PATCH 10/15] staging: comedi: ni_daq_700: tidy up daq700_ai_config()

2014-07-14 Thread H Hartley Sweeten
According to the programming manual, the writes in this function are
required to initialize the DAQCard-700 hardware. For aesthetics,
rename this function to clarify this.

Remove the unused comedi_subdevice parameter.

The programming manual also says that '0x34' should be written to the
counter mode register. Using the 8253.h helpers this would be I8254_MODE2.
Both mode 1 and mode 2 will set OUT0 high so there is no real difference.
But, to follow the manual, change the mode to I8254_MODE2.

For consistency, also change the mode in daq700_ai_start_conv().

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

diff --git a/drivers/staging/comedi/drivers/ni_daq_700.c 
b/drivers/staging/comedi/drivers/ni_daq_700.c
index ad6e404..0be7312 100644
--- a/drivers/staging/comedi/drivers/ni_daq_700.c
+++ b/drivers/staging/comedi/drivers/ni_daq_700.c
@@ -159,7 +159,7 @@ static void daq700_ai_start_conv(struct comedi_device *dev)
i8254_set_mode(dev->iobase + DAQ700_TIMER_BASE, 0,
   0, I8254_MODE0 | I8254_BINARY);  /* OUT0 low */
i8254_set_mode(dev->iobase + DAQ700_TIMER_BASE, 0,
-  0, I8254_MODE1 | I8254_BINARY);  /* OUT0 high */
+  0, I8254_MODE2 | I8254_BINARY);  /* OUT0 high */
 }
 
 static void daq700_ai_flush_fifo(struct comedi_device *dev)
@@ -244,8 +244,7 @@ static int daq700_ai_insn_read(struct comedi_device *dev,
  * The analog input circuitry is initialized to channel 0.
  * The A/D FIFO is cleared.
  */
-static void daq700_ai_config(struct comedi_device *dev,
-struct comedi_subdevice *s)
+static void daq700_initialize(struct comedi_device *dev)
 {
unsigned long iobase = dev->iobase;
 
@@ -254,7 +253,7 @@ static void daq700_ai_config(struct comedi_device *dev,
outb(DAQ700_CMD2_ENADAQ, iobase + DAQ700_CMD2_REG);
outb(DAQ700_CMD3_ARNG(0), iobase + DAQ700_CMD3_REG);
i8254_set_mode(iobase + DAQ700_TIMER_BASE, 0,
-  0, I8254_MODE1 | I8254_BINARY);  /* OUT0 high */
+  0, I8254_MODE2 | I8254_BINARY);  /* OUT0 high */
outb(DAQ700_TIC_CLR_INT, iobase + DAQ700_TIC_REG);
daq700_ai_flush_fifo(dev);
 }
@@ -295,7 +294,8 @@ static int daq700_auto_attach(struct comedi_device *dev,
s->maxdata = (1 << 12) - 1;
s->range_table = &range_daq700_ai;
s->insn_read = daq700_ai_insn_read;
-   daq700_ai_config(dev, s);
+
+   daq700_initialize(dev);
 
return 0;
 }
-- 
1.9.3

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


[PATCH 14/15] staging: comedi: ni_daq_700: add a counter subdevice

2014-07-14 Thread H Hartley Sweeten
The DAQ700Card has an 8254 counter/timer that provides 3 counters.
Counter 0 controls the onboard data acquisition timing, and all three
counters are available for general-purpose timing functions.

Add a subdevice to allow the user to use the counters.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/comedi.h |   9 ++
 drivers/staging/comedi/drivers/ni_daq_700.c | 125 +++-
 2 files changed, 133 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/comedi/comedi.h b/drivers/staging/comedi/comedi.h
index dbaeba7..c722748 100644
--- a/drivers/staging/comedi/comedi.h
+++ b/drivers/staging/comedi/comedi.h
@@ -987,4 +987,13 @@ enum ke_counter_clock_source {
KE_CLK_EXT  /* external clock on pin 21 of D-Sub */
 };
 
+/*
+ * Values for setting the counter 1 clock source with INSN_CONFIG_SET_CLOCK_SRC
+ * for the counter subdevice on the NI PCMCIA DAQCard-700 (ni_daq_700 driver).
+ */
+enum ni_daq700_counter_clock_source {
+   DAQ700_CLK_EXT, /* external CLK1 signal (default) */
+   DAQ700_CLK_1MHZ,/* internal 1MHz */
+};
+
 #endif /* _COMEDI_H */
diff --git a/drivers/staging/comedi/drivers/ni_daq_700.c 
b/drivers/staging/comedi/drivers/ni_daq_700.c
index e1e7ba7..4ff3556 100644
--- a/drivers/staging/comedi/drivers/ni_daq_700.c
+++ b/drivers/staging/comedi/drivers/ni_daq_700.c
@@ -589,6 +589,112 @@ static int daq700_ai_cmdtest(struct comedi_device *dev,
return 0;
 }
 
+static int daq700_counter_insn_read(struct comedi_device *dev,
+   struct comedi_subdevice *s,
+   struct comedi_insn *insn,
+   unsigned int *data)
+{
+   unsigned long timer_base = dev->iobase + DAQ700_TIMER_BASE;
+   unsigned int chan = CR_CHAN(insn->chanspec);
+   int i;
+
+   for (i = 0; i < insn->n; i++)
+   data[i] = i8254_read(timer_base, 0, chan);
+
+   return insn->n;
+}
+
+static int daq700_counter_insn_write(struct comedi_device *dev,
+struct comedi_subdevice *s,
+struct comedi_insn *insn,
+unsigned int *data)
+{
+   unsigned long timer_base = dev->iobase + DAQ700_TIMER_BASE;
+   unsigned int chan = CR_CHAN(insn->chanspec);
+
+   /* only write the final value to the counter */
+   if (insn->n)
+   i8254_write(timer_base, 0, chan, data[insn->n - 1]);
+
+   return insn->n;
+}
+
+static int daq700_counter_insn_config(struct comedi_device *dev,
+ struct comedi_subdevice *s,
+ struct comedi_insn *insn,
+ unsigned int *data)
+{
+   struct daq700_private *devpriv = dev->private;
+   unsigned long timer_base = dev->iobase + DAQ700_TIMER_BASE;
+   unsigned int chan = CR_CHAN(insn->chanspec);
+
+   switch (data[0]) {
+   case INSN_CONFIG_SET_CLOCK_SRC:
+   switch (chan) {
+   case 1:
+   switch (data[1]) {
+   case DAQ700_CLK_EXT:
+   /* CLK1 signal from I/O connector */
+   devpriv->cmd3 &= ~DAQ700_CMD3_CLK1SRC;
+   break;
+   case DAQ700_CLK_1MHZ:
+   /* CLK1 from internal 1MHz */
+   devpriv->cmd3 |= DAQ700_CMD3_CLK1SRC;
+   break;
+   default:
+   return -EINVAL;
+   }
+   outb(devpriv->cmd3, dev->iobase + DAQ700_CMD3_REG);
+   break;
+   default:
+   /*
+* The clock source cannot be changed for all
+* other channels.
+*/
+   return -EINVAL;
+   }
+   break;
+   case INSN_CONFIG_GET_CLOCK_SRC:
+   switch (chan) {
+   case 0:
+   /* counter 0 is connected to the 1MHz internal clock */
+   data[1] = DAQ700_CLK_1MHZ;
+   data[2] = I8254_OSC_BASE_1MHZ;
+   break;
+   case 1:
+   /*
+* Counter 1 can use the 1MHz internal clock or an
+* external clock.
+*/
+   if (devpriv->cmd3 & DAQ700_CMD3_CLK1SRC) {
+   data[1] = DAQ700_CLK_1MHZ;
+   data[2] = I8254_OSC_BASE_1MHZ;
+   } else {
+   data[1] = DAQ700_CLK_EXT;
+   data[2] = 0;/* unknown */
+   }
+ 

[PATCH 08/15] staging: comedi: ni_daq_700: flush A/D FIFO on conversion failure

2014-07-14 Thread H Hartley Sweeten
According to the manual, the A/D FIFO needs to be reset and cleared
after a conversion failure.

For aesthetics, factor the code that does this out of daq700_ai_config()
and use the new helper function when a conversion times out.

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

diff --git a/drivers/staging/comedi/drivers/ni_daq_700.c 
b/drivers/staging/comedi/drivers/ni_daq_700.c
index bde5996..295b14a 100644
--- a/drivers/staging/comedi/drivers/ni_daq_700.c
+++ b/drivers/staging/comedi/drivers/ni_daq_700.c
@@ -162,6 +162,12 @@ static void daq700_ai_start_conv(struct comedi_device *dev)
   0, I8254_MODE1 | I8254_BINARY);  /* OUT0 high */
 }
 
+static void daq700_ai_flush_fifo(struct comedi_device *dev)
+{
+   outb(DAQ700_AI_CLR_FIFO, dev->iobase + DAQ700_AI_CLR_REG);
+   inw(dev->iobase + DAQ700_AI_FIFO_REG);
+}
+
 static int daq700_ai_eoc(struct comedi_device *dev,
 struct comedi_subdevice *s,
 struct comedi_insn *insn,
@@ -216,8 +222,10 @@ static int daq700_ai_rinsn(struct comedi_device *dev,
 
/* wait for conversion to end */
ret = comedi_timeout(dev, s, insn, daq700_ai_eoc, 0);
-   if (ret)
+   if (ret) {
+   daq700_ai_flush_fifo(dev);
return ret;
+   }
 
/* read data */
d = inw(dev->iobase + DAQ700_AI_FIFO_REG);
@@ -253,8 +261,7 @@ static void daq700_ai_config(struct comedi_device *dev,
i8254_set_mode(iobase + DAQ700_TIMER_BASE, 0,
   0, I8254_MODE1 | I8254_BINARY);  /* OUT0 high */
outb(DAQ700_TIC_CLR_INT, iobase + DAQ700_TIC_REG);
-   outb(DAQ700_AI_CLR_FIFO, iobase + DAQ700_AI_CLR_REG);
-   inw(iobase + DAQ700_AI_FIFO_REG);
+   daq700_ai_flush_fifo(dev);
 }
 
 static int daq700_auto_attach(struct comedi_device *dev,
-- 
1.9.3

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


[PATCH 04/15] staging: comedi: ni_daq_700: tidy up daq700_dio_insn_bits()

2014-07-14 Thread H Hartley Sweeten
This board has 8 digital output and 8 digital input channels. For convienence
all 16 channels are packed into one DIO subdevice. Add a comment to clarify
this.

Tidy up the 'mask' check used when updating the digital outputs.

For aesthetics, rename the digital output and digital input registers.

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

diff --git a/drivers/staging/comedi/drivers/ni_daq_700.c 
b/drivers/staging/comedi/drivers/ni_daq_700.c
index ba22951..1798b47 100644
--- a/drivers/staging/comedi/drivers/ni_daq_700.c
+++ b/drivers/staging/comedi/drivers/ni_daq_700.c
@@ -61,11 +61,11 @@
 /*
  * Regsiter I/O map
  */
+#define DAQ700_DO_REG  0x04
+#define DAQ700_DI_REG  0x05
 #define DAQ700_TIMER_BASE  0x08
 
 /* daqcard700 registers */
-#define DIO_W  0x04/* WO 8bit */
-#define DIO_R  0x05/* RO 8bit */
 #define CMD_R1 0x00/* WO 8bit */
 #define CMD_R2 0x07/* RW 8bit */
 #define CMD_R3 0x05/* W0 8bit */
@@ -94,14 +94,16 @@ static int daq700_dio_insn_bits(struct comedi_device *dev,
unsigned int mask;
unsigned int val;
 
+   /*
+* channels 0-7 are always outputs
+* channels 8-15 are always inputs
+*/
mask = comedi_dio_update_state(s, data);
-   if (mask) {
-   if (mask & 0xff)
-   outb(s->state & 0xff, dev->iobase + DIO_W);
-   }
+   if (mask & 0xff)
+   outb(s->state & 0xff, dev->iobase + DAQ700_DO_REG);
 
val = s->state & 0xff;
-   val |= inb(dev->iobase + DIO_R) << 8;
+   val |= inb(dev->iobase + DAQ700_DI_REG) << 8;
 
data[1] = val;
 
-- 
1.9.3

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


[PATCH 00/15] staging: comedi: ni_daq_700: tidy up and add async cmd support

2014-07-14 Thread H Hartley Sweeten
Tidy up this driver a bit and add support for async commands using the
Analog Input subdevice.

H Hartley Sweeten (15):
  staging: comedi: ni_daq_700: remove unnecessary enable and flush of ADC
  staging: comedi: ni_daq_700: use 8253.h helpers for timer operations
  staging: comedi: ni_daq_700: fix daq700_dio_insn_config()
  staging: comedi: ni_daq_700: tidy up daq700_dio_insn_bits()
  staging: comedi: ni_daq_700: tidy up the command register defines
  staging: comedi: ni_daq_700: tidy up the status register defines
  staging: comedi: ni_daq_700: tidy up the remaining register defines
  staging: comedi: ni_daq_700: flush A/D FIFO on conversion failure
  staging: comedi: ni_daq_700: tidy up daq700_ai_rinsn()
  staging: comedi: ni_daq_700: tidy up daq700_ai_config()
  staging: comedi: ni_daq_700: tidy up the subdevice init
  staging: comedi: ni_daq_700: introduce daq700_ai_set_chanspec()
  staging: comedi: ni_daq_700: add ai async command support
  staging: comedi: ni_daq_700: add a counter subdevice
  staging: comedi: ni_daq_700: update the comedi driver comment

 drivers/staging/comedi/Kconfig  |   1 +
 drivers/staging/comedi/comedi.h |   9 +
 drivers/staging/comedi/drivers/ni_daq_700.c | 791 
 3 files changed, 686 insertions(+), 115 deletions(-)

-- 
1.9.3

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


[PATCH 01/15] staging: comedi: ni_daq_700: remove unnecessary enable and flush of ADC

2014-07-14 Thread H Hartley Sweeten
The ADC conversions are enabled and the FIFO is flushed by daq700_ai_config()
when the driver is initially attached. There is no reason to repeat the ADC
enable and flush the FIFO before each sample read in the (*insn_read).

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

diff --git a/drivers/staging/comedi/drivers/ni_daq_700.c 
b/drivers/staging/comedi/drivers/ni_daq_700.c
index 5e472cb..4d5cb5a 100644
--- a/drivers/staging/comedi/drivers/ni_daq_700.c
+++ b/drivers/staging/comedi/drivers/ni_daq_700.c
@@ -169,11 +169,7 @@ static int daq700_ai_rinsn(struct comedi_device *dev,
/* convert n samples */
for (n = 0; n < insn->n; n++) {
/* trigger conversion with out0 L to H */
-   outb(0x00, dev->iobase + CMD_R2); /* enable ADC conversions */
outb(0x30, dev->iobase + CMO_R); /* mode 0 out0 L, from H */
-   outb(0x00, dev->iobase + ADCLEAR_R);/* clear the ADC FIFO */
-   /* read 16bit junk from FIFO to clear */
-   inw(dev->iobase + ADFIFO_R);
/* mode 1 out0 H, L to H, start conversion */
outb(0x32, dev->iobase + CMO_R);
 
-- 
1.9.3

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


[PATCH 11/15] staging: comedi: ni_daq_700: tidy up the subdevice init

2014-07-14 Thread H Hartley Sweeten
For aesthetics, add some white space to the subdevice init and tidy
it up a bit.

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

diff --git a/drivers/staging/comedi/drivers/ni_daq_700.c 
b/drivers/staging/comedi/drivers/ni_daq_700.c
index 0be7312..2b4d4e6 100644
--- a/drivers/staging/comedi/drivers/ni_daq_700.c
+++ b/drivers/staging/comedi/drivers/ni_daq_700.c
@@ -275,25 +275,25 @@ static int daq700_auto_attach(struct comedi_device *dev,
if (ret)
return ret;
 
-   /* DAQCard-700 dio */
+   /* Digital Input/Output subdevice */
s = &dev->subdevices[0];
s->type = COMEDI_SUBD_DIO;
s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
s->n_chan   = 16;
-   s->range_table  = &range_digital;
s->maxdata  = 1;
+   s->range_table  = &range_digital;
s->insn_bits= daq700_dio_insn_bits;
s->insn_config  = daq700_dio_insn_config;
-   s->io_bits  = 0x00ff;
+   s->io_bits  = 0x00ff;   /* direction is fixed */
 
-   /* DAQCard-700 ai */
+   /* Analog Input subdevice */
s = &dev->subdevices[1];
-   s->type = COMEDI_SUBD_AI;
-   s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF;
-   s->n_chan = 16;
-   s->maxdata = (1 << 12) - 1;
-   s->range_table = &range_daq700_ai;
-   s->insn_read = daq700_ai_insn_read;
+   s->type = COMEDI_SUBD_AI;
+   s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF;
+   s->n_chan   = 16;
+   s->maxdata  = 0x0fff;
+   s->range_table  = &range_daq700_ai;
+   s->insn_read= daq700_ai_insn_read;
 
daq700_initialize(dev);
 
-- 
1.9.3

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


[PATCH 03/15] staging: comedi: ni_daq_700: fix daq700_dio_insn_config()

2014-07-14 Thread H Hartley Sweeten
This board has 8 digital output and 8 digital input channels. The direction
of these channels is not configurable. For convienence all 16 channels are
packed into one DIO subdevice.

The (*insn_config) for this subdevice currently uses the comedi core provided
comedi_dio_insn_config() function to handle the instructions. This function
handles the INSN_CONFIG_DIO_INPUT and INSN_CONFIG_DIO_OUTPUT instructions
which are used to change the configuration of the channels. After calling
the core function, this driver "fixes" the subdevice io_bits and returns
success. These instructions should be returning -EINVAL since the channels
are not configurable.

Refactor the (*insn_config) to only handle the INSN_CONFIG_DIO_QUERY instruction
and return -EINVAL for all others.

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

diff --git a/drivers/staging/comedi/drivers/ni_daq_700.c 
b/drivers/staging/comedi/drivers/ni_daq_700.c
index 16b52b6..ba22951 100644
--- a/drivers/staging/comedi/drivers/ni_daq_700.c
+++ b/drivers/staging/comedi/drivers/ni_daq_700.c
@@ -113,14 +113,19 @@ static int daq700_dio_insn_config(struct comedi_device 
*dev,
  struct comedi_insn *insn,
  unsigned int *data)
 {
-   int ret;
-
-   ret = comedi_dio_insn_config(dev, s, insn, data, 0);
-   if (ret)
-   return ret;
+   unsigned int mask = 1 << CR_CHAN(insn->chanspec);
 
-   /* The DIO channels are not configurable, fix the io_bits */
-   s->io_bits = 0x00ff;
+   /*
+* The DIO channels are not configurable, only the query instruction
+* is supported.
+*/
+   switch (data[0]) {
+   case INSN_CONFIG_DIO_QUERY:
+   data[1] = (s->io_bits & mask) ? COMEDI_OUTPUT : COMEDI_INPUT;
+   break;
+   default:
+   return -EINVAL;
+   }
 
return insn->n;
 }
-- 
1.9.3

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


[PATCH 02/15] staging: comedi: ni_daq_700: use 8253.h helpers for timer operations

2014-07-14 Thread H Hartley Sweeten
Clarify the timer operations by using the helper functions in 8253.h.

For aesthetics, factor the "ai start conversion" code out of daq700_ai_rinsn().

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

diff --git a/drivers/staging/comedi/drivers/ni_daq_700.c 
b/drivers/staging/comedi/drivers/ni_daq_700.c
index 4d5cb5a..16b52b6 100644
--- a/drivers/staging/comedi/drivers/ni_daq_700.c
+++ b/drivers/staging/comedi/drivers/ni_daq_700.c
@@ -51,11 +51,18 @@
 #include 
 #include 
 
-#include "../comedidev.h"
-
 #include 
 #include 
 
+#include "../comedidev.h"
+
+#include "8253.h"
+
+/*
+ * Regsiter I/O map
+ */
+#define DAQ700_TIMER_BASE  0x08
+
 /* daqcard700 registers */
 #define DIO_W  0x04/* WO 8bit */
 #define DIO_R  0x05/* RO 8bit */
@@ -66,10 +73,6 @@
 #define STA_R2 0x01/* RO 8bit */
 #define ADFIFO_R   0x02/* RO 16bit */
 #define ADCLEAR_R  0x01/* WO 8bit */
-#define CDA_R0 0x08/* RW 8bit */
-#define CDA_R1 0x09/* RW 8bit */
-#define CDA_R2 0x0A/* RW 8bit */
-#define CMO_R  0x0B/* RO 8bit */
 #define TIC_R  0x06/* WO 8bit */
 /* daqcard700 modes */
 #define CMD_R3_DIFF 0x04/* diff mode */
@@ -122,6 +125,18 @@ static int daq700_dio_insn_config(struct comedi_device 
*dev,
return insn->n;
 }
 
+static void daq700_ai_start_conv(struct comedi_device *dev)
+{
+   /*
+* Manually trigger an A/D conversion with a low-to-high
+* transition of OUT0.
+*/
+   i8254_set_mode(dev->iobase + DAQ700_TIMER_BASE, 0,
+  0, I8254_MODE0 | I8254_BINARY);  /* OUT0 low */
+   i8254_set_mode(dev->iobase + DAQ700_TIMER_BASE, 0,
+  0, I8254_MODE1 | I8254_BINARY);  /* OUT0 high */
+}
+
 static int daq700_ai_eoc(struct comedi_device *dev,
 struct comedi_subdevice *s,
 struct comedi_insn *insn,
@@ -168,10 +183,7 @@ static int daq700_ai_rinsn(struct comedi_device *dev,
 
/* convert n samples */
for (n = 0; n < insn->n; n++) {
-   /* trigger conversion with out0 L to H */
-   outb(0x30, dev->iobase + CMO_R); /* mode 0 out0 L, from H */
-   /* mode 1 out0 H, L to H, start conversion */
-   outb(0x32, dev->iobase + CMO_R);
+   daq700_ai_start_conv(dev);
 
/* wait for conversion to end */
ret = comedi_timeout(dev, s, insn, daq700_ai_eoc, 0);
@@ -208,7 +220,8 @@ static void daq700_ai_config(struct comedi_device *dev,
outb(0x80, iobase + CMD_R1);/* disable scanning, ADC to chan 0 */
outb(0x00, iobase + CMD_R2);/* clear all bits */
outb(0x00, iobase + CMD_R3);/* set +-10 range */
-   outb(0x32, iobase + CMO_R); /* config counter mode1, out0 to H */
+   i8254_set_mode(iobase + DAQ700_TIMER_BASE, 0,
+  0, I8254_MODE1 | I8254_BINARY);  /* OUT0 high */
outb(0x00, iobase + TIC_R); /* clear counter interrupt */
outb(0x00, iobase + ADCLEAR_R); /* clear the ADC FIFO */
inw(iobase + ADFIFO_R); /* read 16bit junk from FIFO to clear */
-- 
1.9.3

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


[PATCH 12/15] staging: comedi: ni_daq_700: introduce daq700_ai_set_chanspec()

2014-07-14 Thread H Hartley Sweeten
In preperation for adding async command support, introduce a helper
function to set chan/range/aref information when reading an analog
input sample.

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

diff --git a/drivers/staging/comedi/drivers/ni_daq_700.c 
b/drivers/staging/comedi/drivers/ni_daq_700.c
index 2b4d4e6..2a474b0 100644
--- a/drivers/staging/comedi/drivers/ni_daq_700.c
+++ b/drivers/staging/comedi/drivers/ni_daq_700.c
@@ -150,6 +150,29 @@ static int daq700_dio_insn_config(struct comedi_device 
*dev,
return insn->n;
 }
 
+static void daq700_ai_set_chanspec(struct comedi_device *dev,
+  unsigned int chanspec)
+{
+   unsigned int chan = CR_CHAN(chanspec);
+   unsigned int range = CR_RANGE(chanspec);
+   unsigned int aref = CR_AREF(chanspec);
+   unsigned int val;
+
+   /* set channel mode/range */
+   if (range >= 1)
+   range++;/* convert range to hardware value */
+   val = DAQ700_CMD3_ARNG(range);
+   if (aref == AREF_DIFF)
+   val |= DAQ700_CMD3_DIFF;
+   outb(val, dev->iobase + DAQ700_CMD3_REG);
+
+   /* set multiplexer for single-channel scan */
+   outb(DAQ700_CMD1_SCANDISAB | DAQ700_CMD1_MA(chan),
+dev->iobase + DAQ700_CMD1_REG);
+   /* mux needs 2us to really settle [Fred Brooks]. */
+   udelay(2);
+}
+
 static void daq700_ai_start_conv(struct comedi_device *dev)
 {
/*
@@ -195,26 +218,11 @@ static int daq700_ai_insn_read(struct comedi_device *dev,
   struct comedi_insn *insn,
   unsigned int *data)
 {
-   unsigned int chan = CR_CHAN(insn->chanspec);
-   unsigned int range = CR_RANGE(insn->chanspec);
-   unsigned int aref = CR_AREF(insn->chanspec);
unsigned int val;
int ret;
int i;
 
-   /* set channel mode/range */
-   if (range >= 1)
-   range++;/* convert range to hardware value */
-   val = DAQ700_CMD3_ARNG(range);
-   if (aref == AREF_DIFF)
-   val |= DAQ700_CMD3_DIFF;
-   outb(val, dev->iobase + DAQ700_CMD3_REG);
-
-   /* set multiplexer for single-channel scan */
-   outb(DAQ700_CMD1_SCANDISAB | DAQ700_CMD1_MA(chan),
-dev->iobase + DAQ700_CMD1_REG);
-   /* mux needs 2us to really settle [Fred Brooks]. */
-   udelay(2);
+   daq700_ai_set_chanspec(dev, insn->chanspec);
 
for (i = 0; i < insn->n; i++) {
daq700_ai_start_conv(dev);
-- 
1.9.3

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


RE: [BISECTED][REGRESSION] Loading Hyper-V network drivers is racy in 3.14+ on Hyper-V 2012 R2

2014-07-14 Thread Haiyang Zhang
> -Original Message-
> From: Sitsofe Wheeler [mailto:sits...@gmail.com]
> Sent: Monday, July 14, 2014 5:31 PM
> To: Haiyang Zhang
> Cc: KY Srinivasan; David S. Miller; de...@linuxdriverproject.org; linux-
> ker...@vger.kernel.org; net...@vger.kernel.org
> Subject: Re: [BISECTED][REGRESSION] Loading Hyper-V network drivers is
> racy in 3.14+ on Hyper-V 2012 R2
> 
> On Fri, Jul 11, 2014 at 03:25:11PM +, Haiyang Zhang wrote:
> > Since you found the commit b679ef73edc is related to this problem,
> > could you do a simple test:
> >   Reduce the receive buffer size back to 2MB, like below, then re-test
> >   it, see if the problem goes away?
> > drivers/net/hyperv/hyperv_net.h
> > #define NETVSC_RECEIVE_BUFFER_SIZE  (1024*1024*2)   /* 2MB
> */
> 
> After doing this I was able to reach over 900 reboots where the network
> connected properly.

Thanks for the tests! I will make a patch that can automatically retry
smaller memory allocs when memory is insufficient.

Thanks,
- Haiyang

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


Re: [BISECTED][REGRESSION] Loading Hyper-V network drivers is racy in 3.14+ on Hyper-V 2012 R2

2014-07-14 Thread Sitsofe Wheeler
On Fri, Jul 11, 2014 at 03:25:11PM +, Haiyang Zhang wrote:
> 
> > -Original Message-
> > From: Sitsofe Wheeler [mailto:sits...@gmail.com]
> > Sent: Friday, July 11, 2014 1:53 AM
> > To: Haiyang Zhang
> > Cc: KY Srinivasan; David S. Miller; de...@linuxdriverproject.org; linux-
> > ker...@vger.kernel.org; net...@vger.kernel.org
> > Subject: Re: [BISECTED][REGRESSION] Loading Hyper-V network drivers is
> > racy in 3.14+ on Hyper-V 2012 R2
> 
> > Oops that should have been
> > https://bugzilla.kernel.org/attachment.cgi?id=142351 (either way it's
> > information linked off
> > https://bugzilla.kernel.org/show_bug.cgi?id=78771 ).
> 
> Thanks for the dmesg. By looking at it, seems the netvsc driver was
> loaded properly, and 2 NICs are up, one NIC is down (probably not set
> to connected in HyperV manager?). Or, this dmesg wasn't the one when
> bug happens?

This was a dmesg where the bug did happen and your first guess is right
- there are 3 NICs but only the first two are connected and the last is
set to "Not connected" in Hyper-V Manager.

> Since you found the commit b679ef73edc is related to this problem,
> could you do a simple test:
>   Reduce the receive buffer size back to 2MB, like below, then re-test
>   it, see if the problem goes away?
>   drivers/net/hyperv/hyperv_net.h
>   #define NETVSC_RECEIVE_BUFFER_SIZE  (1024*1024*2)   /* 2MB 
> */

After doing this I was able to reach over 900 reboots where the network
connected properly.

-- 
Sitsofe | http://sucs.org/~sits/
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v4] staging: android: Clean up else statement from binder_send_failed_reply

2014-07-14 Thread Lucas Tanure
Hi,

This patch got accepted ?

Thanks
--
Lucas Tanure
+55 (19) 988176559


On Sun, Jul 13, 2014 at 9:31 PM, Lucas Tanure  wrote:
> Kernel coding style. Remove useless else statement after return.
> Changes from v1 and v2: Fix warning for mixed declarations and code.
> Declaration of "struct binder_transaction *next" made outside of while.
>
> Changes from v3: Removed initialization to NULL for next variable.
>
> Signed-off-by: Lucas Tanure 
> ---
>  drivers/staging/android/binder.c | 28 ++--
>  1 file changed, 14 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/staging/android/binder.c 
> b/drivers/staging/android/binder.c
> index 14714a6..4f34dc0 100644
> --- a/drivers/staging/android/binder.c
> +++ b/drivers/staging/android/binder.c
> @@ -1183,6 +1183,7 @@ static void binder_send_failed_reply(struct 
> binder_transaction *t,
>  uint32_t error_code)
>  {
> struct binder_thread *target_thread;
> +   struct binder_transaction *next;
>
> BUG_ON(t->flags & TF_ONE_WAY);
> while (1) {
> @@ -1210,24 +1211,23 @@ static void binder_send_failed_reply(struct 
> binder_transaction *t,
> target_thread->return_error);
> }
> return;
> -   } else {
> -   struct binder_transaction *next = t->from_parent;
> +   }
> +   next = t->from_parent;
>
> -   binder_debug(BINDER_DEBUG_FAILED_TRANSACTION,
> -"send failed reply for transaction %d, 
> target dead\n",
> -t->debug_id);
> +   binder_debug(BINDER_DEBUG_FAILED_TRANSACTION,
> +"send failed reply for transaction %d, target 
> dead\n",
> +t->debug_id);
>
> -   binder_pop_transaction(target_thread, t);
> -   if (next == NULL) {
> -   binder_debug(BINDER_DEBUG_DEAD_BINDER,
> -"reply failed, no target thread 
> at root\n");
> -   return;
> -   }
> -   t = next;
> +   binder_pop_transaction(target_thread, t);
> +   if (next == NULL) {
> binder_debug(BINDER_DEBUG_DEAD_BINDER,
> -"reply failed, no target thread -- retry 
> %d\n",
> - t->debug_id);
> +"reply failed, no target thread at 
> root\n");
> +   return;
> }
> +   t = next;
> +   binder_debug(BINDER_DEBUG_DEAD_BINDER,
> +"reply failed, no target thread -- retry %d\n",
> + t->debug_id);
> }
>  }
>
> --
> 2.0.1
>
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 16/28] staging: comedi: ni_stc.h: refactor 'aobits' boardinfo

2014-07-14 Thread H Hartley Sweeten
For aesthetics, change the 'aobits' in the boardinfo to 'ao_maxdata'
to remove the need for the calculation of the subdevice 'maxdata'.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_atmio.c  | 14 ++--
 drivers/staging/comedi/drivers/ni_mio_common.c |  2 +-
 drivers/staging/comedi/drivers/ni_mio_cs.c |  8 +--
 drivers/staging/comedi/drivers/ni_pcimio.c | 88 +-
 drivers/staging/comedi/drivers/ni_stc.h|  2 +-
 5 files changed, 57 insertions(+), 57 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_atmio.c 
b/drivers/staging/comedi/drivers/ni_atmio.c
index 160e703..3858061 100644
--- a/drivers/staging/comedi/drivers/ni_atmio.c
+++ b/drivers/staging/comedi/drivers/ni_atmio.c
@@ -113,7 +113,7 @@ static const struct ni_board_struct ni_boards[] = {
.gainlkup   = ai_gain_16,
.ai_speed   = 800,
.n_aochan   = 2,
-   .aobits = 12,
+   .ao_maxdata = 0x0fff,
.ao_fifo_depth  = 2048,
.ao_range_table = &range_ni_E_ao_ext,
.ao_speed   = 1000,
@@ -129,7 +129,7 @@ static const struct ni_board_struct ni_boards[] = {
.gainlkup   = ai_gain_16,
.ai_speed   = 2000,
.n_aochan   = 2,
-   .aobits = 12,
+   .ao_maxdata = 0x0fff,
.ao_fifo_depth  = 2048,
.ao_range_table = &range_ni_E_ao_ext,
.ao_speed   = 1000,
@@ -145,7 +145,7 @@ static const struct ni_board_struct ni_boards[] = {
.gainlkup   = ai_gain_16,
.ai_speed   = 1,
.n_aochan   = 2,
-   .aobits = 12,
+   .ao_maxdata = 0x0fff,
.ao_range_table = &range_ni_E_ao_ext,
.ao_speed   = 1,
.num_p0_dio_channels = 8,
@@ -160,7 +160,7 @@ static const struct ni_board_struct ni_boards[] = {
.gainlkup   = ai_gain_16,
.ai_speed   = 1,
.n_aochan   = 2,
-   .aobits = 12,
+   .ao_maxdata = 0x0fff,
.ao_range_table = &range_ni_E_ao_ext,
.ao_speed   = 1,
.num_p0_dio_channels = 8,
@@ -176,7 +176,7 @@ static const struct ni_board_struct ni_boards[] = {
.gainlkup   = ai_gain_16,
.ai_speed   = 2000,
.n_aochan   = 2,
-   .aobits = 12,
+   .ao_maxdata = 0x0fff,
.ao_fifo_depth  = 2048,
.ao_range_table = &range_ni_E_ao_ext,
.ao_speed   = 1000,
@@ -193,7 +193,7 @@ static const struct ni_board_struct ni_boards[] = {
.gainlkup   = ai_gain_8,
.ai_speed   = 5,
.n_aochan   = 2,
-   .aobits = 12,
+   .ao_maxdata = 0x0fff,
.ao_range_table = &range_bipolar10,
.ao_speed   = 5,
.num_p0_dio_channels = 8,
@@ -209,7 +209,7 @@ static const struct ni_board_struct ni_boards[] = {
.gainlkup   = ai_gain_14,
.ai_speed   = 1,
.n_aochan   = 2,
-   .aobits = 16,
+   .ao_maxdata = 0x,
.ao_fifo_depth  = 2048,
.ao_range_table = &range_ni_E_ao_ext,
.ao_speed   = 1000,
diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c 
b/drivers/staging/comedi/drivers/ni_mio_common.c
index 4c451b5..8303d66 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -5544,7 +5544,7 @@ static int ni_E_init(struct comedi_device *dev,
if (devpriv->is_m_series)
s->subdev_flags |= SDF_SOFT_CALIBRATED;
s->n_chan = board->n_aochan;
-   s->maxdata = (1 << board->aobits) - 1;
+   s->maxdata = board->ao_maxdata;
s->range_table = board->ao_range_table;
s->insn_read = &ni_ao_insn_read;
s->insn_write = &ni_ao_insn_write;
diff --git a/drivers/staging/comedi/drivers/ni_mio_cs.c 
b/drivers/staging/comedi/drivers/ni_mio_cs.c
index bba709d..bb414ec 100644
--- a/drivers/staging/comedi/drivers/ni_mio_cs.c
+++ b/drivers/staging/comedi/drivers/ni_mio_cs.c
@@ -81,7 +81,7 @@ static const struct ni_board_struct ni_boards[] = {
.gainlkup   = ai_gain_16,
.ai_speed   = 2000,
.n_aochan   = 2,
-   .aobits = 12,
+   .ao_maxdata = 0x0fff,
.ao_fifo_depth  = 2048,
.ao_range_table = &range_bipolar10,
 

[PATCH 15/28] staging: comedi: ni_stc.h: refactor 'adbits' boardinfo

2014-07-14 Thread H Hartley Sweeten
For aesthetics, change the 'adbits' in the boardinfo to 'ai_maxdata'
to remove the need for the calculation of the subdevice 'maxdata'.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_atmio.c  | 16 ++---
 drivers/staging/comedi/drivers/ni_mio_common.c |  4 +-
 drivers/staging/comedi/drivers/ni_mio_cs.c | 10 +--
 drivers/staging/comedi/drivers/ni_pcimio.c | 98 +-
 drivers/staging/comedi/drivers/ni_stc.h|  2 +-
 5 files changed, 65 insertions(+), 65 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_atmio.c 
b/drivers/staging/comedi/drivers/ni_atmio.c
index 0f4dc5a..160e703 100644
--- a/drivers/staging/comedi/drivers/ni_atmio.c
+++ b/drivers/staging/comedi/drivers/ni_atmio.c
@@ -108,7 +108,7 @@ static const struct ni_board_struct ni_boards[] = {
.device_id  = 44,
.isapnp_id  = 0x,   /* XXX unknown */
.n_adchan   = 16,
-   .adbits = 12,
+   .ai_maxdata = 0x0fff,
.ai_fifo_depth  = 8192,
.gainlkup   = ai_gain_16,
.ai_speed   = 800,
@@ -124,7 +124,7 @@ static const struct ni_board_struct ni_boards[] = {
.device_id  = 25,
.isapnp_id  = 0x1900,
.n_adchan   = 16,
-   .adbits = 12,
+   .ai_maxdata = 0x0fff,
.ai_fifo_depth  = 2048,
.gainlkup   = ai_gain_16,
.ai_speed   = 2000,
@@ -140,7 +140,7 @@ static const struct ni_board_struct ni_boards[] = {
.device_id  = 36,
.isapnp_id  = 0x2400,
.n_adchan   = 16,
-   .adbits = 12,
+   .ai_maxdata = 0x0fff,
.ai_fifo_depth  = 512,
.gainlkup   = ai_gain_16,
.ai_speed   = 1,
@@ -155,7 +155,7 @@ static const struct ni_board_struct ni_boards[] = {
.device_id  = 37,
.isapnp_id  = 0x2500,
.n_adchan   = 16,
-   .adbits = 12,
+   .ai_maxdata = 0x0fff,
.ai_fifo_depth  = 512,
.gainlkup   = ai_gain_16,
.ai_speed   = 1,
@@ -171,7 +171,7 @@ static const struct ni_board_struct ni_boards[] = {
.device_id  = 38,
.isapnp_id  = 0x2600,
.n_adchan   = 64,
-   .adbits = 12,
+   .ai_maxdata = 0x0fff,
.ai_fifo_depth  = 2048,
.gainlkup   = ai_gain_16,
.ai_speed   = 2000,
@@ -187,7 +187,7 @@ static const struct ni_board_struct ni_boards[] = {
.device_id  = 39,
.isapnp_id  = 0x2700,
.n_adchan   = 16,
-   .adbits = 16,
+   .ai_maxdata = 0x,
.ai_fifo_depth  = 512,
.alwaysdither   = 1,
.gainlkup   = ai_gain_8,
@@ -203,7 +203,7 @@ static const struct ni_board_struct ni_boards[] = {
.device_id  = 50,
.isapnp_id  = 0x,   /* XXX unknown */
.n_adchan   = 16,
-   .adbits = 16,
+   .ai_maxdata = 0x,
.ai_fifo_depth  = 512,
.alwaysdither   = 1,
.gainlkup   = ai_gain_14,
@@ -220,7 +220,7 @@ static const struct ni_board_struct ni_boards[] = {
.device_id  = 51,
.isapnp_id  = 0x,   /* XXX unknown */
.n_adchan   = 16,
-   .adbits = 16,
+   .ai_maxdata = 0x,
.ai_fifo_depth  = 512,
.alwaysdither   = 1,/* unknown */
.gainlkup   = ai_gain_14,
diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c 
b/drivers/staging/comedi/drivers/ni_mio_common.c
index 05f51bc..4c451b5 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -5513,13 +5513,13 @@ static int ni_E_init(struct comedi_device *dev,
SDF_READABLE | SDF_DIFF | SDF_DITHER | SDF_CMD_READ;
if (!devpriv->is_611x)
s->subdev_flags |= SDF_GROUND | SDF_COMMON | SDF_OTHER;
-   if (board->adbits > 16)
+   if (board->ai_maxdata > 0x)
s->subdev_flags |= SDF_LSAMPL;
if (devpriv->is_m_series)
s->subdev_flags |= SDF_SOFT_CALIBRATED;
s->n_chan = board->n_adchan;
s->len_chanlist = 512;
-   s->maxdata = (1 << board->adbits) - 1;
+   s->maxdata = board->ai_maxdata;

[PATCH 14/28] staging: comedi: ni_mio_common: remove unnecessary use of 'board->adbits'

2014-07-14 Thread H Hartley Sweeten
For aesthetics, use the subdevice 'maxdata' instead of the board 'adbits'.

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

diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c 
b/drivers/staging/comedi/drivers/ni_mio_common.c
index f4125c0..05f51bc 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -1899,13 +1899,11 @@ static void ni_m_series_load_channelgain_list(struct 
comedi_device *dev,
struct ni_private *devpriv = dev->private;
unsigned int chan, range, aref;
unsigned int i;
-   unsigned offset;
unsigned int dither;
unsigned range_code;
 
ni_stc_writew(dev, 1, Configuration_Memory_Clear);
 
-/* offset = 1 << (board->adbits - 1); */
if ((list[0] & CR_ALT_SOURCE)) {
unsigned bypass_bits;
chan = CR_CHAN(list[0]);
@@ -1929,7 +1927,6 @@ static void ni_m_series_load_channelgain_list(struct 
comedi_device *dev,
} else {
ni_writel(dev, 0, M_Offset_AI_Config_FIFO_Bypass);
}
-   offset = 0;
for (i = 0; i < n_chan; i++) {
unsigned config_bits = 0;
chan = CR_CHAN(list[i]);
@@ -1938,7 +1935,7 @@ static void ni_m_series_load_channelgain_list(struct 
comedi_device *dev,
dither = ((list[i] & CR_ALT_FILTER) != 0);
 
range_code = ni_gainlkup[board->gainlkup][range];
-   devpriv->ai_offset[i] = offset;
+   devpriv->ai_offset[i] = 0;
switch (aref) {
case AREF_DIFF:
config_bits |=
@@ -2000,14 +1997,15 @@ static void ni_m_series_load_channelgain_list(struct 
comedi_device *dev,
  *   valid channels are 0-3
  */
 static void ni_load_channelgain_list(struct comedi_device *dev,
+struct comedi_subdevice *s,
 unsigned int n_chan, unsigned int *list)
 {
const struct ni_board_struct *board = comedi_board(dev);
struct ni_private *devpriv = dev->private;
+   unsigned int offset = (s->maxdata + 1) >> 1;
unsigned int chan, range, aref;
unsigned int i;
unsigned int hi, lo;
-   unsigned offset;
unsigned int dither;
 
if (devpriv->is_m_series) {
@@ -2053,7 +2051,6 @@ static void ni_load_channelgain_list(struct comedi_device 
*dev,
}
}
 
-   offset = 1 << (board->adbits - 1);
for (i = 0; i < n_chan; i++) {
if (!devpriv->is_6143 && (list[i] & CR_ALT_SOURCE)) {
chan = devpriv->ai_calib_source;
@@ -2120,15 +2117,14 @@ static int ni_ai_insn_read(struct comedi_device *dev,
   struct comedi_insn *insn,
   unsigned int *data)
 {
-   const struct ni_board_struct *board = comedi_board(dev);
struct ni_private *devpriv = dev->private;
+   unsigned int mask = (s->maxdata + 1) >> 1;
int i, n;
-   const unsigned int mask = (1 << board->adbits) - 1;
unsigned signbits;
unsigned short d;
unsigned long dl;
 
-   ni_load_channelgain_list(dev, 1, &insn->chanspec);
+   ni_load_channelgain_list(dev, s, 1, &insn->chanspec);
 
ni_clear_ai_fifo(dev);
 
@@ -2447,7 +2443,7 @@ static int ni_ai_cmd(struct comedi_device *dev, struct 
comedi_subdevice *s)
}
ni_clear_ai_fifo(dev);
 
-   ni_load_channelgain_list(dev, cmd->chanlist_len, cmd->chanlist);
+   ni_load_channelgain_list(dev, s, cmd->chanlist_len, cmd->chanlist);
 
/* start configuration */
ni_stc_writew(dev, AI_Configuration_Start, Joint_Reset_Register);
-- 
1.9.3

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


[PATCH 17/28] staging: comedi: ni_mio_common: (*cancel) only works with async cmd support

2014-07-14 Thread H Hartley Sweeten
The comedi subdevice (*cancel) function can only be called by the core if the
subdevice supports async commands. Move the initialization of this callback
to it is only set if async commands are enabled.

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

diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c 
b/drivers/staging/comedi/drivers/ni_mio_common.c
index 8303d66..2ab267b 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -5559,11 +5559,11 @@ static int ni_E_init(struct comedi_device *dev,
s->subdev_flags |= SDF_CMD_WRITE;
s->do_cmd = &ni_ao_cmd;
s->do_cmdtest = &ni_ao_cmdtest;
+   s->cancel = &ni_ao_reset;
s->len_chanlist = board->n_aochan;
if (!devpriv->is_m_series)
s->munge = ni_ao_munge;
}
-   s->cancel = &ni_ao_reset;
} else {
s->type = COMEDI_SUBD_UNUSED;
}
-- 
1.9.3

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


[PATCH 10/28] staging: comedi: ni_mio_common: remove some unnecessary boardinfo access

2014-07-14 Thread H Hartley Sweeten
Currently ni_m_series_ao_config_chanlist() gets the boardinfo pointer in
order to get the number of analog output channels. Get this from the
comedi_subdevice instead.

The ni_old_ao_config_chanlist() function also gets the boardinfo pointer
to get the analog output resolution, 'aobits', in order to calculate the
value needed to convert samples from unsigned to two's complement for
bipolar ranges. Use the comedi_subdevice 'maxdata' instead.

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 8854f18..6e79bcf 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -2818,7 +2818,6 @@ static int ni_m_series_ao_config_chanlist(struct 
comedi_device *dev,
  unsigned int chanspec[],
  unsigned int n_chans, int timed)
 {
-   const struct ni_board_struct *board = comedi_board(dev);
struct ni_private *devpriv = dev->private;
unsigned int range;
unsigned int chan;
@@ -2827,7 +2826,7 @@ static int ni_m_series_ao_config_chanlist(struct 
comedi_device *dev,
int invert = 0;
 
if (timed) {
-   for (i = 0; i < board->n_aochan; ++i) {
+   for (i = 0; i < s->n_chan; ++i) {
devpriv->ao_conf[i] &= ~MSeries_AO_Update_Timed_Bit;
ni_writeb(dev, devpriv->ao_conf[i],
  M_Offset_AO_Config_Bank(i));
@@ -2893,7 +2892,6 @@ static int ni_old_ao_config_chanlist(struct comedi_device 
*dev,
 unsigned int chanspec[],
 unsigned int n_chans)
 {
-   const struct ni_board_struct *board = comedi_board(dev);
struct ni_private *devpriv = dev->private;
unsigned int range;
unsigned int chan;
@@ -2908,7 +2906,7 @@ static int ni_old_ao_config_chanlist(struct comedi_device 
*dev,
 
if (comedi_range_is_bipolar(s, range)) {
conf |= AO_Bipolar;
-   invert = (1 << (board->aobits - 1));
+   invert = (s->maxdata + 1) >> 1;
} else {
invert = 0;
}
-- 
1.9.3

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


[PATCH 01/28] staging: comedi: mite.h: tidy up the mite channel register offsets

2014-07-14 Thread H Hartley Sweeten
Convert the inline MITE_* functions, used to calculate the mite channel
register offsets, into simple macros.

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

diff --git a/drivers/staging/comedi/drivers/mite.h 
b/drivers/staging/comedi/drivers/mite.h
index a4852cb..33d87a2 100644
--- a/drivers/staging/comedi/drivers/mite.h
+++ b/drivers/staging/comedi/drivers/mite.h
@@ -107,11 +107,6 @@ void mite_prep_dma(struct mite_channel *mite_chan,
 int mite_buf_change(struct mite_dma_descriptor_ring *ring,
struct comedi_subdevice *s);
 
-static inline int CHAN_OFFSET(int channel)
-{
-   return 0x500 + 0x100 * channel;
-};
-
 enum mite_registers {
/* The bits 0x90180700 in MITE_UNKNOWN_DMA_BURST_REG can be
   written and read back.  The bits 0x1f always read as 1.
@@ -123,90 +118,25 @@ enum mite_registers {
MITE_PCI_CONFIG_OFFSET = 0x300,
MITE_CSIGR = 0x460  /* chip signature */
 };
-static inline int MITE_CHOR(int channel)
-{  /*  channel operation */
-   return CHAN_OFFSET(channel) + 0x0;
-};
-
-static inline int MITE_CHCR(int channel)
-{  /*  channel control */
-   return CHAN_OFFSET(channel) + 0x4;
-};
-
-static inline int MITE_TCR(int channel)
-{  /*  transfer count */
-   return CHAN_OFFSET(channel) + 0x8;
-};
-
-static inline int MITE_MCR(int channel)
-{  /*  memory configuration */
-   return CHAN_OFFSET(channel) + 0xc;
-};
-
-static inline int MITE_MAR(int channel)
-{  /*  memory address */
-   return CHAN_OFFSET(channel) + 0x10;
-};
-
-static inline int MITE_DCR(int channel)
-{  /*  device configuration */
-   return CHAN_OFFSET(channel) + 0x14;
-};
-
-static inline int MITE_DAR(int channel)
-{  /*  device address */
-   return CHAN_OFFSET(channel) + 0x18;
-};
-
-static inline int MITE_LKCR(int channel)
-{  /*  link configuration */
-   return CHAN_OFFSET(channel) + 0x1c;
-};
 
-static inline int MITE_LKAR(int channel)
-{  /*  link address */
-   return CHAN_OFFSET(channel) + 0x20;
-};
-
-static inline int MITE_LLKAR(int channel)
-{  /*  see mite section of tnt5002 manual */
-   return CHAN_OFFSET(channel) + 0x24;
-};
-
-static inline int MITE_BAR(int channel)
-{  /*  base address */
-   return CHAN_OFFSET(channel) + 0x28;
-};
-
-static inline int MITE_BCR(int channel)
-{  /*  base count */
-   return CHAN_OFFSET(channel) + 0x2c;
-};
-
-static inline int MITE_SAR(int channel)
-{  /*  ? address */
-   return CHAN_OFFSET(channel) + 0x30;
-};
-
-static inline int MITE_WSCR(int channel)
-{  /*  ? */
-   return CHAN_OFFSET(channel) + 0x34;
-};
-
-static inline int MITE_WSER(int channel)
-{  /*  ? */
-   return CHAN_OFFSET(channel) + 0x38;
-};
-
-static inline int MITE_CHSR(int channel)
-{  /*  channel status */
-   return CHAN_OFFSET(channel) + 0x3c;
-};
-
-static inline int MITE_FCR(int channel)
-{  /*  fifo count */
-   return CHAN_OFFSET(channel) + 0x40;
-};
+#define MITE_CHAN(x)   (0x500 + 0x100 * (x))
+#define MITE_CHOR(x)   (0x00 + MITE_CHAN(x))   /* channel operation */
+#define MITE_CHCR(x)   (0x04 + MITE_CHAN(x))   /* channel control */
+#define MITE_TCR(x)(0x08 + MITE_CHAN(x))   /* transfer count */
+#define MITE_MCR(x)(0x0c + MITE_CHAN(x))   /* memory configuration */
+#define MITE_MAR(x)(0x10 + MITE_CHAN(x))   /* memory address */
+#define MITE_DCR(x)(0x14 + MITE_CHAN(x))   /* device configuration */
+#define MITE_DAR(x)(0x18 + MITE_CHAN(x))   /* device address */
+#define MITE_LKCR(x)   (0x1c + MITE_CHAN(x))   /* link configuration */
+#define MITE_LKAR(x)   (0x20 + MITE_CHAN(x))   /* link address */
+#define MITE_LLKAR(x)  (0x24 + MITE_CHAN(x))   /* see tnt5002 manual */
+#define MITE_BAR(x)(0x28 + MITE_CHAN(x))   /* base address */
+#define MITE_BCR(x)(0x2c + MITE_CHAN(x))   /* base count */
+#define MITE_SAR(x)(0x30 + MITE_CHAN(x))   /* ? address */
+#define MITE_WSCR(x)   (0x34 + MITE_CHAN(x))   /* ? */
+#define MITE_WSER(x)   (0x38 + MITE_CHAN(x))   /* ? */
+#define MITE_CHSR(x)   (0x3c + MITE_CHAN(x))   /* channel status */
+#define MITE_FCR(x)(0x40 + MITE_CHAN(x))   /* fifo count */
 
 enum MITE_IODWBSR_bits {
WENAB = 0x80,   /*  window enable */
-- 
1.9.3

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

[PATCH 11/28] staging: comedi: ni_mio_common: merge analog output (*insn_write) functions

2014-07-14 Thread H Hartley Sweeten
Currently the PCI6xxx boards use a different (*insn_write) function
for the analog output subdevice. Most of the code is identical to the
(*insn_write) used by all the other board types.

For aesthetics, merge the two (*insn_write) functions and handle the
'is_6xxx' differences in the common code.

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

diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c 
b/drivers/staging/comedi/drivers/ni_mio_common.c
index 6e79bcf..9bcf835 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -2964,10 +2964,15 @@ static int ni_ao_insn_write(struct comedi_device *dev,
int reg;
int i;
 
-   if (devpriv->is_m_series)
+   if (devpriv->is_6xxx) {
+   ni_ao_win_outw(dev, 1 << chan, AO_Immediate_671x);
+
+   reg = DACx_Direct_Data_671x(chan);
+   } else if (devpriv->is_m_series) {
reg = M_Offset_DAC_Direct_Data(chan);
-   else
+   } else {
reg = (chan) ? DAC1_Direct_Data : DAC0_Direct_Data;
+   }
 
ni_ao_config_chanlist(dev, s, &insn->chanspec, 1, 0);
 
@@ -2976,8 +2981,19 @@ static int ni_ao_insn_write(struct comedi_device *dev,
 
devpriv->ao[chan] = val;
 
-   if (devpriv->is_m_series) {
-   /* M-series board always use offset binary values */
+   if (devpriv->is_6xxx) {
+   /*
+* 6xxx boards have bipolar outputs, munge the
+* unsigned comedi values to 2's complement
+*/
+   val = comedi_offset_munge(s, val);
+
+   ni_ao_win_outw(dev, val, reg);
+   } else if (devpriv->is_m_series) {
+   /*
+* M-series boards use offset binary values for
+* bipolar and uinpolar outputs
+*/
ni_writew(dev, val, reg);
} else {
/*
@@ -2994,36 +3010,6 @@ static int ni_ao_insn_write(struct comedi_device *dev,
return insn->n;
 }
 
-static int ni_ao_insn_write_671x(struct comedi_device *dev,
-struct comedi_subdevice *s,
-struct comedi_insn *insn,
-unsigned int *data)
-{
-   struct ni_private *devpriv = dev->private;
-   unsigned int chan = CR_CHAN(insn->chanspec);
-   int i;
-
-   ni_ao_win_outw(dev, 1 << chan, AO_Immediate_671x);
-
-   ni_ao_config_chanlist(dev, s, &insn->chanspec, 1, 0);
-
-   for (i = 0; i < insn->n; i++) {
-   unsigned int val = data[i];
-
-   devpriv->ao[chan] = val;
-
-   /*
-* 671x boards have +/-10V outputs
-* munge the unsigned comedi values to 2's complement
-*/
-   val = comedi_offset_munge(s, val);
-
-   ni_ao_win_outw(dev, val, DACx_Direct_Data_671x(chan));
-   }
-
-   return insn->n;
-}
-
 static int ni_ao_insn_config(struct comedi_device *dev,
 struct comedi_subdevice *s,
 struct comedi_insn *insn, unsigned int *data)
@@ -5565,10 +5551,7 @@ static int ni_E_init(struct comedi_device *dev,
s->maxdata = (1 << board->aobits) - 1;
s->range_table = board->ao_range_table;
s->insn_read = &ni_ao_insn_read;
-   if (devpriv->is_6xxx)
-   s->insn_write = &ni_ao_insn_write_671x;
-   else
-   s->insn_write = &ni_ao_insn_write;
+   s->insn_write = &ni_ao_insn_write;
s->insn_config = &ni_ao_insn_config;
 #ifdef PCIDMA
if (board->n_aochan) {
-- 
1.9.3

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


[PATCH 07/28] staging: comedi: ni_stc.h: add some 'is_{board type}' flags to private data

2014-07-14 Thread H Hartley Sweeten
The board->reg_type if checked quite often in the ni_mio_common.c code to
handle differences in the PCI devices supported by the ni_pcimio driver.
Simplify the code a bit by adding some 'is_{board type}' bit-field flags
to the private data.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_mio_common.c | 147 ++---
 drivers/staging/comedi/drivers/ni_pcimio.c |  20 +++-
 drivers/staging/comedi/drivers/ni_stc.h|  10 ++
 3 files changed, 90 insertions(+), 87 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c 
b/drivers/staging/comedi/drivers/ni_mio_common.c
index c08b9b6..b5b4a7b7 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -958,11 +958,11 @@ static void ni_e_series_enable_second_irq(struct 
comedi_device *dev,
 
 static void ni_clear_ai_fifo(struct comedi_device *dev)
 {
-   const struct ni_board_struct *board = comedi_board(dev);
+   struct ni_private *devpriv = dev->private;
static const int timeout = 1;
int i;
 
-   if (board->reg_type == ni_reg_6143) {
+   if (devpriv->is_6143) {
/*  Flush the 6143 data FIFO */
ni_writel(dev, 0x10, AIFIFO_Control_6143);
ni_writel(dev, 0x00, AIFIFO_Control_6143);
@@ -977,7 +977,7 @@ static void ni_clear_ai_fifo(struct comedi_device *dev)
}
} else {
ni_stc_writew(dev, 1, ADC_FIFO_Clear);
-   if (board->reg_type == ni_reg_625x) {
+   if (devpriv->is_625x) {
ni_writeb(dev, 0, M_Offset_Static_AI_Control(0));
ni_writeb(dev, 1, M_Offset_Static_AI_Control(0));
 #if 0
@@ -1140,7 +1140,7 @@ static int ni_ao_wait_for_dma_load(struct comedi_device 
*dev)
 static void ni_ao_fifo_load(struct comedi_device *dev,
struct comedi_subdevice *s, int n)
 {
-   const struct ni_board_struct *board = comedi_board(dev);
+   struct ni_private *devpriv = dev->private;
struct comedi_async *async = s->async;
struct comedi_cmd *cmd = &async->cmd;
int chan;
@@ -1158,10 +1158,10 @@ static void ni_ao_fifo_load(struct comedi_device *dev,
 
range = CR_RANGE(cmd->chanlist[chan]);
 
-   if (board->reg_type & ni_reg_6xxx_mask) {
+   if (devpriv->is_6xxx) {
packed_data = d & 0x;
/* 6711 only has 16 bit wide ao fifo */
-   if (board->reg_type != ni_reg_6711) {
+   if (!devpriv->is_6711) {
err &= comedi_buf_get(s, &d);
if (err == 0)
break;
@@ -1224,11 +1224,12 @@ static int ni_ao_prep_fifo(struct comedi_device *dev,
   struct comedi_subdevice *s)
 {
const struct ni_board_struct *board = comedi_board(dev);
+   struct ni_private *devpriv = dev->private;
int n;
 
/* reset fifo */
ni_stc_writew(dev, 1, DAC_FIFO_Clear);
-   if (board->reg_type & ni_reg_6xxx_mask)
+   if (devpriv->is_6xxx)
ni_ao_win_outl(dev, 0x6, AO_FIFO_Offset_Load_611x);
 
/* load some data */
@@ -1248,12 +1249,11 @@ static int ni_ao_prep_fifo(struct comedi_device *dev,
 static void ni_ai_fifo_read(struct comedi_device *dev,
struct comedi_subdevice *s, int n)
 {
-   const struct ni_board_struct *board = comedi_board(dev);
struct ni_private *devpriv = dev->private;
struct comedi_async *async = s->async;
int i;
 
-   if (board->reg_type == ni_reg_611x) {
+   if (devpriv->is_611x) {
unsigned short data[2];
u32 dl;
 
@@ -1270,7 +1270,7 @@ static void ni_ai_fifo_read(struct comedi_device *dev,
data[0] = dl & 0x;
cfc_write_to_buffer(s, data[0]);
}
-   } else if (board->reg_type == ni_reg_6143) {
+   } else if (devpriv->is_6143) {
unsigned short data[2];
u32 dl;
 
@@ -1324,7 +1324,6 @@ static void ni_handle_fifo_half_full(struct comedi_device 
*dev)
 */
 static void ni_handle_fifo_dregs(struct comedi_device *dev)
 {
-   const struct ni_board_struct *board = comedi_board(dev);
struct ni_private *devpriv = dev->private;
struct comedi_subdevice *s = dev->read_subdev;
unsigned short data[2];
@@ -1332,7 +1331,7 @@ static void ni_handle_fifo_dregs(struct comedi_device 
*dev)
unsigned short fifo_empty;
int i;
 
-   if (board->reg_type == ni_reg_611x) {
+   if (devpriv->is_611x) {
while ((ni_stc_readw(dev, AI_Status_1_Register) &
AI_FIFO_Empty_St) == 0) {
dl = ni_readl(dev, ADC_FIFO_Data_61

[PATCH 23/28] staging: comedi: ni_mio_common: only reset the ai/ao subdevices if they exist

2014-07-14 Thread H Hartley Sweeten
So of the boards supported by this driver do not have analog inputs and
some don't have analog outputs. Move the calls that reset these subdevices
during the (*attach) by ni_E_init() so they only happen if the subdevices
are present.

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

diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c 
b/drivers/staging/comedi/drivers/ni_mio_common.c
index 6d1754f..e60b9e6 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -5544,6 +5544,9 @@ static int ni_E_init(struct comedi_device *dev,
if (devpriv->mite)
s->async_dma_dir = DMA_FROM_DEVICE;
}
+
+   /* reset the analog input configuration */
+   ni_ai_reset(dev, s);
} else {
s->type = COMEDI_SUBD_UNUSED;
}
@@ -5582,6 +5585,9 @@ static int ni_E_init(struct comedi_device *dev,
 
if (devpriv->is_67xx)
init_ao_67xx(dev, s);
+
+   /* reset the analog output configuration */
+   ni_ao_reset(dev, s);
} else {
s->type = COMEDI_SUBD_UNUSED;
}
@@ -5779,14 +5785,6 @@ static int ni_E_init(struct comedi_device *dev,
s->insn_write = &ni_freq_out_insn_write;
s->insn_config = &ni_freq_out_insn_config;
 
-   /* ai configuration */
-   s = &dev->subdevices[NI_AI_SUBDEV];
-   ni_ai_reset(dev, s);
-
-   /* analog output configuration */
-   s = &dev->subdevices[NI_AO_SUBDEV];
-   ni_ao_reset(dev, s);
-
if (dev->irq) {
ni_stc_writew(dev,
  (irq_polarity ? Interrupt_Output_Polarity : 0) |
-- 
1.9.3

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


[PATCH 24/28] staging: comedi: ni_mio_common: tidy up the calibration subdevice init

2014-07-14 Thread H Hartley Sweeten
For aesthetics, add some whitespace to the subdevice init.

Refactor the code so that the common parts of the subdevice are initialized
in one place.

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

diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c 
b/drivers/staging/comedi/drivers/ni_mio_common.c
index e60b9e6..49c22d6 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -5642,26 +5642,26 @@ static int ni_E_init(struct comedi_device *dev,
s = &dev->subdevices[NI_UNUSED_SUBDEV];
s->type = COMEDI_SUBD_UNUSED;
 
-   /* calibration subdevice -- ai and ao */
+   /* Calibration subdevice */
s = &dev->subdevices[NI_CALIBRATION_SUBDEV];
-   s->type = COMEDI_SUBD_CALIB;
+   s->type = COMEDI_SUBD_CALIB;
+   s->subdev_flags = SDF_INTERNAL;
+   s->n_chan   = 1;
+   s->maxdata  = 0;
if (devpriv->is_m_series) {
-   /*  internal PWM analog output used for AI nonlinearity 
calibration */
-   s->subdev_flags = SDF_INTERNAL;
-   s->insn_config = &ni_m_series_pwm_config;
-   s->n_chan = 1;
-   s->maxdata = 0;
+   /* internal PWM output used for AI nonlinearity calibration */
+   s->insn_config  = ni_m_series_pwm_config;
+
ni_writel(dev, 0x0, M_Offset_Cal_PWM);
} else if (devpriv->is_6143) {
-   /*  internal PWM analog output used for AI nonlinearity 
calibration */
-   s->subdev_flags = SDF_INTERNAL;
-   s->insn_config = &ni_6143_pwm_config;
-   s->n_chan = 1;
-   s->maxdata = 0;
+   /* internal PWM output used for AI nonlinearity calibration */
+   s->insn_config  = ni_6143_pwm_config;
} else {
-   s->subdev_flags = SDF_WRITABLE | SDF_INTERNAL;
-   s->insn_read = &ni_calib_insn_read;
-   s->insn_write = &ni_calib_insn_write;
+   s->subdev_flags |= SDF_WRITABLE;
+   s->insn_read= ni_calib_insn_read;
+   s->insn_write   = ni_calib_insn_write;
+
+   /* setup the caldacs and find the real n_chan and maxdata */
caldac_setup(dev, s);
}
 
-- 
1.9.3

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


[PATCH 27/28] staging: comedi: ni_mio_common: tidy up the gpct counter subdevice init

2014-07-14 Thread H Hartley Sweeten
For aesthetics, add some whitespace to the subdevice init and
tidy it up a bit.

Unfortunately we can't get rid of the '#ifdef PCIDMA' here yet due
to other ifdefery in this file. For now just add the correct test
so that the async command support is not hooked up unless we have
an IRQ and DMA.

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

diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c 
b/drivers/staging/comedi/drivers/ni_mio_common.c
index 4932b4db..6545f11 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -5490,7 +5490,6 @@ static int ni_E_init(struct comedi_device *dev,
const struct ni_board_struct *board = comedi_board(dev);
struct ni_private *devpriv = dev->private;
struct comedi_subdevice *s;
-   enum ni_gpct_variant counter_variant;
int ret;
int i;
 
@@ -5735,44 +5734,47 @@ static int ni_E_init(struct comedi_device *dev,
s->insn_config = ni_rtsi_insn_config;
ni_rtsi_init(dev);
 
-   if (devpriv->is_m_series)
-   counter_variant = ni_gpct_variant_m_series;
-   else
-   counter_variant = ni_gpct_variant_e_series;
+   /* allocate and initialize the gpct counter device */
devpriv->counter_dev = ni_gpct_device_construct(dev,
-   &ni_gpct_write_register,
-   &ni_gpct_read_register,
-   counter_variant,
-   NUM_GPCT);
+   ni_gpct_write_register,
+   ni_gpct_read_register,
+   (devpriv->is_m_series)
+   ? ni_gpct_variant_m_series
+   : ni_gpct_variant_e_series,
+   NUM_GPCT);
if (!devpriv->counter_dev)
return -ENOMEM;
 
-   /* General purpose counters */
+   /* Counter (gpct) subdevices */
for (i = 0; i < NUM_GPCT; ++i) {
+   struct ni_gpct *gpct = &devpriv->counter_dev->counters[i];
+
+   /* setup and initialize the counter */
+   gpct->chip_index = 0;
+   gpct->counter_index = i;
+   ni_tio_init_counter(gpct);
+
s = &dev->subdevices[NI_GPCT_SUBDEV(i)];
-   s->type = COMEDI_SUBD_COUNTER;
-   s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_LSAMPL;
-   s->n_chan = 3;
-   if (devpriv->is_m_series)
-   s->maxdata = 0x;
-   else
-   s->maxdata = 0xff;
-   s->insn_read = ni_tio_insn_read;
-   s->insn_write = ni_tio_insn_read;
-   s->insn_config = ni_tio_insn_config;
+   s->type = COMEDI_SUBD_COUNTER;
+   s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_LSAMPL;
+   s->n_chan   = 3;
+   s->maxdata  = (devpriv->is_m_series) ? 0x
+: 0x00ff;
+   s->insn_read= ni_tio_insn_read;
+   s->insn_write   = ni_tio_insn_read;
+   s->insn_config  = ni_tio_insn_config;
 #ifdef PCIDMA
-   s->subdev_flags |= SDF_CMD_READ /* | SDF_CMD_WRITE */;
-   s->do_cmd = &ni_gpct_cmd;
-   s->len_chanlist = 1;
-   s->do_cmdtest = ni_tio_cmdtest;
-   s->cancel = &ni_gpct_cancel;
-   s->async_dma_dir = DMA_BIDIRECTIONAL;
-#endif
-   s->private = &devpriv->counter_dev->counters[i];
+   if (dev->irq && devpriv->mite) {
+   s->subdev_flags |= SDF_CMD_READ /* | SDF_CMD_WRITE */;
+   s->len_chanlist = 1;
+   s->do_cmdtest   = ni_tio_cmdtest;
+   s->do_cmd   = ni_gpct_cmd;
+   s->cancel   = ni_gpct_cancel;
 
-   devpriv->counter_dev->counters[i].chip_index = 0;
-   devpriv->counter_dev->counters[i].counter_index = i;
-   ni_tio_init_counter(&devpriv->counter_dev->counters[i]);
+   s->async_dma_dir = DMA_BIDIRECTIONAL;
+   }
+#endif
+   s->private  = gpct;
}
 
/* Frequency output */
-- 
1.9.3

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


[PATCH 26/28] staging: comedi: ni_mio_common: tidy up the PFI subdevice init

2014-07-14 Thread H Hartley Sweeten
For aesthetics, add some whitespace to the subdevice init and
tidy it up a bit.

Remove the need for the extra local variable.

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

diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c 
b/drivers/staging/comedi/drivers/ni_mio_common.c
index 8f7edcd..4932b4db 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -5490,9 +5490,9 @@ static int ni_E_init(struct comedi_device *dev,
const struct ni_board_struct *board = comedi_board(dev);
struct ni_private *devpriv = dev->private;
struct comedi_subdevice *s;
-   unsigned j;
enum ni_gpct_variant counter_variant;
int ret;
+   int i;
 
if (board->n_aochan > MAX_N_AO_CHAN) {
printk("bug! n_aochan > MAX_N_AO_CHAN\n");
@@ -5678,25 +5678,25 @@ static int ni_E_init(struct comedi_device *dev,
s->insn_read= ni_eeprom_insn_read;
}
 
-   /* PFI */
+   /* Digital I/O (PFI) subdevice */
s = &dev->subdevices[NI_PFI_DIO_SUBDEV];
-   s->type = COMEDI_SUBD_DIO;
-   s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL;
+   s->type = COMEDI_SUBD_DIO;
+   s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL;
+   s->maxdata  = 1;
if (devpriv->is_m_series) {
-   unsigned i;
-   s->n_chan = 16;
+   s->n_chan   = 16;
+   s->insn_bits= ni_pfi_insn_bits;
+
ni_writew(dev, s->state, M_Offset_PFI_DO);
for (i = 0; i < NUM_PFI_OUTPUT_SELECT_REGS; ++i) {
ni_writew(dev, devpriv->pfi_output_select_reg[i],
  M_Offset_PFI_Output_Select(i + 1));
}
} else {
-   s->n_chan = 10;
+   s->n_chan   = 10;
}
-   s->maxdata = 1;
-   if (devpriv->is_m_series)
-   s->insn_bits = &ni_pfi_insn_bits;
-   s->insn_config = &ni_pfi_insn_config;
+   s->insn_config  = ni_pfi_insn_config;
+
ni_set_bits(dev, IO_Bidirection_Pin_Register, ~0, 0);
 
/* cs5529 calibration adc */
@@ -5748,8 +5748,8 @@ static int ni_E_init(struct comedi_device *dev,
return -ENOMEM;
 
/* General purpose counters */
-   for (j = 0; j < NUM_GPCT; ++j) {
-   s = &dev->subdevices[NI_GPCT_SUBDEV(j)];
+   for (i = 0; i < NUM_GPCT; ++i) {
+   s = &dev->subdevices[NI_GPCT_SUBDEV(i)];
s->type = COMEDI_SUBD_COUNTER;
s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_LSAMPL;
s->n_chan = 3;
@@ -5768,11 +5768,11 @@ static int ni_E_init(struct comedi_device *dev,
s->cancel = &ni_gpct_cancel;
s->async_dma_dir = DMA_BIDIRECTIONAL;
 #endif
-   s->private = &devpriv->counter_dev->counters[j];
+   s->private = &devpriv->counter_dev->counters[i];
 
-   devpriv->counter_dev->counters[j].chip_index = 0;
-   devpriv->counter_dev->counters[j].counter_index = j;
-   ni_tio_init_counter(&devpriv->counter_dev->counters[j]);
+   devpriv->counter_dev->counters[i].chip_index = 0;
+   devpriv->counter_dev->counters[i].counter_index = i;
+   ni_tio_init_counter(&devpriv->counter_dev->counters[i]);
}
 
/* Frequency output */
-- 
1.9.3

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


[PATCH 20/28] staging: comedi: ni_mio_common: refactor 'num_p0_dio_channels' boardinfo

2014-07-14 Thread H Hartley Sweeten
All of the board supported by this driver have at least 8 Digital I/O
channels. A couple of the PCI boards in ni_pcimio have 32 channels.

For aesthetics, change this member of the boardinfo into a bit-field
flag, 'has_32dio_chan', and use that when initializing the DIO subdevice
to set the number of channels to 32 or 8.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_atmio.c  |  8 ---
 drivers/staging/comedi/drivers/ni_mio_common.c |  2 +-
 drivers/staging/comedi/drivers/ni_mio_cs.c |  6 ---
 drivers/staging/comedi/drivers/ni_pcimio.c | 67 --
 drivers/staging/comedi/drivers/ni_stc.h|  3 +-
 5 files changed, 12 insertions(+), 74 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_atmio.c 
b/drivers/staging/comedi/drivers/ni_atmio.c
index 3858061..c613423 100644
--- a/drivers/staging/comedi/drivers/ni_atmio.c
+++ b/drivers/staging/comedi/drivers/ni_atmio.c
@@ -117,7 +117,6 @@ static const struct ni_board_struct ni_boards[] = {
.ao_fifo_depth  = 2048,
.ao_range_table = &range_ni_E_ao_ext,
.ao_speed   = 1000,
-   .num_p0_dio_channels = 8,
.caldac = { mb88341 },
}, {
.name   = "at-mio-16e-2",
@@ -133,7 +132,6 @@ static const struct ni_board_struct ni_boards[] = {
.ao_fifo_depth  = 2048,
.ao_range_table = &range_ni_E_ao_ext,
.ao_speed   = 1000,
-   .num_p0_dio_channels = 8,
.caldac = { mb88341 },
}, {
.name   = "at-mio-16e-10",
@@ -148,7 +146,6 @@ static const struct ni_board_struct ni_boards[] = {
.ao_maxdata = 0x0fff,
.ao_range_table = &range_ni_E_ao_ext,
.ao_speed   = 1,
-   .num_p0_dio_channels = 8,
.caldac = { ad8804_debug },
}, {
.name   = "at-mio-16de-10",
@@ -163,7 +160,6 @@ static const struct ni_board_struct ni_boards[] = {
.ao_maxdata = 0x0fff,
.ao_range_table = &range_ni_E_ao_ext,
.ao_speed   = 1,
-   .num_p0_dio_channels = 8,
.caldac = { ad8804_debug },
.has_8255   = 1,
}, {
@@ -180,7 +176,6 @@ static const struct ni_board_struct ni_boards[] = {
.ao_fifo_depth  = 2048,
.ao_range_table = &range_ni_E_ao_ext,
.ao_speed   = 1000,
-   .num_p0_dio_channels = 8,
.caldac = { ad8804_debug },
}, {
.name   = "at-mio-16xe-50",
@@ -196,7 +191,6 @@ static const struct ni_board_struct ni_boards[] = {
.ao_maxdata = 0x0fff,
.ao_range_table = &range_bipolar10,
.ao_speed   = 5,
-   .num_p0_dio_channels = 8,
.caldac = { dac8800, dac8043 },
}, {
.name   = "at-mio-16xe-10",
@@ -213,7 +207,6 @@ static const struct ni_board_struct ni_boards[] = {
.ao_fifo_depth  = 2048,
.ao_range_table = &range_ni_E_ao_ext,
.ao_speed   = 1000,
-   .num_p0_dio_channels = 8,
.caldac = { dac8800, dac8043, ad8522 },
}, {
.name   = "at-ai-16xe-10",
@@ -225,7 +218,6 @@ static const struct ni_board_struct ni_boards[] = {
.alwaysdither   = 1,/* unknown */
.gainlkup   = ai_gain_14,
.ai_speed   = 1,
-   .num_p0_dio_channels = 8,
.caldac = { dac8800, dac8043, ad8522 },
},
 };
diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c 
b/drivers/staging/comedi/drivers/ni_mio_common.c
index 91b3fb4..7146f21 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -5582,7 +5582,7 @@ static int ni_E_init(struct comedi_device *dev,
s->maxdata = 1;
s->io_bits = 0; /* all bits input */
s->range_table = &range_digital;
-   s->n_chan = board->num_p0_dio_channels;
+   s->n_chan = board->has_32dio_chan ? 32 : 8;
if (devpriv->is_m_series) {
s->subdev_flags |=
SDF_LSAMPL | SDF_CMD_WRITE /* | SDF_CMD_READ */;
diff --git a/drivers/staging/comedi/drivers/ni_mio_cs.c 
b/drivers/staging/comedi/drivers/ni_mio_cs.c
index bb414ec..9b201e4 100644
--- a/drivers/staging/comedi/drivers/ni_mio_cs.c
+++ b/drivers/staging/comedi/drivers/ni_mio_cs.c
@@ -60,7 +60,6 @@ static const struct ni_board_struct ni_boards[] = {
.ai_fifo_depth  = 1024,
.gainlkup   = ai_gain_8,
.ai_speed   = 5000,
-   .num_p0_dio_ch

[PATCH 28/28] staging: comedi: ni_mio_common: tidy up the frequency output subdevice init

2014-07-14 Thread H Hartley Sweeten
For aesthetics, add some whitespace to the subdevice init.

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

diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c 
b/drivers/staging/comedi/drivers/ni_mio_common.c
index 6545f11..01b29d5 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -5777,15 +5777,15 @@ static int ni_E_init(struct comedi_device *dev,
s->private  = gpct;
}
 
-   /* Frequency output */
+   /* Frequency output subdevice */
s = &dev->subdevices[NI_FREQ_OUT_SUBDEV];
-   s->type = COMEDI_SUBD_COUNTER;
-   s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
-   s->n_chan = 1;
-   s->maxdata = 0xf;
-   s->insn_read = &ni_freq_out_insn_read;
-   s->insn_write = &ni_freq_out_insn_write;
-   s->insn_config = &ni_freq_out_insn_config;
+   s->type = COMEDI_SUBD_COUNTER;
+   s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
+   s->n_chan   = 1;
+   s->maxdata  = 0xf;
+   s->insn_read= ni_freq_out_insn_read;
+   s->insn_write   = ni_freq_out_insn_write;
+   s->insn_config  = ni_freq_out_insn_config;
 
if (dev->irq) {
ni_stc_writew(dev,
-- 
1.9.3

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


[PATCH 03/28] staging: comedi: ni_stc.h: remove 'ao_unipolar' flag from ni_board_struct

2014-07-14 Thread H Hartley Sweeten
This member of the boardinfo for the NI MIO drivers is used to indicate if
the ranges for the analog output subdevice (ao_range_table in the boardinfo)
includes any unipolar ranges. If it's not set, the ao_range_table only has
bipolar ranges.

The 'ao_unipolar' flag is checked when munging the ao data values from the
user so that the values for bipolar ranges are converted to 2's complement
values before they are written to the hardware.

The flag is also used when programming the analog output configuration on
non-M series boards for bipolar/unipolar and external reference operation.

Simplify the driver a bit by removing this boardinfo flag and just using
the comedi_range_is_bipolar() and comedi_range_is_external() helpers to
check the range directly.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_atmio.c  |  6 --
 drivers/staging/comedi/drivers/ni_mio_common.c | 18 +++---
 drivers/staging/comedi/drivers/ni_pcimio.c | 16 
 drivers/staging/comedi/drivers/ni_stc.h|  1 -
 4 files changed, 7 insertions(+), 34 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_atmio.c 
b/drivers/staging/comedi/drivers/ni_atmio.c
index d7ee6bd..0f4dc5a 100644
--- a/drivers/staging/comedi/drivers/ni_atmio.c
+++ b/drivers/staging/comedi/drivers/ni_atmio.c
@@ -116,7 +116,6 @@ static const struct ni_board_struct ni_boards[] = {
.aobits = 12,
.ao_fifo_depth  = 2048,
.ao_range_table = &range_ni_E_ao_ext,
-   .ao_unipolar= 1,
.ao_speed   = 1000,
.num_p0_dio_channels = 8,
.caldac = { mb88341 },
@@ -133,7 +132,6 @@ static const struct ni_board_struct ni_boards[] = {
.aobits = 12,
.ao_fifo_depth  = 2048,
.ao_range_table = &range_ni_E_ao_ext,
-   .ao_unipolar= 1,
.ao_speed   = 1000,
.num_p0_dio_channels = 8,
.caldac = { mb88341 },
@@ -149,7 +147,6 @@ static const struct ni_board_struct ni_boards[] = {
.n_aochan   = 2,
.aobits = 12,
.ao_range_table = &range_ni_E_ao_ext,
-   .ao_unipolar= 1,
.ao_speed   = 1,
.num_p0_dio_channels = 8,
.caldac = { ad8804_debug },
@@ -165,7 +162,6 @@ static const struct ni_board_struct ni_boards[] = {
.n_aochan   = 2,
.aobits = 12,
.ao_range_table = &range_ni_E_ao_ext,
-   .ao_unipolar= 1,
.ao_speed   = 1,
.num_p0_dio_channels = 8,
.caldac = { ad8804_debug },
@@ -183,7 +179,6 @@ static const struct ni_board_struct ni_boards[] = {
.aobits = 12,
.ao_fifo_depth  = 2048,
.ao_range_table = &range_ni_E_ao_ext,
-   .ao_unipolar= 1,
.ao_speed   = 1000,
.num_p0_dio_channels = 8,
.caldac = { ad8804_debug },
@@ -217,7 +212,6 @@ static const struct ni_board_struct ni_boards[] = {
.aobits = 16,
.ao_fifo_depth  = 2048,
.ao_range_table = &range_ni_E_ao_ext,
-   .ao_unipolar= 1,
.ao_speed   = 1000,
.num_p0_dio_channels = 8,
.caldac = { dac8800, dac8043, ad8522 },
diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c 
b/drivers/staging/comedi/drivers/ni_mio_common.c
index ff881a7..471d7af 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -2925,7 +2925,8 @@ static void ni_ao_munge(struct comedi_device *dev, struct 
comedi_subdevice *s,
 
for (i = 0; i < length; i++) {
range = CR_RANGE(cmd->chanlist[chan_index]);
-   if (board->ao_unipolar == 0 || (range & 1) == 0)
+
+   if (comedi_range_is_bipolar(s, range))
array[i] -= offset;
 #ifdef PCIDMA
array[i] = cpu_to_le16(array[i]);
@@ -3028,19 +3029,14 @@ static int ni_old_ao_config_chanlist(struct 
comedi_device *dev,
range = CR_RANGE(chanspec[i]);
conf = AO_Channel(chan);
 
-   if (board->ao_unipolar) {
-   if ((range & 1) == 0) {
-   conf |= AO_Bipolar;
-   invert = (1 << (board->aobits - 1));
-   } else {
-   invert = 0;
-   }
-   if (range & 2)
-   conf |= AO_Ext_Ref;
-   } else {
+   if (comedi_range_is_bipolar(s, range)) {
co

[PATCH 18/28] staging: comedi: ni_mio_common: tidy up the Analog Input subdevice init

2014-07-14 Thread H Hartley Sweeten
For aesthetics, add some whitespace to the Analog Input subdevice init.

The callers of ni_E_init() do the request_irq() and set dev->irq if the
interrupt is available. Only hook up the async command support if we
have the irq.

Also, remove the '#ifdef PCIDMA' here. The ni_pcimio driver is the only
place PCIDMA is defined. That driver is also the only user of ni_mio_common
that allocates devpriv->mite. Use that test instead to determine if the
subdevice async_dma_dir member needs to be initialized.

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

diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c 
b/drivers/staging/comedi/drivers/ni_mio_common.c
index 2ab267b..800f4e3 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -5503,36 +5503,37 @@ static int ni_E_init(struct comedi_device *dev,
if (ret)
return ret;
 
-   /* analog input subdevice */
-
+   /* Analog Input subdevice */
s = &dev->subdevices[NI_AI_SUBDEV];
-   dev->read_subdev = s;
if (board->n_adchan) {
-   s->type = COMEDI_SUBD_AI;
-   s->subdev_flags =
-   SDF_READABLE | SDF_DIFF | SDF_DITHER | SDF_CMD_READ;
+   s->type = COMEDI_SUBD_AI;
+   s->subdev_flags = SDF_READABLE | SDF_DIFF | SDF_DITHER;
if (!devpriv->is_611x)
-   s->subdev_flags |= SDF_GROUND | SDF_COMMON | SDF_OTHER;
+   s->subdev_flags |= SDF_GROUND | SDF_COMMON | SDF_OTHER;
if (board->ai_maxdata > 0x)
-   s->subdev_flags |= SDF_LSAMPL;
+   s->subdev_flags |= SDF_LSAMPL;
if (devpriv->is_m_series)
-   s->subdev_flags |= SDF_SOFT_CALIBRATED;
-   s->n_chan = board->n_adchan;
-   s->len_chanlist = 512;
-   s->maxdata = board->ai_maxdata;
-   s->range_table = ni_range_lkup[board->gainlkup];
-   s->insn_read = &ni_ai_insn_read;
-   s->insn_config = &ni_ai_insn_config;
-   s->do_cmdtest = &ni_ai_cmdtest;
-   s->do_cmd = &ni_ai_cmd;
-   s->cancel = &ni_ai_reset;
-   s->poll = &ni_ai_poll;
-   s->munge = &ni_ai_munge;
-#ifdef PCIDMA
-   s->async_dma_dir = DMA_FROM_DEVICE;
-#endif
+   s->subdev_flags |= SDF_SOFT_CALIBRATED;
+   s->n_chan   = board->n_adchan;
+   s->maxdata  = board->ai_maxdata;
+   s->range_table  = ni_range_lkup[board->gainlkup];
+   s->insn_read= ni_ai_insn_read;
+   s->insn_config  = ni_ai_insn_config;
+   if (dev->irq) {
+   dev->read_subdev = s;
+   s->subdev_flags |= SDF_CMD_READ;
+   s->len_chanlist = 512;
+   s->do_cmdtest   = ni_ai_cmdtest;
+   s->do_cmd   = ni_ai_cmd;
+   s->cancel   = ni_ai_reset;
+   s->poll = ni_ai_poll;
+   s->munge= ni_ai_munge;
+
+   if (devpriv->mite)
+   s->async_dma_dir = DMA_FROM_DEVICE;
+   }
} else {
-   s->type = COMEDI_SUBD_UNUSED;
+   s->type = COMEDI_SUBD_UNUSED;
}
 
/* analog output subdevice */
-- 
1.9.3

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


[PATCH 08/28] staging: comedi: ni_mio_common: tidy up ni_ao_munge()

2014-07-14 Thread H Hartley Sweeten
Use the bytes_per_sample() helper instead of 'sizeof(short)' to clarify
the length calculation.

Use comedi_offset_munge() to handle the unsigned to two's complement
munge of the data for bipolar ranges.

Tidy up the local variables.

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

diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c 
b/drivers/staging/comedi/drivers/ni_mio_common.c
index b5b4a7b7..13270b3 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -2886,28 +2886,30 @@ static int ni_ai_insn_config(struct comedi_device *dev,
return -EINVAL;
 }
 
-/* munge data from unsigned to 2's complement for analog output bipolar modes 
*/
 static void ni_ao_munge(struct comedi_device *dev, struct comedi_subdevice *s,
void *data, unsigned int num_bytes,
unsigned int chan_index)
 {
-   const struct ni_board_struct *board = comedi_board(dev);
-   struct comedi_async *async = s->async;
-   struct comedi_cmd *cmd = &async->cmd;
-   unsigned int length = num_bytes / sizeof(short);
-   unsigned int offset = 1 << (board->aobits - 1);
+   struct comedi_cmd *cmd = &s->async->cmd;
+   unsigned int length = num_bytes / bytes_per_sample(s);
unsigned short *array = data;
-   unsigned int range;
unsigned int i;
 
for (i = 0; i < length; i++) {
-   range = CR_RANGE(cmd->chanlist[chan_index]);
+   unsigned int range = CR_RANGE(cmd->chanlist[chan_index]);
+   unsigned short val = array[i];
 
+   /*
+* Munge data from unsigned to two's complement for
+* bipolar ranges.
+*/
if (comedi_range_is_bipolar(s, range))
-   array[i] -= offset;
+   val = comedi_offset_munge(s, val);
 #ifdef PCIDMA
-   array[i] = cpu_to_le16(array[i]);
+   val = cpu_to_le16(val);
 #endif
+   array[i] = val;
+
chan_index++;
chan_index %= cmd->chanlist_len;
}
-- 
1.9.3

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


[PATCH 00/28] staging: comedi: ni_mio_common: more cleanup

2014-07-14 Thread H Hartley Sweeten
The ni_mio_common.c file is included by a number of National Instruments
drivers to provide the "common" driver support. This series does some
more cleanup to get the file closer to being changed into a module instead
of including it in the drivers.

H Hartley Sweeten (28):
  staging: comedi: mite.h: tidy up the mite channel register offsets
  staging: comedi: comedidev.h: introduce some 'range_is_external' helpers
  staging: comedi: ni_stc.h: remove 'ao_unipolar' flag from ni_board_struct
  staging: comedi: ni_mio_common: fix ni_ao_insn_write_671x()
  staging: comedi: ni_mio_common: remove ao_win_out() macro
  staging: comedi: ni_mio_common: fix ni_ao_insn_write()
  staging: comedi: ni_stc.h: add some 'is_{board type}' flags to private data
  staging: comedi: ni_mio_common: tidy up ni_ao_munge()
  staging: comedi: ni_mio_common: remove INSN_CONFIG_ANALOG_TRIG support code
  staging: comedi: ni_mio_common: remove some unnecessary boardinfo access
  staging: comedi: ni_mio_common: merge analog output (*insn_write) functions
  staging: comedi: ni_mio_common: remove ai_continuous from private data
  staging: comedi: ni_mio_common: fix ni_ao_insn_read()
  staging: comedi: ni_mio_common: remove unnecessary use of 'board->adbits'
  staging: comedi: ni_stc.h: refactor 'adbits' boardinfo
  staging: comedi: ni_stc.h: refactor 'aobits' boardinfo
  staging: comedi: ni_mio_common: (*cancel) only works with async cmd support
  staging: comedi: ni_mio_common: tidy up the Analog Input subdevice init
  staging: comedi: ni_mio_common: tidy up the Analog Output subdevice init
  staging: comedi: ni_mio_common: refactor 'num_p0_dio_channels' boardinfo
  staging: comedi: ni_mio_common: tidy up the Digital I/O subdevice init
  staging: comedi: ni_mio_common: init clock dividers early in ni_E_init()
  staging: comedi: ni_mio_common: only reset the ai/ao subdevices if they exist
  staging: comedi: ni_mio_common: tidy up the calibration subdevice init
  staging: comedi: ni_mio_common: tidy up the EEPROM subdevice init
  staging: comedi: ni_mio_common: tidy up the PFI subdevice init
  staging: comedi: ni_mio_common: tidy up the gpct counter subdevice init
  staging: comedi: ni_mio_common: tidy up the frequency output subdevice init

 drivers/staging/comedi/comedidev.h |  13 +
 drivers/staging/comedi/drivers/mite.h  | 106 +---
 drivers/staging/comedi/drivers/ni_atmio.c  |  44 +-
 drivers/staging/comedi/drivers/ni_mio_common.c | 753 +++--
 drivers/staging/comedi/drivers/ni_mio_cs.c |  24 +-
 drivers/staging/comedi/drivers/ni_pcimio.c | 289 --
 drivers/staging/comedi/drivers/ni_stc.h|  24 +-
 7 files changed, 508 insertions(+), 745 deletions(-)

-- 
1.9.3

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


[PATCH 19/28] staging: comedi: ni_mio_common: tidy up the Analog Output subdevice init

2014-07-14 Thread H Hartley Sweeten
For aesthetics, add some whitespace to the Analog Output subdevice init.

Also, remove the '#ifdef PCIDMA' here and only hook up the async command
support if we have an irq and the board either has a fifo or DMA is
supported.

The ni_pcimio driver is the only place PCIDMA is defined. That driver
is also the only user of ni_mio_common that allocates devpriv->mite. Use
that test instead to determine if dma is supported.

Move 'is_67xx' check and init_ao_67xx() call into the Analog Output
subdevice init. The 67xx boards all have analog outputs and this check
does not need to be done for the boards that do not have analog outputs.

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

diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c 
b/drivers/staging/comedi/drivers/ni_mio_common.c
index 800f4e3..91b3fb4 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -5536,40 +5536,43 @@ static int ni_E_init(struct comedi_device *dev,
s->type = COMEDI_SUBD_UNUSED;
}
 
-   /* analog output subdevice */
-
+   /* Analog Output subdevice */
s = &dev->subdevices[NI_AO_SUBDEV];
if (board->n_aochan) {
-   s->type = COMEDI_SUBD_AO;
-   s->subdev_flags = SDF_WRITABLE | SDF_DEGLITCH | SDF_GROUND;
+   s->type = COMEDI_SUBD_AO;
+   s->subdev_flags = SDF_WRITABLE | SDF_DEGLITCH | SDF_GROUND;
if (devpriv->is_m_series)
-   s->subdev_flags |= SDF_SOFT_CALIBRATED;
-   s->n_chan = board->n_aochan;
-   s->maxdata = board->ao_maxdata;
-   s->range_table = board->ao_range_table;
-   s->insn_read = &ni_ao_insn_read;
-   s->insn_write = &ni_ao_insn_write;
-   s->insn_config = &ni_ao_insn_config;
-#ifdef PCIDMA
-   if (board->n_aochan) {
-   s->async_dma_dir = DMA_TO_DEVICE;
-#else
-   if (board->ao_fifo_depth) {
-#endif
+   s->subdev_flags |= SDF_SOFT_CALIBRATED;
+   s->n_chan   = board->n_aochan;
+   s->maxdata  = board->ao_maxdata;
+   s->range_table  = board->ao_range_table;
+   s->insn_read= ni_ao_insn_read;
+   s->insn_write   = ni_ao_insn_write;
+   s->insn_config  = ni_ao_insn_config;
+
+   /*
+* Along with the IRQ we need either a FIFO or DMA for
+* async command support.
+*/
+   if (dev->irq && (board->ao_fifo_depth || devpriv->mite)) {
dev->write_subdev = s;
-   s->subdev_flags |= SDF_CMD_WRITE;
-   s->do_cmd = &ni_ao_cmd;
-   s->do_cmdtest = &ni_ao_cmdtest;
-   s->cancel = &ni_ao_reset;
-   s->len_chanlist = board->n_aochan;
+   s->subdev_flags |= SDF_CMD_WRITE;
+   s->len_chanlist = s->n_chan;
+   s->do_cmdtest   = ni_ao_cmdtest;
+   s->do_cmd   = ni_ao_cmd;
+   s->cancel   = ni_ao_reset;
if (!devpriv->is_m_series)
-   s->munge = ni_ao_munge;
+   s->munge= ni_ao_munge;
+
+   if (devpriv->mite)
+   s->async_dma_dir = DMA_TO_DEVICE;
}
+
+   if (devpriv->is_67xx)
+   init_ao_67xx(dev, s);
} else {
-   s->type = COMEDI_SUBD_UNUSED;
+   s->type = COMEDI_SUBD_UNUSED;
}
-   if (devpriv->is_67xx)
-   init_ao_67xx(dev, s);
 
/* digital i/o subdevice */
 
-- 
1.9.3

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


[PATCH 25/28] staging: comedi: ni_mio_common: tidy up the EEPROM subdevice init

2014-07-14 Thread H Hartley Sweeten
For aesthetics, add some whitespace to the subdevice init.

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

diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c 
b/drivers/staging/comedi/drivers/ni_mio_common.c
index 49c22d6..8f7edcd 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -5665,17 +5665,17 @@ static int ni_E_init(struct comedi_device *dev,
caldac_setup(dev, s);
}
 
-   /* EEPROM */
+   /* EEPROM subdevice */
s = &dev->subdevices[NI_EEPROM_SUBDEV];
-   s->type = COMEDI_SUBD_MEMORY;
-   s->subdev_flags = SDF_READABLE | SDF_INTERNAL;
-   s->maxdata = 0xff;
+   s->type = COMEDI_SUBD_MEMORY;
+   s->subdev_flags = SDF_READABLE | SDF_INTERNAL;
+   s->maxdata  = 0xff;
if (devpriv->is_m_series) {
-   s->n_chan = M_SERIES_EEPROM_SIZE;
-   s->insn_read = &ni_m_series_eeprom_insn_read;
+   s->n_chan   = M_SERIES_EEPROM_SIZE;
+   s->insn_read= ni_m_series_eeprom_insn_read;
} else {
-   s->n_chan = 512;
-   s->insn_read = &ni_eeprom_insn_read;
+   s->n_chan   = 512;
+   s->insn_read= ni_eeprom_insn_read;
}
 
/* PFI */
-- 
1.9.3

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


[PATCH 09/28] staging: comedi: ni_mio_common: remove INSN_CONFIG_ANALOG_TRIG support code

2014-07-14 Thread H Hartley Sweeten
None of the boardinfo that uses this code sets the 'has_analog_trig' flag so
ni_ai_config_analog_trig() always returns -EINVAL.

Also, the private data 'atrig_low', 'atrig_high', and 'atrig_mode' values
that are set by ni_ai_config_analog_trig() are never used.

Remove the incomplete INSN_CONFIG_ANALOG_TRIG support along with the unused
boardinfo and private data members.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_mio_common.c | 102 -
 drivers/staging/comedi/drivers/ni_stc.h|   5 --
 2 files changed, 107 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c 
b/drivers/staging/comedi/drivers/ni_mio_common.c
index 13270b3..8854f18 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -2732,106 +2732,6 @@ static int ni_ai_cmd(struct comedi_device *dev, struct 
comedi_subdevice *s)
return 0;
 }
 
-static int ni_ai_config_analog_trig(struct comedi_device *dev,
-   struct comedi_subdevice *s,
-   struct comedi_insn *insn,
-   unsigned int *data)
-{
-   const struct ni_board_struct *board = comedi_board(dev);
-   struct ni_private *devpriv = dev->private;
-   unsigned int a, b, modebits;
-   int err = 0;
-
-   /* data[1] is flags
-* data[2] is analog line
-* data[3] is set level
-* data[4] is reset level */
-   if (!board->has_analog_trig)
-   return -EINVAL;
-   if ((data[1] & 0x) != COMEDI_EV_SCAN_BEGIN) {
-   data[1] &= (COMEDI_EV_SCAN_BEGIN | 0x);
-   err++;
-   }
-   if (data[2] >= board->n_adchan) {
-   data[2] = board->n_adchan - 1;
-   err++;
-   }
-   if (data[3] > 255) {/* a */
-   data[3] = 255;
-   err++;
-   }
-   if (data[4] > 255) {/* b */
-   data[4] = 255;
-   err++;
-   }
-   /*
-* 00 ignore
-* 01 set
-* 10 reset
-*
-* modes:
-*   1 level:+b-   +a-
-* high mode00 00 01 10
-* low mode 00 00 10 01
-*   2 level: (a> 4);
-   }
-   devpriv->atrig_low = a;
-   devpriv->atrig_high = b;
-   switch (modebits) {
-   case 0x81:  /* low hysteresis mode */
-   devpriv->atrig_mode = 6;
-   break;
-   case 0x42:  /* high hysteresis mode */
-   devpriv->atrig_mode = 3;
-   break;
-   case 0x96:  /* middle window mode */
-   devpriv->atrig_mode = 2;
-   break;
-   default:
-   data[1] &= ~0xff;
-   err++;
-   }
-   } else {
-   /* one level mode */
-   if (b != 0) {
-   data[4] = 0;
-   err++;
-   }
-   switch (modebits) {
-   case 0x06:  /* high window mode */
-   devpriv->atrig_high = a;
-   devpriv->atrig_mode = 0;
-   break;
-   case 0x09:  /* low window mode */
-   devpriv->atrig_low = a;
-   devpriv->atrig_mode = 1;
-   break;
-   default:
-   data[1] &= ~0xff;
-   err++;
-   }
-   }
-   if (err)
-   return -EAGAIN;
-   return 5;
-}
-
 static int ni_ai_insn_config(struct comedi_device *dev,
 struct comedi_subdevice *s,
 struct comedi_insn *insn, unsigned int *data)
@@ -2842,8 +2742,6 @@ static int ni_ai_insn_config(struct comedi_device *dev,
return -EINVAL;
 
switch (data[0]) {
-   case INSN_CONFIG_ANALOG_TRIG:
-   return ni_ai_config_analog_trig(dev, s, insn, data);
case INSN_CONFIG_ALT_SOURCE:
if (devpriv->is_m_series) {
if (data[1] & ~(MSeries_AI_Bypass_Cal_Sel_Pos_Mask |
diff --git a/drivers/staging/comedi/drivers/ni_stc.h 
b/drivers/staging/comedi/drivers/ni_stc.h
index bcb3835..2b937d3 100644
--- a/drivers/staging/comedi/drivers/ni_stc.h
+++ b/drivers/staging/comedi/drivers/ni_stc.h
@@ -1410,7 +1410,6 @@ struct ni_board_struct {
 
int reg_type;
unsigned int has_8255:1;
-   unsigned int has_analog_trig:1;
 
enum caldac_enum caldac[3];
 };
@@ -1471,10 +1470,6 @@ struct ni_private {
unsigned clock_ns;
unsigned clock_source;
 
-   unsigned short atrig_mode;
-   unsigned short atrig_high;
-  

[PATCH 04/28] staging: comedi: ni_mio_common: fix ni_ao_insn_write_671x()

2014-07-14 Thread H Hartley Sweeten
Comedi (*insn_write) functions are expected to write insn->n values to
the hardware. Fix this function to work like the core expects.

Also, use the comedi_offset_munge() helper to convert the comedi unsigned
values into the two's complement values that the hardware needs.

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

diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c 
b/drivers/staging/comedi/drivers/ni_mio_common.c
index 471d7af..b52dd2f 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -3101,22 +3101,32 @@ static int ni_ao_insn_write(struct comedi_device *dev,
 
 static int ni_ao_insn_write_671x(struct comedi_device *dev,
 struct comedi_subdevice *s,
-struct comedi_insn *insn, unsigned int *data)
+struct comedi_insn *insn,
+unsigned int *data)
 {
-   const struct ni_board_struct *board = comedi_board(dev);
struct ni_private *devpriv = dev->private;
unsigned int chan = CR_CHAN(insn->chanspec);
-   unsigned int invert;
+   int i;
 
ao_win_out(1 << chan, AO_Immediate_671x);
-   invert = 1 << (board->aobits - 1);
 
ni_ao_config_chanlist(dev, s, &insn->chanspec, 1, 0);
 
-   devpriv->ao[chan] = data[0];
-   ao_win_out(data[0] ^ invert, DACx_Direct_Data_671x(chan));
+   for (i = 0; i < insn->n; i++) {
+   unsigned int val = data[i];
 
-   return 1;
+   devpriv->ao[chan] = val;
+
+   /*
+* 671x boards have +/-10V outputs
+* munge the unsigned comedi values to 2's complement
+*/
+   val = comedi_offset_munge(s, val);
+
+   ao_win_out(val, DACx_Direct_Data_671x(chan));
+   }
+
+   return insn->n;
 }
 
 static int ni_ao_insn_config(struct comedi_device *dev,
-- 
1.9.3

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


[PATCH 06/28] staging: comedi: ni_mio_common: fix ni_ao_insn_write()

2014-07-14 Thread H Hartley Sweeten
Comedi (*insn_write) functions are expected to write insn->n values
to the hardware. Fix this function to work like the core expects.

Also, don't rely on the return value of ni_ao_comfig_chanlist() to
determine if the values need converted to two's complement before
writing to the hardware. Use the comedi_range_is_bipolar() and
comedi_offset_munge() helpers to clarify the code.

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

diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c 
b/drivers/staging/comedi/drivers/ni_mio_common.c
index d937eb8..c08b9b6 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -3079,23 +3079,43 @@ static int ni_ao_insn_read(struct comedi_device *dev,
 
 static int ni_ao_insn_write(struct comedi_device *dev,
struct comedi_subdevice *s,
-   struct comedi_insn *insn, unsigned int *data)
+   struct comedi_insn *insn,
+   unsigned int *data)
 {
struct ni_private *devpriv = dev->private;
unsigned int chan = CR_CHAN(insn->chanspec);
-   unsigned int invert;
+   unsigned int range = CR_RANGE(insn->chanspec);
+   int reg;
+   int i;
 
-   invert = ni_ao_config_chanlist(dev, s, &insn->chanspec, 1, 0);
+   if (devpriv->is_m_series)
+   reg = M_Offset_DAC_Direct_Data(chan);
+   else
+   reg = (chan) ? DAC1_Direct_Data : DAC0_Direct_Data;
 
-   devpriv->ao[chan] = data[0];
+   ni_ao_config_chanlist(dev, s, &insn->chanspec, 1, 0);
 
-   if (devpriv->is_m_series) {
-   ni_writew(dev, data[0], M_Offset_DAC_Direct_Data(chan));
-   } else
-   ni_writew(dev, data[0] ^ invert,
- (chan) ? DAC1_Direct_Data : DAC0_Direct_Data);
+   for (i = 0; i < insn->n; i++) {
+   unsigned int val = data[i];
 
-   return 1;
+   devpriv->ao[chan] = val;
+
+   if (devpriv->is_m_series) {
+   /* M-series board always use offset binary values */
+   ni_writew(dev, val, reg);
+   } else {
+   /*
+* Non-M series boards need two's complement values
+* for bipolar ranges.
+*/
+   if (comedi_range_is_bipolar(s, range))
+   val = comedi_offset_munge(s, val);
+
+   ni_writew(dev, val, reg);
+   }
+   }
+
+   return insn->n;
 }
 
 static int ni_ao_insn_write_671x(struct comedi_device *dev,
-- 
1.9.3

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


[PATCH 02/28] staging: comedi: comedidev.h: introduce some 'range_is_external' helpers

2014-07-14 Thread H Hartley Sweeten
The comedi_krange includes a flags member that currently identifies the
'units' of the range (RF_UNIT) and if the range is from an internal or
external source (RF_EXTERNAL).

Introduce some helper functions to check if a given range is from an
external source.

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

diff --git a/drivers/staging/comedi/comedidev.h 
b/drivers/staging/comedi/comedidev.h
index 83fd155..6af6467 100644
--- a/drivers/staging/comedi/comedidev.h
+++ b/drivers/staging/comedi/comedidev.h
@@ -363,6 +363,12 @@ static inline bool comedi_range_is_unipolar(struct 
comedi_subdevice *s,
return s->range_table->range[range].min >= 0;
 }
 
+static inline bool comedi_range_is_external(struct comedi_subdevice *s,
+   unsigned int range)
+{
+   return !!(s->range_table->range[range].flags & RF_EXTERNAL);
+}
+
 static inline bool comedi_chan_range_is_bipolar(struct comedi_subdevice *s,
unsigned int chan,
unsigned int range)
@@ -377,6 +383,13 @@ static inline bool comedi_chan_range_is_unipolar(struct 
comedi_subdevice *s,
return s->range_table_list[chan]->range[range].min >= 0;
 }
 
+static inline bool comedi_chan_range_is_external(struct comedi_subdevice *s,
+unsigned int chan,
+unsigned int range)
+{
+   return !!(s->range_table_list[chan]->range[range].flags & RF_EXTERNAL);
+}
+
 /* munge between offset binary and two's complement values */
 static inline unsigned int comedi_offset_munge(struct comedi_subdevice *s,
   unsigned int val)
-- 
1.9.3

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


[PATCH 22/28] staging: comedi: ni_mio_common: init clock dividers early in ni_E_init()

2014-07-14 Thread H Hartley Sweeten
The init/reset of the hardware is a bit scattered in this function. For
aesthetics, move the init of the clock dividers so it happens early and
tidy up the code a bit.

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

diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c 
b/drivers/staging/comedi/drivers/ni_mio_common.c
index dc5f927..6d1754f 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -5499,6 +5499,18 @@ static int ni_E_init(struct comedi_device *dev,
return -EINVAL;
}
 
+   /* initialize clock dividers */
+   devpriv->clock_and_fout = Slow_Internal_Time_Divide_By_2 |
+ Slow_Internal_Timebase |
+ Clock_To_Board_Divide_By_2 |
+ Clock_To_Board;
+   if (!devpriv->is_6xxx) {
+   /* BEAM is this needed for PCI-6143 ?? */
+   devpriv->clock_and_fout |= (AI_Output_Divide_By_2 |
+   AO_Output_Divide_By_2);
+   }
+   ni_stc_writew(dev, devpriv->clock_and_fout, Clock_and_FOUT_Register);
+
ret = comedi_alloc_subdevices(dev, NI_NUM_SUBDEVICES);
if (ret)
return ret;
@@ -5770,21 +5782,6 @@ static int ni_E_init(struct comedi_device *dev,
/* ai configuration */
s = &dev->subdevices[NI_AI_SUBDEV];
ni_ai_reset(dev, s);
-   if (!devpriv->is_6xxx) {
-   /*  BEAM is this needed for PCI-6143 ?? */
-   devpriv->clock_and_fout =
-   Slow_Internal_Time_Divide_By_2 |
-   Slow_Internal_Timebase |
-   Clock_To_Board_Divide_By_2 |
-   Clock_To_Board |
-   AI_Output_Divide_By_2 | AO_Output_Divide_By_2;
-   } else {
-   devpriv->clock_and_fout =
-   Slow_Internal_Time_Divide_By_2 |
-   Slow_Internal_Timebase |
-   Clock_To_Board_Divide_By_2 | Clock_To_Board;
-   }
-   ni_stc_writew(dev, devpriv->clock_and_fout, Clock_and_FOUT_Register);
 
/* analog output configuration */
s = &dev->subdevices[NI_AO_SUBDEV];
-- 
1.9.3

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


[PATCH 13/28] staging: comedi: ni_mio_common: fix ni_ao_insn_read()

2014-07-14 Thread H Hartley Sweeten
The comedi core expects (*insn_read) functions to return insn->n
data smaples. Fix this function to work like the core expects.

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

diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c 
b/drivers/staging/comedi/drivers/ni_mio_common.c
index 1718382..f4125c0 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -2939,14 +2939,18 @@ static int ni_ao_config_chanlist(struct comedi_device 
*dev,
 }
 
 static int ni_ao_insn_read(struct comedi_device *dev,
-  struct comedi_subdevice *s, struct comedi_insn *insn,
+  struct comedi_subdevice *s,
+  struct comedi_insn *insn,
   unsigned int *data)
 {
struct ni_private *devpriv = dev->private;
+   unsigned int chan = CR_CHAN(insn->chanspec);
+   int i;
 
-   data[0] = devpriv->ao[CR_CHAN(insn->chanspec)];
+   for (i = 0; i < insn->n; i++)
+   data[i] = devpriv->ao[chan];
 
-   return 1;
+   return insn->n;
 }
 
 static int ni_ao_insn_write(struct comedi_device *dev,
-- 
1.9.3

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


[PATCH 12/28] staging: comedi: ni_mio_common: remove ai_continuous from private data

2014-07-14 Thread H Hartley Sweeten
This member of the private data can be determined by checking the
cmd->stop_src. Do that instead and remove the member.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_mio_common.c | 8 ++--
 drivers/staging/comedi/drivers/ni_stc.h| 1 -
 2 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c 
b/drivers/staging/comedi/drivers/ni_mio_common.c
index 9bcf835..1718382 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -1499,8 +1499,8 @@ static void ack_a_interrupt(struct comedi_device *dev, 
unsigned short a_status)
 static void handle_a_interrupt(struct comedi_device *dev, unsigned short 
status,
   unsigned ai_mite_status)
 {
-   struct ni_private *devpriv = dev->private;
struct comedi_subdevice *s = dev->read_subdev;
+   struct comedi_cmd *cmd = &s->async->cmd;
 
/* 67xx boards don't have ai subdevice, but their gpct0 might generate 
an a interrupt */
if (s->type == COMEDI_SUBD_UNUSED)
@@ -1551,7 +1551,7 @@ static void handle_a_interrupt(struct comedi_device *dev, 
unsigned short status,
return;
}
if (status & AI_SC_TC_St) {
-   if (!devpriv->ai_continuous)
+   if (cmd->stop_src == TRIG_COUNT)
shutdown_ai_command(dev);
}
}
@@ -2513,7 +2513,6 @@ static int ni_ai_cmd(struct comedi_device *dev, struct 
comedi_subdevice *s)
/* load SC (Scan Count) */
ni_stc_writew(dev, AI_SC_Load, AI_Command_1_Register);
 
-   devpriv->ai_continuous = 0;
if (stop_count == 0) {
devpriv->ai_cmd2 |= AI_End_On_End_Of_Scan;
interrupt_a_enable |= AI_STOP_Interrupt_Enable;
@@ -2532,9 +2531,6 @@ static int ni_ai_cmd(struct comedi_device *dev, struct 
comedi_subdevice *s)
 
/* load SC (Scan Count) */
ni_stc_writew(dev, AI_SC_Load, AI_Command_1_Register);
-
-   devpriv->ai_continuous = 1;
-
break;
}
 
diff --git a/drivers/staging/comedi/drivers/ni_stc.h 
b/drivers/staging/comedi/drivers/ni_stc.h
index 2b937d3..6f9c481 100644
--- a/drivers/staging/comedi/drivers/ni_stc.h
+++ b/drivers/staging/comedi/drivers/ni_stc.h
@@ -1422,7 +1422,6 @@ struct ni_private {
unsigned short dio_output;
unsigned short dio_control;
int aimode;
-   int ai_continuous;
unsigned int ai_calib_source;
unsigned int ai_calib_source_enabled;
spinlock_t window_lock;
-- 
1.9.3

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


[PATCH 05/28] staging: comedi: ni_mio_common: remove ao_win_out() macro

2014-07-14 Thread H Hartley Sweeten
This marco relies on a local variable having a specific name. Remove the
macro and just use ni_ao_win_outw() directly.

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

diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c 
b/drivers/staging/comedi/drivers/ni_mio_common.c
index b52dd2f..d937eb8 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -994,7 +994,6 @@ static void ni_clear_ai_fifo(struct comedi_device *dev)
}
 }
 
-#define ao_win_out(data, addr) ni_ao_win_outw(dev, data, addr)
 static inline void ni_ao_win_outw(struct comedi_device *dev, uint16_t data,
  int addr)
 {
@@ -3108,7 +3107,7 @@ static int ni_ao_insn_write_671x(struct comedi_device 
*dev,
unsigned int chan = CR_CHAN(insn->chanspec);
int i;
 
-   ao_win_out(1 << chan, AO_Immediate_671x);
+   ni_ao_win_outw(dev, 1 << chan, AO_Immediate_671x);
 
ni_ao_config_chanlist(dev, s, &insn->chanspec, 1, 0);
 
@@ -3123,7 +3122,7 @@ static int ni_ao_insn_write_671x(struct comedi_device 
*dev,
 */
val = comedi_offset_munge(s, val);
 
-   ao_win_out(val, DACx_Direct_Data_671x(chan));
+   ni_ao_win_outw(dev, val, DACx_Direct_Data_671x(chan));
}
 
return insn->n;
@@ -3253,7 +3252,7 @@ static int ni_ao_cmd(struct comedi_device *dev, struct 
comedi_subdevice *s)
ni_stc_writew(dev, AO_Disarm, AO_Command_1_Register);
 
if (board->reg_type & ni_reg_6xxx_mask) {
-   ao_win_out(CLEAR_WG, AO_Misc_611x);
+   ni_ao_win_outw(dev, CLEAR_WG, AO_Misc_611x);
 
bits = 0;
for (i = 0; i < cmd->chanlist_len; i++) {
@@ -3261,9 +3260,9 @@ static int ni_ao_cmd(struct comedi_device *dev, struct 
comedi_subdevice *s)
 
chan = CR_CHAN(cmd->chanlist[i]);
bits |= 1 << chan;
-   ao_win_out(chan, AO_Waveform_Generation_611x);
+   ni_ao_win_outw(dev, chan, AO_Waveform_Generation_611x);
}
-   ao_win_out(bits, AO_Timed_611x);
+   ni_ao_win_outw(dev, bits, AO_Timed_611x);
}
 
ni_ao_config_chanlist(dev, s, cmd->chanlist, cmd->chanlist_len, 1);
@@ -3557,8 +3556,8 @@ static int ni_ao_reset(struct comedi_device *dev, struct 
comedi_subdevice *s)
unsigned i;
for (i = 0; i < s->n_chan; ++i)
immediate_bits |= 1 << i;
-   ao_win_out(immediate_bits, AO_Immediate_671x);
-   ao_win_out(CLEAR_WG, AO_Misc_611x);
+   ni_ao_win_outw(dev, immediate_bits, AO_Immediate_671x);
+   ni_ao_win_outw(dev, CLEAR_WG, AO_Misc_611x);
}
ni_stc_writew(dev, AO_Configuration_End, Joint_Reset_Register);
 
@@ -4051,7 +4050,7 @@ static void init_ao_67xx(struct comedi_device *dev, 
struct comedi_subdevice *s)
ni_ao_win_outw(dev, AO_Channel(i) | 0x0,
   AO_Configuration_2_67xx);
}
-   ao_win_out(0x0, AO_Later_Single_Point_Updates);
+   ni_ao_win_outw(dev, 0x0, AO_Later_Single_Point_Updates);
 }
 
 static unsigned ni_gpct_to_stc_register(enum ni_gpct_register reg)
-- 
1.9.3

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


[PATCH 21/28] staging: comedi: ni_mio_common: tidy up the Digital I/O subdevice init

2014-07-14 Thread H Hartley Sweeten
For aesthetics, add some whitespace to the Digital I/O subdevice init.

Only hook up the async command support if we have an irq.

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

diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c 
b/drivers/staging/comedi/drivers/ni_mio_common.c
index 7146f21..dc5f927 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -5574,32 +5574,37 @@ static int ni_E_init(struct comedi_device *dev,
s->type = COMEDI_SUBD_UNUSED;
}
 
-   /* digital i/o subdevice */
-
+   /* Digital I/O subdevice */
s = &dev->subdevices[NI_DIO_SUBDEV];
-   s->type = COMEDI_SUBD_DIO;
-   s->subdev_flags = SDF_WRITABLE | SDF_READABLE;
-   s->maxdata = 1;
-   s->io_bits = 0; /* all bits input */
-   s->range_table = &range_digital;
-   s->n_chan = board->has_32dio_chan ? 32 : 8;
+   s->type = COMEDI_SUBD_DIO;
+   s->subdev_flags = SDF_WRITABLE | SDF_READABLE;
+   s->n_chan   = board->has_32dio_chan ? 32 : 8;
+   s->maxdata  = 1;
+   s->range_table  = &range_digital;
if (devpriv->is_m_series) {
-   s->subdev_flags |=
-   SDF_LSAMPL | SDF_CMD_WRITE /* | SDF_CMD_READ */;
-   s->insn_bits = &ni_m_series_dio_insn_bits;
-   s->insn_config = &ni_m_series_dio_insn_config;
-   s->do_cmd = &ni_cdio_cmd;
-   s->do_cmdtest = &ni_cdio_cmdtest;
-   s->cancel = &ni_cdio_cancel;
-   s->async_dma_dir = DMA_BIDIRECTIONAL;
-   s->len_chanlist = s->n_chan;
+   s->subdev_flags |= SDF_LSAMPL;
+   s->insn_bits= ni_m_series_dio_insn_bits;
+   s->insn_config  = ni_m_series_dio_insn_config;
+   if (dev->irq) {
+   s->subdev_flags |= SDF_CMD_WRITE /* | SDF_CMD_READ */;
+   s->len_chanlist = s->n_chan;
+   s->do_cmdtest   = ni_cdio_cmdtest;
+   s->do_cmd   = ni_cdio_cmd;
+   s->cancel   = ni_cdio_cancel;
+
+   /* M-series boards use DMA */
+   s->async_dma_dir = DMA_BIDIRECTIONAL;
+   }
 
+   /* reset DIO and set all channels to inputs */
ni_writel(dev, CDO_Reset_Bit | CDI_Reset_Bit,
  M_Offset_CDIO_Command);
ni_writel(dev, s->io_bits, M_Offset_DIO_Direction);
} else {
-   s->insn_bits = &ni_dio_insn_bits;
-   s->insn_config = &ni_dio_insn_config;
+   s->insn_bits= ni_dio_insn_bits;
+   s->insn_config  = ni_dio_insn_config;
+
+   /* set all channels to inputs */
devpriv->dio_control = DIO_Pins_Dir(s->io_bits);
ni_writew(dev, devpriv->dio_control, DIO_Control_Register);
}
-- 
1.9.3

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


[PATCH V4 3/6] staging: vt6556: Remove uneeded return statements

2014-07-14 Thread Peter Senna Tschudin
This patch remove uneeded return statements reported by checkpatch
and fixes the indentation of a multi-line call.

Tested by compilation only.

Signed-off-by: Peter Senna Tschudin 
---
Cahnges from V3:
 - Splitted the patches by change type

 drivers/staging/vt6656/card.c |  6 +-
 drivers/staging/vt6656/main_usb.c | 13 -
 2 files changed, 1 insertion(+), 18 deletions(-)

diff --git a/drivers/staging/vt6656/card.c b/drivers/staging/vt6656/card.c
index 37cd96b..f469d68 100644
--- a/drivers/staging/vt6656/card.c
+++ b/drivers/staging/vt6656/card.c
@@ -674,9 +674,7 @@ void vnt_reset_next_tbtt(struct vnt_private *priv, u16 
beacon_interval)
data[7] = (u8)(next_tbtt >> 56);
 
vnt_control_out(priv, MESSAGE_TYPE_SET_TSFTBTT,
-   MESSAGE_REQUEST_TBTT, 0, 8, data);
-
-   return;
+   MESSAGE_REQUEST_TBTT, 0, 8, data);
 }
 
 /*
@@ -714,8 +712,6 @@ void vnt_update_next_tbtt(struct vnt_private *priv, u64 tsf,
MESSAGE_REQUEST_TBTT, 0, 8, data);
 
dev_dbg(&priv->usb->dev, "%s TBTT: %8llx\n", __func__, tsf);
-
-   return;
 }
 
 /*
diff --git a/drivers/staging/vt6656/main_usb.c 
b/drivers/staging/vt6656/main_usb.c
index 8e05f04..553a8e9 100644
--- a/drivers/staging/vt6656/main_usb.c
+++ b/drivers/staging/vt6656/main_usb.c
@@ -493,8 +493,6 @@ static void device_free_tx_bufs(struct vnt_private *priv)
 
kfree(tx_context);
}
-
-   return;
 }
 
 static void device_free_rx_bufs(struct vnt_private *priv)
@@ -519,8 +517,6 @@ static void device_free_rx_bufs(struct vnt_private *priv)
 
kfree(rcb);
}
-
-   return;
 }
 
 static void usb_device_reset(struct vnt_private *pDevice)
@@ -530,14 +526,11 @@ static void usb_device_reset(struct vnt_private *pDevice)
status = usb_reset_device(pDevice->usb);
if (status)
 printk("usb_device_reset fail status=%d\n",status);
-   return ;
 }
 
 static void device_free_int_bufs(struct vnt_private *priv)
 {
kfree(priv->int_buf.data_buf);
-
-   return;
 }
 
 static bool device_alloc_bufs(struct vnt_private *priv)
@@ -718,8 +711,6 @@ static void vnt_stop(struct ieee80211_hw *hw)
 
usb_kill_urb(priv->pInterruptURB);
usb_free_urb(priv->pInterruptURB);
-
-   return;
 }
 
 static int vnt_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif 
*vif)
@@ -785,8 +776,6 @@ static void vnt_remove_interface(struct ieee80211_hw *hw,
 
/* LED slow blink */
vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_SLOW);
-
-   return;
 }
 
 static int vnt_config(struct ieee80211_hw *hw, u32 changed)
@@ -966,8 +955,6 @@ static void vnt_configure(struct ieee80211_hw *hw,
vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG, MAC_REG_RCR, rx_mode);
 
dev_dbg(&priv->usb->dev, "rx mode out= %x\n", rx_mode);
-
-   return;
 }
 
 static int vnt_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
-- 
1.9.3

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


[PATCH V4 4/6] staging: vt6556: Remove typedefs

2014-07-14 Thread Peter Senna Tschudin
This patch removes uneeded typedefs reported by chackpatch and removes
one enum. The removed enum from card.h:

typedef enum _CARD_PHY_TYPE {
PHY_TYPE_AUTO = 0,
PHY_TYPE_11B,
PHY_TYPE_11G,
PHY_TYPE_11A
} CARD_PHY_TYPE, *PCARD_PHY_TYPE;

The following typedefs were removed, but enums were kept at device.h:

 typedef enum __device_msg_level
 typedef enum __DEVICE_NDIS_STATUS

Tested by compilation only.

Signed-off-by: Peter Senna Tschudin 
---
Cahnges from V3:
 - Splitted the patches by change type

 drivers/staging/vt6656/card.h   |  7 ---
 drivers/staging/vt6656/device.h | 17 -
 2 files changed, 8 insertions(+), 16 deletions(-)

diff --git a/drivers/staging/vt6656/card.h b/drivers/staging/vt6656/card.h
index 80fcd53..03fc167 100644
--- a/drivers/staging/vt6656/card.h
+++ b/drivers/staging/vt6656/card.h
@@ -32,13 +32,6 @@
 
 /* init card type */
 
-typedef enum _CARD_PHY_TYPE {
-PHY_TYPE_AUTO = 0,
-PHY_TYPE_11B,
-PHY_TYPE_11G,
-PHY_TYPE_11A
-} CARD_PHY_TYPE, *PCARD_PHY_TYPE;
-
 #define CB_MAX_CHANNEL_24G 14
 #define CB_MAX_CHANNEL_5G  42 /* add channel9(5045MHz), 41==>42 */
 #define CB_MAX_CHANNEL (CB_MAX_CHANNEL_24G + CB_MAX_CHANNEL_5G)
diff --git a/drivers/staging/vt6656/device.h b/drivers/staging/vt6656/device.h
index 50a6749..e3acf2f 100644
--- a/drivers/staging/vt6656/device.h
+++ b/drivers/staging/vt6656/device.h
@@ -187,13 +187,13 @@
 
 #define DBG_PRT(l, p, args...) { if (l <= msglevel) printk(p, ##args); }
 
-typedef enum __device_msg_level {
+enum {
MSG_LEVEL_ERR = 0,/* Errors causing abnormal operation */
MSG_LEVEL_NOTICE = 1, /* Errors needing user notification */
MSG_LEVEL_INFO = 2,   /* Normal message. */
MSG_LEVEL_VERBOSE = 3,/* Will report all trival errors. */
MSG_LEVEL_DEBUG = 4   /* Only for debug purpose. */
-} DEVICE_MSG_LEVEL, *PDEVICE_MSG_LEVEL;
+};
 
 #define DEVICE_INIT_COLD   0x0 /* cold init */
 #define DEVICE_INIT_RESET  0x1 /* reset init or Dx to D0 power remain */
@@ -268,13 +268,12 @@ struct vnt_interrupt_buffer {
 
 /*++ NDIS related */
 
-typedef enum __DEVICE_NDIS_STATUS {
-STATUS_SUCCESS = 0,
-STATUS_FAILURE,
-STATUS_RESOURCES,
-STATUS_PENDING,
-} DEVICE_NDIS_STATUS, *PDEVICE_NDIS_STATUS;
-
+enum {
+   STATUS_SUCCESS = 0,
+   STATUS_FAILURE,
+   STATUS_RESOURCES,
+   STATUS_PENDING,
+};
 
 /* flags for options */
 #define DEVICE_FLAGS_UNPLUG  0x0001UL
-- 
1.9.3

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


[PATCH V4 5/6] staging: vt6556: Cleanup indentation on statements

2014-07-14 Thread Peter Senna Tschudin
Use tabs instead of spaces in a set of statements and fix lines
over 80 chars. Reported by checkpatch.

Tested by compilation only.

Signed-off-by: Peter Senna Tschudin 
---
Cahnges from V3:
 - Splitted the patches by change type

 drivers/staging/vt6656/main_usb.c | 44 ---
 1 file changed, 23 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/vt6656/main_usb.c 
b/drivers/staging/vt6656/main_usb.c
index 553a8e9..cc0281a 100644
--- a/drivers/staging/vt6656/main_usb.c
+++ b/drivers/staging/vt6656/main_usb.c
@@ -382,38 +382,40 @@ static int device_init_registers(struct vnt_private 
*pDevice)
/* load vt3266 calibration parameters in EEPROM */
if (pDevice->byRFType == RF_VT3226D0) {
if ((pDevice->abyEEPROM[EEP_OFS_MAJOR_VER] == 0x1) &&
-   (pDevice->abyEEPROM[EEP_OFS_MINOR_VER] >= 0x4)) {
+  (pDevice->abyEEPROM[EEP_OFS_MINOR_VER] >= 0x4)) {
 
byCalibTXIQ = pDevice->abyEEPROM[EEP_OFS_CALIB_TX_IQ];
byCalibTXDC = pDevice->abyEEPROM[EEP_OFS_CALIB_TX_DC];
byCalibRXIQ = pDevice->abyEEPROM[EEP_OFS_CALIB_RX_IQ];
if (byCalibTXIQ || byCalibTXDC || byCalibRXIQ) {
-   /* CR255, enable TX/RX IQ and DC compensation mode */
+   /* CR255, enable TX/RX IQ and
+  DC compensation mode */
vnt_control_out_u8(pDevice,
-   MESSAGE_REQUEST_BBREG,
-   0xff,
-   0x03);
-   /* CR251, TX I/Q Imbalance Calibration */
+  MESSAGE_REQUEST_BBREG,
+  0xff,
+  0x03);
+   /* CR251, TX I/Q Imbalance Calibration */
vnt_control_out_u8(pDevice,
-   MESSAGE_REQUEST_BBREG,
-   0xfb,
-   byCalibTXIQ);
-   /* CR252, TX DC-Offset Calibration */
+  MESSAGE_REQUEST_BBREG,
+  0xfb,
+  byCalibTXIQ);
+   /* CR252, TX DC-Offset Calibration */
vnt_control_out_u8(pDevice,
-   MESSAGE_REQUEST_BBREG,
-   0xfC,
-   byCalibTXDC);
-   /* CR253, RX I/Q Imbalance Calibration */
+  MESSAGE_REQUEST_BBREG,
+  0xfC,
+  byCalibTXDC);
+   /* CR253, RX I/Q Imbalance Calibration */
vnt_control_out_u8(pDevice,
-   MESSAGE_REQUEST_BBREG,
-   0xfd,
-   byCalibRXIQ);
+  MESSAGE_REQUEST_BBREG,
+  0xfd,
+  byCalibRXIQ);
} else {
-   /* CR255, turn off BB Calibration compensation */
+   /* CR255, turn off
+  BB Calibration compensation */
vnt_control_out_u8(pDevice,
-   MESSAGE_REQUEST_BBREG,
-   0xff,
-   0x0);
+  MESSAGE_REQUEST_BBREG,
+  0xff,
+  0x0);
}
}
}
-- 
1.9.3

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


[PATCH V4 2/6] staging: vt6556: Remove double parentheses

2014-07-14 Thread Peter Senna Tschudin
This patch cleanup a checkpatch warning by removing double parentheses
from if condition. Additionally it fixes a line over 80 chars.

Tested by compilation only.

Signed-off-by: Peter Senna Tschudin 
---
Cahnges from V3:
 - Splitted the patches by change type

 drivers/staging/vt6656/baseband.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/vt6656/baseband.c 
b/drivers/staging/vt6656/baseband.c
index 8678b41..040b232 100644
--- a/drivers/staging/vt6656/baseband.c
+++ b/drivers/staging/vt6656/baseband.c
@@ -452,8 +452,9 @@ int BBbVT3184Init(struct vnt_private *priv)
priv->ldBmThreshold[2] = 0;
priv->ldBmThreshold[3] = 0;
/* Fix VT3226 DFC system timing issue */
-   vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL2, 
SOFTPWRCTL_RFLEOPT);
-   } else if ((priv->byRFType == RF_VT3342A0)) {
+   vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL2,
+   SOFTPWRCTL_RFLEOPT);
+   } else if (priv->byRFType == RF_VT3342A0) {
priv->byBBRxConf = vnt_vt3184_vt3226d0[10];
length = sizeof(vnt_vt3184_vt3226d0);
addr = vnt_vt3184_vt3226d0;
-- 
1.9.3

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


[PATCH V4 1/6] staging: vt6556: Cleanup trivial coding style issues

2014-07-14 Thread Peter Senna Tschudin
This patch cleans up the following checkpatch issues:
 - tabs instead of spaces on the beginning of a line
 - use correct /* */ comment style
 - put { and } on the correct places
 - line over 80 chars
 - indentation style for multi-line calls / comments
 - space after semicolon ,
 - new line after declaration

Tested by compilation only.

Signed-off-by: Peter Senna Tschudin 
---
Cahnges from V3:
 - Splitted the patches by change type

 drivers/staging/vt6656/baseband.c | 23 ---
 drivers/staging/vt6656/card.c | 13 +
 drivers/staging/vt6656/card.h |  6 ++--
 drivers/staging/vt6656/channel.c  |  5 ++--
 drivers/staging/vt6656/device.h   | 10 +++
 drivers/staging/vt6656/main_usb.c | 59 ---
 6 files changed, 61 insertions(+), 55 deletions(-)

diff --git a/drivers/staging/vt6656/baseband.c 
b/drivers/staging/vt6656/baseband.c
index c1675d5..8678b41 100644
--- a/drivers/staging/vt6656/baseband.c
+++ b/drivers/staging/vt6656/baseband.c
@@ -26,9 +26,10 @@
  * Date: Jun. 5, 2002
  *
  * Functions:
- *  vnt_get_frame_time- Calculate data frame transmitting time
- *  vnt_get_phy_field   - Calculate PhyLength, PhyService and Phy Signal 
parameter for baseband Tx
- *  BBbVT3184Init  - VIA VT3184 baseband chip init code
+ * vnt_get_frame_time  - Calculate data frame transmitting time
+ * vnt_get_phy_field   - Calculate PhyLength, PhyService and Phy
+ *   Signal parameter for baseband Tx
+ * BBbVT3184Init   - VIA VT3184 baseband chip init code
  *
  * Revision History:
  *
@@ -86,7 +87,7 @@ static u8 vnt_vt3184_al2230[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00  /* 0xff */
 };
 
-//{{RobertYu:20060515, new BB setting for VT3226D0
+/* {{RobertYu:20060515, new BB setting for VT3226D0 */
 static u8 vnt_vt3184_vt3226d0[] = {
0x31, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
0x70, 0x45, 0x2a, 0x76, 0x00, 0x00, 0x80, 0x00, /* 0x0f */
@@ -122,8 +123,9 @@ static u8 vnt_vt3184_vt3226d0[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00  /* 0xff */
 };
 
-static const u16 awcFrameTime[MAX_RATE] =
-{10, 20, 55, 110, 24, 36, 48, 72, 96, 144, 192, 216};
+static const u16 awcFrameTime[MAX_RATE] = {
+   10, 20, 55, 110, 24, 36, 48, 72, 96, 144, 192, 216
+};
 
 /*
  * Description: Calculate data frame transmitting time
@@ -191,9 +193,9 @@ unsigned int vnt_get_frame_time(u8 preamble_type, u8 
pkt_type,
  *  tx_rate   - Tx Rate
  *  Out:
  * struct vnt_phy_field *phy
- * - pointer to Phy Length field
- * - pointer to Phy Service field
- * - pointer to Phy Signal field
+ * - pointer to Phy Length field
+ * - pointer to Phy Service field
+ * - pointer to Phy Signal field
  *
  * Return Value: none
  *
@@ -467,7 +469,8 @@ int BBbVT3184Init(struct vnt_private *priv)
priv->ldBmThreshold[2] = 0;
priv->ldBmThreshold[3] = 0;
/* Fix VT3226 DFC system timing issue */
-   vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL2, 
SOFTPWRCTL_RFLEOPT);
+   vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL2,
+   SOFTPWRCTL_RFLEOPT);
} else {
return true;
}
diff --git a/drivers/staging/vt6656/card.c b/drivers/staging/vt6656/card.c
index ea06b63..37cd96b 100644
--- a/drivers/staging/vt6656/card.c
+++ b/drivers/staging/vt6656/card.c
@@ -55,11 +55,12 @@
 #include "key.h"
 #include "usbpipe.h"
 
-//const u16 cwRXBCNTSFOff[MAX_RATE] =
-//{17, 34, 96, 192, 34, 23, 17, 11, 8, 5, 4, 3};
+/* const u16 cwRXBCNTSFOff[MAX_RATE] =
+   {17, 34, 96, 192, 34, 23, 17, 11, 8, 5, 4, 3}; */
 
-static const u16 cwRXBCNTSFOff[MAX_RATE] =
-{192, 96, 34, 17, 34, 23, 17, 11, 8, 5, 4, 3};
+static const u16 cwRXBCNTSFOff[MAX_RATE] = {
+   192, 96, 34, 17, 34, 23, 17, 11, 8, 5, 4, 3
+};
 
 /*
  * Description: Set NIC media channel
@@ -477,7 +478,7 @@ void vnt_update_top_rates(struct vnt_private *priv)
}
 
priv->byTopCCKBasicRate = top_cck;
- }
+}
 
 int vnt_ofdm_min_rate(struct vnt_private *priv)
 {
@@ -710,7 +711,7 @@ void vnt_update_next_tbtt(struct vnt_private *priv, u64 tsf,
data[7] = (u8)(tsf >> 56);
 
vnt_control_out(priv, MESSAGE_TYPE_SET_TSFTBTT,
-   MESSAGE_REQUEST_TBTT, 0, 8, data);
+   MESSAGE_REQUEST_TBTT, 0, 8, data);
 
dev_dbg(&priv->usb->dev, "%s TBTT: %8llx\n", __func__, tsf);
 
diff --git a/drivers/staging/vt6656/card.h b/drivers/staging/vt6656/card.h
index 5b7cc5a..80fcd53 100644
--- a/drivers/staging/vt6656/card.h
+++ b/drivers/staging/vt6656/card.h
@@ -39,9 +39,9 @@ typedef enum _CARD_PHY_TYPE {
 PHY_TYPE_11A
 } CARD_PHY_TYPE, *PCARD_PHY_TYPE;
 
-#define CB_MAX_CHANNEL_24G  14
-#define CB_MAX_CHANNEL_5G   42 /* add channel9(5045MHz), 41==>42 */
-#define CB_MA

[PATCH V4 6/6] staging: vt6556: Replace printk by pr_warn

2014-07-14 Thread Peter Senna Tschudin
This patch fixes a checkpatch warning by replacing printk by pr_warn.

Tested by compilation only.

Signed-off-by: Peter Senna Tschudin 
---
Cahnges from V3:
 - Splitted the patches by change type

 drivers/staging/vt6656/main_usb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/vt6656/main_usb.c 
b/drivers/staging/vt6656/main_usb.c
index cc0281a..64c25e2 100644
--- a/drivers/staging/vt6656/main_usb.c
+++ b/drivers/staging/vt6656/main_usb.c
@@ -527,7 +527,7 @@ static void usb_device_reset(struct vnt_private *pDevice)
 
status = usb_reset_device(pDevice->usb);
if (status)
-printk("usb_device_reset fail status=%d\n",status);
+   pr_warn("usb_device_reset fail status=%d\n", status);
 }
 
 static void device_free_int_bufs(struct vnt_private *priv)
-- 
1.9.3

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


[PATCH v2 08/18] staging: comedi: ni_65xx: fix ni_65xx_intr_insn_config()

2014-07-14 Thread H Hartley Sweeten
Refactor this function to follow the standard (*insn_config) form.

Add a sanity check of the number of data parameters (insn->n). Currently
the core does not check INSN_CONFIG_CHANGE_NOTIFY.

Fix the writes to the rise/fall edge enable registers. The macro expects
a "port" value not the port offset value.

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

diff --git a/drivers/staging/comedi/drivers/ni_65xx.c 
b/drivers/staging/comedi/drivers/ni_65xx.c
index 517dbc6..742d3cd 100644
--- a/drivers/staging/comedi/drivers/ni_65xx.c
+++ b/drivers/staging/comedi/drivers/ni_65xx.c
@@ -508,22 +508,41 @@ static int ni_65xx_intr_insn_config(struct comedi_device 
*dev,
 {
struct ni_65xx_private *devpriv = dev->private;
 
-   if (insn->n < 1)
-   return -EINVAL;
-   if (data[0] != INSN_CONFIG_CHANGE_NOTIFY)
-   return -EINVAL;
+   switch (data[0]) {
+   case INSN_CONFIG_CHANGE_NOTIFY:
+   /* add instruction to check_insn_config_length() */
+   if (insn->n != 3)
+   return -EINVAL;
 
-   writeb(data[1], devpriv->mmio + NI_65XX_RISE_EDGE_ENA_REG(0));
-   writeb(data[1] >> 8, devpriv->mmio + NI_65XX_RISE_EDGE_ENA_REG(0x10));
-   writeb(data[1] >> 16, devpriv->mmio + NI_65XX_RISE_EDGE_ENA_REG(0x20));
-   writeb(data[1] >> 24, devpriv->mmio + NI_65XX_RISE_EDGE_ENA_REG(0x30));
+   /*
+* This only works for the first 4 ports (32 channels)!
+*/
 
-   writeb(data[2], devpriv->mmio + NI_65XX_FALL_EDGE_ENA_REG(0));
-   writeb(data[2] >> 8, devpriv->mmio + NI_65XX_FALL_EDGE_ENA_REG(0x10));
-   writeb(data[2] >> 16, devpriv->mmio + NI_65XX_FALL_EDGE_ENA_REG(0x20));
-   writeb(data[2] >> 24, devpriv->mmio + NI_65XX_FALL_EDGE_ENA_REG(0x30));
+   /* set the channels to monitor for rising edges */
+   writeb(data[1] & 0xff,
+  devpriv->mmio + NI_65XX_RISE_EDGE_ENA_REG(0));
+   writeb((data[1] >> 8) & 0xff,
+  devpriv->mmio + NI_65XX_RISE_EDGE_ENA_REG(1));
+   writeb((data[1] >> 16) & 0xff,
+  devpriv->mmio + NI_65XX_RISE_EDGE_ENA_REG(2));
+   writeb((data[1] >> 24) & 0xff,
+  devpriv->mmio + NI_65XX_RISE_EDGE_ENA_REG(3));
+
+   /* set the channels to monitor for falling edges */
+   writeb(data[2] & 0xff,
+  devpriv->mmio + NI_65XX_FALL_EDGE_ENA_REG(0));
+   writeb((data[2] >> 8) & 0xff,
+  devpriv->mmio + NI_65XX_FALL_EDGE_ENA_REG(1));
+   writeb((data[2] >> 16) & 0xff,
+  devpriv->mmio + NI_65XX_FALL_EDGE_ENA_REG(2));
+   writeb((data[2] >> 24) & 0xff,
+  devpriv->mmio + NI_65XX_FALL_EDGE_ENA_REG(3));
+   break;
+   default:
+   return -EINVAL;
+   }
 
-   return 2;
+   return insn->n;
 }
 
 /* ripped from mite.h and mite_setup2() to avoid mite dependancy */
-- 
1.9.3

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


[PATCH v2 06/18] staging: comedi: ni_65xx: remove the need for the subdevice private data

2014-07-14 Thread H Hartley Sweeten
There is only one member in the subdevice private data, an unsigned value
that is the 'base_port' that the subdevice uses to access the port registers.

Just cast the appropriate value into s->private instead of allocating the
private data for each subdevice. The casts are a bit of a nusance but it
removes the unnecessary allocations.

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

diff --git a/drivers/staging/comedi/drivers/ni_65xx.c 
b/drivers/staging/comedi/drivers/ni_65xx.c
index 4b3f504..7e562f1 100644
--- a/drivers/staging/comedi/drivers/ni_65xx.c
+++ b/drivers/staging/comedi/drivers/ni_65xx.c
@@ -274,25 +274,16 @@ struct ni_65xx_private {
unsigned short output_bits[NI_65XX_MAX_NUM_PORTS];
 };
 
-struct ni_65xx_subdevice_private {
-   unsigned base_port;
-};
-
-static inline struct ni_65xx_subdevice_private *sprivate(struct 
comedi_subdevice
-*subdev)
-{
-   return subdev->private;
-}
-
 static int ni_65xx_dio_insn_config(struct comedi_device *dev,
   struct comedi_subdevice *s,
   struct comedi_insn *insn,
   unsigned int *data)
 {
struct ni_65xx_private *devpriv = dev->private;
+   unsigned long base_port = (unsigned long)s->private;
unsigned int chan = CR_CHAN(insn->chanspec);
unsigned int chan_mask = 1 << (chan % ni_65xx_channels_per_port);
-   unsigned port = sprivate(s)->base_port + ni_65xx_port_by_channel(chan);
+   unsigned port = base_port + ni_65xx_port_by_channel(chan);
unsigned int interval;
unsigned int val;
 
@@ -357,6 +348,7 @@ static int ni_65xx_dio_insn_bits(struct comedi_device *dev,
 struct comedi_insn *insn, unsigned int *data)
 {
const struct ni_65xx_board *board = comedi_board(dev);
+   unsigned long base_port = (unsigned long)s->private;
struct ni_65xx_private *devpriv = dev->private;
int base_bitfield_channel;
unsigned read_bits = 0;
@@ -366,7 +358,7 @@ static int ni_65xx_dio_insn_bits(struct comedi_device *dev,
base_bitfield_channel = CR_CHAN(insn->chanspec);
for (port_offset = ni_65xx_port_by_channel(base_bitfield_channel);
 port_offset <= last_port_offset; port_offset++) {
-   unsigned port = sprivate(s)->base_port + port_offset;
+   unsigned port = base_port + port_offset;
int base_port_channel = port_offset * ni_65xx_channels_per_port;
unsigned port_mask, port_data, port_read_bits;
int bitshift = base_port_channel - base_bitfield_channel;
@@ -563,7 +555,6 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
struct pci_dev *pcidev = comedi_to_pci_dev(dev);
const struct ni_65xx_board *board = NULL;
struct ni_65xx_private *devpriv;
-   struct ni_65xx_subdevice_private *spriv;
struct comedi_subdevice *s;
unsigned i;
int ret;
@@ -609,10 +600,9 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
s->maxdata = 1;
s->insn_config = ni_65xx_dio_insn_config;
s->insn_bits = ni_65xx_dio_insn_bits;
-   spriv = comedi_alloc_spriv(s, sizeof(*spriv));
-   if (!spriv)
-   return -ENOMEM;
-   spriv->base_port = 0;
+
+   /* the input ports always start at port 0 */
+   s->private = (void *)0;
} else {
s->type = COMEDI_SUBD_UNUSED;
}
@@ -626,10 +616,9 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
s->range_table = &range_digital;
s->maxdata = 1;
s->insn_bits = ni_65xx_dio_insn_bits;
-   spriv = comedi_alloc_spriv(s, sizeof(*spriv));
-   if (!spriv)
-   return -ENOMEM;
-   spriv->base_port = board->num_di_ports;
+
+   /* the output ports always start after the input ports */
+   s->private = (void *)(unsigned long)board->num_di_ports;
} else {
s->type = COMEDI_SUBD_UNUSED;
}
@@ -644,10 +633,10 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
s->maxdata = 1;
s->insn_config = ni_65xx_dio_insn_config;
s->insn_bits = ni_65xx_dio_insn_bits;
-   spriv = comedi_alloc_spriv(s, sizeof(*spriv));
-   if (!spriv)
-   return -ENOMEM;
-   spriv->base_port = 0;
+
+   /* the input/output ports always start at port 0 */
+   s->private = (void *)0;
+
/* configure all ports for input */
for (i = 0; i

[PATCH v2 12/18] staging: comedi: ni_65xx: clean up multi-line comments

2014-07-14 Thread H Hartley Sweeten
Clean up the multi-line comments at the beginning of the file so they
follow the kernel CodingStyle.

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

diff --git a/drivers/staging/comedi/drivers/ni_65xx.c 
b/drivers/staging/comedi/drivers/ni_65xx.c
index 6c194fc..3b56359 100644
--- a/drivers/staging/comedi/drivers/ni_65xx.c
+++ b/drivers/staging/comedi/drivers/ni_65xx.c
@@ -1,46 +1,65 @@
 /*
-comedi/drivers/ni_6514.c
-driver for National Instruments PCI-6514
-
-Copyright (C) 2006 Jon Grierson 
-Copyright (C) 2006 Frank Mori Hess 
-
-COMEDI - Linux Control and Measurement Device Interface
-Copyright (C) 1999,2002,2003 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.
+ * ni_65xx.c
+ * Comedi driver for National Instruments PCI-65xx static dio boards
+ *
+ * Copyright (C) 2006 Jon Grierson 
+ * Copyright (C) 2006 Frank Mori Hess 
+ *
+ * COMEDI - Linux Control and Measurement Device Interface
+ * Copyright (C) 1999,2002,2003 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.
+ */
 
-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_65xx
-Description: National Instruments 65xx static dio boards
-Author: Jon Grierson ,
-   Frank Mori Hess 
-Status: testing
-Devices: [National Instruments] PCI-6509 (ni_65xx), PXI-6509, PCI-6510,
-  PCI-6511, PXI-6511, PCI-6512, PXI-6512, PCI-6513, PXI-6513, PCI-6514,
-  PXI-6514, PCI-6515, PXI-6515, PCI-6516, PCI-6517, PCI-6518, PCI-6519,
-  PCI-6520, PCI-6521, PXI-6521, PCI-6528, PXI-6528
-Updated: Wed Oct 18 08:59:11 EDT 2006
-
-Based on the PCI-6527 driver by ds.
-The interrupt subdevice (subdevice 3) is probably broken for all boards
-except maybe the 6514.
-
-*/
+ * Driver: ni_65xx
+ * Description: National Instruments 65xx static dio boards
+ * Author: Jon Grierson ,
+ *Frank Mori Hess 
+ * Status: testing
+ * Devices: (National Instruments) PCI-6509 [ni_65xx]
+ * (National Instruments) PXI-6509 [ni_65xx]
+ * (National Instruments) PCI-6510 [ni_65xx]
+ * (National Instruments) PCI-6511 [ni_65xx]
+ * (National Instruments) PXI-6511 [ni_65xx]
+ * (National Instruments) PCI-6512 [ni_65xx]
+ * (National Instruments) PXI-6512 [ni_65xx]
+ * (National Instruments) PCI-6513 [ni_65xx]
+ * (National Instruments) PXI-6513 [ni_65xx]
+ * (National Instruments) PCI-6514 [ni_65xx]
+ * (National Instruments) PXI-6514 [ni_65xx]
+ * (National Instruments) PCI-6515 [ni_65xx]
+ * (National Instruments) PXI-6515 [ni_65xx]
+ * (National Instruments) PCI-6516 [ni_65xx]
+ * (National Instruments) PCI-6517 [ni_65xx]
+ * (National Instruments) PCI-6518 [ni_65xx]
+ * (National Instruments) PCI-6519 [ni_65xx]
+ * (National Instruments) PCI-6520 [ni_65xx]
+ * (National Instruments) PCI-6521 [ni_65xx]
+ * (National Instruments) PXI-6521 [ni_65xx]
+ * (National Instruments) PCI-6528 [ni_65xx]
+ * (National Instruments) PXI-6528 [ni_65xx]
+ * Updated: Wed Oct 18 08:59:11 EDT 2006
+ *
+ * Configuration Options: not applicable, uses PCI auto config
+ *
+ * Based on the PCI-6527 driver by ds.
+ * The interrupt subdevice (subdevice 3) is probably broken for all
+ * boards except maybe the 6514.
+ */
 
 /*
-   Manuals (available from ftp://ftp.natinst.com/support/manuals)
-
-   370106b.pdf 6514 Register Level Programmer Manual
-
+ * Manuals (available from ftp://ftp.natinst.com/support/manuals)
+ *
+ * 370106b.pdf 6514 Register Level Programmer Manual
  */
 
 #include 
-- 
1.9.3

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


[PATCH v2 10/18] staging: comedi: ni_65xx: tidy up the subdevice initialization

2014-07-14 Thread H Hartley Sweeten
For aesthetics, add some whitespace to the subdevice init.

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

diff --git a/drivers/staging/comedi/drivers/ni_65xx.c 
b/drivers/staging/comedi/drivers/ni_65xx.c
index 5218e67..07d5949 100644
--- a/drivers/staging/comedi/drivers/ni_65xx.c
+++ b/drivers/staging/comedi/drivers/ni_65xx.c
@@ -618,44 +618,44 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
 
s = &dev->subdevices[0];
if (board->num_di_ports) {
-   s->type = COMEDI_SUBD_DI;
-   s->subdev_flags = SDF_READABLE;
-   s->n_chan = NI_65XX_PORT_TO_CHAN(board->num_di_ports);
-   s->range_table = &range_digital;
-   s->maxdata = 1;
-   s->insn_config = ni_65xx_dio_insn_config;
-   s->insn_bits = ni_65xx_dio_insn_bits;
+   s->type = COMEDI_SUBD_DI;
+   s->subdev_flags = SDF_READABLE;
+   s->n_chan   = NI_65XX_PORT_TO_CHAN(board->num_di_ports);
+   s->maxdata  = 1;
+   s->range_table  = &range_digital;
+   s->insn_bits= ni_65xx_dio_insn_bits;
+   s->insn_config  = ni_65xx_dio_insn_config;
 
/* the input ports always start at port 0 */
s->private = (void *)0;
} else {
-   s->type = COMEDI_SUBD_UNUSED;
+   s->type = COMEDI_SUBD_UNUSED;
}
 
s = &dev->subdevices[1];
if (board->num_do_ports) {
-   s->type = COMEDI_SUBD_DO;
-   s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
-   s->n_chan = NI_65XX_PORT_TO_CHAN(board->num_do_ports);
-   s->range_table = &range_digital;
-   s->maxdata = 1;
-   s->insn_bits = ni_65xx_dio_insn_bits;
+   s->type = COMEDI_SUBD_DO;
+   s->subdev_flags = SDF_WRITABLE;
+   s->n_chan   = NI_65XX_PORT_TO_CHAN(board->num_do_ports);
+   s->maxdata  = 1;
+   s->range_table  = &range_digital;
+   s->insn_bits= ni_65xx_dio_insn_bits;
 
/* the output ports always start after the input ports */
s->private = (void *)(unsigned long)board->num_di_ports;
} else {
-   s->type = COMEDI_SUBD_UNUSED;
+   s->type = COMEDI_SUBD_UNUSED;
}
 
s = &dev->subdevices[2];
if (board->num_dio_ports) {
-   s->type = COMEDI_SUBD_DIO;
-   s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
-   s->n_chan = NI_65XX_PORT_TO_CHAN(board->num_dio_ports);
-   s->range_table = &range_digital;
-   s->maxdata = 1;
-   s->insn_config = ni_65xx_dio_insn_config;
-   s->insn_bits = ni_65xx_dio_insn_bits;
+   s->type = COMEDI_SUBD_DIO;
+   s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
+   s->n_chan   = NI_65XX_PORT_TO_CHAN(board->num_dio_ports);
+   s->maxdata  = 1;
+   s->range_table  = &range_digital;
+   s->insn_bits= ni_65xx_dio_insn_bits;
+   s->insn_config  = ni_65xx_dio_insn_config;
 
/* the input/output ports always start at port 0 */
s->private = (void *)0;
@@ -666,7 +666,7 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
   devpriv->mmio + NI_65XX_IO_SEL_REG(i));
}
} else {
-   s->type = COMEDI_SUBD_UNUSED;
+   s->type = COMEDI_SUBD_UNUSED;
}
 
s = &dev->subdevices[3];
-- 
1.9.3

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


[PATCH v2 09/18] staging: comedi: ni_65xx: tidy up the port<->chan conversions

2014-07-14 Thread H Hartley Sweeten
Introduce some convienence macros to handle the port to channel,
channel to port, and channel mask calculations based on the 8
channels per port of the hardware.

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

diff --git a/drivers/staging/comedi/drivers/ni_65xx.c 
b/drivers/staging/comedi/drivers/ni_65xx.c
index 742d3cd..5218e67 100644
--- a/drivers/staging/comedi/drivers/ni_65xx.c
+++ b/drivers/staging/comedi/drivers/ni_65xx.c
@@ -110,8 +110,10 @@ except maybe the 6514.
 #define NI_65XX_WDOG_HI_LO_REG(x)  (0x48 + NI_65XX_PORT(x))
 #define NI_65XX_RTSI_ENA(x)(0x49 + NI_65XX_PORT(x))
 
-#define NI_65XX_MAX_NUM_PORTS 12
-static const unsigned ni_65xx_channels_per_port = 8;
+#define NI_65XX_MAX_NUM_PORTS  12
+#define NI_65XX_PORT_TO_CHAN(x)((x) * 8)
+#define NI_65XX_CHAN_TO_PORT(x)((x) / 8)
+#define NI_65XX_CHAN_TO_MASK(x)(1 << ((x) % 8))
 
 enum ni_65xx_boardid {
BOARD_PCI6509,
@@ -258,11 +260,6 @@ static const struct ni_65xx_board ni_65xx_boards[] = {
},
 };
 
-static inline unsigned ni_65xx_port_by_channel(unsigned channel)
-{
-   return channel / ni_65xx_channels_per_port;
-}
-
 static inline unsigned ni_65xx_total_num_ports(const struct ni_65xx_board
   *board)
 {
@@ -282,8 +279,8 @@ static int ni_65xx_dio_insn_config(struct comedi_device 
*dev,
struct ni_65xx_private *devpriv = dev->private;
unsigned long base_port = (unsigned long)s->private;
unsigned int chan = CR_CHAN(insn->chanspec);
-   unsigned int chan_mask = 1 << (chan % ni_65xx_channels_per_port);
-   unsigned port = base_port + ni_65xx_port_by_channel(chan);
+   unsigned int chan_mask = NI_65XX_CHAN_TO_MASK(chan);
+   unsigned port = base_port + NI_65XX_CHAN_TO_PORT(chan);
unsigned int interval;
unsigned int val;
 
@@ -345,23 +342,23 @@ static int ni_65xx_dio_insn_config(struct comedi_device 
*dev,
 
 static int ni_65xx_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)
 {
const struct ni_65xx_board *board = comedi_board(dev);
-   unsigned long base_port = (unsigned long)s->private;
struct ni_65xx_private *devpriv = dev->private;
-   int base_bitfield_channel;
+   unsigned long base_port = (unsigned long)s->private;
+   unsigned int base_chan = CR_CHAN(insn->chanspec);
+   int last_port_offset = NI_65XX_CHAN_TO_PORT(s->n_chan - 1);
unsigned read_bits = 0;
-   int last_port_offset = ni_65xx_port_by_channel(s->n_chan - 1);
int port_offset;
 
-   base_bitfield_channel = CR_CHAN(insn->chanspec);
-   for (port_offset = ni_65xx_port_by_channel(base_bitfield_channel);
+   for (port_offset = NI_65XX_CHAN_TO_PORT(base_chan);
 port_offset <= last_port_offset; port_offset++) {
unsigned port = base_port + port_offset;
-   int base_port_channel = port_offset * ni_65xx_channels_per_port;
+   int base_port_channel = NI_65XX_PORT_TO_CHAN(port_offset);
unsigned port_mask, port_data, port_read_bits;
-   int bitshift = base_port_channel - base_bitfield_channel;
+   int bitshift = base_port_channel - base_chan;
 
if (bitshift >= 32)
break;
@@ -623,8 +620,7 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
if (board->num_di_ports) {
s->type = COMEDI_SUBD_DI;
s->subdev_flags = SDF_READABLE;
-   s->n_chan =
-   board->num_di_ports * ni_65xx_channels_per_port;
+   s->n_chan = NI_65XX_PORT_TO_CHAN(board->num_di_ports);
s->range_table = &range_digital;
s->maxdata = 1;
s->insn_config = ni_65xx_dio_insn_config;
@@ -640,8 +636,7 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
if (board->num_do_ports) {
s->type = COMEDI_SUBD_DO;
s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
-   s->n_chan =
-   board->num_do_ports * ni_65xx_channels_per_port;
+   s->n_chan = NI_65XX_PORT_TO_CHAN(board->num_do_ports);
s->range_table = &range_digital;
s->maxdata = 1;
s->insn_bits = ni_65xx_dio_insn_bits;
@@ -656,8 +651,7 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
if (board->num_dio_ports) {
s->type = COMEDI_SUBD_DIO;
s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
- 

[PATCH v2 01/18] staging: comedi: ni_65xx: filter interval register is 32-bit

2014-07-14 Thread H Hartley Sweeten
According to the register programming manual, the filter interval
register is 32-bit. Fix the writes to this register.

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

diff --git a/drivers/staging/comedi/drivers/ni_65xx.c 
b/drivers/staging/comedi/drivers/ni_65xx.c
index d6c1140..292355b 100644
--- a/drivers/staging/comedi/drivers/ni_65xx.c
+++ b/drivers/staging/comedi/drivers/ni_65xx.c
@@ -299,7 +299,7 @@ static int ni_65xx_config_filter(struct comedi_device *dev,
data[1] = interval * filter_resolution_ns;
 
if (interval != devpriv->filter_interval) {
-   writeb(interval, devpriv->mmio + Filter_Interval);
+   writel(interval, devpriv->mmio + Filter_Interval);
devpriv->filter_interval = interval;
}
 
@@ -689,7 +689,7 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
writeb(0x00, devpriv->mmio + Master_Interrupt_Control);
 
/* Set filter interval to 0  (32bit reg) */
-   writeb(0x, devpriv->mmio + Filter_Interval);
+   writel(0x, devpriv->mmio + Filter_Interval);
 
ret = request_irq(dev->irq, ni_65xx_interrupt, IRQF_SHARED,
  "ni_65xx", dev);
-- 
1.9.3

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


[PATCH v2 15/18] staging: comedi: ni_65xx: remove 'output_bits' from private data

2014-07-14 Thread H Hartley Sweeten
Remove the need for the 'output_bits' in the private data by just
reading the current state of the data port when updating the output
channels in the (*insn_bits) function.

Add a local variable to handle the inverting of the hardware values
when the boardinfo indicates that the outputs are inverted.

Rename the local variable 'port_read_bits' to 'bits' so that we can
use it for updating the output channels and reading back the actual
state to return to the user.

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

diff --git a/drivers/staging/comedi/drivers/ni_65xx.c 
b/drivers/staging/comedi/drivers/ni_65xx.c
index 46d4ebc..a6d5fde 100644
--- a/drivers/staging/comedi/drivers/ni_65xx.c
+++ b/drivers/staging/comedi/drivers/ni_65xx.c
@@ -129,7 +129,6 @@
 #define NI_65XX_WDOG_HI_LO_REG(x)  (0x48 + NI_65XX_PORT(x))
 #define NI_65XX_RTSI_ENA(x)(0x49 + NI_65XX_PORT(x))
 
-#define NI_65XX_MAX_NUM_PORTS  12
 #define NI_65XX_PORT_TO_CHAN(x)((x) * 8)
 #define NI_65XX_CHAN_TO_PORT(x)((x) / 8)
 #define NI_65XX_CHAN_TO_MASK(x)(1 << ((x) % 8))
@@ -287,7 +286,6 @@ static inline unsigned ni_65xx_total_num_ports(const struct 
ni_65xx_board
 
 struct ni_65xx_private {
void __iomem *mmio;
-   unsigned short output_bits[NI_65XX_MAX_NUM_PORTS];
 };
 
 static int ni_65xx_dio_insn_config(struct comedi_device *dev,
@@ -369,14 +367,19 @@ static int ni_65xx_dio_insn_bits(struct comedi_device 
*dev,
unsigned long base_port = (unsigned long)s->private;
unsigned int base_chan = CR_CHAN(insn->chanspec);
int last_port_offset = NI_65XX_CHAN_TO_PORT(s->n_chan - 1);
+   unsigned invert = 0x00;
unsigned read_bits = 0;
int port_offset;
 
+   /* handle inverted outputs if necessary */
+   if (s->type == COMEDI_SUBD_DO && board->invert_outputs)
+   invert = 0xff;
+
for (port_offset = NI_65XX_CHAN_TO_PORT(base_chan);
 port_offset <= last_port_offset; port_offset++) {
unsigned port = base_port + port_offset;
int base_port_channel = NI_65XX_PORT_TO_CHAN(port_offset);
-   unsigned port_mask, port_data, port_read_bits;
+   unsigned port_mask, port_data, bits;
int bitshift = base_port_channel - base_chan;
 
if (bitshift >= 32)
@@ -392,30 +395,26 @@ static int ni_65xx_dio_insn_bits(struct comedi_device 
*dev,
}
port_mask &= 0xff;
port_data &= 0xff;
+
+   /* update the outputs */
if (port_mask) {
-   unsigned bits;
-   devpriv->output_bits[port] &= ~port_mask;
-   devpriv->output_bits[port] |=
-   port_data & port_mask;
-   bits = devpriv->output_bits[port];
-   if (board->invert_outputs)
-   bits = ~bits;
+   bits = readb(devpriv->mmio + NI_65XX_IO_DATA_REG(port));
+   bits ^= invert;
+   bits &= ~port_mask;
+   bits |= (port_data & port_mask);
+   bits ^= invert;
writeb(bits, devpriv->mmio + NI_65XX_IO_DATA_REG(port));
}
-   port_read_bits = readb(devpriv->mmio +
-  NI_65XX_IO_DATA_REG(port));
-   if (s->type == COMEDI_SUBD_DO && board->invert_outputs) {
-   /* Outputs inverted, so invert value read back from
-* DO subdevice.  (Does not apply to boards with DIO
-* subdevice.) */
-   port_read_bits ^= 0xFF;
-   }
+
+   /* read back the actual state */
+   bits = readb(devpriv->mmio + NI_65XX_IO_DATA_REG(port));
+   bits ^= invert;
if (bitshift > 0)
-   port_read_bits <<= bitshift;
+   bits <<= bitshift;
else
-   port_read_bits >>= -bitshift;
+   bits >>= -bitshift;
 
-   read_bits |= port_read_bits;
+   read_bits |= bits;
}
data[1] = read_bits;
return insn->n;
-- 
1.9.3

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


[PATCH v2 03/18] staging: comedi: ni_65xx: cleanup recurring register map

2014-07-14 Thread H Hartley Sweeten
Convert the inline functions used to calculate the offsets to the
recurring port registers and rename them to remove the CamelCase.

Define all the recurring registers.

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

diff --git a/drivers/staging/comedi/drivers/ni_65xx.c 
b/drivers/staging/comedi/drivers/ni_65xx.c
index 42d2c24..83e4144 100644
--- a/drivers/staging/comedi/drivers/ni_65xx.c
+++ b/drivers/staging/comedi/drivers/ni_65xx.c
@@ -96,34 +96,22 @@ except maybe the 6514.
 #define NI_65XX_WDOG_STATUS_EXP(1 << 0)
 #define NI_65XX_WDOG_INTERVAL_REG  0x18 /* 32-bit */
 
+/* Recurring port registers (8-bit) */
+#define NI_65XX_PORT(x)((x) * 0x10)
+#define NI_65XX_IO_DATA_REG(x) (0x40 + NI_65XX_PORT(x))
+#define NI_65XX_IO_SEL_REG(x)  (0x41 + NI_65XX_PORT(x))
+#define NI_65XX_IO_SEL_OUTPUT  (0 << 0)
+#define NI_65XX_IO_SEL_INPUT   (1 << 0)
+#define NI_65XX_RISE_EDGE_ENA_REG(x)   (0x42 + NI_65XX_PORT(x))
+#define NI_65XX_FALL_EDGE_ENA_REG(x)   (0x43 + NI_65XX_PORT(x))
+#define NI_65XX_FILTER_ENA(x)  (0x44 + NI_65XX_PORT(x))
+#define NI_65XX_WDOG_HIZ_REG(x)(0x46 + NI_65XX_PORT(x))
+#define NI_65XX_WDOG_ENA(x)(0x47 + NI_65XX_PORT(x))
+#define NI_65XX_WDOG_HI_LO_REG(x)  (0x48 + NI_65XX_PORT(x))
+#define NI_65XX_RTSI_ENA(x)(0x49 + NI_65XX_PORT(x))
+
 #define NI_65XX_MAX_NUM_PORTS 12
 static const unsigned ni_65xx_channels_per_port = 8;
-static const unsigned ni_65xx_port_offset = 0x10;
-
-static inline unsigned Port_Data(unsigned port)
-{
-   return 0x40 + port * ni_65xx_port_offset;
-}
-
-static inline unsigned Port_Select(unsigned port)
-{
-   return 0x41 + port * ni_65xx_port_offset;
-}
-
-static inline unsigned Rising_Edge_Detection_Enable(unsigned port)
-{
-   return 0x42 + port * ni_65xx_port_offset;
-}
-
-static inline unsigned Falling_Edge_Detection_Enable(unsigned port)
-{
-   return 0x43 + port * ni_65xx_port_offset;
-}
-
-static inline unsigned Filter_Enable(unsigned port)
-{
-   return 0x44 + port * ni_65xx_port_offset;
-}
 
 enum ni_65xx_boardid {
BOARD_PCI6509,
@@ -333,7 +321,7 @@ static int ni_65xx_config_filter(struct comedi_device *dev,
}
 
writeb(devpriv->filter_enable[port],
-  devpriv->mmio + Filter_Enable(port));
+  devpriv->mmio + NI_65XX_FILTER_ENA(port));
 
return 2;
 }
@@ -357,14 +345,16 @@ static int ni_65xx_dio_insn_config(struct comedi_device 
*dev,
if (s->type != COMEDI_SUBD_DIO)
return -EINVAL;
devpriv->dio_direction[port] = COMEDI_OUTPUT;
-   writeb(0, devpriv->mmio + Port_Select(port));
+   writeb(NI_65XX_IO_SEL_OUTPUT,
+  devpriv->mmio + NI_65XX_IO_SEL_REG(port));
return 1;
break;
case INSN_CONFIG_DIO_INPUT:
if (s->type != COMEDI_SUBD_DIO)
return -EINVAL;
devpriv->dio_direction[port] = COMEDI_INPUT;
-   writeb(1, devpriv->mmio + Port_Select(port));
+   writeb(NI_65XX_IO_SEL_INPUT,
+  devpriv->mmio + NI_65XX_IO_SEL_REG(port));
return 1;
break;
case INSN_CONFIG_DIO_QUERY:
@@ -419,9 +409,10 @@ static int ni_65xx_dio_insn_bits(struct comedi_device *dev,
bits = devpriv->output_bits[port];
if (board->invert_outputs)
bits = ~bits;
-   writeb(bits, devpriv->mmio + Port_Data(port));
+   writeb(bits, devpriv->mmio + NI_65XX_IO_DATA_REG(port));
}
-   port_read_bits = readb(devpriv->mmio + Port_Data(port));
+   port_read_bits = readb(devpriv->mmio +
+  NI_65XX_IO_DATA_REG(port));
if (s->type == COMEDI_SUBD_DO && board->invert_outputs) {
/* Outputs inverted, so invert value read back from
 * DO subdevice.  (Does not apply to boards with DIO
@@ -547,21 +538,15 @@ static int ni_65xx_intr_insn_config(struct comedi_device 
*dev,
if (data[0] != INSN_CONFIG_CHANGE_NOTIFY)
return -EINVAL;
 
-   writeb(data[1], devpriv->mmio + Rising_Edge_Detection_Enable(0));
-   writeb(data[1] >> 8,
-  devpriv->mmio + Rising_Edge_Detection_Enable(0x10));
-   writeb(data[1] >> 16,
-  devpriv->mmio + Rising_Edge_Detection_Enable(0x20));
-   writeb(data[1] >> 24,
-  devpriv->mmio + Rising_Edge_Detection_Enable(0x30));
-
-   writeb(data[2], devpriv->mmio + Falling_Edge_Detection_Enable(0));
-   writeb(data[2] >> 8,
-  devpriv

[PATCH v2 13/18] staging: comedi: ni_65xx: update the MODULE_DESCRIPTION

2014-07-14 Thread H Hartley Sweeten
Update the MODULE_DESCRIPTION to better describe the driver.

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

diff --git a/drivers/staging/comedi/drivers/ni_65xx.c 
b/drivers/staging/comedi/drivers/ni_65xx.c
index 3b56359..e547c2f 100644
--- a/drivers/staging/comedi/drivers/ni_65xx.c
+++ b/drivers/staging/comedi/drivers/ni_65xx.c
@@ -781,5 +781,5 @@ static struct pci_driver ni_65xx_pci_driver = {
 module_comedi_pci_driver(ni_65xx_driver, ni_65xx_pci_driver);
 
 MODULE_AUTHOR("Comedi http://www.comedi.org";);
-MODULE_DESCRIPTION("Comedi low-level driver");
+MODULE_DESCRIPTION("Comedi driver for NI PCI-65xx static dio boards");
 MODULE_LICENSE("GPL");
-- 
1.9.3

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


[PATCH v2 18/18] staging: comedi: ni_65xx: factor input filter disable out of (*auto_attach)

2014-07-14 Thread H Hartley Sweeten
For aesthetics, factor the code that disables the input filters out of
ni_65xx_auto_attach().

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

diff --git a/drivers/staging/comedi/drivers/ni_65xx.c 
b/drivers/staging/comedi/drivers/ni_65xx.c
index a0deb01..cad2c28 100644
--- a/drivers/staging/comedi/drivers/ni_65xx.c
+++ b/drivers/staging/comedi/drivers/ni_65xx.c
@@ -278,16 +278,29 @@ static const struct ni_65xx_board ni_65xx_boards[] = {
},
 };
 
-static inline unsigned ni_65xx_total_num_ports(const struct ni_65xx_board
-  *board)
-{
-   return board->num_dio_ports + board->num_di_ports + board->num_do_ports;
-}
-
 struct ni_65xx_private {
void __iomem *mmio;
 };
 
+static void ni_65xx_disable_input_filters(struct comedi_device *dev)
+{
+   const struct ni_65xx_board *board = comedi_board(dev);
+   struct ni_65xx_private *devpriv = dev->private;
+   unsigned num_ports;
+   int i;
+
+   num_ports = board->num_dio_ports +
+   board->num_di_ports +
+   board->num_do_ports;
+
+   /* disable input filtering on all ports */
+   for (i = 0; i < num_ports; ++i)
+   writeb(0x00, devpriv->mmio + NI_65XX_FILTER_ENA(i));
+
+   /* set filter interval to 0 (32bit reg) */
+   writel(0x, devpriv->mmio + NI_65XX_FILTER_REG);
+}
+
 static int ni_65xx_dio_insn_config(struct comedi_device *dev,
   struct comedi_subdevice *s,
   struct comedi_insn *insn,
@@ -709,11 +722,7 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
s->cancel   = ni_65xx_intr_cancel;
}
 
-   for (i = 0; i < ni_65xx_total_num_ports(board); ++i)
-   writeb(0x00, devpriv->mmio + NI_65XX_FILTER_ENA(i));
-
-   /* Set filter interval to 0  (32bit reg) */
-   writel(0x, devpriv->mmio + NI_65XX_FILTER_REG);
+   ni_65xx_disable_input_filters(dev);
 
return 0;
 }
-- 
1.9.3

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


[PATCH v2 02/18] staging: comedi: ni_65xx: cleanup non-recurring register map defines

2014-07-14 Thread H Hartley Sweeten
Rename the CamelCase defines used for the non-recurring registers.

Define all the non-recurring registers and bits.

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

diff --git a/drivers/staging/comedi/drivers/ni_65xx.c 
b/drivers/staging/comedi/drivers/ni_65xx.c
index 292355b..42d2c24 100644
--- a/drivers/staging/comedi/drivers/ni_65xx.c
+++ b/drivers/staging/comedi/drivers/ni_65xx.c
@@ -51,8 +51,50 @@ except maybe the 6514.
 
 #include "comedi_fc.h"
 
-#define NI6514_DIO_SIZE 4096
-#define NI6514_MITE_SIZE 4096
+/*
+ * PCI BAR1 Register Map
+ */
+
+/* Non-recurring Registers (8-bit except where noted) */
+#define NI_65XX_ID_REG 0x00
+#define NI_65XX_CLR_REG0x01
+#define NI_65XX_CLR_WDOG_INT   (1 << 6)
+#define NI_65XX_CLR_WDOG_PING  (1 << 5)
+#define NI_65XX_CLR_WDOG_EXP   (1 << 4)
+#define NI_65XX_CLR_EDGE_INT   (1 << 3)
+#define NI_65XX_CLR_OVERFLOW_INT   (1 << 2)
+#define NI_65XX_STATUS_REG 0x02
+#define NI_65XX_STATUS_WDOG_INT(1 << 5)
+#define NI_65XX_STATUS_FALL_EDGE   (1 << 4)
+#define NI_65XX_STATUS_RISE_EDGE   (1 << 3)
+#define NI_65XX_STATUS_INT (1 << 2)
+#define NI_65XX_STATUS_OVERFLOW_INT(1 << 1)
+#define NI_65XX_STATUS_EDGE_INT(1 << 0)
+#define NI_65XX_CTRL_REG   0x03
+#define NI_65XX_CTRL_WDOG_ENA  (1 << 5)
+#define NI_65XX_CTRL_FALL_EDGE_ENA (1 << 4)
+#define NI_65XX_CTRL_RISE_EDGE_ENA (1 << 3)
+#define NI_65XX_CTRL_INT_ENA   (1 << 2)
+#define NI_65XX_CTRL_OVERFLOW_ENA  (1 << 1)
+#define NI_65XX_CTRL_EDGE_ENA  (1 << 0)
+#define NI_65XX_REV_REG0x04 /* 32-bit */
+#define NI_65XX_FILTER_REG 0x08 /* 32-bit */
+#define NI_65XX_RTSI_ROUTE_REG 0x0c /* 16-bit */
+#define NI_65XX_RTSI_EDGE_REG  0x0e /* 16-bit */
+#define NI_65XX_RTSI_WDOG_REG  0x10 /* 16-bit */
+#define NI_65XX_RTSI_TRIG_REG  0x12 /* 16-bit */
+#define NI_65XX_AUTO_CLK_SEL_REG   0x14 /* PXI-6528 only */
+#define NI_65XX_AUTO_CLK_SEL_STATUS(1 << 1)
+#define NI_65XX_AUTO_CLK_SEL_DISABLE   (1 << 0)
+#define NI_65XX_WDOG_CTRL_REG  0x15
+#define NI_65XX_WDOG_CTRL_ENA  (1 << 0)
+#define NI_65XX_RTSI_CFG_REG   0x16
+#define NI_65XX_RTSI_CFG_RISE_SENSE(1 << 2)
+#define NI_65XX_RTSI_CFG_FALL_SENSE(1 << 1)
+#define NI_65XX_RTSI_CFG_SYNC_DETECT   (1 << 0)
+#define NI_65XX_WDOG_STATUS_REG0x17
+#define NI_65XX_WDOG_STATUS_EXP(1 << 0)
+#define NI_65XX_WDOG_INTERVAL_REG  0x18 /* 32-bit */
 
 #define NI_65XX_MAX_NUM_PORTS 12
 static const unsigned ni_65xx_channels_per_port = 8;
@@ -83,26 +125,6 @@ static inline unsigned Filter_Enable(unsigned port)
return 0x44 + port * ni_65xx_port_offset;
 }
 
-#define ID_Register0x00
-
-#define Clear_Register 0x01
-#define ClrEdge0x08
-#define ClrOverflow0x04
-
-#define Filter_Interval0x08
-
-#define Change_Status  0x02
-#define MasterInterruptStatus  0x04
-#define Overflow   0x02
-#define EdgeStatus 0x01
-
-#define Master_Interrupt_Control   0x03
-#define FallingEdgeIntEnable   0x10
-#define RisingEdgeIntEnable0x08
-#define MasterInterruptEnable  0x04
-#define OverflowIntEnable  0x02
-#define EdgeIntEnable  0x01
-
 enum ni_65xx_boardid {
BOARD_PCI6509,
BOARD_PXI6509,
@@ -299,7 +321,7 @@ static int ni_65xx_config_filter(struct comedi_device *dev,
data[1] = interval * filter_resolution_ns;
 
if (interval != devpriv->filter_interval) {
-   writel(interval, devpriv->mmio + Filter_Interval);
+   writel(interval, devpriv->mmio + NI_65XX_FILTER_REG);
devpriv->filter_interval = interval;
}
 
@@ -424,13 +446,14 @@ static irqreturn_t ni_65xx_interrupt(int irq, void *d)
struct comedi_subdevice *s = dev->read_subdev;
unsigned int status;
 
-   status = readb(devpriv->mmio + Change_Status);
-   if ((status & MasterInterruptStatus) == 0)
+   status = readb(devpriv->mmio + NI_65XX_STATUS_REG);
+   if ((status & NI_65XX_STATUS_INT) == 0)
return IRQ_NONE;
-   if ((status & EdgeStatus) == 0)
+   if ((status & NI_65XX_STATUS_EDGE_INT) == 0)
return IRQ_NONE;
 
-   writeb(ClrEdge | ClrOverflow, devpriv->mmio + Clear_Register);
+   writeb(NI_65XX_CLR_EDGE_INT | NI_65XX_CLR_OVERFLOW_INT,
+  devpriv->mmio + NI_65XX_CLR_REG);
 
comedi_buf_put(s,

[PATCH v2 05/18] staging: comedi: ni_65xx: remove 'dio_direction' from private data

2014-07-14 Thread H Hartley Sweeten
The IO Select registers are readable. Remove the need for the
'dio_direction' member in the private data by just checking the
register value for the INSN_CONFIG_DIO_QUERY instruction.

Also, refactor the switch statement to return -EINVAL for unhandled
instructions and have the (*insn_config) return insn->n normally.

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

diff --git a/drivers/staging/comedi/drivers/ni_65xx.c 
b/drivers/staging/comedi/drivers/ni_65xx.c
index c8cd0e1..4b3f504 100644
--- a/drivers/staging/comedi/drivers/ni_65xx.c
+++ b/drivers/staging/comedi/drivers/ni_65xx.c
@@ -272,7 +272,6 @@ static inline unsigned ni_65xx_total_num_ports(const struct 
ni_65xx_board
 struct ni_65xx_private {
void __iomem *mmio;
unsigned short output_bits[NI_65XX_MAX_NUM_PORTS];
-   unsigned short dio_direction[NI_65XX_MAX_NUM_PORTS];
 };
 
 struct ni_65xx_subdevice_private {
@@ -322,35 +321,35 @@ static int ni_65xx_dio_insn_config(struct comedi_device 
*dev,
val &= ~chan_mask;
}
writeb(val, devpriv->mmio + NI_65XX_FILTER_ENA(port));
-
-   return insn->n;
+   break;
 
case INSN_CONFIG_DIO_OUTPUT:
if (s->type != COMEDI_SUBD_DIO)
return -EINVAL;
-   devpriv->dio_direction[port] = COMEDI_OUTPUT;
writeb(NI_65XX_IO_SEL_OUTPUT,
   devpriv->mmio + NI_65XX_IO_SEL_REG(port));
-   return 1;
break;
+
case INSN_CONFIG_DIO_INPUT:
if (s->type != COMEDI_SUBD_DIO)
return -EINVAL;
-   devpriv->dio_direction[port] = COMEDI_INPUT;
writeb(NI_65XX_IO_SEL_INPUT,
   devpriv->mmio + NI_65XX_IO_SEL_REG(port));
-   return 1;
break;
+
case INSN_CONFIG_DIO_QUERY:
if (s->type != COMEDI_SUBD_DIO)
return -EINVAL;
-   data[1] = devpriv->dio_direction[port];
-   return insn->n;
+   val = readb(devpriv->mmio + NI_65XX_IO_SEL_REG(port));
+   data[1] = (val == NI_65XX_IO_SEL_INPUT) ? COMEDI_INPUT
+   : COMEDI_OUTPUT;
break;
+
default:
-   break;
+   return -EINVAL;
}
-   return -EINVAL;
+
+   return insn->n;
 }
 
 static int ni_65xx_dio_insn_bits(struct comedi_device *dev,
-- 
1.9.3

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


[PATCH v2 07/18] staging: comedi: ni_65xx: hook up command support only if irq is available

2014-07-14 Thread H Hartley Sweeten
Subdevice 3 is used in this driver to provide edge detection of the input
channels.

Move the reset/disable of the interrupts and the request_irq() so that
when subdevice 3 is setup we can conditionally hookup the async command
support only if the irq is available.

Also, remove the noise when the irq is not available.

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

diff --git a/drivers/staging/comedi/drivers/ni_65xx.c 
b/drivers/staging/comedi/drivers/ni_65xx.c
index 7e562f1..517dbc6 100644
--- a/drivers/staging/comedi/drivers/ni_65xx.c
+++ b/drivers/staging/comedi/drivers/ni_65xx.c
@@ -582,7 +582,17 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
if (!devpriv->mmio)
return -ENOMEM;
 
-   dev->irq = pcidev->irq;
+   writeb(NI_65XX_CLR_EDGE_INT | NI_65XX_CLR_OVERFLOW_INT,
+  devpriv->mmio + NI_65XX_CLR_REG);
+   writeb(0x00, devpriv->mmio + NI_65XX_CTRL_REG);
+
+   if (pcidev->irq) {
+   ret = request_irq(pcidev->irq, ni_65xx_interrupt, IRQF_SHARED,
+ dev->board_name, dev);
+   if (ret == 0)
+   dev->irq = pcidev->irq;
+   }
+
dev_info(dev->class_dev, "board: %s, ID=0x%02x", dev->board_name,
   readb(devpriv->mmio + NI_65XX_ID_REG));
 
@@ -647,18 +657,21 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
}
 
s = &dev->subdevices[3];
-   dev->read_subdev = s;
-   s->type = COMEDI_SUBD_DI;
-   s->subdev_flags = SDF_READABLE | SDF_CMD_READ;
-   s->n_chan = 1;
-   s->range_table = &range_unknown;
-   s->maxdata = 1;
-   s->len_chanlist = 1;
-   s->do_cmdtest = ni_65xx_intr_cmdtest;
-   s->do_cmd = ni_65xx_intr_cmd;
-   s->cancel = ni_65xx_intr_cancel;
-   s->insn_bits = ni_65xx_intr_insn_bits;
-   s->insn_config = ni_65xx_intr_insn_config;
+   s->type = COMEDI_SUBD_DI;
+   s->subdev_flags = SDF_READABLE;
+   s->n_chan   = 1;
+   s->maxdata  = 1;
+   s->range_table  = &range_digital;
+   s->insn_bits= ni_65xx_intr_insn_bits;
+   if (dev->irq) {
+   dev->read_subdev = s;
+   s->subdev_flags |= SDF_CMD_READ;
+   s->len_chanlist = 1;
+   s->insn_config  = ni_65xx_intr_insn_config;
+   s->do_cmdtest   = ni_65xx_intr_cmdtest;
+   s->do_cmd   = ni_65xx_intr_cmd;
+   s->cancel   = ni_65xx_intr_cancel;
+   }
 
for (i = 0; i < ni_65xx_total_num_ports(board); ++i) {
writeb(0x00, devpriv->mmio + NI_65XX_FILTER_ENA(i));
@@ -667,20 +680,10 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
else
writeb(0x00, devpriv->mmio + NI_65XX_IO_DATA_REG(i));
}
-   writeb(NI_65XX_CLR_EDGE_INT | NI_65XX_CLR_OVERFLOW_INT,
-  devpriv->mmio + NI_65XX_CLR_REG);
-   writeb(0x00, devpriv->mmio + NI_65XX_CTRL_REG);
 
/* Set filter interval to 0  (32bit reg) */
writel(0x, devpriv->mmio + NI_65XX_FILTER_REG);
 
-   ret = request_irq(dev->irq, ni_65xx_interrupt, IRQF_SHARED,
- "ni_65xx", dev);
-   if (ret < 0) {
-   dev->irq = 0;
-   dev_warn(dev->class_dev, "irq not available\n");
-   }
-
return 0;
 }
 
-- 
1.9.3

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


[PATCH v2 17/18] staging: comedi: ni_65xx: fix digital output reset during attach

2014-07-14 Thread H Hartley Sweeten
During the attach of this driver, the digital output ports are all
initialized to a known state. Some of the boards supported by this
driver have output ports that are inverted from the comedi view of
the output state. For these boards the values written to the ports
needs to be inverted.

Currently, only bit 0 of each port is inverted when the boardinfo
indicates that the outputs are inverted. This results in channels
0, 8, 16, etc. being set to '0' and all other channels being set
to '1'. If the boardinfo does not indicate that the outputs are
inverted, all the channels are set to '0'.

This initialization is unnecessary for the input only ports. The
input/output ports also do not need to be initialized since they
are configured as inputs during the attach.

Move the output port initialization so it occurs when the digital
output subdevice is setup. Use the 's->io_bits' value to initialize
the ports so that the correct inverted/non-inverted state is used
for the comedi '0' value.

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

diff --git a/drivers/staging/comedi/drivers/ni_65xx.c 
b/drivers/staging/comedi/drivers/ni_65xx.c
index 3e25e4e..a0deb01 100644
--- a/drivers/staging/comedi/drivers/ni_65xx.c
+++ b/drivers/staging/comedi/drivers/ni_65xx.c
@@ -659,6 +659,13 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
 
/* use the io_bits to handle the inverted outputs */
s->io_bits  = (board->invert_outputs) ? 0xff : 0x00;
+
+   /* reset all output ports to comedi '0' */
+   for (i = 0; i < board->num_do_ports; ++i) {
+   writeb(s->io_bits,  /* inverted if necessary */
+  devpriv->mmio +
+  NI_65XX_IO_DATA_REG(board->num_di_ports + i));
+   }
} else {
s->type = COMEDI_SUBD_UNUSED;
}
@@ -702,13 +709,8 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
s->cancel   = ni_65xx_intr_cancel;
}
 
-   for (i = 0; i < ni_65xx_total_num_ports(board); ++i) {
+   for (i = 0; i < ni_65xx_total_num_ports(board); ++i)
writeb(0x00, devpriv->mmio + NI_65XX_FILTER_ENA(i));
-   if (board->invert_outputs)
-   writeb(0x01, devpriv->mmio + NI_65XX_IO_DATA_REG(i));
-   else
-   writeb(0x00, devpriv->mmio + NI_65XX_IO_DATA_REG(i));
-   }
 
/* Set filter interval to 0  (32bit reg) */
writel(0x, devpriv->mmio + NI_65XX_FILTER_REG);
-- 
1.9.3

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


[PATCH v2 16/18] staging: comedi: ni_65xx: use the subdevice 'io_bits' to handle the 'invert_outputs'

2014-07-14 Thread H Hartley Sweeten
Some of the boards supported by this driver have output ports that are
inverted from the comedi view of the output state. For these boards the
read values from the output ports needs to be inverted before being
modified and inverted again before being written back in the (*insn_bits)
operation.

Currently the subdevice type and the boardinfo is checked in the (*insn_bits)
to determine if the inverted outputs need to be handled.

Since thise driver does not use the subdevice 'io_bits', simplify the driver
a bit by initializing the 'io_bits' during the attach to handle the inversion.

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

diff --git a/drivers/staging/comedi/drivers/ni_65xx.c 
b/drivers/staging/comedi/drivers/ni_65xx.c
index a6d5fde..3e25e4e 100644
--- a/drivers/staging/comedi/drivers/ni_65xx.c
+++ b/drivers/staging/comedi/drivers/ni_65xx.c
@@ -362,19 +362,13 @@ static int ni_65xx_dio_insn_bits(struct comedi_device 
*dev,
 struct comedi_insn *insn,
 unsigned int *data)
 {
-   const struct ni_65xx_board *board = comedi_board(dev);
struct ni_65xx_private *devpriv = dev->private;
unsigned long base_port = (unsigned long)s->private;
unsigned int base_chan = CR_CHAN(insn->chanspec);
int last_port_offset = NI_65XX_CHAN_TO_PORT(s->n_chan - 1);
-   unsigned invert = 0x00;
unsigned read_bits = 0;
int port_offset;
 
-   /* handle inverted outputs if necessary */
-   if (s->type == COMEDI_SUBD_DO && board->invert_outputs)
-   invert = 0xff;
-
for (port_offset = NI_65XX_CHAN_TO_PORT(base_chan);
 port_offset <= last_port_offset; port_offset++) {
unsigned port = base_port + port_offset;
@@ -399,16 +393,16 @@ static int ni_65xx_dio_insn_bits(struct comedi_device 
*dev,
/* update the outputs */
if (port_mask) {
bits = readb(devpriv->mmio + NI_65XX_IO_DATA_REG(port));
-   bits ^= invert;
+   bits ^= s->io_bits; /* invert if necessary */
bits &= ~port_mask;
bits |= (port_data & port_mask);
-   bits ^= invert;
+   bits ^= s->io_bits; /* invert back */
writeb(bits, devpriv->mmio + NI_65XX_IO_DATA_REG(port));
}
 
/* read back the actual state */
bits = readb(devpriv->mmio + NI_65XX_IO_DATA_REG(port));
-   bits ^= invert;
+   bits ^= s->io_bits; /* invert if necessary */
if (bitshift > 0)
bits <<= bitshift;
else
@@ -662,6 +656,9 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
 
/* the output ports always start after the input ports */
s->private = (void *)(unsigned long)board->num_di_ports;
+
+   /* use the io_bits to handle the inverted outputs */
+   s->io_bits  = (board->invert_outputs) ? 0xff : 0x00;
} else {
s->type = COMEDI_SUBD_UNUSED;
}
-- 
1.9.3

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


[PATCH v2 04/18] staging: comedi: ni_65xx: cleanup INSN_CONFIG_FILTER handling

2014-07-14 Thread H Hartley Sweeten
The INSN_CONFIG_FILTER instruction is used to set the deglitch filter
interval used to debounce the input channels.

Absorb the helper function into the (*insn_config) function and refactor
the code to not require the 'filter_interval' and 'filter_enable' members
in the private data.

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

diff --git a/drivers/staging/comedi/drivers/ni_65xx.c 
b/drivers/staging/comedi/drivers/ni_65xx.c
index 83e4144..c8cd0e1 100644
--- a/drivers/staging/comedi/drivers/ni_65xx.c
+++ b/drivers/staging/comedi/drivers/ni_65xx.c
@@ -271,8 +271,6 @@ static inline unsigned ni_65xx_total_num_ports(const struct 
ni_65xx_board
 
 struct ni_65xx_private {
void __iomem *mmio;
-   unsigned int filter_interval;
-   unsigned short filter_enable[NI_65XX_MAX_NUM_PORTS];
unsigned short output_bits[NI_65XX_MAX_NUM_PORTS];
unsigned short dio_direction[NI_65XX_MAX_NUM_PORTS];
 };
@@ -287,60 +285,46 @@ static inline struct ni_65xx_subdevice_private 
*sprivate(struct comedi_subdevice
return subdev->private;
 }
 
-static int ni_65xx_config_filter(struct comedi_device *dev,
-struct comedi_subdevice *s,
-struct comedi_insn *insn, unsigned int *data)
-{
-   struct ni_65xx_private *devpriv = dev->private;
-   const unsigned chan = CR_CHAN(insn->chanspec);
-   const unsigned port =
-   sprivate(s)->base_port + ni_65xx_port_by_channel(chan);
-
-   if (data[0] != INSN_CONFIG_FILTER)
-   return -EINVAL;
-   if (data[1]) {
-   static const unsigned filter_resolution_ns = 200;
-   static const unsigned max_filter_interval = 0xf;
-   unsigned interval =
-   (data[1] +
-(filter_resolution_ns / 2)) / filter_resolution_ns;
-   if (interval > max_filter_interval)
-   interval = max_filter_interval;
-   data[1] = interval * filter_resolution_ns;
-
-   if (interval != devpriv->filter_interval) {
-   writel(interval, devpriv->mmio + NI_65XX_FILTER_REG);
-   devpriv->filter_interval = interval;
-   }
-
-   devpriv->filter_enable[port] |=
-   1 << (chan % ni_65xx_channels_per_port);
-   } else {
-   devpriv->filter_enable[port] &=
-   ~(1 << (chan % ni_65xx_channels_per_port));
-   }
-
-   writeb(devpriv->filter_enable[port],
-  devpriv->mmio + NI_65XX_FILTER_ENA(port));
-
-   return 2;
-}
-
 static int ni_65xx_dio_insn_config(struct comedi_device *dev,
   struct comedi_subdevice *s,
-  struct comedi_insn *insn, unsigned int *data)
+  struct comedi_insn *insn,
+  unsigned int *data)
 {
struct ni_65xx_private *devpriv = dev->private;
-   unsigned port;
+   unsigned int chan = CR_CHAN(insn->chanspec);
+   unsigned int chan_mask = 1 << (chan % ni_65xx_channels_per_port);
+   unsigned port = sprivate(s)->base_port + ni_65xx_port_by_channel(chan);
+   unsigned int interval;
+   unsigned int val;
 
-   if (insn->n < 1)
-   return -EINVAL;
-   port = sprivate(s)->base_port +
-   ni_65xx_port_by_channel(CR_CHAN(insn->chanspec));
switch (data[0]) {
case INSN_CONFIG_FILTER:
-   return ni_65xx_config_filter(dev, s, insn, data);
-   break;
+   /*
+* The deglitch filter interval is specified in nanoseconds.
+* The hardware supports intervals in 200ns increments. Round
+* the user values up and return the actual interval.
+*/
+   interval = (data[1] + 100) / 200;
+   if (interval > 0xf)
+   interval = 0xf;
+   data[1] = interval * 200;
+
+   /*
+* Enable/disable the channel for deglitch filtering. Note
+* that the filter interval is never set to '0'. This is done
+* because other channels might still be enabled for filtering.
+*/
+   val = readb(devpriv->mmio + NI_65XX_FILTER_ENA(port));
+   if (interval) {
+   writel(interval, devpriv->mmio + NI_65XX_FILTER_REG);
+   val |= chan_mask;
+   } else {
+   val &= ~chan_mask;
+   }
+   writeb(val, devpriv->mmio + NI_65XX_FILTER_ENA(port));
+
+   return insn->n;
+
case INSN_CONFIG_DIO_OUTPUT:
if (s->type != COMEDI_SUBD_DIO)
 

[PATCH v2 14/18] staging: comedi: ni_65xx: tidy ni_65xx_intr_insn_bits() declaration

2014-07-14 Thread H Hartley Sweeten
For aesthetics, tidy up the whitespace of this function declarations to
follow the form in the rest of the driver.

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

diff --git a/drivers/staging/comedi/drivers/ni_65xx.c 
b/drivers/staging/comedi/drivers/ni_65xx.c
index e547c2f..46d4ebc 100644
--- a/drivers/staging/comedi/drivers/ni_65xx.c
+++ b/drivers/staging/comedi/drivers/ni_65xx.c
@@ -511,7 +511,8 @@ static int ni_65xx_intr_cancel(struct comedi_device *dev,
 
 static int ni_65xx_intr_insn_bits(struct comedi_device *dev,
  struct comedi_subdevice *s,
- struct comedi_insn *insn, unsigned int *data)
+ struct comedi_insn *insn,
+ unsigned int *data)
 {
data[1] = 0;
return insn->n;
-- 
1.9.3

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


[PATCH v2 00/18] staging: comedi: ni_65xx: cleanup driver

2014-07-14 Thread H Hartley Sweeten
This series cleans up the comedi ni_65xx driver.

v2: drop the patch that removed the 'invert_outputs' from the boardinfo
 reorder the series a bit to handle the 'invert_outputs' correctly

Depends on:
[PATCH 0/4] staging: comedi: remove unnecessary COMEDI_MITE dependancies   

H Hartley Sweeten (18):
  staging: comedi: ni_65xx: filter interval register is 32-bit
  staging: comedi: ni_65xx: cleanup non-recurring register map defines
  staging: comedi: ni_65xx: cleanup recurring register map
  staging: comedi: ni_65xx: cleanup INSN_CONFIG_FILTER handling
  staging: comedi: ni_65xx: remove 'dio_direction' from private data
  staging: comedi: ni_65xx: remove the need for the subdevice private data
  staging: comedi: ni_65xx: hook up command support only if irq is available
  staging: comedi: ni_65xx: fix ni_65xx_intr_insn_config()
  staging: comedi: ni_65xx: tidy up the port<->chan conversions
  staging: comedi: ni_65xx: tidy up the subdevice initialization
  staging: comedi: ni_65xx: tidy up the comedi_driver declaration
  staging: comedi: ni_65xx: clean up multi-line comments
  staging: comedi: ni_65xx: update the MODULE_DESCRIPTION
  staging: comedi: ni_65xx: tidy ni_65xx_intr_insn_bits() declaration
  staging: comedi: ni_65xx: remove 'output_bits' from private data
  staging: comedi: ni_65xx: use the subdevice 'io_bits' to handle the 
'invert_outputs'
  staging: comedi: ni_65xx: fix digital output reset during attach
  staging: comedi: ni_65xx: factor input filter disable out of (*auto_attach)

 drivers/staging/comedi/drivers/ni_65xx.c | 624 ---
 1 file changed, 325 insertions(+), 299 deletions(-)

-- 
1.9.3

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


[PATCH v2 11/18] staging: comedi: ni_65xx: tidy up the comedi_driver declaration

2014-07-14 Thread H Hartley Sweeten
For aesthetics, add some whitespace to the comedi_driver declaration.

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

diff --git a/drivers/staging/comedi/drivers/ni_65xx.c 
b/drivers/staging/comedi/drivers/ni_65xx.c
index 07d5949..6c194fc 100644
--- a/drivers/staging/comedi/drivers/ni_65xx.c
+++ b/drivers/staging/comedi/drivers/ni_65xx.c
@@ -714,10 +714,10 @@ static void ni_65xx_detach(struct comedi_device *dev)
 }
 
 static struct comedi_driver ni_65xx_driver = {
-   .driver_name = "ni_65xx",
-   .module = THIS_MODULE,
-   .auto_attach = ni_65xx_auto_attach,
-   .detach = ni_65xx_detach,
+   .driver_name= "ni_65xx",
+   .module = THIS_MODULE,
+   .auto_attach= ni_65xx_auto_attach,
+   .detach = ni_65xx_detach,
 };
 
 static int ni_65xx_pci_probe(struct pci_dev *dev,
-- 
1.9.3

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


[PATCH 3/4] staging: comedi: ni_65xx: remove COMEDI_MITE and HAS_DMA dependancy

2014-07-14 Thread H Hartley Sweeten
The mite module provides the DMA interface for the PCI MITE ASIC used on
many National Instruments DAQ boards. This driver does not use DMA and only
depends on the mite module to initialize the MITE ASIC.

Handle the initialization localy and remove the unnecessary dependancies.

Signed-off-by: H Hartley Sweeten 
Reviewed-by: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/Kconfig   |   2 -
 drivers/staging/comedi/drivers/ni_65xx.c | 127 +++
 2 files changed, 60 insertions(+), 69 deletions(-)

diff --git a/drivers/staging/comedi/Kconfig b/drivers/staging/comedi/Kconfig
index 0c079d2..8304c39 100644
--- a/drivers/staging/comedi/Kconfig
+++ b/drivers/staging/comedi/Kconfig
@@ -1014,8 +1014,6 @@ config COMEDI_NI_6527
 
 config COMEDI_NI_65XX
tristate "NI 65xx static dio PCI card support"
-   depends on HAS_DMA
-   select COMEDI_MITE
---help---
  Enable support for National Instruments 65xx static dio boards.
  Supported devices: National Instruments PCI-6509 (ni_65xx),
diff --git a/drivers/staging/comedi/drivers/ni_65xx.c 
b/drivers/staging/comedi/drivers/ni_65xx.c
index 59f592e..d6c1140 100644
--- a/drivers/staging/comedi/drivers/ni_65xx.c
+++ b/drivers/staging/comedi/drivers/ni_65xx.c
@@ -50,7 +50,6 @@ except maybe the 6514.
 #include "../comedidev.h"
 
 #include "comedi_fc.h"
-#include "mite.h"
 
 #define NI6514_DIO_SIZE 4096
 #define NI6514_MITE_SIZE 4096
@@ -261,7 +260,7 @@ static inline unsigned ni_65xx_total_num_ports(const struct 
ni_65xx_board
 }
 
 struct ni_65xx_private {
-   struct mite_struct *mite;
+   void __iomem *mmio;
unsigned int filter_interval;
unsigned short filter_enable[NI_65XX_MAX_NUM_PORTS];
unsigned short output_bits[NI_65XX_MAX_NUM_PORTS];
@@ -300,9 +299,7 @@ static int ni_65xx_config_filter(struct comedi_device *dev,
data[1] = interval * filter_resolution_ns;
 
if (interval != devpriv->filter_interval) {
-   writeb(interval,
-  devpriv->mite->daq_io_addr +
-  Filter_Interval);
+   writeb(interval, devpriv->mmio + Filter_Interval);
devpriv->filter_interval = interval;
}
 
@@ -314,7 +311,7 @@ static int ni_65xx_config_filter(struct comedi_device *dev,
}
 
writeb(devpriv->filter_enable[port],
-  devpriv->mite->daq_io_addr + Filter_Enable(port));
+  devpriv->mmio + Filter_Enable(port));
 
return 2;
 }
@@ -338,14 +335,14 @@ static int ni_65xx_dio_insn_config(struct comedi_device 
*dev,
if (s->type != COMEDI_SUBD_DIO)
return -EINVAL;
devpriv->dio_direction[port] = COMEDI_OUTPUT;
-   writeb(0, devpriv->mite->daq_io_addr + Port_Select(port));
+   writeb(0, devpriv->mmio + Port_Select(port));
return 1;
break;
case INSN_CONFIG_DIO_INPUT:
if (s->type != COMEDI_SUBD_DIO)
return -EINVAL;
devpriv->dio_direction[port] = COMEDI_INPUT;
-   writeb(1, devpriv->mite->daq_io_addr + Port_Select(port));
+   writeb(1, devpriv->mmio + Port_Select(port));
return 1;
break;
case INSN_CONFIG_DIO_QUERY:
@@ -400,12 +397,9 @@ static int ni_65xx_dio_insn_bits(struct comedi_device *dev,
bits = devpriv->output_bits[port];
if (board->invert_outputs)
bits = ~bits;
-   writeb(bits,
-  devpriv->mite->daq_io_addr +
-  Port_Data(port));
+   writeb(bits, devpriv->mmio + Port_Data(port));
}
-   port_read_bits =
-   readb(devpriv->mite->daq_io_addr + Port_Data(port));
+   port_read_bits = readb(devpriv->mmio + Port_Data(port));
if (s->type == COMEDI_SUBD_DO && board->invert_outputs) {
/* Outputs inverted, so invert value read back from
 * DO subdevice.  (Does not apply to boards with DIO
@@ -430,14 +424,13 @@ static irqreturn_t ni_65xx_interrupt(int irq, void *d)
struct comedi_subdevice *s = dev->read_subdev;
unsigned int status;
 
-   status = readb(devpriv->mite->daq_io_addr + Change_Status);
+   status = readb(devpriv->mmio + Change_Status);
if ((status & MasterInterruptStatus) == 0)
return IRQ_NONE;
if ((status & EdgeStatus) == 0)
return IRQ_NONE;
 
-   writeb(ClrEdge | ClrOverflow,
-  devpriv->mite->daq_io_addr + Clear_Register);
+   writeb(ClrEdge | ClrOverflow, devpriv->mmio + Clear_Register);
 
comedi_buf_put(s, 0);
s->async->events |= COMEDI_CB_EOS;

[PATCH 2/4] staging: comedi: ni_labpc_pci: remove COMEDI_MITE and HAS_DMA dependancy

2014-07-14 Thread H Hartley Sweeten
The mite module provides the DMA interface for the PCI MITE ASIC used on
many National Instruments DAQ boards. This driver does not use DMA and only
depends on the mite module to initialize the MITE ASIC.

Handle the initialization localy and remove the unnecessary dependancies.

Signed-off-by: H Hartley Sweeten 
Reviewed-by: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/Kconfig|  2 --
 drivers/staging/comedi/drivers/ni_labpc.h |  1 -
 drivers/staging/comedi/drivers/ni_labpc_pci.c | 48 +++
 3 files changed, 35 insertions(+), 16 deletions(-)

diff --git a/drivers/staging/comedi/Kconfig b/drivers/staging/comedi/Kconfig
index 8d992a8..0c079d2 100644
--- a/drivers/staging/comedi/Kconfig
+++ b/drivers/staging/comedi/Kconfig
@@ -1049,9 +1049,7 @@ config COMEDI_NI_670X
 
 config COMEDI_NI_LABPC_PCI
tristate "NI Lab-PC PCI-1200 support"
-   depends on HAS_DMA
select COMEDI_NI_LABPC
-   select COMEDI_MITE
---help---
  Enable support for National Instruments Lab-PC PCI-1200.
 
diff --git a/drivers/staging/comedi/drivers/ni_labpc.h 
b/drivers/staging/comedi/drivers/ni_labpc.h
index 486589f..0fb4311 100644
--- a/drivers/staging/comedi/drivers/ni_labpc.h
+++ b/drivers/staging/comedi/drivers/ni_labpc.h
@@ -36,7 +36,6 @@ struct labpc_boardinfo {
 };
 
 struct labpc_private {
-   struct mite_struct *mite;   /*  for mite chip on pci-1200 */
/*  number of data points left to be taken */
unsigned long long count;
/*  software copy of analog output values */
diff --git a/drivers/staging/comedi/drivers/ni_labpc_pci.c 
b/drivers/staging/comedi/drivers/ni_labpc_pci.c
index 358c4af..5b59be3 100644
--- a/drivers/staging/comedi/drivers/ni_labpc_pci.c
+++ b/drivers/staging/comedi/drivers/ni_labpc_pci.c
@@ -35,7 +35,6 @@
 
 #include "../comedidev.h"
 
-#include "mite.h"
 #include "ni_labpc.h"
 
 enum labpc_pci_boardid {
@@ -53,12 +52,36 @@ static const struct labpc_boardinfo labpc_pci_boards[] = {
},
 };
 
+/* ripped from mite.h and mite_setup2() to avoid mite dependancy */
+#define MITE_IODWBSR   0xc0 /* IO Device Window Base Size Register */
+#define WENAB  (1 << 7) /* window enable */
+
+static int labpc_pci_mite_init(struct pci_dev *pcidev)
+{
+   void __iomem *mite_base;
+   u32 main_phys_addr;
+
+   /* ioremap the MITE registers (BAR 0) temporarily */
+   mite_base = pci_ioremap_bar(pcidev, 0);
+   if (!mite_base)
+   return -ENOMEM;
+
+   /* set data window to main registers (BAR 1) */
+   main_phys_addr = pci_resource_start(pcidev, 1);
+   writel(main_phys_addr | WENAB, mite_base + MITE_IODWBSR);
+
+   /* finished with MITE registers */
+   iounmap(mite_base);
+   return 0;
+}
+
 static int labpc_pci_auto_attach(struct comedi_device *dev,
 unsigned long context)
 {
struct pci_dev *pcidev = comedi_to_pci_dev(dev);
const struct labpc_boardinfo *board = NULL;
struct labpc_private *devpriv;
+   void __iomem *mmio;
int ret;
 
if (context < ARRAY_SIZE(labpc_pci_boards))
@@ -72,27 +95,26 @@ static int labpc_pci_auto_attach(struct comedi_device *dev,
if (ret)
return ret;
 
-   devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
-   if (!devpriv)
+   ret = labpc_pci_mite_init(pcidev);
+   if (ret)
+   return ret;
+
+   mmio = pci_ioremap_bar(pcidev, 1);
+   if (!mmio)
return -ENOMEM;
+   dev->iobase = (unsigned long)mmio;
 
-   devpriv->mite = mite_alloc(pcidev);
-   if (!devpriv->mite)
+   devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
+   if (!devpriv)
return -ENOMEM;
-   ret = mite_setup(devpriv->mite);
-   if (ret < 0)
-   return ret;
-   dev->iobase = (unsigned long)devpriv->mite->daq_io_addr;
 
return labpc_common_attach(dev, pcidev->irq, IRQF_SHARED);
 }
 
 static void labpc_pci_detach(struct comedi_device *dev)
 {
-   struct labpc_private *devpriv = dev->private;
-
-   if (devpriv)
-   mite_detach(devpriv->mite);
+   if (dev->iobase)
+   iounmap((void __iomem *)dev->iobase);
if (dev->irq)
free_irq(dev->irq, dev);
comedi_pci_disable(dev);
-- 
1.9.3

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


  1   2   >