core.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Cadence USBSS 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. #include <linux/usb/otg.h>
  12. #include <linux/usb/role.h>
  13. #ifndef __LINUX_CDNS3_CORE_H
  14. #define __LINUX_CDNS3_CORE_H
  15. struct cdns3;
  16. /**
  17. * struct cdns3_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 cdns3_role_driver {
  27. int (*start)(struct cdns3 *cdns);
  28. void (*stop)(struct cdns3 *cdns);
  29. int (*suspend)(struct cdns3 *cdns, bool do_wakeup);
  30. int (*resume)(struct cdns3 *cdns, bool hibernated);
  31. const char *name;
  32. #define CDNS3_ROLE_STATE_INACTIVE 0
  33. #define CDNS3_ROLE_STATE_ACTIVE 1
  34. int state;
  35. };
  36. #define CDNS3_XHCI_RESOURCES_NUM 2
  37. /**
  38. * struct cdns3 - Representation of Cadence USB3 DRD controller.
  39. * @dev: pointer to Cadence device struct
  40. * @xhci_regs: pointer to base of xhci registers
  41. * @xhci_res: the resource for xhci
  42. * @dev_regs: pointer to base of dev registers
  43. * @otg_res: the resource for otg
  44. * @otg_v0_regs: pointer to base of v0 otg registers
  45. * @otg_v1_regs: pointer to base of v1 otg registers
  46. * @otg_regs: pointer to base of otg registers
  47. * @otg_irq: irq number for otg controller
  48. * @dev_irq: irq number for device controller
  49. * @roles: array of supported roles for this controller
  50. * @role: current role
  51. * @host_dev: the child host device pointer for cdns3 core
  52. * @gadget_dev: the child gadget device pointer for cdns3 core
  53. * @usb2_phy: pointer to USB2 PHY
  54. * @usb3_phy: pointer to USB3 PHY
  55. * @mutex: the mutex for concurrent code at driver
  56. * @dr_mode: supported mode of operation it can be only Host, only Device
  57. * or OTG mode that allow to switch between Device and Host mode.
  58. * This field based on firmware setting, kernel configuration
  59. * and hardware configuration.
  60. * @role_sw: pointer to role switch object.
  61. * @role_override: set 1 if role rely on SW.
  62. */
  63. struct cdns3 {
  64. struct device *dev;
  65. void __iomem *xhci_regs;
  66. struct resource xhci_res[CDNS3_XHCI_RESOURCES_NUM];
  67. struct cdns3_usb_regs __iomem *dev_regs;
  68. struct resource otg_res;
  69. struct cdns3_otg_legacy_regs *otg_v0_regs;
  70. struct cdns3_otg_regs *otg_v1_regs;
  71. struct cdns3_otg_common_regs *otg_regs;
  72. #define CDNS3_CONTROLLER_V0 0
  73. #define CDNS3_CONTROLLER_V1 1
  74. u32 version;
  75. int otg_irq;
  76. int dev_irq;
  77. struct cdns3_role_driver *roles[USB_ROLE_DEVICE + 1];
  78. enum usb_role role;
  79. struct platform_device *host_dev;
  80. struct cdns3_device *gadget_dev;
  81. struct phy *usb2_phy;
  82. struct phy *usb3_phy;
  83. /* mutext used in workqueue*/
  84. struct mutex mutex;
  85. enum usb_dr_mode dr_mode;
  86. struct usb_role_switch *role_sw;
  87. int role_override;
  88. };
  89. int cdns3_hw_role_switch(struct cdns3 *cdns);
  90. #endif /* __LINUX_CDNS3_CORE_H */