xhci-mtk.h 5.1 KB

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