xhci-mtk.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2015 MediaTek Inc.
  4. * Author:
  5. * Zhigang.Wei <zhigang.wei@mediatek.com>
  6. * Chunfeng.Yun <chunfeng.yun@mediatek.com>
  7. */
  8. #ifndef _XHCI_MTK_H_
  9. #define _XHCI_MTK_H_
  10. #include "xhci.h"
  11. /**
  12. * To simplify scheduler algorithm, set a upper limit for ESIT,
  13. * if a synchromous ep's ESIT is larger than @XHCI_MTK_MAX_ESIT,
  14. * round down to the limit value, that means allocating more
  15. * bandwidth to it.
  16. */
  17. #define XHCI_MTK_MAX_ESIT 64
  18. /**
  19. * struct mu3h_sch_bw_info: schedule information for bandwidth domain
  20. *
  21. * @bus_bw: array to keep track of bandwidth already used at each uframes
  22. * @bw_ep_list: eps in the bandwidth domain
  23. *
  24. * treat a HS root port as a bandwidth domain, but treat a SS root port as
  25. * two bandwidth domains, one for IN eps and another for OUT eps.
  26. */
  27. struct mu3h_sch_bw_info {
  28. u32 bus_bw[XHCI_MTK_MAX_ESIT];
  29. struct list_head bw_ep_list;
  30. };
  31. /**
  32. * struct mu3h_sch_ep_info: schedule information for endpoint
  33. *
  34. * @esit: unit is 125us, equal to 2 << Interval field in ep-context
  35. * @num_budget_microframes: number of continuous uframes
  36. * (@repeat==1) scheduled within the interval
  37. * @bw_cost_per_microframe: bandwidth cost per microframe
  38. * @endpoint: linked into bandwidth domain which it belongs to
  39. * @ep: address of usb_host_endpoint struct
  40. * @offset: which uframe of the interval that transfer should be
  41. * scheduled first time within the interval
  42. * @repeat: the time gap between two uframes that transfers are
  43. * scheduled within a interval. in the simple algorithm, only
  44. * assign 0 or 1 to it; 0 means using only one uframe in a
  45. * interval, and 1 means using @num_budget_microframes
  46. * continuous uframes
  47. * @pkts: number of packets to be transferred in the scheduled uframes
  48. * @cs_count: number of CS that host will trigger
  49. * @burst_mode: burst mode for scheduling. 0: normal burst mode,
  50. * distribute the bMaxBurst+1 packets for a single burst
  51. * according to @pkts and @repeat, repeate the burst multiple
  52. * times; 1: distribute the (bMaxBurst+1)*(Mult+1) packets
  53. * according to @pkts and @repeat. normal mode is used by
  54. * default
  55. */
  56. struct mu3h_sch_ep_info {
  57. u32 esit;
  58. u32 num_budget_microframes;
  59. u32 bw_cost_per_microframe;
  60. struct list_head endpoint;
  61. void *ep;
  62. /*
  63. * mtk xHCI scheduling information put into reserved DWs
  64. * in ep context
  65. */
  66. u32 offset;
  67. u32 repeat;
  68. u32 pkts;
  69. u32 cs_count;
  70. u32 burst_mode;
  71. };
  72. #define MU3C_U3_PORT_MAX 4
  73. #define MU3C_U2_PORT_MAX 5
  74. /**
  75. * struct mu3c_ippc_regs: MTK ssusb ip port control registers
  76. * @ip_pw_ctr0~3: ip power and clock control registers
  77. * @ip_pw_sts1~2: ip power and clock status registers
  78. * @ip_xhci_cap: ip xHCI capability register
  79. * @u3_ctrl_p[x]: ip usb3 port x control register, only low 4bytes are used
  80. * @u2_ctrl_p[x]: ip usb2 port x control register, only low 4bytes are used
  81. * @u2_phy_pll: usb2 phy pll control register
  82. */
  83. struct mu3c_ippc_regs {
  84. __le32 ip_pw_ctr0;
  85. __le32 ip_pw_ctr1;
  86. __le32 ip_pw_ctr2;
  87. __le32 ip_pw_ctr3;
  88. __le32 ip_pw_sts1;
  89. __le32 ip_pw_sts2;
  90. __le32 reserved0[3];
  91. __le32 ip_xhci_cap;
  92. __le32 reserved1[2];
  93. __le64 u3_ctrl_p[MU3C_U3_PORT_MAX];
  94. __le64 u2_ctrl_p[MU3C_U2_PORT_MAX];
  95. __le32 reserved2;
  96. __le32 u2_phy_pll;
  97. __le32 reserved3[33]; /* 0x80 ~ 0xff */
  98. };
  99. struct xhci_hcd_mtk {
  100. struct device *dev;
  101. struct usb_hcd *hcd;
  102. struct mu3h_sch_bw_info *sch_array;
  103. struct mu3c_ippc_regs __iomem *ippc_regs;
  104. bool has_ippc;
  105. int num_u2_ports;
  106. int num_u3_ports;
  107. int u3p_dis_msk;
  108. struct regulator *vusb33;
  109. struct regulator *vbus;
  110. struct clk *sys_clk; /* sys and mac clock */
  111. struct clk *ref_clk;
  112. struct clk *mcu_clk;
  113. struct clk *dma_clk;
  114. struct regmap *pericfg;
  115. struct phy **phys;
  116. int num_phys;
  117. bool lpm_support;
  118. bool u2_lpm_disable;
  119. /* usb remote wakeup */
  120. bool uwk_en;
  121. struct regmap *uwk;
  122. u32 uwk_reg_base;
  123. u32 uwk_vers;
  124. };
  125. static inline struct xhci_hcd_mtk *hcd_to_mtk(struct usb_hcd *hcd)
  126. {
  127. return dev_get_drvdata(hcd->self.controller);
  128. }
  129. #if IS_ENABLED(CONFIG_USB_XHCI_MTK)
  130. int xhci_mtk_sch_init(struct xhci_hcd_mtk *mtk);
  131. void xhci_mtk_sch_exit(struct xhci_hcd_mtk *mtk);
  132. int xhci_mtk_add_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev,
  133. struct usb_host_endpoint *ep);
  134. void xhci_mtk_drop_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev,
  135. struct usb_host_endpoint *ep);
  136. #else
  137. static inline int xhci_mtk_add_ep_quirk(struct usb_hcd *hcd,
  138. struct usb_device *udev, struct usb_host_endpoint *ep)
  139. {
  140. return 0;
  141. }
  142. static inline void xhci_mtk_drop_ep_quirk(struct usb_hcd *hcd,
  143. struct usb_device *udev, struct usb_host_endpoint *ep)
  144. {
  145. }
  146. #endif
  147. #endif /* _XHCI_MTK_H_ */