xref: /linux-6.15/drivers/phy/tegra/xusb.h (revision 23d5ec3f)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (c) 2014-2020, NVIDIA CORPORATION.  All rights reserved.
4  * Copyright (c) 2015, Google Inc.
5  */
6 
7 #ifndef __PHY_TEGRA_XUSB_H
8 #define __PHY_TEGRA_XUSB_H
9 
10 #include <linux/io.h>
11 #include <linux/mutex.h>
12 #include <linux/workqueue.h>
13 
14 #include <linux/usb/otg.h>
15 #include <linux/usb/role.h>
16 
17 /* legacy entry points for backwards-compatibility */
18 int tegra_xusb_padctl_legacy_probe(struct platform_device *pdev);
19 int tegra_xusb_padctl_legacy_remove(struct platform_device *pdev);
20 
21 struct phy;
22 struct phy_provider;
23 struct platform_device;
24 struct regulator;
25 
26 /*
27  * lanes
28  */
29 struct tegra_xusb_lane_soc {
30 	const char *name;
31 
32 	unsigned int offset;
33 	unsigned int shift;
34 	unsigned int mask;
35 
36 	const char * const *funcs;
37 	unsigned int num_funcs;
38 };
39 
40 struct tegra_xusb_lane {
41 	const struct tegra_xusb_lane_soc *soc;
42 	struct tegra_xusb_pad *pad;
43 	struct device_node *np;
44 	struct list_head list;
45 	unsigned int function;
46 	unsigned int index;
47 };
48 
49 int tegra_xusb_lane_parse_dt(struct tegra_xusb_lane *lane,
50 			     struct device_node *np);
51 
52 struct tegra_xusb_usb3_lane {
53 	struct tegra_xusb_lane base;
54 };
55 
56 static inline struct tegra_xusb_usb3_lane *
57 to_usb3_lane(struct tegra_xusb_lane *lane)
58 {
59 	return container_of(lane, struct tegra_xusb_usb3_lane, base);
60 }
61 
62 struct tegra_xusb_usb2_lane {
63 	struct tegra_xusb_lane base;
64 
65 	u32 hs_curr_level_offset;
66 	bool powered_on;
67 };
68 
69 static inline struct tegra_xusb_usb2_lane *
70 to_usb2_lane(struct tegra_xusb_lane *lane)
71 {
72 	return container_of(lane, struct tegra_xusb_usb2_lane, base);
73 }
74 
75 struct tegra_xusb_ulpi_lane {
76 	struct tegra_xusb_lane base;
77 };
78 
79 static inline struct tegra_xusb_ulpi_lane *
80 to_ulpi_lane(struct tegra_xusb_lane *lane)
81 {
82 	return container_of(lane, struct tegra_xusb_ulpi_lane, base);
83 }
84 
85 struct tegra_xusb_hsic_lane {
86 	struct tegra_xusb_lane base;
87 
88 	u32 strobe_trim;
89 	u32 rx_strobe_trim;
90 	u32 rx_data_trim;
91 	u32 tx_rtune_n;
92 	u32 tx_rtune_p;
93 	u32 tx_rslew_n;
94 	u32 tx_rslew_p;
95 	bool auto_term;
96 };
97 
98 static inline struct tegra_xusb_hsic_lane *
99 to_hsic_lane(struct tegra_xusb_lane *lane)
100 {
101 	return container_of(lane, struct tegra_xusb_hsic_lane, base);
102 }
103 
104 struct tegra_xusb_pcie_lane {
105 	struct tegra_xusb_lane base;
106 };
107 
108 static inline struct tegra_xusb_pcie_lane *
109 to_pcie_lane(struct tegra_xusb_lane *lane)
110 {
111 	return container_of(lane, struct tegra_xusb_pcie_lane, base);
112 }
113 
114 struct tegra_xusb_sata_lane {
115 	struct tegra_xusb_lane base;
116 };
117 
118 static inline struct tegra_xusb_sata_lane *
119 to_sata_lane(struct tegra_xusb_lane *lane)
120 {
121 	return container_of(lane, struct tegra_xusb_sata_lane, base);
122 }
123 
124 struct tegra_xusb_lane_ops {
125 	struct tegra_xusb_lane *(*probe)(struct tegra_xusb_pad *pad,
126 					 struct device_node *np,
127 					 unsigned int index);
128 	void (*remove)(struct tegra_xusb_lane *lane);
129 };
130 
131 bool tegra_xusb_lane_check(struct tegra_xusb_lane *lane, const char *function);
132 
133 /*
134  * pads
135  */
136 struct tegra_xusb_pad_soc;
137 struct tegra_xusb_padctl;
138 
139 struct tegra_xusb_pad_ops {
140 	struct tegra_xusb_pad *(*probe)(struct tegra_xusb_padctl *padctl,
141 					const struct tegra_xusb_pad_soc *soc,
142 					struct device_node *np);
143 	void (*remove)(struct tegra_xusb_pad *pad);
144 };
145 
146 struct tegra_xusb_pad_soc {
147 	const char *name;
148 
149 	const struct tegra_xusb_lane_soc *lanes;
150 	unsigned int num_lanes;
151 
152 	const struct tegra_xusb_pad_ops *ops;
153 };
154 
155 struct tegra_xusb_pad {
156 	const struct tegra_xusb_pad_soc *soc;
157 	struct tegra_xusb_padctl *padctl;
158 	struct phy_provider *provider;
159 	struct phy **lanes;
160 	struct device dev;
161 
162 	const struct tegra_xusb_lane_ops *ops;
163 
164 	struct list_head list;
165 };
166 
167 static inline struct tegra_xusb_pad *to_tegra_xusb_pad(struct device *dev)
168 {
169 	return container_of(dev, struct tegra_xusb_pad, dev);
170 }
171 
172 int tegra_xusb_pad_init(struct tegra_xusb_pad *pad,
173 			struct tegra_xusb_padctl *padctl,
174 			struct device_node *np);
175 int tegra_xusb_pad_register(struct tegra_xusb_pad *pad,
176 			    const struct phy_ops *ops);
177 void tegra_xusb_pad_unregister(struct tegra_xusb_pad *pad);
178 
179 struct tegra_xusb_usb3_pad {
180 	struct tegra_xusb_pad base;
181 
182 	unsigned int enable;
183 	struct mutex lock;
184 };
185 
186 static inline struct tegra_xusb_usb3_pad *
187 to_usb3_pad(struct tegra_xusb_pad *pad)
188 {
189 	return container_of(pad, struct tegra_xusb_usb3_pad, base);
190 }
191 
192 struct tegra_xusb_usb2_pad {
193 	struct tegra_xusb_pad base;
194 
195 	struct clk *clk;
196 	unsigned int enable;
197 	struct mutex lock;
198 };
199 
200 static inline struct tegra_xusb_usb2_pad *
201 to_usb2_pad(struct tegra_xusb_pad *pad)
202 {
203 	return container_of(pad, struct tegra_xusb_usb2_pad, base);
204 }
205 
206 struct tegra_xusb_ulpi_pad {
207 	struct tegra_xusb_pad base;
208 };
209 
210 static inline struct tegra_xusb_ulpi_pad *
211 to_ulpi_pad(struct tegra_xusb_pad *pad)
212 {
213 	return container_of(pad, struct tegra_xusb_ulpi_pad, base);
214 }
215 
216 struct tegra_xusb_hsic_pad {
217 	struct tegra_xusb_pad base;
218 
219 	struct regulator *supply;
220 	struct clk *clk;
221 };
222 
223 static inline struct tegra_xusb_hsic_pad *
224 to_hsic_pad(struct tegra_xusb_pad *pad)
225 {
226 	return container_of(pad, struct tegra_xusb_hsic_pad, base);
227 }
228 
229 struct tegra_xusb_pcie_pad {
230 	struct tegra_xusb_pad base;
231 
232 	struct reset_control *rst;
233 	struct clk *pll;
234 
235 	unsigned int enable;
236 };
237 
238 static inline struct tegra_xusb_pcie_pad *
239 to_pcie_pad(struct tegra_xusb_pad *pad)
240 {
241 	return container_of(pad, struct tegra_xusb_pcie_pad, base);
242 }
243 
244 struct tegra_xusb_sata_pad {
245 	struct tegra_xusb_pad base;
246 
247 	struct reset_control *rst;
248 	struct clk *pll;
249 
250 	unsigned int enable;
251 };
252 
253 static inline struct tegra_xusb_sata_pad *
254 to_sata_pad(struct tegra_xusb_pad *pad)
255 {
256 	return container_of(pad, struct tegra_xusb_sata_pad, base);
257 }
258 
259 /*
260  * ports
261  */
262 struct tegra_xusb_port_ops;
263 
264 struct tegra_xusb_port {
265 	struct tegra_xusb_padctl *padctl;
266 	struct tegra_xusb_lane *lane;
267 	unsigned int index;
268 
269 	struct list_head list;
270 	struct device dev;
271 
272 	struct usb_role_switch *usb_role_sw;
273 	struct work_struct usb_phy_work;
274 	struct usb_phy usb_phy;
275 
276 	const struct tegra_xusb_port_ops *ops;
277 };
278 
279 static inline struct tegra_xusb_port *to_tegra_xusb_port(struct device *dev)
280 {
281 	return container_of(dev, struct tegra_xusb_port, dev);
282 }
283 
284 struct tegra_xusb_lane_map {
285 	unsigned int port;
286 	const char *type;
287 	unsigned int index;
288 	const char *func;
289 };
290 
291 struct tegra_xusb_lane *
292 tegra_xusb_port_find_lane(struct tegra_xusb_port *port,
293 			  const struct tegra_xusb_lane_map *map,
294 			  const char *function);
295 
296 struct tegra_xusb_port *
297 tegra_xusb_find_port(struct tegra_xusb_padctl *padctl, const char *type,
298 		     unsigned int index);
299 
300 struct tegra_xusb_usb2_port {
301 	struct tegra_xusb_port base;
302 
303 	struct regulator *supply;
304 	enum usb_dr_mode mode;
305 	bool internal;
306 	int usb3_port_fake;
307 };
308 
309 static inline struct tegra_xusb_usb2_port *
310 to_usb2_port(struct tegra_xusb_port *port)
311 {
312 	return container_of(port, struct tegra_xusb_usb2_port, base);
313 }
314 
315 struct tegra_xusb_usb2_port *
316 tegra_xusb_find_usb2_port(struct tegra_xusb_padctl *padctl,
317 			  unsigned int index);
318 void tegra_xusb_usb2_port_release(struct tegra_xusb_port *port);
319 void tegra_xusb_usb2_port_remove(struct tegra_xusb_port *port);
320 
321 struct tegra_xusb_ulpi_port {
322 	struct tegra_xusb_port base;
323 
324 	struct regulator *supply;
325 	bool internal;
326 };
327 
328 static inline struct tegra_xusb_ulpi_port *
329 to_ulpi_port(struct tegra_xusb_port *port)
330 {
331 	return container_of(port, struct tegra_xusb_ulpi_port, base);
332 }
333 
334 void tegra_xusb_ulpi_port_release(struct tegra_xusb_port *port);
335 
336 struct tegra_xusb_hsic_port {
337 	struct tegra_xusb_port base;
338 };
339 
340 static inline struct tegra_xusb_hsic_port *
341 to_hsic_port(struct tegra_xusb_port *port)
342 {
343 	return container_of(port, struct tegra_xusb_hsic_port, base);
344 }
345 
346 void tegra_xusb_hsic_port_release(struct tegra_xusb_port *port);
347 
348 struct tegra_xusb_usb3_port {
349 	struct tegra_xusb_port base;
350 	struct regulator *supply;
351 	bool context_saved;
352 	unsigned int port;
353 	bool internal;
354 	bool disable_gen2;
355 
356 	u32 tap1;
357 	u32 amp;
358 	u32 ctle_z;
359 	u32 ctle_g;
360 };
361 
362 static inline struct tegra_xusb_usb3_port *
363 to_usb3_port(struct tegra_xusb_port *port)
364 {
365 	return container_of(port, struct tegra_xusb_usb3_port, base);
366 }
367 
368 struct tegra_xusb_usb3_port *
369 tegra_xusb_find_usb3_port(struct tegra_xusb_padctl *padctl,
370 			  unsigned int index);
371 void tegra_xusb_usb3_port_release(struct tegra_xusb_port *port);
372 void tegra_xusb_usb3_port_remove(struct tegra_xusb_port *port);
373 
374 struct tegra_xusb_port_ops {
375 	void (*release)(struct tegra_xusb_port *port);
376 	void (*remove)(struct tegra_xusb_port *port);
377 	int (*enable)(struct tegra_xusb_port *port);
378 	void (*disable)(struct tegra_xusb_port *port);
379 	struct tegra_xusb_lane *(*map)(struct tegra_xusb_port *port);
380 };
381 
382 /*
383  * pad controller
384  */
385 struct tegra_xusb_padctl_soc;
386 
387 struct tegra_xusb_padctl_ops {
388 	struct tegra_xusb_padctl *
389 		(*probe)(struct device *dev,
390 			 const struct tegra_xusb_padctl_soc *soc);
391 	void (*remove)(struct tegra_xusb_padctl *padctl);
392 
393 	int (*usb3_save_context)(struct tegra_xusb_padctl *padctl,
394 				 unsigned int index);
395 	int (*hsic_set_idle)(struct tegra_xusb_padctl *padctl,
396 			     unsigned int index, bool idle);
397 	int (*usb3_set_lfps_detect)(struct tegra_xusb_padctl *padctl,
398 				    unsigned int index, bool enable);
399 	int (*vbus_override)(struct tegra_xusb_padctl *padctl, bool set);
400 	int (*utmi_port_reset)(struct phy *phy);
401 };
402 
403 struct tegra_xusb_padctl_soc {
404 	const struct tegra_xusb_pad_soc * const *pads;
405 	unsigned int num_pads;
406 
407 	struct {
408 		struct {
409 			const struct tegra_xusb_port_ops *ops;
410 			unsigned int count;
411 		} usb2, ulpi, hsic, usb3;
412 	} ports;
413 
414 	const struct tegra_xusb_padctl_ops *ops;
415 
416 	const char * const *supply_names;
417 	unsigned int num_supplies;
418 	bool supports_gen2;
419 	bool need_fake_usb3_port;
420 };
421 
422 struct tegra_xusb_padctl {
423 	struct device *dev;
424 	void __iomem *regs;
425 	struct mutex lock;
426 	struct reset_control *rst;
427 
428 	const struct tegra_xusb_padctl_soc *soc;
429 
430 	struct tegra_xusb_pad *pcie;
431 	struct tegra_xusb_pad *sata;
432 	struct tegra_xusb_pad *ulpi;
433 	struct tegra_xusb_pad *usb2;
434 	struct tegra_xusb_pad *hsic;
435 
436 	struct list_head ports;
437 	struct list_head lanes;
438 	struct list_head pads;
439 
440 	unsigned int enable;
441 
442 	struct clk *clk;
443 
444 	struct regulator_bulk_data *supplies;
445 };
446 
447 static inline void padctl_writel(struct tegra_xusb_padctl *padctl, u32 value,
448 				 unsigned long offset)
449 {
450 	dev_dbg(padctl->dev, "%08lx < %08x\n", offset, value);
451 	writel(value, padctl->regs + offset);
452 }
453 
454 static inline u32 padctl_readl(struct tegra_xusb_padctl *padctl,
455 			       unsigned long offset)
456 {
457 	u32 value = readl(padctl->regs + offset);
458 	dev_dbg(padctl->dev, "%08lx > %08x\n", offset, value);
459 	return value;
460 }
461 
462 struct tegra_xusb_lane *tegra_xusb_find_lane(struct tegra_xusb_padctl *padctl,
463 					     const char *name,
464 					     unsigned int index);
465 
466 #if defined(CONFIG_ARCH_TEGRA_124_SOC) || defined(CONFIG_ARCH_TEGRA_132_SOC)
467 extern const struct tegra_xusb_padctl_soc tegra124_xusb_padctl_soc;
468 #endif
469 #if defined(CONFIG_ARCH_TEGRA_210_SOC)
470 extern const struct tegra_xusb_padctl_soc tegra210_xusb_padctl_soc;
471 #endif
472 #if defined(CONFIG_ARCH_TEGRA_186_SOC)
473 extern const struct tegra_xusb_padctl_soc tegra186_xusb_padctl_soc;
474 #endif
475 #if defined(CONFIG_ARCH_TEGRA_194_SOC)
476 extern const struct tegra_xusb_padctl_soc tegra194_xusb_padctl_soc;
477 #endif
478 
479 #endif /* __PHY_TEGRA_XUSB_H */
480