Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* $Id: avm_cs.c,v 1.4.6.3 2001/09/23 22:24:33 kai Exp $ |
| 2 | * |
| 3 | * A PCMCIA client driver for AVM B1/M1/M2 |
| 4 | * |
| 5 | * Copyright 1999 by Carsten Paeth <calle@calle.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 | #include <linux/kernel.h> |
| 14 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/ptrace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <pcmcia/cistpl.h> |
| 23 | #include <pcmcia/ciscode.h> |
| 24 | #include <pcmcia/ds.h> |
| 25 | #include <pcmcia/cisreg.h> |
| 26 | |
| 27 | #include <linux/skbuff.h> |
| 28 | #include <linux/capi.h> |
| 29 | #include <linux/b1lli.h> |
| 30 | #include <linux/b1pcmcia.h> |
| 31 | |
| 32 | /*====================================================================*/ |
| 33 | |
| 34 | MODULE_DESCRIPTION("CAPI4Linux: PCMCIA client driver for AVM B1/M1/M2"); |
| 35 | MODULE_AUTHOR("Carsten Paeth"); |
| 36 | MODULE_LICENSE("GPL"); |
| 37 | |
| 38 | /*====================================================================*/ |
| 39 | |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 40 | static int avmcs_config(struct pcmcia_device *link); |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 41 | static void avmcs_release(struct pcmcia_device *link); |
Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 42 | static void avmcs_detach(struct pcmcia_device *p_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 44 | static int avmcs_probe(struct pcmcia_device *p_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 46 | /* General socket configuration */ |
| 47 | p_dev->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO; |
| 48 | p_dev->config_index = 1; |
| 49 | p_dev->config_regs = PRESENT_OPTION; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 51 | return avmcs_config(p_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | } /* avmcs_attach */ |
| 53 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 55 | static void avmcs_detach(struct pcmcia_device *link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | { |
Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 57 | avmcs_release(link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | } /* avmcs_detach */ |
| 59 | |
Dominik Brodowski | 00990e7 | 2010-07-30 13:13:46 +0200 | [diff] [blame] | 60 | static int avmcs_configcheck(struct pcmcia_device *p_dev, void *priv_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | { |
Dominik Brodowski | 00990e7 | 2010-07-30 13:13:46 +0200 | [diff] [blame] | 62 | p_dev->resource[0]->end = 16; |
| 63 | p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH; |
| 64 | p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
Dominik Brodowski | 90abdc3 | 2010-07-24 17:23:51 +0200 | [diff] [blame] | 66 | return pcmcia_request_io(p_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | } |
| 68 | |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 69 | static int avmcs_config(struct pcmcia_device *link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 71 | int i = -1; |
| 72 | char devname[128]; |
| 73 | int cardtype; |
| 74 | int (*addcard)(unsigned int port, unsigned irq); |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 75 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 76 | devname[0] = 0; |
| 77 | if (link->prod_id[1]) |
| 78 | strlcpy(devname, link->prod_id[1], sizeof(devname)); |
Dominik Brodowski | 50db3fd | 2006-01-15 10:05:19 +0100 | [diff] [blame] | 79 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | /* |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 81 | * find IO port |
| 82 | */ |
| 83 | if (pcmcia_loop_config(link, avmcs_configcheck, NULL)) |
| 84 | return -ENODEV; |
| 85 | |
| 86 | do { |
| 87 | if (!link->irq) { |
| 88 | /* undo */ |
| 89 | pcmcia_disable_device(link); |
| 90 | break; |
| 91 | } |
| 92 | |
| 93 | /* |
| 94 | * configure the PCMCIA socket |
| 95 | */ |
| 96 | i = pcmcia_enable_device(link); |
| 97 | if (i != 0) { |
| 98 | pcmcia_disable_device(link); |
| 99 | break; |
| 100 | } |
| 101 | |
| 102 | } while (0); |
| 103 | |
| 104 | if (devname[0]) { |
| 105 | char *s = strrchr(devname, ' '); |
| 106 | if (!s) |
| 107 | s = devname; |
| 108 | else s++; |
| 109 | if (strcmp("M1", s) == 0) { |
| 110 | cardtype = AVM_CARDTYPE_M1; |
| 111 | } else if (strcmp("M2", s) == 0) { |
| 112 | cardtype = AVM_CARDTYPE_M2; |
| 113 | } else { |
| 114 | cardtype = AVM_CARDTYPE_B1; |
| 115 | } |
| 116 | } else |
| 117 | cardtype = AVM_CARDTYPE_B1; |
| 118 | |
| 119 | /* If any step failed, release any partially configured state */ |
Dominik Brodowski | 4c89e88 | 2008-08-03 10:07:45 +0200 | [diff] [blame] | 120 | if (i != 0) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 121 | avmcs_release(link); |
| 122 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 126 | switch (cardtype) { |
| 127 | case AVM_CARDTYPE_M1: addcard = b1pcmcia_addcard_m1; break; |
| 128 | case AVM_CARDTYPE_M2: addcard = b1pcmcia_addcard_m2; break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | default: |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 130 | case AVM_CARDTYPE_B1: addcard = b1pcmcia_addcard_b1; break; |
| 131 | } |
| 132 | if ((i = (*addcard)(link->resource[0]->start, link->irq)) < 0) { |
| 133 | dev_err(&link->dev, |
| 134 | "avm_cs: failed to add AVM-Controller at i/o %#x, irq %d\n", |
| 135 | (unsigned int) link->resource[0]->start, link->irq); |
| 136 | avmcs_release(link); |
| 137 | return -ENODEV; |
| 138 | } |
| 139 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
| 141 | } /* avmcs_config */ |
| 142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 144 | static void avmcs_release(struct pcmcia_device *link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | { |
Dominik Brodowski | 9a017a9 | 2010-07-24 15:58:54 +0200 | [diff] [blame] | 146 | b1pcmcia_delcard(link->resource[0]->start, link->irq); |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 147 | pcmcia_disable_device(link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | } /* avmcs_release */ |
| 149 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
Joe Perches | 25f8f54 | 2011-05-03 19:29:01 -0700 | [diff] [blame] | 151 | static const struct pcmcia_device_id avmcs_ids[] = { |
Dominik Brodowski | a13bcf0 | 2005-06-27 16:28:35 -0700 | [diff] [blame] | 152 | PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN-Controller B1", 0x95d42008, 0x845dc335), |
| 153 | PCMCIA_DEVICE_PROD_ID12("AVM", "Mobile ISDN-Controller M1", 0x95d42008, 0x81e10430), |
| 154 | PCMCIA_DEVICE_PROD_ID12("AVM", "Mobile ISDN-Controller M2", 0x95d42008, 0x18e8558a), |
| 155 | PCMCIA_DEVICE_NULL |
| 156 | }; |
| 157 | MODULE_DEVICE_TABLE(pcmcia, avmcs_ids); |
| 158 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | static struct pcmcia_driver avmcs_driver = { |
| 160 | .owner = THIS_MODULE, |
Dominik Brodowski | 2e9b981 | 2010-08-08 11:36:26 +0200 | [diff] [blame] | 161 | .name = "avm_cs", |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 162 | .probe = avmcs_probe, |
Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 163 | .remove = avmcs_detach, |
Dominik Brodowski | a13bcf0 | 2005-06-27 16:28:35 -0700 | [diff] [blame] | 164 | .id_table = avmcs_ids, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | }; |
| 166 | |
| 167 | static int __init avmcs_init(void) |
| 168 | { |
| 169 | return pcmcia_register_driver(&avmcs_driver); |
| 170 | } |
| 171 | |
| 172 | static void __exit avmcs_exit(void) |
| 173 | { |
| 174 | pcmcia_unregister_driver(&avmcs_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | module_init(avmcs_init); |
| 178 | module_exit(avmcs_exit); |