Lines Matching +full:m +full:- +full:phy
1 // SPDX-License-Identifier: GPL-2.0+
3 * StarFive JH7110 USB 2.0 PHY driver
15 #include <linux/phy/phy.h>
28 struct phy *phy; member
36 static void usb2_set_ls_keepalive(struct jh7110_usb2_phy *phy, bool set) in usb2_set_ls_keepalive() argument
40 /* Host mode enable the LS speed keep-alive signal */ in usb2_set_ls_keepalive()
41 val = readl(phy->regs + USB_LS_KEEPALIVE_OFF); in usb2_set_ls_keepalive()
47 writel(val, phy->regs + USB_LS_KEEPALIVE_OFF); in usb2_set_ls_keepalive()
50 static int usb2_phy_set_mode(struct phy *_phy, in usb2_phy_set_mode()
53 struct jh7110_usb2_phy *phy = phy_get_drvdata(_phy); in usb2_phy_set_mode() local
61 return -EINVAL; in usb2_phy_set_mode()
64 if (mode != phy->mode) { in usb2_phy_set_mode()
65 dev_dbg(&_phy->dev, "Changing phy to %d\n", mode); in usb2_phy_set_mode()
66 phy->mode = mode; in usb2_phy_set_mode()
67 usb2_set_ls_keepalive(phy, (mode != PHY_MODE_USB_DEVICE)); in usb2_phy_set_mode()
70 /* Connect usb 2.0 phy mode */ in usb2_phy_set_mode()
71 regmap_update_bits(phy->sys_syscon, SYSCON_USB_SPLIT_OFFSET, in usb2_phy_set_mode()
77 static int jh7110_usb2_phy_init(struct phy *_phy) in jh7110_usb2_phy_init()
79 struct jh7110_usb2_phy *phy = phy_get_drvdata(_phy); in jh7110_usb2_phy_init() local
82 ret = clk_set_rate(phy->usb_125m_clk, USB_125M_CLK_RATE); in jh7110_usb2_phy_init()
86 ret = clk_prepare_enable(phy->app_125m); in jh7110_usb2_phy_init()
93 static int jh7110_usb2_phy_exit(struct phy *_phy) in jh7110_usb2_phy_exit()
95 struct jh7110_usb2_phy *phy = phy_get_drvdata(_phy); in jh7110_usb2_phy_exit() local
97 clk_disable_unprepare(phy->app_125m); in jh7110_usb2_phy_exit()
111 struct jh7110_usb2_phy *phy; in jh7110_usb_phy_probe() local
112 struct device *dev = &pdev->dev; in jh7110_usb_phy_probe()
115 phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); in jh7110_usb_phy_probe()
116 if (!phy) in jh7110_usb_phy_probe()
117 return -ENOMEM; in jh7110_usb_phy_probe()
119 phy->usb_125m_clk = devm_clk_get(dev, "125m"); in jh7110_usb_phy_probe()
120 if (IS_ERR(phy->usb_125m_clk)) in jh7110_usb_phy_probe()
121 return dev_err_probe(dev, PTR_ERR(phy->usb_125m_clk), in jh7110_usb_phy_probe()
122 "Failed to get 125m clock\n"); in jh7110_usb_phy_probe()
124 phy->app_125m = devm_clk_get(dev, "app_125m"); in jh7110_usb_phy_probe()
125 if (IS_ERR(phy->app_125m)) in jh7110_usb_phy_probe()
126 return dev_err_probe(dev, PTR_ERR(phy->app_125m), in jh7110_usb_phy_probe()
127 "Failed to get app 125m clock\n"); in jh7110_usb_phy_probe()
129 phy->regs = devm_platform_ioremap_resource(pdev, 0); in jh7110_usb_phy_probe()
130 if (IS_ERR(phy->regs)) in jh7110_usb_phy_probe()
131 return dev_err_probe(dev, PTR_ERR(phy->regs), in jh7110_usb_phy_probe()
132 "Failed to map phy base\n"); in jh7110_usb_phy_probe()
134 phy->phy = devm_phy_create(dev, NULL, &jh7110_usb2_phy_ops); in jh7110_usb_phy_probe()
135 if (IS_ERR(phy->phy)) in jh7110_usb_phy_probe()
136 return dev_err_probe(dev, PTR_ERR(phy->phy), in jh7110_usb_phy_probe()
137 "Failed to create phy\n"); in jh7110_usb_phy_probe()
139 phy_set_drvdata(phy->phy, phy); in jh7110_usb_phy_probe()
142 phy->sys_syscon = in jh7110_usb_phy_probe()
143 syscon_regmap_lookup_by_compatible("starfive,jh7110-sys-syscon"); in jh7110_usb_phy_probe()
144 if (IS_ERR(phy->sys_syscon)) in jh7110_usb_phy_probe()
145 return dev_err_probe(dev, PTR_ERR(phy->sys_syscon), in jh7110_usb_phy_probe()
146 "Failed to get sys-syscon\n"); in jh7110_usb_phy_probe()
152 { .compatible = "starfive,jh7110-usb-phy" },
161 .name = "jh7110-usb-phy",
166 MODULE_DESCRIPTION("StarFive JH7110 USB 2.0 PHY driver");