18c2ecf20Sopenharmony_ci/** 28c2ecf20Sopenharmony_ci * Copyright (c) 2017 Redpine Signals Inc. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Permission to use, copy, modify, and/or distribute this software for any 58c2ecf20Sopenharmony_ci * purpose with or without fee is hereby granted, provided that the above 68c2ecf20Sopenharmony_ci * copyright notice and this permission notice appear in all copies. 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 98c2ecf20Sopenharmony_ci * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 108c2ecf20Sopenharmony_ci * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 118c2ecf20Sopenharmony_ci * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 128c2ecf20Sopenharmony_ci * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 138c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 148c2ecf20Sopenharmony_ci * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 158c2ecf20Sopenharmony_ci */ 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#ifndef __RSI_HAL_H__ 188c2ecf20Sopenharmony_ci#define __RSI_HAL_H__ 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci/* Device Operating modes */ 218c2ecf20Sopenharmony_ci#define DEV_OPMODE_WIFI_ALONE 1 228c2ecf20Sopenharmony_ci#define DEV_OPMODE_BT_ALONE 4 238c2ecf20Sopenharmony_ci#define DEV_OPMODE_BT_LE_ALONE 8 248c2ecf20Sopenharmony_ci#define DEV_OPMODE_BT_DUAL 12 258c2ecf20Sopenharmony_ci#define DEV_OPMODE_STA_BT 5 268c2ecf20Sopenharmony_ci#define DEV_OPMODE_STA_BT_LE 9 278c2ecf20Sopenharmony_ci#define DEV_OPMODE_STA_BT_DUAL 13 288c2ecf20Sopenharmony_ci#define DEV_OPMODE_AP_BT 6 298c2ecf20Sopenharmony_ci#define DEV_OPMODE_AP_BT_DUAL 14 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci#define DEV_OPMODE_PARAM_DESC \ 328c2ecf20Sopenharmony_ci __stringify(DEV_OPMODE_WIFI_ALONE) "[Wi-Fi alone], " \ 338c2ecf20Sopenharmony_ci __stringify(DEV_OPMODE_BT_ALONE) "[BT classic alone], " \ 348c2ecf20Sopenharmony_ci __stringify(DEV_OPMODE_BT_LE_ALONE) "[BT LE alone], " \ 358c2ecf20Sopenharmony_ci __stringify(DEV_OPMODE_BT_DUAL) "[BT classic + BT LE alone], " \ 368c2ecf20Sopenharmony_ci __stringify(DEV_OPMODE_STA_BT) "[Wi-Fi STA + BT classic], " \ 378c2ecf20Sopenharmony_ci __stringify(DEV_OPMODE_STA_BT_LE) "[Wi-Fi STA + BT LE], " \ 388c2ecf20Sopenharmony_ci __stringify(DEV_OPMODE_STA_BT_DUAL) "[Wi-Fi STA + BT classic + BT LE], " \ 398c2ecf20Sopenharmony_ci __stringify(DEV_OPMODE_AP_BT) "[Wi-Fi AP + BT classic], " \ 408c2ecf20Sopenharmony_ci __stringify(DEV_OPMODE_AP_BT_DUAL) "[Wi-Fi AP + BT classic + BT LE]" 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci#define FLASH_WRITE_CHUNK_SIZE (4 * 1024) 438c2ecf20Sopenharmony_ci#define FLASH_SECTOR_SIZE (4 * 1024) 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci#define FLASH_SIZE_ADDR 0x04000016 468c2ecf20Sopenharmony_ci#define PING_BUFFER_ADDRESS 0x19000 478c2ecf20Sopenharmony_ci#define PONG_BUFFER_ADDRESS 0x1a000 488c2ecf20Sopenharmony_ci#define SWBL_REGIN 0x41050034 498c2ecf20Sopenharmony_ci#define SWBL_REGOUT 0x4105003c 508c2ecf20Sopenharmony_ci#define PING_WRITE 0x1 518c2ecf20Sopenharmony_ci#define PONG_WRITE 0x2 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci#define BL_CMD_TIMEOUT 2000 548c2ecf20Sopenharmony_ci#define BL_BURN_TIMEOUT (50 * 1000) 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci#define REGIN_VALID 0xA 578c2ecf20Sopenharmony_ci#define REGIN_INPUT 0xA0 588c2ecf20Sopenharmony_ci#define REGOUT_VALID 0xAB 598c2ecf20Sopenharmony_ci#define REGOUT_INVALID (~0xAB) 608c2ecf20Sopenharmony_ci#define CMD_PASS 0xAA 618c2ecf20Sopenharmony_ci#define CMD_FAIL 0xCC 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci#define LOAD_HOSTED_FW 'A' 648c2ecf20Sopenharmony_ci#define BURN_HOSTED_FW 'B' 658c2ecf20Sopenharmony_ci#define PING_VALID 'I' 668c2ecf20Sopenharmony_ci#define PONG_VALID 'O' 678c2ecf20Sopenharmony_ci#define PING_AVAIL 'I' 688c2ecf20Sopenharmony_ci#define PONG_AVAIL 'O' 698c2ecf20Sopenharmony_ci#define EOF_REACHED 'E' 708c2ecf20Sopenharmony_ci#define CHECK_CRC 'K' 718c2ecf20Sopenharmony_ci#define POLLING_MODE 'P' 728c2ecf20Sopenharmony_ci#define CONFIG_AUTO_READ_MODE 'R' 738c2ecf20Sopenharmony_ci#define JUMP_TO_ZERO_PC 'J' 748c2ecf20Sopenharmony_ci#define FW_LOADING_SUCCESSFUL 'S' 758c2ecf20Sopenharmony_ci#define LOADING_INITIATED '1' 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci#define RSI_ULP_RESET_REG 0x161 788c2ecf20Sopenharmony_ci#define RSI_WATCH_DOG_TIMER_1 0x16c 798c2ecf20Sopenharmony_ci#define RSI_WATCH_DOG_TIMER_2 0x16d 808c2ecf20Sopenharmony_ci#define RSI_WATCH_DOG_DELAY_TIMER_1 0x16e 818c2ecf20Sopenharmony_ci#define RSI_WATCH_DOG_DELAY_TIMER_2 0x16f 828c2ecf20Sopenharmony_ci#define RSI_WATCH_DOG_TIMER_ENABLE 0x170 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci/* Watchdog timer addresses for 9116 */ 858c2ecf20Sopenharmony_ci#define NWP_AHB_BASE_ADDR 0x41300000 868c2ecf20Sopenharmony_ci#define NWP_WWD_INTERRUPT_TIMER (NWP_AHB_BASE_ADDR + 0x300) 878c2ecf20Sopenharmony_ci#define NWP_WWD_SYSTEM_RESET_TIMER (NWP_AHB_BASE_ADDR + 0x304) 888c2ecf20Sopenharmony_ci#define NWP_WWD_WINDOW_TIMER (NWP_AHB_BASE_ADDR + 0x308) 898c2ecf20Sopenharmony_ci#define NWP_WWD_TIMER_SETTINGS (NWP_AHB_BASE_ADDR + 0x30C) 908c2ecf20Sopenharmony_ci#define NWP_WWD_MODE_AND_RSTART (NWP_AHB_BASE_ADDR + 0x310) 918c2ecf20Sopenharmony_ci#define NWP_WWD_RESET_BYPASS (NWP_AHB_BASE_ADDR + 0x314) 928c2ecf20Sopenharmony_ci#define NWP_FSM_INTR_MASK_REG (NWP_AHB_BASE_ADDR + 0x104) 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci/* Watchdog timer values */ 958c2ecf20Sopenharmony_ci#define NWP_WWD_INT_TIMER_CLKS 5 968c2ecf20Sopenharmony_ci#define NWP_WWD_SYS_RESET_TIMER_CLKS 4 978c2ecf20Sopenharmony_ci#define NWP_WWD_TIMER_DISABLE 0xAA0001 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci#define RSI_ULP_WRITE_0 00 1008c2ecf20Sopenharmony_ci#define RSI_ULP_WRITE_2 02 1018c2ecf20Sopenharmony_ci#define RSI_ULP_WRITE_50 50 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci#define RSI_RESTART_WDT BIT(11) 1048c2ecf20Sopenharmony_ci#define RSI_BYPASS_ULP_ON_WDT BIT(1) 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci#define RSI_ULP_TIMER_ENABLE ((0xaa000) | RSI_RESTART_WDT | \ 1078c2ecf20Sopenharmony_ci RSI_BYPASS_ULP_ON_WDT) 1088c2ecf20Sopenharmony_ci#define RSI_RF_SPI_PROG_REG_BASE_ADDR 0x40080000 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci#define RSI_GSPI_CTRL_REG0 (RSI_RF_SPI_PROG_REG_BASE_ADDR) 1118c2ecf20Sopenharmony_ci#define RSI_GSPI_CTRL_REG1 (RSI_RF_SPI_PROG_REG_BASE_ADDR + 0x2) 1128c2ecf20Sopenharmony_ci#define RSI_GSPI_DATA_REG0 (RSI_RF_SPI_PROG_REG_BASE_ADDR + 0x4) 1138c2ecf20Sopenharmony_ci#define RSI_GSPI_DATA_REG1 (RSI_RF_SPI_PROG_REG_BASE_ADDR + 0x6) 1148c2ecf20Sopenharmony_ci#define RSI_GSPI_DATA_REG2 (RSI_RF_SPI_PROG_REG_BASE_ADDR + 0x8) 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_ci#define RSI_GSPI_CTRL_REG0_VALUE 0x340 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci#define RSI_GSPI_DMA_MODE BIT(13) 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci#define RSI_GSPI_2_ULP BIT(12) 1218c2ecf20Sopenharmony_ci#define RSI_GSPI_TRIG BIT(7) 1228c2ecf20Sopenharmony_ci#define RSI_GSPI_READ BIT(6) 1238c2ecf20Sopenharmony_ci#define RSI_GSPI_RF_SPI_ACTIVE BIT(8) 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci/* Boot loader commands */ 1268c2ecf20Sopenharmony_ci#define SEND_RPS_FILE '2' 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci#define FW_IMAGE_MIN_ADDRESS (68 * 1024) 1298c2ecf20Sopenharmony_ci#define MAX_FLASH_FILE_SIZE (400 * 1024) //400K 1308c2ecf20Sopenharmony_ci#define FLASH_START_ADDRESS 16 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci#define COMMON_HAL_CARD_READY_IND 0x0 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci#define COMMAN_HAL_WAIT_FOR_CARD_READY 1 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci#define RSI_DEV_OPMODE_WIFI_ALONE 1 1378c2ecf20Sopenharmony_ci#define RSI_DEV_COEX_MODE_WIFI_ALONE 1 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci#define BBP_INFO_40MHZ 0x6 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ci#define FW_FLASH_OFFSET 0x820 1428c2ecf20Sopenharmony_ci#define LMAC_VER_OFFSET_9113 (FW_FLASH_OFFSET + 0x200) 1438c2ecf20Sopenharmony_ci#define LMAC_VER_OFFSET_9116 0x22C2 1448c2ecf20Sopenharmony_ci#define MAX_DWORD_ALIGN_BYTES 64 1458c2ecf20Sopenharmony_ci#define RSI_COMMON_REG_SIZE 2 1468c2ecf20Sopenharmony_ci#define RSI_9116_REG_SIZE 4 1478c2ecf20Sopenharmony_ci#define FW_ALIGN_SIZE 4 1488c2ecf20Sopenharmony_ci#define RSI_9116_FW_MAGIC_WORD 0x5aa5 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci#define MEM_ACCESS_CTRL_FROM_HOST 0x41300000 1518c2ecf20Sopenharmony_ci#define RAM_384K_ACCESS_FROM_TA (BIT(2) | BIT(3) | BIT(4) | BIT(5) | \ 1528c2ecf20Sopenharmony_ci BIT(20) | BIT(21) | BIT(22) | \ 1538c2ecf20Sopenharmony_ci BIT(23) | BIT(24) | BIT(25)) 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_cistruct bl_header { 1568c2ecf20Sopenharmony_ci __le32 flags; 1578c2ecf20Sopenharmony_ci __le32 image_no; 1588c2ecf20Sopenharmony_ci __le32 check_sum; 1598c2ecf20Sopenharmony_ci __le32 flash_start_address; 1608c2ecf20Sopenharmony_ci __le32 flash_len; 1618c2ecf20Sopenharmony_ci} __packed; 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_cistruct ta_metadata { 1648c2ecf20Sopenharmony_ci char *name; 1658c2ecf20Sopenharmony_ci unsigned int address; 1668c2ecf20Sopenharmony_ci}; 1678c2ecf20Sopenharmony_ci 1688c2ecf20Sopenharmony_ci#define RSI_BL_CTRL_LEN_MASK 0xFFFFFF 1698c2ecf20Sopenharmony_ci#define RSI_BL_CTRL_SPI_32BIT_MODE BIT(27) 1708c2ecf20Sopenharmony_ci#define RSI_BL_CTRL_REL_TA_SOFTRESET BIT(28) 1718c2ecf20Sopenharmony_ci#define RSI_BL_CTRL_START_FROM_ROM_PC BIT(29) 1728c2ecf20Sopenharmony_ci#define RSI_BL_CTRL_SPI_8BIT_MODE BIT(30) 1738c2ecf20Sopenharmony_ci#define RSI_BL_CTRL_LAST_ENTRY BIT(31) 1748c2ecf20Sopenharmony_cistruct bootload_entry { 1758c2ecf20Sopenharmony_ci __le32 control; 1768c2ecf20Sopenharmony_ci __le32 dst_addr; 1778c2ecf20Sopenharmony_ci} __packed; 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_cistruct bootload_ds { 1808c2ecf20Sopenharmony_ci __le16 fixed_pattern; 1818c2ecf20Sopenharmony_ci __le16 offset; 1828c2ecf20Sopenharmony_ci __le32 reserved; 1838c2ecf20Sopenharmony_ci struct bootload_entry bl_entry[7]; 1848c2ecf20Sopenharmony_ci} __packed; 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_cistruct rsi_mgmt_desc { 1878c2ecf20Sopenharmony_ci __le16 len_qno; 1888c2ecf20Sopenharmony_ci u8 frame_type; 1898c2ecf20Sopenharmony_ci u8 misc_flags; 1908c2ecf20Sopenharmony_ci u8 xtend_desc_size; 1918c2ecf20Sopenharmony_ci u8 header_len; 1928c2ecf20Sopenharmony_ci __le16 frame_info; 1938c2ecf20Sopenharmony_ci __le16 rate_info; 1948c2ecf20Sopenharmony_ci __le16 bbp_info; 1958c2ecf20Sopenharmony_ci __le16 seq_ctrl; 1968c2ecf20Sopenharmony_ci u8 reserved2; 1978c2ecf20Sopenharmony_ci u8 sta_id; 1988c2ecf20Sopenharmony_ci} __packed; 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_cistruct rsi_data_desc { 2018c2ecf20Sopenharmony_ci __le16 len_qno; 2028c2ecf20Sopenharmony_ci u8 cfm_frame_type; 2038c2ecf20Sopenharmony_ci u8 misc_flags; 2048c2ecf20Sopenharmony_ci u8 xtend_desc_size; 2058c2ecf20Sopenharmony_ci u8 header_len; 2068c2ecf20Sopenharmony_ci __le16 frame_info; 2078c2ecf20Sopenharmony_ci __le16 rate_info; 2088c2ecf20Sopenharmony_ci __le16 bbp_info; 2098c2ecf20Sopenharmony_ci __le16 mac_flags; 2108c2ecf20Sopenharmony_ci u8 qid_tid; 2118c2ecf20Sopenharmony_ci u8 sta_id; 2128c2ecf20Sopenharmony_ci} __packed; 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_cistruct rsi_bt_desc { 2158c2ecf20Sopenharmony_ci __le16 len_qno; 2168c2ecf20Sopenharmony_ci __le16 reserved1; 2178c2ecf20Sopenharmony_ci __le32 reserved2; 2188c2ecf20Sopenharmony_ci __le32 reserved3; 2198c2ecf20Sopenharmony_ci __le16 reserved4; 2208c2ecf20Sopenharmony_ci __le16 bt_pkt_type; 2218c2ecf20Sopenharmony_ci} __packed; 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ciint rsi_hal_device_init(struct rsi_hw *adapter); 2248c2ecf20Sopenharmony_ciint rsi_prepare_mgmt_desc(struct rsi_common *common, struct sk_buff *skb); 2258c2ecf20Sopenharmony_ciint rsi_prepare_data_desc(struct rsi_common *common, struct sk_buff *skb); 2268c2ecf20Sopenharmony_ciint rsi_prepare_beacon(struct rsi_common *common, struct sk_buff *skb); 2278c2ecf20Sopenharmony_ciint rsi_send_pkt_to_bus(struct rsi_common *common, struct sk_buff *skb); 2288c2ecf20Sopenharmony_ciint rsi_send_bt_pkt(struct rsi_common *common, struct sk_buff *skb); 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_ci#endif 231