linux/drivers/staging/comedi/comedi_pcmcia.c
<<
>>
Prefs
   1/*
   2 * comedi_pcmcia.c
   3 * Comedi PCMCIA driver specific functions.
   4 *
   5 * COMEDI - Linux Control and Measurement Device Interface
   6 * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
   7 *
   8 * This program is free software; you can redistribute it and/or modify
   9 * it under the terms of the GNU General Public License as published by
  10 * the Free Software Foundation; either version 2 of the License, or
  11 * (at your option) any later version.
  12 *
  13 * This program is distributed in the hope that it will be useful,
  14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16 * GNU General Public License for more details.
  17 */
  18
  19#include <linux/module.h>
  20#include <linux/kernel.h>
  21
  22#include "comedi_pcmcia.h"
  23
  24/**
  25 * comedi_to_pcmcia_dev() - comedi_device pointer to pcmcia_device pointer.
  26 * @dev: comedi_device struct
  27 */
  28struct pcmcia_device *comedi_to_pcmcia_dev(struct comedi_device *dev)
  29{
  30        return dev->hw_dev ? to_pcmcia_dev(dev->hw_dev) : NULL;
  31}
  32EXPORT_SYMBOL_GPL(comedi_to_pcmcia_dev);
  33
  34static int comedi_pcmcia_conf_check(struct pcmcia_device *link,
  35                                    void *priv_data)
  36{
  37        if (link->config_index == 0)
  38                return -EINVAL;
  39
  40        return pcmcia_request_io(link);
  41}
  42
  43/**
  44 * comedi_pcmcia_enable() - Request the regions and enable the PCMCIA device.
  45 * @dev: comedi_device struct
  46 * @conf_check: optional callback to check the pcmcia_device configuration
  47 *
  48 * The comedi PCMCIA driver needs to set the link->config_flags, as
  49 * appropriate for that driver, before calling this function in order
  50 * to allow pcmcia_loop_config() to do its internal autoconfiguration.
  51 */
  52int comedi_pcmcia_enable(struct comedi_device *dev,
  53                         int (*conf_check)(struct pcmcia_device *, void *))
  54{
  55        struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);
  56        int ret;
  57
  58        if (!link)
  59                return -ENODEV;
  60
  61        if (!conf_check)
  62                conf_check = comedi_pcmcia_conf_check;
  63
  64        ret = pcmcia_loop_config(link, conf_check, NULL);
  65        if (ret)
  66                return ret;
  67
  68        return pcmcia_enable_device(link);
  69}
  70EXPORT_SYMBOL_GPL(comedi_pcmcia_enable);
  71
  72/**
  73 * comedi_pcmcia_disable() - Disable the PCMCIA device and release the regions.
  74 * @dev: comedi_device struct
  75 */
  76void comedi_pcmcia_disable(struct comedi_device *dev)
  77{
  78        struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);
  79
  80        if (link)
  81                pcmcia_disable_device(link);
  82}
  83EXPORT_SYMBOL_GPL(comedi_pcmcia_disable);
  84
  85/**
  86 * comedi_pcmcia_auto_config() - Configure/probe a comedi PCMCIA driver.
  87 * @link: pcmcia_device struct
  88 * @driver: comedi_driver struct
  89 *
  90 * Typically called from the pcmcia_driver (*probe) function.
  91 */
  92int comedi_pcmcia_auto_config(struct pcmcia_device *link,
  93                              struct comedi_driver *driver)
  94{
  95        return comedi_auto_config(&link->dev, driver, 0);
  96}
  97EXPORT_SYMBOL_GPL(comedi_pcmcia_auto_config);
  98
  99/**
 100 * comedi_pcmcia_auto_unconfig() - Unconfigure/remove a comedi PCMCIA driver.
 101 * @link: pcmcia_device struct
 102 *
 103 * Typically called from the pcmcia_driver (*remove) function.
 104 */
 105void comedi_pcmcia_auto_unconfig(struct pcmcia_device *link)
 106{
 107        comedi_auto_unconfig(&link->dev);
 108}
 109EXPORT_SYMBOL_GPL(comedi_pcmcia_auto_unconfig);
 110
 111/**
 112 * comedi_pcmcia_driver_register() - Register a comedi PCMCIA driver.
 113 * @comedi_driver: comedi_driver struct
 114 * @pcmcia_driver: pcmcia_driver struct
 115 *
 116 * This function is used for the module_init() of comedi USB drivers.
 117 * Do not call it directly, use the module_comedi_pcmcia_driver() helper
 118 * macro instead.
 119 */
 120int comedi_pcmcia_driver_register(struct comedi_driver *comedi_driver,
 121                                  struct pcmcia_driver *pcmcia_driver)
 122{
 123        int ret;
 124
 125        ret = comedi_driver_register(comedi_driver);
 126        if (ret < 0)
 127                return ret;
 128
 129        ret = pcmcia_register_driver(pcmcia_driver);
 130        if (ret < 0) {
 131                comedi_driver_unregister(comedi_driver);
 132                return ret;
 133        }
 134
 135        return 0;
 136}
 137EXPORT_SYMBOL_GPL(comedi_pcmcia_driver_register);
 138
 139/**
 140 * comedi_pcmcia_driver_unregister() - Unregister a comedi PCMCIA driver.
 141 * @comedi_driver: comedi_driver struct
 142 * @pcmcia_driver: pcmcia_driver struct
 143 *
 144 * This function is used for the module_exit() of comedi PCMCIA drivers.
 145 * Do not call it directly, use the module_comedi_pcmcia_driver() helper
 146 * macro instead.
 147 */
 148void comedi_pcmcia_driver_unregister(struct comedi_driver *comedi_driver,
 149                                     struct pcmcia_driver *pcmcia_driver)
 150{
 151        pcmcia_unregister_driver(pcmcia_driver);
 152        comedi_driver_unregister(comedi_driver);
 153}
 154EXPORT_SYMBOL_GPL(comedi_pcmcia_driver_unregister);
 155
 156static int __init comedi_pcmcia_init(void)
 157{
 158        return 0;
 159}
 160module_init(comedi_pcmcia_init);
 161
 162static void __exit comedi_pcmcia_exit(void)
 163{
 164}
 165module_exit(comedi_pcmcia_exit);
 166
 167MODULE_AUTHOR("http://www.comedi.org");
 168MODULE_DESCRIPTION("Comedi PCMCIA interface module");
 169MODULE_LICENSE("GPL");
 170