xhci-mtk.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. * @ss_bit_map: used to avoid start split microframes overlay
  20. * @fs_bus_bw: array to keep track of bandwidth already used for FS
  21. * @ep_list: Endpoints using this TT
  22. * @usb_tt: usb TT related
  23. * @tt_port: TT port number
  24. */
  25. struct mu3h_sch_tt {
  26. DECLARE_BITMAP(ss_bit_map, XHCI_MTK_MAX_ESIT);
  27. u32 fs_bus_bw[XHCI_MTK_MAX_ESIT];
  28. struct list_head ep_list;
  29. struct usb_tt *usb_tt;
  30. int tt_port;
  31. };
  32. /**
  33. * struct mu3h_sch_bw_info: schedule information for bandwidth domain
  34. *
  35. * @bus_bw: array to keep track of bandwidth already used at each uframes
  36. * @bw_ep_list: eps in the bandwidth domain
  37. *
  38. * treat a HS root port as a bandwidth domain, but treat a SS root port as
  39. * two bandwidth domains, one for IN eps and another for OUT eps.
  40. */
  41. struct mu3h_sch_bw_info {
  42. u32 bus_bw[XHCI_MTK_MAX_ESIT];
  43. struct list_head bw_ep_list;
  44. };
  45. /**
  46. * struct mu3h_sch_ep_info: schedule information for endpoint
  47. *
  48. * @esit: unit is 125us, equal to 2 << Interval field in ep-context
  49. * @num_budget_microframes: number of continuous uframes
  50. * (@repeat==1) scheduled within the interval
  51. * @bw_cost_per_microframe: bandwidth cost per microframe
  52. * @endpoint: linked into bandwidth domain which it belongs to
  53. * @tt_endpoint: linked into mu3h_sch_tt's list which it belongs to
  54. * @sch_tt: mu3h_sch_tt linked into
  55. * @ep_type: endpoint type
  56. * @maxpkt: max packet size of endpoint
  57. * @ep: address of usb_host_endpoint struct
  58. * @allocated: the bandwidth is aready allocated from bus_bw
  59. * @offset: which uframe of the interval that transfer should be
  60. * scheduled first time within the interval
  61. * @repeat: the time gap between two uframes that transfers are
  62. * scheduled within a interval. in the simple algorithm, only
  63. * assign 0 or 1 to it; 0 means using only one uframe in a
  64. * interval, and 1 means using @num_budget_microframes
  65. * continuous uframes
  66. * @pkts: number of packets to be transferred in the scheduled uframes
  67. * @cs_count: number of CS that host will trigger
  68. * @burst_mode: burst mode for scheduling. 0: normal burst mode,
  69. * distribute the bMaxBurst+1 packets for a single burst
  70. * according to @pkts and @repeat, repeate the burst multiple
  71. * times; 1: distribute the (bMaxBurst+1)*(Mult+1) packets
  72. * according to @pkts and @repeat. normal mode is used by
  73. * default
  74. * @bw_budget_table: table to record bandwidth budget per microframe
  75. */
  76. struct mu3h_sch_ep_info {
  77. u32 esit;
  78. u32 num_budget_microframes;
  79. u32 bw_cost_per_microframe;
  80. struct list_head endpoint;
  81. struct list_head tt_endpoint;
  82. struct mu3h_sch_tt *sch_tt;
  83. u32 ep_type;
  84. u32 maxpkt;
  85. void *ep;
  86. bool allocated;
  87. /*
  88. * mtk xHCI scheduling information put into reserved DWs
  89. * in ep context
  90. */
  91. u32 offset;
  92. u32 repeat;
  93. u32 pkts;
  94. u32 cs_count;
  95. u32 burst_mode;
  96. u32 bw_budget_table[0];
  97. };
  98. #define MU3C_U3_PORT_MAX 4
  99. #define MU3C_U2_PORT_MAX 5
  100. /**
  101. * struct mu3c_ippc_regs: MTK ssusb ip port control registers
  102. * @ip_pw_ctr0~3: ip power and clock control registers
  103. * @ip_pw_sts1~2: ip power and clock status registers
  104. * @ip_xhci_cap: ip xHCI capability register
  105. * @u3_ctrl_p[x]: ip usb3 port x control register, only low 4bytes are used
  106. * @u2_ctrl_p[x]: ip usb2 port x control register, only low 4bytes are used
  107. * @u2_phy_pll: usb2 phy pll control register
  108. */
  109. struct mu3c_ippc_regs {
  110. __le32 ip_pw_ctr0;
  111. __le32 ip_pw_ctr1;
  112. __le32 ip_pw_ctr2;
  113. __le32 ip_pw_ctr3;
  114. __le32 ip_pw_sts1;
  115. __le32 ip_pw_sts2;
  116. __le32 reserved0[3];
  117. __le32 ip_xhci_cap;
  118. __le32 reserved1[2];
  119. __le64 u3_ctrl_p[MU3C_U3_PORT_MAX];
  120. __le64 u2_ctrl_p[MU3C_U2_PORT_MAX];
  121. __le32 reserved2;
  122. __le32 u2_phy_pll;
  123. __le32 reserved3[33]; /* 0x80 ~ 0xff */
  124. };
  125. struct xhci_hcd_mtk {
  126. struct device *dev;
  127. struct usb_hcd *hcd;
  128. struct mu3h_sch_bw_info *sch_array;
  129. struct list_head bw_ep_chk_list;
  130. struct mu3c_ippc_regs __iomem *ippc_regs;
  131. bool has_ippc;
  132. int num_u2_ports;
  133. int num_u3_ports;
  134. int u3p_dis_msk;
  135. struct regulator *vusb33;
  136. struct regulator *vbus;
  137. struct clk *sys_clk; /* sys and mac clock */
  138. struct clk *xhci_clk;
  139. struct clk *ref_clk;
  140. struct clk *mcu_clk;
  141. struct clk *dma_clk;
  142. struct regmap *pericfg;
  143. struct phy **phys;
  144. int num_phys;
  145. bool lpm_support;
  146. bool u2_lpm_disable;
  147. /* usb remote wakeup */
  148. bool uwk_en;
  149. struct regmap *uwk;
  150. u32 uwk_reg_base;
  151. u32 uwk_vers;
  152. };
  153. static inline struct xhci_hcd_mtk *hcd_to_mtk(struct usb_hcd *hcd)
  154. {
  155. return dev_get_drvdata(hcd->self.controller);
  156. }
  157. #if IS_ENABLED(CONFIG_USB_XHCI_MTK)
  158. int xhci_mtk_sch_init(struct xhci_hcd_mtk *mtk);
  159. void xhci_mtk_sch_exit(struct xhci_hcd_mtk *mtk);
  160. int xhci_mtk_add_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev,
  161. struct usb_host_endpoint *ep);
  162. void xhci_mtk_drop_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev,
  163. struct usb_host_endpoint *ep);
  164. int xhci_mtk_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev);
  165. void xhci_mtk_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev);
  166. #else
  167. static inline int xhci_mtk_add_ep_quirk(struct usb_hcd *hcd,
  168. struct usb_device *udev, struct usb_host_endpoint *ep)
  169. {
  170. return 0;
  171. }
  172. static inline void xhci_mtk_drop_ep_quirk(struct usb_hcd *hcd,
  173. struct usb_device *udev, struct usb_host_endpoint *ep)
  174. {
  175. }
  176. static inline int xhci_mtk_check_bandwidth(struct usb_hcd *hcd,
  177. struct usb_device *udev)
  178. {
  179. return 0;
  180. }
  181. static inline void xhci_mtk_reset_bandwidth(struct usb_hcd *hcd,
  182. struct usb_device *udev)
  183. {
  184. }
  185. #endif
  186. #endif /* _XHCI_MTK_H_ */