Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
| 6 | * |
| 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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/ptrace.h> |
| 18 | #include <linux/slab.h> |
| 19 | #include <linux/string.h> |
| 20 | #include <asm/io.h> |
| 21 | #include <asm/system.h> |
| 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <pcmcia/cs.h> |
| 24 | #include <pcmcia/cistpl.h> |
| 25 | #include <pcmcia/ds.h> |
| 26 | #include "hisax_cfg.h" |
| 27 | |
| 28 | MODULE_DESCRIPTION("ISDN4Linux: PCMCIA client driver for AVM A1/Fritz!PCMCIA cards"); |
| 29 | MODULE_AUTHOR("Carsten Paeth"); |
| 30 | MODULE_LICENSE("GPL"); |
| 31 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
| 33 | /*====================================================================*/ |
| 34 | |
| 35 | /* Parameters that can be set with 'insmod' */ |
| 36 | |
| 37 | static int isdnprot = 2; |
| 38 | |
| 39 | module_param(isdnprot, int, 0); |
| 40 | |
| 41 | /*====================================================================*/ |
| 42 | |
| 43 | /* |
| 44 | The event() function is this driver's Card Services event handler. |
| 45 | It will be called by Card Services when an appropriate card status |
| 46 | event is received. The config() and release() entry points are |
| 47 | used to configure or release a socket, in response to card insertion |
| 48 | and ejection events. They are invoked from the skeleton event |
| 49 | handler. |
| 50 | */ |
| 51 | |
Henne | a465870 | 2010-03-25 12:05:31 +0000 | [diff] [blame] | 52 | static int avma1cs_config(struct pcmcia_device *link) __devinit ; |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 53 | static void avma1cs_release(struct pcmcia_device *link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | /* |
| 56 | The attach() and detach() entry points are used to create and destroy |
| 57 | "instances" of the driver, where each instance represents everything |
| 58 | needed to manage one actual PCMCIA card. |
| 59 | */ |
| 60 | |
Henne | a465870 | 2010-03-25 12:05:31 +0000 | [diff] [blame] | 61 | static void avma1cs_detach(struct pcmcia_device *p_dev) __devexit ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | /*====================================================================== |
| 65 | |
| 66 | avma1cs_attach() creates an "instance" of the driver, allocating |
| 67 | local data structures for one device. The device is registered |
| 68 | with Card Services. |
| 69 | |
| 70 | The dev_link structure is initialized, but we don't actually |
| 71 | configure the card at this point -- we wait until we receive a |
| 72 | card insertion event. |
| 73 | |
| 74 | ======================================================================*/ |
| 75 | |
Henne | a465870 | 2010-03-25 12:05:31 +0000 | [diff] [blame] | 76 | static int __devinit avma1cs_probe(struct pcmcia_device *p_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | { |
Dominik Brodowski | e773cfe | 2009-10-24 15:50:13 +0200 | [diff] [blame] | 78 | dev_dbg(&p_dev->dev, "avma1cs_attach()\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | /* The io structure describes IO port mapping */ |
Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 81 | p_dev->io.NumPorts1 = 16; |
| 82 | p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8; |
| 83 | p_dev->io.NumPorts2 = 16; |
| 84 | p_dev->io.Attributes2 = IO_DATA_PATH_WIDTH_16; |
| 85 | p_dev->io.IOAddrLines = 5; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | /* General socket configuration */ |
Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 88 | p_dev->conf.Attributes = CONF_ENABLE_IRQ; |
| 89 | p_dev->conf.IntType = INT_MEMORY_AND_IO; |
| 90 | p_dev->conf.ConfigIndex = 1; |
| 91 | p_dev->conf.Present = PRESENT_OPTION; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 93 | return avma1cs_config(p_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | } /* avma1cs_attach */ |
| 95 | |
| 96 | /*====================================================================== |
| 97 | |
| 98 | This deletes a driver "instance". The device is de-registered |
| 99 | with Card Services. If it has been released, all local data |
| 100 | structures are freed. Otherwise, the structures will be freed |
| 101 | when the device is released. |
| 102 | |
| 103 | ======================================================================*/ |
| 104 | |
Henne | a465870 | 2010-03-25 12:05:31 +0000 | [diff] [blame] | 105 | static void __devexit avma1cs_detach(struct pcmcia_device *link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | { |
Dominik Brodowski | e773cfe | 2009-10-24 15:50:13 +0200 | [diff] [blame] | 107 | dev_dbg(&link->dev, "avma1cs_detach(0x%p)\n", link); |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 108 | avma1cs_release(link); |
| 109 | kfree(link->priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | } /* avma1cs_detach */ |
| 111 | |
| 112 | /*====================================================================== |
| 113 | |
| 114 | avma1cs_config() is scheduled to run after a CARD_INSERTION event |
| 115 | is received, to configure the PCMCIA socket, and to make the |
| 116 | ethernet device available to the system. |
| 117 | |
| 118 | ======================================================================*/ |
| 119 | |
Dominik Brodowski | 5fcd4da | 2008-07-29 08:38:55 +0200 | [diff] [blame] | 120 | static int avma1cs_configcheck(struct pcmcia_device *p_dev, |
Dominik Brodowski | 8e2fc39 | 2008-08-02 15:30:31 +0200 | [diff] [blame] | 121 | cistpl_cftable_entry_t *cf, |
| 122 | cistpl_cftable_entry_t *dflt, |
Dominik Brodowski | ad913c1 | 2008-08-02 16:12:00 +0200 | [diff] [blame] | 123 | unsigned int vcc, |
Dominik Brodowski | 8e2fc39 | 2008-08-02 15:30:31 +0200 | [diff] [blame] | 124 | void *priv_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | { |
Dominik Brodowski | 5fcd4da | 2008-07-29 08:38:55 +0200 | [diff] [blame] | 126 | if (cf->io.nwin <= 0) |
| 127 | return -ENODEV; |
| 128 | |
Dominik Brodowski | 5fcd4da | 2008-07-29 08:38:55 +0200 | [diff] [blame] | 129 | p_dev->io.BasePort1 = cf->io.win[0].base; |
| 130 | p_dev->io.NumPorts1 = cf->io.win[0].len; |
| 131 | p_dev->io.NumPorts2 = 0; |
| 132 | printk(KERN_INFO "avma1_cs: testing i/o %#x-%#x\n", |
| 133 | p_dev->io.BasePort1, |
| 134 | p_dev->io.BasePort1+p_dev->io.NumPorts1-1); |
| 135 | return pcmcia_request_io(p_dev, &p_dev->io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
Henne | a465870 | 2010-03-25 12:05:31 +0000 | [diff] [blame] | 139 | static int __devinit avma1cs_config(struct pcmcia_device *link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | { |
Dominik Brodowski | eb14120 | 2010-03-07 12:21:16 +0100 | [diff] [blame] | 141 | int i = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | char devname[128]; |
| 143 | IsdnCard_t icard; |
| 144 | int busy = 0; |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 145 | |
Dominik Brodowski | e773cfe | 2009-10-24 15:50:13 +0200 | [diff] [blame] | 146 | dev_dbg(&link->dev, "avma1cs_config(0x%p)\n", link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
Dominik Brodowski | 5fcd4da | 2008-07-29 08:38:55 +0200 | [diff] [blame] | 148 | devname[0] = 0; |
| 149 | if (link->prod_id[1]) |
| 150 | strlcpy(devname, link->prod_id[1], sizeof(devname)); |
| 151 | |
| 152 | if (pcmcia_loop_config(link, avma1cs_configcheck, NULL)) |
| 153 | return -ENODEV; |
| 154 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | do { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | /* |
| 157 | * allocate an interrupt line |
| 158 | */ |
Dominik Brodowski | eb14120 | 2010-03-07 12:21:16 +0100 | [diff] [blame] | 159 | if (!link->irq) { |
Dominik Brodowski | 50db3fd | 2006-01-15 10:05:19 +0100 | [diff] [blame] | 160 | /* undo */ |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 161 | pcmcia_disable_device(link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | break; |
| 163 | } |
Dominik Brodowski | 50db3fd | 2006-01-15 10:05:19 +0100 | [diff] [blame] | 164 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | /* |
| 166 | * configure the PCMCIA socket |
| 167 | */ |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 168 | i = pcmcia_request_configuration(link, &link->conf); |
Dominik Brodowski | 4c89e88 | 2008-08-03 10:07:45 +0200 | [diff] [blame] | 169 | if (i != 0) { |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 170 | pcmcia_disable_device(link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | break; |
| 172 | } |
| 173 | |
| 174 | } while (0); |
| 175 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | /* If any step failed, release any partially configured state */ |
| 177 | if (i != 0) { |
| 178 | avma1cs_release(link); |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 179 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | printk(KERN_NOTICE "avma1_cs: checking at i/o %#x, irq %d\n", |
Dominik Brodowski | eb14120 | 2010-03-07 12:21:16 +0100 | [diff] [blame] | 183 | link->io.BasePort1, link->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | |
Dominik Brodowski | eb14120 | 2010-03-07 12:21:16 +0100 | [diff] [blame] | 185 | icard.para[0] = link->irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | icard.para[1] = link->io.BasePort1; |
| 187 | icard.protocol = isdnprot; |
| 188 | icard.typ = ISDN_CTYPE_A1_PCMCIA; |
| 189 | |
| 190 | i = hisax_init_pcmcia(link, &busy, &icard); |
| 191 | if (i < 0) { |
| 192 | printk(KERN_ERR "avma1_cs: failed to initialize AVM A1 PCMCIA %d at i/o %#x\n", i, link->io.BasePort1); |
| 193 | avma1cs_release(link); |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 194 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | } |
Dominik Brodowski | b498ada | 2010-03-20 19:43:26 +0100 | [diff] [blame] | 196 | link->priv = (void *) (unsigned long) i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 198 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | } /* avma1cs_config */ |
| 200 | |
| 201 | /*====================================================================== |
| 202 | |
| 203 | After a card is removed, avma1cs_release() will unregister the net |
| 204 | device, and release the PCMCIA configuration. If the device is |
| 205 | still open, this will be postponed until it is closed. |
| 206 | |
| 207 | ======================================================================*/ |
| 208 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 209 | static void avma1cs_release(struct pcmcia_device *link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | { |
Dominik Brodowski | b498ada | 2010-03-20 19:43:26 +0100 | [diff] [blame] | 211 | unsigned long minor = (unsigned long) link->priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | |
Dominik Brodowski | e773cfe | 2009-10-24 15:50:13 +0200 | [diff] [blame] | 213 | dev_dbg(&link->dev, "avma1cs_release(0x%p)\n", link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
Dominik Brodowski | 5f2a71f | 2006-01-15 09:32:39 +0100 | [diff] [blame] | 215 | /* now unregister function with hisax */ |
Dominik Brodowski | b498ada | 2010-03-20 19:43:26 +0100 | [diff] [blame] | 216 | HiSax_closecard(minor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 218 | pcmcia_disable_device(link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | } /* avma1cs_release */ |
| 220 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | |
Dominik Brodowski | c594c12 | 2005-06-27 16:28:34 -0700 | [diff] [blame] | 222 | static struct pcmcia_device_id avma1cs_ids[] = { |
| 223 | PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN A", 0x95d42008, 0xadc9d4bb), |
| 224 | PCMCIA_DEVICE_PROD_ID12("ISDN", "CARD", 0x8d9761c8, 0x01c5aa7b), |
| 225 | PCMCIA_DEVICE_NULL |
| 226 | }; |
| 227 | MODULE_DEVICE_TABLE(pcmcia, avma1cs_ids); |
| 228 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | static struct pcmcia_driver avma1cs_driver = { |
| 230 | .owner = THIS_MODULE, |
| 231 | .drv = { |
| 232 | .name = "avma1_cs", |
| 233 | }, |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 234 | .probe = avma1cs_probe, |
Henne | a465870 | 2010-03-25 12:05:31 +0000 | [diff] [blame] | 235 | .remove = __devexit_p(avma1cs_detach), |
Dominik Brodowski | c594c12 | 2005-06-27 16:28:34 -0700 | [diff] [blame] | 236 | .id_table = avma1cs_ids, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | }; |
Dominik Brodowski | 8661bb5 | 2006-03-02 00:02:33 +0100 | [diff] [blame] | 238 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | /*====================================================================*/ |
| 240 | |
| 241 | static int __init init_avma1_cs(void) |
| 242 | { |
| 243 | return(pcmcia_register_driver(&avma1cs_driver)); |
| 244 | } |
| 245 | |
| 246 | static void __exit exit_avma1_cs(void) |
| 247 | { |
| 248 | pcmcia_unregister_driver(&avma1cs_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | module_init(init_avma1_cs); |
| 252 | module_exit(exit_avma1_cs); |