Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | |
| 3 | Driver for the Marvell 8385 based compact flash WLAN cards. |
| 4 | |
| 5 | (C) 2007 by Holger Schurig <hs4233@mail.mn-solutions.de> |
| 6 | |
| 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. |
| 11 | |
| 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. |
| 16 | |
| 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. |
| 21 | |
| 22 | */ |
| 23 | |
| 24 | #include <linux/module.h> |
| 25 | #include <linux/delay.h> |
| 26 | #include <linux/moduleparam.h> |
| 27 | #include <linux/firmware.h> |
| 28 | #include <linux/netdevice.h> |
| 29 | |
| 30 | #include <pcmcia/cs_types.h> |
| 31 | #include <pcmcia/cs.h> |
| 32 | #include <pcmcia/cistpl.h> |
| 33 | #include <pcmcia/ds.h> |
| 34 | |
| 35 | #include <linux/io.h> |
| 36 | |
| 37 | #define DRV_NAME "libertas_cs" |
| 38 | |
| 39 | #include "decl.h" |
| 40 | #include "defs.h" |
| 41 | #include "dev.h" |
| 42 | |
| 43 | |
| 44 | /********************************************************************/ |
| 45 | /* Module stuff */ |
| 46 | /********************************************************************/ |
| 47 | |
| 48 | MODULE_AUTHOR("Holger Schurig <hs4233@mail.mn-solutions.de>"); |
| 49 | MODULE_DESCRIPTION("Driver for Marvell 83xx compact flash WLAN cards"); |
| 50 | MODULE_LICENSE("GPL"); |
Ben Hutchings | a974a4b | 2009-11-07 22:00:03 +0000 | [diff] [blame] | 51 | MODULE_FIRMWARE("libertas_cs_helper.fw"); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 52 | |
| 53 | |
| 54 | |
| 55 | /********************************************************************/ |
| 56 | /* Data structures */ |
| 57 | /********************************************************************/ |
| 58 | |
| 59 | struct if_cs_card { |
| 60 | struct pcmcia_device *p_dev; |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 61 | struct lbs_private *priv; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 62 | void __iomem *iobase; |
Marek Vasut | 9d45368 | 2009-08-21 04:08:16 +0200 | [diff] [blame] | 63 | bool align_regs; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | |
| 67 | |
| 68 | /********************************************************************/ |
| 69 | /* Hardware access */ |
| 70 | /********************************************************************/ |
| 71 | |
| 72 | /* This define enables wrapper functions which allow you |
| 73 | to dump all register accesses. You normally won't this, |
| 74 | except for development */ |
| 75 | /* #define DEBUG_IO */ |
| 76 | |
| 77 | #ifdef DEBUG_IO |
| 78 | static int debug_output = 0; |
| 79 | #else |
| 80 | /* This way the compiler optimizes the printk's away */ |
| 81 | #define debug_output 0 |
| 82 | #endif |
| 83 | |
| 84 | static inline unsigned int if_cs_read8(struct if_cs_card *card, uint reg) |
| 85 | { |
| 86 | unsigned int val = ioread8(card->iobase + reg); |
| 87 | if (debug_output) |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 88 | printk(KERN_INFO "inb %08x<%02x\n", reg, val); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 89 | return val; |
| 90 | } |
| 91 | static inline unsigned int if_cs_read16(struct if_cs_card *card, uint reg) |
| 92 | { |
| 93 | unsigned int val = ioread16(card->iobase + reg); |
| 94 | if (debug_output) |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 95 | printk(KERN_INFO "inw %08x<%04x\n", reg, val); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 96 | return val; |
| 97 | } |
| 98 | static inline void if_cs_read16_rep( |
| 99 | struct if_cs_card *card, |
| 100 | uint reg, |
| 101 | void *buf, |
| 102 | unsigned long count) |
| 103 | { |
| 104 | if (debug_output) |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 105 | printk(KERN_INFO "insw %08x<(0x%lx words)\n", |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 106 | reg, count); |
| 107 | ioread16_rep(card->iobase + reg, buf, count); |
| 108 | } |
| 109 | |
| 110 | static inline void if_cs_write8(struct if_cs_card *card, uint reg, u8 val) |
| 111 | { |
| 112 | if (debug_output) |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 113 | printk(KERN_INFO "outb %08x>%02x\n", reg, val); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 114 | iowrite8(val, card->iobase + reg); |
| 115 | } |
| 116 | |
| 117 | static inline void if_cs_write16(struct if_cs_card *card, uint reg, u16 val) |
| 118 | { |
| 119 | if (debug_output) |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 120 | printk(KERN_INFO "outw %08x>%04x\n", reg, val); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 121 | iowrite16(val, card->iobase + reg); |
| 122 | } |
| 123 | |
| 124 | static inline void if_cs_write16_rep( |
| 125 | struct if_cs_card *card, |
| 126 | uint reg, |
David Woodhouse | 6dfff89 | 2008-05-23 18:37:51 +0100 | [diff] [blame] | 127 | const void *buf, |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 128 | unsigned long count) |
| 129 | { |
| 130 | if (debug_output) |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 131 | printk(KERN_INFO "outsw %08x>(0x%lx words)\n", |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 132 | reg, count); |
| 133 | iowrite16_rep(card->iobase + reg, buf, count); |
| 134 | } |
| 135 | |
| 136 | |
| 137 | /* |
| 138 | * I know that polling/delaying is frowned upon. However, this procedure |
| 139 | * with polling is needed while downloading the firmware. At this stage, |
| 140 | * the hardware does unfortunately not create any interrupts. |
| 141 | * |
| 142 | * Fortunately, this function is never used once the firmware is in |
| 143 | * the card. :-) |
| 144 | * |
| 145 | * As a reference, see the "Firmware Specification v5.1", page 18 |
| 146 | * and 19. I did not follow their suggested timing to the word, |
| 147 | * but this works nice & fast anyway. |
| 148 | */ |
| 149 | static int if_cs_poll_while_fw_download(struct if_cs_card *card, uint addr, u8 reg) |
| 150 | { |
| 151 | int i; |
| 152 | |
Holger Schurig | 93416c87 | 2008-05-23 10:18:26 +0200 | [diff] [blame] | 153 | for (i = 0; i < 100000; i++) { |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 154 | u8 val = if_cs_read8(card, addr); |
| 155 | if (val == reg) |
Dan Williams | 1fac36e | 2009-01-23 11:55:33 -0500 | [diff] [blame] | 156 | return 0; |
Holger Schurig | 93416c87 | 2008-05-23 10:18:26 +0200 | [diff] [blame] | 157 | udelay(5); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 158 | } |
| 159 | return -ETIME; |
| 160 | } |
| 161 | |
| 162 | |
| 163 | |
Holger Schurig | 5314325 | 2008-06-05 13:07:04 +0200 | [diff] [blame] | 164 | /* |
| 165 | * First the bitmasks for the host/card interrupt/status registers: |
| 166 | */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 167 | #define IF_CS_BIT_TX 0x0001 |
| 168 | #define IF_CS_BIT_RX 0x0002 |
| 169 | #define IF_CS_BIT_COMMAND 0x0004 |
| 170 | #define IF_CS_BIT_RESP 0x0008 |
| 171 | #define IF_CS_BIT_EVENT 0x0010 |
| 172 | #define IF_CS_BIT_MASK 0x001f |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 173 | |
Holger Schurig | 5314325 | 2008-06-05 13:07:04 +0200 | [diff] [blame] | 174 | |
| 175 | |
| 176 | /* |
| 177 | * It's not really clear to me what the host status register is for. It |
| 178 | * needs to be set almost in union with "host int cause". The following |
| 179 | * bits from above are used: |
| 180 | * |
| 181 | * IF_CS_BIT_TX driver downloaded a data packet |
| 182 | * IF_CS_BIT_RX driver got a data packet |
| 183 | * IF_CS_BIT_COMMAND driver downloaded a command |
| 184 | * IF_CS_BIT_RESP not used (has some meaning with powerdown) |
| 185 | * IF_CS_BIT_EVENT driver read a host event |
| 186 | */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 187 | #define IF_CS_HOST_STATUS 0x00000000 |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 188 | |
Holger Schurig | 5314325 | 2008-06-05 13:07:04 +0200 | [diff] [blame] | 189 | /* |
| 190 | * With the host int cause register can the host (that is, Linux) cause |
| 191 | * an interrupt in the firmware, to tell the firmware about those events: |
| 192 | * |
| 193 | * IF_CS_BIT_TX a data packet has been downloaded |
| 194 | * IF_CS_BIT_RX a received data packet has retrieved |
| 195 | * IF_CS_BIT_COMMAND a firmware block or a command has been downloaded |
| 196 | * IF_CS_BIT_RESP not used (has some meaning with powerdown) |
| 197 | * IF_CS_BIT_EVENT a host event (link lost etc) has been retrieved |
| 198 | */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 199 | #define IF_CS_HOST_INT_CAUSE 0x00000002 |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 200 | |
Holger Schurig | 5314325 | 2008-06-05 13:07:04 +0200 | [diff] [blame] | 201 | /* |
| 202 | * The host int mask register is used to enable/disable interrupt. However, |
| 203 | * I have the suspicion that disabled interrupts are lost. |
| 204 | */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 205 | #define IF_CS_HOST_INT_MASK 0x00000004 |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 206 | |
Holger Schurig | 5314325 | 2008-06-05 13:07:04 +0200 | [diff] [blame] | 207 | /* |
| 208 | * Used to send or receive data packets: |
| 209 | */ |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 210 | #define IF_CS_WRITE 0x00000016 |
| 211 | #define IF_CS_WRITE_LEN 0x00000014 |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 212 | #define IF_CS_READ 0x00000010 |
| 213 | #define IF_CS_READ_LEN 0x00000024 |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 214 | |
Holger Schurig | 5314325 | 2008-06-05 13:07:04 +0200 | [diff] [blame] | 215 | /* |
| 216 | * Used to send commands (and to send firmware block) and to |
| 217 | * receive command responses: |
| 218 | */ |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 219 | #define IF_CS_CMD 0x0000001A |
| 220 | #define IF_CS_CMD_LEN 0x00000018 |
| 221 | #define IF_CS_RESP 0x00000012 |
| 222 | #define IF_CS_RESP_LEN 0x00000030 |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 223 | |
Holger Schurig | 5314325 | 2008-06-05 13:07:04 +0200 | [diff] [blame] | 224 | /* |
| 225 | * The card status registers shows what the card/firmware actually |
| 226 | * accepts: |
| 227 | * |
| 228 | * IF_CS_BIT_TX you may send a data packet |
| 229 | * IF_CS_BIT_RX you may retrieve a data packet |
| 230 | * IF_CS_BIT_COMMAND you may send a command |
| 231 | * IF_CS_BIT_RESP you may retrieve a command response |
| 232 | * IF_CS_BIT_EVENT the card has a event for use (link lost, snr low etc) |
| 233 | * |
| 234 | * When reading this register several times, you will get back the same |
| 235 | * results --- with one exception: the IF_CS_BIT_EVENT clear itself |
| 236 | * automatically. |
| 237 | * |
| 238 | * Not that we don't rely on BIT_RX,_BIT_RESP or BIT_EVENT because |
| 239 | * we handle this via the card int cause register. |
| 240 | */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 241 | #define IF_CS_CARD_STATUS 0x00000020 |
| 242 | #define IF_CS_CARD_STATUS_MASK 0x7f00 |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 243 | |
Holger Schurig | 5314325 | 2008-06-05 13:07:04 +0200 | [diff] [blame] | 244 | /* |
| 245 | * The card int cause register is used by the card/firmware to notify us |
| 246 | * about the following events: |
| 247 | * |
| 248 | * IF_CS_BIT_TX a data packet has successfully been sentx |
| 249 | * IF_CS_BIT_RX a data packet has been received and can be retrieved |
| 250 | * IF_CS_BIT_COMMAND not used |
| 251 | * IF_CS_BIT_RESP the firmware has a command response for us |
| 252 | * IF_CS_BIT_EVENT the card has a event for use (link lost, snr low etc) |
| 253 | */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 254 | #define IF_CS_CARD_INT_CAUSE 0x00000022 |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 255 | |
Holger Schurig | 5314325 | 2008-06-05 13:07:04 +0200 | [diff] [blame] | 256 | /* |
| 257 | * This is used to for handshaking with the card's bootloader/helper image |
| 258 | * to synchronize downloading of firmware blocks. |
| 259 | */ |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 260 | #define IF_CS_SQ_READ_LOW 0x00000028 |
| 261 | #define IF_CS_SQ_HELPER_OK 0x10 |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 262 | |
Holger Schurig | 5314325 | 2008-06-05 13:07:04 +0200 | [diff] [blame] | 263 | /* |
| 264 | * The scratch register tells us ... |
| 265 | * |
| 266 | * IF_CS_SCRATCH_BOOT_OK the bootloader runs |
| 267 | * IF_CS_SCRATCH_HELPER_OK the helper firmware already runs |
| 268 | */ |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 269 | #define IF_CS_SCRATCH 0x0000003F |
Holger Schurig | 5314325 | 2008-06-05 13:07:04 +0200 | [diff] [blame] | 270 | #define IF_CS_SCRATCH_BOOT_OK 0x00 |
| 271 | #define IF_CS_SCRATCH_HELPER_OK 0x5a |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 272 | |
Holger Schurig | 4c55523 | 2008-06-05 13:08:35 +0200 | [diff] [blame] | 273 | /* |
| 274 | * Used to detect ancient chips: |
| 275 | */ |
| 276 | #define IF_CS_PRODUCT_ID 0x0000001C |
| 277 | #define IF_CS_CF8385_B1_REV 0x12 |
Marek Vasut | dc7d243 | 2009-03-24 21:33:43 +0100 | [diff] [blame] | 278 | #define IF_CS_CF8381_B3_REV 0x04 |
Marek Vasut | 9d45368 | 2009-08-21 04:08:16 +0200 | [diff] [blame] | 279 | #define IF_CS_CF8305_B1_REV 0x03 |
Holger Schurig | 4c55523 | 2008-06-05 13:08:35 +0200 | [diff] [blame] | 280 | |
Marek Vasut | dc7d243 | 2009-03-24 21:33:43 +0100 | [diff] [blame] | 281 | /* |
| 282 | * Used to detect other cards than CF8385 since their revisions of silicon |
| 283 | * doesn't match those from CF8385, eg. CF8381 B3 works with this driver. |
| 284 | */ |
Marek Vasut | 9d45368 | 2009-08-21 04:08:16 +0200 | [diff] [blame] | 285 | #define CF8305_MANFID 0x02db |
| 286 | #define CF8305_CARDID 0x8103 |
Marek Vasut | dc7d243 | 2009-03-24 21:33:43 +0100 | [diff] [blame] | 287 | #define CF8381_MANFID 0x02db |
| 288 | #define CF8381_CARDID 0x6064 |
| 289 | #define CF8385_MANFID 0x02df |
| 290 | #define CF8385_CARDID 0x8103 |
| 291 | |
Marek Vasut | 9d45368 | 2009-08-21 04:08:16 +0200 | [diff] [blame] | 292 | static inline int if_cs_hw_is_cf8305(struct pcmcia_device *p_dev) |
| 293 | { |
| 294 | return (p_dev->manf_id == CF8305_MANFID && |
| 295 | p_dev->card_id == CF8305_CARDID); |
| 296 | } |
| 297 | |
Marek Vasut | dc7d243 | 2009-03-24 21:33:43 +0100 | [diff] [blame] | 298 | static inline int if_cs_hw_is_cf8381(struct pcmcia_device *p_dev) |
| 299 | { |
| 300 | return (p_dev->manf_id == CF8381_MANFID && |
| 301 | p_dev->card_id == CF8381_CARDID); |
| 302 | } |
| 303 | |
| 304 | static inline int if_cs_hw_is_cf8385(struct pcmcia_device *p_dev) |
| 305 | { |
| 306 | return (p_dev->manf_id == CF8385_MANFID && |
| 307 | p_dev->card_id == CF8385_CARDID); |
| 308 | } |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 309 | |
| 310 | /********************************************************************/ |
Holger Schurig | 43d01c5 | 2008-05-26 12:50:23 +0200 | [diff] [blame] | 311 | /* I/O and interrupt handling */ |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 312 | /********************************************************************/ |
| 313 | |
Holger Schurig | 43d01c5 | 2008-05-26 12:50:23 +0200 | [diff] [blame] | 314 | static inline void if_cs_enable_ints(struct if_cs_card *card) |
| 315 | { |
| 316 | lbs_deb_enter(LBS_DEB_CS); |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 317 | if_cs_write16(card, IF_CS_HOST_INT_MASK, 0); |
Holger Schurig | 43d01c5 | 2008-05-26 12:50:23 +0200 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | static inline void if_cs_disable_ints(struct if_cs_card *card) |
| 321 | { |
| 322 | lbs_deb_enter(LBS_DEB_CS); |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 323 | if_cs_write16(card, IF_CS_HOST_INT_MASK, IF_CS_BIT_MASK); |
Holger Schurig | 43d01c5 | 2008-05-26 12:50:23 +0200 | [diff] [blame] | 324 | } |
| 325 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 326 | /* |
| 327 | * Called from if_cs_host_to_card to send a command to the hardware |
| 328 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 329 | static int if_cs_send_cmd(struct lbs_private *priv, u8 *buf, u16 nb) |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 330 | { |
| 331 | struct if_cs_card *card = (struct if_cs_card *)priv->card; |
| 332 | int ret = -1; |
| 333 | int loops = 0; |
| 334 | |
| 335 | lbs_deb_enter(LBS_DEB_CS); |
Holger Schurig | 43d01c5 | 2008-05-26 12:50:23 +0200 | [diff] [blame] | 336 | if_cs_disable_ints(card); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 337 | |
| 338 | /* Is hardware ready? */ |
| 339 | while (1) { |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 340 | u16 status = if_cs_read16(card, IF_CS_CARD_STATUS); |
| 341 | if (status & IF_CS_BIT_COMMAND) |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 342 | break; |
| 343 | if (++loops > 100) { |
| 344 | lbs_pr_err("card not ready for commands\n"); |
| 345 | goto done; |
| 346 | } |
| 347 | mdelay(1); |
| 348 | } |
| 349 | |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 350 | if_cs_write16(card, IF_CS_CMD_LEN, nb); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 351 | |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 352 | if_cs_write16_rep(card, IF_CS_CMD, buf, nb / 2); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 353 | /* Are we supposed to transfer an odd amount of bytes? */ |
| 354 | if (nb & 1) |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 355 | if_cs_write8(card, IF_CS_CMD, buf[nb-1]); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 356 | |
| 357 | /* "Assert the download over interrupt command in the Host |
| 358 | * status register" */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 359 | if_cs_write16(card, IF_CS_HOST_STATUS, IF_CS_BIT_COMMAND); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 360 | |
| 361 | /* "Assert the download over interrupt command in the Card |
| 362 | * interrupt case register" */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 363 | if_cs_write16(card, IF_CS_HOST_INT_CAUSE, IF_CS_BIT_COMMAND); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 364 | ret = 0; |
| 365 | |
| 366 | done: |
Holger Schurig | 43d01c5 | 2008-05-26 12:50:23 +0200 | [diff] [blame] | 367 | if_cs_enable_ints(card); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 368 | lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret); |
| 369 | return ret; |
| 370 | } |
| 371 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 372 | /* |
| 373 | * Called from if_cs_host_to_card to send a data to the hardware |
| 374 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 375 | static void if_cs_send_data(struct lbs_private *priv, u8 *buf, u16 nb) |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 376 | { |
| 377 | struct if_cs_card *card = (struct if_cs_card *)priv->card; |
Holger Schurig | 43d01c5 | 2008-05-26 12:50:23 +0200 | [diff] [blame] | 378 | u16 status; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 379 | |
| 380 | lbs_deb_enter(LBS_DEB_CS); |
Holger Schurig | 43d01c5 | 2008-05-26 12:50:23 +0200 | [diff] [blame] | 381 | if_cs_disable_ints(card); |
| 382 | |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 383 | status = if_cs_read16(card, IF_CS_CARD_STATUS); |
| 384 | BUG_ON((status & IF_CS_BIT_TX) == 0); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 385 | |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 386 | if_cs_write16(card, IF_CS_WRITE_LEN, nb); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 387 | |
| 388 | /* write even number of bytes, then odd byte if necessary */ |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 389 | if_cs_write16_rep(card, IF_CS_WRITE, buf, nb / 2); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 390 | if (nb & 1) |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 391 | if_cs_write8(card, IF_CS_WRITE, buf[nb-1]); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 392 | |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 393 | if_cs_write16(card, IF_CS_HOST_STATUS, IF_CS_BIT_TX); |
| 394 | if_cs_write16(card, IF_CS_HOST_INT_CAUSE, IF_CS_BIT_TX); |
Holger Schurig | 43d01c5 | 2008-05-26 12:50:23 +0200 | [diff] [blame] | 395 | if_cs_enable_ints(card); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 396 | |
| 397 | lbs_deb_leave(LBS_DEB_CS); |
| 398 | } |
| 399 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 400 | /* |
| 401 | * Get the command result out of the card. |
| 402 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 403 | static int if_cs_receive_cmdres(struct lbs_private *priv, u8 *data, u32 *len) |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 404 | { |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 405 | unsigned long flags; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 406 | int ret = -1; |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 407 | u16 status; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 408 | |
| 409 | lbs_deb_enter(LBS_DEB_CS); |
| 410 | |
| 411 | /* is hardware ready? */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 412 | status = if_cs_read16(priv->card, IF_CS_CARD_STATUS); |
| 413 | if ((status & IF_CS_BIT_RESP) == 0) { |
| 414 | lbs_pr_err("no cmd response in card\n"); |
| 415 | *len = 0; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 416 | goto out; |
| 417 | } |
| 418 | |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 419 | *len = if_cs_read16(priv->card, IF_CS_RESP_LEN); |
Dan Williams | ddac452 | 2007-12-11 13:49:39 -0500 | [diff] [blame] | 420 | if ((*len == 0) || (*len > LBS_CMD_BUFFER_SIZE)) { |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 421 | lbs_pr_err("card cmd buffer has invalid # of bytes (%d)\n", *len); |
| 422 | goto out; |
| 423 | } |
| 424 | |
| 425 | /* read even number of bytes, then odd byte if necessary */ |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 426 | if_cs_read16_rep(priv->card, IF_CS_RESP, data, *len/sizeof(u16)); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 427 | if (*len & 1) |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 428 | data[*len-1] = if_cs_read8(priv->card, IF_CS_RESP); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 429 | |
Holger Schurig | 09d4fad | 2007-12-06 13:50:30 +0100 | [diff] [blame] | 430 | /* This is a workaround for a firmware that reports too much |
| 431 | * bytes */ |
| 432 | *len -= 8; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 433 | ret = 0; |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 434 | |
| 435 | /* Clear this flag again */ |
| 436 | spin_lock_irqsave(&priv->driver_lock, flags); |
| 437 | priv->dnld_sent = DNLD_RES_RECEIVED; |
| 438 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
| 439 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 440 | out: |
| 441 | lbs_deb_leave_args(LBS_DEB_CS, "ret %d, len %d", ret, *len); |
| 442 | return ret; |
| 443 | } |
| 444 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 445 | static struct sk_buff *if_cs_receive_data(struct lbs_private *priv) |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 446 | { |
| 447 | struct sk_buff *skb = NULL; |
| 448 | u16 len; |
| 449 | u8 *data; |
| 450 | |
| 451 | lbs_deb_enter(LBS_DEB_CS); |
| 452 | |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 453 | len = if_cs_read16(priv->card, IF_CS_READ_LEN); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 454 | if (len == 0 || len > MRVDRV_ETH_RX_PACKET_BUFFER_SIZE) { |
| 455 | lbs_pr_err("card data buffer has invalid # of bytes (%d)\n", len); |
Stephen Hemminger | bbfc6b7 | 2009-03-20 19:36:36 +0000 | [diff] [blame] | 456 | priv->dev->stats.rx_dropped++; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 457 | goto dat_err; |
| 458 | } |
| 459 | |
Vladimir Davydov | f31ce76b | 2007-09-06 21:41:02 -0400 | [diff] [blame] | 460 | skb = dev_alloc_skb(MRVDRV_ETH_RX_PACKET_BUFFER_SIZE + 2); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 461 | if (!skb) |
| 462 | goto out; |
Vladimir Davydov | f31ce76b | 2007-09-06 21:41:02 -0400 | [diff] [blame] | 463 | skb_put(skb, len); |
| 464 | skb_reserve(skb, 2);/* 16 byte align */ |
| 465 | data = skb->data; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 466 | |
| 467 | /* read even number of bytes, then odd byte if necessary */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 468 | if_cs_read16_rep(priv->card, IF_CS_READ, data, len/sizeof(u16)); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 469 | if (len & 1) |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 470 | data[len-1] = if_cs_read8(priv->card, IF_CS_READ); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 471 | |
| 472 | dat_err: |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 473 | if_cs_write16(priv->card, IF_CS_HOST_STATUS, IF_CS_BIT_RX); |
| 474 | if_cs_write16(priv->card, IF_CS_HOST_INT_CAUSE, IF_CS_BIT_RX); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 475 | |
| 476 | out: |
| 477 | lbs_deb_leave_args(LBS_DEB_CS, "ret %p", skb); |
| 478 | return skb; |
| 479 | } |
| 480 | |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 481 | static irqreturn_t if_cs_interrupt(int irq, void *data) |
| 482 | { |
| 483 | struct if_cs_card *card = data; |
| 484 | struct lbs_private *priv = card->priv; |
| 485 | u16 cause; |
| 486 | |
| 487 | lbs_deb_enter(LBS_DEB_CS); |
| 488 | |
Holger Schurig | 43d01c5 | 2008-05-26 12:50:23 +0200 | [diff] [blame] | 489 | /* Ask card interrupt cause register if there is something for us */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 490 | cause = if_cs_read16(card, IF_CS_CARD_INT_CAUSE); |
Holger Schurig | 3073556 | 2008-06-05 13:06:15 +0200 | [diff] [blame] | 491 | lbs_deb_cs("cause 0x%04x\n", cause); |
| 492 | |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 493 | if (cause == 0) { |
| 494 | /* Not for us */ |
| 495 | return IRQ_NONE; |
| 496 | } |
| 497 | |
| 498 | if (cause == 0xffff) { |
| 499 | /* Read in junk, the card has probably been removed */ |
| 500 | card->priv->surpriseremoved = 1; |
| 501 | return IRQ_HANDLED; |
| 502 | } |
| 503 | |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 504 | if (cause & IF_CS_BIT_RX) { |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 505 | struct sk_buff *skb; |
| 506 | lbs_deb_cs("rx packet\n"); |
| 507 | skb = if_cs_receive_data(priv); |
| 508 | if (skb) |
| 509 | lbs_process_rxed_packet(priv, skb); |
| 510 | } |
| 511 | |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 512 | if (cause & IF_CS_BIT_TX) { |
Holger Schurig | 43d01c5 | 2008-05-26 12:50:23 +0200 | [diff] [blame] | 513 | lbs_deb_cs("tx done\n"); |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 514 | lbs_host_to_card_done(priv); |
| 515 | } |
| 516 | |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 517 | if (cause & IF_CS_BIT_RESP) { |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 518 | unsigned long flags; |
| 519 | u8 i; |
| 520 | |
Holger Schurig | 43d01c5 | 2008-05-26 12:50:23 +0200 | [diff] [blame] | 521 | lbs_deb_cs("cmd resp\n"); |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 522 | spin_lock_irqsave(&priv->driver_lock, flags); |
| 523 | i = (priv->resp_idx == 0) ? 1 : 0; |
| 524 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
| 525 | |
| 526 | BUG_ON(priv->resp_len[i]); |
| 527 | if_cs_receive_cmdres(priv, priv->resp_buf[i], |
| 528 | &priv->resp_len[i]); |
| 529 | |
| 530 | spin_lock_irqsave(&priv->driver_lock, flags); |
| 531 | lbs_notify_command_response(priv, i); |
| 532 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
| 533 | } |
| 534 | |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 535 | if (cause & IF_CS_BIT_EVENT) { |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 536 | u16 status = if_cs_read16(priv->card, IF_CS_CARD_STATUS); |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 537 | if_cs_write16(priv->card, IF_CS_HOST_INT_CAUSE, |
| 538 | IF_CS_BIT_EVENT); |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 539 | lbs_queue_event(priv, (status & IF_CS_CARD_STATUS_MASK) >> 8); |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 540 | } |
| 541 | |
Holger Schurig | 3073556 | 2008-06-05 13:06:15 +0200 | [diff] [blame] | 542 | /* Clear interrupt cause */ |
| 543 | if_cs_write16(card, IF_CS_CARD_INT_CAUSE, cause & IF_CS_BIT_MASK); |
| 544 | |
Holger Schurig | 43d01c5 | 2008-05-26 12:50:23 +0200 | [diff] [blame] | 545 | lbs_deb_leave(LBS_DEB_CS); |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 546 | return IRQ_HANDLED; |
| 547 | } |
| 548 | |
| 549 | |
| 550 | |
| 551 | |
| 552 | /********************************************************************/ |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 553 | /* Firmware */ |
| 554 | /********************************************************************/ |
| 555 | |
| 556 | /* |
| 557 | * Tries to program the helper firmware. |
| 558 | * |
| 559 | * Return 0 on success |
| 560 | */ |
| 561 | static int if_cs_prog_helper(struct if_cs_card *card) |
| 562 | { |
| 563 | int ret = 0; |
| 564 | int sent = 0; |
| 565 | u8 scratch; |
| 566 | const struct firmware *fw; |
| 567 | |
| 568 | lbs_deb_enter(LBS_DEB_CS); |
| 569 | |
Marek Vasut | 9d45368 | 2009-08-21 04:08:16 +0200 | [diff] [blame] | 570 | /* |
| 571 | * This is the only place where an unaligned register access happens on |
| 572 | * the CF8305 card, therefore for the sake of speed of the driver, we do |
| 573 | * the alignment correction here. |
| 574 | */ |
| 575 | if (card->align_regs) |
| 576 | scratch = if_cs_read16(card, IF_CS_SCRATCH) >> 8; |
| 577 | else |
| 578 | scratch = if_cs_read8(card, IF_CS_SCRATCH); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 579 | |
| 580 | /* "If the value is 0x5a, the firmware is already |
| 581 | * downloaded successfully" |
| 582 | */ |
Holger Schurig | 5314325 | 2008-06-05 13:07:04 +0200 | [diff] [blame] | 583 | if (scratch == IF_CS_SCRATCH_HELPER_OK) |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 584 | goto done; |
| 585 | |
| 586 | /* "If the value is != 00, it is invalid value of register */ |
Holger Schurig | 5314325 | 2008-06-05 13:07:04 +0200 | [diff] [blame] | 587 | if (scratch != IF_CS_SCRATCH_BOOT_OK) { |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 588 | ret = -ENODEV; |
| 589 | goto done; |
| 590 | } |
| 591 | |
| 592 | /* TODO: make firmware file configurable */ |
| 593 | ret = request_firmware(&fw, "libertas_cs_helper.fw", |
Dominik Brodowski | dd2e5a1 | 2009-11-03 10:27:34 +0100 | [diff] [blame] | 594 | &card->p_dev->dev); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 595 | if (ret) { |
| 596 | lbs_pr_err("can't load helper firmware\n"); |
| 597 | ret = -ENODEV; |
| 598 | goto done; |
| 599 | } |
Andrew Morton | 4ecd41b | 2007-08-21 02:15:45 -0700 | [diff] [blame] | 600 | lbs_deb_cs("helper size %td\n", fw->size); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 601 | |
| 602 | /* "Set the 5 bytes of the helper image to 0" */ |
| 603 | /* Not needed, this contains an ARM branch instruction */ |
| 604 | |
| 605 | for (;;) { |
| 606 | /* "the number of bytes to send is 256" */ |
| 607 | int count = 256; |
| 608 | int remain = fw->size - sent; |
| 609 | |
| 610 | if (remain < count) |
| 611 | count = remain; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 612 | |
| 613 | /* "write the number of bytes to be sent to the I/O Command |
| 614 | * write length register" */ |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 615 | if_cs_write16(card, IF_CS_CMD_LEN, count); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 616 | |
| 617 | /* "write this to I/O Command port register as 16 bit writes */ |
| 618 | if (count) |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 619 | if_cs_write16_rep(card, IF_CS_CMD, |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 620 | &fw->data[sent], |
| 621 | count >> 1); |
| 622 | |
| 623 | /* "Assert the download over interrupt command in the Host |
| 624 | * status register" */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 625 | if_cs_write8(card, IF_CS_HOST_STATUS, IF_CS_BIT_COMMAND); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 626 | |
| 627 | /* "Assert the download over interrupt command in the Card |
| 628 | * interrupt case register" */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 629 | if_cs_write16(card, IF_CS_HOST_INT_CAUSE, IF_CS_BIT_COMMAND); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 630 | |
| 631 | /* "The host polls the Card Status register ... for 50 ms before |
| 632 | declaring a failure */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 633 | ret = if_cs_poll_while_fw_download(card, IF_CS_CARD_STATUS, |
| 634 | IF_CS_BIT_COMMAND); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 635 | if (ret < 0) { |
| 636 | lbs_pr_err("can't download helper at 0x%x, ret %d\n", |
| 637 | sent, ret); |
Adrian Bunk | 9a52028 | 2008-08-28 01:05:08 +0300 | [diff] [blame] | 638 | goto err_release; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | if (count == 0) |
| 642 | break; |
| 643 | |
| 644 | sent += count; |
| 645 | } |
| 646 | |
Adrian Bunk | 9a52028 | 2008-08-28 01:05:08 +0300 | [diff] [blame] | 647 | err_release: |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 648 | release_firmware(fw); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 649 | done: |
| 650 | lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret); |
| 651 | return ret; |
| 652 | } |
| 653 | |
| 654 | |
| 655 | static int if_cs_prog_real(struct if_cs_card *card) |
| 656 | { |
| 657 | const struct firmware *fw; |
| 658 | int ret = 0; |
| 659 | int retry = 0; |
| 660 | int len = 0; |
| 661 | int sent; |
| 662 | |
| 663 | lbs_deb_enter(LBS_DEB_CS); |
| 664 | |
| 665 | /* TODO: make firmware file configurable */ |
| 666 | ret = request_firmware(&fw, "libertas_cs.fw", |
Dominik Brodowski | dd2e5a1 | 2009-11-03 10:27:34 +0100 | [diff] [blame] | 667 | &card->p_dev->dev); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 668 | if (ret) { |
| 669 | lbs_pr_err("can't load firmware\n"); |
| 670 | ret = -ENODEV; |
| 671 | goto done; |
| 672 | } |
Andrew Morton | 4ecd41b | 2007-08-21 02:15:45 -0700 | [diff] [blame] | 673 | lbs_deb_cs("fw size %td\n", fw->size); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 674 | |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 675 | ret = if_cs_poll_while_fw_download(card, IF_CS_SQ_READ_LOW, |
| 676 | IF_CS_SQ_HELPER_OK); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 677 | if (ret < 0) { |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 678 | lbs_pr_err("helper firmware doesn't answer\n"); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 679 | goto err_release; |
| 680 | } |
| 681 | |
| 682 | for (sent = 0; sent < fw->size; sent += len) { |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 683 | len = if_cs_read16(card, IF_CS_SQ_READ_LOW); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 684 | if (len & 1) { |
| 685 | retry++; |
| 686 | lbs_pr_info("odd, need to retry this firmware block\n"); |
| 687 | } else { |
| 688 | retry = 0; |
| 689 | } |
| 690 | |
| 691 | if (retry > 20) { |
| 692 | lbs_pr_err("could not download firmware\n"); |
| 693 | ret = -ENODEV; |
| 694 | goto err_release; |
| 695 | } |
| 696 | if (retry) { |
| 697 | sent -= len; |
| 698 | } |
| 699 | |
| 700 | |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 701 | if_cs_write16(card, IF_CS_CMD_LEN, len); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 702 | |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 703 | if_cs_write16_rep(card, IF_CS_CMD, |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 704 | &fw->data[sent], |
| 705 | (len+1) >> 1); |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 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); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 708 | |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 709 | ret = if_cs_poll_while_fw_download(card, IF_CS_CARD_STATUS, |
| 710 | IF_CS_BIT_COMMAND); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 711 | if (ret < 0) { |
| 712 | lbs_pr_err("can't download firmware at 0x%x\n", sent); |
| 713 | goto err_release; |
| 714 | } |
| 715 | } |
| 716 | |
| 717 | ret = if_cs_poll_while_fw_download(card, IF_CS_SCRATCH, 0x5a); |
Adrian Bunk | 9a52028 | 2008-08-28 01:05:08 +0300 | [diff] [blame] | 718 | if (ret < 0) |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 719 | lbs_pr_err("firmware download failed\n"); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 720 | |
| 721 | err_release: |
| 722 | release_firmware(fw); |
| 723 | |
| 724 | done: |
| 725 | lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret); |
| 726 | return ret; |
| 727 | } |
| 728 | |
| 729 | |
| 730 | |
| 731 | /********************************************************************/ |
| 732 | /* Callback functions for libertas.ko */ |
| 733 | /********************************************************************/ |
| 734 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 735 | /* Send commands or data packets to the card */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 736 | static int if_cs_host_to_card(struct lbs_private *priv, |
| 737 | u8 type, |
| 738 | u8 *buf, |
| 739 | u16 nb) |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 740 | { |
| 741 | int ret = -1; |
| 742 | |
| 743 | lbs_deb_enter_args(LBS_DEB_CS, "type %d, bytes %d", type, nb); |
| 744 | |
| 745 | switch (type) { |
| 746 | case MVMS_DAT: |
Ryan Mallon | 6f05cbe | 2007-09-06 21:30:32 -0400 | [diff] [blame] | 747 | priv->dnld_sent = DNLD_DATA_SENT; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 748 | if_cs_send_data(priv, buf, nb); |
| 749 | ret = 0; |
| 750 | break; |
| 751 | case MVMS_CMD: |
Ryan Mallon | 6f05cbe | 2007-09-06 21:30:32 -0400 | [diff] [blame] | 752 | priv->dnld_sent = DNLD_CMD_SENT; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 753 | ret = if_cs_send_cmd(priv, buf, nb); |
| 754 | break; |
| 755 | default: |
Harvey Harrison | c94c93d | 2008-07-28 23:01:34 -0700 | [diff] [blame] | 756 | lbs_pr_err("%s: unsupported type %d\n", __func__, type); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret); |
| 760 | return ret; |
| 761 | } |
| 762 | |
| 763 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 764 | /********************************************************************/ |
| 765 | /* Card Services */ |
| 766 | /********************************************************************/ |
| 767 | |
| 768 | /* |
| 769 | * After a card is removed, if_cs_release() will unregister the |
| 770 | * device, and release the PCMCIA configuration. If the device is |
| 771 | * still open, this will be postponed until it is closed. |
| 772 | */ |
| 773 | static void if_cs_release(struct pcmcia_device *p_dev) |
| 774 | { |
| 775 | struct if_cs_card *card = p_dev->priv; |
| 776 | |
| 777 | lbs_deb_enter(LBS_DEB_CS); |
| 778 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 779 | free_irq(p_dev->irq.AssignedIRQ, card); |
Holger Schurig | fdfb92e | 2008-01-25 14:15:48 +0100 | [diff] [blame] | 780 | pcmcia_disable_device(p_dev); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 781 | if (card->iobase) |
| 782 | ioport_unmap(card->iobase); |
| 783 | |
| 784 | lbs_deb_leave(LBS_DEB_CS); |
| 785 | } |
| 786 | |
| 787 | |
| 788 | /* |
| 789 | * This creates an "instance" of the driver, allocating local data |
| 790 | * structures for one device. The device is registered with Card |
| 791 | * Services. |
| 792 | * |
| 793 | * The dev_link structure is initialized, but we don't actually |
| 794 | * configure the card at this point -- we wait until we receive a card |
| 795 | * insertion event. |
| 796 | */ |
Dominik Brodowski | aaa8cfd | 2009-10-18 18:28:39 +0200 | [diff] [blame] | 797 | |
| 798 | static int if_cs_ioprobe(struct pcmcia_device *p_dev, |
| 799 | cistpl_cftable_entry_t *cfg, |
| 800 | cistpl_cftable_entry_t *dflt, |
| 801 | unsigned int vcc, |
| 802 | void *priv_data) |
| 803 | { |
| 804 | p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; |
| 805 | p_dev->io.BasePort1 = cfg->io.win[0].base; |
| 806 | p_dev->io.NumPorts1 = cfg->io.win[0].len; |
| 807 | |
| 808 | /* Do we need to allocate an interrupt? */ |
| 809 | if (cfg->irq.IRQInfo1) |
| 810 | p_dev->conf.Attributes |= CONF_ENABLE_IRQ; |
| 811 | |
| 812 | /* IO window settings */ |
| 813 | if (cfg->io.nwin != 1) { |
| 814 | lbs_pr_err("wrong CIS (check number of IO windows)\n"); |
| 815 | return -ENODEV; |
| 816 | } |
| 817 | |
| 818 | /* This reserves IO space but doesn't actually enable it */ |
| 819 | return pcmcia_request_io(p_dev, &p_dev->io); |
| 820 | } |
| 821 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 822 | static int if_cs_probe(struct pcmcia_device *p_dev) |
| 823 | { |
| 824 | int ret = -ENOMEM; |
Marek Vasut | dc7d243 | 2009-03-24 21:33:43 +0100 | [diff] [blame] | 825 | unsigned int prod_id; |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 826 | struct lbs_private *priv; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 827 | struct if_cs_card *card; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 828 | |
| 829 | lbs_deb_enter(LBS_DEB_CS); |
| 830 | |
| 831 | card = kzalloc(sizeof(struct if_cs_card), GFP_KERNEL); |
| 832 | if (!card) { |
| 833 | lbs_pr_err("error in kzalloc\n"); |
| 834 | goto out; |
| 835 | } |
| 836 | card->p_dev = p_dev; |
| 837 | p_dev->priv = card; |
| 838 | |
| 839 | p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING; |
| 840 | p_dev->irq.Handler = NULL; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 841 | |
| 842 | p_dev->conf.Attributes = 0; |
| 843 | p_dev->conf.IntType = INT_MEMORY_AND_IO; |
| 844 | |
Dominik Brodowski | aaa8cfd | 2009-10-18 18:28:39 +0200 | [diff] [blame] | 845 | if (pcmcia_loop_config(p_dev, if_cs_ioprobe, NULL)) { |
| 846 | lbs_pr_err("error in pcmcia_loop_config\n"); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 847 | goto out1; |
| 848 | } |
| 849 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 850 | |
| 851 | /* |
| 852 | * Allocate an interrupt line. Note that this does not assign |
| 853 | * a handler to the interrupt, unless the 'Handler' member of |
| 854 | * the irq structure is initialized. |
| 855 | */ |
| 856 | if (p_dev->conf.Attributes & CONF_ENABLE_IRQ) { |
| 857 | ret = pcmcia_request_irq(p_dev, &p_dev->irq); |
| 858 | if (ret) { |
| 859 | lbs_pr_err("error in pcmcia_request_irq\n"); |
| 860 | goto out1; |
| 861 | } |
| 862 | } |
| 863 | |
| 864 | /* Initialize io access */ |
| 865 | card->iobase = ioport_map(p_dev->io.BasePort1, p_dev->io.NumPorts1); |
| 866 | if (!card->iobase) { |
| 867 | lbs_pr_err("error in ioport_map\n"); |
| 868 | ret = -EIO; |
| 869 | goto out1; |
| 870 | } |
| 871 | |
| 872 | /* |
| 873 | * This actually configures the PCMCIA socket -- setting up |
| 874 | * the I/O windows and the interrupt mapping, and putting the |
| 875 | * card and host interface into "Memory and IO" mode. |
| 876 | */ |
| 877 | ret = pcmcia_request_configuration(p_dev, &p_dev->conf); |
| 878 | if (ret) { |
| 879 | lbs_pr_err("error in pcmcia_request_configuration\n"); |
| 880 | goto out2; |
| 881 | } |
| 882 | |
| 883 | /* Finally, report what we've done */ |
| 884 | lbs_deb_cs("irq %d, io 0x%04x-0x%04x\n", |
| 885 | p_dev->irq.AssignedIRQ, p_dev->io.BasePort1, |
| 886 | p_dev->io.BasePort1 + p_dev->io.NumPorts1 - 1); |
| 887 | |
Marek Vasut | 9d45368 | 2009-08-21 04:08:16 +0200 | [diff] [blame] | 888 | /* |
| 889 | * Most of the libertas cards can do unaligned register access, but some |
| 890 | * weird ones can not. That's especially true for the CF8305 card. |
| 891 | */ |
| 892 | card->align_regs = 0; |
| 893 | |
Holger Schurig | 4c55523 | 2008-06-05 13:08:35 +0200 | [diff] [blame] | 894 | /* Check if we have a current silicon */ |
Marek Vasut | dc7d243 | 2009-03-24 21:33:43 +0100 | [diff] [blame] | 895 | prod_id = if_cs_read8(card, IF_CS_PRODUCT_ID); |
Marek Vasut | 9d45368 | 2009-08-21 04:08:16 +0200 | [diff] [blame] | 896 | if (if_cs_hw_is_cf8305(p_dev)) { |
| 897 | card->align_regs = 1; |
| 898 | if (prod_id < IF_CS_CF8305_B1_REV) { |
| 899 | lbs_pr_err("old chips like 8305 rev B3 " |
| 900 | "aren't supported\n"); |
| 901 | ret = -ENODEV; |
| 902 | goto out2; |
| 903 | } |
| 904 | } |
| 905 | |
Marek Vasut | dc7d243 | 2009-03-24 21:33:43 +0100 | [diff] [blame] | 906 | if (if_cs_hw_is_cf8381(p_dev) && prod_id < IF_CS_CF8381_B3_REV) { |
| 907 | lbs_pr_err("old chips like 8381 rev B3 aren't supported\n"); |
| 908 | ret = -ENODEV; |
| 909 | goto out2; |
| 910 | } |
| 911 | |
| 912 | if (if_cs_hw_is_cf8385(p_dev) && prod_id < IF_CS_CF8385_B1_REV) { |
Holger Schurig | 4c55523 | 2008-06-05 13:08:35 +0200 | [diff] [blame] | 913 | lbs_pr_err("old chips like 8385 rev B1 aren't supported\n"); |
| 914 | ret = -ENODEV; |
| 915 | goto out2; |
| 916 | } |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 917 | |
| 918 | /* Load the firmware early, before calling into libertas.ko */ |
| 919 | ret = if_cs_prog_helper(card); |
Marek Vasut | 9d45368 | 2009-08-21 04:08:16 +0200 | [diff] [blame] | 920 | if (ret == 0 && !if_cs_hw_is_cf8305(p_dev)) |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 921 | ret = if_cs_prog_real(card); |
| 922 | if (ret) |
| 923 | goto out2; |
| 924 | |
| 925 | /* Make this card known to the libertas driver */ |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 926 | priv = lbs_add_card(card, &p_dev->dev); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 927 | if (!priv) { |
| 928 | ret = -ENOMEM; |
| 929 | goto out2; |
| 930 | } |
| 931 | |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 932 | /* Finish setting up fields in lbs_private */ |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 933 | card->priv = priv; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 934 | priv->card = card; |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 935 | priv->hw_host_to_card = if_cs_host_to_card; |
Amitkumar Karwar | 4912545 | 2009-09-30 20:04:38 -0700 | [diff] [blame] | 936 | priv->enter_deep_sleep = NULL; |
| 937 | priv->exit_deep_sleep = NULL; |
| 938 | priv->reset_deep_sleep_wakeup = NULL; |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 939 | priv->fw_ready = 1; |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 940 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 941 | /* Now actually get the IRQ */ |
| 942 | ret = request_irq(p_dev->irq.AssignedIRQ, if_cs_interrupt, |
| 943 | IRQF_SHARED, DRV_NAME, card); |
| 944 | if (ret) { |
| 945 | lbs_pr_err("error in request_irq\n"); |
| 946 | goto out3; |
| 947 | } |
| 948 | |
Holger Schurig | 4ef3170 | 2007-10-09 10:41:57 +0200 | [diff] [blame] | 949 | /* Clear any interrupt cause that happend while sending |
| 950 | * firmware/initializing card */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 951 | if_cs_write16(card, IF_CS_CARD_INT_CAUSE, IF_CS_BIT_MASK); |
Ryan Mallon | 28de0b3 | 2007-09-06 21:32:42 -0400 | [diff] [blame] | 952 | if_cs_enable_ints(card); |
| 953 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 954 | /* And finally bring the card up */ |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 955 | if (lbs_start_card(priv) != 0) { |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 956 | lbs_pr_err("could not activate card\n"); |
| 957 | goto out3; |
| 958 | } |
| 959 | |
| 960 | ret = 0; |
| 961 | goto out; |
| 962 | |
| 963 | out3: |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 964 | lbs_remove_card(priv); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 965 | out2: |
| 966 | ioport_unmap(card->iobase); |
| 967 | out1: |
| 968 | pcmcia_disable_device(p_dev); |
| 969 | out: |
| 970 | lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret); |
| 971 | return ret; |
| 972 | } |
| 973 | |
| 974 | |
| 975 | /* |
| 976 | * This deletes a driver "instance". The device is de-registered with |
| 977 | * Card Services. If it has been released, all local data structures |
| 978 | * are freed. Otherwise, the structures will be freed when the device |
| 979 | * is released. |
| 980 | */ |
| 981 | static void if_cs_detach(struct pcmcia_device *p_dev) |
| 982 | { |
| 983 | struct if_cs_card *card = p_dev->priv; |
| 984 | |
| 985 | lbs_deb_enter(LBS_DEB_CS); |
| 986 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 987 | lbs_stop_card(card->priv); |
| 988 | lbs_remove_card(card->priv); |
Ryan Mallon | 28de0b3 | 2007-09-06 21:32:42 -0400 | [diff] [blame] | 989 | if_cs_disable_ints(card); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 990 | if_cs_release(p_dev); |
| 991 | kfree(card); |
| 992 | |
| 993 | lbs_deb_leave(LBS_DEB_CS); |
| 994 | } |
| 995 | |
| 996 | |
| 997 | |
| 998 | /********************************************************************/ |
| 999 | /* Module initialization */ |
| 1000 | /********************************************************************/ |
| 1001 | |
| 1002 | static struct pcmcia_device_id if_cs_ids[] = { |
Marek Vasut | 9d45368 | 2009-08-21 04:08:16 +0200 | [diff] [blame] | 1003 | PCMCIA_DEVICE_MANF_CARD(CF8305_MANFID, CF8305_CARDID), |
Marek Vasut | dc7d243 | 2009-03-24 21:33:43 +0100 | [diff] [blame] | 1004 | PCMCIA_DEVICE_MANF_CARD(CF8381_MANFID, CF8381_CARDID), |
| 1005 | PCMCIA_DEVICE_MANF_CARD(CF8385_MANFID, CF8385_CARDID), |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 1006 | PCMCIA_DEVICE_NULL, |
| 1007 | }; |
| 1008 | MODULE_DEVICE_TABLE(pcmcia, if_cs_ids); |
| 1009 | |
| 1010 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1011 | static struct pcmcia_driver lbs_driver = { |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 1012 | .owner = THIS_MODULE, |
| 1013 | .drv = { |
| 1014 | .name = DRV_NAME, |
| 1015 | }, |
| 1016 | .probe = if_cs_probe, |
| 1017 | .remove = if_cs_detach, |
| 1018 | .id_table = if_cs_ids, |
| 1019 | }; |
| 1020 | |
| 1021 | |
| 1022 | static int __init if_cs_init(void) |
| 1023 | { |
| 1024 | int ret; |
| 1025 | |
| 1026 | lbs_deb_enter(LBS_DEB_CS); |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1027 | ret = pcmcia_register_driver(&lbs_driver); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 1028 | lbs_deb_leave(LBS_DEB_CS); |
| 1029 | return ret; |
| 1030 | } |
| 1031 | |
| 1032 | |
| 1033 | static void __exit if_cs_exit(void) |
| 1034 | { |
| 1035 | lbs_deb_enter(LBS_DEB_CS); |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1036 | pcmcia_unregister_driver(&lbs_driver); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 1037 | lbs_deb_leave(LBS_DEB_CS); |
| 1038 | } |
| 1039 | |
| 1040 | |
| 1041 | module_init(if_cs_init); |
| 1042 | module_exit(if_cs_exit); |