blob: b49dbc36efa32e006e9acd9a189e627181756639 [file] [log] [blame]
Thierry Reding53d2a712015-11-11 18:24:21 +01001/*
2 * Copyright (c) 2014-2015, NVIDIA CORPORATION. All rights reserved.
3 * Copyright (c) 2015, Google Inc.
4 *
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.
8 *
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
12 * more details.
13 */
14
15#ifndef __PHY_TEGRA_XUSB_H
16#define __PHY_TEGRA_XUSB_H
17
18#include <linux/io.h>
19#include <linux/mutex.h>
20#include <linux/workqueue.h>
21
22/* legacy entry points for backwards-compatibility */
23int tegra_xusb_padctl_legacy_probe(struct platform_device *pdev);
24int tegra_xusb_padctl_legacy_remove(struct platform_device *pdev);
25
26struct phy;
27struct phy_provider;
28struct platform_device;
29struct regulator;
30
31/*
32 * lanes
33 */
34struct tegra_xusb_lane_soc {
35 const char *name;
36
37 unsigned int offset;
38 unsigned int shift;
39 unsigned int mask;
40
41 const char * const *funcs;
42 unsigned int num_funcs;
43};
44
45struct 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;
51 unsigned int index;
52};
53
54int tegra_xusb_lane_parse_dt(struct tegra_xusb_lane *lane,
55 struct device_node *np);
56
57struct tegra_xusb_usb2_lane {
58 struct tegra_xusb_lane base;
59
60 u32 hs_curr_level_offset;
61};
62
63static inline struct tegra_xusb_usb2_lane *
64to_usb2_lane(struct tegra_xusb_lane *lane)
65{
66 return container_of(lane, struct tegra_xusb_usb2_lane, base);
67}
68
69struct tegra_xusb_ulpi_lane {
70 struct tegra_xusb_lane base;
71};
72
73static inline struct tegra_xusb_ulpi_lane *
74to_ulpi_lane(struct tegra_xusb_lane *lane)
75{
76 return container_of(lane, struct tegra_xusb_ulpi_lane, base);
77}
78
79struct tegra_xusb_hsic_lane {
80 struct tegra_xusb_lane base;
81
82 u32 strobe_trim;
83 u32 rx_strobe_trim;
84 u32 rx_data_trim;
85 u32 tx_rtune_n;
86 u32 tx_rtune_p;
87 u32 tx_rslew_n;
88 u32 tx_rslew_p;
89 bool auto_term;
90};
91
92static inline struct tegra_xusb_hsic_lane *
93to_hsic_lane(struct tegra_xusb_lane *lane)
94{
95 return container_of(lane, struct tegra_xusb_hsic_lane, base);
96}
97
98struct tegra_xusb_pcie_lane {
99 struct tegra_xusb_lane base;
100};
101
102static inline struct tegra_xusb_pcie_lane *
103to_pcie_lane(struct tegra_xusb_lane *lane)
104{
105 return container_of(lane, struct tegra_xusb_pcie_lane, base);
106}
107
108struct tegra_xusb_sata_lane {
109 struct tegra_xusb_lane base;
110};
111
112static inline struct tegra_xusb_sata_lane *
113to_sata_lane(struct tegra_xusb_lane *lane)
114{
115 return container_of(lane, struct tegra_xusb_sata_lane, base);
116}
117
118struct tegra_xusb_lane_ops {
119 struct tegra_xusb_lane *(*probe)(struct tegra_xusb_pad *pad,
120 struct device_node *np,
121 unsigned int index);
122 void (*remove)(struct tegra_xusb_lane *lane);
123};
124
125/*
126 * pads
127 */
128struct tegra_xusb_pad_soc;
129struct tegra_xusb_padctl;
130
131struct 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);
136};
137
138struct tegra_xusb_pad_soc {
139 const char *name;
140
141 const struct tegra_xusb_lane_soc *lanes;
142 unsigned int num_lanes;
143
144 const struct tegra_xusb_pad_ops *ops;
145};
146
147struct tegra_xusb_pad {
148 const struct tegra_xusb_pad_soc *soc;
149 struct tegra_xusb_padctl *padctl;
150 struct phy_provider *provider;
151 struct phy **lanes;
152 struct device dev;
153
154 const struct tegra_xusb_lane_ops *ops;
155
156 struct list_head list;
157};
158
159static inline struct tegra_xusb_pad *to_tegra_xusb_pad(struct device *dev)
160{
161 return container_of(dev, struct tegra_xusb_pad, dev);
162}
163
164int tegra_xusb_pad_init(struct tegra_xusb_pad *pad,
165 struct tegra_xusb_padctl *padctl,
166 struct device_node *np);
167int tegra_xusb_pad_register(struct tegra_xusb_pad *pad,
168 const struct phy_ops *ops);
169void tegra_xusb_pad_unregister(struct tegra_xusb_pad *pad);
170
171struct tegra_xusb_usb2_pad {
172 struct tegra_xusb_pad base;
173
174 struct clk *clk;
175 unsigned int enable;
176 struct mutex lock;
177};
178
179static inline struct tegra_xusb_usb2_pad *
180to_usb2_pad(struct tegra_xusb_pad *pad)
181{
182 return container_of(pad, struct tegra_xusb_usb2_pad, base);
183}
184
185struct tegra_xusb_ulpi_pad {
186 struct tegra_xusb_pad base;
187};
188
189static inline struct tegra_xusb_ulpi_pad *
190to_ulpi_pad(struct tegra_xusb_pad *pad)
191{
192 return container_of(pad, struct tegra_xusb_ulpi_pad, base);
193}
194
195struct tegra_xusb_hsic_pad {
196 struct tegra_xusb_pad base;
197
198 struct regulator *supply;
199 struct clk *clk;
200};
201
202static inline struct tegra_xusb_hsic_pad *
203to_hsic_pad(struct tegra_xusb_pad *pad)
204{
205 return container_of(pad, struct tegra_xusb_hsic_pad, base);
206}
207
208struct tegra_xusb_pcie_pad {
209 struct tegra_xusb_pad base;
210
211 struct reset_control *rst;
212 struct clk *pll;
213
214 unsigned int enable;
215};
216
217static inline struct tegra_xusb_pcie_pad *
218to_pcie_pad(struct tegra_xusb_pad *pad)
219{
220 return container_of(pad, struct tegra_xusb_pcie_pad, base);
221}
222
223struct tegra_xusb_sata_pad {
224 struct tegra_xusb_pad base;
225
226 struct reset_control *rst;
227 struct clk *pll;
228
229 unsigned int enable;
230};
231
232static inline struct tegra_xusb_sata_pad *
233to_sata_pad(struct tegra_xusb_pad *pad)
234{
235 return container_of(pad, struct tegra_xusb_sata_pad, base);
236}
237
238/*
239 * ports
240 */
241struct tegra_xusb_port_ops;
242
243struct tegra_xusb_port {
244 struct tegra_xusb_padctl *padctl;
245 struct tegra_xusb_lane *lane;
246 unsigned int index;
247
248 struct list_head list;
249 struct device dev;
250
251 const struct tegra_xusb_port_ops *ops;
252};
253
254struct tegra_xusb_lane_map {
255 unsigned int port;
256 const char *type;
257 unsigned int index;
258 const char *func;
259};
260
261struct tegra_xusb_lane *
262tegra_xusb_port_find_lane(struct tegra_xusb_port *port,
263 const struct tegra_xusb_lane_map *map,
264 const char *function);
265
266struct tegra_xusb_port *
267tegra_xusb_find_port(struct tegra_xusb_padctl *padctl, const char *type,
268 unsigned int index);
269
270struct tegra_xusb_usb2_port {
271 struct tegra_xusb_port base;
272
273 struct regulator *supply;
274 bool internal;
275};
276
277static inline struct tegra_xusb_usb2_port *
278to_usb2_port(struct tegra_xusb_port *port)
279{
280 return container_of(port, struct tegra_xusb_usb2_port, base);
281}
282
283struct tegra_xusb_usb2_port *
284tegra_xusb_find_usb2_port(struct tegra_xusb_padctl *padctl,
285 unsigned int index);
286
287struct tegra_xusb_ulpi_port {
288 struct tegra_xusb_port base;
289
290 struct regulator *supply;
291 bool internal;
292};
293
294static inline struct tegra_xusb_ulpi_port *
295to_ulpi_port(struct tegra_xusb_port *port)
296{
297 return container_of(port, struct tegra_xusb_ulpi_port, base);
298}
299
300struct tegra_xusb_hsic_port {
301 struct tegra_xusb_port base;
302};
303
304static inline struct tegra_xusb_hsic_port *
305to_hsic_port(struct tegra_xusb_port *port)
306{
307 return container_of(port, struct tegra_xusb_hsic_port, base);
308}
309
310struct tegra_xusb_usb3_port {
311 struct tegra_xusb_port base;
312 struct regulator *supply;
313 bool context_saved;
314 unsigned int port;
315 bool internal;
316
317 u32 tap1;
318 u32 amp;
319 u32 ctle_z;
320 u32 ctle_g;
321};
322
323static inline struct tegra_xusb_usb3_port *
324to_usb3_port(struct tegra_xusb_port *port)
325{
326 return container_of(port, struct tegra_xusb_usb3_port, base);
327}
328
329struct tegra_xusb_usb3_port *
330tegra_xusb_find_usb3_port(struct tegra_xusb_padctl *padctl,
331 unsigned int index);
332
333struct 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);
337};
338
339/*
340 * pad controller
341 */
342struct tegra_xusb_padctl_soc;
343
344struct 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);
349
350 int (*usb3_save_context)(struct tegra_xusb_padctl *padctl,
351 unsigned int index);
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);
356};
357
358struct tegra_xusb_padctl_soc {
359 const struct tegra_xusb_pad_soc * const *pads;
360 unsigned int num_pads;
361
362 struct {
363 struct {
364 const struct tegra_xusb_port_ops *ops;
365 unsigned int count;
366 } usb2, ulpi, hsic, usb3;
367 } ports;
368
369 const struct tegra_xusb_padctl_ops *ops;
370};
371
372struct tegra_xusb_padctl {
373 struct device *dev;
374 void __iomem *regs;
375 struct mutex lock;
376 struct reset_control *rst;
377
378 const struct tegra_xusb_padctl_soc *soc;
379
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;
385
386 struct list_head ports;
387 struct list_head lanes;
388 struct list_head pads;
389
390 unsigned int enable;
391
392 struct clk *clk;
393};
394
395static inline void padctl_writel(struct tegra_xusb_padctl *padctl, u32 value,
396 unsigned long offset)
397{
398 dev_dbg(padctl->dev, "%08lx < %08x\n", offset, value);
399 writel(value, padctl->regs + offset);
400}
401
402static inline u32 padctl_readl(struct tegra_xusb_padctl *padctl,
403 unsigned long offset)
404{
405 u32 value = readl(padctl->regs + offset);
406 dev_dbg(padctl->dev, "%08lx > %08x\n", offset, value);
407 return value;
408}
409
410struct tegra_xusb_lane *tegra_xusb_find_lane(struct tegra_xusb_padctl *padctl,
411 const char *name,
412 unsigned int index);
413
414#if defined(CONFIG_ARCH_TEGRA_124_SOC) || defined(CONFIG_ARCH_TEGRA_132_SOC)
415extern const struct tegra_xusb_padctl_soc tegra124_xusb_padctl_soc;
416#endif
417#if defined(CONFIG_ARCH_TEGRA_210_SOC)
418extern const struct tegra_xusb_padctl_soc tegra210_xusb_padctl_soc;
419#endif
420
421#endif /* __PHY_TEGRA_XUSB_H */