1 // SPDX-License-Identifier: ISC
3 * Copyright (C) 2018 Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>
5 #include <linux/kernel.h>
6 #include <linux/firmware.h>
11 #define MT_MCU_IVB_ADDR (MT_MCU_ILM_ADDR + 0x54000 - MT_MCU_IVB_SIZE)
13 static int mt76x0e_load_firmware(struct mt76x02_dev
*dev
)
15 bool is_combo_chip
= mt76_chip(&dev
->mt76
) != 0x7610;
16 u32 val
, ilm_len
, dlm_len
, offset
= 0;
17 const struct mt76x02_fw_header
*hdr
;
18 const struct firmware
*fw
;
24 firmware
= MT7650E_FIRMWARE
;
26 firmware
= MT7610E_FIRMWARE
;
28 err
= request_firmware(&fw
, firmware
, dev
->mt76
.dev
);
32 if (!fw
|| !fw
->data
|| fw
->size
< sizeof(*hdr
)) {
37 hdr
= (const struct mt76x02_fw_header
*)fw
->data
;
40 len
+= le32_to_cpu(hdr
->ilm_len
);
41 len
+= le32_to_cpu(hdr
->dlm_len
);
43 if (fw
->size
!= len
) {
48 fw_payload
= fw
->data
+ sizeof(*hdr
);
50 val
= le16_to_cpu(hdr
->fw_ver
);
51 dev_info(dev
->mt76
.dev
, "Firmware Version: %d.%d.%02d\n",
52 (val
>> 12) & 0xf, (val
>> 8) & 0xf, val
& 0xf);
54 val
= le16_to_cpu(hdr
->fw_ver
);
55 dev_dbg(dev
->mt76
.dev
,
56 "Firmware Version: %d.%d.%02d Build: %x Build time: %.16s\n",
57 (val
>> 12) & 0xf, (val
>> 8) & 0xf, val
& 0xf,
58 le16_to_cpu(hdr
->build_ver
), hdr
->build_time
);
60 if (is_combo_chip
&& !mt76_poll(dev
, MT_MCU_SEMAPHORE_00
, 1, 1, 600)) {
61 dev_err(dev
->mt76
.dev
,
62 "Could not get hardware semaphore for loading fw\n");
68 mt76_wr(dev
, MT_MCU_PCIE_REMAP_BASE4
, 0);
69 ilm_len
= le32_to_cpu(hdr
->ilm_len
);
71 ilm_len
-= MT_MCU_IVB_SIZE
;
72 offset
= MT_MCU_IVB_SIZE
;
74 dev_dbg(dev
->mt76
.dev
, "loading FW - ILM %u\n", ilm_len
);
75 mt76_wr_copy(dev
, MT_MCU_ILM_ADDR
+ offset
, fw_payload
+ offset
,
80 dev_dbg(dev
->mt76
.dev
, "loading FW - IVB %u\n",
82 mt76_wr_copy(dev
, MT_MCU_IVB_ADDR
, fw_payload
, MT_MCU_IVB_SIZE
);
86 mt76_wr(dev
, MT_MCU_PCIE_REMAP_BASE4
, MT_MCU_DLM_OFFSET
);
87 dlm_len
= le32_to_cpu(hdr
->dlm_len
);
88 dev_dbg(dev
->mt76
.dev
, "loading FW - DLM %u\n", dlm_len
);
89 mt76_wr_copy(dev
, MT_MCU_ILM_ADDR
,
90 fw_payload
+ le32_to_cpu(hdr
->ilm_len
), dlm_len
);
92 /* trigger firmware */
93 mt76_wr(dev
, MT_MCU_PCIE_REMAP_BASE4
, 0);
95 mt76_wr(dev
, MT_MCU_INT_LEVEL
, 0x3);
97 mt76_wr(dev
, MT_MCU_RESET_CTL
, 0x300);
99 if (!mt76_poll_msec(dev
, MT_MCU_COM_REG0
, 1, 1, 1000)) {
100 dev_err(dev
->mt76
.dev
, "Firmware failed to start\n");
105 mt76x02_set_ethtool_fwver(dev
, hdr
);
106 dev_dbg(dev
->mt76
.dev
, "Firmware running!\n");
110 mt76_wr(dev
, MT_MCU_SEMAPHORE_00
, 0x1);
111 release_firmware(fw
);
116 int mt76x0e_mcu_init(struct mt76x02_dev
*dev
)
118 static const struct mt76_mcu_ops mt76x0e_mcu_ops
= {
119 .mcu_send_msg
= mt76x02_mcu_msg_send
,
123 dev
->mt76
.mcu_ops
= &mt76x0e_mcu_ops
;
125 err
= mt76x0e_load_firmware(dev
);
129 set_bit(MT76_STATE_MCU_RUNNING
, &dev
->mt76
.state
);