blob: 347c3ed1d9f15fbe1edd10944b6b44b72ace07ac [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/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
22#ifdef PCMCIA_DEBUG
23static int pc_debug = PCMCIA_DEBUG;
24module_param(pc_debug, int, 0644);
25#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
26#else
27#define DEBUG(n, args...)
28#endif
29
30typedef struct ixj_info_t {
31 int ndev;
32 dev_node_t node;
33 struct ixj *port;
34} ixj_info_t;
35
Dominik Brodowskicc3b4862005-11-14 21:23:14 +010036static void ixj_detach(struct pcmcia_device *p_dev);
Dominik Brodowski15b99ac2006-03-31 17:26:06 +020037static int ixj_config(struct pcmcia_device * link);
Dominik Brodowskifba395e2006-03-31 17:21:06 +020038static void ixj_cs_release(struct pcmcia_device * link);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Dominik Brodowski15b99ac2006-03-31 17:26:06 +020040static int ixj_probe(struct pcmcia_device *p_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070041{
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 DEBUG(0, "ixj_attach()\n");
43 /* Create new ixj device */
Dominik Brodowskifd238232006-03-05 10:45:09 +010044 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
45 p_dev->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
46 p_dev->io.IOAddrLines = 3;
47 p_dev->conf.IntType = INT_MEMORY_AND_IO;
Yoann Padioleaudd00cc42007-07-19 01:49:03 -070048 p_dev->priv = kzalloc(sizeof(struct ixj_info_t), GFP_KERNEL);
Dominik Brodowskifd238232006-03-05 10:45:09 +010049 if (!p_dev->priv) {
Dominik Brodowskif8cfa612005-11-14 21:25:51 +010050 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 }
Dominik Brodowskif8cfa612005-11-14 21:25:51 +010052
Dominik Brodowski15b99ac2006-03-31 17:26:06 +020053 return ixj_config(p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054}
55
Dominik Brodowskifba395e2006-03-31 17:21:06 +020056static void ixj_detach(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057{
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 DEBUG(0, "ixj_detach(0x%p)\n", link);
Dominik Brodowskib4635812005-11-14 21:25:35 +010059
Dominik Brodowskie2d40962006-03-02 00:09:29 +010060 ixj_cs_release(link);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +010061
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 kfree(link->priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063}
64
65#define CS_CHECK(fn, ret) \
66do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
67
Dominik Brodowskifba395e2006-03-31 17:21:06 +020068static void ixj_get_serial(struct pcmcia_device * link, IXJ * j)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069{
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 char *str;
Dominik Brodowskia9606fd2006-06-04 18:06:13 +020071 int i, place;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 DEBUG(0, "ixj_get_serial(0x%p)\n", link);
Dominik Brodowskia9606fd2006-06-04 18:06:13 +020073
74 str = link->prod_id[0];
75 if (!str)
76 goto cs_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 printk("%s", str);
Dominik Brodowskia9606fd2006-06-04 18:06:13 +020078 str = link->prod_id[1];
79 if (!str)
80 goto cs_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 printk(" %s", str);
Dominik Brodowskia9606fd2006-06-04 18:06:13 +020082 str = link->prod_id[2];
83 if (!str)
84 goto cs_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 place = 1;
86 for (i = strlen(str) - 1; i >= 0; i--) {
87 switch (str[i]) {
88 case '0':
89 case '1':
90 case '2':
91 case '3':
92 case '4':
93 case '5':
94 case '6':
95 case '7':
96 case '8':
97 case '9':
98 j->serial += (str[i] - 48) * place;
99 break;
100 case 'A':
101 case 'B':
102 case 'C':
103 case 'D':
104 case 'E':
105 case 'F':
106 j->serial += (str[i] - 55) * place;
107 break;
108 case 'a':
109 case 'b':
110 case 'c':
111 case 'd':
112 case 'e':
113 case 'f':
114 j->serial += (str[i] - 87) * place;
115 break;
116 }
117 place = place * 0x10;
118 }
Dominik Brodowskia9606fd2006-06-04 18:06:13 +0200119 str = link->prod_id[3];
120 if (!str)
121 goto cs_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 printk(" version %s\n", str);
123 cs_failed:
124 return;
125}
126
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200127static int ixj_config_check(struct pcmcia_device *p_dev,
128 cistpl_cftable_entry_t *cfg,
Dominik Brodowski8e2fc392008-08-02 15:30:31 +0200129 cistpl_cftable_entry_t *dflt,
Dominik Brodowskiad913c12008-08-02 16:12:00 +0200130 unsigned int vcc,
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200131 void *priv_data)
132{
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200133 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
134 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200135 p_dev->io.BasePort1 = io->win[0].base;
136 p_dev->io.NumPorts1 = io->win[0].len;
137 if (io->nwin == 2) {
138 p_dev->io.BasePort2 = io->win[1].base;
139 p_dev->io.NumPorts2 = io->win[1].len;
140 }
Dominik Brodowski8e2fc392008-08-02 15:30:31 +0200141 if (!pcmcia_request_io(p_dev, &p_dev->io))
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200142 return 0;
143 }
144 return -ENODEV;
145}
146
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200147static int ixj_config(struct pcmcia_device * link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148{
149 IXJ *j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 ixj_info_t *info;
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200151 cistpl_cftable_entry_t dflt = { 0 };
152
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 info = link->priv;
154 DEBUG(0, "ixj_config(0x%p)\n", link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200156 if (pcmcia_loop_config(link, ixj_config_check, &dflt))
157 goto cs_failed;
158
159 if (pcmcia_request_configuration(link, &link->conf))
160 goto cs_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
162 /*
163 * Register the card with the core.
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200164 */
165 j = ixj_pcmcia_probe(link->io.BasePort1, link->io.BasePort1 + 0x10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
167 info->ndev = 1;
168 info->node.major = PHONE_MAJOR;
Dominik Brodowskifd238232006-03-05 10:45:09 +0100169 link->dev_node = &info->node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 ixj_get_serial(link, j);
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200171 return 0;
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 cs_failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 ixj_cs_release(link);
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200175 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176}
177
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200178static void ixj_cs_release(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179{
180 ixj_info_t *info = link->priv;
181 DEBUG(0, "ixj_cs_release(0x%p)\n", link);
182 info->ndev = 0;
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200183 pcmcia_disable_device(link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184}
185
Dominik Brodowski07081272005-06-27 16:28:40 -0700186static struct pcmcia_device_id ixj_ids[] = {
187 PCMCIA_DEVICE_MANF_CARD(0x0257, 0x0600),
188 PCMCIA_DEVICE_NULL
189};
190MODULE_DEVICE_TABLE(pcmcia, ixj_ids);
191
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192static struct pcmcia_driver ixj_driver = {
193 .owner = THIS_MODULE,
194 .drv = {
195 .name = "ixj_cs",
196 },
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200197 .probe = ixj_probe,
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100198 .remove = ixj_detach,
Dominik Brodowski07081272005-06-27 16:28:40 -0700199 .id_table = ixj_ids,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200};
201
202static int __init ixj_pcmcia_init(void)
203{
204 return pcmcia_register_driver(&ixj_driver);
205}
206
207static void ixj_pcmcia_exit(void)
208{
209 pcmcia_unregister_driver(&ixj_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210}
211
212module_init(ixj_pcmcia_init);
213module_exit(ixj_pcmcia_exit);
214
215MODULE_LICENSE("GPL");