162306a36Sopenharmony_ci/* 262306a36Sopenharmony_ci * Copyright (c) 2017 Redpine Signals Inc. 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * Permission to use, copy, modify, and/or distribute this software for any 562306a36Sopenharmony_ci * purpose with or without fee is hereby granted, provided that the above 662306a36Sopenharmony_ci * copyright notice and this permission notice appear in all copies. 762306a36Sopenharmony_ci * 862306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 962306a36Sopenharmony_ci * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 1062306a36Sopenharmony_ci * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 1162306a36Sopenharmony_ci * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 1262306a36Sopenharmony_ci * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 1362306a36Sopenharmony_ci * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 1462306a36Sopenharmony_ci * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 1562306a36Sopenharmony_ci */ 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci#ifndef __RSI_HAL_H__ 1862306a36Sopenharmony_ci#define __RSI_HAL_H__ 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci/* Device Operating modes */ 2162306a36Sopenharmony_ci#define DEV_OPMODE_WIFI_ALONE 1 2262306a36Sopenharmony_ci#define DEV_OPMODE_BT_ALONE 4 2362306a36Sopenharmony_ci#define DEV_OPMODE_BT_LE_ALONE 8 2462306a36Sopenharmony_ci#define DEV_OPMODE_BT_DUAL 12 2562306a36Sopenharmony_ci#define DEV_OPMODE_STA_BT 5 2662306a36Sopenharmony_ci#define DEV_OPMODE_STA_BT_LE 9 2762306a36Sopenharmony_ci#define DEV_OPMODE_STA_BT_DUAL 13 2862306a36Sopenharmony_ci#define DEV_OPMODE_AP_BT 6 2962306a36Sopenharmony_ci#define DEV_OPMODE_AP_BT_DUAL 14 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci#define DEV_OPMODE_PARAM_DESC \ 3262306a36Sopenharmony_ci __stringify(DEV_OPMODE_WIFI_ALONE) "[Wi-Fi alone], " \ 3362306a36Sopenharmony_ci __stringify(DEV_OPMODE_BT_ALONE) "[BT classic alone], " \ 3462306a36Sopenharmony_ci __stringify(DEV_OPMODE_BT_LE_ALONE) "[BT LE alone], " \ 3562306a36Sopenharmony_ci __stringify(DEV_OPMODE_BT_DUAL) "[BT classic + BT LE alone], " \ 3662306a36Sopenharmony_ci __stringify(DEV_OPMODE_STA_BT) "[Wi-Fi STA + BT classic], " \ 3762306a36Sopenharmony_ci __stringify(DEV_OPMODE_STA_BT_LE) "[Wi-Fi STA + BT LE], " \ 3862306a36Sopenharmony_ci __stringify(DEV_OPMODE_STA_BT_DUAL) "[Wi-Fi STA + BT classic + BT LE], " \ 3962306a36Sopenharmony_ci __stringify(DEV_OPMODE_AP_BT) "[Wi-Fi AP + BT classic], " \ 4062306a36Sopenharmony_ci __stringify(DEV_OPMODE_AP_BT_DUAL) "[Wi-Fi AP + BT classic + BT LE]" 4162306a36Sopenharmony_ci 4262306a36Sopenharmony_ci#define FLASH_WRITE_CHUNK_SIZE (4 * 1024) 4362306a36Sopenharmony_ci#define FLASH_SECTOR_SIZE (4 * 1024) 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ci#define FLASH_SIZE_ADDR 0x04000016 4662306a36Sopenharmony_ci#define PING_BUFFER_ADDRESS 0x19000 4762306a36Sopenharmony_ci#define PONG_BUFFER_ADDRESS 0x1a000 4862306a36Sopenharmony_ci#define SWBL_REGIN 0x41050034 4962306a36Sopenharmony_ci#define SWBL_REGOUT 0x4105003c 5062306a36Sopenharmony_ci#define PING_WRITE 0x1 5162306a36Sopenharmony_ci#define PONG_WRITE 0x2 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci#define BL_CMD_TIMEOUT 2000 5462306a36Sopenharmony_ci#define BL_BURN_TIMEOUT (50 * 1000) 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ci#define REGIN_VALID 0xA 5762306a36Sopenharmony_ci#define REGIN_INPUT 0xA0 5862306a36Sopenharmony_ci#define REGOUT_VALID 0xAB 5962306a36Sopenharmony_ci#define REGOUT_INVALID (~0xAB) 6062306a36Sopenharmony_ci#define CMD_PASS 0xAA 6162306a36Sopenharmony_ci#define CMD_FAIL 0xCC 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci#define LOAD_HOSTED_FW 'A' 6462306a36Sopenharmony_ci#define BURN_HOSTED_FW 'B' 6562306a36Sopenharmony_ci#define PING_VALID 'I' 6662306a36Sopenharmony_ci#define PONG_VALID 'O' 6762306a36Sopenharmony_ci#define PING_AVAIL 'I' 6862306a36Sopenharmony_ci#define PONG_AVAIL 'O' 6962306a36Sopenharmony_ci#define EOF_REACHED 'E' 7062306a36Sopenharmony_ci#define CHECK_CRC 'K' 7162306a36Sopenharmony_ci#define POLLING_MODE 'P' 7262306a36Sopenharmony_ci#define AUTO_READ_MODE 'R' 7362306a36Sopenharmony_ci#define JUMP_TO_ZERO_PC 'J' 7462306a36Sopenharmony_ci#define FW_LOADING_SUCCESSFUL 'S' 7562306a36Sopenharmony_ci#define LOADING_INITIATED '1' 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ci#define RSI_ULP_RESET_REG 0x161 7862306a36Sopenharmony_ci#define RSI_WATCH_DOG_TIMER_1 0x16c 7962306a36Sopenharmony_ci#define RSI_WATCH_DOG_TIMER_2 0x16d 8062306a36Sopenharmony_ci#define RSI_WATCH_DOG_DELAY_TIMER_1 0x16e 8162306a36Sopenharmony_ci#define RSI_WATCH_DOG_DELAY_TIMER_2 0x16f 8262306a36Sopenharmony_ci#define RSI_WATCH_DOG_TIMER_ENABLE 0x170 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ci/* Watchdog timer addresses for 9116 */ 8562306a36Sopenharmony_ci#define NWP_AHB_BASE_ADDR 0x41300000 8662306a36Sopenharmony_ci#define NWP_WWD_INTERRUPT_TIMER (NWP_AHB_BASE_ADDR + 0x300) 8762306a36Sopenharmony_ci#define NWP_WWD_SYSTEM_RESET_TIMER (NWP_AHB_BASE_ADDR + 0x304) 8862306a36Sopenharmony_ci#define NWP_WWD_WINDOW_TIMER (NWP_AHB_BASE_ADDR + 0x308) 8962306a36Sopenharmony_ci#define NWP_WWD_TIMER_SETTINGS (NWP_AHB_BASE_ADDR + 0x30C) 9062306a36Sopenharmony_ci#define NWP_WWD_MODE_AND_RSTART (NWP_AHB_BASE_ADDR + 0x310) 9162306a36Sopenharmony_ci#define NWP_WWD_RESET_BYPASS (NWP_AHB_BASE_ADDR + 0x314) 9262306a36Sopenharmony_ci#define NWP_FSM_INTR_MASK_REG (NWP_AHB_BASE_ADDR + 0x104) 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_ci/* Watchdog timer values */ 9562306a36Sopenharmony_ci#define NWP_WWD_INT_TIMER_CLKS 5 9662306a36Sopenharmony_ci#define NWP_WWD_SYS_RESET_TIMER_CLKS 4 9762306a36Sopenharmony_ci#define NWP_WWD_TIMER_DISABLE 0xAA0001 9862306a36Sopenharmony_ci 9962306a36Sopenharmony_ci#define RSI_ULP_WRITE_0 00 10062306a36Sopenharmony_ci#define RSI_ULP_WRITE_2 02 10162306a36Sopenharmony_ci#define RSI_ULP_WRITE_50 50 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci#define RSI_RESTART_WDT BIT(11) 10462306a36Sopenharmony_ci#define RSI_BYPASS_ULP_ON_WDT BIT(1) 10562306a36Sopenharmony_ci 10662306a36Sopenharmony_ci#define RSI_ULP_TIMER_ENABLE ((0xaa000) | RSI_RESTART_WDT | \ 10762306a36Sopenharmony_ci RSI_BYPASS_ULP_ON_WDT) 10862306a36Sopenharmony_ci#define RSI_RF_SPI_PROG_REG_BASE_ADDR 0x40080000 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_ci#define RSI_GSPI_CTRL_REG0 (RSI_RF_SPI_PROG_REG_BASE_ADDR) 11162306a36Sopenharmony_ci#define RSI_GSPI_CTRL_REG1 (RSI_RF_SPI_PROG_REG_BASE_ADDR + 0x2) 11262306a36Sopenharmony_ci#define RSI_GSPI_DATA_REG0 (RSI_RF_SPI_PROG_REG_BASE_ADDR + 0x4) 11362306a36Sopenharmony_ci#define RSI_GSPI_DATA_REG1 (RSI_RF_SPI_PROG_REG_BASE_ADDR + 0x6) 11462306a36Sopenharmony_ci#define RSI_GSPI_DATA_REG2 (RSI_RF_SPI_PROG_REG_BASE_ADDR + 0x8) 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_ci#define RSI_GSPI_CTRL_REG0_VALUE 0x340 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_ci#define RSI_GSPI_DMA_MODE BIT(13) 11962306a36Sopenharmony_ci 12062306a36Sopenharmony_ci#define RSI_GSPI_2_ULP BIT(12) 12162306a36Sopenharmony_ci#define RSI_GSPI_TRIG BIT(7) 12262306a36Sopenharmony_ci#define RSI_GSPI_READ BIT(6) 12362306a36Sopenharmony_ci#define RSI_GSPI_RF_SPI_ACTIVE BIT(8) 12462306a36Sopenharmony_ci 12562306a36Sopenharmony_ci/* Boot loader commands */ 12662306a36Sopenharmony_ci#define SEND_RPS_FILE '2' 12762306a36Sopenharmony_ci 12862306a36Sopenharmony_ci#define FW_IMAGE_MIN_ADDRESS (68 * 1024) 12962306a36Sopenharmony_ci#define MAX_FLASH_FILE_SIZE (400 * 1024) //400K 13062306a36Sopenharmony_ci#define FLASH_START_ADDRESS 16 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_ci#define COMMON_HAL_CARD_READY_IND 0x0 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_ci#define COMMAN_HAL_WAIT_FOR_CARD_READY 1 13562306a36Sopenharmony_ci 13662306a36Sopenharmony_ci#define RSI_DEV_OPMODE_WIFI_ALONE 1 13762306a36Sopenharmony_ci#define RSI_DEV_COEX_MODE_WIFI_ALONE 1 13862306a36Sopenharmony_ci 13962306a36Sopenharmony_ci#define BBP_INFO_40MHZ 0x6 14062306a36Sopenharmony_ci 14162306a36Sopenharmony_ci#define FW_FLASH_OFFSET 0x820 14262306a36Sopenharmony_ci#define LMAC_VER_OFFSET_9113 (FW_FLASH_OFFSET + 0x200) 14362306a36Sopenharmony_ci#define LMAC_VER_OFFSET_9116 0x22C2 14462306a36Sopenharmony_ci#define MAX_DWORD_ALIGN_BYTES 64 14562306a36Sopenharmony_ci#define RSI_COMMON_REG_SIZE 2 14662306a36Sopenharmony_ci#define RSI_9116_REG_SIZE 4 14762306a36Sopenharmony_ci#define FW_ALIGN_SIZE 4 14862306a36Sopenharmony_ci#define RSI_9116_FW_MAGIC_WORD 0x5aa5 14962306a36Sopenharmony_ci 15062306a36Sopenharmony_ci#define MEM_ACCESS_CTRL_FROM_HOST 0x41300000 15162306a36Sopenharmony_ci#define RAM_384K_ACCESS_FROM_TA (BIT(2) | BIT(3) | BIT(4) | BIT(5) | \ 15262306a36Sopenharmony_ci BIT(20) | BIT(21) | BIT(22) | \ 15362306a36Sopenharmony_ci BIT(23) | BIT(24) | BIT(25)) 15462306a36Sopenharmony_ci 15562306a36Sopenharmony_cistruct bl_header { 15662306a36Sopenharmony_ci __le32 flags; 15762306a36Sopenharmony_ci __le32 image_no; 15862306a36Sopenharmony_ci __le32 check_sum; 15962306a36Sopenharmony_ci __le32 flash_start_address; 16062306a36Sopenharmony_ci __le32 flash_len; 16162306a36Sopenharmony_ci} __packed; 16262306a36Sopenharmony_ci 16362306a36Sopenharmony_cistruct ta_metadata { 16462306a36Sopenharmony_ci char *name; 16562306a36Sopenharmony_ci unsigned int address; 16662306a36Sopenharmony_ci}; 16762306a36Sopenharmony_ci 16862306a36Sopenharmony_ci#define RSI_BL_CTRL_LEN_MASK 0xFFFFFF 16962306a36Sopenharmony_ci#define RSI_BL_CTRL_SPI_32BIT_MODE BIT(27) 17062306a36Sopenharmony_ci#define RSI_BL_CTRL_REL_TA_SOFTRESET BIT(28) 17162306a36Sopenharmony_ci#define RSI_BL_CTRL_START_FROM_ROM_PC BIT(29) 17262306a36Sopenharmony_ci#define RSI_BL_CTRL_SPI_8BIT_MODE BIT(30) 17362306a36Sopenharmony_ci#define RSI_BL_CTRL_LAST_ENTRY BIT(31) 17462306a36Sopenharmony_cistruct bootload_entry { 17562306a36Sopenharmony_ci __le32 control; 17662306a36Sopenharmony_ci __le32 dst_addr; 17762306a36Sopenharmony_ci} __packed; 17862306a36Sopenharmony_ci 17962306a36Sopenharmony_cistruct bootload_ds { 18062306a36Sopenharmony_ci __le16 fixed_pattern; 18162306a36Sopenharmony_ci __le16 offset; 18262306a36Sopenharmony_ci __le32 reserved; 18362306a36Sopenharmony_ci struct bootload_entry bl_entry[7]; 18462306a36Sopenharmony_ci} __packed; 18562306a36Sopenharmony_ci 18662306a36Sopenharmony_cistruct rsi_mgmt_desc { 18762306a36Sopenharmony_ci __le16 len_qno; 18862306a36Sopenharmony_ci u8 frame_type; 18962306a36Sopenharmony_ci u8 misc_flags; 19062306a36Sopenharmony_ci u8 xtend_desc_size; 19162306a36Sopenharmony_ci u8 header_len; 19262306a36Sopenharmony_ci __le16 frame_info; 19362306a36Sopenharmony_ci __le16 rate_info; 19462306a36Sopenharmony_ci __le16 bbp_info; 19562306a36Sopenharmony_ci __le16 seq_ctrl; 19662306a36Sopenharmony_ci u8 reserved2; 19762306a36Sopenharmony_ci u8 sta_id; 19862306a36Sopenharmony_ci} __packed; 19962306a36Sopenharmony_ci 20062306a36Sopenharmony_cistruct rsi_data_desc { 20162306a36Sopenharmony_ci __le16 len_qno; 20262306a36Sopenharmony_ci u8 cfm_frame_type; 20362306a36Sopenharmony_ci u8 misc_flags; 20462306a36Sopenharmony_ci u8 xtend_desc_size; 20562306a36Sopenharmony_ci u8 header_len; 20662306a36Sopenharmony_ci __le16 frame_info; 20762306a36Sopenharmony_ci __le16 rate_info; 20862306a36Sopenharmony_ci __le16 bbp_info; 20962306a36Sopenharmony_ci __le16 mac_flags; 21062306a36Sopenharmony_ci u8 qid_tid; 21162306a36Sopenharmony_ci u8 sta_id; 21262306a36Sopenharmony_ci} __packed; 21362306a36Sopenharmony_ci 21462306a36Sopenharmony_cistruct rsi_bt_desc { 21562306a36Sopenharmony_ci __le16 len_qno; 21662306a36Sopenharmony_ci __le16 reserved1; 21762306a36Sopenharmony_ci __le32 reserved2; 21862306a36Sopenharmony_ci __le32 reserved3; 21962306a36Sopenharmony_ci __le16 reserved4; 22062306a36Sopenharmony_ci __le16 bt_pkt_type; 22162306a36Sopenharmony_ci} __packed; 22262306a36Sopenharmony_ci 22362306a36Sopenharmony_ciint rsi_hal_device_init(struct rsi_hw *adapter); 22462306a36Sopenharmony_ciint rsi_prepare_mgmt_desc(struct rsi_common *common, struct sk_buff *skb); 22562306a36Sopenharmony_ciint rsi_prepare_data_desc(struct rsi_common *common, struct sk_buff *skb); 22662306a36Sopenharmony_ciint rsi_prepare_beacon(struct rsi_common *common, struct sk_buff *skb); 22762306a36Sopenharmony_ciint rsi_send_pkt_to_bus(struct rsi_common *common, struct sk_buff *skb); 22862306a36Sopenharmony_ciint rsi_send_bt_pkt(struct rsi_common *common, struct sk_buff *skb); 22962306a36Sopenharmony_ci 23062306a36Sopenharmony_ci#endif 231