Re: [PATCH]staging: slicoss: Fix possible reuse of freed memory in timer function

2014-02-10 Thread Denis Kirjanov
On 2/10/14, Kirill Tkhai  wrote:
> Do not call kfree() till timer function is finished.
>
> [This was found using grep. Compiled tested only]
>
> Signed-off-by: Kirill Tkhai 
> CC: Joe Perches 
> CC: Greg Kroah-Hartman 

CC Chris Harrer.

The problem with that driver is that alacritech guys don't seem to
care. Not sure if anyone has a hardware to test the driver and
probably the code is completely broken.
Probably the better option is to drop the code from the staging tree...

> ---
>  drivers/staging/slicoss/slicoss.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> diff --git a/drivers/staging/slicoss/slicoss.c
> b/drivers/staging/slicoss/slicoss.c
> index 1426ca4..e0de497 100644
> --- a/drivers/staging/slicoss/slicoss.c
> +++ b/drivers/staging/slicoss/slicoss.c
> @@ -2970,7 +2970,7 @@ static void slic_card_cleanup(struct sliccard *card)
>  {
>   if (card->loadtimerset) {
>   card->loadtimerset = 0;
> - del_timer(&card->loadtimer);
> + del_timer_sync(&card->loadtimer);
>   }
>
>   slic_debug_card_destroy(card);
> ___
> devel mailing list
> de...@linuxdriverproject.org
> http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
>


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


[PATCH 1/2] drivers:staging:silicom: Fixed MACRO and Extern Coding style warnings and errors

2014-02-10 Thread Surendra Patil
Fixed MACRO and Extern Coding style warnings and errors - listed only few
bpctl_mod.c:120: WARNING: externs should be avoided in .c files
bpctl_mod.c:121: WARNING: externs should be avoided in .c files
bpctl_mod.c:122: WARNING: externs should be avoided in .c files
bpctl_mod.c:124: WARNING: externs should be avoided in .c files
bpctl_mod.c:125: WARNING: externs should be avoided in .c files
bp_ioctl.h:54: ERROR: Macros with complex values should be enclosed in 
parenthesis
bp_ioctl.h:159: ERROR: Macros with complex values should be enclosed in 
parenthesis

Signed-off-by: Surendra Patil 
---
 drivers/staging/silicom/bpctl_mod.c  | 28 ++--
 drivers/staging/silicom/bypasslib/bp_ioctl.h |  4 ++--
 2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/drivers/staging/silicom/bpctl_mod.c 
b/drivers/staging/silicom/bpctl_mod.c
index 20325f5..5edb9d4 100644
--- a/drivers/staging/silicom/bpctl_mod.c
+++ b/drivers/staging/silicom/bpctl_mod.c
@@ -117,12 +117,12 @@ static int wdt_timer(struct bpctl_dev *pbpctl_dev, int 
*time_left);
 static struct bpctl_dev *get_status_port_fn(struct bpctl_dev *pbpctl_dev);
 static void if_scan_init(void);
 
-int bypass_proc_create_dev_sd(struct bpctl_dev *pbp_device_block);
-int bypass_proc_remove_dev_sd(struct bpctl_dev *pbp_device_block);
-int bp_proc_create(void);
+static int bypass_proc_create_dev_sd(struct bpctl_dev *pbp_device_block);
+static int bypass_proc_remove_dev_sd(struct bpctl_dev *pbp_device_block);
+static int bp_proc_create(void);
 
-int is_bypass_fn(struct bpctl_dev *pbpctl_dev);
-int get_dev_idx_bsf(int bus, int slot, int func);
+static int is_bypass_fn(struct bpctl_dev *pbpctl_dev);
+static int get_dev_idx_bsf(int bus, int slot, int func);
 
 static int bp_get_dev_idx_bsf(struct net_device *dev, int *index)
 {
@@ -262,8 +262,8 @@ static struct notifier_block bp_notifier_block = {
.notifier_call = bp_device_event,
 };
 
-int is_bypass_fn(struct bpctl_dev *pbpctl_dev);
-int wdt_time_left(struct bpctl_dev *pbpctl_dev);
+static int is_bypass_fn(struct bpctl_dev *pbpctl_dev);
+static int wdt_time_left(struct bpctl_dev *pbpctl_dev);
 
 static void write_pulse(struct bpctl_dev *pbpctl_dev,
unsigned int ctrl_ext,
@@ -1392,7 +1392,7 @@ static int wdt_pulse(struct bpctl_dev *pbpctl_dev)
(ctrl_ext &
 ~(BP10G_MCLK_DATA_OUT | BP10G_MDIO_DATA_OUT)));
}
-   if ((pbpctl_dev->wdt_status == WDT_STATUS_EN))
+   if (pbpctl_dev->wdt_status == WDT_STATUS_EN)
/*&& (pbpctl_dev->bp_ext_verbypass_wdt_on_time = jiffies;
 #ifdef BP_SYNC_FLAG
@@ -2866,7 +2866,7 @@ int std_nic_off(struct bpctl_dev *pbpctl_dev)
return BP_NOT_CAP;
 }
 
-int wdt_time_left(struct bpctl_dev *pbpctl_dev)
+static int wdt_time_left(struct bpctl_dev *pbpctl_dev)
 {
 
/* unsigned long curr_time=((long long)(jiffies*1000))/HZ, 
delta_time=0,wdt_on_time=((long long)(pbpctl_dev->bypass_wdt_on_time*1000))/HZ; 
*/
@@ -7101,13 +7101,13 @@ int get_bp_hw_reset_sd(int ifindex)
 }
 EXPORT_SYMBOL(get_bp_hw_reset_sd);
 
-int get_bypass_info_sd(int ifindex, struct bp_info *bp_info)
+static int get_bypass_info_sd(int ifindex, struct bp_info *bp_info)
 {
return get_bypass_info_fn(get_dev_idx_p(ifindex), bp_info->prod_name, 
&bp_info->fw_ver);
 }
 EXPORT_SYMBOL(get_bypass_info_sd);
 
-int bp_if_scan_sd(void)
+static int bp_if_scan_sd(void)
 {
if_scan_init();
return 0;
@@ -7118,7 +7118,7 @@ EXPORT_SYMBOL(bp_if_scan_sd);
 
 static struct proc_dir_entry *bp_procfs_dir;
 
-int bp_proc_create(void)
+static int bp_proc_create(void)
 {
bp_procfs_dir = proc_mkdir(BP_PROC_DIR, init_net.proc_net);
if (bp_procfs_dir == (struct proc_dir_entry *)0) {
@@ -7746,7 +7746,7 @@ static int show_wd_autoreset(struct seq_file *m, void *v)
 }
 RW_FOPS(wd_autoreset)
 
-int bypass_proc_create_dev_sd(struct bpctl_dev *pbp_device_block)
+static int bypass_proc_create_dev_sd(struct bpctl_dev *pbp_device_block)
 {
struct bypass_pfs_sd *current_pfs = &(pbp_device_block->bypass_pfs_set);
static struct proc_dir_entry *procfs_dir;
@@ -7816,7 +7816,7 @@ int bypass_proc_create_dev_sd(struct bpctl_dev 
*pbp_device_block)
return ret;
 }
 
-int bypass_proc_remove_dev_sd(struct bpctl_dev *pbp_device_block)
+static int bypass_proc_remove_dev_sd(struct bpctl_dev *pbp_device_block)
 {
 
struct bypass_pfs_sd *current_pfs = &pbp_device_block->bypass_pfs_set;
diff --git a/drivers/staging/silicom/bypasslib/bp_ioctl.h 
b/drivers/staging/silicom/bypasslib/bp_ioctl.h
index 2d1ef53..a0fb79f 100644
--- a/drivers/staging/silicom/bypasslib/bp_ioctl.h
+++ b/drivers/staging/silicom/bypasslib/bp_ioctl.h
@@ -51,7 +51,7 @@
 #define WDT_STEP_TIME  0x10/* BIT_4 */
 
 #define WD_MIN_TIME_GET(desc)   (desc & 0xf)
-#define WD_STEP_COUNT_GET(desc) (desc>>5) & 0xf
+#define WD_STEP_COUNT_GET(desc) ((desc>>5) & 0xf)
 
 typedef 

[PATCH 2/2] drivers:staging:silicom Removed bp_proc_create() declaration

2014-02-10 Thread Surendra Patil
Removed  bp_proc_create() declaration from bp_mod.h,
already declared static in bpctl_mod.c in first patch

Signed-off-by: Surendra Patil 
---
 drivers/staging/silicom/bp_mod.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/staging/silicom/bp_mod.h b/drivers/staging/silicom/bp_mod.h
index 8154a7b..e6e 100644
--- a/drivers/staging/silicom/bp_mod.h
+++ b/drivers/staging/silicom/bp_mod.h
@@ -698,5 +698,3 @@ static inline unsigned int jiffies_to_msecs(const unsigned 
long j)
readl((void *)((a)->mem_map) + BP10GB_##reg))
 
 #endif
-
-int bp_proc_create(void);
-- 
1.8.3.2

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


Re: [PATCH]staging: slicoss: Fix possible reuse of freed memory in timer function

2014-02-10 Thread Joe Perches
On Mon, 2014-02-10 at 22:36 +0400, Kirill Tkhai wrote:
> Do not call kfree() till timer function is finished.
> 
> [This was found using grep. Compiled tested only]
> 
> Signed-off-by: Kirill Tkhai 
> CC: Joe Perches 
> CC: Greg Kroah-Hartman 

I don't need to be cc'd on this.

Perhaps the MAINTAINERS file should be updated
with the names from the README file. (cc'd)

Lior Dotan 
Christopher Harrer 

Also the README could be broken into a separate TODO.

Maybe something like:


From: Joe Perches 
Date: Mon, 10 Feb 2014 16:33:04 -0800
Subject: [PATCH] staging: slicoss: Add MAINTAINERS entry, break README into 
TODO & README

Adding a MAINTAINERS entry with content from the README.
Move the TODO items from the README to a separate TODO file.

Signed-off-by: Joe Perches 
---
 MAINTAINERS|  6 ++
 drivers/staging/slicoss/README | 40 
 drivers/staging/slicoss/TODO   | 38 ++
 3 files changed, 44 insertions(+), 40 deletions(-)
 create mode 100644 drivers/staging/slicoss/TODO

diff --git a/MAINTAINERS b/MAINTAINERS
index 192e027..a6c7899 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8322,6 +8322,12 @@ M:   Teddy Wang 
 S: Odd Fixes
 F: drivers/staging/sm7xxfb/
 
+STAGING - SLICOSS
+M: Lior Dotan 
+M: Christopher Harrer 
+S: Odd Fixes
+F: drivers/staging/slicoss/
+
 STAGING - SOFTLOGIC 6x10 MPEG CODEC
 M: Ismael Luceno 
 S: Supported
diff --git a/drivers/staging/slicoss/README b/drivers/staging/slicoss/README
index 53052c4..4fa50e7 100644
--- a/drivers/staging/slicoss/README
+++ b/drivers/staging/slicoss/README
@@ -5,43 +5,3 @@ This driver is supposed to support:
Kalahari cards (dual and quad port PCI-e Gigabit) copper and fiber
 
 The driver was actually tested on Oasis and Kalahari cards.
-
-TODO:
-   - move firmware loading to request_firmware()
-   - remove direct memory access of structures
-   - any remaining sparse and checkpatch.pl warnings
-
-   - use net_device_ops
-   - use dev->stats rather than adapter->stats
-   - don't cast netdev_priv it is already void
-   - GET RID OF MACROS
-   - work on all architectures
-  - without CONFIG_X86_64 confusion
-  - do 64 bit correctly
-  - don't depend on order of union
-   - get rid of ASSERT(), use BUG() instead but only where necessary
- looks like most aren't really useful
-   - no new SIOCDEVPRIVATE ioctl allowed
-   - don't use module_param for configuring interrupt mitigation
- use ethtool instead
-   - reorder code to elminate use of forward declarations
-   - don't keep private linked list of drivers.
-   - remove all the gratiutous debug infrastructure
-   - use PCI_DEVICE()
-   - do ethtool correctly using ethtool_ops
-   - NAPI?
-   - wasted overhead of extra stats
-   - state variables for things that are
- easily available and shouldn't be kept in card structure, cardnum, ...
- slotnumber, events, ...
-   - get rid of slic_spinlock wrapper
-   - volatile == bad design => bad code
-   - locking too fine grained, not designed just throw more locks
- at problem
-
-
-Please send patches to:
-Greg Kroah-Hartman 
-and Cc: Lior Dotan  and Christopher Harrer
- as well as they are also able to test out any
-changes.
diff --git a/drivers/staging/slicoss/TODO b/drivers/staging/slicoss/TODO
new file mode 100644
index 000..62ff100
--- /dev/null
+++ b/drivers/staging/slicoss/TODO
@@ -0,0 +1,38 @@
+TODO:
+   - move firmware loading to request_firmware()
+   - remove direct memory access of structures
+   - any remaining sparse and checkpatch.pl warnings
+
+   - use net_device_ops
+   - use dev->stats rather than adapter->stats
+   - don't cast netdev_priv it is already void
+   - GET RID OF MACROS
+   - work on all architectures
+  - without CONFIG_X86_64 confusion
+  - do 64 bit correctly
+  - don't depend on order of union
+   - get rid of ASSERT(), use BUG() instead but only where necessary
+ looks like most aren't really useful
+   - no new SIOCDEVPRIVATE ioctl allowed
+   - don't use module_param for configuring interrupt mitigation
+ use ethtool instead
+   - reorder code to elminate use of forward declarations
+   - don't keep private linked list of drivers.
+   - remove all the gratiutous debug infrastructure
+   - use PCI_DEVICE()
+   - do ethtool correctly using ethtool_ops
+   - NAPI?
+   - wasted overhead of extra stats
+   - state variables for things that are
+ easily available and shouldn't be kept in card structure, cardnum, ...
+ slotnumber, events, ...
+   - get rid of slic_spinlock wrapper
+   - volatile == bad design => bad code
+   - locking too fine grained, not designed just throw more locks
+   

[PATCH 9/9] staging: comedi: pcl816: trigger sources were validated in (*do_cmdtest)

2014-02-10 Thread H Hartley Sweeten
The trigger sources were already validataed in the (*do_cmdtest) before the
(*do_cmd) is called. Remove the unnecessary checks in pcl816_ai_cmd().

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

diff --git a/drivers/staging/comedi/drivers/pcl816.c 
b/drivers/staging/comedi/drivers/pcl816.c
index a35f230..044722f 100644
--- a/drivers/staging/comedi/drivers/pcl816.c
+++ b/drivers/staging/comedi/drivers/pcl816.c
@@ -480,15 +480,6 @@ static int pcl816_ai_cmd(struct comedi_device *dev, struct 
comedi_subdevice *s)
struct comedi_cmd *cmd = &s->async->cmd;
unsigned int seglen;
 
-   if (cmd->start_src != TRIG_NOW)
-   return -EINVAL;
-   if (cmd->scan_begin_src != TRIG_FOLLOW)
-   return -EINVAL;
-   if (cmd->scan_end_src != TRIG_COUNT)
-   return -EINVAL;
-   if (cmd->scan_end_arg != cmd->chanlist_len)
-   return -EINVAL;
-/* if(cmd->chanlist_len>MAX_CHANLIST_LEN) return -EINVAL; */
if (devpriv->irq_blocked)
return -EBUSY;
 
-- 
1.8.5.2

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


[PATCH 5/9] staging: comedi: cb_pcidas: trigger sources are validated in (*do_cmdtest)

2014-02-10 Thread H Hartley Sweeten
The trigger sources were already validataed in the (*do_cmdtest) before the
(*do_cmd) is called. Refactor the code in cb_pcidas_ai_cmd() to remove the
final else which can never be reached.

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

diff --git a/drivers/staging/comedi/drivers/cb_pcidas.c 
b/drivers/staging/comedi/drivers/cb_pcidas.c
index 7d068eb..5452b71 100644
--- a/drivers/staging/comedi/drivers/cb_pcidas.c
+++ b/drivers/staging/comedi/drivers/cb_pcidas.c
@@ -1017,9 +1017,9 @@ static int cb_pcidas_ai_cmd(struct comedi_device *dev,
 
/*  set start trigger and burst mode */
bits = 0;
-   if (cmd->start_src == TRIG_NOW)
+   if (cmd->start_src == TRIG_NOW) {
bits |= SW_TRIGGER;
-   else if (cmd->start_src == TRIG_EXT) {
+   } else {/* TRIG_EXT */
bits |= EXT_TRIGGER | TGEN | XTRCL;
if (thisboard->is_1602) {
if (cmd->start_arg & CR_INVERT)
@@ -1027,9 +1027,6 @@ static int cb_pcidas_ai_cmd(struct comedi_device *dev,
if (cmd->start_arg & CR_EDGE)
bits |= TGSEL;
}
-   } else {
-   comedi_error(dev, "bug!");
-   return -1;
}
if (cmd->convert_src == TRIG_NOW && cmd->chanlist_len > 1)
bits |= BURSTE;
-- 
1.8.5.2

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


[PATCH 1/9] staging: comedi: usbduxfast: 'cmd->chanlist_len' was already validataed

2014-02-10 Thread H Hartley Sweeten
Remove the unnecessary check of 'cmd->chanlist_len > 0'. The (*do_cmdtest) 
already
validated this before the (*do_cmd) was called.

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

diff --git a/drivers/staging/comedi/drivers/usbduxfast.c 
b/drivers/staging/comedi/drivers/usbduxfast.c
index 5f85c55..4a927e4 100644
--- a/drivers/staging/comedi/drivers/usbduxfast.c
+++ b/drivers/staging/comedi/drivers/usbduxfast.c
@@ -514,27 +514,25 @@ static int usbduxfast_ai_cmd(struct comedi_device *dev,
 */
devpriv->ignore = PACKETS_TO_IGNORE;
 
-   if (cmd->chanlist_len > 0) {
-   gain = CR_RANGE(cmd->chanlist[0]);
-   for (i = 0; i < cmd->chanlist_len; ++i) {
-   chan = CR_CHAN(cmd->chanlist[i]);
-   if (chan != i) {
-   dev_err(dev->class_dev,
-   "channels are not consecutive\n");
-   up(&devpriv->sem);
-   return -EINVAL;
-   }
-   if ((gain != CR_RANGE(cmd->chanlist[i]))
-   && (cmd->chanlist_len > 3)) {
-   dev_err(dev->class_dev,
-   "gain must be the same for all 
channels\n");
-   up(&devpriv->sem);
-   return -EINVAL;
-   }
-   if (i >= NUMCHANNELS) {
-   dev_err(dev->class_dev, "chanlist too long\n");
-   break;
-   }
+   gain = CR_RANGE(cmd->chanlist[0]);
+   for (i = 0; i < cmd->chanlist_len; ++i) {
+   chan = CR_CHAN(cmd->chanlist[i]);
+   if (chan != i) {
+   dev_err(dev->class_dev,
+   "channels are not consecutive\n");
+   up(&devpriv->sem);
+   return -EINVAL;
+   }
+   if ((gain != CR_RANGE(cmd->chanlist[i]))
+   && (cmd->chanlist_len > 3)) {
+   dev_err(dev->class_dev,
+   "gain must be the same for all channels\n");
+   up(&devpriv->sem);
+   return -EINVAL;
+   }
+   if (i >= NUMCHANNELS) {
+   dev_err(dev->class_dev, "chanlist too long\n");
+   break;
}
}
steps = 0;
-- 
1.8.5.2

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


[PATCH 4/9] staging: comedi: cb_das16_cs: remove incomplete async command support

2014-02-10 Thread H Hartley Sweeten
This driver has a (*do_cmdtest) function for analog input async command
support but the (*do_cmd) function just returns -EINVAL.

Remove the incomplete async command support.

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

diff --git a/drivers/staging/comedi/drivers/cb_das16_cs.c 
b/drivers/staging/comedi/drivers/cb_das16_cs.c
index e0ed193..645fcb0 100644
--- a/drivers/staging/comedi/drivers/cb_das16_cs.c
+++ b/drivers/staging/comedi/drivers/cb_das16_cs.c
@@ -95,12 +95,6 @@ static const struct comedi_lrange das16cs_ai_range = {
}
 };
 
-static irqreturn_t das16cs_interrupt(int irq, void *d)
-{
-   /* struct comedi_device *dev = d; */
-   return IRQ_HANDLED;
-}
-
 static int das16cs_ai_eoc(struct comedi_device *dev,
  struct comedi_subdevice *s,
  struct comedi_insn *insn,
@@ -161,117 +155,6 @@ static int das16cs_ai_rinsn(struct comedi_device *dev,
return i;
 }
 
-static int das16cs_ai_cmd(struct comedi_device *dev, struct comedi_subdevice 
*s)
-{
-   return -EINVAL;
-}
-
-static int das16cs_ai_cmdtest(struct comedi_device *dev,
- struct comedi_subdevice *s,
- struct comedi_cmd *cmd)
-{
-   int err = 0;
-   int tmp;
-
-   /* Step 1 : check if triggers are trivially valid */
-
-   err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW);
-   err |= cfc_check_trigger_src(&cmd->scan_begin_src,
-   TRIG_TIMER | TRIG_EXT);
-   err |= cfc_check_trigger_src(&cmd->convert_src,
-   TRIG_TIMER | TRIG_EXT);
-   err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
-   err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
-
-   if (err)
-   return 1;
-
-   /* Step 2a : make sure trigger sources are unique */
-
-   err |= cfc_check_trigger_is_unique(cmd->scan_begin_src);
-   err |= cfc_check_trigger_is_unique(cmd->convert_src);
-   err |= cfc_check_trigger_is_unique(cmd->stop_src);
-
-   /* Step 2b : and mutually compatible */
-
-   if (err)
-   return 2;
-
-   /* Step 3: check if arguments are trivially valid */
-
-   err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0);
-
-#define MAX_SPEED  1   /* in nanoseconds */
-#define MIN_SPEED  10  /* in nanoseconds */
-
-   if (cmd->scan_begin_src == TRIG_TIMER) {
-   err |= cfc_check_trigger_arg_min(&cmd->scan_begin_arg,
-MAX_SPEED);
-   err |= cfc_check_trigger_arg_max(&cmd->scan_begin_arg,
-MIN_SPEED);
-   } else {
-   /* external trigger */
-   /* should be level/edge, hi/lo specification here */
-   /* should specify multiple external triggers */
-   err |= cfc_check_trigger_arg_max(&cmd->scan_begin_arg, 9);
-   }
-   if (cmd->convert_src == TRIG_TIMER) {
-   err |= cfc_check_trigger_arg_min(&cmd->convert_arg,
-MAX_SPEED);
-   err |= cfc_check_trigger_arg_max(&cmd->convert_arg,
-MIN_SPEED);
-   } else {
-   /* external trigger */
-   /* see above */
-   err |= cfc_check_trigger_arg_max(&cmd->convert_arg, 9);
-   }
-
-   err |= cfc_check_trigger_arg_is(&cmd->scan_end_arg, cmd->chanlist_len);
-
-   if (cmd->stop_src == TRIG_COUNT)
-   err |= cfc_check_trigger_arg_max(&cmd->stop_arg, 0x00ff);
-   else/* TRIG_NONE */
-   err |= cfc_check_trigger_arg_is(&cmd->stop_arg, 0);
-
-   if (err)
-   return 3;
-
-   /* step 4: fix up any arguments */
-
-   if (cmd->scan_begin_src == TRIG_TIMER) {
-   unsigned int div1 = 0, div2 = 0;
-
-   tmp = cmd->scan_begin_arg;
-   i8253_cascade_ns_to_timer(I8254_OSC_BASE_10MHZ,
- &div1, &div2,
- &cmd->scan_begin_arg, cmd->flags);
-   if (tmp != cmd->scan_begin_arg)
-   err++;
-   }
-   if (cmd->convert_src == TRIG_TIMER) {
-   unsigned int div1 = 0, div2 = 0;
-
-   tmp = cmd->convert_arg;
-   i8253_cascade_ns_to_timer(I8254_OSC_BASE_10MHZ,
- &div1, &div2,
- &cmd->scan_begin_arg, cmd->flags);
-   if (tmp != cmd->convert_arg)
-   err++;
-   if (cmd->scan_begin_src == TRIG_TIMER &&
-   cmd->scan_begin_arg <
-   cmd->conv

[PATCH 6/9] staging: comedi: comedi_test: trigger sources are validated in (*do_cmdtest)

2014-02-10 Thread H Hartley Sweeten
The trigger sources were already validataed in the (*do_cmdtest) before the
(*do_cmd) is called. Refactor the code in waveform_ai_cmd() to remove the
final else which can never be reached.

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

diff --git a/drivers/staging/comedi/drivers/comedi_test.c 
b/drivers/staging/comedi/drivers/comedi_test.c
index d539eaf..3f59666 100644
--- a/drivers/staging/comedi/drivers/comedi_test.c
+++ b/drivers/staging/comedi/drivers/comedi_test.c
@@ -318,12 +318,8 @@ static int waveform_ai_cmd(struct comedi_device *dev,
 
if (cmd->convert_src == TRIG_NOW)
devpriv->convert_period = 0;
-   else if (cmd->convert_src == TRIG_TIMER)
+   else/* TRIG_TIMER */
devpriv->convert_period = cmd->convert_arg / nano_per_micro;
-   else {
-   comedi_error(dev, "bug setting conversion period");
-   return -1;
-   }
 
do_gettimeofday(&devpriv->last);
devpriv->usec_current = devpriv->last.tv_usec % devpriv->usec_period;
-- 
1.8.5.2

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


[PATCH 3/9] staging: comedi: adl_pci9111: trigger sources are validated in (*do_cmdtest)

2014-02-10 Thread H Hartley Sweeten
The trigger sources were already validataed in the (*do_cmdtest) before the
(*do_cmd) is called. Refactor the code in pci9111_ai_do_cmd() to use if/else
instead of the switch since the default cases can never be reached.

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

diff --git a/drivers/staging/comedi/drivers/adl_pci9111.c 
b/drivers/staging/comedi/drivers/adl_pci9111.c
index ff086d0..80a0560 100644
--- a/drivers/staging/comedi/drivers/adl_pci9111.c
+++ b/drivers/staging/comedi/drivers/adl_pci9111.c
@@ -489,29 +489,18 @@ static int pci9111_ai_do_cmd(struct comedi_device *dev,
dev->iobase + PCI9111_AI_RANGE_STAT_REG);
 
/* Set counter */
-
-   switch (async_cmd->stop_src) {
-   case TRIG_COUNT:
+   if (async_cmd->stop_src == TRIG_COUNT) {
dev_private->stop_counter =
async_cmd->stop_arg * async_cmd->chanlist_len;
dev_private->stop_is_none = 0;
-   break;
-
-   case TRIG_NONE:
+   } else {/* TRIG_NONE */
dev_private->stop_counter = 0;
dev_private->stop_is_none = 1;
-   break;
-
-   default:
-   comedi_error(dev, "Invalid stop trigger");
-   return -1;
}
 
/*  Set timer pacer */
-
dev_private->scan_delay = 0;
-   switch (async_cmd->convert_src) {
-   case TRIG_TIMER:
+   if (async_cmd->convert_src == TRIG_TIMER) {
pci9111_trigger_source_set(dev, software);
pci9111_timer_set(dev);
pci9111_fifo_reset(dev);
@@ -527,11 +516,7 @@ static int pci9111_ai_do_cmd(struct comedi_device *dev,
 (async_cmd->convert_arg *
  async_cmd->chanlist_len)) - 1;
}
-
-   break;
-
-   case TRIG_EXT:
-
+   } else {/* TRIG_EXT */
pci9111_trigger_source_set(dev, external);
pci9111_fifo_reset(dev);
pci9111_interrupt_source_set(dev, irq_on_fifo_half_full,
@@ -539,11 +524,6 @@ static int pci9111_ai_do_cmd(struct comedi_device *dev,
plx9050_interrupt_control(dev_private->lcr_io_base, true, true,
  false, true, true);
 
-   break;
-
-   default:
-   comedi_error(dev, "Invalid convert trigger");
-   return -1;
}
 
dev_private->stop_counter *= (1 + dev_private->scan_delay);
-- 
1.8.5.2

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


[PATCH 7/9] staging: comedi: das800: trigger sources are validated in (*do_cmdtest)

2014-02-10 Thread H Hartley Sweeten
The trigger sources were already validataed in the (*do_cmdtest) before the
(*do_cmd) is called. Refactor the code in das800_ai_do_cmd() to use if/else
instead of the switch since the default cases can never be reached.

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

diff --git a/drivers/staging/comedi/drivers/das800.c 
b/drivers/staging/comedi/drivers/das800.c
index dbe94ce..8c15929 100644
--- a/drivers/staging/comedi/drivers/das800.c
+++ b/drivers/staging/comedi/drivers/das800.c
@@ -420,17 +420,12 @@ static int das800_ai_do_cmd(struct comedi_device *dev,
gain &= 0xf;
outb(gain, dev->iobase + DAS800_GAIN);
 
-   switch (async->cmd.stop_src) {
-   case TRIG_COUNT:
+   if (async->cmd.stop_src == TRIG_COUNT) {
devpriv->count = async->cmd.stop_arg * async->cmd.chanlist_len;
devpriv->forever = false;
-   break;
-   case TRIG_NONE:
+   } else {/* TRIG_NONE */
devpriv->forever = true;
devpriv->count = 0;
-   break;
-   default:
-   break;
}
 
/* enable auto channel scan, send interrupts on end of conversion
@@ -440,19 +435,13 @@ static int das800_ai_do_cmd(struct comedi_device *dev,
conv_bits |= EACS | IEOC;
if (async->cmd.start_src == TRIG_EXT)
conv_bits |= DTEN;
-   switch (async->cmd.convert_src) {
-   case TRIG_TIMER:
+   if (async->cmd.convert_src == TRIG_TIMER) {
conv_bits |= CASC | ITE;
/* set conversion frequency */
if (das800_set_frequency(dev) < 0) {
comedi_error(dev, "Error setting up counters");
return -1;
}
-   break;
-   case TRIG_EXT:
-   break;
-   default:
-   break;
}
 
spin_lock_irqsave(&dev->spinlock, irq_flags);
-- 
1.8.5.2

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


[PATCH 2/9] staging: comedi: usbduxfast: remove TRIG_TIMER from scan_begin_src

2014-02-10 Thread H Hartley Sweeten
Currently the (*do_cmdtest) indicates that TRIG_TIMER is a valid scan_begin_src
but later this source is tested as -EINVAL. To simplify the code a bit just
remove the TRIG_TIMER source.

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

diff --git a/drivers/staging/comedi/drivers/usbduxfast.c 
b/drivers/staging/comedi/drivers/usbduxfast.c
index 4a927e4..d6fae11 100644
--- a/drivers/staging/comedi/drivers/usbduxfast.c
+++ b/drivers/staging/comedi/drivers/usbduxfast.c
@@ -372,7 +372,7 @@ static int usbduxfast_ai_cmdtest(struct comedi_device *dev,
err |= cfc_check_trigger_src(&cmd->start_src,
TRIG_NOW | TRIG_EXT | TRIG_INT);
err |= cfc_check_trigger_src(&cmd->scan_begin_src,
-   TRIG_TIMER | TRIG_FOLLOW | TRIG_EXT);
+   TRIG_FOLLOW | TRIG_EXT);
err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_TIMER | TRIG_EXT);
err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
@@ -424,9 +424,6 @@ static int usbduxfast_ai_cmdtest(struct comedi_device *dev,
err |= cfc_check_trigger_arg_is(&cmd->convert_arg, tmp);
}
 
-   if (cmd->scan_begin_src == TRIG_TIMER)
-   err |= -EINVAL;
-
/* stop source */
switch (cmd->stop_src) {
case TRIG_COUNT:
@@ -536,12 +533,6 @@ static int usbduxfast_ai_cmd(struct comedi_device *dev,
}
}
steps = 0;
-   if (cmd->scan_begin_src == TRIG_TIMER) {
-   dev_err(dev->class_dev,
-   "scan_begin_src==TRIG_TIMER not valid\n");
-   up(&devpriv->sem);
-   return -EINVAL;
-   }
if (cmd->convert_src == TRIG_TIMER)
steps = (cmd->convert_arg * 30) / 1000;
 
-- 
1.8.5.2

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


[PATCH 8/9] staging: comedi: pcl812: trigger sources were validated in (*do_cmdtest)

2014-02-10 Thread H Hartley Sweeten
The trigger sources were already validataed in the (*do_cmdtest) before the
(*do_cmd) is called. Remove the unnecessary checks in pcl812_ai_cmd().

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

diff --git a/drivers/staging/comedi/drivers/pcl812.c 
b/drivers/staging/comedi/drivers/pcl812.c
index feb9e98..095b325 100644
--- a/drivers/staging/comedi/drivers/pcl812.c
+++ b/drivers/staging/comedi/drivers/pcl812.c
@@ -631,24 +631,6 @@ static int pcl812_ai_cmd(struct comedi_device *dev, struct 
comedi_subdevice *s)
unsigned int divisor1 = 0, divisor2 = 0, i, dma_flags, bytes;
struct comedi_cmd *cmd = &s->async->cmd;
 
-   if (cmd->start_src != TRIG_NOW)
-   return -EINVAL;
-   if (cmd->scan_begin_src != TRIG_FOLLOW)
-   return -EINVAL;
-   if (devpriv->use_ext_trg) {
-   if (cmd->convert_src != TRIG_EXT)
-   return -EINVAL;
-   } else {
-   if (cmd->convert_src != TRIG_TIMER)
-   return -EINVAL;
-   }
-   if (cmd->scan_end_src != TRIG_COUNT)
-   return -EINVAL;
-   if (cmd->scan_end_arg != cmd->chanlist_len)
-   return -EINVAL;
-   if (cmd->chanlist_len > MAX_CHANLIST_LEN)
-   return -EINVAL;
-
if (cmd->convert_src == TRIG_TIMER) {
if (cmd->convert_arg < board->ai_ns_min)
cmd->convert_arg = board->ai_ns_min;
-- 
1.8.5.2

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


[PATCH 0/9] staging: comedi: remove some async command cruft

2014-02-10 Thread H Hartley Sweeten
The comedi core always calls the subdevice (*do_cmdtest) to validata the
async command before it calls the (*do_cmd) to actually execute the command.

Since the (*do_cmdtest) has already validataed the command, any duplicate
tests in the (*do_cmd) are unnecessary. Remove them.

Also, the cb_das16_cs driver has a (*do_cmdtest) but it's (*do_cmd) just
returns -EINVAL and the interrupt handler does nothing. Remove the async
command support from this driver.

H Hartley Sweeten (9):
  staging: comedi: usbduxfast: 'cmd->chanlist_len' was already validataed
  staging: comedi: usbduxfast: remove TRIG_TIMER from scan_begin_src
  staging: comedi: adl_pci9111: trigger sources are validated in (*do_cmdtest)
  staging: comedi: cb_das16_cs: remove incomplete async command support
  staging: comedi: cb_pcidas: trigger sources are validated in (*do_cmdtest)
  staging: comedi: comedi_test: trigger sources are validated in (*do_cmdtest)
  staging: comedi: das800: trigger sources are validated in (*do_cmdtest)
  staging: comedi: pcl812: trigger sources were validated in (*do_cmdtest)
  staging: comedi: pcl816: trigger sources were validated in (*do_cmdtest)

 drivers/staging/comedi/drivers/adl_pci9111.c |  28 +-
 drivers/staging/comedi/drivers/cb_das16_cs.c | 124 ---
 drivers/staging/comedi/drivers/cb_pcidas.c   |   7 +-
 drivers/staging/comedi/drivers/comedi_test.c |   6 +-
 drivers/staging/comedi/drivers/das800.c  |  17 +---
 drivers/staging/comedi/drivers/pcl812.c  |  18 
 drivers/staging/comedi/drivers/pcl816.c  |   9 --
 drivers/staging/comedi/drivers/usbduxfast.c  |  51 +--
 8 files changed, 30 insertions(+), 230 deletions(-)

-- 
1.8.5.2

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


Re: [RFC PATCH 2/3] staging: imx-drm-core: Use graph to find connection between crtc and encoder

2014-02-10 Thread Philipp Zabel
On Mon, Feb 10, 2014 at 04:26:31PM +, Russell King - ARM Linux wrote:
[...]
> Why is this loop soo complicated?  Why do you need to mess around with
> this "last_ep" stuff - you don't actually end up using it.

The last_ep dance is necessary because v4l2_of_get_next_endpoint(node,prev)
does not decrement the reference count of its prev argument.
To make the loop as simple as you propose, I'd either have to change
the get_next_endpoint library function or wrap it to release the prev
node:

static struct device_node *imx_drm_of_get_next_endpoint(
struct device_node *node, struct device_node *prev)
{
node = v4l2_of_get_next_endpoint(node, prev);
of_node_put(prev);
return node;
}
 
> The loop reduces down to this without comments:
> 
>   for (i = 0; !ret; i++) {
>   uint32_t mask;
> 
>   ep = v4l2_of_get_next_endpoint(np, last_ep);
>   if (!ep)
>   break;
> 
>   /* CSI */
>   mask = imx_drm_find_crtc_mask(imxdrm, ep);
>   of_node_put(ep);
> 
>   if (mask == 0)
>   return -EPROBE_DEFER;
> 
>   crtc_mask |= mask;
>   }

Yes, that is easier to read.

> Now, here's the big question: why do we want to use v4l2_* here?  We
> may want to use this functionality, but if this functionality is going
> to be used outside of v4l2, it needs to become something generic, not
> v4l2 specific.
> 
> Let's think about this for a moment... if we want to build imx-drm into
> the kernel, can we do it with modular videodev, or with videodev
> completely unconfigured.  We may wish to do this because we have no
> videodev requirement on a platform.  Should the build fail because the
> v4l2 function isn't there?
> 
> So, before we can change this, I think we first need to get agreement
> from Mauro to move this function out of V4L2, so that it can be
> available independently of V4L2.

Either that, or we add a temporary copy of the v4l2_of_get_next_endpoint
and v4l2_of_get_remote_port functions while doing the same.

regards
Philipp

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


RE: [PATCH] hyperv_fb: Add screen refresh after pause/resume operation

2014-02-10 Thread Haiyang Zhang


> -Original Message-
> From: Haiyang Zhang [mailto:haiya...@microsoft.com]
> Sent: Monday, January 13, 2014 7:21 PM
> To: florianschandi...@gmx.de; a...@linux-foundation.org; linux-
> fb...@vger.kernel.org
> Cc: Haiyang Zhang; KY Srinivasan; o...@aepfle.de; jasow...@redhat.com;
> linux-ker...@vger.kernel.org; driverdev-devel@linuxdriverproject.org
> Subject: [PATCH] hyperv_fb: Add screen refresh after pause/resume operation
> 
> This is necessary because after VM is pause/resumed, some portion of the
> screen may need refresh.
> 
> Signed-off-by: Haiyang Zhang 
> Reviewed-by: K. Y. Srinivasan 
> ---
This was submitted before the tree re-opened. Is it still being considered?

Thanks,
- Haiyang

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


Re: [PATCH] drivers:staging:silicom: Fixed MACRO, Extern, parentheses Coding style warnings and errors

2014-02-10 Thread Dan Carpenter
On Mon, Feb 10, 2014 at 12:18:42PM +0300, Dan Carpenter wrote:
> On Sun, Feb 09, 2014 at 07:05:24PM -0800, Surendra Patil wrote:
> > Fixed MACRO,Extern and parentheses Coding style warnings and errors - 
> > listed only few
> > bpctl_mod.c:120: WARNING: externs should be avoided in .c files
> > bpctl_mod.c:121: WARNING: externs should be avoided in .c files
> > bpctl_mod.c:122: WARNING: externs should be avoided in .c files
> > bpctl_mod.c:124: WARNING: externs should be avoided in .c files
> > bpctl_mod.c:125: WARNING: externs should be avoided in .c files
> > bp_ioctl.h:54: ERROR: Macros with complex values should be enclosed in 
> > parenthesis
> > bp_ioctl.h:159: ERROR: Macros with complex values should be enclosed in p 
> > arenthesis
> > bpctl_mod.c:1395: WARNING: Unnecessary parentheses - maybe == should be = ?
> > 
> 
> These don't seem to match the patch at all.

Oh.  The patch does match.  But it doesn't compile.  bp_proc_create()
is declared in the .h file.

regards,
dan carpenter

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


staging: sbe-2t3e3: Fix possible reuse of freed memory in timer function

2014-02-10 Thread Kirill Tkhai
Do not call kfree() till timer function is finished.

[This was found using grep. Compilation tested only]

Signed-off-by: Kirill Tkhai 
CC: Joe Perches 
CC: Greg Kroah-Hartman 
---
 drivers/staging/sbe-2t3e3/module.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/staging/sbe-2t3e3/module.c
b/drivers/staging/sbe-2t3e3/module.c
index 0e32be5..a6f93a4 100644
--- a/drivers/staging/sbe-2t3e3/module.c
+++ b/drivers/staging/sbe-2t3e3/module.c
@@ -122,7 +122,7 @@ static void t3e3_remove_card(struct pci_dev *pdev)
struct channel *channel0 = pci_get_drvdata(pdev);
struct card *card = channel0->card;

-   del_timer(&card->timer);
+   del_timer_sync(&card->timer);
if (has_two_ports(channel0->pdev)) {
t3e3_remove_channel(&card->channels[1]);
pci_dev_put(card->channels[1].pdev);
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 40/47 v2] staging: comedi: daqboard2000: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input pipe full, scanning,
amd end-of-conversion status. The status to check it passed as the
'context' to comedi_timeout().

Use comedi_timeout() to wait for the analog output end-of-conversion.

This also fixes a possible bug where invalid data is returned for the
analog input read if the conversion did not complete, The analog
output has a similar possible bug where the cached readback value is
incorrect if the conversion times out.

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

diff --git a/drivers/staging/comedi/drivers/daqboard2000.c 
b/drivers/staging/comedi/drivers/daqboard2000.c
index 6ff7d3e..a8f6036 100644
--- a/drivers/staging/comedi/drivers/daqboard2000.c
+++ b/drivers/staging/comedi/drivers/daqboard2000.c
@@ -333,14 +333,28 @@ static void setup_sampling(struct comedi_device *dev, int 
chan, int gain)
writeAcqScanListEntry(dev, word3);
 }
 
+static int daqboard2000_ai_status(struct comedi_device *dev,
+ struct comedi_subdevice *s,
+ struct comedi_insn *insn,
+ unsigned long context)
+{
+   struct daqboard2000_private *devpriv = dev->private;
+   unsigned int status;
+
+   status = readw(devpriv->daq + acqControl);
+   if (status & context)
+   return 0;
+   return -EBUSY;
+}
+
 static int daqboard2000_ai_insn_read(struct comedi_device *dev,
 struct comedi_subdevice *s,
 struct comedi_insn *insn,
 unsigned int *data)
 {
struct daqboard2000_private *devpriv = dev->private;
-   unsigned int val;
-   int gain, chan, timeout;
+   int gain, chan;
+   int ret;
int i;
 
writew(DAQBOARD2000_AcqResetScanListFifo |
@@ -367,25 +381,24 @@ static int daqboard2000_ai_insn_read(struct comedi_device 
*dev,
/* Enable reading from the scanlist FIFO */
writew(DAQBOARD2000_SeqStartScanList,
   devpriv->daq + acqControl);
-   for (timeout = 0; timeout < 20; timeout++) {
-   val = readw(devpriv->daq + acqControl);
-   if (val & DAQBOARD2000_AcqConfigPipeFull)
-   break;
-   /* udelay(2); */
-   }
+
+   ret = comedi_timeout(dev, s, insn, daqboard2000_ai_status,
+DAQBOARD2000_AcqConfigPipeFull);
+   if (ret)
+   return ret;
+
writew(DAQBOARD2000_AdcPacerEnable, devpriv->daq + acqControl);
-   for (timeout = 0; timeout < 20; timeout++) {
-   val = readw(devpriv->daq + acqControl);
-   if (val & DAQBOARD2000_AcqLogicScanning)
-   break;
-   /* udelay(2); */
-   }
-   for (timeout = 0; timeout < 20; timeout++) {
-   val = readw(devpriv->daq + acqControl);
-   if (val & DAQBOARD2000_AcqResultsFIFOHasValidData)
-   break;
-   /* udelay(2); */
-   }
+
+   ret = comedi_timeout(dev, s, insn, daqboard2000_ai_status,
+DAQBOARD2000_AcqLogicScanning);
+   if (ret)
+   return ret;
+
+   ret = comedi_timeout(dev, s, insn, daqboard2000_ai_status,
+DAQBOARD2000_AcqResultsFIFOHasValidData);
+   if (ret)
+   return ret;
+
data[i] = readw(devpriv->daq + acqResultsFIFO);
writew(DAQBOARD2000_AdcPacerDisable, devpriv->daq + acqControl);
writew(DAQBOARD2000_SeqStopScanList, devpriv->daq + acqControl);
@@ -409,6 +422,21 @@ static int daqboard2000_ao_insn_read(struct comedi_device 
*dev,
return i;
 }
 
+static int daqboard2000_ao_eoc(struct comedi_device *dev,
+  struct comedi_subdevice *s,
+  struct comedi_insn *insn,
+  unsigned long context)
+{
+   struct daqboard2000_private *devpriv = dev->private;
+   unsigned int chan = CR_CHAN(insn->chanspec);
+   unsigned int status;
+
+   status = readw(devpriv->daq + dacControl);
+   if ((status & ((chan + 1) * 0x0010)) == 0)
+   return 0;
+   return -EBUSY;
+}
+
 static int daqboard2000_ao_insn_write(struct comedi_device *dev,
  struct comedi_subdevice *s,
  struct comedi_insn *insn,
@@ -416,8 +444,7 @@ static int daqboard2000_ao_insn_write

[PATCH 39/47 v2] staging: comedi: dt282x: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
The wait_for() macro in this driver is a bit nasty. It effects control flow
which according to the CodingStyle is a _very_ bad idea.

The mux_busy() and ad_done() macros are also bad since they rely on a local
variable having a specific name.

Remove these macros and use comedi_timeout() to wait for the analog input
mux busy completion and end-of-conversion. Both of these are detected by
reading the same register and testing different bits. Pass the bits to test
as the 'context' to the callback function.

The dt282x_ai_cmd() function also checks for the mux busy completion. The
'insn' is not available here but passing NULL is safe because nothing
uses it.

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

diff --git a/drivers/staging/comedi/drivers/dt282x.c 
b/drivers/staging/comedi/drivers/dt282x.c
index 895f73a..f768210 100644
--- a/drivers/staging/comedi/drivers/dt282x.c
+++ b/drivers/staging/comedi/drivers/dt282x.c
@@ -63,7 +63,6 @@ Notes:
 
 #include "comedi_fc.h"
 
-#define DT2821_TIMEOUT 100 /* 500 us */
 #define DT2821_SIZE 0x10
 
 /*
@@ -248,27 +247,6 @@ struct dt282x_private {
  *Some useless abstractions
  */
 #define chan_to_DAC(a) ((a)&1)
-#define mux_busy() (inw(dev->iobase+DT2821_ADCSR)&DT2821_MUXBUSY)
-#define ad_done() (inw(dev->iobase+DT2821_ADCSR)&DT2821_ADDONE)
-
-/*
- *danger! macro abuse... a is the expression to wait on, and b is
- *  the statement(s) to execute if it doesn't happen.
- */
-#define wait_for(a, b) \
-   do {\
-   int _i; \
-   for (_i = 0; _i < DT2821_TIMEOUT; _i++) {   \
-   if (a) {\
-   _i = 0; \
-   break;  \
-   }   \
-   udelay(5);  \
-   }   \
-   if (_i) {   \
-   b   \
-   }   \
-   } while (0)
 
 static int prep_ai_dma(struct comedi_device *dev, int chan, int size);
 static int prep_ao_dma(struct comedi_device *dev, int chan, int size);
@@ -530,6 +508,29 @@ static void dt282x_load_changain(struct comedi_device 
*dev, int n,
outw(n - 1, dev->iobase + DT2821_CHANCSR);
 }
 
+static int dt282x_ai_timeout(struct comedi_device *dev,
+struct comedi_subdevice *s,
+struct comedi_insn *insn,
+unsigned long context)
+{
+   unsigned int status;
+
+   status = inw(dev->iobase + DT2821_ADCSR);
+   switch (context) {
+   case DT2821_MUXBUSY:
+   if ((status & DT2821_MUXBUSY) == 0)
+   return 0;
+   break;
+   case DT2821_ADDONE:
+   if (status & DT2821_ADDONE)
+   return 0;
+   break;
+   default:
+   return -EINVAL;
+   }
+   return -EBUSY;
+}
+
 /*
  *Performs a single A/D conversion.
  *  - Put channel/gain into channel-gain list
@@ -542,6 +543,7 @@ static int dt282x_ai_insn_read(struct comedi_device *dev,
 {
const struct dt282x_board *board = comedi_board(dev);
struct dt282x_private *devpriv = dev->private;
+   int ret;
int i;
 
/* XXX should we really be enabling the ad clock here? */
@@ -551,13 +553,22 @@ static int dt282x_ai_insn_read(struct comedi_device *dev,
dt282x_load_changain(dev, 1, &insn->chanspec);
 
outw(devpriv->supcsr | DT2821_PRLD, dev->iobase + DT2821_SUPCSR);
-   wait_for(!mux_busy(), comedi_error(dev, "timeout\n"); return -ETIME;);
+   ret = comedi_timeout(dev, s, insn, dt282x_ai_timeout, DT2821_MUXBUSY);
+   if (ret) {
+   comedi_error(dev, "timeout\n");
+   return ret;
+   }
 
for (i = 0; i < insn->n; i++) {
outw(devpriv->supcsr | DT2821_STRIG,
dev->iobase + DT2821_SUPCSR);
-   wait_for(ad_done(), comedi_error(dev, "timeout\n");
-return -ETIME;);
+
+   ret = comedi_timeout(dev, s, insn, dt282x_ai_timeout,
+DT2821_ADDONE);
+   if (ret) {
+   comedi_error(dev, "timeout\n");
+   return ret;
+   }
 
data[i] =
inw(dev->iobase +
@@ -646,6 +657,7 @@ static int dt282x_ai_cmd(struct comedi_device *dev

[PATCH 27/47 v2] staging: comedi: ni_atmio16d: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input end-of-conversion.

Change the errno returned when the conversion overflows from -ETIME
to -EOVERFLOW.

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

diff --git a/drivers/staging/comedi/drivers/ni_atmio16d.c 
b/drivers/staging/comedi/drivers/ni_atmio16d.c
index 4f26aa9..4262385 100644
--- a/drivers/staging/comedi/drivers/ni_atmio16d.c
+++ b/drivers/staging/comedi/drivers/ni_atmio16d.c
@@ -96,7 +96,6 @@ Devices: [National Instruments] AT-MIO-16 (atmio16), 
AT-MIO-16D (atmio16d)
 #define CLOCK_100_HZ   0x8F25
 /* Other miscellaneous defines */
 #define ATMIO16D_SIZE  32  /* bus address range */
-#define ATMIO16D_TIMEOUT 10
 
 struct atmio16_board_t {
 
@@ -448,16 +447,32 @@ static int atmio16d_ai_cancel(struct comedi_device *dev,
return 0;
 }
 
-/* Mode 0 is used to get a single conversion on demand */
+static int atmio16d_ai_eoc(struct comedi_device *dev,
+  struct comedi_subdevice *s,
+  struct comedi_insn *insn,
+  unsigned long context)
+{
+   unsigned int status;
+
+   status = inw(dev->iobase + STAT_REG);
+   if (status & STAT_AD_CONVAVAIL)
+   return 0;
+   if (status & STAT_AD_OVERFLOW) {
+   outw(0, dev->iobase + AD_CLEAR_REG);
+   return -EOVERFLOW;
+   }
+   return -EBUSY;
+}
+
 static int atmio16d_ai_insn_read(struct comedi_device *dev,
 struct comedi_subdevice *s,
 struct comedi_insn *insn, unsigned int *data)
 {
struct atmio16d_private *devpriv = dev->private;
-   int i, t;
+   int i;
int chan;
int gain;
-   int status;
+   int ret;
 
chan = CR_CHAN(insn->chanspec);
gain = CR_RANGE(insn->chanspec);
@@ -473,26 +488,17 @@ static int atmio16d_ai_insn_read(struct comedi_device 
*dev,
for (i = 0; i < insn->n; i++) {
/* start the conversion */
outw(0, dev->iobase + START_CONVERT_REG);
+
/* wait for it to finish */
-   for (t = 0; t < ATMIO16D_TIMEOUT; t++) {
-   /* check conversion status */
-   status = inw(dev->iobase + STAT_REG);
-   if (status & STAT_AD_CONVAVAIL) {
-   /* read the data now */
-   data[i] = inw(dev->iobase + AD_FIFO_REG);
-   /* change to two's complement if need be */
-   if (devpriv->adc_coding == adc_2comp)
-   data[i] ^= 0x800;
-   break;
-   }
-   if (status & STAT_AD_OVERFLOW) {
-   outw(0, dev->iobase + AD_CLEAR_REG);
-   return -ETIME;
-   }
-   }
-   /* end waiting, now check if it timed out */
-   if (t == ATMIO16D_TIMEOUT)
-   return -ETIME;
+   ret = comedi_timeout(dev, s, insn, atmio16d_ai_eoc, 0);
+   if (ret)
+   return ret;
+
+   /* read the data now */
+   data[i] = inw(dev->iobase + AD_FIFO_REG);
+   /* change to two's complement if need be */
+   if (devpriv->adc_coding == adc_2comp)
+   data[i] ^= 0x800;
}
 
return i;
-- 
1.8.5.2

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


[PATCH 42/47 v2] staging: comedi: pcl816: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input end-of-conversion.

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

diff --git a/drivers/staging/comedi/drivers/pcl816.c 
b/drivers/staging/comedi/drivers/pcl816.c
index e9d4704..db00d07 100644
--- a/drivers/staging/comedi/drivers/pcl816.c
+++ b/drivers/staging/comedi/drivers/pcl816.c
@@ -160,16 +160,25 @@ static int pcl816_ai_cmdtest(struct comedi_device *dev,
 struct comedi_cmd *cmd);
 static int pcl816_ai_cmd(struct comedi_device *dev, struct comedi_subdevice 
*s);
 
-/*
-==
-   ANALOG INPUT MODE0, 816 cards, slow version
-*/
+static int pcl816_ai_eoc(struct comedi_device *dev,
+struct comedi_subdevice *s,
+struct comedi_insn *insn,
+unsigned long context)
+{
+   unsigned int status;
+
+   status = inb(dev->iobase + PCL816_STATUS);
+   if ((status & PCL816_STATUS_DRDY_MASK) == 0)
+   return 0;
+   return -EBUSY;
+}
+
 static int pcl816_ai_insn_read(struct comedi_device *dev,
   struct comedi_subdevice *s,
   struct comedi_insn *insn, unsigned int *data)
 {
+   int ret;
int n;
-   int timeout;
 
/*  software trigger, DMA and INT off */
outb(0, dev->iobase + PCL816_CONTROL);
@@ -185,30 +194,20 @@ static int pcl816_ai_insn_read(struct comedi_device *dev,
 
outb(0, dev->iobase + PCL816_AD_LO);/* start conversion */
 
-   timeout = 100;
-   while (timeout--) {
-   if (!(inb(dev->iobase + PCL816_STATUS) &
- PCL816_STATUS_DRDY_MASK)) {
-   /*  return read value */
-   data[n] =
-   ((inb(dev->iobase +
- PCL816_AD_HI) << 8) |
-(inb(dev->iobase + PCL816_AD_LO)));
-   /* clear INT (conversion end) flag */
-   outb(0, dev->iobase + PCL816_CLRINT);
-   break;
-   }
-   udelay(1);
-   }
-   /*  Return timeout error */
-   if (!timeout) {
+   ret = comedi_timeout(dev, s, insn, pcl816_ai_eoc, 0);
+   if (ret) {
comedi_error(dev, "A/D insn timeout\n");
data[0] = 0;
/* clear INT (conversion end) flag */
outb(0, dev->iobase + PCL816_CLRINT);
-   return -EIO;
+   return ret;
}
 
+   /*  return read value */
+   data[n] = ((inb(dev->iobase + PCL816_AD_HI) << 8) |
+ (inb(dev->iobase + PCL816_AD_LO)));
+   /* clear INT (conversion end) flag */
+   outb(0, dev->iobase + PCL816_CLRINT);
}
return n;
 }
-- 
1.8.5.2

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


[PATCH 43/47 v2] staging: comedi: pcl818: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input end-of-conversion.

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

diff --git a/drivers/staging/comedi/drivers/pcl818.c 
b/drivers/staging/comedi/drivers/pcl818.c
index fa1758a..ff5cc1b 100644
--- a/drivers/staging/comedi/drivers/pcl818.c
+++ b/drivers/staging/comedi/drivers/pcl818.c
@@ -336,16 +336,25 @@ static int pcl818_ai_cancel(struct comedi_device *dev,
 static void start_pacer(struct comedi_device *dev, int mode,
unsigned int divisor1, unsigned int divisor2);
 
-/*
-==
-   ANALOG INPUT MODE0, 818 cards, slow version
-*/
+static int pcl818_ai_eoc(struct comedi_device *dev,
+struct comedi_subdevice *s,
+struct comedi_insn *insn,
+unsigned long context)
+{
+   unsigned int status;
+
+   status = inb(dev->iobase + PCL818_STATUS);
+   if (status & 0x10)
+   return 0;
+   return -EBUSY;
+}
+
 static int pcl818_ai_insn_read(struct comedi_device *dev,
   struct comedi_subdevice *s,
   struct comedi_insn *insn, unsigned int *data)
 {
+   int ret;
int n;
-   int timeout;
 
/* software trigger, DMA and INT off */
outb(0, dev->iobase + PCL818_CONTROL);
@@ -364,18 +373,14 @@ static int pcl818_ai_insn_read(struct comedi_device *dev,
/* start conversion */
outb(0, dev->iobase + PCL818_AD_LO);
 
-   timeout = 100;
-   while (timeout--) {
-   if (inb(dev->iobase + PCL818_STATUS) & 0x10)
-   goto conv_finish;
-   udelay(1);
+   ret = comedi_timeout(dev, s, insn, pcl818_ai_eoc, 0);
+   if (ret) {
+   comedi_error(dev, "A/D insn timeout");
+   /* clear INT (conversion end) flag */
+   outb(0, dev->iobase + PCL818_CLRINT);
+   return ret;
}
-   comedi_error(dev, "A/D insn timeout");
-   /* clear INT (conversion end) flag */
-   outb(0, dev->iobase + PCL818_CLRINT);
-   return -EIO;
 
-conv_finish:
data[n] = ((inb(dev->iobase + PCL818_AD_HI) << 4) |
   (inb(dev->iobase + PCL818_AD_LO) >> 4));
}
-- 
1.8.5.2

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


[PATCH 45/47 v2] staging: comedi: dmm32at: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input settle and end-of-
conversion. These tests use different registers but the same bit so
the register is passed as the 'context'. The same test is used in
dmm32at_ai_cmd() but the 'insn' is not available. This is ok since
the test function, and comedi_timeout() don't use it.

Use comedi_timout() to wait for the analog output end-of-conversion.

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

diff --git a/drivers/staging/comedi/drivers/dmm32at.c 
b/drivers/staging/comedi/drivers/dmm32at.c
index 78a1962..c8a36eb 100644
--- a/drivers/staging/comedi/drivers/dmm32at.c
+++ b/drivers/staging/comedi/drivers/dmm32at.c
@@ -164,16 +164,29 @@ struct dmm32at_private {
 
 };
 
+static int dmm32at_ai_status(struct comedi_device *dev,
+struct comedi_subdevice *s,
+struct comedi_insn *insn,
+unsigned long context)
+{
+   unsigned char status;
+
+   status = inb(dev->iobase + context);
+   if ((status & DMM32AT_STATUS) == 0)
+   return 0;
+   return -EBUSY;
+}
+
 static int dmm32at_ai_rinsn(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
 {
-   int n, i;
+   int n;
unsigned int d;
-   unsigned char status;
unsigned short msb, lsb;
unsigned char chan;
int range;
+   int ret;
 
/* get the channel and range number */
 
@@ -190,26 +203,20 @@ static int dmm32at_ai_rinsn(struct comedi_device *dev,
outb(dmm32at_rangebits[range], dev->iobase + DMM32AT_AICONF);
 
/* wait for circuit to settle */
-   for (i = 0; i < 4; i++) {
-   status = inb(dev->iobase + DMM32AT_AIRBACK);
-   if ((status & DMM32AT_STATUS) == 0)
-   break;
-   }
-   if (i == 4)
-   return -ETIMEDOUT;
+   ret = comedi_timeout(dev, s, insn, dmm32at_ai_status, DMM32AT_AIRBACK);
+   if (ret)
+   return ret;
 
/* convert n samples */
for (n = 0; n < insn->n; n++) {
/* trigger conversion */
outb(0xff, dev->iobase + DMM32AT_CONV);
+
/* wait for conversion to end */
-   for (i = 0; i < 4; i++) {
-   status = inb(dev->iobase + DMM32AT_AISTAT);
-   if ((status & DMM32AT_STATUS) == 0)
-   break;
-   }
-   if (i == 4)
-   return -ETIMEDOUT;
+   ret = comedi_timeout(dev, s, insn, dmm32at_ai_status,
+DMM32AT_AISTAT);
+   if (ret)
+   return ret;
 
/* read data */
lsb = inb(dev->iobase + DMM32AT_AILSB);
@@ -403,8 +410,9 @@ static int dmm32at_ai_cmd(struct comedi_device *dev, struct 
comedi_subdevice *s)
 {
struct dmm32at_private *devpriv = dev->private;
struct comedi_cmd *cmd = &s->async->cmd;
-   int i, range;
-   unsigned char chanlo, chanhi, status;
+   int range;
+   unsigned char chanlo, chanhi;
+   int ret;
 
if (!cmd->chanlist)
return -EINVAL;
@@ -439,14 +447,13 @@ static int dmm32at_ai_cmd(struct comedi_device *dev, 
struct comedi_subdevice *s)
  * isr */
}
 
-   /* wait for circuit to settle */
-   for (i = 0; i < 4; i++) {
-   status = inb(dev->iobase + DMM32AT_AIRBACK);
-   if ((status & DMM32AT_STATUS) == 0)
-   break;
-   }
-   if (i == 4)
-   return -ETIMEDOUT;
+   /*
+* wait for circuit to settle
+* we don't have the 'insn' here but it's not needed
+*/
+   ret = comedi_timeout(dev, s, NULL, dmm32at_ai_status, DMM32AT_AIRBACK);
+   if (ret)
+   return ret;
 
if (devpriv->ai_scans_left > 1) {
/* start the clock and enable the interrupts */
@@ -525,6 +532,19 @@ static irqreturn_t dmm32at_isr(int irq, void *d)
return IRQ_HANDLED;
 }
 
+static int dmm32at_ao_eoc(struct comedi_device *dev,
+ struct comedi_subdevice *s,
+ struct comedi_insn *insn,
+ unsigned long context)
+{
+   unsigned char status;
+
+   status = inb(dev->iobase + DMM32AT_DACSTAT);
+   if ((status & DMM32AT_DACBUSY) == 0)
+   return 0;
+   return -EBUSY;
+}
+
 static int dmm32at_ao_winsn(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)

[PATCH 32/47 v2] staging: comedi: amplc_pci230: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input end-of-conversion.

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

diff --git a/drivers/staging/comedi/drivers/amplc_pci230.c 
b/drivers/staging/comedi/drivers/amplc_pci230.c
index 7356fee..b606bdb 100644
--- a/drivers/staging/comedi/drivers/amplc_pci230.c
+++ b/drivers/staging/comedi/drivers/amplc_pci230.c
@@ -799,19 +799,29 @@ static void pci230_cancel_ct(struct comedi_device *dev, 
unsigned int ct)
/* Counter ct, 8254 mode 1, initial count not written. */
 }
 
-/*
- *  COMEDI_SUBD_AI instruction;
- */
+static int pci230_ai_eoc(struct comedi_device *dev,
+struct comedi_subdevice *s,
+struct comedi_insn *insn,
+unsigned long context)
+{
+   unsigned int status;
+
+   status = inw(dev->iobase + PCI230_ADCCON);
+   if ((status & PCI230_ADC_FIFO_EMPTY) == 0)
+   return 0;
+   return -EBUSY;
+}
+
 static int pci230_ai_rinsn(struct comedi_device *dev,
   struct comedi_subdevice *s, struct comedi_insn *insn,
   unsigned int *data)
 {
struct pci230_private *devpriv = dev->private;
-   unsigned int n, i;
+   unsigned int n;
unsigned int chan, range, aref;
unsigned int gainshift;
-   unsigned int status;
unsigned short adccon, adcen;
+   int ret;
 
/* Unpack channel and range. */
chan = CR_CHAN(insn->chanspec);
@@ -883,17 +893,11 @@ static int pci230_ai_rinsn(struct comedi_device *dev,
i8254_set_mode(devpriv->iobase1 + PCI230_Z2_CT_BASE, 0, 2,
   I8254_MODE1);
 
-#define TIMEOUT 100
/* wait for conversion to end */
-   for (i = 0; i < TIMEOUT; i++) {
-   status = inw(dev->iobase + PCI230_ADCCON);
-   if (!(status & PCI230_ADC_FIFO_EMPTY))
-   break;
-   udelay(1);
-   }
-   if (i == TIMEOUT) {
+   ret = comedi_timeout(dev, s, insn, pci230_ai_eoc, 0);
+   if (ret) {
dev_err(dev->class_dev, "timeout\n");
-   return -ETIMEDOUT;
+   return ret;
}
 
/* read data */
-- 
1.8.5.2

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


[PATCH 18/47 v2] staging: comedi: cb_pcimdas: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input end-of-conversion.

Remove the unnecessary comments.

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

diff --git a/drivers/staging/comedi/drivers/cb_pcimdas.c 
b/drivers/staging/comedi/drivers/cb_pcimdas.c
index 3e39cb5..d3141c8 100644
--- a/drivers/staging/comedi/drivers/cb_pcimdas.c
+++ b/drivers/staging/comedi/drivers/cb_pcimdas.c
@@ -85,21 +85,31 @@ struct cb_pcimdas_private {
unsigned int ao_readback[2];
 };
 
-/*
- * "instructions" read/write data in "one-shot" or "software-triggered"
- * mode.
- */
+static int cb_pcimdas_ai_eoc(struct comedi_device *dev,
+struct comedi_subdevice *s,
+struct comedi_insn *insn,
+unsigned long context)
+{
+   struct cb_pcimdas_private *devpriv = dev->private;
+   unsigned int status;
+
+   status = inb(devpriv->BADR3 + 2);
+   if ((status & 0x80) == 0)
+   return 0;
+   return -EBUSY;
+}
+
 static int cb_pcimdas_ai_rinsn(struct comedi_device *dev,
   struct comedi_subdevice *s,
   struct comedi_insn *insn, unsigned int *data)
 {
struct cb_pcimdas_private *devpriv = dev->private;
-   int n, i;
+   int n;
unsigned int d;
-   unsigned int busy;
int chan = CR_CHAN(insn->chanspec);
unsigned short chanlims;
int maxchans;
+   int ret;
 
/*  only support sw initiated reads from a single channel */
 
@@ -133,17 +143,10 @@ static int cb_pcimdas_ai_rinsn(struct comedi_device *dev,
/* trigger conversion */
outw(0, dev->iobase + 0);
 
-#define TIMEOUT 1000   /* typically takes 5 loops on a lightly loaded 
Pentium 100MHz, */
-   /* this is likely to be 100 loops on a 2GHz machine, so set 
1000 as the limit. */
-
/* wait for conversion to end */
-   for (i = 0; i < TIMEOUT; i++) {
-   busy = inb(devpriv->BADR3 + 2) & 0x80;
-   if (!busy)
-   break;
-   }
-   if (i == TIMEOUT)
-   return -ETIMEDOUT;
+   ret = comedi_timeout(dev, s, insn, cb_pcimdas_ai_eoc, 0);
+   if (ret)
+   return ret;
 
/* read data */
data[n] = inw(dev->iobase + 0);
-- 
1.8.5.2

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


[PATCH 37/47 v2] staging: comedi: rtd520: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input and output end-of-
conversions.

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

diff --git a/drivers/staging/comedi/drivers/rtd520.c 
b/drivers/staging/comedi/drivers/rtd520.c
index 0e83e7e..cd3fdf9 100644
--- a/drivers/staging/comedi/drivers/rtd520.c
+++ b/drivers/staging/comedi/drivers/rtd520.c
@@ -237,20 +237,6 @@
 /* The board support a channel list up to the FIFO length (1K or 8K) */
 #define RTD_MAX_CHANLIST   128 /* max channel list that we allow */
 
-/* tuning for ai/ao instruction done polling */
-#ifdef FAST_SPIN
-#define WAIT_QUIETLY   /* as nothing, spin on done bit */
-#define RTD_ADC_TIMEOUT66000   /* 2 msec at 33mhz bus rate */
-#define RTD_DAC_TIMEOUT66000
-#define RTD_DMA_TIMEOUT33000   /* 1 msec */
-#else
-/* by delaying, power and electrical noise are reduced somewhat */
-#define WAIT_QUIETLY   udelay(1)
-#define RTD_ADC_TIMEOUT2000/* in usec */
-#define RTD_DAC_TIMEOUT2000/* in usec */
-#define RTD_DMA_TIMEOUT1000/* in usec */
-#endif
-
 /*==
   Board specific stuff
 ==*/
@@ -562,21 +548,27 @@ static int rtd520_probe_fifo_depth(struct comedi_device 
*dev)
return fifo_size;
 }
 
-/*
-  "instructions" read/write data in "one-shot" or "software-triggered"
-  mode (simplest case).
-  This doesn't use interrupts.
+static int rtd_ai_eoc(struct comedi_device *dev,
+ struct comedi_subdevice *s,
+ struct comedi_insn *insn,
+ unsigned long context)
+{
+   struct rtd_private *devpriv = dev->private;
+   unsigned int status;
+
+   status = readl(devpriv->las0 + LAS0_ADC);
+   if (status & FS_ADC_NOT_EMPTY)
+   return 0;
+   return -EBUSY;
+}
 
-  Note, we don't do any settling delays.  Use a instruction list to
-  select, delay, then read.
- */
 static int rtd_ai_rinsn(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_insn *insn,
unsigned int *data)
 {
struct rtd_private *devpriv = dev->private;
-   int n, ii;
-   int stat;
+   int ret;
+   int n;
 
/* clear any old fifo data */
writel(0, devpriv->las0 + LAS0_ADC_FIFO_CLEAR);
@@ -593,14 +585,9 @@ static int rtd_ai_rinsn(struct comedi_device *dev,
/* trigger conversion */
writew(0, devpriv->las0 + LAS0_ADC);
 
-   for (ii = 0; ii < RTD_ADC_TIMEOUT; ++ii) {
-   stat = readl(devpriv->las0 + LAS0_ADC);
-   if (stat & FS_ADC_NOT_EMPTY)/* 1 -> not empty */
-   break;
-   WAIT_QUIETLY;
-   }
-   if (ii >= RTD_ADC_TIMEOUT)
-   return -ETIMEDOUT;
+   ret = comedi_timeout(dev, s, insn, rtd_ai_eoc, 0);
+   if (ret)
+   return ret;
 
/* read data */
d = readw(devpriv->las1 + LAS1_ADC_FIFO);
@@ -1116,9 +1103,22 @@ static int rtd_ai_cancel(struct comedi_device *dev, 
struct comedi_subdevice *s)
return 0;
 }
 
-/*
-  Output one (or more) analog values to a single port as fast as possible.
-*/
+static int rtd_ao_eoc(struct comedi_device *dev,
+ struct comedi_subdevice *s,
+ struct comedi_insn *insn,
+ unsigned long context)
+{
+   struct rtd_private *devpriv = dev->private;
+   unsigned int chan = CR_CHAN(insn->chanspec);
+   unsigned int bit = (chan == 0) ? FS_DAC1_NOT_EMPTY : FS_DAC2_NOT_EMPTY;
+   unsigned int status;
+
+   status = readl(devpriv->las0 + LAS0_ADC);
+   if (status & bit)
+   return 0;
+   return -EBUSY;
+}
+
 static int rtd_ao_winsn(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_insn *insn,
unsigned int *data)
@@ -1127,6 +1127,7 @@ static int rtd_ao_winsn(struct comedi_device *dev,
int i;
int chan = CR_CHAN(insn->chanspec);
int range = CR_RANGE(insn->chanspec);
+   int ret;
 
/* Configure the output range (table index matches the range values) */
writew(range & 7, devpriv->las0 +
@@ -1136,8 +1137,6 @@ static int rtd_ao_winsn(struct comedi_device *dev,
 * very useful, but that's how the interface is defined. */
for (i = 0; i < insn->n; ++i) {
int val = data[i] << 3;
-   int stat = 0;   /* initialize to avoid bogus warning */
-   int ii;
 
/* VERIFY: comedi range and offset conversions *

[PATCH 46/47 v2] staging: comedi: move (*insn_{read, write}) timeout debug messages to core

2014-02-10 Thread H Hartley Sweeten
Have the comedi core display a standard dev_dbg() message when a timeout
occurs and remove all the driver specific messages.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/comedi_fops.c  | 13 -
 drivers/staging/comedi/drivers/adl_pci9111.c  |  1 -
 drivers/staging/comedi/drivers/adl_pci9118.c  |  1 -
 drivers/staging/comedi/drivers/adv_pci1710.c  |  1 -
 drivers/staging/comedi/drivers/aio_aio12_8.c  |  4 +---
 drivers/staging/comedi/drivers/amplc_pci230.c |  4 +---
 drivers/staging/comedi/drivers/cb_das16_cs.c  |  4 +---
 drivers/staging/comedi/drivers/cb_pcidas64.c  |  4 +---
 drivers/staging/comedi/drivers/das08.c|  4 +---
 drivers/staging/comedi/drivers/das16m1.c  |  4 +---
 drivers/staging/comedi/drivers/dt2815.c   | 12 ++--
 drivers/staging/comedi/drivers/dt282x.c   | 12 +++-
 drivers/staging/comedi/drivers/dyna_pci10xx.c |  2 --
 drivers/staging/comedi/drivers/icp_multi.c|  3 ---
 drivers/staging/comedi/drivers/me_daq.c   |  4 +---
 drivers/staging/comedi/drivers/ni_at_a2150.c  |  8 ++--
 drivers/staging/comedi/drivers/ni_daq_700.c   | 16 +---
 drivers/staging/comedi/drivers/pcl812.c   |  8 ++--
 drivers/staging/comedi/drivers/pcl816.c   |  1 -
 drivers/staging/comedi/drivers/pcl818.c   |  1 -
 drivers/staging/comedi/drivers/skel.c |  4 +---
 21 files changed, 30 insertions(+), 81 deletions(-)

diff --git a/drivers/staging/comedi/comedi_fops.c 
b/drivers/staging/comedi/comedi_fops.c
index c22c617..e415375 100644
--- a/drivers/staging/comedi/comedi_fops.c
+++ b/drivers/staging/comedi/comedi_fops.c
@@ -1194,6 +1194,11 @@ static int parse_insn(struct comedi_device *dev, struct 
comedi_insn *insn,
switch (insn->insn) {
case INSN_READ:
ret = s->insn_read(dev, s, insn, data);
+   if (ret == -ETIMEDOUT) {
+   dev_dbg(dev->class_dev,
+   "subdevice %d read instruction timed 
out\n",
+   s->index);
+   }
break;
case INSN_WRITE:
maxdata = s->maxdata_list
@@ -1207,8 +1212,14 @@ static int parse_insn(struct comedi_device *dev, struct 
comedi_insn *insn,
break;
}
}
-   if (ret == 0)
+   if (ret == 0) {
ret = s->insn_write(dev, s, insn, data);
+   if (ret == -ETIMEDOUT) {
+   dev_dbg(dev->class_dev,
+   "subdevice %d write instruction 
timed out\n",
+   s->index);
+   }
+   }
break;
case INSN_BITS:
if (insn->n != 2) {
diff --git a/drivers/staging/comedi/drivers/adl_pci9111.c 
b/drivers/staging/comedi/drivers/adl_pci9111.c
index c741e8a..647b2d8 100644
--- a/drivers/staging/comedi/drivers/adl_pci9111.c
+++ b/drivers/staging/comedi/drivers/adl_pci9111.c
@@ -748,7 +748,6 @@ static int pci9111_ai_insn_read(struct comedi_device *dev,
 
ret = comedi_timeout(dev, s, insn, pci9111_ai_eoc, 0);
if (ret) {
-   comedi_error(dev, "A/D read timeout");
data[i] = 0;
pci9111_fifo_reset(dev);
return ret;
diff --git a/drivers/staging/comedi/drivers/adl_pci9118.c 
b/drivers/staging/comedi/drivers/adl_pci9118.c
index 6492bd8..9218e92 100644
--- a/drivers/staging/comedi/drivers/adl_pci9118.c
+++ b/drivers/staging/comedi/drivers/adl_pci9118.c
@@ -614,7 +614,6 @@ static int pci9118_insn_read_ai(struct comedi_device *dev,
 
ret = comedi_timeout(dev, s, insn, pci9118_ai_eoc, 0);
if (ret) {
-   comedi_error(dev, "A/D insn timeout");
data[n] = 0;
outl(0, dev->iobase + PCI9118_DELFIFO); /* flush FIFO */
return ret;
diff --git a/drivers/staging/comedi/drivers/adv_pci1710.c 
b/drivers/staging/comedi/drivers/adv_pci1710.c
index 36ed579..16c4bb0 100644
--- a/drivers/staging/comedi/drivers/adv_pci1710.c
+++ b/drivers/staging/comedi/drivers/adv_pci1710.c
@@ -467,7 +467,6 @@ static int pci171x_insn_read_ai(struct comedi_device *dev,
 
ret = comedi_timeout(dev, s, insn, pci171x_ai_eoc, 0);
if (ret) {
-   comedi_error(dev, "A/D insn timeout");
outb(0, dev->iobase + PCI171x_CLRFIFO);
outb(0, dev->iobase + PCI171x_CLRINT);
data[n] = 0;
diff --git a/driv

[PATCH 44/47 v2] staging: comedi: dt2814: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input end-of-conversion.

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

diff --git a/drivers/staging/comedi/drivers/dt2814.c 
b/drivers/staging/comedi/drivers/dt2814.c
index abad6e4..3794b7e 100644
--- a/drivers/staging/comedi/drivers/dt2814.c
+++ b/drivers/staging/comedi/drivers/dt2814.c
@@ -66,26 +66,35 @@ struct dt2814_private {
 #define DT2814_TIMEOUT 10
 #define DT2814_MAX_SPEED 10/* Arbitrary 10 khz limit */
 
+static int dt2814_ai_eoc(struct comedi_device *dev,
+struct comedi_subdevice *s,
+struct comedi_insn *insn,
+unsigned long context)
+{
+   unsigned int status;
+
+   status = inb(dev->iobase + DT2814_CSR);
+   if (status & DT2814_FINISH)
+   return 0;
+   return -EBUSY;
+}
+
 static int dt2814_ai_insn_read(struct comedi_device *dev,
   struct comedi_subdevice *s,
   struct comedi_insn *insn, unsigned int *data)
 {
-   int n, i, hi, lo;
+   int n, hi, lo;
int chan;
-   int status = 0;
+   int ret;
 
for (n = 0; n < insn->n; n++) {
chan = CR_CHAN(insn->chanspec);
 
outb(chan, dev->iobase + DT2814_CSR);
-   for (i = 0; i < DT2814_TIMEOUT; i++) {
-   status = inb(dev->iobase + DT2814_CSR);
-   udelay(10);
-   if (status & DT2814_FINISH)
-   break;
-   }
-   if (i >= DT2814_TIMEOUT)
-   return -ETIMEDOUT;
+
+   ret = comedi_timeout(dev, s, insn, dt2814_ai_eoc, 0);
+   if (ret)
+   return ret;
 
hi = inb(dev->iobase + DT2814_DATA);
lo = inb(dev->iobase + DT2814_DATA);
-- 
1.8.5.2

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


[PATCH 41/47 v2] staging: comedi: pcl812: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input end-of-conversion.

Combine the logic for the pcl812 and acl812 end-of-conversion in the
helper function to simplify the driver.

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

diff --git a/drivers/staging/comedi/drivers/pcl812.c 
b/drivers/staging/comedi/drivers/pcl812.c
index 53613b38..2ad6c73 100644
--- a/drivers/staging/comedi/drivers/pcl812.c
+++ b/drivers/staging/comedi/drivers/pcl812.c
@@ -394,16 +394,35 @@ static void setup_range_channel(struct comedi_device *dev,
unsigned int rangechan, char wait);
 static int pcl812_ai_cancel(struct comedi_device *dev,
struct comedi_subdevice *s);
-/*
-==
-*/
+
+static int pcl812_ai_eoc(struct comedi_device *dev,
+struct comedi_subdevice *s,
+struct comedi_insn *insn,
+unsigned long context)
+{
+   struct pcl812_private *devpriv = dev->private;
+   unsigned int status;
+
+   if (devpriv->ai_is16b) {
+   status = inb(dev->iobase + ACL8216_STATUS);
+   if ((status & ACL8216_DRDY) == 0)
+   return 0;
+   } else {
+   status = inb(dev->iobase + PCL812_AD_HI);
+   if ((status & PCL812_DRDY) == 0)
+   return 0;
+   }
+   return -EBUSY;
+}
+
 static int pcl812_ai_insn_read(struct comedi_device *dev,
   struct comedi_subdevice *s,
   struct comedi_insn *insn, unsigned int *data)
 {
struct pcl812_private *devpriv = dev->private;
+   int ret = 0;
int n;
-   int timeout, hi;
+   int hi;
 
/* select software trigger */
outb(devpriv->mode_reg_int | 1, dev->iobase + PCL812_MODE);
@@ -413,33 +432,27 @@ static int pcl812_ai_insn_read(struct comedi_device *dev,
/* start conversion */
outb(255, dev->iobase + PCL812_SOFTTRIG);
udelay(5);
-   timeout = 50;   /* wait max 50us, it must finish under 33us */
-   while (timeout--) {
-   hi = inb(dev->iobase + PCL812_AD_HI);
-   if (!(hi & PCL812_DRDY))
-   goto conv_finish;
-   udelay(1);
+
+   ret = comedi_timeout(dev, s, insn, pcl812_ai_eoc, 0);
+   if (ret) {
+   dev_dbg(dev->class_dev, "A/D insn read timeout\n");
+   break;
}
-   dev_dbg(dev->class_dev, "A/D insn read timeout\n");
-   outb(devpriv->mode_reg_int | 0, dev->iobase + PCL812_MODE);
-   return -ETIME;
 
-conv_finish:
+   hi = inb(dev->iobase + PCL812_AD_HI);
data[n] = ((hi & 0xf) << 8) | inb(dev->iobase + PCL812_AD_LO);
}
outb(devpriv->mode_reg_int | 0, dev->iobase + PCL812_MODE);
-   return n;
+
+   return ret ? ret : n;
 }
 
-/*
-==
-*/
 static int acl8216_ai_insn_read(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
 {
+   int ret = 0;
int n;
-   int timeout;
 
/* select software trigger */
outb(1, dev->iobase + PCL812_MODE);
@@ -449,23 +462,20 @@ static int acl8216_ai_insn_read(struct comedi_device *dev,
/* start conversion */
outb(255, dev->iobase + PCL812_SOFTTRIG);
udelay(5);
-   timeout = 50;   /* wait max 50us, it must finish under 33us */
-   while (timeout--) {
-   if (!(inb(dev->iobase + ACL8216_STATUS) & ACL8216_DRDY))
-   goto conv_finish;
-   udelay(1);
+
+   ret = comedi_timeout(dev, s, insn, pcl812_ai_eoc, 0);
+   if (ret) {
+   dev_dbg(dev->class_dev, "A/D insn read timeout\n");
+   break;
}
-   dev_dbg(dev->class_dev, "A/D insn read timeout\n");
-   outb(0, dev->iobase + PCL812_MODE);
-   return -ETIME;
 
-conv_finish:
data[n] =
(inb(dev->iobase +
 PCL812_AD_HI) << 8) | inb(dev->iobase + PCL812_AD_LO);
}
outb(0, dev->iobase + PCL812_MODE);
-   return n;
+
+   return ret ? ret : n;
 }
 
 /*
-- 
1.8.5.2

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

[PATCH 05/47 v2] staging: comedi: das800: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input end-of-conversion.

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

diff --git a/drivers/staging/comedi/drivers/das800.c 
b/drivers/staging/comedi/drivers/das800.c
index 5af0a57..dbe94ce 100644
--- a/drivers/staging/comedi/drivers/das800.c
+++ b/drivers/staging/comedi/drivers/das800.c
@@ -556,15 +556,17 @@ static irqreturn_t das800_interrupt(int irq, void *d)
return IRQ_HANDLED;
 }
 
-static int das800_wait_for_conv(struct comedi_device *dev, int timeout)
+static int das800_ai_eoc(struct comedi_device *dev,
+struct comedi_subdevice *s,
+struct comedi_insn *insn,
+unsigned long context)
 {
-   int i;
+   unsigned int status;
 
-   for (i = 0; i < timeout; i++) {
-   if (!(inb(dev->iobase + DAS800_STATUS) & BUSY))
-   return 0;
-   }
-   return -ETIME;
+   status = inb(dev->iobase + DAS800_STATUS);
+   if ((status & BUSY) == 0)
+   return 0;
+   return -EBUSY;
 }
 
 static int das800_ai_insn_read(struct comedi_device *dev,
@@ -599,7 +601,7 @@ static int das800_ai_insn_read(struct comedi_device *dev,
/* trigger conversion */
outb_p(0, dev->iobase + DAS800_MSB);
 
-   ret = das800_wait_for_conv(dev, 1000);
+   ret = comedi_timeout(dev, s, insn, das800_ai_eoc, 0);
if (ret)
return ret;
 
-- 
1.8.5.2

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


[PATCH 47/47 v2] staging: comedi: don't clear 'data' on (*insn_read) timeout

2014-02-10 Thread H Hartley Sweeten
It's not necessary to clear the returned data pointer when an (*insn_read)
times out. For aesthetics, remove all of these in the drivers.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/adl_pci9111.c  | 1 -
 drivers/staging/comedi/drivers/adl_pci9118.c  | 1 -
 drivers/staging/comedi/drivers/adv_pci1710.c  | 1 -
 drivers/staging/comedi/drivers/dyna_pci10xx.c | 4 +---
 drivers/staging/comedi/drivers/icp_multi.c| 5 +
 drivers/staging/comedi/drivers/pcl816.c   | 1 -
 6 files changed, 2 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/comedi/drivers/adl_pci9111.c 
b/drivers/staging/comedi/drivers/adl_pci9111.c
index 647b2d8..ff086d0 100644
--- a/drivers/staging/comedi/drivers/adl_pci9111.c
+++ b/drivers/staging/comedi/drivers/adl_pci9111.c
@@ -748,7 +748,6 @@ static int pci9111_ai_insn_read(struct comedi_device *dev,
 
ret = comedi_timeout(dev, s, insn, pci9111_ai_eoc, 0);
if (ret) {
-   data[i] = 0;
pci9111_fifo_reset(dev);
return ret;
}
diff --git a/drivers/staging/comedi/drivers/adl_pci9118.c 
b/drivers/staging/comedi/drivers/adl_pci9118.c
index 9218e92..6ca6c42 100644
--- a/drivers/staging/comedi/drivers/adl_pci9118.c
+++ b/drivers/staging/comedi/drivers/adl_pci9118.c
@@ -614,7 +614,6 @@ static int pci9118_insn_read_ai(struct comedi_device *dev,
 
ret = comedi_timeout(dev, s, insn, pci9118_ai_eoc, 0);
if (ret) {
-   data[n] = 0;
outl(0, dev->iobase + PCI9118_DELFIFO); /* flush FIFO */
return ret;
}
diff --git a/drivers/staging/comedi/drivers/adv_pci1710.c 
b/drivers/staging/comedi/drivers/adv_pci1710.c
index 16c4bb0..5978ae6 100644
--- a/drivers/staging/comedi/drivers/adv_pci1710.c
+++ b/drivers/staging/comedi/drivers/adv_pci1710.c
@@ -469,7 +469,6 @@ static int pci171x_insn_read_ai(struct comedi_device *dev,
if (ret) {
outb(0, dev->iobase + PCI171x_CLRFIFO);
outb(0, dev->iobase + PCI171x_CLRINT);
-   data[n] = 0;
return ret;
}
 
diff --git a/drivers/staging/comedi/drivers/dyna_pci10xx.c 
b/drivers/staging/comedi/drivers/dyna_pci10xx.c
index 78d44a9..e5593f8 100644
--- a/drivers/staging/comedi/drivers/dyna_pci10xx.c
+++ b/drivers/staging/comedi/drivers/dyna_pci10xx.c
@@ -93,10 +93,8 @@ static int dyna_pci10xx_insn_read_ai(struct comedi_device 
*dev,
udelay(10);
 
ret = comedi_timeout(dev, s, insn, dyna_pci10xx_ai_eoc, 0);
-   if (ret) {
-   data[n] = 0;
+   if (ret)
break;
-   }
 
/* read data */
d = inw_p(dev->iobase);
diff --git a/drivers/staging/comedi/drivers/icp_multi.c 
b/drivers/staging/comedi/drivers/icp_multi.c
index ee30f2b..0b8b216 100644
--- a/drivers/staging/comedi/drivers/icp_multi.c
+++ b/drivers/staging/comedi/drivers/icp_multi.c
@@ -215,11 +215,8 @@ static int icp_multi_insn_read_ai(struct comedi_device 
*dev,
 
/*  Wait for conversion to complete, or get fed up waiting */
ret = comedi_timeout(dev, s, insn, icp_multi_ai_eoc, 0);
-   if (ret) {
-   /*  Clear data received */
-   data[n] = 0;
+   if (ret)
break;
-   }
 
data[n] =
(readw(devpriv->io_addr + ICP_MULTI_AI) >> 4) & 0x0fff;
diff --git a/drivers/staging/comedi/drivers/pcl816.c 
b/drivers/staging/comedi/drivers/pcl816.c
index 4bf2efb..a35f230 100644
--- a/drivers/staging/comedi/drivers/pcl816.c
+++ b/drivers/staging/comedi/drivers/pcl816.c
@@ -196,7 +196,6 @@ static int pcl816_ai_insn_read(struct comedi_device *dev,
 
ret = comedi_timeout(dev, s, insn, pcl816_ai_eoc, 0);
if (ret) {
-   data[0] = 0;
/* clear INT (conversion end) flag */
outb(0, dev->iobase + PCL816_CLRINT);
return ret;
-- 
1.8.5.2

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


[PATCH 34/47 v2] staging: comedi: icp_multi: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input and output end-of-
conversion.

Use break to exit the loop when a timeout occurs during the analog
input read so that common code can be used to disable the device.

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

diff --git a/drivers/staging/comedi/drivers/icp_multi.c 
b/drivers/staging/comedi/drivers/icp_multi.c
index 19c586b..7fb6ca0 100644
--- a/drivers/staging/comedi/drivers/icp_multi.c
+++ b/drivers/staging/comedi/drivers/icp_multi.c
@@ -171,12 +171,27 @@ static void setup_channel_list(struct comedi_device *dev,
}
 }
 
+static int icp_multi_ai_eoc(struct comedi_device *dev,
+   struct comedi_subdevice *s,
+   struct comedi_insn *insn,
+   unsigned long context)
+{
+   struct icp_multi_private *devpriv = dev->private;
+   unsigned int status;
+
+   status = readw(devpriv->io_addr + ICP_MULTI_ADC_CSR);
+   if ((status & ADC_BSY) == 0)
+   return 0;
+   return -EBUSY;
+}
+
 static int icp_multi_insn_read_ai(struct comedi_device *dev,
  struct comedi_subdevice *s,
  struct comedi_insn *insn, unsigned int *data)
 {
struct icp_multi_private *devpriv = dev->private;
-   int n, timeout;
+   int ret = 0;
+   int n;
 
/*  Disable A/D conversion ready interrupt */
devpriv->IntEnable &= ~ADC_READY;
@@ -199,33 +214,14 @@ static int icp_multi_insn_read_ai(struct comedi_device 
*dev,
udelay(1);
 
/*  Wait for conversion to complete, or get fed up waiting */
-   timeout = 100;
-   while (timeout--) {
-   if (!(readw(devpriv->io_addr +
-   ICP_MULTI_ADC_CSR) & ADC_BSY))
-   goto conv_finish;
-
-   udelay(1);
+   ret = comedi_timeout(dev, s, insn, icp_multi_ai_eoc, 0);
+   if (ret) {
+   comedi_error(dev, "A/D insn timeout");
+   /*  Clear data received */
+   data[n] = 0;
+   break;
}
 
-   /*  If we reach here, a timeout has occurred */
-   comedi_error(dev, "A/D insn timeout");
-
-   /*  Disable interrupt */
-   devpriv->IntEnable &= ~ADC_READY;
-   writew(devpriv->IntEnable, devpriv->io_addr + ICP_MULTI_INT_EN);
-
-   /*  Clear interrupt status */
-   devpriv->IntStatus |= ADC_READY;
-   writew(devpriv->IntStatus,
-  devpriv->io_addr + ICP_MULTI_INT_STAT);
-
-   /*  Clear data received */
-   data[n] = 0;
-
-   return -ETIME;
-
-conv_finish:
data[n] =
(readw(devpriv->io_addr + ICP_MULTI_AI) >> 4) & 0x0fff;
}
@@ -238,7 +234,21 @@ conv_finish:
devpriv->IntStatus |= ADC_READY;
writew(devpriv->IntStatus, devpriv->io_addr + ICP_MULTI_INT_STAT);
 
-   return n;
+   return ret ? ret : n;
+}
+
+static int icp_multi_ao_eoc(struct comedi_device *dev,
+   struct comedi_subdevice *s,
+   struct comedi_insn *insn,
+   unsigned long context)
+{
+   struct icp_multi_private *devpriv = dev->private;
+   unsigned int status;
+
+   status = readw(devpriv->io_addr + ICP_MULTI_DAC_CSR);
+   if ((status & DAC_BSY) == 0)
+   return 0;
+   return -EBUSY;
 }
 
 static int icp_multi_insn_write_ao(struct comedi_device *dev,
@@ -246,7 +256,8 @@ static int icp_multi_insn_write_ao(struct comedi_device 
*dev,
   struct comedi_insn *insn, unsigned int *data)
 {
struct icp_multi_private *devpriv = dev->private;
-   int n, chan, range, timeout;
+   int n, chan, range;
+   int ret;
 
/*  Disable D/A conversion ready interrupt */
devpriv->IntEnable &= ~DAC_READY;
@@ -274,33 +285,26 @@ static int icp_multi_insn_write_ao(struct comedi_device 
*dev,
for (n = 0; n < insn->n; n++) {
/*  Wait for analogue output data register to be
 *  ready for new data, or get fed up waiting */
-   timeout = 100;
-   while (timeout--) {
-   if (!(readw(devpriv->io_addr +
-   ICP_MULTI_DAC_CSR) & DAC_BSY))
-   goto dac_ready;
-
-   udelay(1);
-   }
-
-   /*  If we reach here, a timeout has occurred */
-   comedi_error(dev, "D/A insn timeout");
+   ret = comedi_timeout(dev, s, insn, icp_multi

[PATCH 15/47 v2] staging: comedi: cb_das16_cs: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input end-of-conversion.

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

diff --git a/drivers/staging/comedi/drivers/cb_das16_cs.c 
b/drivers/staging/comedi/drivers/cb_das16_cs.c
index 9a14e26..549844c 100644
--- a/drivers/staging/comedi/drivers/cb_das16_cs.c
+++ b/drivers/staging/comedi/drivers/cb_das16_cs.c
@@ -101,6 +101,19 @@ static irqreturn_t das16cs_interrupt(int irq, void *d)
return IRQ_HANDLED;
 }
 
+static int das16cs_ai_eoc(struct comedi_device *dev,
+ struct comedi_subdevice *s,
+ struct comedi_insn *insn,
+ unsigned long context)
+{
+   unsigned int status;
+
+   status = inw(dev->iobase + DAS16CS_MISC1);
+   if (status & 0x0080)
+   return 0;
+   return -EBUSY;
+}
+
 static int das16cs_ai_rinsn(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
@@ -109,8 +122,8 @@ static int das16cs_ai_rinsn(struct comedi_device *dev,
int chan = CR_CHAN(insn->chanspec);
int range = CR_RANGE(insn->chanspec);
int aref = CR_AREF(insn->chanspec);
+   int ret;
int i;
-   int to;
 
outw(chan, dev->iobase + DAS16CS_DIO_MUX);
 
@@ -138,15 +151,12 @@ static int das16cs_ai_rinsn(struct comedi_device *dev,
for (i = 0; i < insn->n; i++) {
outw(0, dev->iobase + DAS16CS_ADC_DATA);
 
-#define TIMEOUT 1000
-   for (to = 0; to < TIMEOUT; to++) {
-   if (inw(dev->iobase + DAS16CS_MISC1) & 0x0080)
-   break;
-   }
-   if (to == TIMEOUT) {
+   ret = comedi_timeout(dev, s, insn, das16cs_ai_eoc, 0);
+   if (ret) {
dev_dbg(dev->class_dev, "cb_das16_cs: ai timeout\n");
-   return -ETIME;
+   return ret;
}
+
data[i] = inw(dev->iobase + DAS16CS_ADC_DATA);
}
 
-- 
1.8.5.2

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


[PATCH 24/47 v2] staging: comedi: s526: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input end-of-conversion.

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

diff --git a/drivers/staging/comedi/drivers/s526.c 
b/drivers/staging/comedi/drivers/s526.c
index 0a93afa..85d2b7a 100644
--- a/drivers/staging/comedi/drivers/s526.c
+++ b/drivers/staging/comedi/drivers/s526.c
@@ -420,15 +420,28 @@ static int s526_ai_insn_config(struct comedi_device *dev,
return result;
 }
 
+static int s526_ai_eoc(struct comedi_device *dev,
+  struct comedi_subdevice *s,
+  struct comedi_insn *insn,
+  unsigned long context)
+{
+   unsigned int status;
+
+   status = inw(dev->iobase + REG_ISR);
+   if (status & ISR_ADC_DONE)
+   return 0;
+   return -EBUSY;
+}
+
 static int s526_ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
 struct comedi_insn *insn, unsigned int *data)
 {
struct s526_private *devpriv = dev->private;
unsigned int chan = CR_CHAN(insn->chanspec);
-   int n, i;
+   int n;
unsigned short value;
unsigned int d;
-   unsigned int status;
+   int ret;
 
/* Set configured delay, enable channel for this channel only,
 * select "ADC read" channel, set "ADC start" bit. */
@@ -440,17 +453,12 @@ static int s526_ai_rinsn(struct comedi_device *dev, 
struct comedi_subdevice *s,
/* trigger conversion */
outw(value, dev->iobase + REG_ADC);
 
-#define TIMEOUT 100
/* wait for conversion to end */
-   for (i = 0; i < TIMEOUT; i++) {
-   status = inw(dev->iobase + REG_ISR);
-   if (status & ISR_ADC_DONE) {
-   outw(ISR_ADC_DONE, dev->iobase + REG_ISR);
-   break;
-   }
-   }
-   if (i == TIMEOUT)
-   return -ETIMEDOUT;
+   ret = comedi_timeout(dev, s, insn, s526_ai_eoc, 0);
+   if (ret)
+   return ret;
+
+   outw(ISR_ADC_DONE, dev->iobase + REG_ISR);
 
/* read data */
d = inw(dev->iobase + REG_ADD);
-- 
1.8.5.2

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


[PATCH 26/47 v2] staging: comedi: ni_at_a2150: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input end-of-conversion.

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

diff --git a/drivers/staging/comedi/drivers/ni_at_a2150.c 
b/drivers/staging/comedi/drivers/ni_at_a2150.c
index f83eb9e..07239c9 100644
--- a/drivers/staging/comedi/drivers/ni_at_a2150.c
+++ b/drivers/staging/comedi/drivers/ni_at_a2150.c
@@ -488,13 +488,25 @@ static int a2150_ai_cmd(struct comedi_device *dev, struct 
comedi_subdevice *s)
return 0;
 }
 
+static int a2150_ai_eoc(struct comedi_device *dev,
+   struct comedi_subdevice *s,
+   struct comedi_insn *insn,
+   unsigned long context)
+{
+   unsigned int status;
+
+   status = inw(dev->iobase + STATUS_REG);
+   if (status & FNE_BIT)
+   return 0;
+   return -EBUSY;
+}
+
 static int a2150_ai_rinsn(struct comedi_device *dev, struct comedi_subdevice 
*s,
  struct comedi_insn *insn, unsigned int *data)
 {
struct a2150_private *devpriv = dev->private;
-   unsigned int i, n;
-   static const int timeout = 10;
-   static const int filter_delay = 36;
+   unsigned int n;
+   int ret;
 
/*  clear fifo and reset triggering circuitry */
outw(0, dev->iobase + FIFO_RESET_REG);
@@ -524,30 +536,24 @@ static int a2150_ai_rinsn(struct comedi_device *dev, 
struct comedi_subdevice *s,
 * there is a 35.6 sample delay for data to get through the
 * antialias filter
 */
-   for (n = 0; n < filter_delay; n++) {
-   for (i = 0; i < timeout; i++) {
-   if (inw(dev->iobase + STATUS_REG) & FNE_BIT)
-   break;
-   udelay(1);
-   }
-   if (i == timeout) {
+   for (n = 0; n < 36; n++) {
+   ret = comedi_timeout(dev, s, insn, a2150_ai_eoc, 0);
+   if (ret) {
comedi_error(dev, "timeout");
-   return -ETIME;
+   return ret;
}
+
inw(dev->iobase + FIFO_DATA_REG);
}
 
/*  read data */
for (n = 0; n < insn->n; n++) {
-   for (i = 0; i < timeout; i++) {
-   if (inw(dev->iobase + STATUS_REG) & FNE_BIT)
-   break;
-   udelay(1);
-   }
-   if (i == timeout) {
+   ret = comedi_timeout(dev, s, insn, a2150_ai_eoc, 0);
+   if (ret) {
comedi_error(dev, "timeout");
-   return -ETIME;
+   return ret;
}
+
data[n] = inw(dev->iobase + FIFO_DATA_REG);
data[n] ^= 0x8000;
}
-- 
1.8.5.2

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


[PATCH 22/47 v2] staging: comedi: me_daq: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input end-of-conversion.

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

diff --git a/drivers/staging/comedi/drivers/me_daq.c 
b/drivers/staging/comedi/drivers/me_daq.c
index 288ce2b..288fb21 100644
--- a/drivers/staging/comedi/drivers/me_daq.c
+++ b/drivers/staging/comedi/drivers/me_daq.c
@@ -248,6 +248,20 @@ static int me_dio_insn_bits(struct comedi_device *dev,
return insn->n;
 }
 
+static int me_ai_eoc(struct comedi_device *dev,
+struct comedi_subdevice *s,
+struct comedi_insn *insn,
+unsigned long context)
+{
+   struct me_private_data *dev_private = dev->private;
+   unsigned int status;
+
+   status = readw(dev_private->me_regbase + ME_STATUS);
+   if ((status & 0x0004) == 0)
+   return 0;
+   return -EBUSY;
+}
+
 static int me_ai_insn_read(struct comedi_device *dev,
   struct comedi_subdevice *s,
   struct comedi_insn *insn,
@@ -258,7 +272,7 @@ static int me_ai_insn_read(struct comedi_device *dev,
unsigned int rang = CR_RANGE(insn->chanspec);
unsigned int aref = CR_AREF(insn->chanspec);
unsigned short val;
-   int i;
+   int ret;
 
/* stop any running conversion */
dev_private->control_1 &= 0xFFFC;
@@ -290,20 +304,17 @@ static int me_ai_insn_read(struct comedi_device *dev,
readw(dev_private->me_regbase + ME_ADC_START);
 
/* wait for ADC fifo not empty flag */
-   for (i = 10; i > 0; i--)
-   if (!(readw(dev_private->me_regbase + ME_STATUS) & 0x0004))
-   break;
-
-   /* get value from ADC fifo */
-   if (i) {
-   val = readw(dev_private->me_regbase + ME_READ_AD_FIFO);
-   val = (val ^ 0x800) & 0x0fff;
-   data[0] = val;
-   } else {
+   ret = comedi_timeout(dev, s, insn, me_ai_eoc, 0);
+   if (ret) {
dev_err(dev->class_dev, "Cannot get single value\n");
-   return -EIO;
+   return ret;
}
 
+   /* get value from ADC fifo */
+   val = readw(dev_private->me_regbase + ME_READ_AD_FIFO);
+   val = (val ^ 0x800) & 0x0fff;
+   data[0] = val;
+
/* stop any running conversion */
dev_private->control_1 &= 0xFFFC;
writew(dev_private->control_1, dev_private->me_regbase + ME_CONTROL_1);
-- 
1.8.5.2

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


[PATCH 13/47 v2] staging: comedi: rti800: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input end-of-conversion.

Change the errno returned for an overrun from -EIO to -EOVERFLOW.

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

diff --git a/drivers/staging/comedi/drivers/rti800.c 
b/drivers/staging/comedi/drivers/rti800.c
index e1f3671..bd447b2 100644
--- a/drivers/staging/comedi/drivers/rti800.c
+++ b/drivers/staging/comedi/drivers/rti800.c
@@ -83,8 +83,6 @@
 
 #define RTI800_IOSIZE  0x10
 
-#define RTI800_AI_TIMEOUT  100
-
 static const struct comedi_lrange range_rti800_ai_10_bipolar = {
4, {
BIP_RANGE(10),
@@ -145,23 +143,21 @@ struct rti800_private {
unsigned char muxgain_bits;
 };
 
-static int rti800_ai_wait_for_conversion(struct comedi_device *dev,
-int timeout)
+static int rti800_ai_eoc(struct comedi_device *dev,
+struct comedi_subdevice *s,
+struct comedi_insn *insn,
+unsigned long context)
 {
unsigned char status;
-   int i;
 
-   for (i = 0; i < timeout; i++) {
-   status = inb(dev->iobase + RTI800_CSR);
-   if (status & RTI800_CSR_OVERRUN) {
-   outb(0, dev->iobase + RTI800_CLRFLAGS);
-   return -EIO;
-   }
-   if (status & RTI800_CSR_DONE)
-   return 0;
-   udelay(1);
+   status = inb(dev->iobase + RTI800_CSR);
+   if (status & RTI800_CSR_OVERRUN) {
+   outb(0, dev->iobase + RTI800_CLRFLAGS);
+   return -EOVERFLOW;
}
-   return -ETIME;
+   if (status & RTI800_CSR_DONE)
+   return 0;
+   return -EBUSY;
 }
 
 static int rti800_ai_insn_read(struct comedi_device *dev,
@@ -198,7 +194,8 @@ static int rti800_ai_insn_read(struct comedi_device *dev,
 
for (i = 0; i < insn->n; i++) {
outb(0, dev->iobase + RTI800_CONVERT);
-   ret = rti800_ai_wait_for_conversion(dev, RTI800_AI_TIMEOUT);
+
+   ret = comedi_timeout(dev, s, insn, rti800_ai_eoc, 0);
if (ret)
return ret;
 
-- 
1.8.5.2

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


[PATCH 38/47 v2] staging: comedi: s626: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input end-of-conversion.

This prevents a deadlock condition that could occur by providing a
timeout in case the end-of-conversion does not happen.

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

diff --git a/drivers/staging/comedi/drivers/s626.c 
b/drivers/staging/comedi/drivers/s626.c
index 9e711ee..5ba4b4a 100644
--- a/drivers/staging/comedi/drivers/s626.c
+++ b/drivers/staging/comedi/drivers/s626.c
@@ -1846,6 +1846,20 @@ static int s626_ai_rinsn(struct comedi_device *dev,
 }
 #endif
 
+static int s626_ai_eoc(struct comedi_device *dev,
+  struct comedi_subdevice *s,
+  struct comedi_insn *insn,
+  unsigned long context)
+{
+   struct s626_private *devpriv = dev->private;
+   unsigned int status;
+
+   status = readl(devpriv->mmio + S626_P_PSR);
+   if (status & S626_PSR_GPIO2)
+   return 0;
+   return -EBUSY;
+}
+
 static int s626_ai_insn_read(struct comedi_device *dev,
 struct comedi_subdevice *s,
 struct comedi_insn *insn, unsigned int *data)
@@ -1856,6 +1870,7 @@ static int s626_ai_insn_read(struct comedi_device *dev,
uint16_t adc_spec = 0;
uint32_t gpio_image;
uint32_t tmp;
+   int ret;
int n;
 
/*
@@ -1897,8 +1912,9 @@ static int s626_ai_insn_read(struct comedi_device *dev,
 */
 
/* Wait for ADC done */
-   while (!(readl(devpriv->mmio + S626_P_PSR) & S626_PSR_GPIO2))
-   ;
+   ret = comedi_timeout(dev, s, insn, s626_ai_eoc, 0);
+   if (ret)
+   return ret;
 
/* Fetch ADC data */
if (n != 0) {
-- 
1.8.5.2

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


[PATCH 28/47 v2] staging: comedi: adl_pci9111: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input end-of-conversion.

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

diff --git a/drivers/staging/comedi/drivers/adl_pci9111.c 
b/drivers/staging/comedi/drivers/adl_pci9111.c
index 0039b1b..c741e8a 100644
--- a/drivers/staging/comedi/drivers/adl_pci9111.c
+++ b/drivers/staging/comedi/drivers/adl_pci9111.c
@@ -84,7 +84,6 @@ TODO:
 
 #define PCI9111_RANGE_SETTING_DELAY10
 #define PCI9111_AI_INSTANT_READ_UDELAY_US  2
-#define PCI9111_AI_INSTANT_READ_TIMEOUT100
 
 /*
  * IO address map and bit defines
@@ -707,6 +706,19 @@ static irqreturn_t pci9111_interrupt(int irq, void 
*p_device)
return IRQ_HANDLED;
 }
 
+static int pci9111_ai_eoc(struct comedi_device *dev,
+ struct comedi_subdevice *s,
+ struct comedi_insn *insn,
+ unsigned long context)
+{
+   unsigned int status;
+
+   status = inb(dev->iobase + PCI9111_AI_RANGE_STAT_REG);
+   if (status & PCI9111_AI_STAT_FF_EF)
+   return 0;
+   return -EBUSY;
+}
+
 static int pci9111_ai_insn_read(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
@@ -717,7 +729,7 @@ static int pci9111_ai_insn_read(struct comedi_device *dev,
unsigned int invert = (maxdata + 1) >> 1;
unsigned int shift = (maxdata == 0x) ? 0 : 4;
unsigned int status;
-   int timeout;
+   int ret;
int i;
 
outb(chan, dev->iobase + PCI9111_AI_CHANNEL_REG);
@@ -734,22 +746,14 @@ static int pci9111_ai_insn_read(struct comedi_device *dev,
/* Generate a software trigger */
outb(0, dev->iobase + PCI9111_SOFT_TRIG_REG);
 
-   timeout = PCI9111_AI_INSTANT_READ_TIMEOUT;
-
-   while (timeout--) {
-   status = inb(dev->iobase + PCI9111_AI_RANGE_STAT_REG);
-   /* '1' means FIFO is not empty */
-   if (status & PCI9111_AI_STAT_FF_EF)
-   goto conversion_done;
+   ret = comedi_timeout(dev, s, insn, pci9111_ai_eoc, 0);
+   if (ret) {
+   comedi_error(dev, "A/D read timeout");
+   data[i] = 0;
+   pci9111_fifo_reset(dev);
+   return ret;
}
 
-   comedi_error(dev, "A/D read timeout");
-   data[i] = 0;
-   pci9111_fifo_reset(dev);
-   return -ETIME;
-
-conversion_done:
-
data[i] = inw(dev->iobase + PCI9111_AI_FIFO_REG);
data[i] = ((data[i] >> shift) & maxdata) ^ invert;
}
-- 
1.8.5.2

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


[PATCH 11/47 v2] staging: comedi: pcmmio: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input and output end-of-
conversions.

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

diff --git a/drivers/staging/comedi/drivers/pcmmio.c 
b/drivers/staging/comedi/drivers/pcmmio.c
index c388f7f..e89bca8 100644
--- a/drivers/staging/comedi/drivers/pcmmio.c
+++ b/drivers/staging/comedi/drivers/pcmmio.c
@@ -589,16 +589,17 @@ static int pcmmio_cmdtest(struct comedi_device *dev,
return 0;
 }
 
-static int pcmmio_ai_wait_for_eoc(unsigned long iobase, unsigned int timeout)
+static int pcmmio_ai_eoc(struct comedi_device *dev,
+struct comedi_subdevice *s,
+struct comedi_insn *insn,
+unsigned long context)
 {
unsigned char status;
 
-   while (timeout--) {
-   status = inb(iobase + PCMMIO_AI_STATUS_REG);
-   if (status & PCMMIO_AI_STATUS_DATA_READY)
-   return 0;
-   }
-   return -ETIME;
+   status = inb(dev->iobase + PCMMIO_AI_STATUS_REG);
+   if (status & PCMMIO_AI_STATUS_DATA_READY)
+   return 0;
+   return -EBUSY;
 }
 
 static int pcmmio_ai_insn_read(struct comedi_device *dev,
@@ -643,7 +644,8 @@ static int pcmmio_ai_insn_read(struct comedi_device *dev,
cmd |= PCMMIO_AI_CMD_RANGE(range);
 
outb(cmd, iobase + PCMMIO_AI_CMD_REG);
-   ret = pcmmio_ai_wait_for_eoc(iobase, 10);
+
+   ret = comedi_timeout(dev, s, insn, pcmmio_ai_eoc, 0);
if (ret)
return ret;
 
@@ -652,7 +654,8 @@ static int pcmmio_ai_insn_read(struct comedi_device *dev,
 
for (i = 0; i < insn->n; i++) {
outb(cmd, iobase + PCMMIO_AI_CMD_REG);
-   ret = pcmmio_ai_wait_for_eoc(iobase, 10);
+
+   ret = comedi_timeout(dev, s, insn, pcmmio_ai_eoc, 0);
if (ret)
return ret;
 
@@ -684,16 +687,17 @@ static int pcmmio_ao_insn_read(struct comedi_device *dev,
return insn->n;
 }
 
-static int pcmmio_ao_wait_for_eoc(unsigned long iobase, unsigned int timeout)
+static int pcmmio_ao_eoc(struct comedi_device *dev,
+struct comedi_subdevice *s,
+struct comedi_insn *insn,
+unsigned long context)
 {
unsigned char status;
 
-   while (timeout--) {
-   status = inb(iobase + PCMMIO_AO_STATUS_REG);
-   if (status & PCMMIO_AO_STATUS_DATA_READY)
-   return 0;
-   }
-   return -ETIME;
+   status = inb(dev->iobase + PCMMIO_AO_STATUS_REG);
+   if (status & PCMMIO_AO_STATUS_DATA_READY)
+   return 0;
+   return -EBUSY;
 }
 
 static int pcmmio_ao_insn_write(struct comedi_device *dev,
@@ -726,7 +730,8 @@ static int pcmmio_ao_insn_write(struct comedi_device *dev,
outb(PCMMIO_AO_LSB_SPAN(range), iobase + PCMMIO_AO_LSB_REG);
outb(0, iobase + PCMMIO_AO_MSB_REG);
outb(cmd | PCMMIO_AO_CMD_WR_SPAN_UPDATE, iobase + PCMMIO_AO_CMD_REG);
-   ret = pcmmio_ao_wait_for_eoc(iobase, 10);
+
+   ret = comedi_timeout(dev, s, insn, pcmmio_ao_eoc, 0);
if (ret)
return ret;
 
@@ -738,7 +743,8 @@ static int pcmmio_ao_insn_write(struct comedi_device *dev,
outb((val >> 8) & 0xff, iobase + PCMMIO_AO_MSB_REG);
outb(cmd | PCMMIO_AO_CMD_WR_CODE_UPDATE,
 iobase + PCMMIO_AO_CMD_REG);
-   ret = pcmmio_ao_wait_for_eoc(iobase, 10);
+
+   ret = comedi_timeout(dev, s, insn, pcmmio_ao_eoc, 0);
if (ret)
return ret;
 
-- 
1.8.5.2

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


[PATCH 04/47 v2] staging: comedi: das16: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input end-of-conversion.

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

diff --git a/drivers/staging/comedi/drivers/das16.c 
b/drivers/staging/comedi/drivers/das16.c
index a8446ca..6a7d652 100644
--- a/drivers/staging/comedi/drivers/das16.c
+++ b/drivers/staging/comedi/drivers/das16.c
@@ -856,18 +856,17 @@ static void das16_ai_munge(struct comedi_device *dev,
}
 }
 
-static int das16_ai_wait_for_conv(struct comedi_device *dev,
- unsigned int timeout)
+static int das16_ai_eoc(struct comedi_device *dev,
+   struct comedi_subdevice *s,
+   struct comedi_insn *insn,
+   unsigned long context)
 {
unsigned int status;
-   int i;
 
-   for (i = 0; i < timeout; i++) {
-   status = inb(dev->iobase + DAS16_STATUS_REG);
-   if (!(status & DAS16_STATUS_BUSY))
-   return 0;
-   }
-   return -ETIME;
+   status = inb(dev->iobase + DAS16_STATUS_REG);
+   if ((status & DAS16_STATUS_BUSY) == 0)
+   return 0;
+   return -EBUSY;
 }
 
 static int das16_ai_insn_read(struct comedi_device *dev,
@@ -897,7 +896,7 @@ static int das16_ai_insn_read(struct comedi_device *dev,
/* trigger conversion */
outb_p(0, dev->iobase + DAS16_TRIG_REG);
 
-   ret = das16_ai_wait_for_conv(dev, 1000);
+   ret = comedi_timeout(dev, s, insn, das16_ai_eoc, 0);
if (ret)
return ret;
 
-- 
1.8.5.2

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


[PATCH 36/47 v2] staging: comedi: ni_daq_700: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input end-of-conversion.

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

diff --git a/drivers/staging/comedi/drivers/ni_daq_700.c 
b/drivers/staging/comedi/drivers/ni_daq_700.c
index 7979a66..e56bfeb 100644
--- a/drivers/staging/comedi/drivers/ni_daq_700.c
+++ b/drivers/staging/comedi/drivers/ni_daq_700.c
@@ -109,14 +109,31 @@ static int daq700_dio_insn_config(struct comedi_device 
*dev,
return insn->n;
 }
 
+static int daq700_ai_eoc(struct comedi_device *dev,
+struct comedi_subdevice *s,
+struct comedi_insn *insn,
+unsigned long context)
+{
+   unsigned int status;
+
+   status = inb(dev->iobase + STA_R2);
+   if ((status & 0x03))
+   return -EOVERFLOW;
+   status = inb(dev->iobase + STA_R1);
+   if ((status & 0x02))
+   return -ENODATA;
+   if ((status & 0x11) == 0x01)
+   return 0;
+   return -EBUSY;
+}
+
 static int daq700_ai_rinsn(struct comedi_device *dev,
   struct comedi_subdevice *s,
   struct comedi_insn *insn, unsigned int *data)
 {
-   int n, i, chan;
+   int n, chan;
int d;
-   unsigned int status;
-   enum { TIMEOUT = 100 };
+   int ret;
 
chan = CR_CHAN(insn->chanspec);
/* write channel to multiplexer */
@@ -130,30 +147,26 @@ static int daq700_ai_rinsn(struct comedi_device *dev,
outb(0x30, dev->iobase + CMO_R); /* mode 0 out0 L, from H */
/* mode 1 out0 H, L to H, start conversion */
outb(0x32, dev->iobase + CMO_R);
+
/* wait for conversion to end */
-   for (i = 0; i < TIMEOUT; i++) {
-   status = inb(dev->iobase + STA_R2);
-   if ((status & 0x03) != 0) {
+   ret = comedi_timeout(dev, s, insn, daq700_ai_eoc, 0);
+   if (ret) {
+   switch (ret) {
+   case -EOVERFLOW:
dev_info(dev->class_dev,
 "Overflow/run Error\n");
-   return -EOVERFLOW;
-   }
-   status = inb(dev->iobase + STA_R1);
-   if ((status & 0x02) != 0) {
+   break;
+   case -ENODATA:
dev_info(dev->class_dev, "Data Error\n");
-   return -ENODATA;
-   }
-   if ((status & 0x11) == 0x01) {
-   /* ADC conversion complete */
+   break;
+   default:
+   dev_info(dev->class_dev,
+"timeout during ADC conversion\n");
break;
}
-   udelay(1);
-   }
-   if (i == TIMEOUT) {
-   dev_info(dev->class_dev,
-"timeout during ADC conversion\n");
-   return -ETIMEDOUT;
+   return ret;
}
+
/* read data */
d = inw(dev->iobase + ADFIFO_R);
/* mangle the data as necessary */
-- 
1.8.5.2

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


[PATCH 30/47 v2] staging: comedi: adv_pci1710: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input end-of-conversion.

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

diff --git a/drivers/staging/comedi/drivers/adv_pci1710.c 
b/drivers/staging/comedi/drivers/adv_pci1710.c
index f9d6111..36ed579 100644
--- a/drivers/staging/comedi/drivers/adv_pci1710.c
+++ b/drivers/staging/comedi/drivers/adv_pci1710.c
@@ -429,15 +429,26 @@ static void setup_channel_list(struct comedi_device *dev,
outw(devpriv->ai_et_MuxVal, dev->iobase + PCI171x_MUX);
 }
 
-/*
-==
-*/
+static int pci171x_ai_eoc(struct comedi_device *dev,
+ struct comedi_subdevice *s,
+ struct comedi_insn *insn,
+ unsigned long context)
+{
+   unsigned int status;
+
+   status = inw(dev->iobase + PCI171x_STATUS);
+   if ((status & Status_FE) == 0)
+   return 0;
+   return -EBUSY;
+}
+
 static int pci171x_insn_read_ai(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
 {
struct pci1710_private *devpriv = dev->private;
-   int n, timeout;
+   int ret;
+   int n;
 #ifdef PCI171x_PARANOIDCHECK
const struct boardtype *this_board = comedi_board(dev);
unsigned int idata;
@@ -453,19 +464,16 @@ static int pci171x_insn_read_ai(struct comedi_device *dev,
 
for (n = 0; n < insn->n; n++) {
outw(0, dev->iobase + PCI171x_SOFTTRG); /* start conversion */
-   /* udelay(1); */
-   timeout = 100;
-   while (timeout--) {
-   if (!(inw(dev->iobase + PCI171x_STATUS) & Status_FE))
-   goto conv_finish;
+
+   ret = comedi_timeout(dev, s, insn, pci171x_ai_eoc, 0);
+   if (ret) {
+   comedi_error(dev, "A/D insn timeout");
+   outb(0, dev->iobase + PCI171x_CLRFIFO);
+   outb(0, dev->iobase + PCI171x_CLRINT);
+   data[n] = 0;
+   return ret;
}
-   comedi_error(dev, "A/D insn timeout");
-   outb(0, dev->iobase + PCI171x_CLRFIFO);
-   outb(0, dev->iobase + PCI171x_CLRINT);
-   data[n] = 0;
-   return -ETIME;
 
-conv_finish:
 #ifdef PCI171x_PARANOIDCHECK
idata = inw(dev->iobase + PCI171x_AD_DATA);
if (this_board->cardtype != TYPE_PCI1713)
-- 
1.8.5.2

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


[PATCH 31/47 v2] staging: comedi: adq12b: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input end-of-conversion.

This also fixes a possible bug where invalid data is returned if the
conversion did not complete.

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

diff --git a/drivers/staging/comedi/drivers/adq12b.c 
b/drivers/staging/comedi/drivers/adq12b.c
index 3190ef7..b4ea377 100644
--- a/drivers/staging/comedi/drivers/adq12b.c
+++ b/drivers/staging/comedi/drivers/adq12b.c
@@ -94,8 +94,6 @@ If you do not specify any options, they will default to
 /* mask of the bit at STINR to check end of conversion */
 #define ADQ12B_EOC 0x20
 
-#define TIMEOUT20
-
 /* available ranges through the PGA gains */
 static const struct comedi_lrange range_adq12b_ai_bipolar = {
4, {
@@ -122,19 +120,28 @@ struct adq12b_private {
int last_range;
 };
 
-/*
- * "instructions" read/write data in "one-shot" or "software-triggered"
- * mode.
- */
+static int adq12b_ai_eoc(struct comedi_device *dev,
+struct comedi_subdevice *s,
+struct comedi_insn *insn,
+unsigned long context)
+{
+   unsigned char status;
+
+   status = inb(dev->iobase + ADQ12B_STINR);
+   if (status & ADQ12B_EOC)
+   return 0;
+   return -EBUSY;
+}
 
 static int adq12b_ai_rinsn(struct comedi_device *dev,
   struct comedi_subdevice *s, struct comedi_insn *insn,
   unsigned int *data)
 {
struct adq12b_private *devpriv = dev->private;
-   int n, i;
+   int n;
int range, channel;
unsigned char hi, lo, status;
+   int ret;
 
/* change channel and range only if it is different from the previous */
range = CR_RANGE(insn->chanspec);
@@ -151,13 +158,9 @@ static int adq12b_ai_rinsn(struct comedi_device *dev,
for (n = 0; n < insn->n; n++) {
 
/* wait for end of conversion */
-   i = 0;
-   do {
-   /* udelay(1); */
-   status = inb(dev->iobase + ADQ12B_STINR);
-   status = status & ADQ12B_EOC;
-   } while (status == 0 && ++i < TIMEOUT);
-   /* } while (++i < 10); */
+   ret = comedi_timeout(dev, s, insn, adq12b_ai_eoc, 0);
+   if (ret)
+   return ret;
 
/* read data */
hi = inb(dev->iobase + ADQ12B_ADHIG);
-- 
1.8.5.2

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


[PATCH 35/47 v2] staging: comedi: multiq3: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input end-of-conversion.

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

diff --git a/drivers/staging/comedi/drivers/multiq3.c 
b/drivers/staging/comedi/drivers/multiq3.c
index 3ca755e..b74b9e9 100644
--- a/drivers/staging/comedi/drivers/multiq3.c
+++ b/drivers/staging/comedi/drivers/multiq3.c
@@ -81,34 +81,44 @@ struct multiq3_private {
unsigned int ao_readback[2];
 };
 
+static int multiq3_ai_status(struct comedi_device *dev,
+struct comedi_subdevice *s,
+struct comedi_insn *insn,
+unsigned long context)
+{
+   unsigned int status;
+
+   status = inw(dev->iobase + MULTIQ3_STATUS);
+   if (status & context)
+   return 0;
+   return -EBUSY;
+}
+
 static int multiq3_ai_insn_read(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
 {
-   int i, n;
+   int n;
int chan;
unsigned int hi, lo;
+   int ret;
 
chan = CR_CHAN(insn->chanspec);
outw(MULTIQ3_CONTROL_MUST | MULTIQ3_AD_MUX_EN | (chan << 3),
 dev->iobase + MULTIQ3_CONTROL);
 
-   for (i = 0; i < MULTIQ3_TIMEOUT; i++) {
-   if (inw(dev->iobase + MULTIQ3_STATUS) & MULTIQ3_STATUS_EOC)
-   break;
-   }
-   if (i == MULTIQ3_TIMEOUT)
-   return -ETIMEDOUT;
+   ret = comedi_timeout(dev, s, insn, multiq3_ai_status,
+MULTIQ3_STATUS_EOC);
+   if (ret)
+   return ret;
 
for (n = 0; n < insn->n; n++) {
outw(0, dev->iobase + MULTIQ3_AD_CS);
-   for (i = 0; i < MULTIQ3_TIMEOUT; i++) {
-   if (inw(dev->iobase +
-   MULTIQ3_STATUS) & MULTIQ3_STATUS_EOC_I)
-   break;
-   }
-   if (i == MULTIQ3_TIMEOUT)
-   return -ETIMEDOUT;
+
+   ret = comedi_timeout(dev, s, insn, multiq3_ai_status,
+MULTIQ3_STATUS_EOC_I);
+   if (ret)
+   return ret;
 
hi = inb(dev->iobase + MULTIQ3_AD_CS);
lo = inb(dev->iobase + MULTIQ3_AD_CS);
-- 
1.8.5.2

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


[PATCH 12/47 v2] staging: comedi: dt2815: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog output end-of-conversion.

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

diff --git a/drivers/staging/comedi/drivers/dt2815.c 
b/drivers/staging/comedi/drivers/dt2815.c
index ee24717..1ab1dd7 100644
--- a/drivers/staging/comedi/drivers/dt2815.c
+++ b/drivers/staging/comedi/drivers/dt2815.c
@@ -67,15 +67,17 @@ struct dt2815_private {
unsigned int ao_readback[8];
 };
 
-static int dt2815_wait_for_status(struct comedi_device *dev, int status)
+static int dt2815_ao_status(struct comedi_device *dev,
+   struct comedi_subdevice *s,
+   struct comedi_insn *insn,
+   unsigned long context)
 {
-   int i;
+   unsigned int status;
 
-   for (i = 0; i < 100; i++) {
-   if (inb(dev->iobase + DT2815_STATUS) == status)
-   break;
-   }
-   return status;
+   status = inb(dev->iobase + DT2815_STATUS);
+   if (status == context)
+   return 0;
+   return -EBUSY;
 }
 
 static int dt2815_ao_insn_read(struct comedi_device *dev,
@@ -98,30 +100,31 @@ static int dt2815_ao_insn(struct comedi_device *dev, 
struct comedi_subdevice *s,
struct dt2815_private *devpriv = dev->private;
int i;
int chan = CR_CHAN(insn->chanspec);
-   unsigned int status;
unsigned int lo, hi;
+   int ret;
 
for (i = 0; i < insn->n; i++) {
lo = ((data[i] & 0x0f) << 4) | (chan << 1) | 0x01;
hi = (data[i] & 0xff0) >> 4;
 
-   status = dt2815_wait_for_status(dev, 0x00);
-   if (status != 0) {
+   ret = comedi_timeout(dev, s, insn, dt2815_ao_status, 0x00);
+   if (ret) {
dev_dbg(dev->class_dev,
-   "failed to write low byte on %d reason %x\n",
-   chan, status);
-   return -EBUSY;
+   "failed to write low byte on %d\n",
+   chan);
+   return ret;
}
 
outb(lo, dev->iobase + DT2815_DATA);
 
-   status = dt2815_wait_for_status(dev, 0x10);
-   if (status != 0x10) {
+   ret = comedi_timeout(dev, s, insn, dt2815_ao_status, 0x10);
+   if (ret) {
dev_dbg(dev->class_dev,
-   "failed to write high byte on %d reason %x\n",
-   chan, status);
-   return -EBUSY;
+   "failed to write high byte on %d\n",
+   chan);
+   return ret;
}
+
devpriv->ao_readback[chan] = data[i];
}
return i;
-- 
1.8.5.2

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


[PATCH 17/47 v2] staging: comedi: cb_pcidas64: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input end-of-conversion.

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

diff --git a/drivers/staging/comedi/drivers/cb_pcidas64.c 
b/drivers/staging/comedi/drivers/cb_pcidas64.c
index 464c783..21e13a5 100644
--- a/drivers/staging/comedi/drivers/cb_pcidas64.c
+++ b/drivers/staging/comedi/drivers/cb_pcidas64.c
@@ -1664,15 +1664,36 @@ static void i2c_write(struct comedi_device *dev, 
unsigned int address,
i2c_stop(dev);
 }
 
+static int cb_pcidas64_ai_eoc(struct comedi_device *dev,
+ struct comedi_subdevice *s,
+ struct comedi_insn *insn,
+ unsigned long context)
+{
+   const struct pcidas64_board *thisboard = comedi_board(dev);
+   struct pcidas64_private *devpriv = dev->private;
+   unsigned int status;
+
+   status = readw(devpriv->main_iobase + HW_STATUS_REG);
+   if (thisboard->layout == LAYOUT_4020) {
+   status = readw(devpriv->main_iobase + ADC_WRITE_PNTR_REG);
+   if (status)
+   return 0;
+   } else {
+   if (pipe_full_bits(status))
+   return 0;
+   }
+   return -EBUSY;
+}
+
 static int ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
 {
const struct pcidas64_board *thisboard = comedi_board(dev);
struct pcidas64_private *devpriv = dev->private;
-   unsigned int bits = 0, n, i;
+   unsigned int bits = 0, n;
unsigned int channel, range, aref;
unsigned long flags;
-   static const int timeout = 100;
+   int ret;
 
channel = CR_CHAN(insn->chanspec);
range = CR_RANGE(insn->chanspec);
@@ -1770,23 +1791,12 @@ static int ai_rinsn(struct comedi_device *dev, struct 
comedi_subdevice *s,
   devpriv->main_iobase + ADC_CONVERT_REG);
 
/*  wait for data */
-   for (i = 0; i < timeout; i++) {
-   bits = readw(devpriv->main_iobase + HW_STATUS_REG);
-   if (thisboard->layout == LAYOUT_4020) {
-   if (readw(devpriv->main_iobase +
- ADC_WRITE_PNTR_REG))
-   break;
-   } else {
-   if (pipe_full_bits(bits))
-   break;
-   }
-   udelay(1);
-   }
-   if (i == timeout) {
+   ret = comedi_timeout(dev, s, insn, cb_pcidas64_ai_eoc, 0);
+   if (ret) {
comedi_error(dev, " analog input read insn timed out");
-   dev_info(dev->class_dev, "status 0x%x\n", bits);
-   return -ETIME;
+   return ret;
}
+
if (thisboard->layout == LAYOUT_4020)
data[n] = readl(devpriv->dio_counter_iobase +
ADC_FIFO_REG) & 0x;
-- 
1.8.5.2

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


[PATCH 09/47 v2] staging: comedi: pcl711: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input end-of-conversion.

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

diff --git a/drivers/staging/comedi/drivers/pcl711.c 
b/drivers/staging/comedi/drivers/pcl711.c
index 6595788..7c03a5d 100644
--- a/drivers/staging/comedi/drivers/pcl711.c
+++ b/drivers/staging/comedi/drivers/pcl711.c
@@ -253,18 +253,17 @@ static void pcl711_set_changain(struct comedi_device *dev,
outb(mux | PCL711_MUX_CHAN(chan), dev->iobase + PCL711_MUX_REG);
 }
 
-static int pcl711_ai_wait_for_eoc(struct comedi_device *dev,
- unsigned int timeout)
+static int pcl711_ai_eoc(struct comedi_device *dev,
+struct comedi_subdevice *s,
+struct comedi_insn *insn,
+unsigned long context)
 {
-   unsigned int msb;
+   unsigned int status;
 
-   while (timeout--) {
-   msb = inb(dev->iobase + PCL711_AI_MSB_REG);
-   if ((msb & PCL711_AI_MSB_DRDY) == 0)
-   return 0;
-   udelay(1);
-   }
-   return -ETIME;
+   status = inb(dev->iobase + PCL711_AI_MSB_REG);
+   if ((status & PCL711_AI_MSB_DRDY) == 0)
+   return 0;
+   return -EBUSY;
 }
 
 static int pcl711_ai_insn_read(struct comedi_device *dev,
@@ -282,7 +281,7 @@ static int pcl711_ai_insn_read(struct comedi_device *dev,
for (i = 0; i < insn->n; i++) {
outb(PCL711_SOFTTRIG, dev->iobase + PCL711_SOFTTRIG_REG);
 
-   ret = pcl711_ai_wait_for_eoc(dev, 100);
+   ret = comedi_timeout(dev, s, insn, pcl711_ai_eoc, 0);
if (ret)
return ret;
 
-- 
1.8.5.2

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


[PATCH 21/47 v2] staging: comedi: dt2811: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input end-of-conversion.

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

diff --git a/drivers/staging/comedi/drivers/dt2811.c 
b/drivers/staging/comedi/drivers/dt2811.c
index 4271903..ba7c2ba 100644
--- a/drivers/staging/comedi/drivers/dt2811.c
+++ b/drivers/staging/comedi/drivers/dt2811.c
@@ -224,23 +224,32 @@ static const struct comedi_lrange *dac_range_types[] = {
&range_unipolar5
 };
 
-#define DT2811_TIMEOUT 5
+static int dt2811_ai_eoc(struct comedi_device *dev,
+struct comedi_subdevice *s,
+struct comedi_insn *insn,
+unsigned long context)
+{
+   unsigned int status;
+
+   status = inb(dev->iobase + DT2811_ADCSR);
+   if ((status & DT2811_ADBUSY) == 0)
+   return 0;
+   return -EBUSY;
+}
 
 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);
-   int timeout = DT2811_TIMEOUT;
+   int ret;
int i;
 
for (i = 0; i < insn->n; i++) {
outb(chan, dev->iobase + DT2811_ADGCR);
 
-   while (timeout
-  && inb(dev->iobase + DT2811_ADCSR) & DT2811_ADBUSY)
-   timeout--;
-   if (!timeout)
-   return -ETIME;
+   ret = comedi_timeout(dev, s, insn, dt2811_ai_eoc, 0);
+   if (ret)
+   return ret;
 
data[i] = inb(dev->iobase + DT2811_ADDATLO);
data[i] |= inb(dev->iobase + DT2811_ADDATHI) << 8;
-- 
1.8.5.2

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


[PATCH 20/47 v2] staging: comedi: das16m1: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input end-of-conversion.

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

diff --git a/drivers/staging/comedi/drivers/das16m1.c 
b/drivers/staging/comedi/drivers/das16m1.c
index fee5fac..a94b7a4 100644
--- a/drivers/staging/comedi/drivers/das16m1.c
+++ b/drivers/staging/comedi/drivers/das16m1.c
@@ -331,14 +331,27 @@ static int das16m1_cancel(struct comedi_device *dev, 
struct comedi_subdevice *s)
return 0;
 }
 
+static int das16m1_ai_eoc(struct comedi_device *dev,
+ struct comedi_subdevice *s,
+ struct comedi_insn *insn,
+ unsigned long context)
+{
+   unsigned int status;
+
+   status = inb(dev->iobase + DAS16M1_CS);
+   if (status & IRQDATA)
+   return 0;
+   return -EBUSY;
+}
+
 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 i, n;
+   int ret;
+   int n;
int byte;
-   const int timeout = 1000;
 
/* disable interrupts and internal pacer */
devpriv->control_state &= ~INTE & ~PACER_MASK;
@@ -356,14 +369,12 @@ static int das16m1_ai_rinsn(struct comedi_device *dev,
/* trigger conversion */
outb(0, dev->iobase);
 
-   for (i = 0; i < timeout; i++) {
-   if (inb(dev->iobase + DAS16M1_CS) & IRQDATA)
-   break;
-   }
-   if (i == timeout) {
+   ret = comedi_timeout(dev, s, insn, das16m1_ai_eoc, 0);
+   if (ret) {
comedi_error(dev, "timeout");
-   return -ETIME;
+   return ret;
}
+
data[n] = munge_sample(inw(dev->iobase));
}
 
-- 
1.8.5.2

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


[PATCH 06/47 v2] staging: comedi: ii_pci20kc: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input end-of-conversion.

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

diff --git a/drivers/staging/comedi/drivers/ii_pci20kc.c 
b/drivers/staging/comedi/drivers/ii_pci20kc.c
index 858..3558ab3 100644
--- a/drivers/staging/comedi/drivers/ii_pci20kc.c
+++ b/drivers/staging/comedi/drivers/ii_pci20kc.c
@@ -190,20 +190,18 @@ static int ii20k_ao_insn_write(struct comedi_device *dev,
return insn->n;
 }
 
-static int ii20k_ai_wait_eoc(struct comedi_device *dev,
-struct comedi_subdevice *s,
-int timeout)
+static int ii20k_ai_eoc(struct comedi_device *dev,
+   struct comedi_subdevice *s,
+   struct comedi_insn *insn,
+   unsigned long context)
 {
void __iomem *iobase = ii20k_module_iobase(dev, s);
unsigned char status;
 
-   do {
-   status = readb(iobase + II20K_AI_STATUS_REG);
-   if ((status & II20K_AI_STATUS_INT) == 0)
-   return 0;
-   } while (timeout--);
-
-   return -ETIME;
+   status = readb(iobase + II20K_AI_STATUS_REG);
+   if ((status & II20K_AI_STATUS_INT) == 0)
+   return 0;
+   return -EBUSY;
 }
 
 static void ii20k_ai_setup(struct comedi_device *dev,
@@ -263,7 +261,7 @@ static int ii20k_ai_insn_read(struct comedi_device *dev,
/* generate a software start convert signal */
readb(iobase + II20K_AI_PACER_RESET_REG);
 
-   ret = ii20k_ai_wait_eoc(dev, s, 100);
+   ret = comedi_timeout(dev, s, insn, ii20k_ai_eoc, 0);
if (ret)
return ret;
 
-- 
1.8.5.2

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


[PATCH 23/47 v2] staging: comedi: mpc624: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input end-of-conversion.

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

diff --git a/drivers/staging/comedi/drivers/mpc624.c 
b/drivers/staging/comedi/drivers/mpc624.c
index 59ad839..f770400 100644
--- a/drivers/staging/comedi/drivers/mpc624.c
+++ b/drivers/staging/comedi/drivers/mpc624.c
@@ -142,8 +142,18 @@ static const struct comedi_lrange range_mpc624_bipolar10 = 
{
 }
 };
 
-/* Timeout 200ms */
-#define TIMEOUT 200
+static int mpc624_ai_eoc(struct comedi_device *dev,
+struct comedi_subdevice *s,
+struct comedi_insn *insn,
+unsigned long context)
+{
+   unsigned char status;
+
+   status = inb(dev->iobase + MPC624_ADC);
+   if ((status & MPC624_ADBUSY) == 0)
+   return 0;
+   return -EBUSY;
+}
 
 static int mpc624_ai_rinsn(struct comedi_device *dev,
   struct comedi_subdevice *s, struct comedi_insn *insn,
@@ -152,7 +162,7 @@ static int mpc624_ai_rinsn(struct comedi_device *dev,
struct mpc624_private *devpriv = dev->private;
int n, i;
unsigned long int data_in, data_out;
-   unsigned char ucPort;
+   int ret;
 
/*
 *  WARNING:
@@ -170,15 +180,9 @@ static int mpc624_ai_rinsn(struct comedi_device *dev,
udelay(1);
 
/*  Wait for the conversion to end */
-   for (i = 0; i < TIMEOUT; i++) {
-   ucPort = inb(dev->iobase + MPC624_ADC);
-   if (ucPort & MPC624_ADBUSY)
-   udelay(1000);
-   else
-   break;
-   }
-   if (i == TIMEOUT)
-   return -ETIMEDOUT;
+   ret = comedi_timeout(dev, s, insn, mpc624_ai_eoc, 0);
+   if (ret)
+   return ret;
 
/*  Start reading data */
data_in = 0;
-- 
1.8.5.2

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


[PATCH 00/47 v2] staging: comedi: cleanup the "timeout" loops

2014-02-10 Thread H Hartley Sweeten
Many of the comedi drivers implement a "timeout" loop of some sort in the
analog input (*insn_read) or analog output (*insn_write) functions. Some
of these are just crazy "loop this many times" for some status to change.
There are a couple that could actually deadlock the system if the status
does not occur. Some of the drivers also ignore if a timeout occurs and
proceded normally instead of terminating the instruction.

Introduce a comedi core helper function, comedi_timeout(), that handles
the boilerplate for the timeout. This function will wait up to 1 second
for a driver provided callback to indicate that the wait is complete.

This also changes the errno for all timeouts to -ETIMEDOUT. Some of the
comed drivers are returning -ETIME which isn't appropriate.

Patch 01 introduces the helper function.
Patches 02-45 cleanup the individual drivers.
Patch 46 moves the debug message for a timeout to the core.
Patch 47 cleans up the unnecessary clearing of the returned data when a
timeout occurs.

v2: address issues pointed out by Ian Abbott
1) modify the comedi_tiemout() helper
2) remove the use of comedi_timeout() in the interrupt routines
3) drop the patch to das1800
4) add subdevice number to dev_dbg() timeout messages

H Hartley Sweeten (47):
  staging: comedi: introduce comedi_timeout()
  staging: comedi: skel: use comedi_timeout()
  staging: comedi: adl_pci6208x: use comedi_timeout()
  staging: comedi: das16: use comedi_timeout()
  staging: comedi: das800: use comedi_timeout()
  staging: comedi: ii_pci20kc: use comedi_timeout()
  staging: comedi: mf6x4: use comedi_timeout()
  staging: comedi: ni_labpc: use comedi_timeout()
  staging: comedi: pcl711: use comedi_timeout()
  staging: comedi: pcmad: use comedi_timeout()
  staging: comedi: pcmmio: use comedi_timeout()
  staging: comedi: dt2815: use comedi_timeout()
  staging: comedi: rti800: use comedi_timeout()
  staging: comedi: aio_aio12_8: use comedi_timeout()
  staging: comedi: cb_das16_cs: use comedi_timeout()
  staging: comedi: cb_pcidas: use comedi_timeout()
  staging: comedi: cb_pcidas64: use comedi_timeout()
  staging: comedi: cb_pcimdas: use comedi_timeout()
  staging: comedi: das08: use comedi_timeout()
  staging: comedi: das16m1: use comedi_timeout()
  staging: comedi: dt2811: use comedi_timeout()
  staging: comedi: me_daq: use comedi_timeout()
  staging: comedi: mpc624: use comedi_timeout()
  staging: comedi: s526: use comedi_timeout()
  staging: comedi: addi_apci_3xx: use comedi_timeout()
  staging: comedi: ni_at_a2150: use comedi_timeout()
  staging: comedi: ni_atmio16d: use comedi_timeout()
  staging: comedi: adl_pci9111: use comedi_timeout()
  staging: comedi: adl_pci9118: use comedi_timeout()
  staging: comedi: adv_pci1710: use comedi_timeout()
  staging: comedi: adq12b: use comedi_timeout()
  staging: comedi: amplc_pci230: use comedi_timeout()
  staging: comedi: dyna_pci10xx: use comedi_timeout()
  staging: comedi: icp_multi: use comedi_timeout()
  staging: comedi: multiq3: use comedi_timeout()
  staging: comedi: ni_daq_700: use comedi_timeout()
  staging: comedi: rtd520: use comedi_timeout()
  staging: comedi: s626: use comedi_timeout()
  staging: comedi: dt282x: use comedi_timeout()
  staging: comedi: daqboard2000: use comedi_timeout()
  staging: comedi: pcl812: use comedi_timeout()
  staging: comedi: pcl816: use comedi_timeout()
  staging: comedi: pcl818: use comedi_timeout()
  staging: comedi: dt2814: use comedi_timeout()
  staging: comedi: dmm32at: use comedi_timeout()
  staging: comedi: move (*insn_{read,write}) timeout debug messages to core
  staging: comedi: don't clear 'data' on (*insn_read) timeout

 drivers/staging/comedi/comedi_fops.c|  13 ++-
 drivers/staging/comedi/comedidev.h  |   8 ++
 drivers/staging/comedi/drivers.c|  30 +++
 drivers/staging/comedi/drivers/addi_apci_3xxx.c |  44 --
 drivers/staging/comedi/drivers/adl_pci6208.c|  22 +++--
 drivers/staging/comedi/drivers/adl_pci9111.c|  34 
 drivers/staging/comedi/drivers/adl_pci9118.c|  32 ---
 drivers/staging/comedi/drivers/adq12b.c |  31 +++
 drivers/staging/comedi/drivers/adv_pci1710.c|  36 
 drivers/staging/comedi/drivers/aio_aio12_8.c|  28 ---
 drivers/staging/comedi/drivers/amplc_pci230.c   |  34 
 drivers/staging/comedi/drivers/cb_das16_cs.c|  28 ---
 drivers/staging/comedi/drivers/cb_pcidas.c  |  27 --
 drivers/staging/comedi/drivers/cb_pcidas64.c|  46 +-
 drivers/staging/comedi/drivers/cb_pcimdas.c |  35 
 drivers/staging/comedi/drivers/daqboard2000.c   |  82 +++---
 drivers/staging/comedi/drivers/das08.c  |  28 ---
 drivers/staging/comedi/drivers/das16.c  |  19 ++---
 drivers/staging/comedi/drivers/das16m1.c|  29 ---
 drivers/staging/comedi/drivers/das800.c |  18 ++--
 drivers/staging/comedi/drivers/dmm32at.c|  83 +++

[PATCH 25/47 v2] staging: comedi: addi_apci_3xx: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input and output end-of-
conversions.

This prevents a deadlock condition that could occur by providing a
timeout in case the end-of-conversion does not happen.

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

diff --git a/drivers/staging/comedi/drivers/addi_apci_3xxx.c 
b/drivers/staging/comedi/drivers/addi_apci_3xxx.c
index ceadf8e..88d14a9 100644
--- a/drivers/staging/comedi/drivers/addi_apci_3xxx.c
+++ b/drivers/staging/comedi/drivers/addi_apci_3xxx.c
@@ -434,13 +434,26 @@ static int apci3xxx_ai_setup(struct comedi_device *dev, 
unsigned int chanspec)
return 0;
 }
 
+static int apci3xxx_ai_eoc(struct comedi_device *dev,
+  struct comedi_subdevice *s,
+  struct comedi_insn *insn,
+  unsigned long context)
+{
+   struct apci3xxx_private *devpriv = dev->private;
+   unsigned int status;
+
+   status = readl(devpriv->mmio + 20);
+   if (status & 0x1)
+   return 0;
+   return -EBUSY;
+}
+
 static int apci3xxx_ai_insn_read(struct comedi_device *dev,
 struct comedi_subdevice *s,
 struct comedi_insn *insn,
 unsigned int *data)
 {
struct apci3xxx_private *devpriv = dev->private;
-   unsigned int val;
int ret;
int i;
 
@@ -453,10 +466,9 @@ static int apci3xxx_ai_insn_read(struct comedi_device *dev,
writel(0x8, devpriv->mmio + 8);
 
/* Wait the EOS */
-   do {
-   val = readl(devpriv->mmio + 20);
-   val &= 0x1;
-   } while (!val);
+   ret = comedi_timeout(dev, s, insn, apci3xxx_ai_eoc, 0);
+   if (ret)
+   return ret;
 
/* Read the analog value */
data[i] = readl(devpriv->mmio + 28);
@@ -622,6 +634,20 @@ static int apci3xxx_ai_cancel(struct comedi_device *dev,
return 0;
 }
 
+static int apci3xxx_ao_eoc(struct comedi_device *dev,
+  struct comedi_subdevice *s,
+  struct comedi_insn *insn,
+  unsigned long context)
+{
+   struct apci3xxx_private *devpriv = dev->private;
+   unsigned int status;
+
+   status = readl(devpriv->mmio + 96);
+   if (status & 0x100)
+   return 0;
+   return -EBUSY;
+}
+
 static int apci3xxx_ao_insn_write(struct comedi_device *dev,
  struct comedi_subdevice *s,
  struct comedi_insn *insn,
@@ -630,7 +656,7 @@ static int apci3xxx_ao_insn_write(struct comedi_device *dev,
struct apci3xxx_private *devpriv = dev->private;
unsigned int chan = CR_CHAN(insn->chanspec);
unsigned int range = CR_RANGE(insn->chanspec);
-   unsigned int status;
+   int ret;
int i;
 
for (i = 0; i < insn->n; i++) {
@@ -641,9 +667,9 @@ static int apci3xxx_ao_insn_write(struct comedi_device *dev,
writel((data[i] << 8) | chan, devpriv->mmio + 100);
 
/* Wait the end of transfer */
-   do {
-   status = readl(devpriv->mmio + 96);
-   } while ((status & 0x100) != 0x100);
+   ret = comedi_timeout(dev, s, insn, apci3xxx_ao_eoc, 0);
+   if (ret)
+   return ret;
}
 
return insn->n;
-- 
1.8.5.2

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


[PATCH 07/47 v2] staging: comedi: mf6x4: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input end-of-conversion.

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

diff --git a/drivers/staging/comedi/drivers/mf6x4.c 
b/drivers/staging/comedi/drivers/mf6x4.c
index 81b78e0..a4f7d6f 100644
--- a/drivers/staging/comedi/drivers/mf6x4.c
+++ b/drivers/staging/comedi/drivers/mf6x4.c
@@ -133,21 +133,18 @@ static int mf6x4_do_insn_bits(struct comedi_device *dev,
return insn->n;
 }
 
-static int mf6x4_ai_wait_for_eoc(struct comedi_device *dev,
-unsigned int timeout)
+static int mf6x4_ai_eoc(struct comedi_device *dev,
+   struct comedi_subdevice *s,
+   struct comedi_insn *insn,
+   unsigned long context)
 {
struct mf6x4_private *devpriv = dev->private;
-   unsigned int eolc;
+   unsigned int status;
 
-   while (timeout--) {
-   eolc = ioread32(devpriv->gpioc_R) & MF6X4_GPIOC_EOLC;
-   if (eolc)
-   return 0;
-
-   udelay(1);
-   }
-
-   return -ETIME;
+   status = ioread32(devpriv->gpioc_R);
+   if (status & MF6X4_GPIOC_EOLC)
+   return 0;
+   return -EBUSY;
 }
 
 static int mf6x4_ai_insn_read(struct comedi_device *dev,
@@ -168,7 +165,7 @@ static int mf6x4_ai_insn_read(struct comedi_device *dev,
/* Trigger ADC conversion by reading ADSTART */
ioread16(devpriv->bar1_mem + MF6X4_ADSTART_R);
 
-   ret = mf6x4_ai_wait_for_eoc(dev, 100);
+   ret = comedi_timeout(dev, s, insn, mf6x4_ai_eoc, 0);
if (ret)
return ret;
 
-- 
1.8.5.2

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


[PATCH 01/47 v2] staging: comedi: introduce comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Introduce a comedi core helper function to handle the boilerplate
needed by the drivers to busy- wait for a condition to occur.
Typically this condition is the analog input/output end-of-conversion
used with the comedi (*insn_read) and (*insn_write) operations.

To use this function, the drivers just need to provide a callback
that checks for the desired condition. The callback should return
0 if the condition is met or -EBUSY if it is still waiting. Any
other errno will be returned to the caller. If the timeout occurs
before the condition is met -ETIMEDOUT will be returned.

The parameters to the callback function are the comedi_device,
comedi_subdevice, and comedi_insn pointers that were passed to the
(*insn_read) or (*insn_write) as well as an unsigned long, driver
specific, 'context' that can be used to pass any other information
that might be needed in the callback. This 'context' could be anything
such as the register offset to read the status or the bits needed
to check the status. The comedi_timeout() function itself does not
use any of these parameters.

This will help remove all the crazy "wait this many loops" used by
some of the drivers. It also creates a common errno for comedi to
detect when a timeout occurs.

ADC/DAC conversion times are typically pretty fast, usually around
100K samples/sec (10 usec). A conservative timeout of 1 second is used
in comedi_timeout().

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/comedidev.h |  8 
 drivers/staging/comedi/drivers.c   | 30 ++
 2 files changed, 38 insertions(+)

diff --git a/drivers/staging/comedi/comedidev.h 
b/drivers/staging/comedi/comedidev.h
index f82bd42..f36bf3e 100644
--- a/drivers/staging/comedi/comedidev.h
+++ b/drivers/staging/comedi/comedidev.h
@@ -353,6 +353,14 @@ void comedi_buf_memcpy_from(struct comedi_async *async, 
unsigned int offset,
 
 /* drivers.c - general comedi driver functions */
 
+#define COMEDI_TIMEOUT_MS  1000
+
+int comedi_timeout(struct comedi_device *, struct comedi_subdevice *,
+  struct comedi_insn *,
+  int (*cb)(struct comedi_device *, struct comedi_subdevice *,
+struct comedi_insn *, unsigned long context),
+  unsigned long context);
+
 int comedi_dio_insn_config(struct comedi_device *, struct comedi_subdevice *,
   struct comedi_insn *, unsigned int *data,
   unsigned int mask);
diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c
index 5b15033..ab0e8ed 100644
--- a/drivers/staging/comedi/drivers.c
+++ b/drivers/staging/comedi/drivers.c
@@ -155,6 +155,36 @@ int insn_inval(struct comedi_device *dev, struct 
comedi_subdevice *s,
 }
 
 /**
+ * comedi_timeout() - busy-wait for a driver condition to occur.
+ * @dev: comedi_device struct
+ * @s: comedi_subdevice struct
+ * @insn: comedi_insn struct
+ * @cb: callback to check for the condition
+ * @context: private context from the driver
+ */
+int comedi_timeout(struct comedi_device *dev,
+  struct comedi_subdevice *s,
+  struct comedi_insn *insn,
+  int (*cb)(struct comedi_device *dev,
+struct comedi_subdevice *s,
+struct comedi_insn *insn,
+unsigned long context),
+  unsigned long context)
+{
+   unsigned long timeout = jiffies + msecs_to_jiffies(COMEDI_TIMEOUT_MS);
+   int ret;
+
+   while (time_before(jiffies, timeout)) {
+   ret = cb(dev, s, insn, context);
+   if (ret != -EBUSY)
+   return ret; /* success (0) or non EBUSY errno */
+   cpu_relax();
+   }
+   return -ETIMEDOUT;
+}
+EXPORT_SYMBOL_GPL(comedi_timeout);
+
+/**
  * comedi_dio_insn_config() - boilerplate (*insn_config) for DIO subdevices.
  * @dev: comedi_device struct
  * @s: comedi_subdevice struct
-- 
1.8.5.2

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


[PATCH 08/47 v2] staging: comedi: ni_labpc: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input end-of-conversion.

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

diff --git a/drivers/staging/comedi/drivers/ni_labpc.c 
b/drivers/staging/comedi/drivers/ni_labpc.c
index 0512445..037b46e 100644
--- a/drivers/staging/comedi/drivers/ni_labpc.c
+++ b/drivers/staging/comedi/drivers/ni_labpc.c
@@ -73,7 +73,6 @@
 #include "ni_labpc_isadma.h"
 
 #define LABPC_SIZE 0x20/* size of ISA io region */
-#define LABPC_ADC_TIMEOUT  1000
 
 enum scan_mode {
MODE_SINGLE_CHAN,
@@ -308,19 +307,17 @@ static void labpc_clear_adc_fifo(struct comedi_device 
*dev)
labpc_read_adc_fifo(dev);
 }
 
-static int labpc_ai_wait_for_data(struct comedi_device *dev,
- int timeout)
+static int labpc_ai_eoc(struct comedi_device *dev,
+   struct comedi_subdevice *s,
+   struct comedi_insn *insn,
+   unsigned long context)
 {
struct labpc_private *devpriv = dev->private;
-   int i;
 
-   for (i = 0; i < timeout; i++) {
-   devpriv->stat1 = devpriv->read_byte(dev->iobase + STAT1_REG);
-   if (devpriv->stat1 & STAT1_DAVAIL)
-   return 0;
-   udelay(1);
-   }
-   return -ETIME;
+   devpriv->stat1 = devpriv->read_byte(dev->iobase + STAT1_REG);
+   if (devpriv->stat1 & STAT1_DAVAIL)
+   return 0;
+   return -EBUSY;
 }
 
 static int labpc_ai_insn_read(struct comedi_device *dev,
@@ -363,7 +360,7 @@ static int labpc_ai_insn_read(struct comedi_device *dev,
/* trigger conversion */
devpriv->write_byte(0x1, dev->iobase + ADC_START_CONVERT_REG);
 
-   ret = labpc_ai_wait_for_data(dev, LABPC_ADC_TIMEOUT);
+   ret = comedi_timeout(dev, s, insn, labpc_ai_eoc, 0);
if (ret)
return ret;
 
-- 
1.8.5.2

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


[PATCH 29/47 v2] staging: comedi: adl_pci9118: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input end-of-conversion.

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

diff --git a/drivers/staging/comedi/drivers/adl_pci9118.c 
b/drivers/staging/comedi/drivers/adl_pci9118.c
index ef5afdb..6492bd8 100644
--- a/drivers/staging/comedi/drivers/adl_pci9118.c
+++ b/drivers/staging/comedi/drivers/adl_pci9118.c
@@ -571,12 +571,26 @@ static int setup_channel_list(struct comedi_device *dev,
return 1;   /* we can serve this with scan logic */
 }
 
+static int pci9118_ai_eoc(struct comedi_device *dev,
+ struct comedi_subdevice *s,
+ struct comedi_insn *insn,
+ unsigned long context)
+{
+   unsigned int status;
+
+   status = inl(dev->iobase + PCI9118_ADSTAT);
+   if (status & AdStatus_ADrdy)
+   return 0;
+   return -EBUSY;
+}
+
 static int pci9118_insn_read_ai(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
 {
struct pci9118_private *devpriv = dev->private;
-   int n, timeout;
+   int ret;
+   int n;
 
devpriv->AdControlReg = AdControl_Int & 0xff;
devpriv->AdFunctionReg = AdFunction_PDTrg | AdFunction_PETrg;
@@ -597,19 +611,15 @@ static int pci9118_insn_read_ai(struct comedi_device *dev,
for (n = 0; n < insn->n; n++) {
outw(0, dev->iobase + PCI9118_SOFTTRG); /* start conversion */
udelay(2);
-   timeout = 100;
-   while (timeout--) {
-   if (inl(dev->iobase + PCI9118_ADSTAT) & AdStatus_ADrdy)
-   goto conv_finish;
-   udelay(1);
-   }
 
-   comedi_error(dev, "A/D insn timeout");
-   data[n] = 0;
-   outl(0, dev->iobase + PCI9118_DELFIFO); /* flush FIFO */
-   return -ETIME;
+   ret = comedi_timeout(dev, s, insn, pci9118_ai_eoc, 0);
+   if (ret) {
+   comedi_error(dev, "A/D insn timeout");
+   data[n] = 0;
+   outl(0, dev->iobase + PCI9118_DELFIFO); /* flush FIFO */
+   return ret;
+   }
 
-conv_finish:
if (devpriv->ai16bits) {
data[n] =
(inl(dev->iobase +
-- 
1.8.5.2

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


[PATCH 03/47 v2] staging: comedi: adl_pci6208x: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog output end-of-conversion.

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

diff --git a/drivers/staging/comedi/drivers/adl_pci6208.c 
b/drivers/staging/comedi/drivers/adl_pci6208.c
index 5c1413a..921f694 100644
--- a/drivers/staging/comedi/drivers/adl_pci6208.c
+++ b/drivers/staging/comedi/drivers/adl_pci6208.c
@@ -73,19 +73,17 @@ struct pci6208_private {
unsigned int ao_readback[PCI6208_MAX_AO_CHANNELS];
 };
 
-static int pci6208_ao_wait_for_data_send(struct comedi_device *dev,
-unsigned int timeout)
+static int pci6208_ao_eoc(struct comedi_device *dev,
+ struct comedi_subdevice *s,
+ struct comedi_insn *insn,
+ unsigned long context)
 {
unsigned int status;
 
-   while (timeout--) {
-   status = inw(dev->iobase + PCI6208_AO_STATUS);
-   if ((status & PCI6208_AO_STATUS_DATA_SEND) == 0)
-   return 0;
-   udelay(1);
-   }
-
-   return -ETIME;
+   status = inw(dev->iobase + PCI6208_AO_STATUS);
+   if ((status & PCI6208_AO_STATUS_DATA_SEND) == 0)
+   return 0;
+   return -EBUSY;
 }
 
 static int pci6208_ao_insn_write(struct comedi_device *dev,
@@ -102,8 +100,8 @@ static int pci6208_ao_insn_write(struct comedi_device *dev,
for (i = 0; i < insn->n; i++) {
val = data[i];
 
-   /* D/A transfer rate is 2.2us, wait up to 10us */
-   ret = pci6208_ao_wait_for_data_send(dev, 10);
+   /* D/A transfer rate is 2.2us */
+   ret = comedi_timeout(dev, s, insn, pci6208_ao_eoc, 0);
if (ret)
return ret;
 
-- 
1.8.5.2

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


[PATCH 33/47 v2] staging: comedi: dyna_pci10xx: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input end-of-conversion.

Also, remove some unnecessary comments.

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

diff --git a/drivers/staging/comedi/drivers/dyna_pci10xx.c 
b/drivers/staging/comedi/drivers/dyna_pci10xx.c
index 6915732..6d03b8f 100644
--- a/drivers/staging/comedi/drivers/dyna_pci10xx.c
+++ b/drivers/staging/comedi/drivers/dyna_pci10xx.c
@@ -57,18 +57,27 @@ struct dyna_pci10xx_private {
unsigned long BADR3;
 };
 
-/**/
-/** READ WRITE FUNCTIONS 
**/
-/**/
+static int dyna_pci10xx_ai_eoc(struct comedi_device *dev,
+  struct comedi_subdevice *s,
+  struct comedi_insn *insn,
+  unsigned long context)
+{
+   unsigned int status;
+
+   status = inw_p(dev->iobase);
+   if (status & (1 << 15))
+   return 0;
+   return -EBUSY;
+}
 
-/* analog input callback */
 static int dyna_pci10xx_insn_read_ai(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
 {
struct dyna_pci10xx_private *devpriv = dev->private;
-   int n, counter;
+   int n;
u16 d = 0;
+   int ret = 0;
unsigned int chan, range;
 
/* get the channel number and range */
@@ -82,18 +91,17 @@ static int dyna_pci10xx_insn_read_ai(struct comedi_device 
*dev,
smp_mb();
outw_p(0x + range + chan, dev->iobase + 2);
udelay(10);
-   /* read data */
-   for (counter = 0; counter < READ_TIMEOUT; counter++) {
-   d = inw_p(dev->iobase);
 
-   /* check if read is successful if the EOC bit is set */
-   if (d & (1 << 15))
-   goto conv_finish;
+   ret = comedi_timeout(dev, s, insn, dyna_pci10xx_ai_eoc, 0);
+   if (ret) {
+   data[n] = 0;
+   dev_dbg(dev->class_dev,
+   "timeout reading analog input\n");
+   break;
}
-   data[n] = 0;
-   dev_dbg(dev->class_dev, "timeout reading analog input\n");
-   continue;
-conv_finish:
+
+   /* read data */
+   d = inw_p(dev->iobase);
/* mask the first 4 bits - EOC bits */
d &= 0x0FFF;
data[n] = d;
@@ -101,7 +109,7 @@ conv_finish:
mutex_unlock(&devpriv->mutex);
 
/* return the number of samples read/written */
-   return n;
+   return ret ? ret : n;
 }
 
 /* analog output callback */
-- 
1.8.5.2

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


[PATCH 16/47 v2] staging: comedi: cb_pcidas: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input end-of-conversion.

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

diff --git a/drivers/staging/comedi/drivers/cb_pcidas.c 
b/drivers/staging/comedi/drivers/cb_pcidas.c
index 69fbda7..7d068eb 100644
--- a/drivers/staging/comedi/drivers/cb_pcidas.c
+++ b/drivers/staging/comedi/drivers/cb_pcidas.c
@@ -376,6 +376,20 @@ static inline unsigned int cal_enable_bits(struct 
comedi_device *dev)
return CAL_EN_BIT | CAL_SRC_BITS(devpriv->calibration_source);
 }
 
+static int cb_pcidas_ai_eoc(struct comedi_device *dev,
+   struct comedi_subdevice *s,
+   struct comedi_insn *insn,
+   unsigned long context)
+{
+   struct cb_pcidas_private *devpriv = dev->private;
+   unsigned int status;
+
+   status = inw(devpriv->control_status + ADCMUX_CONT);
+   if (status & EOC)
+   return 0;
+   return -EBUSY;
+}
+
 static int cb_pcidas_ai_rinsn(struct comedi_device *dev,
  struct comedi_subdevice *s,
  struct comedi_insn *insn, unsigned int *data)
@@ -385,7 +399,8 @@ static int cb_pcidas_ai_rinsn(struct comedi_device *dev,
unsigned int range = CR_RANGE(insn->chanspec);
unsigned int aref = CR_AREF(insn->chanspec);
unsigned int bits;
-   int n, i;
+   int ret;
+   int n;
 
/* enable calibration input if appropriate */
if (insn->chanspec & CR_ALT_SOURCE) {
@@ -415,13 +430,9 @@ static int cb_pcidas_ai_rinsn(struct comedi_device *dev,
outw(0, devpriv->adc_fifo + ADCDATA);
 
/* wait for conversion to end */
-   /* return -ETIMEDOUT if there is a timeout */
-   for (i = 0; i < 1; i++) {
-   if (inw(devpriv->control_status + ADCMUX_CONT) & EOC)
-   break;
-   }
-   if (i == 1)
-   return -ETIMEDOUT;
+   ret = comedi_timeout(dev, s, insn, cb_pcidas_ai_eoc, 0);
+   if (ret)
+   return ret;
 
/* read data */
data[n] = inw(devpriv->adc_fifo + ADCDATA);
-- 
1.8.5.2

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


[PATCH 14/47 v2] staging: comedi: aio_aio12_8: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input end-of-conversion.

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

diff --git a/drivers/staging/comedi/drivers/aio_aio12_8.c 
b/drivers/staging/comedi/drivers/aio_aio12_8.c
index e2a9177..3f994ed 100644
--- a/drivers/staging/comedi/drivers/aio_aio12_8.c
+++ b/drivers/staging/comedi/drivers/aio_aio12_8.c
@@ -101,14 +101,27 @@ struct aio12_8_private {
unsigned int ao_readback[4];
 };
 
+static int aio_aio12_8_ai_eoc(struct comedi_device *dev,
+ struct comedi_subdevice *s,
+ struct comedi_insn *insn,
+ unsigned long context)
+{
+   unsigned int status;
+
+   status = inb(dev->iobase + AIO12_8_STATUS_REG);
+   if (status & AIO12_8_STATUS_ADC_EOC)
+   return 0;
+   return -EBUSY;
+}
+
 static int aio_aio12_8_ai_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);
-   unsigned int val;
unsigned char control;
+   int ret;
int n;
 
/*
@@ -122,20 +135,15 @@ static int aio_aio12_8_ai_read(struct comedi_device *dev,
inb(dev->iobase + AIO12_8_STATUS_REG);
 
for (n = 0; n < insn->n; n++) {
-   int timeout = 5;
-
/*  Setup and start conversion */
outb(control, dev->iobase + AIO12_8_ADC_REG);
 
/*  Wait for conversion to complete */
-   do {
-   val = inb(dev->iobase + AIO12_8_STATUS_REG);
-   timeout--;
-   if (timeout == 0) {
-   dev_err(dev->class_dev, "ADC timeout\n");
-   return -ETIMEDOUT;
-   }
-   } while (!(val & AIO12_8_STATUS_ADC_EOC));
+   ret = comedi_timeout(dev, s, insn, aio_aio12_8_ai_eoc, 0);
+   if (ret) {
+   dev_err(dev->class_dev, "ADC timeout\n");
+   return ret;
+   }
 
data[n] = inw(dev->iobase + AIO12_8_ADC_REG) & s->maxdata;
}
-- 
1.8.5.2

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


[PATCH 02/47 v2] staging: comedi: skel: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input end-of-conversion.

Since this is the sample skeleton driver, add comments about how the
callback function works with comedi_timeout().

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

diff --git a/drivers/staging/comedi/drivers/skel.c 
b/drivers/staging/comedi/drivers/skel.c
index e800e73..a493368 100644
--- a/drivers/staging/comedi/drivers/skel.c
+++ b/drivers/staging/comedi/drivers/skel.c
@@ -142,6 +142,29 @@ static int skel_ns_to_timer(unsigned int *ns, int round)
 }
 
 /*
+ * This function doesn't require a particular form, this is just
+ * what happens to be used in some of the drivers. The comedi_timeout()
+ * helper uses this callback to check for the end-of-conversion while
+ * waiting for up to 1 second. This function should return 0 when the
+ * conversion is finished and -EBUSY to keep waiting. Any other errno
+ * will terminate comedi_timeout() and return that errno to the caller.
+ * If the timeout occurs, comedi_timeout() will return -ETIMEDOUT.
+ */
+static int skel_ai_eoc(struct comedi_device *dev,
+  struct comedi_subdevice *s,
+  struct comedi_insn *insn,
+  unsigned long context)
+{
+   unsigned int status;
+
+   /* status = inb(dev->iobase + SKEL_STATUS); */
+   status = 1;
+   if (status)
+   return 0;
+   return -EBUSY;
+}
+
+/*
  * "instructions" read/write data in "one-shot" or "software-triggered"
  * mode.
  */
@@ -149,9 +172,9 @@ static int skel_ai_rinsn(struct comedi_device *dev, struct 
comedi_subdevice *s,
 struct comedi_insn *insn, unsigned int *data)
 {
const struct skel_board *thisboard = comedi_board(dev);
-   int n, i;
+   int n;
unsigned int d;
-   unsigned int status;
+   int ret;
 
/* a typical programming sequence */
 
@@ -165,17 +188,11 @@ static int skel_ai_rinsn(struct comedi_device *dev, 
struct comedi_subdevice *s,
/* trigger conversion */
/* outw(0,dev->iobase + SKEL_CONVERT); */
 
-#define TIMEOUT 100
/* wait for conversion to end */
-   for (i = 0; i < TIMEOUT; i++) {
-   status = 1;
-   /* status = inb(dev->iobase + SKEL_STATUS); */
-   if (status)
-   break;
-   }
-   if (i == TIMEOUT) {
+   ret = comedi_timeout(dev, s, insn, skel_ai_eoc, 0);
+   if (ret) {
dev_warn(dev->class_dev, "ai timeout\n");
-   return -ETIMEDOUT;
+   return ret;
}
 
/* read data */
-- 
1.8.5.2

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


[PATCH 19/47 v2] staging: comedi: das08: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input end-of-conversion.

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

diff --git a/drivers/staging/comedi/drivers/das08.c 
b/drivers/staging/comedi/drivers/das08.c
index 3c0e458..b991631 100644
--- a/drivers/staging/comedi/drivers/das08.c
+++ b/drivers/staging/comedi/drivers/das08.c
@@ -201,17 +201,29 @@ static const int *const das08_gainlists[] = {
das08_pgm_gainlist,
 };
 
-#define TIMEOUT 10
+static int das08_ai_eoc(struct comedi_device *dev,
+   struct comedi_subdevice *s,
+   struct comedi_insn *insn,
+   unsigned long context)
+{
+   unsigned int status;
+
+   status = inb(dev->iobase + DAS08_STATUS);
+   if ((status & DAS08_EOC) == 0)
+   return 0;
+   return -EBUSY;
+}
 
 static int das08_ai_rinsn(struct comedi_device *dev, struct comedi_subdevice 
*s,
  struct comedi_insn *insn, unsigned int *data)
 {
const struct das08_board_struct *thisboard = comedi_board(dev);
struct das08_private_struct *devpriv = dev->private;
-   int i, n;
+   int n;
int chan;
int range;
int lsb, msb;
+   int ret;
 
chan = CR_CHAN(insn->chanspec);
range = CR_RANGE(insn->chanspec);
@@ -244,14 +256,12 @@ static int das08_ai_rinsn(struct comedi_device *dev, 
struct comedi_subdevice *s,
/* trigger conversion */
outb_p(0, dev->iobase + DAS08_TRIG_12BIT);
 
-   for (i = 0; i < TIMEOUT; i++) {
-   if (!(inb(dev->iobase + DAS08_STATUS) & DAS08_EOC))
-   break;
-   }
-   if (i == TIMEOUT) {
+   ret = comedi_timeout(dev, s, insn, das08_ai_eoc, 0);
+   if (ret) {
dev_err(dev->class_dev, "timeout\n");
-   return -ETIME;
+   return ret;
}
+
msb = inb(dev->iobase + DAS08_MSB);
lsb = inb(dev->iobase + DAS08_LSB);
if (thisboard->ai_encoding == das08_encode12) {
-- 
1.8.5.2

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


[PATCH 10/47 v2] staging: comedi: pcmad: use comedi_timeout()

2014-02-10 Thread H Hartley Sweeten
Use comedi_timeout() to wait for the analog input end-of-conversion.

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

diff --git a/drivers/staging/comedi/drivers/pcmad.c 
b/drivers/staging/comedi/drivers/pcmad.c
index fe482fd..87c61d9b 100644
--- a/drivers/staging/comedi/drivers/pcmad.c
+++ b/drivers/staging/comedi/drivers/pcmad.c
@@ -61,18 +61,17 @@ static const struct pcmad_board_struct pcmad_boards[] = {
},
 };
 
-#define TIMEOUT100
-
-static int pcmad_ai_wait_for_eoc(struct comedi_device *dev,
-int timeout)
+static int pcmad_ai_eoc(struct comedi_device *dev,
+   struct comedi_subdevice *s,
+   struct comedi_insn *insn,
+   unsigned long context)
 {
-   int i;
+   unsigned int status;
 
-   for (i = 0; i < timeout; i++) {
-   if ((inb(dev->iobase + PCMAD_STATUS) & 0x3) == 0x3)
-   return 0;
-   }
-   return -ETIME;
+   status = inb(dev->iobase + PCMAD_STATUS);
+   if ((status & 0x3) == 0x3)
+   return 0;
+   return -EBUSY;
 }
 
 static int pcmad_ai_insn_read(struct comedi_device *dev,
@@ -89,7 +88,7 @@ static int pcmad_ai_insn_read(struct comedi_device *dev,
for (i = 0; i < insn->n; i++) {
outb(chan, dev->iobase + PCMAD_CONVERT);
 
-   ret = pcmad_ai_wait_for_eoc(dev, TIMEOUT);
+   ret = comedi_timeout(dev, s, insn, pcmad_ai_eoc, 0);
if (ret)
return ret;
 
-- 
1.8.5.2

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


[PATCH]staging: slicoss: Fix possible reuse of freed memory in timer function

2014-02-10 Thread Kirill Tkhai
Do not call kfree() till timer function is finished.

[This was found using grep. Compiled tested only]

Signed-off-by: Kirill Tkhai 
CC: Joe Perches 
CC: Greg Kroah-Hartman 

---
 drivers/staging/slicoss/slicoss.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/staging/slicoss/slicoss.c
b/drivers/staging/slicoss/slicoss.c
index 1426ca4..e0de497 100644
--- a/drivers/staging/slicoss/slicoss.c
+++ b/drivers/staging/slicoss/slicoss.c
@@ -2970,7 +2970,7 @@ static void slic_card_cleanup(struct sliccard *card)
 {
if (card->loadtimerset) {
card->loadtimerset = 0;
-   del_timer(&card->loadtimer);
+   del_timer_sync(&card->loadtimer);
}

slic_debug_card_destroy(card);
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


RE: [PATCH net] hyperv: Fix the carrier status setting

2014-02-10 Thread Haiyang Zhang


> -Original Message-
> From: Dan Carpenter [mailto:dan.carpen...@oracle.com]
> Sent: Monday, February 10, 2014 4:04 AM
> To: Haiyang Zhang
> Cc: da...@davemloft.net; net...@vger.kernel.org; o...@aepfle.de;
> jasow...@redhat.com; driverdev-devel@linuxdriverproject.org; linux-
> ker...@vger.kernel.org
> Subject: Re: [PATCH net] hyperv: Fix the carrier status setting
> 
> On Sun, Feb 09, 2014 at 05:07:58PM -0800, Haiyang Zhang wrote:
> > Signed-off-by: Haiyang Zhang 
> > Reviewed-by: K. Y. Srinivasan 
> 
> Changelog sucks.  What are the user visible effects of this bug?
> 
Without this patch, the "cat /sys/class/net/ethN/operstate" shows 
"unknown", and "ethtool ethN" shows "Link detected: yes", when VM
boots up with or without vNIC connected. This patch fixed the problem.

I will include the comments.

Thanks,
- Haiyang

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


Re: [PATCH RFC v2 00/35] Second preview of imx-drm cleanup series

2014-02-10 Thread Russell King - ARM Linux
On Mon, Feb 10, 2014 at 06:37:26PM +0100, Philipp Zabel wrote:
> I'd like all of them to go through, too. If you don't want to have the DT
> changes integrated, I'd appreciate if you could have a  look at my
> patches on top of your series and possibly append them to your
> series or let me synchronize somehow:
> 
> http://archive.arm.linux.org.uk/lurker/message/20140106.145159.a1d82ba9.en.html

I replied to your 2nd patch there...

I'm not happy ending up with a hard dependency between v4l2 code and
code needed for the display side to work, especially when we can end
up with imx-drm being the primary console display.  I've outlined my
thoughts about what I think needs to happen in the reply to patch 2.

-- 
FTTC broadband for 0.8mile line: 5.8Mbps down 500kbps up.  Estimation
in database were 13.1 to 19Mbit for a good line, about 7.5+ for a bad.
Estimate before purchase was "up to 13.2Mbit".
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


RE: [PATCH net] hyperv: Fix the carrier status setting

2014-02-10 Thread Haiyang Zhang


> -Original Message-
> From: Sergei Shtylyov [mailto:sergei.shtyl...@cogentembedded.com]
> Sent: Monday, February 10, 2014 8:29 AM
> To: Haiyang Zhang; da...@davemloft.net; net...@vger.kernel.org
> Cc: KY Srinivasan; o...@aepfle.de; jasow...@redhat.com; linux-
> ker...@vger.kernel.org; driverdev-devel@linuxdriverproject.org
> Subject: Re: [PATCH net] hyperv: Fix the carrier status setting
> 
> Hello.
> 
> On 10-02-2014 5:07, Haiyang Zhang wrote:
> 
> > Signed-off-by: Haiyang Zhang 
> > Reviewed-by: K. Y. Srinivasan 
> > ---
> >   drivers/net/hyperv/netvsc_drv.c |   24 +++-
> >   1 files changed, 15 insertions(+), 9 deletions(-)
> 
> > diff --git a/drivers/net/hyperv/netvsc_drv.c
> > b/drivers/net/hyperv/netvsc_drv.c index 7756118..836211c 100644
> > --- a/drivers/net/hyperv/netvsc_drv.c
> > +++ b/drivers/net/hyperv/netvsc_drv.c
> [...]
> > @@ -229,15 +238,17 @@ void netvsc_linkstatus_callback(struct hv_device
> *device_obj,
> > struct net_device *net;
> > struct net_device_context *ndev_ctx;
> > struct netvsc_device *net_device;
> > +   struct rndis_device *rdev;
> >
> > net_device = hv_get_drvdata(device_obj);
> > +   rdev = net_device->extension;
> > +
> > +   rdev->link_state = !(status == 1);
> 
> Why not just 'status != 1'?

I will simplify it.
Thanks,
- Haiyang
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH net,v2] hyperv: Fix the carrier status setting

2014-02-10 Thread Haiyang Zhang
Without this patch, the "cat /sys/class/net/ethN/operstate" shows
"unknown", and "ethtool ethN" shows "Link detected: yes", when VM
boots up with or without vNIC connected.

This patch fixed the problem.

Signed-off-by: Haiyang Zhang 
Reviewed-by: K. Y. Srinivasan 
---
 drivers/net/hyperv/netvsc_drv.c |   24 +++-
 1 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index 7756118..18916f7 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -88,8 +88,12 @@ static int netvsc_open(struct net_device *net)
 {
struct net_device_context *net_device_ctx = netdev_priv(net);
struct hv_device *device_obj = net_device_ctx->device_ctx;
+   struct netvsc_device *nvdev;
+   struct rndis_device *rdev;
int ret = 0;
 
+   netif_carrier_off(net);
+
/* Open up the device */
ret = rndis_filter_open(device_obj);
if (ret != 0) {
@@ -99,6 +103,11 @@ static int netvsc_open(struct net_device *net)
 
netif_start_queue(net);
 
+   nvdev = hv_get_drvdata(device_obj);
+   rdev = nvdev->extension;
+   if (!rdev->link_state)
+   netif_carrier_on(net);
+
return ret;
 }
 
@@ -229,15 +238,17 @@ void netvsc_linkstatus_callback(struct hv_device 
*device_obj,
struct net_device *net;
struct net_device_context *ndev_ctx;
struct netvsc_device *net_device;
+   struct rndis_device *rdev;
 
net_device = hv_get_drvdata(device_obj);
+   rdev = net_device->extension;
+
+   rdev->link_state = status != 1;
+
net = net_device->ndev;
 
-   if (!net) {
-   netdev_err(net, "got link status but net device "
-   "not initialized yet\n");
+   if (!net || net->reg_state != NETREG_REGISTERED)
return;
-   }
 
if (status == 1) {
netif_carrier_on(net);
@@ -414,9 +425,6 @@ static int netvsc_probe(struct hv_device *dev,
if (!net)
return -ENOMEM;
 
-   /* Set initial state */
-   netif_carrier_off(net);
-
net_device_ctx = netdev_priv(net);
net_device_ctx->device_ctx = dev;
hv_set_drvdata(dev, net);
@@ -443,8 +451,6 @@ static int netvsc_probe(struct hv_device *dev,
}
memcpy(net->dev_addr, device_info.mac_adr, ETH_ALEN);
 
-   netif_carrier_on(net);
-
ret = register_netdev(net);
if (ret != 0) {
pr_err("Unable to register netdev.\n");
-- 
1.7.4.1

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


Re: [RFC PATCH 2/3] staging: imx-drm-core: Use graph to find connection between crtc and encoder

2014-02-10 Thread Russell King - ARM Linux
On Mon, Jan 06, 2014 at 03:52:01PM +0100, Philipp Zabel wrote:
> @@ -438,24 +453,21 @@ int imx_drm_encoder_parse_of(struct drm_device *drm,
>   struct drm_encoder *encoder, struct device_node *np)
>  {
>   struct imx_drm_device *imxdrm = drm->dev_private;
> + struct device_node *ep, *last_ep = NULL;
>   uint32_t crtc_mask = 0;
>   int i, ret = 0;
>  
>   for (i = 0; !ret; i++) {
> - struct of_phandle_args args;
>   uint32_t mask;
> - int id;
>  
> - ret = of_parse_phandle_with_args(np, "crtcs", "#crtc-cells", i,
> -  &args);
> - if (ret == -ENOENT)
> + ep = v4l2_of_get_next_endpoint(np, last_ep);
> + if (last_ep)
> + of_node_put(last_ep);
> + if (!ep)
>   break;
> - if (ret < 0)
> - return ret;
>  
> - id = args.args_count > 0 ? args.args[0] : 0;
> - mask = imx_drm_find_crtc_mask(imxdrm, args.np, id);
> - of_node_put(args.np);
> + /* CSI */
> + mask = imx_drm_find_crtc_mask(imxdrm, ep);
>  
>   /*
>* If we failed to find the CRTC(s) which this encoder is
> @@ -463,12 +475,20 @@ int imx_drm_encoder_parse_of(struct drm_device *drm,
>* not been registered yet.  Defer probing, and hope that
>* the required CRTC is added later.
>*/
> - if (mask == 0)
> + if (mask == 0) {
> + of_node_put(ep);
>   return -EPROBE_DEFER;
> + }
>  
>   crtc_mask |= mask;
> + last_ep = ep;
>   }
>  
> + if (ep)
> + of_node_put(ep);

Why is this loop soo complicated?  Why do you need to mess around with
this "last_ep" stuff - you don't actually end up using it.

The loop reduces down to this without comments:

for (i = 0; !ret; i++) {
uint32_t mask;

ep = v4l2_of_get_next_endpoint(np, last_ep);
if (!ep)
break;

/* CSI */
mask = imx_drm_find_crtc_mask(imxdrm, ep);
of_node_put(ep);

if (mask == 0)
return -EPROBE_DEFER;

crtc_mask |= mask;
}

Now, here's the big question: why do we want to use v4l2_* here?  We
may want to use this functionality, but if this functionality is going
to be used outside of v4l2, it needs to become something generic, not
v4l2 specific.

Let's think about this for a moment... if we want to build imx-drm into
the kernel, can we do it with modular videodev, or with videodev
completely unconfigured.  We may wish to do this because we have no
videodev requirement on a platform.  Should the build fail because the
v4l2 function isn't there?

So, before we can change this, I think we first need to get agreement
from Mauro to move this function out of V4L2, so that it can be
available independently of V4L2.

-- 
FTTC broadband for 0.8mile line: 5.8Mbps down 500kbps up.  Estimation
in database were 13.1 to 19Mbit for a good line, about 7.5+ for a bad.
Estimate before purchase was "up to 13.2Mbit".
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH RFC v2 00/35] Second preview of imx-drm cleanup series

2014-02-10 Thread Jean-Francois Moine
On Mon, 10 Feb 2014 15:18:21 +
Russell King - ARM Linux  wrote:

> Now, mind explaining what "v4l2 style device tree bindings" means?  I've
> no idea since I'm relatively new to DT.

Documentation/devicetree/bindings/media/video-interfaces.txt

For the Cubox, I have:

tda998x: hdmi-encoder {
compatible = "nxp,tda998x";
...
port {
tda998x_0: endpoint@0 {
remote-endpoint = <&lcd0_0>;
};
};
};

&lcd0 {
status = "okay";
...
port {
lcd0_0: endpoint@0 {
remote-endpoint = <&tda998x_0>;
};
};
};


-- 
Ken ar c'hentañ | ** Breizh ha Linux atav! **
Jef |   http://moinejf.free.fr/
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] [media] v4l: omap4iss: Remove VIDEO_OMAP4_DEBUG

2014-02-10 Thread Laurent Pinchart
Hi Paul,

On Monday 10 February 2014 16:13:51 Paul Bolle wrote:
> On Mon, 2014-02-10 at 15:13 +0100, Laurent Pinchart wrote:
> > On Sunday 09 February 2014 16:09:37 Paul Bolle wrote:
> > > Commit d632dfefd36f ("[media] v4l: omap4iss: Add support for OMAP4
> > > camera interface - Build system") added a Kconfig entry for
> > > VIDEO_OMAP4_DEBUG. But nothing uses that symbol.
> > > 
> > > This entry was apparently copied from a similar entry for "OMAP 3
> > > Camera debug messages". But a corresponding Makefile line is missing.
> > > Besides, the debug code also depends on a mysterious ISS_ISR_DEBUG
> > > macro. This Kconfig entry can be removed.
> > 
> > What about adding the associated Makefile line instead to #define DEBUG
> > when VIDEO_OMAP4_DEBUG is selected, as with the OMAP3 ISP driver ?
> > 
> > > Someone familiar with the code might be able to say what to do with the
> > > code depending on the DEBUG and ISS_ISR_DEBUG macros.
> > 
> > ISS_ISR_DEBUG is expected to be set by manually modifying the source code,
> > as it prints lots of messages in interrupt context.
> 
> Which renders the DEBUG macro pointless. Or does the code use some
> dev_dbg()-like magic, which is only triggered if the DEBUG macro is set?

Yes, dev_dbg() is used.

-- 
Regards,

Laurent Pinchart

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


Re: [PATCH RFC v2 00/35] Second preview of imx-drm cleanup series

2014-02-10 Thread Russell King - ARM Linux
On Mon, Feb 10, 2014 at 04:12:19PM +0100, Philipp Zabel wrote:
> Am Montag, den 10.02.2014, 12:28 + schrieb Russell King - ARM Linux:
> > This is the latest revision of my series cleaning up imx-drm and
> > hopefully getting it ready to be moved out of drivers/staging.
> > This series is updated to v3.14-rc2.
> > 
> > Since the last round of patches were posted, the component support
> > has been merged into mainline, and thus dropped from this series.
> > Greg has taken the first three patches and merged them into his
> > linux-next tree - however, I include them here for completness.
> > 
> > Most of the comments from last time still apply, and I'll look at
> > incorporating some of the other patches that were posted in the
> > coming week.
> > 
> > If I can have some acks for this, I'll start sending some of it to
> >
> >
> > Greg - I'd like to at least get the five or six initial imx-hdmi
> > patches to Greg and queued up for the next merge window sooner
> > rather than later, preferably getting most of this ready for that
> > window too.
> 
> For the first 9 patches up to (including) "imx-drm: ipu-v3: more
> clocking fixes":
> Acked-by: Philipp Zabel 
> 
> As you say, comments about the device tree bindings still apply.
> I'd prefer if the patches that currently use the crtcs property were
> reworked to use the v4l2 style device tree bindings before they hit
> mainline.

I'm trying /not/ to do that much more work on this because there's
other things that need my attention, like a complete rewrite of the
SDHCI mess.  I want to get the imx-drm stuff off my plate so I don't
have to worry about it.

So, I'd really like _all_ these patches to go into mainline for v3.15
with the least rework possible so I can spend the next few months
working on rewriting SDHCI.

What I don't want is carrying hundreds of patches across multiple
kernel versions.

Now, mind explaining what "v4l2 style device tree bindings" means?  I've
no idea since I'm relatively new to DT.

-- 
FTTC broadband for 0.8mile line: 5.8Mbps down 500kbps up.  Estimation
in database were 13.1 to 19Mbit for a good line, about 7.5+ for a bad.
Estimate before purchase was "up to 13.2Mbit".
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH RFC v2 00/35] Second preview of imx-drm cleanup series

2014-02-10 Thread Philipp Zabel
Am Montag, den 10.02.2014, 12:28 + schrieb Russell King - ARM Linux:
> This is the latest revision of my series cleaning up imx-drm and
> hopefully getting it ready to be moved out of drivers/staging.
> This series is updated to v3.14-rc2.
> 
> Since the last round of patches were posted, the component support
> has been merged into mainline, and thus dropped from this series.
> Greg has taken the first three patches and merged them into his
> linux-next tree - however, I include them here for completness.
> 
> Most of the comments from last time still apply, and I'll look at
> incorporating some of the other patches that were posted in the
> coming week.
> 
> If I can have some acks for this, I'll start sending some of it to
>
>
> Greg - I'd like to at least get the five or six initial imx-hdmi
> patches to Greg and queued up for the next merge window sooner
> rather than later, preferably getting most of this ready for that
> window too.

For the first 9 patches up to (including) "imx-drm: ipu-v3: more
clocking fixes":
Acked-by: Philipp Zabel 

As you say, comments about the device tree bindings still apply.
I'd prefer if the patches that currently use the crtcs property were
reworked to use the v4l2 style device tree bindings before they hit
mainline.

regards
Philipp

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


Re: [PATCH v3 1/2] drivers/base: permit base components to omit the bind/unbind ops

2014-02-10 Thread Russell King - ARM Linux
On Mon, Feb 10, 2014 at 03:35:51PM +0100, Jean-Francois Moine wrote:
> On Mon, 10 Feb 2014 13:12:33 +
> Russell King - ARM Linux  wrote:
> 
> > I've NAK'd these patches already - I believe they're based on a
> > mis-understanding of how this should be used.  I believe Jean-Francois
> > has only looked at the core, rather than looking at the imx-drm example
> > it was posted with in an attempt to understand it.
> > 
> > Omitting the component bind operations is absurd because it makes the
> > component code completely pointless, since there is then no way to
> > control the sequencing of driver initialisation - something which is
> > one of the primary reasons for this code existing in the first place.
> 
> I perfectly looked at your example and I use it now in my system.
> 
> You did not see what could be done with your component code. For
> example, since november, I have not yet the clock probe_defer in the
> mainline (http://www.spinics.net/lists/arm-kernel/msg306072.html), so,
> there are 3 solutions:
> 
> - hope the patch will be some day in the mainline and, today, reboot
>   when the system does not start correctly,
> 
> - insert a delay in the tda998x and kirkwood probe sequences (delay
>   long enough to be sure the si5351 is started, or loop),
> 
> - use your component work.
> 
> In the last case, it is easy:
> 
> - the si5351 driver calls component_add (with empty ops: it has no
>   interest in the bind/unbind functions) when it is fully started (i.e.
>   registered - that was the subject of my patch),

There is only one word for this:
Ewww.

Definitely not.

The component stuff is there to sort out the subsystems which expect a
"card" but in DT we supply a set of components.  It's not there to sort
out dependencies between different subsystems.

I've no idea why your patch to add the deferred probing hasn't been acked
by Mike yet, but that needs to happen before I take it.  Or, split it up
in two so I can take the clkdev part and Mike can take the CCF part.

-- 
FTTC broadband for 0.8mile line: 5.8Mbps down 500kbps up.  Estimation
in database were 13.1 to 19Mbit for a good line, about 7.5+ for a bad.
Estimate before purchase was "up to 13.2Mbit".
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] [media] v4l: omap4iss: Remove VIDEO_OMAP4_DEBUG

2014-02-10 Thread Paul Bolle
Laurent,

On Mon, 2014-02-10 at 15:13 +0100, Laurent Pinchart wrote:
> On Sunday 09 February 2014 16:09:37 Paul Bolle wrote:
> > Commit d632dfefd36f ("[media] v4l: omap4iss: Add support for OMAP4
> > camera interface - Build system") added a Kconfig entry for
> > VIDEO_OMAP4_DEBUG. But nothing uses that symbol.
> > 
> > This entry was apparently copied from a similar entry for "OMAP 3
> > Camera debug messages". But a corresponding Makefile line is missing.
> > Besides, the debug code also depends on a mysterious ISS_ISR_DEBUG
> > macro. This Kconfig entry can be removed.
> 
> What about adding the associated Makefile line instead to #define DEBUG when 
> VIDEO_OMAP4_DEBUG is selected, as with the OMAP3 ISP driver ?
>  
> > Someone familiar with the code might be able to say what to do with the
> > code depending on the DEBUG and ISS_ISR_DEBUG macros.
> 
> ISS_ISR_DEBUG is expected to be set by manually modifying the source code, as 
> it prints lots of messages in interrupt context.

Which renders the DEBUG macro pointless. Or does the code use some
dev_dbg()-like magic, which is only triggered if the DEBUG macro is set?

Thanks,


Paul Bolle

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


Re: [PATCH v3 1/2] drivers/base: permit base components to omit the bind/unbind ops

2014-02-10 Thread Jean-Francois Moine
On Mon, 10 Feb 2014 13:12:33 +
Russell King - ARM Linux  wrote:

> I've NAK'd these patches already - I believe they're based on a
> mis-understanding of how this should be used.  I believe Jean-Francois
> has only looked at the core, rather than looking at the imx-drm example
> it was posted with in an attempt to understand it.
> 
> Omitting the component bind operations is absurd because it makes the
> component code completely pointless, since there is then no way to
> control the sequencing of driver initialisation - something which is
> one of the primary reasons for this code existing in the first place.

I perfectly looked at your example and I use it now in my system.

You did not see what could be done with your component code. For
example, since november, I have not yet the clock probe_defer in the
mainline (http://www.spinics.net/lists/arm-kernel/msg306072.html), so,
there are 3 solutions:

- hope the patch will be some day in the mainline and, today, reboot
  when the system does not start correctly,

- insert a delay in the tda998x and kirkwood probe sequences (delay
  long enough to be sure the si5351 is started, or loop),

- use your component work.

In the last case, it is easy:

- the si5351 driver calls component_add (with empty ops: it has no
  interest in the bind/unbind functions) when it is fully started (i.e.
  registered - that was the subject of my patch),

- in the DRM driver, look for the si5351 as a clock in the DT (drm ->
  encoder -> clock), and add it to the awaited components (CRTCs,
  encoders..),

- in the audio subsystem, look for the si5351 as an external clock in
  the DT (simple-card -> CPU DAI -> clock) and add it to the awaited
  components (CPU and CODEC DAIs - yes, the S/PDIF CODEC should also be
  a component with no bin/unbind ops).

Then, when the si5351 is registered, both master components video and
audio can safely run.


-- 
Ken ar c'hentañ | ** Breizh ha Linux atav! **
Jef |   http://moinejf.free.fr/
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] staging : ion : Fix some checkpatch warnings and an error

2014-02-10 Thread Joe Perches
On Mon, 2014-02-10 at 14:56 +0900, Daeseok Youn wrote:
>

Hello.

> diff --git a/drivers/staging/android/ion/ion_priv.h 
> b/drivers/staging/android/ion/ion_priv.h
[]
> - struct sg_table *(*map_dma) (struct ion_heap *heap,
> + struct sg_table * (*map_dma)(struct ion_heap *heap,

The message about space required after "struct sg_table *"
is a checkpatch defect.  This is better as:

struct sg_table *(*map_dma)(struct ion_heap *heap, etc...)

I'll fix checkpatch in a little bit.


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


Re: [PATCH] [media] v4l: omap4iss: Remove VIDEO_OMAP4_DEBUG

2014-02-10 Thread Laurent Pinchart
Hi Paul,

Thank you for the patch.

On Sunday 09 February 2014 16:09:37 Paul Bolle wrote:
> Commit d632dfefd36f ("[media] v4l: omap4iss: Add support for OMAP4
> camera interface - Build system") added a Kconfig entry for
> VIDEO_OMAP4_DEBUG. But nothing uses that symbol.
> 
> This entry was apparently copied from a similar entry for "OMAP 3
> Camera debug messages". But a corresponding Makefile line is missing.
> Besides, the debug code also depends on a mysterious ISS_ISR_DEBUG
> macro. This Kconfig entry can be removed.

What about adding the associated Makefile line instead to #define DEBUG when 
VIDEO_OMAP4_DEBUG is selected, as with the OMAP3 ISP driver ?
 
> Someone familiar with the code might be able to say what to do with the
> code depending on the DEBUG and ISS_ISR_DEBUG macros.

ISS_ISR_DEBUG is expected to be set by manually modifying the source code, as 
it prints lots of messages in interrupt context.

> Signed-off-by: Paul Bolle 
> ---
> Untested.
> 
>  drivers/staging/media/omap4iss/Kconfig | 6 --
>  1 file changed, 6 deletions(-)
> 
> diff --git a/drivers/staging/media/omap4iss/Kconfig
> b/drivers/staging/media/omap4iss/Kconfig index b9fe753..78b0fba 100644
> --- a/drivers/staging/media/omap4iss/Kconfig
> +++ b/drivers/staging/media/omap4iss/Kconfig
> @@ -4,9 +4,3 @@ config VIDEO_OMAP4
>   select VIDEOBUF2_DMA_CONTIG
>   ---help---
> Driver for an OMAP 4 ISS controller.
> -
> -config VIDEO_OMAP4_DEBUG
> - bool "OMAP 4 Camera debug messages"
> - depends on VIDEO_OMAP4
> - ---help---
> -   Enable debug messages on OMAP 4 ISS controller driver.

-- 
Regards,

Laurent Pinchart

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


Re: [PATCH net] hyperv: Fix the carrier status setting

2014-02-10 Thread Sergei Shtylyov

Hello.

On 10-02-2014 5:07, Haiyang Zhang wrote:


Signed-off-by: Haiyang Zhang 
Reviewed-by: K. Y. Srinivasan 
---
  drivers/net/hyperv/netvsc_drv.c |   24 +++-
  1 files changed, 15 insertions(+), 9 deletions(-)



diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index 7756118..836211c 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c

[...]

@@ -229,15 +238,17 @@ void netvsc_linkstatus_callback(struct hv_device 
*device_obj,
struct net_device *net;
struct net_device_context *ndev_ctx;
struct netvsc_device *net_device;
+   struct rndis_device *rdev;

net_device = hv_get_drvdata(device_obj);
+   rdev = net_device->extension;
+
+   rdev->link_state = !(status == 1);


   Why not just 'status != 1'?

WBR, Sergei

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


Re: [PATCH v3 1/2] drivers/base: permit base components to omit the bind/unbind ops

2014-02-10 Thread Russell King - ARM Linux
On Mon, Feb 10, 2014 at 01:53:08PM +0100, Thierry Reding wrote:
> On Fri, Feb 07, 2014 at 04:55:00PM +0100, Jean-Francois Moine wrote:
> > Some simple components don't need to do any specific action on
> > bind to / unbind from a master component.
> > 
> > This patch permits such components to omit the bind/unbind
> > operations.
> > 
> > Signed-off-by: Jean-Francois Moine 
> > ---
> >  drivers/base/component.c | 9 +++--
> >  1 file changed, 7 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/base/component.c b/drivers/base/component.c
> > index c53efe6..0a39d7a 100644
> > --- a/drivers/base/component.c
> > +++ b/drivers/base/component.c
> > @@ -225,7 +225,8 @@ static void component_unbind(struct component 
> > *component,
> >  {
> > WARN_ON(!component->bound);
> >  
> > -   component->ops->unbind(component->dev, master->dev, data);
> > +   if (component->ops)
> > +   component->ops->unbind(component->dev, master->dev, data);
> 
> This doesn't actually do what the commit message says. This makes
> component->ops optional, not component->ops->unbind().
> 
> A more correct check would be:
> 
>   if (component->ops && component->ops->unbind)
> 
> > component->bound = false;
> >  
> > /* Release all resources claimed in the binding of this component */
> > @@ -274,7 +275,11 @@ static int component_bind(struct component *component, 
> > struct master *master,
> > dev_dbg(master->dev, "binding %s (ops %ps)\n",
> > dev_name(component->dev), component->ops);
> >  
> > -   ret = component->ops->bind(component->dev, master->dev, data);
> > +   if (component->ops)
> > +   ret = component->ops->bind(component->dev, master->dev, data);
> 
> Same here.

I've NAK'd these patches already - I believe they're based on a
mis-understanding of how this should be used.  I believe Jean-Francois
has only looked at the core, rather than looking at the imx-drm example
it was posted with in an attempt to understand it.

Omitting the component bind operations is absurd because it makes the
component code completely pointless, since there is then no way to
control the sequencing of driver initialisation - something which is
one of the primary reasons for this code existing in the first place.

-- 
FTTC broadband for 0.8mile line: 5.8Mbps down 500kbps up.  Estimation
in database were 13.1 to 19Mbit for a good line, about 7.5+ for a bad.
Estimate before purchase was "up to 13.2Mbit".
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v3 1/2] drivers/base: permit base components to omit the bind/unbind ops

2014-02-10 Thread Thierry Reding
On Fri, Feb 07, 2014 at 04:55:00PM +0100, Jean-Francois Moine wrote:
> Some simple components don't need to do any specific action on
> bind to / unbind from a master component.
> 
> This patch permits such components to omit the bind/unbind
> operations.
> 
> Signed-off-by: Jean-Francois Moine 
> ---
>  drivers/base/component.c | 9 +++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/base/component.c b/drivers/base/component.c
> index c53efe6..0a39d7a 100644
> --- a/drivers/base/component.c
> +++ b/drivers/base/component.c
> @@ -225,7 +225,8 @@ static void component_unbind(struct component *component,
>  {
>   WARN_ON(!component->bound);
>  
> - component->ops->unbind(component->dev, master->dev, data);
> + if (component->ops)
> + component->ops->unbind(component->dev, master->dev, data);

This doesn't actually do what the commit message says. This makes
component->ops optional, not component->ops->unbind().

A more correct check would be:

if (component->ops && component->ops->unbind)

>   component->bound = false;
>  
>   /* Release all resources claimed in the binding of this component */
> @@ -274,7 +275,11 @@ static int component_bind(struct component *component, 
> struct master *master,
>   dev_dbg(master->dev, "binding %s (ops %ps)\n",
>   dev_name(component->dev), component->ops);
>  
> - ret = component->ops->bind(component->dev, master->dev, data);
> + if (component->ops)
> + ret = component->ops->bind(component->dev, master->dev, data);

Same here.

Thierry


pgpMPGzPZV4wd.pgp
Description: PGP signature
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] Staging: comedi: fix memory leak in comedi_bond.c

2014-02-10 Thread Ian Abbott

On 2014-02-08 05:02, Chase Southwood wrote:

We allocate bdev and then krealloc the devs pointer in order to add bdev
at the end of the devpriv->devs array list.  But if for some reason this
krealloc fails, we need to free bdev before returning an error otherwise
this memory is leaked.

Signed-off-by: Chase Southwood 
---
  drivers/staging/comedi/drivers/comedi_bond.c | 1 +
  1 file changed, 1 insertion(+)

diff --git a/drivers/staging/comedi/drivers/comedi_bond.c 
b/drivers/staging/comedi/drivers/comedi_bond.c
index 51a59e5..406aedb 100644
--- a/drivers/staging/comedi/drivers/comedi_bond.c
+++ b/drivers/staging/comedi/drivers/comedi_bond.c
@@ -254,6 +254,7 @@ static int do_dev_config(struct comedi_device *dev, struct 
comedi_devconfig *it)
if (!devs) {
dev_err(dev->class_dev,
"Could not allocate memory. Out of 
memory?\n");
+   kfree(bdev);
return -ENOMEM;
}
devpriv->devs = devs;



Acked-by: Ian Abbott 

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


[PATCH RFC v2 31/35] imx-drm: imx-drm-core: kill off mutex

2014-02-10 Thread Russell King
This mutex doesn't protect anything anymore; get rid of it.

Signed-off-by: Russell King 
---
 drivers/staging/imx-drm/imx-drm-core.c | 26 +++---
 1 file changed, 3 insertions(+), 23 deletions(-)

diff --git a/drivers/staging/imx-drm/imx-drm-core.c 
b/drivers/staging/imx-drm/imx-drm-core.c
index dd97412d6c8a..d5b82cb0cfae 100644
--- a/drivers/staging/imx-drm/imx-drm-core.c
+++ b/drivers/staging/imx-drm/imx-drm-core.c
@@ -40,14 +40,12 @@ struct imx_drm_device {
struct drm_device   *drm;
struct device   *dev;
struct imx_drm_crtc *crtc[MAX_CRTC];
-   struct mutexmutex;
int pipes;
struct drm_fbdev_cma*fbhelper;
 };
 
 struct imx_drm_crtc {
struct drm_crtc *crtc;
-   struct imx_drm_device   *imxdrm;
int pipe;
struct imx_drm_crtc_helper_funcsimx_drm_helper_funcs;
struct crtc_cookie  cookie;
@@ -270,8 +268,6 @@ static int imx_drm_driver_load(struct drm_device *drm, 
unsigned long flags)
 
drm_mode_config_init(drm);
 
-   mutex_lock(&imxdrm->mutex);
-
drm_kms_helper_poll_init(drm);
 
ret = drm_vblank_init(drm, MAX_CRTC);
@@ -287,12 +283,10 @@ static int imx_drm_driver_load(struct drm_device *drm, 
unsigned long flags)
 
platform_set_drvdata(drm->platformdev, drm);
 
-   mutex_unlock(&imxdrm->mutex);
-
/* Now try and bind all our sub-components */
ret = component_bind_all(drm->dev, drm);
if (ret)
-   goto err_relock;
+   goto err_vblank;
 
/*
 * All components are now added, we can publish the connector sysfs
@@ -332,13 +326,11 @@ static int imx_drm_driver_load(struct drm_device *drm, 
unsigned long flags)
 
 err_unbind:
component_unbind_all(drm->dev, drm);
-err_relock:
-   mutex_lock(&imxdrm->mutex);
+err_vblank:
drm_vblank_cleanup(drm);
 err_kms:
drm_kms_helper_poll_fini(drm);
drm_mode_config_cleanup(drm);
-   mutex_unlock(&imxdrm->mutex);
 
return ret;
 }
@@ -358,8 +350,6 @@ int imx_drm_add_crtc(struct drm_device *drm, struct 
drm_crtc *crtc,
struct imx_drm_crtc *imx_drm_crtc;
int ret;
 
-   mutex_lock(&imxdrm->mutex);
-
/*
 * The vblank arrays are dimensioned by MAX_CRTC - we can't
 * pass IDs greater than this to those functions.
@@ -386,7 +376,6 @@ int imx_drm_add_crtc(struct drm_device *drm, struct 
drm_crtc *crtc,
imx_drm_crtc->cookie.id = id;
imx_drm_crtc->mux_id = imx_drm_crtc->pipe;
imx_drm_crtc->crtc = crtc;
-   imx_drm_crtc->imxdrm = imxdrm;
 
imxdrm->crtc[imx_drm_crtc->pipe] = imx_drm_crtc;
 
@@ -402,8 +391,6 @@ int imx_drm_add_crtc(struct drm_device *drm, struct 
drm_crtc *crtc,
drm_crtc_init(drm, crtc,
imx_drm_crtc->imx_drm_helper_funcs.crtc_funcs);
 
-   mutex_unlock(&imxdrm->mutex);
-
return 0;
 
 err_register:
@@ -411,7 +398,6 @@ int imx_drm_add_crtc(struct drm_device *drm, struct 
drm_crtc *crtc,
kfree(imx_drm_crtc);
 err_alloc:
 err_busy:
-   mutex_unlock(&imxdrm->mutex);
return ret;
 }
 EXPORT_SYMBOL_GPL(imx_drm_add_crtc);
@@ -421,16 +407,12 @@ EXPORT_SYMBOL_GPL(imx_drm_add_crtc);
  */
 int imx_drm_remove_crtc(struct imx_drm_crtc *imx_drm_crtc)
 {
-   struct imx_drm_device *imxdrm = imx_drm_crtc->imxdrm;
-
-   mutex_lock(&imxdrm->mutex);
+   struct imx_drm_device *imxdrm = imx_drm_crtc->crtc->dev->dev_private;
 
drm_crtc_cleanup(imx_drm_crtc->crtc);
 
imxdrm->crtc[imx_drm_crtc->pipe] = NULL;
 
-   mutex_unlock(&imxdrm->mutex);
-
kfree(imx_drm_crtc);
 
return 0;
@@ -657,8 +639,6 @@ static int __init imx_drm_init(void)
if (!imx_drm_device)
return -ENOMEM;
 
-   mutex_init(&imx_drm_device->mutex);
-
ret = platform_driver_register(&imx_drm_pdrv);
if (ret)
goto err_pdrv;
-- 
1.8.3.1

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


[PATCH RFC v2 32/35] imx-drm: imx-drm-core: move allocation of imxdrm device to driver load function

2014-02-10 Thread Russell King
It is now no longer necessary to keep this structure around; we can
allocate it upon DRM driver load and destroy it thereafter without
affecting the other components now.

Signed-off-by: Russell King 
---
 drivers/staging/imx-drm/imx-drm-core.c | 47 +-
 1 file changed, 6 insertions(+), 41 deletions(-)

diff --git a/drivers/staging/imx-drm/imx-drm-core.c 
b/drivers/staging/imx-drm/imx-drm-core.c
index d5b82cb0cfae..35c8f7cf6900 100644
--- a/drivers/staging/imx-drm/imx-drm-core.c
+++ b/drivers/staging/imx-drm/imx-drm-core.c
@@ -38,7 +38,6 @@ struct imx_drm_crtc;
 
 struct imx_drm_device {
struct drm_device   *drm;
-   struct device   *dev;
struct imx_drm_crtc *crtc[MAX_CRTC];
int pipes;
struct drm_fbdev_cma*fbhelper;
@@ -206,13 +205,6 @@ int imx_drm_connector_mode_valid(struct drm_connector 
*connector,
 }
 EXPORT_SYMBOL(imx_drm_connector_mode_valid);
 
-static struct imx_drm_device *imx_drm_device;
-
-static struct imx_drm_device *__imx_drm_device(void)
-{
-   return imx_drm_device;
-}
-
 void imx_drm_connector_destroy(struct drm_connector *connector)
 {
drm_sysfs_connector_remove(connector);
@@ -236,10 +228,14 @@ static struct drm_mode_config_funcs 
imx_drm_mode_config_funcs = {
  */
 static int imx_drm_driver_load(struct drm_device *drm, unsigned long flags)
 {
-   struct imx_drm_device *imxdrm = __imx_drm_device();
+   struct imx_drm_device *imxdrm;
struct drm_connector *connector;
int ret;
 
+   imxdrm = devm_kzalloc(drm->dev, sizeof(*imxdrm), GFP_KERNEL);
+   if (!imxdrm)
+   return -ENOMEM;
+
imxdrm->drm = drm;
 
drm->dev_private = imxdrm;
@@ -604,8 +600,6 @@ static int imx_drm_platform_probe(struct platform_device 
*pdev)
if (ret)
return ret;
 
-   imx_drm_device->dev = &pdev->dev;
-
return component_master_add(&pdev->dev, &imx_drm_ops);
 }
 
@@ -630,36 +624,7 @@ static struct platform_driver imx_drm_pdrv = {
.of_match_table = imx_drm_dt_ids,
},
 };
-
-static int __init imx_drm_init(void)
-{
-   int ret;
-
-   imx_drm_device = kzalloc(sizeof(*imx_drm_device), GFP_KERNEL);
-   if (!imx_drm_device)
-   return -ENOMEM;
-
-   ret = platform_driver_register(&imx_drm_pdrv);
-   if (ret)
-   goto err_pdrv;
-
-   return 0;
-
-err_pdrv:
-   kfree(imx_drm_device);
-
-   return ret;
-}
-
-static void __exit imx_drm_exit(void)
-{
-   platform_driver_unregister(&imx_drm_pdrv);
-
-   kfree(imx_drm_device);
-}
-
-module_init(imx_drm_init);
-module_exit(imx_drm_exit);
+module_platform_driver(imx_drm_pdrv);
 
 MODULE_AUTHOR("Sascha Hauer ");
 MODULE_DESCRIPTION("i.MX drm driver core");
-- 
1.8.3.1

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


[PATCH RFC v2 35/35] imx-drm: imx-hdmi: add hotplug support to HDMI component

2014-02-10 Thread Russell King
Add hotplug support.  We have to make the interrupt handler threaded so
we can call drm_helper_hpd_irq_event().  Keeping in mind that we will
want to share the interrupt with other HDMI interface drivers (eg, audio
and CEC) put the groundwork in now for that, rather than just using
IRQF_ONESHOT.

Also, we must not call drm_helper_hpd_irq_event() until we have fully
setup the connector; keep the interrupt(s) muted until after that point.

Signed-off-by: Russell King 
---
 drivers/staging/imx-drm/imx-hdmi.c | 40 +++---
 1 file changed, 33 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/imx-drm/imx-hdmi.c 
b/drivers/staging/imx-drm/imx-hdmi.c
index c5e57ac07243..a677e3379221 100644
--- a/drivers/staging/imx-drm/imx-hdmi.c
+++ b/drivers/staging/imx-drm/imx-hdmi.c
@@ -119,6 +119,8 @@ struct imx_hdmi {
struct clk *isfr_clk;
struct clk *iahb_clk;
 
+   enum drm_connector_status connector_status;
+
struct hdmi_data_info hdmi_data;
int vic;
 
@@ -1300,9 +1302,6 @@ static int imx_hdmi_fb_registered(struct imx_hdmi *hdmi)
/* Clear Hotplug interrupts */
hdmi_writeb(hdmi, HDMI_IH_PHY_STAT0_HPD, HDMI_IH_PHY_STAT0);
 
-   /* Unmute interrupts */
-   hdmi_writeb(hdmi, ~HDMI_IH_PHY_STAT0_HPD, HDMI_IH_MUTE_PHY_STAT0);
-
return 0;
 }
 
@@ -1371,8 +1370,9 @@ static void imx_hdmi_poweroff(struct imx_hdmi *hdmi)
 static enum drm_connector_status imx_hdmi_connector_detect(struct drm_connector
*connector, bool force)
 {
-   /* FIXME */
-   return connector_status_connected;
+   struct imx_hdmi *hdmi = container_of(connector, struct imx_hdmi,
+connector);
+   return hdmi->connector_status;
 }
 
 static int imx_hdmi_connector_get_modes(struct drm_connector *connector)
@@ -1486,6 +1486,18 @@ static struct drm_connector_helper_funcs 
imx_hdmi_connector_helper_funcs = {
.best_encoder = imx_hdmi_connector_best_encoder,
 };
 
+static irqreturn_t imx_hdmi_hardirq(int irq, void *dev_id)
+{
+   struct imx_hdmi *hdmi = dev_id;
+   u8 intr_stat;
+
+   intr_stat = hdmi_readb(hdmi, HDMI_IH_PHY_STAT0);
+   if (intr_stat)
+   hdmi_writeb(hdmi, ~0, HDMI_IH_MUTE_PHY_STAT0);
+
+   return intr_stat ? IRQ_WAKE_THREAD : IRQ_NONE;
+}
+
 static irqreturn_t imx_hdmi_irq(int irq, void *dev_id)
 {
struct imx_hdmi *hdmi = dev_id;
@@ -1502,17 +1514,21 @@ static irqreturn_t imx_hdmi_irq(int irq, void *dev_id)
 
hdmi_modb(hdmi, 0, HDMI_PHY_HPD, HDMI_PHY_POL0);
 
+   hdmi->connector_status = connector_status_connected;
imx_hdmi_poweron(hdmi);
} else {
dev_dbg(hdmi->dev, "EVENT=plugout\n");
 
hdmi_modb(hdmi, HDMI_PHY_HPD, HDMI_PHY_HPD, 
HDMI_PHY_POL0);
 
+   hdmi->connector_status = connector_status_disconnected;
imx_hdmi_poweroff(hdmi);
}
+   drm_helper_hpd_irq_event(hdmi->connector.dev);
}
 
hdmi_writeb(hdmi, intr_stat, HDMI_IH_PHY_STAT0);
+   hdmi_writeb(hdmi, ~HDMI_IH_PHY_STAT0_HPD, HDMI_IH_MUTE_PHY_STAT0);
 
return IRQ_HANDLED;
 }
@@ -1526,6 +1542,8 @@ static int imx_hdmi_register(struct drm_device *drm, 
struct imx_hdmi *hdmi)
if (ret)
return ret;
 
+   hdmi->connector.polled = DRM_CONNECTOR_POLL_HPD;
+
drm_encoder_helper_add(&hdmi->encoder, &imx_hdmi_encoder_helper_funcs);
drm_encoder_init(drm, &hdmi->encoder, &imx_hdmi_encoder_funcs,
 DRM_MODE_ENCODER_TMDS);
@@ -1577,6 +1595,7 @@ static int imx_hdmi_bind(struct device *dev, struct 
device *master, void *data)
return -ENOMEM;
 
hdmi->dev = dev;
+   hdmi->connector_status = connector_status_disconnected;
hdmi->sample_rate = 48000;
hdmi->ratio = 100;
 
@@ -1600,8 +1619,9 @@ static int imx_hdmi_bind(struct device *dev, struct 
device *master, void *data)
if (irq < 0)
return -EINVAL;
 
-   ret = devm_request_irq(dev, irq, imx_hdmi_irq, 0,
-  dev_name(dev), hdmi);
+   ret = devm_request_threaded_irq(dev, irq, imx_hdmi_hardirq,
+   imx_hdmi_irq, IRQF_SHARED,
+   dev_name(dev), hdmi);
if (ret)
return ret;
 
@@ -1677,6 +1697,9 @@ static int imx_hdmi_bind(struct device *dev, struct 
device *master, void *data)
if (ret)
goto err_iahb;
 
+   /* Unmute interrupts */
+   hdmi_writeb(hdmi, ~HDMI_IH_PHY_STAT0_HPD, HDMI_IH_MUTE_PHY_STAT0);
+
dev_set_drvdata(dev, hdmi);
 
return 0;
@@ -1694,6 +1717,9 @@ static void imx_hdmi_unbind(struct device *dev, struct 
device *master,
 {
struct imx_hdmi *hdmi = dev_g

[PATCH RFC v2 34/35] imx-drm: imx-drm-core: add core hotplug connector support

2014-02-10 Thread Russell King
Add core imx-drm support for hotplug connector support.  We need to
setup the poll helper after we've setup the connectors; the helper
scans the connectors to determine their capabilities.

Signed-off-by: Russell King 
---
 drivers/staging/imx-drm/imx-drm-core.c | 21 +
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/imx-drm/imx-drm-core.c 
b/drivers/staging/imx-drm/imx-drm-core.c
index 7939cea8311a..dcba51853e8a 100644
--- a/drivers/staging/imx-drm/imx-drm-core.c
+++ b/drivers/staging/imx-drm/imx-drm-core.c
@@ -69,7 +69,11 @@ static int imx_drm_driver_unload(struct drm_device *drm)
 {
 #if IS_ENABLED(CONFIG_DRM_IMX_FB_HELPER)
struct imx_drm_device *imxdrm = drm->dev_private;
+#endif
+
+   drm_kms_helper_poll_fini(drm);
 
+#if IS_ENABLED(CONFIG_DRM_IMX_FB_HELPER)
if (imxdrm->fbhelper)
drm_fbdev_cma_fini(imxdrm->fbhelper);
 #endif
@@ -77,7 +81,6 @@ static int imx_drm_driver_unload(struct drm_device *drm)
component_unbind_all(drm->dev, drm);
 
drm_vblank_cleanup(drm);
-   drm_kms_helper_poll_fini(drm);
drm_mode_config_cleanup(drm);
 
return 0;
@@ -213,8 +216,18 @@ void imx_drm_encoder_destroy(struct drm_encoder *encoder)
 }
 EXPORT_SYMBOL_GPL(imx_drm_encoder_destroy);
 
+static void imx_drm_output_poll_changed(struct drm_device *drm)
+{
+#if IS_ENABLED(CONFIG_DRM_IMX_FB_HELPER)
+   struct imx_drm_device *imxdrm = drm->dev_private;
+
+   drm_fbdev_cma_hotplug_event(imxdrm->fbhelper);
+#endif
+}
+
 static struct drm_mode_config_funcs imx_drm_mode_config_funcs = {
.fb_create = drm_fb_cma_create,
+   .output_poll_changed = imx_drm_output_poll_changed,
 };
 
 /*
@@ -259,8 +272,6 @@ static int imx_drm_driver_load(struct drm_device *drm, 
unsigned long flags)
 
drm_mode_config_init(drm);
 
-   drm_kms_helper_poll_init(drm);
-
ret = drm_vblank_init(drm, MAX_CRTC);
if (ret)
goto err_kms;
@@ -313,6 +324,9 @@ static int imx_drm_driver_load(struct drm_device *drm, 
unsigned long flags)
goto err_unbind;
}
 #endif
+
+   drm_kms_helper_poll_init(drm);
+
return 0;
 
 err_unbind:
@@ -320,7 +334,6 @@ static int imx_drm_driver_load(struct drm_device *drm, 
unsigned long flags)
 err_vblank:
drm_vblank_cleanup(drm);
 err_kms:
-   drm_kms_helper_poll_fini(drm);
drm_mode_config_cleanup(drm);
 
return ret;
-- 
1.8.3.1

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


[PATCH RFC v2 29/35] imx-drm: imx-drm-core: remove imx_drm_connector and imx_drm_encoder code

2014-02-10 Thread Russell King
The core imx_drm_connector and imx_drm_encoder code is no longer
required - the connectors and encoders are all using the component
support, so we can remove this.

Signed-off-by: Russell King 
---
 drivers/staging/imx-drm/imx-drm-core.c | 371 +
 drivers/staging/imx-drm/imx-drm.h  |  14 --
 2 files changed, 1 insertion(+), 384 deletions(-)

diff --git a/drivers/staging/imx-drm/imx-drm-core.c 
b/drivers/staging/imx-drm/imx-drm-core.c
index 1f50acd5a982..b27c42539e49 100644
--- a/drivers/staging/imx-drm/imx-drm-core.c
+++ b/drivers/staging/imx-drm/imx-drm-core.c
@@ -40,8 +40,6 @@ struct imx_drm_device {
struct drm_device   *drm;
struct device   *dev;
struct imx_drm_crtc *crtc[MAX_CRTC];
-   struct list_headencoder_list;
-   struct list_headconnector_list;
struct mutexmutex;
int pipes;
struct drm_fbdev_cma*fbhelper;
@@ -56,24 +54,9 @@ struct imx_drm_crtc {
int mux_id;
 };
 
-struct imx_drm_encoder {
-   struct drm_encoder  *encoder;
-   struct list_headlist;
-   struct module   *owner;
-   struct list_headpossible_crtcs;
-};
-
-struct imx_drm_connector {
-   struct drm_connector*connector;
-   struct list_headlist;
-   struct module   *owner;
-};
-
 static int legacyfb_depth = 16;
 module_param(legacyfb_depth, int, 0444);
 
-static void imx_drm_device_put(void);
-
 int imx_drm_crtc_id(struct imx_drm_crtc *crtc)
 {
return crtc->pipe;
@@ -101,8 +84,6 @@ static int imx_drm_driver_unload(struct drm_device *drm)
 
component_unbind_all(drm->dev, drm);
 
-   imx_drm_device_put();
-
drm_vblank_cleanup(drm);
drm_kms_helper_poll_fini(drm);
drm_mode_config_cleanup(drm);
@@ -234,135 +215,6 @@ static struct imx_drm_device *__imx_drm_device(void)
return imx_drm_device;
 }
 
-static struct drm_device *imx_drm_device_get(void)
-{
-   struct imx_drm_device *imxdrm = __imx_drm_device();
-   struct imx_drm_encoder *enc;
-   struct imx_drm_connector *con;
-
-   list_for_each_entry(enc, &imxdrm->encoder_list, list) {
-   if (!try_module_get(enc->owner)) {
-   dev_err(imxdrm->dev, "could not get module %s\n",
-   module_name(enc->owner));
-   goto unwind_enc;
-   }
-   }
-
-   list_for_each_entry(con, &imxdrm->connector_list, list) {
-   if (!try_module_get(con->owner)) {
-   dev_err(imxdrm->dev, "could not get module %s\n",
-   module_name(con->owner));
-   goto unwind_con;
-   }
-   }
-
-   return imxdrm->drm;
-
-unwind_con:
-   list_for_each_entry_continue_reverse(con, &imxdrm->connector_list, list)
-   module_put(con->owner);
-unwind_enc:
-   list_for_each_entry_continue_reverse(enc, &imxdrm->encoder_list, list)
-   module_put(enc->owner);
-
-   mutex_unlock(&imxdrm->mutex);
-
-   return NULL;
-
-}
-
-static void imx_drm_device_put(void)
-{
-   struct imx_drm_device *imxdrm = __imx_drm_device();
-   struct imx_drm_encoder *enc;
-   struct imx_drm_connector *con;
-
-   mutex_lock(&imxdrm->mutex);
-
-   list_for_each_entry(con, &imxdrm->connector_list, list)
-   module_put(con->owner);
-
-   list_for_each_entry(enc, &imxdrm->encoder_list, list)
-   module_put(enc->owner);
-
-   mutex_unlock(&imxdrm->mutex);
-}
-
-static int drm_mode_group_reinit(struct drm_device *dev)
-{
-   struct drm_mode_group *group = &dev->primary->mode_group;
-   uint32_t *id_list = group->id_list;
-   int ret;
-
-   ret = drm_mode_group_init_legacy_group(dev, group);
-   if (ret < 0)
-   return ret;
-
-   kfree(id_list);
-   return 0;
-}
-
-/*
- * register an encoder to the drm core
- */
-static int imx_drm_encoder_register(struct imx_drm_encoder *imx_drm_encoder)
-{
-   struct imx_drm_device *imxdrm = __imx_drm_device();
-
-   INIT_LIST_HEAD(&imx_drm_encoder->possible_crtcs);
-
-   drm_encoder_init(imxdrm->drm, imx_drm_encoder->encoder,
-   imx_drm_encoder->encoder->funcs,
-   imx_drm_encoder->encoder->encoder_type);
-
-   drm_mode_group_reinit(imxdrm->drm);
-
-   return 0;
-}
-
-/*
- * unregister an encoder from the drm core
- */
-static void imx_drm_encoder_unregister(struct imx_drm_encoder
-   *imx_drm_encoder)
-{
-   struct imx_drm_device *imxdrm = __imx_dr

[PATCH RFC v2 33/35] imx-drm: imx-drm-core: various cleanups

2014-02-10 Thread Russell King
Various cleanups are possible after the previous round of changes; these
have no real functional bearing other than tidying up the code.

Signed-off-by: Russell King 
---
 drivers/staging/imx-drm/imx-drm-core.c | 47 --
 drivers/staging/imx-drm/imx-drm.h  |  5 ++--
 2 files changed, 19 insertions(+), 33 deletions(-)

diff --git a/drivers/staging/imx-drm/imx-drm-core.c 
b/drivers/staging/imx-drm/imx-drm-core.c
index 35c8f7cf6900..7939cea8311a 100644
--- a/drivers/staging/imx-drm/imx-drm-core.c
+++ b/drivers/staging/imx-drm/imx-drm-core.c
@@ -15,12 +15,12 @@
  */
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
 #include 
-#include 
-#include 
 #include 
 #include 
 
@@ -28,12 +28,6 @@
 
 #define MAX_CRTC   4
 
-struct crtc_cookie {
-   void *cookie;
-   int id;
-   struct list_head list;
-};
-
 struct imx_drm_crtc;
 
 struct imx_drm_device {
@@ -47,7 +41,8 @@ struct imx_drm_crtc {
struct drm_crtc *crtc;
int pipe;
struct imx_drm_crtc_helper_funcsimx_drm_helper_funcs;
-   struct crtc_cookie  cookie;
+   void*cookie;
+   int id;
int mux_id;
 };
 
@@ -271,9 +266,9 @@ static int imx_drm_driver_load(struct drm_device *drm, 
unsigned long flags)
goto err_kms;
 
/*
-* with vblank_disable_allowed = true, vblank interrupt will be disabled
-* by drm timer once a current process gives up ownership of
-* vblank event.(after drm_vblank_put function is called)
+* with vblank_disable_allowed = true, vblank interrupt will be
+* disabled by drm timer once a current process gives up ownership
+* of vblank event. (after drm_vblank_put function is called)
 */
drm->vblank_disable_allowed = true;
 
@@ -350,26 +345,20 @@ int imx_drm_add_crtc(struct drm_device *drm, struct 
drm_crtc *crtc,
 * The vblank arrays are dimensioned by MAX_CRTC - we can't
 * pass IDs greater than this to those functions.
 */
-   if (imxdrm->pipes >= MAX_CRTC) {
-   ret = -EINVAL;
-   goto err_busy;
-   }
+   if (imxdrm->pipes >= MAX_CRTC)
+   return -EINVAL;
 
-   if (imxdrm->drm->open_count) {
-   ret = -EBUSY;
-   goto err_busy;
-   }
+   if (imxdrm->drm->open_count)
+   return -EBUSY;
 
imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL);
-   if (!imx_drm_crtc) {
-   ret = -ENOMEM;
-   goto err_alloc;
-   }
+   if (!imx_drm_crtc)
+   return -ENOMEM;
 
imx_drm_crtc->imx_drm_helper_funcs = *imx_drm_helper_funcs;
imx_drm_crtc->pipe = imxdrm->pipes++;
-   imx_drm_crtc->cookie.cookie = cookie;
-   imx_drm_crtc->cookie.id = id;
+   imx_drm_crtc->cookie = cookie;
+   imx_drm_crtc->id = id;
imx_drm_crtc->mux_id = imx_drm_crtc->pipe;
imx_drm_crtc->crtc = crtc;
 
@@ -392,8 +381,6 @@ int imx_drm_add_crtc(struct drm_device *drm, struct 
drm_crtc *crtc,
 err_register:
imxdrm->crtc[imx_drm_crtc->pipe] = NULL;
kfree(imx_drm_crtc);
-err_alloc:
-err_busy:
return ret;
 }
 EXPORT_SYMBOL_GPL(imx_drm_add_crtc);
@@ -429,8 +416,8 @@ static uint32_t imx_drm_find_crtc_mask(struct 
imx_drm_device *imxdrm,
 
for (i = 0; i < MAX_CRTC; i++) {
struct imx_drm_crtc *imx_drm_crtc = imxdrm->crtc[i];
-   if (imx_drm_crtc && imx_drm_crtc->cookie.id == id &&
-   imx_drm_crtc->cookie.cookie == cookie)
+   if (imx_drm_crtc && imx_drm_crtc->id == id &&
+   imx_drm_crtc->cookie == cookie)
return drm_crtc_mask(imx_drm_crtc->crtc);
}
 
diff --git a/drivers/staging/imx-drm/imx-drm.h 
b/drivers/staging/imx-drm/imx-drm.h
index ae9c96d181fa..aa2102866689 100644
--- a/drivers/staging/imx-drm/imx-drm.h
+++ b/drivers/staging/imx-drm/imx-drm.h
@@ -5,14 +5,15 @@
 
 #define IPU_PIX_FMT_GBR24  v4l2_fourcc('G', 'B', 'R', '3')
 
+struct device_node;
 struct drm_crtc;
 struct drm_connector;
 struct drm_device;
 struct drm_display_mode;
 struct drm_encoder;
-struct imx_drm_crtc;
 struct drm_fbdev_cma;
 struct drm_framebuffer;
+struct imx_drm_crtc;
 struct platform_device;
 
 int imx_drm_crtc_id(struct imx_drm_crtc *crtc);
@@ -48,8 +49,6 @@ int imx_drm_panel_format_pins(struct drm_encoder *encoder,
 int imx_drm_panel_format(struct drm_encoder *encoder,
u32 interface_pix_fmt);
 
-struct device_node;
-
 int imx_drm_encoder_get_mux_id(struct drm_encoder *encoder);
 int imx_drm_encoder_parse_of(struct drm_device *drm,
struct drm_encoder *encoder, struct device_node *np);
-- 
1.8.3.1

_

[PATCH RFC v2 30/35] imx-drm: imx-drm-core: get rid of drm_mode_group_init_legacy_group()

2014-02-10 Thread Russell King
Since we're now operating like a conventional DRM driver, doing all
the initialisation within the driver's ->load callback, we don't
need to mess around with the mode groups - we can rely on the one
in the DRM platform code.

Signed-off-by: Russell King 
---
 drivers/staging/imx-drm/imx-drm-core.c | 6 --
 1 file changed, 6 deletions(-)

diff --git a/drivers/staging/imx-drm/imx-drm-core.c 
b/drivers/staging/imx-drm/imx-drm-core.c
index b27c42539e49..dd97412d6c8a 100644
--- a/drivers/staging/imx-drm/imx-drm-core.c
+++ b/drivers/staging/imx-drm/imx-drm-core.c
@@ -274,12 +274,6 @@ static int imx_drm_driver_load(struct drm_device *drm, 
unsigned long flags)
 
drm_kms_helper_poll_init(drm);
 
-   /* setup the grouping for the legacy output */
-   ret = drm_mode_group_init_legacy_group(drm,
-   &drm->primary->mode_group);
-   if (ret)
-   goto err_kms;
-
ret = drm_vblank_init(drm, MAX_CRTC);
if (ret)
goto err_kms;
-- 
1.8.3.1

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


[PATCH RFC v2 19/35] imx-drm: convert to componentised device support

2014-02-10 Thread Russell King
Use the componentised device support for imx-drm.  This requires all
the sub-components and the master device to register with the component
device support.

Signed-off-by: Russell King 
---
 arch/arm/boot/dts/imx51-babbage.dts|  10 ++-
 arch/arm/boot/dts/imx53-m53evk.dts |   8 ++-
 arch/arm/boot/dts/imx53-mba53.dts  |   6 ++
 arch/arm/boot/dts/imx53-qsb.dts|   8 ++-
 arch/arm/boot/dts/imx6q-sabresd.dts|   4 ++
 arch/arm/boot/dts/imx6qdl-sabresd.dtsi |   6 ++
 drivers/staging/imx-drm/imx-drm-core.c | 105 +++--
 drivers/staging/imx-drm/imx-ldb.c  |  40 +++
 drivers/staging/imx-drm/imx-tve.c  |  63 ++---
 drivers/staging/imx-drm/ipuv3-crtc.c   |  46 +
 drivers/staging/imx-drm/parallel-display.c |  30 +++--
 11 files changed, 246 insertions(+), 80 deletions(-)

diff --git a/arch/arm/boot/dts/imx51-babbage.dts 
b/arch/arm/boot/dts/imx51-babbage.dts
index be1407cf5abd..6ff15a0eacb3 100644
--- a/arch/arm/boot/dts/imx51-babbage.dts
+++ b/arch/arm/boot/dts/imx51-babbage.dts
@@ -21,7 +21,7 @@
reg = <0x9000 0x2000>;
};
 
-   display@di0 {
+   display0: display@di0 {
compatible = "fsl,imx-parallel-display";
crtcs = <&ipu 0>;
interface-pix-fmt = "rgb24";
@@ -43,7 +43,7 @@
};
};
 
-   display@di1 {
+   display1: display@di1 {
compatible = "fsl,imx-parallel-display";
crtcs = <&ipu 1>;
interface-pix-fmt = "rgb565";
@@ -81,6 +81,12 @@
};
};
 
+   imx-drm {
+   compatible = "fsl,imx-drm";
+   crtcs = <&ipu 0>, <&ipu 1>;
+   connectors = <&display0>, <&display1>;
+   };
+
sound {
compatible = "fsl,imx51-babbage-sgtl5000",
 "fsl,imx-audio-sgtl5000";
diff --git a/arch/arm/boot/dts/imx53-m53evk.dts 
b/arch/arm/boot/dts/imx53-m53evk.dts
index 7d304d02ed38..ee6107b6484c 100644
--- a/arch/arm/boot/dts/imx53-m53evk.dts
+++ b/arch/arm/boot/dts/imx53-m53evk.dts
@@ -21,7 +21,7 @@
};
 
soc {
-   display@di1 {
+   display1: display@di1 {
compatible = "fsl,imx-parallel-display";
crtcs = <&ipu 1>;
interface-pix-fmt = "bgr666";
@@ -53,6 +53,12 @@
default-brightness-level = <6>;
};
 
+   imx-drm {
+   compatible = "fsl,imx-drm";
+   crtcs = <&ipu 1>;
+   connectors = <&display1>;
+   };
+
leds {
compatible = "gpio-leds";
pinctrl-names = "default";
diff --git a/arch/arm/boot/dts/imx53-mba53.dts 
b/arch/arm/boot/dts/imx53-mba53.dts
index a63090267941..9b6e76980a74 100644
--- a/arch/arm/boot/dts/imx53-mba53.dts
+++ b/arch/arm/boot/dts/imx53-mba53.dts
@@ -43,6 +43,12 @@
status = "disabled";
};
 
+   imx-drm {
+   compatible = "fsl,imx-drm";
+   crtcs = <&ipu 1>;
+   connectors = <&disp1>, <&tve>;
+   };
+
reg_3p2v: 3p2v {
compatible = "regulator-fixed";
regulator-name = "3P2V";
diff --git a/arch/arm/boot/dts/imx53-qsb.dts b/arch/arm/boot/dts/imx53-qsb.dts
index 91a5935a4aac..3cb4f7791a91 100644
--- a/arch/arm/boot/dts/imx53-qsb.dts
+++ b/arch/arm/boot/dts/imx53-qsb.dts
@@ -21,7 +21,7 @@
reg = <0x7000 0x4000>;
};
 
-   display@di0 {
+   display0: display@di0 {
compatible = "fsl,imx-parallel-display";
crtcs = <&ipu 0>;
interface-pix-fmt = "rgb565";
@@ -72,6 +72,12 @@
};
};
 
+   imx-drm {
+   compatible = "fsl,imx-drm";
+   crtcs = <&ipu 0>;
+   connectors = <&display0>;
+   };
+
leds {
compatible = "gpio-leds";
pinctrl-names = "default";
diff --git a/arch/arm/boot/dts/imx6q-sabresd.dts 
b/arch/arm/boot/dts/imx6q-sabresd.dts
index 9cbdfe7a0931..66f220a82e45 100644
--- a/arch/arm/boot/dts/imx6q-sabresd.dts
+++ b/arch/arm/boot/dts/imx6q-sabresd.dts
@@ -20,6 +20,10 @@
compatible = "fsl,imx6q-sabresd", "fsl,imx6q";
 };
 
+&imx_drm {
+   crtcs = <&ipu1 0>, <&ipu1 1>, <&ipu2 0>, <&ipu2 1>;
+};
+
 &sata {
status = "okay";
 };
diff --git a/arch/arm/boot/dts/imx6qdl-sabresd.dtsi 
b/arch/arm/boot/dts/imx6qdl-sabresd.dtsi
index e75e11b36dff..dfca3e001398 100644
--- a/arch/arm/boot/dts/imx6qdl-sabresd.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-sabresd.dtsi
@@ -62,6 +62,12 @@
};
};
 
+   imx_drm: imx-drm {
+   compatible = "fsl,imx-drm";
+   crtcs = <&ipu1 0>, <&ipu1 1>;
+   connectors = <&ldb>;
+   };
+
sound {
compatible = "fs

[PATCH RFC v2 22/35] imx-drm: remove separate imx-fbdev

2014-02-10 Thread Russell King
Now that we know when the components of the imx-drm subsystem will be
initialised, we can move the fbdev helper initialisation and teardown
into imx-drm-core.  This gives us the required ordering that DRM wants
in both driver load and unload methods.

We can also stop exporting the imx_drm_device_get() and
imx_drm_device_put() methods; nothing but the fbdev helper was making
use of these.

Signed-off-by: Russell King 
---
 drivers/staging/imx-drm/Makefile   |  1 -
 drivers/staging/imx-drm/imx-drm-core.c | 43 ++--
 drivers/staging/imx-drm/imx-drm.h  |  3 --
 drivers/staging/imx-drm/imx-fbdev.c| 74 --
 4 files changed, 31 insertions(+), 90 deletions(-)
 delete mode 100644 drivers/staging/imx-drm/imx-fbdev.c

diff --git a/drivers/staging/imx-drm/Makefile b/drivers/staging/imx-drm/Makefile
index 4677585b5ad5..5239f908ceec 100644
--- a/drivers/staging/imx-drm/Makefile
+++ b/drivers/staging/imx-drm/Makefile
@@ -6,7 +6,6 @@ obj-$(CONFIG_DRM_IMX) += imxdrm.o
 obj-$(CONFIG_DRM_IMX_PARALLEL_DISPLAY) += parallel-display.o
 obj-$(CONFIG_DRM_IMX_TVE) += imx-tve.o
 obj-$(CONFIG_DRM_IMX_LDB) += imx-ldb.o
-obj-$(CONFIG_DRM_IMX_FB_HELPER) += imx-fbdev.o
 obj-$(CONFIG_DRM_IMX_IPUV3_CORE) += ipu-v3/
 
 imx-ipuv3-crtc-objs  := ipuv3-crtc.o ipuv3-plane.o
diff --git a/drivers/staging/imx-drm/imx-drm-core.c 
b/drivers/staging/imx-drm/imx-drm-core.c
index 3cd330e646f7..5a60886b3a6b 100644
--- a/drivers/staging/imx-drm/imx-drm-core.c
+++ b/drivers/staging/imx-drm/imx-drm-core.c
@@ -70,6 +70,10 @@ struct imx_drm_connector {
struct module   *owner;
 };
 
+static int legacyfb_depth = 16;
+module_param(legacyfb_depth, int, 0444);
+
+static void imx_drm_device_put(void);
 static struct imx_drm_device *__imx_drm_device(void);
 
 int imx_drm_crtc_id(struct imx_drm_crtc *crtc)
@@ -80,16 +84,23 @@ EXPORT_SYMBOL_GPL(imx_drm_crtc_id);
 
 static void imx_drm_driver_lastclose(struct drm_device *drm)
 {
+#if IS_ENABLED(CONFIG_DRM_IMX_FB_HELPER)
struct imx_drm_device *imxdrm = drm->dev_private;
 
if (imxdrm->fbhelper)
drm_fbdev_cma_restore_mode(imxdrm->fbhelper);
+#endif
 }
 
 static int imx_drm_driver_unload(struct drm_device *drm)
 {
+#if IS_ENABLED(CONFIG_DRM_IMX_FB_HELPER)
struct imx_drm_device *imxdrm = drm->dev_private;
 
+   if (imxdrm->fbhelper)
+   drm_fbdev_cma_fini(imxdrm->fbhelper);
+#endif
+
component_unbind_all(drm->dev, drm);
 
imx_drm_device_put();
@@ -225,7 +236,7 @@ static struct imx_drm_device *__imx_drm_device(void)
return imx_drm_device;
 }
 
-struct drm_device *imx_drm_device_get(void)
+static struct drm_device *imx_drm_device_get(void)
 {
struct imx_drm_device *imxdrm = __imx_drm_device();
struct imx_drm_encoder *enc;
@@ -273,9 +284,8 @@ struct drm_device *imx_drm_device_get(void)
return NULL;
 
 }
-EXPORT_SYMBOL_GPL(imx_drm_device_get);
 
-void imx_drm_device_put(void)
+static void imx_drm_device_put(void)
 {
struct imx_drm_device *imxdrm = __imx_drm_device();
struct imx_drm_encoder *enc;
@@ -295,7 +305,6 @@ void imx_drm_device_put(void)
 
mutex_unlock(&imxdrm->mutex);
 }
-EXPORT_SYMBOL_GPL(imx_drm_device_put);
 
 static int drm_mode_group_reinit(struct drm_device *dev)
 {
@@ -450,6 +459,24 @@ static int imx_drm_driver_load(struct drm_device *drm, 
unsigned long flags)
}
}
 
+   /*
+* All components are now initialised, so setup the fb helper.
+* The fb helper takes copies of key hardware information, so the
+* crtcs/connectors/encoders must not change after this point.
+*/
+#if IS_ENABLED(CONFIG_DRM_IMX_FB_HELPER)
+   if (legacyfb_depth != 16 && legacyfb_depth != 32) {
+   dev_warn(drm->dev, "Invalid legacyfb_depth.  Defaulting to 
16bpp\n");
+   legacyfb_depth = 16;
+   }
+   imxdrm->fbhelper = drm_fbdev_cma_init(drm, legacyfb_depth,
+   drm->mode_config.num_crtc, MAX_CRTC);
+   if (IS_ERR(imxdrm->fbhelper)) {
+   ret = PTR_ERR(imxdrm->fbhelper);
+   imxdrm->fbhelper = NULL;
+   goto err_unbind;
+   }
+#endif
return 0;
 
 err_unbind:
@@ -767,14 +794,6 @@ int imx_drm_add_connector(struct drm_connector *connector,
 }
 EXPORT_SYMBOL_GPL(imx_drm_add_connector);
 
-void imx_drm_fb_helper_set(struct drm_fbdev_cma *fbdev_helper)
-{
-   struct imx_drm_device *imxdrm = __imx_drm_device();
-
-   imxdrm->fbhelper = fbdev_helper;
-}
-EXPORT_SYMBOL_GPL(imx_drm_fb_helper_set);
-
 /*
  * imx_drm_remove_connector - remove a connector
  */
diff --git a/drivers/staging/imx-drm/imx-drm.h 
b/drivers/staging/imx-drm/imx-drm.h
index e3ca0c6b6a39..d1fb1146240e 100644
--- a/drivers/staging/imx-drm/imx-drm.h
+++ b/drivers/staging/imx-drm/imx-drm.h
@@ -54,13 +54,10 @@ void imx_drm_mode_config_init(struct drm_device *drm);
 
 struct drm_gem_cma_objec

[PATCH RFC v2 23/35] imx-drm: remove imx-fb.c

2014-02-10 Thread Russell King
imx-fb.c doesn't need to be separate from imx-drm-core.c - all it is
doing is setting up the minimum and maximum sizes of the scanout
buffers, and setting up the mode_config function pointers.  Move the
contents into imx-drm-core.c and kill this file.

Signed-off-by: Russell King 
---
 drivers/staging/imx-drm/Makefile   |  2 +-
 drivers/staging/imx-drm/imx-drm-core.c | 16 +++-
 drivers/staging/imx-drm/imx-fb.c   | 47 --
 3 files changed, 16 insertions(+), 49 deletions(-)
 delete mode 100644 drivers/staging/imx-drm/imx-fb.c

diff --git a/drivers/staging/imx-drm/Makefile b/drivers/staging/imx-drm/Makefile
index 5239f908ceec..129e3a3f59f1 100644
--- a/drivers/staging/imx-drm/Makefile
+++ b/drivers/staging/imx-drm/Makefile
@@ -1,5 +1,5 @@
 
-imxdrm-objs := imx-drm-core.o imx-fb.o
+imxdrm-objs := imx-drm-core.o
 
 obj-$(CONFIG_DRM_IMX) += imxdrm.o
 
diff --git a/drivers/staging/imx-drm/imx-drm-core.c 
b/drivers/staging/imx-drm/imx-drm-core.c
index 5a60886b3a6b..3e3fd281fe6e 100644
--- a/drivers/staging/imx-drm/imx-drm-core.c
+++ b/drivers/staging/imx-drm/imx-drm-core.c
@@ -381,6 +381,10 @@ static void imx_drm_connector_unregister(
drm_mode_group_reinit(imxdrm->drm);
 }
 
+static struct drm_mode_config_funcs imx_drm_mode_config_funcs = {
+   .fb_create = drm_fb_cma_create,
+};
+
 /*
  * Main DRM initialisation. This binds, initialises and registers
  * with DRM the subcomponents of the driver.
@@ -406,8 +410,18 @@ static int imx_drm_driver_load(struct drm_device *drm, 
unsigned long flags)
 */
drm->irq_enabled = true;
 
+   /*
+* set max width and height as default value(4096x4096).
+* this value would be used to check framebuffer size limitation
+* at drm_mode_addfb().
+*/
+   drm->mode_config.min_width = 64;
+   drm->mode_config.min_height = 64;
+   drm->mode_config.max_width = 4096;
+   drm->mode_config.max_height = 4096;
+   drm->mode_config.funcs = &imx_drm_mode_config_funcs;
+
drm_mode_config_init(drm);
-   imx_drm_mode_config_init(drm);
 
mutex_lock(&imxdrm->mutex);
 
diff --git a/drivers/staging/imx-drm/imx-fb.c b/drivers/staging/imx-drm/imx-fb.c
deleted file mode 100644
index 03a7b4e14f67..
--- a/drivers/staging/imx-drm/imx-fb.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * i.MX drm driver
- *
- * Copyright (C) 2012 Sascha Hauer, Pengutronix
- *
- * Based on Samsung Exynos code
- *
- * Copyright (c) 2011 Samsung Electronics Co., Ltd.
- *
- * 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.
- *
- */
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include "imx-drm.h"
-
-static struct drm_mode_config_funcs imx_drm_mode_config_funcs = {
-   .fb_create = drm_fb_cma_create,
-};
-
-void imx_drm_mode_config_init(struct drm_device *dev)
-{
-   dev->mode_config.min_width = 64;
-   dev->mode_config.min_height = 64;
-
-   /*
-* set max width and height as default value(4096x4096).
-* this value would be used to check framebuffer size limitation
-* at drm_mode_addfb().
-*/
-   dev->mode_config.max_width = 4096;
-   dev->mode_config.max_height = 4096;
-
-   dev->mode_config.funcs = &imx_drm_mode_config_funcs;
-}
-- 
1.8.3.1

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


[PATCH RFC v2 24/35] imx-drm: use supplied drm_device where possible

2014-02-10 Thread Russell King
The component helper provides us the drm_device which is being
registered.  Rather than having to reference a global in imx-drm-core,
use this to get the imxdrm device, and also use it to register the CRTC
against.

This means we never have CRTCs/encoders/connectors without the drivers
private data being accessible.

Remove the module owner field as well; this provides no protection
against the device being unbound.

Signed-off-by: Russell King 
---
 drivers/staging/imx-drm/imx-drm-core.c | 34 +-
 drivers/staging/imx-drm/imx-drm.h  |  4 ++--
 drivers/staging/imx-drm/ipuv3-crtc.c   |  9 +
 3 files changed, 12 insertions(+), 35 deletions(-)

diff --git a/drivers/staging/imx-drm/imx-drm-core.c 
b/drivers/staging/imx-drm/imx-drm-core.c
index 3e3fd281fe6e..3d1c6b6c4388 100644
--- a/drivers/staging/imx-drm/imx-drm-core.c
+++ b/drivers/staging/imx-drm/imx-drm-core.c
@@ -52,7 +52,6 @@ struct imx_drm_crtc {
struct imx_drm_device   *imxdrm;
int pipe;
struct imx_drm_crtc_helper_funcsimx_drm_helper_funcs;
-   struct module   *owner;
struct crtc_cookie  cookie;
int mux_id;
 };
@@ -74,7 +73,6 @@ static int legacyfb_depth = 16;
 module_param(legacyfb_depth, int, 0444);
 
 static void imx_drm_device_put(void);
-static struct imx_drm_device *__imx_drm_device(void);
 
 int imx_drm_crtc_id(struct imx_drm_crtc *crtc)
 {
@@ -114,7 +112,7 @@ static int imx_drm_driver_unload(struct drm_device *drm)
 
 struct imx_drm_crtc *imx_drm_find_crtc(struct drm_crtc *crtc)
 {
-   struct imx_drm_device *imxdrm = __imx_drm_device();
+   struct imx_drm_device *imxdrm = crtc->dev->dev_private;
unsigned i;
 
for (i = 0; i < MAX_CRTC; i++)
@@ -241,7 +239,6 @@ static struct drm_device *imx_drm_device_get(void)
struct imx_drm_device *imxdrm = __imx_drm_device();
struct imx_drm_encoder *enc;
struct imx_drm_connector *con;
-   struct imx_drm_crtc *crtc;
 
list_for_each_entry(enc, &imxdrm->encoder_list, list) {
if (!try_module_get(enc->owner)) {
@@ -259,19 +256,8 @@ static struct drm_device *imx_drm_device_get(void)
}
}
 
-   list_for_each_entry(crtc, &imxdrm->crtc_list, list) {
-   if (!try_module_get(crtc->owner)) {
-   dev_err(imxdrm->dev, "could not get module %s\n",
-   module_name(crtc->owner));
-   goto unwind_crtc;
-   }
-   }
-
return imxdrm->drm;
 
-unwind_crtc:
-   list_for_each_entry_continue_reverse(crtc, &imxdrm->crtc_list, list)
-   module_put(crtc->owner);
 unwind_con:
list_for_each_entry_continue_reverse(con, &imxdrm->connector_list, list)
module_put(con->owner);
@@ -290,13 +276,9 @@ static void imx_drm_device_put(void)
struct imx_drm_device *imxdrm = __imx_drm_device();
struct imx_drm_encoder *enc;
struct imx_drm_connector *con;
-   struct imx_drm_crtc *crtc;
 
mutex_lock(&imxdrm->mutex);
 
-   list_for_each_entry(crtc, &imxdrm->crtc_list, list)
-   module_put(crtc->owner);
-
list_for_each_entry(con, &imxdrm->connector_list, list)
module_put(con->owner);
 
@@ -536,12 +518,12 @@ static void imx_drm_update_possible_crtcs(void)
  * The return value if !NULL is a cookie for the caller to pass to
  * imx_drm_remove_crtc later.
  */
-int imx_drm_add_crtc(struct drm_crtc *crtc,
+int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc,
struct imx_drm_crtc **new_crtc,
const struct imx_drm_crtc_helper_funcs *imx_drm_helper_funcs,
-   struct module *owner, void *cookie, int id)
+   void *cookie, int id)
 {
-   struct imx_drm_device *imxdrm = __imx_drm_device();
+   struct imx_drm_device *imxdrm = drm->dev_private;
struct imx_drm_crtc *imx_drm_crtc;
int ret;
 
@@ -575,8 +557,6 @@ int imx_drm_add_crtc(struct drm_crtc *crtc,
imx_drm_crtc->crtc = crtc;
imx_drm_crtc->imxdrm = imxdrm;
 
-   imx_drm_crtc->owner = owner;
-
imxdrm->crtc[imx_drm_crtc->pipe] = imx_drm_crtc;
 
*new_crtc = imx_drm_crtc;
@@ -588,11 +568,9 @@ int imx_drm_add_crtc(struct drm_crtc *crtc,
drm_crtc_helper_add(crtc,
imx_drm_crtc->imx_drm_helper_funcs.crtc_helper_funcs);
 
-   drm_crtc_init(imxdrm->drm, crtc,
+   drm_crtc_init(drm, crtc,
imx_drm_crtc->imx_drm_helper_funcs.crtc_funcs);
 
-   drm_mode_group_reinit(imxdrm->drm);
-
imx_drm_update_possible_crtcs();
 
mutex_unlock(&imxdrm->mutex);
@@ -622,8 +600,6 @@ int imx_drm_remove_crtc(struct imx_drm_crtc *imx_drm_crtc)
 
imxdrm->crtc[imx_drm_crtc->pipe] = NULL;
 
-  

[PATCH RFC v2 26/35] imx-drm: imx-drm-core: provide common connector and encoder cleanup functions

2014-02-10 Thread Russell King
Provide two helper functions to assist with cleaning up imx-drm
connectors and encoders.

Signed-off-by: Russell King 
---
 drivers/staging/imx-drm/imx-drm-core.c | 13 +
 drivers/staging/imx-drm/imx-drm.h  |  3 +++
 2 files changed, 16 insertions(+)

diff --git a/drivers/staging/imx-drm/imx-drm-core.c 
b/drivers/staging/imx-drm/imx-drm-core.c
index 5cac6ee24472..1f50acd5a982 100644
--- a/drivers/staging/imx-drm/imx-drm-core.c
+++ b/drivers/staging/imx-drm/imx-drm-core.c
@@ -363,6 +363,19 @@ static void imx_drm_connector_unregister(
drm_mode_group_reinit(imxdrm->drm);
 }
 
+void imx_drm_connector_destroy(struct drm_connector *connector)
+{
+   drm_sysfs_connector_remove(connector);
+   drm_connector_cleanup(connector);
+}
+EXPORT_SYMBOL_GPL(imx_drm_connector_destroy);
+
+void imx_drm_encoder_destroy(struct drm_encoder *encoder)
+{
+   drm_encoder_cleanup(encoder);
+}
+EXPORT_SYMBOL_GPL(imx_drm_encoder_destroy);
+
 static struct drm_mode_config_funcs imx_drm_mode_config_funcs = {
.fb_create = drm_fb_cma_create,
 };
diff --git a/drivers/staging/imx-drm/imx-drm.h 
b/drivers/staging/imx-drm/imx-drm.h
index 49d4aaf33f97..0543606c587a 100644
--- a/drivers/staging/imx-drm/imx-drm.h
+++ b/drivers/staging/imx-drm/imx-drm.h
@@ -8,6 +8,7 @@
 struct drm_crtc;
 struct drm_connector;
 struct drm_device;
+struct drm_display_mode;
 struct drm_encoder;
 struct imx_drm_crtc;
 struct drm_fbdev_cma;
@@ -69,5 +70,7 @@ int imx_drm_encoder_parse_of(struct drm_device *drm,
 
 int imx_drm_connector_mode_valid(struct drm_connector *connector,
struct drm_display_mode *mode);
+void imx_drm_connector_destroy(struct drm_connector *connector);
+void imx_drm_encoder_destroy(struct drm_encoder *encoder);
 
 #endif /* _IMX_DRM_H_ */
-- 
1.8.3.1

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


[PATCH RFC v2 28/35] imx-drm: imx-hdmi: initialise drm components directly

2014-02-10 Thread Russell King
Signed-off-by: Russell King 
---
 drivers/staging/imx-drm/imx-hdmi.c | 56 ++
 1 file changed, 15 insertions(+), 41 deletions(-)

diff --git a/drivers/staging/imx-drm/imx-hdmi.c 
b/drivers/staging/imx-drm/imx-hdmi.c
index 7086ea66490f..c5e57ac07243 100644
--- a/drivers/staging/imx-drm/imx-hdmi.c
+++ b/drivers/staging/imx-drm/imx-hdmi.c
@@ -112,9 +112,7 @@ struct hdmi_data_info {
 
 struct imx_hdmi {
struct drm_connector connector;
-   struct imx_drm_connector *imx_drm_connector;
struct drm_encoder encoder;
-   struct imx_drm_encoder *imx_drm_encoder;
 
enum imx_hdmi_devtype dev_type;
struct device *dev;
@@ -1377,10 +1375,6 @@ static enum drm_connector_status 
imx_hdmi_connector_detect(struct drm_connector
return connector_status_connected;
 }
 
-static void imx_hdmi_connector_destroy(struct drm_connector *connector)
-{
-}
-
 static int imx_hdmi_connector_get_modes(struct drm_connector *connector)
 {
struct imx_hdmi *hdmi = container_of(connector, struct imx_hdmi,
@@ -1466,13 +1460,8 @@ static void imx_hdmi_encoder_commit(struct drm_encoder 
*encoder)
imx_hdmi_poweron(hdmi);
 }
 
-static void imx_hdmi_encoder_destroy(struct drm_encoder *encoder)
-{
-   return;
-}
-
 static struct drm_encoder_funcs imx_hdmi_encoder_funcs = {
-   .destroy = imx_hdmi_encoder_destroy,
+   .destroy = imx_drm_encoder_destroy,
 };
 
 static struct drm_encoder_helper_funcs imx_hdmi_encoder_helper_funcs = {
@@ -1488,7 +1477,7 @@ static struct drm_connector_funcs 
imx_hdmi_connector_funcs = {
.dpms = drm_helper_connector_dpms,
.fill_modes = drm_helper_probe_single_connector_modes,
.detect = imx_hdmi_connector_detect,
-   .destroy = imx_hdmi_connector_destroy,
+   .destroy = imx_drm_connector_destroy,
 };
 
 static struct drm_connector_helper_funcs imx_hdmi_connector_helper_funcs = {
@@ -1528,34 +1517,23 @@ static irqreturn_t imx_hdmi_irq(int irq, void *dev_id)
return IRQ_HANDLED;
 }
 
-static int imx_hdmi_register(struct imx_hdmi *hdmi)
+static int imx_hdmi_register(struct drm_device *drm, struct imx_hdmi *hdmi)
 {
int ret;
 
-   hdmi->connector.funcs = &imx_hdmi_connector_funcs;
-   hdmi->encoder.funcs = &imx_hdmi_encoder_funcs;
-
-   hdmi->encoder.encoder_type = DRM_MODE_ENCODER_TMDS;
-   hdmi->connector.connector_type = DRM_MODE_CONNECTOR_HDMIA;
+   ret = imx_drm_encoder_parse_of(drm, &hdmi->encoder,
+  hdmi->dev->of_node);
+   if (ret)
+   return ret;
 
drm_encoder_helper_add(&hdmi->encoder, &imx_hdmi_encoder_helper_funcs);
-   ret = imx_drm_add_encoder(&hdmi->encoder, &hdmi->imx_drm_encoder,
-   THIS_MODULE);
-   if (ret) {
-   dev_err(hdmi->dev, "adding encoder failed: %d\n", ret);
-   return ret;
-   }
+   drm_encoder_init(drm, &hdmi->encoder, &imx_hdmi_encoder_funcs,
+DRM_MODE_ENCODER_TMDS);
 
drm_connector_helper_add(&hdmi->connector,
&imx_hdmi_connector_helper_funcs);
-
-   ret = imx_drm_add_connector(&hdmi->connector,
-   &hdmi->imx_drm_connector, THIS_MODULE);
-   if (ret) {
-   imx_drm_remove_encoder(hdmi->imx_drm_encoder);
-   dev_err(hdmi->dev, "adding connector failed: %d\n", ret);
-   return ret;
-   }
+   drm_connector_init(drm, &hdmi->connector, &imx_hdmi_connector_funcs,
+  DRM_MODE_CONNECTOR_HDMIA);
 
hdmi->connector.encoder = &hdmi->encoder;
 
@@ -1587,6 +1565,7 @@ static int imx_hdmi_bind(struct device *dev, struct 
device *master, void *data)
struct platform_device *pdev = to_platform_device(dev);
const struct of_device_id *of_id =
of_match_device(imx_hdmi_dt_ids, dev);
+   struct drm_device *drm = data;
struct device_node *np = dev->of_node;
struct device_node *ddc_node;
struct imx_hdmi *hdmi;
@@ -1694,12 +1673,10 @@ static int imx_hdmi_bind(struct device *dev, struct 
device *master, void *data)
if (ret)
goto err_iahb;
 
-   ret = imx_hdmi_register(hdmi);
+   ret = imx_hdmi_register(drm, hdmi);
if (ret)
goto err_iahb;
 
-   imx_drm_encoder_add_possible_crtcs(hdmi->imx_drm_encoder, np);
-
dev_set_drvdata(dev, hdmi);
 
return 0;
@@ -1716,12 +1693,9 @@ static void imx_hdmi_unbind(struct device *dev, struct 
device *master,
void *data)
 {
struct imx_hdmi *hdmi = dev_get_drvdata(dev);
-   struct drm_connector *connector = &hdmi->connector;
-   struct drm_encoder *encoder = &hdmi->encoder;
 
-   drm_mode_connector_detach_encoder(connector, encoder);
-   imx_drm_remove_connector(hdmi->imx_drm_connector);
-   imx_drm_remove_encoder(hdmi->imx_drm_encoder);
+   hdmi->connector.fu

[PATCH RFC v2 25/35] imx-drm: imx-drm-core: provide helper function to parse possible crtcs

2014-02-10 Thread Russell King
Provide a helper function to parse possible crtcs before the encoder
is registered.  The crtc mask is derived from the position of the
CRTCs registered in the drm_device.

Signed-off-by: Russell King 
---
 drivers/staging/imx-drm/imx-drm-core.c | 66 ++
 drivers/staging/imx-drm/imx-drm.h  |  2 ++
 2 files changed, 68 insertions(+)

diff --git a/drivers/staging/imx-drm/imx-drm-core.c 
b/drivers/staging/imx-drm/imx-drm-core.c
index 3d1c6b6c4388..5cac6ee24472 100644
--- a/drivers/staging/imx-drm/imx-drm-core.c
+++ b/drivers/staging/imx-drm/imx-drm-core.c
@@ -658,6 +658,72 @@ int imx_drm_add_encoder(struct drm_encoder *encoder,
 }
 EXPORT_SYMBOL_GPL(imx_drm_add_encoder);
 
+/*
+ * Find the DRM CRTC possible mask for the device node cookie/id.
+ *
+ * The encoder possible masks are defined by their position in the
+ * mode_config crtc_list.  This means that CRTCs must not be added
+ * or removed once the DRM device has been fully initialised.
+ */
+static uint32_t imx_drm_find_crtc_mask(struct imx_drm_device *imxdrm,
+   void *cookie, int id)
+{
+   unsigned i;
+
+   for (i = 0; i < MAX_CRTC; i++) {
+   struct imx_drm_crtc *imx_drm_crtc = imxdrm->crtc[i];
+   if (imx_drm_crtc && imx_drm_crtc->cookie.id == id &&
+   imx_drm_crtc->cookie.cookie == cookie)
+   return drm_crtc_mask(imx_drm_crtc->crtc);
+   }
+
+   return 0;
+}
+
+int imx_drm_encoder_parse_of(struct drm_device *drm,
+   struct drm_encoder *encoder, struct device_node *np)
+{
+   struct imx_drm_device *imxdrm = drm->dev_private;
+   uint32_t crtc_mask = 0;
+   int i, ret = 0;
+
+   for (i = 0; !ret; i++) {
+   struct of_phandle_args args;
+   uint32_t mask;
+   int id;
+
+   ret = of_parse_phandle_with_args(np, "crtcs", "#crtc-cells", i,
+&args);
+   if (ret == -ENOENT)
+   break;
+   if (ret < 0)
+   return ret;
+
+   id = args.args_count > 0 ? args.args[0] : 0;
+   mask = imx_drm_find_crtc_mask(imxdrm, args.np, id);
+   of_node_put(args.np);
+
+   /*
+* If we failed to find the CRTC(s) which this encoder is
+* supposed to be connected to, it's because the CRTC has
+* not been registered yet.  Defer probing, and hope that
+* the required CRTC is added later.
+*/
+   if (mask == 0)
+   return -EPROBE_DEFER;
+
+   crtc_mask |= mask;
+   }
+
+   encoder->possible_crtcs = crtc_mask;
+
+   /* FIXME: this is the mask of outputs which can clone this output. */
+   encoder->possible_clones = ~0;
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(imx_drm_encoder_parse_of);
+
 int imx_drm_encoder_add_possible_crtcs(
struct imx_drm_encoder *imx_drm_encoder,
struct device_node *np)
diff --git a/drivers/staging/imx-drm/imx-drm.h 
b/drivers/staging/imx-drm/imx-drm.h
index 78465239ed4c..49d4aaf33f97 100644
--- a/drivers/staging/imx-drm/imx-drm.h
+++ b/drivers/staging/imx-drm/imx-drm.h
@@ -64,6 +64,8 @@ struct device_node;
 int imx_drm_encoder_get_mux_id(struct drm_encoder *encoder);
 int imx_drm_encoder_add_possible_crtcs(struct imx_drm_encoder *imx_drm_encoder,
struct device_node *np);
+int imx_drm_encoder_parse_of(struct drm_device *drm,
+   struct drm_encoder *encoder, struct device_node *np);
 
 int imx_drm_connector_mode_valid(struct drm_connector *connector,
struct drm_display_mode *mode);
-- 
1.8.3.1

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


[PATCH RFC v2 27/35] imx-drm: parallel-display,imx-tve,imx-ldb: initialise drm components directly

2014-02-10 Thread Russell King
Now that our bind function is only ever called during the main DRM
driver ->load callback, we don't need to have the imx_drm_connector or
imx_drm_encoder abstractions anymore.  So let's get rid of it, and move
the DRM connector and encoder setup into the connector support files.

Signed-off-by: Russell King 
---
 drivers/staging/imx-drm/imx-ldb.c  | 68 ++
 drivers/staging/imx-drm/imx-tve.c  | 58 +++--
 drivers/staging/imx-drm/parallel-display.c | 61 ---
 3 files changed, 54 insertions(+), 133 deletions(-)

diff --git a/drivers/staging/imx-drm/imx-ldb.c 
b/drivers/staging/imx-drm/imx-ldb.c
index d00f93f3440d..5168c76cff53 100644
--- a/drivers/staging/imx-drm/imx-ldb.c
+++ b/drivers/staging/imx-drm/imx-ldb.c
@@ -59,9 +59,8 @@ struct imx_ldb;
 struct imx_ldb_channel {
struct imx_ldb *ldb;
struct drm_connector connector;
-   struct imx_drm_connector *imx_drm_connector;
struct drm_encoder encoder;
-   struct imx_drm_encoder *imx_drm_encoder;
+   struct device_node *child;
int chno;
void *edid;
int edid_len;
@@ -92,11 +91,6 @@ static enum drm_connector_status imx_ldb_connector_detect(
return connector_status_connected;
 }
 
-static void imx_ldb_connector_destroy(struct drm_connector *connector)
-{
-   /* do not free here */
-}
-
 static int imx_ldb_connector_get_modes(struct drm_connector *connector)
 {
struct imx_ldb_channel *imx_ldb_ch = con_to_imx_ldb_ch(connector);
@@ -308,16 +302,11 @@ static void imx_ldb_encoder_disable(struct drm_encoder 
*encoder)
}
 }
 
-static void imx_ldb_encoder_destroy(struct drm_encoder *encoder)
-{
-   /* do not free here */
-}
-
 static struct drm_connector_funcs imx_ldb_connector_funcs = {
.dpms = drm_helper_connector_dpms,
.fill_modes = drm_helper_probe_single_connector_modes,
.detect = imx_ldb_connector_detect,
-   .destroy = imx_ldb_connector_destroy,
+   .destroy = imx_drm_connector_destroy,
 };
 
 static struct drm_connector_helper_funcs imx_ldb_connector_helper_funcs = {
@@ -327,7 +316,7 @@ static struct drm_connector_helper_funcs 
imx_ldb_connector_helper_funcs = {
 };
 
 static struct drm_encoder_funcs imx_ldb_encoder_funcs = {
-   .destroy = imx_ldb_encoder_destroy,
+   .destroy = imx_drm_encoder_destroy,
 };
 
 static struct drm_encoder_helper_funcs imx_ldb_encoder_helper_funcs = {
@@ -354,45 +343,36 @@ static int imx_ldb_get_clk(struct imx_ldb *ldb, int chno)
return PTR_ERR_OR_ZERO(ldb->clk_pll[chno]);
 }
 
-static int imx_ldb_register(struct imx_ldb_channel *imx_ldb_ch)
+static int imx_ldb_register(struct drm_device *drm,
+   struct imx_ldb_channel *imx_ldb_ch)
 {
-   int ret;
struct imx_ldb *ldb = imx_ldb_ch->ldb;
+   int ret;
+
+   ret = imx_drm_encoder_parse_of(drm, &imx_ldb_ch->encoder,
+  imx_ldb_ch->child);
+   if (ret)
+   return ret;
 
ret = imx_ldb_get_clk(ldb, imx_ldb_ch->chno);
if (ret)
return ret;
+
if (ldb->ldb_ctrl & LDB_SPLIT_MODE_EN) {
-   ret |= imx_ldb_get_clk(ldb, 1);
+   ret = imx_ldb_get_clk(ldb, 1);
if (ret)
return ret;
}
 
-   imx_ldb_ch->connector.funcs = &imx_ldb_connector_funcs;
-   imx_ldb_ch->encoder.funcs = &imx_ldb_encoder_funcs;
-
-   imx_ldb_ch->encoder.encoder_type = DRM_MODE_ENCODER_LVDS;
-   imx_ldb_ch->connector.connector_type = DRM_MODE_CONNECTOR_LVDS;
-
drm_encoder_helper_add(&imx_ldb_ch->encoder,
&imx_ldb_encoder_helper_funcs);
-   ret = imx_drm_add_encoder(&imx_ldb_ch->encoder,
-   &imx_ldb_ch->imx_drm_encoder, THIS_MODULE);
-   if (ret) {
-   dev_err(ldb->dev, "adding encoder failed with %d\n", ret);
-   return ret;
-   }
+   drm_encoder_init(drm, &imx_ldb_ch->encoder, &imx_ldb_encoder_funcs,
+DRM_MODE_ENCODER_LVDS);
 
drm_connector_helper_add(&imx_ldb_ch->connector,
&imx_ldb_connector_helper_funcs);
-
-   ret = imx_drm_add_connector(&imx_ldb_ch->connector,
-   &imx_ldb_ch->imx_drm_connector, THIS_MODULE);
-   if (ret) {
-   imx_drm_remove_encoder(imx_ldb_ch->imx_drm_encoder);
-   dev_err(ldb->dev, "adding connector failed with %d\n", ret);
-   return ret;
-   }
+   drm_connector_init(drm, &imx_ldb_ch->connector,
+  &imx_ldb_connector_funcs, DRM_MODE_CONNECTOR_LVDS);
 
drm_mode_connector_attach_encoder(&imx_ldb_ch->connector,
&imx_ldb_ch->encoder);
@@ -453,6 +433,7 @@ MODULE_DEVICE_TABLE(of, imx_ldb_dt_ids);
 
 static int imx_ldb_bind(struct device *dev, struct device *master, void *data)
 {
+   struct drm_device *drm = data;
  

  1   2   >