]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/telephony/ixj_pcmcia.c
drm/radeon/r100/r200: fix calculation of compressed cube maps
[net-next-2.6.git] / drivers / telephony / ixj_pcmcia.c
CommitLineData
1da177e4
LT
1#include "ixj-ver.h"
2
3#include <linux/module.h>
4
5#include <linux/init.h>
1da177e4
LT
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
1da177e4
LT
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
1da177e4
LT
22
23typedef struct ixj_info_t {
24 int ndev;
1da177e4
LT
25 struct ixj *port;
26} ixj_info_t;
27
cc3b4866 28static void ixj_detach(struct pcmcia_device *p_dev);
15b99ac1 29static int ixj_config(struct pcmcia_device * link);
fba395ee 30static void ixj_cs_release(struct pcmcia_device * link);
1da177e4 31
15b99ac1 32static int ixj_probe(struct pcmcia_device *p_dev)
1da177e4 33{
9b44de20 34 dev_dbg(&p_dev->dev, "ixj_attach()\n");
1da177e4 35 /* Create new ixj device */
fd238232
DB
36 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;
dd00cc48 40 p_dev->priv = kzalloc(sizeof(struct ixj_info_t), GFP_KERNEL);
fd238232 41 if (!p_dev->priv) {
f8cfa618 42 return -ENOMEM;
1da177e4 43 }
f8cfa618 44
15b99ac1 45 return ixj_config(p_dev);
1da177e4
LT
46}
47
fba395ee 48static void ixj_detach(struct pcmcia_device *link)
1da177e4 49{
9b44de20 50 dev_dbg(&link->dev, "ixj_detach\n");
b4635811 51
e2d40963 52 ixj_cs_release(link);
cc3b4866 53
1da177e4 54 kfree(link->priv);
1da177e4
LT
55}
56
fba395ee 57static void ixj_get_serial(struct pcmcia_device * link, IXJ * j)
1da177e4 58{
1da177e4 59 char *str;
a9606fd3 60 int i, place;
9b44de20 61 dev_dbg(&link->dev, "ixj_get_serial\n");
a9606fd3
DB
62
63 str = link->prod_id[0];
64 if (!str)
9b44de20 65 goto failed;
1da177e4 66 printk("%s", str);
a9606fd3
DB
67 str = link->prod_id[1];
68 if (!str)
9b44de20 69 goto failed;
1da177e4 70 printk(" %s", str);
a9606fd3
DB
71 str = link->prod_id[2];
72 if (!str)
9b44de20 73 goto failed;
1da177e4
LT
74 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 }
a9606fd3
DB
108 str = link->prod_id[3];
109 if (!str)
9b44de20 110 goto failed;
1da177e4 111 printk(" version %s\n", str);
9b44de20 112failed:
1da177e4
LT
113 return;
114}
115
84e2d340
DB
116static int ixj_config_check(struct pcmcia_device *p_dev,
117 cistpl_cftable_entry_t *cfg,
8e2fc39d 118 cistpl_cftable_entry_t *dflt,
ad913c11 119 unsigned int vcc,
84e2d340
DB
120 void *priv_data)
121{
84e2d340
DB
122 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
123 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
84e2d340
DB
124 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 }
8e2fc39d 130 if (!pcmcia_request_io(p_dev, &p_dev->io))
84e2d340
DB
131 return 0;
132 }
133 return -ENODEV;
134}
135
15b99ac1 136static int ixj_config(struct pcmcia_device * link)
1da177e4
LT
137{
138 IXJ *j;
1da177e4 139 ixj_info_t *info;
84e2d340
DB
140 cistpl_cftable_entry_t dflt = { 0 };
141
1da177e4 142 info = link->priv;
9b44de20 143 dev_dbg(&link->dev, "ixj_config\n");
1da177e4 144
84e2d340 145 if (pcmcia_loop_config(link, ixj_config_check, &dflt))
9b44de20 146 goto failed;
84e2d340
DB
147
148 if (pcmcia_request_configuration(link, &link->conf))
9b44de20 149 goto failed;
1da177e4
LT
150
151 /*
152 * Register the card with the core.
84e2d340
DB
153 */
154 j = ixj_pcmcia_probe(link->io.BasePort1, link->io.BasePort1 + 0x10);
1da177e4
LT
155
156 info->ndev = 1;
1da177e4 157 ixj_get_serial(link, j);
15b99ac1 158 return 0;
84e2d340 159
9b44de20 160failed:
1da177e4 161 ixj_cs_release(link);
15b99ac1 162 return -ENODEV;
1da177e4
LT
163}
164
fba395ee 165static void ixj_cs_release(struct pcmcia_device *link)
1da177e4
LT
166{
167 ixj_info_t *info = link->priv;
9b44de20 168 dev_dbg(&link->dev, "ixj_cs_release\n");
1da177e4 169 info->ndev = 0;
fba395ee 170 pcmcia_disable_device(link);
1da177e4
LT
171}
172
07081273
DB
173static 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
1da177e4
LT
179static struct pcmcia_driver ixj_driver = {
180 .owner = THIS_MODULE,
181 .drv = {
182 .name = "ixj_cs",
183 },
15b99ac1 184 .probe = ixj_probe,
cc3b4866 185 .remove = ixj_detach,
07081273 186 .id_table = ixj_ids,
1da177e4
LT
187};
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);
1da177e4
LT
197}
198
199module_init(ixj_pcmcia_init);
200module_exit(ixj_pcmcia_exit);
201
202MODULE_LICENSE("GPL");