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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include <linux/kernel.h> /* printk() */ |
| 7 | #include <linux/fs.h> /* everything... */ |
| 8 | #include <linux/errno.h> /* error codes */ |
| 9 | #include <linux/slab.h> |
| 10 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <pcmcia/cs_types.h> |
| 12 | #include <pcmcia/cs.h> |
| 13 | #include <pcmcia/cistpl.h> |
| 14 | #include <pcmcia/ds.h> |
| 15 | |
| 16 | #include "ixj.h" |
| 17 | |
| 18 | /* |
| 19 | * PCMCIA service support for Quicknet cards |
| 20 | */ |
| 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
| 23 | typedef struct ixj_info_t { |
| 24 | int ndev; |
| 25 | dev_node_t node; |
| 26 | struct ixj *port; |
| 27 | } ixj_info_t; |
| 28 | |
Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 29 | static void ixj_detach(struct pcmcia_device *p_dev); |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 30 | static int ixj_config(struct pcmcia_device * link); |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 31 | static void ixj_cs_release(struct pcmcia_device * link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 33 | static int ixj_probe(struct pcmcia_device *p_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | { |
Dominik Brodowski | 9b44de2 | 2009-10-24 15:55:39 +0200 | [diff] [blame] | 35 | dev_dbg(&p_dev->dev, "ixj_attach()\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | /* Create new ixj device */ |
Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 37 | p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8; |
| 38 | p_dev->io.Attributes2 = IO_DATA_PATH_WIDTH_8; |
| 39 | p_dev->io.IOAddrLines = 3; |
| 40 | p_dev->conf.IntType = INT_MEMORY_AND_IO; |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 41 | p_dev->priv = kzalloc(sizeof(struct ixj_info_t), GFP_KERNEL); |
Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 42 | if (!p_dev->priv) { |
Dominik Brodowski | f8cfa61 | 2005-11-14 21:25:51 +0100 | [diff] [blame] | 43 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | } |
Dominik Brodowski | f8cfa61 | 2005-11-14 21:25:51 +0100 | [diff] [blame] | 45 | |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 46 | return ixj_config(p_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 49 | static void ixj_detach(struct pcmcia_device *link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | { |
Dominik Brodowski | 9b44de2 | 2009-10-24 15:55:39 +0200 | [diff] [blame] | 51 | dev_dbg(&link->dev, "ixj_detach\n"); |
Dominik Brodowski | b463581 | 2005-11-14 21:25:35 +0100 | [diff] [blame] | 52 | |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 53 | ixj_cs_release(link); |
Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 54 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | kfree(link->priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | } |
| 57 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 58 | static void ixj_get_serial(struct pcmcia_device * link, IXJ * j) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | char *str; |
Dominik Brodowski | a9606fd | 2006-06-04 18:06:13 +0200 | [diff] [blame] | 61 | int i, place; |
Dominik Brodowski | 9b44de2 | 2009-10-24 15:55:39 +0200 | [diff] [blame] | 62 | dev_dbg(&link->dev, "ixj_get_serial\n"); |
Dominik Brodowski | a9606fd | 2006-06-04 18:06:13 +0200 | [diff] [blame] | 63 | |
| 64 | str = link->prod_id[0]; |
| 65 | if (!str) |
Dominik Brodowski | 9b44de2 | 2009-10-24 15:55:39 +0200 | [diff] [blame] | 66 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | printk("%s", str); |
Dominik Brodowski | a9606fd | 2006-06-04 18:06:13 +0200 | [diff] [blame] | 68 | str = link->prod_id[1]; |
| 69 | if (!str) |
Dominik Brodowski | 9b44de2 | 2009-10-24 15:55:39 +0200 | [diff] [blame] | 70 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | printk(" %s", str); |
Dominik Brodowski | a9606fd | 2006-06-04 18:06:13 +0200 | [diff] [blame] | 72 | str = link->prod_id[2]; |
| 73 | if (!str) |
Dominik Brodowski | 9b44de2 | 2009-10-24 15:55:39 +0200 | [diff] [blame] | 74 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | place = 1; |
| 76 | for (i = strlen(str) - 1; i >= 0; i--) { |
| 77 | switch (str[i]) { |
| 78 | case '0': |
| 79 | case '1': |
| 80 | case '2': |
| 81 | case '3': |
| 82 | case '4': |
| 83 | case '5': |
| 84 | case '6': |
| 85 | case '7': |
| 86 | case '8': |
| 87 | case '9': |
| 88 | j->serial += (str[i] - 48) * place; |
| 89 | break; |
| 90 | case 'A': |
| 91 | case 'B': |
| 92 | case 'C': |
| 93 | case 'D': |
| 94 | case 'E': |
| 95 | case 'F': |
| 96 | j->serial += (str[i] - 55) * place; |
| 97 | break; |
| 98 | case 'a': |
| 99 | case 'b': |
| 100 | case 'c': |
| 101 | case 'd': |
| 102 | case 'e': |
| 103 | case 'f': |
| 104 | j->serial += (str[i] - 87) * place; |
| 105 | break; |
| 106 | } |
| 107 | place = place * 0x10; |
| 108 | } |
Dominik Brodowski | a9606fd | 2006-06-04 18:06:13 +0200 | [diff] [blame] | 109 | str = link->prod_id[3]; |
| 110 | if (!str) |
Dominik Brodowski | 9b44de2 | 2009-10-24 15:55:39 +0200 | [diff] [blame] | 111 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | printk(" version %s\n", str); |
Dominik Brodowski | 9b44de2 | 2009-10-24 15:55:39 +0200 | [diff] [blame] | 113 | failed: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | return; |
| 115 | } |
| 116 | |
Dominik Brodowski | 84e2d34 | 2008-07-29 08:38:55 +0200 | [diff] [blame] | 117 | static int ixj_config_check(struct pcmcia_device *p_dev, |
| 118 | cistpl_cftable_entry_t *cfg, |
Dominik Brodowski | 8e2fc39 | 2008-08-02 15:30:31 +0200 | [diff] [blame] | 119 | cistpl_cftable_entry_t *dflt, |
Dominik Brodowski | ad913c1 | 2008-08-02 16:12:00 +0200 | [diff] [blame] | 120 | unsigned int vcc, |
Dominik Brodowski | 84e2d34 | 2008-07-29 08:38:55 +0200 | [diff] [blame] | 121 | void *priv_data) |
| 122 | { |
Dominik Brodowski | 84e2d34 | 2008-07-29 08:38:55 +0200 | [diff] [blame] | 123 | if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) { |
| 124 | cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io; |
Dominik Brodowski | 84e2d34 | 2008-07-29 08:38:55 +0200 | [diff] [blame] | 125 | p_dev->io.BasePort1 = io->win[0].base; |
| 126 | p_dev->io.NumPorts1 = io->win[0].len; |
| 127 | if (io->nwin == 2) { |
| 128 | p_dev->io.BasePort2 = io->win[1].base; |
| 129 | p_dev->io.NumPorts2 = io->win[1].len; |
| 130 | } |
Dominik Brodowski | 8e2fc39 | 2008-08-02 15:30:31 +0200 | [diff] [blame] | 131 | if (!pcmcia_request_io(p_dev, &p_dev->io)) |
Dominik Brodowski | 84e2d34 | 2008-07-29 08:38:55 +0200 | [diff] [blame] | 132 | return 0; |
| 133 | } |
| 134 | return -ENODEV; |
| 135 | } |
| 136 | |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 137 | static int ixj_config(struct pcmcia_device * link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | { |
| 139 | IXJ *j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | ixj_info_t *info; |
Dominik Brodowski | 84e2d34 | 2008-07-29 08:38:55 +0200 | [diff] [blame] | 141 | cistpl_cftable_entry_t dflt = { 0 }; |
| 142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | info = link->priv; |
Dominik Brodowski | 9b44de2 | 2009-10-24 15:55:39 +0200 | [diff] [blame] | 144 | dev_dbg(&link->dev, "ixj_config\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
Dominik Brodowski | 84e2d34 | 2008-07-29 08:38:55 +0200 | [diff] [blame] | 146 | if (pcmcia_loop_config(link, ixj_config_check, &dflt)) |
Dominik Brodowski | 9b44de2 | 2009-10-24 15:55:39 +0200 | [diff] [blame] | 147 | goto failed; |
Dominik Brodowski | 84e2d34 | 2008-07-29 08:38:55 +0200 | [diff] [blame] | 148 | |
| 149 | if (pcmcia_request_configuration(link, &link->conf)) |
Dominik Brodowski | 9b44de2 | 2009-10-24 15:55:39 +0200 | [diff] [blame] | 150 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
| 152 | /* |
| 153 | * Register the card with the core. |
Dominik Brodowski | 84e2d34 | 2008-07-29 08:38:55 +0200 | [diff] [blame] | 154 | */ |
| 155 | j = ixj_pcmcia_probe(link->io.BasePort1, link->io.BasePort1 + 0x10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
| 157 | info->ndev = 1; |
| 158 | info->node.major = PHONE_MAJOR; |
Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 159 | link->dev_node = &info->node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | ixj_get_serial(link, j); |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 161 | return 0; |
Dominik Brodowski | 84e2d34 | 2008-07-29 08:38:55 +0200 | [diff] [blame] | 162 | |
Dominik Brodowski | 9b44de2 | 2009-10-24 15:55:39 +0200 | [diff] [blame] | 163 | failed: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | ixj_cs_release(link); |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 165 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 168 | static void ixj_cs_release(struct pcmcia_device *link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | { |
| 170 | ixj_info_t *info = link->priv; |
Dominik Brodowski | 9b44de2 | 2009-10-24 15:55:39 +0200 | [diff] [blame] | 171 | dev_dbg(&link->dev, "ixj_cs_release\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | info->ndev = 0; |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 173 | pcmcia_disable_device(link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Dominik Brodowski | 0708127 | 2005-06-27 16:28:40 -0700 | [diff] [blame] | 176 | static struct pcmcia_device_id ixj_ids[] = { |
| 177 | PCMCIA_DEVICE_MANF_CARD(0x0257, 0x0600), |
| 178 | PCMCIA_DEVICE_NULL |
| 179 | }; |
| 180 | MODULE_DEVICE_TABLE(pcmcia, ixj_ids); |
| 181 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | static struct pcmcia_driver ixj_driver = { |
| 183 | .owner = THIS_MODULE, |
| 184 | .drv = { |
| 185 | .name = "ixj_cs", |
| 186 | }, |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 187 | .probe = ixj_probe, |
Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 188 | .remove = ixj_detach, |
Dominik Brodowski | 0708127 | 2005-06-27 16:28:40 -0700 | [diff] [blame] | 189 | .id_table = ixj_ids, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | }; |
| 191 | |
| 192 | static int __init ixj_pcmcia_init(void) |
| 193 | { |
| 194 | return pcmcia_register_driver(&ixj_driver); |
| 195 | } |
| 196 | |
| 197 | static void ixj_pcmcia_exit(void) |
| 198 | { |
| 199 | pcmcia_unregister_driver(&ixj_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | module_init(ixj_pcmcia_init); |
| 203 | module_exit(ixj_pcmcia_exit); |
| 204 | |
| 205 | MODULE_LICENSE("GPL"); |