serial_cs.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:20k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  1. /*======================================================================
  2.     A driver for PCMCIA serial devices
  3.     serial_cs.c 1.128 2001/10/18 12:18:35
  4.     The contents of this file are subject to the Mozilla Public
  5.     License Version 1.1 (the "License"); you may not use this file
  6.     except in compliance with the License. You may obtain a copy of
  7.     the License at http://www.mozilla.org/MPL/
  8.     Software distributed under the License is distributed on an "AS
  9.     IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  10.     implied. See the License for the specific language governing
  11.     rights and limitations under the License.
  12.     The initial developer of the original code is David A. Hinds
  13.     <dahinds@users.sourceforge.net>.  Portions created by David A. Hinds
  14.     are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.
  15.     Alternatively, the contents of this file may be used under the
  16.     terms of the GNU General Public License version 2 (the "GPL"), in
  17.     which case the provisions of the GPL are applicable instead of the
  18.     above.  If you wish to allow the use of your version of this file
  19.     only under the terms of the GPL and not to allow others to use
  20.     your version of this file under the MPL, indicate your decision
  21.     by deleting the provisions above and replace them with the notice
  22.     and other provisions required by the GPL.  If you do not delete
  23.     the provisions above, a recipient may use your version of this
  24.     file under either the MPL or the GPL.
  25.     
  26. ======================================================================*/
  27. #include <linux/module.h>
  28. #include <linux/kernel.h>
  29. #include <linux/init.h>
  30. #include <linux/sched.h>
  31. #include <linux/ptrace.h>
  32. #include <linux/slab.h>
  33. #include <linux/string.h>
  34. #include <linux/timer.h>
  35. #include <linux/tty.h>
  36. #include <linux/serial.h>
  37. #include <linux/major.h>
  38. #include <asm/io.h>
  39. #include <asm/system.h>
  40. #include <asm/byteorder.h>
  41. #include <pcmcia/version.h>
  42. #include <pcmcia/cs_types.h>
  43. #include <pcmcia/cs.h>
  44. #include <pcmcia/cistpl.h>
  45. #include <pcmcia/ciscode.h>
  46. #include <pcmcia/ds.h>
  47. #include <pcmcia/cisreg.h>
  48. /*====================================================================*/
  49. /* Module parameters */
  50. MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>");
  51. MODULE_DESCRIPTION("PCMCIA serial card driver");
  52. MODULE_LICENSE("Dual MPL/GPL");
  53. #define INT_MODULE_PARM(n, v) static int n = v; MODULE_PARM(n, "i")
  54. /* Bit map of interrupts to choose from */
  55. INT_MODULE_PARM(irq_mask, 0xdeb8);
  56. static int irq_list[4] = { -1 };
  57. MODULE_PARM(irq_list, "1-4i");
  58. /* Enable the speaker? */
  59. INT_MODULE_PARM(do_sound, 1);
  60. #ifdef PCMCIA_DEBUG
  61. INT_MODULE_PARM(pc_debug, PCMCIA_DEBUG);
  62. #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
  63. static char *version =
  64. "serial_cs.c 1.128 2001/10/18 12:18:35 (David Hinds)";
  65. #else
  66. #define DEBUG(n, args...)
  67. #endif
  68. /*====================================================================*/
  69. /* Table of multi-port card ID's */
  70. typedef struct {
  71.     u_short manfid;
  72.     u_short prodid;
  73.     int multi; /* 1 = multifunction, > 1 = # ports */
  74. } multi_id_t;
  75. static multi_id_t multi_id[] = {
  76.     { MANFID_OMEGA, PRODID_OMEGA_QSP_100, 4 },
  77.     { MANFID_QUATECH, PRODID_QUATECH_DUAL_RS232, 2 },
  78.     { MANFID_QUATECH, PRODID_QUATECH_DUAL_RS232_D1, 2 },
  79.     { MANFID_QUATECH, PRODID_QUATECH_QUAD_RS232, 4 },
  80.     { MANFID_QUATECH, PRODID_QUATECH_DUAL_RS422, 2 },
  81.     { MANFID_QUATECH, PRODID_QUATECH_QUAD_RS422, 4 },
  82.     { MANFID_SOCKET, PRODID_SOCKET_DUAL_RS232, 2 },
  83.     { MANFID_INTEL, PRODID_INTEL_DUAL_RS232, 2 },
  84.     { MANFID_NATINST, PRODID_NATINST_QUAD_RS232, 4 }
  85. };
  86. #define MULTI_COUNT (sizeof(multi_id)/sizeof(multi_id_t))
  87. typedef struct serial_info_t {
  88.     dev_link_t link;
  89.     int ndev;
  90.     int multi;
  91.     int slave;
  92.     int manfid;
  93.     dev_node_t node[4];
  94.     int line[4];
  95. } serial_info_t;
  96. static void serial_config(dev_link_t *link);
  97. static void serial_release(u_long arg);
  98. static int serial_event(event_t event, int priority,
  99. event_callback_args_t *args);
  100. static dev_info_t dev_info = "serial_cs";
  101. static dev_link_t *serial_attach(void);
  102. static void serial_detach(dev_link_t *);
  103. static dev_link_t *dev_list = NULL;
  104. /*====================================================================*/
  105. static void cs_error(client_handle_t handle, int func, int ret)
  106. {
  107.     error_info_t err = { func, ret };
  108.     CardServices(ReportError, handle, &err);
  109. }
  110. /*======================================================================
  111.     serial_attach() creates an "instance" of the driver, allocating
  112.     local data structures for one device.  The device is registered
  113.     with Card Services.
  114. ======================================================================*/
  115. static dev_link_t *serial_attach(void)
  116. {
  117.     serial_info_t *info;
  118.     client_reg_t client_reg;
  119.     dev_link_t *link;
  120.     int i, ret;
  121.     
  122.     DEBUG(0, "serial_attach()n");
  123.     /* Create new serial device */
  124.     info = kmalloc(sizeof(*info), GFP_KERNEL);
  125.     if (!info) return NULL;
  126.     memset(info, 0, sizeof(*info));
  127.     link = &info->link; link->priv = info;
  128.     link->release.function = &serial_release;
  129.     link->release.data = (u_long)link;
  130.     link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
  131.     link->io.NumPorts1 = 8;
  132.     link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
  133.     link->irq.IRQInfo1 = IRQ_INFO2_VALID|IRQ_LEVEL_ID;
  134.     if (irq_list[0] == -1)
  135. link->irq.IRQInfo2 = irq_mask;
  136.     else
  137. for (i = 0; i < 4; i++)
  138.     link->irq.IRQInfo2 |= 1 << irq_list[i];
  139.     link->conf.Attributes = CONF_ENABLE_IRQ;
  140.     link->conf.Vcc = 50;
  141.     if (do_sound) {
  142. link->conf.Attributes |= CONF_ENABLE_SPKR;
  143. link->conf.Status = CCSR_AUDIO_ENA;
  144.     }
  145.     link->conf.IntType = INT_MEMORY_AND_IO;
  146.     
  147.     /* Register with Card Services */
  148.     link->next = dev_list;
  149.     dev_list = link;
  150.     client_reg.dev_info = &dev_info;
  151.     client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE;
  152.     client_reg.EventMask =
  153. CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
  154. CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
  155. CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
  156.     client_reg.event_handler = &serial_event;
  157.     client_reg.Version = 0x0210;
  158.     client_reg.event_callback_args.client_data = link;
  159.     ret = CardServices(RegisterClient, &link->handle, &client_reg);
  160.     if (ret != CS_SUCCESS) {
  161. cs_error(link->handle, RegisterClient, ret);
  162. serial_detach(link);
  163. return NULL;
  164.     }
  165.     
  166.     return link;
  167. } /* serial_attach */
  168. /*======================================================================
  169.     This deletes a driver "instance".  The device is de-registered
  170.     with Card Services.  If it has been released, all local data
  171.     structures are freed.  Otherwise, the structures will be freed
  172.     when the device is released.
  173. ======================================================================*/
  174. static void serial_detach(dev_link_t *link)
  175. {
  176.     serial_info_t *info = link->priv;
  177.     dev_link_t **linkp;
  178.     int ret;
  179.     DEBUG(0, "serial_detach(0x%p)n", link);
  180.     
  181.     /* Locate device structure */
  182.     for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
  183. if (*linkp == link) break;
  184.     if (*linkp == NULL)
  185. return;
  186.     del_timer(&link->release);
  187.     if (link->state & DEV_CONFIG)
  188. serial_release((u_long)link);
  189.     
  190.     if (link->handle) {
  191. ret = CardServices(DeregisterClient, link->handle);
  192. if (ret != CS_SUCCESS)
  193.     cs_error(link->handle, DeregisterClient, ret);
  194.     }
  195.     
  196.     /* Unlink device structure, free bits */
  197.     *linkp = link->next;
  198.     kfree(info);
  199.     
  200. } /* serial_detach */
  201. /*====================================================================*/
  202. static int setup_serial(serial_info_t *info, ioaddr_t port, int irq)
  203. {
  204.     struct serial_struct serial;
  205.     int line;
  206.     
  207.     memset(&serial, 0, sizeof(serial));
  208.     serial.port = port;
  209.     serial.irq = irq;
  210.     serial.flags = ASYNC_SKIP_TEST | ASYNC_SHARE_IRQ;
  211.     line = register_serial(&serial);
  212.     if (line < 0) {
  213. printk(KERN_NOTICE "serial_cs: register_serial() at 0x%04lx,"
  214.        " irq %d failedn", (u_long)serial.port, serial.irq);
  215. return -1;
  216.     }
  217.     
  218.     info->line[info->ndev] = line;
  219.     sprintf(info->node[info->ndev].dev_name, "ttyS%d", line);
  220.     info->node[info->ndev].major = TTY_MAJOR;
  221.     info->node[info->ndev].minor = 0x40+line;
  222.     if (info->ndev > 0)
  223. info->node[info->ndev-1].next = &info->node[info->ndev];
  224.     info->ndev++;
  225.     
  226.     return 0;
  227. }
  228. /*====================================================================*/
  229. static int get_tuple(int fn, client_handle_t handle, tuple_t *tuple,
  230.      cisparse_t *parse)
  231. {
  232.     int i;
  233.     i = CardServices(fn, handle, tuple);
  234.     if (i != CS_SUCCESS) return CS_NO_MORE_ITEMS;
  235.     i = CardServices(GetTupleData, handle, tuple);
  236.     if (i != CS_SUCCESS) return i;
  237.     return CardServices(ParseTuple, handle, tuple, parse);
  238. }
  239. #define first_tuple(a, b, c) get_tuple(GetFirstTuple, a, b, c)
  240. #define next_tuple(a, b, c) get_tuple(GetNextTuple, a, b, c)
  241. /*====================================================================*/
  242. static int simple_config(dev_link_t *link)
  243. {
  244.     static ioaddr_t base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
  245.     client_handle_t handle = link->handle;
  246.     serial_info_t *info = link->priv;
  247.     tuple_t tuple;
  248.     u_char buf[256];
  249.     cisparse_t parse;
  250.     cistpl_cftable_entry_t *cf = &parse.cftable_entry;
  251.     config_info_t config;
  252.     int i, j, try;
  253.     /* If the card is already configured, look up the port and irq */
  254.     i = CardServices(GetConfigurationInfo, handle, &config);
  255.     if ((i == CS_SUCCESS) &&
  256. (config.Attributes & CONF_VALID_CLIENT)) {
  257. ioaddr_t port = 0;
  258. if ((config.BasePort2 != 0) && (config.NumPorts2 == 8)) {
  259.     port = config.BasePort2;
  260.     info->slave = 1;
  261. } else if ((info->manfid == MANFID_OSITECH) &&
  262.    (config.NumPorts1 == 0x40)) {
  263.     port = config.BasePort1 + 0x28;
  264.     info->slave = 1;
  265. }
  266. if (info->slave)
  267.     return setup_serial(info, port, config.AssignedIRQ);
  268.     }
  269.     link->conf.Vcc = config.Vcc;
  270.     
  271.     /* First pass: look for a config entry that looks normal. */
  272.     tuple.TupleData = (cisdata_t *)buf;
  273.     tuple.TupleOffset = 0; tuple.TupleDataMax = 255;
  274.     tuple.Attributes = 0;
  275.     tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
  276.     /* Two tries: without IO aliases, then with aliases */
  277.     for (try = 0; try < 2; try++) {
  278. i = first_tuple(handle, &tuple, &parse);
  279. while (i != CS_NO_MORE_ITEMS) {
  280.     if (i != CS_SUCCESS) goto next_entry;
  281.     if (cf->vpp1.present & (1<<CISTPL_POWER_VNOM))
  282. link->conf.Vpp1 = link->conf.Vpp2 =
  283.     cf->vpp1.param[CISTPL_POWER_VNOM]/10000;
  284.     if ((cf->io.nwin > 0) && (cf->io.win[0].len == 8) &&
  285. (cf->io.win[0].base != 0)) {
  286. link->conf.ConfigIndex = cf->index;
  287. link->io.BasePort1 = cf->io.win[0].base;
  288. link->io.IOAddrLines = (try == 0) ?
  289.     16 : cf->io.flags & CISTPL_IO_LINES_MASK;
  290. i = CardServices(RequestIO, link->handle, &link->io);
  291. if (i == CS_SUCCESS) goto found_port;
  292.     }
  293. next_entry:
  294.     i = next_tuple(handle, &tuple, &parse);
  295. }
  296.     }
  297.     
  298.     /* Second pass: try to find an entry that isn't picky about
  299.        its base address, then try to grab any standard serial port
  300.        address, and finally try to get any free port. */
  301.     i = first_tuple(handle, &tuple, &parse);
  302.     while (i != CS_NO_MORE_ITEMS) {
  303. if ((i == CS_SUCCESS) && (cf->io.nwin > 0) &&
  304.     ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) {
  305.     link->conf.ConfigIndex = cf->index;
  306.     for (j = 0; j < 5; j++) {
  307. link->io.BasePort1 = base[j];
  308. link->io.IOAddrLines = base[j] ? 16 : 3;
  309. i = CardServices(RequestIO, link->handle,
  310.  &link->io);
  311. if (i == CS_SUCCESS) goto found_port;
  312.     }
  313. }
  314. i = next_tuple(handle, &tuple, &parse);
  315.     }
  316. found_port:
  317.     if (i != CS_SUCCESS) {
  318. cs_error(link->handle, RequestIO, i);
  319. return -1;
  320.     }
  321.     
  322.     i = CardServices(RequestIRQ, link->handle, &link->irq);
  323.     if (i != CS_SUCCESS) {
  324. cs_error(link->handle, RequestIRQ, i);
  325. link->irq.AssignedIRQ = 0;
  326.     }
  327.     if (info->multi && (info->manfid == MANFID_3COM))
  328. link->conf.ConfigIndex &= ~(0x08);
  329.     i = CardServices(RequestConfiguration, link->handle, &link->conf);
  330.     if (i != CS_SUCCESS) {
  331. cs_error(link->handle, RequestConfiguration, i);
  332. return -1;
  333.     }
  334.     return setup_serial(info, link->io.BasePort1, link->irq.AssignedIRQ);
  335. }
  336. static int multi_config(dev_link_t *link)
  337. {
  338.     client_handle_t handle = link->handle;
  339.     serial_info_t *info = link->priv;
  340.     tuple_t tuple;
  341.     u_char buf[256];
  342.     cisparse_t parse;
  343.     cistpl_cftable_entry_t *cf = &parse.cftable_entry;
  344.     int i, base2 = 0;
  345.     tuple.TupleData = (cisdata_t *)buf;
  346.     tuple.TupleOffset = 0; tuple.TupleDataMax = 255;
  347.     tuple.Attributes = 0;
  348.     tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
  349.     /* First, look for a generic full-sized window */
  350.     link->io.NumPorts1 = info->multi * 8;
  351.     i = first_tuple(handle, &tuple, &parse);
  352.     while (i != CS_NO_MORE_ITEMS) {
  353. /* The quad port cards have bad CIS's, so just look for a
  354.    window larger than 8 ports and assume it will be right */
  355. if ((i == CS_SUCCESS) && (cf->io.nwin == 1) &&
  356.     (cf->io.win[0].len > 8)) {
  357.     link->conf.ConfigIndex = cf->index;
  358.     link->io.BasePort1 = cf->io.win[0].base;
  359.     link->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK;
  360.     i = CardServices(RequestIO, link->handle, &link->io);
  361.     base2 = link->io.BasePort1 + 8;
  362.     if (i == CS_SUCCESS) break;
  363. }
  364. i = next_tuple(handle, &tuple, &parse);
  365.     }
  366.     /* If that didn't work, look for two windows */
  367.     if (i != CS_SUCCESS) {
  368. link->io.NumPorts1 = link->io.NumPorts2 = 8;
  369. info->multi = 2;
  370. i = first_tuple(handle, &tuple, &parse);
  371. while (i != CS_NO_MORE_ITEMS) {
  372.     if ((i == CS_SUCCESS) && (cf->io.nwin == 2)) {
  373. link->conf.ConfigIndex = cf->index;
  374. link->io.BasePort1 = cf->io.win[0].base;
  375. link->io.BasePort2 = cf->io.win[1].base;
  376. link->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK;
  377. i = CardServices(RequestIO, link->handle, &link->io);
  378. base2 = link->io.BasePort2;
  379. if (i == CS_SUCCESS) break;
  380.     }
  381.     i = next_tuple(handle, &tuple, &parse);
  382. }
  383.     }
  384.     
  385.     if (i != CS_SUCCESS) {
  386. cs_error(link->handle, RequestIO, i);
  387. return -1;
  388.     }
  389.     
  390.     i = CardServices(RequestIRQ, link->handle, &link->irq);
  391.     if (i != CS_SUCCESS) {
  392. cs_error(link->handle, RequestIRQ, i);
  393. link->irq.AssignedIRQ = 0;
  394.     }
  395.     /* Socket Dual IO: this enables irq's for second port */
  396.     if (info->multi && (info->manfid == MANFID_SOCKET)) {
  397. link->conf.Present |= PRESENT_EXT_STATUS;
  398. link->conf.ExtStatus = ESR_REQ_ATTN_ENA;
  399.     }
  400.     i = CardServices(RequestConfiguration, link->handle, &link->conf);
  401.     if (i != CS_SUCCESS) {
  402. cs_error(link->handle, RequestConfiguration, i);
  403. return -1;
  404.     }
  405.     
  406.     setup_serial(info, link->io.BasePort1, link->irq.AssignedIRQ);
  407.     /* The Nokia cards are not really multiport cards */
  408.     if (info->manfid == MANFID_NOKIA)
  409. return 0;
  410.     for (i = 0; i < info->multi-1; i++)
  411. setup_serial(info, base2+(8*i), link->irq.AssignedIRQ);
  412.     
  413.     return 0;
  414. }
  415. /*======================================================================
  416.     serial_config() is scheduled to run after a CARD_INSERTION event
  417.     is received, to configure the PCMCIA socket, and to make the
  418.     serial device available to the system.
  419. ======================================================================*/
  420. #define CS_CHECK(fn, args...) 
  421. while ((last_ret=CardServices(last_fn=(fn), args))!=0) goto cs_failed
  422. void serial_config(dev_link_t *link)
  423. {
  424.     client_handle_t handle = link->handle;
  425.     serial_info_t *info = link->priv;
  426.     tuple_t tuple;
  427.     u_short buf[128];
  428.     cisparse_t parse;
  429.     cistpl_cftable_entry_t *cf = &parse.cftable_entry;
  430.     int i, last_ret, last_fn;
  431.     DEBUG(0, "serial_config(0x%p)n", link);
  432.     
  433.     tuple.TupleData = (cisdata_t *)buf;
  434.     tuple.TupleOffset = 0; tuple.TupleDataMax = 255;
  435.     tuple.Attributes = 0;
  436.     /* Get configuration register information */
  437.     tuple.DesiredTuple = CISTPL_CONFIG;
  438.     last_ret = first_tuple(handle, &tuple, &parse);
  439.     if (last_ret != CS_SUCCESS) {
  440. last_fn = ParseTuple;
  441. goto cs_failed;
  442.     }
  443.     link->conf.ConfigBase = parse.config.base;
  444.     link->conf.Present = parse.config.rmask[0];
  445.     
  446.     /* Configure card */
  447.     link->state |= DEV_CONFIG;
  448.     /* Is this a compliant multifunction card? */
  449.     tuple.DesiredTuple = CISTPL_LONGLINK_MFC;
  450.     tuple.Attributes = TUPLE_RETURN_COMMON | TUPLE_RETURN_LINK;
  451.     info->multi = (first_tuple(handle, &tuple, &parse) == CS_SUCCESS);
  452.     
  453.     /* Is this a multiport card? */
  454.     tuple.DesiredTuple = CISTPL_MANFID;
  455.     if (first_tuple(handle, &tuple, &parse) == CS_SUCCESS) {
  456. info->manfid = le16_to_cpu(buf[0]);
  457. for (i = 0; i < MULTI_COUNT; i++)
  458.     if ((info->manfid == multi_id[i].manfid) &&
  459. (le16_to_cpu(buf[1]) == multi_id[i].prodid))
  460. break;
  461. if (i < MULTI_COUNT)
  462.     info->multi = multi_id[i].multi;
  463.     }
  464.     /* Another check for dual-serial cards: look for either serial or
  465.        multifunction cards that ask for appropriate IO port ranges */
  466.     tuple.DesiredTuple = CISTPL_FUNCID;
  467.     if ((info->multi == 0) &&
  468. ((first_tuple(handle, &tuple, &parse) != CS_SUCCESS) ||
  469.  (parse.funcid.func == CISTPL_FUNCID_MULTI) ||
  470.  (parse.funcid.func == CISTPL_FUNCID_SERIAL))) {
  471. tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
  472. if (first_tuple(handle, &tuple, &parse) == CS_SUCCESS) {
  473.     if ((cf->io.nwin == 1) && (cf->io.win[0].len % 8 == 0))
  474. info->multi = cf->io.win[0].len >> 3;
  475.     if ((cf->io.nwin == 2) && (cf->io.win[0].len == 8) &&
  476. (cf->io.win[1].len == 8))
  477. info->multi = 2;
  478. }
  479.     }
  480.     
  481.     if (info->multi > 1)
  482. multi_config(link);
  483.     else
  484. simple_config(link);
  485.     
  486.     if (info->ndev == 0)
  487. goto failed;
  488.     
  489.     if (info->manfid == MANFID_IBM) {
  490. conf_reg_t reg = { 0, CS_READ, 0x800, 0 };
  491. CS_CHECK(AccessConfigurationRegister, link->handle, &reg);
  492. reg.Action = CS_WRITE;
  493. reg.Value = reg.Value | 1;
  494. CS_CHECK(AccessConfigurationRegister, link->handle, &reg);
  495.     }
  496.     link->dev = &info->node[0];
  497.     link->state &= ~DEV_CONFIG_PENDING;
  498.     return;
  499. cs_failed:
  500.     cs_error(link->handle, last_fn, last_ret);
  501. failed:
  502.     serial_release((u_long)link);
  503. } /* serial_config */
  504. /*======================================================================
  505.     After a card is removed, serial_release() will unregister the net
  506.     device, and release the PCMCIA configuration.
  507.     
  508. ======================================================================*/
  509. void serial_release(u_long arg)
  510. {
  511.     dev_link_t *link = (dev_link_t *)arg;
  512.     serial_info_t *info = link->priv;
  513.     int i;
  514.     
  515.     DEBUG(0, "serial_release(0x%p)n", link);
  516.     for (i = 0; i < info->ndev; i++) {
  517. unregister_serial(info->line[i]);
  518.     }
  519.     link->dev = NULL;
  520.     if (!info->slave) {
  521. CardServices(ReleaseConfiguration, link->handle);
  522. CardServices(ReleaseIO, link->handle, &link->io);
  523. CardServices(ReleaseIRQ, link->handle, &link->irq);
  524.     }
  525.     
  526.     link->state &= ~DEV_CONFIG;
  527. } /* serial_release */
  528. /*======================================================================
  529.     The card status event handler.  Mostly, this schedules other
  530.     stuff to run after an event is received.  A CARD_REMOVAL event
  531.     also sets some flags to discourage the serial drivers from
  532.     talking to the ports.
  533.     
  534. ======================================================================*/
  535. static int serial_event(event_t event, int priority,
  536. event_callback_args_t *args)
  537. {
  538.     dev_link_t *link = args->client_data;
  539.     serial_info_t *info = link->priv;
  540.     
  541.     DEBUG(1, "serial_event(0x%06x)n", event);
  542.     
  543.     switch (event) {
  544.     case CS_EVENT_CARD_REMOVAL:
  545. link->state &= ~DEV_PRESENT;
  546. if (link->state & DEV_CONFIG)
  547.     mod_timer(&link->release, jiffies + HZ/20);
  548. break;
  549.     case CS_EVENT_CARD_INSERTION:
  550. link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
  551. serial_config(link);
  552. break;
  553.     case CS_EVENT_PM_SUSPEND:
  554. link->state |= DEV_SUSPEND;
  555. /* Fall through... */
  556.     case CS_EVENT_RESET_PHYSICAL:
  557. if ((link->state & DEV_CONFIG) && !info->slave)
  558.     CardServices(ReleaseConfiguration, link->handle);
  559. break;
  560.     case CS_EVENT_PM_RESUME:
  561. link->state &= ~DEV_SUSPEND;
  562. /* Fall through... */
  563.     case CS_EVENT_CARD_RESET:
  564. if (DEV_OK(link) && !info->slave)
  565.     CardServices(RequestConfiguration, link->handle, &link->conf);
  566. break;
  567.     }
  568.     return 0;
  569. } /* serial_event */
  570. /*====================================================================*/
  571. static int __init init_serial_cs(void)
  572. {
  573.     servinfo_t serv;
  574.     DEBUG(0, "%sn", version);
  575.     CardServices(GetCardServicesInfo, &serv);
  576.     if (serv.Revision != CS_RELEASE_CODE) {
  577. printk(KERN_NOTICE "serial_cs: Card Services release "
  578.        "does not match!n");
  579. return -1;
  580.     }
  581.     register_pccard_driver(&dev_info, &serial_attach, &serial_detach);
  582.     return 0;
  583. }
  584. static void __exit exit_serial_cs(void)
  585. {
  586.     DEBUG(0, "serial_cs: unloadingn");
  587.     unregister_pccard_driver(&dev_info);
  588.     while (dev_list != NULL)
  589. serial_detach(dev_list);
  590. }
  591. module_init(init_serial_cs);
  592. module_exit(exit_serial_cs);