hwio.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /*
  2. * Low-level API for mac80211 ST-Ericsson CW1200 drivers
  3. *
  4. * Copyright (c) 2010, ST-Ericsson
  5. * Author: Dmitry Tarnyagin <dmitry.tarnyagin@lockless.no>
  6. *
  7. * Based on:
  8. * ST-Ericsson UMAC CW1200 driver which is
  9. * Copyright (c) 2010, ST-Ericsson
  10. * Author: Ajitpal Singh <ajitpal.singh@stericsson.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 version 2 as
  14. * published by the Free Software Foundation.
  15. */
  16. #ifndef CW1200_HWIO_H_INCLUDED
  17. #define CW1200_HWIO_H_INCLUDED
  18. /* extern */ struct cw1200_common;
  19. #define CW1200_CUT_11_ID_STR (0x302E3830)
  20. #define CW1200_CUT_22_ID_STR1 (0x302e3132)
  21. #define CW1200_CUT_22_ID_STR2 (0x32302e30)
  22. #define CW1200_CUT_22_ID_STR3 (0x3335)
  23. #define CW1200_CUT_ID_ADDR (0xFFF17F90)
  24. #define CW1200_CUT2_ID_ADDR (0xFFF1FF90)
  25. /* Download control area */
  26. /* boot loader start address in SRAM */
  27. #define DOWNLOAD_BOOT_LOADER_OFFSET (0x00000000)
  28. /* 32K, 0x4000 to 0xDFFF */
  29. #define DOWNLOAD_FIFO_OFFSET (0x00004000)
  30. /* 32K */
  31. #define DOWNLOAD_FIFO_SIZE (0x00008000)
  32. /* 128 bytes, 0xFF80 to 0xFFFF */
  33. #define DOWNLOAD_CTRL_OFFSET (0x0000FF80)
  34. #define DOWNLOAD_CTRL_DATA_DWORDS (32-6)
  35. struct download_cntl_t {
  36. /* size of whole firmware file (including Cheksum), host init */
  37. u32 image_size;
  38. /* downloading flags */
  39. u32 flags;
  40. /* No. of bytes put into the download, init & updated by host */
  41. u32 put;
  42. /* last traced program counter, last ARM reg_pc */
  43. u32 trace_pc;
  44. /* No. of bytes read from the download, host init, device updates */
  45. u32 get;
  46. /* r0, boot losader status, host init to pending, device updates */
  47. u32 status;
  48. /* Extra debug info, r1 to r14 if status=r0=DOWNLOAD_EXCEPTION */
  49. u32 debug_data[DOWNLOAD_CTRL_DATA_DWORDS];
  50. };
  51. #define DOWNLOAD_IMAGE_SIZE_REG \
  52. (DOWNLOAD_CTRL_OFFSET + offsetof(struct download_cntl_t, image_size))
  53. #define DOWNLOAD_FLAGS_REG \
  54. (DOWNLOAD_CTRL_OFFSET + offsetof(struct download_cntl_t, flags))
  55. #define DOWNLOAD_PUT_REG \
  56. (DOWNLOAD_CTRL_OFFSET + offsetof(struct download_cntl_t, put))
  57. #define DOWNLOAD_TRACE_PC_REG \
  58. (DOWNLOAD_CTRL_OFFSET + offsetof(struct download_cntl_t, trace_pc))
  59. #define DOWNLOAD_GET_REG \
  60. (DOWNLOAD_CTRL_OFFSET + offsetof(struct download_cntl_t, get))
  61. #define DOWNLOAD_STATUS_REG \
  62. (DOWNLOAD_CTRL_OFFSET + offsetof(struct download_cntl_t, status))
  63. #define DOWNLOAD_DEBUG_DATA_REG \
  64. (DOWNLOAD_CTRL_OFFSET + offsetof(struct download_cntl_t, debug_data))
  65. #define DOWNLOAD_DEBUG_DATA_LEN (108)
  66. #define DOWNLOAD_BLOCK_SIZE (1024)
  67. /* For boot loader detection */
  68. #define DOWNLOAD_ARE_YOU_HERE (0x87654321)
  69. #define DOWNLOAD_I_AM_HERE (0x12345678)
  70. /* Download error code */
  71. #define DOWNLOAD_PENDING (0xFFFFFFFF)
  72. #define DOWNLOAD_SUCCESS (0)
  73. #define DOWNLOAD_EXCEPTION (1)
  74. #define DOWNLOAD_ERR_MEM_1 (2)
  75. #define DOWNLOAD_ERR_MEM_2 (3)
  76. #define DOWNLOAD_ERR_SOFTWARE (4)
  77. #define DOWNLOAD_ERR_FILE_SIZE (5)
  78. #define DOWNLOAD_ERR_CHECKSUM (6)
  79. #define DOWNLOAD_ERR_OVERFLOW (7)
  80. #define DOWNLOAD_ERR_IMAGE (8)
  81. #define DOWNLOAD_ERR_HOST (9)
  82. #define DOWNLOAD_ERR_ABORT (10)
  83. #define SYS_BASE_ADDR_SILICON (0)
  84. #define PAC_BASE_ADDRESS_SILICON (SYS_BASE_ADDR_SILICON + 0x09000000)
  85. #define PAC_SHARED_MEMORY_SILICON (PAC_BASE_ADDRESS_SILICON)
  86. #define CW1200_APB(addr) (PAC_SHARED_MEMORY_SILICON + (addr))
  87. /* Device register definitions */
  88. /* WBF - SPI Register Addresses */
  89. #define ST90TDS_ADDR_ID_BASE (0x0000)
  90. /* 16/32 bits */
  91. #define ST90TDS_CONFIG_REG_ID (0x0000)
  92. /* 16/32 bits */
  93. #define ST90TDS_CONTROL_REG_ID (0x0001)
  94. /* 16 bits, Q mode W/R */
  95. #define ST90TDS_IN_OUT_QUEUE_REG_ID (0x0002)
  96. /* 32 bits, AHB bus R/W */
  97. #define ST90TDS_AHB_DPORT_REG_ID (0x0003)
  98. /* 16/32 bits */
  99. #define ST90TDS_SRAM_BASE_ADDR_REG_ID (0x0004)
  100. /* 32 bits, APB bus R/W */
  101. #define ST90TDS_SRAM_DPORT_REG_ID (0x0005)
  102. /* 32 bits, t_settle/general */
  103. #define ST90TDS_TSET_GEN_R_W_REG_ID (0x0006)
  104. /* 16 bits, Q mode read, no length */
  105. #define ST90TDS_FRAME_OUT_REG_ID (0x0007)
  106. #define ST90TDS_ADDR_ID_MAX (ST90TDS_FRAME_OUT_REG_ID)
  107. /* WBF - Control register bit set */
  108. /* next o/p length, bit 11 to 0 */
  109. #define ST90TDS_CONT_NEXT_LEN_MASK (0x0FFF)
  110. #define ST90TDS_CONT_WUP_BIT (BIT(12))
  111. #define ST90TDS_CONT_RDY_BIT (BIT(13))
  112. #define ST90TDS_CONT_IRQ_ENABLE (BIT(14))
  113. #define ST90TDS_CONT_RDY_ENABLE (BIT(15))
  114. #define ST90TDS_CONT_IRQ_RDY_ENABLE (BIT(14)|BIT(15))
  115. /* SPI Config register bit set */
  116. #define ST90TDS_CONFIG_FRAME_BIT (BIT(2))
  117. #define ST90TDS_CONFIG_WORD_MODE_BITS (BIT(3)|BIT(4))
  118. #define ST90TDS_CONFIG_WORD_MODE_1 (BIT(3))
  119. #define ST90TDS_CONFIG_WORD_MODE_2 (BIT(4))
  120. #define ST90TDS_CONFIG_ERROR_0_BIT (BIT(5))
  121. #define ST90TDS_CONFIG_ERROR_1_BIT (BIT(6))
  122. #define ST90TDS_CONFIG_ERROR_2_BIT (BIT(7))
  123. /* TBD: Sure??? */
  124. #define ST90TDS_CONFIG_CSN_FRAME_BIT (BIT(7))
  125. #define ST90TDS_CONFIG_ERROR_3_BIT (BIT(8))
  126. #define ST90TDS_CONFIG_ERROR_4_BIT (BIT(9))
  127. /* QueueM */
  128. #define ST90TDS_CONFIG_ACCESS_MODE_BIT (BIT(10))
  129. /* AHB bus */
  130. #define ST90TDS_CONFIG_AHB_PRFETCH_BIT (BIT(11))
  131. #define ST90TDS_CONFIG_CPU_CLK_DIS_BIT (BIT(12))
  132. /* APB bus */
  133. #define ST90TDS_CONFIG_PRFETCH_BIT (BIT(13))
  134. /* cpu reset */
  135. #define ST90TDS_CONFIG_CPU_RESET_BIT (BIT(14))
  136. #define ST90TDS_CONFIG_CLEAR_INT_BIT (BIT(15))
  137. /* For CW1200 the IRQ Enable and Ready Bits are in CONFIG register */
  138. #define ST90TDS_CONF_IRQ_ENABLE (BIT(16))
  139. #define ST90TDS_CONF_RDY_ENABLE (BIT(17))
  140. #define ST90TDS_CONF_IRQ_RDY_ENABLE (BIT(16)|BIT(17))
  141. int cw1200_data_read(struct cw1200_common *priv,
  142. void *buf, size_t buf_len);
  143. int cw1200_data_write(struct cw1200_common *priv,
  144. const void *buf, size_t buf_len);
  145. int cw1200_reg_read(struct cw1200_common *priv, u16 addr,
  146. void *buf, size_t buf_len);
  147. int cw1200_reg_write(struct cw1200_common *priv, u16 addr,
  148. const void *buf, size_t buf_len);
  149. static inline int cw1200_reg_read_16(struct cw1200_common *priv,
  150. u16 addr, u16 *val)
  151. {
  152. __le32 tmp;
  153. int i;
  154. i = cw1200_reg_read(priv, addr, &tmp, sizeof(tmp));
  155. *val = le32_to_cpu(tmp) & 0xfffff;
  156. return i;
  157. }
  158. static inline int cw1200_reg_write_16(struct cw1200_common *priv,
  159. u16 addr, u16 val)
  160. {
  161. __le32 tmp = cpu_to_le32((u32)val);
  162. return cw1200_reg_write(priv, addr, &tmp, sizeof(tmp));
  163. }
  164. static inline int cw1200_reg_read_32(struct cw1200_common *priv,
  165. u16 addr, u32 *val)
  166. {
  167. __le32 tmp;
  168. int i = cw1200_reg_read(priv, addr, &tmp, sizeof(tmp));
  169. *val = le32_to_cpu(tmp);
  170. return i;
  171. }
  172. static inline int cw1200_reg_write_32(struct cw1200_common *priv,
  173. u16 addr, u32 val)
  174. {
  175. __le32 tmp = cpu_to_le32(val);
  176. return cw1200_reg_write(priv, addr, &tmp, sizeof(val));
  177. }
  178. int cw1200_indirect_read(struct cw1200_common *priv, u32 addr, void *buf,
  179. size_t buf_len, u32 prefetch, u16 port_addr);
  180. int cw1200_apb_write(struct cw1200_common *priv, u32 addr, const void *buf,
  181. size_t buf_len);
  182. static inline int cw1200_apb_read(struct cw1200_common *priv, u32 addr,
  183. void *buf, size_t buf_len)
  184. {
  185. return cw1200_indirect_read(priv, addr, buf, buf_len,
  186. ST90TDS_CONFIG_PRFETCH_BIT,
  187. ST90TDS_SRAM_DPORT_REG_ID);
  188. }
  189. static inline int cw1200_ahb_read(struct cw1200_common *priv, u32 addr,
  190. void *buf, size_t buf_len)
  191. {
  192. return cw1200_indirect_read(priv, addr, buf, buf_len,
  193. ST90TDS_CONFIG_AHB_PRFETCH_BIT,
  194. ST90TDS_AHB_DPORT_REG_ID);
  195. }
  196. static inline int cw1200_apb_read_32(struct cw1200_common *priv,
  197. u32 addr, u32 *val)
  198. {
  199. __le32 tmp;
  200. int i = cw1200_apb_read(priv, addr, &tmp, sizeof(tmp));
  201. *val = le32_to_cpu(tmp);
  202. return i;
  203. }
  204. static inline int cw1200_apb_write_32(struct cw1200_common *priv,
  205. u32 addr, u32 val)
  206. {
  207. __le32 tmp = cpu_to_le32(val);
  208. return cw1200_apb_write(priv, addr, &tmp, sizeof(val));
  209. }
  210. static inline int cw1200_ahb_read_32(struct cw1200_common *priv,
  211. u32 addr, u32 *val)
  212. {
  213. __le32 tmp;
  214. int i = cw1200_ahb_read(priv, addr, &tmp, sizeof(tmp));
  215. *val = le32_to_cpu(tmp);
  216. return i;
  217. }
  218. #endif /* CW1200_HWIO_H_INCLUDED */