| 1 |
|
| 2 |
|
| 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_MT7922 "mediatek/BT_RAM_CODE_MT7922_1_1_hdr.bin"
|
| 8 | #define FIRMWARE_MT7902 "mediatek/BT_RAM_CODE_MT7902_1_1_hdr.bin"
|
| 9 | #define FIRMWARE_MT7961 "mediatek/BT_RAM_CODE_MT7961_1_2_hdr.bin"
|
| 10 | #define FIRMWARE_MT7920 "mediatek/BT_RAM_CODE_MT7961_1a_2_hdr.bin"
|
| 11 | #define FIRMWARE_MT7925 "mediatek/mt7925/BT_RAM_CODE_MT7925_1_1_hdr.bin"
|
| 12 | #define FIRMWARE_MT7927 "mediatek/mt7927/BT_RAM_CODE_MT6639_2_1_hdr.bin"
|
| 13 |
|
| 14 | #define HCI_EV_WMT 0xe4
|
| 15 | #define HCI_WMT_MAX_EVENT_SIZE 64
|
| 16 |
|
| 17 | #define BTMTK_WMT_REG_WRITE 0x1
|
| 18 | #define BTMTK_WMT_REG_READ 0x2
|
| 19 |
|
| 20 | #define MT7921_BTSYS_RST 0x70002610
|
| 21 | #define MT7921_BTSYS_RST_WITH_GPIO BIT(7)
|
| 22 |
|
| 23 | #define MT7921_PINMUX_0 0x70005050
|
| 24 | #define MT7921_PINMUX_1 0x70005054
|
| 25 |
|
| 26 | #define MT7921_DLSTATUS 0x7c053c10
|
| 27 | #define BT_DL_STATE BIT(1)
|
| 28 |
|
| 29 | #define MTK_COREDUMP_SIZE (1024 * 1000)
|
| 30 | #define MTK_COREDUMP_END "coredump end"
|
| 31 | #define MTK_COREDUMP_END_LEN (sizeof(MTK_COREDUMP_END))
|
| 32 | #define MTK_COREDUMP_NUM 255
|
| 33 |
|
| 34 |
|
| 35 | #define MTK_BT_MISC 0x70002510
|
| 36 | #define MTK_BT_SUBSYS_RST 0x70002610
|
| 37 | #define MTK_UDMA_INT_STA_BT 0x74000024
|
| 38 | #define MTK_UDMA_INT_STA_BT1 0x74000308
|
| 39 | #define MTK_BT_WDT_STATUS 0x740003A0
|
| 40 | #define MTK_EP_RST_OPT 0x74011890
|
| 41 | #define MTK_EP_RST_IN_OUT_OPT 0x00010001
|
| 42 | #define MTK_BT_RST_DONE 0x00000100
|
| 43 | #define MTK_BT_RESET_REG_CONNV3 0x70028610
|
| 44 | #define MTK_BT_READ_DEV_ID 0x70010200
|
| 45 |
|
| 46 |
|
| 47 | #define MTK_ISO_IFNUM 2
|
| 48 |
|
| 49 | enum {
|
| 50 | BTMTK_WMT_PATCH_DWNLD = 0x1,
|
| 51 | BTMTK_WMT_TEST = 0x2,
|
| 52 | BTMTK_WMT_WAKEUP = 0x3,
|
| 53 | BTMTK_WMT_HIF = 0x4,
|
| 54 | BTMTK_WMT_FUNC_CTRL = 0x6,
|
| 55 | BTMTK_WMT_RST = 0x7,
|
| 56 | BTMTK_WMT_REGISTER = 0x8,
|
| 57 | BTMTK_WMT_SEMAPHORE = 0x17,
|
| 58 | };
|
| 59 |
|
| 60 | enum {
|
| 61 | BTMTK_WMT_INVALID,
|
| 62 | BTMTK_WMT_PATCH_UNDONE,
|
| 63 | BTMTK_WMT_PATCH_PROGRESS,
|
| 64 | BTMTK_WMT_PATCH_DONE,
|
| 65 | BTMTK_WMT_ON_UNDONE,
|
| 66 | BTMTK_WMT_ON_DONE,
|
| 67 | BTMTK_WMT_ON_PROGRESS,
|
| 68 | };
|
| 69 |
|
| 70 | struct btmtk_wmt_hdr {
|
| 71 | u8 dir;
|
| 72 | u8 op;
|
| 73 | __le16 dlen;
|
| 74 | u8 flag;
|
| 75 | } __packed;
|
| 76 |
|
| 77 | struct btmtk_hci_wmt_cmd {
|
| 78 | struct btmtk_wmt_hdr hdr;
|
| 79 | u8 data[];
|
| 80 | } __packed;
|
| 81 |
|
| 82 | struct btmtk_hci_wmt_evt {
|
| 83 | struct hci_event_hdr hhdr;
|
| 84 | struct btmtk_wmt_hdr whdr;
|
| 85 | } __packed;
|
| 86 |
|
| 87 | struct btmtk_hci_wmt_evt_funcc {
|
| 88 | struct btmtk_hci_wmt_evt hwhdr;
|
| 89 | __be16 status;
|
| 90 | } __packed;
|
| 91 |
|
| 92 | struct btmtk_hci_wmt_evt_reg {
|
| 93 | struct btmtk_hci_wmt_evt hwhdr;
|
| 94 | u8 rsv[2];
|
| 95 | u8 num;
|
| 96 | __le32 addr;
|
| 97 | __le32 val;
|
| 98 | } __packed;
|
| 99 |
|
| 100 | struct btmtk_tci_sleep {
|
| 101 | u8 mode;
|
| 102 | __le16 duration;
|
| 103 | __le16 host_duration;
|
| 104 | u8 host_wakeup_pin;
|
| 105 | u8 time_compensation;
|
| 106 | } __packed;
|
| 107 |
|
| 108 | struct btmtk_wakeon {
|
| 109 | u8 mode;
|
| 110 | u8 gpo;
|
| 111 | u8 active_high;
|
| 112 | __le16 enable_delay;
|
| 113 | __le16 wakeup_delay;
|
| 114 | } __packed;
|
| 115 |
|
| 116 | struct btmtk_sco {
|
| 117 | u8 clock_config;
|
| 118 | u8 transmit_format_config;
|
| 119 | u8 channel_format_config;
|
| 120 | u8 channel_select_config;
|
| 121 | } __packed;
|
| 122 |
|
| 123 | struct reg_read_cmd {
|
| 124 | u8 type;
|
| 125 | u8 rsv;
|
| 126 | u8 num;
|
| 127 | __le32 addr;
|
| 128 | } __packed;
|
| 129 |
|
| 130 | struct reg_write_cmd {
|
| 131 | u8 type;
|
| 132 | u8 rsv;
|
| 133 | u8 num;
|
| 134 | __le32 addr;
|
| 135 | __le32 data;
|
| 136 | __le32 mask;
|
| 137 | } __packed;
|
| 138 |
|
| 139 | struct btmtk_hci_wmt_params {
|
| 140 | u8 op;
|
| 141 | u8 flag;
|
| 142 | u16 dlen;
|
| 143 | const void *data;
|
| 144 | u32 *status;
|
| 145 | };
|
| 146 |
|
| 147 | enum {
|
| 148 | BTMTK_TX_WAIT_VND_EVT,
|
| 149 | BTMTK_FIRMWARE_LOADED,
|
| 150 | BTMTK_HW_RESET_ACTIVE,
|
| 151 | BTMTK_ISOPKT_OVER_INTR,
|
| 152 | BTMTK_ISOPKT_RUNNING,
|
| 153 | BTMTK_FIRMWARE_DL_RETRY,
|
| 154 | };
|
| 155 |
|
| 156 | typedef int (*btmtk_reset_sync_func_t)(struct hci_dev *, void *);
|
| 157 |
|
| 158 | struct btmtk_coredump_info {
|
| 159 | const char *driver_name;
|
| 160 | u32 fw_version;
|
| 161 | u16 cnt;
|
| 162 | int state;
|
| 163 | };
|
| 164 |
|
| 165 | struct btmtk_data {
|
| 166 | const char *drv_name;
|
| 167 | unsigned long flags;
|
| 168 | u32 dev_id;
|
| 169 | btmtk_reset_sync_func_t reset_sync;
|
| 170 | struct btmtk_coredump_info cd_info;
|
| 171 |
|
| 172 | struct usb_device *udev;
|
| 173 | struct usb_interface *intf;
|
| 174 | struct usb_anchor *ctrl_anchor;
|
| 175 | struct sk_buff *evt_skb;
|
| 176 | struct usb_endpoint_descriptor *isopkt_tx_ep;
|
| 177 | struct usb_endpoint_descriptor *isopkt_rx_ep;
|
| 178 | struct usb_interface *isopkt_intf;
|
| 179 | struct usb_anchor isopkt_anchor;
|
| 180 | struct sk_buff *isopkt_skb;
|
| 181 |
|
| 182 |
|
| 183 | spinlock_t isorxlock;
|
| 184 | };
|
| 185 |
|
| 186 | typedef int (*wmt_cmd_sync_func_t)(struct hci_dev *,
|
| 187 | struct btmtk_hci_wmt_params *);
|
| 188 |
|
| 189 | #if IS_ENABLED(CONFIG_BT_MTK)
|
| 190 |
|
| 191 | int btmtk_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr);
|
| 192 |
|
| 193 | int btmtk_setup_firmware_79xx(struct hci_dev *hdev, const char *fwname,
|
| 194 | wmt_cmd_sync_func_t wmt_cmd_sync,
|
| 195 | u32 dev_id);
|
| 196 |
|
| 197 | int btmtk_setup_firmware(struct hci_dev *hdev, const char *fwname,
|
| 198 | wmt_cmd_sync_func_t wmt_cmd_sync);
|
| 199 |
|
| 200 | void btmtk_reset_sync(struct hci_dev *hdev);
|
| 201 |
|
| 202 | int btmtk_register_coredump(struct hci_dev *hdev, const char *name,
|
| 203 | u32 fw_version);
|
| 204 |
|
| 205 | int btmtk_process_coredump(struct hci_dev *hdev, struct sk_buff *skb);
|
| 206 |
|
| 207 | void btmtk_fw_get_filename(char *buf, size_t size, u32 dev_id, u32 fw_ver,
|
| 208 | u32 fw_flavor);
|
| 209 |
|
| 210 | int btmtk_usb_subsys_reset(struct hci_dev *hdev, u32 dev_id);
|
| 211 |
|
| 212 | int btmtk_usb_recv_acl(struct hci_dev *hdev, struct sk_buff *skb);
|
| 213 |
|
| 214 | struct urb *alloc_mtk_intr_urb(struct hci_dev *hdev, struct sk_buff *skb,
|
| 215 | usb_complete_t tx_complete);
|
| 216 |
|
| 217 | int btmtk_usb_resume(struct hci_dev *hdev);
|
| 218 |
|
| 219 | int btmtk_usb_suspend(struct hci_dev *hdev);
|
| 220 |
|
| 221 | int btmtk_usb_setup(struct hci_dev *hdev);
|
| 222 |
|
| 223 | int btmtk_usb_shutdown(struct hci_dev *hdev);
|
| 224 |
|
| 225 | int btmtk_recv_event(struct hci_dev *hdev, struct sk_buff *skb);
|
| 226 | #else
|
| 227 |
|
| 228 | static inline int btmtk_set_bdaddr(struct hci_dev *hdev,
|
| 229 | const bdaddr_t *bdaddr)
|
| 230 | {
|
| 231 | return -EOPNOTSUPP;
|
| 232 | }
|
| 233 |
|
| 234 | static inline int btmtk_setup_firmware_79xx(struct hci_dev *hdev,
|
| 235 | const char *fwname,
|
| 236 | wmt_cmd_sync_func_t wmt_cmd_sync,
|
| 237 | u32 dev_id)
|
| 238 | {
|
| 239 | return -EOPNOTSUPP;
|
| 240 | }
|
| 241 |
|
| 242 | static inline int btmtk_setup_firmware(struct hci_dev *hdev, const char *fwname,
|
| 243 | wmt_cmd_sync_func_t wmt_cmd_sync)
|
| 244 | {
|
| 245 | return -EOPNOTSUPP;
|
| 246 | }
|
| 247 |
|
| 248 | static inline void btmtk_reset_sync(struct hci_dev *hdev)
|
| 249 | {
|
| 250 | }
|
| 251 |
|
| 252 | static inline int btmtk_register_coredump(struct hci_dev *hdev,
|
| 253 | const char *name, u32 fw_version)
|
| 254 | {
|
| 255 | return -EOPNOTSUPP;
|
| 256 | }
|
| 257 |
|
| 258 | static inline int btmtk_process_coredump(struct hci_dev *hdev,
|
| 259 | struct sk_buff *skb)
|
| 260 | {
|
| 261 | return -EOPNOTSUPP;
|
| 262 | }
|
| 263 |
|
| 264 | static inline void btmtk_fw_get_filename(char *buf, size_t size, u32 dev_id,
|
| 265 | u32 fw_ver, u32 fw_flavor)
|
| 266 | {
|
| 267 | }
|
| 268 |
|
| 269 | static inline int btmtk_usb_subsys_reset(struct hci_dev *hdev, u32 dev_id)
|
| 270 | {
|
| 271 | return -EOPNOTSUPP;
|
| 272 | }
|
| 273 |
|
| 274 | static inline int btmtk_usb_recv_acl(struct hci_dev *hdev, struct sk_buff *skb)
|
| 275 | {
|
| 276 | return -EOPNOTSUPP;
|
| 277 | }
|
| 278 |
|
| 279 | static inline struct urb *alloc_mtk_intr_urb(struct hci_dev *hdev,
|
| 280 | struct sk_buff *skb,
|
| 281 | usb_complete_t tx_complete)
|
| 282 | {
|
| 283 | return ERR_PTR(-EOPNOTSUPP);
|
| 284 | }
|
| 285 |
|
| 286 | static inline int btmtk_usb_resume(struct hci_dev *hdev)
|
| 287 | {
|
| 288 | return -EOPNOTSUPP;
|
| 289 | }
|
| 290 |
|
| 291 | static inline int btmtk_usb_suspend(struct hci_dev *hdev)
|
| 292 | {
|
| 293 | return -EOPNOTSUPP;
|
| 294 | }
|
| 295 |
|
| 296 | static inline int btmtk_usb_setup(struct hci_dev *hdev)
|
| 297 | {
|
| 298 | return -EOPNOTSUPP;
|
| 299 | }
|
| 300 |
|
| 301 | static inline int btmtk_usb_shutdown(struct hci_dev *hdev)
|
| 302 | {
|
| 303 | return -EOPNOTSUPP;
|
| 304 | }
|
| 305 |
|
| 306 | static inline int btmtk_recv_event(struct hci_dev *hdev, struct sk_buff *skb)
|
| 307 | {
|
| 308 | return hci_recv_frame(hdev, skb);
|
| 309 | }
|
| 310 | #endif
|