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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 25 | #include <linux/slab.h> |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 26 | #include <linux/delay.h> |
| 27 | #include <linux/moduleparam.h> |
| 28 | #include <linux/firmware.h> |
| 29 | #include <linux/netdevice.h> |
| 30 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 31 | #include <pcmcia/cistpl.h> |
| 32 | #include <pcmcia/ds.h> |
| 33 | |
| 34 | #include <linux/io.h> |
| 35 | |
| 36 | #define DRV_NAME "libertas_cs" |
| 37 | |
| 38 | #include "decl.h" |
| 39 | #include "defs.h" |
| 40 | #include "dev.h" |
| 41 | |
| 42 | |
| 43 | /********************************************************************/ |
| 44 | /* Module stuff */ |
| 45 | /********************************************************************/ |
| 46 | |
| 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"); |
| 50 | |
| 51 | |
| 52 | |
| 53 | /********************************************************************/ |
| 54 | /* Data structures */ |
| 55 | /********************************************************************/ |
| 56 | |
| 57 | struct if_cs_card { |
| 58 | struct pcmcia_device *p_dev; |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 59 | struct lbs_private *priv; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 60 | void __iomem *iobase; |
Marek Vasut | 9d45368 | 2009-08-21 04:08:16 +0200 | [diff] [blame] | 61 | bool align_regs; |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame] | 62 | u32 model; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame] | 66 | enum { |
| 67 | MODEL_UNKNOWN = 0x00, |
| 68 | MODEL_8305 = 0x01, |
| 69 | MODEL_8381 = 0x02, |
| 70 | MODEL_8385 = 0x03 |
| 71 | }; |
| 72 | |
| 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" }, |
| 80 | { 0, NULL, NULL } |
| 81 | }; |
| 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"); |
| 89 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 90 | |
| 91 | /********************************************************************/ |
| 92 | /* Hardware access */ |
| 93 | /********************************************************************/ |
| 94 | |
| 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 */ |
| 99 | |
| 100 | #ifdef DEBUG_IO |
| 101 | static int debug_output = 0; |
| 102 | #else |
| 103 | /* This way the compiler optimizes the printk's away */ |
| 104 | #define debug_output 0 |
| 105 | #endif |
| 106 | |
| 107 | static inline unsigned int if_cs_read8(struct if_cs_card *card, uint reg) |
| 108 | { |
| 109 | unsigned int val = ioread8(card->iobase + reg); |
| 110 | if (debug_output) |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 111 | printk(KERN_INFO "inb %08x<%02x\n", reg, val); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 112 | return val; |
| 113 | } |
| 114 | static inline unsigned int if_cs_read16(struct if_cs_card *card, uint reg) |
| 115 | { |
| 116 | unsigned int val = ioread16(card->iobase + reg); |
| 117 | if (debug_output) |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 118 | printk(KERN_INFO "inw %08x<%04x\n", reg, val); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 119 | return val; |
| 120 | } |
| 121 | static inline void if_cs_read16_rep( |
| 122 | struct if_cs_card *card, |
| 123 | uint reg, |
| 124 | void *buf, |
| 125 | unsigned long count) |
| 126 | { |
| 127 | if (debug_output) |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 128 | printk(KERN_INFO "insw %08x<(0x%lx words)\n", |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 129 | reg, count); |
| 130 | ioread16_rep(card->iobase + reg, buf, count); |
| 131 | } |
| 132 | |
| 133 | static inline void if_cs_write8(struct if_cs_card *card, uint reg, u8 val) |
| 134 | { |
| 135 | if (debug_output) |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 136 | printk(KERN_INFO "outb %08x>%02x\n", reg, val); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 137 | iowrite8(val, card->iobase + reg); |
| 138 | } |
| 139 | |
| 140 | static inline void if_cs_write16(struct if_cs_card *card, uint reg, u16 val) |
| 141 | { |
| 142 | if (debug_output) |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 143 | printk(KERN_INFO "outw %08x>%04x\n", reg, val); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 144 | iowrite16(val, card->iobase + reg); |
| 145 | } |
| 146 | |
| 147 | static inline void if_cs_write16_rep( |
| 148 | struct if_cs_card *card, |
| 149 | uint reg, |
David Woodhouse | 6dfff89 | 2008-05-23 18:37:51 +0100 | [diff] [blame] | 150 | const void *buf, |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 151 | unsigned long count) |
| 152 | { |
| 153 | if (debug_output) |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 154 | printk(KERN_INFO "outsw %08x>(0x%lx words)\n", |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 155 | reg, count); |
| 156 | iowrite16_rep(card->iobase + reg, buf, count); |
| 157 | } |
| 158 | |
| 159 | |
| 160 | /* |
| 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. |
| 164 | * |
| 165 | * Fortunately, this function is never used once the firmware is in |
| 166 | * the card. :-) |
| 167 | * |
| 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. |
| 171 | */ |
| 172 | static int if_cs_poll_while_fw_download(struct if_cs_card *card, uint addr, u8 reg) |
| 173 | { |
| 174 | int i; |
| 175 | |
Holger Schurig | 93416c8 | 2008-05-23 10:18:26 +0200 | [diff] [blame] | 176 | for (i = 0; i < 100000; i++) { |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 177 | u8 val = if_cs_read8(card, addr); |
| 178 | if (val == reg) |
Dan Williams | 1fac36e | 2009-01-23 11:55:33 -0500 | [diff] [blame] | 179 | return 0; |
Holger Schurig | 93416c8 | 2008-05-23 10:18:26 +0200 | [diff] [blame] | 180 | udelay(5); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 181 | } |
| 182 | return -ETIME; |
| 183 | } |
| 184 | |
| 185 | |
| 186 | |
Holger Schurig | 5314325 | 2008-06-05 13:07:04 +0200 | [diff] [blame] | 187 | /* |
| 188 | * First the bitmasks for the host/card interrupt/status registers: |
| 189 | */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 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 |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 196 | |
Holger Schurig | 5314325 | 2008-06-05 13:07:04 +0200 | [diff] [blame] | 197 | |
| 198 | |
| 199 | /* |
| 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: |
| 203 | * |
| 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 |
| 209 | */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 210 | #define IF_CS_HOST_STATUS 0x00000000 |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 211 | |
Holger Schurig | 5314325 | 2008-06-05 13:07:04 +0200 | [diff] [blame] | 212 | /* |
| 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: |
| 215 | * |
| 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 |
| 221 | */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 222 | #define IF_CS_HOST_INT_CAUSE 0x00000002 |
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 host int mask register is used to enable/disable interrupt. However, |
| 226 | * I have the suspicion that disabled interrupts are lost. |
| 227 | */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 228 | #define IF_CS_HOST_INT_MASK 0x00000004 |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 229 | |
Holger Schurig | 5314325 | 2008-06-05 13:07:04 +0200 | [diff] [blame] | 230 | /* |
| 231 | * Used to send or receive data packets: |
| 232 | */ |
Holger Schurig | a78a832 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 233 | #define IF_CS_WRITE 0x00000016 |
| 234 | #define IF_CS_WRITE_LEN 0x00000014 |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 235 | #define IF_CS_READ 0x00000010 |
| 236 | #define IF_CS_READ_LEN 0x00000024 |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 237 | |
Holger Schurig | 5314325 | 2008-06-05 13:07:04 +0200 | [diff] [blame] | 238 | /* |
| 239 | * Used to send commands (and to send firmware block) and to |
| 240 | * receive command responses: |
| 241 | */ |
Holger Schurig | a78a832 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 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 |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 246 | |
Holger Schurig | 5314325 | 2008-06-05 13:07:04 +0200 | [diff] [blame] | 247 | /* |
| 248 | * The card status registers shows what the card/firmware actually |
| 249 | * accepts: |
| 250 | * |
| 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) |
| 256 | * |
| 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 |
| 259 | * automatically. |
| 260 | * |
| 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. |
| 263 | */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 264 | #define IF_CS_CARD_STATUS 0x00000020 |
| 265 | #define IF_CS_CARD_STATUS_MASK 0x7f00 |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 266 | |
Holger Schurig | 5314325 | 2008-06-05 13:07:04 +0200 | [diff] [blame] | 267 | /* |
| 268 | * The card int cause register is used by the card/firmware to notify us |
| 269 | * about the following events: |
| 270 | * |
| 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) |
| 276 | */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 277 | #define IF_CS_CARD_INT_CAUSE 0x00000022 |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 278 | |
Holger Schurig | 5314325 | 2008-06-05 13:07:04 +0200 | [diff] [blame] | 279 | /* |
| 280 | * This is used to for handshaking with the card's bootloader/helper image |
| 281 | * to synchronize downloading of firmware blocks. |
| 282 | */ |
Holger Schurig | a78a832 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 283 | #define IF_CS_SQ_READ_LOW 0x00000028 |
| 284 | #define IF_CS_SQ_HELPER_OK 0x10 |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 285 | |
Holger Schurig | 5314325 | 2008-06-05 13:07:04 +0200 | [diff] [blame] | 286 | /* |
| 287 | * The scratch register tells us ... |
| 288 | * |
| 289 | * IF_CS_SCRATCH_BOOT_OK the bootloader runs |
| 290 | * IF_CS_SCRATCH_HELPER_OK the helper firmware already runs |
| 291 | */ |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 292 | #define IF_CS_SCRATCH 0x0000003F |
Holger Schurig | 5314325 | 2008-06-05 13:07:04 +0200 | [diff] [blame] | 293 | #define IF_CS_SCRATCH_BOOT_OK 0x00 |
| 294 | #define IF_CS_SCRATCH_HELPER_OK 0x5a |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 295 | |
Holger Schurig | 4c55523 | 2008-06-05 13:08:35 +0200 | [diff] [blame] | 296 | /* |
| 297 | * Used to detect ancient chips: |
| 298 | */ |
| 299 | #define IF_CS_PRODUCT_ID 0x0000001C |
| 300 | #define IF_CS_CF8385_B1_REV 0x12 |
Marek Vasut | dc7d243 | 2009-03-24 21:33:43 +0100 | [diff] [blame] | 301 | #define IF_CS_CF8381_B3_REV 0x04 |
Marek Vasut | 9d45368 | 2009-08-21 04:08:16 +0200 | [diff] [blame] | 302 | #define IF_CS_CF8305_B1_REV 0x03 |
Holger Schurig | 4c55523 | 2008-06-05 13:08:35 +0200 | [diff] [blame] | 303 | |
Marek Vasut | dc7d243 | 2009-03-24 21:33:43 +0100 | [diff] [blame] | 304 | /* |
| 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. |
| 307 | */ |
Marek Vasut | 9d45368 | 2009-08-21 04:08:16 +0200 | [diff] [blame] | 308 | #define CF8305_MANFID 0x02db |
| 309 | #define CF8305_CARDID 0x8103 |
Marek Vasut | dc7d243 | 2009-03-24 21:33:43 +0100 | [diff] [blame] | 310 | #define CF8381_MANFID 0x02db |
| 311 | #define CF8381_CARDID 0x6064 |
| 312 | #define CF8385_MANFID 0x02df |
| 313 | #define CF8385_CARDID 0x8103 |
| 314 | |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame] | 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. |
| 317 | */ |
| 318 | static inline u32 get_model(u16 manf_id, u16 card_id) |
Marek Vasut | 9d45368 | 2009-08-21 04:08:16 +0200 | [diff] [blame] | 319 | { |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame] | 320 | /* NOTE: keep in sync with if_cs_ids */ |
| 321 | if (manf_id == CF8305_MANFID && card_id == CF8305_CARDID) |
| 322 | return MODEL_8305; |
| 323 | else if (manf_id == CF8381_MANFID && card_id == CF8381_CARDID) |
| 324 | return MODEL_8381; |
| 325 | else if (manf_id == CF8385_MANFID && card_id == CF8385_CARDID) |
| 326 | return MODEL_8385; |
| 327 | return MODEL_UNKNOWN; |
Marek Vasut | dc7d243 | 2009-03-24 21:33:43 +0100 | [diff] [blame] | 328 | } |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 329 | |
| 330 | /********************************************************************/ |
Holger Schurig | 43d01c5 | 2008-05-26 12:50:23 +0200 | [diff] [blame] | 331 | /* I/O and interrupt handling */ |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 332 | /********************************************************************/ |
| 333 | |
Holger Schurig | 43d01c5 | 2008-05-26 12:50:23 +0200 | [diff] [blame] | 334 | static inline void if_cs_enable_ints(struct if_cs_card *card) |
| 335 | { |
| 336 | lbs_deb_enter(LBS_DEB_CS); |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 337 | if_cs_write16(card, IF_CS_HOST_INT_MASK, 0); |
Holger Schurig | 43d01c5 | 2008-05-26 12:50:23 +0200 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | static inline void if_cs_disable_ints(struct if_cs_card *card) |
| 341 | { |
| 342 | lbs_deb_enter(LBS_DEB_CS); |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 343 | 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] | 344 | } |
| 345 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 346 | /* |
| 347 | * Called from if_cs_host_to_card to send a command to the hardware |
| 348 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 349 | 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] | 350 | { |
| 351 | struct if_cs_card *card = (struct if_cs_card *)priv->card; |
| 352 | int ret = -1; |
| 353 | int loops = 0; |
| 354 | |
| 355 | lbs_deb_enter(LBS_DEB_CS); |
Holger Schurig | 43d01c5 | 2008-05-26 12:50:23 +0200 | [diff] [blame] | 356 | if_cs_disable_ints(card); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 357 | |
| 358 | /* Is hardware ready? */ |
| 359 | while (1) { |
Holger Schurig | a78a832 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 360 | u16 status = if_cs_read16(card, IF_CS_CARD_STATUS); |
| 361 | if (status & IF_CS_BIT_COMMAND) |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 362 | break; |
| 363 | if (++loops > 100) { |
| 364 | lbs_pr_err("card not ready for commands\n"); |
| 365 | goto done; |
| 366 | } |
| 367 | mdelay(1); |
| 368 | } |
| 369 | |
Holger Schurig | a78a832 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 370 | if_cs_write16(card, IF_CS_CMD_LEN, nb); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 371 | |
Holger Schurig | a78a832 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 372 | if_cs_write16_rep(card, IF_CS_CMD, buf, nb / 2); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 373 | /* Are we supposed to transfer an odd amount of bytes? */ |
| 374 | if (nb & 1) |
Holger Schurig | a78a832 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 375 | if_cs_write8(card, IF_CS_CMD, buf[nb-1]); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 376 | |
| 377 | /* "Assert the download over interrupt command in the Host |
| 378 | * status register" */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 379 | if_cs_write16(card, IF_CS_HOST_STATUS, IF_CS_BIT_COMMAND); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 380 | |
| 381 | /* "Assert the download over interrupt command in the Card |
| 382 | * interrupt case register" */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 383 | 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] | 384 | ret = 0; |
| 385 | |
| 386 | done: |
Holger Schurig | 43d01c5 | 2008-05-26 12:50:23 +0200 | [diff] [blame] | 387 | if_cs_enable_ints(card); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 388 | lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret); |
| 389 | return ret; |
| 390 | } |
| 391 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 392 | /* |
| 393 | * Called from if_cs_host_to_card to send a data to the hardware |
| 394 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 395 | 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] | 396 | { |
| 397 | struct if_cs_card *card = (struct if_cs_card *)priv->card; |
Holger Schurig | 43d01c5 | 2008-05-26 12:50:23 +0200 | [diff] [blame] | 398 | u16 status; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 399 | |
| 400 | lbs_deb_enter(LBS_DEB_CS); |
Holger Schurig | 43d01c5 | 2008-05-26 12:50:23 +0200 | [diff] [blame] | 401 | if_cs_disable_ints(card); |
| 402 | |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 403 | status = if_cs_read16(card, IF_CS_CARD_STATUS); |
| 404 | BUG_ON((status & IF_CS_BIT_TX) == 0); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 405 | |
Holger Schurig | a78a832 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 406 | if_cs_write16(card, IF_CS_WRITE_LEN, nb); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 407 | |
| 408 | /* write even number of bytes, then odd byte if necessary */ |
Holger Schurig | a78a832 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 409 | if_cs_write16_rep(card, IF_CS_WRITE, buf, nb / 2); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 410 | if (nb & 1) |
Holger Schurig | a78a832 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 411 | if_cs_write8(card, IF_CS_WRITE, buf[nb-1]); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 412 | |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 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); |
Holger Schurig | 43d01c5 | 2008-05-26 12:50:23 +0200 | [diff] [blame] | 415 | if_cs_enable_ints(card); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 416 | |
| 417 | lbs_deb_leave(LBS_DEB_CS); |
| 418 | } |
| 419 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 420 | /* |
| 421 | * Get the command result out of the card. |
| 422 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 423 | 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] | 424 | { |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 425 | unsigned long flags; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 426 | int ret = -1; |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 427 | u16 status; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 428 | |
| 429 | lbs_deb_enter(LBS_DEB_CS); |
| 430 | |
| 431 | /* is hardware ready? */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 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"); |
| 435 | *len = 0; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 436 | goto out; |
| 437 | } |
| 438 | |
Holger Schurig | a78a832 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 439 | *len = if_cs_read16(priv->card, IF_CS_RESP_LEN); |
Dan Williams | ddac452 | 2007-12-11 13:49:39 -0500 | [diff] [blame] | 440 | if ((*len == 0) || (*len > LBS_CMD_BUFFER_SIZE)) { |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 441 | lbs_pr_err("card cmd buffer has invalid # of bytes (%d)\n", *len); |
| 442 | goto out; |
| 443 | } |
| 444 | |
| 445 | /* read even number of bytes, then odd byte if necessary */ |
Holger Schurig | a78a832 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 446 | 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] | 447 | if (*len & 1) |
Holger Schurig | a78a832 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 448 | data[*len-1] = if_cs_read8(priv->card, IF_CS_RESP); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 449 | |
Holger Schurig | 09d4fad | 2007-12-06 13:50:30 +0100 | [diff] [blame] | 450 | /* This is a workaround for a firmware that reports too much |
| 451 | * bytes */ |
| 452 | *len -= 8; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 453 | ret = 0; |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 454 | |
| 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); |
| 459 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 460 | out: |
| 461 | lbs_deb_leave_args(LBS_DEB_CS, "ret %d, len %d", ret, *len); |
| 462 | return ret; |
| 463 | } |
| 464 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 465 | static struct sk_buff *if_cs_receive_data(struct lbs_private *priv) |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 466 | { |
| 467 | struct sk_buff *skb = NULL; |
| 468 | u16 len; |
| 469 | u8 *data; |
| 470 | |
| 471 | lbs_deb_enter(LBS_DEB_CS); |
| 472 | |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 473 | len = if_cs_read16(priv->card, IF_CS_READ_LEN); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 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); |
Stephen Hemminger | bbfc6b7 | 2009-03-20 19:36:36 +0000 | [diff] [blame] | 476 | priv->dev->stats.rx_dropped++; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 477 | goto dat_err; |
| 478 | } |
| 479 | |
Vladimir Davydov | f31ce76b | 2007-09-06 21:41:02 -0400 | [diff] [blame] | 480 | skb = dev_alloc_skb(MRVDRV_ETH_RX_PACKET_BUFFER_SIZE + 2); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 481 | if (!skb) |
| 482 | goto out; |
Vladimir Davydov | f31ce76b | 2007-09-06 21:41:02 -0400 | [diff] [blame] | 483 | skb_put(skb, len); |
| 484 | skb_reserve(skb, 2);/* 16 byte align */ |
| 485 | data = skb->data; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 486 | |
| 487 | /* read even number of bytes, then odd byte if necessary */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 488 | 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] | 489 | if (len & 1) |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 490 | data[len-1] = if_cs_read8(priv->card, IF_CS_READ); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 491 | |
| 492 | dat_err: |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 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); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 495 | |
| 496 | out: |
| 497 | lbs_deb_leave_args(LBS_DEB_CS, "ret %p", skb); |
| 498 | return skb; |
| 499 | } |
| 500 | |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 501 | static irqreturn_t if_cs_interrupt(int irq, void *data) |
| 502 | { |
| 503 | struct if_cs_card *card = data; |
| 504 | struct lbs_private *priv = card->priv; |
| 505 | u16 cause; |
| 506 | |
| 507 | lbs_deb_enter(LBS_DEB_CS); |
| 508 | |
Holger Schurig | 43d01c5 | 2008-05-26 12:50:23 +0200 | [diff] [blame] | 509 | /* Ask card interrupt cause register if there is something for us */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 510 | cause = if_cs_read16(card, IF_CS_CARD_INT_CAUSE); |
Holger Schurig | 3073556 | 2008-06-05 13:06:15 +0200 | [diff] [blame] | 511 | lbs_deb_cs("cause 0x%04x\n", cause); |
| 512 | |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 513 | if (cause == 0) { |
| 514 | /* Not for us */ |
| 515 | return IRQ_NONE; |
| 516 | } |
| 517 | |
| 518 | if (cause == 0xffff) { |
| 519 | /* Read in junk, the card has probably been removed */ |
| 520 | card->priv->surpriseremoved = 1; |
| 521 | return IRQ_HANDLED; |
| 522 | } |
| 523 | |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 524 | if (cause & IF_CS_BIT_RX) { |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 525 | struct sk_buff *skb; |
| 526 | lbs_deb_cs("rx packet\n"); |
| 527 | skb = if_cs_receive_data(priv); |
| 528 | if (skb) |
| 529 | lbs_process_rxed_packet(priv, skb); |
| 530 | } |
| 531 | |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 532 | if (cause & IF_CS_BIT_TX) { |
Holger Schurig | 43d01c5 | 2008-05-26 12:50:23 +0200 | [diff] [blame] | 533 | lbs_deb_cs("tx done\n"); |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 534 | lbs_host_to_card_done(priv); |
| 535 | } |
| 536 | |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 537 | if (cause & IF_CS_BIT_RESP) { |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 538 | unsigned long flags; |
| 539 | u8 i; |
| 540 | |
Holger Schurig | 43d01c5 | 2008-05-26 12:50:23 +0200 | [diff] [blame] | 541 | lbs_deb_cs("cmd resp\n"); |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 542 | spin_lock_irqsave(&priv->driver_lock, flags); |
| 543 | i = (priv->resp_idx == 0) ? 1 : 0; |
| 544 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
| 545 | |
| 546 | BUG_ON(priv->resp_len[i]); |
| 547 | if_cs_receive_cmdres(priv, priv->resp_buf[i], |
| 548 | &priv->resp_len[i]); |
| 549 | |
| 550 | spin_lock_irqsave(&priv->driver_lock, flags); |
| 551 | lbs_notify_command_response(priv, i); |
| 552 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
| 553 | } |
| 554 | |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 555 | if (cause & IF_CS_BIT_EVENT) { |
Holger Schurig | a78a832 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 556 | u16 status = if_cs_read16(priv->card, IF_CS_CARD_STATUS); |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 557 | if_cs_write16(priv->card, IF_CS_HOST_INT_CAUSE, |
| 558 | IF_CS_BIT_EVENT); |
Holger Schurig | a78a832 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 559 | lbs_queue_event(priv, (status & IF_CS_CARD_STATUS_MASK) >> 8); |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 560 | } |
| 561 | |
Holger Schurig | 3073556 | 2008-06-05 13:06:15 +0200 | [diff] [blame] | 562 | /* Clear interrupt cause */ |
| 563 | if_cs_write16(card, IF_CS_CARD_INT_CAUSE, cause & IF_CS_BIT_MASK); |
| 564 | |
Holger Schurig | 43d01c5 | 2008-05-26 12:50:23 +0200 | [diff] [blame] | 565 | lbs_deb_leave(LBS_DEB_CS); |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 566 | return IRQ_HANDLED; |
| 567 | } |
| 568 | |
| 569 | |
| 570 | |
| 571 | |
| 572 | /********************************************************************/ |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 573 | /* Firmware */ |
| 574 | /********************************************************************/ |
| 575 | |
| 576 | /* |
| 577 | * Tries to program the helper firmware. |
| 578 | * |
| 579 | * Return 0 on success |
| 580 | */ |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame] | 581 | static int if_cs_prog_helper(struct if_cs_card *card, const struct firmware *fw) |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 582 | { |
| 583 | int ret = 0; |
| 584 | int sent = 0; |
| 585 | u8 scratch; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 586 | |
| 587 | lbs_deb_enter(LBS_DEB_CS); |
| 588 | |
Marek Vasut | 9d45368 | 2009-08-21 04:08:16 +0200 | [diff] [blame] | 589 | /* |
| 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. |
| 593 | */ |
| 594 | if (card->align_regs) |
| 595 | scratch = if_cs_read16(card, IF_CS_SCRATCH) >> 8; |
| 596 | else |
| 597 | scratch = if_cs_read8(card, IF_CS_SCRATCH); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 598 | |
| 599 | /* "If the value is 0x5a, the firmware is already |
| 600 | * downloaded successfully" |
| 601 | */ |
Holger Schurig | 5314325 | 2008-06-05 13:07:04 +0200 | [diff] [blame] | 602 | if (scratch == IF_CS_SCRATCH_HELPER_OK) |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 603 | goto done; |
| 604 | |
| 605 | /* "If the value is != 00, it is invalid value of register */ |
Holger Schurig | 5314325 | 2008-06-05 13:07:04 +0200 | [diff] [blame] | 606 | if (scratch != IF_CS_SCRATCH_BOOT_OK) { |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 607 | ret = -ENODEV; |
| 608 | goto done; |
| 609 | } |
| 610 | |
Andrew Morton | 4ecd41b | 2007-08-21 02:15:45 -0700 | [diff] [blame] | 611 | lbs_deb_cs("helper size %td\n", fw->size); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 612 | |
| 613 | /* "Set the 5 bytes of the helper image to 0" */ |
| 614 | /* Not needed, this contains an ARM branch instruction */ |
| 615 | |
| 616 | for (;;) { |
| 617 | /* "the number of bytes to send is 256" */ |
| 618 | int count = 256; |
| 619 | int remain = fw->size - sent; |
| 620 | |
| 621 | if (remain < count) |
| 622 | count = remain; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 623 | |
| 624 | /* "write the number of bytes to be sent to the I/O Command |
| 625 | * write length register" */ |
Holger Schurig | a78a832 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 626 | if_cs_write16(card, IF_CS_CMD_LEN, count); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 627 | |
| 628 | /* "write this to I/O Command port register as 16 bit writes */ |
| 629 | if (count) |
Holger Schurig | a78a832 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 630 | if_cs_write16_rep(card, IF_CS_CMD, |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 631 | &fw->data[sent], |
| 632 | count >> 1); |
| 633 | |
| 634 | /* "Assert the download over interrupt command in the Host |
| 635 | * status register" */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 636 | if_cs_write8(card, IF_CS_HOST_STATUS, IF_CS_BIT_COMMAND); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 637 | |
| 638 | /* "Assert the download over interrupt command in the Card |
| 639 | * interrupt case register" */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 640 | 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] | 641 | |
| 642 | /* "The host polls the Card Status register ... for 50 ms before |
| 643 | declaring a failure */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 644 | ret = if_cs_poll_while_fw_download(card, IF_CS_CARD_STATUS, |
| 645 | IF_CS_BIT_COMMAND); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 646 | if (ret < 0) { |
| 647 | lbs_pr_err("can't download helper at 0x%x, ret %d\n", |
| 648 | sent, ret); |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame] | 649 | goto done; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | if (count == 0) |
| 653 | break; |
| 654 | |
| 655 | sent += count; |
| 656 | } |
| 657 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 658 | done: |
| 659 | lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret); |
| 660 | return ret; |
| 661 | } |
| 662 | |
| 663 | |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame] | 664 | static int if_cs_prog_real(struct if_cs_card *card, const struct firmware *fw) |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 665 | { |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 666 | int ret = 0; |
| 667 | int retry = 0; |
| 668 | int len = 0; |
| 669 | int sent; |
| 670 | |
| 671 | lbs_deb_enter(LBS_DEB_CS); |
| 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 | a78a832 | 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"); |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame] | 679 | goto done; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | for (sent = 0; sent < fw->size; sent += len) { |
Holger Schurig | a78a832 | 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; |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame] | 694 | goto done; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 695 | } |
| 696 | if (retry) { |
| 697 | sent -= len; |
| 698 | } |
| 699 | |
| 700 | |
Holger Schurig | a78a832 | 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 | a78a832 | 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); |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame] | 713 | goto done; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 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 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 721 | done: |
| 722 | lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret); |
| 723 | return ret; |
| 724 | } |
| 725 | |
| 726 | |
| 727 | |
| 728 | /********************************************************************/ |
| 729 | /* Callback functions for libertas.ko */ |
| 730 | /********************************************************************/ |
| 731 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 732 | /* Send commands or data packets to the card */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 733 | static int if_cs_host_to_card(struct lbs_private *priv, |
| 734 | u8 type, |
| 735 | u8 *buf, |
| 736 | u16 nb) |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 737 | { |
| 738 | int ret = -1; |
| 739 | |
| 740 | lbs_deb_enter_args(LBS_DEB_CS, "type %d, bytes %d", type, nb); |
| 741 | |
| 742 | switch (type) { |
| 743 | case MVMS_DAT: |
Ryan Mallon | 6f05cbe | 2007-09-06 21:30:32 -0400 | [diff] [blame] | 744 | priv->dnld_sent = DNLD_DATA_SENT; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 745 | if_cs_send_data(priv, buf, nb); |
| 746 | ret = 0; |
| 747 | break; |
| 748 | case MVMS_CMD: |
Ryan Mallon | 6f05cbe | 2007-09-06 21:30:32 -0400 | [diff] [blame] | 749 | priv->dnld_sent = DNLD_CMD_SENT; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 750 | ret = if_cs_send_cmd(priv, buf, nb); |
| 751 | break; |
| 752 | default: |
Harvey Harrison | c94c93d | 2008-07-28 23:01:34 -0700 | [diff] [blame] | 753 | lbs_pr_err("%s: unsupported type %d\n", __func__, type); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret); |
| 757 | return ret; |
| 758 | } |
| 759 | |
| 760 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 761 | static void if_cs_release(struct pcmcia_device *p_dev) |
| 762 | { |
| 763 | struct if_cs_card *card = p_dev->priv; |
| 764 | |
| 765 | lbs_deb_enter(LBS_DEB_CS); |
| 766 | |
Dominik Brodowski | eb14120 | 2010-03-07 12:21:16 +0100 | [diff] [blame] | 767 | free_irq(p_dev->irq, card); |
Holger Schurig | fdfb92e | 2008-01-25 14:15:48 +0100 | [diff] [blame] | 768 | pcmcia_disable_device(p_dev); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 769 | if (card->iobase) |
| 770 | ioport_unmap(card->iobase); |
| 771 | |
| 772 | lbs_deb_leave(LBS_DEB_CS); |
| 773 | } |
| 774 | |
| 775 | |
Dominik Brodowski | 00990e7 | 2010-07-30 13:13:46 +0200 | [diff] [blame] | 776 | static int if_cs_ioprobe(struct pcmcia_device *p_dev, void *priv_data) |
Dominik Brodowski | aaa8cfd | 2009-10-18 18:28:39 +0200 | [diff] [blame] | 777 | { |
Dominik Brodowski | 00990e7 | 2010-07-30 13:13:46 +0200 | [diff] [blame] | 778 | p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH; |
Dominik Brodowski | 90abdc3 | 2010-07-24 17:23:51 +0200 | [diff] [blame] | 779 | p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO; |
Dominik Brodowski | aaa8cfd | 2009-10-18 18:28:39 +0200 | [diff] [blame] | 780 | |
Dominik Brodowski | 00990e7 | 2010-07-30 13:13:46 +0200 | [diff] [blame] | 781 | if (p_dev->resource[1]->end) { |
Dominik Brodowski | aaa8cfd | 2009-10-18 18:28:39 +0200 | [diff] [blame] | 782 | lbs_pr_err("wrong CIS (check number of IO windows)\n"); |
| 783 | return -ENODEV; |
| 784 | } |
| 785 | |
| 786 | /* This reserves IO space but doesn't actually enable it */ |
Dominik Brodowski | 90abdc3 | 2010-07-24 17:23:51 +0200 | [diff] [blame] | 787 | return pcmcia_request_io(p_dev); |
Dominik Brodowski | aaa8cfd | 2009-10-18 18:28:39 +0200 | [diff] [blame] | 788 | } |
| 789 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 790 | static int if_cs_probe(struct pcmcia_device *p_dev) |
| 791 | { |
| 792 | int ret = -ENOMEM; |
Marek Vasut | dc7d243 | 2009-03-24 21:33:43 +0100 | [diff] [blame] | 793 | unsigned int prod_id; |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 794 | struct lbs_private *priv; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 795 | struct if_cs_card *card; |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame] | 796 | const struct firmware *helper = NULL; |
| 797 | const struct firmware *mainfw = NULL; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 798 | |
| 799 | lbs_deb_enter(LBS_DEB_CS); |
| 800 | |
| 801 | card = kzalloc(sizeof(struct if_cs_card), GFP_KERNEL); |
| 802 | if (!card) { |
| 803 | lbs_pr_err("error in kzalloc\n"); |
| 804 | goto out; |
| 805 | } |
| 806 | card->p_dev = p_dev; |
| 807 | p_dev->priv = card; |
| 808 | |
Dominik Brodowski | 00990e7 | 2010-07-30 13:13:46 +0200 | [diff] [blame] | 809 | p_dev->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO; |
| 810 | |
Dominik Brodowski | aaa8cfd | 2009-10-18 18:28:39 +0200 | [diff] [blame] | 811 | if (pcmcia_loop_config(p_dev, if_cs_ioprobe, NULL)) { |
| 812 | lbs_pr_err("error in pcmcia_loop_config\n"); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 813 | goto out1; |
| 814 | } |
| 815 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 816 | /* |
| 817 | * Allocate an interrupt line. Note that this does not assign |
| 818 | * a handler to the interrupt, unless the 'Handler' member of |
| 819 | * the irq structure is initialized. |
| 820 | */ |
Dominik Brodowski | eb14120 | 2010-03-07 12:21:16 +0100 | [diff] [blame] | 821 | if (!p_dev->irq) |
| 822 | goto out1; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 823 | |
| 824 | /* Initialize io access */ |
Dominik Brodowski | 9a017a9 | 2010-07-24 15:58:54 +0200 | [diff] [blame] | 825 | card->iobase = ioport_map(p_dev->resource[0]->start, |
| 826 | resource_size(p_dev->resource[0])); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 827 | if (!card->iobase) { |
| 828 | lbs_pr_err("error in ioport_map\n"); |
| 829 | ret = -EIO; |
| 830 | goto out1; |
| 831 | } |
| 832 | |
Dominik Brodowski | 1ac71e5 | 2010-07-29 19:27:09 +0200 | [diff] [blame] | 833 | ret = pcmcia_enable_device(p_dev); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 834 | if (ret) { |
Dominik Brodowski | 1ac71e5 | 2010-07-29 19:27:09 +0200 | [diff] [blame] | 835 | lbs_pr_err("error in pcmcia_enable_device\n"); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 836 | goto out2; |
| 837 | } |
| 838 | |
| 839 | /* Finally, report what we've done */ |
Dominik Brodowski | 9a017a9 | 2010-07-24 15:58:54 +0200 | [diff] [blame] | 840 | lbs_deb_cs("irq %d, io %pR", p_dev->irq, p_dev->resource[0]); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 841 | |
Marek Vasut | 9d45368 | 2009-08-21 04:08:16 +0200 | [diff] [blame] | 842 | /* |
| 843 | * Most of the libertas cards can do unaligned register access, but some |
| 844 | * weird ones can not. That's especially true for the CF8305 card. |
| 845 | */ |
| 846 | card->align_regs = 0; |
| 847 | |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame] | 848 | card->model = get_model(p_dev->manf_id, p_dev->card_id); |
| 849 | if (card->model == MODEL_UNKNOWN) { |
| 850 | lbs_pr_err("unsupported manf_id 0x%04x / card_id 0x%04x\n", |
| 851 | p_dev->manf_id, p_dev->card_id); |
| 852 | goto out2; |
| 853 | } |
| 854 | |
Holger Schurig | 4c55523 | 2008-06-05 13:08:35 +0200 | [diff] [blame] | 855 | /* Check if we have a current silicon */ |
Marek Vasut | dc7d243 | 2009-03-24 21:33:43 +0100 | [diff] [blame] | 856 | prod_id = if_cs_read8(card, IF_CS_PRODUCT_ID); |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame] | 857 | if (card->model == MODEL_8305) { |
Marek Vasut | 9d45368 | 2009-08-21 04:08:16 +0200 | [diff] [blame] | 858 | card->align_regs = 1; |
| 859 | if (prod_id < IF_CS_CF8305_B1_REV) { |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame] | 860 | lbs_pr_err("8305 rev B0 and older are not supported\n"); |
Marek Vasut | 9d45368 | 2009-08-21 04:08:16 +0200 | [diff] [blame] | 861 | ret = -ENODEV; |
| 862 | goto out2; |
| 863 | } |
| 864 | } |
| 865 | |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame] | 866 | if ((card->model == MODEL_8381) && prod_id < IF_CS_CF8381_B3_REV) { |
| 867 | lbs_pr_err("8381 rev B2 and older are not supported\n"); |
Marek Vasut | dc7d243 | 2009-03-24 21:33:43 +0100 | [diff] [blame] | 868 | ret = -ENODEV; |
| 869 | goto out2; |
| 870 | } |
| 871 | |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame] | 872 | if ((card->model == MODEL_8385) && prod_id < IF_CS_CF8385_B1_REV) { |
| 873 | lbs_pr_err("8385 rev B0 and older are not supported\n"); |
Holger Schurig | 4c55523 | 2008-06-05 13:08:35 +0200 | [diff] [blame] | 874 | ret = -ENODEV; |
| 875 | goto out2; |
| 876 | } |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 877 | |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame] | 878 | ret = lbs_get_firmware(&p_dev->dev, NULL, NULL, card->model, |
| 879 | &fw_table[0], &helper, &mainfw); |
| 880 | if (ret) { |
| 881 | lbs_pr_err("failed to find firmware (%d)\n", ret); |
| 882 | goto out2; |
| 883 | } |
| 884 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 885 | /* Load the firmware early, before calling into libertas.ko */ |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame] | 886 | ret = if_cs_prog_helper(card, helper); |
| 887 | if (ret == 0 && (card->model != MODEL_8305)) |
| 888 | ret = if_cs_prog_real(card, mainfw); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 889 | if (ret) |
| 890 | goto out2; |
| 891 | |
| 892 | /* Make this card known to the libertas driver */ |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 893 | priv = lbs_add_card(card, &p_dev->dev); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 894 | if (!priv) { |
| 895 | ret = -ENOMEM; |
| 896 | goto out2; |
| 897 | } |
| 898 | |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 899 | /* Finish setting up fields in lbs_private */ |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 900 | card->priv = priv; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 901 | priv->card = card; |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 902 | priv->hw_host_to_card = if_cs_host_to_card; |
Amitkumar Karwar | 4912545 | 2009-09-30 20:04:38 -0700 | [diff] [blame] | 903 | priv->enter_deep_sleep = NULL; |
| 904 | priv->exit_deep_sleep = NULL; |
| 905 | priv->reset_deep_sleep_wakeup = NULL; |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 906 | priv->fw_ready = 1; |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 907 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 908 | /* Now actually get the IRQ */ |
Dominik Brodowski | eb14120 | 2010-03-07 12:21:16 +0100 | [diff] [blame] | 909 | ret = request_irq(p_dev->irq, if_cs_interrupt, |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 910 | IRQF_SHARED, DRV_NAME, card); |
| 911 | if (ret) { |
| 912 | lbs_pr_err("error in request_irq\n"); |
| 913 | goto out3; |
| 914 | } |
| 915 | |
Holger Schurig | 4ef3170 | 2007-10-09 10:41:57 +0200 | [diff] [blame] | 916 | /* Clear any interrupt cause that happend while sending |
| 917 | * firmware/initializing card */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 918 | 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] | 919 | if_cs_enable_ints(card); |
| 920 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 921 | /* And finally bring the card up */ |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 922 | if (lbs_start_card(priv) != 0) { |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 923 | lbs_pr_err("could not activate card\n"); |
| 924 | goto out3; |
| 925 | } |
| 926 | |
| 927 | ret = 0; |
| 928 | goto out; |
| 929 | |
| 930 | out3: |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 931 | lbs_remove_card(priv); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 932 | out2: |
| 933 | ioport_unmap(card->iobase); |
| 934 | out1: |
| 935 | pcmcia_disable_device(p_dev); |
| 936 | out: |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame] | 937 | if (helper) |
| 938 | release_firmware(helper); |
| 939 | if (mainfw) |
| 940 | release_firmware(mainfw); |
| 941 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 942 | lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret); |
| 943 | return ret; |
| 944 | } |
| 945 | |
| 946 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 947 | static void if_cs_detach(struct pcmcia_device *p_dev) |
| 948 | { |
| 949 | struct if_cs_card *card = p_dev->priv; |
| 950 | |
| 951 | lbs_deb_enter(LBS_DEB_CS); |
| 952 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 953 | lbs_stop_card(card->priv); |
| 954 | lbs_remove_card(card->priv); |
Ryan Mallon | 28de0b3 | 2007-09-06 21:32:42 -0400 | [diff] [blame] | 955 | if_cs_disable_ints(card); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 956 | if_cs_release(p_dev); |
| 957 | kfree(card); |
| 958 | |
| 959 | lbs_deb_leave(LBS_DEB_CS); |
| 960 | } |
| 961 | |
| 962 | |
| 963 | |
| 964 | /********************************************************************/ |
| 965 | /* Module initialization */ |
| 966 | /********************************************************************/ |
| 967 | |
| 968 | static struct pcmcia_device_id if_cs_ids[] = { |
Marek Vasut | 9d45368 | 2009-08-21 04:08:16 +0200 | [diff] [blame] | 969 | PCMCIA_DEVICE_MANF_CARD(CF8305_MANFID, CF8305_CARDID), |
Marek Vasut | dc7d243 | 2009-03-24 21:33:43 +0100 | [diff] [blame] | 970 | PCMCIA_DEVICE_MANF_CARD(CF8381_MANFID, CF8381_CARDID), |
| 971 | PCMCIA_DEVICE_MANF_CARD(CF8385_MANFID, CF8385_CARDID), |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame] | 972 | /* NOTE: keep in sync with get_model() */ |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 973 | PCMCIA_DEVICE_NULL, |
| 974 | }; |
| 975 | MODULE_DEVICE_TABLE(pcmcia, if_cs_ids); |
| 976 | |
| 977 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 978 | static struct pcmcia_driver lbs_driver = { |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 979 | .owner = THIS_MODULE, |
Dominik Brodowski | 2e9b981 | 2010-08-08 11:36:26 +0200 | [diff] [blame] | 980 | .name = DRV_NAME, |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 981 | .probe = if_cs_probe, |
| 982 | .remove = if_cs_detach, |
| 983 | .id_table = if_cs_ids, |
| 984 | }; |
| 985 | |
| 986 | |
| 987 | static int __init if_cs_init(void) |
| 988 | { |
| 989 | int ret; |
| 990 | |
| 991 | lbs_deb_enter(LBS_DEB_CS); |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 992 | ret = pcmcia_register_driver(&lbs_driver); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 993 | lbs_deb_leave(LBS_DEB_CS); |
| 994 | return ret; |
| 995 | } |
| 996 | |
| 997 | |
| 998 | static void __exit if_cs_exit(void) |
| 999 | { |
| 1000 | lbs_deb_enter(LBS_DEB_CS); |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1001 | pcmcia_unregister_driver(&lbs_driver); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 1002 | lbs_deb_leave(LBS_DEB_CS); |
| 1003 | } |
| 1004 | |
| 1005 | |
| 1006 | module_init(if_cs_init); |
| 1007 | module_exit(if_cs_exit); |