1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (c) 2014-2020, 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/mutex.h>
12 #include <linux/workqueue.h>
14 #include <linux/usb/ch9.h>
15 #include <linux/usb/otg.h>
16 #include <linux/usb/role.h>
18 /* legacy entry points for backwards-compatibility */
19 int tegra_xusb_padctl_legacy_probe(struct platform_device *pdev);
20 int tegra_xusb_padctl_legacy_remove(struct platform_device *pdev);
24 struct platform_device;
30 struct tegra_xusb_lane_soc {
37 const char * const *funcs;
38 unsigned int num_funcs;
41 unsigned int misc_ctl2;
45 struct tegra_xusb_lane {
46 const struct tegra_xusb_lane_soc *soc;
47 struct tegra_xusb_pad *pad;
48 struct device_node *np;
49 struct list_head list;
50 unsigned int function;
54 int tegra_xusb_lane_parse_dt(struct tegra_xusb_lane *lane,
55 struct device_node *np);
57 struct tegra_xusb_usb3_lane {
58 struct tegra_xusb_lane base;
61 static inline struct tegra_xusb_usb3_lane *
62 to_usb3_lane(struct tegra_xusb_lane *lane)
64 return container_of(lane, struct tegra_xusb_usb3_lane, base);
67 struct tegra_xusb_usb2_lane {
68 struct tegra_xusb_lane base;
70 u32 hs_curr_level_offset;
74 static inline struct tegra_xusb_usb2_lane *
75 to_usb2_lane(struct tegra_xusb_lane *lane)
77 return container_of(lane, struct tegra_xusb_usb2_lane, base);
80 struct tegra_xusb_ulpi_lane {
81 struct tegra_xusb_lane base;
84 static inline struct tegra_xusb_ulpi_lane *
85 to_ulpi_lane(struct tegra_xusb_lane *lane)
87 return container_of(lane, struct tegra_xusb_ulpi_lane, base);
90 struct tegra_xusb_hsic_lane {
91 struct tegra_xusb_lane base;
103 static inline struct tegra_xusb_hsic_lane *
104 to_hsic_lane(struct tegra_xusb_lane *lane)
106 return container_of(lane, struct tegra_xusb_hsic_lane, base);
109 struct tegra_xusb_pcie_lane {
110 struct tegra_xusb_lane base;
113 static inline struct tegra_xusb_pcie_lane *
114 to_pcie_lane(struct tegra_xusb_lane *lane)
116 return container_of(lane, struct tegra_xusb_pcie_lane, base);
119 struct tegra_xusb_sata_lane {
120 struct tegra_xusb_lane base;
123 static inline struct tegra_xusb_sata_lane *
124 to_sata_lane(struct tegra_xusb_lane *lane)
126 return container_of(lane, struct tegra_xusb_sata_lane, base);
129 struct tegra_xusb_lane_ops {
130 struct tegra_xusb_lane *(*probe)(struct tegra_xusb_pad *pad,
131 struct device_node *np,
133 void (*remove)(struct tegra_xusb_lane *lane);
134 void (*iddq_enable)(struct tegra_xusb_lane *lane);
135 void (*iddq_disable)(struct tegra_xusb_lane *lane);
136 int (*enable_phy_sleepwalk)(struct tegra_xusb_lane *lane, enum usb_device_speed speed);
137 int (*disable_phy_sleepwalk)(struct tegra_xusb_lane *lane);
138 int (*enable_phy_wake)(struct tegra_xusb_lane *lane);
139 int (*disable_phy_wake)(struct tegra_xusb_lane *lane);
140 bool (*remote_wake_detected)(struct tegra_xusb_lane *lane);
143 bool tegra_xusb_lane_check(struct tegra_xusb_lane *lane, const char *function);
148 struct tegra_xusb_pad_soc;
149 struct tegra_xusb_padctl;
151 struct tegra_xusb_pad_ops {
152 struct tegra_xusb_pad *(*probe)(struct tegra_xusb_padctl *padctl,
153 const struct tegra_xusb_pad_soc *soc,
154 struct device_node *np);
155 void (*remove)(struct tegra_xusb_pad *pad);
158 struct tegra_xusb_pad_soc {
161 const struct tegra_xusb_lane_soc *lanes;
162 unsigned int num_lanes;
164 const struct tegra_xusb_pad_ops *ops;
167 struct tegra_xusb_pad {
168 const struct tegra_xusb_pad_soc *soc;
169 struct tegra_xusb_padctl *padctl;
170 struct phy_provider *provider;
174 const struct tegra_xusb_lane_ops *ops;
176 struct list_head list;
179 static inline struct tegra_xusb_pad *to_tegra_xusb_pad(struct device *dev)
181 return container_of(dev, struct tegra_xusb_pad, dev);
184 int tegra_xusb_pad_init(struct tegra_xusb_pad *pad,
185 struct tegra_xusb_padctl *padctl,
186 struct device_node *np);
187 int tegra_xusb_pad_register(struct tegra_xusb_pad *pad,
188 const struct phy_ops *ops);
189 void tegra_xusb_pad_unregister(struct tegra_xusb_pad *pad);
191 struct tegra_xusb_usb3_pad {
192 struct tegra_xusb_pad base;
198 static inline struct tegra_xusb_usb3_pad *
199 to_usb3_pad(struct tegra_xusb_pad *pad)
201 return container_of(pad, struct tegra_xusb_usb3_pad, base);
204 struct tegra_xusb_usb2_pad {
205 struct tegra_xusb_pad base;
212 static inline struct tegra_xusb_usb2_pad *
213 to_usb2_pad(struct tegra_xusb_pad *pad)
215 return container_of(pad, struct tegra_xusb_usb2_pad, base);
218 struct tegra_xusb_ulpi_pad {
219 struct tegra_xusb_pad base;
222 static inline struct tegra_xusb_ulpi_pad *
223 to_ulpi_pad(struct tegra_xusb_pad *pad)
225 return container_of(pad, struct tegra_xusb_ulpi_pad, base);
228 struct tegra_xusb_hsic_pad {
229 struct tegra_xusb_pad base;
231 struct regulator *supply;
235 static inline struct tegra_xusb_hsic_pad *
236 to_hsic_pad(struct tegra_xusb_pad *pad)
238 return container_of(pad, struct tegra_xusb_hsic_pad, base);
241 struct tegra_xusb_pcie_pad {
242 struct tegra_xusb_pad base;
244 struct reset_control *rst;
250 static inline struct tegra_xusb_pcie_pad *
251 to_pcie_pad(struct tegra_xusb_pad *pad)
253 return container_of(pad, struct tegra_xusb_pcie_pad, base);
256 struct tegra_xusb_sata_pad {
257 struct tegra_xusb_pad base;
259 struct reset_control *rst;
265 static inline struct tegra_xusb_sata_pad *
266 to_sata_pad(struct tegra_xusb_pad *pad)
268 return container_of(pad, struct tegra_xusb_sata_pad, base);
274 struct tegra_xusb_port_ops;
276 struct tegra_xusb_port {
277 struct tegra_xusb_padctl *padctl;
278 struct tegra_xusb_lane *lane;
281 struct list_head list;
284 struct usb_role_switch *usb_role_sw;
285 struct work_struct usb_phy_work;
286 struct usb_phy usb_phy;
288 const struct tegra_xusb_port_ops *ops;
291 static inline struct tegra_xusb_port *to_tegra_xusb_port(struct device *dev)
293 return container_of(dev, struct tegra_xusb_port, dev);
296 struct tegra_xusb_lane_map {
303 struct tegra_xusb_lane *
304 tegra_xusb_port_find_lane(struct tegra_xusb_port *port,
305 const struct tegra_xusb_lane_map *map,
306 const char *function);
308 struct tegra_xusb_port *
309 tegra_xusb_find_port(struct tegra_xusb_padctl *padctl, const char *type,
312 struct tegra_xusb_usb2_port {
313 struct tegra_xusb_port base;
315 struct regulator *supply;
316 enum usb_dr_mode mode;
321 static inline struct tegra_xusb_usb2_port *
322 to_usb2_port(struct tegra_xusb_port *port)
324 return container_of(port, struct tegra_xusb_usb2_port, base);
327 struct tegra_xusb_usb2_port *
328 tegra_xusb_find_usb2_port(struct tegra_xusb_padctl *padctl,
330 void tegra_xusb_usb2_port_release(struct tegra_xusb_port *port);
331 void tegra_xusb_usb2_port_remove(struct tegra_xusb_port *port);
333 struct tegra_xusb_ulpi_port {
334 struct tegra_xusb_port base;
336 struct regulator *supply;
340 static inline struct tegra_xusb_ulpi_port *
341 to_ulpi_port(struct tegra_xusb_port *port)
343 return container_of(port, struct tegra_xusb_ulpi_port, base);
346 void tegra_xusb_ulpi_port_release(struct tegra_xusb_port *port);
348 struct tegra_xusb_hsic_port {
349 struct tegra_xusb_port base;
352 static inline struct tegra_xusb_hsic_port *
353 to_hsic_port(struct tegra_xusb_port *port)
355 return container_of(port, struct tegra_xusb_hsic_port, base);
358 void tegra_xusb_hsic_port_release(struct tegra_xusb_port *port);
360 struct tegra_xusb_usb3_port {
361 struct tegra_xusb_port base;
362 struct regulator *supply;
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);
384 void tegra_xusb_usb3_port_remove(struct tegra_xusb_port *port);
386 struct tegra_xusb_port_ops {
387 void (*release)(struct tegra_xusb_port *port);
388 void (*remove)(struct tegra_xusb_port *port);
389 int (*enable)(struct tegra_xusb_port *port);
390 void (*disable)(struct tegra_xusb_port *port);
391 struct tegra_xusb_lane *(*map)(struct tegra_xusb_port *port);
397 struct tegra_xusb_padctl_soc;
399 struct tegra_xusb_padctl_ops {
400 struct tegra_xusb_padctl *
401 (*probe)(struct device *dev,
402 const struct tegra_xusb_padctl_soc *soc);
403 void (*remove)(struct tegra_xusb_padctl *padctl);
405 int (*suspend_noirq)(struct tegra_xusb_padctl *padctl);
406 int (*resume_noirq)(struct tegra_xusb_padctl *padctl);
407 int (*usb3_save_context)(struct tegra_xusb_padctl *padctl,
409 int (*hsic_set_idle)(struct tegra_xusb_padctl *padctl,
410 unsigned int index, bool idle);
411 int (*usb3_set_lfps_detect)(struct tegra_xusb_padctl *padctl,
412 unsigned int index, bool enable);
413 int (*vbus_override)(struct tegra_xusb_padctl *padctl, bool set);
414 int (*utmi_port_reset)(struct phy *phy);
417 struct tegra_xusb_padctl_soc {
418 const struct tegra_xusb_pad_soc * const *pads;
419 unsigned int num_pads;
423 const struct tegra_xusb_port_ops *ops;
425 } usb2, ulpi, hsic, usb3;
428 const struct tegra_xusb_padctl_ops *ops;
430 const char * const *supply_names;
431 unsigned int num_supplies;
433 bool need_fake_usb3_port;
436 struct tegra_xusb_padctl {
440 struct reset_control *rst;
442 const struct tegra_xusb_padctl_soc *soc;
444 struct tegra_xusb_pad *pcie;
445 struct tegra_xusb_pad *sata;
446 struct tegra_xusb_pad *ulpi;
447 struct tegra_xusb_pad *usb2;
448 struct tegra_xusb_pad *hsic;
450 struct list_head ports;
451 struct list_head lanes;
452 struct list_head pads;
458 struct regulator_bulk_data *supplies;
461 static inline void padctl_writel(struct tegra_xusb_padctl *padctl, u32 value,
462 unsigned long offset)
464 dev_dbg(padctl->dev, "%08lx < %08x\n", offset, value);
465 writel(value, padctl->regs + offset);
468 static inline u32 padctl_readl(struct tegra_xusb_padctl *padctl,
469 unsigned long offset)
471 u32 value = readl(padctl->regs + offset);
472 dev_dbg(padctl->dev, "%08lx > %08x\n", offset, value);
476 struct tegra_xusb_lane *tegra_xusb_find_lane(struct tegra_xusb_padctl *padctl,
480 #if defined(CONFIG_ARCH_TEGRA_124_SOC) || defined(CONFIG_ARCH_TEGRA_132_SOC)
481 extern const struct tegra_xusb_padctl_soc tegra124_xusb_padctl_soc;
483 #if defined(CONFIG_ARCH_TEGRA_210_SOC)
484 extern const struct tegra_xusb_padctl_soc tegra210_xusb_padctl_soc;
486 #if defined(CONFIG_ARCH_TEGRA_186_SOC)
487 extern const struct tegra_xusb_padctl_soc tegra186_xusb_padctl_soc;
489 #if defined(CONFIG_ARCH_TEGRA_194_SOC)
490 extern const struct tegra_xusb_padctl_soc tegra194_xusb_padctl_soc;
493 #endif /* __PHY_TEGRA_XUSB_H */