pcmcia: do not use io_req_t when calling pcmcia_request_io()
[deliverable/linux.git] / drivers / net / wireless / orinoco / spectrum_cs.c
CommitLineData
3a48c4c2
PR
1/*
2 * Driver for 802.11b cards using RAM-loadable Symbol firmware, such as
4ebe2eb0 3 * Symbol Wireless Networker LA4137, CompactFlash cards by Socket
3a48c4c2
PR
4 * Communications and Intel PRO/Wireless 2011B.
5 *
6 * The driver implements Symbol firmware download. The rest is handled
47445cb9 7 * in hermes.c and main.c.
3a48c4c2
PR
8 *
9 * Utilities for downloading the Symbol firmware are available at
10 * http://sourceforge.net/projects/orinoco/
11 *
12 * Copyright (C) 2002-2005 Pavel Roskin <proski@gnu.org>
13 * Portions based on orinoco_cs.c:
14 * Copyright (C) David Gibson, Linuxcare Australia
15 * Portions based on Spectrum24tDnld.c from original spectrum24 driver:
16 * Copyright (C) Symbol Technologies.
17 *
47445cb9 18 * See copyright notice in file main.c.
3a48c4c2
PR
19 */
20
21#define DRIVER_NAME "spectrum_cs"
22#define PFX DRIVER_NAME ": "
23
3a48c4c2
PR
24#include <linux/module.h>
25#include <linux/kernel.h>
26#include <linux/init.h>
ef846bf0 27#include <linux/delay.h>
3a48c4c2
PR
28#include <pcmcia/cs.h>
29#include <pcmcia/cistpl.h>
30#include <pcmcia/cisreg.h>
31#include <pcmcia/ds.h>
32
3a48c4c2 33#include "orinoco.h"
3a48c4c2
PR
34
35/********************************************************************/
36/* Module stuff */
37/********************************************************************/
38
39MODULE_AUTHOR("Pavel Roskin <proski@gnu.org>");
40MODULE_DESCRIPTION("Driver for Symbol Spectrum24 Trilogy cards with firmware downloader");
41MODULE_LICENSE("Dual MPL/GPL");
42
43/* Module parameters */
44
45/* Some D-Link cards have buggy CIS. They do work at 5v properly, but
46 * don't have any CIS entry for it. This workaround it... */
47static int ignore_cis_vcc; /* = 0 */
48module_param(ignore_cis_vcc, int, 0);
49MODULE_PARM_DESC(ignore_cis_vcc, "Allow voltage mismatch between card and socket");
50
3a48c4c2
PR
51/********************************************************************/
52/* Data structures */
53/********************************************************************/
54
55/* PCMCIA specific device information (goes in the card field of
56 * struct orinoco_private */
57struct orinoco_pccard {
fd238232 58 struct pcmcia_device *p_dev;
3a48c4c2
PR
59};
60
3a48c4c2
PR
61/********************************************************************/
62/* Function prototypes */
63/********************************************************************/
64
15b99ac1 65static int spectrum_cs_config(struct pcmcia_device *link);
fba395ee 66static void spectrum_cs_release(struct pcmcia_device *link);
3a48c4c2 67
3a48c4c2
PR
68/* Constants for the CISREG_CCSR register */
69#define HCR_RUN 0x07 /* run firmware after reset */
70#define HCR_IDLE 0x0E /* don't run firmware after reset */
71#define HCR_MEM16 0x10 /* memory width bit, should be preserved */
72
3a48c4c2 73
3a48c4c2
PR
74/*
75 * Reset the card using configuration registers COR and CCSR.
76 * If IDLE is 1, stop the firmware, so that it can be safely rewritten.
77 */
78static int
fba395ee 79spectrum_reset(struct pcmcia_device *link, int idle)
3a48c4c2 80{
2caff147 81 int ret;
1d5cc192
DB
82 u8 save_cor;
83 u8 ccsr;
3a48c4c2
PR
84
85 /* Doing it if hardware is gone is guaranteed crash */
c5ab964d 86 if (!pcmcia_dev_present(link))
3a48c4c2
PR
87 return -ENODEV;
88
89 /* Save original COR value */
1d5cc192 90 ret = pcmcia_read_config_byte(link, CISREG_COR, &save_cor);
2caff147
DB
91 if (ret)
92 goto failed;
3a48c4c2
PR
93
94 /* Soft-Reset card */
1d5cc192
DB
95 ret = pcmcia_write_config_byte(link, CISREG_COR,
96 (save_cor | COR_SOFT_RESET));
2caff147
DB
97 if (ret)
98 goto failed;
3a48c4c2
PR
99 udelay(1000);
100
101 /* Read CCSR */
1d5cc192 102 ret = pcmcia_read_config_byte(link, CISREG_CCSR, &ccsr);
2caff147
DB
103 if (ret)
104 goto failed;
3a48c4c2
PR
105
106 /*
107 * Start or stop the firmware. Memory width bit should be
108 * preserved from the value we've just read.
109 */
1d5cc192
DB
110 ccsr = (idle ? HCR_IDLE : HCR_RUN) | (ccsr & HCR_MEM16);
111 ret = pcmcia_write_config_byte(link, CISREG_CCSR, ccsr);
2caff147
DB
112 if (ret)
113 goto failed;
3a48c4c2
PR
114 udelay(1000);
115
116 /* Restore original COR configuration index */
1d5cc192
DB
117 ret = pcmcia_write_config_byte(link, CISREG_COR,
118 (save_cor & ~COR_SOFT_RESET));
2caff147
DB
119 if (ret)
120 goto failed;
3a48c4c2
PR
121 udelay(1000);
122 return 0;
123
2caff147 124failed:
3a48c4c2
PR
125 return -ENODEV;
126}
127
3994d502
DK
128/********************************************************************/
129/* Device methods */
130/********************************************************************/
3a48c4c2 131
3a48c4c2 132static int
3994d502 133spectrum_cs_hard_reset(struct orinoco_private *priv)
3a48c4c2 134{
3994d502
DK
135 struct orinoco_pccard *card = priv->card;
136 struct pcmcia_device *link = card->p_dev;
3a48c4c2 137
3994d502
DK
138 /* Soft reset using COR and HCR */
139 spectrum_reset(link, 0);
3a48c4c2
PR
140
141 return 0;
142}
143
3a48c4c2 144static int
3994d502 145spectrum_cs_stop_firmware(struct orinoco_private *priv, int idle)
3a48c4c2
PR
146{
147 struct orinoco_pccard *card = priv->card;
fba395ee 148 struct pcmcia_device *link = card->p_dev;
3a48c4c2 149
3994d502 150 return spectrum_reset(link, idle);
3a48c4c2
PR
151}
152
153/********************************************************************/
154/* PCMCIA stuff */
155/********************************************************************/
156
157/*
158 * This creates an "instance" of the driver, allocating local data
159 * structures for one device. The device is registered with Card
160 * Services.
d14c7c1d 161 *
3a48c4c2
PR
162 * The dev_link structure is initialized, but we don't actually
163 * configure the card at this point -- we wait until we receive a card
164 * insertion event. */
f8cfa618 165static int
15b99ac1 166spectrum_cs_probe(struct pcmcia_device *link)
3a48c4c2 167{
3a48c4c2
PR
168 struct orinoco_private *priv;
169 struct orinoco_pccard *card;
3a48c4c2 170
dd2e5a15 171 priv = alloc_orinocodev(sizeof(*card), &link->dev,
a2608362
DK
172 spectrum_cs_hard_reset,
173 spectrum_cs_stop_firmware);
174 if (!priv)
f8cfa618 175 return -ENOMEM;
3a48c4c2
PR
176 card = priv->card;
177
178 /* Link both structures together */
fba395ee 179 card->p_dev = link;
a2608362 180 link->priv = priv;
3a48c4c2 181
3a48c4c2
PR
182 /* General socket configuration defaults can go here. In this
183 * client, we assume very little, and rely on the CIS for
184 * almost everything. In most clients, many details (i.e.,
185 * number, sizes, and attributes of IO windows) are fixed by
186 * the nature of the device, and can be hard-wired here. */
187 link->conf.Attributes = 0;
188 link->conf.IntType = INT_MEMORY_AND_IO;
189
15b99ac1 190 return spectrum_cs_config(link);
3a48c4c2
PR
191} /* spectrum_cs_attach */
192
193/*
194 * This deletes a driver "instance". The device is de-registered with
195 * Card Services. If it has been released, all local data structures
196 * are freed. Otherwise, the structures will be freed when the device
197 * is released.
198 */
fba395ee 199static void spectrum_cs_detach(struct pcmcia_device *link)
3a48c4c2 200{
a2608362 201 struct orinoco_private *priv = link->priv;
3a48c4c2 202
c7c2fa07 203 orinoco_if_del(priv);
e4f4f98e 204
e2d40963 205 spectrum_cs_release(link);
3a48c4c2 206
a2608362 207 free_orinocodev(priv);
3a48c4c2
PR
208} /* spectrum_cs_detach */
209
210/*
211 * spectrum_cs_config() is scheduled to run after a CARD_INSERTION
212 * event is received, to configure the PCMCIA socket, and to make the
213 * device available to the system.
214 */
215
b54bf94b
DB
216static int spectrum_cs_config_check(struct pcmcia_device *p_dev,
217 cistpl_cftable_entry_t *cfg,
8e2fc39d 218 cistpl_cftable_entry_t *dflt,
ad913c11 219 unsigned int vcc,
b54bf94b
DB
220 void *priv_data)
221{
b54bf94b
DB
222 if (cfg->index == 0)
223 goto next_entry;
b54bf94b
DB
224
225 /* Use power settings for Vcc and Vpp if present */
226 /* Note that the CIS values need to be rescaled */
227 if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
ad913c11 228 if (vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000) {
62d714e5
DK
229 DEBUG(2, "%s: Vcc mismatch (vcc = %d, CIS = %d)\n",
230 __func__, vcc,
231 cfg->vcc.param[CISTPL_POWER_VNOM] / 10000);
b54bf94b
DB
232 if (!ignore_cis_vcc)
233 goto next_entry;
234 }
8e2fc39d 235 } else if (dflt->vcc.present & (1 << CISTPL_POWER_VNOM)) {
ad913c11 236 if (vcc != dflt->vcc.param[CISTPL_POWER_VNOM] / 10000) {
62d714e5
DK
237 DEBUG(2, "%s: Vcc mismatch (vcc = %d, CIS = %d)\n",
238 __func__, vcc,
239 dflt->vcc.param[CISTPL_POWER_VNOM] / 10000);
b54bf94b
DB
240 if (!ignore_cis_vcc)
241 goto next_entry;
242 }
243 }
244
245 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
246 p_dev->conf.Vpp =
247 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
8e2fc39d 248 else if (dflt->vpp1.present & (1 << CISTPL_POWER_VNOM))
b54bf94b 249 p_dev->conf.Vpp =
8e2fc39d 250 dflt->vpp1.param[CISTPL_POWER_VNOM] / 10000;
b54bf94b
DB
251
252 /* Do we need to allocate an interrupt? */
253 p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
254
255 /* IO window settings */
90abdc3b 256 p_dev->resource[0]->end = p_dev->resource[1]->end = 0;
8e2fc39d
DB
257 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
258 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
90abdc3b
DB
259 p_dev->io_lines = io->flags & CISTPL_IO_LINES_MASK;
260 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
261 p_dev->resource[0]->flags |=
262 pcmcia_io_cfg_data_width(io->flags);
263 p_dev->resource[0]->start = io->win[0].base;
264 p_dev->resource[0]->end = io->win[0].len;
b54bf94b 265 if (io->nwin > 1) {
90abdc3b
DB
266 p_dev->resource[1]->flags = p_dev->resource[0]->flags;
267 p_dev->resource[1]->start = io->win[1].base;
268 p_dev->resource[1]->end = io->win[1].len;
b54bf94b
DB
269 }
270
271 /* This reserves IO space but doesn't actually enable it */
90abdc3b 272 if (pcmcia_request_io(p_dev) != 0)
b54bf94b
DB
273 goto next_entry;
274 }
275 return 0;
276
277next_entry:
278 pcmcia_disable_device(p_dev);
279 return -ENODEV;
280};
281
15b99ac1 282static int
fba395ee 283spectrum_cs_config(struct pcmcia_device *link)
3a48c4c2 284{
a2608362 285 struct orinoco_private *priv = link->priv;
3a48c4c2 286 hermes_t *hw = &priv->hw;
2caff147 287 int ret;
3a48c4c2
PR
288 void __iomem *mem;
289
3a48c4c2
PR
290 /*
291 * In this loop, we scan the CIS for configuration table
292 * entries, each of which describes a valid card
293 * configuration, including voltage, IO window, memory window,
294 * and interrupt settings.
295 *
296 * We make no assumptions about the card to be configured: we
297 * use just the information available in the CIS. In an ideal
298 * world, this would work for any PCMCIA card, but it requires
299 * a complete and accurate CIS. In practice, a driver usually
300 * "knows" most of these things without consulting the CIS,
301 * and most client drivers will only use the CIS to fill in
302 * implementation-defined details.
303 */
2caff147
DB
304 ret = pcmcia_loop_config(link, spectrum_cs_config_check, NULL);
305 if (ret) {
b54bf94b 306 if (!ignore_cis_vcc)
3a48c4c2
PR
307 printk(KERN_ERR PFX "GetNextTuple(): No matching "
308 "CIS configuration. Maybe you need the "
309 "ignore_cis_vcc=1 parameter.\n");
b54bf94b 310 goto failed;
3a48c4c2
PR
311 }
312
eb14120f 313 ret = pcmcia_request_irq(link, orinoco_interrupt);
2caff147
DB
314 if (ret)
315 goto failed;
3a48c4c2
PR
316
317 /* We initialize the hermes structure before completing PCMCIA
318 * configuration just in case the interrupt handler gets
319 * called. */
9a017a91
DB
320 mem = ioport_map(link->resource[0]->start,
321 resource_size(link->resource[0]));
3a48c4c2 322 if (!mem)
2caff147 323 goto failed;
3a48c4c2
PR
324
325 hermes_struct_init(hw, mem, HERMES_16BIT_REGSPACING);
07cefe7a 326 hw->eeprom_pda = true;
3a48c4c2
PR
327
328 /*
329 * This actually configures the PCMCIA socket -- setting up
330 * the I/O windows and the interrupt mapping, and putting the
331 * card and host interface into "Memory and IO" mode.
332 */
2caff147
DB
333 ret = pcmcia_request_configuration(link, &link->conf);
334 if (ret)
335 goto failed;
3a48c4c2 336
3994d502 337 /* Reset card */
d14c7c1d 338 if (spectrum_cs_hard_reset(priv) != 0)
3a48c4c2 339 goto failed;
3a48c4c2 340
8e638267
DK
341 /* Initialise the main driver */
342 if (orinoco_init(priv) != 0) {
343 printk(KERN_ERR PFX "orinoco_init() failed\n");
344 goto failed;
345 }
346
5381956b 347 /* Register an interface with the stack */
9a017a91 348 if (orinoco_if_add(priv, link->resource[0]->start,
f8965467 349 link->irq, NULL) != 0) {
5381956b 350 printk(KERN_ERR PFX "orinoco_if_add() failed\n");
3a48c4c2
PR
351 goto failed;
352 }
353
15b99ac1 354 return 0;
3a48c4c2 355
3a48c4c2
PR
356 failed:
357 spectrum_cs_release(link);
15b99ac1 358 return -ENODEV;
3a48c4c2
PR
359} /* spectrum_cs_config */
360
361/*
362 * After a card is removed, spectrum_cs_release() will unregister the
363 * device, and release the PCMCIA configuration. If the device is
364 * still open, this will be postponed until it is closed.
365 */
366static void
fba395ee 367spectrum_cs_release(struct pcmcia_device *link)
3a48c4c2 368{
a2608362 369 struct orinoco_private *priv = link->priv;
3a48c4c2
PR
370 unsigned long flags;
371
372 /* We're committed to taking the device away now, so mark the
373 * hardware as unavailable */
bcad6e80 374 priv->hw.ops->lock_irqsave(&priv->lock, &flags);
3a48c4c2 375 priv->hw_unavailable++;
bcad6e80 376 priv->hw.ops->unlock_irqrestore(&priv->lock, &flags);
3a48c4c2 377
fba395ee 378 pcmcia_disable_device(link);
3a48c4c2
PR
379 if (priv->hw.iobase)
380 ioport_unmap(priv->hw.iobase);
381} /* spectrum_cs_release */
382
98e4c28b
DB
383
384static int
fba395ee 385spectrum_cs_suspend(struct pcmcia_device *link)
98e4c28b 386{
a2608362 387 struct orinoco_private *priv = link->priv;
98e4c28b
DB
388 int err = 0;
389
98e4c28b 390 /* Mark the device as stopped, to block IO until later */
6415f7df 391 orinoco_down(priv);
98e4c28b 392
6cbaa330 393 return err;
98e4c28b
DB
394}
395
396static int
fba395ee 397spectrum_cs_resume(struct pcmcia_device *link)
98e4c28b 398{
a2608362 399 struct orinoco_private *priv = link->priv;
6415f7df 400 int err = orinoco_up(priv);
ac7cafd7 401
6415f7df 402 return err;
98e4c28b
DB
403}
404
3a48c4c2
PR
405
406/********************************************************************/
407/* Module initialization */
408/********************************************************************/
409
410/* Can't be declared "const" or the whole __initdata section will
411 * become const */
412static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
413 " (Pavel Roskin <proski@gnu.org>,"
414 " David Gibson <hermes@gibson.dropbear.id.au>, et al)";
415
416static struct pcmcia_device_id spectrum_cs_ids[] = {
4ebe2eb0 417 PCMCIA_DEVICE_MANF_CARD(0x026c, 0x0001), /* Symbol Spectrum24 LA4137 */
3a48c4c2 418 PCMCIA_DEVICE_MANF_CARD(0x0104, 0x0001), /* Socket Communications CF */
9c8a11d7 419 PCMCIA_DEVICE_PROD_ID12("Intel", "PRO/Wireless LAN PC Card", 0x816cc815, 0x6fbf459a), /* 2011B, not 2011 */
3a48c4c2
PR
420 PCMCIA_DEVICE_NULL,
421};
422MODULE_DEVICE_TABLE(pcmcia, spectrum_cs_ids);
423
424static struct pcmcia_driver orinoco_driver = {
425 .owner = THIS_MODULE,
426 .drv = {
427 .name = DRIVER_NAME,
428 },
15b99ac1 429 .probe = spectrum_cs_probe,
cc3b4866 430 .remove = spectrum_cs_detach,
98e4c28b
DB
431 .suspend = spectrum_cs_suspend,
432 .resume = spectrum_cs_resume,
3a48c4c2
PR
433 .id_table = spectrum_cs_ids,
434};
435
436static int __init
437init_spectrum_cs(void)
438{
439 printk(KERN_DEBUG "%s\n", version);
440
441 return pcmcia_register_driver(&orinoco_driver);
442}
443
444static void __exit
445exit_spectrum_cs(void)
446{
447 pcmcia_unregister_driver(&orinoco_driver);
3a48c4c2
PR
448}
449
450module_init(init_spectrum_cs);
451module_exit(exit_spectrum_cs);
This page took 0.992541 seconds and 5 git commands to generate.