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/cistpl.h> |
| 24 | #include <pcmcia/ds.h> |
| 25 | #include "hisax_cfg.h" |
| 26 | |
| 27 | MODULE_DESCRIPTION("ISDN4Linux: PCMCIA client driver for AVM A1/Fritz!PCMCIA cards"); |
| 28 | MODULE_AUTHOR("Carsten Paeth"); |
| 29 | MODULE_LICENSE("GPL"); |
| 30 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
| 32 | /*====================================================================*/ |
| 33 | |
| 34 | /* Parameters that can be set with 'insmod' */ |
| 35 | |
| 36 | static int isdnprot = 2; |
| 37 | |
| 38 | module_param(isdnprot, int, 0); |
| 39 | |
| 40 | /*====================================================================*/ |
| 41 | |
Henne | a465870 | 2010-03-25 12:05:31 +0000 | [diff] [blame] | 42 | static int avma1cs_config(struct pcmcia_device *link) __devinit ; |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 43 | static void avma1cs_release(struct pcmcia_device *link); |
Henne | a465870 | 2010-03-25 12:05:31 +0000 | [diff] [blame] | 44 | static void avma1cs_detach(struct pcmcia_device *p_dev) __devexit ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Henne | a465870 | 2010-03-25 12:05:31 +0000 | [diff] [blame] | 46 | static int __devinit avma1cs_probe(struct pcmcia_device *p_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | { |
Dominik Brodowski | e773cfe | 2009-10-24 15:50:13 +0200 | [diff] [blame] | 48 | dev_dbg(&p_dev->dev, "avma1cs_attach()\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | /* General socket configuration */ |
Dominik Brodowski | 00990e7 | 2010-07-30 13:13:46 +0200 | [diff] [blame] | 51 | p_dev->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO; |
Dominik Brodowski | 7feabb6 | 2010-07-29 18:35:47 +0200 | [diff] [blame] | 52 | p_dev->config_index = 1; |
| 53 | p_dev->config_regs = PRESENT_OPTION; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 55 | return avma1cs_config(p_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | } /* avma1cs_attach */ |
| 57 | |
Henne | a465870 | 2010-03-25 12:05:31 +0000 | [diff] [blame] | 58 | static void __devexit avma1cs_detach(struct pcmcia_device *link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | { |
Dominik Brodowski | e773cfe | 2009-10-24 15:50:13 +0200 | [diff] [blame] | 60 | dev_dbg(&link->dev, "avma1cs_detach(0x%p)\n", link); |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 61 | avma1cs_release(link); |
| 62 | kfree(link->priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | } /* avma1cs_detach */ |
| 64 | |
Dominik Brodowski | 00990e7 | 2010-07-30 13:13:46 +0200 | [diff] [blame] | 65 | static int avma1cs_configcheck(struct pcmcia_device *p_dev, void *priv_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | { |
Dominik Brodowski | 00990e7 | 2010-07-30 13:13:46 +0200 | [diff] [blame] | 67 | p_dev->resource[0]->end = 16; |
| 68 | p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH; |
| 69 | p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8; |
Dominik Brodowski | 90abdc3 | 2010-07-24 17:23:51 +0200 | [diff] [blame] | 70 | p_dev->io_lines = 5; |
Dominik Brodowski | 00990e7 | 2010-07-30 13:13:46 +0200 | [diff] [blame] | 71 | |
Dominik Brodowski | 90abdc3 | 2010-07-24 17:23:51 +0200 | [diff] [blame] | 72 | return pcmcia_request_io(p_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
Henne | a465870 | 2010-03-25 12:05:31 +0000 | [diff] [blame] | 76 | static int __devinit avma1cs_config(struct pcmcia_device *link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | { |
Dominik Brodowski | eb14120 | 2010-03-07 12:21:16 +0100 | [diff] [blame] | 78 | int i = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | char devname[128]; |
| 80 | IsdnCard_t icard; |
| 81 | int busy = 0; |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 82 | |
Dominik Brodowski | e773cfe | 2009-10-24 15:50:13 +0200 | [diff] [blame] | 83 | dev_dbg(&link->dev, "avma1cs_config(0x%p)\n", link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
Dominik Brodowski | 5fcd4da | 2008-07-29 08:38:55 +0200 | [diff] [blame] | 85 | devname[0] = 0; |
| 86 | if (link->prod_id[1]) |
| 87 | strlcpy(devname, link->prod_id[1], sizeof(devname)); |
| 88 | |
| 89 | if (pcmcia_loop_config(link, avma1cs_configcheck, NULL)) |
| 90 | return -ENODEV; |
| 91 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | do { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | /* |
| 94 | * allocate an interrupt line |
| 95 | */ |
Dominik Brodowski | eb14120 | 2010-03-07 12:21:16 +0100 | [diff] [blame] | 96 | if (!link->irq) { |
Dominik Brodowski | 50db3fd | 2006-01-15 10:05:19 +0100 | [diff] [blame] | 97 | /* undo */ |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 98 | pcmcia_disable_device(link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | break; |
| 100 | } |
Dominik Brodowski | 50db3fd | 2006-01-15 10:05:19 +0100 | [diff] [blame] | 101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | /* |
| 103 | * configure the PCMCIA socket |
| 104 | */ |
Dominik Brodowski | 1ac71e5 | 2010-07-29 19:27:09 +0200 | [diff] [blame] | 105 | i = pcmcia_enable_device(link); |
Dominik Brodowski | 4c89e88 | 2008-08-03 10:07:45 +0200 | [diff] [blame] | 106 | if (i != 0) { |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 107 | pcmcia_disable_device(link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | break; |
| 109 | } |
| 110 | |
| 111 | } while (0); |
| 112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | /* If any step failed, release any partially configured state */ |
| 114 | if (i != 0) { |
| 115 | avma1cs_release(link); |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 116 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Dominik Brodowski | eb14120 | 2010-03-07 12:21:16 +0100 | [diff] [blame] | 119 | icard.para[0] = link->irq; |
Dominik Brodowski | 9a017a9 | 2010-07-24 15:58:54 +0200 | [diff] [blame] | 120 | icard.para[1] = link->resource[0]->start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | icard.protocol = isdnprot; |
| 122 | icard.typ = ISDN_CTYPE_A1_PCMCIA; |
| 123 | |
| 124 | i = hisax_init_pcmcia(link, &busy, &icard); |
| 125 | if (i < 0) { |
Dominik Brodowski | 9a017a9 | 2010-07-24 15:58:54 +0200 | [diff] [blame] | 126 | printk(KERN_ERR "avma1_cs: failed to initialize AVM A1 " |
| 127 | "PCMCIA %d at i/o %#x\n", i, |
| 128 | (unsigned int) link->resource[0]->start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | avma1cs_release(link); |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 130 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | } |
Dominik Brodowski | b498ada | 2010-03-20 19:43:26 +0100 | [diff] [blame] | 132 | link->priv = (void *) (unsigned long) i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 134 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | } /* avma1cs_config */ |
| 136 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 137 | static void avma1cs_release(struct pcmcia_device *link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | { |
Dominik Brodowski | b498ada | 2010-03-20 19:43:26 +0100 | [diff] [blame] | 139 | unsigned long minor = (unsigned long) link->priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
Dominik Brodowski | e773cfe | 2009-10-24 15:50:13 +0200 | [diff] [blame] | 141 | dev_dbg(&link->dev, "avma1cs_release(0x%p)\n", link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | |
Dominik Brodowski | 5f2a71f | 2006-01-15 09:32:39 +0100 | [diff] [blame] | 143 | /* now unregister function with hisax */ |
Dominik Brodowski | b498ada | 2010-03-20 19:43:26 +0100 | [diff] [blame] | 144 | HiSax_closecard(minor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 146 | pcmcia_disable_device(link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | } /* avma1cs_release */ |
| 148 | |
Joe Perches | 25f8f54 | 2011-05-03 19:29:01 -0700 | [diff] [blame] | 149 | static const struct pcmcia_device_id avma1cs_ids[] = { |
Dominik Brodowski | c594c12 | 2005-06-27 16:28:34 -0700 | [diff] [blame] | 150 | PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN A", 0x95d42008, 0xadc9d4bb), |
| 151 | PCMCIA_DEVICE_PROD_ID12("ISDN", "CARD", 0x8d9761c8, 0x01c5aa7b), |
| 152 | PCMCIA_DEVICE_NULL |
| 153 | }; |
| 154 | MODULE_DEVICE_TABLE(pcmcia, avma1cs_ids); |
| 155 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | static struct pcmcia_driver avma1cs_driver = { |
| 157 | .owner = THIS_MODULE, |
Dominik Brodowski | 2e9b981 | 2010-08-08 11:36:26 +0200 | [diff] [blame] | 158 | .name = "avma1_cs", |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 159 | .probe = avma1cs_probe, |
Henne | a465870 | 2010-03-25 12:05:31 +0000 | [diff] [blame] | 160 | .remove = __devexit_p(avma1cs_detach), |
Dominik Brodowski | c594c12 | 2005-06-27 16:28:34 -0700 | [diff] [blame] | 161 | .id_table = avma1cs_ids, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | }; |
Dominik Brodowski | 8661bb5 | 2006-03-02 00:02:33 +0100 | [diff] [blame] | 163 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | static int __init init_avma1_cs(void) |
| 165 | { |
Dominik Brodowski | 06b3a1d | 2010-08-08 12:27:40 +0200 | [diff] [blame] | 166 | return pcmcia_register_driver(&avma1cs_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | static void __exit exit_avma1_cs(void) |
| 170 | { |
| 171 | pcmcia_unregister_driver(&avma1cs_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | module_init(init_avma1_cs); |
| 175 | module_exit(exit_avma1_cs); |