xhci-mtk.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 <linux/clk.h>
  11. #include <linux/hashtable.h>
  12. #include <linux/regulator/consumer.h>
  13. #include "xhci.h"
  14. #define BULK_CLKS_NUM 6
  15. #define BULK_VREGS_NUM 2
  16. /* support at most 64 ep, use 32 size hash table */
  17. #define SCH_EP_HASH_BITS 5
  18. /**
  19. * To simplify scheduler algorithm, set a upper limit for ESIT,
  20. * if a synchromous ep's ESIT is larger than @XHCI_MTK_MAX_ESIT,
  21. * round down to the limit value, that means allocating more
  22. * bandwidth to it.
  23. */
  24. #define XHCI_MTK_MAX_ESIT (1 << 6)
  25. #define XHCI_MTK_BW_INDEX(x) ((x) & (XHCI_MTK_MAX_ESIT - 1))
  26. #define UFRAMES_PER_FRAME 8
  27. #define XHCI_MTK_FRAMES_CNT (XHCI_MTK_MAX_ESIT / UFRAMES_PER_FRAME)
  28. /**
  29. * @fs_bus_bw_out: save bandwidth used by FS/LS OUT eps in each uframes
  30. * @fs_bus_bw_in: save bandwidth used by FS/LS IN eps in each uframes
  31. * @ls_bus_bw: save bandwidth used by LS eps in each uframes
  32. * @fs_frame_bw: save bandwidth used by FS/LS eps in each FS frames
  33. * @in_ss_cnt: the count of Start-Split for IN eps
  34. * @ep_list: Endpoints using this TT
  35. */
  36. struct mu3h_sch_tt {
  37. u16 fs_bus_bw_out[XHCI_MTK_MAX_ESIT];
  38. u16 fs_bus_bw_in[XHCI_MTK_MAX_ESIT];
  39. u8 ls_bus_bw[XHCI_MTK_MAX_ESIT];
  40. u16 fs_frame_bw[XHCI_MTK_FRAMES_CNT];
  41. u8 in_ss_cnt[XHCI_MTK_MAX_ESIT];
  42. struct list_head ep_list;
  43. };
  44. /**
  45. * struct mu3h_sch_bw_info: schedule information for bandwidth domain
  46. *
  47. * @bus_bw: array to keep track of bandwidth already used at each uframes
  48. *
  49. * treat a HS root port as a bandwidth domain, but treat a SS root port as
  50. * two bandwidth domains, one for IN eps and another for OUT eps.
  51. */
  52. struct mu3h_sch_bw_info {
  53. u32 bus_bw[XHCI_MTK_MAX_ESIT];
  54. };
  55. /**
  56. * struct mu3h_sch_ep_info: schedule information for endpoint
  57. *
  58. * @esit: unit is 125us, equal to 2 << Interval field in ep-context
  59. * @num_esit: number of @esit in a period
  60. * @num_budget_microframes: number of continuous uframes
  61. * (@repeat==1) scheduled within the interval
  62. * @hentry: hash table entry
  63. * @endpoint: linked into bandwidth domain which it belongs to
  64. * @tt_endpoint: linked into mu3h_sch_tt's list which it belongs to
  65. * @bw_info: bandwidth domain which this endpoint belongs
  66. * @sch_tt: mu3h_sch_tt linked into
  67. * @ep_type: endpoint type
  68. * @maxpkt: max packet size of endpoint
  69. * @ep: address of usb_host_endpoint struct
  70. * @allocated: the bandwidth is aready allocated from bus_bw
  71. * @offset: which uframe of the interval that transfer should be
  72. * scheduled first time within the interval
  73. * @repeat: the time gap between two uframes that transfers are
  74. * scheduled within a interval. in the simple algorithm, only
  75. * assign 0 or 1 to it; 0 means using only one uframe in a
  76. * interval, and 1 means using @num_budget_microframes
  77. * continuous uframes
  78. * @pkts: number of packets to be transferred in the scheduled uframes
  79. * @cs_count: number of CS that host will trigger
  80. * @burst_mode: burst mode for scheduling. 0: normal burst mode,
  81. * distribute the bMaxBurst+1 packets for a single burst
  82. * according to @pkts and @repeat, repeate the burst multiple
  83. * times; 1: distribute the (bMaxBurst+1)*(Mult+1) packets
  84. * according to @pkts and @repeat. normal mode is used by
  85. * default
  86. * @bw_budget_table: table to record bandwidth budget per microframe
  87. */
  88. struct mu3h_sch_ep_info {
  89. u32 esit;
  90. u32 num_esit;
  91. u32 num_budget_microframes;
  92. struct list_head endpoint;
  93. struct hlist_node hentry;
  94. struct list_head tt_endpoint;
  95. struct mu3h_sch_bw_info *bw_info;
  96. struct mu3h_sch_tt *sch_tt;
  97. u32 ep_type;
  98. u32 maxpkt;
  99. struct usb_host_endpoint *ep;
  100. enum usb_device_speed speed;
  101. bool allocated;
  102. /*
  103. * mtk xHCI scheduling information put into reserved DWs
  104. * in ep context
  105. */
  106. u32 offset;
  107. u32 repeat;
  108. u32 pkts;
  109. u32 cs_count;
  110. u32 burst_mode;
  111. u32 bw_budget_table[];
  112. };
  113. #define MU3C_U3_PORT_MAX 4
  114. #define MU3C_U2_PORT_MAX 5
  115. /**
  116. * struct mu3c_ippc_regs: MTK ssusb ip port control registers
  117. * @ip_pw_ctr0~3: ip power and clock control registers
  118. * @ip_pw_sts1~2: ip power and clock status registers
  119. * @ip_xhci_cap: ip xHCI capability register
  120. * @u3_ctrl_p[x]: ip usb3 port x control register, only low 4bytes are used
  121. * @u2_ctrl_p[x]: ip usb2 port x control register, only low 4bytes are used
  122. * @u2_phy_pll: usb2 phy pll control register
  123. */
  124. struct mu3c_ippc_regs {
  125. __le32 ip_pw_ctr0;
  126. __le32 ip_pw_ctr1;
  127. __le32 ip_pw_ctr2;
  128. __le32 ip_pw_ctr3;
  129. __le32 ip_pw_sts1;
  130. __le32 ip_pw_sts2;
  131. __le32 reserved0[3];
  132. __le32 ip_xhci_cap;
  133. __le32 reserved1[2];
  134. __le64 u3_ctrl_p[MU3C_U3_PORT_MAX];
  135. __le64 u2_ctrl_p[MU3C_U2_PORT_MAX];
  136. __le32 reserved2;
  137. __le32 u2_phy_pll;
  138. __le32 reserved3[33]; /* 0x80 ~ 0xff */
  139. };
  140. struct xhci_hcd_mtk {
  141. struct device *dev;
  142. struct usb_hcd *hcd;
  143. struct mu3h_sch_bw_info *sch_array;
  144. struct list_head bw_ep_chk_list;
  145. DECLARE_HASHTABLE(sch_ep_hash, SCH_EP_HASH_BITS);
  146. struct mu3c_ippc_regs __iomem *ippc_regs;
  147. int num_u2_ports;
  148. int num_u3_ports;
  149. int u2p_dis_msk;
  150. int u3p_dis_msk;
  151. struct clk_bulk_data clks[BULK_CLKS_NUM];
  152. struct regulator_bulk_data supplies[BULK_VREGS_NUM];
  153. unsigned int has_ippc:1;
  154. unsigned int lpm_support:1;
  155. unsigned int u2_lpm_disable:1;
  156. /* usb remote wakeup */
  157. unsigned int uwk_en:1;
  158. struct regmap *uwk;
  159. u32 uwk_reg_base;
  160. u32 uwk_vers;
  161. /* quirk */
  162. u32 rxfifo_depth;
  163. };
  164. static inline struct xhci_hcd_mtk *hcd_to_mtk(struct usb_hcd *hcd)
  165. {
  166. return dev_get_drvdata(hcd->self.controller);
  167. }
  168. int xhci_mtk_sch_init(struct xhci_hcd_mtk *mtk);
  169. void xhci_mtk_sch_exit(struct xhci_hcd_mtk *mtk);
  170. int xhci_mtk_add_ep(struct usb_hcd *hcd, struct usb_device *udev,
  171. struct usb_host_endpoint *ep);
  172. int xhci_mtk_drop_ep(struct usb_hcd *hcd, struct usb_device *udev,
  173. struct usb_host_endpoint *ep);
  174. int xhci_mtk_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev);
  175. void xhci_mtk_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev);
  176. #endif /* _XHCI_MTK_H_ */