1dfc7743dSSean Wang // SPDX-License-Identifier: ISC
2dfc7743dSSean Wang /* Copyright (C) 2021 MediaTek Inc. */
3dfc7743dSSean Wang
4dfc7743dSSean Wang #include "mt7921.h"
5dfc7743dSSean Wang #include "mcu.h"
6dfc7743dSSean Wang
mt7921e_driver_own(struct mt792x_dev * dev)7*975e122dSLorenzo Bianconi int mt7921e_driver_own(struct mt792x_dev *dev)
8dfc7743dSSean Wang {
9dfc7743dSSean Wang u32 reg = mt7921_reg_map_l1(dev, MT_TOP_LPCR_HOST_BAND0);
10dfc7743dSSean Wang
11dfc7743dSSean Wang mt76_wr(dev, reg, MT_TOP_LPCR_HOST_DRV_OWN);
12dfc7743dSSean Wang if (!mt76_poll_msec(dev, reg, MT_TOP_LPCR_HOST_FW_OWN,
13dfc7743dSSean Wang 0, 500)) {
14dfc7743dSSean Wang dev_err(dev->mt76.dev, "Timeout for driver own\n");
15dfc7743dSSean Wang return -EIO;
16dfc7743dSSean Wang }
17dfc7743dSSean Wang
18dfc7743dSSean Wang return 0;
19dfc7743dSSean Wang }
20dfc7743dSSean Wang
21fe0195f7SSean Wang static int
mt7921_mcu_send_message(struct mt76_dev * mdev,struct sk_buff * skb,int cmd,int * seq)22fe0195f7SSean Wang mt7921_mcu_send_message(struct mt76_dev *mdev, struct sk_buff *skb,
23fe0195f7SSean Wang int cmd, int *seq)
24fe0195f7SSean Wang {
25*975e122dSLorenzo Bianconi struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76);
26fe0195f7SSean Wang enum mt76_mcuq_id txq = MT_MCUQ_WM;
27fe0195f7SSean Wang int ret;
28fe0195f7SSean Wang
29d2f5c8edSLorenzo Bianconi ret = mt76_connac2_mcu_fill_message(mdev, skb, cmd, seq);
30fe0195f7SSean Wang if (ret)
31fe0195f7SSean Wang return ret;
32fe0195f7SSean Wang
33d2f5c8edSLorenzo Bianconi mdev->mcu.timeout = 3 * HZ;
34d2f5c8edSLorenzo Bianconi
35ffc2198dSLorenzo Bianconi if (cmd == MCU_CMD(FW_SCATTER))
36fe0195f7SSean Wang txq = MT_MCUQ_FWDL;
37fe0195f7SSean Wang
38fe0195f7SSean Wang return mt76_tx_queue_skb_raw(dev, mdev->q_mcu[txq], skb, 0);
39fe0195f7SSean Wang }
40fe0195f7SSean Wang
mt7921e_mcu_init(struct mt792x_dev * dev)41*975e122dSLorenzo Bianconi int mt7921e_mcu_init(struct mt792x_dev *dev)
42dfc7743dSSean Wang {
43dfc7743dSSean Wang static const struct mt76_mcu_ops mt7921_mcu_ops = {
44fc6ee71aSLorenzo Bianconi .headroom = sizeof(struct mt76_connac2_mcu_txd),
45dfc7743dSSean Wang .mcu_skb_send_msg = mt7921_mcu_send_message,
46dfc7743dSSean Wang .mcu_parse_response = mt7921_mcu_parse_response,
47dfc7743dSSean Wang };
48dfc7743dSSean Wang int err;
49dfc7743dSSean Wang
50dfc7743dSSean Wang dev->mt76.mcu_ops = &mt7921_mcu_ops;
51dfc7743dSSean Wang
52dfc7743dSSean Wang err = mt7921e_driver_own(dev);
53dfc7743dSSean Wang if (err)
54dfc7743dSSean Wang return err;
55dfc7743dSSean Wang
5629e247ecSDeren Wu mt76_rmw_field(dev, MT_PCIE_MAC_PM, MT_PCIE_MAC_PM_L0S_DIS, 1);
5729e247ecSDeren Wu
58dfc7743dSSean Wang err = mt7921_run_firmware(dev);
59dfc7743dSSean Wang
60dfc7743dSSean Wang mt76_queue_tx_cleanup(dev, dev->mt76.q_mcu[MT_MCUQ_FWDL], false);
61dfc7743dSSean Wang
62dfc7743dSSean Wang return err;
63dfc7743dSSean Wang }
64