core.h 3.1 KB

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