24 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
26 #include <linux/module.h>
27 #include <linux/slab.h>
31 #include <linux/netdevice.h>
38 #define DRV_NAME "libertas_cs"
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" },
106 #define debug_output 0
123 static inline void if_cs_read16_rep(
149 static inline void if_cs_write16_rep(
178 for (i = 0; i < 100000; i++) {
179 u8 val = if_cs_read8(card, addr);
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
212 #define IF_CS_HOST_STATUS 0x00000000
224 #define IF_CS_HOST_INT_CAUSE 0x00000002
230 #define IF_CS_HOST_INT_MASK 0x00000004
235 #define IF_CS_WRITE 0x00000016
236 #define IF_CS_WRITE_LEN 0x00000014
237 #define IF_CS_READ 0x00000010
238 #define IF_CS_READ_LEN 0x00000024
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
266 #define IF_CS_CARD_STATUS 0x00000020
267 #define IF_CS_CARD_STATUS_MASK 0x7f00
279 #define IF_CS_CARD_INT_CAUSE 0x00000022
285 #define IF_CS_SQ_READ_LOW 0x00000028
286 #define IF_CS_SQ_HELPER_OK 0x10
294 #define IF_CS_SCRATCH 0x0000003F
295 #define IF_CS_SCRATCH_BOOT_OK 0x00
296 #define IF_CS_SCRATCH_HELPER_OK 0x5a
301 #define IF_CS_PRODUCT_ID 0x0000001C
302 #define IF_CS_CF8385_B1_REV 0x12
303 #define IF_CS_CF8381_B3_REV 0x04
304 #define IF_CS_CF8305_B1_REV 0x03
310 #define CF8305_MANFID 0x02db
311 #define CF8305_CARDID 0x8103
312 #define CF8381_MANFID 0x02db
313 #define CF8381_CARDID 0x6064
314 #define CF8385_MANFID 0x02df
315 #define CF8385_CARDID 0x8103
321 static inline u32 get_model(
u16 manf_id,
u16 card_id)
337 static inline void if_cs_enable_ints(
struct if_cs_card *card)
343 static inline void if_cs_disable_ints(
struct if_cs_card *card)
359 if_cs_disable_ints(card);
367 netdev_err(priv->
dev,
"card not ready for commands\n");
375 if_cs_write16_rep(card,
IF_CS_CMD, buf, nb / 2);
378 if_cs_write8(card,
IF_CS_CMD, buf[nb-1]);
390 if_cs_enable_ints(card);
404 if_cs_disable_ints(card);
418 if_cs_enable_ints(card);
437 netdev_err(priv->
dev,
"no cmd response in card\n");
444 netdev_err(priv->
dev,
445 "card cmd buffer has invalid # of bytes (%d)\n",
480 netdev_err(priv->
dev,
481 "card data buffer has invalid # of bytes (%d)\n",
483 priv->
dev->stats.rx_dropped++;
508 static irqreturn_t if_cs_interrupt(
int irq,
void *data)
525 if (cause == 0xffff) {
527 card->
priv->surpriseremoved = 1;
534 skb = if_cs_receive_data(priv);
544 if (cause & IF_CS_BIT_RESP) {
554 if_cs_receive_cmdres(priv, priv->
resp_buf[i],
626 int remain = fw->
size - sent;
662 pr_err(
"can't download helper at 0x%x, ret %d\n",
693 pr_err(
"helper firmware doesn't answer\n");
697 for (sent = 0; sent < fw->
size; sent +=
len) {
701 pr_info(
"odd, need to retry this firmware block\n");
707 pr_err(
"could not download firmware\n");
727 pr_err(
"can't download firmware at 0x%x\n", sent);
732 ret = if_cs_poll_while_fw_download(card,
IF_CS_SCRATCH, 0x5a);
734 pr_err(
"firmware download failed\n");
741 static void if_cs_prog_firmware(
struct lbs_private *priv,
int ret,
748 pr_err(
"failed to find firmware (%d)\n", ret);
753 ret = if_cs_prog_helper(card, helper);
755 ret = if_cs_prog_real(card, mainfw);
763 pr_err(
"error in request_irq\n");
772 if_cs_enable_ints(card);
777 pr_err(
"could not activate card\n");
792 static int if_cs_host_to_card(
struct lbs_private *priv,
804 if_cs_send_data(priv, buf, nb);
809 ret = if_cs_send_cmd(priv, buf, nb);
812 netdev_err(priv->
dev,
"%s: unsupported type %d\n",
821 static void if_cs_release(
struct pcmcia_device *
p_dev)
836 static int if_cs_ioprobe(
struct pcmcia_device *p_dev,
void *priv_data)
838 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
839 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
841 if (p_dev->resource[1]->end) {
842 pr_err(
"wrong CIS (check number of IO windows)\n");
850 static int if_cs_probe(
struct pcmcia_device *p_dev)
853 unsigned int prod_id;
866 p_dev->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
868 if (pcmcia_loop_config(p_dev, if_cs_ioprobe,
NULL)) {
869 pr_err(
"error in pcmcia_loop_config\n");
883 resource_size(p_dev->resource[0]));
885 pr_err(
"error in ioport_map\n");
892 pr_err(
"error in pcmcia_enable_device\n");
897 lbs_deb_cs(
"irq %d, io %pR", p_dev->irq, p_dev->resource[0]);
905 card->
model = get_model(p_dev->manf_id, p_dev->card_id);
907 pr_err(
"unsupported manf_id 0x%04x / card_id 0x%04x\n",
908 p_dev->manf_id, p_dev->card_id);
917 pr_err(
"8305 rev B0 and older are not supported\n");
924 pr_err(
"8381 rev B2 and older are not supported\n");
930 pr_err(
"8385 rev B0 and older are not supported\n");
952 if_cs_prog_firmware);
954 pr_err(
"failed to find firmware (%d)\n", ret);
972 static void if_cs_detach(
struct pcmcia_device *p_dev)
980 if_cs_disable_ints(card);
981 if_cs_release(p_dev);
1003 static struct pcmcia_driver lbs_driver = {
1006 .probe = if_cs_probe,
1007 .remove = if_cs_detach,
1008 .id_table = if_cs_ids,
1012 static int __init if_cs_init(
void)
1023 static void __exit if_cs_exit(
void)