1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2020 MediaTek Inc. All Rights Reserved.
5 * Author: Weijie Gao <weijie.gao@mediatek.com>
10 #include <generic-phy.h>
13 #include <dm/device_compat.h>
14 #include <linux/delay.h>
15 #include <mach/mt7620-sysc.h>
17 struct mt7620_usb_phy {
19 struct clk_bulk clocks;
20 struct reset_ctl_bulk resets;
23 static int mt7620_usb_phy_power_on(struct phy *_phy)
25 struct mt7620_usb_phy *phy = dev_get_priv(_phy->dev);
26 u32 mode = MT7620_SYSC_USB_HOST_MODE;
29 reset_deassert_bulk(&phy->resets);
31 clk_enable_bulk(&phy->clocks);
35 ret = misc_ioctl(phy->sysc, MT7620_SYSC_IOCTL_SET_USB_MODE, &mode);
38 "mt7620_usbphy: failed to set USB host mode\n");
47 static int mt7620_usb_phy_power_off(struct phy *_phy)
49 struct mt7620_usb_phy *phy = dev_get_priv(_phy->dev);
51 clk_disable_bulk(&phy->clocks);
53 reset_assert_bulk(&phy->resets);
58 static int mt7620_usb_phy_probe(struct udevice *dev)
60 struct mt7620_usb_phy *phy = dev_get_priv(dev);
61 struct ofnode_phandle_args sysc_args;
64 ret = ofnode_parse_phandle_with_args(dev_ofnode(dev), "mediatek,sysc", NULL,
67 dev_err(dev, "mt7620_usbphy: sysc property not found\n");
71 ret = uclass_get_device_by_ofnode(UCLASS_MISC, sysc_args.node,
74 dev_err(dev, "mt7620_usbphy: failed to sysc device\n");
78 ret = clk_get_bulk(dev, &phy->clocks);
80 dev_err(dev, "mt7620_usbphy: failed to get clocks\n");
84 ret = reset_get_bulk(dev, &phy->resets);
86 dev_err(dev, "mt7620_usbphy: failed to get reset control\n");
93 static struct phy_ops mt7620_usb_phy_ops = {
94 .power_on = mt7620_usb_phy_power_on,
95 .power_off = mt7620_usb_phy_power_off,
98 static const struct udevice_id mt7620_usb_phy_ids[] = {
99 { .compatible = "mediatek,mt7620-usbphy" },
103 U_BOOT_DRIVER(mt7620_usb_phy) = {
104 .name = "mt7620_usb_phy",
106 .of_match = mt7620_usb_phy_ids,
107 .ops = &mt7620_usb_phy_ops,
108 .probe = mt7620_usb_phy_probe,
109 .priv_auto = sizeof(struct mt7620_usb_phy),