sedlbauer_cs.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:22k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*======================================================================
  2.     A Sedlbauer PCMCIA client driver
  3.     This driver is for the Sedlbauer Speed Star and Speed Star II, 
  4.     which are ISDN PCMCIA Cards.
  5.     
  6.     The contents of this file are subject to the Mozilla Public
  7.     License Version 1.1 (the "License"); you may not use this file
  8.     except in compliance with the License. You may obtain a copy of
  9.     the License at http://www.mozilla.org/MPL/
  10.     Software distributed under the License is distributed on an "AS
  11.     IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  12.     implied. See the License for the specific language governing
  13.     rights and limitations under the License.
  14.     The initial developer of the original code is David A. Hinds
  15.     <dahinds@users.sourceforge.net>.  Portions created by David A. Hinds
  16.     are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.
  17.     Modifications from dummy_cs.c are Copyright (C) 1999-2001 Marcus Niemann
  18.     <maniemann@users.sourceforge.net>. All Rights Reserved.
  19.     Alternatively, the contents of this file may be used under the
  20.     terms of the GNU General Public License version 2 (the "GPL"), in
  21.     which case the provisions of the GPL are applicable instead of the
  22.     above.  If you wish to allow the use of your version of this file
  23.     only under the terms of the GPL and not to allow others to use
  24.     your version of this file under the MPL, indicate your decision
  25.     by deleting the provisions above and replace them with the notice
  26.     and other provisions required by the GPL.  If you do not delete
  27.     the provisions above, a recipient may use your version of this
  28.     file under either the MPL or the GPL.
  29.     
  30. ======================================================================*/
  31. #include <linux/kernel.h>
  32. #include <linux/module.h>
  33. #include <linux/init.h>
  34. #include <linux/sched.h>
  35. #include <linux/ptrace.h>
  36. #include <linux/slab.h>
  37. #include <linux/string.h>
  38. #include <linux/timer.h>
  39. #include <linux/ioport.h>
  40. #include <asm/io.h>
  41. #include <asm/system.h>
  42. #include <pcmcia/version.h>
  43. #include <pcmcia/cs_types.h>
  44. #include <pcmcia/cs.h>
  45. #include <pcmcia/cistpl.h>
  46. #include <pcmcia/cisreg.h>
  47. #include <pcmcia/ds.h>
  48. #include <pcmcia/bus_ops.h>
  49. MODULE_DESCRIPTION("ISDN4Linux: PCMCIA client driver for Sedlbauer cards");
  50. MODULE_AUTHOR("Marcus Niemann");
  51. MODULE_LICENSE("Dual MPL/GPL");
  52. /*
  53.    All the PCMCIA modules use PCMCIA_DEBUG to control debugging.  If
  54.    you do not define PCMCIA_DEBUG at all, all the debug code will be
  55.    left out.  If you compile with PCMCIA_DEBUG=0, the debug code will
  56.    be present but disabled -- but it can then be enabled for specific
  57.    modules at load time with a 'pc_debug=#' option to insmod.
  58. */
  59. #ifdef PCMCIA_DEBUG
  60. static int pc_debug = PCMCIA_DEBUG;
  61. MODULE_PARM(pc_debug, "i");
  62. #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args); 
  63. static char *version =
  64. "sedlbauer_cs.c 1.1a 2001/01/28 15:04:04 (M.Niemann)";
  65. #else
  66. #define DEBUG(n, args...)
  67. #endif
  68. /*====================================================================*/
  69. /* Parameters that can be set with 'insmod' */
  70. /* The old way: bit map of interrupts to choose from */
  71. /* This means pick from 15, 14, 12, 11, 10, 9, 7, 5, 4, and 3 */
  72. static u_int irq_mask = 0xdeb8;
  73. /* Newer, simpler way of listing specific interrupts */
  74. static int irq_list[4] = { -1 };
  75. MODULE_PARM(irq_mask, "i");
  76. MODULE_PARM(irq_list, "1-4i");
  77. static int protocol = 2;        /* EURO-ISDN Default */
  78. MODULE_PARM(protocol, "i");
  79. extern int sedl_init_pcmcia(int, int, int*, int);
  80. /*====================================================================*/
  81. /*
  82.    The event() function is this driver's Card Services event handler.
  83.    It will be called by Card Services when an appropriate card status
  84.    event is received.  The config() and release() entry points are
  85.    used to configure or release a socket, in response to card
  86.    insertion and ejection events.  They are invoked from the sedlbauer
  87.    event handler. 
  88. */
  89. static void sedlbauer_config(dev_link_t *link);
  90. static void sedlbauer_release(u_long arg);
  91. static int sedlbauer_event(event_t event, int priority,
  92.        event_callback_args_t *args);
  93. /*
  94.    The attach() and detach() entry points are used to create and destroy
  95.    "instances" of the driver, where each instance represents everything
  96.    needed to manage one actual PCMCIA card.
  97. */
  98. static dev_link_t *sedlbauer_attach(void);
  99. static void sedlbauer_detach(dev_link_t *);
  100. /*
  101.    You'll also need to prototype all the functions that will actually
  102.    be used to talk to your device.  See 'memory_cs' for a good example
  103.    of a fully self-sufficient driver; the other drivers rely more or
  104.    less on other parts of the kernel.
  105. */
  106. /*
  107.    The dev_info variable is the "key" that is used to match up this
  108.    device driver with appropriate cards, through the card configuration
  109.    database.
  110. */
  111. static dev_info_t dev_info = "sedlbauer_cs";
  112. /*
  113.    A linked list of "instances" of the sedlbauer device.  Each actual
  114.    PCMCIA card corresponds to one device instance, and is described
  115.    by one dev_link_t structure (defined in ds.h).
  116.    You may not want to use a linked list for this -- for example, the
  117.    memory card driver uses an array of dev_link_t pointers, where minor
  118.    device numbers are used to derive the corresponding array index.
  119. */
  120. static dev_link_t *dev_list = NULL;
  121. /*
  122.    A dev_link_t structure has fields for most things that are needed
  123.    to keep track of a socket, but there will usually be some device
  124.    specific information that also needs to be kept track of.  The
  125.    'priv' pointer in a dev_link_t structure can be used to point to
  126.    a device-specific private data structure, like this.
  127.    To simplify the data structure handling, we actually include the
  128.    dev_link_t structure in the device's private data structure.
  129.    A driver needs to provide a dev_node_t structure for each device
  130.    on a card.  In some cases, there is only one device per card (for
  131.    example, ethernet cards, modems).  In other cases, there may be
  132.    many actual or logical devices (SCSI adapters, memory cards with
  133.    multiple partitions).  The dev_node_t structures need to be kept
  134.    in a linked list starting at the 'dev' field of a dev_link_t
  135.    structure.  We allocate them in the card's private data structure,
  136.    because they generally shouldn't be allocated dynamically.
  137.    In this case, we also provide a flag to indicate if a device is
  138.    "stopped" due to a power management event, or card ejection.  The
  139.    device IO routines can use a flag like this to throttle IO to a
  140.    card that is not ready to accept it.
  141.    The bus_operations pointer is used on platforms for which we need
  142.    to use special socket-specific versions of normal IO primitives
  143.    (inb, outb, readb, writeb, etc) for card IO.
  144. */
  145.    
  146. typedef struct local_info_t {
  147.     dev_link_t link;
  148.     dev_node_t node;
  149.     int stop;
  150.     struct bus_operations *bus;
  151. } local_info_t;
  152. /*====================================================================*/
  153. static void cs_error(client_handle_t handle, int func, int ret)
  154. {
  155.     error_info_t err = { func, ret };
  156.     CardServices(ReportError, handle, &err);
  157. }
  158. /*======================================================================
  159.     sedlbauer_attach() creates an "instance" of the driver, allocating
  160.     local data structures for one device.  The device is registered
  161.     with Card Services.
  162.     The dev_link structure is initialized, but we don't actually
  163.     configure the card at this point -- we wait until we receive a
  164.     card insertion event.
  165.     
  166. ======================================================================*/
  167. static dev_link_t *sedlbauer_attach(void)
  168. {
  169.     local_info_t *local;
  170.     dev_link_t *link;
  171.     client_reg_t client_reg;
  172.     int ret, i;
  173.     
  174.     DEBUG(0, "sedlbauer_attach()n");
  175.     /* Allocate space for private device-specific data */
  176.     local = kmalloc(sizeof(local_info_t), GFP_KERNEL);
  177.     if (!local) return NULL;
  178.     memset(local, 0, sizeof(local_info_t));
  179.     link = &local->link; link->priv = local;
  180.     
  181.     /* Initialize the dev_link_t structure */
  182.     link->release.function = &sedlbauer_release;
  183.     link->release.data = (u_long)link;
  184.     /* Interrupt setup */
  185.     link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
  186.     link->irq.IRQInfo1 = IRQ_INFO2_VALID|IRQ_LEVEL_ID;
  187.     if (irq_list[0] == -1)
  188. link->irq.IRQInfo2 = irq_mask;
  189.     else
  190. for (i = 0; i < 4; i++)
  191.     link->irq.IRQInfo2 |= 1 << irq_list[i];
  192.     link->irq.Handler = NULL;
  193.     
  194.     /*
  195.       General socket configuration defaults can go here.  In this
  196.       client, we assume very little, and rely on the CIS for almost
  197.       everything.  In most clients, many details (i.e., number, sizes,
  198.       and attributes of IO windows) are fixed by the nature of the
  199.       device, and can be hard-wired here.
  200.     */
  201.     /* from old sedl_cs 
  202.     */
  203.     /* The io structure describes IO port mapping */
  204.     link->io.NumPorts1 = 8;
  205.     link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
  206.     link->io.IOAddrLines = 3;
  207.     link->conf.Attributes = 0;
  208.     link->conf.Vcc = 50;
  209.     link->conf.IntType = INT_MEMORY_AND_IO;
  210.     /* Register with Card Services */
  211.     link->next = dev_list;
  212.     dev_list = link;
  213.     client_reg.dev_info = &dev_info;
  214.     client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE;
  215.     client_reg.EventMask =
  216. CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
  217. CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
  218. CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
  219.     client_reg.event_handler = &sedlbauer_event;
  220.     client_reg.Version = 0x0210;
  221.     client_reg.event_callback_args.client_data = link;
  222.     ret = CardServices(RegisterClient, &link->handle, &client_reg);
  223.     if (ret != CS_SUCCESS) {
  224. cs_error(link->handle, RegisterClient, ret);
  225. sedlbauer_detach(link);
  226. return NULL;
  227.     }
  228.     return link;
  229. } /* sedlbauer_attach */
  230. /*======================================================================
  231.     This deletes a driver "instance".  The device is de-registered
  232.     with Card Services.  If it has been released, all local data
  233.     structures are freed.  Otherwise, the structures will be freed
  234.     when the device is released.
  235. ======================================================================*/
  236. static void sedlbauer_detach(dev_link_t *link)
  237. {
  238.     dev_link_t **linkp;
  239.     DEBUG(0, "sedlbauer_detach(0x%p)n", link);
  240.     
  241.     /* Locate device structure */
  242.     for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
  243. if (*linkp == link) break;
  244.     if (*linkp == NULL)
  245. return;
  246.     /*
  247.        If the device is currently configured and active, we won't
  248.        actually delete it yet.  Instead, it is marked so that when
  249.        the release() function is called, that will trigger a proper
  250.        detach().
  251.     */
  252.     if (link->state & DEV_CONFIG) {
  253. #ifdef PCMCIA_DEBUG
  254. printk(KERN_DEBUG "sedlbauer_cs: detach postponed, '%s' "
  255.        "still lockedn", link->dev->dev_name);
  256. #endif
  257. link->state |= DEV_STALE_LINK;
  258. return;
  259.     }
  260.     /* Break the link with Card Services */
  261.     if (link->handle)
  262. CardServices(DeregisterClient, link->handle);
  263.     
  264.     /* Unlink device structure, and free it */
  265.     *linkp = link->next;
  266.     /* This points to the parent local_info_t struct */
  267.     kfree(link->priv);
  268. } /* sedlbauer_detach */
  269. /*======================================================================
  270.     sedlbauer_config() is scheduled to run after a CARD_INSERTION event
  271.     is received, to configure the PCMCIA socket, and to make the
  272.     device available to the system.
  273.     
  274. ======================================================================*/
  275. #define CS_CHECK(fn, args...) 
  276. while ((last_ret=CardServices(last_fn=(fn),args))!=0) goto cs_failed
  277. #define CFG_CHECK(fn, args...) 
  278. if (CardServices(fn, args) != 0) goto next_entry
  279. static void sedlbauer_config(dev_link_t *link)
  280. {
  281.     client_handle_t handle = link->handle;
  282.     local_info_t *dev = link->priv;
  283.     tuple_t tuple;
  284.     cisparse_t parse;
  285.     int last_fn, last_ret;
  286.     u_char buf[64];
  287.     config_info_t conf;
  288.     win_req_t req;
  289.     memreq_t map;
  290.     
  291.     DEBUG(0, "sedlbauer_config(0x%p)n", link);
  292.     /*
  293.        This reads the card's CONFIG tuple to find its configuration
  294.        registers.
  295.     */
  296.     tuple.DesiredTuple = CISTPL_CONFIG;
  297.     tuple.Attributes = 0;
  298.     tuple.TupleData = buf;
  299.     tuple.TupleDataMax = sizeof(buf);
  300.     tuple.TupleOffset = 0;
  301.     CS_CHECK(GetFirstTuple, handle, &tuple);
  302.     CS_CHECK(GetTupleData, handle, &tuple);
  303.     CS_CHECK(ParseTuple, handle, &tuple, &parse);
  304.     link->conf.ConfigBase = parse.config.base;
  305.     link->conf.Present = parse.config.rmask[0];
  306.     
  307.     /* Configure card */
  308.     link->state |= DEV_CONFIG;
  309.     /* Look up the current Vcc */
  310.     CS_CHECK(GetConfigurationInfo, handle, &conf);
  311.     link->conf.Vcc = conf.Vcc;
  312.     /*
  313.       In this loop, we scan the CIS for configuration table entries,
  314.       each of which describes a valid card configuration, including
  315.       voltage, IO window, memory window, and interrupt settings.
  316.       We make no assumptions about the card to be configured: we use
  317.       just the information available in the CIS.  In an ideal world,
  318.       this would work for any PCMCIA card, but it requires a complete
  319.       and accurate CIS.  In practice, a driver usually "knows" most of
  320.       these things without consulting the CIS, and most client drivers
  321.       will only use the CIS to fill in implementation-defined details.
  322.     */
  323.     tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
  324.     CS_CHECK(GetFirstTuple, handle, &tuple);
  325.     while (1) {
  326. cistpl_cftable_entry_t dflt = { 0 };
  327. cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
  328. CFG_CHECK(GetTupleData, handle, &tuple);
  329. CFG_CHECK(ParseTuple, handle, &tuple, &parse);
  330. if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg;
  331. if (cfg->index == 0) goto next_entry;
  332. link->conf.ConfigIndex = cfg->index;
  333. /* Does this card need audio output? */
  334. if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
  335.     link->conf.Attributes |= CONF_ENABLE_SPKR;
  336.     link->conf.Status = CCSR_AUDIO_ENA;
  337. }
  338. /* Use power settings for Vcc and Vpp if present */
  339. /*  Note that the CIS values need to be rescaled */
  340. if (cfg->vcc.present & (1<<CISTPL_POWER_VNOM)) {
  341.     if (conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM]/10000)
  342. goto next_entry;
  343. } else if (dflt.vcc.present & (1<<CISTPL_POWER_VNOM)) {
  344.     if (conf.Vcc != dflt.vcc.param[CISTPL_POWER_VNOM]/10000)
  345. goto next_entry;
  346. }
  347.     
  348. if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
  349.     link->conf.Vpp1 = link->conf.Vpp2 =
  350. cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
  351. else if (dflt.vpp1.present & (1<<CISTPL_POWER_VNOM))
  352.     link->conf.Vpp1 = link->conf.Vpp2 =
  353. dflt.vpp1.param[CISTPL_POWER_VNOM]/10000;
  354. /* Do we need to allocate an interrupt? */
  355. if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1)
  356.     link->conf.Attributes |= CONF_ENABLE_IRQ;
  357. /* IO window settings */
  358. link->io.NumPorts1 = link->io.NumPorts2 = 0;
  359. if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
  360.     cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
  361.     link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
  362.     if (!(io->flags & CISTPL_IO_8BIT))
  363. link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
  364.     if (!(io->flags & CISTPL_IO_16BIT))
  365. link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
  366. /* new in dummy.cs 2001/01/28 MN 
  367.             link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
  368. */
  369.     link->io.BasePort1 = io->win[0].base;
  370.     link->io.NumPorts1 = io->win[0].len;
  371.     if (io->nwin > 1) {
  372. link->io.Attributes2 = link->io.Attributes1;
  373. link->io.BasePort2 = io->win[1].base;
  374. link->io.NumPorts2 = io->win[1].len;
  375.     }
  376.     /* This reserves IO space but doesn't actually enable it */
  377.     CFG_CHECK(RequestIO, link->handle, &link->io);
  378. }
  379. /*
  380.   Now set up a common memory window, if needed.  There is room
  381.   in the dev_link_t structure for one memory window handle,
  382.   but if the base addresses need to be saved, or if multiple
  383.   windows are needed, the info should go in the private data
  384.   structure for this device.
  385.   Note that the memory window base is a physical address, and
  386.   needs to be mapped to virtual space with ioremap() before it
  387.   is used.
  388. */
  389. if ((cfg->mem.nwin > 0) || (dflt.mem.nwin > 0)) {
  390.     cistpl_mem_t *mem =
  391. (cfg->mem.nwin) ? &cfg->mem : &dflt.mem;
  392.     req.Attributes = WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_CM;
  393.     req.Attributes |= WIN_ENABLE;
  394.     req.Base = mem->win[0].host_addr;
  395.     req.Size = mem->win[0].len;
  396. /* new in dummy.cs 2001/01/28 MN 
  397.             if (req.Size < 0x1000)
  398.                 req.Size = 0x1000;
  399. */
  400.     req.AccessSpeed = 0;
  401.     link->win = (window_handle_t)link->handle;
  402.     CFG_CHECK(RequestWindow, &link->win, &req);
  403.     map.Page = 0; map.CardOffset = mem->win[0].card_addr;
  404.     CFG_CHECK(MapMemPage, link->win, &map);
  405. }
  406. /* If we got this far, we're cool! */
  407. break;
  408.     next_entry:
  409. /* new in dummy.cs 2001/01/28 MN 
  410.         if (link->io.NumPorts1)
  411.            CardServices(ReleaseIO, link->handle, &link->io);
  412. */
  413. CS_CHECK(GetNextTuple, handle, &tuple);
  414.     }
  415.     
  416.     /*
  417.        Allocate an interrupt line.  Note that this does not assign a
  418.        handler to the interrupt, unless the 'Handler' member of the
  419.        irq structure is initialized.
  420.     */
  421.     if (link->conf.Attributes & CONF_ENABLE_IRQ)
  422. CS_CHECK(RequestIRQ, link->handle, &link->irq);
  423.     /*
  424.        This actually configures the PCMCIA socket -- setting up
  425.        the I/O windows and the interrupt mapping, and putting the
  426.        card and host interface into "Memory and IO" mode.
  427.     */
  428.     CS_CHECK(RequestConfiguration, link->handle, &link->conf);
  429.     /*
  430.       At this point, the dev_node_t structure(s) need to be
  431.       initialized and arranged in a linked list at link->dev.
  432.     */
  433.     sprintf(dev->node.dev_name, "sedlbauer");
  434.     dev->node.major = dev->node.minor = 0;
  435.     link->dev = &dev->node;
  436.     /* Finally, report what we've done */
  437.     printk(KERN_INFO "%s: index 0x%02x: Vcc %d.%d",
  438.    dev->node.dev_name, link->conf.ConfigIndex,
  439.    link->conf.Vcc/10, link->conf.Vcc%10);
  440.     if (link->conf.Vpp1)
  441. printk(", Vpp %d.%d", link->conf.Vpp1/10, link->conf.Vpp1%10);
  442.     if (link->conf.Attributes & CONF_ENABLE_IRQ)
  443. printk(", irq %d", link->irq.AssignedIRQ);
  444.     if (link->io.NumPorts1)
  445. printk(", io 0x%04x-0x%04x", link->io.BasePort1,
  446.        link->io.BasePort1+link->io.NumPorts1-1);
  447.     if (link->io.NumPorts2)
  448. printk(" & 0x%04x-0x%04x", link->io.BasePort2,
  449.        link->io.BasePort2+link->io.NumPorts2-1);
  450.     if (link->win)
  451. printk(", mem 0x%06lx-0x%06lx", req.Base,
  452.        req.Base+req.Size-1);
  453.     printk("n");
  454.     
  455.     link->state &= ~DEV_CONFIG_PENDING;
  456.  
  457.     sedl_init_pcmcia(link->io.BasePort1, link->irq.AssignedIRQ,
  458.                      &(((local_info_t*)link->priv)->stop),
  459.                      protocol);
  460.     return;
  461. cs_failed:
  462.     cs_error(link->handle, last_fn, last_ret);
  463.     sedlbauer_release((u_long)link);
  464. } /* sedlbauer_config */
  465. /*======================================================================
  466.     After a card is removed, sedlbauer_release() will unregister the
  467.     device, and release the PCMCIA configuration.  If the device is
  468.     still open, this will be postponed until it is closed.
  469.     
  470. ======================================================================*/
  471. static void sedlbauer_release(u_long arg)
  472. {
  473.     dev_link_t *link = (dev_link_t *)arg;
  474.     DEBUG(0, "sedlbauer_release(0x%p)n", link);
  475.     /*
  476.        If the device is currently in use, we won't release until it
  477.        is actually closed, because until then, we can't be sure that
  478.        no one will try to access the device or its data structures.
  479.     */
  480.     if (link->open) {
  481. DEBUG(1, "sedlbauer_cs: release postponed, '%s' still openn",
  482.       link->dev->dev_name);
  483. link->state |= DEV_STALE_CONFIG;
  484. return;
  485.     }
  486.     /* Unlink the device chain */
  487.     link->dev = NULL;
  488.     /*
  489.       In a normal driver, additional code may be needed to release
  490.       other kernel data structures associated with this device. 
  491.     */
  492.     
  493.     /* Don't bother checking to see if these succeed or not */
  494.     if (link->win)
  495. CardServices(ReleaseWindow, link->win);
  496.     CardServices(ReleaseConfiguration, link->handle);
  497.     if (link->io.NumPorts1)
  498. CardServices(ReleaseIO, link->handle, &link->io);
  499.     if (link->irq.AssignedIRQ)
  500. CardServices(ReleaseIRQ, link->handle, &link->irq);
  501.     link->state &= ~DEV_CONFIG;
  502.     
  503.     if (link->state & DEV_STALE_LINK)
  504. sedlbauer_detach(link);
  505.     
  506. } /* sedlbauer_release */
  507. /*======================================================================
  508.     The card status event handler.  Mostly, this schedules other
  509.     stuff to run after an event is received.
  510.     When a CARD_REMOVAL event is received, we immediately set a
  511.     private flag to block future accesses to this device.  All the
  512.     functions that actually access the device should check this flag
  513.     to make sure the card is still present.
  514.     
  515. ======================================================================*/
  516. static int sedlbauer_event(event_t event, int priority,
  517.        event_callback_args_t *args)
  518. {
  519.     dev_link_t *link = args->client_data;
  520.     local_info_t *dev = link->priv;
  521.     
  522.     DEBUG(1, "sedlbauer_event(0x%06x)n", event);
  523.     
  524.     switch (event) {
  525.     case CS_EVENT_CARD_REMOVAL:
  526. link->state &= ~DEV_PRESENT;
  527. if (link->state & DEV_CONFIG) {
  528.     ((local_info_t *)link->priv)->stop = 1;
  529.     mod_timer(&link->release, jiffies + HZ/20);
  530. }
  531. break;
  532.     case CS_EVENT_CARD_INSERTION:
  533. link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
  534. dev->bus = args->bus;
  535. sedlbauer_config(link);
  536. break;
  537.     case CS_EVENT_PM_SUSPEND:
  538. link->state |= DEV_SUSPEND;
  539. /* Fall through... */
  540.     case CS_EVENT_RESET_PHYSICAL:
  541. /* Mark the device as stopped, to block IO until later */
  542. dev->stop = 1;
  543. if (link->state & DEV_CONFIG)
  544.     CardServices(ReleaseConfiguration, link->handle);
  545. break;
  546.     case CS_EVENT_PM_RESUME:
  547. link->state &= ~DEV_SUSPEND;
  548. /* Fall through... */
  549.     case CS_EVENT_CARD_RESET:
  550. if (link->state & DEV_CONFIG)
  551.     CardServices(RequestConfiguration, link->handle, &link->conf);
  552. dev->stop = 0;
  553. /*
  554.   In a normal driver, additional code may go here to restore
  555.   the device state and restart IO. 
  556. */
  557. break;
  558.     }
  559.     return 0;
  560. } /* sedlbauer_event */
  561. /*====================================================================*/
  562. static int __init init_sedlbauer_cs(void)
  563. {
  564.     servinfo_t serv;
  565.     DEBUG(0, "%sn", version);
  566.     CardServices(GetCardServicesInfo, &serv);
  567.     if (serv.Revision != CS_RELEASE_CODE) {
  568. printk(KERN_NOTICE "sedlbauer_cs: Card Services release "
  569.        "does not match!n");
  570. return -1;
  571.     }
  572.     register_pccard_driver(&dev_info, &sedlbauer_attach, &sedlbauer_detach);
  573.     return 0;
  574. }
  575. static void __exit exit_sedlbauer_cs(void)
  576. {
  577.     DEBUG(0, "sedlbauer_cs: unloadingn");
  578.     unregister_pccard_driver(&dev_info);
  579.     while (dev_list != NULL) {
  580. del_timer(&dev_list->release);
  581. if (dev_list->state & DEV_CONFIG)
  582.     sedlbauer_release((u_long)dev_list);
  583. sedlbauer_detach(dev_list);
  584.     }
  585. }
  586. module_init(init_sedlbauer_cs);
  587. module_exit(exit_sedlbauer_cs);