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
81 list_for_each_entry_safe(packet, tmp, &card->cmd_packet_list, list) { in free_if_spi_card()
85 list_for_each_entry_safe(packet, tmp, &card->data_packet_list, list) { in free_if_spi_card()
89 kfree(card); in free_if_spi_card()
126 static void spu_transaction_init(struct if_spi_card *card) in spu_transaction_init() argument
128 if (!time_after(jiffies, card->prev_xfer_time + 1)) { in spu_transaction_init()
137 static void spu_transaction_finish(struct if_spi_card *card) in spu_transaction_finish() argument
139 card->prev_xfer_time = jiffies; in spu_transaction_finish()
146 static int spu_write(struct if_spi_card *card, u16 reg, const u8 *buf, int len) in spu_write() argument
162 spu_transaction_init(card); in spu_write()
174 err = spi_sync(card->spi, &m); in spu_write()
175 spu_transaction_finish(card); in spu_write()
179 static inline int spu_write_u16(struct if_spi_card *card, u16 reg, u16 val) in spu_write_u16() argument
184 return spu_write(card, reg, (u8 *)&buff, sizeof(u16)); in spu_write_u16()
199 static int spu_read(struct if_spi_card *card, u16 reg, u8 *buf, int len) in spu_read() argument
215 spu_transaction_init(card); in spu_read()
227 delay = spu_reg_is_port_reg(reg) ? card->spu_port_delay : in spu_read()
228 card->spu_reg_delay; in spu_read()
229 if (card->use_dummy_writes) { in spu_read()
245 err = spi_sync(card->spi, &m); in spu_read()
246 spu_transaction_finish(card); in spu_read()
251 static inline int spu_read_u16(struct if_spi_card *card, u16 reg, u16 *val) in spu_read_u16() argument
256 ret = spu_read(card, reg, (u8 *)&buf, sizeof(buf)); in spu_read_u16()
266 static int spu_read_u32(struct if_spi_card *card, u16 reg, u32 *val) in spu_read_u32() argument
271 err = spu_read(card, reg, (u8 *)&buf, sizeof(buf)); in spu_read_u32()
286 static int spu_wait_for_u16(struct if_spi_card *card, u16 reg, in spu_wait_for_u16() argument
293 err = spu_read_u16(card, reg, &val); in spu_wait_for_u16()
316 static int spu_wait_for_u32(struct if_spi_card *card, u32 reg, u32 target) in spu_wait_for_u32() argument
321 err = spu_read_u32(card, reg, &val); in spu_wait_for_u32()
331 static int spu_set_interrupt_mode(struct if_spi_card *card, in spu_set_interrupt_mode() argument
342 err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_MASK_REG, 0); in spu_set_interrupt_mode()
346 err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_MASK_REG, in spu_set_interrupt_mode()
359 * are off, we need to set the "Card Interrupt Cause" register to in spu_set_interrupt_mode()
360 * trigger a card interrupt. in spu_set_interrupt_mode()
363 err = spu_write_u16(card, IF_SPI_HOST_INT_CTRL_REG, in spu_set_interrupt_mode()
371 err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_MASK_REG, 0); in spu_set_interrupt_mode()
378 static int spu_get_chip_revision(struct if_spi_card *card, in spu_get_chip_revision() argument
383 err = spu_read_u32(card, IF_SPI_DEVICEID_CTRL_REG, &dev_ctrl); in spu_get_chip_revision()
391 static int spu_set_bus_mode(struct if_spi_card *card, u16 mode) in spu_set_bus_mode() argument
396 err = spu_write_u16(card, IF_SPI_SPU_BUS_MODE_REG, mode); in spu_set_bus_mode()
400 err = spu_read_u16(card, IF_SPI_SPU_BUS_MODE_REG, &rval); in spu_set_bus_mode()
410 static int spu_init(struct if_spi_card *card, int use_dummy_writes) in spu_init() argument
419 card->use_dummy_writes = 0; in spu_init()
420 err = spu_set_bus_mode(card, in spu_init()
426 card->spu_port_delay = 1000; in spu_init()
427 card->spu_reg_delay = 1000; in spu_init()
428 err = spu_read_u32(card, IF_SPI_DELAY_READ_REG, &delay); in spu_init()
431 card->spu_port_delay = delay & 0x0000ffff; in spu_init()
432 card->spu_reg_delay = (delay & 0xffff0000) >> 16; in spu_init()
436 card->use_dummy_writes = 1; in spu_init()
437 err = spu_set_bus_mode(card, in spu_init()
447 card->spu_port_delay, card->spu_reg_delay); in spu_init()
455 static int if_spi_prog_helper_firmware(struct if_spi_card *card, in if_spi_prog_helper_firmware() argument
463 err = spu_set_interrupt_mode(card, 1, 0); in if_spi_prog_helper_firmware()
476 err = spu_write_u16(card, IF_SPI_SCRATCH_1_REG, in if_spi_prog_helper_firmware()
481 err = spu_wait_for_u16(card, IF_SPI_HOST_INT_STATUS_REG, in if_spi_prog_helper_firmware()
495 err = spu_write(card, IF_SPI_CMD_RDWRPORT_REG, in if_spi_prog_helper_firmware()
501 err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_REG, 0); in if_spi_prog_helper_firmware()
504 err = spu_write_u16(card, IF_SPI_CARD_INT_CAUSE_REG, in if_spi_prog_helper_firmware()
517 err = spu_write_u16(card, IF_SPI_SCRATCH_1_REG, FIRMWARE_DNLD_OK); in if_spi_prog_helper_firmware()
520 err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_REG, 0); in if_spi_prog_helper_firmware()
523 err = spu_write_u16(card, IF_SPI_CARD_INT_CAUSE_REG, in if_spi_prog_helper_firmware()
536 static int if_spi_prog_main_firmware_check_len(struct if_spi_card *card, in if_spi_prog_main_firmware_check_len() argument
546 err = spu_wait_for_u16(card, IF_SPI_HOST_INT_STATUS_REG, in if_spi_prog_main_firmware_check_len()
555 err = spu_read_u16(card, IF_SPI_SCRATCH_1_REG, &len); in if_spi_prog_main_firmware_check_len()
574 static int if_spi_prog_main_firmware(struct if_spi_card *card, in if_spi_prog_main_firmware() argument
577 struct lbs_private *priv = card->priv; in if_spi_prog_main_firmware()
583 err = spu_set_interrupt_mode(card, 1, 0); in if_spi_prog_main_firmware()
587 err = spu_wait_for_u16(card, IF_SPI_SCRATCH_1_REG, 0, 0); in if_spi_prog_main_firmware()
599 while ((len = if_spi_prog_main_firmware_check_len(card, &crc_err))) { in if_spi_prog_main_firmware()
626 memset(card->cmd_buffer, 0, len); in if_spi_prog_main_firmware()
627 memcpy(card->cmd_buffer, fw, bytes); in if_spi_prog_main_firmware()
629 memcpy(card->cmd_buffer, fw, len); in if_spi_prog_main_firmware()
631 err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_REG, 0); in if_spi_prog_main_firmware()
634 err = spu_write(card, IF_SPI_CMD_RDWRPORT_REG, in if_spi_prog_main_firmware()
635 card->cmd_buffer, len); in if_spi_prog_main_firmware()
638 err = spu_write_u16(card, IF_SPI_CARD_INT_CAUSE_REG , in if_spi_prog_main_firmware()
649 err = spu_wait_for_u32(card, IF_SPI_SCRATCH_4_REG, in if_spi_prog_main_firmware()
669 /* Move a command from the card to the host */
670 static int if_spi_c2h_cmd(struct if_spi_card *card) in if_spi_c2h_cmd() argument
672 struct lbs_private *priv = card->priv; in if_spi_c2h_cmd()
693 err = spu_read_u16(card, IF_SPI_SCRATCH_2_REG, &len); in if_spi_c2h_cmd()
697 netdev_err(priv->dev, "%s: error: card has no data for host\n", in if_spi_c2h_cmd()
710 err = spu_read(card, IF_SPI_CMD_RDWRPORT_REG, in if_spi_c2h_cmd()
711 card->cmd_buffer, ALIGN(len, 4)); in if_spi_c2h_cmd()
719 memcpy(priv->resp_buf[i], card->cmd_buffer, len); in if_spi_c2h_cmd()
730 /* Move data from the card to the host */
731 static int if_spi_c2h_data(struct if_spi_card *card) in if_spi_c2h_data() argument
733 struct lbs_private *priv = card->priv; in if_spi_c2h_data()
740 err = spu_read_u16(card, IF_SPI_SCRATCH_1_REG, &len); in if_spi_c2h_data()
744 netdev_err(priv->dev, "%s: error: card has no data for host\n", in if_spi_c2h_data()
750 "%s: error: card has %d bytes of data, but our maximum skb size is %zu\n", in if_spi_c2h_data()
766 err = spu_read(card, IF_SPI_DATA_RDWRPORT_REG, data, ALIGN(len, 4)); in if_spi_c2h_data()
773 err = lbs_process_rxed_packet(card->priv, skb); in if_spi_c2h_data()
783 /* Move data or a command from the host to the card. */
784 static void if_spi_h2c(struct if_spi_card *card, in if_spi_h2c() argument
787 struct lbs_private *priv = card->priv; in if_spi_h2c()
805 /* Write the data to the card */ in if_spi_h2c()
806 err = spu_write(card, port_reg, packet->buffer, packet->blen); in if_spi_h2c()
817 /* Inform the host about a card event */
818 static void if_spi_e2h(struct if_spi_card *card) in if_spi_e2h() argument
822 struct lbs_private *priv = card->priv; in if_spi_e2h()
824 err = spu_read_u32(card, IF_SPI_SCRATCH_3_REG, &cause); in if_spi_e2h()
828 /* re-enable the card event interrupt */ in if_spi_e2h()
829 err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_REG, in if_spi_e2h()
834 /* generate a card interrupt */ in if_spi_e2h()
835 err = spu_write_u16(card, IF_SPI_CARD_INT_CAUSE_REG, in if_spi_e2h()
849 struct if_spi_card *card; in if_spi_host_to_card_worker() local
855 card = container_of(work, struct if_spi_card, packet_work); in if_spi_host_to_card_worker()
856 priv = card->priv; in if_spi_host_to_card_worker()
862 err = spu_read_u16(card, IF_SPI_HOST_INT_STATUS_REG, in if_spi_host_to_card_worker()
870 err = if_spi_c2h_cmd(card); in if_spi_host_to_card_worker()
875 err = if_spi_c2h_data(card); in if_spi_host_to_card_worker()
881 * workaround: in PS mode, the card does not set the Command in if_spi_host_to_card_worker()
885 (card->priv->psstate != PS_STATE_FULL_POWER && in if_spi_host_to_card_worker()
889 * if there was a previous command sent, the card has in if_spi_host_to_card_worker()
894 lbs_host_to_card_done(card->priv); in if_spi_host_to_card_worker()
898 spin_lock_irqsave(&card->buffer_lock, flags); in if_spi_host_to_card_worker()
899 if (!list_empty(&card->cmd_packet_list)) { in if_spi_host_to_card_worker()
900 packet = (struct if_spi_packet *)(card-> in if_spi_host_to_card_worker()
904 spin_unlock_irqrestore(&card->buffer_lock, flags); in if_spi_host_to_card_worker()
907 if_spi_h2c(card, packet, MVMS_CMD); in if_spi_host_to_card_worker()
912 spin_lock_irqsave(&card->buffer_lock, flags); in if_spi_host_to_card_worker()
913 if (!list_empty(&card->data_packet_list)) { in if_spi_host_to_card_worker()
914 packet = (struct if_spi_packet *)(card-> in if_spi_host_to_card_worker()
918 spin_unlock_irqrestore(&card->buffer_lock, flags); in if_spi_host_to_card_worker()
921 if_spi_h2c(card, packet, MVMS_DAT); in if_spi_host_to_card_worker()
924 if_spi_e2h(card); in if_spi_host_to_card_worker()
932 * Host to Card
942 struct if_spi_card *card = priv->card; in if_spi_host_to_card() local
965 spin_lock_irqsave(&card->buffer_lock, flags); in if_spi_host_to_card()
966 list_add_tail(&packet->list, &card->cmd_packet_list); in if_spi_host_to_card()
967 spin_unlock_irqrestore(&card->buffer_lock, flags); in if_spi_host_to_card()
971 spin_lock_irqsave(&card->buffer_lock, flags); in if_spi_host_to_card()
972 list_add_tail(&packet->list, &card->data_packet_list); in if_spi_host_to_card()
973 spin_unlock_irqrestore(&card->buffer_lock, flags); in if_spi_host_to_card()
984 queue_work(card->workqueue, &card->packet_work); in if_spi_host_to_card()
997 struct if_spi_card *card = dev_id; in if_spi_host_interrupt() local
999 queue_work(card->workqueue, &card->packet_work); in if_spi_host_interrupt()
1008 static int if_spi_init_card(struct if_spi_card *card) in if_spi_init_card() argument
1010 struct lbs_private *priv = card->priv; in if_spi_init_card()
1016 err = spu_init(card, card->pdata->use_dummy_writes); in if_spi_init_card()
1019 err = spu_get_chip_revision(card, &card->card_id, &card->card_rev); in if_spi_init_card()
1023 err = spu_read_u32(card, IF_SPI_SCRATCH_4_REG, &scratch); in if_spi_init_card()
1030 /* Check if we support this card */ in if_spi_init_card()
1032 if (card->card_id == fw_table[i].model) in if_spi_init_card()
1037 card->card_id); in if_spi_init_card()
1042 err = lbs_get_firmware(&card->spi->dev, card->card_id, in if_spi_init_card()
1054 card->card_id, card->card_rev, in if_spi_init_card()
1055 card->spi->controller->bus_num, in if_spi_init_card()
1056 spi_get_chipselect(card->spi, 0), in if_spi_init_card()
1057 card->spi->max_speed_hz); in if_spi_init_card()
1058 err = if_spi_prog_helper_firmware(card, helper); in if_spi_init_card()
1061 err = if_spi_prog_main_firmware(card, mainfw); in if_spi_init_card()
1067 err = spu_set_interrupt_mode(card, 0, 1); in if_spi_init_card()
1077 struct if_spi_card *card; in if_spi_resume_worker() local
1079 card = container_of(work, struct if_spi_card, resume_work); in if_spi_resume_worker()
1081 if (card->suspended) { in if_spi_resume_worker()
1082 if (card->pdata->setup) in if_spi_resume_worker()
1083 card->pdata->setup(card->spi); in if_spi_resume_worker()
1085 /* Init card ... */ in if_spi_resume_worker()
1086 if_spi_init_card(card); in if_spi_resume_worker()
1088 enable_irq(card->spi->irq); in if_spi_resume_worker()
1091 lbs_resume(card->priv); in if_spi_resume_worker()
1093 card->suspended = 0; in if_spi_resume_worker()
1099 struct if_spi_card *card; in if_spi_probe() local
1115 /* Allocate card structure to represent this specific device */ in if_spi_probe()
1116 card = kzalloc(sizeof(struct if_spi_card), GFP_KERNEL); in if_spi_probe()
1117 if (!card) { in if_spi_probe()
1121 spi_set_drvdata(spi, card); in if_spi_probe()
1122 card->pdata = pdata; in if_spi_probe()
1123 card->spi = spi; in if_spi_probe()
1124 card->prev_xfer_time = jiffies; in if_spi_probe()
1126 INIT_LIST_HEAD(&card->cmd_packet_list); in if_spi_probe()
1127 INIT_LIST_HEAD(&card->data_packet_list); in if_spi_probe()
1128 spin_lock_init(&card->buffer_lock); in if_spi_probe()
1133 err = if_spi_init_card(card); in if_spi_probe()
1138 * Register our card with libertas. in if_spi_probe()
1141 priv = lbs_add_card(card, &spi->dev); in if_spi_probe()
1146 card->priv = priv; in if_spi_probe()
1148 priv->card = card; in if_spi_probe()
1156 card->workqueue = alloc_workqueue("libertas_spi", WQ_MEM_RECLAIM, 0); in if_spi_probe()
1157 if (!card->workqueue) { in if_spi_probe()
1161 INIT_WORK(&card->packet_work, if_spi_host_to_card_worker); in if_spi_probe()
1162 INIT_WORK(&card->resume_work, if_spi_resume_worker); in if_spi_probe()
1165 IRQF_TRIGGER_FALLING, "libertas_spi", card); in if_spi_probe()
1172 * Start the card. in if_spi_probe()
1186 free_irq(spi->irq, card); in if_spi_probe()
1188 destroy_workqueue(card->workqueue); in if_spi_probe()
1192 free_if_spi_card(card); in if_spi_probe()
1202 struct if_spi_card *card = spi_get_drvdata(spi); in libertas_spi_remove() local
1203 struct lbs_private *priv = card->priv; in libertas_spi_remove()
1207 cancel_work_sync(&card->resume_work); in libertas_spi_remove()
1212 free_irq(spi->irq, card); in libertas_spi_remove()
1213 destroy_workqueue(card->workqueue); in libertas_spi_remove()
1214 if (card->pdata->teardown) in libertas_spi_remove()
1215 card->pdata->teardown(spi); in libertas_spi_remove()
1216 free_if_spi_card(card); in libertas_spi_remove()
1222 struct if_spi_card *card = spi_get_drvdata(spi); in if_spi_suspend() local
1224 if (!card->suspended) { in if_spi_suspend()
1225 lbs_suspend(card->priv); in if_spi_suspend()
1226 flush_workqueue(card->workqueue); in if_spi_suspend()
1229 if (card->pdata->teardown) in if_spi_suspend()
1230 card->pdata->teardown(spi); in if_spi_suspend()
1231 card->suspended = 1; in if_spi_suspend()
1240 struct if_spi_card *card = spi_get_drvdata(spi); in if_spi_resume() local
1243 schedule_work(&card->resume_work); in if_spi_resume()