2 * Copyright (c) 2014-2015, NVIDIA CORPORATION. All rights reserved.
3 * Copyright (c) 2015, Google Inc.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 #ifndef __PHY_TEGRA_XUSB_H
16 #define __PHY_TEGRA_XUSB_H
19 #include <linux/mutex.h>
20 #include <linux/workqueue.h>
22 /* legacy entry points for backwards-compatibility */
23 int tegra_xusb_padctl_legacy_probe(struct platform_device
*pdev
);
24 int tegra_xusb_padctl_legacy_remove(struct platform_device
*pdev
);
28 struct platform_device
;
34 struct tegra_xusb_lane_soc
{
41 const char * const *funcs
;
42 unsigned int num_funcs
;
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_usb2_lane
{
58 struct tegra_xusb_lane base
;
60 u32 hs_curr_level_offset
;
63 static inline struct tegra_xusb_usb2_lane
*
64 to_usb2_lane(struct tegra_xusb_lane
*lane
)
66 return container_of(lane
, struct tegra_xusb_usb2_lane
, base
);
69 struct tegra_xusb_ulpi_lane
{
70 struct tegra_xusb_lane base
;
73 static inline struct tegra_xusb_ulpi_lane
*
74 to_ulpi_lane(struct tegra_xusb_lane
*lane
)
76 return container_of(lane
, struct tegra_xusb_ulpi_lane
, base
);
79 struct tegra_xusb_hsic_lane
{
80 struct tegra_xusb_lane base
;
92 static inline struct tegra_xusb_hsic_lane
*
93 to_hsic_lane(struct tegra_xusb_lane
*lane
)
95 return container_of(lane
, struct tegra_xusb_hsic_lane
, base
);
98 struct tegra_xusb_pcie_lane
{
99 struct tegra_xusb_lane base
;
102 static inline struct tegra_xusb_pcie_lane
*
103 to_pcie_lane(struct tegra_xusb_lane
*lane
)
105 return container_of(lane
, struct tegra_xusb_pcie_lane
, base
);
108 struct tegra_xusb_sata_lane
{
109 struct tegra_xusb_lane base
;
112 static inline struct tegra_xusb_sata_lane
*
113 to_sata_lane(struct tegra_xusb_lane
*lane
)
115 return container_of(lane
, struct tegra_xusb_sata_lane
, base
);
118 struct tegra_xusb_lane_ops
{
119 struct tegra_xusb_lane
*(*probe
)(struct tegra_xusb_pad
*pad
,
120 struct device_node
*np
,
122 void (*remove
)(struct tegra_xusb_lane
*lane
);
128 struct tegra_xusb_pad_soc
;
129 struct tegra_xusb_padctl
;
131 struct tegra_xusb_pad_ops
{
132 struct tegra_xusb_pad
*(*probe
)(struct tegra_xusb_padctl
*padctl
,
133 const struct tegra_xusb_pad_soc
*soc
,
134 struct device_node
*np
);
135 void (*remove
)(struct tegra_xusb_pad
*pad
);
138 struct tegra_xusb_pad_soc
{
141 const struct tegra_xusb_lane_soc
*lanes
;
142 unsigned int num_lanes
;
144 const struct tegra_xusb_pad_ops
*ops
;
147 struct tegra_xusb_pad
{
148 const struct tegra_xusb_pad_soc
*soc
;
149 struct tegra_xusb_padctl
*padctl
;
150 struct phy_provider
*provider
;
154 const struct tegra_xusb_lane_ops
*ops
;
156 struct list_head list
;
159 static inline struct tegra_xusb_pad
*to_tegra_xusb_pad(struct device
*dev
)
161 return container_of(dev
, struct tegra_xusb_pad
, dev
);
164 int tegra_xusb_pad_init(struct tegra_xusb_pad
*pad
,
165 struct tegra_xusb_padctl
*padctl
,
166 struct device_node
*np
);
167 int tegra_xusb_pad_register(struct tegra_xusb_pad
*pad
,
168 const struct phy_ops
*ops
);
169 void tegra_xusb_pad_unregister(struct tegra_xusb_pad
*pad
);
171 struct tegra_xusb_usb2_pad
{
172 struct tegra_xusb_pad base
;
179 static inline struct tegra_xusb_usb2_pad
*
180 to_usb2_pad(struct tegra_xusb_pad
*pad
)
182 return container_of(pad
, struct tegra_xusb_usb2_pad
, base
);
185 struct tegra_xusb_ulpi_pad
{
186 struct tegra_xusb_pad base
;
189 static inline struct tegra_xusb_ulpi_pad
*
190 to_ulpi_pad(struct tegra_xusb_pad
*pad
)
192 return container_of(pad
, struct tegra_xusb_ulpi_pad
, base
);
195 struct tegra_xusb_hsic_pad
{
196 struct tegra_xusb_pad base
;
198 struct regulator
*supply
;
202 static inline struct tegra_xusb_hsic_pad
*
203 to_hsic_pad(struct tegra_xusb_pad
*pad
)
205 return container_of(pad
, struct tegra_xusb_hsic_pad
, base
);
208 struct tegra_xusb_pcie_pad
{
209 struct tegra_xusb_pad base
;
211 struct reset_control
*rst
;
217 static inline struct tegra_xusb_pcie_pad
*
218 to_pcie_pad(struct tegra_xusb_pad
*pad
)
220 return container_of(pad
, struct tegra_xusb_pcie_pad
, base
);
223 struct tegra_xusb_sata_pad
{
224 struct tegra_xusb_pad base
;
226 struct reset_control
*rst
;
232 static inline struct tegra_xusb_sata_pad
*
233 to_sata_pad(struct tegra_xusb_pad
*pad
)
235 return container_of(pad
, struct tegra_xusb_sata_pad
, base
);
241 struct tegra_xusb_port_ops
;
243 struct tegra_xusb_port
{
244 struct tegra_xusb_padctl
*padctl
;
245 struct tegra_xusb_lane
*lane
;
248 struct list_head list
;
251 const struct tegra_xusb_port_ops
*ops
;
254 struct tegra_xusb_lane_map
{
261 struct tegra_xusb_lane
*
262 tegra_xusb_port_find_lane(struct tegra_xusb_port
*port
,
263 const struct tegra_xusb_lane_map
*map
,
264 const char *function
);
266 struct tegra_xusb_port
*
267 tegra_xusb_find_port(struct tegra_xusb_padctl
*padctl
, const char *type
,
270 struct tegra_xusb_usb2_port
{
271 struct tegra_xusb_port base
;
273 struct regulator
*supply
;
277 static inline struct tegra_xusb_usb2_port
*
278 to_usb2_port(struct tegra_xusb_port
*port
)
280 return container_of(port
, struct tegra_xusb_usb2_port
, base
);
283 struct tegra_xusb_usb2_port
*
284 tegra_xusb_find_usb2_port(struct tegra_xusb_padctl
*padctl
,
287 struct tegra_xusb_ulpi_port
{
288 struct tegra_xusb_port base
;
290 struct regulator
*supply
;
294 static inline struct tegra_xusb_ulpi_port
*
295 to_ulpi_port(struct tegra_xusb_port
*port
)
297 return container_of(port
, struct tegra_xusb_ulpi_port
, base
);
300 struct tegra_xusb_hsic_port
{
301 struct tegra_xusb_port base
;
304 static inline struct tegra_xusb_hsic_port
*
305 to_hsic_port(struct tegra_xusb_port
*port
)
307 return container_of(port
, struct tegra_xusb_hsic_port
, base
);
310 struct tegra_xusb_usb3_port
{
311 struct tegra_xusb_port base
;
312 struct regulator
*supply
;
323 static inline struct tegra_xusb_usb3_port
*
324 to_usb3_port(struct tegra_xusb_port
*port
)
326 return container_of(port
, struct tegra_xusb_usb3_port
, base
);
329 struct tegra_xusb_usb3_port
*
330 tegra_xusb_find_usb3_port(struct tegra_xusb_padctl
*padctl
,
333 struct tegra_xusb_port_ops
{
334 int (*enable
)(struct tegra_xusb_port
*port
);
335 void (*disable
)(struct tegra_xusb_port
*port
);
336 struct tegra_xusb_lane
*(*map
)(struct tegra_xusb_port
*port
);
342 struct tegra_xusb_padctl_soc
;
344 struct tegra_xusb_padctl_ops
{
345 struct tegra_xusb_padctl
*
346 (*probe
)(struct device
*dev
,
347 const struct tegra_xusb_padctl_soc
*soc
);
348 void (*remove
)(struct tegra_xusb_padctl
*padctl
);
350 int (*usb3_save_context
)(struct tegra_xusb_padctl
*padctl
,
352 int (*hsic_set_idle
)(struct tegra_xusb_padctl
*padctl
,
353 unsigned int index
, bool idle
);
354 int (*usb3_set_lfps_detect
)(struct tegra_xusb_padctl
*padctl
,
355 unsigned int index
, bool enable
);
358 struct tegra_xusb_padctl_soc
{
359 const struct tegra_xusb_pad_soc
* const *pads
;
360 unsigned int num_pads
;
364 const struct tegra_xusb_port_ops
*ops
;
366 } usb2
, ulpi
, hsic
, usb3
;
369 const struct tegra_xusb_padctl_ops
*ops
;
372 struct tegra_xusb_padctl
{
376 struct reset_control
*rst
;
378 const struct tegra_xusb_padctl_soc
*soc
;
380 struct tegra_xusb_pad
*pcie
;
381 struct tegra_xusb_pad
*sata
;
382 struct tegra_xusb_pad
*ulpi
;
383 struct tegra_xusb_pad
*usb2
;
384 struct tegra_xusb_pad
*hsic
;
386 struct list_head ports
;
387 struct list_head lanes
;
388 struct list_head pads
;
395 static inline void padctl_writel(struct tegra_xusb_padctl
*padctl
, u32 value
,
396 unsigned long offset
)
398 dev_dbg(padctl
->dev
, "%08lx < %08x\n", offset
, value
);
399 writel(value
, padctl
->regs
+ offset
);
402 static inline u32
padctl_readl(struct tegra_xusb_padctl
*padctl
,
403 unsigned long offset
)
405 u32 value
= readl(padctl
->regs
+ offset
);
406 dev_dbg(padctl
->dev
, "%08lx > %08x\n", offset
, value
);
410 struct tegra_xusb_lane
*tegra_xusb_find_lane(struct tegra_xusb_padctl
*padctl
,
414 #if defined(CONFIG_ARCH_TEGRA_124_SOC) || defined(CONFIG_ARCH_TEGRA_132_SOC)
415 extern const struct tegra_xusb_padctl_soc tegra124_xusb_padctl_soc
;
417 #if defined(CONFIG_ARCH_TEGRA_210_SOC)
418 extern const struct tegra_xusb_padctl_soc tegra210_xusb_padctl_soc
;
421 #endif /* __PHY_TEGRA_XUSB_H */