xhci-mtk.h 4.8 KB

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