treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / phy / tegra / xusb.h
blobda94fcce630752acb3d89f15175fea4b959efc59
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * Copyright (c) 2014-2015, NVIDIA CORPORATION. All rights reserved.
4 * Copyright (c) 2015, Google Inc.
5 */
7 #ifndef __PHY_TEGRA_XUSB_H
8 #define __PHY_TEGRA_XUSB_H
10 #include <linux/io.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);
20 struct phy;
21 struct phy_provider;
22 struct platform_device;
23 struct regulator;
26 * lanes
28 struct tegra_xusb_lane_soc {
29 const char *name;
31 unsigned int offset;
32 unsigned int shift;
33 unsigned int mask;
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;
45 unsigned int index;
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;
65 bool powered_on;
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;
87 u32 strobe_trim;
88 u32 rx_strobe_trim;
89 u32 rx_data_trim;
90 u32 tx_rtune_n;
91 u32 tx_rtune_p;
92 u32 tx_rslew_n;
93 u32 tx_rslew_p;
94 bool auto_term;
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,
126 unsigned int index);
127 void (*remove)(struct tegra_xusb_lane *lane);
131 * pads
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 {
144 const char *name;
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;
156 struct phy **lanes;
157 struct device dev;
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;
179 unsigned int enable;
180 struct mutex lock;
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;
192 struct clk *clk;
193 unsigned int enable;
194 struct mutex lock;
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;
217 struct clk *clk;
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;
230 struct clk *pll;
232 unsigned int enable;
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;
245 struct clk *pll;
247 unsigned int enable;
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);
257 * ports
259 struct tegra_xusb_port_ops;
261 struct tegra_xusb_port {
262 struct tegra_xusb_padctl *padctl;
263 struct tegra_xusb_lane *lane;
264 unsigned int index;
266 struct list_head list;
267 struct device dev;
269 const struct tegra_xusb_port_ops *ops;
272 struct tegra_xusb_lane_map {
273 unsigned int port;
274 const char *type;
275 unsigned int index;
276 const char *func;
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,
286 unsigned int index);
288 struct tegra_xusb_usb2_port {
289 struct tegra_xusb_port base;
291 struct regulator *supply;
292 enum usb_dr_mode mode;
293 bool internal;
294 int usb3_port_fake;
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,
305 unsigned int index);
307 struct tegra_xusb_ulpi_port {
308 struct tegra_xusb_port base;
310 struct regulator *supply;
311 bool internal;
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;
333 bool context_saved;
334 unsigned int port;
335 bool internal;
337 u32 tap1;
338 u32 amp;
339 u32 ctle_z;
340 u32 ctle_g;
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,
351 unsigned int index);
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);
360 * pad controller
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,
371 unsigned int index);
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;
384 struct {
385 struct {
386 const struct tegra_xusb_port_ops *ops;
387 unsigned int count;
388 } usb2, ulpi, hsic, usb3;
389 } ports;
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 {
399 struct device *dev;
400 void __iomem *regs;
401 struct mutex lock;
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;
416 unsigned int enable;
418 struct clk *clk;
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);
435 return value;
438 struct tegra_xusb_lane *tegra_xusb_find_lane(struct tegra_xusb_padctl *padctl,
439 const char *name,
440 unsigned int index);
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;
444 #endif
445 #if defined(CONFIG_ARCH_TEGRA_210_SOC)
446 extern const struct tegra_xusb_padctl_soc tegra210_xusb_padctl_soc;
447 #endif
448 #if defined(CONFIG_ARCH_TEGRA_186_SOC)
449 extern const struct tegra_xusb_padctl_soc tegra186_xusb_padctl_soc;
450 #endif
452 #endif /* __PHY_TEGRA_XUSB_H */