rsi_hal.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * Copyright (c) 2017 Redpine Signals Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #ifndef __RSI_HAL_H__
  17. #define __RSI_HAL_H__
  18. /* Device Operating modes */
  19. #define DEV_OPMODE_WIFI_ALONE 1
  20. #define DEV_OPMODE_BT_ALONE 4
  21. #define DEV_OPMODE_BT_LE_ALONE 8
  22. #define DEV_OPMODE_BT_DUAL 12
  23. #define DEV_OPMODE_STA_BT 5
  24. #define DEV_OPMODE_STA_BT_LE 9
  25. #define DEV_OPMODE_STA_BT_DUAL 13
  26. #define DEV_OPMODE_AP_BT 6
  27. #define DEV_OPMODE_AP_BT_DUAL 14
  28. #define DEV_OPMODE_PARAM_DESC \
  29. __stringify(DEV_OPMODE_WIFI_ALONE) "[Wi-Fi alone], " \
  30. __stringify(DEV_OPMODE_BT_ALONE) "[BT classic alone], " \
  31. __stringify(DEV_OPMODE_BT_LE_ALONE) "[BT LE alone], " \
  32. __stringify(DEV_OPMODE_BT_DUAL) "[BT classic + BT LE alone], " \
  33. __stringify(DEV_OPMODE_STA_BT) "[Wi-Fi STA + BT classic], " \
  34. __stringify(DEV_OPMODE_STA_BT_LE) "[Wi-Fi STA + BT LE], " \
  35. __stringify(DEV_OPMODE_STA_BT_DUAL) "[Wi-Fi STA + BT classic + BT LE], " \
  36. __stringify(DEV_OPMODE_AP_BT) "[Wi-Fi AP + BT classic], " \
  37. __stringify(DEV_OPMODE_AP_BT_DUAL) "[Wi-Fi AP + BT classic + BT LE]"
  38. #define FLASH_WRITE_CHUNK_SIZE (4 * 1024)
  39. #define FLASH_SECTOR_SIZE (4 * 1024)
  40. #define FLASH_SIZE_ADDR 0x04000016
  41. #define PING_BUFFER_ADDRESS 0x19000
  42. #define PONG_BUFFER_ADDRESS 0x1a000
  43. #define SWBL_REGIN 0x41050034
  44. #define SWBL_REGOUT 0x4105003c
  45. #define PING_WRITE 0x1
  46. #define PONG_WRITE 0x2
  47. #define BL_CMD_TIMEOUT 2000
  48. #define BL_BURN_TIMEOUT (50 * 1000)
  49. #define REGIN_VALID 0xA
  50. #define REGIN_INPUT 0xA0
  51. #define REGOUT_VALID 0xAB
  52. #define REGOUT_INVALID (~0xAB)
  53. #define CMD_PASS 0xAA
  54. #define CMD_FAIL 0xCC
  55. #define LOAD_HOSTED_FW 'A'
  56. #define BURN_HOSTED_FW 'B'
  57. #define PING_VALID 'I'
  58. #define PONG_VALID 'O'
  59. #define PING_AVAIL 'I'
  60. #define PONG_AVAIL 'O'
  61. #define EOF_REACHED 'E'
  62. #define CHECK_CRC 'K'
  63. #define POLLING_MODE 'P'
  64. #define CONFIG_AUTO_READ_MODE 'R'
  65. #define JUMP_TO_ZERO_PC 'J'
  66. #define FW_LOADING_SUCCESSFUL 'S'
  67. #define LOADING_INITIATED '1'
  68. #define RSI_ULP_RESET_REG 0x161
  69. #define RSI_WATCH_DOG_TIMER_1 0x16c
  70. #define RSI_WATCH_DOG_TIMER_2 0x16d
  71. #define RSI_WATCH_DOG_DELAY_TIMER_1 0x16e
  72. #define RSI_WATCH_DOG_DELAY_TIMER_2 0x16f
  73. #define RSI_WATCH_DOG_TIMER_ENABLE 0x170
  74. /* Watchdog timer addresses for 9116 */
  75. #define NWP_AHB_BASE_ADDR 0x41300000
  76. #define NWP_WWD_INTERRUPT_TIMER (NWP_AHB_BASE_ADDR + 0x300)
  77. #define NWP_WWD_SYSTEM_RESET_TIMER (NWP_AHB_BASE_ADDR + 0x304)
  78. #define NWP_WWD_WINDOW_TIMER (NWP_AHB_BASE_ADDR + 0x308)
  79. #define NWP_WWD_TIMER_SETTINGS (NWP_AHB_BASE_ADDR + 0x30C)
  80. #define NWP_WWD_MODE_AND_RSTART (NWP_AHB_BASE_ADDR + 0x310)
  81. #define NWP_WWD_RESET_BYPASS (NWP_AHB_BASE_ADDR + 0x314)
  82. #define NWP_FSM_INTR_MASK_REG (NWP_AHB_BASE_ADDR + 0x104)
  83. /* Watchdog timer values */
  84. #define NWP_WWD_INT_TIMER_CLKS 5
  85. #define NWP_WWD_SYS_RESET_TIMER_CLKS 4
  86. #define NWP_WWD_TIMER_DISABLE 0xAA0001
  87. #define RSI_ULP_WRITE_0 00
  88. #define RSI_ULP_WRITE_2 02
  89. #define RSI_ULP_WRITE_50 50
  90. #define RSI_RESTART_WDT BIT(11)
  91. #define RSI_BYPASS_ULP_ON_WDT BIT(1)
  92. #define RSI_ULP_TIMER_ENABLE ((0xaa000) | RSI_RESTART_WDT | \
  93. RSI_BYPASS_ULP_ON_WDT)
  94. #define RSI_RF_SPI_PROG_REG_BASE_ADDR 0x40080000
  95. #define RSI_GSPI_CTRL_REG0 (RSI_RF_SPI_PROG_REG_BASE_ADDR)
  96. #define RSI_GSPI_CTRL_REG1 (RSI_RF_SPI_PROG_REG_BASE_ADDR + 0x2)
  97. #define RSI_GSPI_DATA_REG0 (RSI_RF_SPI_PROG_REG_BASE_ADDR + 0x4)
  98. #define RSI_GSPI_DATA_REG1 (RSI_RF_SPI_PROG_REG_BASE_ADDR + 0x6)
  99. #define RSI_GSPI_DATA_REG2 (RSI_RF_SPI_PROG_REG_BASE_ADDR + 0x8)
  100. #define RSI_GSPI_CTRL_REG0_VALUE 0x340
  101. #define RSI_GSPI_DMA_MODE BIT(13)
  102. #define RSI_GSPI_2_ULP BIT(12)
  103. #define RSI_GSPI_TRIG BIT(7)
  104. #define RSI_GSPI_READ BIT(6)
  105. #define RSI_GSPI_RF_SPI_ACTIVE BIT(8)
  106. /* Boot loader commands */
  107. #define SEND_RPS_FILE '2'
  108. #define FW_IMAGE_MIN_ADDRESS (68 * 1024)
  109. #define MAX_FLASH_FILE_SIZE (400 * 1024) //400K
  110. #define FLASH_START_ADDRESS 16
  111. #define COMMON_HAL_CARD_READY_IND 0x0
  112. #define COMMAN_HAL_WAIT_FOR_CARD_READY 1
  113. #define RSI_DEV_OPMODE_WIFI_ALONE 1
  114. #define RSI_DEV_COEX_MODE_WIFI_ALONE 1
  115. #define BBP_INFO_40MHZ 0x6
  116. #define FW_FLASH_OFFSET 0x820
  117. #define LMAC_VER_OFFSET_9113 (FW_FLASH_OFFSET + 0x200)
  118. #define LMAC_VER_OFFSET_9116 0x22C2
  119. #define MAX_DWORD_ALIGN_BYTES 64
  120. #define RSI_COMMON_REG_SIZE 2
  121. #define RSI_9116_REG_SIZE 4
  122. #define FW_ALIGN_SIZE 4
  123. #define RSI_9116_FW_MAGIC_WORD 0x5aa5
  124. #define MEM_ACCESS_CTRL_FROM_HOST 0x41300000
  125. #define RAM_384K_ACCESS_FROM_TA (BIT(2) | BIT(3) | BIT(4) | BIT(5) | \
  126. BIT(20) | BIT(21) | BIT(22) | \
  127. BIT(23) | BIT(24) | BIT(25))
  128. struct bl_header {
  129. __le32 flags;
  130. __le32 image_no;
  131. __le32 check_sum;
  132. __le32 flash_start_address;
  133. __le32 flash_len;
  134. } __packed;
  135. struct ta_metadata {
  136. char *name;
  137. unsigned int address;
  138. };
  139. #define RSI_BL_CTRL_LEN_MASK 0xFFFFFF
  140. #define RSI_BL_CTRL_SPI_32BIT_MODE BIT(27)
  141. #define RSI_BL_CTRL_REL_TA_SOFTRESET BIT(28)
  142. #define RSI_BL_CTRL_START_FROM_ROM_PC BIT(29)
  143. #define RSI_BL_CTRL_SPI_8BIT_MODE BIT(30)
  144. #define RSI_BL_CTRL_LAST_ENTRY BIT(31)
  145. struct bootload_entry {
  146. __le32 control;
  147. __le32 dst_addr;
  148. } __packed;
  149. struct bootload_ds {
  150. __le16 fixed_pattern;
  151. __le16 offset;
  152. __le32 reserved;
  153. struct bootload_entry bl_entry[7];
  154. } __packed;
  155. struct rsi_mgmt_desc {
  156. __le16 len_qno;
  157. u8 frame_type;
  158. u8 misc_flags;
  159. u8 xtend_desc_size;
  160. u8 header_len;
  161. __le16 frame_info;
  162. __le16 rate_info;
  163. __le16 bbp_info;
  164. __le16 seq_ctrl;
  165. u8 reserved2;
  166. u8 sta_id;
  167. } __packed;
  168. struct rsi_data_desc {
  169. __le16 len_qno;
  170. u8 cfm_frame_type;
  171. u8 misc_flags;
  172. u8 xtend_desc_size;
  173. u8 header_len;
  174. __le16 frame_info;
  175. __le16 rate_info;
  176. __le16 bbp_info;
  177. __le16 mac_flags;
  178. u8 qid_tid;
  179. u8 sta_id;
  180. } __packed;
  181. struct rsi_bt_desc {
  182. __le16 len_qno;
  183. __le16 reserved1;
  184. __le32 reserved2;
  185. __le32 reserved3;
  186. __le16 reserved4;
  187. __le16 bt_pkt_type;
  188. } __packed;
  189. int rsi_hal_device_init(struct rsi_hw *adapter);
  190. int rsi_prepare_mgmt_desc(struct rsi_common *common, struct sk_buff *skb);
  191. int rsi_prepare_data_desc(struct rsi_common *common, struct sk_buff *skb);
  192. int rsi_prepare_beacon(struct rsi_common *common, struct sk_buff *skb);
  193. int rsi_send_pkt_to_bus(struct rsi_common *common, struct sk_buff *skb);
  194. int rsi_send_bt_pkt(struct rsi_common *common, struct sk_buff *skb);
  195. #endif