xref: /linux/drivers/bluetooth/btqca.h (revision e7c22eeaff8565d9a8374f320238c251ca31480b)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  *  Bluetooth supports for Qualcomm Atheros ROME chips
4  *
5  *  Copyright (c) 2015 The Linux Foundation. All rights reserved.
6  */
7 
8 #define EDL_PATCH_CMD_OPCODE		(0xFC00)
9 #define EDL_NVM_ACCESS_OPCODE		(0xFC0B)
10 #define EDL_WRITE_BD_ADDR_OPCODE	(0xFC14)
11 #define EDL_PATCH_CMD_LEN		(1)
12 #define EDL_PATCH_VER_REQ_CMD		(0x19)
13 #define EDL_PATCH_TLV_REQ_CMD		(0x1E)
14 #define EDL_NVM_ACCESS_SET_REQ_CMD	(0x01)
15 #define MAX_SIZE_PER_TLV_SEGMENT	(243)
16 #define QCA_PRE_SHUTDOWN_CMD		(0xFC08)
17 #define QCA_DISABLE_LOGGING		(0xFC17)
18 
19 #define EDL_CMD_REQ_RES_EVT		(0x00)
20 #define EDL_PATCH_VER_RES_EVT		(0x19)
21 #define EDL_APP_VER_RES_EVT		(0x02)
22 #define EDL_TVL_DNLD_RES_EVT		(0x04)
23 #define EDL_CMD_EXE_STATUS_EVT		(0x00)
24 #define EDL_SET_BAUDRATE_RSP_EVT	(0x92)
25 #define EDL_NVM_ACCESS_CODE_EVT		(0x0B)
26 #define QCA_DISABLE_LOGGING_SUB_OP	(0x14)
27 
28 #define EDL_TAG_ID_HCI			(17)
29 #define EDL_TAG_ID_DEEP_SLEEP		(27)
30 
31 #define QCA_WCN3990_POWERON_PULSE	0xFC
32 #define QCA_WCN3990_POWEROFF_PULSE	0xC0
33 
34 #define QCA_HCI_CC_OPCODE		0xFC00
35 #define QCA_HCI_CC_SUCCESS		0x00
36 
37 #define QCA_WCN3991_SOC_ID		(0x40014320)
38 
39 /* QCA chipset version can be decided by patch and SoC
40  * version, combination with upper 2 bytes from SoC
41  * and lower 2 bytes from patch will be used.
42  */
43 #define get_soc_ver(soc_id, rom_ver)	\
44 	((le32_to_cpu(soc_id) << 16) | (le16_to_cpu(rom_ver)))
45 
46 #define QCA_FW_BUILD_VER_LEN		255
47 
48 
49 enum qca_baudrate {
50 	QCA_BAUDRATE_115200 	= 0,
51 	QCA_BAUDRATE_57600,
52 	QCA_BAUDRATE_38400,
53 	QCA_BAUDRATE_19200,
54 	QCA_BAUDRATE_9600,
55 	QCA_BAUDRATE_230400,
56 	QCA_BAUDRATE_250000,
57 	QCA_BAUDRATE_460800,
58 	QCA_BAUDRATE_500000,
59 	QCA_BAUDRATE_720000,
60 	QCA_BAUDRATE_921600,
61 	QCA_BAUDRATE_1000000,
62 	QCA_BAUDRATE_1250000,
63 	QCA_BAUDRATE_2000000,
64 	QCA_BAUDRATE_3000000,
65 	QCA_BAUDRATE_4000000,
66 	QCA_BAUDRATE_1600000,
67 	QCA_BAUDRATE_3200000,
68 	QCA_BAUDRATE_3500000,
69 	QCA_BAUDRATE_AUTO 	= 0xFE,
70 	QCA_BAUDRATE_RESERVED
71 };
72 
73 enum qca_tlv_dnld_mode {
74 	QCA_SKIP_EVT_NONE,
75 	QCA_SKIP_EVT_VSE,
76 	QCA_SKIP_EVT_CC,
77 	QCA_SKIP_EVT_VSE_CC
78 };
79 
80 enum qca_tlv_type {
81 	TLV_TYPE_PATCH = 1,
82 	TLV_TYPE_NVM
83 };
84 
85 struct qca_fw_config {
86 	u8 type;
87 	char fwname[64];
88 	uint8_t user_baud_rate;
89 	enum qca_tlv_dnld_mode dnld_mode;
90 	enum qca_tlv_dnld_mode dnld_type;
91 };
92 
93 struct edl_event_hdr {
94 	__u8 cresp;
95 	__u8 rtype;
96 	__u8 data[];
97 } __packed;
98 
99 struct qca_btsoc_version {
100 	__le32 product_id;
101 	__le16 patch_ver;
102 	__le16 rom_ver;
103 	__le32 soc_id;
104 } __packed;
105 
106 struct tlv_seg_resp {
107 	__u8 result;
108 } __packed;
109 
110 struct tlv_type_patch {
111 	__le32 total_size;
112 	__le32 data_length;
113 	__u8   format_version;
114 	__u8   signature;
115 	__u8   download_mode;
116 	__u8   reserved1;
117 	__le16 product_id;
118 	__le16 rom_build;
119 	__le16 patch_version;
120 	__le16 reserved2;
121 	__le32 entry;
122 } __packed;
123 
124 struct tlv_type_nvm {
125 	__le16 tag_id;
126 	__le16 tag_len;
127 	__le32 reserve1;
128 	__le32 reserve2;
129 	__u8   data[];
130 } __packed;
131 
132 struct tlv_type_hdr {
133 	__le32 type_len;
134 	__u8   data[];
135 } __packed;
136 
137 enum qca_btsoc_type {
138 	QCA_INVALID = -1,
139 	QCA_AR3002,
140 	QCA_ROME,
141 	QCA_WCN3990,
142 	QCA_WCN3998,
143 	QCA_WCN3991,
144 	QCA_QCA6390,
145 };
146 
147 #if IS_ENABLED(CONFIG_BT_QCA)
148 
149 int qca_set_bdaddr_rome(struct hci_dev *hdev, const bdaddr_t *bdaddr);
150 int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate,
151 		   enum qca_btsoc_type soc_type, struct qca_btsoc_version ver,
152 		   const char *firmware_name);
153 int qca_read_soc_version(struct hci_dev *hdev, struct qca_btsoc_version *ver,
154 			 enum qca_btsoc_type);
155 int qca_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr);
156 int qca_send_pre_shutdown_cmd(struct hci_dev *hdev);
157 static inline bool qca_is_wcn399x(enum qca_btsoc_type soc_type)
158 {
159 	return soc_type == QCA_WCN3990 || soc_type == QCA_WCN3991 ||
160 	       soc_type == QCA_WCN3998;
161 }
162 #else
163 
164 static inline int qca_set_bdaddr_rome(struct hci_dev *hdev, const bdaddr_t *bdaddr)
165 {
166 	return -EOPNOTSUPP;
167 }
168 
169 static inline int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate,
170 				 enum qca_btsoc_type soc_type,
171 				 struct qca_btsoc_version ver,
172 				 const char *firmware_name)
173 {
174 	return -EOPNOTSUPP;
175 }
176 
177 static inline int qca_read_soc_version(struct hci_dev *hdev,
178 				       struct qca_btsoc_version *ver,
179 				       enum qca_btsoc_type)
180 {
181 	return -EOPNOTSUPP;
182 }
183 
184 static inline int qca_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
185 {
186 	return -EOPNOTSUPP;
187 }
188 
189 static inline bool qca_is_wcn399x(enum qca_btsoc_type soc_type)
190 {
191 	return false;
192 }
193 
194 static inline int qca_send_pre_shutdown_cmd(struct hci_dev *hdev)
195 {
196 	return -EOPNOTSUPP;
197 }
198 #endif
199