3
Driver for the Marvell 8385 based compact flash WLAN cards.
5
(C) 2007 by Holger Schurig <hs4233@mail.mn-solutions.de>
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with this program; see the file COPYING. If not, write to
19
the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
20
Boston, MA 02110-1301, USA.
24
#include <linux/module.h>
25
#include <linux/slab.h>
26
#include <linux/delay.h>
27
#include <linux/moduleparam.h>
28
#include <linux/firmware.h>
29
#include <linux/netdevice.h>
31
#include <pcmcia/cistpl.h>
32
#include <pcmcia/ds.h>
36
#define DRV_NAME "libertas_cs"
43
/********************************************************************/
45
/********************************************************************/
47
MODULE_AUTHOR("Holger Schurig <hs4233@mail.mn-solutions.de>");
48
MODULE_DESCRIPTION("Driver for Marvell 83xx compact flash WLAN cards");
49
MODULE_LICENSE("GPL");
53
/********************************************************************/
55
/********************************************************************/
58
struct pcmcia_device *p_dev;
59
struct lbs_private *priv;
73
static const struct lbs_fw_table fw_table[] = {
74
{ MODEL_8305, "libertas/cf8305.bin", NULL },
75
{ MODEL_8305, "libertas_cs_helper.fw", NULL },
76
{ MODEL_8381, "libertas/cf8381_helper.bin", "libertas/cf8381.bin" },
77
{ MODEL_8381, "libertas_cs_helper.fw", "libertas_cs.fw" },
78
{ MODEL_8385, "libertas/cf8385_helper.bin", "libertas/cf8385.bin" },
79
{ MODEL_8385, "libertas_cs_helper.fw", "libertas_cs.fw" },
82
MODULE_FIRMWARE("libertas/cf8305.bin");
83
MODULE_FIRMWARE("libertas/cf8381_helper.bin");
84
MODULE_FIRMWARE("libertas/cf8381.bin");
85
MODULE_FIRMWARE("libertas/cf8385_helper.bin");
86
MODULE_FIRMWARE("libertas/cf8385.bin");
87
MODULE_FIRMWARE("libertas_cs_helper.fw");
88
MODULE_FIRMWARE("libertas_cs.fw");
91
/********************************************************************/
93
/********************************************************************/
95
/* This define enables wrapper functions which allow you
96
to dump all register accesses. You normally won't this,
97
except for development */
98
/* #define DEBUG_IO */
101
static int debug_output = 0;
103
/* This way the compiler optimizes the printk's away */
104
#define debug_output 0
107
static inline unsigned int if_cs_read8(struct if_cs_card *card, uint reg)
109
unsigned int val = ioread8(card->iobase + reg);
111
printk(KERN_INFO "inb %08x<%02x\n", reg, val);
114
static inline unsigned int if_cs_read16(struct if_cs_card *card, uint reg)
116
unsigned int val = ioread16(card->iobase + reg);
118
printk(KERN_INFO "inw %08x<%04x\n", reg, val);
121
static inline void if_cs_read16_rep(
122
struct if_cs_card *card,
128
printk(KERN_INFO "insw %08x<(0x%lx words)\n",
130
ioread16_rep(card->iobase + reg, buf, count);
133
static inline void if_cs_write8(struct if_cs_card *card, uint reg, u8 val)
136
printk(KERN_INFO "outb %08x>%02x\n", reg, val);
137
iowrite8(val, card->iobase + reg);
140
static inline void if_cs_write16(struct if_cs_card *card, uint reg, u16 val)
143
printk(KERN_INFO "outw %08x>%04x\n", reg, val);
144
iowrite16(val, card->iobase + reg);
147
static inline void if_cs_write16_rep(
148
struct if_cs_card *card,
154
printk(KERN_INFO "outsw %08x>(0x%lx words)\n",
156
iowrite16_rep(card->iobase + reg, buf, count);
161
* I know that polling/delaying is frowned upon. However, this procedure
162
* with polling is needed while downloading the firmware. At this stage,
163
* the hardware does unfortunately not create any interrupts.
165
* Fortunately, this function is never used once the firmware is in
168
* As a reference, see the "Firmware Specification v5.1", page 18
169
* and 19. I did not follow their suggested timing to the word,
170
* but this works nice & fast anyway.
172
static int if_cs_poll_while_fw_download(struct if_cs_card *card, uint addr, u8 reg)
176
for (i = 0; i < 100000; i++) {
177
u8 val = if_cs_read8(card, addr);
188
* First the bitmasks for the host/card interrupt/status registers:
190
#define IF_CS_BIT_TX 0x0001
191
#define IF_CS_BIT_RX 0x0002
192
#define IF_CS_BIT_COMMAND 0x0004
193
#define IF_CS_BIT_RESP 0x0008
194
#define IF_CS_BIT_EVENT 0x0010
195
#define IF_CS_BIT_MASK 0x001f
200
* It's not really clear to me what the host status register is for. It
201
* needs to be set almost in union with "host int cause". The following
202
* bits from above are used:
204
* IF_CS_BIT_TX driver downloaded a data packet
205
* IF_CS_BIT_RX driver got a data packet
206
* IF_CS_BIT_COMMAND driver downloaded a command
207
* IF_CS_BIT_RESP not used (has some meaning with powerdown)
208
* IF_CS_BIT_EVENT driver read a host event
210
#define IF_CS_HOST_STATUS 0x00000000
213
* With the host int cause register can the host (that is, Linux) cause
214
* an interrupt in the firmware, to tell the firmware about those events:
216
* IF_CS_BIT_TX a data packet has been downloaded
217
* IF_CS_BIT_RX a received data packet has retrieved
218
* IF_CS_BIT_COMMAND a firmware block or a command has been downloaded
219
* IF_CS_BIT_RESP not used (has some meaning with powerdown)
220
* IF_CS_BIT_EVENT a host event (link lost etc) has been retrieved
222
#define IF_CS_HOST_INT_CAUSE 0x00000002
225
* The host int mask register is used to enable/disable interrupt. However,
226
* I have the suspicion that disabled interrupts are lost.
228
#define IF_CS_HOST_INT_MASK 0x00000004
231
* Used to send or receive data packets:
233
#define IF_CS_WRITE 0x00000016
234
#define IF_CS_WRITE_LEN 0x00000014
235
#define IF_CS_READ 0x00000010
236
#define IF_CS_READ_LEN 0x00000024
239
* Used to send commands (and to send firmware block) and to
240
* receive command responses:
242
#define IF_CS_CMD 0x0000001A
243
#define IF_CS_CMD_LEN 0x00000018
244
#define IF_CS_RESP 0x00000012
245
#define IF_CS_RESP_LEN 0x00000030
248
* The card status registers shows what the card/firmware actually
251
* IF_CS_BIT_TX you may send a data packet
252
* IF_CS_BIT_RX you may retrieve a data packet
253
* IF_CS_BIT_COMMAND you may send a command
254
* IF_CS_BIT_RESP you may retrieve a command response
255
* IF_CS_BIT_EVENT the card has a event for use (link lost, snr low etc)
257
* When reading this register several times, you will get back the same
258
* results --- with one exception: the IF_CS_BIT_EVENT clear itself
261
* Not that we don't rely on BIT_RX,_BIT_RESP or BIT_EVENT because
262
* we handle this via the card int cause register.
264
#define IF_CS_CARD_STATUS 0x00000020
265
#define IF_CS_CARD_STATUS_MASK 0x7f00
268
* The card int cause register is used by the card/firmware to notify us
269
* about the following events:
271
* IF_CS_BIT_TX a data packet has successfully been sentx
272
* IF_CS_BIT_RX a data packet has been received and can be retrieved
273
* IF_CS_BIT_COMMAND not used
274
* IF_CS_BIT_RESP the firmware has a command response for us
275
* IF_CS_BIT_EVENT the card has a event for use (link lost, snr low etc)
277
#define IF_CS_CARD_INT_CAUSE 0x00000022
280
* This is used to for handshaking with the card's bootloader/helper image
281
* to synchronize downloading of firmware blocks.
283
#define IF_CS_SQ_READ_LOW 0x00000028
284
#define IF_CS_SQ_HELPER_OK 0x10
287
* The scratch register tells us ...
289
* IF_CS_SCRATCH_BOOT_OK the bootloader runs
290
* IF_CS_SCRATCH_HELPER_OK the helper firmware already runs
292
#define IF_CS_SCRATCH 0x0000003F
293
#define IF_CS_SCRATCH_BOOT_OK 0x00
294
#define IF_CS_SCRATCH_HELPER_OK 0x5a
297
* Used to detect ancient chips:
299
#define IF_CS_PRODUCT_ID 0x0000001C
300
#define IF_CS_CF8385_B1_REV 0x12
301
#define IF_CS_CF8381_B3_REV 0x04
302
#define IF_CS_CF8305_B1_REV 0x03
305
* Used to detect other cards than CF8385 since their revisions of silicon
306
* doesn't match those from CF8385, eg. CF8381 B3 works with this driver.
308
#define CF8305_MANFID 0x02db
309
#define CF8305_CARDID 0x8103
310
#define CF8381_MANFID 0x02db
311
#define CF8381_CARDID 0x6064
312
#define CF8385_MANFID 0x02df
313
#define CF8385_CARDID 0x8103
315
/* FIXME: just use the 'driver_info' field of 'struct pcmcia_device_id' when
316
* that gets fixed. Currently there's no way to access it from the probe hook.
318
static inline u32 get_model(u16 manf_id, u16 card_id)
320
/* NOTE: keep in sync with if_cs_ids */
321
if (manf_id == CF8305_MANFID && card_id == CF8305_CARDID)
323
else if (manf_id == CF8381_MANFID && card_id == CF8381_CARDID)
325
else if (manf_id == CF8385_MANFID && card_id == CF8385_CARDID)
327
return MODEL_UNKNOWN;
330
/********************************************************************/
331
/* I/O and interrupt handling */
332
/********************************************************************/
334
static inline void if_cs_enable_ints(struct if_cs_card *card)
336
lbs_deb_enter(LBS_DEB_CS);
337
if_cs_write16(card, IF_CS_HOST_INT_MASK, 0);
340
static inline void if_cs_disable_ints(struct if_cs_card *card)
342
lbs_deb_enter(LBS_DEB_CS);
343
if_cs_write16(card, IF_CS_HOST_INT_MASK, IF_CS_BIT_MASK);
347
* Called from if_cs_host_to_card to send a command to the hardware
349
static int if_cs_send_cmd(struct lbs_private *priv, u8 *buf, u16 nb)
351
struct if_cs_card *card = (struct if_cs_card *)priv->card;
355
lbs_deb_enter(LBS_DEB_CS);
356
if_cs_disable_ints(card);
358
/* Is hardware ready? */
360
u16 status = if_cs_read16(card, IF_CS_CARD_STATUS);
361
if (status & IF_CS_BIT_COMMAND)
364
lbs_pr_err("card not ready for commands\n");
370
if_cs_write16(card, IF_CS_CMD_LEN, nb);
372
if_cs_write16_rep(card, IF_CS_CMD, buf, nb / 2);
373
/* Are we supposed to transfer an odd amount of bytes? */
375
if_cs_write8(card, IF_CS_CMD, buf[nb-1]);
377
/* "Assert the download over interrupt command in the Host
378
* status register" */
379
if_cs_write16(card, IF_CS_HOST_STATUS, IF_CS_BIT_COMMAND);
381
/* "Assert the download over interrupt command in the Card
382
* interrupt case register" */
383
if_cs_write16(card, IF_CS_HOST_INT_CAUSE, IF_CS_BIT_COMMAND);
387
if_cs_enable_ints(card);
388
lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
393
* Called from if_cs_host_to_card to send a data to the hardware
395
static void if_cs_send_data(struct lbs_private *priv, u8 *buf, u16 nb)
397
struct if_cs_card *card = (struct if_cs_card *)priv->card;
400
lbs_deb_enter(LBS_DEB_CS);
401
if_cs_disable_ints(card);
403
status = if_cs_read16(card, IF_CS_CARD_STATUS);
404
BUG_ON((status & IF_CS_BIT_TX) == 0);
406
if_cs_write16(card, IF_CS_WRITE_LEN, nb);
408
/* write even number of bytes, then odd byte if necessary */
409
if_cs_write16_rep(card, IF_CS_WRITE, buf, nb / 2);
411
if_cs_write8(card, IF_CS_WRITE, buf[nb-1]);
413
if_cs_write16(card, IF_CS_HOST_STATUS, IF_CS_BIT_TX);
414
if_cs_write16(card, IF_CS_HOST_INT_CAUSE, IF_CS_BIT_TX);
415
if_cs_enable_ints(card);
417
lbs_deb_leave(LBS_DEB_CS);
421
* Get the command result out of the card.
423
static int if_cs_receive_cmdres(struct lbs_private *priv, u8 *data, u32 *len)
429
lbs_deb_enter(LBS_DEB_CS);
431
/* is hardware ready? */
432
status = if_cs_read16(priv->card, IF_CS_CARD_STATUS);
433
if ((status & IF_CS_BIT_RESP) == 0) {
434
lbs_pr_err("no cmd response in card\n");
439
*len = if_cs_read16(priv->card, IF_CS_RESP_LEN);
440
if ((*len == 0) || (*len > LBS_CMD_BUFFER_SIZE)) {
441
lbs_pr_err("card cmd buffer has invalid # of bytes (%d)\n", *len);
445
/* read even number of bytes, then odd byte if necessary */
446
if_cs_read16_rep(priv->card, IF_CS_RESP, data, *len/sizeof(u16));
448
data[*len-1] = if_cs_read8(priv->card, IF_CS_RESP);
450
/* This is a workaround for a firmware that reports too much
455
/* Clear this flag again */
456
spin_lock_irqsave(&priv->driver_lock, flags);
457
priv->dnld_sent = DNLD_RES_RECEIVED;
458
spin_unlock_irqrestore(&priv->driver_lock, flags);
461
lbs_deb_leave_args(LBS_DEB_CS, "ret %d, len %d", ret, *len);
465
static struct sk_buff *if_cs_receive_data(struct lbs_private *priv)
467
struct sk_buff *skb = NULL;
471
lbs_deb_enter(LBS_DEB_CS);
473
len = if_cs_read16(priv->card, IF_CS_READ_LEN);
474
if (len == 0 || len > MRVDRV_ETH_RX_PACKET_BUFFER_SIZE) {
475
lbs_pr_err("card data buffer has invalid # of bytes (%d)\n", len);
476
priv->dev->stats.rx_dropped++;
480
skb = dev_alloc_skb(MRVDRV_ETH_RX_PACKET_BUFFER_SIZE + 2);
484
skb_reserve(skb, 2);/* 16 byte align */
487
/* read even number of bytes, then odd byte if necessary */
488
if_cs_read16_rep(priv->card, IF_CS_READ, data, len/sizeof(u16));
490
data[len-1] = if_cs_read8(priv->card, IF_CS_READ);
493
if_cs_write16(priv->card, IF_CS_HOST_STATUS, IF_CS_BIT_RX);
494
if_cs_write16(priv->card, IF_CS_HOST_INT_CAUSE, IF_CS_BIT_RX);
497
lbs_deb_leave_args(LBS_DEB_CS, "ret %p", skb);
501
static irqreturn_t if_cs_interrupt(int irq, void *data)
503
struct if_cs_card *card = data;
504
struct lbs_private *priv = card->priv;
507
lbs_deb_enter(LBS_DEB_CS);
509
/* Ask card interrupt cause register if there is something for us */
510
cause = if_cs_read16(card, IF_CS_CARD_INT_CAUSE);
511
lbs_deb_cs("cause 0x%04x\n", cause);
518
if (cause == 0xffff) {
519
/* Read in junk, the card has probably been removed */
520
card->priv->surpriseremoved = 1;
524
if (cause & IF_CS_BIT_RX) {
526
lbs_deb_cs("rx packet\n");
527
skb = if_cs_receive_data(priv);
529
lbs_process_rxed_packet(priv, skb);
532
if (cause & IF_CS_BIT_TX) {
533
lbs_deb_cs("tx done\n");
534
lbs_host_to_card_done(priv);
537
if (cause & IF_CS_BIT_RESP) {
541
lbs_deb_cs("cmd resp\n");
542
spin_lock_irqsave(&priv->driver_lock, flags);
543
i = (priv->resp_idx == 0) ? 1 : 0;
544
spin_unlock_irqrestore(&priv->driver_lock, flags);
546
BUG_ON(priv->resp_len[i]);
547
if_cs_receive_cmdres(priv, priv->resp_buf[i],
550
spin_lock_irqsave(&priv->driver_lock, flags);
551
lbs_notify_command_response(priv, i);
552
spin_unlock_irqrestore(&priv->driver_lock, flags);
555
if (cause & IF_CS_BIT_EVENT) {
556
u16 status = if_cs_read16(priv->card, IF_CS_CARD_STATUS);
557
if_cs_write16(priv->card, IF_CS_HOST_INT_CAUSE,
559
lbs_queue_event(priv, (status & IF_CS_CARD_STATUS_MASK) >> 8);
562
/* Clear interrupt cause */
563
if_cs_write16(card, IF_CS_CARD_INT_CAUSE, cause & IF_CS_BIT_MASK);
565
lbs_deb_leave(LBS_DEB_CS);
572
/********************************************************************/
574
/********************************************************************/
577
* Tries to program the helper firmware.
579
* Return 0 on success
581
static int if_cs_prog_helper(struct if_cs_card *card, const struct firmware *fw)
587
lbs_deb_enter(LBS_DEB_CS);
590
* This is the only place where an unaligned register access happens on
591
* the CF8305 card, therefore for the sake of speed of the driver, we do
592
* the alignment correction here.
594
if (card->align_regs)
595
scratch = if_cs_read16(card, IF_CS_SCRATCH) >> 8;
597
scratch = if_cs_read8(card, IF_CS_SCRATCH);
599
/* "If the value is 0x5a, the firmware is already
600
* downloaded successfully"
602
if (scratch == IF_CS_SCRATCH_HELPER_OK)
605
/* "If the value is != 00, it is invalid value of register */
606
if (scratch != IF_CS_SCRATCH_BOOT_OK) {
611
lbs_deb_cs("helper size %td\n", fw->size);
613
/* "Set the 5 bytes of the helper image to 0" */
614
/* Not needed, this contains an ARM branch instruction */
617
/* "the number of bytes to send is 256" */
619
int remain = fw->size - sent;
624
/* "write the number of bytes to be sent to the I/O Command
625
* write length register" */
626
if_cs_write16(card, IF_CS_CMD_LEN, count);
628
/* "write this to I/O Command port register as 16 bit writes */
630
if_cs_write16_rep(card, IF_CS_CMD,
634
/* "Assert the download over interrupt command in the Host
635
* status register" */
636
if_cs_write8(card, IF_CS_HOST_STATUS, IF_CS_BIT_COMMAND);
638
/* "Assert the download over interrupt command in the Card
639
* interrupt case register" */
640
if_cs_write16(card, IF_CS_HOST_INT_CAUSE, IF_CS_BIT_COMMAND);
642
/* "The host polls the Card Status register ... for 50 ms before
643
declaring a failure */
644
ret = if_cs_poll_while_fw_download(card, IF_CS_CARD_STATUS,
647
lbs_pr_err("can't download helper at 0x%x, ret %d\n",
659
lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
664
static int if_cs_prog_real(struct if_cs_card *card, const struct firmware *fw)
671
lbs_deb_enter(LBS_DEB_CS);
673
lbs_deb_cs("fw size %td\n", fw->size);
675
ret = if_cs_poll_while_fw_download(card, IF_CS_SQ_READ_LOW,
678
lbs_pr_err("helper firmware doesn't answer\n");
682
for (sent = 0; sent < fw->size; sent += len) {
683
len = if_cs_read16(card, IF_CS_SQ_READ_LOW);
686
lbs_pr_info("odd, need to retry this firmware block\n");
692
lbs_pr_err("could not download firmware\n");
701
if_cs_write16(card, IF_CS_CMD_LEN, len);
703
if_cs_write16_rep(card, IF_CS_CMD,
706
if_cs_write8(card, IF_CS_HOST_STATUS, IF_CS_BIT_COMMAND);
707
if_cs_write16(card, IF_CS_HOST_INT_CAUSE, IF_CS_BIT_COMMAND);
709
ret = if_cs_poll_while_fw_download(card, IF_CS_CARD_STATUS,
712
lbs_pr_err("can't download firmware at 0x%x\n", sent);
717
ret = if_cs_poll_while_fw_download(card, IF_CS_SCRATCH, 0x5a);
719
lbs_pr_err("firmware download failed\n");
722
lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
728
/********************************************************************/
729
/* Callback functions for libertas.ko */
730
/********************************************************************/
732
/* Send commands or data packets to the card */
733
static int if_cs_host_to_card(struct lbs_private *priv,
740
lbs_deb_enter_args(LBS_DEB_CS, "type %d, bytes %d", type, nb);
744
priv->dnld_sent = DNLD_DATA_SENT;
745
if_cs_send_data(priv, buf, nb);
749
priv->dnld_sent = DNLD_CMD_SENT;
750
ret = if_cs_send_cmd(priv, buf, nb);
753
lbs_pr_err("%s: unsupported type %d\n", __func__, type);
756
lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
761
static void if_cs_release(struct pcmcia_device *p_dev)
763
struct if_cs_card *card = p_dev->priv;
765
lbs_deb_enter(LBS_DEB_CS);
767
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
768
free_irq(p_dev->irq, card);
770
free_irq(p_dev->irq.AssignedIRQ, card);
772
pcmcia_disable_device(p_dev);
774
ioport_unmap(card->iobase);
776
lbs_deb_leave(LBS_DEB_CS);
779
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
780
static int if_cs_ioprobe(struct pcmcia_device *p_dev, void *priv_data)
782
p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
783
p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
785
if (p_dev->resource[1]->end) {
786
lbs_pr_err("wrong CIS (check number of IO windows)\n");
790
static int if_cs_ioprobe(struct pcmcia_device *p_dev,
791
cistpl_cftable_entry_t *cfg,
792
cistpl_cftable_entry_t *dflt,
796
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36))
797
p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
798
p_dev->resource[0]->start = cfg->io.win[0].base;
799
p_dev->resource[0]->end = cfg->io.win[0].len;
801
p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
802
p_dev->io.BasePort1 = cfg->io.win[0].base;
803
p_dev->io.NumPorts1 = cfg->io.win[0].len;
806
/* Do we need to allocate an interrupt? */
807
p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
809
/* IO window settings */
810
if (cfg->io.nwin != 1) {
811
lbs_pr_err("wrong CIS (check number of IO windows)\n");
816
/* This reserves IO space but doesn't actually enable it */
817
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36))
818
return pcmcia_request_io(p_dev);
820
return pcmcia_request_io(p_dev, &p_dev->io);
824
static int if_cs_probe(struct pcmcia_device *p_dev)
827
unsigned int prod_id;
828
struct lbs_private *priv;
829
struct if_cs_card *card;
830
const struct firmware *helper = NULL;
831
const struct firmware *mainfw = NULL;
833
lbs_deb_enter(LBS_DEB_CS);
835
card = kzalloc(sizeof(struct if_cs_card), GFP_KERNEL);
837
lbs_pr_err("error in kzalloc\n");
843
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
844
p_dev->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
846
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35))
847
p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
848
p_dev->irq.Handler = NULL;
850
p_dev->conf.Attributes = 0;
851
p_dev->conf.IntType = INT_MEMORY_AND_IO;
854
if (pcmcia_loop_config(p_dev, if_cs_ioprobe, NULL)) {
855
lbs_pr_err("error in pcmcia_loop_config\n");
860
* Allocate an interrupt line. Note that this does not assign
861
* a handler to the interrupt, unless the 'Handler' member of
862
* the irq structure is initialized.
864
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
868
if (p_dev->conf.Attributes & CONF_ENABLE_IRQ) {
869
ret = pcmcia_request_irq(p_dev, &p_dev->irq);
871
lbs_pr_err("error in pcmcia_request_irq\n");
877
/* Initialize io access */
878
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36))
879
card->iobase = ioport_map(p_dev->resource[0]->start,
880
resource_size(p_dev->resource[0]));
882
card->iobase = ioport_map(p_dev->io.BasePort1, p_dev->io.NumPorts1);
885
lbs_pr_err("error in ioport_map\n");
890
ret = pcmcia_enable_device(p_dev);
892
lbs_pr_err("error in pcmcia_enable_device\n");
896
/* Finally, report what we've done */
897
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36))
898
lbs_deb_cs("irq %d, io %pR", p_dev->irq, p_dev->resource[0]);
899
#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
900
lbs_deb_cs("irq %d, io 0x%04x-0x%04x\n",
901
p_dev->irq, p_dev->io.BasePort1,
902
p_dev->io.BasePort1 + p_dev->io.NumPorts1 - 1);
904
lbs_deb_cs("irq %d, io 0x%04x-0x%04x\n",
905
p_dev->irq.AssignedIRQ, p_dev->io.BasePort1,
906
p_dev->io.BasePort1 + p_dev->io.NumPorts1 - 1);
910
* Most of the libertas cards can do unaligned register access, but some
911
* weird ones can not. That's especially true for the CF8305 card.
913
card->align_regs = 0;
915
card->model = get_model(p_dev->manf_id, p_dev->card_id);
916
if (card->model == MODEL_UNKNOWN) {
917
lbs_pr_err("unsupported manf_id 0x%04x / card_id 0x%04x\n",
918
p_dev->manf_id, p_dev->card_id);
922
/* Check if we have a current silicon */
923
prod_id = if_cs_read8(card, IF_CS_PRODUCT_ID);
924
if (card->model == MODEL_8305) {
925
card->align_regs = 1;
926
if (prod_id < IF_CS_CF8305_B1_REV) {
927
lbs_pr_err("8305 rev B0 and older are not supported\n");
933
if ((card->model == MODEL_8381) && prod_id < IF_CS_CF8381_B3_REV) {
934
lbs_pr_err("8381 rev B2 and older are not supported\n");
939
if ((card->model == MODEL_8385) && prod_id < IF_CS_CF8385_B1_REV) {
940
lbs_pr_err("8385 rev B0 and older are not supported\n");
945
ret = lbs_get_firmware(&p_dev->dev, NULL, NULL, card->model,
946
&fw_table[0], &helper, &mainfw);
948
lbs_pr_err("failed to find firmware (%d)\n", ret);
952
/* Load the firmware early, before calling into libertas.ko */
953
ret = if_cs_prog_helper(card, helper);
954
if (ret == 0 && (card->model != MODEL_8305))
955
ret = if_cs_prog_real(card, mainfw);
959
/* Make this card known to the libertas driver */
960
priv = lbs_add_card(card, &p_dev->dev);
966
/* Finish setting up fields in lbs_private */
969
priv->hw_host_to_card = if_cs_host_to_card;
970
priv->enter_deep_sleep = NULL;
971
priv->exit_deep_sleep = NULL;
972
priv->reset_deep_sleep_wakeup = NULL;
975
/* Now actually get the IRQ */
976
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
977
ret = request_irq(p_dev->irq, if_cs_interrupt,
979
ret = request_irq(p_dev->irq.AssignedIRQ, if_cs_interrupt,
981
IRQF_SHARED, DRV_NAME, card);
983
lbs_pr_err("error in request_irq\n");
987
/* Clear any interrupt cause that happend while sending
988
* firmware/initializing card */
989
if_cs_write16(card, IF_CS_CARD_INT_CAUSE, IF_CS_BIT_MASK);
990
if_cs_enable_ints(card);
992
/* And finally bring the card up */
993
if (lbs_start_card(priv) != 0) {
994
lbs_pr_err("could not activate card\n");
1002
lbs_remove_card(priv);
1004
ioport_unmap(card->iobase);
1006
pcmcia_disable_device(p_dev);
1009
release_firmware(helper);
1011
release_firmware(mainfw);
1013
lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
1018
static void if_cs_detach(struct pcmcia_device *p_dev)
1020
struct if_cs_card *card = p_dev->priv;
1022
lbs_deb_enter(LBS_DEB_CS);
1024
lbs_stop_card(card->priv);
1025
lbs_remove_card(card->priv);
1026
if_cs_disable_ints(card);
1027
if_cs_release(p_dev);
1030
lbs_deb_leave(LBS_DEB_CS);
1035
/********************************************************************/
1036
/* Module initialization */
1037
/********************************************************************/
1039
static struct pcmcia_device_id if_cs_ids[] = {
1040
PCMCIA_DEVICE_MANF_CARD(CF8305_MANFID, CF8305_CARDID),
1041
PCMCIA_DEVICE_MANF_CARD(CF8381_MANFID, CF8381_CARDID),
1042
PCMCIA_DEVICE_MANF_CARD(CF8385_MANFID, CF8385_CARDID),
1043
/* NOTE: keep in sync with get_model() */
1046
MODULE_DEVICE_TABLE(pcmcia, if_cs_ids);
1049
static struct pcmcia_driver lbs_driver = {
1050
.owner = THIS_MODULE,
1051
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
1058
.probe = if_cs_probe,
1059
.remove = if_cs_detach,
1060
.id_table = if_cs_ids,
1064
static int __init if_cs_init(void)
1068
lbs_deb_enter(LBS_DEB_CS);
1069
ret = pcmcia_register_driver(&lbs_driver);
1070
lbs_deb_leave(LBS_DEB_CS);
1075
static void __exit if_cs_exit(void)
1077
lbs_deb_enter(LBS_DEB_CS);
1078
pcmcia_unregister_driver(&lbs_driver);
1079
lbs_deb_leave(LBS_DEB_CS);
1083
module_init(if_cs_init);
1084
module_exit(if_cs_exit);