Lines Matching +full:drv +full:- +full:0
1 // SPDX-License-Identifier: GPL-2.0
3 * Renesas R-Car Gen2 PHY driver
20 #define USBHS_LPSTS 0x02
21 #define USBHS_UGCTRL 0x80
22 #define USBHS_UGCTRL2 0x84
23 #define USBHS_UGSTS 0x88 /* From technical update */
26 #define USBHS_LPSTS_SUSPM 0x4000
29 #define USBHS_UGCTRL_CONNECT 0x00000004
30 #define USBHS_UGCTRL_PLLRESET 0x00000001
33 #define USBHS_UGCTRL2_USB2SEL 0x80000000
34 #define USBHS_UGCTRL2_USB2SEL_PCI 0x00000000
35 #define USBHS_UGCTRL2_USB2SEL_USB30 0x80000000
36 #define USBHS_UGCTRL2_USB0SEL 0x00000030
37 #define USBHS_UGCTRL2_USB0SEL_PCI 0x00000010
38 #define USBHS_UGCTRL2_USB0SEL_HS_USB 0x00000030
39 #define USBHS_UGCTRL2_USB0SEL_USB20 0x00000010
40 #define USBHS_UGCTRL2_USB0SEL_HS_USB20 0x00000020
43 #define USBHS_UGSTS_LOCK 0x00000100 /* From technical update */
56 struct rcar_gen2_phy_driver *drv; member
79 struct rcar_gen2_channel *channel = phy->channel; in rcar_gen2_phy_init()
80 struct rcar_gen2_phy_driver *drv = channel->drv; in rcar_gen2_phy_init() local
88 * driver. Achieving this with cmpxcgh() should be SMP-safe. in rcar_gen2_phy_init()
90 if (cmpxchg(&channel->selected_phy, -1, phy->number) != -1) in rcar_gen2_phy_init()
91 return -EBUSY; in rcar_gen2_phy_init()
93 clk_prepare_enable(drv->clk); in rcar_gen2_phy_init()
95 spin_lock_irqsave(&drv->lock, flags); in rcar_gen2_phy_init()
96 ugctrl2 = readl(drv->base + USBHS_UGCTRL2); in rcar_gen2_phy_init()
97 ugctrl2 &= ~channel->select_mask; in rcar_gen2_phy_init()
98 ugctrl2 |= phy->select_value; in rcar_gen2_phy_init()
99 writel(ugctrl2, drv->base + USBHS_UGCTRL2); in rcar_gen2_phy_init()
100 spin_unlock_irqrestore(&drv->lock, flags); in rcar_gen2_phy_init()
101 return 0; in rcar_gen2_phy_init()
107 struct rcar_gen2_channel *channel = phy->channel; in rcar_gen2_phy_exit()
109 clk_disable_unprepare(channel->drv->clk); in rcar_gen2_phy_exit()
111 channel->selected_phy = -1; in rcar_gen2_phy_exit()
113 return 0; in rcar_gen2_phy_exit()
119 struct rcar_gen2_phy_driver *drv = phy->channel->drv; in rcar_gen2_phy_power_on() local
120 void __iomem *base = drv->base; in rcar_gen2_phy_power_on()
123 int err = 0, i; in rcar_gen2_phy_power_on()
126 if (phy->select_value != USBHS_UGCTRL2_USB0SEL_HS_USB) in rcar_gen2_phy_power_on()
127 return 0; in rcar_gen2_phy_power_on()
129 spin_lock_irqsave(&drv->lock, flags); in rcar_gen2_phy_power_on()
140 for (i = 0; i < 20; i++) { in rcar_gen2_phy_power_on()
152 err = -ETIMEDOUT; in rcar_gen2_phy_power_on()
155 spin_unlock_irqrestore(&drv->lock, flags); in rcar_gen2_phy_power_on()
163 struct rcar_gen2_phy_driver *drv = phy->channel->drv; in rcar_gen2_phy_power_off() local
164 void __iomem *base = drv->base; in rcar_gen2_phy_power_off()
169 if (phy->select_value != USBHS_UGCTRL2_USB0SEL_HS_USB) in rcar_gen2_phy_power_off()
170 return 0; in rcar_gen2_phy_power_off()
172 spin_lock_irqsave(&drv->lock, flags); in rcar_gen2_phy_power_off()
187 spin_unlock_irqrestore(&drv->lock, flags); in rcar_gen2_phy_power_off()
189 return 0; in rcar_gen2_phy_power_off()
195 struct rcar_gen2_phy_driver *drv = phy->channel->drv; in rz_g1c_phy_power_on() local
196 void __iomem *base = drv->base; in rz_g1c_phy_power_on()
200 spin_lock_irqsave(&drv->lock, flags); in rz_g1c_phy_power_on()
210 if (phy->select_value == USBHS_UGCTRL2_USB0SEL_HS_USB20) { in rz_g1c_phy_power_on()
216 spin_unlock_irqrestore(&drv->lock, flags); in rz_g1c_phy_power_on()
218 return 0; in rz_g1c_phy_power_on()
224 struct rcar_gen2_phy_driver *drv = phy->channel->drv; in rz_g1c_phy_power_off() local
225 void __iomem *base = drv->base; in rz_g1c_phy_power_off()
229 spin_lock_irqsave(&drv->lock, flags); in rz_g1c_phy_power_off()
231 if (phy->select_value == USBHS_UGCTRL2_USB0SEL_HS_USB20) { in rz_g1c_phy_power_off()
241 spin_unlock_irqrestore(&drv->lock, flags); in rz_g1c_phy_power_off()
243 return 0; in rz_g1c_phy_power_off()
263 [0] = { USBHS_UGCTRL2_USB0SEL_PCI, USBHS_UGCTRL2_USB0SEL_HS_USB },
285 .compatible = "renesas,usb-phy-r8a77470",
289 .compatible = "renesas,usb-phy-r8a7790",
293 .compatible = "renesas,usb-phy-r8a7791",
297 .compatible = "renesas,usb-phy-r8a7794",
301 .compatible = "renesas,rcar-gen2-usb-phy",
311 struct rcar_gen2_phy_driver *drv; in rcar_gen2_phy_xlate() local
312 struct device_node *np = args->np; in rcar_gen2_phy_xlate()
315 drv = dev_get_drvdata(dev); in rcar_gen2_phy_xlate()
316 if (!drv) in rcar_gen2_phy_xlate()
317 return ERR_PTR(-EINVAL); in rcar_gen2_phy_xlate()
319 for (i = 0; i < drv->num_channels; i++) { in rcar_gen2_phy_xlate()
320 if (np == drv->channels[i].of_node) in rcar_gen2_phy_xlate()
324 if (i >= drv->num_channels || args->args[0] >= 2) in rcar_gen2_phy_xlate()
325 return ERR_PTR(-ENODEV); in rcar_gen2_phy_xlate()
327 return drv->channels[i].phys[args->args[0]].phy; in rcar_gen2_phy_xlate()
331 [0] = USBHS_UGCTRL2_USB0SEL,
337 struct device *dev = &pdev->dev; in rcar_gen2_phy_probe()
338 struct rcar_gen2_phy_driver *drv; in rcar_gen2_phy_probe() local
344 int i = 0; in rcar_gen2_phy_probe()
346 if (!dev->of_node) { in rcar_gen2_phy_probe()
349 return -EINVAL; in rcar_gen2_phy_probe()
358 base = devm_platform_ioremap_resource(pdev, 0); in rcar_gen2_phy_probe()
362 drv = devm_kzalloc(dev, sizeof(*drv), GFP_KERNEL); in rcar_gen2_phy_probe()
363 if (!drv) in rcar_gen2_phy_probe()
364 return -ENOMEM; in rcar_gen2_phy_probe()
366 spin_lock_init(&drv->lock); in rcar_gen2_phy_probe()
368 drv->clk = clk; in rcar_gen2_phy_probe()
369 drv->base = base; in rcar_gen2_phy_probe()
373 return -EINVAL; in rcar_gen2_phy_probe()
375 drv->num_channels = of_get_child_count(dev->of_node); in rcar_gen2_phy_probe()
376 drv->channels = devm_kcalloc(dev, drv->num_channels, in rcar_gen2_phy_probe()
379 if (!drv->channels) in rcar_gen2_phy_probe()
380 return -ENOMEM; in rcar_gen2_phy_probe()
382 for_each_child_of_node(dev->of_node, np) { in rcar_gen2_phy_probe()
383 struct rcar_gen2_channel *channel = drv->channels + i; in rcar_gen2_phy_probe()
387 channel->of_node = np; in rcar_gen2_phy_probe()
388 channel->drv = drv; in rcar_gen2_phy_probe()
389 channel->selected_phy = -1; in rcar_gen2_phy_probe()
392 if (error || channel_num >= data->num_channels) { in rcar_gen2_phy_probe()
397 channel->select_mask = select_mask[channel_num]; in rcar_gen2_phy_probe()
399 for (n = 0; n < PHYS_PER_CHANNEL; n++) { in rcar_gen2_phy_probe()
400 struct rcar_gen2_phy *phy = &channel->phys[n]; in rcar_gen2_phy_probe()
402 phy->channel = channel; in rcar_gen2_phy_probe()
403 phy->number = n; in rcar_gen2_phy_probe()
404 phy->select_value = data->select_value[channel_num][n]; in rcar_gen2_phy_probe()
406 phy->phy = devm_phy_create(dev, NULL, in rcar_gen2_phy_probe()
407 data->gen2_phy_ops); in rcar_gen2_phy_probe()
408 if (IS_ERR(phy->phy)) { in rcar_gen2_phy_probe()
411 return PTR_ERR(phy->phy); in rcar_gen2_phy_probe()
413 phy_set_drvdata(phy->phy, phy); in rcar_gen2_phy_probe()
425 dev_set_drvdata(dev, drv); in rcar_gen2_phy_probe()
427 return 0; in rcar_gen2_phy_probe()
441 MODULE_DESCRIPTION("Renesas R-Car Gen2 PHY");