1 /* SPDX-License-Identifier: ISC */ 2 /* Copyright (C) 2021 MediaTek Inc. */ 3 4 #define FIRMWARE_MT7622 "mediatek/mt7622pr2h.bin" 5 #define FIRMWARE_MT7663 "mediatek/mt7663pr2h.bin" 6 #define FIRMWARE_MT7668 "mediatek/mt7668pr2h.bin" 7 #define FIRMWARE_MT7961 "mediatek/BT_RAM_CODE_MT7961_1_2_hdr.bin" 8 #define FIRMWARE_MT7925 "mediatek/mt7925/BT_RAM_CODE_MT7925_1_1_hdr.bin" 9 10 #define HCI_EV_WMT 0xe4 11 #define HCI_WMT_MAX_EVENT_SIZE 64 12 13 #define BTMTK_WMT_REG_WRITE 0x1 14 #define BTMTK_WMT_REG_READ 0x2 15 16 #define MT7921_BTSYS_RST 0x70002610 17 #define MT7921_BTSYS_RST_WITH_GPIO BIT(7) 18 19 #define MT7921_PINMUX_0 0x70005050 20 #define MT7921_PINMUX_1 0x70005054 21 22 #define MT7921_DLSTATUS 0x7c053c10 23 #define BT_DL_STATE BIT(1) 24 25 #define MTK_COREDUMP_SIZE (1024 * 1000) 26 #define MTK_COREDUMP_END "coredump end" 27 #define MTK_COREDUMP_END_LEN (sizeof(MTK_COREDUMP_END)) 28 #define MTK_COREDUMP_NUM 255 29 30 enum { 31 BTMTK_WMT_PATCH_DWNLD = 0x1, 32 BTMTK_WMT_TEST = 0x2, 33 BTMTK_WMT_WAKEUP = 0x3, 34 BTMTK_WMT_HIF = 0x4, 35 BTMTK_WMT_FUNC_CTRL = 0x6, 36 BTMTK_WMT_RST = 0x7, 37 BTMTK_WMT_REGISTER = 0x8, 38 BTMTK_WMT_SEMAPHORE = 0x17, 39 }; 40 41 enum { 42 BTMTK_WMT_INVALID, 43 BTMTK_WMT_PATCH_UNDONE, 44 BTMTK_WMT_PATCH_PROGRESS, 45 BTMTK_WMT_PATCH_DONE, 46 BTMTK_WMT_ON_UNDONE, 47 BTMTK_WMT_ON_DONE, 48 BTMTK_WMT_ON_PROGRESS, 49 }; 50 51 struct btmtk_wmt_hdr { 52 u8 dir; 53 u8 op; 54 __le16 dlen; 55 u8 flag; 56 } __packed; 57 58 struct btmtk_hci_wmt_cmd { 59 struct btmtk_wmt_hdr hdr; 60 u8 data[]; 61 } __packed; 62 63 struct btmtk_hci_wmt_evt { 64 struct hci_event_hdr hhdr; 65 struct btmtk_wmt_hdr whdr; 66 } __packed; 67 68 struct btmtk_hci_wmt_evt_funcc { 69 struct btmtk_hci_wmt_evt hwhdr; 70 __be16 status; 71 } __packed; 72 73 struct btmtk_hci_wmt_evt_reg { 74 struct btmtk_hci_wmt_evt hwhdr; 75 u8 rsv[2]; 76 u8 num; 77 __le32 addr; 78 __le32 val; 79 } __packed; 80 81 struct btmtk_tci_sleep { 82 u8 mode; 83 __le16 duration; 84 __le16 host_duration; 85 u8 host_wakeup_pin; 86 u8 time_compensation; 87 } __packed; 88 89 struct btmtk_wakeon { 90 u8 mode; 91 u8 gpo; 92 u8 active_high; 93 __le16 enable_delay; 94 __le16 wakeup_delay; 95 } __packed; 96 97 struct btmtk_sco { 98 u8 clock_config; 99 u8 transmit_format_config; 100 u8 channel_format_config; 101 u8 channel_select_config; 102 } __packed; 103 104 struct reg_read_cmd { 105 u8 type; 106 u8 rsv; 107 u8 num; 108 __le32 addr; 109 } __packed; 110 111 struct reg_write_cmd { 112 u8 type; 113 u8 rsv; 114 u8 num; 115 __le32 addr; 116 __le32 data; 117 __le32 mask; 118 } __packed; 119 120 struct btmtk_hci_wmt_params { 121 u8 op; 122 u8 flag; 123 u16 dlen; 124 const void *data; 125 u32 *status; 126 }; 127 128 typedef int (*btmtk_reset_sync_func_t)(struct hci_dev *, void *); 129 130 struct btmtk_coredump_info { 131 const char *driver_name; 132 u32 fw_version; 133 u16 cnt; 134 int state; 135 }; 136 137 struct btmediatek_data { 138 u32 dev_id; 139 btmtk_reset_sync_func_t reset_sync; 140 struct btmtk_coredump_info cd_info; 141 }; 142 143 typedef int (*wmt_cmd_sync_func_t)(struct hci_dev *, 144 struct btmtk_hci_wmt_params *); 145 146 #if IS_ENABLED(CONFIG_BT_MTK) 147 148 int btmtk_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr); 149 150 int btmtk_setup_firmware_79xx(struct hci_dev *hdev, const char *fwname, 151 wmt_cmd_sync_func_t wmt_cmd_sync); 152 153 int btmtk_setup_firmware(struct hci_dev *hdev, const char *fwname, 154 wmt_cmd_sync_func_t wmt_cmd_sync); 155 156 void btmtk_reset_sync(struct hci_dev *hdev); 157 158 int btmtk_register_coredump(struct hci_dev *hdev, const char *name, 159 u32 fw_version); 160 161 int btmtk_process_coredump(struct hci_dev *hdev, struct sk_buff *skb); 162 #else 163 164 static inline int btmtk_set_bdaddr(struct hci_dev *hdev, 165 const bdaddr_t *bdaddr) 166 { 167 return -EOPNOTSUPP; 168 } 169 170 static int btmtk_setup_firmware_79xx(struct hci_dev *hdev, const char *fwname, 171 wmt_cmd_sync_func_t wmt_cmd_sync) 172 { 173 return -EOPNOTSUPP; 174 } 175 176 static int btmtk_setup_firmware(struct hci_dev *hdev, const char *fwname, 177 wmt_cmd_sync_func_t wmt_cmd_sync) 178 { 179 return -EOPNOTSUPP; 180 } 181 182 static void btmtk_reset_sync(struct hci_dev *hdev) 183 { 184 } 185 186 static int btmtk_register_coredump(struct hci_dev *hdev, const char *name, 187 u32 fw_version) 188 { 189 return -EOPNOTSUPP; 190 } 191 192 static int btmtk_process_coredump(struct hci_dev *hdev, struct sk_buff *skb) 193 { 194 return -EOPNOTSUPP; 195 } 196 #endif 197