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 | |
| 31 | #include <pcmcia/cs_types.h> |
| 32 | #include <pcmcia/cs.h> |
| 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 | |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame^] | 317 | /* FIXME: just use the 'driver_info' field of 'struct pcmcia_device_id' when |
| 318 | * that gets fixed. Currently there's no way to access it from the probe hook. |
| 319 | */ |
| 320 | static inline u32 get_model(u16 manf_id, u16 card_id) |
Marek Vasut | 9d45368 | 2009-08-21 04:08:16 +0200 | [diff] [blame] | 321 | { |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame^] | 322 | /* NOTE: keep in sync with if_cs_ids */ |
| 323 | if (manf_id == CF8305_MANFID && card_id == CF8305_CARDID) |
| 324 | return MODEL_8305; |
| 325 | else if (manf_id == CF8381_MANFID && card_id == CF8381_CARDID) |
| 326 | return MODEL_8381; |
| 327 | else if (manf_id == CF8385_MANFID && card_id == CF8385_CARDID) |
| 328 | return MODEL_8385; |
| 329 | return MODEL_UNKNOWN; |
Marek Vasut | dc7d243 | 2009-03-24 21:33:43 +0100 | [diff] [blame] | 330 | } |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 331 | |
| 332 | /********************************************************************/ |
Holger Schurig | 43d01c5 | 2008-05-26 12:50:23 +0200 | [diff] [blame] | 333 | /* I/O and interrupt handling */ |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 334 | /********************************************************************/ |
| 335 | |
Holger Schurig | 43d01c5 | 2008-05-26 12:50:23 +0200 | [diff] [blame] | 336 | static inline void if_cs_enable_ints(struct if_cs_card *card) |
| 337 | { |
| 338 | lbs_deb_enter(LBS_DEB_CS); |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 339 | if_cs_write16(card, IF_CS_HOST_INT_MASK, 0); |
Holger Schurig | 43d01c5 | 2008-05-26 12:50:23 +0200 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | static inline void if_cs_disable_ints(struct if_cs_card *card) |
| 343 | { |
| 344 | lbs_deb_enter(LBS_DEB_CS); |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 345 | 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] | 346 | } |
| 347 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 348 | /* |
| 349 | * Called from if_cs_host_to_card to send a command to the hardware |
| 350 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 351 | 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] | 352 | { |
| 353 | struct if_cs_card *card = (struct if_cs_card *)priv->card; |
| 354 | int ret = -1; |
| 355 | int loops = 0; |
| 356 | |
| 357 | lbs_deb_enter(LBS_DEB_CS); |
Holger Schurig | 43d01c5 | 2008-05-26 12:50:23 +0200 | [diff] [blame] | 358 | if_cs_disable_ints(card); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 359 | |
| 360 | /* Is hardware ready? */ |
| 361 | while (1) { |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 362 | u16 status = if_cs_read16(card, IF_CS_CARD_STATUS); |
| 363 | if (status & IF_CS_BIT_COMMAND) |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 364 | break; |
| 365 | if (++loops > 100) { |
| 366 | lbs_pr_err("card not ready for commands\n"); |
| 367 | goto done; |
| 368 | } |
| 369 | mdelay(1); |
| 370 | } |
| 371 | |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 372 | if_cs_write16(card, IF_CS_CMD_LEN, nb); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 373 | |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 374 | if_cs_write16_rep(card, IF_CS_CMD, buf, nb / 2); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 375 | /* Are we supposed to transfer an odd amount of bytes? */ |
| 376 | if (nb & 1) |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 377 | if_cs_write8(card, IF_CS_CMD, buf[nb-1]); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 378 | |
| 379 | /* "Assert the download over interrupt command in the Host |
| 380 | * status register" */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 381 | if_cs_write16(card, IF_CS_HOST_STATUS, IF_CS_BIT_COMMAND); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 382 | |
| 383 | /* "Assert the download over interrupt command in the Card |
| 384 | * interrupt case register" */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 385 | 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] | 386 | ret = 0; |
| 387 | |
| 388 | done: |
Holger Schurig | 43d01c5 | 2008-05-26 12:50:23 +0200 | [diff] [blame] | 389 | if_cs_enable_ints(card); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 390 | lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret); |
| 391 | return ret; |
| 392 | } |
| 393 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 394 | /* |
| 395 | * Called from if_cs_host_to_card to send a data to the hardware |
| 396 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 397 | 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] | 398 | { |
| 399 | struct if_cs_card *card = (struct if_cs_card *)priv->card; |
Holger Schurig | 43d01c5 | 2008-05-26 12:50:23 +0200 | [diff] [blame] | 400 | u16 status; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 401 | |
| 402 | lbs_deb_enter(LBS_DEB_CS); |
Holger Schurig | 43d01c5 | 2008-05-26 12:50:23 +0200 | [diff] [blame] | 403 | if_cs_disable_ints(card); |
| 404 | |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 405 | status = if_cs_read16(card, IF_CS_CARD_STATUS); |
| 406 | BUG_ON((status & IF_CS_BIT_TX) == 0); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 407 | |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 408 | if_cs_write16(card, IF_CS_WRITE_LEN, nb); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 409 | |
| 410 | /* write even number of bytes, then odd byte if necessary */ |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 411 | if_cs_write16_rep(card, IF_CS_WRITE, buf, nb / 2); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 412 | if (nb & 1) |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 413 | if_cs_write8(card, IF_CS_WRITE, buf[nb-1]); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 414 | |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 415 | if_cs_write16(card, IF_CS_HOST_STATUS, IF_CS_BIT_TX); |
| 416 | 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] | 417 | if_cs_enable_ints(card); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 418 | |
| 419 | lbs_deb_leave(LBS_DEB_CS); |
| 420 | } |
| 421 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 422 | /* |
| 423 | * Get the command result out of the card. |
| 424 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 425 | 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] | 426 | { |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 427 | unsigned long flags; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 428 | int ret = -1; |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 429 | u16 status; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 430 | |
| 431 | lbs_deb_enter(LBS_DEB_CS); |
| 432 | |
| 433 | /* is hardware ready? */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 434 | status = if_cs_read16(priv->card, IF_CS_CARD_STATUS); |
| 435 | if ((status & IF_CS_BIT_RESP) == 0) { |
| 436 | lbs_pr_err("no cmd response in card\n"); |
| 437 | *len = 0; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 438 | goto out; |
| 439 | } |
| 440 | |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 441 | *len = if_cs_read16(priv->card, IF_CS_RESP_LEN); |
Dan Williams | ddac452 | 2007-12-11 13:49:39 -0500 | [diff] [blame] | 442 | if ((*len == 0) || (*len > LBS_CMD_BUFFER_SIZE)) { |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 443 | lbs_pr_err("card cmd buffer has invalid # of bytes (%d)\n", *len); |
| 444 | goto out; |
| 445 | } |
| 446 | |
| 447 | /* read even number of bytes, then odd byte if necessary */ |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 448 | 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] | 449 | if (*len & 1) |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 450 | data[*len-1] = if_cs_read8(priv->card, IF_CS_RESP); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 451 | |
Holger Schurig | 09d4fad | 2007-12-06 13:50:30 +0100 | [diff] [blame] | 452 | /* This is a workaround for a firmware that reports too much |
| 453 | * bytes */ |
| 454 | *len -= 8; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 455 | ret = 0; |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 456 | |
| 457 | /* Clear this flag again */ |
| 458 | spin_lock_irqsave(&priv->driver_lock, flags); |
| 459 | priv->dnld_sent = DNLD_RES_RECEIVED; |
| 460 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
| 461 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 462 | out: |
| 463 | lbs_deb_leave_args(LBS_DEB_CS, "ret %d, len %d", ret, *len); |
| 464 | return ret; |
| 465 | } |
| 466 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 467 | static struct sk_buff *if_cs_receive_data(struct lbs_private *priv) |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 468 | { |
| 469 | struct sk_buff *skb = NULL; |
| 470 | u16 len; |
| 471 | u8 *data; |
| 472 | |
| 473 | lbs_deb_enter(LBS_DEB_CS); |
| 474 | |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 475 | len = if_cs_read16(priv->card, IF_CS_READ_LEN); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 476 | if (len == 0 || len > MRVDRV_ETH_RX_PACKET_BUFFER_SIZE) { |
| 477 | 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] | 478 | priv->dev->stats.rx_dropped++; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 479 | goto dat_err; |
| 480 | } |
| 481 | |
Vladimir Davydov | f31ce76b | 2007-09-06 21:41:02 -0400 | [diff] [blame] | 482 | skb = dev_alloc_skb(MRVDRV_ETH_RX_PACKET_BUFFER_SIZE + 2); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 483 | if (!skb) |
| 484 | goto out; |
Vladimir Davydov | f31ce76b | 2007-09-06 21:41:02 -0400 | [diff] [blame] | 485 | skb_put(skb, len); |
| 486 | skb_reserve(skb, 2);/* 16 byte align */ |
| 487 | data = skb->data; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 488 | |
| 489 | /* read even number of bytes, then odd byte if necessary */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 490 | 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] | 491 | if (len & 1) |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 492 | data[len-1] = if_cs_read8(priv->card, IF_CS_READ); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 493 | |
| 494 | dat_err: |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 495 | if_cs_write16(priv->card, IF_CS_HOST_STATUS, IF_CS_BIT_RX); |
| 496 | 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] | 497 | |
| 498 | out: |
| 499 | lbs_deb_leave_args(LBS_DEB_CS, "ret %p", skb); |
| 500 | return skb; |
| 501 | } |
| 502 | |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 503 | static irqreturn_t if_cs_interrupt(int irq, void *data) |
| 504 | { |
| 505 | struct if_cs_card *card = data; |
| 506 | struct lbs_private *priv = card->priv; |
| 507 | u16 cause; |
| 508 | |
| 509 | lbs_deb_enter(LBS_DEB_CS); |
| 510 | |
Holger Schurig | 43d01c5 | 2008-05-26 12:50:23 +0200 | [diff] [blame] | 511 | /* Ask card interrupt cause register if there is something for us */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 512 | cause = if_cs_read16(card, IF_CS_CARD_INT_CAUSE); |
Holger Schurig | 3073556 | 2008-06-05 13:06:15 +0200 | [diff] [blame] | 513 | lbs_deb_cs("cause 0x%04x\n", cause); |
| 514 | |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 515 | if (cause == 0) { |
| 516 | /* Not for us */ |
| 517 | return IRQ_NONE; |
| 518 | } |
| 519 | |
| 520 | if (cause == 0xffff) { |
| 521 | /* Read in junk, the card has probably been removed */ |
| 522 | card->priv->surpriseremoved = 1; |
| 523 | return IRQ_HANDLED; |
| 524 | } |
| 525 | |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 526 | if (cause & IF_CS_BIT_RX) { |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 527 | struct sk_buff *skb; |
| 528 | lbs_deb_cs("rx packet\n"); |
| 529 | skb = if_cs_receive_data(priv); |
| 530 | if (skb) |
| 531 | lbs_process_rxed_packet(priv, skb); |
| 532 | } |
| 533 | |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 534 | if (cause & IF_CS_BIT_TX) { |
Holger Schurig | 43d01c5 | 2008-05-26 12:50:23 +0200 | [diff] [blame] | 535 | lbs_deb_cs("tx done\n"); |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 536 | lbs_host_to_card_done(priv); |
| 537 | } |
| 538 | |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 539 | if (cause & IF_CS_BIT_RESP) { |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 540 | unsigned long flags; |
| 541 | u8 i; |
| 542 | |
Holger Schurig | 43d01c5 | 2008-05-26 12:50:23 +0200 | [diff] [blame] | 543 | lbs_deb_cs("cmd resp\n"); |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 544 | spin_lock_irqsave(&priv->driver_lock, flags); |
| 545 | i = (priv->resp_idx == 0) ? 1 : 0; |
| 546 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
| 547 | |
| 548 | BUG_ON(priv->resp_len[i]); |
| 549 | if_cs_receive_cmdres(priv, priv->resp_buf[i], |
| 550 | &priv->resp_len[i]); |
| 551 | |
| 552 | spin_lock_irqsave(&priv->driver_lock, flags); |
| 553 | lbs_notify_command_response(priv, i); |
| 554 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
| 555 | } |
| 556 | |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 557 | if (cause & IF_CS_BIT_EVENT) { |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 558 | u16 status = if_cs_read16(priv->card, IF_CS_CARD_STATUS); |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 559 | if_cs_write16(priv->card, IF_CS_HOST_INT_CAUSE, |
| 560 | IF_CS_BIT_EVENT); |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 561 | lbs_queue_event(priv, (status & IF_CS_CARD_STATUS_MASK) >> 8); |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 562 | } |
| 563 | |
Holger Schurig | 3073556 | 2008-06-05 13:06:15 +0200 | [diff] [blame] | 564 | /* Clear interrupt cause */ |
| 565 | if_cs_write16(card, IF_CS_CARD_INT_CAUSE, cause & IF_CS_BIT_MASK); |
| 566 | |
Holger Schurig | 43d01c5 | 2008-05-26 12:50:23 +0200 | [diff] [blame] | 567 | lbs_deb_leave(LBS_DEB_CS); |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 568 | return IRQ_HANDLED; |
| 569 | } |
| 570 | |
| 571 | |
| 572 | |
| 573 | |
| 574 | /********************************************************************/ |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 575 | /* Firmware */ |
| 576 | /********************************************************************/ |
| 577 | |
| 578 | /* |
| 579 | * Tries to program the helper firmware. |
| 580 | * |
| 581 | * Return 0 on success |
| 582 | */ |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame^] | 583 | 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] | 584 | { |
| 585 | int ret = 0; |
| 586 | int sent = 0; |
| 587 | u8 scratch; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 588 | |
| 589 | lbs_deb_enter(LBS_DEB_CS); |
| 590 | |
Marek Vasut | 9d45368 | 2009-08-21 04:08:16 +0200 | [diff] [blame] | 591 | /* |
| 592 | * This is the only place where an unaligned register access happens on |
| 593 | * the CF8305 card, therefore for the sake of speed of the driver, we do |
| 594 | * the alignment correction here. |
| 595 | */ |
| 596 | if (card->align_regs) |
| 597 | scratch = if_cs_read16(card, IF_CS_SCRATCH) >> 8; |
| 598 | else |
| 599 | scratch = if_cs_read8(card, IF_CS_SCRATCH); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 600 | |
| 601 | /* "If the value is 0x5a, the firmware is already |
| 602 | * downloaded successfully" |
| 603 | */ |
Holger Schurig | 5314325 | 2008-06-05 13:07:04 +0200 | [diff] [blame] | 604 | if (scratch == IF_CS_SCRATCH_HELPER_OK) |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 605 | goto done; |
| 606 | |
| 607 | /* "If the value is != 00, it is invalid value of register */ |
Holger Schurig | 5314325 | 2008-06-05 13:07:04 +0200 | [diff] [blame] | 608 | if (scratch != IF_CS_SCRATCH_BOOT_OK) { |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 609 | ret = -ENODEV; |
| 610 | goto done; |
| 611 | } |
| 612 | |
Andrew Morton | 4ecd41b | 2007-08-21 02:15:45 -0700 | [diff] [blame] | 613 | lbs_deb_cs("helper size %td\n", fw->size); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 614 | |
| 615 | /* "Set the 5 bytes of the helper image to 0" */ |
| 616 | /* Not needed, this contains an ARM branch instruction */ |
| 617 | |
| 618 | for (;;) { |
| 619 | /* "the number of bytes to send is 256" */ |
| 620 | int count = 256; |
| 621 | int remain = fw->size - sent; |
| 622 | |
| 623 | if (remain < count) |
| 624 | count = remain; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 625 | |
| 626 | /* "write the number of bytes to be sent to the I/O Command |
| 627 | * write length register" */ |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 628 | if_cs_write16(card, IF_CS_CMD_LEN, count); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 629 | |
| 630 | /* "write this to I/O Command port register as 16 bit writes */ |
| 631 | if (count) |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 632 | if_cs_write16_rep(card, IF_CS_CMD, |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 633 | &fw->data[sent], |
| 634 | count >> 1); |
| 635 | |
| 636 | /* "Assert the download over interrupt command in the Host |
| 637 | * status register" */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 638 | if_cs_write8(card, IF_CS_HOST_STATUS, IF_CS_BIT_COMMAND); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 639 | |
| 640 | /* "Assert the download over interrupt command in the Card |
| 641 | * interrupt case register" */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 642 | 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] | 643 | |
| 644 | /* "The host polls the Card Status register ... for 50 ms before |
| 645 | declaring a failure */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 646 | ret = if_cs_poll_while_fw_download(card, IF_CS_CARD_STATUS, |
| 647 | IF_CS_BIT_COMMAND); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 648 | if (ret < 0) { |
| 649 | lbs_pr_err("can't download helper at 0x%x, ret %d\n", |
| 650 | sent, ret); |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame^] | 651 | goto done; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | if (count == 0) |
| 655 | break; |
| 656 | |
| 657 | sent += count; |
| 658 | } |
| 659 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 660 | done: |
| 661 | lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret); |
| 662 | return ret; |
| 663 | } |
| 664 | |
| 665 | |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame^] | 666 | 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] | 667 | { |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 668 | int ret = 0; |
| 669 | int retry = 0; |
| 670 | int len = 0; |
| 671 | int sent; |
| 672 | |
| 673 | lbs_deb_enter(LBS_DEB_CS); |
| 674 | |
Andrew Morton | 4ecd41b | 2007-08-21 02:15:45 -0700 | [diff] [blame] | 675 | lbs_deb_cs("fw size %td\n", fw->size); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 676 | |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 677 | ret = if_cs_poll_while_fw_download(card, IF_CS_SQ_READ_LOW, |
| 678 | IF_CS_SQ_HELPER_OK); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 679 | if (ret < 0) { |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 680 | lbs_pr_err("helper firmware doesn't answer\n"); |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame^] | 681 | goto done; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | for (sent = 0; sent < fw->size; sent += len) { |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 685 | len = if_cs_read16(card, IF_CS_SQ_READ_LOW); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 686 | if (len & 1) { |
| 687 | retry++; |
| 688 | lbs_pr_info("odd, need to retry this firmware block\n"); |
| 689 | } else { |
| 690 | retry = 0; |
| 691 | } |
| 692 | |
| 693 | if (retry > 20) { |
| 694 | lbs_pr_err("could not download firmware\n"); |
| 695 | ret = -ENODEV; |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame^] | 696 | goto done; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 697 | } |
| 698 | if (retry) { |
| 699 | sent -= len; |
| 700 | } |
| 701 | |
| 702 | |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 703 | if_cs_write16(card, IF_CS_CMD_LEN, len); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 704 | |
Holger Schurig | a78a8325 | 2008-06-05 13:09:50 +0200 | [diff] [blame] | 705 | if_cs_write16_rep(card, IF_CS_CMD, |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 706 | &fw->data[sent], |
| 707 | (len+1) >> 1); |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 708 | if_cs_write8(card, IF_CS_HOST_STATUS, IF_CS_BIT_COMMAND); |
| 709 | 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] | 710 | |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 711 | ret = if_cs_poll_while_fw_download(card, IF_CS_CARD_STATUS, |
| 712 | IF_CS_BIT_COMMAND); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 713 | if (ret < 0) { |
| 714 | lbs_pr_err("can't download firmware at 0x%x\n", sent); |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame^] | 715 | goto done; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 716 | } |
| 717 | } |
| 718 | |
| 719 | ret = if_cs_poll_while_fw_download(card, IF_CS_SCRATCH, 0x5a); |
Adrian Bunk | 9a52028 | 2008-08-28 01:05:08 +0300 | [diff] [blame] | 720 | if (ret < 0) |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 721 | lbs_pr_err("firmware download failed\n"); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 722 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 723 | done: |
| 724 | lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret); |
| 725 | return ret; |
| 726 | } |
| 727 | |
| 728 | |
| 729 | |
| 730 | /********************************************************************/ |
| 731 | /* Callback functions for libertas.ko */ |
| 732 | /********************************************************************/ |
| 733 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 734 | /* Send commands or data packets to the card */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 735 | static int if_cs_host_to_card(struct lbs_private *priv, |
| 736 | u8 type, |
| 737 | u8 *buf, |
| 738 | u16 nb) |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 739 | { |
| 740 | int ret = -1; |
| 741 | |
| 742 | lbs_deb_enter_args(LBS_DEB_CS, "type %d, bytes %d", type, nb); |
| 743 | |
| 744 | switch (type) { |
| 745 | case MVMS_DAT: |
Ryan Mallon | 6f05cbe | 2007-09-06 21:30:32 -0400 | [diff] [blame] | 746 | priv->dnld_sent = DNLD_DATA_SENT; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 747 | if_cs_send_data(priv, buf, nb); |
| 748 | ret = 0; |
| 749 | break; |
| 750 | case MVMS_CMD: |
Ryan Mallon | 6f05cbe | 2007-09-06 21:30:32 -0400 | [diff] [blame] | 751 | priv->dnld_sent = DNLD_CMD_SENT; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 752 | ret = if_cs_send_cmd(priv, buf, nb); |
| 753 | break; |
| 754 | default: |
Harvey Harrison | c94c93d | 2008-07-28 23:01:34 -0700 | [diff] [blame] | 755 | lbs_pr_err("%s: unsupported type %d\n", __func__, type); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret); |
| 759 | return ret; |
| 760 | } |
| 761 | |
| 762 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 763 | /********************************************************************/ |
| 764 | /* Card Services */ |
| 765 | /********************************************************************/ |
| 766 | |
| 767 | /* |
| 768 | * After a card is removed, if_cs_release() will unregister the |
| 769 | * device, and release the PCMCIA configuration. If the device is |
| 770 | * still open, this will be postponed until it is closed. |
| 771 | */ |
| 772 | static void if_cs_release(struct pcmcia_device *p_dev) |
| 773 | { |
| 774 | struct if_cs_card *card = p_dev->priv; |
| 775 | |
| 776 | lbs_deb_enter(LBS_DEB_CS); |
| 777 | |
Dominik Brodowski | eb14120 | 2010-03-07 12:21:16 +0100 | [diff] [blame] | 778 | free_irq(p_dev->irq, card); |
Holger Schurig | fdfb92e | 2008-01-25 14:15:48 +0100 | [diff] [blame] | 779 | pcmcia_disable_device(p_dev); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 780 | if (card->iobase) |
| 781 | ioport_unmap(card->iobase); |
| 782 | |
| 783 | lbs_deb_leave(LBS_DEB_CS); |
| 784 | } |
| 785 | |
| 786 | |
| 787 | /* |
| 788 | * This creates an "instance" of the driver, allocating local data |
| 789 | * structures for one device. The device is registered with Card |
| 790 | * Services. |
| 791 | * |
| 792 | * The dev_link structure is initialized, but we don't actually |
| 793 | * configure the card at this point -- we wait until we receive a card |
| 794 | * insertion event. |
| 795 | */ |
Dominik Brodowski | aaa8cfd | 2009-10-18 18:28:39 +0200 | [diff] [blame] | 796 | |
| 797 | static int if_cs_ioprobe(struct pcmcia_device *p_dev, |
| 798 | cistpl_cftable_entry_t *cfg, |
| 799 | cistpl_cftable_entry_t *dflt, |
| 800 | unsigned int vcc, |
| 801 | void *priv_data) |
| 802 | { |
| 803 | p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; |
| 804 | p_dev->io.BasePort1 = cfg->io.win[0].base; |
| 805 | p_dev->io.NumPorts1 = cfg->io.win[0].len; |
| 806 | |
| 807 | /* Do we need to allocate an interrupt? */ |
Dominik Brodowski | eb14120 | 2010-03-07 12:21:16 +0100 | [diff] [blame] | 808 | p_dev->conf.Attributes |= CONF_ENABLE_IRQ; |
Dominik Brodowski | aaa8cfd | 2009-10-18 18:28:39 +0200 | [diff] [blame] | 809 | |
| 810 | /* IO window settings */ |
| 811 | if (cfg->io.nwin != 1) { |
| 812 | lbs_pr_err("wrong CIS (check number of IO windows)\n"); |
| 813 | return -ENODEV; |
| 814 | } |
| 815 | |
| 816 | /* This reserves IO space but doesn't actually enable it */ |
| 817 | return pcmcia_request_io(p_dev, &p_dev->io); |
| 818 | } |
| 819 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 820 | static int if_cs_probe(struct pcmcia_device *p_dev) |
| 821 | { |
| 822 | int ret = -ENOMEM; |
Marek Vasut | dc7d243 | 2009-03-24 21:33:43 +0100 | [diff] [blame] | 823 | unsigned int prod_id; |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 824 | struct lbs_private *priv; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 825 | struct if_cs_card *card; |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame^] | 826 | const struct firmware *helper = NULL; |
| 827 | const struct firmware *mainfw = NULL; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 828 | |
| 829 | lbs_deb_enter(LBS_DEB_CS); |
| 830 | |
| 831 | card = kzalloc(sizeof(struct if_cs_card), GFP_KERNEL); |
| 832 | if (!card) { |
| 833 | lbs_pr_err("error in kzalloc\n"); |
| 834 | goto out; |
| 835 | } |
| 836 | card->p_dev = p_dev; |
| 837 | p_dev->priv = card; |
| 838 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 839 | p_dev->conf.Attributes = 0; |
| 840 | p_dev->conf.IntType = INT_MEMORY_AND_IO; |
| 841 | |
Dominik Brodowski | aaa8cfd | 2009-10-18 18:28:39 +0200 | [diff] [blame] | 842 | if (pcmcia_loop_config(p_dev, if_cs_ioprobe, NULL)) { |
| 843 | lbs_pr_err("error in pcmcia_loop_config\n"); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 844 | goto out1; |
| 845 | } |
| 846 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 847 | /* |
| 848 | * Allocate an interrupt line. Note that this does not assign |
| 849 | * a handler to the interrupt, unless the 'Handler' member of |
| 850 | * the irq structure is initialized. |
| 851 | */ |
Dominik Brodowski | eb14120 | 2010-03-07 12:21:16 +0100 | [diff] [blame] | 852 | if (!p_dev->irq) |
| 853 | goto out1; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 854 | |
| 855 | /* Initialize io access */ |
| 856 | card->iobase = ioport_map(p_dev->io.BasePort1, p_dev->io.NumPorts1); |
| 857 | if (!card->iobase) { |
| 858 | lbs_pr_err("error in ioport_map\n"); |
| 859 | ret = -EIO; |
| 860 | goto out1; |
| 861 | } |
| 862 | |
| 863 | /* |
| 864 | * This actually configures the PCMCIA socket -- setting up |
| 865 | * the I/O windows and the interrupt mapping, and putting the |
| 866 | * card and host interface into "Memory and IO" mode. |
| 867 | */ |
| 868 | ret = pcmcia_request_configuration(p_dev, &p_dev->conf); |
| 869 | if (ret) { |
| 870 | lbs_pr_err("error in pcmcia_request_configuration\n"); |
| 871 | goto out2; |
| 872 | } |
| 873 | |
| 874 | /* Finally, report what we've done */ |
| 875 | lbs_deb_cs("irq %d, io 0x%04x-0x%04x\n", |
Dominik Brodowski | eb14120 | 2010-03-07 12:21:16 +0100 | [diff] [blame] | 876 | p_dev->irq, p_dev->io.BasePort1, |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 877 | p_dev->io.BasePort1 + p_dev->io.NumPorts1 - 1); |
| 878 | |
Marek Vasut | 9d45368 | 2009-08-21 04:08:16 +0200 | [diff] [blame] | 879 | /* |
| 880 | * Most of the libertas cards can do unaligned register access, but some |
| 881 | * weird ones can not. That's especially true for the CF8305 card. |
| 882 | */ |
| 883 | card->align_regs = 0; |
| 884 | |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame^] | 885 | card->model = get_model(p_dev->manf_id, p_dev->card_id); |
| 886 | if (card->model == MODEL_UNKNOWN) { |
| 887 | lbs_pr_err("unsupported manf_id 0x%04x / card_id 0x%04x\n", |
| 888 | p_dev->manf_id, p_dev->card_id); |
| 889 | goto out2; |
| 890 | } |
| 891 | |
Holger Schurig | 4c55523 | 2008-06-05 13:08:35 +0200 | [diff] [blame] | 892 | /* Check if we have a current silicon */ |
Marek Vasut | dc7d243 | 2009-03-24 21:33:43 +0100 | [diff] [blame] | 893 | prod_id = if_cs_read8(card, IF_CS_PRODUCT_ID); |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame^] | 894 | if (card->model == MODEL_8305) { |
Marek Vasut | 9d45368 | 2009-08-21 04:08:16 +0200 | [diff] [blame] | 895 | card->align_regs = 1; |
| 896 | if (prod_id < IF_CS_CF8305_B1_REV) { |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame^] | 897 | lbs_pr_err("8305 rev B0 and older are not supported\n"); |
Marek Vasut | 9d45368 | 2009-08-21 04:08:16 +0200 | [diff] [blame] | 898 | ret = -ENODEV; |
| 899 | goto out2; |
| 900 | } |
| 901 | } |
| 902 | |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame^] | 903 | if ((card->model == MODEL_8381) && prod_id < IF_CS_CF8381_B3_REV) { |
| 904 | lbs_pr_err("8381 rev B2 and older are not supported\n"); |
Marek Vasut | dc7d243 | 2009-03-24 21:33:43 +0100 | [diff] [blame] | 905 | ret = -ENODEV; |
| 906 | goto out2; |
| 907 | } |
| 908 | |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame^] | 909 | if ((card->model == MODEL_8385) && prod_id < IF_CS_CF8385_B1_REV) { |
| 910 | lbs_pr_err("8385 rev B0 and older are not supported\n"); |
Holger Schurig | 4c55523 | 2008-06-05 13:08:35 +0200 | [diff] [blame] | 911 | ret = -ENODEV; |
| 912 | goto out2; |
| 913 | } |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 914 | |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame^] | 915 | ret = lbs_get_firmware(&p_dev->dev, NULL, NULL, card->model, |
| 916 | &fw_table[0], &helper, &mainfw); |
| 917 | if (ret) { |
| 918 | lbs_pr_err("failed to find firmware (%d)\n", ret); |
| 919 | goto out2; |
| 920 | } |
| 921 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 922 | /* Load the firmware early, before calling into libertas.ko */ |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame^] | 923 | ret = if_cs_prog_helper(card, helper); |
| 924 | if (ret == 0 && (card->model != MODEL_8305)) |
| 925 | ret = if_cs_prog_real(card, mainfw); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 926 | if (ret) |
| 927 | goto out2; |
| 928 | |
| 929 | /* Make this card known to the libertas driver */ |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 930 | priv = lbs_add_card(card, &p_dev->dev); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 931 | if (!priv) { |
| 932 | ret = -ENOMEM; |
| 933 | goto out2; |
| 934 | } |
| 935 | |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 936 | /* Finish setting up fields in lbs_private */ |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 937 | card->priv = priv; |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 938 | priv->card = card; |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 939 | priv->hw_host_to_card = if_cs_host_to_card; |
Amitkumar Karwar | 4912545 | 2009-09-30 20:04:38 -0700 | [diff] [blame] | 940 | priv->enter_deep_sleep = NULL; |
| 941 | priv->exit_deep_sleep = NULL; |
| 942 | priv->reset_deep_sleep_wakeup = NULL; |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 943 | priv->fw_ready = 1; |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 944 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 945 | /* Now actually get the IRQ */ |
Dominik Brodowski | eb14120 | 2010-03-07 12:21:16 +0100 | [diff] [blame] | 946 | ret = request_irq(p_dev->irq, if_cs_interrupt, |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 947 | IRQF_SHARED, DRV_NAME, card); |
| 948 | if (ret) { |
| 949 | lbs_pr_err("error in request_irq\n"); |
| 950 | goto out3; |
| 951 | } |
| 952 | |
Holger Schurig | 4ef3170 | 2007-10-09 10:41:57 +0200 | [diff] [blame] | 953 | /* Clear any interrupt cause that happend while sending |
| 954 | * firmware/initializing card */ |
Holger Schurig | 78cf074 | 2008-06-02 09:25:05 +0200 | [diff] [blame] | 955 | 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] | 956 | if_cs_enable_ints(card); |
| 957 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 958 | /* And finally bring the card up */ |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 959 | if (lbs_start_card(priv) != 0) { |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 960 | lbs_pr_err("could not activate card\n"); |
| 961 | goto out3; |
| 962 | } |
| 963 | |
| 964 | ret = 0; |
| 965 | goto out; |
| 966 | |
| 967 | out3: |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 968 | lbs_remove_card(priv); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 969 | out2: |
| 970 | ioport_unmap(card->iobase); |
| 971 | out1: |
| 972 | pcmcia_disable_device(p_dev); |
| 973 | out: |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame^] | 974 | if (helper) |
| 975 | release_firmware(helper); |
| 976 | if (mainfw) |
| 977 | release_firmware(mainfw); |
| 978 | |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 979 | lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret); |
| 980 | return ret; |
| 981 | } |
| 982 | |
| 983 | |
| 984 | /* |
| 985 | * This deletes a driver "instance". The device is de-registered with |
| 986 | * Card Services. If it has been released, all local data structures |
| 987 | * are freed. Otherwise, the structures will be freed when the device |
| 988 | * is released. |
| 989 | */ |
| 990 | static void if_cs_detach(struct pcmcia_device *p_dev) |
| 991 | { |
| 992 | struct if_cs_card *card = p_dev->priv; |
| 993 | |
| 994 | lbs_deb_enter(LBS_DEB_CS); |
| 995 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 996 | lbs_stop_card(card->priv); |
| 997 | lbs_remove_card(card->priv); |
Ryan Mallon | 28de0b3 | 2007-09-06 21:32:42 -0400 | [diff] [blame] | 998 | if_cs_disable_ints(card); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 999 | if_cs_release(p_dev); |
| 1000 | kfree(card); |
| 1001 | |
| 1002 | lbs_deb_leave(LBS_DEB_CS); |
| 1003 | } |
| 1004 | |
| 1005 | |
| 1006 | |
| 1007 | /********************************************************************/ |
| 1008 | /* Module initialization */ |
| 1009 | /********************************************************************/ |
| 1010 | |
| 1011 | static struct pcmcia_device_id if_cs_ids[] = { |
Marek Vasut | 9d45368 | 2009-08-21 04:08:16 +0200 | [diff] [blame] | 1012 | PCMCIA_DEVICE_MANF_CARD(CF8305_MANFID, CF8305_CARDID), |
Marek Vasut | dc7d243 | 2009-03-24 21:33:43 +0100 | [diff] [blame] | 1013 | PCMCIA_DEVICE_MANF_CARD(CF8381_MANFID, CF8381_CARDID), |
| 1014 | PCMCIA_DEVICE_MANF_CARD(CF8385_MANFID, CF8385_CARDID), |
Dan Williams | 82222e9 | 2010-08-07 21:15:19 -0500 | [diff] [blame^] | 1015 | /* NOTE: keep in sync with get_model() */ |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 1016 | PCMCIA_DEVICE_NULL, |
| 1017 | }; |
| 1018 | MODULE_DEVICE_TABLE(pcmcia, if_cs_ids); |
| 1019 | |
| 1020 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1021 | static struct pcmcia_driver lbs_driver = { |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 1022 | .owner = THIS_MODULE, |
| 1023 | .drv = { |
| 1024 | .name = DRV_NAME, |
| 1025 | }, |
| 1026 | .probe = if_cs_probe, |
| 1027 | .remove = if_cs_detach, |
| 1028 | .id_table = if_cs_ids, |
| 1029 | }; |
| 1030 | |
| 1031 | |
| 1032 | static int __init if_cs_init(void) |
| 1033 | { |
| 1034 | int ret; |
| 1035 | |
| 1036 | lbs_deb_enter(LBS_DEB_CS); |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1037 | ret = pcmcia_register_driver(&lbs_driver); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 1038 | lbs_deb_leave(LBS_DEB_CS); |
| 1039 | return ret; |
| 1040 | } |
| 1041 | |
| 1042 | |
| 1043 | static void __exit if_cs_exit(void) |
| 1044 | { |
| 1045 | lbs_deb_enter(LBS_DEB_CS); |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1046 | pcmcia_unregister_driver(&lbs_driver); |
Holger Schurig | 27590d0 | 2007-10-03 17:25:41 -0700 | [diff] [blame] | 1047 | lbs_deb_leave(LBS_DEB_CS); |
| 1048 | } |
| 1049 | |
| 1050 | |
| 1051 | module_init(if_cs_init); |
| 1052 | module_exit(if_cs_exit); |