1 /* SPDX-License-Identifier: ISC */
2 /* Copyright (C) 2021 MediaTek Inc. */
4 #define FIRMWARE_MT7622 "mediatek/mt7622pr2h.bin"
5 #define FIRMWARE_MT7663 "mediatek/mt7663pr2h.bin"
6 #define FIRMWARE_MT7668 "mediatek/mt7668pr2h.bin"
7 #define FIRMWARE_MT7922 "mediatek/BT_RAM_CODE_MT7922_1_1_hdr.bin"
8 #define FIRMWARE_MT7961 "mediatek/BT_RAM_CODE_MT7961_1_2_hdr.bin"
9 #define FIRMWARE_MT7925 "mediatek/mt7925/BT_RAM_CODE_MT7925_1_1_hdr.bin"
11 #define HCI_EV_WMT 0xe4
12 #define HCI_WMT_MAX_EVENT_SIZE 64
14 #define BTMTK_WMT_REG_WRITE 0x1
15 #define BTMTK_WMT_REG_READ 0x2
17 #define MT7921_BTSYS_RST 0x70002610
18 #define MT7921_BTSYS_RST_WITH_GPIO BIT(7)
20 #define MT7921_PINMUX_0 0x70005050
21 #define MT7921_PINMUX_1 0x70005054
23 #define MT7921_DLSTATUS 0x7c053c10
24 #define BT_DL_STATE BIT(1)
26 #define MTK_COREDUMP_SIZE (1024 * 1000)
27 #define MTK_COREDUMP_END "coredump end"
28 #define MTK_COREDUMP_END_LEN (sizeof(MTK_COREDUMP_END))
29 #define MTK_COREDUMP_NUM 255
32 #define MTK_BT_MISC 0x70002510
33 #define MTK_BT_SUBSYS_RST 0x70002610
34 #define MTK_UDMA_INT_STA_BT 0x74000024
35 #define MTK_UDMA_INT_STA_BT1 0x74000308
36 #define MTK_BT_WDT_STATUS 0x740003A0
37 #define MTK_EP_RST_OPT 0x74011890
38 #define MTK_EP_RST_IN_OUT_OPT 0x00010001
39 #define MTK_BT_RST_DONE 0x00000100
40 #define MTK_BT_RESET_REG_CONNV3 0x70028610
41 #define MTK_BT_READ_DEV_ID 0x70010200
43 /* MediaTek ISO Interface */
44 #define MTK_ISO_IFNUM 2
47 BTMTK_WMT_PATCH_DWNLD
= 0x1,
49 BTMTK_WMT_WAKEUP
= 0x3,
51 BTMTK_WMT_FUNC_CTRL
= 0x6,
53 BTMTK_WMT_REGISTER
= 0x8,
54 BTMTK_WMT_SEMAPHORE
= 0x17,
59 BTMTK_WMT_PATCH_UNDONE
,
60 BTMTK_WMT_PATCH_PROGRESS
,
64 BTMTK_WMT_ON_PROGRESS
,
67 struct btmtk_wmt_hdr
{
74 struct btmtk_hci_wmt_cmd
{
75 struct btmtk_wmt_hdr hdr
;
79 struct btmtk_hci_wmt_evt
{
80 struct hci_event_hdr hhdr
;
81 struct btmtk_wmt_hdr whdr
;
84 struct btmtk_hci_wmt_evt_funcc
{
85 struct btmtk_hci_wmt_evt hwhdr
;
89 struct btmtk_hci_wmt_evt_reg
{
90 struct btmtk_hci_wmt_evt hwhdr
;
97 struct btmtk_tci_sleep
{
100 __le16 host_duration
;
102 u8 time_compensation
;
105 struct btmtk_wakeon
{
115 u8 transmit_format_config
;
116 u8 channel_format_config
;
117 u8 channel_select_config
;
120 struct reg_read_cmd
{
127 struct reg_write_cmd
{
136 struct btmtk_hci_wmt_params
{
145 BTMTK_TX_WAIT_VND_EVT
,
146 BTMTK_FIRMWARE_LOADED
,
147 BTMTK_HW_RESET_ACTIVE
,
148 BTMTK_ISOPKT_OVER_INTR
,
149 BTMTK_ISOPKT_RUNNING
,
152 typedef int (*btmtk_reset_sync_func_t
)(struct hci_dev
*, void *);
154 struct btmtk_coredump_info
{
155 const char *driver_name
;
162 const char *drv_name
;
165 btmtk_reset_sync_func_t reset_sync
;
166 struct btmtk_coredump_info cd_info
;
168 struct usb_device
*udev
;
169 struct usb_interface
*intf
;
170 struct usb_anchor
*ctrl_anchor
;
171 struct sk_buff
*evt_skb
;
172 struct usb_endpoint_descriptor
*isopkt_tx_ep
;
173 struct usb_endpoint_descriptor
*isopkt_rx_ep
;
174 struct usb_interface
*isopkt_intf
;
175 struct usb_anchor isopkt_anchor
;
176 struct sk_buff
*isopkt_skb
;
178 /* spinlock for ISO data transmission */
179 spinlock_t isorxlock
;
182 typedef int (*wmt_cmd_sync_func_t
)(struct hci_dev
*,
183 struct btmtk_hci_wmt_params
*);
185 #if IS_ENABLED(CONFIG_BT_MTK)
187 int btmtk_set_bdaddr(struct hci_dev
*hdev
, const bdaddr_t
*bdaddr
);
189 int btmtk_setup_firmware_79xx(struct hci_dev
*hdev
, const char *fwname
,
190 wmt_cmd_sync_func_t wmt_cmd_sync
);
192 int btmtk_setup_firmware(struct hci_dev
*hdev
, const char *fwname
,
193 wmt_cmd_sync_func_t wmt_cmd_sync
);
195 void btmtk_reset_sync(struct hci_dev
*hdev
);
197 int btmtk_register_coredump(struct hci_dev
*hdev
, const char *name
,
200 int btmtk_process_coredump(struct hci_dev
*hdev
, struct sk_buff
*skb
);
202 void btmtk_fw_get_filename(char *buf
, size_t size
, u32 dev_id
, u32 fw_ver
,
205 int btmtk_usb_subsys_reset(struct hci_dev
*hdev
, u32 dev_id
);
207 int btmtk_usb_recv_acl(struct hci_dev
*hdev
, struct sk_buff
*skb
);
209 struct urb
*alloc_mtk_intr_urb(struct hci_dev
*hdev
, struct sk_buff
*skb
,
210 usb_complete_t tx_complete
);
212 int btmtk_usb_resume(struct hci_dev
*hdev
);
214 int btmtk_usb_suspend(struct hci_dev
*hdev
);
216 int btmtk_usb_setup(struct hci_dev
*hdev
);
218 int btmtk_usb_shutdown(struct hci_dev
*hdev
);
221 static inline int btmtk_set_bdaddr(struct hci_dev
*hdev
,
222 const bdaddr_t
*bdaddr
)
227 static inline int btmtk_setup_firmware_79xx(struct hci_dev
*hdev
,
229 wmt_cmd_sync_func_t wmt_cmd_sync
)
234 static inline int btmtk_setup_firmware(struct hci_dev
*hdev
, const char *fwname
,
235 wmt_cmd_sync_func_t wmt_cmd_sync
)
240 static inline void btmtk_reset_sync(struct hci_dev
*hdev
)
244 static inline int btmtk_register_coredump(struct hci_dev
*hdev
,
245 const char *name
, u32 fw_version
)
250 static inline int btmtk_process_coredump(struct hci_dev
*hdev
,
256 static inline void btmtk_fw_get_filename(char *buf
, size_t size
, u32 dev_id
,
257 u32 fw_ver
, u32 fw_flavor
)
261 static inline int btmtk_usb_subsys_reset(struct hci_dev
*hdev
, u32 dev_id
)
266 static inline int btmtk_usb_recv_acl(struct hci_dev
*hdev
, struct sk_buff
*skb
)
271 static inline struct urb
*alloc_mtk_intr_urb(struct hci_dev
*hdev
,
273 usb_complete_t tx_complete
)
275 return ERR_PTR(-EOPNOTSUPP
);
278 static inline int btmtk_usb_resume(struct hci_dev
*hdev
)
283 static inline int btmtk_usb_suspend(struct hci_dev
*hdev
)
288 static inline int btmtk_usb_setup(struct hci_dev
*hdev
)
293 static inline int btmtk_usb_shutdown(struct hci_dev
*hdev
)