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