Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * PCMCIA client driver for AVM A1 / Fritz!PCMCIA | |
3 | * | |
4 | * Author Carsten Paeth | |
5 | * Copyright 1998-2001 by Carsten Paeth <calle@calle.in-berlin.de> | |
475be4d8 | 6 | * |
1da177e4 LT |
7 | * This software may be used and distributed according to the terms |
8 | * of the GNU General Public License, incorporated herein by reference. | |
9 | * | |
10 | */ | |
11 | ||
12 | #include <linux/module.h> | |
13 | ||
14 | ||
15 | #include <linux/kernel.h> | |
16 | #include <linux/init.h> | |
1da177e4 LT |
17 | #include <linux/ptrace.h> |
18 | #include <linux/slab.h> | |
19 | #include <linux/string.h> | |
20 | #include <asm/io.h> | |
1da177e4 | 21 | |
1da177e4 LT |
22 | #include <pcmcia/cistpl.h> |
23 | #include <pcmcia/ds.h> | |
24 | #include "hisax_cfg.h" | |
25 | ||
26 | MODULE_DESCRIPTION("ISDN4Linux: PCMCIA client driver for AVM A1/Fritz!PCMCIA cards"); | |
27 | MODULE_AUTHOR("Carsten Paeth"); | |
28 | MODULE_LICENSE("GPL"); | |
29 | ||
1da177e4 LT |
30 | |
31 | /*====================================================================*/ | |
32 | ||
33 | /* Parameters that can be set with 'insmod' */ | |
34 | ||
35 | static int isdnprot = 2; | |
36 | ||
37 | module_param(isdnprot, int, 0); | |
38 | ||
39 | /*====================================================================*/ | |
40 | ||
ed5a84cd | 41 | static int avma1cs_config(struct pcmcia_device *link); |
fba395ee | 42 | static void avma1cs_release(struct pcmcia_device *link); |
ed5a84cd | 43 | static void avma1cs_detach(struct pcmcia_device *p_dev); |
1da177e4 | 44 | |
ed5a84cd | 45 | static int avma1cs_probe(struct pcmcia_device *p_dev) |
1da177e4 | 46 | { |
475be4d8 | 47 | dev_dbg(&p_dev->dev, "avma1cs_attach()\n"); |
1da177e4 | 48 | |
475be4d8 JP |
49 | /* General socket configuration */ |
50 | p_dev->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO; | |
51 | p_dev->config_index = 1; | |
52 | p_dev->config_regs = PRESENT_OPTION; | |
f8cfa618 | 53 | |
475be4d8 | 54 | return avma1cs_config(p_dev); |
1da177e4 LT |
55 | } /* avma1cs_attach */ |
56 | ||
ed5a84cd | 57 | static void avma1cs_detach(struct pcmcia_device *link) |
1da177e4 | 58 | { |
e773cfe1 | 59 | dev_dbg(&link->dev, "avma1cs_detach(0x%p)\n", link); |
e2d40963 DB |
60 | avma1cs_release(link); |
61 | kfree(link->priv); | |
1da177e4 LT |
62 | } /* avma1cs_detach */ |
63 | ||
00990e7c | 64 | static int avma1cs_configcheck(struct pcmcia_device *p_dev, void *priv_data) |
1da177e4 | 65 | { |
00990e7c DB |
66 | p_dev->resource[0]->end = 16; |
67 | p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH; | |
68 | p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8; | |
90abdc3b | 69 | p_dev->io_lines = 5; |
00990e7c | 70 | |
90abdc3b | 71 | return pcmcia_request_io(p_dev); |
1da177e4 LT |
72 | } |
73 | ||
1da177e4 | 74 | |
ed5a84cd | 75 | static int avma1cs_config(struct pcmcia_device *link) |
1da177e4 | 76 | { |
475be4d8 JP |
77 | int i = -1; |
78 | char devname[128]; | |
79 | IsdnCard_t icard; | |
80 | int busy = 0; | |
81 | ||
82 | dev_dbg(&link->dev, "avma1cs_config(0x%p)\n", link); | |
83 | ||
84 | devname[0] = 0; | |
85 | if (link->prod_id[1]) | |
86 | strlcpy(devname, link->prod_id[1], sizeof(devname)); | |
87 | ||
88 | if (pcmcia_loop_config(link, avma1cs_configcheck, NULL)) | |
89 | return -ENODEV; | |
90 | ||
91 | do { | |
92 | /* | |
93 | * allocate an interrupt line | |
94 | */ | |
95 | if (!link->irq) { | |
96 | /* undo */ | |
97 | pcmcia_disable_device(link); | |
98 | break; | |
99 | } | |
100 | ||
101 | /* | |
102 | * configure the PCMCIA socket | |
103 | */ | |
104 | i = pcmcia_enable_device(link); | |
105 | if (i != 0) { | |
106 | pcmcia_disable_device(link); | |
107 | break; | |
108 | } | |
109 | ||
110 | } while (0); | |
111 | ||
112 | /* If any step failed, release any partially configured state */ | |
4c89e88b | 113 | if (i != 0) { |
475be4d8 JP |
114 | avma1cs_release(link); |
115 | return -ENODEV; | |
1da177e4 LT |
116 | } |
117 | ||
475be4d8 JP |
118 | icard.para[0] = link->irq; |
119 | icard.para[1] = link->resource[0]->start; | |
120 | icard.protocol = isdnprot; | |
121 | icard.typ = ISDN_CTYPE_A1_PCMCIA; | |
122 | ||
123 | i = hisax_init_pcmcia(link, &busy, &icard); | |
124 | if (i < 0) { | |
125 | printk(KERN_ERR "avma1_cs: failed to initialize AVM A1 " | |
126 | "PCMCIA %d at i/o %#x\n", i, | |
127 | (unsigned int) link->resource[0]->start); | |
128 | avma1cs_release(link); | |
129 | return -ENODEV; | |
130 | } | |
131 | link->priv = (void *) (unsigned long) i; | |
1da177e4 | 132 | |
475be4d8 | 133 | return 0; |
1da177e4 LT |
134 | } /* avma1cs_config */ |
135 | ||
fba395ee | 136 | static void avma1cs_release(struct pcmcia_device *link) |
1da177e4 | 137 | { |
b498ada6 | 138 | unsigned long minor = (unsigned long) link->priv; |
1da177e4 | 139 | |
e773cfe1 | 140 | dev_dbg(&link->dev, "avma1cs_release(0x%p)\n", link); |
1da177e4 | 141 | |
5f2a71fc | 142 | /* now unregister function with hisax */ |
b498ada6 | 143 | HiSax_closecard(minor); |
1da177e4 | 144 | |
fba395ee | 145 | pcmcia_disable_device(link); |
1da177e4 LT |
146 | } /* avma1cs_release */ |
147 | ||
25f8f54f | 148 | static const struct pcmcia_device_id avma1cs_ids[] = { |
c594c12c DB |
149 | PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN A", 0x95d42008, 0xadc9d4bb), |
150 | PCMCIA_DEVICE_PROD_ID12("ISDN", "CARD", 0x8d9761c8, 0x01c5aa7b), | |
151 | PCMCIA_DEVICE_NULL | |
152 | }; | |
153 | MODULE_DEVICE_TABLE(pcmcia, avma1cs_ids); | |
154 | ||
1da177e4 LT |
155 | static struct pcmcia_driver avma1cs_driver = { |
156 | .owner = THIS_MODULE, | |
2e9b981a | 157 | .name = "avma1_cs", |
15b99ac1 | 158 | .probe = avma1cs_probe, |
ed5a84cd | 159 | .remove = avma1cs_detach, |
c594c12c | 160 | .id_table = avma1cs_ids, |
1da177e4 | 161 | }; |
0aae9c6a | 162 | module_pcmcia_driver(avma1cs_driver); |