xref: /openbmc/linux/drivers/bluetooth/btmtk.h (revision ce64b3e9)
1 /* SPDX-License-Identifier: ISC */
2 /* Copyright (C) 2021 MediaTek Inc. */
3 
4 #define FIRMWARE_MT7663		"mediatek/mt7663pr2h.bin"
5 #define FIRMWARE_MT7668		"mediatek/mt7668pr2h.bin"
6 #define FIRMWARE_MT7961		"mediatek/BT_RAM_CODE_MT7961_1_2_hdr.bin"
7 
8 #define HCI_WMT_MAX_EVENT_SIZE		64
9 
10 #define BTMTK_WMT_REG_READ 0x2
11 
12 enum {
13 	BTMTK_WMT_PATCH_DWNLD = 0x1,
14 	BTMTK_WMT_TEST = 0x2,
15 	BTMTK_WMT_WAKEUP = 0x3,
16 	BTMTK_WMT_HIF = 0x4,
17 	BTMTK_WMT_FUNC_CTRL = 0x6,
18 	BTMTK_WMT_RST = 0x7,
19 	BTMTK_WMT_REGISTER = 0x8,
20 	BTMTK_WMT_SEMAPHORE = 0x17,
21 };
22 
23 enum {
24 	BTMTK_WMT_INVALID,
25 	BTMTK_WMT_PATCH_UNDONE,
26 	BTMTK_WMT_PATCH_PROGRESS,
27 	BTMTK_WMT_PATCH_DONE,
28 	BTMTK_WMT_ON_UNDONE,
29 	BTMTK_WMT_ON_DONE,
30 	BTMTK_WMT_ON_PROGRESS,
31 };
32 
33 struct btmtk_wmt_hdr {
34 	u8	dir;
35 	u8	op;
36 	__le16	dlen;
37 	u8	flag;
38 } __packed;
39 
40 struct btmtk_hci_wmt_cmd {
41 	struct btmtk_wmt_hdr hdr;
42 	u8 data[];
43 } __packed;
44 
45 struct btmtk_hci_wmt_evt {
46 	struct hci_event_hdr hhdr;
47 	struct btmtk_wmt_hdr whdr;
48 } __packed;
49 
50 struct btmtk_hci_wmt_evt_funcc {
51 	struct btmtk_hci_wmt_evt hwhdr;
52 	__be16 status;
53 } __packed;
54 
55 struct btmtk_hci_wmt_evt_reg {
56 	struct btmtk_hci_wmt_evt hwhdr;
57 	u8 rsv[2];
58 	u8 num;
59 	__le32 addr;
60 	__le32 val;
61 } __packed;
62 
63 struct btmtk_tci_sleep {
64 	u8 mode;
65 	__le16 duration;
66 	__le16 host_duration;
67 	u8 host_wakeup_pin;
68 	u8 time_compensation;
69 } __packed;
70 
71 struct btmtk_wakeon {
72 	u8 mode;
73 	u8 gpo;
74 	u8 active_high;
75 	__le16 enable_delay;
76 	__le16 wakeup_delay;
77 } __packed;
78 
79 struct btmtk_hci_wmt_params {
80 	u8 op;
81 	u8 flag;
82 	u16 dlen;
83 	const void *data;
84 	u32 *status;
85 };
86 
87 typedef int (*wmt_cmd_sync_func_t)(struct hci_dev *,
88 				   struct btmtk_hci_wmt_params *);
89 
90 #if IS_ENABLED(CONFIG_BT_MTK)
91 
92 int btmtk_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr);
93 
94 int btmtk_setup_firmware_79xx(struct hci_dev *hdev, const char *fwname,
95 			      wmt_cmd_sync_func_t wmt_cmd_sync);
96 
97 int btmtk_setup_firmware(struct hci_dev *hdev, const char *fwname,
98 			 wmt_cmd_sync_func_t wmt_cmd_sync);
99 #else
100 
101 static inline int btmtk_set_bdaddr(struct hci_dev *hdev,
102 				   const bdaddr_t *bdaddr)
103 {
104 	return -EOPNOTSUPP;
105 }
106 
107 static int btmtk_setup_firmware_79xx(struct hci_dev *hdev, const char *fwname,
108 				     wmt_cmd_sync_func_t wmt_cmd_sync)
109 {
110 	return -EOPNOTSUPP;
111 }
112 
113 static int btmtk_setup_firmware(struct hci_dev *hdev, const char *fwname,
114 				wmt_cmd_sync_func_t wmt_cmd_sync)
115 {
116 	return -EOPNOTSUPP;
117 }
118 
119 #endif
120