re: staging: dgnc: use tty_alloc_driver instead of kcalloc

2016-05-03 Thread Dan Carpenter
Hello Daeseok Youn,

The patch 60b3109e5e2d: "staging: dgnc: use tty_alloc_driver instead
of kcalloc" from Apr 14, 2016, leads to the following static checker
warning:

drivers/staging/dgnc/dgnc_tty.c:229 dgnc_tty_register()
error: 'brd->print_driver' dereferencing possible ERR_PTR()

drivers/staging/dgnc/dgnc_tty.c
   217  /*
   218   * If we're doing transparent print, we have to do all of the 
above
   219   * again, separately so we don't get the LD confused about what 
major
   220   * we are when we get into the dgnc_tty_open() routine.
   221   */
   222  brd->print_driver = tty_alloc_driver(brd->maxports,
   223   TTY_DRIVER_REAL_RAW |
   224   TTY_DRIVER_DYNAMIC_DEV |
   225   TTY_DRIVER_HARDWARE_BREAK);

This function call needs error handling.

   226  
   227  snprintf(brd->print_name, MAXTTYNAMELEN, "pr_dgnc_%d_", 
brd->boardnum);
   228  
   229  brd->print_driver->name = brd->print_name;
   230  brd->print_driver->name_base = 0;
   231  brd->print_driver->major = brd->serial_driver->major;
   232  brd->print_driver->minor_start = 0x80;

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


Re: [PATCH 0/6] Intel Secure Guard Extensions

2016-05-03 Thread Dr. Greg Wettstein
On May 2, 11:37am, "Austin S. Hemmelgarn" wrote:
} Subject: Re: [PATCH 0/6] Intel Secure Guard Extensions

Good morning, I hope the day is starting out well for everyone.

> On 2016-04-29 16:17, Jarkko Sakkinen wrote:
> > On Tue, Apr 26, 2016 at 09:00:10PM +0200, Pavel Machek wrote:
> >> On Mon 2016-04-25 20:34:07, Jarkko Sakkinen wrote:
> >>> Intel(R) SGX is a set of CPU instructions that can be used by
> >>> applications to set aside private regions of code and data.  The code
> >>> outside the enclave is disallowed to access the memory inside the
> >>> enclave by the CPU access control.
> >>>
> >>> The firmware uses PRMRR registers to reserve an area of physical memory
> >>> called Enclave Page Cache (EPC). There is a hardware unit in the
> >>> processor called Memory Encryption Engine. The MEE encrypts and decrypts
> >>> the EPC pages as they enter and leave the processor package.
> >>
> >> What are non-evil use cases for this?
> >
> > I'm not sure what you mean by non-evil.

> I would think that this should be pretty straightforward.  Pretty
> much every security technology integrated in every computer in
> existence has the potential to be used by malware for various
> purposes.  Based on a cursory look at SGX, it is pretty easy to
> figure out how to use this to hide arbitrary code from virus
> scanners and the OS itself unless you have some way to force
> everything to be a debug enclave, which entirely defeats the stated
> purpose of the extensions.  I can see this being useful for tight
> embedded systems.  On a desktop which I have full control of
> physical access to though, it's something I'd immediately turn off,
> because the risk of misuse is so significant (I've done so on my new
> Thinkpad L560 too, although that's mostly because Linux doesn't
> support it yet).

We were somewhat surprised to see Intel announce the SGX driver for
Linux without a bit more community preparation given the nature of the
technology.  But, given the history of opacity around this technology,
it probably isn't surprising.  We thought it may be useful to offer a
few thoughts on this technology as discussion around integrating the
driver moves forward.

We have been following and analyzing this technology since the first
HASP paper was published detailing its development.  We have been
working to integrate, at least at the simulator level, portions of
this technology in solutions we deliver.  We have just recently begun
to acquire validated reference platforms to test these
implementations.

I told my associates the first time I reviewed this technology that
SGX has the ability to be a bit of a Pandora's box and it seems to be
following that course.

SGX belongs to a genre of solutions collectively known as Trusted
Execution Environments (TEE's).  The intent of these platforms is to
support data and application confidentiality and integrity in the face
of an Iago threat environment, ie. a situation where a security
aggressor has complete control of the hardware and operating system,
up to and including the OS 'lying' about what it is doing to the
application.

There are those, including us, who question the quality of the
security gurantee that can be provided but that doesn't diminish the
usefulness or demand for such technology.  If one buys the notion that
all IT delivery will move into the 'cloud' there is certainly a
rationale for a guarantee that clients can push data into a cloud
without concern for whether or not the platform is compromised or
being used to spy on the user's application or data.

As is the case with any security technology, the only way that such a
guarantee can be made is to have a definable origin or root of trust.
At the current time, and this may be the biggest problem with SGX, the
only origin for that root of trust is Intel itself.  Given the nature
and design of SGX this is actually a bilateral root of trust since
Intel, by signing a developer's enclave key, is trusting the developer
to agree to do nothing nefarious while being shrouded by the security
guarantee that SGX provides.

It would be helpful and instructive for anyone involved in this debate
to review the following URL which details Intel's SGX licening
program:

https://software.intel.com/en-us/articles/intel-sgx-product-licensing

Which details what a developer is required to do in order to obtain an
enclave signing key which will be recognized by an SGX capable
processor.   Without a valid signing key an SGX capable system will
only launch an enclave in 'debug' mode which allows the enclave to be
single stepped and examined in a debugger, which obviously invalidates
any TEE based security guarantees which SGX is designed to effect.

Intel is obviously cognizant of the risk surrounding illicit uses of
this technology since it clearly calls out that, by agreeing to have
their key signed, a developer agrees to not implement nefarious or
privacy invasive software.  Given the known issues that Certificate
Authorities have wi

Re: [PATCH 10/19] staging: comedi: mite: use prefered form for passing a struct size

2016-05-03 Thread Ian Abbott

On 02/05/16 18:11, H Hartley Sweeten wrote:

Add a local variable to mite_buf_change() so that the prefered
form of passing a struct size, sizeof(*p), can be used.

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

diff --git a/drivers/staging/comedi/drivers/mite.c 
b/drivers/staging/comedi/drivers/mite.c
index 8b0f875..650c603 100644
--- a/drivers/staging/comedi/drivers/mite.c
+++ b/drivers/staging/comedi/drivers/mite.c
@@ -473,6 +473,7 @@ int mite_buf_change(struct mite_ring *ring,
struct comedi_subdevice *s)
  {
struct comedi_async *async = s->async;
+   struct mite_dma_desc *descs;
unsigned int n_links;

mite_free_dma_descs(ring);
@@ -482,15 +483,15 @@ int mite_buf_change(struct mite_ring *ring,

n_links = async->prealloc_bufsz >> PAGE_SHIFT;

-   ring->descs =
-   dma_alloc_coherent(ring->hw_dev,
-  n_links * sizeof(struct mite_dma_desc),
-  &ring->dma_addr, GFP_KERNEL);
-   if (!ring->descs) {
+   descs = dma_alloc_coherent(ring->hw_dev,
+  n_links * sizeof(*descs),
+  &ring->dma_addr, GFP_KERNEL);
+   if (!descs) {
dev_err(s->device->class_dev,
"mite: ring buffer allocation failed\n");
return -ENOMEM;
}
+   ring->descs = descs;
ring->n_links = n_links;

return mite_init_ring_descriptors(ring, s, n_links << PAGE_SHIFT);



It doesn't matter, but you could have just used `sizeof(*ring->descs)` 
instead of defining a new variable.


--
-=( Ian Abbott @ MEV Ltd.E-mail:  )=-
-=(  Web: http://www.mev.co.uk/  )=-
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 00/19] staging: comedi: mite: final cleanup

2016-05-03 Thread Ian Abbott

On 02/05/16 18:11, H Hartley Sweeten wrote:

This "driver" is not a actually a comedi driver. It's a helper module that
handles DMA for the National Instruments boards that use the MITE ASIC.

This series is mostly an aesthetic cleanup that shortens the long struct
names and the members of the structs. It also shuffles around the functions
in the driver to make it easier to follow and adds docbook comments for all
the exported functions.

H Hartley Sweeten (19):
   staging: comedi: mite: rename 'struct mite_struct'
   staging: comedi: mite: rename 'struct mite_dma_descriptor'
   staging: comedi: mite: rename 'struct mite_dma_descriptor_ring'
   staging: comedi: mite: rename mite_ring member 'descriptors_dma_addr'
   staging: comedi: mite: rename mite_ring member 'descriptors'
   staging: comedi: mite: tidy up mite_init_ring_descriptors()
   staging: comedi: mite: rename mite member 'mite_io_addr'
   staging: comedi: mite: remove mite member 'channel_allocated'
   staging: comedi: mite: introduce mite_free_dma_descs()
   staging: comedi: mite: use prefered form for passing a struct size
   staging: comedi: mite: document mite_alloc()/mite_detach()
   staging: comedi: mite: do mite_steup() as part of mite_attach()
   staging: comedi: mite: tidy up kernel messages in mite_steup()
   staging: comedi: mite: move the mite ring functions
   staging: comedi: mite: tidy up mite dma channel request/release
   staging: comedi: mite: move mite_prep_dma()
   staging: comedi: mite: move the mite dma arm/disarm/reset functions
   staging: comedi: mite: document the remaining exported functions
   staging: comedi: mite: tidy up module init/exit

  drivers/staging/comedi/drivers/mite.c  | 990 ++---
  drivers/staging/comedi/drivers/mite.h  |  81 +-
  drivers/staging/comedi/drivers/ni_660x.c   |  26 +-
  drivers/staging/comedi/drivers/ni_mio_common.c |   2 +-
  drivers/staging/comedi/drivers/ni_pcidio.c |  10 +-
  drivers/staging/comedi/drivers/ni_pcimio.c |  32 +-
  drivers/staging/comedi/drivers/ni_stc.h|  10 +-
  7 files changed, 605 insertions(+), 546 deletions(-)



Thanks!

Reviewed-by: Ian Abbott 
--
-=( Ian Abbott @ MEV Ltd.E-mail:  )=-
-=(  Web: http://www.mev.co.uk/  )=-
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH [RFC]] PCI: hv: add explicit fencing to config space access

2016-05-03 Thread Vitaly Kuznetsov
I'm trying to pass-through Broadcom BCM5720 NIC (Dell Device 1f5b) on Dell
R720 server. Everything works fine when target VM has only one CPU, but
SMP guests reboot when NIC driver is trying to access PCI config space
(with  hv_pcifront_read_config/hv_pcifront_write_config). The reboot
appears to be induced by the hypervisor and no crash is observed. Windows
event logs are not helpful at all ('Virtual machine ... has quit
unexpectedly'). The particular access point is always different and
putting debug between them (printk/mdelay/...) moves the issue further
away. The server model affects the issue as well: on Dell R420 I'm able to
pass-through BCM5720 NIC to SMP guests without issues.

While I'm obviously failing to reveal the essence of the issue I was able
to come up with a (possible) solution: if explicit fencing is put to
hv_pcifront_read_config/hv_pcifront_write_config the issue goes away. The
essential minimum is rmb() at the end on _hv_pcifront_read_config() and
wmb() at the end of _hv_pcifront_write_config() but I'm not confident it
will be sufficient for all hardware. I suggest the following fencing:
1) wmb()/mb() between choosing the function and writing to its space.
2) mb() before releasing the spinlock in both _hv_pcifront_read_config()/
   _hv_pcifront_write_config to ensure that consecutive reads/writes to
  the space won't get re-ordered as drivers may count on that.
Config space access is not supposed to be performance-critical so this
explicit fencing is not supposed to bring any slowdown.

Signed-off-by: Vitaly Kuznetsov 
---
 drivers/pci/host/pci-hyperv.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/drivers/pci/host/pci-hyperv.c b/drivers/pci/host/pci-hyperv.c
index c17e792..7e9b2de 100644
--- a/drivers/pci/host/pci-hyperv.c
+++ b/drivers/pci/host/pci-hyperv.c
@@ -553,6 +553,8 @@ static void _hv_pcifront_read_config(struct hv_pci_dev 
*hpdev, int where,
spin_lock_irqsave(&hpdev->hbus->config_lock, flags);
/* Choose the function to be read. (See comment above) */
writel(hpdev->desc.win_slot.slot, hpdev->hbus->cfg_addr);
+   /* Make sure the function was chosen before we start reading. */
+   mb();
/* Read from that function's config space. */
switch (size) {
case 1:
@@ -565,6 +567,11 @@ static void _hv_pcifront_read_config(struct hv_pci_dev 
*hpdev, int where,
*val = readl(addr);
break;
}
+   /*
+* Make sure the write was done before we release the spinlock
+* allowing consecutive reads/writes.
+*/
+   mb();
spin_unlock_irqrestore(&hpdev->hbus->config_lock, flags);
} else {
dev_err(&hpdev->hbus->hdev->device,
@@ -592,6 +599,8 @@ static void _hv_pcifront_write_config(struct hv_pci_dev 
*hpdev, int where,
spin_lock_irqsave(&hpdev->hbus->config_lock, flags);
/* Choose the function to be written. (See comment above) */
writel(hpdev->desc.win_slot.slot, hpdev->hbus->cfg_addr);
+   /* Make sure the function was chosen before we start writing. */
+   wmb();
/* Write to that function's config space. */
switch (size) {
case 1:
@@ -604,6 +613,11 @@ static void _hv_pcifront_write_config(struct hv_pci_dev 
*hpdev, int where,
writel(val, addr);
break;
}
+   /*
+* Make sure the write was done before we release the spinlock
+* allowing consecutive reads/writes.
+*/
+   mb();
spin_unlock_irqrestore(&hpdev->hbus->config_lock, flags);
} else {
dev_err(&hpdev->hbus->hdev->device,
-- 
2.5.5

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


Re: [PATCH v2] vme: change LM callback argument to void pointer

2016-05-03 Thread Alessio Igor Bogani
Dan,

On 30 April 2016 at 12:16, Dan Carpenter  wrote:
> On Fri, Apr 29, 2016 at 04:41:02PM -0500, Aaron Sierra wrote:
>> There appear to be no in-kernel callers of vme_lm_attach (or
>> vme_lme_request for that matter), so this change only affects the VME
>> subsystem and bridge drivers.
>
> Are we planning to add in-kernel users soon?

It would be great since we have a lot of VME drivers (for devices not
for bridges) which we would like see mainlined.
Unfortunately, considering the limitations of the current VME stack
implementation, submit these is almost useless.

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


Re: [PATCH v2] vme: change LM callback argument to void pointer

2016-05-03 Thread Dan Carpenter
On Tue, May 03, 2016 at 02:52:54PM +0200, Alessio Igor Bogani wrote:
> Dan,
> 
> On 30 April 2016 at 12:16, Dan Carpenter  wrote:
> > On Fri, Apr 29, 2016 at 04:41:02PM -0500, Aaron Sierra wrote:
> >> There appear to be no in-kernel callers of vme_lm_attach (or
> >> vme_lme_request for that matter), so this change only affects the VME
> >> subsystem and bridge drivers.
> >
> > Are we planning to add in-kernel users soon?
> 
> It would be great since we have a lot of VME drivers (for devices not
> for bridges) which we would like see mainlined.
> Unfortunately, considering the limitations of the current VME stack
> implementation, submit these is almost useless.

What do we need to do to make it better?

regards,
dan carpenter

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


Re: [PATCH v2] vme: change LM callback argument to void pointer

2016-05-03 Thread Aaron Sierra
- Original Message -
> From: "Dan Carpenter" 
> To: "Alessio Igor Bogani" 
> Sent: Tuesday, May 3, 2016 8:18:38 AM
> 
> On Tue, May 03, 2016 at 02:52:54PM +0200, Alessio Igor Bogani wrote:
> > Dan,
> > 
> > On 30 April 2016 at 12:16, Dan Carpenter  wrote:
> > > On Fri, Apr 29, 2016 at 04:41:02PM -0500, Aaron Sierra wrote:
> > >> There appear to be no in-kernel callers of vme_lm_attach (or
> > >> vme_lme_request for that matter), so this change only affects the VME
> > >> subsystem and bridge drivers.
> > >
> > > Are we planning to add in-kernel users soon?
> > 
> > It would be great since we have a lot of VME drivers (for devices not
> > for bridges) which we would like see mainlined.
> > Unfortunately, considering the limitations of the current VME stack
> > implementation, submit these is almost useless.
> 
> What do we need to do to make it better?

I'm interested to hear Alessio's thoughts; these are my own.

The biggest challenge that I've found in developing VME drivers is defining
and maintaining VME resource assignments across intelligent hosts.

I've made a proof-of-concept Open Firmware layer for VME that enables a
bridge's resources (inbound/outbound windows, IRQs, LMs, and outbound IRQs)
to be defined concisely and allocated to child nodes (platform devices) from
a single text file (later compiled into a DTB). This could be generally useful
and allow each board's view of the bus to be more easily defined and
maintained. I tested on PowerPC, but think it could also work on x86 now that
it's device-tree capable.

This resulted in my VME device driver requiring very little VME-awareness.

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


[PATCH] staging:comedi:Use unsigned int instead of unsigned

2016-05-03 Thread Nikita Eshkeev
This patch fixed the checkpatch.pl warning:

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

Signed-off-by: Nikita Eshkeev 
---
 drivers/staging/comedi/comedi.h  |  2 +-
 drivers/staging/comedi/drivers/comedi_bond.c | 10 +-
 drivers/staging/comedi/drivers/das800.c  |  4 ++--
 drivers/staging/comedi/drivers/ni_65xx.c | 18 +-
 drivers/staging/comedi/drivers/ni_pcidio.c   |  4 ++--
 drivers/staging/comedi/drivers/ni_pcimio.c   |  8 
 drivers/staging/comedi/drivers/pcmuio.c  |  2 +-
 drivers/staging/comedi/drivers/quatech_daqp_cs.c |  2 +-
 drivers/staging/comedi/drivers/rtd520.c  | 10 +-
 drivers/staging/comedi/drivers/s626.c|  8 
 10 files changed, 34 insertions(+), 34 deletions(-)

diff --git a/drivers/staging/comedi/comedi.h b/drivers/staging/comedi/comedi.h
index ad5297f..08fb26b 100644
--- a/drivers/staging/comedi/comedi.h
+++ b/drivers/staging/comedi/comedi.h
@@ -779,7 +779,7 @@ struct comedi_subdinfo {
unsigned int flags;
unsigned int range_type;
unsigned int settling_time_0;
-   unsigned insn_bits_support;
+   unsigned int insn_bits_support;
unsigned int unused[8];
 };
 
diff --git a/drivers/staging/comedi/drivers/comedi_bond.c 
b/drivers/staging/comedi/drivers/comedi_bond.c
index 50b76ec..64a5ea3 100644
--- a/drivers/staging/comedi/drivers/comedi_bond.c
+++ b/drivers/staging/comedi/drivers/comedi_bond.c
@@ -55,16 +55,16 @@
 
 struct bonded_device {
struct comedi_device *dev;
-   unsigned minor;
-   unsigned subdev;
-   unsigned nchans;
+   unsigned int minor;
+   unsigned int subdev;
+   unsigned int nchans;
 };
 
 struct comedi_bond_private {
char name[256];
struct bonded_device **devs;
-   unsigned ndevs;
-   unsigned nchans;
+   unsigned int ndevs;
+   unsigned int nchans;
 };
 
 static int bonding_dio_insn_bits(struct comedi_device *dev,
diff --git a/drivers/staging/comedi/drivers/das800.c 
b/drivers/staging/comedi/drivers/das800.c
index b02f122..9059872 100644
--- a/drivers/staging/comedi/drivers/das800.c
+++ b/drivers/staging/comedi/drivers/das800.c
@@ -218,7 +218,7 @@ struct das800_private {
 };
 
 static void das800_ind_write(struct comedi_device *dev,
-unsigned val, unsigned reg)
+unsigned int val, unsigned int reg)
 {
/*
 * Select dev->iobase + 2 to be desired register
@@ -228,7 +228,7 @@ static void das800_ind_write(struct comedi_device *dev,
outb(val, dev->iobase + 2);
 }
 
-static unsigned das800_ind_read(struct comedi_device *dev, unsigned reg)
+static unsigned int das800_ind_read(struct comedi_device *dev, unsigned int 
reg)
 {
/*
 * Select dev->iobase + 7 to be desired register
diff --git a/drivers/staging/comedi/drivers/ni_65xx.c 
b/drivers/staging/comedi/drivers/ni_65xx.c
index 251117b..07f38e3 100644
--- a/drivers/staging/comedi/drivers/ni_65xx.c
+++ b/drivers/staging/comedi/drivers/ni_65xx.c
@@ -151,10 +151,10 @@ enum ni_65xx_boardid {
 
 struct ni_65xx_board {
const char *name;
-   unsigned num_dio_ports;
-   unsigned num_di_ports;
-   unsigned num_do_ports;
-   unsigned legacy_invert:1;
+   unsigned int num_dio_ports;
+   unsigned int num_di_ports;
+   unsigned int num_do_ports;
+   unsigned int legacy_invert:1;
 };
 
 static const struct ni_65xx_board ni_65xx_boards[] = {
@@ -360,7 +360,7 @@ static int ni_65xx_dio_insn_config(struct comedi_device 
*dev,
unsigned long base_port = (unsigned long)s->private;
unsigned int chan = CR_CHAN(insn->chanspec);
unsigned int chan_mask = NI_65XX_CHAN_TO_MASK(chan);
-   unsigned port = base_port + NI_65XX_CHAN_TO_PORT(chan);
+   unsigned int port = base_port + NI_65XX_CHAN_TO_PORT(chan);
unsigned int interval;
unsigned int val;
 
@@ -428,14 +428,14 @@ static int ni_65xx_dio_insn_bits(struct comedi_device 
*dev,
unsigned long base_port = (unsigned long)s->private;
unsigned int base_chan = CR_CHAN(insn->chanspec);
int last_port_offset = NI_65XX_CHAN_TO_PORT(s->n_chan - 1);
-   unsigned read_bits = 0;
+   unsigned int read_bits = 0;
int port_offset;
 
for (port_offset = NI_65XX_CHAN_TO_PORT(base_chan);
 port_offset <= last_port_offset; port_offset++) {
-   unsigned port = base_port + port_offset;
+   unsigned int port = base_port + port_offset;
int base_port_channel = NI_65XX_PORT_TO_CHAN(port_offset);
-   unsigned port_mask, port_data, bits;
+   unsigned int port_mask, port_data, bits;
int bitshift = base_port_channel - base_chan;
 
if (bitshift >= 32)
@@ -640,7 +640,7 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
struct pci_dev *pcidev = comedi_to_pci_dev(de

Re: [PATCH 0/6] Intel Secure Guard Extensions

2016-05-03 Thread Pavel Machek
Hi!

> We have been following and analyzing this technology since the first
> HASP paper was published detailing its development.  We have been

(1)

> 
> I told my associates the first time I reviewed this technology that
> SGX has the ability to be a bit of a Pandora's box and it seems to be
> following that course.

Can you elaborate on the Pandora's box? System administrator should be able to
disable SGX on the system, and use system to do anything that could be done with
the older CPUs, right?

> support data and application confidentiality and integrity in the face
> of an Iago threat environment, ie. a situation where a security

(2)

> Intel is obviously cognizant of the risk surrounding illicit uses of
> this technology since it clearly calls out that, by agreeing to have
> their key signed, a developer agrees to not implement nefarious or
> privacy invasive software.  Given the known issues that Certificate

Yeah, that's likely to work ... not :-(. "It is not spyware, it is just
collecting some anonymous statistics."

> domination and control.  They probably have enough on their hands with
> attempting to convert humanity to FPGA's and away from devices which
> are capable of maintaining a context of exection... :-)

Heh. FPGAs are not designed to replace CPUs anytime soon... And probably never.

> the Haven paper in which Microsoft Research discussed how SGX could be
> used to run unmodified Windows applications within an SGX TEE.

(3)

> I think Intel was somewhat sobered by the follow on paper in which
> Microsoft demonstrated that in an Iago environment an interloper was
> capable of determing with accuracy levels greater then 60% what was
> being done in an SGX TEE.  Matt Hoekstra was very quick to call out
> the need for the community to understand and develop side channel

(4)

> In the TL;DR department I would highly recommend that anyone
> interested in all of this read MIT's 170+ page review of the
> technology before jumping to any conclusions :-)

(5)

Would you have links for 1-5?

Thanks,
Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) 
http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH net-next 4/5] treewide: replace dev->trans_start update with helper

2016-05-03 Thread Florian Westphal
Replace all trans_start updates with netif_trans_update helper.
change was done via spatch:

struct net_device *d;
@@
- d->trans_start = jiffies
+ netif_trans_update(d)

Compile tested only.

Cc: user-mode-linux-de...@lists.sourceforge.net
Cc: linux-xte...@linux-xtensa.org
Cc: linux1394-de...@lists.sourceforge.net
Cc: linux-r...@vger.kernel.org
Cc: net...@vger.kernel.org
Cc: mpt-fusionlinux@broadcom.com
Cc: linux-s...@vger.kernel.org
Cc: linux-...@vger.kernel.org
Cc: linux-par...@vger.kernel.org
Cc: linux-o...@vger.kernel.org
Cc: linux-h...@vger.kernel.org
Cc: linux-...@vger.kernel.org
Cc: linux-wirel...@vger.kernel.org
Cc: linux-s...@vger.kernel.org
Cc: de...@driverdev.osuosl.org
Cc: b.a.t.m@lists.open-mesh.org
Cc: linux-blueto...@vger.kernel.org
Signed-off-by: Florian Westphal 
---
 Checkpatch complains about whitespace damage, but
 this extra whitespace already exists before this patch.

 arch/um/drivers/net_kern.c | 4 ++--
 arch/xtensa/platforms/iss/network.c| 2 +-
 drivers/char/pcmcia/synclink_cs.c  | 4 ++--
 drivers/firewire/net.c | 2 +-
 drivers/infiniband/hw/nes/nes_nic.c| 2 +-
 drivers/infiniband/ulp/ipoib/ipoib_cm.c| 2 +-
 drivers/infiniband/ulp/ipoib/ipoib_ib.c| 2 +-
 drivers/isdn/hysdn/hysdn_net.c | 2 +-
 drivers/isdn/i4l/isdn_net.c| 4 ++--
 drivers/isdn/i4l/isdn_x25iface.c   | 2 +-
 drivers/message/fusion/mptlan.c| 2 +-
 drivers/net/appletalk/cops.c   | 2 +-
 drivers/net/can/mscan/mscan.c  | 4 ++--
 drivers/net/can/usb/ems_usb.c  | 4 ++--
 drivers/net/can/usb/esd_usb2.c | 4 ++--
 drivers/net/can/usb/peak_usb/pcan_usb_core.c   | 4 ++--
 drivers/net/cris/eth_v10.c | 2 +-
 drivers/net/ethernet/3com/3c509.c  | 2 +-
 drivers/net/ethernet/3com/3c515.c  | 2 +-
 drivers/net/ethernet/3com/3c574_cs.c   | 2 +-
 drivers/net/ethernet/3com/3c589_cs.c   | 2 +-
 drivers/net/ethernet/3com/3c59x.c  | 2 +-
 drivers/net/ethernet/8390/axnet_cs.c   | 6 +++---
 drivers/net/ethernet/8390/lib8390.c| 4 ++--
 drivers/net/ethernet/adaptec/starfire.c| 2 +-
 drivers/net/ethernet/adi/bfin_mac.c| 2 +-
 drivers/net/ethernet/agere/et131x.c| 4 ++--
 drivers/net/ethernet/allwinner/sun4i-emac.c| 6 +++---
 drivers/net/ethernet/amd/7990.c| 4 ++--
 drivers/net/ethernet/amd/a2065.c   | 2 +-
 drivers/net/ethernet/amd/atarilance.c  | 2 +-
 drivers/net/ethernet/amd/au1000_eth.c  | 2 +-
 drivers/net/ethernet/amd/declance.c| 2 +-
 drivers/net/ethernet/amd/lance.c   | 2 +-
 drivers/net/ethernet/amd/ni65.c| 4 ++--
 drivers/net/ethernet/amd/nmclan_cs.c   | 2 +-
 drivers/net/ethernet/amd/pcnet32.c | 4 ++--
 drivers/net/ethernet/amd/sunlance.c| 2 +-
 drivers/net/ethernet/atheros/alx/main.c| 2 +-
 drivers/net/ethernet/broadcom/bcmsysport.c | 2 +-
 drivers/net/ethernet/broadcom/genet/bcmgenet.c | 2 +-
 drivers/net/ethernet/broadcom/sb1250-mac.c | 2 +-
 drivers/net/ethernet/broadcom/tg3.c| 2 +-
 drivers/net/ethernet/cavium/liquidio/lio_main.c| 4 ++--
 drivers/net/ethernet/cavium/octeon/octeon_mgmt.c   | 2 +-
 drivers/net/ethernet/cavium/thunder/nicvf_main.c   | 2 +-
 drivers/net/ethernet/chelsio/cxgb4vf/sge.c | 2 +-
 drivers/net/ethernet/davicom/dm9000.c  | 4 ++--
 drivers/net/ethernet/dec/tulip/de4x5.c | 4 ++--
 drivers/net/ethernet/dec/tulip/dmfe.c  | 6 +++---
 drivers/net/ethernet/dec/tulip/pnic.c  | 6 +++---
 drivers/net/ethernet/dec/tulip/tulip_core.c| 2 +-
 drivers/net/ethernet/dec/tulip/uli526x.c   | 4 ++--
 drivers/net/ethernet/dec/tulip/winbond-840.c   | 2 +-
 drivers/net/ethernet/dlink/dl2k.c  | 2 +-
 drivers/net/ethernet/dlink/sundance.c  | 2 +-
 drivers/net/ethernet/fealnx.c  | 2 +-
 drivers/net/ethernet/freescale/gianfar.c   | 2 +-
 drivers/net/ethernet/fujitsu/fmvj18x_cs.c  | 2 +-
 drivers/net/ethernet/hisilicon/hix5hd2_gmac.c  | 2 +-
 drivers/net/ethernet/hisilicon/hns/hns_enet.c  | 6 +++---
 drivers/net/ethernet/hp/hp100.c| 2 +-
 drivers/net/ethernet/i825xx/82596.c| 2 +-
 drivers/net/ethernet/i825xx/lib82596.c | 2 +-
 dr

RE: [PATCH [RFC]] PCI: hv: add explicit fencing to config space access

2016-05-03 Thread Jake Oshins
> -Original Message-
> From: Vitaly Kuznetsov [mailto:vkuzn...@redhat.com]
> Sent: Tuesday, May 3, 2016 5:22 AM
> To: linux-...@vger.kernel.org
> Cc: linux-ker...@vger.kernel.org; de...@linuxdriverproject.org; Bjorn
> Helgaas ; Haiyang Zhang
> ; KY Srinivasan ; Jake
> Oshins 
> Subject: [PATCH [RFC]] PCI: hv: add explicit fencing to config space access
> 
> I'm trying to pass-through Broadcom BCM5720 NIC (Dell Device 1f5b) on Dell
> R720 server. Everything works fine when target VM has only one CPU, but
> SMP guests reboot when NIC driver is trying to access PCI config space
> (with  hv_pcifront_read_config/hv_pcifront_write_config). The reboot
> appears to be induced by the hypervisor and no crash is observed. Windows
> event logs are not helpful at all ('Virtual machine ... has quit
> unexpectedly'). The particular access point is always different and
> putting debug between them (printk/mdelay/...) moves the issue further
> away. The server model affects the issue as well: on Dell R420 I'm able to
> pass-through BCM5720 NIC to SMP guests without issues.
> 
> While I'm obviously failing to reveal the essence of the issue I was able
> to come up with a (possible) solution: if explicit fencing is put to
> hv_pcifront_read_config/hv_pcifront_write_config the issue goes away. The
> essential minimum is rmb() at the end on _hv_pcifront_read_config() and
> wmb() at the end of _hv_pcifront_write_config() but I'm not confident it
> will be sufficient for all hardware. I suggest the following fencing:
> 1) wmb()/mb() between choosing the function and writing to its space.
> 2) mb() before releasing the spinlock in both _hv_pcifront_read_config()/
>_hv_pcifront_write_config to ensure that consecutive reads/writes to
>   the space won't get re-ordered as drivers may count on that.
> Config space access is not supposed to be performance-critical so this
> explicit fencing is not supposed to bring any slowdown.
> 
> Signed-off-by: Vitaly Kuznetsov 
Acked-by: Jake Oshins 


> ---
>  drivers/pci/host/pci-hyperv.c | 14 ++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/drivers/pci/host/pci-hyperv.c b/drivers/pci/host/pci-hyperv.c
> index c17e792..7e9b2de 100644
> --- a/drivers/pci/host/pci-hyperv.c
> +++ b/drivers/pci/host/pci-hyperv.c
> @@ -553,6 +553,8 @@ static void _hv_pcifront_read_config(struct
> hv_pci_dev *hpdev, int where,
>   spin_lock_irqsave(&hpdev->hbus->config_lock, flags);
>   /* Choose the function to be read. (See comment above) */
>   writel(hpdev->desc.win_slot.slot, hpdev->hbus->cfg_addr);
> + /* Make sure the function was chosen before we start
> reading. */
> + mb();
>   /* Read from that function's config space. */
>   switch (size) {
>   case 1:
> @@ -565,6 +567,11 @@ static void _hv_pcifront_read_config(struct
> hv_pci_dev *hpdev, int where,
>   *val = readl(addr);
>   break;
>   }
> + /*
> +  * Make sure the write was done before we release the
> spinlock
> +  * allowing consecutive reads/writes.
> +  */
> + mb();
>   spin_unlock_irqrestore(&hpdev->hbus->config_lock, flags);
>   } else {
>   dev_err(&hpdev->hbus->hdev->device,
> @@ -592,6 +599,8 @@ static void _hv_pcifront_write_config(struct
> hv_pci_dev *hpdev, int where,
>   spin_lock_irqsave(&hpdev->hbus->config_lock, flags);
>   /* Choose the function to be written. (See comment above)
> */
>   writel(hpdev->desc.win_slot.slot, hpdev->hbus->cfg_addr);
> + /* Make sure the function was chosen before we start
> writing. */
> + wmb();
>   /* Write to that function's config space. */
>   switch (size) {
>   case 1:
> @@ -604,6 +613,11 @@ static void _hv_pcifront_write_config(struct
> hv_pci_dev *hpdev, int where,
>   writel(val, addr);
>   break;
>   }
> + /*
> +  * Make sure the write was done before we release the
> spinlock
> +  * allowing consecutive reads/writes.
> +  */
> + mb();
>   spin_unlock_irqrestore(&hpdev->hbus->config_lock, flags);
>   } else {
>   dev_err(&hpdev->hbus->hdev->device,
> --
> 2.5.5

I'm honestly not as familiar with gcc or the Linux kernel as I should be.  When 
I wrote this code, I assumed that the writel() and writeb() macros would 
guarantee ordering.  (The analogous macros in Windows kernel programming that 
I'm more familiar with do so.)  Now that I look at this, I see that it's mostly 
just a wrapper around a volatile declaration.  This is clearly my error, and 
the fixes above seem good to me.

While I was developing this driver, I saw the exact behavior that you're 
describing, where configuring the VM with multip

[PATCH 08/25] staging: comedi: das16m1: tidy up digital input/output register defines

2016-05-03 Thread H Hartley Sweeten
The digtial inputs and outputs are read/written using the same register
offset but they are different logical registers. Physically they are the
same register with the hi 4 bits returning the inputs and the lo 4 bits
driving the outputs.

For aesthetics, use two different defines for the registers.

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

diff --git a/drivers/staging/comedi/drivers/das16m1.c 
b/drivers/staging/comedi/drivers/das16m1.c
index 49eb829..e85d989 100644
--- a/drivers/staging/comedi/drivers/das16m1.c
+++ b/drivers/staging/comedi/drivers/das16m1.c
@@ -70,7 +70,8 @@
 #define DAS16M1_CS_EXT_TRIGBIT(0)
 #define DAS16M1_CS_OVRUN   BIT(5)
 #define DAS16M1_CS_IRQDATA BIT(7)
-#define DAS16M1_DIO3
+#define DAS16M1_DI_REG 0x03
+#define DAS16M1_DO_REG 0x03
 #define DAS16M1_CLEAR_INTR 4
 #define DAS16M1_INTR_CONTROL   5
 #define   EXT_PACER  0x2
@@ -351,7 +352,7 @@ static int das16m1_di_rbits(struct comedi_device *dev,
 {
unsigned int bits;
 
-   bits = inb(dev->iobase + DAS16M1_DIO) & 0xf;
+   bits = inb(dev->iobase + DAS16M1_DI_REG) & 0xf;
data[1] = bits;
data[0] = 0;
 
@@ -364,7 +365,7 @@ static int das16m1_do_wbits(struct comedi_device *dev,
unsigned int *data)
 {
if (comedi_dio_update_state(s, data))
-   outb(s->state, dev->iobase + DAS16M1_DIO);
+   outb(s->state, dev->iobase + DAS16M1_DO_REG);
 
data[1] = s->state;
 
@@ -596,7 +597,7 @@ static int das16m1_attach(struct comedi_device *dev,
return ret;
 
/*  initialize digital output lines */
-   outb(0, dev->iobase + DAS16M1_DIO);
+   outb(0, dev->iobase + DAS16M1_DO_REG);
 
/* set the interrupt level */
devpriv->control_state = das16m1_irq_bits(dev->irq) << 4;
-- 
2.6.3

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


[PATCH 07/25] staging: comedi: das16m1: tidy up control/status register defines

2016-05-03 Thread H Hartley Sweeten
Rename the defines for the control/status register/bits. Use the BIT
macro to define the bits.

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

diff --git a/drivers/staging/comedi/drivers/das16m1.c 
b/drivers/staging/comedi/drivers/das16m1.c
index 2c7c86c..49eb829 100644
--- a/drivers/staging/comedi/drivers/das16m1.c
+++ b/drivers/staging/comedi/drivers/das16m1.c
@@ -66,10 +66,10 @@
 #define DAS16M1_AI_REG 0x00/* 16-bit register */
 #define DAS16M1_AI_TO_CHAN(x)  (((x) >> 0) & 0xf)
 #define DAS16M1_AI_TO_SAMPLE(x)(((x) >> 4) & 0xfff)
-#define DAS16M1_CS 2
-#define   EXT_TRIG_BIT   0x1
-#define   OVRUN  0x20
-#define   IRQDATA0x80
+#define DAS16M1_CS_REG 0x02
+#define DAS16M1_CS_EXT_TRIGBIT(0)
+#define DAS16M1_CS_OVRUN   BIT(5)
+#define DAS16M1_CS_IRQDATA BIT(7)
 #define DAS16M1_DIO3
 #define DAS16M1_CLEAR_INTR 4
 #define DAS16M1_INTR_CONTROL   5
@@ -272,9 +272,9 @@ static int das16m1_cmd_exec(struct comedi_device *dev,
 * both start and conversion triggers external simultaneously).
 */
if (cmd->start_src == TRIG_EXT && cmd->convert_src != TRIG_EXT)
-   byte |= EXT_TRIG_BIT;
+   byte |= DAS16M1_CS_EXT_TRIG;
 
-   outb(byte, dev->iobase + DAS16M1_CS);
+   outb(byte, dev->iobase + DAS16M1_CS_REG);
/* clear interrupt bit */
outb(0, dev->iobase + DAS16M1_CLEAR_INTR);
 
@@ -301,8 +301,8 @@ static int das16m1_ai_eoc(struct comedi_device *dev,
 {
unsigned int status;
 
-   status = inb(dev->iobase + DAS16M1_CS);
-   if (status & IRQDATA)
+   status = inb(dev->iobase + DAS16M1_CS_REG);
+   if (status & DAS16M1_CS_IRQDATA)
return 0;
return -EBUSY;
 }
@@ -329,7 +329,7 @@ static int das16m1_ai_rinsn(struct comedi_device *dev,
for (n = 0; n < insn->n; n++) {
unsigned short val;
 
-   /* clear IRQDATA bit */
+   /* clear DAS16M1_CS_IRQDATA bit */
outb(0, dev->iobase + DAS16M1_CLEAR_INTR);
/* trigger conversion */
outb(0, dev->iobase + DAS16M1_AI_REG);
@@ -430,7 +430,7 @@ static void das16m1_handler(struct comedi_device *dev, 
unsigned int status)
 * This probably won't catch overruns since the card doesn't generate
 * overrun interrupts, but we might as well try.
 */
-   if (status & OVRUN) {
+   if (status & DAS16M1_CS_OVRUN) {
async->events |= COMEDI_CB_ERROR;
dev_err(dev->class_dev, "fifo overflow\n");
}
@@ -445,7 +445,7 @@ static int das16m1_poll(struct comedi_device *dev, struct 
comedi_subdevice *s)
 
/*  prevent race with interrupt handler */
spin_lock_irqsave(&dev->spinlock, flags);
-   status = inb(dev->iobase + DAS16M1_CS);
+   status = inb(dev->iobase + DAS16M1_CS_REG);
das16m1_handler(dev, status);
spin_unlock_irqrestore(&dev->spinlock, flags);
 
@@ -464,9 +464,9 @@ static irqreturn_t das16m1_interrupt(int irq, void *d)
/*  prevent race with comedi_poll() */
spin_lock(&dev->spinlock);
 
-   status = inb(dev->iobase + DAS16M1_CS);
+   status = inb(dev->iobase + DAS16M1_CS_REG);
 
-   if ((status & (IRQDATA | OVRUN)) == 0) {
+   if ((status & (DAS16M1_CS_IRQDATA | DAS16M1_CS_OVRUN)) == 0) {
dev_err(dev->class_dev, "spurious interrupt\n");
spin_unlock(&dev->spinlock);
return IRQ_NONE;
-- 
2.6.3

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


[PATCH 04/25] staging: comedi: das16m1: remove unnecessary private data comments

2016-05-03 Thread H Hartley Sweeten
These comments are just extra cruft. Removing them also fixes a
checkpatch.pl issue:
WARNING: Block comments use a trailing */ on a separate line

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

diff --git a/drivers/staging/comedi/drivers/das16m1.c 
b/drivers/staging/comedi/drivers/das16m1.c
index 05ceb13..078b26e 100644
--- a/drivers/staging/comedi/drivers/das16m1.c
+++ b/drivers/staging/comedi/drivers/das16m1.c
@@ -120,10 +120,7 @@ static const struct comedi_lrange range_das16m1 = {
 struct das16m1_private_struct {
struct comedi_8254 *counter;
unsigned int control_state;
-   unsigned int adc_count; /*  number of samples completed */
-   /* initial value in lower half of hardware conversion counter,
-* needed to keep track of whether new count has been loaded into
-* counter yet (loaded by first sample conversion) */
+   unsigned int adc_count;
u16 initial_hw_count;
unsigned short ai_buffer[FIFO_SIZE];
unsigned long extra_iobase;
-- 
2.6.3

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


[PATCH 18/25] staging: comedi: das16m1: tidy up 8254/8255 register defines

2016-05-03 Thread H Hartley Sweeten
For aesthetics, rename these defines.

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

diff --git a/drivers/staging/comedi/drivers/das16m1.c 
b/drivers/staging/comedi/drivers/das16m1.c
index cb5cd5e..824cc94 100644
--- a/drivers/staging/comedi/drivers/das16m1.c
+++ b/drivers/staging/comedi/drivers/das16m1.c
@@ -84,10 +84,10 @@
 #define DAS16M1_Q_REG  0x07
 #define DAS16M1_Q_CHAN(x)  (((x) & 0x7) << 0)
 #define DAS16M1_Q_RANGE(x) (((x) & 0xf) << 4)
-#define DAS16M1_8254_FIRST 0x8
-#define DAS16M1_8254_SECOND0xc
-#define DAS16M1_82C55  0x400
-#define DAS16M1_8254_THIRD 0x404
+#define DAS16M1_8254_IOBASE1   0x08
+#define DAS16M1_8254_IOBASE2   0x0c
+#define DAS16M1_8255_IOBASE0x400
+#define DAS16M1_8254_IOBASE3   0x404
 
 static const struct comedi_lrange range_das16m1 = {
9, {
@@ -524,12 +524,12 @@ static int das16m1_attach(struct comedi_device *dev,
ret = comedi_request_region(dev, it->options[0], 0x10);
if (ret)
return ret;
-   /* Request an additional region for the 8255 */
-   ret = __comedi_request_region(dev, dev->iobase + DAS16M1_82C55,
+   /* Request an additional region for the 8255 and 3rd 8254 */
+   ret = __comedi_request_region(dev, dev->iobase + DAS16M1_8255_IOBASE,
  DAS16M1_SIZE2);
if (ret)
return ret;
-   devpriv->extra_iobase = dev->iobase + DAS16M1_82C55;
+   devpriv->extra_iobase = dev->iobase + DAS16M1_8255_IOBASE;
 
/* only irqs 2, 3, 4, 5, 6, 7, 10, 11, 12, 14, and 15 are valid */
if ((1 << it->options[1]) & 0xdcfc) {
@@ -539,12 +539,12 @@ static int das16m1_attach(struct comedi_device *dev,
dev->irq = it->options[1];
}
 
-   dev->pacer = comedi_8254_init(dev->iobase + DAS16M1_8254_SECOND,
+   dev->pacer = comedi_8254_init(dev->iobase + DAS16M1_8254_IOBASE2,
  I8254_OSC_BASE_10MHZ, I8254_IO8, 0);
if (!dev->pacer)
return -ENOMEM;
 
-   devpriv->counter = comedi_8254_init(dev->iobase + DAS16M1_8254_FIRST,
+   devpriv->counter = comedi_8254_init(dev->iobase + DAS16M1_8254_IOBASE1,
0, I8254_IO8, 0);
if (!devpriv->counter)
return -ENOMEM;
@@ -589,9 +589,9 @@ static int das16m1_attach(struct comedi_device *dev,
s->range_table  = &range_digital;
s->insn_bits= das16m1_do_insn_bits;
 
+   /* Digital I/O subdevice (8255) */
s = &dev->subdevices[3];
-   /* 8255 */
-   ret = subdev_8255_init(dev, s, NULL, DAS16M1_82C55);
+   ret = subdev_8255_init(dev, s, NULL, DAS16M1_8255_IOBASE);
if (ret)
return ret;
 
-- 
2.6.3

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


[PATCH 24/25] staging: comedi: das16m1: rename struct das16m1_private_struct

2016-05-03 Thread H Hartley Sweeten
For aesthetics, remove the redundant '_struct' suffix.

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

diff --git a/drivers/staging/comedi/drivers/das16m1.c 
b/drivers/staging/comedi/drivers/das16m1.c
index a803032..7185b85 100644
--- a/drivers/staging/comedi/drivers/das16m1.c
+++ b/drivers/staging/comedi/drivers/das16m1.c
@@ -103,7 +103,7 @@ static const struct comedi_lrange range_das16m1 = {
}
 };
 
-struct das16m1_private_struct {
+struct das16m1_private {
struct comedi_8254 *counter;
unsigned int intr_ctrl;
unsigned int adc_count;
@@ -248,7 +248,7 @@ static int das16m1_ai_cmdtest(struct comedi_device *dev,
 static int das16m1_ai_cmd(struct comedi_device *dev,
  struct comedi_subdevice *s)
 {
-   struct das16m1_private_struct *devpriv = dev->private;
+   struct das16m1_private *devpriv = dev->private;
struct comedi_async *async = s->async;
struct comedi_cmd *cmd = &async->cmd;
unsigned int byte;
@@ -305,7 +305,7 @@ static int das16m1_ai_cmd(struct comedi_device *dev,
 static int das16m1_ai_cancel(struct comedi_device *dev,
 struct comedi_subdevice *s)
 {
-   struct das16m1_private_struct *devpriv = dev->private;
+   struct das16m1_private *devpriv = dev->private;
 
/* disable interrupts and pacer */
devpriv->intr_ctrl &= ~(DAS16M1_INTR_CTRL_INTE |
@@ -382,7 +382,7 @@ static int das16m1_do_insn_bits(struct comedi_device *dev,
 
 static void das16m1_handler(struct comedi_device *dev, unsigned int status)
 {
-   struct das16m1_private_struct *devpriv = dev->private;
+   struct das16m1_private *devpriv = dev->private;
struct comedi_subdevice *s = dev->read_subdev;
struct comedi_async *async = s->async;
struct comedi_cmd *cmd = &async->cmd;
@@ -513,7 +513,7 @@ static int das16m1_irq_bits(unsigned int irq)
 static int das16m1_attach(struct comedi_device *dev,
  struct comedi_devconfig *it)
 {
-   struct das16m1_private_struct *devpriv;
+   struct das16m1_private *devpriv;
struct comedi_subdevice *s;
int ret;
 
@@ -608,7 +608,7 @@ static int das16m1_attach(struct comedi_device *dev,
 
 static void das16m1_detach(struct comedi_device *dev)
 {
-   struct das16m1_private_struct *devpriv = dev->private;
+   struct das16m1_private *devpriv = dev->private;
 
if (devpriv) {
if (devpriv->extra_iobase)
-- 
2.6.3

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


[PATCH 16/25] staging: comedi: das16m1: tidy up das16m1_di_insn_bits()

2016-05-03 Thread H Hartley Sweeten
The (*insn_bits) for a digital input subdevice only needs to return the
state of the inputs in data[1]. Remove the cruft.

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

diff --git a/drivers/staging/comedi/drivers/das16m1.c 
b/drivers/staging/comedi/drivers/das16m1.c
index f51da80..538544b 100644
--- a/drivers/staging/comedi/drivers/das16m1.c
+++ b/drivers/staging/comedi/drivers/das16m1.c
@@ -352,11 +352,7 @@ static int das16m1_di_insn_bits(struct comedi_device *dev,
struct comedi_insn *insn,
unsigned int *data)
 {
-   unsigned int bits;
-
-   bits = inb(dev->iobase + DAS16M1_DI_REG) & 0xf;
-   data[1] = bits;
-   data[0] = 0;
+   data[1] = inb(dev->iobase + DAS16M1_DI_REG) & 0xf;
 
return insn->n;
 }
-- 
2.6.3

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


[PATCH 01/25] staging: comedi: das16m1: tidy up copyright and comedi comments

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

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

diff --git a/drivers/staging/comedi/drivers/das16m1.c 
b/drivers/staging/comedi/drivers/das16m1.c
index 3a37373..90d3869 100644
--- a/drivers/staging/comedi/drivers/das16m1.c
+++ b/drivers/staging/comedi/drivers/das16m1.c
@@ -1,56 +1,52 @@
 /*
-comedi/drivers/das16m1.c
-CIO-DAS16/M1 driver
-Author: Frank Mori Hess, based on code from the das16
-  driver.
-Copyright (C) 2001 Frank Mori Hess 
-
-COMEDI - Linux Control and Measurement Device Interface
-Copyright (C) 2000 David A. Schleef 
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-*/
+ * Comedi driver for CIO-DAS16/M1
+ * Author: Frank Mori Hess, based on code from the das16 driver.
+ * Copyright (C) 2001 Frank Mori Hess 
+ *
+ * COMEDI - Linux Control and Measurement Device Interface
+ * Copyright (C) 2000 David A. Schleef 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
 /*
-Driver: das16m1
-Description: CIO-DAS16/M1
-Author: Frank Mori Hess 
-Devices: [Measurement Computing] CIO-DAS16/M1 (das16m1)
-Status: works
-
-This driver supports a single board - the CIO-DAS16/M1.
-As far as I know, there are no other boards that have
-the same register layout.  Even the CIO-DAS16/M1/16 is
-significantly different.
-
-I was _barely_ able to reach the full 1 MHz capability
-of this board, using a hard real-time interrupt
-(set the TRIG_RT flag in your struct comedi_cmd and use
-rtlinux or RTAI).  The board can't do dma, so the bottleneck is
-pulling the data across the ISA bus.  I timed the interrupt
-handler, and it took my computer ~470 microseconds to pull 512
-samples from the board.  So at 1 Mhz sampling rate,
-expect your CPU to be spending almost all of its
-time in the interrupt handler.
-
-This board has some unusual restrictions for its channel/gain list.  If the
-list has 2 or more channels in it, then two conditions must be satisfied:
-(1) - even/odd channels must appear at even/odd indices in the list
-(2) - the list must have an even number of entries.
-
-Options:
-   [0] - base io address
-   [1] - irq (optional, but you probably want it)
-
-irq can be omitted, although the cmd interface will not work without it.
-*/
+ * Driver: das16m1
+ * Description: CIO-DAS16/M1
+ * Author: Frank Mori Hess 
+ * Devices: [Measurement Computing] CIO-DAS16/M1 (das16m1)
+ * Status: works
+ *
+ * This driver supports a single board - the CIO-DAS16/M1. As far as I know,
+ * there are no other boards that have the same register layout. Even the
+ * CIO-DAS16/M1/16 is significantly different.
+ *
+ * I was _barely_ able to reach the full 1 MHz capability of this board, using
+ * a hard real-time interrupt (set the TRIG_RT flag in your struct comedi_cmd
+ * and use rtlinux or RTAI). The board can't do dma, so the bottleneck is
+ * pulling the data across the ISA bus. I timed the interrupt handler, and it
+ * took my computer ~470 microseconds to pull 512 samples from the board. So
+ * at 1 Mhz sampling rate, expect your CPU to be spending almost all of its
+ * time in the interrupt handler.
+ *
+ * This board has some unusual restrictions for its channel/gain list.  If the
+ * list has 2 or more channels in it, then two conditions must be satisfied:
+ * (1) - even/odd channels must appear at even/odd indices in the list
+ * (2) - the list must have an even number of entries.
+ *
+ * Configuration options:
+ *   [0] - base io address
+ *   [1] - irq (optional, but you probably want it)
+ *
+ * irq can be omitted, although the cmd interface will not work without it.
+ */
 
 #include 
 #include 
-- 
2.6.3

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


[PATCH 25/25] staging: comedi: das16m1: update the MODULE_DESCRIPTION

2016-05-03 Thread H Hartley Sweeten
Change the MODULE_DESCRIPTION to something more usefull than the generic
"Comedi low-level driver".

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

diff --git a/drivers/staging/comedi/drivers/das16m1.c 
b/drivers/staging/comedi/drivers/das16m1.c
index 7185b85..bb8d6ec 100644
--- a/drivers/staging/comedi/drivers/das16m1.c
+++ b/drivers/staging/comedi/drivers/das16m1.c
@@ -627,5 +627,5 @@ static struct comedi_driver das16m1_driver = {
 module_comedi_driver(das16m1_driver);
 
 MODULE_AUTHOR("Comedi http://www.comedi.org";);
-MODULE_DESCRIPTION("Comedi low-level driver");
+MODULE_DESCRIPTION("Comedi driver for CIO-DAS16/M1 ISA cards");
 MODULE_LICENSE("GPL");
-- 
2.6.3

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


[PATCH 05/25] staging: comedi: das16m1: tidy up register map comment

2016-05-03 Thread H Hartley Sweeten
The comment about all the registers is not neccessary. The defines
give the same information. This also fixes a checkpatch.pl issue:
WARNING: Block comments use * on subsequent lines

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

diff --git a/drivers/staging/comedi/drivers/das16m1.c 
b/drivers/staging/comedi/drivers/das16m1.c
index 078b26e..6638a9a 100644
--- a/drivers/staging/comedi/drivers/das16m1.c
+++ b/drivers/staging/comedi/drivers/das16m1.c
@@ -61,25 +61,8 @@
 #define FIFO_SIZE 1024 /*  1024 sample fifo */
 
 /*
-CIO-DAS16_M1.pdf
-
-"cio-das16/m1"
-
-  0a/d bits 0-3, mux   start 12 bit
-  1a/d bits 4-11   unused
-  2status  control
-  3di 4 bitdo 4 bit
-  4unused  clear interrupt
-  5interrupt, pacer
-  6channel/gain queue address
-  7channel/gain queue data
-  89ab 8254
-  cdef 8254
-  400  8255
-  404-407  8254
-
-*/
-
+ * Register map (dev->iobase)
+ */
 #define DAS16M1_AI 0   /*  16-bit wide register */
 #define   AI_CHAN(x) ((x) & 0xf)
 #define DAS16M1_CS 2
-- 
2.6.3

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


[PATCH 13/25] staging: comedi: das16m1: introduce das16m1_ai_set_queue()

2016-05-03 Thread H Hartley Sweeten
Introduce a helper function to handle writing the channel/gain data to
the queue for single channel reads, (*insn_read), and multi-channel
scans, (*do_cmd).

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

diff --git a/drivers/staging/comedi/drivers/das16m1.c 
b/drivers/staging/comedi/drivers/das16m1.c
index 1a8cf92..b941dcf 100644
--- a/drivers/staging/comedi/drivers/das16m1.c
+++ b/drivers/staging/comedi/drivers/das16m1.c
@@ -112,6 +112,21 @@ struct das16m1_private_struct {
unsigned long extra_iobase;
 };
 
+static void das16m1_ai_set_queue(struct comedi_device *dev,
+unsigned int *chanspec, unsigned int len)
+{
+   unsigned int i;
+
+   for (i = 0; i < len; i++) {
+   unsigned int chan = CR_CHAN(chanspec[i]);
+   unsigned int range = CR_RANGE(chanspec[i]);
+
+   outb(i, dev->iobase + DAS16M1_Q_ADDR_REG);
+   outb(DAS16M1_Q_CHAN(chan) | DAS16M1_Q_RANGE(range),
+dev->iobase + DAS16M1_Q_REG);
+   }
+}
+
 static void munge_sample_array(unsigned short *array, unsigned int 
num_elements)
 {
unsigned int i;
@@ -225,7 +240,7 @@ static int das16m1_cmd_exec(struct comedi_device *dev,
struct das16m1_private_struct *devpriv = dev->private;
struct comedi_async *async = s->async;
struct comedi_cmd *cmd = &async->cmd;
-   unsigned int byte, i;
+   unsigned int byte;
 
/*  set software count */
devpriv->adc_count = 0;
@@ -244,14 +259,7 @@ static int das16m1_cmd_exec(struct comedi_device *dev,
 */
devpriv->initial_hw_count = comedi_8254_read(devpriv->counter, 1);
 
-   /* setup channel/gain queue */
-   for (i = 0; i < cmd->chanlist_len; i++) {
-   outb(i, dev->iobase + DAS16M1_Q_ADDR_REG);
-   byte =
-   DAS16M1_Q_CHAN(CR_CHAN(cmd->chanlist[i])) |
-   DAS16M1_Q_RANGE(CR_RANGE(cmd->chanlist[i]));
-   outb(byte, dev->iobase + DAS16M1_Q_REG);
-   }
+   das16m1_ai_set_queue(dev, cmd->chanlist, cmd->chanlist_len);
 
/* enable interrupts and set internal pacer counter mode and counts */
devpriv->intr_ctrl &= ~DAS16M1_INTR_CTRL_PACER_MASK;
@@ -314,13 +322,8 @@ static int das16m1_ai_rinsn(struct comedi_device *dev,
 {
int ret;
int n;
-   int byte;
 
-   /* setup channel/gain queue */
-   outb(0, dev->iobase + DAS16M1_Q_ADDR_REG);
-   byte = DAS16M1_Q_CHAN(CR_CHAN(insn->chanspec)) |
-  DAS16M1_Q_RANGE(CR_RANGE(insn->chanspec));
-   outb(byte, dev->iobase + DAS16M1_Q_REG);
+   das16m1_ai_set_queue(dev, &insn->chanspec, 1);
 
for (n = 0; n < insn->n; n++) {
unsigned short val;
-- 
2.6.3

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


[PATCH 03/25] staging: comedi: das16m1: tidy up comment in das16m1_cmd_exec()

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

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

diff --git a/drivers/staging/comedi/drivers/das16m1.c 
b/drivers/staging/comedi/drivers/das16m1.c
index 75e096a..05ceb13 100644
--- a/drivers/staging/comedi/drivers/das16m1.c
+++ b/drivers/staging/comedi/drivers/das16m1.c
@@ -291,8 +291,10 @@ static int das16m1_cmd_exec(struct comedi_device *dev,
 
/*  set control & status register */
byte = 0;
-   /* if we are using external start trigger (also board dislikes having
-* both start and conversion triggers external simultaneously) */
+   /*
+* If we are using external start trigger (also board dislikes having
+* both start and conversion triggers external simultaneously).
+*/
if (cmd->start_src == TRIG_EXT && cmd->convert_src != TRIG_EXT)
byte |= EXT_TRIG_BIT;
 
-- 
2.6.3

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


[PATCH 02/25] staging: comedi: das16m1: tidy up comments in das16m1_handler()

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

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

diff --git a/drivers/staging/comedi/drivers/das16m1.c 
b/drivers/staging/comedi/drivers/das16m1.c
index 90d3869..75e096a 100644
--- a/drivers/staging/comedi/drivers/das16m1.c
+++ b/drivers/staging/comedi/drivers/das16m1.c
@@ -405,20 +405,24 @@ static void das16m1_handler(struct comedi_device *dev, 
unsigned int status)
 
/* figure out how many samples are in fifo */
hw_counter = comedi_8254_read(devpriv->counter, 1);
-   /* make sure hardware counter reading is not bogus due to initial value
-* not having been loaded yet */
+   /*
+* Make sure hardware counter reading is not bogus due to initial
+* value not having been loaded yet.
+*/
if (devpriv->adc_count == 0 &&
hw_counter == devpriv->initial_hw_count) {
num_samples = 0;
} else {
-   /* The calculation of num_samples looks odd, but it uses the
+   /*
+* The calculation of num_samples looks odd, but it uses the
 * following facts. 16 bit hardware counter is initialized with
 * value of zero (which really means 0x1000).  The counter
 * decrements by one on each conversion (when the counter
 * decrements from zero it goes to 0x).  num_samples is a
 * 16 bit variable, so it will roll over in a similar fashion
 * to the hardware counter.  Work it out, and this is what you
-* get. */
+* get.
+*/
num_samples = -hw_counter - devpriv->adc_count;
}
/*  check if we only need some of the points */
@@ -441,8 +445,10 @@ static void das16m1_handler(struct comedi_device *dev, 
unsigned int status)
}
}
 
-   /* this probably won't catch overruns since the card doesn't generate
-* overrun interrupts, but we might as well try */
+   /*
+* This probably won't catch overruns since the card doesn't generate
+* overrun interrupts, but we might as well try.
+*/
if (status & OVRUN) {
async->events |= COMEDI_CB_ERROR;
dev_err(dev->class_dev, "fifo overflow\n");
-- 
2.6.3

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


[PATCH 12/25] staging: comedi: das16m1: tidy up queue register defines

2016-05-03 Thread H Hartley Sweeten
Rename these defines.

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

diff --git a/drivers/staging/comedi/drivers/das16m1.c 
b/drivers/staging/comedi/drivers/das16m1.c
index 5b1d1fc..1a8cf92 100644
--- a/drivers/staging/comedi/drivers/das16m1.c
+++ b/drivers/staging/comedi/drivers/das16m1.c
@@ -80,11 +80,10 @@
 #define DAS16M1_INTR_CTRL_PACER_MASK   DAS16M1_INTR_CTRL_PACER(3)
 #define DAS16M1_INTR_CTRL_IRQ(x)   (((x) & 0x7) << 4)
 #define DAS16M1_INTR_CTRL_INTE BIT(7)
-#define DAS16M1_QUEUE_ADDR 6
-#define DAS16M1_QUEUE_DATA 7
-#define   Q_CHAN(x)  ((x) & 0x7)
-#define   Q_RANGE(x) (((x) & 0xf) << 4)
-#define   UNIPOLAR   0x40
+#define DAS16M1_Q_ADDR_REG 0x06
+#define DAS16M1_Q_REG  0x07
+#define DAS16M1_Q_CHAN(x)  (((x) & 0x7) << 0)
+#define DAS16M1_Q_RANGE(x) (((x) & 0xf) << 4)
 #define DAS16M1_8254_FIRST 0x8
 #define DAS16M1_8254_SECOND0xc
 #define DAS16M1_82C55  0x400
@@ -247,11 +246,11 @@ static int das16m1_cmd_exec(struct comedi_device *dev,
 
/* setup channel/gain queue */
for (i = 0; i < cmd->chanlist_len; i++) {
-   outb(i, dev->iobase + DAS16M1_QUEUE_ADDR);
+   outb(i, dev->iobase + DAS16M1_Q_ADDR_REG);
byte =
-   Q_CHAN(CR_CHAN(cmd->chanlist[i])) |
-   Q_RANGE(CR_RANGE(cmd->chanlist[i]));
-   outb(byte, dev->iobase + DAS16M1_QUEUE_DATA);
+   DAS16M1_Q_CHAN(CR_CHAN(cmd->chanlist[i])) |
+   DAS16M1_Q_RANGE(CR_RANGE(cmd->chanlist[i]));
+   outb(byte, dev->iobase + DAS16M1_Q_REG);
}
 
/* enable interrupts and set internal pacer counter mode and counts */
@@ -318,10 +317,10 @@ static int das16m1_ai_rinsn(struct comedi_device *dev,
int byte;
 
/* setup channel/gain queue */
-   outb(0, dev->iobase + DAS16M1_QUEUE_ADDR);
-   byte =
-   Q_CHAN(CR_CHAN(insn->chanspec)) | Q_RANGE(CR_RANGE(insn->chanspec));
-   outb(byte, dev->iobase + DAS16M1_QUEUE_DATA);
+   outb(0, dev->iobase + DAS16M1_Q_ADDR_REG);
+   byte = DAS16M1_Q_CHAN(CR_CHAN(insn->chanspec)) |
+  DAS16M1_Q_RANGE(CR_RANGE(insn->chanspec));
+   outb(byte, dev->iobase + DAS16M1_Q_REG);
 
for (n = 0; n < insn->n; n++) {
unsigned short val;
-- 
2.6.3

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


[PATCH 10/25] staging: comedi: das16m1: remove unnecessary ai 'cancel' operations

2016-05-03 Thread H Hartley Sweeten
The comedi core will only call the (*insn_read) and (*do_cmd) functions
if the subdevice is not "busy". All async commands are terminated by
a (*cancel) operation which clears the INTE and PACER_MASK bits in the
interrupt control register. These bits are also cleared when the driver
first attaches. There is no need for the (*insn_read) or (*do_cmd) to
duplicate the cancel.

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

diff --git a/drivers/staging/comedi/drivers/das16m1.c 
b/drivers/staging/comedi/drivers/das16m1.c
index dcec4e2..ce788ae 100644
--- a/drivers/staging/comedi/drivers/das16m1.c
+++ b/drivers/staging/comedi/drivers/das16m1.c
@@ -226,10 +226,6 @@ static int das16m1_cmd_exec(struct comedi_device *dev,
struct comedi_cmd *cmd = &async->cmd;
unsigned int byte, i;
 
-   /* disable interrupts and internal pacer */
-   devpriv->control_state &= ~INTE & ~PACER_MASK;
-   outb(devpriv->control_state, dev->iobase + DAS16M1_INTR_CONTROL);
-
/*  set software count */
devpriv->adc_count = 0;
 
@@ -313,15 +309,10 @@ static int das16m1_ai_rinsn(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
 {
-   struct das16m1_private_struct *devpriv = dev->private;
int ret;
int n;
int byte;
 
-   /* disable interrupts and internal pacer */
-   devpriv->control_state &= ~INTE & ~PACER_MASK;
-   outb(devpriv->control_state, dev->iobase + DAS16M1_INTR_CONTROL);
-
/* setup channel/gain queue */
outb(0, dev->iobase + DAS16M1_QUEUE_ADDR);
byte =
-- 
2.6.3

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


[PATCH 22/25] staging: comedi: das16m1: minor cleanup to das16m1_ai_insn_read()

2016-05-03 Thread H Hartley Sweeten
The (*insn_read) functions return the number of data values read. The 'n'
value is correct but for clarity change the return to 'insn->n'.

For aesthetics, change the 'n' loop variable name to 'i'. That's more common
in comedi drivers.

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

diff --git a/drivers/staging/comedi/drivers/das16m1.c 
b/drivers/staging/comedi/drivers/das16m1.c
index d4b1b92..c0f2796 100644
--- a/drivers/staging/comedi/drivers/das16m1.c
+++ b/drivers/staging/comedi/drivers/das16m1.c
@@ -324,11 +324,11 @@ static int das16m1_ai_insn_read(struct comedi_device *dev,
unsigned int *data)
 {
int ret;
-   int n;
+   int i;
 
das16m1_ai_set_queue(dev, &insn->chanspec, 1);
 
-   for (n = 0; n < insn->n; n++) {
+   for (i = 0; i < insn->n; i++) {
unsigned short val;
 
/* clear interrupt */
@@ -341,10 +341,10 @@ static int das16m1_ai_insn_read(struct comedi_device *dev,
return ret;
 
val = inw(dev->iobase + DAS16M1_AI_REG);
-   data[n] = DAS16M1_AI_TO_SAMPLE(val);
+   data[i] = DAS16M1_AI_TO_SAMPLE(val);
}
 
-   return n;
+   return insn->n;
 }
 
 static int das16m1_di_insn_bits(struct comedi_device *dev,
-- 
2.6.3

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


[PATCH 11/25] staging: comedi: das16m1: tidy up interrupt control register defines

2016-05-03 Thread H Hartley Sweeten
Rename these defines and use the BIT macro to define the bits. Define
some macros for the multi-bit fields in the register.

Rename the private data 'control_state' member to better match the
register name.

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

diff --git a/drivers/staging/comedi/drivers/das16m1.c 
b/drivers/staging/comedi/drivers/das16m1.c
index ce788ae..5b1d1fc 100644
--- a/drivers/staging/comedi/drivers/das16m1.c
+++ b/drivers/staging/comedi/drivers/das16m1.c
@@ -73,11 +73,13 @@
 #define DAS16M1_DI_REG 0x03
 #define DAS16M1_DO_REG 0x03
 #define DAS16M1_CLR_INTR_REG   0x04
-#define DAS16M1_INTR_CONTROL   5
-#define   EXT_PACER  0x2
-#define   INT_PACER  0x3
-#define   PACER_MASK 0x3
-#define   INTE   0x80
+#define DAS16M1_INTR_CTRL_REG  0x05
+#define DAS16M1_INTR_CTRL_PACER(x) (((x) & 0x3) << 0)
+#define DAS16M1_INTR_CTRL_PACER_EXTDAS16M1_INTR_CTRL_PACER(2)
+#define DAS16M1_INTR_CTRL_PACER_INTDAS16M1_INTR_CTRL_PACER(3)
+#define DAS16M1_INTR_CTRL_PACER_MASK   DAS16M1_INTR_CTRL_PACER(3)
+#define DAS16M1_INTR_CTRL_IRQ(x)   (((x) & 0x7) << 4)
+#define DAS16M1_INTR_CTRL_INTE BIT(7)
 #define DAS16M1_QUEUE_ADDR 6
 #define DAS16M1_QUEUE_DATA 7
 #define   Q_CHAN(x)  ((x) & 0x7)
@@ -104,7 +106,7 @@ static const struct comedi_lrange range_das16m1 = {
 
 struct das16m1_private_struct {
struct comedi_8254 *counter;
-   unsigned int control_state;
+   unsigned int intr_ctrl;
unsigned int adc_count;
u16 initial_hw_count;
unsigned short ai_buffer[FIFO_SIZE];
@@ -253,13 +255,13 @@ static int das16m1_cmd_exec(struct comedi_device *dev,
}
 
/* enable interrupts and set internal pacer counter mode and counts */
-   devpriv->control_state &= ~PACER_MASK;
+   devpriv->intr_ctrl &= ~DAS16M1_INTR_CTRL_PACER_MASK;
if (cmd->convert_src == TRIG_TIMER) {
comedi_8254_update_divisors(dev->pacer);
comedi_8254_pacer_enable(dev->pacer, 1, 2, true);
-   devpriv->control_state |= INT_PACER;
+   devpriv->intr_ctrl |= DAS16M1_INTR_CTRL_PACER_INT;
} else {/* TRIG_EXT */
-   devpriv->control_state |= EXT_PACER;
+   devpriv->intr_ctrl |= DAS16M1_INTR_CTRL_PACER_EXT;
}
 
/*  set control & status register */
@@ -276,8 +278,8 @@ static int das16m1_cmd_exec(struct comedi_device *dev,
/* clear interrupt */
outb(0, dev->iobase + DAS16M1_CLR_INTR_REG);
 
-   devpriv->control_state |= INTE;
-   outb(devpriv->control_state, dev->iobase + DAS16M1_INTR_CONTROL);
+   devpriv->intr_ctrl |= DAS16M1_INTR_CTRL_INTE;
+   outb(devpriv->intr_ctrl, dev->iobase + DAS16M1_INTR_CTRL_REG);
 
return 0;
 }
@@ -286,8 +288,10 @@ static int das16m1_cancel(struct comedi_device *dev, 
struct comedi_subdevice *s)
 {
struct das16m1_private_struct *devpriv = dev->private;
 
-   devpriv->control_state &= ~INTE & ~PACER_MASK;
-   outb(devpriv->control_state, dev->iobase + DAS16M1_INTR_CONTROL);
+   /* disable interrupts and pacer */
+   devpriv->intr_ctrl &= ~(DAS16M1_INTR_CTRL_INTE |
+   DAS16M1_INTR_CTRL_PACER_MASK);
+   outb(devpriv->intr_ctrl, dev->iobase + DAS16M1_INTR_CTRL_REG);
 
return 0;
 }
@@ -592,8 +596,8 @@ static int das16m1_attach(struct comedi_device *dev,
outb(0, dev->iobase + DAS16M1_DO_REG);
 
/* set the interrupt level */
-   devpriv->control_state = das16m1_irq_bits(dev->irq) << 4;
-   outb(devpriv->control_state, dev->iobase + DAS16M1_INTR_CONTROL);
+   devpriv->intr_ctrl = DAS16M1_INTR_CTRL_IRQ(das16m1_irq_bits(dev->irq));
+   outb(devpriv->intr_ctrl, dev->iobase + DAS16M1_INTR_CTRL_REG);
 
return 0;
 }
-- 
2.6.3

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


[PATCH 06/25] staging: comedi: das16m1: tidy up analog input data register defines

2016-05-03 Thread H Hartley Sweeten
Convert the inline helper munge_sample() into a macro and rename the
defines for the analog input data register/bits. Use the register define
when accessing this register instead of just dev->iobase.

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

diff --git a/drivers/staging/comedi/drivers/das16m1.c 
b/drivers/staging/comedi/drivers/das16m1.c
index 6638a9a..2c7c86c 100644
--- a/drivers/staging/comedi/drivers/das16m1.c
+++ b/drivers/staging/comedi/drivers/das16m1.c
@@ -63,8 +63,9 @@
 /*
  * Register map (dev->iobase)
  */
-#define DAS16M1_AI 0   /*  16-bit wide register */
-#define   AI_CHAN(x) ((x) & 0xf)
+#define DAS16M1_AI_REG 0x00/* 16-bit register */
+#define DAS16M1_AI_TO_CHAN(x)  (((x) >> 0) & 0xf)
+#define DAS16M1_AI_TO_SAMPLE(x)(((x) >> 4) & 0xfff)
 #define DAS16M1_CS 2
 #define   EXT_TRIG_BIT   0x1
 #define   OVRUN  0x20
@@ -109,17 +110,12 @@ struct das16m1_private_struct {
unsigned long extra_iobase;
 };
 
-static inline unsigned short munge_sample(unsigned short data)
-{
-   return (data >> 4) & 0xfff;
-}
-
 static void munge_sample_array(unsigned short *array, unsigned int 
num_elements)
 {
unsigned int i;
 
for (i = 0; i < num_elements; i++)
-   array[i] = munge_sample(array[i]);
+   array[i] = DAS16M1_AI_TO_SAMPLE(array[i]);
 }
 
 static int das16m1_ai_check_chanlist(struct comedi_device *dev,
@@ -331,16 +327,19 @@ static int das16m1_ai_rinsn(struct comedi_device *dev,
outb(byte, dev->iobase + DAS16M1_QUEUE_DATA);
 
for (n = 0; n < insn->n; n++) {
+   unsigned short val;
+
/* clear IRQDATA bit */
outb(0, dev->iobase + DAS16M1_CLEAR_INTR);
/* trigger conversion */
-   outb(0, dev->iobase);
+   outb(0, dev->iobase + DAS16M1_AI_REG);
 
ret = comedi_timeout(dev, s, insn, das16m1_ai_eoc, 0);
if (ret)
return ret;
 
-   data[n] = munge_sample(inw(dev->iobase));
+   val = inw(dev->iobase + DAS16M1_AI_REG);
+   data[n] = DAS16M1_AI_TO_SAMPLE(val);
}
 
return n;
-- 
2.6.3

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


[PATCH 14/25] staging: comedi: das16m1: tidy up analog input subdevice init

2016-05-03 Thread H Hartley Sweeten
Add some whitespace to the subdevice init and rename the support
functions.

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

diff --git a/drivers/staging/comedi/drivers/das16m1.c 
b/drivers/staging/comedi/drivers/das16m1.c
index b941dcf..b19715c 100644
--- a/drivers/staging/comedi/drivers/das16m1.c
+++ b/drivers/staging/comedi/drivers/das16m1.c
@@ -163,8 +163,9 @@ static int das16m1_ai_check_chanlist(struct comedi_device 
*dev,
return 0;
 }
 
-static int das16m1_cmd_test(struct comedi_device *dev,
-   struct comedi_subdevice *s, struct comedi_cmd *cmd)
+static int das16m1_ai_cmdtest(struct comedi_device *dev,
+ struct comedi_subdevice *s,
+ struct comedi_cmd *cmd)
 {
int err = 0;
 
@@ -234,8 +235,8 @@ static int das16m1_cmd_test(struct comedi_device *dev,
return 0;
 }
 
-static int das16m1_cmd_exec(struct comedi_device *dev,
-   struct comedi_subdevice *s)
+static int das16m1_ai_cmd(struct comedi_device *dev,
+ struct comedi_subdevice *s)
 {
struct das16m1_private_struct *devpriv = dev->private;
struct comedi_async *async = s->async;
@@ -291,7 +292,8 @@ static int das16m1_cmd_exec(struct comedi_device *dev,
return 0;
 }
 
-static int das16m1_cancel(struct comedi_device *dev, struct comedi_subdevice 
*s)
+static int das16m1_ai_cancel(struct comedi_device *dev,
+struct comedi_subdevice *s)
 {
struct das16m1_private_struct *devpriv = dev->private;
 
@@ -316,9 +318,10 @@ static int das16m1_ai_eoc(struct comedi_device *dev,
return -EBUSY;
 }
 
-static int das16m1_ai_rinsn(struct comedi_device *dev,
-   struct comedi_subdevice *s,
-   struct comedi_insn *insn, unsigned int *data)
+static int das16m1_ai_insn_read(struct comedi_device *dev,
+   struct comedi_subdevice *s,
+   struct comedi_insn *insn,
+   unsigned int *data)
 {
int ret;
int n;
@@ -437,7 +440,8 @@ static void das16m1_handler(struct comedi_device *dev, 
unsigned int status)
comedi_handle_events(dev, s);
 }
 
-static int das16m1_poll(struct comedi_device *dev, struct comedi_subdevice *s)
+static int das16m1_ai_poll(struct comedi_device *dev,
+  struct comedi_subdevice *s)
 {
unsigned long flags;
unsigned int status;
@@ -552,22 +556,22 @@ static int das16m1_attach(struct comedi_device *dev,
if (ret)
return ret;
 
+   /* Analog Input subdevice */
s = &dev->subdevices[0];
-   /* ai */
-   s->type = COMEDI_SUBD_AI;
-   s->subdev_flags = SDF_READABLE | SDF_DIFF;
-   s->n_chan = 8;
-   s->maxdata = (1 << 12) - 1;
-   s->range_table = &range_das16m1;
-   s->insn_read = das16m1_ai_rinsn;
+   s->type = COMEDI_SUBD_AI;
+   s->subdev_flags = SDF_READABLE | SDF_DIFF;
+   s->n_chan   = 8;
+   s->maxdata  = 0x0fff;
+   s->range_table  = &range_das16m1;
+   s->insn_read= das16m1_ai_insn_read;
if (dev->irq) {
dev->read_subdev = s;
-   s->subdev_flags |= SDF_CMD_READ;
-   s->len_chanlist = 256;
-   s->do_cmdtest = das16m1_cmd_test;
-   s->do_cmd = das16m1_cmd_exec;
-   s->cancel = das16m1_cancel;
-   s->poll = das16m1_poll;
+   s->subdev_flags |= SDF_CMD_READ;
+   s->len_chanlist = 256;
+   s->do_cmdtest   = das16m1_ai_cmdtest;
+   s->do_cmd   = das16m1_ai_cmd;
+   s->cancel   = das16m1_ai_cancel;
+   s->poll = das16m1_ai_poll;
}
 
s = &dev->subdevices[1];
-- 
2.6.3

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


[PATCH 17/25] staging: comedi: das16m1: tidy up digital output subdevice init

2016-05-03 Thread H Hartley Sweeten
Add some whitespace to the subdevice init and rename the support
function.

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

diff --git a/drivers/staging/comedi/drivers/das16m1.c 
b/drivers/staging/comedi/drivers/das16m1.c
index 538544b..cb5cd5e 100644
--- a/drivers/staging/comedi/drivers/das16m1.c
+++ b/drivers/staging/comedi/drivers/das16m1.c
@@ -357,10 +357,10 @@ static int das16m1_di_insn_bits(struct comedi_device *dev,
return insn->n;
 }
 
-static int das16m1_do_wbits(struct comedi_device *dev,
-   struct comedi_subdevice *s,
-   struct comedi_insn *insn,
-   unsigned int *data)
+static int das16m1_do_insn_bits(struct comedi_device *dev,
+   struct comedi_subdevice *s,
+   struct comedi_insn *insn,
+   unsigned int *data)
 {
if (comedi_dio_update_state(s, data))
outb(s->state, dev->iobase + DAS16M1_DO_REG);
@@ -580,14 +580,14 @@ static int das16m1_attach(struct comedi_device *dev,
s->range_table  = &range_digital;
s->insn_bits= das16m1_di_insn_bits;
 
+   /* Digital Output subdevice */
s = &dev->subdevices[2];
-   /* do */
-   s->type = COMEDI_SUBD_DO;
-   s->subdev_flags = SDF_WRITABLE;
-   s->n_chan = 4;
-   s->maxdata = 1;
-   s->range_table = &range_digital;
-   s->insn_bits = das16m1_do_wbits;
+   s->type = COMEDI_SUBD_DO;
+   s->subdev_flags = SDF_WRITABLE;
+   s->n_chan   = 4;
+   s->maxdata  = 1;
+   s->range_table  = &range_digital;
+   s->insn_bits= das16m1_do_insn_bits;
 
s = &dev->subdevices[3];
/* 8255 */
-- 
2.6.3

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


[PATCH 23/25] staging: comedi: das16m1: convert munge_sample_array() into a subdevice (*munge)

2016-05-03 Thread H Hartley Sweeten
For aesthetics, convert this function into a subdevice (*munge) function and let
the comedi core handle the munging.

Add a comment about why the data needs to be munged.

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

diff --git a/drivers/staging/comedi/drivers/das16m1.c 
b/drivers/staging/comedi/drivers/das16m1.c
index c0f2796..a803032 100644
--- a/drivers/staging/comedi/drivers/das16m1.c
+++ b/drivers/staging/comedi/drivers/das16m1.c
@@ -127,11 +127,21 @@ static void das16m1_ai_set_queue(struct comedi_device 
*dev,
}
 }
 
-static void munge_sample_array(unsigned short *array, unsigned int 
num_elements)
+static void das16m1_ai_munge(struct comedi_device *dev,
+struct comedi_subdevice *s,
+void *data, unsigned int num_bytes,
+unsigned int start_chan_index)
 {
+   unsigned short *array = data;
+   unsigned int nsamples = comedi_bytes_to_samples(s, num_bytes);
unsigned int i;
 
-   for (i = 0; i < num_elements; i++)
+   /*
+* The fifo values have the channel number in the lower 4-bits and
+* the sample in the upper 12-bits. This just shifts the values
+* to remove the channel numbers.
+*/
+   for (i = 0; i < nsamples; i++)
array[i] = DAS16M1_AI_TO_SAMPLE(array[i]);
 }
 
@@ -410,7 +420,6 @@ static void das16m1_handler(struct comedi_device *dev, 
unsigned int status)
if (num_samples > DAS16M1_AI_FIFO_SZ)
num_samples = DAS16M1_AI_FIFO_SZ;
insw(dev->iobase, devpriv->ai_buffer, num_samples);
-   munge_sample_array(devpriv->ai_buffer, num_samples);
comedi_buf_write_samples(s, devpriv->ai_buffer, num_samples);
devpriv->adc_count += num_samples;
 
@@ -560,6 +569,7 @@ static int das16m1_attach(struct comedi_device *dev,
s->do_cmd   = das16m1_ai_cmd;
s->cancel   = das16m1_ai_cancel;
s->poll = das16m1_ai_poll;
+   s->munge= das16m1_ai_munge;
}
 
/* Digital Input subdevice */
-- 
2.6.3

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


[PATCH 20/25] staging: comedi: das16m1: remove an unnecessery comment

2016-05-03 Thread H Hartley Sweeten
The configuration options are listed in the comedi comment block.

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

diff --git a/drivers/staging/comedi/drivers/das16m1.c 
b/drivers/staging/comedi/drivers/das16m1.c
index 6797da1..3a62f5a 100644
--- a/drivers/staging/comedi/drivers/das16m1.c
+++ b/drivers/staging/comedi/drivers/das16m1.c
@@ -505,11 +505,6 @@ static int das16m1_irq_bits(unsigned int irq)
}
 }
 
-/*
- * Options list:
- *   0  I/O base
- *   1  IRQ
- */
 static int das16m1_attach(struct comedi_device *dev,
  struct comedi_devconfig *it)
 {
-- 
2.6.3

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


[PATCH 21/25] staging: comedi: das16m1: init local variables when declared

2016-05-03 Thread H Hartley Sweeten
For aesthetics, init the comedi_subdevice, comedi_async, and comedi_cmd
pointers when the local variables are declared.

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

diff --git a/drivers/staging/comedi/drivers/das16m1.c 
b/drivers/staging/comedi/drivers/das16m1.c
index 3a62f5a..d4b1b92 100644
--- a/drivers/staging/comedi/drivers/das16m1.c
+++ b/drivers/staging/comedi/drivers/das16m1.c
@@ -373,16 +373,12 @@ static int das16m1_do_insn_bits(struct comedi_device *dev,
 static void das16m1_handler(struct comedi_device *dev, unsigned int status)
 {
struct das16m1_private_struct *devpriv = dev->private;
-   struct comedi_subdevice *s;
-   struct comedi_async *async;
-   struct comedi_cmd *cmd;
+   struct comedi_subdevice *s = dev->read_subdev;
+   struct comedi_async *async = s->async;
+   struct comedi_cmd *cmd = &async->cmd;
u16 num_samples;
u16 hw_counter;
 
-   s = dev->read_subdev;
-   async = s->async;
-   cmd = &async->cmd;
-
/* figure out how many samples are in fifo */
hw_counter = comedi_8254_read(devpriv->counter, 1);
/*
-- 
2.6.3

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


[PATCH 09/25] staging: comedi: das16m1: tidy up clear interrupt register define

2016-05-03 Thread H Hartley Sweeten
Rename this define and use a consistent comment throughout the code.

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

diff --git a/drivers/staging/comedi/drivers/das16m1.c 
b/drivers/staging/comedi/drivers/das16m1.c
index e85d989..dcec4e2 100644
--- a/drivers/staging/comedi/drivers/das16m1.c
+++ b/drivers/staging/comedi/drivers/das16m1.c
@@ -72,7 +72,7 @@
 #define DAS16M1_CS_IRQDATA BIT(7)
 #define DAS16M1_DI_REG 0x03
 #define DAS16M1_DO_REG 0x03
-#define DAS16M1_CLEAR_INTR 4
+#define DAS16M1_CLR_INTR_REG   0x04
 #define DAS16M1_INTR_CONTROL   5
 #define   EXT_PACER  0x2
 #define   INT_PACER  0x3
@@ -276,8 +276,9 @@ static int das16m1_cmd_exec(struct comedi_device *dev,
byte |= DAS16M1_CS_EXT_TRIG;
 
outb(byte, dev->iobase + DAS16M1_CS_REG);
-   /* clear interrupt bit */
-   outb(0, dev->iobase + DAS16M1_CLEAR_INTR);
+
+   /* clear interrupt */
+   outb(0, dev->iobase + DAS16M1_CLR_INTR_REG);
 
devpriv->control_state |= INTE;
outb(devpriv->control_state, dev->iobase + DAS16M1_INTR_CONTROL);
@@ -330,8 +331,8 @@ static int das16m1_ai_rinsn(struct comedi_device *dev,
for (n = 0; n < insn->n; n++) {
unsigned short val;
 
-   /* clear DAS16M1_CS_IRQDATA bit */
-   outb(0, dev->iobase + DAS16M1_CLEAR_INTR);
+   /* clear interrupt */
+   outb(0, dev->iobase + DAS16M1_CLR_INTR_REG);
/* trigger conversion */
outb(0, dev->iobase + DAS16M1_AI_REG);
 
@@ -476,7 +477,7 @@ static irqreturn_t das16m1_interrupt(int irq, void *d)
das16m1_handler(dev, status);
 
/* clear interrupt */
-   outb(0, dev->iobase + DAS16M1_CLEAR_INTR);
+   outb(0, dev->iobase + DAS16M1_CLR_INTR_REG);
 
spin_unlock(&dev->spinlock);
return IRQ_HANDLED;
-- 
2.6.3

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


[PATCH 15/25] staging: comedi: das16m1: tidy up digital input subdevice init

2016-05-03 Thread H Hartley Sweeten
Add some whitespace to the subdevice init and rename the support
function.

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

diff --git a/drivers/staging/comedi/drivers/das16m1.c 
b/drivers/staging/comedi/drivers/das16m1.c
index b19715c..f51da80 100644
--- a/drivers/staging/comedi/drivers/das16m1.c
+++ b/drivers/staging/comedi/drivers/das16m1.c
@@ -347,9 +347,10 @@ static int das16m1_ai_insn_read(struct comedi_device *dev,
return n;
 }
 
-static int das16m1_di_rbits(struct comedi_device *dev,
-   struct comedi_subdevice *s,
-   struct comedi_insn *insn, unsigned int *data)
+static int das16m1_di_insn_bits(struct comedi_device *dev,
+   struct comedi_subdevice *s,
+   struct comedi_insn *insn,
+   unsigned int *data)
 {
unsigned int bits;
 
@@ -574,14 +575,14 @@ static int das16m1_attach(struct comedi_device *dev,
s->poll = das16m1_ai_poll;
}
 
+   /* Digital Input subdevice */
s = &dev->subdevices[1];
-   /* di */
-   s->type = COMEDI_SUBD_DI;
-   s->subdev_flags = SDF_READABLE;
-   s->n_chan = 4;
-   s->maxdata = 1;
-   s->range_table = &range_digital;
-   s->insn_bits = das16m1_di_rbits;
+   s->type = COMEDI_SUBD_DI;
+   s->subdev_flags = SDF_READABLE;
+   s->n_chan   = 4;
+   s->maxdata  = 1;
+   s->range_table  = &range_digital;
+   s->insn_bits= das16m1_di_insn_bits;
 
s = &dev->subdevices[2];
/* do */
-- 
2.6.3

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


[PATCH 00/25] staging: comedi: das16m1: cleanup driver

2016-05-03 Thread H Hartley Sweeten
Fixe all the checkpatch.pl issues and tidy up the driver.

H Hartley Sweeten (25):
  staging: comedi: das16m1: tidy up copyright and comedi comments
  staging: comedi: das16m1: tidy up comments in das16m1_handler()
  staging: comedi: das16m1: tidy up comment in das16m1_cmd_exec()
  staging: comedi: das16m1: remove unnecessary private data comments
  staging: comedi: das16m1: tidy up register map comment
  staging: comedi: das16m1: tidy up analog input data register defines
  staging: comedi: das16m1: tidy up control/status register defines
  staging: comedi: das16m1: tidy up digital input/output register defines
  staging: comedi: das16m1: tidy up clear interrupt register define
  staging: comedi: das16m1: remove unnecessary ai 'cancel' operations
  staging: comedi: das16m1: tidy up interrupt control register defines
  staging: comedi: das16m1: tidy up queue register defines
  staging: comedi: das16m1: introduce das16m1_ai_set_queue()
  staging: comedi: das16m1: tidy up analog input subdevice init
  staging: comedi: das16m1: tidy up digital input subdevice init
  staging: comedi: das16m1: tidy up das16m1_di_insn_bits()
  staging: comedi: das16m1: tidy up digital output subdevice init
  staging: comedi: das16m1: tidy up 8254/8255 register defines
  staging: comedi: das16m1: tidy up misc. defines
  staging: comedi: das16m1: remove an unnecessery comment
  staging: comedi: das16m1: init local variables when declared
  staging: comedi: das16m1: minor cleanup to das16m1_ai_insn_read()
  staging: comedi: das16m1: convert munge_sample_array() into a subdevice 
(*munge)
  staging: comedi: das16m1: rename struct das16m1_private_struct
  staging: comedi: das16m1: update the MODULE_DESCRIPTION

 drivers/staging/comedi/drivers/das16m1.c | 482 +++
 1 file changed, 233 insertions(+), 249 deletions(-)

-- 
2.6.3

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


[PATCH 19/25] staging: comedi: das16m1: tidy up misc. defines

2016-05-03 Thread H Hartley Sweeten
For aesthetics, move these after the register map defines and rename
the FIFO_SIZE define.

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

diff --git a/drivers/staging/comedi/drivers/das16m1.c 
b/drivers/staging/comedi/drivers/das16m1.c
index 824cc94..6797da1 100644
--- a/drivers/staging/comedi/drivers/das16m1.c
+++ b/drivers/staging/comedi/drivers/das16m1.c
@@ -56,10 +56,6 @@
 #include "8255.h"
 #include "comedi_8254.h"
 
-#define DAS16M1_SIZE2 8
-
-#define FIFO_SIZE 1024 /*  1024 sample fifo */
-
 /*
  * Register map (dev->iobase)
  */
@@ -89,6 +85,10 @@
 #define DAS16M1_8255_IOBASE0x400
 #define DAS16M1_8254_IOBASE3   0x404
 
+#define DAS16M1_SIZE2  0x08
+
+#define DAS16M1_AI_FIFO_SZ 1024/* # samples */
+
 static const struct comedi_lrange range_das16m1 = {
9, {
BIP_RANGE(5),
@@ -108,7 +108,7 @@ struct das16m1_private_struct {
unsigned int intr_ctrl;
unsigned int adc_count;
u16 initial_hw_count;
-   unsigned short ai_buffer[FIFO_SIZE];
+   unsigned short ai_buffer[DAS16M1_AI_FIFO_SZ];
unsigned long extra_iobase;
 };
 
@@ -411,8 +411,8 @@ static void das16m1_handler(struct comedi_device *dev, 
unsigned int status)
num_samples = cmd->stop_arg * cmd->chanlist_len;
}
/*  make sure we dont try to get too many points if fifo has overrun */
-   if (num_samples > FIFO_SIZE)
-   num_samples = FIFO_SIZE;
+   if (num_samples > DAS16M1_AI_FIFO_SZ)
+   num_samples = DAS16M1_AI_FIFO_SZ;
insw(dev->iobase, devpriv->ai_buffer, num_samples);
munge_sample_array(devpriv->ai_buffer, num_samples);
comedi_buf_write_samples(s, devpriv->ai_buffer, num_samples);
-- 
2.6.3

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


[PATCH 03/19] staging: comedi: dt2811: remove disabled code

2016-05-03 Thread H Hartley Sweeten
There is no reason the (*attach) should be trying to read an analog
input sample. Remove this disabled code.

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

diff --git a/drivers/staging/comedi/drivers/dt2811.c 
b/drivers/staging/comedi/drivers/dt2811.c
index 5d550d1..3cd9fe5 100644
--- a/drivers/staging/comedi/drivers/dt2811.c
+++ b/drivers/staging/comedi/drivers/dt2811.c
@@ -299,23 +299,15 @@ static int dt2811_do_insn_bits(struct comedi_device *dev,
 
 static int dt2811_attach(struct comedi_device *dev, struct comedi_devconfig 
*it)
 {
-   /* int i; */
const struct dt2811_board *board = dev->board_ptr;
struct dt2811_private *devpriv;
-   int ret;
struct comedi_subdevice *s;
+   int ret;
 
ret = comedi_request_region(dev, it->options[0], 0x8);
if (ret)
return ret;
 
-#if 0
-   outb(0, dev->iobase + DT2811_ADCSR);
-   udelay(100);
-   i = inb(dev->iobase + DT2811_ADDATLO);
-   i = inb(dev->iobase + DT2811_ADDATHI);
-#endif
-
ret = comedi_alloc_subdevices(dev, 4);
if (ret)
return ret;
-- 
2.6.3

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


[PATCH 08/19] staging: comedi: dt2811: tidy up Digital Input/Output register defines

2016-05-03 Thread H Hartley Sweeten
The digital input and outputs are separate ports even though they share the
same register offset. For aesthetics, define then separately and remove the
redundant information in the comment.

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

diff --git a/drivers/staging/comedi/drivers/dt2811.c 
b/drivers/staging/comedi/drivers/dt2811.c
index 1717281..61aa323 100644
--- a/drivers/staging/comedi/drivers/dt2811.c
+++ b/drivers/staging/comedi/drivers/dt2811.c
@@ -73,6 +73,9 @@
 #define DT2811_DADATA_LO_REG(x)(0x02 + ((x) * 2)) /* w D/A 
Data low */
 #define DT2811_DADATA_HI_REG(x)(0x03 + ((x) * 2)) /* w D/A 
Data high */
 
+#define DT2811_DI_REG  0x06/* r   Digital Input Port 0 */
+#define DT2811_DO_REG  0x06/* w   Digital Output Port 1 */
+
 static const struct comedi_lrange range_dt2811_pgh_ai_5_unipolar = {
4, {
UNI_RANGE(5),
@@ -128,9 +131,6 @@ static const struct comedi_lrange 
range_dt2811_pgl_ai_5_bipolar = {
 };
 
 /*
-   0x06 (R) DIO0 Digital Input Port 0
-   (W) DIO1 Digital Output Port 1
-
0x07 TMRCTR (R/W) Timer/Counter Register
bits 6,7 - reserved
bits 5-3 - Timer frequency control (mantissa)
@@ -158,7 +158,6 @@ static const struct comedi_lrange 
range_dt2811_pgl_ai_5_bipolar = {
 
 #define TIMEOUT 1
 
-#define DT2811_DIO 6
 #define DT2811_TMRCTR 7
 
 struct dt2811_board {
@@ -254,7 +253,7 @@ static int dt2811_di_insn_bits(struct comedi_device *dev,
   struct comedi_subdevice *s,
   struct comedi_insn *insn, unsigned int *data)
 {
-   data[1] = inb(dev->iobase + DT2811_DIO);
+   data[1] = inb(dev->iobase + DT2811_DI_REG);
 
return insn->n;
 }
@@ -265,7 +264,7 @@ static int dt2811_do_insn_bits(struct comedi_device *dev,
   unsigned int *data)
 {
if (comedi_dio_update_state(s, data))
-   outb(s->state, dev->iobase + DT2811_DIO);
+   outb(s->state, dev->iobase + DT2811_DO_REG);
 
data[1] = s->state;
 
-- 
2.6.3

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


[PATCH 02/19] staging: comedi: dt2811: remove redundant block comment

2016-05-03 Thread H Hartley Sweeten
The configuration options are listed in the comedi comment block.

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

diff --git a/drivers/staging/comedi/drivers/dt2811.c 
b/drivers/staging/comedi/drivers/dt2811.c
index 499637b..5d550d1 100644
--- a/drivers/staging/comedi/drivers/dt2811.c
+++ b/drivers/staging/comedi/drivers/dt2811.c
@@ -297,26 +297,6 @@ static int dt2811_do_insn_bits(struct comedi_device *dev,
return insn->n;
 }
 
-/*
-  options[0]   Board base address
-  options[1]   IRQ
-  options[2]   Input configuration
-0 == single-ended
-1 == differential
-2 == pseudo-differential
-  options[3]   Analog input range configuration
-0 == bipolar 5  (-5V -- +5V)
-1 == bipolar 2.5V  (-2.5V -- +2.5V)
-2 == unipolar 5V  (0V -- +5V)
-  options[4]   Analog output 0 range configuration
-0 == bipolar 5  (-5V -- +5V)
-1 == bipolar 2.5V  (-2.5V -- +2.5V)
-2 == unipolar 5V  (0V -- +5V)
-  options[5]   Analog output 1 range configuration
-0 == bipolar 5  (-5V -- +5V)
-1 == bipolar 2.5V  (-2.5V -- +2.5V)
-2 == unipolar 5V  (0V -- +5V)
-*/
 static int dt2811_attach(struct comedi_device *dev, struct comedi_devconfig 
*it)
 {
/* int i; */
-- 
2.6.3

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


[PATCH 07/19] staging: comedi: dt2811: tidy up D/A Data register defines

2016-05-03 Thread H Hartley Sweeten
Cleanup the defines for these registers and and remove the redundant
information in the comment.

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

diff --git a/drivers/staging/comedi/drivers/dt2811.c 
b/drivers/staging/comedi/drivers/dt2811.c
index 0c0b7b7..1717281 100644
--- a/drivers/staging/comedi/drivers/dt2811.c
+++ b/drivers/staging/comedi/drivers/dt2811.c
@@ -70,6 +70,9 @@
 #define DT2811_ADDATA_LO_REG   0x02/* r   A/D Data low byte */
 #define DT2811_ADDATA_HI_REG   0x03/* r   A/D Data high byte */
 
+#define DT2811_DADATA_LO_REG(x)(0x02 + ((x) * 2)) /* w D/A 
Data low */
+#define DT2811_DADATA_HI_REG(x)(0x03 + ((x) * 2)) /* w D/A 
Data high */
+
 static const struct comedi_lrange range_dt2811_pgh_ai_5_unipolar = {
4, {
UNI_RANGE(5),
@@ -125,14 +128,6 @@ static const struct comedi_lrange 
range_dt2811_pgl_ai_5_bipolar = {
 };
 
 /*
-
-   0x02,0x03
-   (W) DADAT0 D/A Data Register 0
-   0x02 low byte
-   0x03 high byte
-
-   0x04,0x05 (W) DADAT0 D/A Data Register 1
-
0x06 (R) DIO0 Digital Input Port 0
(W) DIO1 Digital Output Port 1
 
@@ -163,10 +158,6 @@ static const struct comedi_lrange 
range_dt2811_pgl_ai_5_bipolar = {
 
 #define TIMEOUT 1
 
-#define DT2811_DADAT0LO 2
-#define DT2811_DADAT0HI 3
-#define DT2811_DADAT1LO 4
-#define DT2811_DADAT1HI 5
 #define DT2811_DIO 6
 #define DT2811_TMRCTR 7
 
@@ -250,9 +241,9 @@ static int dt2811_ao_insn_write(struct comedi_device *dev,
 
for (i = 0; i < insn->n; i++) {
val = data[i];
-   outb(val & 0xff, dev->iobase + DT2811_DADAT0LO + 2 * chan);
+   outb(val & 0xff, dev->iobase + DT2811_DADATA_LO_REG(chan));
outb((val >> 8) & 0xff,
-dev->iobase + DT2811_DADAT0HI + 2 * chan);
+dev->iobase + DT2811_DADATA_HI_REG(chan));
}
s->readback[chan] = val;
 
-- 
2.6.3

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


[PATCH 15/19] staging: comedi: dt2811: simplify analog input range options

2016-05-03 Thread H Hartley Sweeten
The A/D ranges are not programmable but the gain is. Currently this driver
uses a configuration option to select the comedi_lrange that will be used
for the analog input subdevice. This requires that the user makes sure the
correct option value is used.

The user space library uses the range information to convert between raw
values and physical units. If the user passed an incorrect option when
attaching the driver the conversion will be incorrect.

A previous patch allowed the gain to be set based on the chanspec range.
Prior to that the gain was always set to 1 so any conversion with a gain
that is not 1 would be incorrect anyway.

Simplify the analog input ranges by providing a range_table for the pgh and
pgl boards that contain all the possible range/gain options. The user can
then select the correct range (and gain) when converting values or reading
the analog inputs.

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

diff --git a/drivers/staging/comedi/drivers/dt2811.c 
b/drivers/staging/comedi/drivers/dt2811.c
index 379b7d5..acc9db8 100644
--- a/drivers/staging/comedi/drivers/dt2811.c
+++ b/drivers/staging/comedi/drivers/dt2811.c
@@ -33,14 +33,17 @@
  *0 = single-ended (16 channels)
  *1 = differential (8 channels)
  *2 = pseudo-differential (16 channels)
- *   [3] - A/D range
- *0 = [-5, 5]
- *1 = [-2.5, 2.5]
- *2 = [0, 5]
+ *   [3] - A/D range (deprecated, see below)
  *   [4] - D/A 0 range (deprecated, see below)
  *   [5] - D/A 1 range (deprecated, see below)
  *
  * Notes:
+ *   - A/D ranges are not programmable but the gain is. The AI subdevice has
+ * a range_table containing all the possible analog input range/gain
+ * options for the dt2811-pgh or dt2811-pgl. Use the range that matches
+ * your board configuration and the desired gain to correctly convert
+ * between data values and physical units and to set the correct output
+ * gain.
  *   - D/A ranges are not programmable. The AO subdevice has a range_table
  * containing all the possible analog output ranges. Use the range
  * that matches your board configuration to convert between data
@@ -99,57 +102,52 @@
 #define DT2811_TMRCTR_MANTISSA(x)  (((x) & 0x7) << 3)
 #define DT2811_TMRCTR_EXPONENT(x)  (((x) & 0x7) << 0)
 
-static const struct comedi_lrange range_dt2811_pgh_ai_5_unipolar = {
-   4, {
-   UNI_RANGE(5),
-   UNI_RANGE(2.5),
-   UNI_RANGE(1.25),
-   UNI_RANGE(0.625)
-   }
-};
-
-static const struct comedi_lrange range_dt2811_pgh_ai_2_5_bipolar = {
-   4, {
-   BIP_RANGE(2.5),
-   BIP_RANGE(1.25),
-   BIP_RANGE(0.625),
-   BIP_RANGE(0.3125)
-   }
-};
-
-static const struct comedi_lrange range_dt2811_pgh_ai_5_bipolar = {
-   4, {
-   BIP_RANGE(5),
-   BIP_RANGE(2.5),
-   BIP_RANGE(1.25),
-   BIP_RANGE(0.625)
-   }
-};
-
-static const struct comedi_lrange range_dt2811_pgl_ai_5_unipolar = {
-   4, {
-   UNI_RANGE(5),
-   UNI_RANGE(0.5),
-   UNI_RANGE(0.05),
-   UNI_RANGE(0.01)
-   }
-};
-
-static const struct comedi_lrange range_dt2811_pgl_ai_2_5_bipolar = {
-   4, {
-   BIP_RANGE(2.5),
-   BIP_RANGE(0.25),
-   BIP_RANGE(0.025),
-   BIP_RANGE(0.005)
+/*
+ * The Analog Input range is set using jumpers on the board.
+ *
+ * Input Range W9  W10
+ * 0V to +5V   Out In
+ * -5V to +5V  In  Out
+ * -2.5V to +2.5V  In  In
+ *
+ * The gain may be set to 1, 2, 4, or 8 (on the dt2811-pgh) or to
+ * 1, 10, 100, 500 (on the dt2811-pgl).
+ */
+static const struct comedi_lrange dt2811_pgh_ai_ranges = {
+   12, {
+   UNI_RANGE(5),   /* range 0: gain=1 */
+   UNI_RANGE(2.5), /* range 1: gain=2 */
+   UNI_RANGE(1.25),/* range 2: gain=4 */
+   UNI_RANGE(0.625),   /* range 3: gain=8 */
+
+   BIP_RANGE(5),   /* range 0+4: gain=1 */
+   BIP_RANGE(2.5), /* range 1+4: gain=2 */
+   BIP_RANGE(1.25),/* range 2+4: gain=4 */
+   BIP_RANGE(0.625),   /* range 3+4: gain=8 */
+
+   BIP_RANGE(2.5), /* range 0+8: gain=1 */
+   BIP_RANGE(1.25),/* range 1+8: gain=2 */
+   BIP_RANGE(0.625),   /* range 2+8: gain=4 */
+   BIP_RANGE(0.3125)   /* range 3+8: gain=8 */
}
 };
 
-static const struct comedi_lrange range_dt2811_pgl_ai_5_bipolar = {
-   4, {
-   BIP_RANGE(5),
-   BIP_RANGE(0.5),
-   BIP_RANGE(0.05),
-   BIP_RANGE(0.01)
+static const struct c

[PATCH 06/19] staging: comedi: dt2811: tidy up A/D Data register defines

2016-05-03 Thread H Hartley Sweeten
Cleanup the defines for these registers and and remove the redundant
information in the comment.

Tidy up the reading of the data registers in the (*insn_read).

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

diff --git a/drivers/staging/comedi/drivers/dt2811.c 
b/drivers/staging/comedi/drivers/dt2811.c
index f72d6c8..0c0b7b7 100644
--- a/drivers/staging/comedi/drivers/dt2811.c
+++ b/drivers/staging/comedi/drivers/dt2811.c
@@ -67,6 +67,9 @@
 #define DT2811_ADGCR_GAIN(x)   (((x) & 0x3) << 6)
 #define DT2811_ADGCR_CHAN(x)   (((x) & 0xf) << 0)
 
+#define DT2811_ADDATA_LO_REG   0x02/* r   A/D Data low byte */
+#define DT2811_ADDATA_HI_REG   0x03/* r   A/D Data high byte */
+
 static const struct comedi_lrange range_dt2811_pgh_ai_5_unipolar = {
4, {
UNI_RANGE(5),
@@ -123,7 +126,7 @@ static const struct comedi_lrange 
range_dt2811_pgl_ai_5_bipolar = {
 
 /*
 
-   0x02,0x03 (R) ADDAT A/D Data Register
+   0x02,0x03
(W) DADAT0 D/A Data Register 0
0x02 low byte
0x03 high byte
@@ -160,8 +163,6 @@ static const struct comedi_lrange 
range_dt2811_pgl_ai_5_bipolar = {
 
 #define TIMEOUT 1
 
-#define DT2811_ADDATLO 2
-#define DT2811_ADDATHI 3
 #define DT2811_DADAT0LO 2
 #define DT2811_DADAT0HI 3
 #define DT2811_DADAT1LO 4
@@ -218,6 +219,8 @@ static int dt2811_ai_insn(struct comedi_device *dev, struct 
comedi_subdevice *s,
int i;
 
for (i = 0; i < insn->n; i++) {
+   unsigned int val;
+
/* select channel/gain and trigger conversion */
outb(DT2811_ADGCR_CHAN(chan) | DT2811_ADGCR_GAIN(range),
 dev->iobase + DT2811_ADGCR_REG);
@@ -226,9 +229,11 @@ static int dt2811_ai_insn(struct comedi_device *dev, 
struct comedi_subdevice *s,
if (ret)
return ret;
 
-   data[i] = inb(dev->iobase + DT2811_ADDATLO);
-   data[i] |= inb(dev->iobase + DT2811_ADDATHI) << 8;
-   data[i] &= 0xfff;
+   val = inb(dev->iobase + DT2811_ADDATA_LO_REG) |
+ (inb(dev->iobase + DT2811_ADDATA_HI_REG) << 8);
+   val &= s->maxdata;
+
+   data[i] = val;
}
 
return i;
-- 
2.6.3

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


[PATCH 09/19] staging: comedi: dt2811: tidy up Timer/Counter register defines

2016-05-03 Thread H Hartley Sweeten
This register currently is not being used. For aesthetics, cleanup the
define and the comment about the frequency control.

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

diff --git a/drivers/staging/comedi/drivers/dt2811.c 
b/drivers/staging/comedi/drivers/dt2811.c
index 61aa323..6ea1ad4 100644
--- a/drivers/staging/comedi/drivers/dt2811.c
+++ b/drivers/staging/comedi/drivers/dt2811.c
@@ -76,6 +76,23 @@
 #define DT2811_DI_REG  0x06/* r   Digital Input Port 0 */
 #define DT2811_DO_REG  0x06/* w   Digital Output Port 1 */
 
+/*
+ * Timer frequency control:
+ *   DT2811_TMRCTR_MANTISSADT2811_TMRCTR_EXPONENT
+ *   val  divisor  frequency   val  multiply divisor/divide frequency by
+ *0  1  600 kHz 0   1
+ *1 10   60 kHz 1   10
+ *2  2  300 kHz 2   100
+ *3  3  200 kHz 3   1000
+ *4  4  150 kHz 4   1
+ *5  5  120 kHz 5   10
+ *6  6  100 kHz 6   100
+ *7 12   50 kHz 7   1000
+ */
+#define DT2811_TMRCTR_REG  0x07/* r/w  Timer/Counter */
+#define DT2811_TMRCTR_MANTISSA(x)  (((x) & 0x7) << 3)
+#define DT2811_TMRCTR_EXPONENT(x)  (((x) & 0x7) << 0)
+
 static const struct comedi_lrange range_dt2811_pgh_ai_5_unipolar = {
4, {
UNI_RANGE(5),
@@ -130,36 +147,8 @@ static const struct comedi_lrange 
range_dt2811_pgl_ai_5_bipolar = {
}
 };
 
-/*
-   0x07 TMRCTR (R/W) Timer/Counter Register
-   bits 6,7 - reserved
-   bits 5-3 - Timer frequency control (mantissa)
-   543  divisor  freqency (kHz)
-   000  1600
-   001  10   60
-   010  2300
-   011  3200
-   100  4150
-   101  5120
-   110  6100
-   111  12   50
-   bits 2-0 - Timer frequency control (exponent)
-   210  multiply divisor/divide frequency by
-   000  1
-   001  10
-   010  100
-   011  1000
-   100  1
-   101  10
-   110  100
-   111  1000
-
- */
-
 #define TIMEOUT 1
 
-#define DT2811_TMRCTR 7
-
 struct dt2811_board {
const char *name;
const struct comedi_lrange *bip_5;
-- 
2.6.3

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


[PATCH 04/19] staging: comedi: dt2811: tidy up A/D Control/Status register defines

2016-05-03 Thread H Hartley Sweeten
Cleanup the defines for this register and its bits and remove the
redundant information in the comment.

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

diff --git a/drivers/staging/comedi/drivers/dt2811.c 
b/drivers/staging/comedi/drivers/dt2811.c
index 3cd9fe5..433cfd1 100644
--- a/drivers/staging/comedi/drivers/dt2811.c
+++ b/drivers/staging/comedi/drivers/dt2811.c
@@ -44,6 +44,25 @@
 #include 
 #include "../comedidev.h"
 
+/*
+ * Register I/O map
+ */
+#define DT2811_ADCSR_REG   0x00/* r/w  A/D Control/Status */
+#define DT2811_ADCSR_ADDONEBIT(7)  /* r  1=A/D conv done */
+#define DT2811_ADCSR_ADERROR   BIT(6)  /* r  1=A/D error */
+#define DT2811_ADCSR_ADBUSYBIT(5)  /* r  1=A/D busy */
+#define DT2811_ADCSR_CLRERROR  BIT(4)
+#define DT2811_ADCSR_INTENBBIT(2)  /* r/w1=interupts ena */
+#define DT2811_ADCSR_ADMODE(x) (((x) & 0x3) << 0)
+/* single conversion on ADGCR load */
+#define DT2811_ADCSR_ADMODE_SINGLE DT2811_ADCSR_ADMODE(0)
+/* continuous conversion, internal clock, (clock enabled on ADGCR load) */
+#define DT2811_ADCSR_ADMODE_CONT   DT2811_ADCSR_ADMODE(1)
+/* continuous conversion, internal clock, external trigger */
+#define DT2811_ADCSR_ADMODE_EXT_TRIG   DT2811_ADCSR_ADMODE(2)
+/* continuous conversion, external clock, external trigger */
+#define DT2811_ADCSR_ADMODE_EXTDT2811_ADCSR_ADMODE(3)
+
 static const struct comedi_lrange range_dt2811_pgh_ai_5_unipolar = {
4, {
UNI_RANGE(5),
@@ -100,28 +119,6 @@ static const struct comedi_lrange 
range_dt2811_pgl_ai_5_bipolar = {
 
 /*
 
-   0x00ADCSR R/W  A/D Control/Status Register
-   bit 7 - (R) 1 indicates A/D conversion done
-   reading ADDAT clears bit
-   (W) ignored
-   bit 6 - (R) 1 indicates A/D error
-   (W) ignored
-   bit 5 - (R) 1 indicates A/D busy, cleared at end
-   of conversion
-   (W) ignored
-   bit 4 - (R) 0
-   (W)
-   bit 3 - (R) 0
-   bit 2 - (R/W) 1 indicates interrupts enabled
-   bits 1,0 - (R/W) mode bits
-   00  single conversion on ADGCR load
-   01  continuous conversion, internal clock,
-   (clock enabled on ADGCR load)
-   10  continuous conversion, internal clock,
-   external trigger
-   11  continuous conversion, external clock,
-   external trigger
-
0x01ADGCR R/W A/D Gain/Channel Register
bit 6,7 - (R/W) gain select
00  gain=1, both PGH, PGL models
@@ -169,7 +166,6 @@ static const struct comedi_lrange 
range_dt2811_pgl_ai_5_bipolar = {
 
 #define TIMEOUT 1
 
-#define DT2811_ADCSR 0
 #define DT2811_ADGCR 1
 #define DT2811_ADDATLO 2
 #define DT2811_ADDATHI 3
@@ -180,19 +176,6 @@ static const struct comedi_lrange 
range_dt2811_pgl_ai_5_bipolar = {
 #define DT2811_DIO 6
 #define DT2811_TMRCTR 7
 
-/*
- * flags
- */
-
-/* ADCSR */
-
-#define DT2811_ADDONE   0x80
-#define DT2811_ADERROR  0x40
-#define DT2811_ADBUSY   0x20
-#define DT2811_CLRERROR 0x10
-#define DT2811_INTENB   0x04
-#define DT2811_ADMODE   0x03
-
 struct dt2811_board {
const char *name;
const struct comedi_lrange *bip_5;
@@ -227,8 +210,8 @@ static int dt2811_ai_eoc(struct comedi_device *dev,
 {
unsigned int status;
 
-   status = inb(dev->iobase + DT2811_ADCSR);
-   if ((status & DT2811_ADBUSY) == 0)
+   status = inb(dev->iobase + DT2811_ADCSR_REG);
+   if ((status & DT2811_ADCSR_ADBUSY) == 0)
return 0;
return -EBUSY;
 }
-- 
2.6.3

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


[PATCH 11/19] staging: comedi: dt2811: simplify analog output range options

2016-05-03 Thread H Hartley Sweeten
The D/A ranges are not programmable. Currently this driver uses some
configuration options to select the comedi_lrange for each channel.
This is a bit messy and it requires the user to make sure the correct
option value is used.

The range information isn't used by the driver. The user space library
uses it to convert between raw data values and physical units. If the
user passed an incorrect option when attaching the driver the conversion
will be incorrect.

Simplify the analog output ranges by providing a range_table that
contains all the possible output ranges. The user can then select the
correct range when converting values.

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

diff --git a/drivers/staging/comedi/drivers/dt2811.c 
b/drivers/staging/comedi/drivers/dt2811.c
index 0512d70..6850eb8 100644
--- a/drivers/staging/comedi/drivers/dt2811.c
+++ b/drivers/staging/comedi/drivers/dt2811.c
@@ -37,8 +37,14 @@
  *0 = [-5, 5]
  *1 = [-2.5, 2.5]
  *2 = [0, 5]
- *   [4] - D/A 0 range (same as A/D range)
- *   [5] - D/A 1 range (same as A/D range)
+ *   [4] - D/A 0 range (deprecated, see below)
+ *   [5] - D/A 1 range (deprecated, see below)
+ *
+ * Notes:
+ *   - D/A ranges are not programmable. The AO subdevice has a range_table
+ * containing all the possible analog output ranges. Use the range
+ * that matches your board configuration to convert between data
+ * values and physical units.
  */
 
 #include 
@@ -147,6 +153,23 @@ static const struct comedi_lrange 
range_dt2811_pgl_ai_5_bipolar = {
}
 };
 
+/*
+ * The Analog Output range is set per-channel using jumpers on the board.
+ *
+ * DAC0 JumpersDAC1 Jumpers
+ * Output RangeW5  W6  W7  W8  W1  W2  W3  W4
+ * -5V to +5V  In  Out In  Out In  Out In  Out
+ * -2.5V to +2.5V  In  Out Out In  In  Out Out In
+ * 0 to +5VOut In  Out In  Out In  Out In
+ */
+static const struct comedi_lrange dt2811_ao_ranges = {
+   3, {
+   BIP_RANGE(5),   /* default setting from factory */
+   BIP_RANGE(2.5),
+   UNI_RANGE(5)
+   }
+};
+
 #define TIMEOUT 1
 
 struct dt2811_board {
@@ -164,16 +187,6 @@ struct dt2811_private {
enum {
adc_singleended, adc_diff, adc_pseudo_diff
} adc_mux;
-   enum {
-   dac_bipolar_5, dac_bipolar_2_5, dac_unipolar_5
-   } dac_range[2];
-   const struct comedi_lrange *range_type_list[2];
-};
-
-static const struct comedi_lrange *dac_range_types[] = {
-   &range_bipolar5,
-   &range_bipolar2_5,
-   &range_unipolar5
 };
 
 static int dt2811_ai_eoc(struct comedi_device *dev,
@@ -294,34 +307,6 @@ static int dt2811_attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
devpriv->adc_mux = adc_singleended;
break;
}
-   switch (it->options[4]) {
-   case 0:
-   devpriv->dac_range[0] = dac_bipolar_5;
-   break;
-   case 1:
-   devpriv->dac_range[0] = dac_bipolar_2_5;
-   break;
-   case 2:
-   devpriv->dac_range[0] = dac_unipolar_5;
-   break;
-   default:
-   devpriv->dac_range[0] = dac_bipolar_5;
-   break;
-   }
-   switch (it->options[5]) {
-   case 0:
-   devpriv->dac_range[1] = dac_bipolar_5;
-   break;
-   case 1:
-   devpriv->dac_range[1] = dac_bipolar_2_5;
-   break;
-   case 2:
-   devpriv->dac_range[1] = dac_unipolar_5;
-   break;
-   default:
-   devpriv->dac_range[1] = dac_bipolar_5;
-   break;
-   }
 
s = &dev->subdevices[0];
/* initialize the ADC subdevice */
@@ -349,9 +334,7 @@ static int dt2811_attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
s->subdev_flags = SDF_WRITABLE;
s->n_chan = 2;
s->maxdata = 0xfff;
-   s->range_table_list = devpriv->range_type_list;
-   devpriv->range_type_list[0] = dac_range_types[devpriv->dac_range[0]];
-   devpriv->range_type_list[1] = dac_range_types[devpriv->dac_range[1]];
+   s->range_table = &dt2811_ao_ranges;
s->insn_write = dt2811_ao_insn_write;
 
ret = comedi_alloc_subdev_readback(s);
-- 
2.6.3

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


[PATCH 14/19] staging: comedi: dt2811: remove private data

2016-05-03 Thread H Hartley Sweeten
The remaining members of the private data are not used by the driver.
Remove it and the allocation.

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

diff --git a/drivers/staging/comedi/drivers/dt2811.c 
b/drivers/staging/comedi/drivers/dt2811.c
index 1fe657c..379b7d5 100644
--- a/drivers/staging/comedi/drivers/dt2811.c
+++ b/drivers/staging/comedi/drivers/dt2811.c
@@ -181,11 +181,6 @@ struct dt2811_board {
 
 enum { card_2811_pgh, card_2811_pgl };
 
-struct dt2811_private {
-   int ntrig;
-   int curadchan;
-};
-
 static int dt2811_ai_eoc(struct comedi_device *dev,
 struct comedi_subdevice *s,
 struct comedi_insn *insn,
@@ -274,7 +269,6 @@ static int dt2811_do_insn_bits(struct comedi_device *dev,
 static int dt2811_attach(struct comedi_device *dev, struct comedi_devconfig 
*it)
 {
const struct dt2811_board *board = dev->board_ptr;
-   struct dt2811_private *devpriv;
struct comedi_subdevice *s;
int ret;
 
@@ -286,10 +280,6 @@ static int dt2811_attach(struct comedi_device *dev, struct 
comedi_devconfig *it)
if (ret)
return ret;
 
-   devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
-   if (!devpriv)
-   return -ENOMEM;
-
s = &dev->subdevices[0];
/* initialize the ADC subdevice */
s->type = COMEDI_SUBD_AI;
-- 
2.6.3

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


[PATCH 12/19] staging: comedi: dt2811: tidy up analog output subdevice init

2016-05-03 Thread H Hartley Sweeten
Add some whitespace to the analog output subdevice initialization.

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

diff --git a/drivers/staging/comedi/drivers/dt2811.c 
b/drivers/staging/comedi/drivers/dt2811.c
index 6850eb8..b60ee74 100644
--- a/drivers/staging/comedi/drivers/dt2811.c
+++ b/drivers/staging/comedi/drivers/dt2811.c
@@ -328,14 +328,14 @@ static int dt2811_attach(struct comedi_device *dev, 
struct comedi_devconfig *it)
break;
}
 
+   /* Analog Output subdevice */
s = &dev->subdevices[1];
-   /* ao subdevice */
-   s->type = COMEDI_SUBD_AO;
-   s->subdev_flags = SDF_WRITABLE;
-   s->n_chan = 2;
-   s->maxdata = 0xfff;
-   s->range_table = &dt2811_ao_ranges;
-   s->insn_write = dt2811_ao_insn_write;
+   s->type = COMEDI_SUBD_AO;
+   s->subdev_flags = SDF_WRITABLE;
+   s->n_chan   = 2;
+   s->maxdata  = 0x0fff;
+   s->range_table  = &dt2811_ao_ranges;
+   s->insn_write   = dt2811_ao_insn_write;
 
ret = comedi_alloc_subdev_readback(s);
if (ret)
-- 
2.6.3

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


[PATCH 16/19] staging: comedi: dt2811: tidy up analog input subdevice init

2016-05-03 Thread H Hartley Sweeten
Add some whitespace to the analog output subdevice initialization
and rename the (*insn_read) function.

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

diff --git a/drivers/staging/comedi/drivers/dt2811.c 
b/drivers/staging/comedi/drivers/dt2811.c
index acc9db8..9a74964 100644
--- a/drivers/staging/comedi/drivers/dt2811.c
+++ b/drivers/staging/comedi/drivers/dt2811.c
@@ -197,8 +197,10 @@ static int dt2811_ai_eoc(struct comedi_device *dev,
return -EBUSY;
 }
 
-static int dt2811_ai_insn(struct comedi_device *dev, struct comedi_subdevice 
*s,
- struct comedi_insn *insn, unsigned int *data)
+static int dt2811_ai_insn_read(struct comedi_device *dev,
+  struct comedi_subdevice *s,
+  struct comedi_insn *insn,
+  unsigned int *data)
 {
unsigned int chan = CR_CHAN(insn->chanspec);
unsigned int range = CR_RANGE(insn->chanspec);
@@ -283,17 +285,17 @@ static int dt2811_attach(struct comedi_device *dev, 
struct comedi_devconfig *it)
if (ret)
return ret;
 
+   /* Analog Input subdevice */
s = &dev->subdevices[0];
-   /* initialize the ADC subdevice */
-   s->type = COMEDI_SUBD_AI;
-   s->subdev_flags = SDF_READABLE |
+   s->type = COMEDI_SUBD_AI;
+   s->subdev_flags = SDF_READABLE |
  (it->options[2] == 1) ? SDF_DIFF :
  (it->options[2] == 2) ? SDF_COMMON : SDF_GROUND;
-   s->n_chan = (it->options[2] == 1) ? 8 : 16;
-   s->insn_read = dt2811_ai_insn;
-   s->maxdata = 0xfff;
+   s->n_chan   = (it->options[2] == 1) ? 8 : 16;
+   s->maxdata  = 0x0fff;
s->range_table  = board->is_pgh ? &dt2811_pgh_ai_ranges
: &dt2811_pgl_ai_ranges;
+   s->insn_read= dt2811_ai_insn_read;
 
/* Analog Output subdevice */
s = &dev->subdevices[1];
-- 
2.6.3

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


[PATCH 10/19] staging: comedi: dt2811: tidy up the digital subdevices

2016-05-03 Thread H Hartley Sweeten
Add some whitespace to the digital input and output subdevice
initialization. Reorder the initialization a bit.

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

diff --git a/drivers/staging/comedi/drivers/dt2811.c 
b/drivers/staging/comedi/drivers/dt2811.c
index 6ea1ad4..0512d70 100644
--- a/drivers/staging/comedi/drivers/dt2811.c
+++ b/drivers/staging/comedi/drivers/dt2811.c
@@ -240,7 +240,8 @@ static int dt2811_ao_insn_write(struct comedi_device *dev,
 
 static int dt2811_di_insn_bits(struct comedi_device *dev,
   struct comedi_subdevice *s,
-  struct comedi_insn *insn, unsigned int *data)
+  struct comedi_insn *insn,
+  unsigned int *data)
 {
data[1] = inb(dev->iobase + DT2811_DI_REG);
 
@@ -357,24 +358,23 @@ static int dt2811_attach(struct comedi_device *dev, 
struct comedi_devconfig *it)
if (ret)
return ret;
 
+   /* Digital Input subdevice */
s = &dev->subdevices[2];
-   /* di subdevice */
-   s->type = COMEDI_SUBD_DI;
-   s->subdev_flags = SDF_READABLE;
-   s->n_chan = 8;
-   s->insn_bits = dt2811_di_insn_bits;
-   s->maxdata = 1;
-   s->range_table = &range_digital;
-
+   s->type = COMEDI_SUBD_DI;
+   s->subdev_flags = SDF_READABLE;
+   s->n_chan   = 8;
+   s->maxdata  = 1;
+   s->range_table  = &range_digital;
+   s->insn_bits= dt2811_di_insn_bits;
+
+   /* Digital Output subdevice */
s = &dev->subdevices[3];
-   /* do subdevice */
-   s->type = COMEDI_SUBD_DO;
-   s->subdev_flags = SDF_WRITABLE;
-   s->n_chan = 8;
-   s->insn_bits = dt2811_do_insn_bits;
-   s->maxdata = 1;
-   s->state = 0;
-   s->range_table = &range_digital;
+   s->type = COMEDI_SUBD_DO;
+   s->subdev_flags = SDF_WRITABLE;
+   s->n_chan   = 8;
+   s->maxdata  = 1;
+   s->range_table  = &range_digital;
+   s->insn_bits= dt2811_do_insn_bits;
 
return 0;
 }
-- 
2.6.3

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


[PATCH 18/19] staging: comedi: dt2811: rename 'boardtypes'

2016-05-03 Thread H Hartley Sweeten
Rename this array so it has namespace associated with the driver.

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

diff --git a/drivers/staging/comedi/drivers/dt2811.c 
b/drivers/staging/comedi/drivers/dt2811.c
index 6beebc2..ca768dc 100644
--- a/drivers/staging/comedi/drivers/dt2811.c
+++ b/drivers/staging/comedi/drivers/dt2811.c
@@ -173,7 +173,7 @@ struct dt2811_board {
unsigned int is_pgh:1;
 };
 
-static const struct dt2811_board boardtypes[] = {
+static const struct dt2811_board dt2811_boards[] = {
{
.name   = "dt2811-pgh",
.is_pgh = 1,
@@ -334,8 +334,8 @@ static struct comedi_driver dt2811_driver = {
.module = THIS_MODULE,
.attach = dt2811_attach,
.detach = comedi_legacy_detach,
-   .board_name = &boardtypes[0].name,
-   .num_names  = ARRAY_SIZE(boardtypes),
+   .board_name = &dt2811_boards[0].name,
+   .num_names  = ARRAY_SIZE(dt2811_boards),
.offset = sizeof(struct dt2811_board),
 };
 module_comedi_driver(dt2811_driver);
-- 
2.6.3

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


[PATCH 01/19] staging: comedi: dt2811: tidy up copyright and comedi comments

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

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

diff --git a/drivers/staging/comedi/drivers/dt2811.c 
b/drivers/staging/comedi/drivers/dt2811.c
index a807732..499637b 100644
--- a/drivers/staging/comedi/drivers/dt2811.c
+++ b/drivers/staging/comedi/drivers/dt2811.c
@@ -1,45 +1,45 @@
 /*
-   comedi/drivers/dt2811.c
-   Hardware driver for Data Translation DT2811
-
-   COMEDI - Linux Control and Measurement Device Interface
-   History:
-   Base Version  - David A. Schleef 
-   December 1998 - Updated to work.  David does not have a DT2811
-   board any longer so this was suffering from bitrot.
-   Updated performed by ...
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
+ * Comedi driver for Data Translation DT2811
+ *
+ * COMEDI - Linux Control and Measurement Device Interface
+ * History:
+ * Base Version  - David A. Schleef 
+ * December 1998 - Updated to work.  David does not have a DT2811
+ * board any longer so this was suffering from bitrot.
+ * Updated performed by ...
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  */
+
 /*
-Driver: dt2811
-Description: Data Translation DT2811
-Author: ds
-Devices: [Data Translation] DT2811-PGL (dt2811-pgl), DT2811-PGH (dt2811-pgh)
-Status: works
-
-Configuration options:
-  [0] - I/O port base address
-  [1] - IRQ, although this is currently unused
-  [2] - A/D reference
- 0 = signle-ended
- 1 = differential
- 2 = pseudo-differential (common reference)
-  [3] - A/D range
- 0 = [-5, 5]
- 1 = [-2.5, 2.5]
- 2 = [0, 5]
-  [4] - D/A 0 range (same choices)
-  [4] - D/A 1 range (same choices)
-*/
+ * Driver: dt2811
+ * Description: Data Translation DT2811
+ * Author: ds
+ * Devices: [Data Translation] DT2811-PGL (dt2811-pgl), DT2811-PGH (dt2811-pgh)
+ * Status: works
+ *
+ * Configuration options:
+ *   [0] - I/O port base address
+ *   [1] - IRQ, although this is currently unused
+ *   [2] - A/D reference
+ *0 = single-ended
+ *1 = differential
+ *2 = pseudo-differential (common reference)
+ *   [3] - A/D range
+ *0 = [-5, 5]
+ *1 = [-2.5, 2.5]
+ *2 = [0, 5]
+ *   [4] - D/A 0 range (same as A/D range)
+ *   [5] - D/A 1 range (same as A/D range)
+ */
 
 #include 
 #include "../comedidev.h"
-- 
2.6.3

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


[PATCH 05/19] staging: comedi: dt2811: tidy up A/D Gain/Channel register defines

2016-05-03 Thread H Hartley Sweeten
Cleanup the defines for this register and its bits and remove the
redundant information in the comment.

Make the (*insn_read) use the range to set the gain bits correctly.
Currently the gain is always set to 1.

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

diff --git a/drivers/staging/comedi/drivers/dt2811.c 
b/drivers/staging/comedi/drivers/dt2811.c
index 433cfd1..f72d6c8 100644
--- a/drivers/staging/comedi/drivers/dt2811.c
+++ b/drivers/staging/comedi/drivers/dt2811.c
@@ -63,6 +63,10 @@
 /* continuous conversion, external clock, external trigger */
 #define DT2811_ADCSR_ADMODE_EXTDT2811_ADCSR_ADMODE(3)
 
+#define DT2811_ADGCR_REG   0x01/* r/w  A/D Gain/Channel */
+#define DT2811_ADGCR_GAIN(x)   (((x) & 0x3) << 6)
+#define DT2811_ADGCR_CHAN(x)   (((x) & 0xf) << 0)
+
 static const struct comedi_lrange range_dt2811_pgh_ai_5_unipolar = {
4, {
UNI_RANGE(5),
@@ -119,16 +123,6 @@ static const struct comedi_lrange 
range_dt2811_pgl_ai_5_bipolar = {
 
 /*
 
-   0x01ADGCR R/W A/D Gain/Channel Register
-   bit 6,7 - (R/W) gain select
-   00  gain=1, both PGH, PGL models
-   01  gain=2 PGH, 10 PGL
-   10  gain=4 PGH, 100 PGL
-   11  gain=8 PGH, 500 PGL
-   bit 4,5 - reserved
-   bit 3-0 - (R/W) channel select
-   channel number from 0-15
-
0x02,0x03 (R) ADDAT A/D Data Register
(W) DADAT0 D/A Data Register 0
0x02 low byte
@@ -166,7 +160,6 @@ static const struct comedi_lrange 
range_dt2811_pgl_ai_5_bipolar = {
 
 #define TIMEOUT 1
 
-#define DT2811_ADGCR 1
 #define DT2811_ADDATLO 2
 #define DT2811_ADDATHI 3
 #define DT2811_DADAT0LO 2
@@ -219,12 +212,15 @@ static int dt2811_ai_eoc(struct comedi_device *dev,
 static int dt2811_ai_insn(struct comedi_device *dev, struct comedi_subdevice 
*s,
  struct comedi_insn *insn, unsigned int *data)
 {
-   int chan = CR_CHAN(insn->chanspec);
+   unsigned int chan = CR_CHAN(insn->chanspec);
+   unsigned int range = CR_RANGE(insn->chanspec);
int ret;
int i;
 
for (i = 0; i < insn->n; i++) {
-   outb(chan, dev->iobase + DT2811_ADGCR);
+   /* select channel/gain and trigger conversion */
+   outb(DT2811_ADGCR_CHAN(chan) | DT2811_ADGCR_GAIN(range),
+dev->iobase + DT2811_ADGCR_REG);
 
ret = comedi_timeout(dev, s, insn, dt2811_ai_eoc, 0);
if (ret)
-- 
2.6.3

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


[PATCH 19/19] staging: comedi: dt2811: update the MODULE_DESCRIPTION

2016-05-03 Thread H Hartley Sweeten
Change the MODULE_DESCRIPTION to something more useful than the generic
"Comedi low-level driver".

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

diff --git a/drivers/staging/comedi/drivers/dt2811.c 
b/drivers/staging/comedi/drivers/dt2811.c
index ca768dc..8f35493 100644
--- a/drivers/staging/comedi/drivers/dt2811.c
+++ b/drivers/staging/comedi/drivers/dt2811.c
@@ -341,5 +341,5 @@ static struct comedi_driver dt2811_driver = {
 module_comedi_driver(dt2811_driver);
 
 MODULE_AUTHOR("Comedi http://www.comedi.org";);
-MODULE_DESCRIPTION("Comedi low-level driver");
+MODULE_DESCRIPTION("Comedi driver for Data Translation DT2811 series boards");
 MODULE_LICENSE("GPL");
-- 
2.6.3

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


[PATCH 13/19] staging: comedi: dt2811: simplify A/D reference configuration

2016-05-03 Thread H Hartley Sweeten
The analog inputs are confgured with jumpers on the board to be:
  * 16 single-ended inputs
  * 8 differential inputs
  * 16 pseudo-differential inputs (common ground)

Simplify the handling of this configuration option and properly set
the subdev_flags based on the selected input mode.

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

diff --git a/drivers/staging/comedi/drivers/dt2811.c 
b/drivers/staging/comedi/drivers/dt2811.c
index b60ee74..1fe657c 100644
--- a/drivers/staging/comedi/drivers/dt2811.c
+++ b/drivers/staging/comedi/drivers/dt2811.c
@@ -29,10 +29,10 @@
  * Configuration options:
  *   [0] - I/O port base address
  *   [1] - IRQ, although this is currently unused
- *   [2] - A/D reference
- *0 = single-ended
- *1 = differential
- *2 = pseudo-differential (common reference)
+ *   [2] - A/D reference (# of analog inputs)
+ *0 = single-ended (16 channels)
+ *1 = differential (8 channels)
+ *2 = pseudo-differential (16 channels)
  *   [3] - A/D range
  *0 = [-5, 5]
  *1 = [-2.5, 2.5]
@@ -184,9 +184,6 @@ enum { card_2811_pgh, card_2811_pgl };
 struct dt2811_private {
int ntrig;
int curadchan;
-   enum {
-   adc_singleended, adc_diff, adc_pseudo_diff
-   } adc_mux;
 };
 
 static int dt2811_ai_eoc(struct comedi_device *dev,
@@ -293,26 +290,13 @@ static int dt2811_attach(struct comedi_device *dev, 
struct comedi_devconfig *it)
if (!devpriv)
return -ENOMEM;
 
-   switch (it->options[2]) {
-   case 0:
-   devpriv->adc_mux = adc_singleended;
-   break;
-   case 1:
-   devpriv->adc_mux = adc_diff;
-   break;
-   case 2:
-   devpriv->adc_mux = adc_pseudo_diff;
-   break;
-   default:
-   devpriv->adc_mux = adc_singleended;
-   break;
-   }
-
s = &dev->subdevices[0];
/* initialize the ADC subdevice */
s->type = COMEDI_SUBD_AI;
-   s->subdev_flags = SDF_READABLE | SDF_GROUND;
-   s->n_chan = devpriv->adc_mux == adc_diff ? 8 : 16;
+   s->subdev_flags = SDF_READABLE |
+ (it->options[2] == 1) ? SDF_DIFF :
+ (it->options[2] == 2) ? SDF_COMMON : SDF_GROUND;
+   s->n_chan = (it->options[2] == 1) ? 8 : 16;
s->insn_read = dt2811_ai_insn;
s->maxdata = 0xfff;
switch (it->options[3]) {
-- 
2.6.3

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


[PATCH 17/19] staging: comedi: dt2811: remove unused define

2016-05-03 Thread H Hartley Sweeten
This define is not used by the driver. Remove it.

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

diff --git a/drivers/staging/comedi/drivers/dt2811.c 
b/drivers/staging/comedi/drivers/dt2811.c
index 9a74964..6beebc2 100644
--- a/drivers/staging/comedi/drivers/dt2811.c
+++ b/drivers/staging/comedi/drivers/dt2811.c
@@ -168,8 +168,6 @@ static const struct comedi_lrange dt2811_ao_ranges = {
}
 };
 
-#define TIMEOUT 1
-
 struct dt2811_board {
const char *name;
unsigned int is_pgh:1;
-- 
2.6.3

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


[PATCH 00/19] staging: comedi: dt2811: cleanup driver

2016-05-03 Thread H Hartley Sweeten
Fix all the checkpatch.pl issues and tidy up the driver.

H Hartley Sweeten (19):
  staging: comedi: dt2811: tidy up copyright and comedi comments
  staging: comedi: dt2811: remove redundant block comment
  staging: comedi: dt2811: remove disabled code
  staging: comedi: dt2811: tidy up A/D Control/Status register defines
  staging: comedi: dt2811: tidy up A/D Gain/Channel register defines
  staging: comedi: dt2811: tidy up A/D Data register defines
  staging: comedi: dt2811: tidy up D/A Data register defines
  staging: comedi: dt2811: tidy up Digital Input/Output register defines
  staging: comedi: dt2811: tidy up Timer/Counter register defines
  staging: comedi: dt2811: tidy up the digital subdevices
  staging: comedi: dt2811: simplify analog output range options
  staging: comedi: dt2811: tidy up analog output subdevice init
  staging: comedi: dt2811: simplify A/D reference configuration
  staging: comedi: dt2811: remove private data
  staging: comedi: dt2811: simplify analog input range options
  staging: comedi: dt2811: tidy up analog input subdevice init
  staging: comedi: dt2811: remove unused define
  staging: comedi: dt2811: rename 'boardtypes'
  staging: comedi: dt2811: update the MODULE_DESCRIPTION

 drivers/staging/comedi/drivers/dt2811.c | 569 
 1 file changed, 220 insertions(+), 349 deletions(-)

-- 
2.6.3

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


[PATCH] fix infoleak in wilc_wfi_cfgoperations

2016-05-03 Thread Kangjie Lu
"mac" is an array allocated in stack without being initialized,
and will be sent out via "nla_put". The dump_station() is supposed
to initialize the mac address; otherwise, sensitive data in kernel
stack will be leaked. To fix this, copy the mac address to it.

Signed-off-by: Kangjie Lu 
---
 drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c 
b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
index 448a5c8..c6e71d9 100644
--- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
+++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
@@ -1797,6 +1797,7 @@ static int dump_station(struct wiphy *wiphy, struct 
net_device *dev,
 
wilc_get_rssi(vif, &sinfo->signal);
 
+   memcpy(mac, priv->au8AssociatedBss, ETH_ALEN);
return 0;
 }
 
-- 
1.9.1

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


[PATCH V6 4/9] staging: rtl8192u: propagate errors in rtl8192_read_eeprom_info

2016-05-03 Thread Salah Triki
Propagate error from eprom_read and change the return type of
rtl8192_read_eeprom_info from void to int.

Signed-off-by: Salah Triki 
---
 drivers/staging/rtl8192u/r8192U_core.c | 34 ++
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/drivers/staging/rtl8192u/r8192U_core.c 
b/drivers/staging/rtl8192u/r8192U_core.c
index 32ee6ef..12e54d8 100644
--- a/drivers/staging/rtl8192u/r8192U_core.c
+++ b/drivers/staging/rtl8192u/r8192U_core.c
@@ -2421,7 +2421,7 @@ static inline u16 endian_swap(u16 *data)
return *data;
 }
 
-static void rtl8192_read_eeprom_info(struct net_device *dev)
+static int rtl8192_read_eeprom_info(struct net_device *dev)
 {
u16 wEPROM_ID = 0;
u8 bMac_Tmp_Addr[6] = {0x00, 0xe0, 0x4c, 0x00, 0x00, 0x02};
@@ -2434,7 +2434,7 @@ static void rtl8192_read_eeprom_info(struct net_device 
*dev)
RT_TRACE(COMP_EPROM, "===>%s()\n", __func__);
ret = eprom_read(dev, 0); /* first read EEPROM ID out; */
if (ret < 0)
-   return;
+   return ret;
wEPROM_ID = (u16)ret;
RT_TRACE(COMP_EPROM, "EEPROM ID is 0x%x\n", wEPROM_ID);
 
@@ -2449,22 +2449,22 @@ static void rtl8192_read_eeprom_info(struct net_device 
*dev)
tmpValue = eprom_read(dev, EEPROM_VID >> 1);
ret = eprom_read(dev, EEPROM_VID >> 1);
if (ret < 0)
-   return;
+   return ret;
tmpValue = (u16)ret;
priv->eeprom_vid = endian_swap(&tmpValue);
ret = eprom_read(dev, EEPROM_PID >> 1);
if (ret < 0)
-   return;
+   return ret;
priv->eeprom_pid = (u16)ret;
ret = eprom_read(dev, EEPROM_ChannelPlan >> 1);
if (ret < 0)
-   return;
+   return ret;
tmpValue = (u16)ret;
priv->eeprom_ChannelPlan = (tmpValue & 0xff00) >> 8;
priv->btxpowerdata_readfromEEPORM = true;
ret = eprom_read(dev, (EEPROM_Customer_ID >> 1)) >> 8;
if (ret < 0)
-   return;
+   return ret;
priv->eeprom_CustomerID = (u16)ret;
} else {
priv->eeprom_vid = 0;
@@ -2485,7 +2485,7 @@ static void rtl8192_read_eeprom_info(struct net_device 
*dev)
for (i = 0; i < 6; i += 2) {
ret = eprom_read(dev, (u16)((EEPROM_NODE_ADDRESS_BYTE_0 
+ i) >> 1));
if (ret < 0)
-   return;
+   return ret;
*(u16 *)(&dev->dev_addr[i]) = (u16)ret;
}
} else {
@@ -2501,7 +2501,7 @@ static void rtl8192_read_eeprom_info(struct net_device 
*dev)
if (bLoad_From_EEPOM) {
ret = eprom_read(dev, (EEPROM_TxPowerDiff >> 1));
if (ret < 0)
-   return;
+   return ret;
priv->EEPROMTxPowerDiff = ((u16)ret & 0xff00) >> 8;
} else
priv->EEPROMTxPowerDiff = EEPROM_Default_TxPower;
@@ -2510,7 +2510,7 @@ static void rtl8192_read_eeprom_info(struct net_device 
*dev)
if (bLoad_From_EEPOM) {
ret = eprom_read(dev, (EEPROM_ThermalMeter >> 1));
if (ret < 0)
-   return;
+   return ret;
priv->EEPROMThermalMeter = (u8)((u16)ret & 0x00ff);
} else
priv->EEPROMThermalMeter = EEPROM_Default_ThermalMeter;
@@ -2521,7 +2521,7 @@ static void rtl8192_read_eeprom_info(struct net_device 
*dev)
if (bLoad_From_EEPOM) {
ret = eprom_read(dev, (EEPROM_PwDiff >> 1));
if (ret < 0)
-   return;
+   return ret;
priv->EEPROMPwDiff = ((u16)ret & 0x0f00) >> 8;
} else
priv->EEPROMPwDiff = EEPROM_Default_PwDiff;
@@ -2530,7 +2530,7 @@ static void rtl8192_read_eeprom_info(struct net_device 
*dev)
if (bLoad_From_EEPOM) {
ret = eprom_read(dev, (EEPROM_CrystalCap >> 1));
if (ret < 0)
-   return;
+   return ret;
priv->EEPROMCrystalCap = (u16)ret & 0x0f;
} else
priv->EEPROMCrystalCap = EEPROM_Default_CrystalCap;
@@ -2539,7 +2539,7 @@ static void rtl8192_read_eeprom_info(struct net_device 
*dev)
if (bLoad_From_EEPOM) {
ret = eprom_read(dev, (EEPROM_TxPwIndex_Ver >> 1));
if (ret < 0)

[PATCH V6 1/9] staging: rtl8192u: check return value of read_nic_word_E

2016-05-03 Thread Salah Triki
The call of read_nic_word_E may fail, therefore its return value must be
checked and propagated in the case of error.

Signed-off-by: Salah Triki 
---
 drivers/staging/rtl8192u/r8180_93cx6.c | 21 +
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8192u/r8180_93cx6.c 
b/drivers/staging/rtl8192u/r8180_93cx6.c
index 97d9b3f..2c53132 100644
--- a/drivers/staging/rtl8192u/r8180_93cx6.c
+++ b/drivers/staging/rtl8192u/r8180_93cx6.c
@@ -23,8 +23,11 @@
 static void eprom_cs(struct net_device *dev, short bit)
 {
u8 cmdreg;
+   int err;
 
-   read_nic_byte_E(dev, EPROM_CMD, &cmdreg);
+   err = read_nic_byte_E(dev, EPROM_CMD, &cmdreg);
+   if (err)
+   return;
if (bit)
/* enable EPROM */
write_nic_byte_E(dev, EPROM_CMD, cmdreg | EPROM_CS_BIT);
@@ -40,8 +43,11 @@ static void eprom_cs(struct net_device *dev, short bit)
 static void eprom_ck_cycle(struct net_device *dev)
 {
u8 cmdreg;
+   int err;
 
-   read_nic_byte_E(dev, EPROM_CMD, &cmdreg);
+   err = read_nic_byte_E(dev, EPROM_CMD, &cmdreg);
+   if (err)
+   return;
write_nic_byte_E(dev, EPROM_CMD, cmdreg | EPROM_CK_BIT);
force_pci_posting(dev);
udelay(EPROM_DELAY);
@@ -56,8 +62,11 @@ static void eprom_ck_cycle(struct net_device *dev)
 static void eprom_w(struct net_device *dev, short bit)
 {
u8 cmdreg;
+   int err;
 
-   read_nic_byte_E(dev, EPROM_CMD, &cmdreg);
+   err = read_nic_byte_E(dev, EPROM_CMD, &cmdreg);
+   if (err)
+   return;
if (bit)
write_nic_byte_E(dev, EPROM_CMD, cmdreg | EPROM_W_BIT);
else
@@ -71,8 +80,12 @@ static void eprom_w(struct net_device *dev, short bit)
 static short eprom_r(struct net_device *dev)
 {
u8 bit;
+   int err;
+
+   err = read_nic_byte_E(dev, EPROM_CMD, &bit);
+   if (err)
+   return err;
 
-   read_nic_byte_E(dev, EPROM_CMD, &bit);
udelay(EPROM_DELAY);
 
if (bit & EPROM_R_BIT)
-- 
1.9.1

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


[PATCH V6 0/9] staging: rtl8192u: Checking return value/propagating errors

2016-05-03 Thread Salah Triki
These patchs check the return value/propagate error of the functions
read_nic_word_E, eprom_r, eprom_read, rtl8192_read_eeprom_info, write_nic_*

Salah Triki (9):
  staging: rtl8192u: check return value of read_nic_word_E
  staging: rtl8192u: propagate errors in eprom_read
  staging: rtl8192u: check return value eprom_read
  staging: rtl8192u: propagate errors in rtl8192_read_eeprom_info
  staging: rtl8192u: check return value of rtl8192_read_eeprom_info
  rtl8192u: propagate errors in write_nic_byte
  staging: rtl8192u: propagate errors in write_nic_byte_E
  staging: rtl8192u: propagate errors in write_nic_word
  staging: rtl8192u: propagate errors in write_nic_dword

 drivers/staging/rtl8192u/r8180_93cx6.c |  30 --
 drivers/staging/rtl8192u/r8180_93cx6.h |   2 +-
 drivers/staging/rtl8192u/r8192U.h  |   8 +-
 drivers/staging/rtl8192u/r8192U_core.c | 165 +++--
 4 files changed, 144 insertions(+), 61 deletions(-)

-- 
1.9.1

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


[PATCH V6 8/9] staging: rtl8192u: propagate errors in write_nic_word

2016-05-03 Thread Salah Triki
Propagate errors from kzalloc and usb_control_msg and change the
return type of write_nic_word from void to int.

Signed-off-by: Salah Triki 
---
 drivers/staging/rtl8192u/r8192U.h  |  2 +-
 drivers/staging/rtl8192u/r8192U_core.c | 10 +++---
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8192u/r8192U.h 
b/drivers/staging/rtl8192u/r8192U.h
index e0abcf5..27f9aa5 100644
--- a/drivers/staging/rtl8192u/r8192U.h
+++ b/drivers/staging/rtl8192u/r8192U.h
@@ -1131,7 +1131,7 @@ int read_nic_dword(struct net_device *dev, int x, u32 
*data);
 int read_nic_word(struct net_device *dev, int x, u16 *data);
 int write_nic_byte(struct net_device *dev, int x, u8 y);
 int write_nic_byte_E(struct net_device *dev, int x, u8 y);
-void write_nic_word(struct net_device *dev, int x, u16 y);
+int write_nic_word(struct net_device *dev, int x, u16 y);
 void write_nic_dword(struct net_device *dev, int x, u32 y);
 void force_pci_posting(struct net_device *dev);
 
diff --git a/drivers/staging/rtl8192u/r8192U_core.c 
b/drivers/staging/rtl8192u/r8192U_core.c
index 6d1ffb0..2faffb2 100644
--- a/drivers/staging/rtl8192u/r8192U_core.c
+++ b/drivers/staging/rtl8192u/r8192U_core.c
@@ -329,7 +329,7 @@ int write_nic_byte(struct net_device *dev, int indx, u8 
data)
 }
 
 
-void write_nic_word(struct net_device *dev, int indx, u16 data)
+int write_nic_word(struct net_device *dev, int indx, u16 data)
 {
int status;
 
@@ -338,7 +338,7 @@ void write_nic_word(struct net_device *dev, int indx, u16 
data)
u16 *usbdata = kzalloc(sizeof(data), GFP_KERNEL);
 
if (!usbdata)
-   return;
+   return -ENOMEM;
*usbdata = data;
 
status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
@@ -347,8 +347,12 @@ void write_nic_word(struct net_device *dev, int indx, u16 
data)
 usbdata, 2, HZ / 2);
kfree(usbdata);
 
-   if (status < 0)
+   if (status < 0) {
netdev_err(dev, "write_nic_word TimeOut! status: %d\n", status);
+   return status;
+   }
+
+   return 0;
 }
 
 
-- 
1.9.1

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


[PATCH V6 5/9] staging: rtl8192u: check return value of rtl8192_read_eeprom_info

2016-05-03 Thread Salah Triki
The call of rtl8192_read_eeprom_info may fail, therefore its return
value must be checked and propagated in the case of error

Signed-off-by: Salah Triki 
---
 drivers/staging/rtl8192u/r8192U_core.c | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/rtl8192u/r8192U_core.c 
b/drivers/staging/rtl8192u/r8192U_core.c
index 12e54d8..7ce7460 100644
--- a/drivers/staging/rtl8192u/r8192U_core.c
+++ b/drivers/staging/rtl8192u/r8192U_core.c
@@ -2706,6 +2706,7 @@ static short rtl8192_get_channel_map(struct net_device 
*dev)
 static short rtl8192_init(struct net_device *dev)
 {
struct r8192_priv *priv = ieee80211_priv(dev);
+   int err;
 
memset(&(priv->stats), 0, sizeof(struct Stats));
memset(priv->txqueue_to_outpipemap, 0, 9);
@@ -2727,7 +2728,14 @@ static short rtl8192_init(struct net_device *dev)
rtl8192_init_priv_lock(priv);
rtl8192_init_priv_task(dev);
rtl8192_get_eeprom_size(dev);
-   rtl8192_read_eeprom_info(dev);
+   err = rtl8192_read_eeprom_info(dev);
+   if (err) {
+   DMESG("Reading EEPROM info failed");
+   kfree(priv->pFirmware);
+   priv->pFirmware = NULL;
+   free_ieee80211(dev);
+   return err;
+   }
rtl8192_get_channel_map(dev);
init_hal_dm(dev);
setup_timer(&priv->watch_dog_timer, watch_dog_timer_callback,
-- 
1.9.1

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


[PATCH V6 3/9] staging: rtl8192u: check return value eprom_read

2016-05-03 Thread Salah Triki
The call of eprom_read may fail, therefore its return value must be
checked

Signed-off-by: Salah Triki 
---
 drivers/staging/rtl8192u/r8192U_core.c | 112 ++---
 1 file changed, 76 insertions(+), 36 deletions(-)

diff --git a/drivers/staging/rtl8192u/r8192U_core.c 
b/drivers/staging/rtl8192u/r8192U_core.c
index 0a83e2d..32ee6ef 100644
--- a/drivers/staging/rtl8192u/r8192U_core.c
+++ b/drivers/staging/rtl8192u/r8192U_core.c
@@ -2429,9 +2429,13 @@ static void rtl8192_read_eeprom_info(struct net_device 
*dev)
struct r8192_priv *priv = ieee80211_priv(dev);
u16 tmpValue = 0;
int i;
+   int ret;
 
RT_TRACE(COMP_EPROM, "===>%s()\n", __func__);
-   wEPROM_ID = eprom_read(dev, 0); /* first read EEPROM ID out; */
+   ret = eprom_read(dev, 0); /* first read EEPROM ID out; */
+   if (ret < 0)
+   return;
+   wEPROM_ID = (u16)ret;
RT_TRACE(COMP_EPROM, "EEPROM ID is 0x%x\n", wEPROM_ID);
 
if (wEPROM_ID != RTL8190_EEPROM_ID)
@@ -2443,13 +2447,25 @@ static void rtl8192_read_eeprom_info(struct net_device 
*dev)
 
if (bLoad_From_EEPOM) {
tmpValue = eprom_read(dev, EEPROM_VID >> 1);
+   ret = eprom_read(dev, EEPROM_VID >> 1);
+   if (ret < 0)
+   return;
+   tmpValue = (u16)ret;
priv->eeprom_vid = endian_swap(&tmpValue);
-   priv->eeprom_pid = eprom_read(dev, EEPROM_PID >> 1);
-   tmpValue = eprom_read(dev, EEPROM_ChannelPlan >> 1);
+   ret = eprom_read(dev, EEPROM_PID >> 1);
+   if (ret < 0)
+   return;
+   priv->eeprom_pid = (u16)ret;
+   ret = eprom_read(dev, EEPROM_ChannelPlan >> 1);
+   if (ret < 0)
+   return;
+   tmpValue = (u16)ret;
priv->eeprom_ChannelPlan = (tmpValue & 0xff00) >> 8;
priv->btxpowerdata_readfromEEPORM = true;
-   priv->eeprom_CustomerID =
-   eprom_read(dev, (EEPROM_Customer_ID >> 1)) >> 8;
+   ret = eprom_read(dev, (EEPROM_Customer_ID >> 1)) >> 8;
+   if (ret < 0)
+   return;
+   priv->eeprom_CustomerID = (u16)ret;
} else {
priv->eeprom_vid = 0;
priv->eeprom_pid = 0;
@@ -2467,10 +2483,10 @@ static void rtl8192_read_eeprom_info(struct net_device 
*dev)
int i;
 
for (i = 0; i < 6; i += 2) {
-   u16 tmp = 0;
-
-   tmp = eprom_read(dev, (u16)((EEPROM_NODE_ADDRESS_BYTE_0 
+ i) >> 1));
-   *(u16 *)(&dev->dev_addr[i]) = tmp;
+   ret = eprom_read(dev, (u16)((EEPROM_NODE_ADDRESS_BYTE_0 
+ i) >> 1));
+   if (ret < 0)
+   return;
+   *(u16 *)(&dev->dev_addr[i]) = (u16)ret;
}
} else {
memcpy(dev->dev_addr, bMac_Tmp_Addr, 6);
@@ -2482,52 +2498,72 @@ static void rtl8192_read_eeprom_info(struct net_device 
*dev)
 
if (priv->card_8192_version == (u8)VERSION_819xU_A) {
/* read Tx power gain offset of legacy OFDM to HT rate */
-   if (bLoad_From_EEPOM)
-   priv->EEPROMTxPowerDiff = (eprom_read(dev, 
(EEPROM_TxPowerDiff >> 1)) & 0xff00) >> 8;
-   else
+   if (bLoad_From_EEPOM) {
+   ret = eprom_read(dev, (EEPROM_TxPowerDiff >> 1));
+   if (ret < 0)
+   return;
+   priv->EEPROMTxPowerDiff = ((u16)ret & 0xff00) >> 8;
+   } else
priv->EEPROMTxPowerDiff = EEPROM_Default_TxPower;
RT_TRACE(COMP_EPROM, "TxPowerDiff:%d\n", 
priv->EEPROMTxPowerDiff);
/* read ThermalMeter from EEPROM */
-   if (bLoad_From_EEPOM)
-   priv->EEPROMThermalMeter = (u8)(eprom_read(dev, 
(EEPROM_ThermalMeter >> 1)) & 0x00ff);
-   else
+   if (bLoad_From_EEPOM) {
+   ret = eprom_read(dev, (EEPROM_ThermalMeter >> 1));
+   if (ret < 0)
+   return;
+   priv->EEPROMThermalMeter = (u8)((u16)ret & 0x00ff);
+   } else
priv->EEPROMThermalMeter = EEPROM_Default_ThermalMeter;
RT_TRACE(COMP_EPROM, "ThermalMeter:%d\n", 
priv->EEPROMThermalMeter);
/* for tx power track */
priv->TSSI_13dBm = priv->EEPROMThermalMeter * 100;
/* read antenna tx power offset of B/C/D to A from EEPROM */
-   if (bLoad_From_EEPOM)
-   priv->EEPROMPwDiff = (eprom_read(dev, (EEPROM_PwDiff >> 
1)) & 0x0f00) >> 8;
-   else
+   if (bLoad_From_EEPOM) {
+ 

[PATCH V6 2/9] staging: rtl8192u: propagate errors in eprom_read

2016-05-03 Thread Salah Triki
Propagate error from eprom_r and change the return type of eprom_read
from u32 to int.

Signed-off-by: Salah Triki 
---
 drivers/staging/rtl8192u/r8180_93cx6.c | 9 +++--
 drivers/staging/rtl8192u/r8180_93cx6.h | 2 +-
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/rtl8192u/r8180_93cx6.c 
b/drivers/staging/rtl8192u/r8180_93cx6.c
index 2c53132..f35defc 100644
--- a/drivers/staging/rtl8192u/r8180_93cx6.c
+++ b/drivers/staging/rtl8192u/r8180_93cx6.c
@@ -106,7 +106,7 @@ static void eprom_send_bits_string(struct net_device *dev, 
short b[], int len)
 }
 
 
-u32 eprom_read(struct net_device *dev, u32 addr)
+int eprom_read(struct net_device *dev, u32 addr)
 {
struct r8192_priv *priv = ieee80211_priv(dev);
short read_cmd[] = {1, 1, 0};
@@ -114,6 +114,7 @@ u32 eprom_read(struct net_device *dev, u32 addr)
int i;
int addr_len;
u32 ret;
+   int err;
 
ret = 0;
/* enable EPROM programming */
@@ -157,7 +158,11 @@ u32 eprom_read(struct net_device *dev, u32 addr)
 * and reading data. (eeprom outs a dummy 0)
 */
eprom_ck_cycle(dev);
-   ret |= (eprom_r(dev)<<(15-i));
+   err = eprom_r(dev);
+   if (err < 0)
+   return err;
+
+   ret |= err<<(15-i);
}
 
eprom_cs(dev, 0);
diff --git a/drivers/staging/rtl8192u/r8180_93cx6.h 
b/drivers/staging/rtl8192u/r8180_93cx6.h
index b840348..9cf7f58 100644
--- a/drivers/staging/rtl8192u/r8180_93cx6.h
+++ b/drivers/staging/rtl8192u/r8180_93cx6.h
@@ -40,4 +40,4 @@
 #define EPROM_TXPW1 0x3d
 
 
-u32 eprom_read(struct net_device *dev, u32 addr); /* reads a 16 bits word */
+int eprom_read(struct net_device *dev, u32 addr); /* reads a 16 bits word */
-- 
1.9.1

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


[PATCH V6 7/9] staging: rtl8192u: propagate errors in write_nic_byte_E

2016-05-03 Thread Salah Triki
Propagate errors from  kzalloc and usb_control_msg and change the
return type of write_nic_byte_E from void to int.

Signed-off-by: Salah Triki 
---
 drivers/staging/rtl8192u/r8192U.h  | 2 +-
 drivers/staging/rtl8192u/r8192U_core.c | 9 ++---
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8192u/r8192U.h 
b/drivers/staging/rtl8192u/r8192U.h
index da9b92b..e0abcf5 100644
--- a/drivers/staging/rtl8192u/r8192U.h
+++ b/drivers/staging/rtl8192u/r8192U.h
@@ -1130,7 +1130,7 @@ int read_nic_byte_E(struct net_device *dev, int x, u8 
*data);
 int read_nic_dword(struct net_device *dev, int x, u32 *data);
 int read_nic_word(struct net_device *dev, int x, u16 *data);
 int write_nic_byte(struct net_device *dev, int x, u8 y);
-void write_nic_byte_E(struct net_device *dev, int x, u8 y);
+int write_nic_byte_E(struct net_device *dev, int x, u8 y);
 void write_nic_word(struct net_device *dev, int x, u16 y);
 void write_nic_dword(struct net_device *dev, int x, u32 y);
 void force_pci_posting(struct net_device *dev);
diff --git a/drivers/staging/rtl8192u/r8192U_core.c 
b/drivers/staging/rtl8192u/r8192U_core.c
index d9345d0..6d1ffb0 100644
--- a/drivers/staging/rtl8192u/r8192U_core.c
+++ b/drivers/staging/rtl8192u/r8192U_core.c
@@ -253,7 +253,7 @@ u32 read_cam(struct net_device *dev, u8 addr)
return data;
 }
 
-void write_nic_byte_E(struct net_device *dev, int indx, u8 data)
+int write_nic_byte_E(struct net_device *dev, int indx, u8 data)
 {
int status;
struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
@@ -261,7 +261,7 @@ void write_nic_byte_E(struct net_device *dev, int indx, u8 
data)
u8 *usbdata = kzalloc(sizeof(data), GFP_KERNEL);
 
if (!usbdata)
-   return;
+   return -ENOMEM;
*usbdata = data;
 
status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
@@ -269,9 +269,12 @@ void write_nic_byte_E(struct net_device *dev, int indx, u8 
data)
 indx | 0xfe00, 0, usbdata, 1, HZ / 2);
kfree(usbdata);
 
-   if (status < 0)
+   if (status < 0){
netdev_err(dev, "write_nic_byte_E TimeOut! status: %d\n",
   status);
+   return status;
+   }
+   return 0;
 }
 
 int read_nic_byte_E(struct net_device *dev, int indx, u8 *data)
-- 
1.9.1

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


[PATCH V6 6/9] staging: rtl8192u: propagate errors in write_nic_byte

2016-05-03 Thread Salah Triki
Propagate errors from  kzalloc and usb_control_msg and change the
return type of write_nic_byte from void to int.

Signed-off-by: Salah Triki 
---
 drivers/staging/rtl8192u/r8192U.h  |  2 +-
 drivers/staging/rtl8192u/r8192U_core.c | 10 +++---
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8192u/r8192U.h 
b/drivers/staging/rtl8192u/r8192U.h
index ee1c722..da9b92b 100644
--- a/drivers/staging/rtl8192u/r8192U.h
+++ b/drivers/staging/rtl8192u/r8192U.h
@@ -1129,7 +1129,7 @@ int read_nic_byte(struct net_device *dev, int x, u8 
*data);
 int read_nic_byte_E(struct net_device *dev, int x, u8 *data);
 int read_nic_dword(struct net_device *dev, int x, u32 *data);
 int read_nic_word(struct net_device *dev, int x, u16 *data);
-void write_nic_byte(struct net_device *dev, int x, u8 y);
+int write_nic_byte(struct net_device *dev, int x, u8 y);
 void write_nic_byte_E(struct net_device *dev, int x, u8 y);
 void write_nic_word(struct net_device *dev, int x, u16 y);
 void write_nic_dword(struct net_device *dev, int x, u32 y);
diff --git a/drivers/staging/rtl8192u/r8192U_core.c 
b/drivers/staging/rtl8192u/r8192U_core.c
index 7ce7460..d9345d0 100644
--- a/drivers/staging/rtl8192u/r8192U_core.c
+++ b/drivers/staging/rtl8192u/r8192U_core.c
@@ -299,7 +299,7 @@ int read_nic_byte_E(struct net_device *dev, int indx, u8 
*data)
 }
 
 /* as 92U has extend page from 4 to 16, so modify functions below. */
-void write_nic_byte(struct net_device *dev, int indx, u8 data)
+int write_nic_byte(struct net_device *dev, int indx, u8 data)
 {
int status;
 
@@ -308,7 +308,7 @@ void write_nic_byte(struct net_device *dev, int indx, u8 
data)
u8 *usbdata = kzalloc(sizeof(data), GFP_KERNEL);
 
if (!usbdata)
-   return;
+   return -ENOMEM;
*usbdata = data;
 
status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
@@ -317,8 +317,12 @@ void write_nic_byte(struct net_device *dev, int indx, u8 
data)
 usbdata, 1, HZ / 2);
kfree(usbdata);
 
-   if (status < 0)
+   if (status < 0) {
netdev_err(dev, "write_nic_byte TimeOut! status: %d\n", status);
+   return status;
+   }
+
+   return 0;
 }
 
 
-- 
1.9.1

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


[PATCH V6 9/9] staging: rtl8192u: propagate errors in write_nic_dword

2016-05-03 Thread Salah Triki
Propagate errors from kzalloc and usb_control_msg and change the
return type of write_nic_dword from void to int.

Signed-off-by: Salah Triki 
---
 drivers/staging/rtl8192u/r8192U.h  |  2 +-
 drivers/staging/rtl8192u/r8192U_core.c | 10 +++---
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8192u/r8192U.h 
b/drivers/staging/rtl8192u/r8192U.h
index 27f9aa5..eb0c351 100644
--- a/drivers/staging/rtl8192u/r8192U.h
+++ b/drivers/staging/rtl8192u/r8192U.h
@@ -1132,7 +1132,7 @@ int read_nic_word(struct net_device *dev, int x, u16 
*data);
 int write_nic_byte(struct net_device *dev, int x, u8 y);
 int write_nic_byte_E(struct net_device *dev, int x, u8 y);
 int write_nic_word(struct net_device *dev, int x, u16 y);
-void write_nic_dword(struct net_device *dev, int x, u32 y);
+int write_nic_dword(struct net_device *dev, int x, u32 y);
 void force_pci_posting(struct net_device *dev);
 
 void rtl8192_rtx_disable(struct net_device *);
diff --git a/drivers/staging/rtl8192u/r8192U_core.c 
b/drivers/staging/rtl8192u/r8192U_core.c
index 2faffb2..3fdcb86 100644
--- a/drivers/staging/rtl8192u/r8192U_core.c
+++ b/drivers/staging/rtl8192u/r8192U_core.c
@@ -356,7 +356,7 @@ int write_nic_word(struct net_device *dev, int indx, u16 
data)
 }
 
 
-void write_nic_dword(struct net_device *dev, int indx, u32 data)
+int write_nic_dword(struct net_device *dev, int indx, u32 data)
 {
int status;
 
@@ -365,7 +365,7 @@ void write_nic_dword(struct net_device *dev, int indx, u32 
data)
u32 *usbdata = kzalloc(sizeof(data), GFP_KERNEL);
 
if (!usbdata)
-   return;
+   return -ENOMEM;
*usbdata = data;
 
status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
@@ -375,9 +375,13 @@ void write_nic_dword(struct net_device *dev, int indx, u32 
data)
kfree(usbdata);
 
 
-   if (status < 0)
+   if (status < 0) {
netdev_err(dev, "write_nic_dword TimeOut! status: %d\n",
   status);
+   return status;
+   }
+
+   return 0;
 }
 
 
-- 
1.9.1

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


[PATCH 2/3] staging: dgnc: remove useless assigned error value in

2016-05-03 Thread Daeseok Youn
the result in dgnc_get_mstat() was initialized with -EIO but
there are no use of EIO as a result in this function.

Signed-off-by: Daeseok Youn 
---
 drivers/staging/dgnc/dgnc_tty.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/staging/dgnc/dgnc_tty.c b/drivers/staging/dgnc/dgnc_tty.c
index d85d005..46ca01d 100644
--- a/drivers/staging/dgnc/dgnc_tty.c
+++ b/drivers/staging/dgnc/dgnc_tty.c
@@ -1979,7 +1979,7 @@ static void dgnc_tty_send_xchar(struct tty_struct *tty, 
char c)
 static inline int dgnc_get_mstat(struct channel_t *ch)
 {
unsigned char mstat;
-   int result = -EIO;
+   int result = 0;
unsigned long flags;
 
if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
@@ -1991,8 +1991,6 @@ static inline int dgnc_get_mstat(struct channel_t *ch)
 
spin_unlock_irqrestore(&ch->ch_lock, flags);
 
-   result = 0;
-
if (mstat & UART_MCR_DTR)
result |= TIOCM_DTR;
if (mstat & UART_MCR_RTS)
-- 
2.8.2

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


[PATCH 1/3] staging: dgnc: remove redundant NULL check in

2016-05-03 Thread Daeseok Youn
tty and ch are already checked for NULL
before calling dgnc_block_til_ready().

Signed-off-by: Daeseok Youn 
---
 drivers/staging/dgnc/dgnc_tty.c | 9 ++---
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/dgnc/dgnc_tty.c b/drivers/staging/dgnc/dgnc_tty.c
index 2cecdb0..d85d005 100644
--- a/drivers/staging/dgnc/dgnc_tty.c
+++ b/drivers/staging/dgnc/dgnc_tty.c
@@ -1172,17 +1172,12 @@ static int dgnc_block_til_ready(struct tty_struct *tty,
struct channel_t *ch)
 {
int retval = 0;
-   struct un_t *un = NULL;
+   struct un_t *un = tty->driver_data;
unsigned long flags;
uintold_flags = 0;
int sleep_on_un_flags = 0;
 
-   if (!tty || tty->magic != TTY_MAGIC || !file || !ch ||
-   ch->magic != DGNC_CHANNEL_MAGIC)
-   return -ENXIO;
-
-   un = tty->driver_data;
-   if (!un || un->magic != DGNC_UNIT_MAGIC)
+   if (!file)
return -ENXIO;
 
spin_lock_irqsave(&ch->ch_lock, flags);
-- 
2.8.2

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


[PATCH 3/3] staging: dgnc: clean up the dgnc_get_modem_info()

2016-05-03 Thread Daeseok Youn
the "ch" in dgnc_get_modem_info() was already checked before calling
this function and also if "ch" is not NULL, dgnc_get_mstat() returns
valid value so it doesn't need to check an error.

Signed-off-by: Daeseok Youn 
---
 drivers/staging/dgnc/dgnc_tty.c | 12 +---
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/drivers/staging/dgnc/dgnc_tty.c b/drivers/staging/dgnc/dgnc_tty.c
index 46ca01d..f67d7d4 100644
--- a/drivers/staging/dgnc/dgnc_tty.c
+++ b/drivers/staging/dgnc/dgnc_tty.c
@@ -2013,17 +2013,7 @@ static inline int dgnc_get_mstat(struct channel_t *ch)
 static int dgnc_get_modem_info(struct channel_t *ch,
   unsigned int  __user *value)
 {
-   int result;
-
-   if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
-   return -ENXIO;
-
-   result = dgnc_get_mstat(ch);
-
-   if (result < 0)
-   return -ENXIO;
-
-   return put_user(result, value);
+   return put_user(dgnc_get_mstat(ch), value);
 }
 
 /*
-- 
2.8.2

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


Re: staging: dgnc: use tty_alloc_driver instead of kcalloc

2016-05-03 Thread DaeSeok Youn
2016-05-03 17:15 GMT+09:00 Dan Carpenter :
> Hello Daeseok Youn,
Hello Dan,
>
> The patch 60b3109e5e2d: "staging: dgnc: use tty_alloc_driver instead
> of kcalloc" from Apr 14, 2016, leads to the following static checker
> warning:
>
> drivers/staging/dgnc/dgnc_tty.c:229 dgnc_tty_register()
> error: 'brd->print_driver' dereferencing possible ERR_PTR()
>
> drivers/staging/dgnc/dgnc_tty.c
>217  /*
>218   * If we're doing transparent print, we have to do all of the 
> above
>219   * again, separately so we don't get the LD confused about 
> what major
>220   * we are when we get into the dgnc_tty_open() routine.
>221   */
>222  brd->print_driver = tty_alloc_driver(brd->maxports,
>223   TTY_DRIVER_REAL_RAW |
>224   TTY_DRIVER_DYNAMIC_DEV |
>225   
> TTY_DRIVER_HARDWARE_BREAK);
>
> This function call needs error handling.
Yes, right. I had a mistake for handling error for print_driver.
Error handling code will be moved after calling tty_alloc_driver().

>
>226
>227  snprintf(brd->print_name, MAXTTYNAMELEN, "pr_dgnc_%d_", 
> brd->boardnum);
>228
>229  brd->print_driver->name = brd->print_name;
>230  brd->print_driver->name_base = 0;
>231  brd->print_driver->major = brd->serial_driver->major;
>232  brd->print_driver->minor_start = 0x80;
>
> regards,
> dan carpenter
Thanks.

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


[PATCH] staging: dgnc: Fix a NULL pointer dereference

2016-05-03 Thread Daeseok Youn
The error handling for print_drive after calling tty_alloc_driver()
was needed. But there was error handling but too late for this.
Error handling code moved after tty_alloc_driver() call.

Fixes: 60b3109e5e2d ("staging: dgnc: use tty_alloc_driver instead of kcalloc")
Reported-by: Dan Carpenter 
Signed-off-by: Daeseok Youn 
---
 drivers/staging/dgnc/dgnc_tty.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/dgnc/dgnc_tty.c b/drivers/staging/dgnc/dgnc_tty.c
index 2cecdb0..392d532 100644
--- a/drivers/staging/dgnc/dgnc_tty.c
+++ b/drivers/staging/dgnc/dgnc_tty.c
@@ -224,6 +224,11 @@ int dgnc_tty_register(struct dgnc_board *brd)
 TTY_DRIVER_DYNAMIC_DEV |
 TTY_DRIVER_HARDWARE_BREAK);
 
+   if (IS_ERR(brd->print_driver)) {
+   rc = PTR_ERR(brd->print_driver);
+   goto unregister_serial_driver;
+   }
+
snprintf(brd->print_name, MAXTTYNAMELEN, "pr_dgnc_%d_", brd->boardnum);
 
brd->print_driver->name = brd->print_name;
@@ -235,11 +240,6 @@ int dgnc_tty_register(struct dgnc_board *brd)
brd->print_driver->init_termios = DgncDefaultTermios;
brd->print_driver->driver_name = DRVSTR;
 
-   if (IS_ERR(brd->print_driver)) {
-   rc = PTR_ERR(brd->print_driver);
-   goto unregister_serial_driver;
-   }
-
/*
 * Entry points for driver.  Called by the kernel from
 * tty_io.c and n_tty.c.
-- 
2.8.2

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


Re: [PATCH] staging: dgnc: Fix a NULL pointer dereference

2016-05-03 Thread Greg KH
On Wed, May 04, 2016 at 02:41:22PM +0900, Daeseok Youn wrote:
> The error handling for print_drive after calling tty_alloc_driver()
> was needed. But there was error handling but too late for this.
> Error handling code moved after tty_alloc_driver() call.
> 
> Fixes: 60b3109e5e2d ("staging: dgnc: use tty_alloc_driver instead of kcalloc")
> Reported-by: Dan Carpenter 
> Signed-off-by: Daeseok Youn 
> ---
>  drivers/staging/dgnc/dgnc_tty.c | 10 +-
>  1 file changed, 5 insertions(+), 5 deletions(-)

Patch doesn't apply at all, does it need something else to be merged
first?

confused,

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


Re: [PATCH] staging: dgnc: Fix a NULL pointer dereference

2016-05-03 Thread Greg KH
On Tue, May 03, 2016 at 10:56:09PM -0700, Greg KH wrote:
> On Wed, May 04, 2016 at 02:41:22PM +0900, Daeseok Youn wrote:
> > The error handling for print_drive after calling tty_alloc_driver()
> > was needed. But there was error handling but too late for this.
> > Error handling code moved after tty_alloc_driver() call.
> > 
> > Fixes: 60b3109e5e2d ("staging: dgnc: use tty_alloc_driver instead of 
> > kcalloc")
> > Reported-by: Dan Carpenter 
> > Signed-off-by: Daeseok Youn 
> > ---
> >  drivers/staging/dgnc/dgnc_tty.c | 10 +-
> >  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> Patch doesn't apply at all, does it need something else to be merged
> first?

Oh nevermind, I tried applying it to the wrong git tree, my fault...

I need some sleep...

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