blob: 99cb2246ac728c24e9d9b39335577dbeb713a6c0 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
23typedef struct ixj_info_t {
24 int ndev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 struct ixj *port;
26} ixj_info_t;
27
Dominik Brodowskicc3b4862005-11-14 21:23:14 +010028static void ixj_detach(struct pcmcia_device *p_dev);
Dominik Brodowski15b99ac2006-03-31 17:26:06 +020029static int ixj_config(struct pcmcia_device * link);
Dominik Brodowskifba395e2006-03-31 17:21:06 +020030static void ixj_cs_release(struct pcmcia_device * link);
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Dominik Brodowski15b99ac2006-03-31 17:26:06 +020032static int ixj_probe(struct pcmcia_device *p_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070033{
Dominik Brodowski9b44de22009-10-24 15:55:39 +020034 dev_dbg(&p_dev->dev, "ixj_attach()\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 /* Create new ixj device */
Dominik Brodowskifd238232006-03-05 10:45:09 +010036 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
37 p_dev->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
38 p_dev->io.IOAddrLines = 3;
39 p_dev->conf.IntType = INT_MEMORY_AND_IO;
Yoann Padioleaudd00cc42007-07-19 01:49:03 -070040 p_dev->priv = kzalloc(sizeof(struct ixj_info_t), GFP_KERNEL);
Dominik Brodowskifd238232006-03-05 10:45:09 +010041 if (!p_dev->priv) {
Dominik Brodowskif8cfa612005-11-14 21:25:51 +010042 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 }
Dominik Brodowskif8cfa612005-11-14 21:25:51 +010044
Dominik Brodowski15b99ac2006-03-31 17:26:06 +020045 return ixj_config(p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046}
47
Dominik Brodowskifba395e2006-03-31 17:21:06 +020048static void ixj_detach(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049{
Dominik Brodowski9b44de22009-10-24 15:55:39 +020050 dev_dbg(&link->dev, "ixj_detach\n");
Dominik Brodowskib4635812005-11-14 21:25:35 +010051
Dominik Brodowskie2d40962006-03-02 00:09:29 +010052 ixj_cs_release(link);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +010053
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 kfree(link->priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055}
56
Dominik Brodowskifba395e2006-03-31 17:21:06 +020057static void ixj_get_serial(struct pcmcia_device * link, IXJ * j)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058{
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 char *str;
Dominik Brodowskia9606fd2006-06-04 18:06:13 +020060 int i, place;
Dominik Brodowski9b44de22009-10-24 15:55:39 +020061 dev_dbg(&link->dev, "ixj_get_serial\n");
Dominik Brodowskia9606fd2006-06-04 18:06:13 +020062
63 str = link->prod_id[0];
64 if (!str)
Dominik Brodowski9b44de22009-10-24 15:55:39 +020065 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 printk("%s", str);
Dominik Brodowskia9606fd2006-06-04 18:06:13 +020067 str = link->prod_id[1];
68 if (!str)
Dominik Brodowski9b44de22009-10-24 15:55:39 +020069 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 printk(" %s", str);
Dominik Brodowskia9606fd2006-06-04 18:06:13 +020071 str = link->prod_id[2];
72 if (!str)
Dominik Brodowski9b44de22009-10-24 15:55:39 +020073 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 place = 1;
75 for (i = strlen(str) - 1; i >= 0; i--) {
76 switch (str[i]) {
77 case '0':
78 case '1':
79 case '2':
80 case '3':
81 case '4':
82 case '5':
83 case '6':
84 case '7':
85 case '8':
86 case '9':
87 j->serial += (str[i] - 48) * place;
88 break;
89 case 'A':
90 case 'B':
91 case 'C':
92 case 'D':
93 case 'E':
94 case 'F':
95 j->serial += (str[i] - 55) * place;
96 break;
97 case 'a':
98 case 'b':
99 case 'c':
100 case 'd':
101 case 'e':
102 case 'f':
103 j->serial += (str[i] - 87) * place;
104 break;
105 }
106 place = place * 0x10;
107 }
Dominik Brodowskia9606fd2006-06-04 18:06:13 +0200108 str = link->prod_id[3];
109 if (!str)
Dominik Brodowski9b44de22009-10-24 15:55:39 +0200110 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 printk(" version %s\n", str);
Dominik Brodowski9b44de22009-10-24 15:55:39 +0200112failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 return;
114}
115
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200116static int ixj_config_check(struct pcmcia_device *p_dev,
117 cistpl_cftable_entry_t *cfg,
Dominik Brodowski8e2fc392008-08-02 15:30:31 +0200118 cistpl_cftable_entry_t *dflt,
Dominik Brodowskiad913c12008-08-02 16:12:00 +0200119 unsigned int vcc,
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200120 void *priv_data)
121{
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200122 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
123 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200124 p_dev->io.BasePort1 = io->win[0].base;
125 p_dev->io.NumPorts1 = io->win[0].len;
126 if (io->nwin == 2) {
127 p_dev->io.BasePort2 = io->win[1].base;
128 p_dev->io.NumPorts2 = io->win[1].len;
129 }
Dominik Brodowski8e2fc392008-08-02 15:30:31 +0200130 if (!pcmcia_request_io(p_dev, &p_dev->io))
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200131 return 0;
132 }
133 return -ENODEV;
134}
135
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200136static int ixj_config(struct pcmcia_device * link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137{
138 IXJ *j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 ixj_info_t *info;
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200140 cistpl_cftable_entry_t dflt = { 0 };
141
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 info = link->priv;
Dominik Brodowski9b44de22009-10-24 15:55:39 +0200143 dev_dbg(&link->dev, "ixj_config\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200145 if (pcmcia_loop_config(link, ixj_config_check, &dflt))
Dominik Brodowski9b44de22009-10-24 15:55:39 +0200146 goto failed;
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200147
148 if (pcmcia_request_configuration(link, &link->conf))
Dominik Brodowski9b44de22009-10-24 15:55:39 +0200149 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
151 /*
152 * Register the card with the core.
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200153 */
154 j = ixj_pcmcia_probe(link->io.BasePort1, link->io.BasePort1 + 0x10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
156 info->ndev = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 ixj_get_serial(link, j);
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200158 return 0;
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200159
Dominik Brodowski9b44de22009-10-24 15:55:39 +0200160failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 ixj_cs_release(link);
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200162 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163}
164
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200165static void ixj_cs_release(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166{
167 ixj_info_t *info = link->priv;
Dominik Brodowski9b44de22009-10-24 15:55:39 +0200168 dev_dbg(&link->dev, "ixj_cs_release\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 info->ndev = 0;
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200170 pcmcia_disable_device(link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171}
172
Dominik Brodowski07081272005-06-27 16:28:40 -0700173static struct pcmcia_device_id ixj_ids[] = {
174 PCMCIA_DEVICE_MANF_CARD(0x0257, 0x0600),
175 PCMCIA_DEVICE_NULL
176};
177MODULE_DEVICE_TABLE(pcmcia, ixj_ids);
178
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179static struct pcmcia_driver ixj_driver = {
180 .owner = THIS_MODULE,
181 .drv = {
182 .name = "ixj_cs",
183 },
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200184 .probe = ixj_probe,
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100185 .remove = ixj_detach,
Dominik Brodowski07081272005-06-27 16:28:40 -0700186 .id_table = ixj_ids,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187};
188
189static int __init ixj_pcmcia_init(void)
190{
191 return pcmcia_register_driver(&ixj_driver);
192}
193
194static void ixj_pcmcia_exit(void)
195{
196 pcmcia_unregister_driver(&ixj_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197}
198
199module_init(ixj_pcmcia_init);
200module_exit(ixj_pcmcia_exit);
201
202MODULE_LICENSE("GPL");