Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /* Copyright (C) 2019 MediaTek Inc.
0003  *
0004  * Author: Felix Fietkau <nbd@nbd.name>
0005  *     Lorenzo Bianconi <lorenzo@kernel.org>
0006  *     Sean Wang <sean.wang@mediatek.com>
0007  */
0008 #include <linux/kernel.h>
0009 #include <linux/module.h>
0010 
0011 #include "mt7615.h"
0012 #include "mac.h"
0013 #include "mcu.h"
0014 #include "regs.h"
0015 
0016 static int
0017 mt7663u_mcu_send_message(struct mt76_dev *mdev, struct sk_buff *skb,
0018              int cmd, int *seq)
0019 {
0020     struct mt7615_dev *dev = container_of(mdev, struct mt7615_dev, mt76);
0021     int ret, ep, len, pad;
0022 
0023     mt7615_mcu_fill_msg(dev, skb, cmd, seq);
0024     if (cmd != MCU_CMD(FW_SCATTER))
0025         ep = MT_EP_OUT_INBAND_CMD;
0026     else
0027         ep = MT_EP_OUT_AC_BE;
0028 
0029     len = skb->len;
0030     put_unaligned_le32(len, skb_push(skb, sizeof(len)));
0031     pad = round_up(skb->len, 4) + 4 - skb->len;
0032     ret = mt76_skb_adjust_pad(skb, pad);
0033     if (ret < 0)
0034         goto out;
0035 
0036     ret = mt76u_bulk_msg(&dev->mt76, skb->data, skb->len, NULL,
0037                  1000, ep);
0038 
0039 out:
0040     dev_kfree_skb(skb);
0041 
0042     return ret;
0043 }
0044 
0045 int mt7663u_mcu_power_on(struct mt7615_dev *dev)
0046 {
0047     int ret;
0048 
0049     ret = mt76u_vendor_request(&dev->mt76, MT_VEND_POWER_ON,
0050                    USB_DIR_OUT | USB_TYPE_VENDOR,
0051                    0x0, 0x1, NULL, 0);
0052     if (ret)
0053         return ret;
0054 
0055     if (!mt76_poll_msec(dev, MT_CONN_ON_MISC,
0056                 MT_TOP_MISC2_FW_PWR_ON,
0057                 FW_STATE_PWR_ON << 1, 500)) {
0058         dev_err(dev->mt76.dev, "Timeout for power on\n");
0059         ret = -EIO;
0060     }
0061 
0062     return 0;
0063 }
0064 
0065 int mt7663u_mcu_init(struct mt7615_dev *dev)
0066 {
0067     static const struct mt76_mcu_ops mt7663u_mcu_ops = {
0068         .headroom = MT_USB_HDR_SIZE + sizeof(struct mt7615_mcu_txd),
0069         .tailroom = MT_USB_TAIL_SIZE,
0070         .mcu_skb_send_msg = mt7663u_mcu_send_message,
0071         .mcu_parse_response = mt7615_mcu_parse_response,
0072         .mcu_restart = mt7615_mcu_restart,
0073     };
0074     int ret;
0075 
0076     dev->mt76.mcu_ops = &mt7663u_mcu_ops,
0077 
0078     mt76_set(dev, MT_UDMA_TX_QSEL, MT_FW_DL_EN);
0079     if (test_and_clear_bit(MT76_STATE_POWER_OFF, &dev->mphy.state)) {
0080         ret = mt7615_mcu_restart(&dev->mt76);
0081         if (ret)
0082             return ret;
0083 
0084         if (!mt76_poll_msec(dev, MT_CONN_ON_MISC,
0085                     MT_TOP_MISC2_FW_PWR_ON, 0, 500))
0086             return -EIO;
0087 
0088         ret = mt7663u_mcu_power_on(dev);
0089         if (ret)
0090             return ret;
0091     }
0092 
0093     ret = __mt7663_load_firmware(dev);
0094     if (ret)
0095         return ret;
0096 
0097     mt76_clear(dev, MT_UDMA_TX_QSEL, MT_FW_DL_EN);
0098     set_bit(MT76_STATE_MCU_RUNNING, &dev->mphy.state);
0099 
0100     return 0;
0101 }