Lines Matching full:card
46 /* The card ID and card revision, as reported by the hardware. */
73 /* True is card suspended */
77 static void free_if_spi_card(struct if_spi_card *card) in free_if_spi_card() argument
82 list_for_each_safe(cursor, next, &card->cmd_packet_list) { in free_if_spi_card()
87 list_for_each_safe(cursor, next, &card->data_packet_list) { in free_if_spi_card()
92 kfree(card); in free_if_spi_card()
129 static void spu_transaction_init(struct if_spi_card *card) in spu_transaction_init() argument
131 if (!time_after(jiffies, card->prev_xfer_time + 1)) { in spu_transaction_init()
140 static void spu_transaction_finish(struct if_spi_card *card) in spu_transaction_finish() argument
142 card->prev_xfer_time = jiffies; in spu_transaction_finish()
149 static int spu_write(struct if_spi_card *card, u16 reg, const u8 *buf, int len) in spu_write() argument
165 spu_transaction_init(card); in spu_write()
177 err = spi_sync(card->spi, &m); in spu_write()
178 spu_transaction_finish(card); in spu_write()
182 static inline int spu_write_u16(struct if_spi_card *card, u16 reg, u16 val) in spu_write_u16() argument
187 return spu_write(card, reg, (u8 *)&buff, sizeof(u16)); in spu_write_u16()
202 static int spu_read(struct if_spi_card *card, u16 reg, u8 *buf, int len) in spu_read() argument
218 spu_transaction_init(card); in spu_read()
230 delay = spu_reg_is_port_reg(reg) ? card->spu_port_delay : in spu_read()
231 card->spu_reg_delay; in spu_read()
232 if (card->use_dummy_writes) { in spu_read()
248 err = spi_sync(card->spi, &m); in spu_read()
249 spu_transaction_finish(card); in spu_read()
254 static inline int spu_read_u16(struct if_spi_card *card, u16 reg, u16 *val) in spu_read_u16() argument
259 ret = spu_read(card, reg, (u8 *)&buf, sizeof(buf)); in spu_read_u16()
269 static int spu_read_u32(struct if_spi_card *card, u16 reg, u32 *val) in spu_read_u32() argument
274 err = spu_read(card, reg, (u8 *)&buf, sizeof(buf)); in spu_read_u32()
289 static int spu_wait_for_u16(struct if_spi_card *card, u16 reg, in spu_wait_for_u16() argument
296 err = spu_read_u16(card, reg, &val); in spu_wait_for_u16()
319 static int spu_wait_for_u32(struct if_spi_card *card, u32 reg, u32 target) in spu_wait_for_u32() argument
324 err = spu_read_u32(card, reg, &val); in spu_wait_for_u32()
334 static int spu_set_interrupt_mode(struct if_spi_card *card, in spu_set_interrupt_mode() argument
345 err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_MASK_REG, 0); in spu_set_interrupt_mode()
349 err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_MASK_REG, in spu_set_interrupt_mode()
362 * are off, we need to set the "Card Interrupt Cause" register to in spu_set_interrupt_mode()
363 * trigger a card interrupt. in spu_set_interrupt_mode()
366 err = spu_write_u16(card, IF_SPI_HOST_INT_CTRL_REG, in spu_set_interrupt_mode()
374 err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_MASK_REG, 0); in spu_set_interrupt_mode()
381 static int spu_get_chip_revision(struct if_spi_card *card, in spu_get_chip_revision() argument
386 err = spu_read_u32(card, IF_SPI_DEVICEID_CTRL_REG, &dev_ctrl); in spu_get_chip_revision()
394 static int spu_set_bus_mode(struct if_spi_card *card, u16 mode) in spu_set_bus_mode() argument
399 err = spu_write_u16(card, IF_SPI_SPU_BUS_MODE_REG, mode); in spu_set_bus_mode()
403 err = spu_read_u16(card, IF_SPI_SPU_BUS_MODE_REG, &rval); in spu_set_bus_mode()
413 static int spu_init(struct if_spi_card *card, int use_dummy_writes) in spu_init() argument
422 card->use_dummy_writes = 0; in spu_init()
423 err = spu_set_bus_mode(card, in spu_init()
429 card->spu_port_delay = 1000; in spu_init()
430 card->spu_reg_delay = 1000; in spu_init()
431 err = spu_read_u32(card, IF_SPI_DELAY_READ_REG, &delay); in spu_init()
434 card->spu_port_delay = delay & 0x0000ffff; in spu_init()
435 card->spu_reg_delay = (delay & 0xffff0000) >> 16; in spu_init()
439 card->use_dummy_writes = 1; in spu_init()
440 err = spu_set_bus_mode(card, in spu_init()
450 card->spu_port_delay, card->spu_reg_delay); in spu_init()
458 static int if_spi_prog_helper_firmware(struct if_spi_card *card, in if_spi_prog_helper_firmware() argument
466 err = spu_set_interrupt_mode(card, 1, 0); in if_spi_prog_helper_firmware()
479 err = spu_write_u16(card, IF_SPI_SCRATCH_1_REG, in if_spi_prog_helper_firmware()
484 err = spu_wait_for_u16(card, IF_SPI_HOST_INT_STATUS_REG, in if_spi_prog_helper_firmware()
498 err = spu_write(card, IF_SPI_CMD_RDWRPORT_REG, in if_spi_prog_helper_firmware()
504 err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_REG, 0); in if_spi_prog_helper_firmware()
507 err = spu_write_u16(card, IF_SPI_CARD_INT_CAUSE_REG, in if_spi_prog_helper_firmware()
520 err = spu_write_u16(card, IF_SPI_SCRATCH_1_REG, FIRMWARE_DNLD_OK); in if_spi_prog_helper_firmware()
523 err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_REG, 0); in if_spi_prog_helper_firmware()
526 err = spu_write_u16(card, IF_SPI_CARD_INT_CAUSE_REG, in if_spi_prog_helper_firmware()
539 static int if_spi_prog_main_firmware_check_len(struct if_spi_card *card, in if_spi_prog_main_firmware_check_len() argument
549 err = spu_wait_for_u16(card, IF_SPI_HOST_INT_STATUS_REG, in if_spi_prog_main_firmware_check_len()
558 err = spu_read_u16(card, IF_SPI_SCRATCH_1_REG, &len); in if_spi_prog_main_firmware_check_len()
577 static int if_spi_prog_main_firmware(struct if_spi_card *card, in if_spi_prog_main_firmware() argument
580 struct lbs_private *priv = card->priv; in if_spi_prog_main_firmware()
586 err = spu_set_interrupt_mode(card, 1, 0); in if_spi_prog_main_firmware()
590 err = spu_wait_for_u16(card, IF_SPI_SCRATCH_1_REG, 0, 0); in if_spi_prog_main_firmware()
602 while ((len = if_spi_prog_main_firmware_check_len(card, &crc_err))) { in if_spi_prog_main_firmware()
629 memset(card->cmd_buffer, 0, len); in if_spi_prog_main_firmware()
630 memcpy(card->cmd_buffer, fw, bytes); in if_spi_prog_main_firmware()
632 memcpy(card->cmd_buffer, fw, len); in if_spi_prog_main_firmware()
634 err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_REG, 0); in if_spi_prog_main_firmware()
637 err = spu_write(card, IF_SPI_CMD_RDWRPORT_REG, in if_spi_prog_main_firmware()
638 card->cmd_buffer, len); in if_spi_prog_main_firmware()
641 err = spu_write_u16(card, IF_SPI_CARD_INT_CAUSE_REG , in if_spi_prog_main_firmware()
652 err = spu_wait_for_u32(card, IF_SPI_SCRATCH_4_REG, in if_spi_prog_main_firmware()
672 /* Move a command from the card to the host */
673 static int if_spi_c2h_cmd(struct if_spi_card *card) in if_spi_c2h_cmd() argument
675 struct lbs_private *priv = card->priv; in if_spi_c2h_cmd()
696 err = spu_read_u16(card, IF_SPI_SCRATCH_2_REG, &len); in if_spi_c2h_cmd()
700 netdev_err(priv->dev, "%s: error: card has no data for host\n", in if_spi_c2h_cmd()
713 err = spu_read(card, IF_SPI_CMD_RDWRPORT_REG, in if_spi_c2h_cmd()
714 card->cmd_buffer, ALIGN(len, 4)); in if_spi_c2h_cmd()
722 memcpy(priv->resp_buf[i], card->cmd_buffer, len); in if_spi_c2h_cmd()
733 /* Move data from the card to the host */
734 static int if_spi_c2h_data(struct if_spi_card *card) in if_spi_c2h_data() argument
736 struct lbs_private *priv = card->priv; in if_spi_c2h_data()
743 err = spu_read_u16(card, IF_SPI_SCRATCH_1_REG, &len); in if_spi_c2h_data()
747 netdev_err(priv->dev, "%s: error: card has no data for host\n", in if_spi_c2h_data()
753 "%s: error: card has %d bytes of data, but our maximum skb size is %zu\n", in if_spi_c2h_data()
769 err = spu_read(card, IF_SPI_DATA_RDWRPORT_REG, data, ALIGN(len, 4)); in if_spi_c2h_data()
776 err = lbs_process_rxed_packet(card->priv, skb); in if_spi_c2h_data()
786 /* Move data or a command from the host to the card. */
787 static void if_spi_h2c(struct if_spi_card *card, in if_spi_h2c() argument
790 struct lbs_private *priv = card->priv; in if_spi_h2c()
808 /* Write the data to the card */ in if_spi_h2c()
809 err = spu_write(card, port_reg, packet->buffer, packet->blen); in if_spi_h2c()
820 /* Inform the host about a card event */
821 static void if_spi_e2h(struct if_spi_card *card) in if_spi_e2h() argument
825 struct lbs_private *priv = card->priv; in if_spi_e2h()
827 err = spu_read_u32(card, IF_SPI_SCRATCH_3_REG, &cause); in if_spi_e2h()
831 /* re-enable the card event interrupt */ in if_spi_e2h()
832 spu_write_u16(card, IF_SPI_HOST_INT_STATUS_REG, in if_spi_e2h()
835 /* generate a card interrupt */ in if_spi_e2h()
836 spu_write_u16(card, IF_SPI_CARD_INT_CAUSE_REG, IF_SPI_CIC_HOST_EVENT); in if_spi_e2h()
847 struct if_spi_card *card; in if_spi_host_to_card_worker() local
853 card = container_of(work, struct if_spi_card, packet_work); in if_spi_host_to_card_worker()
854 priv = card->priv; in if_spi_host_to_card_worker()
860 err = spu_read_u16(card, IF_SPI_HOST_INT_STATUS_REG, in if_spi_host_to_card_worker()
868 err = if_spi_c2h_cmd(card); in if_spi_host_to_card_worker()
873 err = if_spi_c2h_data(card); in if_spi_host_to_card_worker()
879 * workaround: in PS mode, the card does not set the Command in if_spi_host_to_card_worker()
883 (card->priv->psstate != PS_STATE_FULL_POWER && in if_spi_host_to_card_worker()
887 * if there was a previous command sent, the card has in if_spi_host_to_card_worker()
892 lbs_host_to_card_done(card->priv); in if_spi_host_to_card_worker()
896 spin_lock_irqsave(&card->buffer_lock, flags); in if_spi_host_to_card_worker()
897 if (!list_empty(&card->cmd_packet_list)) { in if_spi_host_to_card_worker()
898 packet = (struct if_spi_packet *)(card-> in if_spi_host_to_card_worker()
902 spin_unlock_irqrestore(&card->buffer_lock, flags); in if_spi_host_to_card_worker()
905 if_spi_h2c(card, packet, MVMS_CMD); in if_spi_host_to_card_worker()
910 spin_lock_irqsave(&card->buffer_lock, flags); in if_spi_host_to_card_worker()
911 if (!list_empty(&card->data_packet_list)) { in if_spi_host_to_card_worker()
912 packet = (struct if_spi_packet *)(card-> in if_spi_host_to_card_worker()
916 spin_unlock_irqrestore(&card->buffer_lock, flags); in if_spi_host_to_card_worker()
919 if_spi_h2c(card, packet, MVMS_DAT); in if_spi_host_to_card_worker()
922 if_spi_e2h(card); in if_spi_host_to_card_worker()
930 * Host to Card
940 struct if_spi_card *card = priv->card; in if_spi_host_to_card() local
963 spin_lock_irqsave(&card->buffer_lock, flags); in if_spi_host_to_card()
964 list_add_tail(&packet->list, &card->cmd_packet_list); in if_spi_host_to_card()
965 spin_unlock_irqrestore(&card->buffer_lock, flags); in if_spi_host_to_card()
969 spin_lock_irqsave(&card->buffer_lock, flags); in if_spi_host_to_card()
970 list_add_tail(&packet->list, &card->data_packet_list); in if_spi_host_to_card()
971 spin_unlock_irqrestore(&card->buffer_lock, flags); in if_spi_host_to_card()
982 queue_work(card->workqueue, &card->packet_work); in if_spi_host_to_card()
995 struct if_spi_card *card = dev_id; in if_spi_host_interrupt() local
997 queue_work(card->workqueue, &card->packet_work); in if_spi_host_interrupt()
1006 static int if_spi_init_card(struct if_spi_card *card) in if_spi_init_card() argument
1008 struct lbs_private *priv = card->priv; in if_spi_init_card()
1014 err = spu_init(card, card->pdata->use_dummy_writes); in if_spi_init_card()
1017 err = spu_get_chip_revision(card, &card->card_id, &card->card_rev); in if_spi_init_card()
1021 err = spu_read_u32(card, IF_SPI_SCRATCH_4_REG, &scratch); in if_spi_init_card()
1028 /* Check if we support this card */ in if_spi_init_card()
1030 if (card->card_id == fw_table[i].model) in if_spi_init_card()
1035 card->card_id); in if_spi_init_card()
1040 err = lbs_get_firmware(&card->spi->dev, card->card_id, in if_spi_init_card()
1052 card->card_id, card->card_rev, in if_spi_init_card()
1053 card->spi->master->bus_num, in if_spi_init_card()
1054 card->spi->chip_select, in if_spi_init_card()
1055 card->spi->max_speed_hz); in if_spi_init_card()
1056 err = if_spi_prog_helper_firmware(card, helper); in if_spi_init_card()
1059 err = if_spi_prog_main_firmware(card, mainfw); in if_spi_init_card()
1065 err = spu_set_interrupt_mode(card, 0, 1); in if_spi_init_card()
1075 struct if_spi_card *card; in if_spi_resume_worker() local
1077 card = container_of(work, struct if_spi_card, resume_work); in if_spi_resume_worker()
1079 if (card->suspended) { in if_spi_resume_worker()
1080 if (card->pdata->setup) in if_spi_resume_worker()
1081 card->pdata->setup(card->spi); in if_spi_resume_worker()
1083 /* Init card ... */ in if_spi_resume_worker()
1084 if_spi_init_card(card); in if_spi_resume_worker()
1086 enable_irq(card->spi->irq); in if_spi_resume_worker()
1089 lbs_resume(card->priv); in if_spi_resume_worker()
1091 card->suspended = 0; in if_spi_resume_worker()
1097 struct if_spi_card *card; in if_spi_probe() local
1113 /* Allocate card structure to represent this specific device */ in if_spi_probe()
1114 card = kzalloc(sizeof(struct if_spi_card), GFP_KERNEL); in if_spi_probe()
1115 if (!card) { in if_spi_probe()
1119 spi_set_drvdata(spi, card); in if_spi_probe()
1120 card->pdata = pdata; in if_spi_probe()
1121 card->spi = spi; in if_spi_probe()
1122 card->prev_xfer_time = jiffies; in if_spi_probe()
1124 INIT_LIST_HEAD(&card->cmd_packet_list); in if_spi_probe()
1125 INIT_LIST_HEAD(&card->data_packet_list); in if_spi_probe()
1126 spin_lock_init(&card->buffer_lock); in if_spi_probe()
1131 err = if_spi_init_card(card); in if_spi_probe()
1136 * Register our card with libertas. in if_spi_probe()
1139 priv = lbs_add_card(card, &spi->dev); in if_spi_probe()
1144 card->priv = priv; in if_spi_probe()
1146 priv->card = card; in if_spi_probe()
1154 card->workqueue = alloc_workqueue("libertas_spi", WQ_MEM_RECLAIM, 0); in if_spi_probe()
1155 if (!card->workqueue) { in if_spi_probe()
1159 INIT_WORK(&card->packet_work, if_spi_host_to_card_worker); in if_spi_probe()
1160 INIT_WORK(&card->resume_work, if_spi_resume_worker); in if_spi_probe()
1163 IRQF_TRIGGER_FALLING, "libertas_spi", card); in if_spi_probe()
1170 * Start the card. in if_spi_probe()
1184 free_irq(spi->irq, card); in if_spi_probe()
1186 destroy_workqueue(card->workqueue); in if_spi_probe()
1190 free_if_spi_card(card); in if_spi_probe()
1200 struct if_spi_card *card = spi_get_drvdata(spi); in libertas_spi_remove() local
1201 struct lbs_private *priv = card->priv; in libertas_spi_remove()
1205 cancel_work_sync(&card->resume_work); in libertas_spi_remove()
1210 free_irq(spi->irq, card); in libertas_spi_remove()
1211 destroy_workqueue(card->workqueue); in libertas_spi_remove()
1212 if (card->pdata->teardown) in libertas_spi_remove()
1213 card->pdata->teardown(spi); in libertas_spi_remove()
1214 free_if_spi_card(card); in libertas_spi_remove()
1220 struct if_spi_card *card = spi_get_drvdata(spi); in if_spi_suspend() local
1222 if (!card->suspended) { in if_spi_suspend()
1223 lbs_suspend(card->priv); in if_spi_suspend()
1224 flush_workqueue(card->workqueue); in if_spi_suspend()
1227 if (card->pdata->teardown) in if_spi_suspend()
1228 card->pdata->teardown(spi); in if_spi_suspend()
1229 card->suspended = 1; in if_spi_suspend()
1238 struct if_spi_card *card = spi_get_drvdata(spi); in if_spi_resume() local
1241 schedule_work(&card->resume_work); in if_spi_resume()