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