RE: staging tree closed for 3.7

2012-09-26 Thread H Hartley Sweeten
On Wednesday, September 26, 2012 10:57 AM, Greg Kroah-Hartman wrote:
 On Wed, Sep 26, 2012 at 10:56:06AM -0700, Greg Kroah-Hartman wrote:
 
 With 3.6 about to be released, I've now closed the 3.7 staging-next tree
 for new features / cleanups.  It's bug-fixes only now until 3.7-rc1 is
 out.

 Oh, and if I've missed any patches that people have sent me already,
 please let me know, because I don't have them anymore.

Greg,

What about my staging: comedi: drivers: use comedi_fc.h cmdtest helpers?

It's quite large but does have decent diffstat:
46 files changed, 766 insertions(+), 1997 deletions(-)

If it doesn't apply due to conflicts, or you would rather just wait
until 3.7-rc1, it's not a problem.

I have updated the patch to fix the typo Ian pointed out and to remove
the Reported-by signoff from Dan if you would like me to repost it.

Regards,
Hartley

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: staging tree closed for 3.7

2012-09-26 Thread H Hartley Sweeten
On Wednesday, September 26, 2012 1:05 PM, Greg Kroah-Hartman wrote:
 On Wed, Sep 26, 2012 at 01:47:11PM -0500, H Hartley Sweeten wrote:
 On Wednesday, September 26, 2012 10:57 AM, Greg Kroah-Hartman wrote:
 On Wed, Sep 26, 2012 at 10:56:06AM -0700, Greg Kroah-Hartman wrote:
 
 With 3.6 about to be released, I've now closed the 3.7 staging-next tree
 for new features / cleanups.  It's bug-fixes only now until 3.7-rc1 is
 out.

 Oh, and if I've missed any patches that people have sent me already,
 please let me know, because I don't have them anymore.
 
 Greg,
 
 What about my staging: comedi: drivers: use comedi_fc.h cmdtest helpers?
 
 It's quite large but does have decent diffstat:
 46 files changed, 766 insertions(+), 1997 deletions(-)

 Care to resend it?  I thought that was part of the __user rework, my
 apologies.

Not a problem. Just reposted it (v2).

 If it doesn't apply due to conflicts, or you would rather just wait
 until 3.7-rc1, it's not a problem.
 
 I have updated the patch to fix the typo Ian pointed out and to remove
 the Reported-by signoff from Dan if you would like me to repost it.

 Please redo it and resend it, that must have been why I didn't apply it,
 I was waiting for a newer version :)

If there is a merge issue please let me know. If so I'll wait until 3.7-rc1 is
out and rebase the patch.

Thanks!
Hartley

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Q: Kconfig option VIRT_TO_BUS

2012-11-12 Thread H Hartley Sweeten
Hello all,

Does anyone know what the Kconfig option VIRT_TO_BUS does?
There are a number of depends on that option but it does not
seem to directly enable any code in the kernel.

Thanks for any reply.

Regards,
Hartley
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: Q: Kconfig option VIRT_TO_BUS

2012-11-12 Thread H Hartley Sweeten
On Monday, November 12, 2012 11:41 AM, Bjorn Helgaas wrote:
 On Mon, Nov 12, 2012 at 9:18 AM, H Hartley Sweeten wrote:
 Does anyone know what the Kconfig option VIRT_TO_BUS does?
 There are a number of depends on that option but it does not
 seem to directly enable any code in the kernel.

 virt_to_bus() is a deprecated interface for converting a kernel
 virtual address to a bus address.  It's deprecated because it's
 impossible to implement correctly when there are multiple bus address
 spaces, because you don't know which bus address space the caller has
 in mind.

Thanks for the info.

So if a driver does not use virt_to_bus() then the depends on VIRT_TO_BUS 
is not necessary. Correct?

Thanks,
Hartley
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 0/2] staging: comedi: remove the devpriv and thisboard macros

2012-07-12 Thread H Hartley Sweeten
The macros 'devpriv' and 'thisboard' rely on a local variable having
a specific name and yeild pointers derived from that variable. Replace
the macros with local variables where used and use to comedi_board()
helper to get the 'thisboard' pointer.

The dt282x driver needs some initial cleanup to remove some macros that
use the 'devpriv' macro.

There are still a couple comedi drivers that have the macros but they are
pretty tangled up and require a bit more work.

Unfortunately this patch adds quite a few lines-of-code to the drivers.
But, it cleans up the CodingStyle issue pointed out in Chapter 12:

2) macros that depend on having a local variable with a magic name:

#define FOO(val) bar(index, val)

might look like a good thing, but it's confusing as hell when one reads the
code and it's prone to breakage from seemingly innocent changes.

H Hartley Sweeten (2):
  staging: comedi: dt282x: remove the outw wrapper macros
  staging: comedi: remove the devpriv and thisboard macros

 .../staging/comedi/drivers/addi-data/addi_common.c |  19 +++-
 .../staging/comedi/drivers/addi-data/addi_eeprom.c |   2 +
 .../comedi/drivers/addi-data/hwdrv_apci035.c   |  14 +++
 .../comedi/drivers/addi-data/hwdrv_apci1032.c  |  11 +-
 .../comedi/drivers/addi-data/hwdrv_apci1500.c  |  21 +++-
 .../comedi/drivers/addi-data/hwdrv_apci1516.c  |  17 ++-
 .../comedi/drivers/addi-data/hwdrv_apci1564.c  |  16 +++
 .../comedi/drivers/addi-data/hwdrv_apci16xx.c  |   8 ++
 .../comedi/drivers/addi-data/hwdrv_apci2016.c  |  12 ++
 .../comedi/drivers/addi-data/hwdrv_apci2032.c  |  14 +++
 .../comedi/drivers/addi-data/hwdrv_apci2200.c  |  19 +++-
 .../comedi/drivers/addi-data/hwdrv_apci3120.c  |  42 +--
 .../comedi/drivers/addi-data/hwdrv_apci3200.c  |  27 -
 .../comedi/drivers/addi-data/hwdrv_apci3501.c  |  18 +++
 .../comedi/drivers/addi-data/hwdrv_apci3xxx.c  |  18 +++
 drivers/staging/comedi/drivers/adl_pci9111.c   |  36 --
 drivers/staging/comedi/drivers/adl_pci9118.c   |  55 +-
 drivers/staging/comedi/drivers/adq12b.c|  10 +-
 drivers/staging/comedi/drivers/adv_pci1710.c   |  45 +++-
 drivers/staging/comedi/drivers/adv_pci1723.c   |  20 ++--
 drivers/staging/comedi/drivers/adv_pci_dio.c   |  22 +++-
 drivers/staging/comedi/drivers/aio_aio12_8.c   |   8 +-
 drivers/staging/comedi/drivers/aio_iiro_16.c   |  11 --
 drivers/staging/comedi/drivers/amplc_dio200.c  |  10 +-
 drivers/staging/comedi/drivers/amplc_pc236.c   |  12 +-
 drivers/staging/comedi/drivers/amplc_pc263.c   |  11 +-
 drivers/staging/comedi/drivers/amplc_pci224.c  |   9 +-
 drivers/staging/comedi/drivers/amplc_pci230.c  |   3 +-
 drivers/staging/comedi/drivers/cb_das16_cs.c   |   4 +-
 drivers/staging/comedi/drivers/cb_pcidas.c |   2 +-
 drivers/staging/comedi/drivers/cb_pcidda.c |  27 ++---
 drivers/staging/comedi/drivers/cb_pcidio.c |  11 +-
 drivers/staging/comedi/drivers/cb_pcimdas.c|  23 ++--
 drivers/staging/comedi/drivers/cb_pcimdda.c|  29 +++--
 drivers/staging/comedi/drivers/comedi_bond.c   |  26 ++---
 drivers/staging/comedi/drivers/comedi_parport.c|  16 ++-
 drivers/staging/comedi/drivers/comedi_test.c   |  17 ++-
 drivers/staging/comedi/drivers/contec_pci_dio.c|   6 +-
 drivers/staging/comedi/drivers/daqboard2000.c  |  27 -
 drivers/staging/comedi/drivers/das08.c |   8 +-
 drivers/staging/comedi/drivers/das08_cs.c  |   4 +-
 drivers/staging/comedi/drivers/das16.c |  19 +++-
 drivers/staging/comedi/drivers/das16m1.c   |  14 ++-
 drivers/staging/comedi/drivers/das1800.c   |  41 +--
 drivers/staging/comedi/drivers/das6402.c   |  11 +-
 drivers/staging/comedi/drivers/das800.c|  29 +++--
 drivers/staging/comedi/drivers/dt2801.c|  28 +++--
 drivers/staging/comedi/drivers/dt2811.c|   9 +-
 drivers/staging/comedi/drivers/dt2814.c|   8 +-
 drivers/staging/comedi/drivers/dt2815.c|   8 +-
 drivers/staging/comedi/drivers/dt282x.c| 122 +
 drivers/staging/comedi/drivers/dt3000.c|  28 -
 drivers/staging/comedi/drivers/dt9812.c|  13 ++-
 drivers/staging/comedi/drivers/dyna_pci10xx.c  |  18 ++-
 drivers/staging/comedi/drivers/fl512.c |   9 +-
 drivers/staging/comedi/drivers/icp_multi.c |  36 --
 drivers/staging/comedi/drivers/ii_pci20kc.c|  10 +-
 drivers/staging/comedi/drivers/jr3_pci.c   |   5 +-
 drivers/staging/comedi/drivers/me4000.c|  55 --
 drivers/staging/comedi/drivers/me4000.h|   4 -
 drivers/staging/comedi/drivers/me_daq.c|  27 +++--
 drivers/staging/comedi/drivers/mpc624.c|   6 +-
 drivers/staging/comedi/drivers/mpc8260cpm.c|  11 --
 drivers/staging/comedi/drivers/multiq3.c

[PATCH 1/2] staging: comedi: dt282x: remove the outw wrapper macros

2012-07-12 Thread H Hartley Sweeten
The macros 'update_dacsr', 'update_adcsr', and 'update_supcsr' all use
the 'devpriv' macro which uses a local variable of a specific name and
yeilds a pointer derived from that name. They are also just wrappers
around simple 'outw' calls. Remove the macros.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/dt282x.c | 55 +
 1 file changed, 29 insertions(+), 26 deletions(-)

diff --git a/drivers/staging/comedi/drivers/dt282x.c 
b/drivers/staging/comedi/drivers/dt282x.c
index 4af3343..1f0b40e 100644
--- a/drivers/staging/comedi/drivers/dt282x.c
+++ b/drivers/staging/comedi/drivers/dt282x.c
@@ -255,11 +255,8 @@ struct dt282x_private {
  *Some useless abstractions
  */
 #define chan_to_DAC(a) ((a)1)
-#define update_dacsr(a)outw(devpriv-dacsr|(a), 
dev-iobase+DT2821_DACSR)
-#define update_adcsr(a)outw(devpriv-adcsr|(a), 
dev-iobase+DT2821_ADCSR)
 #define mux_busy() (inw(dev-iobase+DT2821_ADCSR)DT2821_MUXBUSY)
 #define ad_done() (inw(dev-iobase+DT2821_ADCSR)DT2821_ADDONE)
-#define update_supcsr(a) outw(devpriv-supcsr|(a), dev-iobase+DT2821_SUPCSR)
 
 /*
  *danger! macro abuse... a is the expression to wait on, and b is
@@ -317,7 +314,7 @@ static void dt282x_ao_dma_interrupt(struct comedi_device 
*dev)
int i;
struct comedi_subdevice *s = dev-subdevices + 1;
 
-   update_supcsr(DT2821_CLRDMADNE);
+   outw(devpriv-supcsr | DT2821_CLRDMADNE, dev-iobase + DT2821_SUPCSR);
 
if (!s-async-prealloc_buf) {
printk(KERN_ERR async-data disappeared.  dang!\n);
@@ -350,7 +347,7 @@ static void dt282x_ai_dma_interrupt(struct comedi_device 
*dev)
int ret;
struct comedi_subdevice *s = dev-subdevices;
 
-   update_supcsr(DT2821_CLRDMADNE);
+   outw(devpriv-supcsr | DT2821_CLRDMADNE, dev-iobase + DT2821_SUPCSR);
 
if (!s-async-prealloc_buf) {
printk(KERN_ERR async-data disappeared.  dang!\n);
@@ -387,7 +384,7 @@ static void dt282x_ai_dma_interrupt(struct comedi_device 
*dev)
/* XXX probably wrong */
if (!devpriv-ntrig) {
devpriv-supcsr = ~(DT2821_DDMA);
-   update_supcsr(0);
+   outw(devpriv-supcsr, dev-iobase + DT2821_SUPCSR);
}
 #endif
/* restart the channel */
@@ -513,7 +510,8 @@ static irqreturn_t dt282x_interrupt(int irq, void *d)
s-async-events |= COMEDI_CB_EOA;
} else {
if (supcsr  DT2821_SCDN)
-   update_supcsr(DT2821_STRIG);
+   outw(devpriv-supcsr | DT2821_STRIG,
+   dev-iobase + DT2821_SUPCSR);
}
handled = 1;
}
@@ -534,7 +532,8 @@ static void dt282x_load_changain(struct comedi_device *dev, 
int n,
for (i = 0; i  n; i++) {
chan = CR_CHAN(chanlist[i]);
range = CR_RANGE(chanlist[i]);
-   update_adcsr((range  4) | (chan));
+   outw(devpriv-adcsr | (range  4) | chan,
+   dev-iobase + DT2821_ADCSR);
}
outw(n - 1, dev-iobase + DT2821_CHANCSR);
 }
@@ -553,15 +552,16 @@ static int dt282x_ai_insn_read(struct comedi_device *dev,
 
/* XXX should we really be enabling the ad clock here? */
devpriv-adcsr = DT2821_ADCLK;
-   update_adcsr(0);
+   outw(devpriv-adcsr, dev-iobase + DT2821_ADCSR);
 
dt282x_load_changain(dev, 1, insn-chanspec);
 
-   update_supcsr(DT2821_PRLD);
+   outw(devpriv-supcsr | DT2821_PRLD, dev-iobase + DT2821_SUPCSR);
wait_for(!mux_busy(), comedi_error(dev, timeout\n); return -ETIME;);
 
for (i = 0; i  insn-n; i++) {
-   update_supcsr(DT2821_STRIG);
+   outw(devpriv-supcsr | DT2821_STRIG,
+   dev-iobase + DT2821_SUPCSR);
wait_for(ad_done(), comedi_error(dev, timeout\n);
 return -ETIME;);
 
@@ -718,7 +718,8 @@ static int dt282x_ai_cmd(struct comedi_device *dev, struct 
comedi_subdevice *s)
/* external trigger */
devpriv-supcsr = DT2821_ERRINTEN | DT2821_DS0 | DT2821_DS1;
}
-   update_supcsr(DT2821_CLRDMADNE | DT2821_BUFFB | DT2821_ADCINIT);
+   outw(devpriv-supcsr | DT2821_CLRDMADNE | DT2821_BUFFB | DT2821_ADCINIT,
+   dev-iobase + DT2821_SUPCSR);
 
devpriv-ntrig = cmd-stop_arg * cmd-scan_end_arg;
devpriv-nread = devpriv-ntrig;
@@ -729,7 +730,7 @@ static int dt282x_ai_cmd(struct comedi_device *dev, struct 
comedi_subdevice *s)
if (devpriv-ntrig) {
prep_ai_dma(dev, 1, 0);
devpriv-supcsr |= DT2821_DDMA;
-   update_supcsr(0);
+   outw(devpriv-supcsr, dev-iobase + DT2821_SUPCSR);
}
 
devpriv

[PATCH] staging: comedi: addi_data: remove pr_TTLRangelist

2012-07-13 Thread H Hartley Sweeten
All the addi driver ttl subdevices use the range table
'range_digital' provided by the comedi core. The boardinfo
value  'pr_TTLRangeList' is not used by the drivers. Remove
the unused range tables and the boardinfo pointer.

The unused range tables don't make sense anyway...

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 .../staging/comedi/drivers/addi-data/addi_common.c | 23 --
 .../staging/comedi/drivers/addi-data/addi_common.h |  1 -
 .../comedi/drivers/addi-data/hwdrv_apci16xx.h  | 15 --
 .../comedi/drivers/addi-data/hwdrv_apci3xxx.h  | 14 -
 4 files changed, 53 deletions(-)

diff --git a/drivers/staging/comedi/drivers/addi-data/addi_common.c 
b/drivers/staging/comedi/drivers/addi-data/addi_common.c
index 1e62f33..d7c1e1d 100644
--- a/drivers/staging/comedi/drivers/addi-data/addi_common.c
+++ b/drivers/staging/comedi/drivers/addi-data/addi_common.c
@@ -610,7 +610,6 @@ static const struct addi_board boardtypes[] = {
.i_IorangeBase0 = 128,
.i_PCIEeprom= ADDIDATA_NO_EEPROM,
.i_NbrTTLChannel= 48,
-   .pr_TTLRangelist= range_apci16xx_ttl,
.reset  = i_APCI16XX_Reset,
.ttl_config = i_APCI16XX_InsnConfigInitTTLIO,
.ttl_bits   = i_APCI16XX_InsnBitsReadTTLIO,
@@ -623,7 +622,6 @@ static const struct addi_board boardtypes[] = {
.i_IorangeBase0 = 128,
.i_PCIEeprom= ADDIDATA_NO_EEPROM,
.i_NbrTTLChannel= 96,
-   .pr_TTLRangelist= range_apci16xx_ttl,
.reset  = i_APCI16XX_Reset,
.ttl_config = i_APCI16XX_InsnConfigInitTTLIO,
.ttl_bits   = i_APCI16XX_InsnBitsReadTTLIO,
@@ -648,7 +646,6 @@ static const struct addi_board boardtypes[] = {
.i_AiMaxdata= 4095,
.pr_AiRangelist = range_apci3XXX_ai,
.i_NbrTTLChannel= 24,
-   .pr_TTLRangelist= range_apci3XXX_ttl,
.b_AvailableConvertUnit = 6,
.ui_MinAcquisitiontimeNs = 1,
.interrupt  = v_APCI3XXX_Interrupt,
@@ -675,7 +672,6 @@ static const struct addi_board boardtypes[] = {
.i_AiMaxdata= 4095,
.pr_AiRangelist = range_apci3XXX_ai,
.i_NbrTTLChannel= 24,
-   .pr_TTLRangelist= range_apci3XXX_ttl,
.b_AvailableConvertUnit = 6,
.ui_MinAcquisitiontimeNs = 1,
.interrupt  = v_APCI3XXX_Interrupt,
@@ -702,7 +698,6 @@ static const struct addi_board boardtypes[] = {
.i_AiMaxdata= 4095,
.pr_AiRangelist = range_apci3XXX_ai,
.i_NbrTTLChannel= 24,
-   .pr_TTLRangelist= range_apci3XXX_ttl,
.b_AvailableConvertUnit = 6,
.ui_MinAcquisitiontimeNs = 1,
.interrupt  = v_APCI3XXX_Interrupt,
@@ -729,7 +724,6 @@ static const struct addi_board boardtypes[] = {
.i_AiMaxdata= 65535,
.pr_AiRangelist = range_apci3XXX_ai,
.i_NbrTTLChannel= 24,
-   .pr_TTLRangelist= range_apci3XXX_ttl,
.b_AvailableConvertUnit = 6,
.ui_MinAcquisitiontimeNs = 1,
.interrupt  = v_APCI3XXX_Interrupt,
@@ -756,7 +750,6 @@ static const struct addi_board boardtypes[] = {
.i_AiMaxdata= 65535,
.pr_AiRangelist = range_apci3XXX_ai,
.i_NbrTTLChannel= 24,
-   .pr_TTLRangelist= range_apci3XXX_ttl,
.b_AvailableConvertUnit = 6,
.ui_MinAcquisitiontimeNs = 1,
.interrupt  = v_APCI3XXX_Interrupt,
@@ -783,7 +776,6 @@ static const struct addi_board boardtypes[] = {
.i_AiMaxdata= 65535,
.pr_AiRangelist = range_apci3XXX_ai,
.i_NbrTTLChannel= 24,
-   .pr_TTLRangelist= range_apci3XXX_ttl,
.b_AvailableConvertUnit = 6,
.ui_MinAcquisitiontimeNs = 1,
.interrupt  = v_APCI3XXX_Interrupt,
@@ -813,7 +805,6 @@ static const struct addi_board boardtypes[] = {
.i_NbrDoChannel = 4,
.i_DoMaxdata= 1,
.i_NbrTTLChannel= 24,
-   .pr_TTLRangelist= range_apci3XXX_ttl,
.b_AvailableConvertUnit = 6

RE: [PATCH 01/30] staging: comedi: add pci_dev pointer to comedi_device

2012-07-16 Thread H Hartley Sweeten
On Monday, July 16, 2012 6:52 PM, Greg KH wrote:
 On Wed, Jul 11, 2012 at 02:49:14PM -0700, H Hartley Sweeten wrote:
 The pci_dev pointer in the private driver data is used by every
 comedi pci driver. Some of them only have the need for the
 private data because of this pointer.
 
 Introduce the pci_dev pointer in the comedi_device struct so it
 can be used instead of needing it in the private data.
 
 Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
 Cc: Ian Abbott abbo...@mev.co.uk
 Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
 ---
  drivers/staging/comedi/comedidev.h | 2 ++
  1 file changed, 2 insertions(+)
 
 diff --git a/drivers/staging/comedi/comedidev.h 
 b/drivers/staging/comedi/comedidev.h
 index de8c99c..55f2373 100644
 --- a/drivers/staging/comedi/comedidev.h
 +++ b/drivers/staging/comedi/comedidev.h
 @@ -212,6 +212,8 @@ struct comedi_device {
   * DMA_NONE */
  struct device *hw_dev;
  
 +struct pci_dev *pcidev;

 No, the field above this, hw_dev, should be used instead here, as that's
 what it is there for, right?

The hw_dev pointer is currently only used for something dealing with dma.
I have not dug into it yet to see what exactly it's used for.  The comment
says:

/* hw_dev is passed to dma_alloc_coherent when allocating async buffers
 * for subdevices that have async_dma_dir set to something other than
 * DMA_NONE */

 Care to rework this series with that change instead?

It could probably be used with some sort of container_of but I'm not sure.

Regards,
Hartley
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: [PATCH 2/2] staging: comedi: remove the devpriv and thisboard macros

2012-07-16 Thread H Hartley Sweeten
On Monday, July 16, 2012 7:09 PM, Greg KH wrote:
 Because I didn't take your other large patch series, this one didn't
 apply :(

Of course... ;-)

Looking at using the hw_dev right now. I should have something tomorrow.

Thanks.
Hartley

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: [PATCH 01/30] staging: comedi: add pci_dev pointer to comedi_device

2012-07-16 Thread H Hartley Sweeten
On Monday, July 16, 2012 7:01 PM, Greg KH wrote:
 On Mon, Jul 16, 2012 at 08:55:47PM -0500, H Hartley Sweeten wrote:
 On Monday, July 16, 2012 6:52 PM, Greg KH wrote:
 No, the field above this, hw_dev, should be used instead here, as that's
 what it is there for, right?

 The hw_dev pointer is currently only used for something dealing with dma.
 I have not dug into it yet to see what exactly it's used for.  The comment
 says:
 
  /* hw_dev is passed to dma_alloc_coherent when allocating async buffers
   * for subdevices that have async_dma_dir set to something other than
   * DMA_NONE */

 Which is exactly what the pci device should be used for, it knows this
 information :)

 Care to rework this series with that change instead?
 
 It could probably be used with some sort of container_of but I'm not sure.

 Yes it can.

 To set the field:

   hw_dev = pci_dev-dev;

 to get it back:
   pci_dev = container_of(hw_dev, struct pci_device, struct device);

 I think.  That's off the top of my head, please try it out first.

 And use a macro for the container_of stuff, that makes it easier to
 understand.

Greg,

I'm posting a patch to the adl_pci6208 driver right now. It compiles fine
but could you look it over and see if it looks right.

Thanks,
Hartley

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] staging: comedi: adl_pci6208: use the comedi_device hw_dev to hold the pci_dev

2012-07-16 Thread H Hartley Sweeten
Use the 'struct device *hw_dev' variable in the comedi_device struct
to hold the pci_dev instead of carrying it in the private data.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/adl_pci6208.c | 19 ++-
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/comedi/drivers/adl_pci6208.c 
b/drivers/staging/comedi/drivers/adl_pci6208.c
index 487fd4a..ffecbe7 100644
--- a/drivers/staging/comedi/drivers/adl_pci6208.c
+++ b/drivers/staging/comedi/drivers/adl_pci6208.c
@@ -73,7 +73,6 @@ static const struct pci6208_board pci6208_boards[] = {
 };
 
 struct pci6208_private {
-   struct pci_dev *pci_dev;
unsigned int ao_readback[PCI6208_MAX_AO_CHANNELS];
 };
 
@@ -200,6 +199,7 @@ static int pci6208_attach(struct comedi_device *dev,
 {
const struct pci6208_board *thisboard;
struct pci6208_private *devpriv;
+   struct pci_dev *pcidev;
struct comedi_subdevice *s;
int ret;
 
@@ -208,20 +208,21 @@ static int pci6208_attach(struct comedi_device *dev,
return ret;
devpriv = dev-private;
 
-   devpriv-pci_dev = pci6208_find_device(dev, it);
-   if (!devpriv-pci_dev)
+   pcidev = pci6208_find_device(dev, it);
+   if (!pcidev)
return -EIO;
+   comedi_set_hw_dev(dev, pcidev-dev);
thisboard = comedi_board(dev);
 
dev-board_name = thisboard-name;
 
-   ret = comedi_pci_enable(devpriv-pci_dev, dev-driver-driver_name);
+   ret = comedi_pci_enable(pcidev, dev-driver-driver_name);
if (ret) {
dev_err(dev-class_dev,
Failed to enable PCI device and request regions\n);
return ret;
}
-   dev-iobase = pci_resource_start(devpriv-pci_dev, 2);
+   dev-iobase = pci_resource_start(pcidev, 2);
 
ret = comedi_alloc_subdevices(dev, 2);
if (ret)
@@ -258,12 +259,12 @@ static int pci6208_attach(struct comedi_device *dev,
 
 static void pci6208_detach(struct comedi_device *dev)
 {
-   struct pci6208_private *devpriv = dev-private;
+   struct pci_dev *pcidev = to_pci_dev(dev-hw_dev);
 
-   if (devpriv  devpriv-pci_dev) {
+   if (pcidev) {
if (dev-iobase)
-   comedi_pci_disable(devpriv-pci_dev);
-   pci_dev_put(devpriv-pci_dev);
+   comedi_pci_disable(pcidev);
+   pci_dev_put(pcidev);
}
 }
 
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: [PATCH] staging: comedi: adl_pci6208: use the comedi_device hw_dev to hold the pci_dev

2012-07-16 Thread H Hartley Sweeten
On Monday, July 16, 2012 7:31 PM, Greg KH wrote:
 On Mon, Jul 16, 2012 at 07:26:22PM -0700, H Hartley Sweeten wrote:
 Use the 'struct device *hw_dev' variable in the comedi_device struct
 to hold the pci_dev instead of carrying it in the private data.
 
 Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
 Cc: Ian Abbott abbo...@mev.co.uk
 Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
 ---
  drivers/staging/comedi/drivers/adl_pci6208.c | 19 ++-
  1 file changed, 10 insertions(+), 9 deletions(-)

 Looks good to me, I forgot we had the to_pci_dev() macro in pci.h.  Want
 to redo all of these and resend this one with the larger series?

Will do. Should be able to get it out tomorrow.

Regards,
Hartley

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 00/90] staging: comedi: cleanup the pci_dev usage

2012-07-18 Thread H Hartley Sweeten
All the comedi pci drivers currently store a pointer to the pci_dev
in their private data. We can use the 'struct device *hw_dev' variable
in the comedi_device struct instead and introduce a wrapper for
to_pci_dev() to allow the drivers to easily get the pci_dev.

This patchset does just that. It also removes the private data from
the drivers that no longer needed it.

Some of the drivers required a bit of cleanup to their find pci device
code or the private data in order to make the conversion cleaner.

There are still a couple drivers, specifically the ni and addi ones,
that need additional work before they can be converted cleanly.

H Hartley Sweeten (90):
  staging: comedi: comedidev.h: introduce comedi_to_pci_dev() helper
  staging: comedi: adl_pci6208: store the pci_dev in the comedi_device
  staging: comedi: adl_pci7230: store the pci_dev in the comedi_device
  staging: comedi: adl_pci7230: remove the private data
  staging: comedi: adl_pci7296: store the pci_dev in the comedi_device
  staging: comedi: adl_pci7296: remove the private data
  staging: comedi: adl_pci7432: store the pci_dev in the comedi_device
  staging: comedi: adl_pci7432: remove the private data
  staging: comedi: adl_pci8164: store the pci_dev in the comedi_device
  staging: comedi: adl_pci8164: remove the private data
  staging: comedi: adl_pci9111: store the pci_dev in the comedi_device
  staging: comedi: adl_pci9118: store the pci_dev in the comedi_device
  staging: comedi: adv_pci1723: factor out the find pci device code
  staging: comedi: adv_pci1723: cleanup find pci device code
  staging: comedi: adv_pci1723: move comedi_pci_enable() into the attach
  staging: comedi: adv_pci1723: store the pci_dev in the comedi_device
  staging: comedi: adv_pci1710: factor out the find pci device code
  staging: comedi: adv_pci1710: cleanup find pci device code
  staging: comedi: adv_pci1710: move comedi_pci_enable() into the attach
  staging: comedi: adv_pci1710: store the pci_dev in the comedi_device
  staging: comedi: adv_pci_dio: factor out the find pci device code
  staging: comedi: adv_pci_dio: remove CheckAndAllocCard()
  staging: comedi: adv_pci_dio: cleanup find pci device code
  staging: comedi: adv_pci_dio: store the pci_dev in the comedi_device
  staging: comedi: cb_pcidas: store the pci_dev in the comedi_device
  staging: comedi: cb_pcidio: factor out the find pci device code
  staging: comedi: cb_pcidio: cleanup find pci device code
  staging: comedi: cb_pcidio: store the pci_dev in the comedi_device
  staging: comedi: amplc_dio200: cleanup find pci device code
  staging: comedi: amplc_dio200: store the pci_dev in the comedi_device
  staging: comedi: amplc_pc236: cleanup find pci device code
  staging: comedi: amplc_pc236: store the pci_dev in the comedi_device
  staging: comedi: amplc_pc263: cleanup find pci device code
  staging: comedi: amplc_pc263: store the pci_dev in the comedi_device
  staging: comedi: amplc_pci224: cleanup find pci device code
  staging: comedi: amplc_pci224: store the pci_dev in the comedi_device
  staging: comedi: amplc_pci230: cleanup find pci device code
  staging: comedi: amplc_pci230: store the pci_dev in the comedi_device
  staging: comedi: cb_pcidas64: factor out the find pci device code
  staging: comedi: cb_pcidas64: cleanup find pci device code
  staging: comedi: cb_pcidas64: store the pci_dev in the comedi_device
  staging: comedi: cb_pcidda: factor out the find pci device code
  staging: comedi: cb_pcidda: cleanup find pci device code
  staging: comedi: cb_pcidda: store the pci_dev in the comedi_device
  staging: comedi: cb_pcidio: store the iobase in the comedi_device
  staging: comedi: cb_pcidio: remove the private data
  staging: comedi: cb_pcimdas: factor out the find pci device code
  staging: comedi: cb_pcimdas: cleanup find pci device code
  staging: comedi: cb_pcimdas: remove the debug print of the pci bars
  staging: comedi: cb_pcimdas: cleanup the private data
  staging: comedi: cb_pcimdas: remove BADR1 from the private data
  staging: comedi: cb_pcimdas: remove BADR4 from the private data
  staging: comedi: cb_pcimdas: remove BADR2 from the private data
  staging: comedi: cb_pcimdas: remove BADR0 from the private data
  staging: comedi: cb_pcimdas: store the pci_dev in the comedi_device
  staging: comedi: contec_pci_dio: factor out the find pci device code
  staging: comedi: contec_pci_dio: cleanup find pci device code
  staging: comedi: contec_pci_dio: store the pci_dev in the comedi_device
  staging: comedi: contec_pci_dio: remove the private data
  staging: comedi: daqboard2000: factor out the find pci device code
  staging: comedi: daqboard2000: cleanup find pci device code
  staging: comedi: daqboard2000: remove 'got_regions' from private data
  staging: comedi: daqboard2000: store the pci_dev in the comedi_device
  staging: comedi: daqboard2000: void *plx should be a void __iomem *
  staging: comedi: dt3000: cleanup find pci device code
  staging: comedi: dt3000: move

[PATCH 01/90] staging: comedi: comedidev.h: introduce comedi_to_pci_dev() helper

2012-07-18 Thread H Hartley Sweeten
Introduce a wrapper for to_pci_dev() to allow the comedi pci drivers
to store the pci_dev pointer in the comedi_device hw_dev variable and
retrieve it easily.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/comedidev.h | 5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/staging/comedi/comedidev.h 
b/drivers/staging/comedi/comedidev.h
index de8c99c..620222d 100644
--- a/drivers/staging/comedi/comedidev.h
+++ b/drivers/staging/comedi/comedidev.h
@@ -446,6 +446,11 @@ static inline void comedi_set_hw_dev(struct comedi_device 
*dev,
}
 }
 
+static inline struct pci_dev *comedi_to_pci_dev(struct comedi_device *dev)
+{
+   return to_pci_dev(dev-hw_dev);
+}
+
 int comedi_buf_put(struct comedi_async *async, short x);
 int comedi_buf_get(struct comedi_async *async, short *x);
 
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 03/90] staging: comedi: adl_pci7230: store the pci_dev in the comedi_device

2012-07-18 Thread H Hartley Sweeten
Use the hw_dev pointer in the comedi_device struct to hold the
pci_dev instead of carrying it in the private data.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/adl_pci7230.c | 19 +++
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/comedi/drivers/adl_pci7230.c 
b/drivers/staging/comedi/drivers/adl_pci7230.c
index cfb8bb0..cdf3949 100644
--- a/drivers/staging/comedi/drivers/adl_pci7230.c
+++ b/drivers/staging/comedi/drivers/adl_pci7230.c
@@ -44,7 +44,6 @@ Configuration Options:
 
 struct adl_pci7230_private {
int data;
-   struct pci_dev *pci_dev;
 };
 
 #define devpriv ((struct adl_pci7230_private *)dev-private)
@@ -102,6 +101,7 @@ static int adl_pci7230_attach(struct comedi_device *dev,
struct comedi_devconfig *it)
 {
struct comedi_subdevice *s;
+   struct pci_dev *pcidev;
int ret;
 
printk(KERN_INFO comedi%d: adl_pci7230\n, dev-minor);
@@ -115,16 +115,17 @@ static int adl_pci7230_attach(struct comedi_device *dev,
if (ret)
return ret;
 
-   devpriv-pci_dev = adl_pci7230_find_pci(dev, it);
-   if (!devpriv-pci_dev)
+   pcidev = adl_pci7230_find_pci(dev, it);
+   if (!pcidev)
return -EIO;
+   comedi_set_hw_dev(dev, pcidev-dev);
 
-   if (comedi_pci_enable(devpriv-pci_dev, adl_pci7230)  0) {
+   if (comedi_pci_enable(pcidev, adl_pci7230)  0) {
printk(KERN_ERR comedi%d: Failed to enable PCI device and 
request regions\n,
dev-minor);
return -EIO;
}
-   dev-iobase = pci_resource_start(devpriv-pci_dev, 2);
+   dev-iobase = pci_resource_start(pcidev, 2);
printk(KERN_DEBUG comedi: base addr %4lx\n, dev-iobase);
 
s = dev-subdevices + 0;
@@ -152,10 +153,12 @@ static int adl_pci7230_attach(struct comedi_device *dev,
 
 static void adl_pci7230_detach(struct comedi_device *dev)
 {
-   if (devpriv  devpriv-pci_dev) {
+   struct pci_dev *pcidev = comedi_to_pci_dev(dev);
+
+   if (pcidev) {
if (dev-iobase)
-   comedi_pci_disable(devpriv-pci_dev);
-   pci_dev_put(devpriv-pci_dev);
+   comedi_pci_disable(pcidev);
+   pci_dev_put(pcidev);
}
 }
 
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 04/90] staging: comedi: adl_pci7230: remove the private data

2012-07-18 Thread H Hartley Sweeten
The private data is no longer needed by this driver. Remove the
struct, devpriv macro, and the allocation.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/adl_pci7230.c | 9 -
 1 file changed, 9 deletions(-)

diff --git a/drivers/staging/comedi/drivers/adl_pci7230.c 
b/drivers/staging/comedi/drivers/adl_pci7230.c
index cdf3949..7df4c96 100644
--- a/drivers/staging/comedi/drivers/adl_pci7230.c
+++ b/drivers/staging/comedi/drivers/adl_pci7230.c
@@ -42,12 +42,6 @@ Configuration Options:
 
 #define PCI_DEVICE_ID_PCI7230 0x7230
 
-struct adl_pci7230_private {
-   int data;
-};
-
-#define devpriv ((struct adl_pci7230_private *)dev-private)
-
 static int adl_pci7230_do_insn_bits(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn,
@@ -108,9 +102,6 @@ static int adl_pci7230_attach(struct comedi_device *dev,
 
dev-board_name = pci7230;
 
-   if (alloc_private(dev, sizeof(struct adl_pci7230_private))  0)
-   return -ENOMEM;
-
ret = comedi_alloc_subdevices(dev, 2);
if (ret)
return ret;
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 02/90] staging: comedi: adl_pci6208: store the pci_dev in the comedi_device

2012-07-18 Thread H Hartley Sweeten
Use the hw_dev pointer in the comedi_device struct to hold the
pci_dev instead of carrying it in the private data.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/adl_pci6208.c | 19 ++-
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/comedi/drivers/adl_pci6208.c 
b/drivers/staging/comedi/drivers/adl_pci6208.c
index 487fd4a..3bec0f6 100644
--- a/drivers/staging/comedi/drivers/adl_pci6208.c
+++ b/drivers/staging/comedi/drivers/adl_pci6208.c
@@ -73,7 +73,6 @@ static const struct pci6208_board pci6208_boards[] = {
 };
 
 struct pci6208_private {
-   struct pci_dev *pci_dev;
unsigned int ao_readback[PCI6208_MAX_AO_CHANNELS];
 };
 
@@ -200,6 +199,7 @@ static int pci6208_attach(struct comedi_device *dev,
 {
const struct pci6208_board *thisboard;
struct pci6208_private *devpriv;
+   struct pci_dev *pcidev;
struct comedi_subdevice *s;
int ret;
 
@@ -208,20 +208,21 @@ static int pci6208_attach(struct comedi_device *dev,
return ret;
devpriv = dev-private;
 
-   devpriv-pci_dev = pci6208_find_device(dev, it);
-   if (!devpriv-pci_dev)
+   pcidev = pci6208_find_device(dev, it);
+   if (!pcidev)
return -EIO;
+   comedi_set_hw_dev(dev, pcidev-dev);
thisboard = comedi_board(dev);
 
dev-board_name = thisboard-name;
 
-   ret = comedi_pci_enable(devpriv-pci_dev, dev-driver-driver_name);
+   ret = comedi_pci_enable(pcidev, dev-driver-driver_name);
if (ret) {
dev_err(dev-class_dev,
Failed to enable PCI device and request regions\n);
return ret;
}
-   dev-iobase = pci_resource_start(devpriv-pci_dev, 2);
+   dev-iobase = pci_resource_start(pcidev, 2);
 
ret = comedi_alloc_subdevices(dev, 2);
if (ret)
@@ -258,12 +259,12 @@ static int pci6208_attach(struct comedi_device *dev,
 
 static void pci6208_detach(struct comedi_device *dev)
 {
-   struct pci6208_private *devpriv = dev-private;
+   struct pci_dev *pcidev = comedi_to_pci_dev(dev);
 
-   if (devpriv  devpriv-pci_dev) {
+   if (pcidev) {
if (dev-iobase)
-   comedi_pci_disable(devpriv-pci_dev);
-   pci_dev_put(devpriv-pci_dev);
+   comedi_pci_disable(pcidev);
+   pci_dev_put(pcidev);
}
 }
 
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 05/90] staging: comedi: adl_pci7296: store the pci_dev in the comedi_device

2012-07-18 Thread H Hartley Sweeten
Use the hw_dev pointer in the comedi_device struct to hold the
pci_dev instead of carrying it in the private data.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/adl_pci7296.c | 19 +++
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/comedi/drivers/adl_pci7296.c 
b/drivers/staging/comedi/drivers/adl_pci7296.c
index 58deb60..b003ed0 100644
--- a/drivers/staging/comedi/drivers/adl_pci7296.c
+++ b/drivers/staging/comedi/drivers/adl_pci7296.c
@@ -49,7 +49,6 @@ Configuration Options:
 
 struct adl_pci7296_private {
int data;
-   struct pci_dev *pci_dev;
 };
 
 #define devpriv ((struct adl_pci7296_private *)dev-private)
@@ -82,6 +81,7 @@ static struct pci_dev *adl_pci7296_find_pci(struct 
comedi_device *dev,
 static int adl_pci7296_attach(struct comedi_device *dev,
  struct comedi_devconfig *it)
 {
+   struct pci_dev *pcidev;
struct comedi_subdevice *s;
int ret;
 
@@ -96,18 +96,19 @@ static int adl_pci7296_attach(struct comedi_device *dev,
if (ret)
return ret;
 
-   devpriv-pci_dev = adl_pci7296_find_pci(dev, it);
-   if (!devpriv-pci_dev)
+   pcidev = adl_pci7296_find_pci(dev, it);
+   if (!pcidev)
return -EIO;
+   comedi_set_hw_dev(dev, pcidev-dev);
 
-   if (comedi_pci_enable(devpriv-pci_dev, adl_pci7296)  0) {
+   if (comedi_pci_enable(pcidev, adl_pci7296)  0) {
printk(KERN_ERR
comedi%d: Failed to enable PCI device and request 
regions\n,
dev-minor);
return -EIO;
}
 
-   dev-iobase = pci_resource_start(devpriv-pci_dev, 2);
+   dev-iobase = pci_resource_start(pcidev, 2);
printk(KERN_INFO comedi: base addr %4lx\n, dev-iobase);
 
/*  four 8255 digital io subdevices */
@@ -139,10 +140,12 @@ static int adl_pci7296_attach(struct comedi_device *dev,
 
 static void adl_pci7296_detach(struct comedi_device *dev)
 {
-   if (devpriv  devpriv-pci_dev) {
+   struct pci_dev *pcidev = comedi_to_pci_dev(dev);
+
+   if (pcidev) {
if (dev-iobase)
-   comedi_pci_disable(devpriv-pci_dev);
-   pci_dev_put(devpriv-pci_dev);
+   comedi_pci_disable(pcidev);
+   pci_dev_put(pcidev);
}
if (dev-subdevices) {
subdev_8255_cleanup(dev, dev-subdevices + 0);
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 06/90] staging: comedi: adl_pci7296: remove the private data

2012-07-18 Thread H Hartley Sweeten
The private data is no longer needed by this driver. Remove the
struct, devpriv macro, and the allocation.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/adl_pci7296.c | 9 -
 1 file changed, 9 deletions(-)

diff --git a/drivers/staging/comedi/drivers/adl_pci7296.c 
b/drivers/staging/comedi/drivers/adl_pci7296.c
index b003ed0..19b47af 100644
--- a/drivers/staging/comedi/drivers/adl_pci7296.c
+++ b/drivers/staging/comedi/drivers/adl_pci7296.c
@@ -47,12 +47,6 @@ Configuration Options:
 
 #define PCI_DEVICE_ID_PCI7296 0x7296
 
-struct adl_pci7296_private {
-   int data;
-};
-
-#define devpriv ((struct adl_pci7296_private *)dev-private)
-
 static struct pci_dev *adl_pci7296_find_pci(struct comedi_device *dev,
struct comedi_devconfig *it)
 {
@@ -89,9 +83,6 @@ static int adl_pci7296_attach(struct comedi_device *dev,
 
dev-board_name = pci7432;
 
-   if (alloc_private(dev, sizeof(struct adl_pci7296_private))  0)
-   return -ENOMEM;
-
ret = comedi_alloc_subdevices(dev, 4);
if (ret)
return ret;
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 07/90] staging: comedi: adl_pci7432: store the pci_dev in the comedi_device

2012-07-18 Thread H Hartley Sweeten
Use the hw_dev pointer in the comedi_device struct to hold the
pci_dev instead of carrying it in the private data.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/adl_pci7432.c | 19 +++
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/comedi/drivers/adl_pci7432.c 
b/drivers/staging/comedi/drivers/adl_pci7432.c
index 10683c2..ebe022d 100644
--- a/drivers/staging/comedi/drivers/adl_pci7432.c
+++ b/drivers/staging/comedi/drivers/adl_pci7432.c
@@ -44,7 +44,6 @@ Configuration Options:
 
 struct adl_pci7432_private {
int data;
-   struct pci_dev *pci_dev;
 };
 
 #define devpriv ((struct adl_pci7432_private *)dev-private)
@@ -110,6 +109,7 @@ static struct pci_dev *adl_pci7432_find_pci(struct 
comedi_device *dev,
 static int adl_pci7432_attach(struct comedi_device *dev,
  struct comedi_devconfig *it)
 {
+   struct pci_dev *pcidev;
struct comedi_subdevice *s;
int ret;
 
@@ -124,16 +124,17 @@ static int adl_pci7432_attach(struct comedi_device *dev,
if (ret)
return ret;
 
-   devpriv-pci_dev = adl_pci7432_find_pci(dev, it);
-   if (!devpriv-pci_dev)
+   pcidev = adl_pci7432_find_pci(dev, it);
+   if (!pcidev)
return -EIO;
+   comedi_set_hw_dev(dev, pcidev-dev);
 
-   if (comedi_pci_enable(devpriv-pci_dev, adl_pci7432)  0) {
+   if (comedi_pci_enable(pcidev, adl_pci7432)  0) {
printk(KERN_ERR comedi%d: Failed to enable PCI device and 
request regions\n,
dev-minor);
return -EIO;
}
-   dev-iobase = pci_resource_start(devpriv-pci_dev, 2);
+   dev-iobase = pci_resource_start(pcidev, 2);
printk(KERN_INFO comedi: base addr %4lx\n, dev-iobase);
 
s = dev-subdevices + 0;
@@ -162,10 +163,12 @@ static int adl_pci7432_attach(struct comedi_device *dev,
 
 static void adl_pci7432_detach(struct comedi_device *dev)
 {
-   if (devpriv  devpriv-pci_dev) {
+   struct pci_dev *pcidev = comedi_to_pci_dev(dev);
+
+   if (pcidev) {
if (dev-iobase)
-   comedi_pci_disable(devpriv-pci_dev);
-   pci_dev_put(devpriv-pci_dev);
+   comedi_pci_disable(pcidev);
+   pci_dev_put(pcidev);
}
 }
 
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 08/90] staging: comedi: adl_pci7432: remove the private data

2012-07-18 Thread H Hartley Sweeten
The private data is no longer needed by this driver. Remove the
struct, devpriv macro, and the allocation.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/adl_pci7432.c | 9 -
 1 file changed, 9 deletions(-)

diff --git a/drivers/staging/comedi/drivers/adl_pci7432.c 
b/drivers/staging/comedi/drivers/adl_pci7432.c
index ebe022d..6b8d940 100644
--- a/drivers/staging/comedi/drivers/adl_pci7432.c
+++ b/drivers/staging/comedi/drivers/adl_pci7432.c
@@ -42,12 +42,6 @@ Configuration Options:
 
 #define PCI_DEVICE_ID_PCI7432 0x7432
 
-struct adl_pci7432_private {
-   int data;
-};
-
-#define devpriv ((struct adl_pci7432_private *)dev-private)
-
 static int adl_pci7432_do_insn_bits(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn,
@@ -117,9 +111,6 @@ static int adl_pci7432_attach(struct comedi_device *dev,
 
dev-board_name = pci7432;
 
-   if (alloc_private(dev, sizeof(struct adl_pci7432_private))  0)
-   return -ENOMEM;
-
ret = comedi_alloc_subdevices(dev, 2);
if (ret)
return ret;
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 09/90] staging: comedi: adl_pci8164: store the pci_dev in the comedi_device

2012-07-18 Thread H Hartley Sweeten
Use the hw_dev pointer in the comedi_device struct to hold the
pci_dev instead of carrying it in the private data.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/adl_pci8164.c | 19 +++
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/comedi/drivers/adl_pci8164.c 
b/drivers/staging/comedi/drivers/adl_pci8164.c
index 1811375..94230d6 100644
--- a/drivers/staging/comedi/drivers/adl_pci8164.c
+++ b/drivers/staging/comedi/drivers/adl_pci8164.c
@@ -57,7 +57,6 @@ Configuration Options:
 
 struct adl_pci8164_private {
int data;
-   struct pci_dev *pci_dev;
 };
 
 #define devpriv ((struct adl_pci8164_private *)dev-private)
@@ -251,6 +250,7 @@ static struct pci_dev *adl_pci8164_find_pci(struct 
comedi_device *dev,
 static int adl_pci8164_attach(struct comedi_device *dev,
  struct comedi_devconfig *it)
 {
+   struct pci_dev *pcidev;
struct comedi_subdevice *s;
int ret;
 
@@ -266,16 +266,17 @@ static int adl_pci8164_attach(struct comedi_device *dev,
if (ret)
return ret;
 
-   devpriv-pci_dev = adl_pci8164_find_pci(dev, it);
-   if (!devpriv-pci_dev)
+   pcidev = adl_pci8164_find_pci(dev, it);
+   if (!pcidev)
return -EIO;
+   comedi_set_hw_dev(dev, pcidev-dev);
 
-   if (comedi_pci_enable(devpriv-pci_dev, adl_pci8164)  0) {
+   if (comedi_pci_enable(pcidev, adl_pci8164)  0) {
printk(KERN_ERR comedi%d: Failed to enable 
PCI device and request regions\n, dev-minor);
return -EIO;
}
-   dev-iobase = pci_resource_start(devpriv-pci_dev, 2);
+   dev-iobase = pci_resource_start(pcidev, 2);
printk(KERN_DEBUG comedi: base addr %4lx\n, dev-iobase);
 
s = dev-subdevices + 0;
@@ -324,10 +325,12 @@ static int adl_pci8164_attach(struct comedi_device *dev,
 
 static void adl_pci8164_detach(struct comedi_device *dev)
 {
-   if (devpriv  devpriv-pci_dev) {
+   struct pci_dev *pcidev = comedi_to_pci_dev(dev);
+
+   if (pcidev) {
if (dev-iobase)
-   comedi_pci_disable(devpriv-pci_dev);
-   pci_dev_put(devpriv-pci_dev);
+   comedi_pci_disable(pcidev);
+   pci_dev_put(pcidev);
}
 }
 
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 10/90] staging: comedi: adl_pci8164: remove the private data

2012-07-18 Thread H Hartley Sweeten
The private data is no longer needed by this driver. Remove the
struct, devpriv macro, and the allocation.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/adl_pci8164.c | 9 -
 1 file changed, 9 deletions(-)

diff --git a/drivers/staging/comedi/drivers/adl_pci8164.c 
b/drivers/staging/comedi/drivers/adl_pci8164.c
index 94230d6..247ef00 100644
--- a/drivers/staging/comedi/drivers/adl_pci8164.c
+++ b/drivers/staging/comedi/drivers/adl_pci8164.c
@@ -55,12 +55,6 @@ Configuration Options:
 
 #define PCI_DEVICE_ID_PCI8164 0x8164
 
-struct adl_pci8164_private {
-   int data;
-};
-
-#define devpriv ((struct adl_pci8164_private *)dev-private)
-
 /*
  all the read commands are the same except for the addition a constant
  * const to the data for inw()
@@ -259,9 +253,6 @@ static int adl_pci8164_attach(struct comedi_device *dev,
 
dev-board_name = pci8164;
 
-   if (alloc_private(dev, sizeof(struct adl_pci8164_private))  0)
-   return -ENOMEM;
-
ret = comedi_alloc_subdevices(dev, 4);
if (ret)
return ret;
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 11/90] staging: comedi: adl_pci9111: store the pci_dev in the comedi_device

2012-07-18 Thread H Hartley Sweeten
Use the hw_dev pointer in the comedi_device struct to hold the
pci_dev instead of carrying it in the private data.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/adl_pci9111.c | 29 +++-
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/comedi/drivers/adl_pci9111.c 
b/drivers/staging/comedi/drivers/adl_pci9111.c
index c41cfc5..a31dae6 100644
--- a/drivers/staging/comedi/drivers/adl_pci9111.c
+++ b/drivers/staging/comedi/drivers/adl_pci9111.c
@@ -338,7 +338,6 @@ static const struct pci9111_board pci9111_boards[] = {
 /*  Private data structure */
 
 struct pci9111_private_data {
-   struct pci_dev *pci_device;
unsigned long io_range; /*  PCI6503 io range */
 
unsigned long lcr_io_base; /* Local configuration register base
@@ -1247,6 +1246,7 @@ static struct pci_dev *pci9111_find_pci(struct 
comedi_device *dev,
 static int pci9111_attach(struct comedi_device *dev,
  struct comedi_devconfig *it)
 {
+   struct pci_dev *pcidev;
struct comedi_subdevice *subdevice;
unsigned long io_base, io_range, lcr_io_base, lcr_io_range;
int error;
@@ -1259,9 +1259,10 @@ static int pci9111_attach(struct comedi_device *dev,
printk(KERN_ERR comedi%d:  PCI9111_DRIVER_NAME  driver\n,
dev-minor);
 
-   dev_private-pci_device = pci9111_find_pci(dev, it);
-   if (!dev_private-pci_device)
+   pcidev = pci9111_find_pci(dev, it);
+   if (!pcidev)
return -EIO;
+   comedi_set_hw_dev(dev, pcidev-dev);
board = (struct pci9111_board *)dev-board_ptr;
 
/*  TODO: Warn about non-tested boards. */
@@ -1269,15 +1270,15 @@ static int pci9111_attach(struct comedi_device *dev,
/*  Read local configuration register base address
 *  [PCI_BASE_ADDRESS #1]. */
 
-   lcr_io_base = pci_resource_start(dev_private-pci_device, 1);
-   lcr_io_range = pci_resource_len(dev_private-pci_device, 1);
+   lcr_io_base = pci_resource_start(pcidev, 1);
+   lcr_io_range = pci_resource_len(pcidev, 1);
 
printk
(comedi%d: local configuration registers at address 0x%4lx 
[0x%4lx]\n,
 dev-minor, lcr_io_base, lcr_io_range);
 
/*  Enable PCI device and request regions */
-   if (comedi_pci_enable(dev_private-pci_device, PCI9111_DRIVER_NAME)  
0) {
+   if (comedi_pci_enable(pcidev, PCI9111_DRIVER_NAME)  0) {
printk
(comedi%d: Failed to enable PCI device and request 
regions\n,
 dev-minor);
@@ -1285,8 +1286,8 @@ static int pci9111_attach(struct comedi_device *dev,
}
/*  Read PCI6308 register base address [PCI_BASE_ADDRESS #2]. */
 
-   io_base = pci_resource_start(dev_private-pci_device, 2);
-   io_range = pci_resource_len(dev_private-pci_device, 2);
+   io_base = pci_resource_start(pcidev, 2);
+   io_range = pci_resource_len(pcidev, 2);
 
printk(KERN_ERR comedi%d: 6503 registers at address 0x%4lx [0x%4lx]\n,
   dev-minor, io_base, io_range);
@@ -1303,8 +1304,8 @@ static int pci9111_attach(struct comedi_device *dev,
/*  Irq setup */
 
dev-irq = 0;
-   if (dev_private-pci_device-irq  0) {
-   dev-irq = dev_private-pci_device-irq;
+   if (pcidev-irq  0) {
+   dev-irq = pcidev-irq;
 
if (request_irq(dev-irq, pci9111_interrupt,
IRQF_SHARED, PCI9111_DRIVER_NAME, dev) != 0) {
@@ -1374,16 +1375,18 @@ static int pci9111_attach(struct comedi_device *dev,
 
 static void pci9111_detach(struct comedi_device *dev)
 {
+   struct pci_dev *pcidev = comedi_to_pci_dev(dev);
+
if (dev-private != NULL) {
if (dev_private-is_valid)
pci9111_reset(dev);
}
if (dev-irq != 0)
free_irq(dev-irq, dev);
-   if (dev_private != NULL  dev_private-pci_device != NULL) {
+   if (pcidev) {
if (dev-iobase)
-   comedi_pci_disable(dev_private-pci_device);
-   pci_dev_put(dev_private-pci_device);
+   comedi_pci_disable(pcidev);
+   pci_dev_put(pcidev);
}
 }
 
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 12/90] staging: comedi: adl_pci9118: store the pci_dev in the comedi_device

2012-07-18 Thread H Hartley Sweeten
Use the hw_dev pointer in the comedi_device struct to hold the
pci_dev instead of carrying it in the private data.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/adl_pci9118.c | 33 +++-
 1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/drivers/staging/comedi/drivers/adl_pci9118.c 
b/drivers/staging/comedi/drivers/adl_pci9118.c
index 4482aab..a1f74c2 100644
--- a/drivers/staging/comedi/drivers/adl_pci9118.c
+++ b/drivers/staging/comedi/drivers/adl_pci9118.c
@@ -250,7 +250,6 @@ struct boardtype {
 struct pci9118_private {
unsigned long iobase_a; /* base+size for AMCC chip */
unsigned int master;/* master capable */
-   struct pci_dev *pcidev; /* ptr to actual pcidev */
unsigned int usemux;/* we want to use external multiplexor! */
 #ifdef PCI9118_PARANOIDCHECK
unsigned short chanlist[PCI9118_CHANLEN + 1];   /*
@@ -2151,6 +2150,7 @@ static struct pci_dev *pci9118_find_pci(struct 
comedi_device *dev,
 static int pci9118_attach(struct comedi_device *dev,
  struct comedi_devconfig *it)
 {
+   struct pci_dev *pcidev;
struct comedi_subdevice *s;
int ret, pages, i;
unsigned short master;
@@ -2170,16 +2170,17 @@ static int pci9118_attach(struct comedi_device *dev,
return -ENOMEM;
}
 
-   devpriv-pcidev = pci9118_find_pci(dev, it);
-   if (!devpriv-pcidev)
+   pcidev = pci9118_find_pci(dev, it);
+   if (!pcidev)
return -EIO;
+   comedi_set_hw_dev(dev, pcidev-dev);
 
if (master)
-   pci_set_master(devpriv-pcidev);
+   pci_set_master(pcidev);
 
-   irq = devpriv-pcidev-irq;
-   devpriv-iobase_a = pci_resource_start(devpriv-pcidev, 0);
-   dev-iobase = pci_resource_start(devpriv-pcidev, 2);
+   irq = pcidev-irq;
+   devpriv-iobase_a = pci_resource_start(pcidev, 0);
+   dev-iobase = pci_resource_start(pcidev, 2);
 
dev-board_name = this_board-name;
 
@@ -2264,8 +2265,8 @@ static int pci9118_attach(struct comedi_device *dev,
 
printk(.\n);
 
-   pci_read_config_word(devpriv-pcidev, PCI_COMMAND, u16w);
-   pci_write_config_word(devpriv-pcidev, PCI_COMMAND, u16w | 64);
+   pci_read_config_word(pcidev, PCI_COMMAND, u16w);
+   pci_write_config_word(pcidev, PCI_COMMAND, u16w | 64);
/* Enable parity check for parity error */
 
ret = comedi_alloc_subdevices(dev, 4);
@@ -2343,17 +2344,13 @@ static int pci9118_attach(struct comedi_device *dev,
 
 static void pci9118_detach(struct comedi_device *dev)
 {
+   struct pci_dev *pcidev = comedi_to_pci_dev(dev);
+
if (dev-private) {
if (devpriv-valid)
pci9118_reset(dev);
if (dev-irq)
free_irq(dev-irq, dev);
-   if (devpriv-pcidev) {
-   if (dev-iobase)
-   comedi_pci_disable(devpriv-pcidev);
-
-   pci_dev_put(devpriv-pcidev);
-   }
if (devpriv-dmabuf_virt[0])
free_pages((unsigned long)devpriv-dmabuf_virt[0],
   devpriv-dmabuf_pages[0]);
@@ -2361,6 +2358,12 @@ static void pci9118_detach(struct comedi_device *dev)
free_pages((unsigned long)devpriv-dmabuf_virt[1],
   devpriv-dmabuf_pages[1]);
}
+   if (pcidev) {
+   if (dev-iobase)
+   comedi_pci_disable(pcidev);
+
+   pci_dev_put(pcidev);
+   }
 }
 
 static const struct boardtype boardtypes[] = {
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 13/90] staging: comedi: adv_pci1723: factor out the find pci device code

2012-07-18 Thread H Hartley Sweeten
Factor the find pci device code out of the attach function.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/adv_pci1723.c | 42 +---
 1 file changed, 26 insertions(+), 16 deletions(-)

diff --git a/drivers/staging/comedi/drivers/adv_pci1723.c 
b/drivers/staging/comedi/drivers/adv_pci1723.c
index 5c99c74..4803a8c 100644
--- a/drivers/staging/comedi/drivers/adv_pci1723.c
+++ b/drivers/staging/comedi/drivers/adv_pci1723.c
@@ -287,29 +287,18 @@ static int pci1723_dio_insn_bits(struct comedi_device 
*dev,
return insn-n;
 }
 
-static int pci1723_attach(struct comedi_device *dev,
- struct comedi_devconfig *it)
+static struct pci_dev *pci1723_find_pci_dev(struct comedi_device *dev,
+   struct comedi_devconfig *it)
 {
-   struct comedi_subdevice *s;
-   int ret, subdev, n_subdevices;
struct pci_dev *pcidev;
unsigned int iobase;
unsigned char pci_bus, pci_slot, pci_func;
int opt_bus, opt_slot;
const char *errstr;
 
-   printk(KERN_ERR comedi%d: adv_pci1723: board=%s,
-   dev-minor, this_board-name);
-
opt_bus = it-options[0];
opt_slot = it-options[1];
 
-   ret = alloc_private(dev, sizeof(struct pci1723_private));
-   if (ret  0) {
-   printk( - Allocation failed!\n);
-   return -ENOMEM;
-   }
-
/* Look for matching PCI device */
errstr = not found!;
pcidev = NULL;
@@ -342,7 +331,7 @@ static int pci1723_attach(struct comedi_device *dev,
} else {
printk(KERN_ERR  - Card %s\n, errstr);
}
-   return -EIO;
+   return NULL;
}
 
pci_bus = pcidev-bus-number;
@@ -353,10 +342,31 @@ static int pci1723_attach(struct comedi_device *dev,
printk(KERN_ERR , b:s:f=%d:%d:%d, io=0x%4x,
   pci_bus, pci_slot, pci_func, iobase);
 
-   dev-iobase = iobase;
+   return pcidev;
+}
+
+static int pci1723_attach(struct comedi_device *dev,
+ struct comedi_devconfig *it)
+{
+   struct comedi_subdevice *s;
+   int ret, subdev, n_subdevices;
+
+   printk(KERN_ERR comedi%d: adv_pci1723: board=%s,
+   dev-minor, this_board-name);
+
+   ret = alloc_private(dev, sizeof(struct pci1723_private));
+   if (ret  0) {
+   printk( - Allocation failed!\n);
+   return -ENOMEM;
+   }
+
+   devpriv-pcidev = pci1723_find_pci_dev(dev, it);
+   if (!devpriv-pcidev)
+   return -EIO;
+
+   dev-iobase = pci_resource_start(devpriv-pcidev, 2);
 
dev-board_name = this_board-name;
-   devpriv-pcidev = pcidev;
 
n_subdevices = 0;
 
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 14/90] staging: comedi: adv_pci1723: cleanup find pci device code

2012-07-18 Thread H Hartley Sweeten
Use for_each_pci_dev() instead of open-coding the loop using
pci_get_device().

Drop the printk error messages. They just add noise.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/adv_pci1723.c | 63 
 1 file changed, 17 insertions(+), 46 deletions(-)

diff --git a/drivers/staging/comedi/drivers/adv_pci1723.c 
b/drivers/staging/comedi/drivers/adv_pci1723.c
index 4803a8c..f561a2a 100644
--- a/drivers/staging/comedi/drivers/adv_pci1723.c
+++ b/drivers/staging/comedi/drivers/adv_pci1723.c
@@ -290,59 +290,30 @@ static int pci1723_dio_insn_bits(struct comedi_device 
*dev,
 static struct pci_dev *pci1723_find_pci_dev(struct comedi_device *dev,
struct comedi_devconfig *it)
 {
-   struct pci_dev *pcidev;
-   unsigned int iobase;
-   unsigned char pci_bus, pci_slot, pci_func;
-   int opt_bus, opt_slot;
-   const char *errstr;
-
-   opt_bus = it-options[0];
-   opt_slot = it-options[1];
-
-   /* Look for matching PCI device */
-   errstr = not found!;
-   pcidev = NULL;
-   while (NULL != (pcidev =
-   pci_get_device(PCI_VENDOR_ID_ADVANTECH,
-  this_board-device_id, pcidev))) {
-   /* Found matching vendor/device. */
-   if (opt_bus || opt_slot) {
-   /* Check bus/slot. */
-   if (opt_bus != pcidev-bus-number
-   || opt_slot != PCI_SLOT(pcidev-devfn))
-   continue;   /* no match */
+   struct pci_dev *pcidev = NULL;
+   int bus = it-options[0];
+   int slot = it-options[1];
+
+   for_each_pci_dev(pcidev) {
+   if (bus || slot) {
+   if (bus != pcidev-bus-number ||
+   slot != PCI_SLOT(pcidev-devfn))
+   continue;
}
+   if (pcidev-vendor != PCI_VENDOR_ID_ADVANTECH)
+   continue;
/*
 * Look for device that isn't in use.
 * Enable PCI device and request regions.
 */
-   if (comedi_pci_enable(pcidev, adv_pci1723)) {
-   errstr =
-   failed to enable PCI device and request regions!;
+   if (comedi_pci_enable(pcidev, adv_pci1723))
continue;
-   }
-   break;
-   }
-
-   if (!pcidev) {
-   if (opt_bus || opt_slot) {
-   printk(KERN_ERR  - Card at b:s %d:%d %s\n,
-opt_bus, opt_slot, errstr);
-   } else {
-   printk(KERN_ERR  - Card %s\n, errstr);
-   }
-   return NULL;
+   return pcidev;
}
-
-   pci_bus = pcidev-bus-number;
-   pci_slot = PCI_SLOT(pcidev-devfn);
-   pci_func = PCI_FUNC(pcidev-devfn);
-   iobase = pci_resource_start(pcidev, 2);
-
-   printk(KERN_ERR , b:s:f=%d:%d:%d, io=0x%4x,
-  pci_bus, pci_slot, pci_func, iobase);
-
-   return pcidev;
+   dev_err(dev-class_dev,
+   No supported board found! (req. bus %d, slot %d)\n,
+   bus, slot);
+   return NULL;
 }
 
 static int pci1723_attach(struct comedi_device *dev,
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 15/90] staging: comedi: adv_pci1723: move comedi_pci_enable() into the attach

2012-07-18 Thread H Hartley Sweeten
Use pci_is_enabled() in the find pci device function to determine if
the found pci device is not in use and move the comedi_pci_enable() call
into the attach.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/adv_pci1723.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/comedi/drivers/adv_pci1723.c 
b/drivers/staging/comedi/drivers/adv_pci1723.c
index f561a2a..e971fa6 100644
--- a/drivers/staging/comedi/drivers/adv_pci1723.c
+++ b/drivers/staging/comedi/drivers/adv_pci1723.c
@@ -302,11 +302,7 @@ static struct pci_dev *pci1723_find_pci_dev(struct 
comedi_device *dev,
}
if (pcidev-vendor != PCI_VENDOR_ID_ADVANTECH)
continue;
-   /*
-* Look for device that isn't in use.
-* Enable PCI device and request regions.
-*/
-   if (comedi_pci_enable(pcidev, adv_pci1723))
+   if (pci_is_enabled(pcidev))
continue;
return pcidev;
}
@@ -335,6 +331,10 @@ static int pci1723_attach(struct comedi_device *dev,
if (!devpriv-pcidev)
return -EIO;
 
+   ret = comedi_pci_enable(devpriv-pcidev, adv_pci1723);
+   if (ret)
+   return ret;
+
dev-iobase = pci_resource_start(devpriv-pcidev, 2);
 
dev-board_name = this_board-name;
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 16/90] staging: comedi: adv_pci1723: store the pci_dev in the comedi_device

2012-07-18 Thread H Hartley Sweeten
Use the hw_dev pointer in the comedi_device struct to hold the
pci_dev instead of carrying it in the private data.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/adv_pci1723.c | 23 +--
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/comedi/drivers/adv_pci1723.c 
b/drivers/staging/comedi/drivers/adv_pci1723.c
index e971fa6..da5ee69 100644
--- a/drivers/staging/comedi/drivers/adv_pci1723.c
+++ b/drivers/staging/comedi/drivers/adv_pci1723.c
@@ -152,7 +152,6 @@ static const struct pci1723_board boardtypes[] = {
 struct pci1723_private {
int valid;  /* card is usable; */
 
-   struct pci_dev *pcidev;
unsigned char da_range[8];  /* D/A output range for each channel */
 
short ao_data[8];   /* data output buffer */
@@ -315,6 +314,7 @@ static struct pci_dev *pci1723_find_pci_dev(struct 
comedi_device *dev,
 static int pci1723_attach(struct comedi_device *dev,
  struct comedi_devconfig *it)
 {
+   struct pci_dev *pcidev;
struct comedi_subdevice *s;
int ret, subdev, n_subdevices;
 
@@ -327,15 +327,16 @@ static int pci1723_attach(struct comedi_device *dev,
return -ENOMEM;
}
 
-   devpriv-pcidev = pci1723_find_pci_dev(dev, it);
-   if (!devpriv-pcidev)
+   pcidev = pci1723_find_pci_dev(dev, it);
+   if (!pcidev)
return -EIO;
+   comedi_set_hw_dev(dev, pcidev-dev);
 
-   ret = comedi_pci_enable(devpriv-pcidev, adv_pci1723);
+   ret = comedi_pci_enable(pcidev, adv_pci1723);
if (ret)
return ret;
 
-   dev-iobase = pci_resource_start(devpriv-pcidev, 2);
+   dev-iobase = pci_resource_start(pcidev, 2);
 
dev-board_name = this_board-name;
 
@@ -410,14 +411,16 @@ static int pci1723_attach(struct comedi_device *dev,
 
 static void pci1723_detach(struct comedi_device *dev)
 {
+   struct pci_dev *pcidev = comedi_to_pci_dev(dev);
+
if (dev-private) {
if (devpriv-valid)
pci1723_reset(dev);
-   if (devpriv-pcidev) {
-   if (dev-iobase)
-   comedi_pci_disable(devpriv-pcidev);
-   pci_dev_put(devpriv-pcidev);
-   }
+   }
+   if (pcidev) {
+   if (dev-iobase)
+   comedi_pci_disable(pcidev);
+   pci_dev_put(pcidev);
}
 }
 
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 17/90] staging: comedi: adv_pci1710: factor out the find pci device code

2012-07-18 Thread H Hartley Sweeten
Factor the find pci device code out of the attach function.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/adv_pci1710.c | 42 ++--
 1 file changed, 27 insertions(+), 15 deletions(-)

diff --git a/drivers/staging/comedi/drivers/adv_pci1710.c 
b/drivers/staging/comedi/drivers/adv_pci1710.c
index 0ed1ff9..0823a36 100644
--- a/drivers/staging/comedi/drivers/adv_pci1710.c
+++ b/drivers/staging/comedi/drivers/adv_pci1710.c
@@ -1333,29 +1333,21 @@ static int pci1710_reset(struct comedi_device *dev)
DPRINTK(adv_pci1710 EDBG: END: pci1710_reset(...)\n);
 }
 
-static int pci1710_attach(struct comedi_device *dev,
- struct comedi_devconfig *it)
+static struct pci_dev *pci1710_find_pci_dev(struct comedi_device *dev,
+   struct comedi_devconfig *it)
 {
-   struct comedi_subdevice *s;
-   int ret, subdev, n_subdevices;
-   unsigned int irq;
-   unsigned long iobase;
struct pci_dev *pcidev;
int opt_bus, opt_slot;
const char *errstr;
unsigned char pci_bus, pci_slot, pci_func;
int i;
int board_index;
-
-   dev_info(dev-class_dev, DRV_NAME : attach\n);
+   unsigned int irq;
+   unsigned long iobase;
 
opt_bus = it-options[0];
opt_slot = it-options[1];
 
-   ret = alloc_private(dev, sizeof(struct pci1710_private));
-   if (ret  0)
-   return -ENOMEM;
-
/* Look for matching PCI device */
errstr = not found!;
pcidev = NULL;
@@ -1404,7 +1396,7 @@ static int pci1710_attach(struct comedi_device *dev,
} else {
dev_err(dev-class_dev, - Card %s\n, errstr);
}
-   return -EIO;
+   return NULL;
}
 
pci_bus = pcidev-bus-number;
@@ -1416,10 +1408,30 @@ static int pci1710_attach(struct comedi_device *dev,
dev_dbg(dev-class_dev, b:s:f=%d:%d:%d, io=0x%4lx\n,
pci_bus, pci_slot, pci_func, iobase);
 
-   dev-iobase = iobase;
+   return pcidev;
+}
+
+static int pci1710_attach(struct comedi_device *dev,
+ struct comedi_devconfig *it)
+{
+   struct comedi_subdevice *s;
+   int ret, subdev, n_subdevices;
+   unsigned int irq;
+
+   dev_info(dev-class_dev, DRV_NAME : attach\n);
+
+   ret = alloc_private(dev, sizeof(struct pci1710_private));
+   if (ret  0)
+   return -ENOMEM;
+
+   devpriv-pcidev = pci1710_find_pci_dev(dev, it);
+   if (!devpriv-pcidev)
+   return -EIO;
+
+   dev-iobase = pci_resource_start(devpriv-pcidev, 2);
+   irq = devpriv-pcidev-irq;
 
dev-board_name = this_board-name;
-   devpriv-pcidev = pcidev;
 
n_subdevices = 0;
if (this_board-n_aichan)
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 19/90] staging: comedi: adv_pci1710: move comedi_pci_enable() into the attach

2012-07-18 Thread H Hartley Sweeten
Use pci_is_enabled() in the find pci device function to determine if
the found pci device is not in use and move the comedi_pci_enable() call
into the attach.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/adv_pci1710.c | 15 ++-
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/comedi/drivers/adv_pci1710.c 
b/drivers/staging/comedi/drivers/adv_pci1710.c
index 5eecf6b..33dd1db 100644
--- a/drivers/staging/comedi/drivers/adv_pci1710.c
+++ b/drivers/staging/comedi/drivers/adv_pci1710.c
@@ -1350,6 +1350,8 @@ static struct pci_dev *pci1710_find_pci_dev(struct 
comedi_device *dev,
}
if (pcidev-vendor != PCI_VENDOR_ID_ADVANTECH)
continue;
+   if (pci_is_enabled(pcidev))
+   continue;
 
if (strcmp(this_board-name, DRV_NAME) == 0) {
for (i = 0; i  ARRAY_SIZE(boardtypes); ++i) {
@@ -1364,15 +1366,6 @@ static struct pci_dev *pci1710_find_pci_dev(struct 
comedi_device *dev,
if (pcidev-device != boardtypes[board_index].device_id)
continue;
}
-
-   /*
-* Look for device that isn't in use.
-* Enable PCI device and request regions.
-*/
-   if (comedi_pci_enable(pcidev, DRV_NAME)) {
-   continue;
-   }
-   /*  fixup board_ptr in case we were using the dummy entry with 
the driver name */
dev-board_ptr = boardtypes[board_index];
return pcidev;
}
@@ -1399,6 +1392,10 @@ static int pci1710_attach(struct comedi_device *dev,
if (!devpriv-pcidev)
return -EIO;
 
+   ret = comedi_pci_enable(devpriv-pcidev, DRV_NAME);
+   if (ret)
+   return ret;
+
dev-iobase = pci_resource_start(devpriv-pcidev, 2);
irq = devpriv-pcidev-irq;
 
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 20/90] staging: comedi: adv_pci1710: store the pci_dev in the comedi_device

2012-07-18 Thread H Hartley Sweeten
Use the hw_dev pointer in the comedi_device struct to hold the
pci_dev instead of carrying it in the private data.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/adv_pci1710.c | 25 ++---
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/comedi/drivers/adv_pci1710.c 
b/drivers/staging/comedi/drivers/adv_pci1710.c
index 33dd1db..3198660 100644
--- a/drivers/staging/comedi/drivers/adv_pci1710.c
+++ b/drivers/staging/comedi/drivers/adv_pci1710.c
@@ -248,7 +248,6 @@ static const struct boardtype boardtypes[] = {
 };
 
 struct pci1710_private {
-   struct pci_dev *pcidev; /*  ptr to PCI device */
char valid; /*  card is usable */
char neverending_ai;/*  we do unlimited AI */
unsigned int CntrlReg;  /*  Control register */
@@ -1378,6 +1377,7 @@ static struct pci_dev *pci1710_find_pci_dev(struct 
comedi_device *dev,
 static int pci1710_attach(struct comedi_device *dev,
  struct comedi_devconfig *it)
 {
+   struct pci_dev *pcidev;
struct comedi_subdevice *s;
int ret, subdev, n_subdevices;
unsigned int irq;
@@ -1388,16 +1388,17 @@ static int pci1710_attach(struct comedi_device *dev,
if (ret  0)
return -ENOMEM;
 
-   devpriv-pcidev = pci1710_find_pci_dev(dev, it);
-   if (!devpriv-pcidev)
+   pcidev = pci1710_find_pci_dev(dev, it);
+   if (!pcidev)
return -EIO;
+   comedi_set_hw_dev(dev, pcidev-dev);
 
-   ret = comedi_pci_enable(devpriv-pcidev, DRV_NAME);
+   ret = comedi_pci_enable(pcidev, DRV_NAME);
if (ret)
return ret;
 
-   dev-iobase = pci_resource_start(devpriv-pcidev, 2);
-   irq = devpriv-pcidev-irq;
+   dev-iobase = pci_resource_start(pcidev, 2);
+   irq = pcidev-irq;
 
dev-board_name = this_board-name;
 
@@ -1532,16 +1533,18 @@ static int pci1710_attach(struct comedi_device *dev,
 
 static void pci1710_detach(struct comedi_device *dev)
 {
+   struct pci_dev *pcidev = comedi_to_pci_dev(dev);
+
if (dev-private) {
if (devpriv-valid)
pci1710_reset(dev);
if (dev-irq)
free_irq(dev-irq, dev);
-   if (devpriv-pcidev) {
-   if (dev-iobase)
-   comedi_pci_disable(devpriv-pcidev);
-   pci_dev_put(devpriv-pcidev);
-   }
+   }
+   if (pcidev) {
+   if (dev-iobase)
+   comedi_pci_disable(pcidev);
+   pci_dev_put(pcidev);
}
 }
 
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 21/90] staging: comedi: adv_pci_dio: factor out the find pci device code

2012-07-18 Thread H Hartley Sweeten
Factor the find pci device code out of the attach function.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/adv_pci_dio.c | 48 +---
 1 file changed, 29 insertions(+), 19 deletions(-)

diff --git a/drivers/staging/comedi/drivers/adv_pci_dio.c 
b/drivers/staging/comedi/drivers/adv_pci_dio.c
index ad653a5..e1f52c6 100644
--- a/drivers/staging/comedi/drivers/adv_pci_dio.c
+++ b/drivers/staging/comedi/drivers/adv_pci_dio.c
@@ -1077,23 +1077,16 @@ static int CheckAndAllocCard(struct comedi_device *dev,
pci_priv = devpriv;
}
 
-   devpriv-pcidev = pcidev;
-
return 1;
 }
 
-static int pci_dio_attach(struct comedi_device *dev,
- struct comedi_devconfig *it)
+static struct pci_dev *pci_dio_find_pci_dev(struct comedi_device *dev,
+   struct comedi_devconfig *it)
 {
-   struct comedi_subdevice *s;
-   int ret, subdev, n_subdevices, i, j;
-   unsigned long iobase;
struct pci_dev *pcidev = NULL;
-
-
-   ret = alloc_private(dev, sizeof(struct pci_dio_private));
-   if (ret  0)
-   return -ENOMEM;
+   unsigned long iobase;
+   int i;
+   int ret;
 
for_each_pci_dev(pcidev) {
/*  loop through cards supported by this driver */
@@ -1123,20 +1116,37 @@ static int pci_dio_attach(struct comedi_device *dev,
if (!dev-board_ptr) {
dev_err(dev-class_dev,
Error: Requested type of the card was not found!\n);
-   return -EIO;
+   return NULL;
}
+   iobase = pci_resource_start(devpriv-pcidev, 
this_board-main_pci_region);
+   dev_dbg(dev-class_dev, b:s:f=%d:%d:%d, io=0x%4lx\n,
+   pcidev-bus-number, PCI_SLOT(pcidev-devfn),
+   PCI_FUNC(pcidev-devfn), iobase);
+   return pcidev;
+}
 
-   if (comedi_pci_enable(pcidev, dev-driver-driver_name)) {
+static int pci_dio_attach(struct comedi_device *dev,
+ struct comedi_devconfig *it)
+{
+   struct comedi_subdevice *s;
+   int ret, subdev, n_subdevices, i, j;
+
+   ret = alloc_private(dev, sizeof(struct pci_dio_private));
+   if (ret  0)
+   return -ENOMEM;
+
+   devpriv-pcidev = pci_dio_find_pci_dev(dev, it);
+   if (!devpriv-pcidev)
+   return -EIO;
+
+   if (comedi_pci_enable(devpriv-pcidev, dev-driver-driver_name)) {
dev_err(dev-class_dev,
Error: Can't enable PCI device and request 
regions!\n);
return -EIO;
}
-   iobase = pci_resource_start(pcidev, this_board-main_pci_region);
-   dev_dbg(dev-class_dev, b:s:f=%d:%d:%d, io=0x%4lx\n,
-   pcidev-bus-number, PCI_SLOT(pcidev-devfn),
-   PCI_FUNC(pcidev-devfn), iobase);
 
-   dev-iobase = iobase;
+   dev-iobase = pci_resource_start(devpriv-pcidev,
+this_board-main_pci_region);
dev-board_name = this_board-name;
 
if (this_board-cardtype == TYPE_PCI1760) {
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 22/90] staging: comedi: adv_pci_dio: remove CheckAndAllocCard()

2012-07-18 Thread H Hartley Sweeten
This driver creates a linked list of all the pci devices in
the system while it's looking for a match. It's only use is
to determine if a device is free to use. The pci_is_enabled()
helper can give us the same information. Use that instead and
remove the linked list.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/adv_pci_dio.c | 39 +---
 1 file changed, 1 insertion(+), 38 deletions(-)

diff --git a/drivers/staging/comedi/drivers/adv_pci_dio.c 
b/drivers/staging/comedi/drivers/adv_pci_dio.c
index e1f52c6..ab92169 100644
--- a/drivers/staging/comedi/drivers/adv_pci_dio.c
+++ b/drivers/staging/comedi/drivers/adv_pci_dio.c
@@ -382,8 +382,6 @@ static const struct dio_boardtype boardtypes[] = {
 };
 
 struct pci_dio_private {
-   struct pci_dio_private *prev;   /*  previous private struct */
-   struct pci_dio_private *next;   /*  next private struct */
struct pci_dev *pcidev; /*  pointer to board's pci_dev */
char valid; /*  card is usable */
char GlobalIrqEnabled;  /*  1= any IRQ source is enabled */
@@ -404,8 +402,6 @@ struct pci_dio_private {
unsigned short IDIFiltrHigh[8]; /*  IDI's filter value high signal */
 };
 
-static struct pci_dio_private *pci_priv;   /* list of allocated cards */
-
 #define devpriv ((struct pci_dio_private *)dev-private)
 #define this_board ((const struct dio_boardtype *)dev-board_ptr)
 
@@ -1055,38 +1051,12 @@ static int pci_dio_add_8254(struct comedi_device *dev,
return 0;
 }
 
-/*
-==
-*/
-static int CheckAndAllocCard(struct comedi_device *dev,
-struct comedi_devconfig *it,
-struct pci_dev *pcidev)
-{
-   struct pci_dio_private *pr, *prev;
-
-   for (pr = pci_priv, prev = NULL; pr != NULL; prev = pr, pr = pr-next) {
-   if (pr-pcidev == pcidev)
-   return 0; /* this card is used, look for another */
-
-   }
-
-   if (prev) {
-   devpriv-prev = prev;
-   prev-next = devpriv;
-   } else {
-   pci_priv = devpriv;
-   }
-
-   return 1;
-}
-
 static struct pci_dev *pci_dio_find_pci_dev(struct comedi_device *dev,
struct comedi_devconfig *it)
 {
struct pci_dev *pcidev = NULL;
unsigned long iobase;
int i;
-   int ret;
 
for_each_pci_dev(pcidev) {
/*  loop through cards supported by this driver */
@@ -1103,8 +1073,7 @@ static struct pci_dev *pci_dio_find_pci_dev(struct 
comedi_device *dev,
continue;
}
}
-   ret = CheckAndAllocCard(dev, it, pcidev);
-   if (ret != 1)
+   if (pci_is_enabled(pcidev))
continue;
dev-board_ptr = boardtypes + i;
break;
@@ -1260,12 +1229,6 @@ static void pci_dio_detach(struct comedi_device *dev)
comedi_pci_disable(devpriv-pcidev);
pci_dev_put(devpriv-pcidev);
}
-   if (devpriv-prev)
-   devpriv-prev-next = devpriv-next;
-   else
-   pci_priv = devpriv-next;
-   if (devpriv-next)
-   devpriv-next-prev = devpriv-prev;
}
 }
 
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 23/90] staging: comedi: adv_pci_dio: cleanup find pci device code

2012-07-18 Thread H Hartley Sweeten
Add a couple local variables to make the tests more concise.
Reorder the tests to make the for() loop checking for a
matching boardtype quicker.

Drop the dev_dbg message for a match. It's just add noise.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/adv_pci_dio.c | 40 ++--
 1 file changed, 14 insertions(+), 26 deletions(-)

diff --git a/drivers/staging/comedi/drivers/adv_pci_dio.c 
b/drivers/staging/comedi/drivers/adv_pci_dio.c
index ab92169..c805208 100644
--- a/drivers/staging/comedi/drivers/adv_pci_dio.c
+++ b/drivers/staging/comedi/drivers/adv_pci_dio.c
@@ -1055,43 +1055,31 @@ static struct pci_dev *pci_dio_find_pci_dev(struct 
comedi_device *dev,
struct comedi_devconfig *it)
 {
struct pci_dev *pcidev = NULL;
-   unsigned long iobase;
+   int bus = it-options[0];
+   int slot = it-options[1];
int i;
 
for_each_pci_dev(pcidev) {
-   /*  loop through cards supported by this driver */
+   if (bus || slot) {
+   if (bus != pcidev-bus-number ||
+   slot != PCI_SLOT(pcidev-devfn))
+   continue;
+   }
+   if (pci_is_enabled(pcidev))
+   continue;
for (i = 0; i  ARRAY_SIZE(boardtypes); ++i) {
if (boardtypes[i].vendor_id != pcidev-vendor)
continue;
if (boardtypes[i].device_id != pcidev-device)
continue;
-   /*  was a particular bus/slot requested? */
-   if (it-options[0] || it-options[1]) {
-   /*  are we on the wrong bus/slot? */
-   if (pcidev-bus-number != it-options[0] ||
-   PCI_SLOT(pcidev-devfn) != it-options[1]) {
-   continue;
-   }
-   }
-   if (pci_is_enabled(pcidev))
-   continue;
dev-board_ptr = boardtypes + i;
-   break;
+   return pcidev;
}
-   if (dev-board_ptr)
-   break;
-   }
-
-   if (!dev-board_ptr) {
-   dev_err(dev-class_dev,
-   Error: Requested type of the card was not found!\n);
-   return NULL;
}
-   iobase = pci_resource_start(devpriv-pcidev, 
this_board-main_pci_region);
-   dev_dbg(dev-class_dev, b:s:f=%d:%d:%d, io=0x%4lx\n,
-   pcidev-bus-number, PCI_SLOT(pcidev-devfn),
-   PCI_FUNC(pcidev-devfn), iobase);
-   return pcidev;
+   dev_err(dev-class_dev,
+   No supported board found! (req. bus %d, slot %d)\n,
+   bus, slot);
+   return NULL;
 }
 
 static int pci_dio_attach(struct comedi_device *dev,
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 24/90] staging: comedi: adv_pci_dio: store the pci_dev in the comedi_device

2012-07-18 Thread H Hartley Sweeten
Use the hw_dev pointer in the comedi_device struct to hold the
pci_dev instead of carrying it in the private data.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/adv_pci_dio.c | 23 ---
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/comedi/drivers/adv_pci_dio.c 
b/drivers/staging/comedi/drivers/adv_pci_dio.c
index c805208..97f06dc 100644
--- a/drivers/staging/comedi/drivers/adv_pci_dio.c
+++ b/drivers/staging/comedi/drivers/adv_pci_dio.c
@@ -382,7 +382,6 @@ static const struct dio_boardtype boardtypes[] = {
 };
 
 struct pci_dio_private {
-   struct pci_dev *pcidev; /*  pointer to board's pci_dev */
char valid; /*  card is usable */
char GlobalIrqEnabled;  /*  1= any IRQ source is enabled */
/*  PCI-1760 specific data */
@@ -1085,6 +1084,7 @@ static struct pci_dev *pci_dio_find_pci_dev(struct 
comedi_device *dev,
 static int pci_dio_attach(struct comedi_device *dev,
  struct comedi_devconfig *it)
 {
+   struct pci_dev *pcidev;
struct comedi_subdevice *s;
int ret, subdev, n_subdevices, i, j;
 
@@ -1092,18 +1092,18 @@ static int pci_dio_attach(struct comedi_device *dev,
if (ret  0)
return -ENOMEM;
 
-   devpriv-pcidev = pci_dio_find_pci_dev(dev, it);
-   if (!devpriv-pcidev)
+   pcidev = pci_dio_find_pci_dev(dev, it);
+   if (!pcidev)
return -EIO;
+   comedi_set_hw_dev(dev, pcidev-dev);
 
-   if (comedi_pci_enable(devpriv-pcidev, dev-driver-driver_name)) {
+   if (comedi_pci_enable(pcidev, dev-driver-driver_name)) {
dev_err(dev-class_dev,
Error: Can't enable PCI device and request 
regions!\n);
return -EIO;
}
 
-   dev-iobase = pci_resource_start(devpriv-pcidev,
-this_board-main_pci_region);
+   dev-iobase = pci_resource_start(pcidev, this_board-main_pci_region);
dev-board_name = this_board-name;
 
if (this_board-cardtype == TYPE_PCI1760) {
@@ -1180,6 +1180,7 @@ static int pci_dio_attach(struct comedi_device *dev,
 
 static void pci_dio_detach(struct comedi_device *dev)
 {
+   struct pci_dev *pcidev = comedi_to_pci_dev(dev);
int i, j;
struct comedi_subdevice *s;
int subdev;
@@ -1212,11 +1213,11 @@ static void pci_dio_detach(struct comedi_device *dev)
s = dev-subdevices + i;
s-private = NULL;
}
-   if (devpriv-pcidev) {
-   if (dev-iobase)
-   comedi_pci_disable(devpriv-pcidev);
-   pci_dev_put(devpriv-pcidev);
-   }
+   }
+   if (pcidev) {
+   if (dev-iobase)
+   comedi_pci_disable(pcidev);
+   pci_dev_put(pcidev);
}
 }
 
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 25/90] staging: comedi: cb_pcidas: store the pci_dev in the comedi_device

2012-07-18 Thread H Hartley Sweeten
Use the hw_dev pointer in the comedi_device struct to hold the
pci_dev instead of carrying it in the private data.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/cb_pcidas.c | 32 --
 1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/drivers/staging/comedi/drivers/cb_pcidas.c 
b/drivers/staging/comedi/drivers/cb_pcidas.c
index 301444e..2b6a637 100644
--- a/drivers/staging/comedi/drivers/cb_pcidas.c
+++ b/drivers/staging/comedi/drivers/cb_pcidas.c
@@ -343,7 +343,6 @@ static const struct cb_pcidas_board cb_pcidas_boards[] = {
 };
 
 struct cb_pcidas_private {
-   struct pci_dev *pci_dev;
/* base addresses */
unsigned long s5933_config;
unsigned long control_status;
@@ -1545,6 +1544,7 @@ static int cb_pcidas_attach(struct comedi_device *dev,
 {
const struct cb_pcidas_board *thisboard;
struct cb_pcidas_private *devpriv;
+   struct pci_dev *pcidev;
struct comedi_subdevice *s;
int i;
int ret;
@@ -1553,35 +1553,36 @@ static int cb_pcidas_attach(struct comedi_device *dev,
return -ENOMEM;
devpriv = dev-private;
 
-   devpriv-pci_dev = cb_pcidas_find_pci_device(dev, it);
-   if (!devpriv-pci_dev)
+   pcidev = cb_pcidas_find_pci_device(dev, it);
+   if (!pcidev)
return -EIO;
+   comedi_set_hw_dev(dev, pcidev-dev);
thisboard = comedi_board(dev);
 
-   if (comedi_pci_enable(devpriv-pci_dev, dev-driver-driver_name)) {
+   if (comedi_pci_enable(pcidev, dev-driver-driver_name)) {
dev_err(dev-class_dev,
Failed to enable PCI device and request regions\n);
return -EIO;
}
 
-   devpriv-s5933_config = pci_resource_start(devpriv-pci_dev, 0);
-   devpriv-control_status = pci_resource_start(devpriv-pci_dev, 1);
-   devpriv-adc_fifo = pci_resource_start(devpriv-pci_dev, 2);
-   devpriv-pacer_counter_dio = pci_resource_start(devpriv-pci_dev, 3);
+   devpriv-s5933_config = pci_resource_start(pcidev, 0);
+   devpriv-control_status = pci_resource_start(pcidev, 1);
+   devpriv-adc_fifo = pci_resource_start(pcidev, 2);
+   devpriv-pacer_counter_dio = pci_resource_start(pcidev, 3);
if (thisboard-ao_nchan)
-   devpriv-ao_registers = pci_resource_start(devpriv-pci_dev, 4);
+   devpriv-ao_registers = pci_resource_start(pcidev, 4);
 
/*  disable and clear interrupts on amcc s5933 */
outl(INTCSR_INBOX_INTR_STATUS,
 devpriv-s5933_config + AMCC_OP_REG_INTCSR);
 
-   if (request_irq(devpriv-pci_dev-irq, cb_pcidas_interrupt,
+   if (request_irq(pcidev-irq, cb_pcidas_interrupt,
IRQF_SHARED, dev-driver-driver_name, dev)) {
dev_dbg(dev-class_dev, unable to allocate irq %d\n,
-   devpriv-pci_dev-irq);
+   pcidev-irq);
return -EINVAL;
}
-   dev-irq = devpriv-pci_dev-irq;
+   dev-irq = pcidev-irq;
 
dev-board_name = thisboard-name;
 
@@ -1703,6 +1704,7 @@ static int cb_pcidas_attach(struct comedi_device *dev,
 static void cb_pcidas_detach(struct comedi_device *dev)
 {
struct cb_pcidas_private *devpriv = dev-private;
+   struct pci_dev *pcidev = comedi_to_pci_dev(dev);
 
if (devpriv) {
if (devpriv-s5933_config) {
@@ -1714,10 +1716,10 @@ static void cb_pcidas_detach(struct comedi_device *dev)
free_irq(dev-irq, dev);
if (dev-subdevices)
subdev_8255_cleanup(dev, dev-subdevices + 2);
-   if (devpriv  devpriv-pci_dev) {
+   if (pcidev) {
if (devpriv-s5933_config)
-   comedi_pci_disable(devpriv-pci_dev);
-   pci_dev_put(devpriv-pci_dev);
+   comedi_pci_disable(pcidev);
+   pci_dev_put(pcidev);
}
 }
 
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 26/90] staging: comedi: cb_pcidio: factor out the find pci device code

2012-07-18 Thread H Hartley Sweeten
Factor the find pci device code out of the attach function.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/cb_pcidio.c | 54 ++
 1 file changed, 25 insertions(+), 29 deletions(-)

diff --git a/drivers/staging/comedi/drivers/cb_pcidio.c 
b/drivers/staging/comedi/drivers/cb_pcidio.c
index 9160859..5f4d0a5 100644
--- a/drivers/staging/comedi/drivers/cb_pcidio.c
+++ b/drivers/staging/comedi/drivers/cb_pcidio.c
@@ -111,27 +111,11 @@ struct pcidio_private {
  */
 #define devpriv ((struct pcidio_private *)dev-private)
 
-static int pcidio_attach(struct comedi_device *dev, struct comedi_devconfig 
*it)
+static struct pci_dev *pcidio_find_pci_dev(struct comedi_device *dev,
+  struct comedi_devconfig *it)
 {
struct pci_dev *pcidev = NULL;
int index;
-   int i;
-   int ret;
-
-/*
- * Allocate the private structure area.  alloc_private() is a
- * convenient macro defined in comedidev.h.
- */
-   if (alloc_private(dev, sizeof(struct pcidio_private))  0)
-   return -ENOMEM;
-/*
- * If you can probe the device to determine what device in a series
- * it is, this is the place to do it.  Otherwise, dev-board_ptr
- * should already be initialized.
- */
-/*
- * Probe the device to determine what device in the series it is.
- */
 
for_each_pci_dev(pcidev) {
/*  is it not a computer boards card? */
@@ -151,15 +135,32 @@ static int pcidio_attach(struct comedi_device *dev, 
struct comedi_devconfig *it)
}
}
dev-board_ptr = pcidio_boards + index;
-   goto found;
+   dev_dbg(dev-class_dev, Found %s on bus %i, slot %i\n,
+   thisboard-name, devpriv-pci_dev-bus-number,
+   PCI_SLOT(devpriv-pci_dev-devfn));
+   return pcidev;
}
}
-
dev_err(dev-class_dev,
No supported ComputerBoards/MeasurementComputing card found on 
requested position\n);
-   return -EIO;
+   return NULL;
+}
+
+static int pcidio_attach(struct comedi_device *dev, struct comedi_devconfig 
*it)
+{
+   int i;
+   int ret;
+
+/*
+ * Allocate the private structure area.  alloc_private() is a
+ * convenient macro defined in comedidev.h.
+ */
+   if (alloc_private(dev, sizeof(struct pcidio_private))  0)
+   return -ENOMEM;
 
-found:
+   devpriv-pci_dev = pcidio_find_pci_dev(dev, it);
+   if (!devpriv-pci_dev)
+   return -EIO;
 
 /*
  * Initialize dev-board_name.  Note that we can use the thisboard
@@ -167,17 +168,12 @@ found:
  */
dev-board_name = thisboard-name;
 
-   devpriv-pci_dev = pcidev;
-   dev_dbg(dev-class_dev, Found %s on bus %i, slot %i\n,
-   thisboard-name, devpriv-pci_dev-bus-number,
-   PCI_SLOT(devpriv-pci_dev-devfn));
-   if (comedi_pci_enable(pcidev, thisboard-name))
+   if (comedi_pci_enable(devpriv-pci_dev, thisboard-name))
return -EIO;
 
devpriv-dio_reg_base
=
-   pci_resource_start(devpriv-pci_dev,
-  pcidio_boards[index].dioregs_badrindex);
+   pci_resource_start(devpriv-pci_dev, thisboard-dioregs_badrindex);
 
ret = comedi_alloc_subdevices(dev, thisboard-n_8255);
if (ret)
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 27/90] staging: comedi: cb_pcidio: cleanup find pci device code

2012-07-18 Thread H Hartley Sweeten
Add a couple local variables to make the tests more concise.
Reorder the tests to make the for() loop checking for a
matching boardtype quicker.

Drop the dev_dbg for a match. It's just add noise.
Reword the dev_err when no match is found.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/cb_pcidio.c | 31 +-
 1 file changed, 13 insertions(+), 18 deletions(-)

diff --git a/drivers/staging/comedi/drivers/cb_pcidio.c 
b/drivers/staging/comedi/drivers/cb_pcidio.c
index 5f4d0a5..5527b4b 100644
--- a/drivers/staging/comedi/drivers/cb_pcidio.c
+++ b/drivers/staging/comedi/drivers/cb_pcidio.c
@@ -115,34 +115,29 @@ static struct pci_dev *pcidio_find_pci_dev(struct 
comedi_device *dev,
   struct comedi_devconfig *it)
 {
struct pci_dev *pcidev = NULL;
-   int index;
+   int bus = it-options[0];
+   int slot = it-options[1];
+   int i;
 
for_each_pci_dev(pcidev) {
-   /*  is it not a computer boards card? */
+   if (bus || slot) {
+   if (bus != pcidev-bus-number ||
+   slot != PCI_SLOT(pcidev-devfn))
+   continue;
+   }
if (pcidev-vendor != PCI_VENDOR_ID_CB)
continue;
-   /*  loop through cards supported by this driver */
-   for (index = 0; index  ARRAY_SIZE(pcidio_boards); index++) {
-   if (pcidio_boards[index].dev_id != pcidev-device)
+   for (i = 0; i  ARRAY_SIZE(pcidio_boards); i++) {
+   if (pcidio_boards[i].dev_id != pcidev-device)
continue;
 
-   /*  was a particular bus/slot requested? */
-   if (it-options[0] || it-options[1]) {
-   /*  are we on the wrong bus/slot? */
-   if (pcidev-bus-number != it-options[0] ||
-   PCI_SLOT(pcidev-devfn) != it-options[1]) {
-   continue;
-   }
-   }
-   dev-board_ptr = pcidio_boards + index;
-   dev_dbg(dev-class_dev, Found %s on bus %i, slot %i\n,
-   thisboard-name, devpriv-pci_dev-bus-number,
-   PCI_SLOT(devpriv-pci_dev-devfn));
+   dev-board_ptr = pcidio_boards + i;
return pcidev;
}
}
dev_err(dev-class_dev,
-   No supported ComputerBoards/MeasurementComputing card found on 
requested position\n);
+   No supported board found! (req. bus %d, slot %d)\n,
+   bus, slot);
return NULL;
 }
 
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 28/90] staging: comedi: cb_pcidio: store the pci_dev in the comedi_device

2012-07-18 Thread H Hartley Sweeten
Use the hw_dev pointer in the comedi_device struct to hold the
pci_dev instead of carrying it in the private data.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/cb_pcidio.c | 25 -
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/comedi/drivers/cb_pcidio.c 
b/drivers/staging/comedi/drivers/cb_pcidio.c
index 5527b4b..11c7502 100644
--- a/drivers/staging/comedi/drivers/cb_pcidio.c
+++ b/drivers/staging/comedi/drivers/cb_pcidio.c
@@ -96,9 +96,6 @@ static const struct pcidio_board pcidio_boards[] = {
 struct pcidio_private {
int data;   /*  currently unused */
 
-   /* would be useful for a PCI device */
-   struct pci_dev *pci_dev;
-
/* used for DO readback, currently unused */
unsigned int do_readback[4];/* up to 4 unsigned int suffice to hold 
96 bits for PCI-DIO96 */
 
@@ -143,6 +140,7 @@ static struct pci_dev *pcidio_find_pci_dev(struct 
comedi_device *dev,
 
 static int pcidio_attach(struct comedi_device *dev, struct comedi_devconfig 
*it)
 {
+   struct pci_dev *pcidev;
int i;
int ret;
 
@@ -153,9 +151,10 @@ static int pcidio_attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
if (alloc_private(dev, sizeof(struct pcidio_private))  0)
return -ENOMEM;
 
-   devpriv-pci_dev = pcidio_find_pci_dev(dev, it);
-   if (!devpriv-pci_dev)
+   pcidev = pcidio_find_pci_dev(dev, it);
+   if (!pcidev)
return -EIO;
+   comedi_set_hw_dev(dev, pcidev-dev);
 
 /*
  * Initialize dev-board_name.  Note that we can use the thisboard
@@ -163,12 +162,12 @@ static int pcidio_attach(struct comedi_device *dev, 
struct comedi_devconfig *it)
  */
dev-board_name = thisboard-name;
 
-   if (comedi_pci_enable(devpriv-pci_dev, thisboard-name))
+   if (comedi_pci_enable(pcidev, thisboard-name))
return -EIO;
 
devpriv-dio_reg_base
=
-   pci_resource_start(devpriv-pci_dev, thisboard-dioregs_badrindex);
+   pci_resource_start(pcidev, thisboard-dioregs_badrindex);
 
ret = comedi_alloc_subdevices(dev, thisboard-n_8255);
if (ret)
@@ -186,12 +185,12 @@ static int pcidio_attach(struct comedi_device *dev, 
struct comedi_devconfig *it)
 
 static void pcidio_detach(struct comedi_device *dev)
 {
-   if (devpriv) {
-   if (devpriv-pci_dev) {
-   if (devpriv-dio_reg_base)
-   comedi_pci_disable(devpriv-pci_dev);
-   pci_dev_put(devpriv-pci_dev);
-   }
+   struct pci_dev *pcidev = comedi_to_pci_dev(dev);
+
+   if (pcidev) {
+   if (devpriv-dio_reg_base)
+   comedi_pci_disable(pcidev);
+   pci_dev_put(pcidev);
}
if (dev-subdevices) {
int i;
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 29/90] staging: comedi: amplc_dio200: cleanup find pci device code

2012-07-18 Thread H Hartley Sweeten
For aesthetic reasons, rename the function and pass the
comedi_devconfig struct instead of pre-parsing out the bus/slot
information.

Use for_each_pci_dev() instead of open-coding the loop using
pci_get_device().

Consolidate the dev_err messages when a pci device is not found.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/amplc_dio200.c | 42 ++-
 1 file changed, 15 insertions(+), 27 deletions(-)

diff --git a/drivers/staging/comedi/drivers/amplc_dio200.c 
b/drivers/staging/comedi/drivers/amplc_dio200.c
index 55f3050..ca9d4f2 100644
--- a/drivers/staging/comedi/drivers/amplc_dio200.c
+++ b/drivers/staging/comedi/drivers/amplc_dio200.c
@@ -469,23 +469,23 @@ dio200_find_pci_board(struct pci_dev *pci_dev)
  * This function looks for a PCI device matching the requested board name,
  * bus and slot.
  */
-static struct pci_dev *
-dio200_find_pci(struct comedi_device *dev, int bus, int slot)
+static struct pci_dev *dio200_find_pci_dev(struct comedi_device *dev,
+  struct comedi_devconfig *it)
 {
const struct dio200_board *thisboard = comedi_board(dev);
struct pci_dev *pci_dev = NULL;
+   int bus = it-options[0];
+   int slot = it-options[1];
 
-   /* Look for matching PCI device. */
-   for (pci_dev = pci_get_device(PCI_VENDOR_ID_AMPLICON, PCI_ANY_ID, NULL);
-pci_dev != NULL;
-pci_dev = pci_get_device(PCI_VENDOR_ID_AMPLICON,
- PCI_ANY_ID, pci_dev)) {
-   /* If bus/slot specified, check them. */
+   for_each_pci_dev(pci_dev) {
if (bus || slot) {
-   if (bus != pci_dev-bus-number
-   || slot != PCI_SLOT(pci_dev-devfn))
+   if (bus != pci_dev-bus-number ||
+   slot != PCI_SLOT(pci_dev-devfn))
continue;
}
+   if (pci_dev-vendor != PCI_VENDOR_ID_AMPLICON)
+   continue;
+
if (thisboard-model == anypci_model) {
/* Wildcard board matches any supported PCI board. */
const struct dio200_board *foundboard;
@@ -495,25 +495,16 @@ dio200_find_pci(struct comedi_device *dev, int bus, int 
slot)
continue;
/* Replace wildcard board_ptr. */
dev-board_ptr = foundboard;
-   thisboard = comedi_board(dev);
} else {
/* Match specific model name. */
if (pci_dev-device != thisboard-devid)
continue;
}
-
-   /* Found a match. */
return pci_dev;
}
-   /* No match found. */
-   if (bus || slot) {
-   dev_err(dev-class_dev,
-   error! no %s found at pci %02x:%02x!\n,
-   thisboard-name, bus, slot);
-   } else {
-   dev_err(dev-class_dev, error! no %s found!\n,
-   thisboard-name);
-   }
+   dev_err(dev-class_dev,
+   No supported board found! (req. bus %d, slot %d)\n,
+   bus, slot);
return NULL;
 }
 
@@ -1385,12 +1376,9 @@ static int dio200_attach(struct comedi_device *dev, 
struct comedi_devconfig *it)
} else if (IS_ENABLED(CONFIG_COMEDI_AMPLC_DIO200_PCI) 
   thisboard-bustype == pci_bustype) {
struct pci_dev *pci_dev;
-   int bus, slot;
 
-   bus = it-options[0];
-   slot = it-options[1];
-   pci_dev = dio200_find_pci(dev, bus, slot);
-   if (pci_dev == NULL)
+   pci_dev = dio200_find_pci_dev(dev, it);
+   if (!pci_dev)
return -EIO;
return dio200_pci_common_attach(dev, pci_dev);
} else {
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 30/90] staging: comedi: amplc_dio200: store the pci_dev in the comedi_device

2012-07-18 Thread H Hartley Sweeten
Use the hw_dev pointer in the comedi_device struct to hold the
pci_dev instead of carrying it in the private data.

Since the pci_dev is no longer held in the provate data, we can
also cleanup the detach a bit. Remove the IS_ENABLED() tests in
the detach. If the pci_dev is non NULL it's a PCI device otherwise
it's an ISA device. Using IS_ENABLED() to omit the code paths
makes the code a bit confusing and doesn't save much.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/amplc_dio200.c | 31 +++
 1 file changed, 12 insertions(+), 19 deletions(-)

diff --git a/drivers/staging/comedi/drivers/amplc_dio200.c 
b/drivers/staging/comedi/drivers/amplc_dio200.c
index ca9d4f2..6c81e377 100644
--- a/drivers/staging/comedi/drivers/amplc_dio200.c
+++ b/drivers/staging/comedi/drivers/amplc_dio200.c
@@ -424,7 +424,6 @@ static const struct dio200_layout_struct dio200_layouts[] = 
{
feel free to suggest moving the variable to the struct comedi_device struct.
  */
 struct dio200_private {
-   struct pci_dev *pci_dev;/* PCI device */
int intr_sd;
 };
 
@@ -1225,7 +1224,7 @@ dio200_subdev_8254_cleanup(struct comedi_device *dev,
 static void dio200_report_attach(struct comedi_device *dev, unsigned int irq)
 {
const struct dio200_board *thisboard = comedi_board(dev);
-   struct dio200_private *devpriv = dev-private;
+   struct pci_dev *pcidev = comedi_to_pci_dev(dev);
char tmpbuf[60];
int tmplen;
 
@@ -1236,7 +1235,7 @@ static void dio200_report_attach(struct comedi_device 
*dev, unsigned int irq)
else if (IS_ENABLED(CONFIG_COMEDI_AMPLC_DIO200_PCI) 
 thisboard-bustype == pci_bustype)
tmplen = scnprintf(tmpbuf, sizeof(tmpbuf),
-  (pci %s) , pci_name(devpriv-pci_dev));
+  (pci %s) , pci_name(pcidev));
else
tmplen = 0;
if (irq)
@@ -1327,11 +1326,11 @@ static int dio200_common_attach(struct comedi_device 
*dev, unsigned long iobase,
 static int dio200_pci_common_attach(struct comedi_device *dev,
struct pci_dev *pci_dev)
 {
-   struct dio200_private *devpriv = dev-private;
unsigned long iobase;
int ret;
 
-   devpriv-pci_dev = pci_dev;
+   comedi_set_hw_dev(dev, pci_dev-dev);
+
ret = comedi_pci_enable(pci_dev, DIO200_DRIVER_NAME);
if (ret  0) {
dev_err(dev-class_dev,
@@ -1419,7 +1418,7 @@ static int __devinit dio200_attach_pci(struct 
comedi_device *dev,
 static void dio200_detach(struct comedi_device *dev)
 {
const struct dio200_board *thisboard = comedi_board(dev);
-   struct dio200_private *devpriv = dev-private;
+   struct pci_dev *pcidev = comedi_to_pci_dev(dev);
const struct dio200_layout_struct *layout;
unsigned n;
 
@@ -1444,19 +1443,13 @@ static void dio200_detach(struct comedi_device *dev)
}
}
}
-   if (devpriv) {
-   if (IS_ENABLED(CONFIG_COMEDI_AMPLC_DIO200_PCI) 
-   thisboard-bustype == pci_bustype) {
-   if (devpriv-pci_dev) {
-   if (dev-iobase)
-   comedi_pci_disable(devpriv-pci_dev);
-   pci_dev_put(devpriv-pci_dev);
-   }
-   } else if (IS_ENABLED(CONFIG_COMEDI_AMPLC_DIO200_ISA) 
-  thisboard-bustype == isa_bustype) {
-   if (dev-iobase)
-   release_region(dev-iobase, DIO200_IO_SIZE);
-   }
+   if (pcidev) {
+   if (dev-iobase)
+   comedi_pci_disable(pcidev);
+   pci_dev_put(pcidev);
+   } else {
+   if (dev-iobase)
+   release_region(dev-iobase, DIO200_IO_SIZE);
}
 }
 
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 31/90] staging: comedi: amplc_pc236: cleanup find pci device code

2012-07-18 Thread H Hartley Sweeten
For aesthetic reasons, rename the function and pass the
comedi_devconfig struct instead of pre-parsing out the bus/slot
information.

Use for_each_pci_dev() instead of open-coding the loop using
pci_get_device().

Consolidate the dev_err messages when a pci device is not found.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/amplc_pc236.c | 43 +++-
 1 file changed, 17 insertions(+), 26 deletions(-)

diff --git a/drivers/staging/comedi/drivers/amplc_pc236.c 
b/drivers/staging/comedi/drivers/amplc_pc236.c
index 77dae8e..3eee7f3 100644
--- a/drivers/staging/comedi/drivers/amplc_pc236.c
+++ b/drivers/staging/comedi/drivers/amplc_pc236.c
@@ -155,49 +155,42 @@ static const struct pc236_board 
*pc236_find_pci_board(struct pci_dev *pci_dev)
  * This function looks for a PCI device matching the requested board name,
  * bus and slot.
  */
-static struct pci_dev *
-pc236_find_pci(struct comedi_device *dev, int bus, int slot)
+static struct pci_dev *pc236_find_pci_dev(struct comedi_device *dev,
+ struct comedi_devconfig *it)
 {
const struct pc236_board *thisboard = comedi_board(dev);
struct pci_dev *pci_dev = NULL;
+   int bus = it-options[0];
+   int slot = it-options[1];
 
-   /* Look for matching PCI device. */
-   for (pci_dev = pci_get_device(PCI_VENDOR_ID_AMPLICON, PCI_ANY_ID, NULL);
-pci_dev != NULL;
-pci_dev = pci_get_device(PCI_VENDOR_ID_AMPLICON,
- PCI_ANY_ID, pci_dev)) {
-   /* If bus/slot specified, check them. */
+   for_each_pci_dev(pci_dev) {
if (bus || slot) {
-   if (bus != pci_dev-bus-number
-   || slot != PCI_SLOT(pci_dev-devfn))
+   if (bus != pci_dev-bus-number ||
+   slot != PCI_SLOT(pci_dev-devfn))
continue;
}
+   if (pci_dev-vendor != PCI_VENDOR_ID_AMPLICON)
+   continue;
+
if (thisboard-model == anypci_model) {
/* Wildcard board matches any supported PCI board. */
const struct pc236_board *foundboard;
+
foundboard = pc236_find_pci_board(pci_dev);
if (foundboard == NULL)
continue;
/* Replace wildcard board_ptr. */
-   dev-board_ptr = thisboard = foundboard;
+   dev-board_ptr = foundboard;
} else {
/* Match specific model name. */
if (pci_dev-device != thisboard-devid)
continue;
}
-
-   /* Found a match. */
return pci_dev;
}
-   /* No match found. */
-   if (bus || slot) {
-   dev_err(dev-class_dev,
-   error! no %s found at pci %02x:%02x!\n,
-   thisboard-name, bus, slot);
-   } else {
-   dev_err(dev-class_dev, error! no %s found!\n,
-   thisboard-name);
-   }
+   dev_err(dev-class_dev,
+   No supported board found! (req. bus %d, slot %d)\n,
+   bus, slot);
return NULL;
 }
 
@@ -536,12 +529,10 @@ static int pc236_attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
return pc236_common_attach(dev, iobase, irq, 0);
} else if (IS_ENABLED(CONFIG_COMEDI_AMPLC_PC236_PCI) 
   thisboard-bustype == pci_bustype) {
-   int bus = it-options[0];
-   int slot = it-options[1];
struct pci_dev *pci_dev;
 
-   pci_dev = pc236_find_pci(dev, bus, slot);
-   if (pci_dev == NULL)
+   pci_dev = pc236_find_pci_dev(dev, it);
+   if (!pci_dev)
return -EIO;
return pc236_pci_common_attach(dev, pci_dev);
} else {
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 32/90] staging: comedi: amplc_pc236: store the pci_dev in the comedi_device

2012-07-18 Thread H Hartley Sweeten
Use the hw_dev pointer in the comedi_device struct to hold the
pci_dev instead of carrying it in the private data.

Since the pci_dev is no longer held in the provate data, we can
also cleanup the detach a bit. Remove the IS_ENABLED() tests in
the detach. If the pci_dev is non NULL it's a PCI device otherwise
it's an ISA device. Using IS_ENABLED() to omit the code paths
makes the code a bit confusing and doesn't save much.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/amplc_pc236.c | 28 
 1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/drivers/staging/comedi/drivers/amplc_pc236.c 
b/drivers/staging/comedi/drivers/amplc_pc236.c
index 3eee7f3..aabba98 100644
--- a/drivers/staging/comedi/drivers/amplc_pc236.c
+++ b/drivers/staging/comedi/drivers/amplc_pc236.c
@@ -131,8 +131,6 @@ static const struct pc236_board pc236_boards[] = {
feel free to suggest moving the variable to the struct comedi_device struct.
  */
 struct pc236_private {
-   /* PCI device */
-   struct pci_dev *pci_dev;
unsigned long lcr_iobase; /* PLX PCI9052 config registers in PCIBAR1 */
int enable_irq;
 };
@@ -412,6 +410,7 @@ static irqreturn_t pc236_interrupt(int irq, void *d)
 static void pc236_report_attach(struct comedi_device *dev, unsigned int irq)
 {
const struct pc236_board *thisboard = comedi_board(dev);
+   struct pci_dev *pcidev = comedi_to_pci_dev(dev);
char tmpbuf[60];
int tmplen;
 
@@ -421,10 +420,8 @@ static void pc236_report_attach(struct comedi_device *dev, 
unsigned int irq)
   (base %#lx) , dev-iobase);
else if (IS_ENABLED(CONFIG_COMEDI_AMPLC_PC236_PCI) 
 thisboard-bustype == pci_bustype) {
-   struct pc236_private *devpriv = dev-private;
-   struct pci_dev *pci_dev = devpriv-pci_dev;
tmplen = scnprintf(tmpbuf, sizeof(tmpbuf),
-  (pci %s) , pci_name(pci_dev));
+  (pci %s) , pci_name(pcidev));
} else
tmplen = 0;
if (irq)
@@ -489,7 +486,8 @@ static int pc236_pci_common_attach(struct comedi_device 
*dev,
unsigned long iobase;
int ret;
 
-   devpriv-pci_dev = pci_dev;
+   comedi_set_hw_dev(dev, pci_dev-dev);
+
ret = comedi_pci_enable(pci_dev, PC236_DRIVER_NAME);
if (ret  0) {
dev_err(dev-class_dev,
@@ -573,6 +571,7 @@ static int __devinit pc236_attach_pci(struct comedi_device 
*dev,
 static void pc236_detach(struct comedi_device *dev)
 {
struct pc236_private *devpriv = dev-private;
+   struct pci_dev *pcidev = comedi_to_pci_dev(dev);
 
if (devpriv)
pc236_intr_disable(dev);
@@ -580,16 +579,13 @@ static void pc236_detach(struct comedi_device *dev)
free_irq(dev-irq, dev);
if (dev-subdevices)
subdev_8255_cleanup(dev, dev-subdevices + 0);
-   if (devpriv) {
-   if (IS_ENABLED(CONFIG_COMEDI_AMPLC_PC236_PCI) 
-   devpriv-pci_dev) {
-   if (dev-iobase)
-   comedi_pci_disable(devpriv-pci_dev);
-   pci_dev_put(devpriv-pci_dev);
-   } else if (IS_ENABLED(CONFIG_COMEDI_AMPLC_PC236_ISA)) {
-   if (dev-iobase)
-   release_region(dev-iobase, PC236_IO_SIZE);
-   }
+   if (pcidev) {
+   if (dev-iobase)
+   comedi_pci_disable(pcidev);
+   pci_dev_put(pcidev);
+   } else {
+   if (dev-iobase)
+   release_region(dev-iobase, PC236_IO_SIZE);
}
 }
 
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 33/90] staging: comedi: amplc_pc263: cleanup find pci device code

2012-07-18 Thread H Hartley Sweeten
For aesthetic reasons, rename the function and pass the
comedi_devconfig struct instead of pre-parsing out the bus/slot
information.

Use for_each_pci_dev() instead of open-coding the loop using
pci_get_device().

Consolidate the dev_err messages when a pci device is not found.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/amplc_pc263.c | 42 +++-
 1 file changed, 16 insertions(+), 26 deletions(-)

diff --git a/drivers/staging/comedi/drivers/amplc_pc263.c 
b/drivers/staging/comedi/drivers/amplc_pc263.c
index e90178d..8ed8601 100644
--- a/drivers/staging/comedi/drivers/amplc_pc263.c
+++ b/drivers/staging/comedi/drivers/amplc_pc263.c
@@ -121,26 +121,27 @@ static const struct pc263_board 
*pc263_find_pci_board(struct pci_dev *pci_dev)
  * This function looks for a PCI device matching the requested board name,
  * bus and slot.
  */
-static struct pci_dev *
-pc263_find_pci(struct comedi_device *dev, int bus, int slot)
+static struct pci_dev *pc263_find_pci_dev(struct comedi_device *dev,
+ struct comedi_devconfig *it)
 {
const struct pc263_board *thisboard = comedi_board(dev);
struct pci_dev *pci_dev = NULL;
+   int bus = it-options[0];
+   int slot = it-options[1];
 
-   /* Look for matching PCI device. */
-   for (pci_dev = pci_get_device(PCI_VENDOR_ID_AMPLICON, PCI_ANY_ID, NULL);
-pci_dev != NULL;
-pci_dev = pci_get_device(PCI_VENDOR_ID_AMPLICON,
- PCI_ANY_ID, pci_dev)) {
-   /* If bus/slot specified, check them. */
+   for_each_pci_dev(pci_dev) {
if (bus || slot) {
-   if (bus != pci_dev-bus-number
-   || slot != PCI_SLOT(pci_dev-devfn))
+   if (bus != pci_dev-bus-number ||
+   slot != PCI_SLOT(pci_dev-devfn))
continue;
}
+   if (pci_dev-vendor != PCI_VENDOR_ID_AMPLICON)
+   continue;
+
if (thisboard-model == anypci_model) {
/* Wildcard board matches any supported PCI board. */
const struct pc263_board *foundboard;
+
foundboard = pc263_find_pci_board(pci_dev);
if (foundboard == NULL)
continue;
@@ -151,19 +152,11 @@ pc263_find_pci(struct comedi_device *dev, int bus, int 
slot)
if (pci_dev-device != thisboard-devid)
continue;
}
-
-   /* Found a match. */
return pci_dev;
}
-   /* No match found. */
-   if (bus || slot) {
-   dev_err(dev-class_dev,
-   error! no %s found at pci %02x:%02x!\n,
-   thisboard-name, bus, slot);
-   } else {
-   dev_err(dev-class_dev, error! no %s found!\n,
-   thisboard-name);
-   }
+   dev_err(dev-class_dev,
+   No supported board found! (req. bus %d, slot %d)\n,
+   bus, slot);
return NULL;
 }
 /*
@@ -285,17 +278,14 @@ static int pc263_attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
} else if (IS_ENABLED(CONFIG_COMEDI_AMPLC_PC263_PCI) 
   thisboard-bustype == pci_bustype) {
struct pci_dev *pci_dev;
-   int bus, slot;
 
ret = alloc_private(dev, sizeof(struct pc263_private));
if (ret  0) {
dev_err(dev-class_dev, error! out of memory!\n);
return ret;
}
-   bus = it-options[0];
-   slot = it-options[1];
-   pci_dev = pc263_find_pci(dev, bus, slot);
-   if (pci_dev == NULL)
+   pci_dev = pc263_find_pci_dev(dev, it);
+   if (!pci_dev)
return -EIO;
return pc263_pci_common_attach(dev, pci_dev);
} else {
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 34/90] staging: comedi: amplc_pc263: store the pci_dev in the comedi_device

2012-07-18 Thread H Hartley Sweeten
Use the hw_dev pointer in the comedi_device struct to hold the
pci_dev instead of carrying it in the private data.

Since the pci_dev is no longer held in the provate data, we can
also cleanup the detach a bit. Remove the IS_ENABLED() tests in
the detach. If the pci_dev is non NULL it's a PCI device otherwise
it's an ISA device. Using IS_ENABLED() to omit the code paths
makes the code a bit confusing and doesn't save much.

Since the pci_dev was the only thing in the private data, remove
the struct, and it's allocation.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/amplc_pc263.c | 40 +++-
 1 file changed, 9 insertions(+), 31 deletions(-)

diff --git a/drivers/staging/comedi/drivers/amplc_pc263.c 
b/drivers/staging/comedi/drivers/amplc_pc263.c
index 8ed8601..40ec1ff 100644
--- a/drivers/staging/comedi/drivers/amplc_pc263.c
+++ b/drivers/staging/comedi/drivers/amplc_pc263.c
@@ -93,15 +93,6 @@ static const struct pc263_board pc263_boards[] = {
 #endif
 };
 
-/* this structure is for data unique to this hardware driver.  If
-   several hardware drivers keep similar information in this structure,
-   feel free to suggest moving the variable to the struct comedi_device struct.
-*/
-struct pc263_private {
-   /* PCI device. */
-   struct pci_dev *pci_dev;
-};
-
 /*
  * This function looks for a board matching the supplied PCI device.
  */
@@ -193,7 +184,7 @@ static int pc263_do_insn_bits(struct comedi_device *dev,
 static void pc263_report_attach(struct comedi_device *dev)
 {
const struct pc263_board *thisboard = comedi_board(dev);
-   struct pc263_private *devpriv = dev-private;
+   struct pci_dev *pcidev = comedi_to_pci_dev(dev);
char tmpbuf[40];
 
if (IS_ENABLED(CONFIG_COMEDI_AMPLC_PC263_ISA) 
@@ -202,7 +193,7 @@ static void pc263_report_attach(struct comedi_device *dev)
else if (IS_ENABLED(CONFIG_COMEDI_AMPLC_PC263_PCI) 
 thisboard-bustype == pci_bustype)
snprintf(tmpbuf, sizeof(tmpbuf), (pci %s) ,
-pci_name(devpriv-pci_dev));
+pci_name(pcidev));
else
tmpbuf[0] = '\0';
dev_info(dev-class_dev, %s %sattached\n, dev-board_name, tmpbuf);
@@ -239,11 +230,11 @@ static int pc263_common_attach(struct comedi_device *dev, 
unsigned long iobase)
 static int pc263_pci_common_attach(struct comedi_device *dev,
   struct pci_dev *pci_dev)
 {
-   struct pc263_private *devpriv = dev-private;
unsigned long iobase;
int ret;
 
-   devpriv-pci_dev = pci_dev;
+   comedi_set_hw_dev(dev, pci_dev-dev);
+
ret = comedi_pci_enable(pci_dev, PC263_DRIVER_NAME);
if (ret  0) {
dev_err(dev-class_dev,
@@ -279,11 +270,6 @@ static int pc263_attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
   thisboard-bustype == pci_bustype) {
struct pci_dev *pci_dev;
 
-   ret = alloc_private(dev, sizeof(struct pc263_private));
-   if (ret  0) {
-   dev_err(dev-class_dev, error! out of memory!\n);
-   return ret;
-   }
pci_dev = pc263_find_pci_dev(dev, it);
if (!pci_dev)
return -EIO;
@@ -302,18 +288,11 @@ static int pc263_attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
 static int __devinit pc263_attach_pci(struct comedi_device *dev,
  struct pci_dev *pci_dev)
 {
-   int ret;
-
if (!IS_ENABLED(CONFIG_COMEDI_AMPLC_PC263_PCI))
return -EINVAL;
 
dev_info(dev-class_dev, PC263_DRIVER_NAME : attach pci %s\n,
 pci_name(pci_dev));
-   ret = alloc_private(dev, sizeof(struct pc263_private));
-   if (ret  0) {
-   dev_err(dev-class_dev, error! out of memory!\n);
-   return ret;
-   }
dev-board_ptr = pc263_find_pci_board(pci_dev);
if (dev-board_ptr == NULL) {
dev_err(dev-class_dev, BUG! cannot determine board type!\n);
@@ -324,14 +303,13 @@ static int __devinit pc263_attach_pci(struct 
comedi_device *dev,
 
 static void pc263_detach(struct comedi_device *dev)
 {
-   struct pc263_private *devpriv = dev-private;
+   struct pci_dev *pcidev = comedi_to_pci_dev(dev);
 
-   if (IS_ENABLED(CONFIG_COMEDI_AMPLC_PC263_PCI)  devpriv 
-   devpriv-pci_dev) {
+   if (pcidev) {
if (dev-iobase)
-   comedi_pci_disable(devpriv-pci_dev);
-   pci_dev_put(devpriv-pci_dev);
-   } else if (IS_ENABLED(CONFIG_COMEDI_AMPLC_PC263_ISA)) {
+   comedi_pci_disable(pcidev);
+   pci_dev_put(pcidev);
+   } else {
if (dev-iobase

[PATCH 35/90] staging: comedi: amplc_pci224: cleanup find pci device code

2012-07-18 Thread H Hartley Sweeten
For aesthetic reasons, rename the function and pass the
comedi_devconfig struct instead of pre-parsing out the bus/slot
information.

Use for_each_pci_dev() instead of open-coding the loop using
pci_get_device().

Consolidate the dev_err messages when a pci device is not found.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/amplc_pci224.c | 43 ++-
 1 file changed, 16 insertions(+), 27 deletions(-)

diff --git a/drivers/staging/comedi/drivers/amplc_pci224.c 
b/drivers/staging/comedi/drivers/amplc_pci224.c
index b87e10d..d489367 100644
--- a/drivers/staging/comedi/drivers/amplc_pci224.c
+++ b/drivers/staging/comedi/drivers/amplc_pci224.c
@@ -1256,50 +1256,42 @@ static const struct pci224_board
  * This function looks for a PCI device matching the requested board name,
  * bus and slot.
  */
-static struct pci_dev *
-pci224_find_pci(struct comedi_device *dev, int bus, int slot)
+static struct pci_dev *pci224_find_pci_dev(struct comedi_device *dev,
+  struct comedi_devconfig *it)
 {
const struct pci224_board *thisboard = comedi_board(dev);
struct pci_dev *pci_dev = NULL;
+   int bus = it-options[0];
+   int slot = it-options[1];
 
-   /* Look for matching PCI device. */
-   for (pci_dev = pci_get_device(PCI_VENDOR_ID_AMPLICON, PCI_ANY_ID, NULL);
-pci_dev != NULL;
-pci_dev = pci_get_device(PCI_VENDOR_ID_AMPLICON, PCI_ANY_ID,
- pci_dev)) {
-   /* If bus/slot specified, check them. */
+   for_each_pci_dev(pci_dev) {
if (bus || slot) {
-   if (bus != pci_dev-bus-number
-   || slot != PCI_SLOT(pci_dev-devfn))
+   if (bus != pci_dev-bus-number ||
+   slot != PCI_SLOT(pci_dev-devfn))
continue;
}
+   if (pci_dev-vendor != PCI_VENDOR_ID_AMPLICON)
+   continue;
+
if (thisboard-model == any_model) {
/* Match any supported model. */
const struct pci224_board *board_ptr;
+
board_ptr = pci224_find_pci_board(pci_dev);
if (board_ptr == NULL)
continue;
/* Change board_ptr to matched board. */
dev-board_ptr = board_ptr;
-   thisboard = comedi_board(dev);
} else {
/* Match specific model name. */
if (thisboard-devid != pci_dev-device)
continue;
}
-
-   /* Found a match. */
return pci_dev;
}
-   /* No match found. */
-   if (bus || slot) {
-   dev_err(dev-class_dev,
-   error! no %s found at pci %02x:%02x!\n,
-   thisboard-name, bus, slot);
-   } else {
-   dev_err(dev-class_dev, error! no %s found!\n,
-   thisboard-name);
-   }
+   dev_err(dev-class_dev,
+   No supported board found! (req. bus %d, slot %d)\n,
+   bus, slot);
return NULL;
 }
 
@@ -1474,21 +1466,18 @@ static int pci224_attach_common(struct comedi_device 
*dev,
 static int pci224_attach(struct comedi_device *dev, struct comedi_devconfig 
*it)
 {
struct pci_dev *pci_dev;
-   int bus, slot;
int ret;
 
dev_info(dev-class_dev, DRIVER_NAME : attach\n);
 
-   bus = it-options[0];
-   slot = it-options[1];
ret = alloc_private(dev, sizeof(struct pci224_private));
if (ret  0) {
dev_err(dev-class_dev, error! out of memory!\n);
return ret;
}
 
-   pci_dev = pci224_find_pci(dev, bus, slot);
-   if (pci_dev == NULL)
+   pci_dev = pci224_find_pci_dev(dev, it);
+   if (!pci_dev)
return -EIO;
 
return pci224_attach_common(dev, pci_dev, it-options);
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 37/90] staging: comedi: amplc_pci230: cleanup find pci device code

2012-07-18 Thread H Hartley Sweeten
For aesthetic reasons, rename the function and pass the
comedi_devconfig struct instead of pre-parsing out the bus/slot
information.

Consolidate the dev_err messages when a pci device is not found.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/amplc_pci230.c | 22 --
 1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/drivers/staging/comedi/drivers/amplc_pci230.c 
b/drivers/staging/comedi/drivers/amplc_pci230.c
index 3d7f2cd..0b09934 100644
--- a/drivers/staging/comedi/drivers/amplc_pci230.c
+++ b/drivers/staging/comedi/drivers/amplc_pci230.c
@@ -2683,11 +2683,13 @@ static const struct pci230_board 
*pci230_find_pci_board(struct pci_dev *pci_dev)
 }
 
 /* Look for PCI device matching requested board name, bus and slot. */
-static struct pci_dev *pci230_find_pci(struct comedi_device *dev,
-  int bus, int slot)
+static struct pci_dev *pci230_find_pci_dev(struct comedi_device *dev,
+  struct comedi_devconfig *it)
 {
const struct pci230_board *thisboard = comedi_board(dev);
struct pci_dev *pci_dev = NULL;
+   int bus = it-options[0];
+   int slot = it-options[1];
 
for_each_pci_dev(pci_dev) {
/* Check vendor ID (same for all supported PCI boards). */
@@ -2707,23 +2709,16 @@ static struct pci_dev *pci230_find_pci(struct 
comedi_device *dev,
continue;
/* Replace wildcard board_ptr. */
dev-board_ptr = foundboard;
-   thisboard = comedi_board(dev);
} else {
/* Need to match a specific board. */
if (!pci230_match_pci_board(thisboard, pci_dev))
continue;
}
-   /* Found a matching PCI device. */
return pci_dev;
}
-   /* No matching PCI device found. */
-   if (bus || slot)
-   dev_err(dev-class_dev,
-   error! no %s found at pci %02x:%02x\n,
-   thisboard-name, bus, slot);
-   else
-   dev_err(dev-class_dev,
-   error! no %s found\n, thisboard-name);
+   dev_err(dev-class_dev,
+   No supported board found! (req. bus %d, slot %d)\n,
+   bus, slot);
return NULL;
 }
 
@@ -2909,8 +2904,7 @@ static int pci230_attach(struct comedi_device *dev, 
struct comedi_devconfig *it)
rc = pci230_alloc_private(dev); /* sets dev-private */
if (rc)
return rc;
-   /* Find card. */
-   pci_dev = pci230_find_pci(dev, it-options[0], it-options[1]);
+   pci_dev = pci230_find_pci_dev(dev, it);
if (!pci_dev)
return -EIO;
return pci230_attach_common(dev, pci_dev);
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 38/90] staging: comedi: amplc_pci230: store the pci_dev in the comedi_device

2012-07-18 Thread H Hartley Sweeten
Use the hw_dev pointer in the comedi_device struct to hold the
pci_dev instead of carrying it in the private data.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/amplc_pci230.c | 25 +++--
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/drivers/staging/comedi/drivers/amplc_pci230.c 
b/drivers/staging/comedi/drivers/amplc_pci230.c
index 0b09934..1b67d0c 100644
--- a/drivers/staging/comedi/drivers/amplc_pci230.c
+++ b/drivers/staging/comedi/drivers/amplc_pci230.c
@@ -500,7 +500,6 @@ static const struct pci230_board pci230_boards[] = {
several hardware drivers keep similar information in this structure,
feel free to suggest moving the variable to the struct comedi_device 
struct.  */
 struct pci230_private {
-   struct pci_dev *pci_dev;
spinlock_t isr_spinlock;/* Interrupt spin lock */
spinlock_t res_spinlock;/* Shared resources spin lock */
spinlock_t ai_stop_spinlock;/* Spin lock for stopping AI command */
@@ -2752,7 +2751,8 @@ static int pci230_attach_common(struct comedi_device *dev,
/* PCI230's I/O spaces 1 and 2 respectively. */
int irq_hdl, rc;
 
-   devpriv-pci_dev = pci_dev;
+   comedi_set_hw_dev(dev, pci_dev-dev);
+
dev-board_name = thisboard-name;
/* Enable PCI device and reserve I/O spaces. */
if (comedi_pci_enable(pci_dev, amplc_pci230)  0) {
@@ -2823,16 +2823,15 @@ static int pci230_attach_common(struct comedi_device 
*dev,
outw(devpriv-adccon | PCI230_ADC_FIFO_RESET,
 dev-iobase + PCI230_ADCCON);
/* Register the interrupt handler. */
-   irq_hdl = request_irq(devpriv-pci_dev-irq, pci230_interrupt,
+   irq_hdl = request_irq(pci_dev-irq, pci230_interrupt,
  IRQF_SHARED, amplc_pci230, dev);
if (irq_hdl  0) {
dev_warn(dev-class_dev,
 unable to register irq %u, commands will not be 
available\n,
-devpriv-pci_dev-irq);
+pci_dev-irq);
} else {
-   dev-irq = devpriv-pci_dev-irq;
-   dev_dbg(dev-class_dev, registered irq %u\n,
-   devpriv-pci_dev-irq);
+   dev-irq = pci_dev-irq;
+   dev_dbg(dev-class_dev, registered irq %u\n, pci_dev-irq);
}
 
rc = comedi_alloc_subdevices(dev, 3);
@@ -2932,18 +2931,16 @@ static int __devinit pci230_attach_pci(struct 
comedi_device *dev,
 static void pci230_detach(struct comedi_device *dev)
 {
const struct pci230_board *thisboard = comedi_board(dev);
-   struct pci230_private *devpriv = dev-private;
+   struct pci_dev *pcidev = comedi_to_pci_dev(dev);
 
if (dev-subdevices  thisboard-have_dio)
subdev_8255_cleanup(dev, dev-subdevices + 2);
if (dev-irq)
free_irq(dev-irq, dev);
-   if (devpriv) {
-   if (devpriv-pci_dev) {
-   if (dev-iobase)
-   comedi_pci_disable(devpriv-pci_dev);
-   pci_dev_put(devpriv-pci_dev);
-   }
+   if (pcidev) {
+   if (dev-iobase)
+   comedi_pci_disable(pcidev);
+   pci_dev_put(pcidev);
}
 }
 
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 39/90] staging: comedi: cb_pcidas64: factor out the find pci device code

2012-07-18 Thread H Hartley Sweeten
Factor the find pci device code out of the attach function.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/cb_pcidas64.c | 57 ++--
 1 file changed, 29 insertions(+), 28 deletions(-)

diff --git a/drivers/staging/comedi/drivers/cb_pcidas64.c 
b/drivers/staging/comedi/drivers/cb_pcidas64.c
index 11ce3fd..704f5ea 100644
--- a/drivers/staging/comedi/drivers/cb_pcidas64.c
+++ b/drivers/staging/comedi/drivers/cb_pcidas64.c
@@ -1650,26 +1650,11 @@ static inline void warn_external_queue(struct 
comedi_device *dev)
 Use internal AI channel queue (channels must be 
consecutive and use same range/aref));
 }
 
-/*
- * Attach is called by the Comedi core to configure the driver
- * for a particular board.
- */
-static int attach(struct comedi_device *dev, struct comedi_devconfig *it)
+static struct pci_dev *cb_pcidas64_find_pci_dev(struct comedi_device *dev,
+   struct comedi_devconfig *it)
 {
struct pci_dev *pcidev = NULL;
int index;
-   uint32_t local_range, local_decode;
-   int retval;
-
-/*
- * Allocate the private structure area.
- */
-   if (alloc_private(dev, sizeof(struct pcidas64_private))  0)
-   return -ENOMEM;
-
-/*
- * Probe the device to determine what device in the series it is.
- */
 
for_each_pci_dev(pcidev) {
/*  is it not a computer boards card? */
@@ -1687,22 +1672,38 @@ static int attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
continue;
}
}
-   priv(dev)-hw_dev = pcidev;
dev-board_ptr = pcidas64_boards + index;
-   break;
+   dev_dbg(dev-class_dev, Found %s on bus %i, slot %i\n,
+   board(dev)-name,
+   pcidev-bus-number, PCI_SLOT(pcidev-devfn));
+   return pcidev;
}
-   if (dev-board_ptr)
-   break;
}
 
-   if (dev-board_ptr == NULL) {
-   printk
-   (No supported ComputerBoards/MeasurementComputing card 
found\n);
-   return -EIO;
-   }
+   printk(No supported ComputerBoards/MeasurementComputing card found\n);
+   return NULL;
+}
+
+/*
+ * Attach is called by the Comedi core to configure the driver
+ * for a particular board.
+ */
+static int attach(struct comedi_device *dev, struct comedi_devconfig *it)
+{
+   struct pci_dev *pcidev;
+   uint32_t local_range, local_decode;
+   int retval;
 
-   dev_dbg(dev-class_dev, Found %s on bus %i, slot %i\n,
-   board(dev)-name, pcidev-bus-number, PCI_SLOT(pcidev-devfn));
+/*
+ * Allocate the private structure area.
+ */
+   if (alloc_private(dev, sizeof(struct pcidas64_private))  0)
+   return -ENOMEM;
+
+   pcidev = cb_pcidas64_find_pci_dev(dev, it);
+   if (!pcidev)
+   return -EIO;
+   priv(dev)-hw_dev = pcidev;
 
if (comedi_pci_enable(pcidev, dev-driver-driver_name)) {
dev_warn(dev-class_dev,
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 40/90] staging: comedi: cb_pcidas64: cleanup find pci device code

2012-07-18 Thread H Hartley Sweeten
Add a couple local variables to make the tests more concise.
Reorder the tests to make the for() loop checking for a
matching boardtype quicker.

Drop the dev_dbg for a match. It's just add noise.
Reword the dev_err when no match is found.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/cb_pcidas64.c | 34 
 1 file changed, 15 insertions(+), 19 deletions(-)

diff --git a/drivers/staging/comedi/drivers/cb_pcidas64.c 
b/drivers/staging/comedi/drivers/cb_pcidas64.c
index 704f5ea..d1b0327 100644
--- a/drivers/staging/comedi/drivers/cb_pcidas64.c
+++ b/drivers/staging/comedi/drivers/cb_pcidas64.c
@@ -1654,33 +1654,29 @@ static struct pci_dev *cb_pcidas64_find_pci_dev(struct 
comedi_device *dev,
struct comedi_devconfig *it)
 {
struct pci_dev *pcidev = NULL;
-   int index;
+   int bus = it-options[0];
+   int slot = it-options[1];
+   int i;
 
for_each_pci_dev(pcidev) {
-   /*  is it not a computer boards card? */
+   if (bus || slot) {
+   if (bus != pcidev-bus-number ||
+   slot != PCI_SLOT(pcidev-devfn))
+   continue;
+   }
if (pcidev-vendor != PCI_VENDOR_ID_COMPUTERBOARDS)
continue;
-   /*  loop through cards supported by this driver */
-   for (index = 0; index  ARRAY_SIZE(pcidas64_boards); index++) {
-   if (pcidas64_boards[index].device_id != pcidev-device)
+
+   for (i = 0; i  ARRAY_SIZE(pcidas64_boards); i++) {
+   if (pcidas64_boards[i].device_id != pcidev-device)
continue;
-   /*  was a particular bus/slot requested? */
-   if (it-options[0] || it-options[1]) {
-   /*  are we on the wrong bus/slot? */
-   if (pcidev-bus-number != it-options[0] ||
-   PCI_SLOT(pcidev-devfn) != it-options[1]) {
-   continue;
-   }
-   }
-   dev-board_ptr = pcidas64_boards + index;
-   dev_dbg(dev-class_dev, Found %s on bus %i, slot %i\n,
-   board(dev)-name,
-   pcidev-bus-number, PCI_SLOT(pcidev-devfn));
+   dev-board_ptr = pcidas64_boards + i;
return pcidev;
}
}
-
-   printk(No supported ComputerBoards/MeasurementComputing card found\n);
+   dev_err(dev-class_dev,
+   No supported board found! (req. bus %d, slot %d)\n,
+   bus, slot);
return NULL;
 }
 
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 41/90] staging: comedi: cb_pcidas64: store the pci_dev in the comedi_device

2012-07-18 Thread H Hartley Sweeten
Use the hw_dev pointer in the comedi_device struct to hold the
pci_dev instead of carrying it in the private data.

Save the pci bar in dev-iobase so the detach is consistent with
the other comedi pci drivers.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/cb_pcidas64.c | 39 +++-
 1 file changed, 21 insertions(+), 18 deletions(-)

diff --git a/drivers/staging/comedi/drivers/cb_pcidas64.c 
b/drivers/staging/comedi/drivers/cb_pcidas64.c
index d1b0327..65cbaab 100644
--- a/drivers/staging/comedi/drivers/cb_pcidas64.c
+++ b/drivers/staging/comedi/drivers/cb_pcidas64.c
@@ -1047,8 +1047,6 @@ struct ext_clock_info {
 
 /* this structure is for data unique to this hardware driver. */
 struct pcidas64_private {
-
-   struct pci_dev *hw_dev; /*  pointer to board's pci_dev struct */
/*  base addresses (physical) */
resource_size_t plx9080_phys_iobase;
resource_size_t main_phys_iobase;
@@ -1553,12 +1551,13 @@ static void init_stc_registers(struct comedi_device 
*dev)
 
 static int alloc_and_init_dma_members(struct comedi_device *dev)
 {
+   struct pci_dev *pcidev = comedi_to_pci_dev(dev);
int i;
 
/*  alocate pci dma buffers */
for (i = 0; i  ai_dma_ring_count(board(dev)); i++) {
priv(dev)-ai_buffer[i] =
-   pci_alloc_consistent(priv(dev)-hw_dev, DMA_BUFFER_SIZE,
+   pci_alloc_consistent(pcidev, DMA_BUFFER_SIZE,
 priv(dev)-ai_buffer_bus_addr[i]);
if (priv(dev)-ai_buffer[i] == NULL)
return -ENOMEM;
@@ -1567,7 +1566,7 @@ static int alloc_and_init_dma_members(struct 
comedi_device *dev)
for (i = 0; i  AO_DMA_RING_COUNT; i++) {
if (ao_cmd_is_supported(board(dev))) {
priv(dev)-ao_buffer[i] =
-   pci_alloc_consistent(priv(dev)-hw_dev,
+   pci_alloc_consistent(pcidev,
 DMA_BUFFER_SIZE,
 priv(dev)-
 ao_buffer_bus_addr[i]);
@@ -1578,7 +1577,7 @@ static int alloc_and_init_dma_members(struct 
comedi_device *dev)
}
/*  allocate dma descriptors */
priv(dev)-ai_dma_desc =
-   pci_alloc_consistent(priv(dev)-hw_dev,
+   pci_alloc_consistent(pcidev,
 sizeof(struct plx_dma_desc) *
 ai_dma_ring_count(board(dev)),
 priv(dev)-ai_dma_desc_bus_addr);
@@ -1589,7 +1588,7 @@ static int alloc_and_init_dma_members(struct 
comedi_device *dev)
priv(dev)-ai_dma_desc_bus_addr);
if (ao_cmd_is_supported(board(dev))) {
priv(dev)-ao_dma_desc =
-   pci_alloc_consistent(priv(dev)-hw_dev,
+   pci_alloc_consistent(pcidev,
 sizeof(struct plx_dma_desc) *
 AO_DMA_RING_COUNT,
 priv(dev)-ao_dma_desc_bus_addr);
@@ -1699,7 +1698,7 @@ static int attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
pcidev = cb_pcidas64_find_pci_dev(dev, it);
if (!pcidev)
return -EIO;
-   priv(dev)-hw_dev = pcidev;
+   comedi_set_hw_dev(dev, pcidev-dev);
 
if (comedi_pci_enable(pcidev, dev-driver-driver_name)) {
dev_warn(dev-class_dev,
@@ -1711,10 +1710,11 @@ static int attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
/* Initialize dev-board_name */
dev-board_name = board(dev)-name;
 
+   dev-iobase = pci_resource_start(pcidev, MAIN_BADDRINDEX);
+
priv(dev)-plx9080_phys_iobase =
pci_resource_start(pcidev, PLX9080_BADDRINDEX);
-   priv(dev)-main_phys_iobase =
-   pci_resource_start(pcidev, MAIN_BADDRINDEX);
+   priv(dev)-main_phys_iobase = dev-iobase;
priv(dev)-dio_counter_phys_iobase =
pci_resource_start(pcidev, DIO_COUNTER_BADDRINDEX);
 
@@ -1791,12 +1791,13 @@ static int attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
 
 static void detach(struct comedi_device *dev)
 {
+   struct pci_dev *pcidev = comedi_to_pci_dev(dev);
unsigned int i;
 
if (dev-irq)
free_irq(dev-irq, dev);
if (priv(dev)) {
-   if (priv(dev)-hw_dev) {
+   if (pcidev) {
if (priv(dev)-plx9080_iobase) {
disable_plx_interrupts(dev);
iounmap(priv(dev)-plx9080_iobase);
@@ -1808,7 +1809,7 @@ static void detach(struct comedi_device *dev)
/*  free pci dma buffers

[PATCH 42/90] staging: comedi: cb_pcidda: factor out the find pci device code

2012-07-18 Thread H Hartley Sweeten
Factor the find pci device code out of the attach function.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/cb_pcidda.c | 60 --
 1 file changed, 32 insertions(+), 28 deletions(-)

diff --git a/drivers/staging/comedi/drivers/cb_pcidda.c 
b/drivers/staging/comedi/drivers/cb_pcidda.c
index f5a7957..d3d8326 100644
--- a/drivers/staging/comedi/drivers/cb_pcidda.c
+++ b/drivers/staging/comedi/drivers/cb_pcidda.c
@@ -255,27 +255,11 @@ static unsigned int cb_pcidda_read_eeprom(struct 
comedi_device *dev,
 static void cb_pcidda_calibrate(struct comedi_device *dev, unsigned int 
channel,
unsigned int range);
 
-/*
- * Attach is called by the Comedi core to configure the driver
- * for a particular board.
- */
-static int cb_pcidda_attach(struct comedi_device *dev,
-   struct comedi_devconfig *it)
+static struct pci_dev *cb_pcidda_find_pci_dev(struct comedi_device *dev,
+ struct comedi_devconfig *it)
 {
-   struct comedi_subdevice *s;
struct pci_dev *pcidev = NULL;
int index;
-   int ret;
-
-/*
- * Allocate the private structure area.
- */
-   if (alloc_private(dev, sizeof(struct cb_pcidda_private))  0)
-   return -ENOMEM;
-
-/*
- * Probe the device to determine what device in the series it is.
- */
 
for_each_pci_dev(pcidev) {
if (pcidev-vendor == PCI_VENDOR_ID_CB) {
@@ -288,22 +272,42 @@ static int cb_pcidda_attach(struct comedi_device *dev,
for (index = 0; index  ARRAY_SIZE(cb_pcidda_boards); 
index++) {
if (cb_pcidda_boards[index].device_id ==
pcidev-device) {
-   goto found;
+   dev-board_ptr = cb_pcidda_boards + 
index;
+   dev_dbg(dev-class_dev,
+   Found %s at requested 
position\n,
+   thisboard-name);
+   return pcidev;
}
}
}
}
-   if (!pcidev) {
-   dev_err(dev-class_dev,
-   Not a ComputerBoards/MeasurementComputing card on 
requested position\n);
+   dev_err(dev-class_dev,
+   Not a ComputerBoards/MeasurementComputing card on requested 
position\n);
+   return NULL;
+}
+
+/*
+ * Attach is called by the Comedi core to configure the driver
+ * for a particular board.
+ */
+static int cb_pcidda_attach(struct comedi_device *dev,
+   struct comedi_devconfig *it)
+{
+   struct pci_dev *pcidev;
+   struct comedi_subdevice *s;
+   int index;
+   int ret;
+
+/*
+ * Allocate the private structure area.
+ */
+   if (alloc_private(dev, sizeof(struct cb_pcidda_private))  0)
+   return -ENOMEM;
+
+   pcidev = cb_pcidda_find_pci_dev(dev, it);
+   if (!pcidev)
return -EIO;
-   }
-found:
devpriv-pci_dev = pcidev;
-   dev-board_ptr = cb_pcidda_boards + index;
-   /*  thisboard macro can be used from here. */
-   dev_dbg(dev-class_dev, Found %s at requested position\n,
-   thisboard-name);
 
/*
 * Enable PCI device and request regions.
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 43/90] staging: comedi: cb_pcidda: cleanup find pci device code

2012-07-18 Thread H Hartley Sweeten
Add a couple local variables to make the tests more concise.
Reorder the tests to make the for() loop checking for a
matching boardtype quicker.

Drop the dev_dbg for a match. It's just add noise.
Reword the dev_err when no match is found.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/cb_pcidda.c | 37 +++---
 1 file changed, 18 insertions(+), 19 deletions(-)

diff --git a/drivers/staging/comedi/drivers/cb_pcidda.c 
b/drivers/staging/comedi/drivers/cb_pcidda.c
index d3d8326..3567f4a 100644
--- a/drivers/staging/comedi/drivers/cb_pcidda.c
+++ b/drivers/staging/comedi/drivers/cb_pcidda.c
@@ -259,30 +259,29 @@ static struct pci_dev *cb_pcidda_find_pci_dev(struct 
comedi_device *dev,
  struct comedi_devconfig *it)
 {
struct pci_dev *pcidev = NULL;
-   int index;
+   int bus = it-options[0];
+   int slot = it-options[1];
+   int i;
 
for_each_pci_dev(pcidev) {
-   if (pcidev-vendor == PCI_VENDOR_ID_CB) {
-   if (it-options[0] || it-options[1]) {
-   if (pcidev-bus-number != it-options[0] ||
-   PCI_SLOT(pcidev-devfn) != it-options[1]) {
-   continue;
-   }
-   }
-   for (index = 0; index  ARRAY_SIZE(cb_pcidda_boards); 
index++) {
-   if (cb_pcidda_boards[index].device_id ==
-   pcidev-device) {
-   dev-board_ptr = cb_pcidda_boards + 
index;
-   dev_dbg(dev-class_dev,
-   Found %s at requested 
position\n,
-   thisboard-name);
-   return pcidev;
-   }
-   }
+   if (bus || slot) {
+   if (bus != pcidev-bus-number ||
+   slot != PCI_SLOT(pcidev-devfn))
+   continue;
+   }
+   if (pcidev-vendor != PCI_VENDOR_ID_CB)
+   continue;
+
+   for (i = 0; i  ARRAY_SIZE(cb_pcidda_boards); i++) {
+   if (cb_pcidda_boards[i].device_id != pcidev-device)
+   continue;
+   dev-board_ptr = cb_pcidda_boards + i;
+   return pcidev;
}
}
dev_err(dev-class_dev,
-   Not a ComputerBoards/MeasurementComputing card on requested 
position\n);
+   No supported board found! (req. bus %d, slot %d)\n,
+   bus, slot);
return NULL;
 }
 
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 44/90] staging: comedi: cb_pcidda: store the pci_dev in the comedi_device

2012-07-18 Thread H Hartley Sweeten
Use the hw_dev pointer in the comedi_device struct to hold the
pci_dev instead of carrying it in the private data.

Save the pci bar in dev-iobase so the detach is consistent with
the other comedi pci drivers.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/cb_pcidda.c | 23 ++-
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/comedi/drivers/cb_pcidda.c 
b/drivers/staging/comedi/drivers/cb_pcidda.c
index 3567f4a..12660a3 100644
--- a/drivers/staging/comedi/drivers/cb_pcidda.c
+++ b/drivers/staging/comedi/drivers/cb_pcidda.c
@@ -216,9 +216,6 @@ static const struct cb_pcidda_board cb_pcidda_boards[] = {
 struct cb_pcidda_private {
int data;
 
-   /* would be useful for a PCI device */
-   struct pci_dev *pci_dev;
-
unsigned long digitalio;
unsigned long dac;
 
@@ -306,7 +303,7 @@ static int cb_pcidda_attach(struct comedi_device *dev,
pcidev = cb_pcidda_find_pci_dev(dev, it);
if (!pcidev)
return -EIO;
-   devpriv-pci_dev = pcidev;
+   comedi_set_hw_dev(dev, pcidev-dev);
 
/*
 * Enable PCI device and request regions.
@@ -320,9 +317,9 @@ static int cb_pcidda_attach(struct comedi_device *dev,
 /*
  * Allocate the I/O ports.
  */
-   devpriv-digitalio =
-   pci_resource_start(devpriv-pci_dev, DIGITALIO_BADRINDEX);
-   devpriv-dac = pci_resource_start(devpriv-pci_dev, DAC_BADRINDEX);
+   devpriv-digitalio = pci_resource_start(pcidev, DIGITALIO_BADRINDEX);
+   devpriv-dac = pci_resource_start(pcidev, DAC_BADRINDEX);
+   dev-iobase = devpriv-dac;
 
 /*
  * Warn about the status of the driver.
@@ -377,12 +374,12 @@ static int cb_pcidda_attach(struct comedi_device *dev,
 
 static void cb_pcidda_detach(struct comedi_device *dev)
 {
-   if (devpriv) {
-   if (devpriv-pci_dev) {
-   if (devpriv-dac)
-   comedi_pci_disable(devpriv-pci_dev);
-   pci_dev_put(devpriv-pci_dev);
-   }
+   struct pci_dev *pcidev = comedi_to_pci_dev(dev);
+
+   if (pcidev) {
+   if (dev-iobase)
+   comedi_pci_disable(pcidev);
+   pci_dev_put(pcidev);
}
if (dev-subdevices) {
subdev_8255_cleanup(dev, dev-subdevices + 1);
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 45/90] staging: comedi: cb_pcidio: store the iobase in the comedi_device

2012-07-18 Thread H Hartley Sweeten
Save the pci bar in dev-iobase instead of carrying it in the
private data.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/cb_pcidio.c | 11 ---
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/comedi/drivers/cb_pcidio.c 
b/drivers/staging/comedi/drivers/cb_pcidio.c
index 11c7502..f30f6da 100644
--- a/drivers/staging/comedi/drivers/cb_pcidio.c
+++ b/drivers/staging/comedi/drivers/cb_pcidio.c
@@ -99,7 +99,6 @@ struct pcidio_private {
/* used for DO readback, currently unused */
unsigned int do_readback[4];/* up to 4 unsigned int suffice to hold 
96 bits for PCI-DIO96 */
 
-   unsigned long dio_reg_base; /*  address of port A of the first 8255 
chip on board */
 };
 
 /*
@@ -165,9 +164,7 @@ static int pcidio_attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
if (comedi_pci_enable(pcidev, thisboard-name))
return -EIO;
 
-   devpriv-dio_reg_base
-   =
-   pci_resource_start(pcidev, thisboard-dioregs_badrindex);
+   dev-iobase = pci_resource_start(pcidev, thisboard-dioregs_badrindex);
 
ret = comedi_alloc_subdevices(dev, thisboard-n_8255);
if (ret)
@@ -175,9 +172,9 @@ static int pcidio_attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
 
for (i = 0; i  thisboard-n_8255; i++) {
subdev_8255_init(dev, dev-subdevices + i,
-NULL, devpriv-dio_reg_base + i * 4);
+NULL, dev-iobase + i * 4);
dev_dbg(dev-class_dev, subdev %d: base = 0x%lx\n, i,
-   devpriv-dio_reg_base + i * 4);
+   dev-iobase + i * 4);
}
 
return 1;
@@ -188,7 +185,7 @@ static void pcidio_detach(struct comedi_device *dev)
struct pci_dev *pcidev = comedi_to_pci_dev(dev);
 
if (pcidev) {
-   if (devpriv-dio_reg_base)
+   if (dev-iobase)
comedi_pci_disable(pcidev);
pci_dev_put(pcidev);
}
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 46/90] staging: comedi: cb_pcidio: remove the private data

2012-07-18 Thread H Hartley Sweeten
The private data is no longer needed by this driver. Remove the
struct, devpriv macro, and the allocation.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/cb_pcidio.c | 24 
 1 file changed, 24 deletions(-)

diff --git a/drivers/staging/comedi/drivers/cb_pcidio.c 
b/drivers/staging/comedi/drivers/cb_pcidio.c
index f30f6da..e370d0d 100644
--- a/drivers/staging/comedi/drivers/cb_pcidio.c
+++ b/drivers/staging/comedi/drivers/cb_pcidio.c
@@ -90,23 +90,6 @@ static const struct pcidio_board pcidio_boards[] = {
  */
 #define thisboard ((const struct pcidio_board *)dev-board_ptr)
 
-/* this structure is for data unique to this hardware driver.  If
-   several hardware drivers keep similar information in this structure,
-   feel free to suggest moving the variable to the struct comedi_device 
struct.  */
-struct pcidio_private {
-   int data;   /*  currently unused */
-
-   /* used for DO readback, currently unused */
-   unsigned int do_readback[4];/* up to 4 unsigned int suffice to hold 
96 bits for PCI-DIO96 */
-
-};
-
-/*
- * most drivers define the following macro to make it easy to
- * access the private structure.
- */
-#define devpriv ((struct pcidio_private *)dev-private)
-
 static struct pci_dev *pcidio_find_pci_dev(struct comedi_device *dev,
   struct comedi_devconfig *it)
 {
@@ -143,13 +126,6 @@ static int pcidio_attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
int i;
int ret;
 
-/*
- * Allocate the private structure area.  alloc_private() is a
- * convenient macro defined in comedidev.h.
- */
-   if (alloc_private(dev, sizeof(struct pcidio_private))  0)
-   return -ENOMEM;
-
pcidev = pcidio_find_pci_dev(dev, it);
if (!pcidev)
return -EIO;
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 47/90] staging: comedi: cb_pcimdas: factor out the find pci device code

2012-07-18 Thread H Hartley Sweeten
Factor the find pci device code out of the attach function.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/cb_pcimdas.c | 61 +++--
 1 file changed, 32 insertions(+), 29 deletions(-)

diff --git a/drivers/staging/comedi/drivers/cb_pcimdas.c 
b/drivers/staging/comedi/drivers/cb_pcimdas.c
index 2977f2d..8999a72 100644
--- a/drivers/staging/comedi/drivers/cb_pcimdas.c
+++ b/drivers/staging/comedi/drivers/cb_pcimdas.c
@@ -175,30 +175,11 @@ static int cb_pcimdas_ao_rinsn(struct comedi_device *dev,
   struct comedi_subdevice *s,
   struct comedi_insn *insn, unsigned int *data);
 
-/*
- * Attach is called by the Comedi core to configure the driver
- * for a particular board.  If you specified a board_name array
- * in the driver structure, dev-board_ptr contains that
- * address.
- */
-static int cb_pcimdas_attach(struct comedi_device *dev,
-struct comedi_devconfig *it)
+static struct pci_dev *cb_pcimdas_find_pci_dev(struct comedi_device *dev,
+  struct comedi_devconfig *it)
 {
-   struct comedi_subdevice *s;
struct pci_dev *pcidev = NULL;
int index;
-   int ret;
-   /* int i; */
-
-/*
- * Allocate the private structure area.
- */
-   if (alloc_private(dev, sizeof(struct cb_pcimdas_private))  0)
-   return -ENOMEM;
-
-/*
- * Probe the device to determine what device in the series it is.
- */
 
for_each_pci_dev(pcidev) {
/*  is it not a computer boards card? */
@@ -217,21 +198,43 @@ static int cb_pcimdas_attach(struct comedi_device *dev,
continue;
}
}
-   devpriv-pci_dev = pcidev;
dev-board_ptr = cb_pcimdas_boards + index;
-   goto found;
+   dev_dbg(dev-class_dev,
+   Found %s on bus %i, slot %i\n,
+   cb_pcimdas_boards[index].name,
+   pcidev-bus-number,
+   PCI_SLOT(pcidev-devfn));
+   return pcidev;
}
}
-
dev_err(dev-class_dev,
No supported ComputerBoards/MeasurementComputing card found on 
requested position\n);
-   return -EIO;
+   return NULL;
+}
 
-found:
+/*
+ * Attach is called by the Comedi core to configure the driver
+ * for a particular board.  If you specified a board_name array
+ * in the driver structure, dev-board_ptr contains that
+ * address.
+ */
+static int cb_pcimdas_attach(struct comedi_device *dev,
+struct comedi_devconfig *it)
+{
+   struct pci_dev *pcidev;
+   struct comedi_subdevice *s;
+   int ret;
 
-   dev_dbg(dev-class_dev, Found %s on bus %i, slot %i\n,
-   cb_pcimdas_boards[index].name, pcidev-bus-number,
-   PCI_SLOT(pcidev-devfn));
+/*
+ * Allocate the private structure area.
+ */
+   if (alloc_private(dev, sizeof(struct cb_pcimdas_private))  0)
+   return -ENOMEM;
+
+   pcidev = cb_pcimdas_find_pci_dev(dev, it);
+   if (!pcidev)
+   return -EIO;
+   devpriv-pci_dev = pcidev;
 
/*  Warn about non-tested features */
switch (thisboard-device_id) {
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 48/90] staging: comedi: cb_pcimdas: cleanup find pci device code

2012-07-18 Thread H Hartley Sweeten
Add a couple local variables to make the tests more concise.

Reorder the tests to make the for() loop checking for a
matching boardtype quicker.

Use ARRAY_SIZE() to determine the number of boards instead
of the hard-coded '1'.

Drop the dev_dbg for a match. It's just add noise.

Reword the dev_err when no match is found.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/cb_pcimdas.c | 38 -
 1 file changed, 15 insertions(+), 23 deletions(-)

diff --git a/drivers/staging/comedi/drivers/cb_pcimdas.c 
b/drivers/staging/comedi/drivers/cb_pcimdas.c
index 8999a72..1b6ebb7 100644
--- a/drivers/staging/comedi/drivers/cb_pcimdas.c
+++ b/drivers/staging/comedi/drivers/cb_pcimdas.c
@@ -122,8 +122,6 @@ static const struct cb_pcimdas_board cb_pcimdas_boards[] = {
 },
 };
 
-#define N_BOARDS 1 /*  Max number of boards supported */
-
 /*
  * Useful for shorthand access to the particular board structure
  */
@@ -179,36 +177,30 @@ static struct pci_dev *cb_pcimdas_find_pci_dev(struct 
comedi_device *dev,
   struct comedi_devconfig *it)
 {
struct pci_dev *pcidev = NULL;
-   int index;
+   int bus = it-options[0];
+   int slot = it-options[1];
+   int i;
 
for_each_pci_dev(pcidev) {
-   /*  is it not a computer boards card? */
+   if (bus || slot) {
+   if (bus != pcidev-bus-number ||
+   slot != PCI_SLOT(pcidev-devfn))
+   continue;
+   }
if (pcidev-vendor != PCI_VENDOR_ID_COMPUTERBOARDS)
continue;
-   /*  loop through cards supported by this driver */
-   for (index = 0; index  N_BOARDS; index++) {
-   if (cb_pcimdas_boards[index].device_id !=
-   pcidev-device)
+
+   for (i = 0; i  ARRAY_SIZE(cb_pcimdas_boards); i++) {
+   if (cb_pcimdas_boards[i].device_id != pcidev-device)
continue;
-   /*  was a particular bus/slot requested? */
-   if (it-options[0] || it-options[1]) {
-   /*  are we on the wrong bus/slot? */
-   if (pcidev-bus-number != it-options[0] ||
-   PCI_SLOT(pcidev-devfn) != it-options[1]) {
-   continue;
-   }
-   }
-   dev-board_ptr = cb_pcimdas_boards + index;
-   dev_dbg(dev-class_dev,
-   Found %s on bus %i, slot %i\n,
-   cb_pcimdas_boards[index].name,
-   pcidev-bus-number,
-   PCI_SLOT(pcidev-devfn));
+
+   dev-board_ptr = cb_pcimdas_boards + i;
return pcidev;
}
}
dev_err(dev-class_dev,
-   No supported ComputerBoards/MeasurementComputing card found on 
requested position\n);
+   No supported board found! (req. bus %d, slot %d)\n,
+   bus, slot);
return NULL;
 }
 
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 49/90] staging: comedi: cb_pcimdas: remove the debug print of the pci bars

2012-07-18 Thread H Hartley Sweeten
Remove the dev_dbg output of the pci addresses. It's just add noise.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/cb_pcimdas.c | 6 --
 1 file changed, 6 deletions(-)

diff --git a/drivers/staging/comedi/drivers/cb_pcimdas.c 
b/drivers/staging/comedi/drivers/cb_pcimdas.c
index 1b6ebb7..3400067 100644
--- a/drivers/staging/comedi/drivers/cb_pcimdas.c
+++ b/drivers/staging/comedi/drivers/cb_pcimdas.c
@@ -250,12 +250,6 @@ static int cb_pcimdas_attach(struct comedi_device *dev,
devpriv-BADR3 = pci_resource_start(devpriv-pci_dev, 3);
devpriv-BADR4 = pci_resource_start(devpriv-pci_dev, 4);
 
-   dev_dbg(dev-class_dev, devpriv-BADR0 = 0x%lx\n, devpriv-BADR0);
-   dev_dbg(dev-class_dev, devpriv-BADR1 = 0x%lx\n, devpriv-BADR1);
-   dev_dbg(dev-class_dev, devpriv-BADR2 = 0x%lx\n, devpriv-BADR2);
-   dev_dbg(dev-class_dev, devpriv-BADR3 = 0x%lx\n, devpriv-BADR3);
-   dev_dbg(dev-class_dev, devpriv-BADR4 = 0x%lx\n, devpriv-BADR4);
-
 /* Dont support IRQ yet */
 /*  get irq */
 /* if(request_irq(devpriv-pci_dev-irq, cb_pcimdas_interrupt, IRQF_SHARED, 
cb_pcimdas, dev )) */
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 50/90] staging: comedi: cb_pcimdas: cleanup the private data

2012-07-18 Thread H Hartley Sweeten
Remove the unused variables from the private data.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/cb_pcimdas.c | 9 -
 1 file changed, 9 deletions(-)

diff --git a/drivers/staging/comedi/drivers/cb_pcimdas.c 
b/drivers/staging/comedi/drivers/cb_pcimdas.c
index 3400067..9e4bac1 100644
--- a/drivers/staging/comedi/drivers/cb_pcimdas.c
+++ b/drivers/staging/comedi/drivers/cb_pcimdas.c
@@ -134,8 +134,6 @@ static const struct cb_pcimdas_board cb_pcimdas_boards[] = {
  * struct.
  */
 struct cb_pcimdas_private {
-   int data;
-
/*  would be useful for a PCI device */
struct pci_dev *pci_dev;
 
@@ -148,13 +146,6 @@ struct cb_pcimdas_private {
 
/* Used for AO readback */
unsigned int ao_readback[2];
-
-   /*  Used for DIO */
-   unsigned short int port_a;  /*  copy of BADR4+0 */
-   unsigned short int port_b;  /*  copy of BADR4+1 */
-   unsigned short int port_c;  /*  copy of BADR4+2 */
-   unsigned short int dio_mode;/*  copy of BADR4+3 */
-
 };
 
 /*
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 51/90] staging: comedi: cb_pcimdas: remove BADR1 from the private data

2012-07-18 Thread H Hartley Sweeten
The pci resource bar 1 address is not used in the driver. Remove
it from the private data.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/cb_pcimdas.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/staging/comedi/drivers/cb_pcimdas.c 
b/drivers/staging/comedi/drivers/cb_pcimdas.c
index 9e4bac1..3902c85bc 100644
--- a/drivers/staging/comedi/drivers/cb_pcimdas.c
+++ b/drivers/staging/comedi/drivers/cb_pcimdas.c
@@ -57,7 +57,6 @@ See http://www.mccdaq.com/PDFs/Manuals/pcim-das1602-16.pdf 
for more details.
 
 /* sizes of io regions (bytes) */
 #define BADR0_SIZE 2   /* ?? */
-#define BADR1_SIZE 4
 #define BADR2_SIZE 6
 #define BADR3_SIZE 16
 #define BADR4_SIZE 4
@@ -139,7 +138,6 @@ struct cb_pcimdas_private {
 
/* base addresses */
unsigned long BADR0;
-   unsigned long BADR1;
unsigned long BADR2;
unsigned long BADR3;
unsigned long BADR4;
@@ -236,7 +234,6 @@ static int cb_pcimdas_attach(struct comedi_device *dev,
}
 
devpriv-BADR0 = pci_resource_start(devpriv-pci_dev, 0);
-   devpriv-BADR1 = pci_resource_start(devpriv-pci_dev, 1);
devpriv-BADR2 = pci_resource_start(devpriv-pci_dev, 2);
devpriv-BADR3 = pci_resource_start(devpriv-pci_dev, 3);
devpriv-BADR4 = pci_resource_start(devpriv-pci_dev, 4);
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 52/90] staging: comedi: cb_pcimdas: remove BADR4 from the private data

2012-07-18 Thread H Hartley Sweeten
The pci resource bar 4 address is only needed to initialize the
8255 subdevice. Use a local variable to hold it and remove it
from the private data.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/cb_pcimdas.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/comedi/drivers/cb_pcimdas.c 
b/drivers/staging/comedi/drivers/cb_pcimdas.c
index 3902c85bc..c8df680 100644
--- a/drivers/staging/comedi/drivers/cb_pcimdas.c
+++ b/drivers/staging/comedi/drivers/cb_pcimdas.c
@@ -59,7 +59,6 @@ See http://www.mccdaq.com/PDFs/Manuals/pcim-das1602-16.pdf 
for more details.
 #define BADR0_SIZE 2   /* ?? */
 #define BADR2_SIZE 6
 #define BADR3_SIZE 16
-#define BADR4_SIZE 4
 
 /* DAC Offsets */
 #define ADC_TRIG 0
@@ -140,7 +139,6 @@ struct cb_pcimdas_private {
unsigned long BADR0;
unsigned long BADR2;
unsigned long BADR3;
-   unsigned long BADR4;
 
/* Used for AO readback */
unsigned int ao_readback[2];
@@ -204,6 +202,7 @@ static int cb_pcimdas_attach(struct comedi_device *dev,
 {
struct pci_dev *pcidev;
struct comedi_subdevice *s;
+   unsigned long iobase_8255;
int ret;
 
 /*
@@ -236,7 +235,7 @@ static int cb_pcimdas_attach(struct comedi_device *dev,
devpriv-BADR0 = pci_resource_start(devpriv-pci_dev, 0);
devpriv-BADR2 = pci_resource_start(devpriv-pci_dev, 2);
devpriv-BADR3 = pci_resource_start(devpriv-pci_dev, 3);
-   devpriv-BADR4 = pci_resource_start(devpriv-pci_dev, 4);
+   iobase_8255 = pci_resource_start(devpriv-pci_dev, 4);
 
 /* Dont support IRQ yet */
 /*  get irq */
@@ -280,7 +279,7 @@ static int cb_pcimdas_attach(struct comedi_device *dev,
s = dev-subdevices + 2;
/* digital i/o subdevice */
if (thisboard-has_dio)
-   subdev_8255_init(dev, s, NULL, devpriv-BADR4);
+   subdev_8255_init(dev, s, NULL, iobase_8255);
else
s-type = COMEDI_SUBD_UNUSED;
 
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 53/90] staging: comedi: cb_pcimdas: remove BADR2 from the private data

2012-07-18 Thread H Hartley Sweeten
The pci resource bar 2 address is the primary i/o address used
by this device. Store it in dev-iobase and remove it from the
private data.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/cb_pcimdas.c | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/comedi/drivers/cb_pcimdas.c 
b/drivers/staging/comedi/drivers/cb_pcimdas.c
index c8df680..4312e9b 100644
--- a/drivers/staging/comedi/drivers/cb_pcimdas.c
+++ b/drivers/staging/comedi/drivers/cb_pcimdas.c
@@ -57,7 +57,6 @@ See http://www.mccdaq.com/PDFs/Manuals/pcim-das1602-16.pdf 
for more details.
 
 /* sizes of io regions (bytes) */
 #define BADR0_SIZE 2   /* ?? */
-#define BADR2_SIZE 6
 #define BADR3_SIZE 16
 
 /* DAC Offsets */
@@ -137,7 +136,6 @@ struct cb_pcimdas_private {
 
/* base addresses */
unsigned long BADR0;
-   unsigned long BADR2;
unsigned long BADR3;
 
/* Used for AO readback */
@@ -233,7 +231,7 @@ static int cb_pcimdas_attach(struct comedi_device *dev,
}
 
devpriv-BADR0 = pci_resource_start(devpriv-pci_dev, 0);
-   devpriv-BADR2 = pci_resource_start(devpriv-pci_dev, 2);
+   dev-iobase = pci_resource_start(devpriv-pci_dev, 2);
devpriv-BADR3 = pci_resource_start(devpriv-pci_dev, 3);
iobase_8255 = pci_resource_start(devpriv-pci_dev, 4);
 
@@ -344,7 +342,7 @@ static int cb_pcimdas_ai_rinsn(struct comedi_device *dev,
/* convert n samples */
for (n = 0; n  insn-n; n++) {
/* trigger conversion */
-   outw(0, devpriv-BADR2 + 0);
+   outw(0, dev-iobase + 0);
 
 #define TIMEOUT 1000   /* typically takes 5 loops on a lightly loaded 
Pentium 100MHz, */
/* this is likely to be 100 loops on a 2GHz machine, so set 
1000 as the limit. */
@@ -360,7 +358,7 @@ static int cb_pcimdas_ai_rinsn(struct comedi_device *dev,
return -ETIMEDOUT;
}
/* read data */
-   d = inw(devpriv-BADR2 + 0);
+   d = inw(dev-iobase + 0);
 
/* mangle the data as necessary */
/* d ^= 1(thisboard-ai_bits-1); // 16 bit data from ADC, so 
no mangle needed. */
@@ -384,10 +382,10 @@ static int cb_pcimdas_ao_winsn(struct comedi_device *dev,
for (i = 0; i  insn-n; i++) {
switch (chan) {
case 0:
-   outw(data[i]  0x0FFF, devpriv-BADR2 + DAC0_OFFSET);
+   outw(data[i]  0x0FFF, dev-iobase + DAC0_OFFSET);
break;
case 1:
-   outw(data[i]  0x0FFF, devpriv-BADR2 + DAC1_OFFSET);
+   outw(data[i]  0x0FFF, dev-iobase + DAC1_OFFSET);
break;
default:
return -1;
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 54/90] staging: comedi: cb_pcimdas: remove BADR0 from the private data

2012-07-18 Thread H Hartley Sweeten
The pci resource bar 0 address is only used as a flag to
let the datach function know that the pci device has been
enabled. Use dev-iobase in the detach instead and remove
BADR0 from the private data.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/cb_pcimdas.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/staging/comedi/drivers/cb_pcimdas.c 
b/drivers/staging/comedi/drivers/cb_pcimdas.c
index 4312e9b..ce08533 100644
--- a/drivers/staging/comedi/drivers/cb_pcimdas.c
+++ b/drivers/staging/comedi/drivers/cb_pcimdas.c
@@ -56,7 +56,6 @@ See http://www.mccdaq.com/PDFs/Manuals/pcim-das1602-16.pdf 
for more details.
 /* Registers for the PCIM-DAS1602/16 */
 
 /* sizes of io regions (bytes) */
-#define BADR0_SIZE 2   /* ?? */
 #define BADR3_SIZE 16
 
 /* DAC Offsets */
@@ -135,7 +134,6 @@ struct cb_pcimdas_private {
struct pci_dev *pci_dev;
 
/* base addresses */
-   unsigned long BADR0;
unsigned long BADR3;
 
/* Used for AO readback */
@@ -230,7 +228,6 @@ static int cb_pcimdas_attach(struct comedi_device *dev,
return -EIO;
}
 
-   devpriv-BADR0 = pci_resource_start(devpriv-pci_dev, 0);
dev-iobase = pci_resource_start(devpriv-pci_dev, 2);
devpriv-BADR3 = pci_resource_start(devpriv-pci_dev, 3);
iobase_8255 = pci_resource_start(devpriv-pci_dev, 4);
@@ -290,7 +287,7 @@ static void cb_pcimdas_detach(struct comedi_device *dev)
free_irq(dev-irq, dev);
if (devpriv) {
if (devpriv-pci_dev) {
-   if (devpriv-BADR0)
+   if (dev-iobase)
comedi_pci_disable(devpriv-pci_dev);
pci_dev_put(devpriv-pci_dev);
}
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 55/90] staging: comedi: cb_pcimdas: store the pci_dev in the comedi_device

2012-07-18 Thread H Hartley Sweeten
Use the hw_dev pointer in the comedi_device struct to hold the
pci_dev instead of carrying it in the private data.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/cb_pcimdas.c | 29 +
 1 file changed, 13 insertions(+), 16 deletions(-)

diff --git a/drivers/staging/comedi/drivers/cb_pcimdas.c 
b/drivers/staging/comedi/drivers/cb_pcimdas.c
index ce08533..c632a89 100644
--- a/drivers/staging/comedi/drivers/cb_pcimdas.c
+++ b/drivers/staging/comedi/drivers/cb_pcimdas.c
@@ -130,9 +130,6 @@ static const struct cb_pcimdas_board cb_pcimdas_boards[] = {
  * struct.
  */
 struct cb_pcimdas_private {
-   /*  would be useful for a PCI device */
-   struct pci_dev *pci_dev;
-
/* base addresses */
unsigned long BADR3;
 
@@ -210,7 +207,7 @@ static int cb_pcimdas_attach(struct comedi_device *dev,
pcidev = cb_pcimdas_find_pci_dev(dev, it);
if (!pcidev)
return -EIO;
-   devpriv-pci_dev = pcidev;
+   comedi_set_hw_dev(dev, pcidev-dev);
 
/*  Warn about non-tested features */
switch (thisboard-device_id) {
@@ -228,18 +225,18 @@ static int cb_pcimdas_attach(struct comedi_device *dev,
return -EIO;
}
 
-   dev-iobase = pci_resource_start(devpriv-pci_dev, 2);
-   devpriv-BADR3 = pci_resource_start(devpriv-pci_dev, 3);
-   iobase_8255 = pci_resource_start(devpriv-pci_dev, 4);
+   dev-iobase = pci_resource_start(pcidev, 2);
+   devpriv-BADR3 = pci_resource_start(pcidev, 3);
+   iobase_8255 = pci_resource_start(pcidev, 4);
 
 /* Dont support IRQ yet */
 /*  get irq */
-/* if(request_irq(devpriv-pci_dev-irq, cb_pcimdas_interrupt, IRQF_SHARED, 
cb_pcimdas, dev )) */
+/* if(request_irq(pcidev-irq, cb_pcimdas_interrupt, IRQF_SHARED, 
cb_pcimdas, dev )) */
 /* { */
-/* printk( unable to allocate irq %u\n, devpriv-pci_dev-irq); */
+/* printk( unable to allocate irq %u\n, pcidev-irq); */
 /* return -EINVAL; */
 /* } */
-/* dev-irq = devpriv-pci_dev-irq; */
+/* dev-irq = pcidev-irq; */
 
/* Initialize dev-board_name */
dev-board_name = thisboard-name;
@@ -283,14 +280,14 @@ static int cb_pcimdas_attach(struct comedi_device *dev,
 
 static void cb_pcimdas_detach(struct comedi_device *dev)
 {
+   struct pci_dev *pcidev = comedi_to_pci_dev(dev);
+
if (dev-irq)
free_irq(dev-irq, dev);
-   if (devpriv) {
-   if (devpriv-pci_dev) {
-   if (dev-iobase)
-   comedi_pci_disable(devpriv-pci_dev);
-   pci_dev_put(devpriv-pci_dev);
-   }
+   if (pcidev) {
+   if (dev-iobase)
+   comedi_pci_disable(pcidev);
+   pci_dev_put(pcidev);
}
 }
 
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 56/90] staging: comedi: contec_pci_dio: factor out the find pci device code

2012-07-18 Thread H Hartley Sweeten
Factor the find pci device code out of the attach function.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/contec_pci_dio.c | 92 ++---
 1 file changed, 50 insertions(+), 42 deletions(-)

diff --git a/drivers/staging/comedi/drivers/contec_pci_dio.c 
b/drivers/staging/comedi/drivers/contec_pci_dio.c
index ee769e0..e4d37fc 100644
--- a/drivers/staging/comedi/drivers/contec_pci_dio.c
+++ b/drivers/staging/comedi/drivers/contec_pci_dio.c
@@ -97,22 +97,10 @@ static int contec_di_insn_bits(struct comedi_device *dev,
return insn-n;
 }
 
-static int contec_attach(struct comedi_device *dev, struct comedi_devconfig 
*it)
+static struct pci_dev *contec_find_pci_dev(struct comedi_device *dev,
+  struct comedi_devconfig *it)
 {
struct pci_dev *pcidev = NULL;
-   struct comedi_subdevice *s;
-   int ret;
-
-   printk(comedi%d: contec: , dev-minor);
-
-   dev-board_name = thisboard-name;
-
-   if (alloc_private(dev, sizeof(struct contec_private))  0)
-   return -ENOMEM;
-
-   ret = comedi_alloc_subdevices(dev, 2);
-   if (ret)
-   return ret;
 
for_each_pci_dev(pcidev) {
if (pcidev-vendor == PCI_VENDOR_ID_CONTEC 
@@ -124,43 +112,63 @@ static int contec_attach(struct comedi_device *dev, 
struct comedi_devconfig *it)
continue;
}
}
-   devpriv-pci_dev = pcidev;
-   if (comedi_pci_enable(pcidev, contec_pci_dio)) {
-   printk
-   (error enabling PCI device and request 
regions!\n);
-   return -EIO;
-   }
-   dev-iobase = pci_resource_start(pcidev, 0);
-   printk( base addr %lx , dev-iobase);
-
dev-board_ptr = contec_boards + 0;
+   return pcidev;
+   }
+   }
+   printk(card not present!\n);
+   return NULL;
+}
 
-   s = dev-subdevices + 0;
+static int contec_attach(struct comedi_device *dev, struct comedi_devconfig 
*it)
+{
+   struct pci_dev *pcidev;
+   struct comedi_subdevice *s;
+   int ret;
 
-   s-type = COMEDI_SUBD_DI;
-   s-subdev_flags = SDF_READABLE;
-   s-n_chan = 16;
-   s-maxdata = 1;
-   s-range_table = range_digital;
-   s-insn_bits = contec_di_insn_bits;
+   printk(comedi%d: contec: , dev-minor);
 
-   s = dev-subdevices + 1;
-   s-type = COMEDI_SUBD_DO;
-   s-subdev_flags = SDF_WRITABLE;
-   s-n_chan = 16;
-   s-maxdata = 1;
-   s-range_table = range_digital;
-   s-insn_bits = contec_do_insn_bits;
+   dev-board_name = thisboard-name;
 
-   printk(attached\n);
+   if (alloc_private(dev, sizeof(struct contec_private))  0)
+   return -ENOMEM;
 
-   return 1;
-   }
+   ret = comedi_alloc_subdevices(dev, 2);
+   if (ret)
+   return ret;
+
+   pcidev = contec_find_pci_dev(dev, it);
+   if (!pcidev)
+   return -EIO;
+   devpriv-pci_dev = pcidev;
+
+   if (comedi_pci_enable(pcidev, contec_pci_dio)) {
+   printk(error enabling PCI device and request regions!\n);
+   return -EIO;
}
+   dev-iobase = pci_resource_start(pcidev, 0);
+   printk( base addr %lx , dev-iobase);
 
-   printk(card not present!\n);
+   s = dev-subdevices + 0;
+
+   s-type = COMEDI_SUBD_DI;
+   s-subdev_flags = SDF_READABLE;
+   s-n_chan = 16;
+   s-maxdata = 1;
+   s-range_table = range_digital;
+   s-insn_bits = contec_di_insn_bits;
+
+   s = dev-subdevices + 1;
+   s-type = COMEDI_SUBD_DO;
+   s-subdev_flags = SDF_WRITABLE;
+   s-n_chan = 16;
+   s-maxdata = 1;
+   s-range_table = range_digital;
+   s-insn_bits = contec_do_insn_bits;
+
+   printk(attached\n);
 
-   return -EIO;
+   return 1;
 }
 
 static void contec_detach(struct comedi_device *dev)
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 57/90] staging: comedi: contec_pci_dio: cleanup find pci device code

2012-07-18 Thread H Hartley Sweeten
Add a couple local variables and reorder the tests to make
to make the more concise.

Change the printk to a dev_err when no match is found and reword
the message.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/contec_pci_dio.c | 27 ++---
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/comedi/drivers/contec_pci_dio.c 
b/drivers/staging/comedi/drivers/contec_pci_dio.c
index e4d37fc..b75a8af 100644
--- a/drivers/staging/comedi/drivers/contec_pci_dio.c
+++ b/drivers/staging/comedi/drivers/contec_pci_dio.c
@@ -101,22 +101,25 @@ static struct pci_dev *contec_find_pci_dev(struct 
comedi_device *dev,
   struct comedi_devconfig *it)
 {
struct pci_dev *pcidev = NULL;
+   int bus = it-options[0];
+   int slot = it-options[1];
 
for_each_pci_dev(pcidev) {
-   if (pcidev-vendor == PCI_VENDOR_ID_CONTEC 
-   pcidev-device == PCI_DEVICE_ID_PIO1616L) {
-   if (it-options[0] || it-options[1]) {
-   /* Check bus and slot. */
-   if (it-options[0] != pcidev-bus-number ||
-   it-options[1] != PCI_SLOT(pcidev-devfn)) {
-   continue;
-   }
-   }
-   dev-board_ptr = contec_boards + 0;
-   return pcidev;
+   if (bus || slot) {
+   if (bus != pcidev-bus-number ||
+   slot != PCI_SLOT(pcidev-devfn))
+   continue;
}
+   if (pcidev-vendor != PCI_VENDOR_ID_CONTEC ||
+   pcidev-device != PCI_DEVICE_ID_PIO1616L)
+   continue;
+
+   dev-board_ptr = contec_boards + 0;
+   return pcidev;
}
-   printk(card not present!\n);
+   dev_err(dev-class_dev,
+   No supported board found! (req. bus %d, slot %d)\n,
+   bus, slot);
return NULL;
 }
 
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 58/90] staging: comedi: contec_pci_dio: store the pci_dev in the comedi_device

2012-07-18 Thread H Hartley Sweeten
Use the hw_dev pointer in the comedi_device struct to hold the
pci_dev instead of carrying it in the private data.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/contec_pci_dio.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/comedi/drivers/contec_pci_dio.c 
b/drivers/staging/comedi/drivers/contec_pci_dio.c
index b75a8af..5578c2c 100644
--- a/drivers/staging/comedi/drivers/contec_pci_dio.c
+++ b/drivers/staging/comedi/drivers/contec_pci_dio.c
@@ -59,9 +59,6 @@ static const struct contec_board contec_boards[] = {
 
 struct contec_private {
int data;
-
-   struct pci_dev *pci_dev;
-
 };
 
 #define devpriv ((struct contec_private *)dev-private)
@@ -143,7 +140,7 @@ static int contec_attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
pcidev = contec_find_pci_dev(dev, it);
if (!pcidev)
return -EIO;
-   devpriv-pci_dev = pcidev;
+   comedi_set_hw_dev(dev, pcidev-dev);
 
if (comedi_pci_enable(pcidev, contec_pci_dio)) {
printk(error enabling PCI device and request regions!\n);
@@ -176,10 +173,12 @@ static int contec_attach(struct comedi_device *dev, 
struct comedi_devconfig *it)
 
 static void contec_detach(struct comedi_device *dev)
 {
-   if (devpriv  devpriv-pci_dev) {
+   struct pci_dev *pcidev = comedi_to_pci_dev(dev);
+
+   if (pcidev) {
if (dev-iobase)
-   comedi_pci_disable(devpriv-pci_dev);
-   pci_dev_put(devpriv-pci_dev);
+   comedi_pci_disable(pcidev);
+   pci_dev_put(pcidev);
}
 }
 
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 59/90] staging: comedi: contec_pci_dio: remove the private data

2012-07-18 Thread H Hartley Sweeten
The private data is no longer needed by this driver. Remove the
struct, devpriv macro, and the allocation.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/contec_pci_dio.c | 9 -
 1 file changed, 9 deletions(-)

diff --git a/drivers/staging/comedi/drivers/contec_pci_dio.c 
b/drivers/staging/comedi/drivers/contec_pci_dio.c
index 5578c2c..944cfee 100644
--- a/drivers/staging/comedi/drivers/contec_pci_dio.c
+++ b/drivers/staging/comedi/drivers/contec_pci_dio.c
@@ -57,12 +57,6 @@ static const struct contec_board contec_boards[] = {
 
 #define thisboard ((const struct contec_board *)dev-board_ptr)
 
-struct contec_private {
-   int data;
-};
-
-#define devpriv ((struct contec_private *)dev-private)
-
 static int contec_do_insn_bits(struct comedi_device *dev,
   struct comedi_subdevice *s,
   struct comedi_insn *insn, unsigned int *data)
@@ -130,9 +124,6 @@ static int contec_attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
 
dev-board_name = thisboard-name;
 
-   if (alloc_private(dev, sizeof(struct contec_private))  0)
-   return -ENOMEM;
-
ret = comedi_alloc_subdevices(dev, 2);
if (ret)
return ret;
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 60/90] staging: comedi: daqboard2000: factor out the find pci device code

2012-07-18 Thread H Hartley Sweeten
Factor the find pci device code out of the attach function.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/daqboard2000.c | 68 +++
 1 file changed, 39 insertions(+), 29 deletions(-)

diff --git a/drivers/staging/comedi/drivers/daqboard2000.c 
b/drivers/staging/comedi/drivers/daqboard2000.c
index 8455cb9..fe2f39c 100644
--- a/drivers/staging/comedi/drivers/daqboard2000.c
+++ b/drivers/staging/comedi/drivers/daqboard2000.c
@@ -703,48 +703,38 @@ static int daqboard2000_8255_cb(int dir, int port, int 
data,
return result;
 }
 
-static int daqboard2000_attach(struct comedi_device *dev,
-  struct comedi_devconfig *it)
+static struct pci_dev *daqboard2000_find_pci_dev(struct comedi_device *dev,
+struct comedi_devconfig *it)
 {
-   int result = 0;
-   struct comedi_subdevice *s;
-   struct pci_dev *card = NULL;
-   void *aux_data;
-   unsigned int aux_len;
-   int bus, slot;
-
-   bus = it-options[0];
-   slot = it-options[1];
+   struct pci_dev *pcidev = NULL;
+   int bus = it-options[0];
+   int slot = it-options[1];
 
-   result = alloc_private(dev, sizeof(struct daqboard2000_private));
-   if (result  0)
-   return -ENOMEM;
-
-   for (card = pci_get_device(0x1616, 0x0409, NULL);
-card != NULL; card = pci_get_device(0x1616, 0x0409, card)) {
+   for (pcidev = pci_get_device(0x1616, 0x0409, NULL);
+pcidev != NULL; pcidev = pci_get_device(0x1616, 0x0409, pcidev)) {
if (bus || slot) {
/* requested particular bus/slot */
-   if (card-bus-number != bus ||
-   PCI_SLOT(card-devfn) != slot) {
+   if (pcidev-bus-number != bus ||
+   PCI_SLOT(pcidev-devfn) != slot) {
continue;
}
}
break;  /* found one */
}
-   if (!card) {
+   if (!pcidev) {
if (bus || slot)
dev_err(dev-class_dev,
no daqboard2000 found at bus/slot: %d/%d\n,
bus, slot);
else
dev_err(dev-class_dev, no daqboard2000 found\n);
-   return -EIO;
+   return NULL;
} else {
u32 id;
int i;
-   devpriv-pci_dev = card;
-   id = ((u32) card-
- subsystem_device  16) | card-subsystem_vendor;
+
+   id = ((u32) pcidev-
+ subsystem_device  16) | pcidev-subsystem_vendor;
for (i = 0; i  ARRAY_SIZE(boardtypes); i++) {
if (boardtypes[i].id == id) {
dev_dbg(dev-class_dev, %s\n,
@@ -758,9 +748,29 @@ static int daqboard2000_attach(struct comedi_device *dev,
 id);
dev-board_ptr = boardtypes;
}
+   return pcidev;
}
+}
+
+static int daqboard2000_attach(struct comedi_device *dev,
+  struct comedi_devconfig *it)
+{
+   struct pci_dev *pcidev;
+   struct comedi_subdevice *s;
+   void *aux_data;
+   unsigned int aux_len;
+   int result;
+
+   result = alloc_private(dev, sizeof(struct daqboard2000_private));
+   if (result  0)
+   return -ENOMEM;
+
+   pcidev = daqboard2000_find_pci_dev(dev, it);
+   if (!pcidev)
+   return -EIO;
+   devpriv-pci_dev = pcidev;
 
-   result = comedi_pci_enable(card, daqboard2000);
+   result = comedi_pci_enable(pcidev, daqboard2000);
if (result  0) {
dev_err(dev-class_dev,
failed to enable PCI device and request regions\n);
@@ -768,9 +778,9 @@ static int daqboard2000_attach(struct comedi_device *dev,
}
devpriv-got_regions = 1;
devpriv-plx =
-   ioremap(pci_resource_start(card, 0), DAQBOARD2000_PLX_SIZE);
+   ioremap(pci_resource_start(pcidev, 0), DAQBOARD2000_PLX_SIZE);
devpriv-daq =
-   ioremap(pci_resource_start(card, 2), DAQBOARD2000_DAQ_SIZE);
+   ioremap(pci_resource_start(pcidev, 2), DAQBOARD2000_DAQ_SIZE);
if (!devpriv-plx || !devpriv-daq)
return -ENOMEM;
 
@@ -783,7 +793,7 @@ static int daqboard2000_attach(struct comedi_device *dev,
/*
   u8 interrupt;
   Windows code does restore interrupts, but since we don't use them...
-  pci_read_config_byte(card, PCI_INTERRUPT_LINE, interrupt);
+  pci_read_config_byte(pcidev, PCI_INTERRUPT_LINE, interrupt);
   printk(Interrupt

[PATCH 61/90] staging: comedi: daqboard2000: cleanup find pci device code

2012-07-18 Thread H Hartley Sweeten
The find pci device code for this driver was quite a bit
different from the other comedi pci drivers. Clean it up so
it follows the format of the other drivers.

Use for_each_pci_dev() instead of open-coding the loop using
pci_get_device().

Check for a specific bus/slot then the vendor/device ids.

The loop checking for the matching boardinfo was creating an
id based on the subsystem_device and subsystem_vendor info
from the pci_dev. The vendor id was already checked so just
check against the subsystem_device.

Only return the pci_dev if a matching boardinfo is found.

Consolidate the dev_err messages when a device is not found
into a single message.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/daqboard2000.c | 56 ++-
 1 file changed, 20 insertions(+), 36 deletions(-)

diff --git a/drivers/staging/comedi/drivers/daqboard2000.c 
b/drivers/staging/comedi/drivers/daqboard2000.c
index fe2f39c..eb07466 100644
--- a/drivers/staging/comedi/drivers/daqboard2000.c
+++ b/drivers/staging/comedi/drivers/daqboard2000.c
@@ -120,8 +120,10 @@ Configuration options:
 
 #include 8255.h
 
-#define DAQBOARD2000_SUBSYSTEM_IDS20x00021616  /* Daqboard/2000 - 2 
Dacs */
-#define DAQBOARD2000_SUBSYSTEM_IDS40x00041616  /* Daqboard/2000 - 4 
Dacs */
+#define PCI_VENDOR_ID_IOTECH   0x1616
+
+#define DAQBOARD2000_SUBSYSTEM_IDS20x0002  /* Daqboard/2000 - 2 Dacs */
+#define DAQBOARD2000_SUBSYSTEM_IDS40x0004  /* Daqboard/2000 - 4 Dacs */
 
 #define DAQBOARD2000_DAQ_SIZE  0x1002
 #define DAQBOARD2000_PLX_SIZE  0x100
@@ -709,47 +711,29 @@ static struct pci_dev *daqboard2000_find_pci_dev(struct 
comedi_device *dev,
struct pci_dev *pcidev = NULL;
int bus = it-options[0];
int slot = it-options[1];
+   int i;
 
-   for (pcidev = pci_get_device(0x1616, 0x0409, NULL);
-pcidev != NULL; pcidev = pci_get_device(0x1616, 0x0409, pcidev)) {
+   for_each_pci_dev(pcidev) {
if (bus || slot) {
-   /* requested particular bus/slot */
-   if (pcidev-bus-number != bus ||
-   PCI_SLOT(pcidev-devfn) != slot) {
+   if (bus != pcidev-bus-number ||
+   slot != PCI_SLOT(pcidev-devfn))
continue;
-   }
}
-   break;  /* found one */
-   }
-   if (!pcidev) {
-   if (bus || slot)
-   dev_err(dev-class_dev,
-   no daqboard2000 found at bus/slot: %d/%d\n,
-   bus, slot);
-   else
-   dev_err(dev-class_dev, no daqboard2000 found\n);
-   return NULL;
-   } else {
-   u32 id;
-   int i;
+   if (pcidev-vendor != PCI_VENDOR_ID_IOTECH ||
+   pcidev-device != 0x0409)
+   continue;
 
-   id = ((u32) pcidev-
- subsystem_device  16) | pcidev-subsystem_vendor;
for (i = 0; i  ARRAY_SIZE(boardtypes); i++) {
-   if (boardtypes[i].id == id) {
-   dev_dbg(dev-class_dev, %s\n,
-   boardtypes[i].name);
-   dev-board_ptr = boardtypes + i;
-   }
-   }
-   if (!dev-board_ptr) {
-   printk
-   ( unknown subsystem id %08x (pretend it is an 
ids2),
-id);
-   dev-board_ptr = boardtypes;
+   if (boardtypes[i].id != pcidev-subsystem_device)
+   continue;
+   dev-board_ptr = boardtypes + i;
+   return pcidev;
}
-   return pcidev;
}
+   dev_err(dev-class_dev,
+   No supported board found! (req. bus %d, slot %d)\n,
+   bus, slot);
+   return NULL;
 }
 
 static int daqboard2000_attach(struct comedi_device *dev,
@@ -886,7 +870,7 @@ static void __devexit daqboard2000_pci_remove(struct 
pci_dev *dev)
 }
 
 static DEFINE_PCI_DEVICE_TABLE(daqboard2000_pci_table) = {
-   { PCI_DEVICE(0x1616, 0x0409) },
+   { PCI_DEVICE(PCI_VENDOR_ID_IOTECH, 0x0409) },
{ 0 }
 };
 MODULE_DEVICE_TABLE(pci, daqboard2000_pci_table);
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 62/90] staging: comedi: daqboard2000: remove 'got_regions' from private data

2012-07-18 Thread H Hartley Sweeten
The 'got_regions' variable in the private data is used as a flag
for the detach to know if the pci device has been enabled.

Typically the dev-iobase variable is used to indicate this in
all the other comedi drivers. Do the same here for consistancy.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/daqboard2000.c | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/comedi/drivers/daqboard2000.c 
b/drivers/staging/comedi/drivers/daqboard2000.c
index eb07466..1d94b58 100644
--- a/drivers/staging/comedi/drivers/daqboard2000.c
+++ b/drivers/staging/comedi/drivers/daqboard2000.c
@@ -320,7 +320,6 @@ struct daqboard2000_private {
struct pci_dev *pci_dev;
void *daq;
void *plx;
-   int got_regions;
unsigned int ao_readback[2];
 };
 
@@ -760,11 +759,11 @@ static int daqboard2000_attach(struct comedi_device *dev,
failed to enable PCI device and request regions\n);
return -EIO;
}
-   devpriv-got_regions = 1;
+   dev-iobase = pci_resource_start(pcidev, 2);
+
devpriv-plx =
ioremap(pci_resource_start(pcidev, 0), DAQBOARD2000_PLX_SIZE);
-   devpriv-daq =
-   ioremap(pci_resource_start(pcidev, 2), DAQBOARD2000_DAQ_SIZE);
+   devpriv-daq = ioremap(dev-iobase, DAQBOARD2000_DAQ_SIZE);
if (!devpriv-plx || !devpriv-daq)
return -ENOMEM;
 
@@ -844,7 +843,7 @@ static void daqboard2000_detach(struct comedi_device *dev)
if (devpriv-plx)
iounmap(devpriv-plx);
if (devpriv-pci_dev) {
-   if (devpriv-got_regions)
+   if (dev-iobase)
comedi_pci_disable(devpriv-pci_dev);
pci_dev_put(devpriv-pci_dev);
}
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 63/90] staging: comedi: daqboard2000: store the pci_dev in the comedi_device

2012-07-18 Thread H Hartley Sweeten
Use the hw_dev pointer in the comedi_device struct to hold the
pci_dev instead of carrying it in the private data.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/daqboard2000.c | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/comedi/drivers/daqboard2000.c 
b/drivers/staging/comedi/drivers/daqboard2000.c
index 1d94b58..ba61e32 100644
--- a/drivers/staging/comedi/drivers/daqboard2000.c
+++ b/drivers/staging/comedi/drivers/daqboard2000.c
@@ -317,7 +317,6 @@ struct daqboard2000_private {
enum {
card_daqboard_2000
} card;
-   struct pci_dev *pci_dev;
void *daq;
void *plx;
unsigned int ao_readback[2];
@@ -751,7 +750,7 @@ static int daqboard2000_attach(struct comedi_device *dev,
pcidev = daqboard2000_find_pci_dev(dev, it);
if (!pcidev)
return -EIO;
-   devpriv-pci_dev = pcidev;
+   comedi_set_hw_dev(dev, pcidev-dev);
 
result = comedi_pci_enable(pcidev, daqboard2000);
if (result  0) {
@@ -833,6 +832,8 @@ out:
 
 static void daqboard2000_detach(struct comedi_device *dev)
 {
+   struct pci_dev *pcidev = comedi_to_pci_dev(dev);
+
if (dev-subdevices)
subdev_8255_cleanup(dev, dev-subdevices + 2);
if (dev-irq)
@@ -842,11 +843,11 @@ static void daqboard2000_detach(struct comedi_device *dev)
iounmap(devpriv-daq);
if (devpriv-plx)
iounmap(devpriv-plx);
-   if (devpriv-pci_dev) {
-   if (dev-iobase)
-   comedi_pci_disable(devpriv-pci_dev);
-   pci_dev_put(devpriv-pci_dev);
-   }
+   }
+   if (pcidev) {
+   if (dev-iobase)
+   comedi_pci_disable(pcidev);
+   pci_dev_put(pcidev);
}
 }
 
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 64/90] staging: comedi: daqboard2000: void *plx should be a void __iomem *

2012-07-18 Thread H Hartley Sweeten
The private data variable 'plx' is an ioremap'ed pci resource and
should be a void __iomem *. This quiets a number of sparse warnings
about different address spaces.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/daqboard2000.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/comedi/drivers/daqboard2000.c 
b/drivers/staging/comedi/drivers/daqboard2000.c
index ba61e32..ef28385 100644
--- a/drivers/staging/comedi/drivers/daqboard2000.c
+++ b/drivers/staging/comedi/drivers/daqboard2000.c
@@ -318,7 +318,7 @@ struct daqboard2000_private {
card_daqboard_2000
} card;
void *daq;
-   void *plx;
+   void __iomem *plx;
unsigned int ao_readback[2];
 };
 
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 65/90] staging: comedi: dt3000: cleanup find pci device code

2012-07-18 Thread H Hartley Sweeten
The find pci device code for this driver was split between
two functions which could cause the driver to walk the pci
bus multiple times while looking for a match.

Consolidate the functions into the format that is more
standard for the comedi pci drivers.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/dt3000.c | 85 -
 1 file changed, 31 insertions(+), 54 deletions(-)

diff --git a/drivers/staging/comedi/drivers/dt3000.c 
b/drivers/staging/comedi/drivers/dt3000.c
index d1d99a3..10b43a2 100644
--- a/drivers/staging/comedi/drivers/dt3000.c
+++ b/drivers/staging/comedi/drivers/dt3000.c
@@ -159,7 +159,6 @@ static const struct dt3k_boardtype dt3k_boardtypes[] = {
 },
 };
 
-#define n_dt3k_boards sizeof(dt3k_boardtypes)/sizeof(struct dt3k_boardtype)
 #define this_board ((const struct dt3k_boardtype *)dev-board_ptr)
 
 #define DT3000_SIZE(4*0x1000)
@@ -797,87 +796,65 @@ static int setup_pci(struct comedi_device *dev)
return 0;
 }
 
-static struct pci_dev *dt_pci_find_device(struct pci_dev *from, int *board)
+static struct pci_dev *dt3000_find_pci_dev(struct comedi_device *dev,
+  struct comedi_devconfig *it)
 {
+   struct pci_dev *pcidev = NULL;
+   int bus = it-options[0];
+   int slot = it-options[1];
int i;
 
-   for (from = pci_get_device(PCI_VENDOR_ID_DT, PCI_ANY_ID, from);
-from != NULL;
-from = pci_get_device(PCI_VENDOR_ID_DT, PCI_ANY_ID, from)) {
-   for (i = 0; i  n_dt3k_boards; i++) {
-   if (from-device == dt3k_boardtypes[i].device_id) {
-   *board = i;
-   return from;
-   }
+   for_each_pci_dev(pcidev) {
+   if (bus || slot) {
+   if (bus != pcidev-bus-number ||
+   slot != PCI_SLOT(pcidev-devfn))
+   continue;
}
-   printk
-   (unknown Data Translation PCI device found with 
device_id=0x%04x\n,
-from-device);
-   }
-   *board = -1;
-   return from;
-}
-
-static int dt_pci_probe(struct comedi_device *dev, int bus, int slot)
-{
-   int board;
-   int ret;
-   struct pci_dev *pcidev;
-
-   pcidev = NULL;
-   while ((pcidev = dt_pci_find_device(pcidev, board)) != NULL) {
-   if ((bus == 0  slot == 0) ||
-   (pcidev-bus-number == bus 
-PCI_SLOT(pcidev-devfn) == slot)) {
-   break;
+   if (pcidev-vendor != PCI_VENDOR_ID_DT)
+   continue;
+   for (i = 0; i  ARRAY_SIZE(dt3k_boardtypes); i++) {
+   if (dt3k_boardtypes[i].device_id != pcidev-device)
+   continue;
+   dev-board_ptr = dt3k_boardtypes + i;
+   return pcidev;
}
}
-   devpriv-pci_dev = pcidev;
-
-   if (board = 0)
-   dev-board_ptr = dt3k_boardtypes + board;
-
-   if (!devpriv-pci_dev)
-   return 0;
-
-   ret = setup_pci(dev);
-   if (ret  0)
-   return ret;
-
-   return 1;
+   dev_err(dev-class_dev,
+   No supported board found! (req. bus %d, slot %d)\n,
+   bus, slot);
+   return NULL;
 }
 
 static int dt3000_attach(struct comedi_device *dev, struct comedi_devconfig 
*it)
 {
+   struct pci_dev *pcidev;
struct comedi_subdevice *s;
-   int bus, slot;
int ret = 0;
 
dev_dbg(dev-class_dev, dt3000:\n);
-   bus = it-options[0];
-   slot = it-options[1];
 
ret = alloc_private(dev, sizeof(struct dt3k_private));
if (ret  0)
return ret;
 
-   ret = dt_pci_probe(dev, bus, slot);
+   pcidev = dt3000_find_pci_dev(dev, it);
+   if (!pcidev)
+   return -EIO;
+   devpriv-pci_dev = pcidev;
+
+   ret = setup_pci(dev);
if (ret  0)
return ret;
-   if (ret == 0) {
-   dev_warn(dev-class_dev, no DT board found\n);
-   return -ENODEV;
-   }
 
dev-board_name = this_board-name;
 
-   if (request_irq(devpriv-pci_dev-irq, dt3k_interrupt, IRQF_SHARED,
+   if (request_irq(pcidev-irq, dt3k_interrupt, IRQF_SHARED,
dt3000, dev)) {
dev_err(dev-class_dev, unable to allocate IRQ %u\n,
-   devpriv-pci_dev-irq);
+   pcidev-irq);
return -EINVAL;
}
-   dev-irq = devpriv-pci_dev-irq;
+   dev-irq = pcidev-irq;
 
ret = comedi_alloc_subdevices(dev, 4);
if (ret)
-- 
1.7.11

--
To unsubscribe from this list: send

[PATCH 66/90] staging: comedi: dt3000: move the setup_pci() code into the attach

2012-07-18 Thread H Hartley Sweeten
The setup_pci() function simply calls comedi_pci_enable() to enable
the device then ioremaps the pci address. Move the code directly
into the attach function as is more typical for the comedi pci
drivers.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/dt3000.c | 29 ++---
 1 file changed, 6 insertions(+), 23 deletions(-)

diff --git a/drivers/staging/comedi/drivers/dt3000.c 
b/drivers/staging/comedi/drivers/dt3000.c
index 10b43a2..92558e7 100644
--- a/drivers/staging/comedi/drivers/dt3000.c
+++ b/drivers/staging/comedi/drivers/dt3000.c
@@ -774,28 +774,6 @@ static int dt3k_mem_insn_read(struct comedi_device *dev,
return i;
 }
 
-static int setup_pci(struct comedi_device *dev)
-{
-   resource_size_t addr;
-   int ret;
-
-   ret = comedi_pci_enable(devpriv-pci_dev, dt3000);
-   if (ret  0)
-   return ret;
-
-   addr = pci_resource_start(devpriv-pci_dev, 0);
-   devpriv-phys_addr = addr;
-   devpriv-io_addr = ioremap(devpriv-phys_addr, DT3000_SIZE);
-   if (!devpriv-io_addr)
-   return -ENOMEM;
-#if DEBUG
-   printk(0x%08llx mapped to %p, ,
-  (unsigned long long)devpriv-phys_addr, devpriv-io_addr);
-#endif
-
-   return 0;
-}
-
 static struct pci_dev *dt3000_find_pci_dev(struct comedi_device *dev,
   struct comedi_devconfig *it)
 {
@@ -842,10 +820,15 @@ static int dt3000_attach(struct comedi_device *dev, 
struct comedi_devconfig *it)
return -EIO;
devpriv-pci_dev = pcidev;
 
-   ret = setup_pci(dev);
+   ret = comedi_pci_enable(pcidev, dt3000);
if (ret  0)
return ret;
 
+   devpriv-phys_addr = pci_resource_start(pcidev, 0);
+   devpriv-io_addr = ioremap(devpriv-phys_addr, DT3000_SIZE);
+   if (!devpriv-io_addr)
+   return -ENOMEM;
+
dev-board_name = this_board-name;
 
if (request_irq(pcidev-irq, dt3k_interrupt, IRQF_SHARED,
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 67/90] staging: comedi: dt3000: remove 'phys_addr' from the private data

2012-07-18 Thread H Hartley Sweeten
The 'phys_addr' variable in the private data is simply used as
a flag for the detach function to know that the pci device has
been enabled. Use the 'dev-iobase' variable instead as is more
typical for other comedi pci drivers.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/dt3000.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/comedi/drivers/dt3000.c 
b/drivers/staging/comedi/drivers/dt3000.c
index 92558e7..3937e87 100644
--- a/drivers/staging/comedi/drivers/dt3000.c
+++ b/drivers/staging/comedi/drivers/dt3000.c
@@ -250,7 +250,6 @@ static const struct dt3k_boardtype dt3k_boardtypes[] = {
 struct dt3k_private {
 
struct pci_dev *pci_dev;
-   resource_size_t phys_addr;
void __iomem *io_addr;
unsigned int lock;
unsigned int ao_readback[2];
@@ -824,8 +823,8 @@ static int dt3000_attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
if (ret  0)
return ret;
 
-   devpriv-phys_addr = pci_resource_start(pcidev, 0);
-   devpriv-io_addr = ioremap(devpriv-phys_addr, DT3000_SIZE);
+   dev-iobase = pci_resource_start(pcidev, 0);
+   devpriv-io_addr = ioremap(dev-iobase, DT3000_SIZE);
if (!devpriv-io_addr)
return -ENOMEM;
 
@@ -905,7 +904,7 @@ static void dt3000_detach(struct comedi_device *dev)
free_irq(dev-irq, dev);
if (devpriv) {
if (devpriv-pci_dev) {
-   if (devpriv-phys_addr)
+   if (dev-iobase)
comedi_pci_disable(devpriv-pci_dev);
pci_dev_put(devpriv-pci_dev);
}
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 68/90] staging: comedi: dt3000: store the pci_dev in the comedi_device

2012-07-18 Thread H Hartley Sweeten
Use the hw_dev pointer in the comedi_device struct to hold the
pci_dev instead of carrying it in the private data.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/dt3000.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/comedi/drivers/dt3000.c 
b/drivers/staging/comedi/drivers/dt3000.c
index 3937e87..a6fe6c9 100644
--- a/drivers/staging/comedi/drivers/dt3000.c
+++ b/drivers/staging/comedi/drivers/dt3000.c
@@ -248,8 +248,6 @@ static const struct dt3k_boardtype dt3k_boardtypes[] = {
 #define DT3000_CHANNEL_MODE_DI 1
 
 struct dt3k_private {
-
-   struct pci_dev *pci_dev;
void __iomem *io_addr;
unsigned int lock;
unsigned int ao_readback[2];
@@ -817,7 +815,7 @@ static int dt3000_attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
pcidev = dt3000_find_pci_dev(dev, it);
if (!pcidev)
return -EIO;
-   devpriv-pci_dev = pcidev;
+   comedi_set_hw_dev(dev, pcidev-dev);
 
ret = comedi_pci_enable(pcidev, dt3000);
if (ret  0)
@@ -900,17 +898,19 @@ static int dt3000_attach(struct comedi_device *dev, 
struct comedi_devconfig *it)
 
 static void dt3000_detach(struct comedi_device *dev)
 {
+   struct pci_dev *pcidev = comedi_to_pci_dev(dev);
+
if (dev-irq)
free_irq(dev-irq, dev);
if (devpriv) {
-   if (devpriv-pci_dev) {
-   if (dev-iobase)
-   comedi_pci_disable(devpriv-pci_dev);
-   pci_dev_put(devpriv-pci_dev);
-   }
if (devpriv-io_addr)
iounmap(devpriv-io_addr);
}
+   if (pcidev) {
+   if (dev-iobase)
+   comedi_pci_disable(pcidev);
+   pci_dev_put(pcidev);
+   }
 }
 
 static struct comedi_driver dt3000_driver = {
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 71/90] staging: comedi: dyna_pci10xx: remove the 'start_stop_sem' mutex

2012-07-18 Thread H Hartley Sweeten
The comedi core already has a mutex protecting the attach/detach
of the comedi drivers.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/dyna_pci10xx.c | 15 ++-
 1 file changed, 2 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/comedi/drivers/dyna_pci10xx.c 
b/drivers/staging/comedi/drivers/dyna_pci10xx.c
index bd804f1..82002c4 100644
--- a/drivers/staging/comedi/drivers/dyna_pci10xx.c
+++ b/drivers/staging/comedi/drivers/dyna_pci10xx.c
@@ -45,8 +45,6 @@
 
 #define READ_TIMEOUT 50
 
-static DEFINE_MUTEX(start_stop_sem);
-
 static const struct comedi_lrange range_pci1050_ai = { 3, {
  BIP_RANGE(10),
  BIP_RANGE(5),
@@ -267,20 +265,15 @@ static int dyna_pci10xx_attach(struct comedi_device *dev,
struct comedi_subdevice *s;
int ret;
 
-   mutex_lock(start_stop_sem);
-
if (alloc_private(dev, sizeof(struct dyna_pci10xx_private))  0) {
printk(KERN_ERR comedi: dyna_pci10xx: 
failed to allocate memory!\n);
-   mutex_unlock(start_stop_sem);
return -ENOMEM;
}
 
pcidev = dyna_pci10xx_find_pci_dev(dev, it);
-   if (!pcidev) {
-   mutex_unlock(start_stop_sem);
+   if (!pcidev)
return -EIO;
-   }
devpriv-pci_dev = pcidev;
 
dev-board_name = thisboard-name;
@@ -289,7 +282,6 @@ static int dyna_pci10xx_attach(struct comedi_device *dev,
if (comedi_pci_enable(pcidev, DRV_NAME)) {
printk(KERN_ERR comedi: dyna_pci10xx: 
failed to enable PCI device and request regions!);
-   mutex_unlock(start_stop_sem);
return -EIO;
}
 
@@ -306,10 +298,8 @@ static int dyna_pci10xx_attach(struct comedi_device *dev,
devpriv-BADR5 = pci_resource_start(pcidev, 5);
 
ret = comedi_alloc_subdevices(dev, 4);
-   if (ret) {
-   mutex_unlock(start_stop_sem);
+   if (ret)
return ret;
-   }
 
/* analog input */
s = dev-subdevices + 0;
@@ -353,7 +343,6 @@ static int dyna_pci10xx_attach(struct comedi_device *dev,
s-insn_bits = dyna_pci10xx_do_insn_bits;
 
devpriv-valid = 1;
-   mutex_unlock(start_stop_sem);
 
printk(KERN_INFO comedi: dyna_pci10xx: %s - device setup completed!\n,
thisboard-name);
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 72/90] staging: comedi: dyna_pci10xx: remove 'valid' from the private data

2012-07-18 Thread H Hartley Sweeten
This variable is set at the end of the attach but never used
in the driver. Remove it.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/dyna_pci10xx.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/staging/comedi/drivers/dyna_pci10xx.c 
b/drivers/staging/comedi/drivers/dyna_pci10xx.c
index 82002c4..24c5cd2 100644
--- a/drivers/staging/comedi/drivers/dyna_pci10xx.c
+++ b/drivers/staging/comedi/drivers/dyna_pci10xx.c
@@ -101,7 +101,6 @@ static const struct boardtype boardtypes[] = {
 
 struct dyna_pci10xx_private {
struct pci_dev *pci_dev;/*  ptr to PCI device */
-   char valid; /*  card is usable */
struct mutex mutex;
 
/* device base address registers */
@@ -342,8 +341,6 @@ static int dyna_pci10xx_attach(struct comedi_device *dev,
s-state = 0;
s-insn_bits = dyna_pci10xx_do_insn_bits;
 
-   devpriv-valid = 1;
-
printk(KERN_INFO comedi: dyna_pci10xx: %s - device setup completed!\n,
thisboard-name);
 
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 73/90] staging: comedi: dyna_pci10xx: remove unused bars from the private data

2012-07-18 Thread H Hartley Sweeten
All of the pci device base address registers are saved in the private
data but only bar2 and bar3 are used by the driver. Remove the others.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/dyna_pci10xx.c | 7 +--
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/staging/comedi/drivers/dyna_pci10xx.c 
b/drivers/staging/comedi/drivers/dyna_pci10xx.c
index 24c5cd2..95ee422 100644
--- a/drivers/staging/comedi/drivers/dyna_pci10xx.c
+++ b/drivers/staging/comedi/drivers/dyna_pci10xx.c
@@ -104,7 +104,7 @@ struct dyna_pci10xx_private {
struct mutex mutex;
 
/* device base address registers */
-   unsigned long BADR0, BADR1, BADR2, BADR3, BADR4, BADR5;
+   unsigned long BADR2, BADR3;
 };
 
 #define thisboard ((const struct boardtype *)dev-board_ptr)
@@ -288,13 +288,8 @@ static int dyna_pci10xx_attach(struct comedi_device *dev,
 
printk(KERN_INFO comedi: dyna_pci10xx: device found!\n);
 
-   /* initialize device base address registers */
-   devpriv-BADR0 = pci_resource_start(pcidev, 0);
-   devpriv-BADR1 = pci_resource_start(pcidev, 1);
devpriv-BADR2 = pci_resource_start(pcidev, 2);
devpriv-BADR3 = pci_resource_start(pcidev, 3);
-   devpriv-BADR4 = pci_resource_start(pcidev, 4);
-   devpriv-BADR5 = pci_resource_start(pcidev, 5);
 
ret = comedi_alloc_subdevices(dev, 4);
if (ret)
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 74/90] staging: comedi: dyna_pci10xx: use dev-iobase

2012-07-18 Thread H Hartley Sweeten
Use dev-iobase to hold one of the pci base addresses used
by the driver instead of carrying it in the private data.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/dyna_pci10xx.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/comedi/drivers/dyna_pci10xx.c 
b/drivers/staging/comedi/drivers/dyna_pci10xx.c
index 95ee422..e7086b1 100644
--- a/drivers/staging/comedi/drivers/dyna_pci10xx.c
+++ b/drivers/staging/comedi/drivers/dyna_pci10xx.c
@@ -104,7 +104,7 @@ struct dyna_pci10xx_private {
struct mutex mutex;
 
/* device base address registers */
-   unsigned long BADR2, BADR3;
+   unsigned long BADR3;
 };
 
 #define thisboard ((const struct boardtype *)dev-board_ptr)
@@ -132,11 +132,11 @@ static int dyna_pci10xx_insn_read_ai(struct comedi_device 
*dev,
for (n = 0; n  insn-n; n++) {
/* trigger conversion */
smp_mb();
-   outw_p(0x + range + chan, devpriv-BADR2 + 2);
+   outw_p(0x + range + chan, dev-iobase + 2);
udelay(10);
/* read data */
for (counter = 0; counter  READ_TIMEOUT; counter++) {
-   d = inw_p(devpriv-BADR2);
+   d = inw_p(dev-iobase);
 
/* check if read is successful if the EOC bit is set */
if (d  (1  15))
@@ -172,7 +172,7 @@ static int dyna_pci10xx_insn_write_ao(struct comedi_device 
*dev,
for (n = 0; n  insn-n; n++) {
smp_mb();
/* trigger conversion and write data */
-   outw_p(data[n], devpriv-BADR2);
+   outw_p(data[n], dev-iobase);
udelay(10);
}
mutex_unlock(devpriv-mutex);
@@ -288,7 +288,7 @@ static int dyna_pci10xx_attach(struct comedi_device *dev,
 
printk(KERN_INFO comedi: dyna_pci10xx: device found!\n);
 
-   devpriv-BADR2 = pci_resource_start(pcidev, 2);
+   dev-iobase = pci_resource_start(pcidev, 2);
devpriv-BADR3 = pci_resource_start(pcidev, 3);
 
ret = comedi_alloc_subdevices(dev, 4);
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 75/90] staging: comedi: dyna_pci10xx: store the pci_dev in the comedi_device

2012-07-18 Thread H Hartley Sweeten
Use the hw_dev pointer in the comedi_device struct to hold the
pci_dev instead of carrying it in the private data.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/dyna_pci10xx.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/comedi/drivers/dyna_pci10xx.c 
b/drivers/staging/comedi/drivers/dyna_pci10xx.c
index e7086b1..6821f87 100644
--- a/drivers/staging/comedi/drivers/dyna_pci10xx.c
+++ b/drivers/staging/comedi/drivers/dyna_pci10xx.c
@@ -100,10 +100,7 @@ static const struct boardtype boardtypes[] = {
 };
 
 struct dyna_pci10xx_private {
-   struct pci_dev *pci_dev;/*  ptr to PCI device */
struct mutex mutex;
-
-   /* device base address registers */
unsigned long BADR3;
 };
 
@@ -273,7 +270,7 @@ static int dyna_pci10xx_attach(struct comedi_device *dev,
pcidev = dyna_pci10xx_find_pci_dev(dev, it);
if (!pcidev)
return -EIO;
-   devpriv-pci_dev = pcidev;
+   comedi_set_hw_dev(dev, pcidev-dev);
 
dev-board_name = thisboard-name;
dev-irq = 0;
@@ -344,9 +341,12 @@ static int dyna_pci10xx_attach(struct comedi_device *dev,
 
 static void dyna_pci10xx_detach(struct comedi_device *dev)
 {
-   if (devpriv  devpriv-pci_dev) {
-   comedi_pci_disable(devpriv-pci_dev);
+   struct pci_dev *pcidev = comedi_to_pci_dev(dev);
+
+   if (devpriv)
mutex_destroy(devpriv-mutex);
+   if (pcidev) {
+   comedi_pci_disable(pcidev);
}
 }
 
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 76/90] staging: comedi: dyna_pci10xx: fix detach

2012-07-18 Thread H Hartley Sweeten
The detach for this driver is missing the check to make sure
that the pci device is enabled before disabling it.

It's also missing the pci_dev_put().

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/dyna_pci10xx.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/comedi/drivers/dyna_pci10xx.c 
b/drivers/staging/comedi/drivers/dyna_pci10xx.c
index 6821f87..064be9a 100644
--- a/drivers/staging/comedi/drivers/dyna_pci10xx.c
+++ b/drivers/staging/comedi/drivers/dyna_pci10xx.c
@@ -346,7 +346,9 @@ static void dyna_pci10xx_detach(struct comedi_device *dev)
if (devpriv)
mutex_destroy(devpriv-mutex);
if (pcidev) {
-   comedi_pci_disable(pcidev);
+   if (dev-iobase)
+   comedi_pci_disable(pcidev);
+   pci_dev_put(pcidev);
}
 }
 
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 77/90] staging: comedi: ke_counter: factor out the find pci device code

2012-07-18 Thread H Hartley Sweeten
Factor the find pci device code out of the attach function.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/ke_counter.c | 37 -
 1 file changed, 26 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ke_counter.c 
b/drivers/staging/comedi/drivers/ke_counter.c
index 019e91a..f0b8652 100644
--- a/drivers/staging/comedi/drivers/ke_counter.c
+++ b/drivers/staging/comedi/drivers/ke_counter.c
@@ -122,18 +122,12 @@ static int cnt_rinsn(struct comedi_device *dev,
return 1;
 }
 
-static int cnt_attach(struct comedi_device *dev, struct comedi_devconfig *it)
+static struct pci_dev *cnt_find_pci_dev(struct comedi_device *dev,
+   struct comedi_devconfig *it)
 {
-   struct comedi_subdevice *subdevice;
-   struct pci_dev *pci_device = NULL;
struct cnt_board_struct *board;
-   unsigned long io_base;
-   int error, i;
-
-   /* allocate device private structure */
-   error = alloc_private(dev, sizeof(struct cnt_device_private));
-   if (error  0)
-   return error;
+   struct pci_dev *pci_device = NULL;
+   int i;
 
/* Probe the device to determine what device in the series it is. */
for_each_pci_dev(pci_device) {
@@ -166,14 +160,35 @@ static int cnt_attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
printk(KERN_WARNING
   comedi%d: no supported board found! (req. bus/slot: %d/%d)\n,
   dev-minor, it-options[0], it-options[1]);
-   return -EIO;
+   return NULL;
 
 found:
printk(KERN_INFO
   comedi%d: found %s at PCI bus %d, slot %d\n, dev-minor,
   board-name, pci_device-bus-number,
   PCI_SLOT(pci_device-devfn));
+   return pci_device;
+}
+
+static int cnt_attach(struct comedi_device *dev, struct comedi_devconfig *it)
+{
+   struct pci_dev *pci_device;
+   struct comedi_subdevice *subdevice;
+   struct cnt_board_struct *board;
+   unsigned long io_base;
+   int error;
+
+   /* allocate device private structure */
+   error = alloc_private(dev, sizeof(struct cnt_device_private));
+   if (error  0)
+   return error;
+
+   pci_device = cnt_find_pci_dev(dev, it);
+   if (!pci_device)
+   return -EIO;
devpriv-pcidev = pci_device;
+   board = (struct cnt_board_struct *)dev-board_ptr;
+
dev-board_name = board-name;
 
/* enable PCI device and request regions */
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 78/90] staging: comedi: ke_counter: cleanup find pci device code

2012-07-18 Thread H Hartley Sweeten
Cleanup the find pci device code so that it follows the style
of the other comedi pci drivers.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/ke_counter.c | 60 +++--
 1 file changed, 23 insertions(+), 37 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ke_counter.c 
b/drivers/staging/comedi/drivers/ke_counter.c
index f0b8652..826e6c2 100644
--- a/drivers/staging/comedi/drivers/ke_counter.c
+++ b/drivers/staging/comedi/drivers/ke_counter.c
@@ -125,49 +125,35 @@ static int cnt_rinsn(struct comedi_device *dev,
 static struct pci_dev *cnt_find_pci_dev(struct comedi_device *dev,
struct comedi_devconfig *it)
 {
-   struct cnt_board_struct *board;
-   struct pci_dev *pci_device = NULL;
+   const struct cnt_board_struct *board;
+   struct pci_dev *pcidev = NULL;
+   int bus = it-options[0];
+   int slot = it-options[1];
int i;
 
/* Probe the device to determine what device in the series it is. */
-   for_each_pci_dev(pci_device) {
-   if (pci_device-vendor == PCI_VENDOR_ID_KOLTER) {
-   for (i = 0; i  cnt_board_nbr; i++) {
-   if (cnt_boards[i].device_id ==
-   pci_device-device) {
-   /* was a particular bus/slot requested? 
*/
-   if ((it-options[0] != 0)
-   || (it-options[1] != 0)) {
-   /* are we on the wrong 
bus/slot? */
-   if (pci_device-bus-number !=
-   it-options[0]
-   ||
-   PCI_SLOT(pci_device-devfn)
-   != it-options[1]) {
-   continue;
-   }
-   }
-
-   dev-board_ptr = cnt_boards + i;
-   board =
-   (struct cnt_board_struct *)
-   dev-board_ptr;
-   goto found;
-   }
-   }
+   for_each_pci_dev(pcidev) {
+   if (bus || slot) {
+   if (pcidev-bus-number != bus ||
+   PCI_SLOT(pcidev-devfn) != slot)
+   continue;
+   }
+   if (pcidev-vendor != PCI_VENDOR_ID_KOLTER)
+   continue;
+
+   for (i = 0; i  cnt_board_nbr; i++) {
+   board = cnt_boards[i];
+   if (board-device_id != pcidev-device)
+   continue;
+
+   dev-board_ptr = board;
+   return pcidev;
}
}
-   printk(KERN_WARNING
-  comedi%d: no supported board found! (req. bus/slot: %d/%d)\n,
-  dev-minor, it-options[0], it-options[1]);
+   dev_err(dev-class_dev,
+   No supported board found! (req. bus %d, slot %d)\n,
+   bus, slot);
return NULL;
-
-found:
-   printk(KERN_INFO
-  comedi%d: found %s at PCI bus %d, slot %d\n, dev-minor,
-  board-name, pci_device-bus-number,
-  PCI_SLOT(pci_device-devfn));
-   return pci_device;
 }
 
 static int cnt_attach(struct comedi_device *dev, struct comedi_devconfig *it)
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 79/90] staging: comedi: ke_counter: minor cleanup of cnt_attach()

2012-07-18 Thread H Hartley Sweeten
Cleanup the attach function a bit to follow the style of
the other comedi pci drivers.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/ke_counter.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ke_counter.c 
b/drivers/staging/comedi/drivers/ke_counter.c
index 826e6c2..78eb8d4 100644
--- a/drivers/staging/comedi/drivers/ke_counter.c
+++ b/drivers/staging/comedi/drivers/ke_counter.c
@@ -158,9 +158,9 @@ static struct pci_dev *cnt_find_pci_dev(struct 
comedi_device *dev,
 
 static int cnt_attach(struct comedi_device *dev, struct comedi_devconfig *it)
 {
-   struct pci_dev *pci_device;
+   const struct cnt_board_struct *board;
+   struct pci_dev *pcidev;
struct comedi_subdevice *subdevice;
-   struct cnt_board_struct *board;
unsigned long io_base;
int error;
 
@@ -169,16 +169,16 @@ static int cnt_attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
if (error  0)
return error;
 
-   pci_device = cnt_find_pci_dev(dev, it);
-   if (!pci_device)
+   pcidev = cnt_find_pci_dev(dev, it);
+   if (!pcidev)
return -EIO;
-   devpriv-pcidev = pci_device;
-   board = (struct cnt_board_struct *)dev-board_ptr;
+   devpriv-pcidev = pcidev;
+   board = comedi_board(dev);
 
dev-board_name = board-name;
 
/* enable PCI device and request regions */
-   error = comedi_pci_enable(pci_device, CNT_DRIVER_NAME);
+   error = comedi_pci_enable(pcidev, CNT_DRIVER_NAME);
if (error  0) {
printk(KERN_WARNING comedi%d: 
   failed to enable PCI device and request regions!\n,
@@ -187,7 +187,7 @@ static int cnt_attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
}
 
/* read register base address [PCI_BASE_ADDRESS #0] */
-   io_base = pci_resource_start(pci_device, 0);
+   io_base = pci_resource_start(pcidev, 0);
dev-iobase = io_base;
 
error = comedi_alloc_subdevices(dev, 1);
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 80/90] staging: comedi: ke_counter: store the pci_dev in the comedi_device

2012-07-18 Thread H Hartley Sweeten
Use the hw_dev pointer in the comedi_device struct to hold the
pci_dev instead of carrying it in the private data.

Since the pci_dev was the only thing in the private data, remove
the struct, the devpriv macro, and it's allocation.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/ke_counter.c | 24 ++--
 1 file changed, 6 insertions(+), 18 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ke_counter.c 
b/drivers/staging/comedi/drivers/ke_counter.c
index 78eb8d4..4153977 100644
--- a/drivers/staging/comedi/drivers/ke_counter.c
+++ b/drivers/staging/comedi/drivers/ke_counter.c
@@ -64,15 +64,6 @@ static const struct cnt_board_struct cnt_boards[] = {
 
 #define cnt_board_nbr (sizeof(cnt_boards)/sizeof(struct cnt_board_struct))
 
-/*-- device private structure ---*/
-
-struct cnt_device_private {
-
-   struct pci_dev *pcidev;
-};
-
-#define devpriv ((struct cnt_device_private *)dev-private)
-
 /*-- counter write --*/
 
 /* This should be used only for resetting the counters; maybe it is better
@@ -164,15 +155,10 @@ static int cnt_attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
unsigned long io_base;
int error;
 
-   /* allocate device private structure */
-   error = alloc_private(dev, sizeof(struct cnt_device_private));
-   if (error  0)
-   return error;
-
pcidev = cnt_find_pci_dev(dev, it);
if (!pcidev)
return -EIO;
-   devpriv-pcidev = pcidev;
+   comedi_set_hw_dev(dev, pcidev-dev);
board = comedi_board(dev);
 
dev-board_name = board-name;
@@ -219,10 +205,12 @@ static int cnt_attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
 
 static void cnt_detach(struct comedi_device *dev)
 {
-   if (devpriv  devpriv-pcidev) {
+   struct pci_dev *pcidev = comedi_to_pci_dev(dev);
+
+   if (pcidev) {
if (dev-iobase)
-   comedi_pci_disable(devpriv-pcidev);
-   pci_dev_put(devpriv-pcidev);
+   comedi_pci_disable(pcidev);
+   pci_dev_put(pcidev);
}
 }
 
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 81/90] staging: comedi: ke_counter: remove the cnt_board_nbr macro

2012-07-18 Thread H Hartley Sweeten
This macro is an open-coded version of ARRAY_SIZE(). Use that
instead.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/ke_counter.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ke_counter.c 
b/drivers/staging/comedi/drivers/ke_counter.c
index 4153977..d4e9292 100644
--- a/drivers/staging/comedi/drivers/ke_counter.c
+++ b/drivers/staging/comedi/drivers/ke_counter.c
@@ -62,8 +62,6 @@ static const struct cnt_board_struct cnt_boards[] = {
 .cnt_bits = 24}
 };
 
-#define cnt_board_nbr (sizeof(cnt_boards)/sizeof(struct cnt_board_struct))
-
 /*-- counter write --*/
 
 /* This should be used only for resetting the counters; maybe it is better
@@ -132,7 +130,7 @@ static struct pci_dev *cnt_find_pci_dev(struct 
comedi_device *dev,
if (pcidev-vendor != PCI_VENDOR_ID_KOLTER)
continue;
 
-   for (i = 0; i  cnt_board_nbr; i++) {
+   for (i = 0; i  ARRAY_SIZE(cnt_boards); i++) {
board = cnt_boards[i];
if (board-device_id != pcidev-device)
continue;
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 82/90] staging: comedi: me_daq: factor out the find pci device code

2012-07-18 Thread H Hartley Sweeten
Factor the find pci device code out of the attach function.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/me_daq.c | 49 -
 1 file changed, 30 insertions(+), 19 deletions(-)

diff --git a/drivers/staging/comedi/drivers/me_daq.c 
b/drivers/staging/comedi/drivers/me_daq.c
index 1803d66..dc0fbbd 100644
--- a/drivers/staging/comedi/drivers/me_daq.c
+++ b/drivers/staging/comedi/drivers/me_daq.c
@@ -610,23 +610,11 @@ static int me_reset(struct comedi_device *dev)
return 0;
 }
 
-static int me_attach(struct comedi_device *dev, struct comedi_devconfig *it)
+static struct pci_dev *me_find_pci_dev(struct comedi_device *dev,
+  struct comedi_devconfig *it)
 {
struct pci_dev *pci_device = NULL;
-   struct comedi_subdevice *subdevice;
-   struct me_board *board;
-   resource_size_t plx_regbase_tmp;
-   unsigned long plx_regbase_size_tmp;
-   resource_size_t me_regbase_tmp;
-   unsigned long me_regbase_size_tmp;
-   resource_size_t swap_regbase_tmp;
-   unsigned long swap_regbase_size_tmp;
-   resource_size_t regbase_tmp;
-   int result, error, i;
-
-   /* Allocate private memory */
-   if (alloc_private(dev, sizeof(struct me_private_data))  0)
-   return -ENOMEM;
+   int i;
 
/* Probe the device to determine what device in the series it is. */
for_each_pci_dev(pci_device) {
@@ -652,9 +640,6 @@ static int me_attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
}
 
dev-board_ptr = me_boards + i;
-   board =
-   (struct me_board *)dev-board_ptr;
-   dev_private-pci_device = pci_device;
goto found;
}
}
@@ -664,12 +649,38 @@ static int me_attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
printk(KERN_ERR
   comedi%d: no supported board found! (req. bus/slot : %d/%d)\n,
   dev-minor, it-options[0], it-options[1]);
-   return -EIO;
+   return NULL;
 
 found:
printk(KERN_INFO comedi%d: found %s at PCI bus %d, slot %d\n,
   dev-minor, me_boards[i].name,
   pci_device-bus-number, PCI_SLOT(pci_device-devfn));
+   return pci_device;
+}
+
+static int me_attach(struct comedi_device *dev, struct comedi_devconfig *it)
+{
+   struct pci_dev *pci_device;
+   struct comedi_subdevice *subdevice;
+   struct me_board *board;
+   resource_size_t plx_regbase_tmp;
+   unsigned long plx_regbase_size_tmp;
+   resource_size_t me_regbase_tmp;
+   unsigned long me_regbase_size_tmp;
+   resource_size_t swap_regbase_tmp;
+   unsigned long swap_regbase_size_tmp;
+   resource_size_t regbase_tmp;
+   int result, error;
+
+   /* Allocate private memory */
+   if (alloc_private(dev, sizeof(struct me_private_data))  0)
+   return -ENOMEM;
+
+   pci_device = me_find_pci_dev(dev, it);
+   if (!pci_device)
+   return -EIO;
+   dev_private-pci_device = pci_device;
+   board = (struct me_board *)dev-board_ptr;
 
/* Enable PCI device and request PCI regions */
if (comedi_pci_enable(pci_device, ME_DRIVER_NAME)  0) {
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 83/90] staging: comedi: me_daq: cleanup find pci device code

2012-07-18 Thread H Hartley Sweeten
Cleanup the find pci device code so that it follows the style
of the other comedi pci drivers.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/me_daq.c | 63 -
 1 file changed, 23 insertions(+), 40 deletions(-)

diff --git a/drivers/staging/comedi/drivers/me_daq.c 
b/drivers/staging/comedi/drivers/me_daq.c
index dc0fbbd..cd66af9 100644
--- a/drivers/staging/comedi/drivers/me_daq.c
+++ b/drivers/staging/comedi/drivers/me_daq.c
@@ -231,8 +231,6 @@ static const struct me_board me_boards[] = {
 }
 };
 
-#define me_board_nbr (sizeof(me_boards)/sizeof(struct me_board))
-
 /* Private data structure */
 struct me_private_data {
struct pci_dev *pci_device;
@@ -613,49 +611,34 @@ static int me_reset(struct comedi_device *dev)
 static struct pci_dev *me_find_pci_dev(struct comedi_device *dev,
   struct comedi_devconfig *it)
 {
-   struct pci_dev *pci_device = NULL;
+   const struct me_board *board;
+   struct pci_dev *pcidev = NULL;
+   int bus = it-options[0];
+   int slot = it-options[1];
int i;
 
-   /* Probe the device to determine what device in the series it is. */
-   for_each_pci_dev(pci_device) {
-   if (pci_device-vendor == PCI_VENDOR_ID_MEILHAUS) {
-   for (i = 0; i  me_board_nbr; i++) {
-   if (me_boards[i].device_id ==
-   pci_device-device) {
-   /*
-* was a particular bus/slot requested?
-*/
-   if ((it-options[0] != 0)
-   || (it-options[1] != 0)) {
-   /*
-* are we on the wrong bus/slot?
-*/
-   if (pci_device-bus-number !=
-   it-options[0]
-   ||
-   PCI_SLOT(pci_device-devfn)
-   != it-options[1]) {
-   continue;
-   }
-   }
-
-   dev-board_ptr = me_boards + i;
-   goto found;
-   }
-   }
+   for_each_pci_dev(pcidev) {
+   if (bus || slot) {
+   if (pcidev-bus-number != bus ||
+   PCI_SLOT(pcidev-devfn) != slot)
+   continue;
}
-   }
+   if (pcidev-vendor != PCI_VENDOR_ID_MEILHAUS)
+   continue;
 
-   printk(KERN_ERR
-  comedi%d: no supported board found! (req. bus/slot : %d/%d)\n,
-  dev-minor, it-options[0], it-options[1]);
-   return NULL;
+   for (i = 0; i  ARRAY_SIZE(me_boards); i++) {
+   board = me_boards[i];
+   if (board-device_id != pcidev-device)
+   continue;
 
-found:
-   printk(KERN_INFO comedi%d: found %s at PCI bus %d, slot %d\n,
-  dev-minor, me_boards[i].name,
-  pci_device-bus-number, PCI_SLOT(pci_device-devfn));
-   return pci_device;
+   dev-board_ptr = board;
+   return pcidev;
+   }
+   }
+   dev_err(dev-class_dev,
+   No supported board found! (req. bus %d, slot %d)\n,
+   bus, slot);
+   return NULL;
 }
 
 static int me_attach(struct comedi_device *dev, struct comedi_devconfig *it)
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 84/90] staging: comedi: me_daq: store the pci_dev in the comedi_device

2012-07-18 Thread H Hartley Sweeten
Use the hw_dev pointer in the comedi_device struct to hold the
pci_dev instead of carrying it in the private data.

Since the pci_dev was the only thing in the private data, remove
the struct, the devpriv macro, and it's allocation.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/me_daq.c | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/comedi/drivers/me_daq.c 
b/drivers/staging/comedi/drivers/me_daq.c
index cd66af9..8c6f8b9 100644
--- a/drivers/staging/comedi/drivers/me_daq.c
+++ b/drivers/staging/comedi/drivers/me_daq.c
@@ -233,7 +233,6 @@ static const struct me_board me_boards[] = {
 
 /* Private data structure */
 struct me_private_data {
-   struct pci_dev *pci_device;
void __iomem *plx_regbase;  /* PLX configuration base address */
void __iomem *me_regbase;   /* Base address of the Meilhaus card */
unsigned long plx_regbase_size; /* Size of PLX configuration space */
@@ -662,7 +661,7 @@ static int me_attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
pci_device = me_find_pci_dev(dev, it);
if (!pci_device)
return -EIO;
-   dev_private-pci_device = pci_device;
+   comedi_set_hw_dev(dev, pci_device-dev);
board = (struct me_board *)dev-board_ptr;
 
/* Enable PCI device and request PCI regions */
@@ -799,6 +798,8 @@ static int me_attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
 
 static void me_detach(struct comedi_device *dev)
 {
+   struct pci_dev *pcidev = comedi_to_pci_dev(dev);
+
if (dev_private) {
if (dev_private-me_regbase) {
me_reset(dev);
@@ -806,11 +807,11 @@ static void me_detach(struct comedi_device *dev)
}
if (dev_private-plx_regbase)
iounmap(dev_private-plx_regbase);
-   if (dev_private-pci_device) {
-   if (dev_private-plx_regbase_size)
-   comedi_pci_disable(dev_private-pci_device);
-   pci_dev_put(dev_private-pci_device);
-   }
+   }
+   if (pcidev) {
+   if (dev_private-plx_regbase_size)
+   comedi_pci_disable(pcidev);
+   pci_dev_put(pcidev);
}
 }
 
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 85/90] staging: comedi: rtd520: remove the debug print of the pci addresses

2012-07-18 Thread H Hartley Sweeten
This is just noise.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/rtd520.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/staging/comedi/drivers/rtd520.c 
b/drivers/staging/comedi/drivers/rtd520.c
index 9998d6b..02be4dd 100644
--- a/drivers/staging/comedi/drivers/rtd520.c
+++ b/drivers/staging/comedi/drivers/rtd520.c
@@ -1676,10 +1676,6 @@ static int rtd_attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
if (!devpriv-las0 || !devpriv-las1 || !devpriv-lcfg)
return -ENOMEM;
 
-
-   DPRINTK(%s: LAS0=%llx, LAS1=%llx, CFG=%llx.\n, dev-board_name,
-   (unsigned long long)physLas0, (unsigned long long)physLas1,
-   (unsigned long long)physLcfg);
{   /* The RTD driver does this */
unsigned char pci_latency;
u16 revision;
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 86/90] staging: comedi: rtd520: remove 'got_regions' from private data

2012-07-18 Thread H Hartley Sweeten
The 'got_regions' variable in the private data is used as a flag
for the detach to know if the pci device has been enabled.

Typically the dev-iobase variable is used to indicate this in
all the other comedi drivers. Do the same here for consistancy.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/rtd520.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/comedi/drivers/rtd520.c 
b/drivers/staging/comedi/drivers/rtd520.c
index 02be4dd..aeccae9 100644
--- a/drivers/staging/comedi/drivers/rtd520.c
+++ b/drivers/staging/comedi/drivers/rtd520.c
@@ -312,7 +312,6 @@ struct rtdPrivate {
 
/* PCI device info */
struct pci_dev *pci_dev;
-   int got_regions;/* non-zero if PCI regions owned */
 
/* channel list info */
/* chanBipolar tracks whether a channel is bipolar (and needs +2048) */
@@ -1623,7 +1622,6 @@ static int rtd_attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
struct rtdPrivate *devpriv;
struct comedi_subdevice *s;
int ret;
-   resource_size_t physLas0;   /* configuration */
resource_size_t physLas1;   /* data area */
resource_size_t physLcfg;   /* PLX9080 */
 #ifdef USE_DMA
@@ -1658,18 +1656,17 @@ static int rtd_attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
printk(KERN_INFO Failed to enable PCI device and request 
regions.\n);
return ret;
}
-   devpriv-got_regions = 1;
 
/*
 * Initialize base addresses
 */
/* Get the physical address from PCI config */
-   physLas0 = pci_resource_start(devpriv-pci_dev, LAS0_PCIINDEX);
+   dev-iobase = pci_resource_start(devpriv-pci_dev, LAS0_PCIINDEX);
physLas1 = pci_resource_start(devpriv-pci_dev, LAS1_PCIINDEX);
physLcfg = pci_resource_start(devpriv-pci_dev, LCFG_PCIINDEX);
/* Now have the kernel map this into memory */
/* ASSUME page aligned */
-   devpriv-las0 = ioremap_nocache(physLas0, LAS0_PCISIZE);
+   devpriv-las0 = ioremap_nocache(dev-iobase, LAS0_PCISIZE);
devpriv-las1 = ioremap_nocache(physLas1, LAS1_PCISIZE);
devpriv-lcfg = ioremap_nocache(physLcfg, LCFG_PCISIZE);
 
@@ -2000,7 +1997,7 @@ static void rtd_detach(struct comedi_device *dev)
if (devpriv-lcfg)
iounmap(devpriv-lcfg);
if (devpriv-pci_dev) {
-   if (devpriv-got_regions)
+   if (dev-iobase)
comedi_pci_disable(devpriv-pci_dev);
pci_dev_put(devpriv-pci_dev);
}
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 87/90] staging: comedi: rtd520: remove the '#if 0' code in the attach

2012-07-18 Thread H Hartley Sweeten
This driver has code #if 0'ed out that would allow cleaning up
the attach if there was an error. The comedi core currently
calls the detach function to do this if the attach fails.

Remove the #if 0'ed out code.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/rtd520.c | 46 -
 1 file changed, 46 deletions(-)

diff --git a/drivers/staging/comedi/drivers/rtd520.c 
b/drivers/staging/comedi/drivers/rtd520.c
index aeccae9..d1753e2 100644
--- a/drivers/staging/comedi/drivers/rtd520.c
+++ b/drivers/staging/comedi/drivers/rtd520.c
@@ -1886,52 +1886,6 @@ static int rtd_attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
printk(\ncomedi%d: rtd520 driver attached.\n, dev-minor);
 
return 1;
-
-#if 0
-   /* hit an error, clean up memory and return ret */
-/* rtd_attach_die_error: */
-#ifdef USE_DMA
-   for (index = 0; index  DMA_CHAIN_COUNT; index++) {
-   if (NULL != devpriv-dma0Buff[index]) { /* free buffer memory */
-   pci_free_consistent(devpriv-pci_dev,
-   sizeof(u16) * devpriv-fifoLen / 2,
-   devpriv-dma0Buff[index],
-   devpriv-dma0BuffPhysAddr[index]);
-   devpriv-dma0Buff[index] = NULL;
-   }
-   }
-   if (NULL != devpriv-dma0Chain) {
-   pci_free_consistent(devpriv-pci_dev,
-   sizeof(struct plx_dma_desc)
-   * DMA_CHAIN_COUNT,
-   devpriv-dma0Chain,
-   devpriv-dma0ChainPhysAddr);
-   devpriv-dma0Chain = NULL;
-   }
-#endif /* USE_DMA */
-   /* subdevices and priv are freed by the core */
-   if (dev-irq) {
-   writel(readl(devpriv-lcfg + LCFG_ITCSR) 
-   ~(ICS_PLIE | ICS_DMA0_E | ICS_DMA1_E),
-   devpriv-lcfg + LCFG_ITCSR);
-   free_irq(dev-irq, dev);
-   }
-
-   /* release all regions that were allocated */
-   if (devpriv-las0)
-   iounmap(devpriv-las0);
-
-   if (devpriv-las1)
-   iounmap(devpriv-las1);
-
-   if (devpriv-lcfg)
-   iounmap(devpriv-lcfg);
-
-   if (devpriv-pci_dev)
-   pci_dev_put(devpriv-pci_dev);
-
-   return ret;
-#endif
 }
 
 static void rtd_detach(struct comedi_device *dev)
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 88/90] staging: comedi: rtd520: store the pci_dev in the comedi_device

2012-07-18 Thread H Hartley Sweeten
Use the hw_dev pointer in the comedi_device struct to hold the
pci_dev instead of carrying it in the private data.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/rtd520.c | 48 -
 1 file changed, 24 insertions(+), 24 deletions(-)

diff --git a/drivers/staging/comedi/drivers/rtd520.c 
b/drivers/staging/comedi/drivers/rtd520.c
index d1753e2..112fdc3 100644
--- a/drivers/staging/comedi/drivers/rtd520.c
+++ b/drivers/staging/comedi/drivers/rtd520.c
@@ -310,9 +310,6 @@ struct rtdPrivate {
int transCount; /* # to transfer data. 0-1/2FIFO */
int flags;  /* flag event modes */
 
-   /* PCI device info */
-   struct pci_dev *pci_dev;
-
/* channel list info */
/* chanBipolar tracks whether a channel is bipolar (and needs +2048) */
unsigned char chanBipolar[RTD_MAX_CHANLIST / 8];/* bit array */
@@ -1620,6 +1617,7 @@ static int rtd_attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
 {  /* board name and options flags */
const struct rtdBoard *thisboard;
struct rtdPrivate *devpriv;
+   struct pci_dev *pcidev;
struct comedi_subdevice *s;
int ret;
resource_size_t physLas1;   /* data area */
@@ -1644,14 +1642,15 @@ static int rtd_attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
return -ENOMEM;
devpriv = dev-private;
 
-   devpriv-pci_dev = rtd_find_pci(dev, it);
-   if (!devpriv-pci_dev)
+   pcidev = rtd_find_pci(dev, it);
+   if (!pcidev)
return -EIO;
+   comedi_set_hw_dev(dev, pcidev-dev);
thisboard = comedi_board(dev);
 
dev-board_name = thisboard-name;
 
-   ret = comedi_pci_enable(devpriv-pci_dev, DRV_NAME);
+   ret = comedi_pci_enable(pcidev, DRV_NAME);
if (ret  0) {
printk(KERN_INFO Failed to enable PCI device and request 
regions.\n);
return ret;
@@ -1661,9 +1660,9 @@ static int rtd_attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
 * Initialize base addresses
 */
/* Get the physical address from PCI config */
-   dev-iobase = pci_resource_start(devpriv-pci_dev, LAS0_PCIINDEX);
-   physLas1 = pci_resource_start(devpriv-pci_dev, LAS1_PCIINDEX);
-   physLcfg = pci_resource_start(devpriv-pci_dev, LCFG_PCIINDEX);
+   dev-iobase = pci_resource_start(pcidev, LAS0_PCIINDEX);
+   physLas1 = pci_resource_start(pcidev, LAS1_PCIINDEX);
+   physLcfg = pci_resource_start(pcidev, LCFG_PCIINDEX);
/* Now have the kernel map this into memory */
/* ASSUME page aligned */
devpriv-las0 = ioremap_nocache(dev-iobase, LAS0_PCISIZE);
@@ -1678,16 +1677,16 @@ static int rtd_attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
u16 revision;
/*uint32_t epld_version; */
 
-   pci_read_config_word(devpriv-pci_dev, PCI_REVISION_ID,
+   pci_read_config_word(pcidev, PCI_REVISION_ID,
 revision);
DPRINTK(%s: PCI revision %d.\n, dev-board_name, revision);
 
-   pci_read_config_byte(devpriv-pci_dev,
+   pci_read_config_byte(pcidev,
 PCI_LATENCY_TIMER, pci_latency);
if (pci_latency  32) {
printk(KERN_INFO %s: PCI latency changed from %d to 
%d\n,
   dev-board_name, pci_latency, 32);
-   pci_write_config_byte(devpriv-pci_dev,
+   pci_write_config_byte(pcidev,
  PCI_LATENCY_TIMER, 32);
} else {
DPRINTK(rtd520: PCI latency = %d\n, pci_latency);
@@ -1790,15 +1789,15 @@ static int rtd_attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
/* TODO: set user out source ??? */
 
/* check if our interrupt is available and get it */
-   ret = request_irq(devpriv-pci_dev-irq, rtd_interrupt,
+   ret = request_irq(pcidev-irq, rtd_interrupt,
  IRQF_SHARED, DRV_NAME, dev);
 
if (ret  0) {
printk(Could not get interrupt! (%u)\n,
-  devpriv-pci_dev-irq);
+  pcidev-irq);
return ret;
}
-   dev-irq = devpriv-pci_dev-irq;
+   dev-irq = pcidev-irq;
printk(KERN_INFO ( irq=%u ), dev-irq);
 
ret = rtd520_probe_fifo_depth(dev);
@@ -1820,7 +1819,7 @@ static int rtd_attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
 
for (index = 0; index  DMA_CHAIN_COUNT; index++) {
devpriv-dma0Buff[index] =
-   pci_alloc_consistent(devpriv

[PATCH 89/90] staging: comedi: aio_iiro_16: remove the private data

2012-07-18 Thread H Hartley Sweeten
The private data is not used by this driver. Remove the struct,
devpriv macro, and the allocation.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/aio_iiro_16.c | 11 ---
 1 file changed, 11 deletions(-)

diff --git a/drivers/staging/comedi/drivers/aio_iiro_16.c 
b/drivers/staging/comedi/drivers/aio_iiro_16.c
index 16f28f6..ba1e3bb 100644
--- a/drivers/staging/comedi/drivers/aio_iiro_16.c
+++ b/drivers/staging/comedi/drivers/aio_iiro_16.c
@@ -57,14 +57,6 @@ static const struct aio_iiro_16_board aio_iiro_16_boards[] = 
{
 .do_ = 16},
 };
 
-struct aio_iiro_16_private {
-   int data;
-   struct pci_dev *pci_dev;
-   unsigned int ao_readback[2];
-};
-
-#definedevpriv ((struct aio_iiro_16_private *) dev-private)
-
 static int aio_iiro_16_dio_insn_bits_write(struct comedi_device *dev,
   struct comedi_subdevice *s,
   struct comedi_insn *insn,
@@ -116,9 +108,6 @@ static int aio_iiro_16_attach(struct comedi_device *dev,
 
dev-iobase = iobase;
 
-   if (alloc_private(dev, sizeof(struct aio_iiro_16_private))  0)
-   return -ENOMEM;
-
ret = comedi_alloc_subdevices(dev, 2);
if (ret)
return ret;
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 90/90] staging: comedi: s526: remove unused variables in the private data

2012-07-18 Thread H Hartley Sweeten
The 'data' and 'pci_dev' variables in the private data are not used.
They appear to be cut-and-paste from the skel driver. Remove them.

Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
Cc: Ian Abbott abbo...@mev.co.uk
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/staging/comedi/drivers/s526.c | 8 
 1 file changed, 8 deletions(-)

diff --git a/drivers/staging/comedi/drivers/s526.c 
b/drivers/staging/comedi/drivers/s526.c
index 358380f..737a194 100644
--- a/drivers/staging/comedi/drivers/s526.c
+++ b/drivers/staging/comedi/drivers/s526.c
@@ -206,15 +206,7 @@ static const struct s526_board s526_boards[] = {
struct.
 */
 struct s526_private {
-
-   int data;
-
-   /* would be useful for a PCI device */
-   struct pci_dev *pci_dev;
-
-   /* Used for AO readback */
unsigned int ao_readback[2];
-
struct s526GPCTConfig s526_gpct_config[4];
unsigned short s526_ai_config;
 };
-- 
1.7.11

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: [PATCH 01/90] staging: comedi: comedidev.h: introduce comedi_to_pci_dev() helper

2012-07-19 Thread H Hartley Sweeten
On Thursday, July 19, 2012 2:23 AM, Ian Abbott wrote:
 On 2012-07-19 02:24, H Hartley Sweeten wrote:
 Introduce a wrapper for to_pci_dev() to allow the comedi pci drivers
 to store the pci_dev pointer in the comedi_device hw_dev variable and
 retrieve it easily.

 Signed-off-by: H Hartley Sweeten hswee...@visionengravers.com
 Cc: Ian Abbott abbo...@mev.co.uk
 Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
 ---
   drivers/staging/comedi/comedidev.h | 5 +
   1 file changed, 5 insertions(+)

 diff --git a/drivers/staging/comedi/comedidev.h 
 b/drivers/staging/comedi/comedidev.h
 index de8c99c..620222d 100644
 --- a/drivers/staging/comedi/comedidev.h
 +++ b/drivers/staging/comedi/comedidev.h
 @@ -446,6 +446,11 @@ static inline void comedi_set_hw_dev(struct 
 comedi_device *dev,
  }
   }

 +static inline struct pci_dev *comedi_to_pci_dev(struct comedi_device *dev)
 +{
 +return to_pci_dev(dev-hw_dev);
 +}
 +

 That needs to be something like:

   return dev-hw_dev ? to_pci_dev(dev-hw_dev) : NULL;

Hmm.. I'm not really sure.

I assumed that the container_of() macro would return NULL if the ptr passed to
it was NULL. But, I'm not sure how this actually unwinds for that case.

Greg, do you know if the NULL check is needed? It's is possible that the 
dev-hw_dev
pointer could be NULL.

Thanks,
Hartley



  1   2   3   4   5   6   7   8   9   10   >