1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (c) 2015 MediaTek Inc.
12 #include <linux/clk.h>
16 #define BULK_CLKS_NUM 5
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
24 #define XHCI_MTK_MAX_ESIT 64
27 * @ss_bit_map: used to avoid start split microframes overlay
28 * @fs_bus_bw: array to keep track of bandwidth already used for FS
29 * @ep_list: Endpoints using this TT
32 DECLARE_BITMAP(ss_bit_map, XHCI_MTK_MAX_ESIT);
33 u32 fs_bus_bw[XHCI_MTK_MAX_ESIT];
34 struct list_head ep_list;
38 * struct mu3h_sch_bw_info: schedule information for bandwidth domain
40 * @bus_bw: array to keep track of bandwidth already used at each uframes
41 * @bw_ep_list: eps in the bandwidth domain
43 * treat a HS root port as a bandwidth domain, but treat a SS root port as
44 * two bandwidth domains, one for IN eps and another for OUT eps.
46 struct mu3h_sch_bw_info {
47 u32 bus_bw[XHCI_MTK_MAX_ESIT];
48 struct list_head bw_ep_list;
52 * struct mu3h_sch_ep_info: schedule information for endpoint
54 * @esit: unit is 125us, equal to 2 << Interval field in ep-context
55 * @num_budget_microframes: number of continuous uframes
56 * (@repeat==1) scheduled within the interval
57 * @bw_cost_per_microframe: bandwidth cost per microframe
58 * @endpoint: linked into bandwidth domain which it belongs to
59 * @tt_endpoint: linked into mu3h_sch_tt's list which it belongs to
60 * @sch_tt: mu3h_sch_tt linked into
61 * @ep_type: endpoint type
62 * @maxpkt: max packet size of endpoint
63 * @ep: address of usb_host_endpoint struct
64 * @allocated: the bandwidth is aready allocated from bus_bw
65 * @offset: which uframe of the interval that transfer should be
66 * scheduled first time within the interval
67 * @repeat: the time gap between two uframes that transfers are
68 * scheduled within a interval. in the simple algorithm, only
69 * assign 0 or 1 to it; 0 means using only one uframe in a
70 * interval, and 1 means using @num_budget_microframes
72 * @pkts: number of packets to be transferred in the scheduled uframes
73 * @cs_count: number of CS that host will trigger
74 * @burst_mode: burst mode for scheduling. 0: normal burst mode,
75 * distribute the bMaxBurst+1 packets for a single burst
76 * according to @pkts and @repeat, repeate the burst multiple
77 * times; 1: distribute the (bMaxBurst+1)*(Mult+1) packets
78 * according to @pkts and @repeat. normal mode is used by
80 * @bw_budget_table: table to record bandwidth budget per microframe
82 struct mu3h_sch_ep_info {
84 u32 num_budget_microframes;
85 u32 bw_cost_per_microframe;
86 struct list_head endpoint;
87 struct list_head tt_endpoint;
88 struct mu3h_sch_tt *sch_tt;
91 struct usb_host_endpoint *ep;
92 enum usb_device_speed speed;
95 * mtk xHCI scheduling information put into reserved DWs
103 u32 bw_budget_table[];
106 #define MU3C_U3_PORT_MAX 4
107 #define MU3C_U2_PORT_MAX 5
110 * struct mu3c_ippc_regs: MTK ssusb ip port control registers
111 * @ip_pw_ctr0~3: ip power and clock control registers
112 * @ip_pw_sts1~2: ip power and clock status registers
113 * @ip_xhci_cap: ip xHCI capability register
114 * @u3_ctrl_p[x]: ip usb3 port x control register, only low 4bytes are used
115 * @u2_ctrl_p[x]: ip usb2 port x control register, only low 4bytes are used
116 * @u2_phy_pll: usb2 phy pll control register
118 struct mu3c_ippc_regs {
128 __le64 u3_ctrl_p[MU3C_U3_PORT_MAX];
129 __le64 u2_ctrl_p[MU3C_U2_PORT_MAX];
132 __le32 reserved3[33]; /* 0x80 ~ 0xff */
135 struct xhci_hcd_mtk {
138 struct mu3h_sch_bw_info *sch_array;
139 struct list_head bw_ep_chk_list;
140 struct mu3c_ippc_regs __iomem *ippc_regs;
145 struct regulator *vusb33;
146 struct regulator *vbus;
147 struct clk_bulk_data clks[BULK_CLKS_NUM];
150 /* usb remote wakeup */
157 static inline struct xhci_hcd_mtk *hcd_to_mtk(struct usb_hcd *hcd)
159 return dev_get_drvdata(hcd->self.controller);
162 int xhci_mtk_sch_init(struct xhci_hcd_mtk *mtk);
163 void xhci_mtk_sch_exit(struct xhci_hcd_mtk *mtk);
164 int xhci_mtk_add_ep(struct usb_hcd *hcd, struct usb_device *udev,
165 struct usb_host_endpoint *ep);
166 int xhci_mtk_drop_ep(struct usb_hcd *hcd, struct usb_device *udev,
167 struct usb_host_endpoint *ep);
168 int xhci_mtk_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev);
169 void xhci_mtk_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev);
171 #endif /* _XHCI_MTK_H_ */