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