xhci-mtk.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2015 MediaTek Inc.
  4. * Author:
  5. * Zhigang.Wei <[email protected]>
  6. * Chunfeng.Yun <[email protected]>
  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 5
  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. /**
  27. * @fs_bus_bw: array to keep track of bandwidth already used for FS
  28. * @ep_list: Endpoints using this TT
  29. */
  30. struct mu3h_sch_tt {
  31. u32 fs_bus_bw[XHCI_MTK_MAX_ESIT];
  32. struct list_head ep_list;
  33. };
  34. /**
  35. * struct mu3h_sch_bw_info: schedule information for bandwidth domain
  36. *
  37. * @bus_bw: array to keep track of bandwidth already used at each uframes
  38. *
  39. * treat a HS root port as a bandwidth domain, but treat a SS root port as
  40. * two bandwidth domains, one for IN eps and another for OUT eps.
  41. */
  42. struct mu3h_sch_bw_info {
  43. u32 bus_bw[XHCI_MTK_MAX_ESIT];
  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_esit: number of @esit in a period
  50. * @num_budget_microframes: number of continuous uframes
  51. * (@repeat==1) scheduled within the interval
  52. * @bw_cost_per_microframe: bandwidth cost per microframe
  53. * @hentry: hash table entry
  54. * @endpoint: linked into bandwidth domain which it belongs to
  55. * @tt_endpoint: linked into mu3h_sch_tt's list which it belongs to
  56. * @bw_info: bandwidth domain which this endpoint belongs
  57. * @sch_tt: mu3h_sch_tt linked into
  58. * @ep_type: endpoint type
  59. * @maxpkt: max packet size of endpoint
  60. * @ep: address of usb_host_endpoint struct
  61. * @allocated: the bandwidth is aready allocated from bus_bw
  62. * @offset: which uframe of the interval that transfer should be
  63. * scheduled first time within the interval
  64. * @repeat: the time gap between two uframes that transfers are
  65. * scheduled within a interval. in the simple algorithm, only
  66. * assign 0 or 1 to it; 0 means using only one uframe in a
  67. * interval, and 1 means using @num_budget_microframes
  68. * continuous uframes
  69. * @pkts: number of packets to be transferred in the scheduled uframes
  70. * @cs_count: number of CS that host will trigger
  71. * @burst_mode: burst mode for scheduling. 0: normal burst mode,
  72. * distribute the bMaxBurst+1 packets for a single burst
  73. * according to @pkts and @repeat, repeate the burst multiple
  74. * times; 1: distribute the (bMaxBurst+1)*(Mult+1) packets
  75. * according to @pkts and @repeat. normal mode is used by
  76. * default
  77. */
  78. struct mu3h_sch_ep_info {
  79. u32 esit;
  80. u32 num_esit;
  81. u32 num_budget_microframes;
  82. u32 bw_cost_per_microframe;
  83. struct list_head endpoint;
  84. struct hlist_node hentry;
  85. struct list_head tt_endpoint;
  86. struct mu3h_sch_bw_info *bw_info;
  87. struct mu3h_sch_tt *sch_tt;
  88. u32 ep_type;
  89. u32 maxpkt;
  90. struct usb_host_endpoint *ep;
  91. enum usb_device_speed speed;
  92. bool allocated;
  93. /*
  94. * mtk xHCI scheduling information put into reserved DWs
  95. * in ep context
  96. */
  97. u32 offset;
  98. u32 repeat;
  99. u32 pkts;
  100. u32 cs_count;
  101. u32 burst_mode;
  102. };
  103. #define MU3C_U3_PORT_MAX 4
  104. #define MU3C_U2_PORT_MAX 5
  105. /**
  106. * struct mu3c_ippc_regs: MTK ssusb ip port control registers
  107. * @ip_pw_ctr0~3: ip power and clock control registers
  108. * @ip_pw_sts1~2: ip power and clock status registers
  109. * @ip_xhci_cap: ip xHCI capability register
  110. * @u3_ctrl_p[x]: ip usb3 port x control register, only low 4bytes are used
  111. * @u2_ctrl_p[x]: ip usb2 port x control register, only low 4bytes are used
  112. * @u2_phy_pll: usb2 phy pll control register
  113. */
  114. struct mu3c_ippc_regs {
  115. __le32 ip_pw_ctr0;
  116. __le32 ip_pw_ctr1;
  117. __le32 ip_pw_ctr2;
  118. __le32 ip_pw_ctr3;
  119. __le32 ip_pw_sts1;
  120. __le32 ip_pw_sts2;
  121. __le32 reserved0[3];
  122. __le32 ip_xhci_cap;
  123. __le32 reserved1[2];
  124. __le64 u3_ctrl_p[MU3C_U3_PORT_MAX];
  125. __le64 u2_ctrl_p[MU3C_U2_PORT_MAX];
  126. __le32 reserved2;
  127. __le32 u2_phy_pll;
  128. __le32 reserved3[33]; /* 0x80 ~ 0xff */
  129. };
  130. struct xhci_hcd_mtk {
  131. struct device *dev;
  132. struct usb_hcd *hcd;
  133. struct mu3h_sch_bw_info *sch_array;
  134. struct list_head bw_ep_chk_list;
  135. DECLARE_HASHTABLE(sch_ep_hash, SCH_EP_HASH_BITS);
  136. struct mu3c_ippc_regs __iomem *ippc_regs;
  137. int num_u2_ports;
  138. int num_u3_ports;
  139. int u2p_dis_msk;
  140. int u3p_dis_msk;
  141. struct clk_bulk_data clks[BULK_CLKS_NUM];
  142. struct regulator_bulk_data supplies[BULK_VREGS_NUM];
  143. unsigned int has_ippc:1;
  144. unsigned int lpm_support:1;
  145. unsigned int u2_lpm_disable:1;
  146. /* usb remote wakeup */
  147. unsigned int uwk_en:1;
  148. struct regmap *uwk;
  149. u32 uwk_reg_base;
  150. u32 uwk_vers;
  151. };
  152. static inline struct xhci_hcd_mtk *hcd_to_mtk(struct usb_hcd *hcd)
  153. {
  154. return dev_get_drvdata(hcd->self.controller);
  155. }
  156. int xhci_mtk_sch_init(struct xhci_hcd_mtk *mtk);
  157. void xhci_mtk_sch_exit(struct xhci_hcd_mtk *mtk);
  158. int xhci_mtk_add_ep(struct usb_hcd *hcd, struct usb_device *udev,
  159. struct usb_host_endpoint *ep);
  160. int xhci_mtk_drop_ep(struct usb_hcd *hcd, struct usb_device *udev,
  161. struct usb_host_endpoint *ep);
  162. int xhci_mtk_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev);
  163. void xhci_mtk_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev);
  164. #endif /* _XHCI_MTK_H_ */