aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/libertas/if_spi.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/libertas/if_spi.c')
-rw-r--r--drivers/net/wireless/libertas/if_spi.c134
1 files changed, 87 insertions, 47 deletions
diff --git a/drivers/net/wireless/libertas/if_spi.c b/drivers/net/wireless/libertas/if_spi.c
index 078ef43d957d..67de5b3c68b2 100644
--- a/drivers/net/wireless/libertas/if_spi.c
+++ b/drivers/net/wireless/libertas/if_spi.c
@@ -143,8 +143,10 @@ static void spu_transaction_finish(struct if_spi_card *card)
143 card->prev_xfer_time = jiffies; 143 card->prev_xfer_time = jiffies;
144} 144}
145 145
146/* Write out a byte buffer to an SPI register, 146/*
147 * using a series of 16-bit transfers. */ 147 * Write out a byte buffer to an SPI register,
148 * using a series of 16-bit transfers.
149 */
148static int spu_write(struct if_spi_card *card, u16 reg, const u8 *buf, int len) 150static int spu_write(struct if_spi_card *card, u16 reg, const u8 *buf, int len)
149{ 151{
150 int err = 0; 152 int err = 0;
@@ -208,8 +210,10 @@ static int spu_read(struct if_spi_card *card, u16 reg, u8 *buf, int len)
208 struct spi_transfer dummy_trans; 210 struct spi_transfer dummy_trans;
209 struct spi_transfer data_trans; 211 struct spi_transfer data_trans;
210 212
211 /* You must take an even number of bytes from the SPU, even if you 213 /*
212 * don't care about the last one. */ 214 * You must take an even number of bytes from the SPU, even if you
215 * don't care about the last one.
216 */
213 BUG_ON(len & 0x1); 217 BUG_ON(len & 0x1);
214 218
215 spu_transaction_init(card); 219 spu_transaction_init(card);
@@ -258,8 +262,10 @@ static inline int spu_read_u16(struct if_spi_card *card, u16 reg, u16 *val)
258 return ret; 262 return ret;
259} 263}
260 264
261/* Read 32 bits from an SPI register. 265/*
262 * The low 16 bits are read first. */ 266 * Read 32 bits from an SPI register.
267 * The low 16 bits are read first.
268 */
263static int spu_read_u32(struct if_spi_card *card, u16 reg, u32 *val) 269static int spu_read_u32(struct if_spi_card *card, u16 reg, u32 *val)
264{ 270{
265 __le32 buf; 271 __le32 buf;
@@ -271,13 +277,15 @@ static int spu_read_u32(struct if_spi_card *card, u16 reg, u32 *val)
271 return err; 277 return err;
272} 278}
273 279
274/* Keep reading 16 bits from an SPI register until you get the correct result. 280/*
281 * Keep reading 16 bits from an SPI register until you get the correct result.
275 * 282 *
276 * If mask = 0, the correct result is any non-zero number. 283 * If mask = 0, the correct result is any non-zero number.
277 * If mask != 0, the correct result is any number where 284 * If mask != 0, the correct result is any number where
278 * number & target_mask == target 285 * number & target_mask == target
279 * 286 *
280 * Returns -ETIMEDOUT if a second passes without the correct result. */ 287 * Returns -ETIMEDOUT if a second passes without the correct result.
288 */
281static int spu_wait_for_u16(struct if_spi_card *card, u16 reg, 289static int spu_wait_for_u16(struct if_spi_card *card, u16 reg,
282 u16 target_mask, u16 target) 290 u16 target_mask, u16 target)
283{ 291{
@@ -305,8 +313,10 @@ static int spu_wait_for_u16(struct if_spi_card *card, u16 reg,
305 } 313 }
306} 314}
307 315
308/* Read 16 bits from an SPI register until you receive a specific value. 316/*
309 * Returns -ETIMEDOUT if a 4 tries pass without success. */ 317 * Read 16 bits from an SPI register until you receive a specific value.
318 * Returns -ETIMEDOUT if a 4 tries pass without success.
319 */
310static int spu_wait_for_u32(struct if_spi_card *card, u32 reg, u32 target) 320static int spu_wait_for_u32(struct if_spi_card *card, u32 reg, u32 target)
311{ 321{
312 int err, try; 322 int err, try;
@@ -328,8 +338,10 @@ static int spu_set_interrupt_mode(struct if_spi_card *card,
328{ 338{
329 int err = 0; 339 int err = 0;
330 340
331 /* We can suppress a host interrupt by clearing the appropriate 341 /*
332 * bit in the "host interrupt status mask" register */ 342 * We can suppress a host interrupt by clearing the appropriate
343 * bit in the "host interrupt status mask" register
344 */
333 if (suppress_host_int) { 345 if (suppress_host_int) {
334 err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_MASK_REG, 0); 346 err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_MASK_REG, 0);
335 if (err) 347 if (err)
@@ -345,10 +357,12 @@ static int spu_set_interrupt_mode(struct if_spi_card *card,
345 return err; 357 return err;
346 } 358 }
347 359
348 /* If auto-interrupts are on, the completion of certain transactions 360 /*
361 * If auto-interrupts are on, the completion of certain transactions
349 * will trigger an interrupt automatically. If auto-interrupts 362 * will trigger an interrupt automatically. If auto-interrupts
350 * are off, we need to set the "Card Interrupt Cause" register to 363 * are off, we need to set the "Card Interrupt Cause" register to
351 * trigger a card interrupt. */ 364 * trigger a card interrupt.
365 */
352 if (auto_int) { 366 if (auto_int) {
353 err = spu_write_u16(card, IF_SPI_HOST_INT_CTRL_REG, 367 err = spu_write_u16(card, IF_SPI_HOST_INT_CTRL_REG,
354 IF_SPI_HICT_TX_DOWNLOAD_OVER_AUTO | 368 IF_SPI_HICT_TX_DOWNLOAD_OVER_AUTO |
@@ -402,8 +416,10 @@ static int spu_init(struct if_spi_card *card, int use_dummy_writes)
402 int err = 0; 416 int err = 0;
403 u32 delay; 417 u32 delay;
404 418
405 /* We have to start up in timed delay mode so that we can safely 419 /*
406 * read the Delay Read Register. */ 420 * We have to start up in timed delay mode so that we can safely
421 * read the Delay Read Register.
422 */
407 card->use_dummy_writes = 0; 423 card->use_dummy_writes = 0;
408 err = spu_set_bus_mode(card, 424 err = spu_set_bus_mode(card,
409 IF_SPI_BUS_MODE_SPI_CLOCK_PHASE_RISING | 425 IF_SPI_BUS_MODE_SPI_CLOCK_PHASE_RISING |
@@ -459,8 +475,10 @@ static int if_spi_prog_helper_firmware(struct if_spi_card *card,
459 475
460 /* Load helper firmware image */ 476 /* Load helper firmware image */
461 while (bytes_remaining > 0) { 477 while (bytes_remaining > 0) {
462 /* Scratch pad 1 should contain the number of bytes we 478 /*
463 * want to download to the firmware */ 479 * Scratch pad 1 should contain the number of bytes we
480 * want to download to the firmware
481 */
464 err = spu_write_u16(card, IF_SPI_SCRATCH_1_REG, 482 err = spu_write_u16(card, IF_SPI_SCRATCH_1_REG,
465 HELPER_FW_LOAD_CHUNK_SZ); 483 HELPER_FW_LOAD_CHUNK_SZ);
466 if (err) 484 if (err)
@@ -472,8 +490,10 @@ static int if_spi_prog_helper_firmware(struct if_spi_card *card,
472 if (err) 490 if (err)
473 goto out; 491 goto out;
474 492
475 /* Feed the data into the command read/write port reg 493 /*
476 * in chunks of 64 bytes */ 494 * Feed the data into the command read/write port reg
495 * in chunks of 64 bytes
496 */
477 memset(temp, 0, sizeof(temp)); 497 memset(temp, 0, sizeof(temp));
478 memcpy(temp, fw, 498 memcpy(temp, fw,
479 min(bytes_remaining, HELPER_FW_LOAD_CHUNK_SZ)); 499 min(bytes_remaining, HELPER_FW_LOAD_CHUNK_SZ));
@@ -495,9 +515,11 @@ static int if_spi_prog_helper_firmware(struct if_spi_card *card,
495 fw += HELPER_FW_LOAD_CHUNK_SZ; 515 fw += HELPER_FW_LOAD_CHUNK_SZ;
496 } 516 }
497 517
498 /* Once the helper / single stage firmware download is complete, 518 /*
519 * Once the helper / single stage firmware download is complete,
499 * write 0 to scratch pad 1 and interrupt the 520 * write 0 to scratch pad 1 and interrupt the
500 * bootloader. This completes the helper download. */ 521 * bootloader. This completes the helper download.
522 */
501 err = spu_write_u16(card, IF_SPI_SCRATCH_1_REG, FIRMWARE_DNLD_OK); 523 err = spu_write_u16(card, IF_SPI_SCRATCH_1_REG, FIRMWARE_DNLD_OK);
502 if (err) 524 if (err)
503 goto out; 525 goto out;
@@ -517,16 +539,20 @@ out:
517 return err; 539 return err;
518} 540}
519 541
520/* Returns the length of the next packet the firmware expects us to send 542/*
521 * Sets crc_err if the previous transfer had a CRC error. */ 543 * Returns the length of the next packet the firmware expects us to send.
544 * Sets crc_err if the previous transfer had a CRC error.
545 */
522static int if_spi_prog_main_firmware_check_len(struct if_spi_card *card, 546static int if_spi_prog_main_firmware_check_len(struct if_spi_card *card,
523 int *crc_err) 547 int *crc_err)
524{ 548{
525 u16 len; 549 u16 len;
526 int err = 0; 550 int err = 0;
527 551
528 /* wait until the host interrupt status register indicates 552 /*
529 * that we are ready to download */ 553 * wait until the host interrupt status register indicates
554 * that we are ready to download
555 */
530 err = spu_wait_for_u16(card, IF_SPI_HOST_INT_STATUS_REG, 556 err = spu_wait_for_u16(card, IF_SPI_HOST_INT_STATUS_REG,
531 IF_SPI_HIST_CMD_DOWNLOAD_RDY, 557 IF_SPI_HIST_CMD_DOWNLOAD_RDY,
532 IF_SPI_HIST_CMD_DOWNLOAD_RDY); 558 IF_SPI_HIST_CMD_DOWNLOAD_RDY);
@@ -587,8 +613,10 @@ static int if_spi_prog_main_firmware(struct if_spi_card *card,
587 goto out; 613 goto out;
588 } 614 }
589 if (bytes < 0) { 615 if (bytes < 0) {
590 /* If there are no more bytes left, we would normally 616 /*
591 * expect to have terminated with len = 0 */ 617 * If there are no more bytes left, we would normally
618 * expect to have terminated with len = 0
619 */
592 lbs_pr_err("Firmware load wants more bytes " 620 lbs_pr_err("Firmware load wants more bytes "
593 "than we have to offer.\n"); 621 "than we have to offer.\n");
594 break; 622 break;
@@ -660,14 +688,18 @@ static int if_spi_c2h_cmd(struct if_spi_card *card)
660 u16 len; 688 u16 len;
661 u8 i; 689 u8 i;
662 690
663 /* We need a buffer big enough to handle whatever people send to 691 /*
664 * hw_host_to_card */ 692 * We need a buffer big enough to handle whatever people send to
693 * hw_host_to_card
694 */
665 BUILD_BUG_ON(IF_SPI_CMD_BUF_SIZE < LBS_CMD_BUFFER_SIZE); 695 BUILD_BUG_ON(IF_SPI_CMD_BUF_SIZE < LBS_CMD_BUFFER_SIZE);
666 BUILD_BUG_ON(IF_SPI_CMD_BUF_SIZE < LBS_UPLD_SIZE); 696 BUILD_BUG_ON(IF_SPI_CMD_BUF_SIZE < LBS_UPLD_SIZE);
667 697
668 /* It's just annoying if the buffer size isn't a multiple of 4, because 698 /*
669 * then we might have len < IF_SPI_CMD_BUF_SIZE but 699 * It's just annoying if the buffer size isn't a multiple of 4, because
670 * ALIGN(len, 4) > IF_SPI_CMD_BUF_SIZE */ 700 * then we might have len < IF_SPI_CMD_BUF_SIZE but
701 * ALIGN(len, 4) > IF_SPI_CMD_BUF_SIZE
702 */
671 BUILD_BUG_ON(IF_SPI_CMD_BUF_SIZE % 4 != 0); 703 BUILD_BUG_ON(IF_SPI_CMD_BUF_SIZE % 4 != 0);
672 704
673 lbs_deb_enter(LBS_DEB_SPI); 705 lbs_deb_enter(LBS_DEB_SPI);
@@ -838,8 +870,10 @@ static void if_spi_host_to_card_worker(struct work_struct *work)
838 870
839 lbs_deb_enter(LBS_DEB_SPI); 871 lbs_deb_enter(LBS_DEB_SPI);
840 872
841 /* Read the host interrupt status register to see what we 873 /*
842 * can do. */ 874 * Read the host interrupt status register to see what we
875 * can do.
876 */
843 err = spu_read_u16(card, IF_SPI_HOST_INT_STATUS_REG, 877 err = spu_read_u16(card, IF_SPI_HOST_INT_STATUS_REG,
844 &hiStatus); 878 &hiStatus);
845 if (err) { 879 if (err) {
@@ -858,12 +892,15 @@ static void if_spi_host_to_card_worker(struct work_struct *work)
858 goto err; 892 goto err;
859 } 893 }
860 894
861 /* workaround: in PS mode, the card does not set the Command 895 /*
862 * Download Ready bit, but it sets TX Download Ready. */ 896 * workaround: in PS mode, the card does not set the Command
897 * Download Ready bit, but it sets TX Download Ready.
898 */
863 if (hiStatus & IF_SPI_HIST_CMD_DOWNLOAD_RDY || 899 if (hiStatus & IF_SPI_HIST_CMD_DOWNLOAD_RDY ||
864 (card->priv->psstate != PS_STATE_FULL_POWER && 900 (card->priv->psstate != PS_STATE_FULL_POWER &&
865 (hiStatus & IF_SPI_HIST_TX_DOWNLOAD_RDY))) { 901 (hiStatus & IF_SPI_HIST_TX_DOWNLOAD_RDY))) {
866 /* This means two things. First of all, 902 /*
903 * This means two things. First of all,
867 * if there was a previous command sent, the card has 904 * if there was a previous command sent, the card has
868 * successfully received it. 905 * successfully received it.
869 * Secondly, it is now ready to download another 906 * Secondly, it is now ready to download another
@@ -871,8 +908,7 @@ static void if_spi_host_to_card_worker(struct work_struct *work)
871 */ 908 */
872 lbs_host_to_card_done(card->priv); 909 lbs_host_to_card_done(card->priv);
873 910
874 /* Do we have any command packets from the host to 911 /* Do we have any command packets from the host to send? */
875 * send? */
876 packet = NULL; 912 packet = NULL;
877 spin_lock_irqsave(&card->buffer_lock, flags); 913 spin_lock_irqsave(&card->buffer_lock, flags);
878 if (!list_empty(&card->cmd_packet_list)) { 914 if (!list_empty(&card->cmd_packet_list)) {
@@ -886,8 +922,7 @@ static void if_spi_host_to_card_worker(struct work_struct *work)
886 if_spi_h2c(card, packet, MVMS_CMD); 922 if_spi_h2c(card, packet, MVMS_CMD);
887 } 923 }
888 if (hiStatus & IF_SPI_HIST_TX_DOWNLOAD_RDY) { 924 if (hiStatus & IF_SPI_HIST_TX_DOWNLOAD_RDY) {
889 /* Do we have any data packets from the host to 925 /* Do we have any data packets from the host to send? */
890 * send? */
891 packet = NULL; 926 packet = NULL;
892 spin_lock_irqsave(&card->buffer_lock, flags); 927 spin_lock_irqsave(&card->buffer_lock, flags);
893 if (!list_empty(&card->data_packet_list)) { 928 if (!list_empty(&card->data_packet_list)) {
@@ -914,7 +949,8 @@ err:
914 * Host to Card 949 * Host to Card
915 * 950 *
916 * Called from Libertas to transfer some data to the WLAN device 951 * Called from Libertas to transfer some data to the WLAN device
917 * We can't sleep here. */ 952 * We can't sleep here.
953 */
918static int if_spi_host_to_card(struct lbs_private *priv, 954static int if_spi_host_to_card(struct lbs_private *priv,
919 u8 type, u8 *buf, u16 nb) 955 u8 type, u8 *buf, u16 nb)
920{ 956{
@@ -1125,8 +1161,10 @@ static int __devinit if_spi_probe(struct spi_device *spi)
1125 if (err) 1161 if (err)
1126 goto free_card; 1162 goto free_card;
1127 1163
1128 /* Register our card with libertas. 1164 /*
1129 * This will call alloc_etherdev */ 1165 * Register our card with libertas.
1166 * This will call alloc_etherdev.
1167 */
1130 priv = lbs_add_card(card, &spi->dev); 1168 priv = lbs_add_card(card, &spi->dev);
1131 if (!priv) { 1169 if (!priv) {
1132 err = -ENOMEM; 1170 err = -ENOMEM;
@@ -1153,9 +1191,11 @@ static int __devinit if_spi_probe(struct spi_device *spi)
1153 goto terminate_workqueue; 1191 goto terminate_workqueue;
1154 } 1192 }
1155 1193
1156 /* Start the card. 1194 /*
1195 * Start the card.
1157 * This will call register_netdev, and we'll start 1196 * This will call register_netdev, and we'll start
1158 * getting interrupts... */ 1197 * getting interrupts...
1198 */
1159 err = lbs_start_card(priv); 1199 err = lbs_start_card(priv);
1160 if (err) 1200 if (err)
1161 goto release_irq; 1201 goto release_irq;