blob: d005b9eeebbcc1f751763c7ab039c9dea13333ca [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#include "ixj-ver.h"
2
3#include <linux/module.h>
4
5#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006#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 Torvalds1da177e2005-04-16 15:20:36 -070011#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 Torvalds1da177e2005-04-16 15:20:36 -070020
21typedef struct ixj_info_t {
22 int ndev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070023 struct ixj *port;
24} ixj_info_t;
25
Dominik Brodowskicc3b4862005-11-14 21:23:14 +010026static void ixj_detach(struct pcmcia_device *p_dev);
Dominik Brodowski15b99ac2006-03-31 17:26:06 +020027static int ixj_config(struct pcmcia_device * link);
Dominik Brodowskifba395e2006-03-31 17:21:06 +020028static void ixj_cs_release(struct pcmcia_device * link);
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Dominik Brodowski15b99ac2006-03-31 17:26:06 +020030static int ixj_probe(struct pcmcia_device *p_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070031{
Dominik Brodowski9b44de22009-10-24 15:55:39 +020032 dev_dbg(&p_dev->dev, "ixj_attach()\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 /* Create new ixj device */
Yoann Padioleaudd00cc42007-07-19 01:49:03 -070034 p_dev->priv = kzalloc(sizeof(struct ixj_info_t), GFP_KERNEL);
Dominik Brodowskifd238232006-03-05 10:45:09 +010035 if (!p_dev->priv) {
Dominik Brodowskif8cfa612005-11-14 21:25:51 +010036 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 }
Dominik Brodowskif8cfa612005-11-14 21:25:51 +010038
Dominik Brodowski15b99ac2006-03-31 17:26:06 +020039 return ixj_config(p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070040}
41
Dominik Brodowskifba395e2006-03-31 17:21:06 +020042static void ixj_detach(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -070043{
Dominik Brodowski9b44de22009-10-24 15:55:39 +020044 dev_dbg(&link->dev, "ixj_detach\n");
Dominik Brodowskib4635812005-11-14 21:25:35 +010045
Dominik Brodowskie2d40962006-03-02 00:09:29 +010046 ixj_cs_release(link);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +010047
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 kfree(link->priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -070049}
50
Dominik Brodowskifba395e2006-03-31 17:21:06 +020051static void ixj_get_serial(struct pcmcia_device * link, IXJ * j)
Linus Torvalds1da177e2005-04-16 15:20:36 -070052{
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 char *str;
Dominik Brodowskia9606fd2006-06-04 18:06:13 +020054 int i, place;
Dominik Brodowski9b44de22009-10-24 15:55:39 +020055 dev_dbg(&link->dev, "ixj_get_serial\n");
Dominik Brodowskia9606fd2006-06-04 18:06:13 +020056
57 str = link->prod_id[0];
58 if (!str)
Dominik Brodowski9b44de22009-10-24 15:55:39 +020059 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 printk("%s", str);
Dominik Brodowskia9606fd2006-06-04 18:06:13 +020061 str = link->prod_id[1];
62 if (!str)
Dominik Brodowski9b44de22009-10-24 15:55:39 +020063 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 printk(" %s", str);
Dominik Brodowskia9606fd2006-06-04 18:06:13 +020065 str = link->prod_id[2];
66 if (!str)
Dominik Brodowski9b44de22009-10-24 15:55:39 +020067 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 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 Brodowskia9606fd2006-06-04 18:06:13 +0200102 str = link->prod_id[3];
103 if (!str)
Dominik Brodowski9b44de22009-10-24 15:55:39 +0200104 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 printk(" version %s\n", str);
Dominik Brodowski9b44de22009-10-24 15:55:39 +0200106failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 return;
108}
109
Dominik Brodowski00990e72010-07-30 13:13:46 +0200110static int ixj_config_check(struct pcmcia_device *p_dev, void *priv_data)
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200111{
Dominik Brodowski00990e72010-07-30 13:13:46 +0200112 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 Brodowski84e2d342008-07-29 08:38:55 +0200119}
120
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200121static int ixj_config(struct pcmcia_device * link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122{
123 IXJ *j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 ixj_info_t *info;
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200125
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 info = link->priv;
Dominik Brodowski9b44de22009-10-24 15:55:39 +0200127 dev_dbg(&link->dev, "ixj_config\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
Dominik Brodowski00990e72010-07-30 13:13:46 +0200129 link->config_flags = CONF_AUTO_SET_IO;
130
131 if (pcmcia_loop_config(link, ixj_config_check, NULL))
Dominik Brodowski9b44de22009-10-24 15:55:39 +0200132 goto failed;
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200133
Dominik Brodowski1ac71e52010-07-29 19:27:09 +0200134 if (pcmcia_enable_device(link))
Dominik Brodowski9b44de22009-10-24 15:55:39 +0200135 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
137 /*
138 * Register the card with the core.
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200139 */
Dominik Brodowski9a017a92010-07-24 15:58:54 +0200140 j = ixj_pcmcia_probe(link->resource[0]->start,
141 link->resource[0]->start + 0x10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
143 info->ndev = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 ixj_get_serial(link, j);
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200145 return 0;
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200146
Dominik Brodowski9b44de22009-10-24 15:55:39 +0200147failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 ixj_cs_release(link);
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200149 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150}
151
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200152static void ixj_cs_release(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153{
154 ixj_info_t *info = link->priv;
Dominik Brodowski9b44de22009-10-24 15:55:39 +0200155 dev_dbg(&link->dev, "ixj_cs_release\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 info->ndev = 0;
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200157 pcmcia_disable_device(link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158}
159
Dominik Brodowski07081272005-06-27 16:28:40 -0700160static struct pcmcia_device_id ixj_ids[] = {
161 PCMCIA_DEVICE_MANF_CARD(0x0257, 0x0600),
162 PCMCIA_DEVICE_NULL
163};
164MODULE_DEVICE_TABLE(pcmcia, ixj_ids);
165
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166static struct pcmcia_driver ixj_driver = {
167 .owner = THIS_MODULE,
Dominik Brodowski2e9b9812010-08-08 11:36:26 +0200168 .name = "ixj_cs",
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200169 .probe = ixj_probe,
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100170 .remove = ixj_detach,
Dominik Brodowski07081272005-06-27 16:28:40 -0700171 .id_table = ixj_ids,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172};
173
174static int __init ixj_pcmcia_init(void)
175{
176 return pcmcia_register_driver(&ixj_driver);
177}
178
179static void ixj_pcmcia_exit(void)
180{
181 pcmcia_unregister_driver(&ixj_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182}
183
184module_init(ixj_pcmcia_init);
185module_exit(ixj_pcmcia_exit);
186
187MODULE_LICENSE("GPL");