xusb.h 9.3 KB

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