Thomas Gleixner | 4505153 | 2019-05-29 16:57:47 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Bluetooth supports for Qualcomm Atheros ROME chips |
| 4 | * |
| 5 | * Copyright (c) 2015 The Linux Foundation. All rights reserved. |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #define EDL_PATCH_CMD_OPCODE (0xFC00) |
| 9 | #define EDL_NVM_ACCESS_OPCODE (0xFC0B) |
Balakrishna Godavarthi | 5c0a1001 | 2019-01-16 18:01:15 +0530 | [diff] [blame] | 10 | #define EDL_WRITE_BD_ADDR_OPCODE (0xFC14) |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 11 | #define EDL_PATCH_CMD_LEN (1) |
| 12 | #define EDL_PATCH_VER_REQ_CMD (0x19) |
| 13 | #define EDL_PATCH_TLV_REQ_CMD (0x1E) |
Venkata Lakshmi Narayana Gubba | c0187b0 | 2020-12-08 17:25:29 +0530 | [diff] [blame] | 14 | #define EDL_GET_BUILD_INFO_CMD (0x20) |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 15 | #define EDL_NVM_ACCESS_SET_REQ_CMD (0x01) |
Sai Teja Aluvala | 4fac8a7 | 2022-01-07 11:50:53 +0530 | [diff] [blame] | 16 | #define EDL_PATCH_CONFIG_CMD (0x28) |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 17 | #define MAX_SIZE_PER_TLV_SEGMENT (243) |
Harish Bandi | a278088 | 2019-07-12 10:39:40 +0530 | [diff] [blame] | 18 | #define QCA_PRE_SHUTDOWN_CMD (0xFC08) |
Balakrishna Godavarthi | 590decc | 2020-06-12 17:50:28 +0530 | [diff] [blame] | 19 | #define QCA_DISABLE_LOGGING (0xFC17) |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 20 | |
| 21 | #define EDL_CMD_REQ_RES_EVT (0x00) |
| 22 | #define EDL_PATCH_VER_RES_EVT (0x19) |
| 23 | #define EDL_APP_VER_RES_EVT (0x02) |
| 24 | #define EDL_TVL_DNLD_RES_EVT (0x04) |
| 25 | #define EDL_CMD_EXE_STATUS_EVT (0x00) |
| 26 | #define EDL_SET_BAUDRATE_RSP_EVT (0x92) |
| 27 | #define EDL_NVM_ACCESS_CODE_EVT (0x0B) |
Sai Teja Aluvala | 4fac8a7 | 2022-01-07 11:50:53 +0530 | [diff] [blame] | 28 | #define EDL_PATCH_CONFIG_RES_EVT (0x00) |
Balakrishna Godavarthi | 590decc | 2020-06-12 17:50:28 +0530 | [diff] [blame] | 29 | #define QCA_DISABLE_LOGGING_SUB_OP (0x14) |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 30 | |
| 31 | #define EDL_TAG_ID_HCI (17) |
| 32 | #define EDL_TAG_ID_DEEP_SLEEP (27) |
| 33 | |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 34 | #define QCA_WCN3990_POWERON_PULSE 0xFC |
| 35 | #define QCA_WCN3990_POWEROFF_PULSE 0xC0 |
| 36 | |
Balakrishna Godavarthi | 32646db | 2019-05-28 14:43:22 -0700 | [diff] [blame] | 37 | #define QCA_HCI_CC_OPCODE 0xFC00 |
| 38 | #define QCA_HCI_CC_SUCCESS 0x00 |
| 39 | |
Venkata Lakshmi Narayana Gubba | 059924f | 2020-11-19 18:24:09 +0530 | [diff] [blame] | 40 | #define QCA_WCN3991_SOC_ID (0x40014320) |
| 41 | |
| 42 | /* QCA chipset version can be decided by patch and SoC |
| 43 | * version, combination with upper 2 bytes from SoC |
| 44 | * and lower 2 bytes from patch will be used. |
| 45 | */ |
| 46 | #define get_soc_ver(soc_id, rom_ver) \ |
| 47 | ((le32_to_cpu(soc_id) << 16) | (le16_to_cpu(rom_ver))) |
| 48 | |
| 49 | #define QCA_FW_BUILD_VER_LEN 255 |
| 50 | |
| 51 | |
Matthias Kaehlcke | 75c98a9 | 2019-03-12 16:02:57 -0700 | [diff] [blame] | 52 | enum qca_baudrate { |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 53 | QCA_BAUDRATE_115200 = 0, |
| 54 | QCA_BAUDRATE_57600, |
| 55 | QCA_BAUDRATE_38400, |
| 56 | QCA_BAUDRATE_19200, |
| 57 | QCA_BAUDRATE_9600, |
| 58 | QCA_BAUDRATE_230400, |
| 59 | QCA_BAUDRATE_250000, |
| 60 | QCA_BAUDRATE_460800, |
| 61 | QCA_BAUDRATE_500000, |
| 62 | QCA_BAUDRATE_720000, |
| 63 | QCA_BAUDRATE_921600, |
| 64 | QCA_BAUDRATE_1000000, |
| 65 | QCA_BAUDRATE_1250000, |
| 66 | QCA_BAUDRATE_2000000, |
| 67 | QCA_BAUDRATE_3000000, |
| 68 | QCA_BAUDRATE_4000000, |
| 69 | QCA_BAUDRATE_1600000, |
| 70 | QCA_BAUDRATE_3200000, |
| 71 | QCA_BAUDRATE_3500000, |
| 72 | QCA_BAUDRATE_AUTO = 0xFE, |
| 73 | QCA_BAUDRATE_RESERVED |
| 74 | }; |
| 75 | |
Balakrishna Godavarthi | e303d12 | 2019-11-06 15:18:31 +0530 | [diff] [blame] | 76 | enum qca_tlv_dnld_mode { |
| 77 | QCA_SKIP_EVT_NONE, |
| 78 | QCA_SKIP_EVT_VSE, |
| 79 | QCA_SKIP_EVT_CC, |
| 80 | QCA_SKIP_EVT_VSE_CC |
Loic Poulain | 6e03126 | 2018-04-26 13:13:27 +0200 | [diff] [blame] | 81 | }; |
| 82 | |
Balakrishna Godavarthi | e303d12 | 2019-11-06 15:18:31 +0530 | [diff] [blame] | 83 | enum qca_tlv_type { |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 84 | TLV_TYPE_PATCH = 1, |
Venkata Lakshmi Narayana Gubba | ecf6b2d | 2021-05-18 22:04:43 +0530 | [diff] [blame] | 85 | TLV_TYPE_NVM, |
| 86 | ELF_TYPE_PATCH, |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
Balakrishna Godavarthi | e303d12 | 2019-11-06 15:18:31 +0530 | [diff] [blame] | 89 | struct qca_fw_config { |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 90 | u8 type; |
| 91 | char fwname[64]; |
| 92 | uint8_t user_baud_rate; |
Balakrishna Godavarthi | e303d12 | 2019-11-06 15:18:31 +0530 | [diff] [blame] | 93 | enum qca_tlv_dnld_mode dnld_mode; |
| 94 | enum qca_tlv_dnld_mode dnld_type; |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | struct edl_event_hdr { |
| 98 | __u8 cresp; |
| 99 | __u8 rtype; |
Gustavo A. R. Silva | a7e4545 | 2020-02-26 17:02:27 -0600 | [diff] [blame] | 100 | __u8 data[]; |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 101 | } __packed; |
| 102 | |
Balakrishna Godavarthi | e303d12 | 2019-11-06 15:18:31 +0530 | [diff] [blame] | 103 | struct qca_btsoc_version { |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 104 | __le32 product_id; |
| 105 | __le16 patch_ver; |
Balakrishna Godavarthi | e303d12 | 2019-11-06 15:18:31 +0530 | [diff] [blame] | 106 | __le16 rom_ver; |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 107 | __le32 soc_id; |
| 108 | } __packed; |
| 109 | |
| 110 | struct tlv_seg_resp { |
| 111 | __u8 result; |
| 112 | } __packed; |
| 113 | |
| 114 | struct tlv_type_patch { |
| 115 | __le32 total_size; |
| 116 | __le32 data_length; |
| 117 | __u8 format_version; |
| 118 | __u8 signature; |
Loic Poulain | 6e03126 | 2018-04-26 13:13:27 +0200 | [diff] [blame] | 119 | __u8 download_mode; |
| 120 | __u8 reserved1; |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 121 | __le16 product_id; |
| 122 | __le16 rom_build; |
| 123 | __le16 patch_version; |
| 124 | __le16 reserved2; |
| 125 | __le32 entry; |
| 126 | } __packed; |
| 127 | |
| 128 | struct tlv_type_nvm { |
| 129 | __le16 tag_id; |
| 130 | __le16 tag_len; |
| 131 | __le32 reserve1; |
| 132 | __le32 reserve2; |
Gustavo A. R. Silva | a7e4545 | 2020-02-26 17:02:27 -0600 | [diff] [blame] | 133 | __u8 data[]; |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 134 | } __packed; |
| 135 | |
| 136 | struct tlv_type_hdr { |
| 137 | __le32 type_len; |
Gustavo A. R. Silva | a7e4545 | 2020-02-26 17:02:27 -0600 | [diff] [blame] | 138 | __u8 data[]; |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 139 | } __packed; |
| 140 | |
Balakrishna Godavarthi | aadebac | 2018-08-03 17:46:28 +0530 | [diff] [blame] | 141 | enum qca_btsoc_type { |
| 142 | QCA_INVALID = -1, |
| 143 | QCA_AR3002, |
| 144 | QCA_ROME, |
Harish Bandi | 523760b | 2019-04-26 19:26:01 +0530 | [diff] [blame] | 145 | QCA_WCN3990, |
| 146 | QCA_WCN3998, |
Rocky Liao | e5d6468 | 2020-03-25 10:26:37 +0800 | [diff] [blame] | 147 | QCA_WCN3991, |
| 148 | QCA_QCA6390, |
Venkata Lakshmi Narayana Gubba | d8f97da | 2021-05-18 22:04:42 +0530 | [diff] [blame] | 149 | QCA_WCN6750, |
Balakrishna Godavarthi | aadebac | 2018-08-03 17:46:28 +0530 | [diff] [blame] | 150 | }; |
| 151 | |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 152 | #if IS_ENABLED(CONFIG_BT_QCA) |
| 153 | |
| 154 | int qca_set_bdaddr_rome(struct hci_dev *hdev, const bdaddr_t *bdaddr); |
Balakrishna Godavarthi | aadebac | 2018-08-03 17:46:28 +0530 | [diff] [blame] | 155 | int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate, |
Venkata Lakshmi Narayana Gubba | 059924f | 2020-11-19 18:24:09 +0530 | [diff] [blame] | 156 | enum qca_btsoc_type soc_type, struct qca_btsoc_version ver, |
Rocky Liao | 99c905c | 2019-06-06 17:40:30 +0800 | [diff] [blame] | 157 | const char *firmware_name); |
Venkata Lakshmi Narayana Gubba | 059924f | 2020-11-19 18:24:09 +0530 | [diff] [blame] | 158 | int qca_read_soc_version(struct hci_dev *hdev, struct qca_btsoc_version *ver, |
Balakrishna Godavarthi | 7d250a0 | 2019-11-06 15:18:32 +0530 | [diff] [blame] | 159 | enum qca_btsoc_type); |
Balakrishna Godavarthi | 5c0a1001 | 2019-01-16 18:01:15 +0530 | [diff] [blame] | 160 | int qca_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr); |
Harish Bandi | a278088 | 2019-07-12 10:39:40 +0530 | [diff] [blame] | 161 | int qca_send_pre_shutdown_cmd(struct hci_dev *hdev); |
Harish Bandi | 523760b | 2019-04-26 19:26:01 +0530 | [diff] [blame] | 162 | static inline bool qca_is_wcn399x(enum qca_btsoc_type soc_type) |
| 163 | { |
Balakrishna Godavarthi | 7d250a0 | 2019-11-06 15:18:32 +0530 | [diff] [blame] | 164 | return soc_type == QCA_WCN3990 || soc_type == QCA_WCN3991 || |
| 165 | soc_type == QCA_WCN3998; |
Harish Bandi | 523760b | 2019-04-26 19:26:01 +0530 | [diff] [blame] | 166 | } |
Venkata Lakshmi Narayana Gubba | d8f97da | 2021-05-18 22:04:42 +0530 | [diff] [blame] | 167 | static inline bool qca_is_wcn6750(enum qca_btsoc_type soc_type) |
| 168 | { |
| 169 | return soc_type == QCA_WCN6750; |
| 170 | } |
| 171 | |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 172 | #else |
| 173 | |
| 174 | static inline int qca_set_bdaddr_rome(struct hci_dev *hdev, const bdaddr_t *bdaddr) |
| 175 | { |
| 176 | return -EOPNOTSUPP; |
| 177 | } |
| 178 | |
Balakrishna Godavarthi | aadebac | 2018-08-03 17:46:28 +0530 | [diff] [blame] | 179 | static inline int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate, |
Venkata Lakshmi Narayana Gubba | 059924f | 2020-11-19 18:24:09 +0530 | [diff] [blame] | 180 | enum qca_btsoc_type soc_type, |
| 181 | struct qca_btsoc_version ver, |
Rocky Liao | 99c905c | 2019-06-06 17:40:30 +0800 | [diff] [blame] | 182 | const char *firmware_name) |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame] | 183 | { |
| 184 | return -EOPNOTSUPP; |
| 185 | } |
| 186 | |
Venkata Lakshmi Narayana Gubba | 059924f | 2020-11-19 18:24:09 +0530 | [diff] [blame] | 187 | static inline int qca_read_soc_version(struct hci_dev *hdev, |
| 188 | struct qca_btsoc_version *ver, |
Balakrishna Godavarthi | 7d250a0 | 2019-11-06 15:18:32 +0530 | [diff] [blame] | 189 | enum qca_btsoc_type) |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 190 | { |
| 191 | return -EOPNOTSUPP; |
| 192 | } |
| 193 | |
Balakrishna Godavarthi | 5c0a1001 | 2019-01-16 18:01:15 +0530 | [diff] [blame] | 194 | static inline int qca_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr) |
| 195 | { |
| 196 | return -EOPNOTSUPP; |
| 197 | } |
| 198 | |
Harish Bandi | 523760b | 2019-04-26 19:26:01 +0530 | [diff] [blame] | 199 | static inline bool qca_is_wcn399x(enum qca_btsoc_type soc_type) |
| 200 | { |
| 201 | return false; |
| 202 | } |
Harish Bandi | a278088 | 2019-07-12 10:39:40 +0530 | [diff] [blame] | 203 | |
Venkata Lakshmi Narayana Gubba | d8f97da | 2021-05-18 22:04:42 +0530 | [diff] [blame] | 204 | static inline bool qca_is_wcn6750(enum qca_btsoc_type soc_type) |
| 205 | { |
| 206 | return false; |
| 207 | } |
| 208 | |
Harish Bandi | a278088 | 2019-07-12 10:39:40 +0530 | [diff] [blame] | 209 | static inline int qca_send_pre_shutdown_cmd(struct hci_dev *hdev) |
| 210 | { |
| 211 | return -EOPNOTSUPP; |
| 212 | } |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 213 | #endif |