]>
Commit | Line | Data |
---|---|---|
4b12783c JJH |
1 | // SPDX-License-Identifier: GPL-2.0+ |
2 | /* | |
a94a4071 | 3 | * Copyright (C) 2017 Texas Instruments Incorporated - https://www.ti.com/ |
4b12783c JJH |
4 | * Written by Jean-Jacques Hiblot <jjhiblot@ti.com> |
5 | */ | |
6 | ||
d678a59d | 7 | #include <common.h> |
4b12783c | 8 | #include <dm.h> |
f7ae49fc | 9 | #include <log.h> |
4b12783c JJH |
10 | #include <dm/device.h> |
11 | #include <generic-phy.h> | |
12 | #include <asm/io.h> | |
2bbc1bbf | 13 | #include <asm/arch/psc_defs.h> |
cd93d625 | 14 | #include <linux/bitops.h> |
c05ed00a | 15 | #include <linux/delay.h> |
1e94b46f | 16 | #include <linux/printk.h> |
4b12783c JJH |
17 | |
18 | /* USB PHY control register offsets */ | |
19 | #define USB_PHY_CTL_UTMI 0x0000 | |
20 | #define USB_PHY_CTL_PIPE 0x0004 | |
21 | #define USB_PHY_CTL_PARAM_1 0x0008 | |
22 | #define USB_PHY_CTL_PARAM_2 0x000c | |
23 | #define USB_PHY_CTL_CLOCK 0x0010 | |
24 | #define USB_PHY_CTL_PLL 0x0014 | |
25 | ||
26 | #define PHY_OTG_VBUSVLDECTSEL BIT(16) | |
27 | #define PHY_REF_SSP_EN BIT(29) | |
28 | ||
29 | struct keystone_usb_phy { | |
2bbc1bbf | 30 | u32 psc_domain; |
4b12783c JJH |
31 | void __iomem *reg; |
32 | }; | |
33 | ||
34 | static int keystone_usb_init(struct phy *phy) | |
35 | { | |
36 | u32 val; | |
2bbc1bbf | 37 | int rc; |
4b12783c JJH |
38 | struct udevice *dev = phy->dev; |
39 | struct keystone_usb_phy *keystone = dev_get_priv(dev); | |
40 | ||
2bbc1bbf JJH |
41 | /* Release USB from reset */ |
42 | rc = psc_enable_module(keystone->psc_domain); | |
43 | if (rc) { | |
44 | debug("Cannot enable USB module"); | |
45 | return -rc; | |
46 | } | |
47 | mdelay(10); | |
48 | ||
4b12783c JJH |
49 | /* |
50 | * VBUSVLDEXTSEL has a default value of 1 in BootCfg but shouldn't. | |
51 | * It should always be cleared because our USB PHY has an onchip VBUS | |
52 | * analog comparator. | |
53 | */ | |
54 | val = readl(keystone->reg + USB_PHY_CTL_CLOCK); | |
55 | /* quit selecting the vbusvldextsel by default! */ | |
56 | val &= ~PHY_OTG_VBUSVLDECTSEL; | |
57 | writel(val, keystone->reg + USB_PHY_CTL_CLOCK); | |
58 | ||
59 | return 0; | |
60 | } | |
61 | ||
62 | static int keystone_usb_power_on(struct phy *phy) | |
63 | { | |
64 | u32 val; | |
65 | struct udevice *dev = phy->dev; | |
66 | struct keystone_usb_phy *keystone = dev_get_priv(dev); | |
67 | ||
68 | val = readl(keystone->reg + USB_PHY_CTL_CLOCK); | |
69 | val |= PHY_REF_SSP_EN; | |
70 | writel(val, keystone->reg + USB_PHY_CTL_CLOCK); | |
71 | ||
72 | return 0; | |
73 | } | |
74 | ||
75 | static int keystone_usb_power_off(struct phy *phy) | |
76 | { | |
77 | u32 val; | |
78 | struct udevice *dev = phy->dev; | |
79 | struct keystone_usb_phy *keystone = dev_get_priv(dev); | |
80 | ||
81 | val = readl(keystone->reg + USB_PHY_CTL_CLOCK); | |
82 | val &= ~PHY_REF_SSP_EN; | |
83 | writel(val, keystone->reg + USB_PHY_CTL_CLOCK); | |
84 | ||
85 | return 0; | |
86 | } | |
87 | ||
88 | static int keystone_usb_exit(struct phy *phy) | |
89 | { | |
2bbc1bbf JJH |
90 | struct udevice *dev = phy->dev; |
91 | struct keystone_usb_phy *keystone = dev_get_priv(dev); | |
92 | ||
93 | if (psc_disable_module(keystone->psc_domain)) | |
94 | debug("failed to disable USB module!\n"); | |
95 | ||
4b12783c JJH |
96 | return 0; |
97 | } | |
98 | ||
99 | static int keystone_usb_phy_probe(struct udevice *dev) | |
100 | { | |
2bbc1bbf | 101 | int rc; |
4b12783c JJH |
102 | struct keystone_usb_phy *keystone = dev_get_priv(dev); |
103 | ||
2bbc1bbf JJH |
104 | rc = dev_read_u32(dev, "psc-domain", &keystone->psc_domain); |
105 | if (rc) | |
106 | return rc; | |
107 | ||
4b12783c JJH |
108 | keystone->reg = dev_remap_addr_index(dev, 0); |
109 | if (!keystone->reg) { | |
110 | pr_err("unable to remap usb phy\n"); | |
111 | return -EINVAL; | |
112 | } | |
113 | return 0; | |
114 | } | |
115 | ||
116 | static const struct udevice_id keystone_usb_phy_ids[] = { | |
117 | { .compatible = "ti,keystone-usbphy" }, | |
118 | { } | |
119 | }; | |
120 | ||
121 | static struct phy_ops keystone_usb_phy_ops = { | |
122 | .init = keystone_usb_init, | |
123 | .power_on = keystone_usb_power_on, | |
124 | .power_off = keystone_usb_power_off, | |
125 | .exit = keystone_usb_exit, | |
126 | }; | |
127 | ||
128 | U_BOOT_DRIVER(keystone_usb_phy) = { | |
129 | .name = "keystone_usb_phy", | |
130 | .id = UCLASS_PHY, | |
131 | .of_match = keystone_usb_phy_ids, | |
132 | .ops = &keystone_usb_phy_ops, | |
133 | .probe = keystone_usb_phy_probe, | |
41575d8e | 134 | .priv_auto = sizeof(struct keystone_usb_phy), |
4b12783c | 135 | }; |