1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
// SPDX-License-Identifier: GPL-2.0+
/*
* OMAP USB2 PHY LAYER
*
* Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com
* Written by Jean-Jacques Hiblot <jjhiblot@ti.com>
*/
#include <common.h>
#include <asm/io.h>
#include <dm.h>
#include <errno.h>
#include <generic-phy.h>
#include <regmap.h>
#include <syscon.h>
#include <linux/bitops.h>
#include <linux/err.h>
#define OMAP_USB2_CALIBRATE_FALSE_DISCONNECT BIT(0)
#define OMAP_USB2_DISABLE_CHG_DET BIT(1)
#define OMAP_DEV_PHY_PD BIT(0)
#define OMAP_USB2_PHY_PD BIT(28)
#define AM437X_USB2_PHY_PD BIT(0)
#define AM437X_USB2_OTG_PD BIT(1)
#define AM437X_USB2_OTGVDET_EN BIT(19)
#define AM437X_USB2_OTGSESSEND_EN BIT(20)
#define USB2PHY_DISCON_BYP_LATCH BIT(31)
#define USB2PHY_ANA_CONFIG1 (0x4c)
#define AM654_USB2_OTG_PD BIT(8)
#define AM654_USB2_VBUS_DET_EN BIT(5)
#define AM654_USB2_VBUSVALID_DET_EN BIT(4)
#define USB2PHY_CHRG_DET 0x14
#define USB2PHY_USE_CHG_DET_REG BIT(29)
#define USB2PHY_DIS_CHG_DET BIT(28)
DECLARE_GLOBAL_DATA_PTR;
struct omap_usb2_phy {
struct regmap *pwr_regmap;
ulong flags;
void *phy_base;
u32 pwr_reg_offset;
};
struct usb_phy_data {
const char *label;
u8 flags;
u32 mask;
u32 power_on;
u32 power_off;
};
static const struct usb_phy_data omap5_usb2_data = {
.label = "omap5_usb2",
.flags = 0,
.mask = OMAP_DEV_PHY_PD,
.power_off = OMAP_DEV_PHY_PD,
};
static const struct usb_phy_data dra7x_usb2_data = {
.label = "dra7x_usb2",
.flags = OMAP_USB2_CALIBRATE_FALSE_DISCONNECT,
.mask = OMAP_DEV_PHY_PD,
.power_off = OMAP_DEV_PHY_PD,
};
static const struct usb_phy_data dra7x_usb2_phy2_data = {
.label = "dra7x_usb2_phy2",
.flags = OMAP_USB2_CALIBRATE_FALSE_DISCONNECT,
.mask = OMAP_USB2_PHY_PD,
.power_off = OMAP_USB2_PHY_PD,
};
static const struct usb_phy_data am437x_usb2_data = {
.label = "am437x_usb2",
.flags = 0,
.mask = AM437X_USB2_PHY_PD | AM437X_USB2_OTG_PD |
AM437X_USB2_OTGVDET_EN | AM437X_USB2_OTGSESSEND_EN,
.power_on = AM437X_USB2_OTGVDET_EN | AM437X_USB2_OTGSESSEND_EN,
.power_off = AM437X_USB2_PHY_PD | AM437X_USB2_OTG_PD,
};
static const struct usb_phy_data am654_usb2_data = {
.label = "am654_usb2",
.flags = OMAP_USB2_CALIBRATE_FALSE_DISCONNECT,
.mask = AM654_USB2_OTG_PD | AM654_USB2_VBUS_DET_EN |
AM654_USB2_VBUSVALID_DET_EN,
.power_on = AM654_USB2_VBUS_DET_EN | AM654_USB2_VBUSVALID_DET_EN,
.power_off = AM654_USB2_OTG_PD,
};
static const struct udevice_id omap_usb2_id_table[] = {
{
.compatible = "ti,omap5-usb2",
.data = (ulong)&omap5_usb2_data,
},
{
.compatible = "ti,dra7x-usb2",
.data = (ulong)&dra7x_usb2_data,
},
{
.compatible = "ti,dra7x-usb2-phy2",
.data = (ulong)&dra7x_usb2_phy2_data,
},
{
.compatible = "ti,am437x-usb2",
.data = (ulong)&am437x_usb2_data,
},
{
.compatible = "ti,am654-usb2",
.data = (ulong)&am654_usb2_data,
},
{},
};
static int omap_usb_phy_power(struct phy *usb_phy, bool on)
{
struct udevice *dev = usb_phy->dev;
const struct usb_phy_data *data;
const struct omap_usb2_phy *phy = dev_get_priv(dev);
u32 val;
int rc;
data = (const struct usb_phy_data *)dev_get_driver_data(dev);
if (!data)
return -EINVAL;
rc = regmap_read(phy->pwr_regmap, phy->pwr_reg_offset, &val);
if (rc)
return rc;
val &= ~data->mask;
if (on)
val |= data->power_on;
else
val |= data->power_off;
rc = regmap_write(phy->pwr_regmap, phy->pwr_reg_offset, val);
if (rc)
return rc;
return 0;
}
static int omap_usb2_phy_init(struct phy *usb_phy)
{
struct udevice *dev = usb_phy->dev;
struct omap_usb2_phy *priv = dev_get_priv(dev);
u32 val;
if (priv->flags & OMAP_USB2_CALIBRATE_FALSE_DISCONNECT) {
/*
*
* Reduce the sensitivity of internal PHY by enabling the
* DISCON_BYP_LATCH of the USB2PHY_ANA_CONFIG1 register. This
* resolves issues with certain devices which can otherwise
* be prone to false disconnects.
*
*/
val = readl(priv->phy_base + USB2PHY_ANA_CONFIG1);
val |= USB2PHY_DISCON_BYP_LATCH;
writel(val, priv->phy_base + USB2PHY_ANA_CONFIG1);
}
if (priv->flags & OMAP_USB2_DISABLE_CHG_DET) {
val = readl(priv->phy_base + USB2PHY_CHRG_DET);
val |= USB2PHY_USE_CHG_DET_REG | USB2PHY_DIS_CHG_DET;
writel(val, priv->phy_base + USB2PHY_CHRG_DET);
}
return 0;
}
static int omap_usb2_phy_power_on(struct phy *usb_phy)
{
return omap_usb_phy_power(usb_phy, true);
}
static int omap_usb2_phy_power_off(struct phy *usb_phy)
{
return omap_usb_phy_power(usb_phy, false);
}
static int omap_usb2_phy_exit(struct phy *usb_phy)
{
return omap_usb_phy_power(usb_phy, false);
}
struct phy_ops omap_usb2_phy_ops = {
.init = omap_usb2_phy_init,
.power_on = omap_usb2_phy_power_on,
.power_off = omap_usb2_phy_power_off,
.exit = omap_usb2_phy_exit,
};
int omap_usb2_phy_probe(struct udevice *dev)
{
int rc;
struct regmap *regmap;
struct omap_usb2_phy *priv = dev_get_priv(dev);
const struct usb_phy_data *data;
u32 tmp[2];
data = (const struct usb_phy_data *)dev_get_driver_data(dev);
if (!data)
return -EINVAL;
priv->phy_base = dev_read_addr_ptr(dev);
if (!priv->phy_base)
return -EINVAL;
if (data->flags & OMAP_USB2_CALIBRATE_FALSE_DISCONNECT)
priv->flags |= OMAP_USB2_CALIBRATE_FALSE_DISCONNECT;
/*
* AM654x PG1.0 has a silicon bug that D+ is pulled high after
* POR, which could cause enumeration failure with some USB hubs.
* Disabling the USB2_PHY Charger Detect function will put D+
* into the normal state.
*
* Using property "ti,dis-chg-det-quirk" in the DT usb2-phy node
* to enable this workaround for AM654x PG1.0.
*/
if (dev_read_bool(dev, "ti,dis-chg-det-quirk"))
priv->flags |= OMAP_USB2_DISABLE_CHG_DET;
regmap = syscon_regmap_lookup_by_phandle(dev, "syscon-phy-power");
if (!IS_ERR(regmap)) {
priv->pwr_regmap = regmap;
rc = dev_read_u32_array(dev, "syscon-phy-power", tmp, 2);
if (rc) {
printf("couldn't get power reg. offset (err %d)\n", rc);
return rc;
}
priv->pwr_reg_offset = tmp[1];
return 0;
}
regmap = syscon_regmap_lookup_by_phandle(dev, "ctrl-module");
if (!IS_ERR(regmap)) {
priv->pwr_regmap = regmap;
priv->pwr_reg_offset = 0;
return 0;
}
printf("can't get regmap (err %ld)\n", PTR_ERR(regmap));
return PTR_ERR(regmap);
}
U_BOOT_DRIVER(omap_usb2_phy) = {
.name = "omap_usb2_phy",
.id = UCLASS_PHY,
.of_match = omap_usb2_id_table,
.probe = omap_usb2_phy_probe,
.ops = &omap_usb2_phy_ops,
.priv_auto_alloc_size = sizeof(struct omap_usb2_phy),
};
|