if_spi.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * linux/drivers/net/wireless/libertas/if_spi.c
  3. *
  4. * Driver for Marvell SPI WLAN cards.
  5. *
  6. * Copyright 2008 Analog Devices Inc.
  7. *
  8. * Authors:
  9. * Andrey Yurovsky <andrey@cozybit.com>
  10. * Colin McCabe <colin@cozybit.com>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or (at
  15. * your option) any later version.
  16. */
  17. #ifndef _LBS_IF_SPI_H_
  18. #define _LBS_IF_SPI_H_
  19. #define IPFIELD_ALIGN_OFFSET 2
  20. #define IF_SPI_CMD_BUF_SIZE 2400
  21. /***************** Firmware *****************/
  22. #define IF_SPI_FW_NAME_MAX 30
  23. #define MAX_MAIN_FW_LOAD_CRC_ERR 10
  24. /* Chunk size when loading the helper firmware */
  25. #define HELPER_FW_LOAD_CHUNK_SZ 64
  26. /* Value to write to indicate end of helper firmware dnld */
  27. #define FIRMWARE_DNLD_OK 0x0000
  28. /* Value to check once the main firmware is downloaded */
  29. #define SUCCESSFUL_FW_DOWNLOAD_MAGIC 0x88888888
  30. /***************** SPI Interface Unit *****************/
  31. /* Masks used in SPI register read/write operations */
  32. #define IF_SPI_READ_OPERATION_MASK 0x0
  33. #define IF_SPI_WRITE_OPERATION_MASK 0x8000
  34. /* SPI register offsets. 4-byte aligned. */
  35. #define IF_SPI_DEVICEID_CTRL_REG 0x00 /* DeviceID controller reg */
  36. #define IF_SPI_IO_READBASE_REG 0x04 /* Read I/O base reg */
  37. #define IF_SPI_IO_WRITEBASE_REG 0x08 /* Write I/O base reg */
  38. #define IF_SPI_IO_RDWRPORT_REG 0x0C /* Read/Write I/O port reg */
  39. #define IF_SPI_CMD_READBASE_REG 0x10 /* Read command base reg */
  40. #define IF_SPI_CMD_WRITEBASE_REG 0x14 /* Write command base reg */
  41. #define IF_SPI_CMD_RDWRPORT_REG 0x18 /* Read/Write command port reg */
  42. #define IF_SPI_DATA_READBASE_REG 0x1C /* Read data base reg */
  43. #define IF_SPI_DATA_WRITEBASE_REG 0x20 /* Write data base reg */
  44. #define IF_SPI_DATA_RDWRPORT_REG 0x24 /* Read/Write data port reg */
  45. #define IF_SPI_SCRATCH_1_REG 0x28 /* Scratch reg 1 */
  46. #define IF_SPI_SCRATCH_2_REG 0x2C /* Scratch reg 2 */
  47. #define IF_SPI_SCRATCH_3_REG 0x30 /* Scratch reg 3 */
  48. #define IF_SPI_SCRATCH_4_REG 0x34 /* Scratch reg 4 */
  49. #define IF_SPI_TX_FRAME_SEQ_NUM_REG 0x38 /* Tx frame sequence number reg */
  50. #define IF_SPI_TX_FRAME_STATUS_REG 0x3C /* Tx frame status reg */
  51. #define IF_SPI_HOST_INT_CTRL_REG 0x40 /* Host interrupt controller reg */
  52. #define IF_SPI_CARD_INT_CAUSE_REG 0x44 /* Card interrupt cause reg */
  53. #define IF_SPI_CARD_INT_STATUS_REG 0x48 /* Card interrupt status reg */
  54. #define IF_SPI_CARD_INT_EVENT_MASK_REG 0x4C /* Card interrupt event mask */
  55. #define IF_SPI_CARD_INT_STATUS_MASK_REG 0x50 /* Card interrupt status mask */
  56. #define IF_SPI_CARD_INT_RESET_SELECT_REG 0x54 /* Card interrupt reset select */
  57. #define IF_SPI_HOST_INT_CAUSE_REG 0x58 /* Host interrupt cause reg */
  58. #define IF_SPI_HOST_INT_STATUS_REG 0x5C /* Host interrupt status reg */
  59. #define IF_SPI_HOST_INT_EVENT_MASK_REG 0x60 /* Host interrupt event mask */
  60. #define IF_SPI_HOST_INT_STATUS_MASK_REG 0x64 /* Host interrupt status mask */
  61. #define IF_SPI_HOST_INT_RESET_SELECT_REG 0x68 /* Host interrupt reset select */
  62. #define IF_SPI_DELAY_READ_REG 0x6C /* Delay read reg */
  63. #define IF_SPI_SPU_BUS_MODE_REG 0x70 /* SPU BUS mode reg */
  64. /***************** IF_SPI_DEVICEID_CTRL_REG *****************/
  65. #define IF_SPI_DEVICEID_CTRL_REG_TO_CARD_ID(dc) ((dc & 0xffff0000)>>16)
  66. #define IF_SPI_DEVICEID_CTRL_REG_TO_CARD_REV(dc) (dc & 0x000000ff)
  67. /***************** IF_SPI_HOST_INT_CTRL_REG *****************/
  68. /* Host Interrupt Control bit : Wake up */
  69. #define IF_SPI_HICT_WAKE_UP (1<<0)
  70. /* Host Interrupt Control bit : WLAN ready */
  71. #define IF_SPI_HICT_WLAN_READY (1<<1)
  72. /*#define IF_SPI_HICT_FIFO_FIRST_HALF_EMPTY (1<<2) */
  73. /*#define IF_SPI_HICT_FIFO_SECOND_HALF_EMPTY (1<<3) */
  74. /*#define IF_SPI_HICT_IRQSRC_WLAN (1<<4) */
  75. /* Host Interrupt Control bit : Tx auto download */
  76. #define IF_SPI_HICT_TX_DOWNLOAD_OVER_AUTO (1<<5)
  77. /* Host Interrupt Control bit : Rx auto upload */
  78. #define IF_SPI_HICT_RX_UPLOAD_OVER_AUTO (1<<6)
  79. /* Host Interrupt Control bit : Command auto download */
  80. #define IF_SPI_HICT_CMD_DOWNLOAD_OVER_AUTO (1<<7)
  81. /* Host Interrupt Control bit : Command auto upload */
  82. #define IF_SPI_HICT_CMD_UPLOAD_OVER_AUTO (1<<8)
  83. /***************** IF_SPI_CARD_INT_CAUSE_REG *****************/
  84. /* Card Interrupt Case bit : Tx download over */
  85. #define IF_SPI_CIC_TX_DOWNLOAD_OVER (1<<0)
  86. /* Card Interrupt Case bit : Rx upload over */
  87. #define IF_SPI_CIC_RX_UPLOAD_OVER (1<<1)
  88. /* Card Interrupt Case bit : Command download over */
  89. #define IF_SPI_CIC_CMD_DOWNLOAD_OVER (1<<2)
  90. /* Card Interrupt Case bit : Host event */
  91. #define IF_SPI_CIC_HOST_EVENT (1<<3)
  92. /* Card Interrupt Case bit : Command upload over */
  93. #define IF_SPI_CIC_CMD_UPLOAD_OVER (1<<4)
  94. /* Card Interrupt Case bit : Power down */
  95. #define IF_SPI_CIC_POWER_DOWN (1<<5)
  96. /***************** IF_SPI_CARD_INT_STATUS_REG *****************/
  97. #define IF_SPI_CIS_TX_DOWNLOAD_OVER (1<<0)
  98. #define IF_SPI_CIS_RX_UPLOAD_OVER (1<<1)
  99. #define IF_SPI_CIS_CMD_DOWNLOAD_OVER (1<<2)
  100. #define IF_SPI_CIS_HOST_EVENT (1<<3)
  101. #define IF_SPI_CIS_CMD_UPLOAD_OVER (1<<4)
  102. #define IF_SPI_CIS_POWER_DOWN (1<<5)
  103. /***************** IF_SPI_HOST_INT_CAUSE_REG *****************/
  104. #define IF_SPI_HICU_TX_DOWNLOAD_RDY (1<<0)
  105. #define IF_SPI_HICU_RX_UPLOAD_RDY (1<<1)
  106. #define IF_SPI_HICU_CMD_DOWNLOAD_RDY (1<<2)
  107. #define IF_SPI_HICU_CARD_EVENT (1<<3)
  108. #define IF_SPI_HICU_CMD_UPLOAD_RDY (1<<4)
  109. #define IF_SPI_HICU_IO_WR_FIFO_OVERFLOW (1<<5)
  110. #define IF_SPI_HICU_IO_RD_FIFO_UNDERFLOW (1<<6)
  111. #define IF_SPI_HICU_DATA_WR_FIFO_OVERFLOW (1<<7)
  112. #define IF_SPI_HICU_DATA_RD_FIFO_UNDERFLOW (1<<8)
  113. #define IF_SPI_HICU_CMD_WR_FIFO_OVERFLOW (1<<9)
  114. #define IF_SPI_HICU_CMD_RD_FIFO_UNDERFLOW (1<<10)
  115. /***************** IF_SPI_HOST_INT_STATUS_REG *****************/
  116. /* Host Interrupt Status bit : Tx download ready */
  117. #define IF_SPI_HIST_TX_DOWNLOAD_RDY (1<<0)
  118. /* Host Interrupt Status bit : Rx upload ready */
  119. #define IF_SPI_HIST_RX_UPLOAD_RDY (1<<1)
  120. /* Host Interrupt Status bit : Command download ready */
  121. #define IF_SPI_HIST_CMD_DOWNLOAD_RDY (1<<2)
  122. /* Host Interrupt Status bit : Card event */
  123. #define IF_SPI_HIST_CARD_EVENT (1<<3)
  124. /* Host Interrupt Status bit : Command upload ready */
  125. #define IF_SPI_HIST_CMD_UPLOAD_RDY (1<<4)
  126. /* Host Interrupt Status bit : I/O write FIFO overflow */
  127. #define IF_SPI_HIST_IO_WR_FIFO_OVERFLOW (1<<5)
  128. /* Host Interrupt Status bit : I/O read FIFO underflow */
  129. #define IF_SPI_HIST_IO_RD_FIFO_UNDRFLOW (1<<6)
  130. /* Host Interrupt Status bit : Data write FIFO overflow */
  131. #define IF_SPI_HIST_DATA_WR_FIFO_OVERFLOW (1<<7)
  132. /* Host Interrupt Status bit : Data read FIFO underflow */
  133. #define IF_SPI_HIST_DATA_RD_FIFO_UNDERFLOW (1<<8)
  134. /* Host Interrupt Status bit : Command write FIFO overflow */
  135. #define IF_SPI_HIST_CMD_WR_FIFO_OVERFLOW (1<<9)
  136. /* Host Interrupt Status bit : Command read FIFO underflow */
  137. #define IF_SPI_HIST_CMD_RD_FIFO_UNDERFLOW (1<<10)
  138. /***************** IF_SPI_HOST_INT_STATUS_MASK_REG *****************/
  139. /* Host Interrupt Status Mask bit : Tx download ready */
  140. #define IF_SPI_HISM_TX_DOWNLOAD_RDY (1<<0)
  141. /* Host Interrupt Status Mask bit : Rx upload ready */
  142. #define IF_SPI_HISM_RX_UPLOAD_RDY (1<<1)
  143. /* Host Interrupt Status Mask bit : Command download ready */
  144. #define IF_SPI_HISM_CMD_DOWNLOAD_RDY (1<<2)
  145. /* Host Interrupt Status Mask bit : Card event */
  146. #define IF_SPI_HISM_CARDEVENT (1<<3)
  147. /* Host Interrupt Status Mask bit : Command upload ready */
  148. #define IF_SPI_HISM_CMD_UPLOAD_RDY (1<<4)
  149. /* Host Interrupt Status Mask bit : I/O write FIFO overflow */
  150. #define IF_SPI_HISM_IO_WR_FIFO_OVERFLOW (1<<5)
  151. /* Host Interrupt Status Mask bit : I/O read FIFO underflow */
  152. #define IF_SPI_HISM_IO_RD_FIFO_UNDERFLOW (1<<6)
  153. /* Host Interrupt Status Mask bit : Data write FIFO overflow */
  154. #define IF_SPI_HISM_DATA_WR_FIFO_OVERFLOW (1<<7)
  155. /* Host Interrupt Status Mask bit : Data write FIFO underflow */
  156. #define IF_SPI_HISM_DATA_RD_FIFO_UNDERFLOW (1<<8)
  157. /* Host Interrupt Status Mask bit : Command write FIFO overflow */
  158. #define IF_SPI_HISM_CMD_WR_FIFO_OVERFLOW (1<<9)
  159. /* Host Interrupt Status Mask bit : Command write FIFO underflow */
  160. #define IF_SPI_HISM_CMD_RD_FIFO_UNDERFLOW (1<<10)
  161. /***************** IF_SPI_SPU_BUS_MODE_REG *****************/
  162. /* SCK edge on which the WLAN module outputs data on MISO */
  163. #define IF_SPI_BUS_MODE_SPI_CLOCK_PHASE_FALLING 0x8
  164. #define IF_SPI_BUS_MODE_SPI_CLOCK_PHASE_RISING 0x0
  165. /* In a SPU read operation, there is a delay between writing the SPU
  166. * register name and getting back data from the WLAN module.
  167. * This can be specified in terms of nanoseconds or in terms of dummy
  168. * clock cycles which the master must output before receiving a response. */
  169. #define IF_SPI_BUS_MODE_DELAY_METHOD_DUMMY_CLOCK 0x4
  170. #define IF_SPI_BUS_MODE_DELAY_METHOD_TIMED 0x0
  171. /* Some different modes of SPI operation */
  172. #define IF_SPI_BUS_MODE_8_BIT_ADDRESS_16_BIT_DATA 0x00
  173. #define IF_SPI_BUS_MODE_8_BIT_ADDRESS_32_BIT_DATA 0x01
  174. #define IF_SPI_BUS_MODE_16_BIT_ADDRESS_16_BIT_DATA 0x02
  175. #define IF_SPI_BUS_MODE_16_BIT_ADDRESS_32_BIT_DATA 0x03
  176. #endif