xref: /linux/drivers/bluetooth/btmtk.h (revision 7a8c6fb21a7c913ddb99785b14914dab2f934fbd)
18c0d17b6SSean Wang /* SPDX-License-Identifier: ISC */
28c0d17b6SSean Wang /* Copyright (C) 2021 MediaTek Inc. */
38c0d17b6SSean Wang 
4f5c3f989SSean Wang #define FIRMWARE_MT7622		"mediatek/mt7622pr2h.bin"
58c0d17b6SSean Wang #define FIRMWARE_MT7663		"mediatek/mt7663pr2h.bin"
68c0d17b6SSean Wang #define FIRMWARE_MT7668		"mediatek/mt7668pr2h.bin"
73e465a07STakashi Iwai #define FIRMWARE_MT7922		"mediatek/BT_RAM_CODE_MT7922_1_1_hdr.bin"
88c0d17b6SSean Wang #define FIRMWARE_MT7961		"mediatek/BT_RAM_CODE_MT7961_1_2_hdr.bin"
94c92ae75SPeter Tsao #define FIRMWARE_MT7925		"mediatek/mt7925/BT_RAM_CODE_MT7925_1_1_hdr.bin"
108c0d17b6SSean Wang 
11e4412654SSean Wang #define HCI_EV_WMT 0xe4
128c0d17b6SSean Wang #define HCI_WMT_MAX_EVENT_SIZE		64
138c0d17b6SSean Wang 
14191c8723SMark Chen #define BTMTK_WMT_REG_WRITE 0x1
15c603bf1fSSean Wang #define BTMTK_WMT_REG_READ 0x2
16c603bf1fSSean Wang 
178fafe702SChih-Ying Chiang #define MT7921_BTSYS_RST 0x70002610
188fafe702SChih-Ying Chiang #define MT7921_BTSYS_RST_WITH_GPIO BIT(7)
198fafe702SChih-Ying Chiang 
20191c8723SMark Chen #define MT7921_PINMUX_0 0x70005050
21191c8723SMark Chen #define MT7921_PINMUX_1 0x70005054
22191c8723SMark Chen 
238fafe702SChih-Ying Chiang #define MT7921_DLSTATUS 0x7c053c10
248fafe702SChih-Ying Chiang #define BT_DL_STATE BIT(1)
258fafe702SChih-Ying Chiang 
260b701513SJing Cai #define MTK_COREDUMP_SIZE		(1024 * 1000)
270b701513SJing Cai #define MTK_COREDUMP_END		"coredump end"
280e72e3b1SChris Lu #define MTK_COREDUMP_END_LEN		(sizeof(MTK_COREDUMP_END))
290b701513SJing Cai #define MTK_COREDUMP_NUM		255
300b701513SJing Cai 
31d019930bSChris Lu /* UHW CR mapping */
32d019930bSChris Lu #define MTK_BT_MISC		0x70002510
33d019930bSChris Lu #define MTK_BT_SUBSYS_RST	0x70002610
34d019930bSChris Lu #define MTK_UDMA_INT_STA_BT	0x74000024
35d019930bSChris Lu #define MTK_UDMA_INT_STA_BT1	0x74000308
36d019930bSChris Lu #define MTK_BT_WDT_STATUS	0x740003A0
37d019930bSChris Lu #define MTK_EP_RST_OPT		0x74011890
38d019930bSChris Lu #define MTK_EP_RST_IN_OUT_OPT	0x00010001
39d019930bSChris Lu #define MTK_BT_RST_DONE		0x00000100
40d019930bSChris Lu #define MTK_BT_RESET_REG_CONNV3	0x70028610
41d019930bSChris Lu #define MTK_BT_READ_DEV_ID	0x70010200
42d019930bSChris Lu 
43ceac1cb0SChris Lu /* MediaTek ISO Interface */
44ceac1cb0SChris Lu #define MTK_ISO_IFNUM		2
45ceac1cb0SChris Lu 
468c0d17b6SSean Wang enum {
478c0d17b6SSean Wang 	BTMTK_WMT_PATCH_DWNLD = 0x1,
483a722044SSean Wang 	BTMTK_WMT_TEST = 0x2,
493a722044SSean Wang 	BTMTK_WMT_WAKEUP = 0x3,
503a722044SSean Wang 	BTMTK_WMT_HIF = 0x4,
518c0d17b6SSean Wang 	BTMTK_WMT_FUNC_CTRL = 0x6,
528c0d17b6SSean Wang 	BTMTK_WMT_RST = 0x7,
53c603bf1fSSean Wang 	BTMTK_WMT_REGISTER = 0x8,
548c0d17b6SSean Wang 	BTMTK_WMT_SEMAPHORE = 0x17,
558c0d17b6SSean Wang };
568c0d17b6SSean Wang 
578c0d17b6SSean Wang enum {
588c0d17b6SSean Wang 	BTMTK_WMT_INVALID,
598c0d17b6SSean Wang 	BTMTK_WMT_PATCH_UNDONE,
608c0d17b6SSean Wang 	BTMTK_WMT_PATCH_PROGRESS,
618c0d17b6SSean Wang 	BTMTK_WMT_PATCH_DONE,
628c0d17b6SSean Wang 	BTMTK_WMT_ON_UNDONE,
638c0d17b6SSean Wang 	BTMTK_WMT_ON_DONE,
648c0d17b6SSean Wang 	BTMTK_WMT_ON_PROGRESS,
658c0d17b6SSean Wang };
668c0d17b6SSean Wang 
678c0d17b6SSean Wang struct btmtk_wmt_hdr {
688c0d17b6SSean Wang 	u8	dir;
698c0d17b6SSean Wang 	u8	op;
708c0d17b6SSean Wang 	__le16	dlen;
718c0d17b6SSean Wang 	u8	flag;
728c0d17b6SSean Wang } __packed;
738c0d17b6SSean Wang 
748c0d17b6SSean Wang struct btmtk_hci_wmt_cmd {
758c0d17b6SSean Wang 	struct btmtk_wmt_hdr hdr;
768c0d17b6SSean Wang 	u8 data[];
778c0d17b6SSean Wang } __packed;
788c0d17b6SSean Wang 
798c0d17b6SSean Wang struct btmtk_hci_wmt_evt {
808c0d17b6SSean Wang 	struct hci_event_hdr hhdr;
818c0d17b6SSean Wang 	struct btmtk_wmt_hdr whdr;
828c0d17b6SSean Wang } __packed;
838c0d17b6SSean Wang 
848c0d17b6SSean Wang struct btmtk_hci_wmt_evt_funcc {
858c0d17b6SSean Wang 	struct btmtk_hci_wmt_evt hwhdr;
868c0d17b6SSean Wang 	__be16 status;
878c0d17b6SSean Wang } __packed;
888c0d17b6SSean Wang 
89c603bf1fSSean Wang struct btmtk_hci_wmt_evt_reg {
90c603bf1fSSean Wang 	struct btmtk_hci_wmt_evt hwhdr;
91c603bf1fSSean Wang 	u8 rsv[2];
92c603bf1fSSean Wang 	u8 num;
93c603bf1fSSean Wang 	__le32 addr;
94c603bf1fSSean Wang 	__le32 val;
95c603bf1fSSean Wang } __packed;
96c603bf1fSSean Wang 
978c0d17b6SSean Wang struct btmtk_tci_sleep {
988c0d17b6SSean Wang 	u8 mode;
998c0d17b6SSean Wang 	__le16 duration;
1008c0d17b6SSean Wang 	__le16 host_duration;
1018c0d17b6SSean Wang 	u8 host_wakeup_pin;
1028c0d17b6SSean Wang 	u8 time_compensation;
1038c0d17b6SSean Wang } __packed;
1048c0d17b6SSean Wang 
105ce64b3e9SMark Chen struct btmtk_wakeon {
106ce64b3e9SMark Chen 	u8 mode;
107ce64b3e9SMark Chen 	u8 gpo;
108ce64b3e9SMark Chen 	u8 active_high;
109ce64b3e9SMark Chen 	__le16 enable_delay;
110ce64b3e9SMark Chen 	__le16 wakeup_delay;
111ce64b3e9SMark Chen } __packed;
112ce64b3e9SMark Chen 
113191c8723SMark Chen struct btmtk_sco {
114191c8723SMark Chen 	u8 clock_config;
115191c8723SMark Chen 	u8 transmit_format_config;
116191c8723SMark Chen 	u8 channel_format_config;
117191c8723SMark Chen 	u8 channel_select_config;
118191c8723SMark Chen } __packed;
119191c8723SMark Chen 
1205677bcf6SSean Wang struct reg_read_cmd {
1215677bcf6SSean Wang 	u8 type;
1225677bcf6SSean Wang 	u8 rsv;
1235677bcf6SSean Wang 	u8 num;
1245677bcf6SSean Wang 	__le32 addr;
1255677bcf6SSean Wang } __packed;
1265677bcf6SSean Wang 
127191c8723SMark Chen struct reg_write_cmd {
128191c8723SMark Chen 	u8 type;
129191c8723SMark Chen 	u8 rsv;
130191c8723SMark Chen 	u8 num;
131191c8723SMark Chen 	__le32 addr;
132191c8723SMark Chen 	__le32 data;
133191c8723SMark Chen 	__le32 mask;
134191c8723SMark Chen } __packed;
135191c8723SMark Chen 
1368c0d17b6SSean Wang struct btmtk_hci_wmt_params {
1378c0d17b6SSean Wang 	u8 op;
1388c0d17b6SSean Wang 	u8 flag;
1398c0d17b6SSean Wang 	u16 dlen;
1408c0d17b6SSean Wang 	const void *data;
1418c0d17b6SSean Wang 	u32 *status;
1428c0d17b6SSean Wang };
1438c0d17b6SSean Wang 
144d019930bSChris Lu enum {
145d019930bSChris Lu 	BTMTK_TX_WAIT_VND_EVT,
1465c5e8c52SChris Lu 	BTMTK_FIRMWARE_LOADED,
1475c5e8c52SChris Lu 	BTMTK_HW_RESET_ACTIVE,
148ceac1cb0SChris Lu 	BTMTK_ISOPKT_OVER_INTR,
149ceac1cb0SChris Lu 	BTMTK_ISOPKT_RUNNING,
150d019930bSChris Lu };
151d019930bSChris Lu 
15225b6d759SJing Cai typedef int (*btmtk_reset_sync_func_t)(struct hci_dev *, void *);
15325b6d759SJing Cai 
1540b701513SJing Cai struct btmtk_coredump_info {
1550b701513SJing Cai 	const char *driver_name;
1560b701513SJing Cai 	u32 fw_version;
1570b701513SJing Cai 	u16 cnt;
1580b701513SJing Cai 	int state;
1590b701513SJing Cai };
1600b701513SJing Cai 
161d3e62360SChris Lu struct btmtk_data {
1625c5e8c52SChris Lu 	const char *drv_name;
163d019930bSChris Lu 	unsigned long flags;
1644c92ae75SPeter Tsao 	u32 dev_id;
16525b6d759SJing Cai 	btmtk_reset_sync_func_t reset_sync;
1660b701513SJing Cai 	struct btmtk_coredump_info cd_info;
167d019930bSChris Lu 
168d019930bSChris Lu 	struct usb_device *udev;
169d019930bSChris Lu 	struct usb_interface *intf;
170d019930bSChris Lu 	struct usb_anchor *ctrl_anchor;
171d019930bSChris Lu 	struct sk_buff *evt_skb;
172ceac1cb0SChris Lu 	struct usb_endpoint_descriptor *isopkt_tx_ep;
173ceac1cb0SChris Lu 	struct usb_endpoint_descriptor *isopkt_rx_ep;
174ceac1cb0SChris Lu 	struct usb_interface *isopkt_intf;
175ceac1cb0SChris Lu 	struct usb_anchor isopkt_anchor;
176ceac1cb0SChris Lu 	struct sk_buff *isopkt_skb;
177ceac1cb0SChris Lu 
178ceac1cb0SChris Lu 	/* spinlock for ISO data transmission */
179ceac1cb0SChris Lu 	spinlock_t isorxlock;
1804c92ae75SPeter Tsao };
1814c92ae75SPeter Tsao 
1828c0d17b6SSean Wang typedef int (*wmt_cmd_sync_func_t)(struct hci_dev *,
1838c0d17b6SSean Wang 				   struct btmtk_hci_wmt_params *);
1848c0d17b6SSean Wang 
1858c0d17b6SSean Wang #if IS_ENABLED(CONFIG_BT_MTK)
1868c0d17b6SSean Wang 
1878c0d17b6SSean Wang int btmtk_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr);
1888c0d17b6SSean Wang 
1898c0d17b6SSean Wang int btmtk_setup_firmware_79xx(struct hci_dev *hdev, const char *fwname,
1908c0d17b6SSean Wang 			      wmt_cmd_sync_func_t wmt_cmd_sync);
1918c0d17b6SSean Wang 
1928c0d17b6SSean Wang int btmtk_setup_firmware(struct hci_dev *hdev, const char *fwname,
1938c0d17b6SSean Wang 			 wmt_cmd_sync_func_t wmt_cmd_sync);
19425b6d759SJing Cai 
19525b6d759SJing Cai void btmtk_reset_sync(struct hci_dev *hdev);
1960b701513SJing Cai 
1970b701513SJing Cai int btmtk_register_coredump(struct hci_dev *hdev, const char *name,
1980b701513SJing Cai 			    u32 fw_version);
1990b701513SJing Cai 
2000b701513SJing Cai int btmtk_process_coredump(struct hci_dev *hdev, struct sk_buff *skb);
20100f993fdSSean Wang 
20200f993fdSSean Wang void btmtk_fw_get_filename(char *buf, size_t size, u32 dev_id, u32 fw_ver,
20300f993fdSSean Wang 			   u32 fw_flavor);
204d019930bSChris Lu 
2055c5e8c52SChris Lu int btmtk_usb_subsys_reset(struct hci_dev *hdev, u32 dev_id);
2065c5e8c52SChris Lu 
2076dc22ab9SChris Lu int btmtk_usb_recv_acl(struct hci_dev *hdev, struct sk_buff *skb);
2086dc22ab9SChris Lu 
209ceac1cb0SChris Lu struct urb *alloc_mtk_intr_urb(struct hci_dev *hdev, struct sk_buff *skb,
210ceac1cb0SChris Lu 			       usb_complete_t tx_complete);
211ceac1cb0SChris Lu 
212ceac1cb0SChris Lu int btmtk_usb_resume(struct hci_dev *hdev);
213ceac1cb0SChris Lu 
214ceac1cb0SChris Lu int btmtk_usb_suspend(struct hci_dev *hdev);
215ceac1cb0SChris Lu 
2165c5e8c52SChris Lu int btmtk_usb_setup(struct hci_dev *hdev);
2175c5e8c52SChris Lu 
2185c5e8c52SChris Lu int btmtk_usb_shutdown(struct hci_dev *hdev);
2198c0d17b6SSean Wang #else
2208c0d17b6SSean Wang 
btmtk_set_bdaddr(struct hci_dev * hdev,const bdaddr_t * bdaddr)2218c0d17b6SSean Wang static inline int btmtk_set_bdaddr(struct hci_dev *hdev,
2228c0d17b6SSean Wang 				   const bdaddr_t *bdaddr)
2238c0d17b6SSean Wang {
2248c0d17b6SSean Wang 	return -EOPNOTSUPP;
2258c0d17b6SSean Wang }
2268c0d17b6SSean Wang 
btmtk_setup_firmware_79xx(struct hci_dev * hdev,const char * fwname,wmt_cmd_sync_func_t wmt_cmd_sync)227*23e88450SNathan Chancellor static inline int btmtk_setup_firmware_79xx(struct hci_dev *hdev,
228*23e88450SNathan Chancellor 					    const char *fwname,
2298c0d17b6SSean Wang 					    wmt_cmd_sync_func_t wmt_cmd_sync)
2308c0d17b6SSean Wang {
2318c0d17b6SSean Wang 	return -EOPNOTSUPP;
2328c0d17b6SSean Wang }
2338c0d17b6SSean Wang 
btmtk_setup_firmware(struct hci_dev * hdev,const char * fwname,wmt_cmd_sync_func_t wmt_cmd_sync)234*23e88450SNathan Chancellor static inline int btmtk_setup_firmware(struct hci_dev *hdev, const char *fwname,
2358c0d17b6SSean Wang 				       wmt_cmd_sync_func_t wmt_cmd_sync)
2368c0d17b6SSean Wang {
2378c0d17b6SSean Wang 	return -EOPNOTSUPP;
2388c0d17b6SSean Wang }
2398c0d17b6SSean Wang 
btmtk_reset_sync(struct hci_dev * hdev)240*23e88450SNathan Chancellor static inline void btmtk_reset_sync(struct hci_dev *hdev)
24125b6d759SJing Cai {
24225b6d759SJing Cai }
2430b701513SJing Cai 
btmtk_register_coredump(struct hci_dev * hdev,const char * name,u32 fw_version)244*23e88450SNathan Chancellor static inline int btmtk_register_coredump(struct hci_dev *hdev,
245*23e88450SNathan Chancellor 					  const char *name, u32 fw_version)
2460b701513SJing Cai {
2470b701513SJing Cai 	return -EOPNOTSUPP;
2480b701513SJing Cai }
2490b701513SJing Cai 
btmtk_process_coredump(struct hci_dev * hdev,struct sk_buff * skb)250*23e88450SNathan Chancellor static inline int btmtk_process_coredump(struct hci_dev *hdev,
251*23e88450SNathan Chancellor 					 struct sk_buff *skb)
2520b701513SJing Cai {
2530b701513SJing Cai 	return -EOPNOTSUPP;
2540b701513SJing Cai }
25500f993fdSSean Wang 
btmtk_fw_get_filename(char * buf,size_t size,u32 dev_id,u32 fw_ver,u32 fw_flavor)256*23e88450SNathan Chancellor static inline void btmtk_fw_get_filename(char *buf, size_t size, u32 dev_id,
25700f993fdSSean Wang 					 u32 fw_ver, u32 fw_flavor)
25800f993fdSSean Wang {
25900f993fdSSean Wang }
260d019930bSChris Lu 
btmtk_usb_subsys_reset(struct hci_dev * hdev,u32 dev_id)261*23e88450SNathan Chancellor static inline int btmtk_usb_subsys_reset(struct hci_dev *hdev, u32 dev_id)
2625c5e8c52SChris Lu {
2635c5e8c52SChris Lu 	return -EOPNOTSUPP;
2645c5e8c52SChris Lu }
2655c5e8c52SChris Lu 
btmtk_usb_recv_acl(struct hci_dev * hdev,struct sk_buff * skb)266*23e88450SNathan Chancellor static inline int btmtk_usb_recv_acl(struct hci_dev *hdev, struct sk_buff *skb)
2676dc22ab9SChris Lu {
2686dc22ab9SChris Lu 	return -EOPNOTSUPP;
2696dc22ab9SChris Lu }
2706dc22ab9SChris Lu 
alloc_mtk_intr_urb(struct hci_dev * hdev,struct sk_buff * skb,usb_complete_t tx_complete)271*23e88450SNathan Chancellor static inline struct urb *alloc_mtk_intr_urb(struct hci_dev *hdev,
272*23e88450SNathan Chancellor 					     struct sk_buff *skb,
273ceac1cb0SChris Lu 					     usb_complete_t tx_complete)
274ceac1cb0SChris Lu {
275ceac1cb0SChris Lu 	return ERR_PTR(-EOPNOTSUPP);
276ceac1cb0SChris Lu }
277ceac1cb0SChris Lu 
btmtk_usb_resume(struct hci_dev * hdev)278*23e88450SNathan Chancellor static inline int btmtk_usb_resume(struct hci_dev *hdev)
279ceac1cb0SChris Lu {
280ceac1cb0SChris Lu 	return -EOPNOTSUPP;
281ceac1cb0SChris Lu }
282ceac1cb0SChris Lu 
btmtk_usb_suspend(struct hci_dev * hdev)283*23e88450SNathan Chancellor static inline int btmtk_usb_suspend(struct hci_dev *hdev)
284ceac1cb0SChris Lu {
285ceac1cb0SChris Lu 	return -EOPNOTSUPP;
286ceac1cb0SChris Lu }
287ceac1cb0SChris Lu 
btmtk_usb_setup(struct hci_dev * hdev)288*23e88450SNathan Chancellor static inline int btmtk_usb_setup(struct hci_dev *hdev)
2895c5e8c52SChris Lu {
2905c5e8c52SChris Lu 	return -EOPNOTSUPP;
2915c5e8c52SChris Lu }
2925c5e8c52SChris Lu 
btmtk_usb_shutdown(struct hci_dev * hdev)293*23e88450SNathan Chancellor static inline int btmtk_usb_shutdown(struct hci_dev *hdev)
294d019930bSChris Lu {
295d019930bSChris Lu 	return -EOPNOTSUPP;
296d019930bSChris Lu }
2978c0d17b6SSean Wang #endif
298