]> rtime.felk.cvut.cz Git - linux-imx.git/commitdiff
staging: comedi: comedi_pcmcia: introduce comedi_pcmcia_{enable, disable}
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Mon, 4 Feb 2013 21:19:35 +0000 (14:19 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 4 Feb 2013 22:47:18 +0000 (14:47 -0800)
Introduce some helper functions to enable/disable the PCMCIA device.
This will allow removing some of the boilerplate code in the comedi
PCMCIA drivers.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/comedi_pcmcia.c
drivers/staging/comedi/comedidev.h

index f10bcc529585ebae867e57eb544625765dbc4dbc..925f12825c1b052c5c94c3e51aadd9194790c0c1 100644 (file)
@@ -37,6 +37,52 @@ struct pcmcia_device *comedi_to_pcmcia_dev(struct comedi_device *dev)
 }
 EXPORT_SYMBOL_GPL(comedi_to_pcmcia_dev);
 
+static int comedi_pcmcia_conf_check(struct pcmcia_device *link,
+                                   void *priv_data)
+{
+       if (link->config_index == 0)
+               return -EINVAL;
+
+       return pcmcia_request_io(link);
+}
+
+/**
+ * comedi_pcmcia_enable() - Request the regions and enable the PCMCIA device.
+ * @dev: comedi_device struct
+ *
+ * The comedi PCMCIA driver needs to set the link->config_flags, as
+ * appropriate for that driver, before calling this function in order
+ * to allow pcmcia_loop_config() to do its internal autoconfiguration.
+ */
+int comedi_pcmcia_enable(struct comedi_device *dev)
+{
+       struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);
+       int ret;
+
+       if (!link)
+               return -ENODEV;
+
+       ret = pcmcia_loop_config(link, comedi_pcmcia_conf_check, NULL);
+       if (ret)
+               return ret;
+
+       return pcmcia_enable_device(link);
+}
+EXPORT_SYMBOL_GPL(comedi_pcmcia_enable);
+
+/**
+ * comedi_pcmcia_disable() - Disable the PCMCIA device and release the regions.
+ * @dev: comedi_device struct
+ */
+void comedi_pcmcia_disable(struct comedi_device *dev)
+{
+       struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);
+
+       if (link)
+               pcmcia_disable_device(link);
+}
+EXPORT_SYMBOL_GPL(comedi_pcmcia_disable);
+
 /**
  * comedi_pcmcia_auto_config() - Configure/probe a comedi PCMCIA driver.
  * @link: pcmcia_device struct
index b7bb120f48be996c0bd5e66088c3e0755d641225..4836fe6dfb356aa83843192c23ccbc8576906b3f 100644 (file)
@@ -440,6 +440,9 @@ struct pcmcia_device;
 
 struct pcmcia_device *comedi_to_pcmcia_dev(struct comedi_device *);
 
+int comedi_pcmcia_enable(struct comedi_device *);
+void comedi_pcmcia_disable(struct comedi_device *);
+
 int comedi_pcmcia_auto_config(struct pcmcia_device *, struct comedi_driver *);
 void comedi_pcmcia_auto_unconfig(struct pcmcia_device *);