Skip to content

Commit

Permalink
mt76: mt7663u: introduce mt7663u_mcu_power_on routine
Browse files Browse the repository at this point in the history
Introduce mt7663u_mcu_power_on utility routine since the code is shared
between mt7663u_mcu_init() and mt7663u_probe().

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
  • Loading branch information
LorenzoBianconi authored and nbd168 committed Mar 14, 2022
1 parent d3471b0 commit f4c87b3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
1 change: 1 addition & 0 deletions mt7615/mt7615.h
Expand Up @@ -559,6 +559,7 @@ void mt7663_usb_sdio_tx_complete_skb(struct mt76_dev *mdev,
struct mt76_queue_entry *e);
int mt7663_usb_sdio_register_device(struct mt7615_dev *dev);
int mt7663u_mcu_init(struct mt7615_dev *dev);
int mt7663u_mcu_power_on(struct mt7615_dev *dev);

/* sdio */
int mt7663s_mcu_init(struct mt7615_dev *dev);
Expand Down
22 changes: 5 additions & 17 deletions mt7615/usb.c
Expand Up @@ -100,27 +100,15 @@ static int mt7663u_probe(struct usb_interface *usb_intf,
(mt76_rr(dev, MT_HW_REV) & 0xff);
dev_dbg(mdev->dev, "ASIC revision: %04x\n", mdev->rev);

if (mt76_poll_msec(dev, MT_CONN_ON_MISC, MT_TOP_MISC2_FW_PWR_ON,
FW_STATE_PWR_ON << 1, 500)) {
dev_dbg(dev->mt76.dev, "Usb device already powered on\n");
set_bit(MT76_STATE_POWER_OFF, &dev->mphy.state);
goto alloc_queues;
}

ret = mt76u_vendor_request(&dev->mt76, MT_VEND_POWER_ON,
USB_DIR_OUT | USB_TYPE_VENDOR,
0x0, 0x1, NULL, 0);
if (ret)
goto error;

if (!mt76_poll_msec(dev, MT_CONN_ON_MISC, MT_TOP_MISC2_FW_PWR_ON,
FW_STATE_PWR_ON << 1, 500)) {
dev_err(dev->mt76.dev, "Timeout for power on\n");
ret = -EIO;
goto error;
ret = mt7663u_mcu_power_on(dev);
if (ret)
goto error;
} else {
set_bit(MT76_STATE_POWER_OFF, &dev->mphy.state);
}

alloc_queues:
ret = mt76u_alloc_mcu_queue(&dev->mt76);
if (ret)
goto error;
Expand Down
31 changes: 21 additions & 10 deletions mt7615/usb_mcu.c
Expand Up @@ -42,6 +42,26 @@ mt7663u_mcu_send_message(struct mt76_dev *mdev, struct sk_buff *skb,
return ret;
}

int mt7663u_mcu_power_on(struct mt7615_dev *dev)
{
int ret;

ret = mt76u_vendor_request(&dev->mt76, MT_VEND_POWER_ON,
USB_DIR_OUT | USB_TYPE_VENDOR,
0x0, 0x1, NULL, 0);
if (ret)
return ret;

if (!mt76_poll_msec(dev, MT_CONN_ON_MISC,
MT_TOP_MISC2_FW_PWR_ON,
FW_STATE_PWR_ON << 1, 500)) {
dev_err(dev->mt76.dev, "Timeout for power on\n");
ret = -EIO;
}

return 0;
}

int mt7663u_mcu_init(struct mt7615_dev *dev)
{
static const struct mt76_mcu_ops mt7663u_mcu_ops = {
Expand All @@ -65,18 +85,9 @@ int mt7663u_mcu_init(struct mt7615_dev *dev)
MT_TOP_MISC2_FW_PWR_ON, 0, 500))
return -EIO;

ret = mt76u_vendor_request(&dev->mt76, MT_VEND_POWER_ON,
USB_DIR_OUT | USB_TYPE_VENDOR,
0x0, 0x1, NULL, 0);
ret = mt7663u_mcu_power_on(dev);
if (ret)
return ret;

if (!mt76_poll_msec(dev, MT_CONN_ON_MISC,
MT_TOP_MISC2_FW_PWR_ON,
FW_STATE_PWR_ON << 1, 500)) {
dev_err(dev->mt76.dev, "Timeout for power on\n");
return -EIO;
}
}

ret = __mt7663_load_firmware(dev);
Expand Down

0 comments on commit f4c87b3

Please sign in to comment.