1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Copyright (c) 2014-2020, NVIDIA CORPORATION. All rights reserved. 4 * Copyright (c) 2015, Google Inc. 5 */ 6 7 #ifndef __PHY_TEGRA_XUSB_H 8 #define __PHY_TEGRA_XUSB_H 9 10 #include <linux/io.h> 11 #include <linux/mutex.h> 12 #include <linux/workqueue.h> 13 14 #include <linux/usb/ch9.h> 15 #include <linux/usb/otg.h> 16 #include <linux/usb/role.h> 17 18 /* legacy entry points for backwards-compatibility */ 19 int tegra_xusb_padctl_legacy_probe(struct platform_device *pdev); 20 int tegra_xusb_padctl_legacy_remove(struct platform_device *pdev); 21 22 struct phy; 23 struct phy_provider; 24 struct platform_device; 25 struct regulator; 26 27 /* 28 * lanes 29 */ 30 struct tegra_xusb_lane_soc { 31 const char *name; 32 33 unsigned int offset; 34 unsigned int shift; 35 unsigned int mask; 36 37 const char * const *funcs; 38 unsigned int num_funcs; 39 40 struct { 41 unsigned int misc_ctl2; 42 } regs; 43 }; 44 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; 51 unsigned int index; 52 }; 53 54 int tegra_xusb_lane_parse_dt(struct tegra_xusb_lane *lane, 55 struct device_node *np); 56 57 struct tegra_xusb_usb3_lane { 58 struct tegra_xusb_lane base; 59 }; 60 61 static inline struct tegra_xusb_usb3_lane * 62 to_usb3_lane(struct tegra_xusb_lane *lane) 63 { 64 return container_of(lane, struct tegra_xusb_usb3_lane, base); 65 } 66 67 struct tegra_xusb_usb2_lane { 68 struct tegra_xusb_lane base; 69 70 u32 hs_curr_level_offset; 71 bool powered_on; 72 }; 73 74 static inline struct tegra_xusb_usb2_lane * 75 to_usb2_lane(struct tegra_xusb_lane *lane) 76 { 77 return container_of(lane, struct tegra_xusb_usb2_lane, base); 78 } 79 80 struct tegra_xusb_ulpi_lane { 81 struct tegra_xusb_lane base; 82 }; 83 84 static inline struct tegra_xusb_ulpi_lane * 85 to_ulpi_lane(struct tegra_xusb_lane *lane) 86 { 87 return container_of(lane, struct tegra_xusb_ulpi_lane, base); 88 } 89 90 struct tegra_xusb_hsic_lane { 91 struct tegra_xusb_lane base; 92 93 u32 strobe_trim; 94 u32 rx_strobe_trim; 95 u32 rx_data_trim; 96 u32 tx_rtune_n; 97 u32 tx_rtune_p; 98 u32 tx_rslew_n; 99 u32 tx_rslew_p; 100 bool auto_term; 101 }; 102 103 static inline struct tegra_xusb_hsic_lane * 104 to_hsic_lane(struct tegra_xusb_lane *lane) 105 { 106 return container_of(lane, struct tegra_xusb_hsic_lane, base); 107 } 108 109 struct tegra_xusb_pcie_lane { 110 struct tegra_xusb_lane base; 111 }; 112 113 static inline struct tegra_xusb_pcie_lane * 114 to_pcie_lane(struct tegra_xusb_lane *lane) 115 { 116 return container_of(lane, struct tegra_xusb_pcie_lane, base); 117 } 118 119 struct tegra_xusb_sata_lane { 120 struct tegra_xusb_lane base; 121 }; 122 123 static inline struct tegra_xusb_sata_lane * 124 to_sata_lane(struct tegra_xusb_lane *lane) 125 { 126 return container_of(lane, struct tegra_xusb_sata_lane, base); 127 } 128 129 struct tegra_xusb_lane_ops { 130 struct tegra_xusb_lane *(*probe)(struct tegra_xusb_pad *pad, 131 struct device_node *np, 132 unsigned int index); 133 void (*remove)(struct tegra_xusb_lane *lane); 134 void (*iddq_enable)(struct tegra_xusb_lane *lane); 135 void (*iddq_disable)(struct tegra_xusb_lane *lane); 136 int (*enable_phy_sleepwalk)(struct tegra_xusb_lane *lane, enum usb_device_speed speed); 137 int (*disable_phy_sleepwalk)(struct tegra_xusb_lane *lane); 138 int (*enable_phy_wake)(struct tegra_xusb_lane *lane); 139 int (*disable_phy_wake)(struct tegra_xusb_lane *lane); 140 bool (*remote_wake_detected)(struct tegra_xusb_lane *lane); 141 }; 142 143 bool tegra_xusb_lane_check(struct tegra_xusb_lane *lane, const char *function); 144 145 /* 146 * pads 147 */ 148 struct tegra_xusb_pad_soc; 149 struct tegra_xusb_padctl; 150 151 struct tegra_xusb_pad_ops { 152 struct tegra_xusb_pad *(*probe)(struct tegra_xusb_padctl *padctl, 153 const struct tegra_xusb_pad_soc *soc, 154 struct device_node *np); 155 void (*remove)(struct tegra_xusb_pad *pad); 156 }; 157 158 struct tegra_xusb_pad_soc { 159 const char *name; 160 161 const struct tegra_xusb_lane_soc *lanes; 162 unsigned int num_lanes; 163 164 const struct tegra_xusb_pad_ops *ops; 165 }; 166 167 struct tegra_xusb_pad { 168 const struct tegra_xusb_pad_soc *soc; 169 struct tegra_xusb_padctl *padctl; 170 struct phy_provider *provider; 171 struct phy **lanes; 172 struct device dev; 173 174 const struct tegra_xusb_lane_ops *ops; 175 176 struct list_head list; 177 }; 178 179 static inline struct tegra_xusb_pad *to_tegra_xusb_pad(struct device *dev) 180 { 181 return container_of(dev, struct tegra_xusb_pad, dev); 182 } 183 184 int tegra_xusb_pad_init(struct tegra_xusb_pad *pad, 185 struct tegra_xusb_padctl *padctl, 186 struct device_node *np); 187 int tegra_xusb_pad_register(struct tegra_xusb_pad *pad, 188 const struct phy_ops *ops); 189 void tegra_xusb_pad_unregister(struct tegra_xusb_pad *pad); 190 191 struct tegra_xusb_usb3_pad { 192 struct tegra_xusb_pad base; 193 194 unsigned int enable; 195 struct mutex lock; 196 }; 197 198 static inline struct tegra_xusb_usb3_pad * 199 to_usb3_pad(struct tegra_xusb_pad *pad) 200 { 201 return container_of(pad, struct tegra_xusb_usb3_pad, base); 202 } 203 204 struct tegra_xusb_usb2_pad { 205 struct tegra_xusb_pad base; 206 207 struct clk *clk; 208 unsigned int enable; 209 struct mutex lock; 210 }; 211 212 static inline struct tegra_xusb_usb2_pad * 213 to_usb2_pad(struct tegra_xusb_pad *pad) 214 { 215 return container_of(pad, struct tegra_xusb_usb2_pad, base); 216 } 217 218 struct tegra_xusb_ulpi_pad { 219 struct tegra_xusb_pad base; 220 }; 221 222 static inline struct tegra_xusb_ulpi_pad * 223 to_ulpi_pad(struct tegra_xusb_pad *pad) 224 { 225 return container_of(pad, struct tegra_xusb_ulpi_pad, base); 226 } 227 228 struct tegra_xusb_hsic_pad { 229 struct tegra_xusb_pad base; 230 231 struct regulator *supply; 232 struct clk *clk; 233 }; 234 235 static inline struct tegra_xusb_hsic_pad * 236 to_hsic_pad(struct tegra_xusb_pad *pad) 237 { 238 return container_of(pad, struct tegra_xusb_hsic_pad, base); 239 } 240 241 struct tegra_xusb_pcie_pad { 242 struct tegra_xusb_pad base; 243 244 struct reset_control *rst; 245 struct clk *pll; 246 247 bool enable; 248 }; 249 250 static inline struct tegra_xusb_pcie_pad * 251 to_pcie_pad(struct tegra_xusb_pad *pad) 252 { 253 return container_of(pad, struct tegra_xusb_pcie_pad, base); 254 } 255 256 struct tegra_xusb_sata_pad { 257 struct tegra_xusb_pad base; 258 259 struct reset_control *rst; 260 struct clk *pll; 261 262 bool enable; 263 }; 264 265 static inline struct tegra_xusb_sata_pad * 266 to_sata_pad(struct tegra_xusb_pad *pad) 267 { 268 return container_of(pad, struct tegra_xusb_sata_pad, base); 269 } 270 271 /* 272 * ports 273 */ 274 struct tegra_xusb_port_ops; 275 276 struct tegra_xusb_port { 277 struct tegra_xusb_padctl *padctl; 278 struct tegra_xusb_lane *lane; 279 unsigned int index; 280 281 struct list_head list; 282 struct device dev; 283 284 struct usb_role_switch *usb_role_sw; 285 struct work_struct usb_phy_work; 286 struct usb_phy usb_phy; 287 288 const struct tegra_xusb_port_ops *ops; 289 }; 290 291 static inline struct tegra_xusb_port *to_tegra_xusb_port(struct device *dev) 292 { 293 return container_of(dev, struct tegra_xusb_port, dev); 294 } 295 296 struct tegra_xusb_lane_map { 297 unsigned int port; 298 const char *type; 299 unsigned int index; 300 const char *func; 301 }; 302 303 struct tegra_xusb_lane * 304 tegra_xusb_port_find_lane(struct tegra_xusb_port *port, 305 const struct tegra_xusb_lane_map *map, 306 const char *function); 307 308 struct tegra_xusb_port * 309 tegra_xusb_find_port(struct tegra_xusb_padctl *padctl, const char *type, 310 unsigned int index); 311 312 struct tegra_xusb_usb2_port { 313 struct tegra_xusb_port base; 314 315 struct regulator *supply; 316 enum usb_dr_mode mode; 317 bool internal; 318 int usb3_port_fake; 319 }; 320 321 static inline struct tegra_xusb_usb2_port * 322 to_usb2_port(struct tegra_xusb_port *port) 323 { 324 return container_of(port, struct tegra_xusb_usb2_port, base); 325 } 326 327 struct tegra_xusb_usb2_port * 328 tegra_xusb_find_usb2_port(struct tegra_xusb_padctl *padctl, 329 unsigned int index); 330 void tegra_xusb_usb2_port_release(struct tegra_xusb_port *port); 331 void tegra_xusb_usb2_port_remove(struct tegra_xusb_port *port); 332 333 struct tegra_xusb_ulpi_port { 334 struct tegra_xusb_port base; 335 336 struct regulator *supply; 337 bool internal; 338 }; 339 340 static inline struct tegra_xusb_ulpi_port * 341 to_ulpi_port(struct tegra_xusb_port *port) 342 { 343 return container_of(port, struct tegra_xusb_ulpi_port, base); 344 } 345 346 void tegra_xusb_ulpi_port_release(struct tegra_xusb_port *port); 347 348 struct tegra_xusb_hsic_port { 349 struct tegra_xusb_port base; 350 }; 351 352 static inline struct tegra_xusb_hsic_port * 353 to_hsic_port(struct tegra_xusb_port *port) 354 { 355 return container_of(port, struct tegra_xusb_hsic_port, base); 356 } 357 358 void tegra_xusb_hsic_port_release(struct tegra_xusb_port *port); 359 360 struct tegra_xusb_usb3_port { 361 struct tegra_xusb_port base; 362 struct regulator *supply; 363 bool context_saved; 364 unsigned int port; 365 bool internal; 366 bool disable_gen2; 367 368 u32 tap1; 369 u32 amp; 370 u32 ctle_z; 371 u32 ctle_g; 372 }; 373 374 static inline struct tegra_xusb_usb3_port * 375 to_usb3_port(struct tegra_xusb_port *port) 376 { 377 return container_of(port, struct tegra_xusb_usb3_port, base); 378 } 379 380 struct tegra_xusb_usb3_port * 381 tegra_xusb_find_usb3_port(struct tegra_xusb_padctl *padctl, 382 unsigned int index); 383 void tegra_xusb_usb3_port_release(struct tegra_xusb_port *port); 384 void tegra_xusb_usb3_port_remove(struct tegra_xusb_port *port); 385 386 struct tegra_xusb_port_ops { 387 void (*release)(struct tegra_xusb_port *port); 388 void (*remove)(struct tegra_xusb_port *port); 389 int (*enable)(struct tegra_xusb_port *port); 390 void (*disable)(struct tegra_xusb_port *port); 391 struct tegra_xusb_lane *(*map)(struct tegra_xusb_port *port); 392 }; 393 394 /* 395 * pad controller 396 */ 397 struct tegra_xusb_padctl_soc; 398 399 struct tegra_xusb_padctl_ops { 400 struct tegra_xusb_padctl * 401 (*probe)(struct device *dev, 402 const struct tegra_xusb_padctl_soc *soc); 403 void (*remove)(struct tegra_xusb_padctl *padctl); 404 405 int (*suspend_noirq)(struct tegra_xusb_padctl *padctl); 406 int (*resume_noirq)(struct tegra_xusb_padctl *padctl); 407 int (*usb3_save_context)(struct tegra_xusb_padctl *padctl, 408 unsigned int index); 409 int (*hsic_set_idle)(struct tegra_xusb_padctl *padctl, 410 unsigned int index, bool idle); 411 int (*usb3_set_lfps_detect)(struct tegra_xusb_padctl *padctl, 412 unsigned int index, bool enable); 413 int (*vbus_override)(struct tegra_xusb_padctl *padctl, bool set); 414 int (*utmi_port_reset)(struct phy *phy); 415 }; 416 417 struct tegra_xusb_padctl_soc { 418 const struct tegra_xusb_pad_soc * const *pads; 419 unsigned int num_pads; 420 421 struct { 422 struct { 423 const struct tegra_xusb_port_ops *ops; 424 unsigned int count; 425 } usb2, ulpi, hsic, usb3; 426 } ports; 427 428 const struct tegra_xusb_padctl_ops *ops; 429 430 const char * const *supply_names; 431 unsigned int num_supplies; 432 bool supports_gen2; 433 bool need_fake_usb3_port; 434 }; 435 436 struct tegra_xusb_padctl { 437 struct device *dev; 438 void __iomem *regs; 439 struct mutex lock; 440 struct reset_control *rst; 441 442 const struct tegra_xusb_padctl_soc *soc; 443 444 struct tegra_xusb_pad *pcie; 445 struct tegra_xusb_pad *sata; 446 struct tegra_xusb_pad *ulpi; 447 struct tegra_xusb_pad *usb2; 448 struct tegra_xusb_pad *hsic; 449 450 struct list_head ports; 451 struct list_head lanes; 452 struct list_head pads; 453 454 unsigned int enable; 455 456 struct clk *clk; 457 458 struct regulator_bulk_data *supplies; 459 }; 460 461 static inline void padctl_writel(struct tegra_xusb_padctl *padctl, u32 value, 462 unsigned long offset) 463 { 464 dev_dbg(padctl->dev, "%08lx < %08x\n", offset, value); 465 writel(value, padctl->regs + offset); 466 } 467 468 static inline u32 padctl_readl(struct tegra_xusb_padctl *padctl, 469 unsigned long offset) 470 { 471 u32 value = readl(padctl->regs + offset); 472 dev_dbg(padctl->dev, "%08lx > %08x\n", offset, value); 473 return value; 474 } 475 476 struct tegra_xusb_lane *tegra_xusb_find_lane(struct tegra_xusb_padctl *padctl, 477 const char *name, 478 unsigned int index); 479 480 #if defined(CONFIG_ARCH_TEGRA_124_SOC) || defined(CONFIG_ARCH_TEGRA_132_SOC) 481 extern const struct tegra_xusb_padctl_soc tegra124_xusb_padctl_soc; 482 #endif 483 #if defined(CONFIG_ARCH_TEGRA_210_SOC) 484 extern const struct tegra_xusb_padctl_soc tegra210_xusb_padctl_soc; 485 #endif 486 #if defined(CONFIG_ARCH_TEGRA_186_SOC) 487 extern const struct tegra_xusb_padctl_soc tegra186_xusb_padctl_soc; 488 #endif 489 #if defined(CONFIG_ARCH_TEGRA_194_SOC) 490 extern const struct tegra_xusb_padctl_soc tegra194_xusb_padctl_soc; 491 #endif 492 493 #endif /* __PHY_TEGRA_XUSB_H */ 494