1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (c) 2014-2015, 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/otg.h>
16 /* legacy entry points for backwards-compatibility */
17 int tegra_xusb_padctl_legacy_probe(struct platform_device
*pdev
);
18 int tegra_xusb_padctl_legacy_remove(struct platform_device
*pdev
);
22 struct platform_device
;
28 struct tegra_xusb_lane_soc
{
35 const char * const *funcs
;
36 unsigned int num_funcs
;
39 struct tegra_xusb_lane
{
40 const struct tegra_xusb_lane_soc
*soc
;
41 struct tegra_xusb_pad
*pad
;
42 struct device_node
*np
;
43 struct list_head list
;
44 unsigned int function
;
48 int tegra_xusb_lane_parse_dt(struct tegra_xusb_lane
*lane
,
49 struct device_node
*np
);
51 struct tegra_xusb_usb3_lane
{
52 struct tegra_xusb_lane base
;
55 static inline struct tegra_xusb_usb3_lane
*
56 to_usb3_lane(struct tegra_xusb_lane
*lane
)
58 return container_of(lane
, struct tegra_xusb_usb3_lane
, base
);
61 struct tegra_xusb_usb2_lane
{
62 struct tegra_xusb_lane base
;
64 u32 hs_curr_level_offset
;
68 static inline struct tegra_xusb_usb2_lane
*
69 to_usb2_lane(struct tegra_xusb_lane
*lane
)
71 return container_of(lane
, struct tegra_xusb_usb2_lane
, base
);
74 struct tegra_xusb_ulpi_lane
{
75 struct tegra_xusb_lane base
;
78 static inline struct tegra_xusb_ulpi_lane
*
79 to_ulpi_lane(struct tegra_xusb_lane
*lane
)
81 return container_of(lane
, struct tegra_xusb_ulpi_lane
, base
);
84 struct tegra_xusb_hsic_lane
{
85 struct tegra_xusb_lane base
;
97 static inline struct tegra_xusb_hsic_lane
*
98 to_hsic_lane(struct tegra_xusb_lane
*lane
)
100 return container_of(lane
, struct tegra_xusb_hsic_lane
, base
);
103 struct tegra_xusb_pcie_lane
{
104 struct tegra_xusb_lane base
;
107 static inline struct tegra_xusb_pcie_lane
*
108 to_pcie_lane(struct tegra_xusb_lane
*lane
)
110 return container_of(lane
, struct tegra_xusb_pcie_lane
, base
);
113 struct tegra_xusb_sata_lane
{
114 struct tegra_xusb_lane base
;
117 static inline struct tegra_xusb_sata_lane
*
118 to_sata_lane(struct tegra_xusb_lane
*lane
)
120 return container_of(lane
, struct tegra_xusb_sata_lane
, base
);
123 struct tegra_xusb_lane_ops
{
124 struct tegra_xusb_lane
*(*probe
)(struct tegra_xusb_pad
*pad
,
125 struct device_node
*np
,
127 void (*remove
)(struct tegra_xusb_lane
*lane
);
133 struct tegra_xusb_pad_soc
;
134 struct tegra_xusb_padctl
;
136 struct tegra_xusb_pad_ops
{
137 struct tegra_xusb_pad
*(*probe
)(struct tegra_xusb_padctl
*padctl
,
138 const struct tegra_xusb_pad_soc
*soc
,
139 struct device_node
*np
);
140 void (*remove
)(struct tegra_xusb_pad
*pad
);
143 struct tegra_xusb_pad_soc
{
146 const struct tegra_xusb_lane_soc
*lanes
;
147 unsigned int num_lanes
;
149 const struct tegra_xusb_pad_ops
*ops
;
152 struct tegra_xusb_pad
{
153 const struct tegra_xusb_pad_soc
*soc
;
154 struct tegra_xusb_padctl
*padctl
;
155 struct phy_provider
*provider
;
159 const struct tegra_xusb_lane_ops
*ops
;
161 struct list_head list
;
164 static inline struct tegra_xusb_pad
*to_tegra_xusb_pad(struct device
*dev
)
166 return container_of(dev
, struct tegra_xusb_pad
, dev
);
169 int tegra_xusb_pad_init(struct tegra_xusb_pad
*pad
,
170 struct tegra_xusb_padctl
*padctl
,
171 struct device_node
*np
);
172 int tegra_xusb_pad_register(struct tegra_xusb_pad
*pad
,
173 const struct phy_ops
*ops
);
174 void tegra_xusb_pad_unregister(struct tegra_xusb_pad
*pad
);
176 struct tegra_xusb_usb3_pad
{
177 struct tegra_xusb_pad base
;
183 static inline struct tegra_xusb_usb3_pad
*
184 to_usb3_pad(struct tegra_xusb_pad
*pad
)
186 return container_of(pad
, struct tegra_xusb_usb3_pad
, base
);
189 struct tegra_xusb_usb2_pad
{
190 struct tegra_xusb_pad base
;
197 static inline struct tegra_xusb_usb2_pad
*
198 to_usb2_pad(struct tegra_xusb_pad
*pad
)
200 return container_of(pad
, struct tegra_xusb_usb2_pad
, base
);
203 struct tegra_xusb_ulpi_pad
{
204 struct tegra_xusb_pad base
;
207 static inline struct tegra_xusb_ulpi_pad
*
208 to_ulpi_pad(struct tegra_xusb_pad
*pad
)
210 return container_of(pad
, struct tegra_xusb_ulpi_pad
, base
);
213 struct tegra_xusb_hsic_pad
{
214 struct tegra_xusb_pad base
;
216 struct regulator
*supply
;
220 static inline struct tegra_xusb_hsic_pad
*
221 to_hsic_pad(struct tegra_xusb_pad
*pad
)
223 return container_of(pad
, struct tegra_xusb_hsic_pad
, base
);
226 struct tegra_xusb_pcie_pad
{
227 struct tegra_xusb_pad base
;
229 struct reset_control
*rst
;
235 static inline struct tegra_xusb_pcie_pad
*
236 to_pcie_pad(struct tegra_xusb_pad
*pad
)
238 return container_of(pad
, struct tegra_xusb_pcie_pad
, base
);
241 struct tegra_xusb_sata_pad
{
242 struct tegra_xusb_pad base
;
244 struct reset_control
*rst
;
250 static inline struct tegra_xusb_sata_pad
*
251 to_sata_pad(struct tegra_xusb_pad
*pad
)
253 return container_of(pad
, struct tegra_xusb_sata_pad
, base
);
259 struct tegra_xusb_port_ops
;
261 struct tegra_xusb_port
{
262 struct tegra_xusb_padctl
*padctl
;
263 struct tegra_xusb_lane
*lane
;
266 struct list_head list
;
269 const struct tegra_xusb_port_ops
*ops
;
272 struct tegra_xusb_lane_map
{
279 struct tegra_xusb_lane
*
280 tegra_xusb_port_find_lane(struct tegra_xusb_port
*port
,
281 const struct tegra_xusb_lane_map
*map
,
282 const char *function
);
284 struct tegra_xusb_port
*
285 tegra_xusb_find_port(struct tegra_xusb_padctl
*padctl
, const char *type
,
288 struct tegra_xusb_usb2_port
{
289 struct tegra_xusb_port base
;
291 struct regulator
*supply
;
292 enum usb_dr_mode mode
;
297 static inline struct tegra_xusb_usb2_port
*
298 to_usb2_port(struct tegra_xusb_port
*port
)
300 return container_of(port
, struct tegra_xusb_usb2_port
, base
);
303 struct tegra_xusb_usb2_port
*
304 tegra_xusb_find_usb2_port(struct tegra_xusb_padctl
*padctl
,
307 struct tegra_xusb_ulpi_port
{
308 struct tegra_xusb_port base
;
310 struct regulator
*supply
;
314 static inline struct tegra_xusb_ulpi_port
*
315 to_ulpi_port(struct tegra_xusb_port
*port
)
317 return container_of(port
, struct tegra_xusb_ulpi_port
, base
);
320 struct tegra_xusb_hsic_port
{
321 struct tegra_xusb_port base
;
324 static inline struct tegra_xusb_hsic_port
*
325 to_hsic_port(struct tegra_xusb_port
*port
)
327 return container_of(port
, struct tegra_xusb_hsic_port
, base
);
330 struct tegra_xusb_usb3_port
{
331 struct tegra_xusb_port base
;
332 struct regulator
*supply
;
343 static inline struct tegra_xusb_usb3_port
*
344 to_usb3_port(struct tegra_xusb_port
*port
)
346 return container_of(port
, struct tegra_xusb_usb3_port
, base
);
349 struct tegra_xusb_usb3_port
*
350 tegra_xusb_find_usb3_port(struct tegra_xusb_padctl
*padctl
,
353 struct tegra_xusb_port_ops
{
354 int (*enable
)(struct tegra_xusb_port
*port
);
355 void (*disable
)(struct tegra_xusb_port
*port
);
356 struct tegra_xusb_lane
*(*map
)(struct tegra_xusb_port
*port
);
362 struct tegra_xusb_padctl_soc
;
364 struct tegra_xusb_padctl_ops
{
365 struct tegra_xusb_padctl
*
366 (*probe
)(struct device
*dev
,
367 const struct tegra_xusb_padctl_soc
*soc
);
368 void (*remove
)(struct tegra_xusb_padctl
*padctl
);
370 int (*usb3_save_context
)(struct tegra_xusb_padctl
*padctl
,
372 int (*hsic_set_idle
)(struct tegra_xusb_padctl
*padctl
,
373 unsigned int index
, bool idle
);
374 int (*usb3_set_lfps_detect
)(struct tegra_xusb_padctl
*padctl
,
375 unsigned int index
, bool enable
);
376 int (*vbus_override
)(struct tegra_xusb_padctl
*padctl
, bool set
);
377 int (*utmi_port_reset
)(struct phy
*phy
);
380 struct tegra_xusb_padctl_soc
{
381 const struct tegra_xusb_pad_soc
* const *pads
;
382 unsigned int num_pads
;
386 const struct tegra_xusb_port_ops
*ops
;
388 } usb2
, ulpi
, hsic
, usb3
;
391 const struct tegra_xusb_padctl_ops
*ops
;
393 const char * const *supply_names
;
394 unsigned int num_supplies
;
395 bool need_fake_usb3_port
;
398 struct tegra_xusb_padctl
{
402 struct reset_control
*rst
;
404 const struct tegra_xusb_padctl_soc
*soc
;
406 struct tegra_xusb_pad
*pcie
;
407 struct tegra_xusb_pad
*sata
;
408 struct tegra_xusb_pad
*ulpi
;
409 struct tegra_xusb_pad
*usb2
;
410 struct tegra_xusb_pad
*hsic
;
412 struct list_head ports
;
413 struct list_head lanes
;
414 struct list_head pads
;
420 struct regulator_bulk_data
*supplies
;
423 static inline void padctl_writel(struct tegra_xusb_padctl
*padctl
, u32 value
,
424 unsigned long offset
)
426 dev_dbg(padctl
->dev
, "%08lx < %08x\n", offset
, value
);
427 writel(value
, padctl
->regs
+ offset
);
430 static inline u32
padctl_readl(struct tegra_xusb_padctl
*padctl
,
431 unsigned long offset
)
433 u32 value
= readl(padctl
->regs
+ offset
);
434 dev_dbg(padctl
->dev
, "%08lx > %08x\n", offset
, value
);
438 struct tegra_xusb_lane
*tegra_xusb_find_lane(struct tegra_xusb_padctl
*padctl
,
442 #if defined(CONFIG_ARCH_TEGRA_124_SOC) || defined(CONFIG_ARCH_TEGRA_132_SOC)
443 extern const struct tegra_xusb_padctl_soc tegra124_xusb_padctl_soc
;
445 #if defined(CONFIG_ARCH_TEGRA_210_SOC)
446 extern const struct tegra_xusb_padctl_soc tegra210_xusb_padctl_soc
;
448 #if defined(CONFIG_ARCH_TEGRA_186_SOC)
449 extern const struct tegra_xusb_padctl_soc tegra186_xusb_padctl_soc
;
452 #endif /* __PHY_TEGRA_XUSB_H */