i2c-eg20t: change timeout value 50msec to 1000msec
[zen-stable.git] / drivers / isdn / hardware / avm / avm_cs.c
blob61f516f376dc8d9dd2db0c9d366054c6cec4f266
1 /* $Id: avm_cs.c,v 1.4.6.3 2001/09/23 22:24:33 kai Exp $
3 * A PCMCIA client driver for AVM B1/M1/M2
5 * Copyright 1999 by Carsten Paeth <calle@calle.de>
7 * This software may be used and distributed according to the terms
8 * of the GNU General Public License, incorporated herein by reference.
12 #include <linux/module.h>
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/ptrace.h>
16 #include <linux/string.h>
17 #include <linux/tty.h>
18 #include <linux/serial.h>
19 #include <linux/major.h>
20 #include <asm/io.h>
21 #include <asm/system.h>
23 #include <pcmcia/cistpl.h>
24 #include <pcmcia/ciscode.h>
25 #include <pcmcia/ds.h>
26 #include <pcmcia/cisreg.h>
28 #include <linux/skbuff.h>
29 #include <linux/capi.h>
30 #include <linux/b1lli.h>
31 #include <linux/b1pcmcia.h>
33 /*====================================================================*/
35 MODULE_DESCRIPTION("CAPI4Linux: PCMCIA client driver for AVM B1/M1/M2");
36 MODULE_AUTHOR("Carsten Paeth");
37 MODULE_LICENSE("GPL");
39 /*====================================================================*/
41 static int avmcs_config(struct pcmcia_device *link);
42 static void avmcs_release(struct pcmcia_device *link);
43 static void avmcs_detach(struct pcmcia_device *p_dev);
45 static int avmcs_probe(struct pcmcia_device *p_dev)
47 /* General socket configuration */
48 p_dev->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
49 p_dev->config_index = 1;
50 p_dev->config_regs = PRESENT_OPTION;
52 return avmcs_config(p_dev);
53 } /* avmcs_attach */
56 static void avmcs_detach(struct pcmcia_device *link)
58 avmcs_release(link);
59 } /* avmcs_detach */
61 static int avmcs_configcheck(struct pcmcia_device *p_dev, void *priv_data)
63 p_dev->resource[0]->end = 16;
64 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
65 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
67 return pcmcia_request_io(p_dev);
70 static int avmcs_config(struct pcmcia_device *link)
72 int i = -1;
73 char devname[128];
74 int cardtype;
75 int (*addcard)(unsigned int port, unsigned irq);
77 devname[0] = 0;
78 if (link->prod_id[1])
79 strlcpy(devname, link->prod_id[1], sizeof(devname));
82 * find IO port
84 if (pcmcia_loop_config(link, avmcs_configcheck, NULL))
85 return -ENODEV;
87 do {
88 if (!link->irq) {
89 /* undo */
90 pcmcia_disable_device(link);
91 break;
95 * configure the PCMCIA socket
97 i = pcmcia_enable_device(link);
98 if (i != 0) {
99 pcmcia_disable_device(link);
100 break;
103 } while (0);
105 if (devname[0]) {
106 char *s = strrchr(devname, ' ');
107 if (!s)
108 s = devname;
109 else s++;
110 if (strcmp("M1", s) == 0) {
111 cardtype = AVM_CARDTYPE_M1;
112 } else if (strcmp("M2", s) == 0) {
113 cardtype = AVM_CARDTYPE_M2;
114 } else {
115 cardtype = AVM_CARDTYPE_B1;
117 } else
118 cardtype = AVM_CARDTYPE_B1;
120 /* If any step failed, release any partially configured state */
121 if (i != 0) {
122 avmcs_release(link);
123 return -ENODEV;
127 switch (cardtype) {
128 case AVM_CARDTYPE_M1: addcard = b1pcmcia_addcard_m1; break;
129 case AVM_CARDTYPE_M2: addcard = b1pcmcia_addcard_m2; break;
130 default:
131 case AVM_CARDTYPE_B1: addcard = b1pcmcia_addcard_b1; break;
133 if ((i = (*addcard)(link->resource[0]->start, link->irq)) < 0) {
134 dev_err(&link->dev,
135 "avm_cs: failed to add AVM-Controller at i/o %#x, irq %d\n",
136 (unsigned int) link->resource[0]->start, link->irq);
137 avmcs_release(link);
138 return -ENODEV;
140 return 0;
142 } /* avmcs_config */
145 static void avmcs_release(struct pcmcia_device *link)
147 b1pcmcia_delcard(link->resource[0]->start, link->irq);
148 pcmcia_disable_device(link);
149 } /* avmcs_release */
152 static const struct pcmcia_device_id avmcs_ids[] = {
153 PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN-Controller B1", 0x95d42008, 0x845dc335),
154 PCMCIA_DEVICE_PROD_ID12("AVM", "Mobile ISDN-Controller M1", 0x95d42008, 0x81e10430),
155 PCMCIA_DEVICE_PROD_ID12("AVM", "Mobile ISDN-Controller M2", 0x95d42008, 0x18e8558a),
156 PCMCIA_DEVICE_NULL
158 MODULE_DEVICE_TABLE(pcmcia, avmcs_ids);
160 static struct pcmcia_driver avmcs_driver = {
161 .owner = THIS_MODULE,
162 .name = "avm_cs",
163 .probe = avmcs_probe,
164 .remove = avmcs_detach,
165 .id_table = avmcs_ids,
168 static int __init avmcs_init(void)
170 return pcmcia_register_driver(&avmcs_driver);
173 static void __exit avmcs_exit(void)
175 pcmcia_unregister_driver(&avmcs_driver);
178 module_init(avmcs_init);
179 module_exit(avmcs_exit);