1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (c) 2014-2022, NVIDIA CORPORATION. All rights reserved.
4 * Copyright (c) 2015, Google Inc.
7 #ifndef __PHY_TEGRA_XUSB_H
8 #define __PHY_TEGRA_XUSB_H
11 #include <linux/iopoll.h>
12 #include <linux/mutex.h>
13 #include <linux/workqueue.h>
15 #include <linux/usb/ch9.h>
16 #include <linux/usb/otg.h>
17 #include <linux/usb/role.h>
19 /* legacy entry points for backwards-compatibility */
20 int tegra_xusb_padctl_legacy_probe(struct platform_device
*pdev
);
21 int tegra_xusb_padctl_legacy_remove(struct platform_device
*pdev
);
25 struct platform_device
;
31 struct tegra_xusb_lane_soc
{
38 const char * const *funcs
;
39 unsigned int num_funcs
;
42 unsigned int misc_ctl2
;
46 struct tegra_xusb_lane
{
47 const struct tegra_xusb_lane_soc
*soc
;
48 struct tegra_xusb_pad
*pad
;
49 struct device_node
*np
;
50 struct list_head list
;
51 unsigned int function
;
55 int tegra_xusb_lane_parse_dt(struct tegra_xusb_lane
*lane
,
56 struct device_node
*np
);
58 struct tegra_xusb_usb3_lane
{
59 struct tegra_xusb_lane base
;
62 static inline struct tegra_xusb_usb3_lane
*
63 to_usb3_lane(struct tegra_xusb_lane
*lane
)
65 return container_of(lane
, struct tegra_xusb_usb3_lane
, base
);
68 struct tegra_xusb_usb2_lane
{
69 struct tegra_xusb_lane base
;
71 u32 hs_curr_level_offset
;
75 static inline struct tegra_xusb_usb2_lane
*
76 to_usb2_lane(struct tegra_xusb_lane
*lane
)
78 return container_of(lane
, struct tegra_xusb_usb2_lane
, base
);
81 struct tegra_xusb_ulpi_lane
{
82 struct tegra_xusb_lane base
;
85 static inline struct tegra_xusb_ulpi_lane
*
86 to_ulpi_lane(struct tegra_xusb_lane
*lane
)
88 return container_of(lane
, struct tegra_xusb_ulpi_lane
, base
);
91 struct tegra_xusb_hsic_lane
{
92 struct tegra_xusb_lane base
;
104 static inline struct tegra_xusb_hsic_lane
*
105 to_hsic_lane(struct tegra_xusb_lane
*lane
)
107 return container_of(lane
, struct tegra_xusb_hsic_lane
, base
);
110 struct tegra_xusb_pcie_lane
{
111 struct tegra_xusb_lane base
;
114 static inline struct tegra_xusb_pcie_lane
*
115 to_pcie_lane(struct tegra_xusb_lane
*lane
)
117 return container_of(lane
, struct tegra_xusb_pcie_lane
, base
);
120 struct tegra_xusb_sata_lane
{
121 struct tegra_xusb_lane base
;
124 static inline struct tegra_xusb_sata_lane
*
125 to_sata_lane(struct tegra_xusb_lane
*lane
)
127 return container_of(lane
, struct tegra_xusb_sata_lane
, base
);
130 struct tegra_xusb_lane_ops
{
131 struct tegra_xusb_lane
*(*probe
)(struct tegra_xusb_pad
*pad
,
132 struct device_node
*np
,
134 void (*remove
)(struct tegra_xusb_lane
*lane
);
135 void (*iddq_enable
)(struct tegra_xusb_lane
*lane
);
136 void (*iddq_disable
)(struct tegra_xusb_lane
*lane
);
137 int (*enable_phy_sleepwalk
)(struct tegra_xusb_lane
*lane
, enum usb_device_speed speed
);
138 int (*disable_phy_sleepwalk
)(struct tegra_xusb_lane
*lane
);
139 int (*enable_phy_wake
)(struct tegra_xusb_lane
*lane
);
140 int (*disable_phy_wake
)(struct tegra_xusb_lane
*lane
);
141 bool (*remote_wake_detected
)(struct tegra_xusb_lane
*lane
);
144 bool tegra_xusb_lane_check(struct tegra_xusb_lane
*lane
, const char *function
);
149 struct tegra_xusb_pad_soc
;
150 struct tegra_xusb_padctl
;
152 struct tegra_xusb_pad_ops
{
153 struct tegra_xusb_pad
*(*probe
)(struct tegra_xusb_padctl
*padctl
,
154 const struct tegra_xusb_pad_soc
*soc
,
155 struct device_node
*np
);
156 void (*remove
)(struct tegra_xusb_pad
*pad
);
159 struct tegra_xusb_pad_soc
{
162 const struct tegra_xusb_lane_soc
*lanes
;
163 unsigned int num_lanes
;
165 const struct tegra_xusb_pad_ops
*ops
;
168 struct tegra_xusb_pad
{
169 const struct tegra_xusb_pad_soc
*soc
;
170 struct tegra_xusb_padctl
*padctl
;
171 struct phy_provider
*provider
;
175 const struct tegra_xusb_lane_ops
*ops
;
177 struct list_head list
;
180 static inline struct tegra_xusb_pad
*to_tegra_xusb_pad(struct device
*dev
)
182 return container_of(dev
, struct tegra_xusb_pad
, dev
);
185 int tegra_xusb_pad_init(struct tegra_xusb_pad
*pad
,
186 struct tegra_xusb_padctl
*padctl
,
187 struct device_node
*np
);
188 int tegra_xusb_pad_register(struct tegra_xusb_pad
*pad
,
189 const struct phy_ops
*ops
);
190 void tegra_xusb_pad_unregister(struct tegra_xusb_pad
*pad
);
192 struct tegra_xusb_usb3_pad
{
193 struct tegra_xusb_pad base
;
199 static inline struct tegra_xusb_usb3_pad
*
200 to_usb3_pad(struct tegra_xusb_pad
*pad
)
202 return container_of(pad
, struct tegra_xusb_usb3_pad
, base
);
205 struct tegra_xusb_usb2_pad
{
206 struct tegra_xusb_pad base
;
213 static inline struct tegra_xusb_usb2_pad
*
214 to_usb2_pad(struct tegra_xusb_pad
*pad
)
216 return container_of(pad
, struct tegra_xusb_usb2_pad
, base
);
219 struct tegra_xusb_ulpi_pad
{
220 struct tegra_xusb_pad base
;
223 static inline struct tegra_xusb_ulpi_pad
*
224 to_ulpi_pad(struct tegra_xusb_pad
*pad
)
226 return container_of(pad
, struct tegra_xusb_ulpi_pad
, base
);
229 struct tegra_xusb_hsic_pad
{
230 struct tegra_xusb_pad base
;
232 struct regulator
*supply
;
236 static inline struct tegra_xusb_hsic_pad
*
237 to_hsic_pad(struct tegra_xusb_pad
*pad
)
239 return container_of(pad
, struct tegra_xusb_hsic_pad
, base
);
242 struct tegra_xusb_pcie_pad
{
243 struct tegra_xusb_pad base
;
245 struct reset_control
*rst
;
251 static inline struct tegra_xusb_pcie_pad
*
252 to_pcie_pad(struct tegra_xusb_pad
*pad
)
254 return container_of(pad
, struct tegra_xusb_pcie_pad
, base
);
257 struct tegra_xusb_sata_pad
{
258 struct tegra_xusb_pad base
;
260 struct reset_control
*rst
;
266 static inline struct tegra_xusb_sata_pad
*
267 to_sata_pad(struct tegra_xusb_pad
*pad
)
269 return container_of(pad
, struct tegra_xusb_sata_pad
, base
);
275 struct tegra_xusb_port_ops
;
277 struct tegra_xusb_port
{
278 struct tegra_xusb_padctl
*padctl
;
279 struct tegra_xusb_lane
*lane
;
282 struct list_head list
;
285 struct usb_role_switch
*usb_role_sw
;
286 struct work_struct usb_phy_work
;
287 struct usb_phy usb_phy
;
289 const struct tegra_xusb_port_ops
*ops
;
292 static inline struct tegra_xusb_port
*to_tegra_xusb_port(struct device
*dev
)
294 return container_of(dev
, struct tegra_xusb_port
, dev
);
297 struct tegra_xusb_lane_map
{
304 struct tegra_xusb_lane
*
305 tegra_xusb_port_find_lane(struct tegra_xusb_port
*port
,
306 const struct tegra_xusb_lane_map
*map
,
307 const char *function
);
309 struct tegra_xusb_port
*
310 tegra_xusb_find_port(struct tegra_xusb_padctl
*padctl
, const char *type
,
313 struct tegra_xusb_usb2_port
{
314 struct tegra_xusb_port base
;
316 struct regulator
*supply
;
317 enum usb_dr_mode mode
;
322 static inline struct tegra_xusb_usb2_port
*
323 to_usb2_port(struct tegra_xusb_port
*port
)
325 return container_of(port
, struct tegra_xusb_usb2_port
, base
);
328 struct tegra_xusb_usb2_port
*
329 tegra_xusb_find_usb2_port(struct tegra_xusb_padctl
*padctl
,
331 void tegra_xusb_usb2_port_release(struct tegra_xusb_port
*port
);
332 void tegra_xusb_usb2_port_remove(struct tegra_xusb_port
*port
);
334 struct tegra_xusb_ulpi_port
{
335 struct tegra_xusb_port base
;
337 struct regulator
*supply
;
341 static inline struct tegra_xusb_ulpi_port
*
342 to_ulpi_port(struct tegra_xusb_port
*port
)
344 return container_of(port
, struct tegra_xusb_ulpi_port
, base
);
347 void tegra_xusb_ulpi_port_release(struct tegra_xusb_port
*port
);
349 struct tegra_xusb_hsic_port
{
350 struct tegra_xusb_port base
;
353 static inline struct tegra_xusb_hsic_port
*
354 to_hsic_port(struct tegra_xusb_port
*port
)
356 return container_of(port
, struct tegra_xusb_hsic_port
, base
);
359 void tegra_xusb_hsic_port_release(struct tegra_xusb_port
*port
);
361 struct tegra_xusb_usb3_port
{
362 struct tegra_xusb_port base
;
374 static inline struct tegra_xusb_usb3_port
*
375 to_usb3_port(struct tegra_xusb_port
*port
)
377 return container_of(port
, struct tegra_xusb_usb3_port
, base
);
380 struct tegra_xusb_usb3_port
*
381 tegra_xusb_find_usb3_port(struct tegra_xusb_padctl
*padctl
,
383 void tegra_xusb_usb3_port_release(struct tegra_xusb_port
*port
);
385 struct tegra_xusb_port_ops
{
386 void (*release
)(struct tegra_xusb_port
*port
);
387 void (*remove
)(struct tegra_xusb_port
*port
);
388 int (*enable
)(struct tegra_xusb_port
*port
);
389 void (*disable
)(struct tegra_xusb_port
*port
);
390 struct tegra_xusb_lane
*(*map
)(struct tegra_xusb_port
*port
);
396 struct tegra_xusb_padctl_soc
;
398 struct tegra_xusb_padctl_ops
{
399 struct tegra_xusb_padctl
*
400 (*probe
)(struct device
*dev
,
401 const struct tegra_xusb_padctl_soc
*soc
);
402 void (*remove
)(struct tegra_xusb_padctl
*padctl
);
404 int (*suspend_noirq
)(struct tegra_xusb_padctl
*padctl
);
405 int (*resume_noirq
)(struct tegra_xusb_padctl
*padctl
);
406 int (*usb3_save_context
)(struct tegra_xusb_padctl
*padctl
,
408 int (*hsic_set_idle
)(struct tegra_xusb_padctl
*padctl
,
409 unsigned int index
, bool idle
);
410 int (*usb3_set_lfps_detect
)(struct tegra_xusb_padctl
*padctl
,
411 unsigned int index
, bool enable
);
412 int (*vbus_override
)(struct tegra_xusb_padctl
*padctl
, bool set
);
413 int (*utmi_port_reset
)(struct phy
*phy
);
414 void (*utmi_pad_power_on
)(struct phy
*phy
);
415 void (*utmi_pad_power_down
)(struct phy
*phy
);
418 struct tegra_xusb_padctl_soc
{
419 const struct tegra_xusb_pad_soc
* const *pads
;
420 unsigned int num_pads
;
424 const struct tegra_xusb_port_ops
*ops
;
426 } usb2
, ulpi
, hsic
, usb3
;
429 const struct tegra_xusb_padctl_ops
*ops
;
431 const char * const *supply_names
;
432 unsigned int num_supplies
;
434 bool need_fake_usb3_port
;
435 bool poll_trk_completed
;
437 bool supports_lp_cfg_en
;
440 struct tegra_xusb_padctl
{
444 struct reset_control
*rst
;
446 const struct tegra_xusb_padctl_soc
*soc
;
448 struct tegra_xusb_pad
*pcie
;
449 struct tegra_xusb_pad
*sata
;
450 struct tegra_xusb_pad
*ulpi
;
451 struct tegra_xusb_pad
*usb2
;
452 struct tegra_xusb_pad
*hsic
;
454 struct list_head ports
;
455 struct list_head lanes
;
456 struct list_head pads
;
462 struct regulator_bulk_data
*supplies
;
465 static inline void padctl_writel(struct tegra_xusb_padctl
*padctl
, u32 value
,
466 unsigned long offset
)
468 dev_dbg(padctl
->dev
, "%08lx < %08x\n", offset
, value
);
469 writel(value
, padctl
->regs
+ offset
);
472 static inline u32
padctl_readl(struct tegra_xusb_padctl
*padctl
,
473 unsigned long offset
)
475 u32 value
= readl(padctl
->regs
+ offset
);
476 dev_dbg(padctl
->dev
, "%08lx > %08x\n", offset
, value
);
480 static inline u32
padctl_readl_poll(struct tegra_xusb_padctl
*padctl
,
481 unsigned long offset
, u32 val
, u32 mask
,
487 err
= readl_poll_timeout(padctl
->regs
+ offset
, regval
,
488 (regval
& mask
) == val
, 1, us
);
490 dev_err(padctl
->dev
, "%08lx poll timeout > %08x\n", offset
,
497 struct tegra_xusb_lane
*tegra_xusb_find_lane(struct tegra_xusb_padctl
*padctl
,
501 #if defined(CONFIG_ARCH_TEGRA_124_SOC) || defined(CONFIG_ARCH_TEGRA_132_SOC)
502 extern const struct tegra_xusb_padctl_soc tegra124_xusb_padctl_soc
;
504 #if defined(CONFIG_ARCH_TEGRA_210_SOC)
505 extern const struct tegra_xusb_padctl_soc tegra210_xusb_padctl_soc
;
507 #if defined(CONFIG_ARCH_TEGRA_186_SOC)
508 extern const struct tegra_xusb_padctl_soc tegra186_xusb_padctl_soc
;
510 #if defined(CONFIG_ARCH_TEGRA_194_SOC)
511 extern const struct tegra_xusb_padctl_soc tegra194_xusb_padctl_soc
;
513 #if defined(CONFIG_ARCH_TEGRA_234_SOC)
514 extern const struct tegra_xusb_padctl_soc tegra234_xusb_padctl_soc
;
517 #endif /* __PHY_TEGRA_XUSB_H */