xref: /openbmc/linux/drivers/usb/host/xhci-mtk.h (revision e19ee44a)
13e45ed3cSNishad Kamdar /* SPDX-License-Identifier: GPL-2.0 */
20cbd4b34SChunfeng Yun /*
30cbd4b34SChunfeng Yun  * Copyright (c) 2015 MediaTek Inc.
40cbd4b34SChunfeng Yun  * Author:
50cbd4b34SChunfeng Yun  *  Zhigang.Wei <zhigang.wei@mediatek.com>
60cbd4b34SChunfeng Yun  *  Chunfeng.Yun <chunfeng.yun@mediatek.com>
70cbd4b34SChunfeng Yun  */
80cbd4b34SChunfeng Yun 
90cbd4b34SChunfeng Yun #ifndef _XHCI_MTK_H_
100cbd4b34SChunfeng Yun #define _XHCI_MTK_H_
110cbd4b34SChunfeng Yun 
120cbd4b34SChunfeng Yun #include "xhci.h"
130cbd4b34SChunfeng Yun 
140cbd4b34SChunfeng Yun /**
150cbd4b34SChunfeng Yun  * To simplify scheduler algorithm, set a upper limit for ESIT,
160cbd4b34SChunfeng Yun  * if a synchromous ep's ESIT is larger than @XHCI_MTK_MAX_ESIT,
170cbd4b34SChunfeng Yun  * round down to the limit value, that means allocating more
180cbd4b34SChunfeng Yun  * bandwidth to it.
190cbd4b34SChunfeng Yun  */
200cbd4b34SChunfeng Yun #define XHCI_MTK_MAX_ESIT	64
210cbd4b34SChunfeng Yun 
220cbd4b34SChunfeng Yun /**
23*e19ee44aSChunfeng Yun  * @ss_bit_map: used to avoid start split microframes overlay
24*e19ee44aSChunfeng Yun  * @fs_bus_bw: array to keep track of bandwidth already used for FS
2508e469deSChunfeng Yun  * @ep_list: Endpoints using this TT
2608e469deSChunfeng Yun  * @usb_tt: usb TT related
2708e469deSChunfeng Yun  * @tt_port: TT port number
2808e469deSChunfeng Yun  */
2908e469deSChunfeng Yun struct mu3h_sch_tt {
30*e19ee44aSChunfeng Yun 	DECLARE_BITMAP(ss_bit_map, XHCI_MTK_MAX_ESIT);
31*e19ee44aSChunfeng Yun 	u32 fs_bus_bw[XHCI_MTK_MAX_ESIT];
3208e469deSChunfeng Yun 	struct list_head ep_list;
3308e469deSChunfeng Yun 	struct usb_tt *usb_tt;
3408e469deSChunfeng Yun 	int tt_port;
3508e469deSChunfeng Yun };
3608e469deSChunfeng Yun 
3708e469deSChunfeng Yun /**
380cbd4b34SChunfeng Yun  * struct mu3h_sch_bw_info: schedule information for bandwidth domain
390cbd4b34SChunfeng Yun  *
400cbd4b34SChunfeng Yun  * @bus_bw: array to keep track of bandwidth already used at each uframes
410cbd4b34SChunfeng Yun  * @bw_ep_list: eps in the bandwidth domain
420cbd4b34SChunfeng Yun  *
430cbd4b34SChunfeng Yun  * treat a HS root port as a bandwidth domain, but treat a SS root port as
440cbd4b34SChunfeng Yun  * two bandwidth domains, one for IN eps and another for OUT eps.
450cbd4b34SChunfeng Yun  */
460cbd4b34SChunfeng Yun struct mu3h_sch_bw_info {
470cbd4b34SChunfeng Yun 	u32 bus_bw[XHCI_MTK_MAX_ESIT];
480cbd4b34SChunfeng Yun 	struct list_head bw_ep_list;
490cbd4b34SChunfeng Yun };
500cbd4b34SChunfeng Yun 
510cbd4b34SChunfeng Yun /**
520cbd4b34SChunfeng Yun  * struct mu3h_sch_ep_info: schedule information for endpoint
530cbd4b34SChunfeng Yun  *
540cbd4b34SChunfeng Yun  * @esit: unit is 125us, equal to 2 << Interval field in ep-context
550cbd4b34SChunfeng Yun  * @num_budget_microframes: number of continuous uframes
560cbd4b34SChunfeng Yun  *		(@repeat==1) scheduled within the interval
570cbd4b34SChunfeng Yun  * @bw_cost_per_microframe: bandwidth cost per microframe
580cbd4b34SChunfeng Yun  * @endpoint: linked into bandwidth domain which it belongs to
5908e469deSChunfeng Yun  * @tt_endpoint: linked into mu3h_sch_tt's list which it belongs to
6008e469deSChunfeng Yun  * @sch_tt: mu3h_sch_tt linked into
6108e469deSChunfeng Yun  * @ep_type: endpoint type
6208e469deSChunfeng Yun  * @maxpkt: max packet size of endpoint
630cbd4b34SChunfeng Yun  * @ep: address of usb_host_endpoint struct
6454f6a8afSChunfeng Yun  * @allocated: the bandwidth is aready allocated from bus_bw
650cbd4b34SChunfeng Yun  * @offset: which uframe of the interval that transfer should be
660cbd4b34SChunfeng Yun  *		scheduled first time within the interval
670cbd4b34SChunfeng Yun  * @repeat: the time gap between two uframes that transfers are
680cbd4b34SChunfeng Yun  *		scheduled within a interval. in the simple algorithm, only
690cbd4b34SChunfeng Yun  *		assign 0 or 1 to it; 0 means using only one uframe in a
700cbd4b34SChunfeng Yun  *		interval, and 1 means using @num_budget_microframes
710cbd4b34SChunfeng Yun  *		continuous uframes
720cbd4b34SChunfeng Yun  * @pkts: number of packets to be transferred in the scheduled uframes
730cbd4b34SChunfeng Yun  * @cs_count: number of CS that host will trigger
740cbd4b34SChunfeng Yun  * @burst_mode: burst mode for scheduling. 0: normal burst mode,
750cbd4b34SChunfeng Yun  *		distribute the bMaxBurst+1 packets for a single burst
760cbd4b34SChunfeng Yun  *		according to @pkts and @repeat, repeate the burst multiple
770cbd4b34SChunfeng Yun  *		times; 1: distribute the (bMaxBurst+1)*(Mult+1) packets
780cbd4b34SChunfeng Yun  *		according to @pkts and @repeat. normal mode is used by
790cbd4b34SChunfeng Yun  *		default
8095b516c1SChunfeng Yun  * @bw_budget_table: table to record bandwidth budget per microframe
810cbd4b34SChunfeng Yun  */
820cbd4b34SChunfeng Yun struct mu3h_sch_ep_info {
830cbd4b34SChunfeng Yun 	u32 esit;
840cbd4b34SChunfeng Yun 	u32 num_budget_microframes;
850cbd4b34SChunfeng Yun 	u32 bw_cost_per_microframe;
860cbd4b34SChunfeng Yun 	struct list_head endpoint;
8708e469deSChunfeng Yun 	struct list_head tt_endpoint;
8808e469deSChunfeng Yun 	struct mu3h_sch_tt *sch_tt;
8908e469deSChunfeng Yun 	u32 ep_type;
9008e469deSChunfeng Yun 	u32 maxpkt;
910cbd4b34SChunfeng Yun 	void *ep;
9254f6a8afSChunfeng Yun 	bool allocated;
930cbd4b34SChunfeng Yun 	/*
940cbd4b34SChunfeng Yun 	 * mtk xHCI scheduling information put into reserved DWs
950cbd4b34SChunfeng Yun 	 * in ep context
960cbd4b34SChunfeng Yun 	 */
970cbd4b34SChunfeng Yun 	u32 offset;
980cbd4b34SChunfeng Yun 	u32 repeat;
990cbd4b34SChunfeng Yun 	u32 pkts;
1000cbd4b34SChunfeng Yun 	u32 cs_count;
1010cbd4b34SChunfeng Yun 	u32 burst_mode;
1026bc3f397SGustavo A. R. Silva 	u32 bw_budget_table[];
1030cbd4b34SChunfeng Yun };
1040cbd4b34SChunfeng Yun 
1050cbd4b34SChunfeng Yun #define MU3C_U3_PORT_MAX 4
1060cbd4b34SChunfeng Yun #define MU3C_U2_PORT_MAX 5
1070cbd4b34SChunfeng Yun 
1080cbd4b34SChunfeng Yun /**
1090cbd4b34SChunfeng Yun  * struct mu3c_ippc_regs: MTK ssusb ip port control registers
1100cbd4b34SChunfeng Yun  * @ip_pw_ctr0~3: ip power and clock control registers
1110cbd4b34SChunfeng Yun  * @ip_pw_sts1~2: ip power and clock status registers
1120cbd4b34SChunfeng Yun  * @ip_xhci_cap: ip xHCI capability register
1130cbd4b34SChunfeng Yun  * @u3_ctrl_p[x]: ip usb3 port x control register, only low 4bytes are used
1140cbd4b34SChunfeng Yun  * @u2_ctrl_p[x]: ip usb2 port x control register, only low 4bytes are used
1150cbd4b34SChunfeng Yun  * @u2_phy_pll: usb2 phy pll control register
1160cbd4b34SChunfeng Yun  */
1170cbd4b34SChunfeng Yun struct mu3c_ippc_regs {
1180cbd4b34SChunfeng Yun 	__le32 ip_pw_ctr0;
1190cbd4b34SChunfeng Yun 	__le32 ip_pw_ctr1;
1200cbd4b34SChunfeng Yun 	__le32 ip_pw_ctr2;
1210cbd4b34SChunfeng Yun 	__le32 ip_pw_ctr3;
1220cbd4b34SChunfeng Yun 	__le32 ip_pw_sts1;
1230cbd4b34SChunfeng Yun 	__le32 ip_pw_sts2;
1240cbd4b34SChunfeng Yun 	__le32 reserved0[3];
1250cbd4b34SChunfeng Yun 	__le32 ip_xhci_cap;
1260cbd4b34SChunfeng Yun 	__le32 reserved1[2];
1270cbd4b34SChunfeng Yun 	__le64 u3_ctrl_p[MU3C_U3_PORT_MAX];
1280cbd4b34SChunfeng Yun 	__le64 u2_ctrl_p[MU3C_U2_PORT_MAX];
1290cbd4b34SChunfeng Yun 	__le32 reserved2;
1300cbd4b34SChunfeng Yun 	__le32 u2_phy_pll;
1310cbd4b34SChunfeng Yun 	__le32 reserved3[33]; /* 0x80 ~ 0xff */
1320cbd4b34SChunfeng Yun };
1330cbd4b34SChunfeng Yun 
1340cbd4b34SChunfeng Yun struct xhci_hcd_mtk {
1350cbd4b34SChunfeng Yun 	struct device *dev;
1360cbd4b34SChunfeng Yun 	struct usb_hcd *hcd;
1370cbd4b34SChunfeng Yun 	struct mu3h_sch_bw_info *sch_array;
13854f6a8afSChunfeng Yun 	struct list_head bw_ep_chk_list;
1390cbd4b34SChunfeng Yun 	struct mu3c_ippc_regs __iomem *ippc_regs;
140065d48cfSChunfeng Yun 	bool has_ippc;
1410cbd4b34SChunfeng Yun 	int num_u2_ports;
1420cbd4b34SChunfeng Yun 	int num_u3_ports;
14355ba6e9eSChunfeng Yun 	int u3p_dis_msk;
1440cbd4b34SChunfeng Yun 	struct regulator *vusb33;
1450cbd4b34SChunfeng Yun 	struct regulator *vbus;
1460cbd4b34SChunfeng Yun 	struct clk *sys_clk;	/* sys and mac clock */
147b2fcb285SChunfeng Yun 	struct clk *xhci_clk;
1489c4afd42SChunfeng Yun 	struct clk *ref_clk;
149b6bb72cfSChunfeng Yun 	struct clk *mcu_clk;
150b6bb72cfSChunfeng Yun 	struct clk *dma_clk;
1510cbd4b34SChunfeng Yun 	struct regmap *pericfg;
1520cbd4b34SChunfeng Yun 	struct phy **phys;
1530cbd4b34SChunfeng Yun 	int num_phys;
1540cbd4b34SChunfeng Yun 	bool lpm_support;
155a2ecc4dfSChunfeng Yun 	/* usb remote wakeup */
156a2ecc4dfSChunfeng Yun 	bool uwk_en;
157a2ecc4dfSChunfeng Yun 	struct regmap *uwk;
158a2ecc4dfSChunfeng Yun 	u32 uwk_reg_base;
159a2ecc4dfSChunfeng Yun 	u32 uwk_vers;
1600cbd4b34SChunfeng Yun };
1610cbd4b34SChunfeng Yun 
1620cbd4b34SChunfeng Yun static inline struct xhci_hcd_mtk *hcd_to_mtk(struct usb_hcd *hcd)
1630cbd4b34SChunfeng Yun {
1640cbd4b34SChunfeng Yun 	return dev_get_drvdata(hcd->self.controller);
1650cbd4b34SChunfeng Yun }
1660cbd4b34SChunfeng Yun 
1670cbd4b34SChunfeng Yun #if IS_ENABLED(CONFIG_USB_XHCI_MTK)
1680cbd4b34SChunfeng Yun int xhci_mtk_sch_init(struct xhci_hcd_mtk *mtk);
1690cbd4b34SChunfeng Yun void xhci_mtk_sch_exit(struct xhci_hcd_mtk *mtk);
1700cbd4b34SChunfeng Yun int xhci_mtk_add_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev,
1710cbd4b34SChunfeng Yun 		struct usb_host_endpoint *ep);
1720cbd4b34SChunfeng Yun void xhci_mtk_drop_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev,
1730cbd4b34SChunfeng Yun 		struct usb_host_endpoint *ep);
1741d69f9d9SIkjoon Jang int xhci_mtk_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev);
1751d69f9d9SIkjoon Jang void xhci_mtk_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev);
1760cbd4b34SChunfeng Yun 
1770cbd4b34SChunfeng Yun #else
1780cbd4b34SChunfeng Yun static inline int xhci_mtk_add_ep_quirk(struct usb_hcd *hcd,
1790cbd4b34SChunfeng Yun 	struct usb_device *udev, struct usb_host_endpoint *ep)
1800cbd4b34SChunfeng Yun {
1810cbd4b34SChunfeng Yun 	return 0;
1820cbd4b34SChunfeng Yun }
1830cbd4b34SChunfeng Yun 
1840cbd4b34SChunfeng Yun static inline void xhci_mtk_drop_ep_quirk(struct usb_hcd *hcd,
1850cbd4b34SChunfeng Yun 	struct usb_device *udev, struct usb_host_endpoint *ep)
1860cbd4b34SChunfeng Yun {
1870cbd4b34SChunfeng Yun }
1880cbd4b34SChunfeng Yun 
1891d69f9d9SIkjoon Jang static inline int xhci_mtk_check_bandwidth(struct usb_hcd *hcd,
1901d69f9d9SIkjoon Jang 		struct usb_device *udev)
1911d69f9d9SIkjoon Jang {
1921d69f9d9SIkjoon Jang 	return 0;
1931d69f9d9SIkjoon Jang }
1941d69f9d9SIkjoon Jang 
1951d69f9d9SIkjoon Jang static inline void xhci_mtk_reset_bandwidth(struct usb_hcd *hcd,
1961d69f9d9SIkjoon Jang 		struct usb_device *udev)
1971d69f9d9SIkjoon Jang {
1981d69f9d9SIkjoon Jang }
1990cbd4b34SChunfeng Yun #endif
2000cbd4b34SChunfeng Yun 
2010cbd4b34SChunfeng Yun #endif		/* _XHCI_MTK_H_ */
202