core.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Cadence USBSS and USBSSP DRD Header File.
  4. *
  5. * Copyright (C) 2017-2018 NXP
  6. * Copyright (C) 2018-2019 Cadence.
  7. *
  8. * Authors: Peter Chen <peter.chen@nxp.com>
  9. * Pawel Laszczak <pawell@cadence.com>
  10. */
  11. #ifndef __LINUX_CDNS3_CORE_H
  12. #define __LINUX_CDNS3_CORE_H
  13. #include <linux/usb/otg.h>
  14. #include <linux/usb/role.h>
  15. struct cdns;
  16. /**
  17. * struct cdns_role_driver - host/gadget role driver
  18. * @start: start this role
  19. * @stop: stop this role
  20. * @suspend: suspend callback for this role
  21. * @resume: resume callback for this role
  22. * @irq: irq handler for this role
  23. * @name: role name string (host/gadget)
  24. * @state: current state
  25. */
  26. struct cdns_role_driver {
  27. int (*start)(struct cdns *cdns);
  28. void (*stop)(struct cdns *cdns);
  29. int (*suspend)(struct cdns *cdns, bool do_wakeup);
  30. int (*resume)(struct cdns *cdns, bool hibernated);
  31. const char *name;
  32. #define CDNS_ROLE_STATE_INACTIVE 0
  33. #define CDNS_ROLE_STATE_ACTIVE 1
  34. int state;
  35. };
  36. #define CDNS_XHCI_RESOURCES_NUM 2
  37. struct cdns3_platform_data {
  38. int (*platform_suspend)(struct device *dev,
  39. bool suspend, bool wakeup);
  40. unsigned long quirks;
  41. #define CDNS3_DEFAULT_PM_RUNTIME_ALLOW BIT(0)
  42. #define CDNS3_DRD_SUSPEND_RESIDENCY_ENABLE BIT(1)
  43. };
  44. /**
  45. * struct cdns - Representation of Cadence USB3 DRD controller.
  46. * @dev: pointer to Cadence device struct
  47. * @xhci_regs: pointer to base of xhci registers
  48. * @xhci_res: the resource for xhci
  49. * @dev_regs: pointer to base of dev registers
  50. * @otg_res: the resource for otg
  51. * @otg_v0_regs: pointer to base of v0 otg registers
  52. * @otg_v1_regs: pointer to base of v1 otg registers
  53. * @otg_cdnsp_regs: pointer to base of CDNSP otg registers
  54. * @otg_regs: pointer to base of otg registers
  55. * @otg_irq_regs: pointer to interrupt registers
  56. * @otg_irq: irq number for otg controller
  57. * @dev_irq: irq number for device controller
  58. * @wakeup_irq: irq number for wakeup event, it is optional
  59. * @roles: array of supported roles for this controller
  60. * @role: current role
  61. * @host_dev: the child host device pointer for cdns core
  62. * @gadget_dev: the child gadget device pointer
  63. * @usb2_phy: pointer to USB2 PHY
  64. * @usb3_phy: pointer to USB3 PHY
  65. * @mutex: the mutex for concurrent code at driver
  66. * @dr_mode: supported mode of operation it can be only Host, only Device
  67. * or OTG mode that allow to switch between Device and Host mode.
  68. * This field based on firmware setting, kernel configuration
  69. * and hardware configuration.
  70. * @role_sw: pointer to role switch object.
  71. * @in_lpm: indicate the controller is in low power mode
  72. * @wakeup_pending: wakeup interrupt pending
  73. * @pdata: platform data from glue layer
  74. * @lock: spinlock structure
  75. * @xhci_plat_data: xhci private data structure pointer
  76. * @gadget_init: pointer to gadget initialization function
  77. */
  78. struct cdns {
  79. struct device *dev;
  80. void __iomem *xhci_regs;
  81. struct resource xhci_res[CDNS_XHCI_RESOURCES_NUM];
  82. struct cdns3_usb_regs __iomem *dev_regs;
  83. struct resource otg_res;
  84. struct cdns3_otg_legacy_regs __iomem *otg_v0_regs;
  85. struct cdns3_otg_regs __iomem *otg_v1_regs;
  86. struct cdnsp_otg_regs __iomem *otg_cdnsp_regs;
  87. struct cdns_otg_common_regs __iomem *otg_regs;
  88. struct cdns_otg_irq_regs __iomem *otg_irq_regs;
  89. #define CDNS3_CONTROLLER_V0 0
  90. #define CDNS3_CONTROLLER_V1 1
  91. #define CDNSP_CONTROLLER_V2 2
  92. u32 version;
  93. bool phyrst_a_enable;
  94. int otg_irq;
  95. int dev_irq;
  96. int wakeup_irq;
  97. struct cdns_role_driver *roles[USB_ROLE_DEVICE + 1];
  98. enum usb_role role;
  99. struct platform_device *host_dev;
  100. void *gadget_dev;
  101. struct phy *usb2_phy;
  102. struct phy *usb3_phy;
  103. /* mutext used in workqueue*/
  104. struct mutex mutex;
  105. enum usb_dr_mode dr_mode;
  106. struct usb_role_switch *role_sw;
  107. bool in_lpm;
  108. bool wakeup_pending;
  109. struct cdns3_platform_data *pdata;
  110. spinlock_t lock;
  111. struct xhci_plat_priv *xhci_plat_data;
  112. int (*gadget_init)(struct cdns *cdns);
  113. };
  114. int cdns_hw_role_switch(struct cdns *cdns);
  115. int cdns_init(struct cdns *cdns);
  116. int cdns_remove(struct cdns *cdns);
  117. #ifdef CONFIG_PM_SLEEP
  118. int cdns_resume(struct cdns *cdns);
  119. int cdns_suspend(struct cdns *cdns);
  120. void cdns_set_active(struct cdns *cdns, u8 set_active);
  121. #else /* CONFIG_PM_SLEEP */
  122. static inline int cdns_resume(struct cdns *cdns)
  123. { return 0; }
  124. static inline void cdns_set_active(struct cdns *cdns, u8 set_active) { }
  125. static inline int cdns_suspend(struct cdns *cdns)
  126. { return 0; }
  127. #endif /* CONFIG_PM_SLEEP */
  128. #endif /* __LINUX_CDNS3_CORE_H */