Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #include "ixj-ver.h" |
| 2 | |
| 3 | #include <linux/module.h> |
| 4 | |
| 5 | #include <linux/init.h> |
| 6 | #include <linux/sched.h> |
| 7 | #include <linux/kernel.h> /* printk() */ |
| 8 | #include <linux/fs.h> /* everything... */ |
| 9 | #include <linux/errno.h> /* error codes */ |
| 10 | #include <linux/slab.h> |
| 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <pcmcia/cs_types.h> |
| 13 | #include <pcmcia/cs.h> |
| 14 | #include <pcmcia/cistpl.h> |
| 15 | #include <pcmcia/ds.h> |
| 16 | |
| 17 | #include "ixj.h" |
| 18 | |
| 19 | /* |
| 20 | * PCMCIA service support for Quicknet cards |
| 21 | */ |
| 22 | |
| 23 | #ifdef PCMCIA_DEBUG |
| 24 | static int pc_debug = PCMCIA_DEBUG; |
| 25 | module_param(pc_debug, int, 0644); |
| 26 | #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args) |
| 27 | #else |
| 28 | #define DEBUG(n, args...) |
| 29 | #endif |
| 30 | |
| 31 | typedef struct ixj_info_t { |
| 32 | int ndev; |
| 33 | dev_node_t node; |
| 34 | struct ixj *port; |
| 35 | } ixj_info_t; |
| 36 | |
Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 37 | static void ixj_detach(struct pcmcia_device *p_dev); |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame^] | 38 | static int ixj_config(struct pcmcia_device * link); |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 39 | static void ixj_cs_release(struct pcmcia_device * link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame^] | 41 | static int ixj_probe(struct pcmcia_device *p_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | DEBUG(0, "ixj_attach()\n"); |
| 44 | /* Create new ixj device */ |
Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 45 | p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8; |
| 46 | p_dev->io.Attributes2 = IO_DATA_PATH_WIDTH_8; |
| 47 | p_dev->io.IOAddrLines = 3; |
| 48 | p_dev->conf.IntType = INT_MEMORY_AND_IO; |
| 49 | p_dev->priv = kmalloc(sizeof(struct ixj_info_t), GFP_KERNEL); |
| 50 | if (!p_dev->priv) { |
Dominik Brodowski | f8cfa61 | 2005-11-14 21:25:51 +0100 | [diff] [blame] | 51 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | } |
Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 53 | memset(p_dev->priv, 0, sizeof(struct ixj_info_t)); |
Dominik Brodowski | f8cfa61 | 2005-11-14 21:25:51 +0100 | [diff] [blame] | 54 | |
Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 55 | p_dev->state |= DEV_PRESENT | DEV_CONFIG_PENDING; |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame^] | 56 | return ixj_config(p_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 59 | static void ixj_detach(struct pcmcia_device *link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | DEBUG(0, "ixj_detach(0x%p)\n", link); |
Dominik Brodowski | b463581 | 2005-11-14 21:25:35 +0100 | [diff] [blame] | 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | link->state &= ~DEV_RELEASE_PENDING; |
| 64 | if (link->state & DEV_CONFIG) |
| 65 | ixj_cs_release(link); |
Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 66 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | kfree(link->priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | #define CS_CHECK(fn, ret) \ |
| 71 | do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) |
| 72 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 73 | static void ixj_get_serial(struct pcmcia_device * link, IXJ * j) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | tuple_t tuple; |
| 76 | u_short buf[128]; |
| 77 | char *str; |
| 78 | int last_ret, last_fn, i, place; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | DEBUG(0, "ixj_get_serial(0x%p)\n", link); |
| 80 | tuple.TupleData = (cisdata_t *) buf; |
| 81 | tuple.TupleOffset = 0; |
| 82 | tuple.TupleDataMax = 80; |
| 83 | tuple.Attributes = 0; |
| 84 | tuple.DesiredTuple = CISTPL_VERS_1; |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 85 | CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple)); |
| 86 | CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | str = (char *) buf; |
| 88 | printk("PCMCIA Version %d.%d\n", str[0], str[1]); |
| 89 | str += 2; |
| 90 | printk("%s", str); |
| 91 | str = str + strlen(str) + 1; |
| 92 | printk(" %s", str); |
| 93 | str = str + strlen(str) + 1; |
| 94 | place = 1; |
| 95 | for (i = strlen(str) - 1; i >= 0; i--) { |
| 96 | switch (str[i]) { |
| 97 | case '0': |
| 98 | case '1': |
| 99 | case '2': |
| 100 | case '3': |
| 101 | case '4': |
| 102 | case '5': |
| 103 | case '6': |
| 104 | case '7': |
| 105 | case '8': |
| 106 | case '9': |
| 107 | j->serial += (str[i] - 48) * place; |
| 108 | break; |
| 109 | case 'A': |
| 110 | case 'B': |
| 111 | case 'C': |
| 112 | case 'D': |
| 113 | case 'E': |
| 114 | case 'F': |
| 115 | j->serial += (str[i] - 55) * place; |
| 116 | break; |
| 117 | case 'a': |
| 118 | case 'b': |
| 119 | case 'c': |
| 120 | case 'd': |
| 121 | case 'e': |
| 122 | case 'f': |
| 123 | j->serial += (str[i] - 87) * place; |
| 124 | break; |
| 125 | } |
| 126 | place = place * 0x10; |
| 127 | } |
| 128 | str = str + strlen(str) + 1; |
| 129 | printk(" version %s\n", str); |
| 130 | cs_failed: |
| 131 | return; |
| 132 | } |
| 133 | |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame^] | 134 | static int ixj_config(struct pcmcia_device * link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | { |
| 136 | IXJ *j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | ixj_info_t *info; |
| 138 | tuple_t tuple; |
| 139 | u_short buf[128]; |
| 140 | cisparse_t parse; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | cistpl_cftable_entry_t *cfg = &parse.cftable_entry; |
| 142 | cistpl_cftable_entry_t dflt = |
| 143 | { |
| 144 | 0 |
| 145 | }; |
| 146 | int last_ret, last_fn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | info = link->priv; |
| 148 | DEBUG(0, "ixj_config(0x%p)\n", link); |
| 149 | tuple.TupleData = (cisdata_t *) buf; |
| 150 | tuple.TupleOffset = 0; |
| 151 | tuple.TupleDataMax = 255; |
| 152 | tuple.Attributes = 0; |
| 153 | tuple.DesiredTuple = CISTPL_CONFIG; |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 154 | CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple)); |
| 155 | CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple)); |
| 156 | CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | link->conf.ConfigBase = parse.config.base; |
| 158 | link->conf.Present = parse.config.rmask[0]; |
| 159 | link->state |= DEV_CONFIG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; |
| 161 | tuple.Attributes = 0; |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 162 | CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | while (1) { |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 164 | if (pcmcia_get_tuple_data(link, &tuple) != 0 || |
| 165 | pcmcia_parse_tuple(link, &tuple, &parse) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | goto next_entry; |
| 167 | if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) { |
| 168 | cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io; |
| 169 | link->conf.ConfigIndex = cfg->index; |
| 170 | link->io.BasePort1 = io->win[0].base; |
| 171 | link->io.NumPorts1 = io->win[0].len; |
| 172 | if (io->nwin == 2) { |
| 173 | link->io.BasePort2 = io->win[1].base; |
| 174 | link->io.NumPorts2 = io->win[1].len; |
| 175 | } |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 176 | if (pcmcia_request_io(link, &link->io) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | goto next_entry; |
| 178 | /* If we've got this far, we're done */ |
| 179 | break; |
| 180 | } |
| 181 | next_entry: |
| 182 | if (cfg->flags & CISTPL_CFTABLE_DEFAULT) |
| 183 | dflt = *cfg; |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 184 | CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | } |
| 186 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 187 | CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | |
| 189 | /* |
| 190 | * Register the card with the core. |
| 191 | */ |
| 192 | j=ixj_pcmcia_probe(link->io.BasePort1,link->io.BasePort1 + 0x10); |
| 193 | |
| 194 | info->ndev = 1; |
| 195 | info->node.major = PHONE_MAJOR; |
Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 196 | link->dev_node = &info->node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | ixj_get_serial(link, j); |
| 198 | link->state &= ~DEV_CONFIG_PENDING; |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame^] | 199 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | cs_failed: |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 201 | cs_error(link, last_fn, last_ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | ixj_cs_release(link); |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame^] | 203 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | } |
| 205 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 206 | static void ixj_cs_release(struct pcmcia_device *link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | { |
| 208 | ixj_info_t *info = link->priv; |
| 209 | DEBUG(0, "ixj_cs_release(0x%p)\n", link); |
| 210 | info->ndev = 0; |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 211 | pcmcia_disable_device(link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Dominik Brodowski | 0708127 | 2005-06-27 16:28:40 -0700 | [diff] [blame] | 214 | static struct pcmcia_device_id ixj_ids[] = { |
| 215 | PCMCIA_DEVICE_MANF_CARD(0x0257, 0x0600), |
| 216 | PCMCIA_DEVICE_NULL |
| 217 | }; |
| 218 | MODULE_DEVICE_TABLE(pcmcia, ixj_ids); |
| 219 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | static struct pcmcia_driver ixj_driver = { |
| 221 | .owner = THIS_MODULE, |
| 222 | .drv = { |
| 223 | .name = "ixj_cs", |
| 224 | }, |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame^] | 225 | .probe = ixj_probe, |
Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 226 | .remove = ixj_detach, |
Dominik Brodowski | 0708127 | 2005-06-27 16:28:40 -0700 | [diff] [blame] | 227 | .id_table = ixj_ids, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | }; |
| 229 | |
| 230 | static int __init ixj_pcmcia_init(void) |
| 231 | { |
| 232 | return pcmcia_register_driver(&ixj_driver); |
| 233 | } |
| 234 | |
| 235 | static void ixj_pcmcia_exit(void) |
| 236 | { |
| 237 | pcmcia_unregister_driver(&ixj_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | module_init(ixj_pcmcia_init); |
| 241 | module_exit(ixj_pcmcia_exit); |
| 242 | |
| 243 | MODULE_LICENSE("GPL"); |