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 /** 23e19ee44aSChunfeng Yun * @ss_bit_map: used to avoid start split microframes overlay 24e19ee44aSChunfeng Yun * @fs_bus_bw: array to keep track of bandwidth already used for FS 2508e469deSChunfeng Yun * @ep_list: Endpoints using this TT 2608e469deSChunfeng Yun */ 2708e469deSChunfeng Yun struct mu3h_sch_tt { 28e19ee44aSChunfeng Yun DECLARE_BITMAP(ss_bit_map, XHCI_MTK_MAX_ESIT); 29e19ee44aSChunfeng Yun u32 fs_bus_bw[XHCI_MTK_MAX_ESIT]; 3008e469deSChunfeng Yun struct list_head ep_list; 3108e469deSChunfeng Yun }; 3208e469deSChunfeng Yun 3308e469deSChunfeng Yun /** 340cbd4b34SChunfeng Yun * struct mu3h_sch_bw_info: schedule information for bandwidth domain 350cbd4b34SChunfeng Yun * 360cbd4b34SChunfeng Yun * @bus_bw: array to keep track of bandwidth already used at each uframes 370cbd4b34SChunfeng Yun * @bw_ep_list: eps in the bandwidth domain 380cbd4b34SChunfeng Yun * 390cbd4b34SChunfeng Yun * treat a HS root port as a bandwidth domain, but treat a SS root port as 400cbd4b34SChunfeng Yun * two bandwidth domains, one for IN eps and another for OUT eps. 410cbd4b34SChunfeng Yun */ 420cbd4b34SChunfeng Yun struct mu3h_sch_bw_info { 430cbd4b34SChunfeng Yun u32 bus_bw[XHCI_MTK_MAX_ESIT]; 440cbd4b34SChunfeng Yun struct list_head bw_ep_list; 450cbd4b34SChunfeng Yun }; 460cbd4b34SChunfeng Yun 470cbd4b34SChunfeng Yun /** 480cbd4b34SChunfeng Yun * struct mu3h_sch_ep_info: schedule information for endpoint 490cbd4b34SChunfeng Yun * 500cbd4b34SChunfeng Yun * @esit: unit is 125us, equal to 2 << Interval field in ep-context 510cbd4b34SChunfeng Yun * @num_budget_microframes: number of continuous uframes 520cbd4b34SChunfeng Yun * (@repeat==1) scheduled within the interval 530cbd4b34SChunfeng Yun * @bw_cost_per_microframe: bandwidth cost per microframe 540cbd4b34SChunfeng Yun * @endpoint: linked into bandwidth domain which it belongs to 5508e469deSChunfeng Yun * @tt_endpoint: linked into mu3h_sch_tt's list which it belongs to 5608e469deSChunfeng Yun * @sch_tt: mu3h_sch_tt linked into 5708e469deSChunfeng Yun * @ep_type: endpoint type 5808e469deSChunfeng Yun * @maxpkt: max packet size of endpoint 590cbd4b34SChunfeng Yun * @ep: address of usb_host_endpoint struct 6054f6a8afSChunfeng Yun * @allocated: the bandwidth is aready allocated from bus_bw 610cbd4b34SChunfeng Yun * @offset: which uframe of the interval that transfer should be 620cbd4b34SChunfeng Yun * scheduled first time within the interval 630cbd4b34SChunfeng Yun * @repeat: the time gap between two uframes that transfers are 640cbd4b34SChunfeng Yun * scheduled within a interval. in the simple algorithm, only 650cbd4b34SChunfeng Yun * assign 0 or 1 to it; 0 means using only one uframe in a 660cbd4b34SChunfeng Yun * interval, and 1 means using @num_budget_microframes 670cbd4b34SChunfeng Yun * continuous uframes 680cbd4b34SChunfeng Yun * @pkts: number of packets to be transferred in the scheduled uframes 690cbd4b34SChunfeng Yun * @cs_count: number of CS that host will trigger 700cbd4b34SChunfeng Yun * @burst_mode: burst mode for scheduling. 0: normal burst mode, 710cbd4b34SChunfeng Yun * distribute the bMaxBurst+1 packets for a single burst 720cbd4b34SChunfeng Yun * according to @pkts and @repeat, repeate the burst multiple 730cbd4b34SChunfeng Yun * times; 1: distribute the (bMaxBurst+1)*(Mult+1) packets 740cbd4b34SChunfeng Yun * according to @pkts and @repeat. normal mode is used by 750cbd4b34SChunfeng Yun * default 7695b516c1SChunfeng Yun * @bw_budget_table: table to record bandwidth budget per microframe 770cbd4b34SChunfeng Yun */ 780cbd4b34SChunfeng Yun struct mu3h_sch_ep_info { 790cbd4b34SChunfeng Yun u32 esit; 800cbd4b34SChunfeng Yun u32 num_budget_microframes; 810cbd4b34SChunfeng Yun u32 bw_cost_per_microframe; 820cbd4b34SChunfeng Yun struct list_head endpoint; 8308e469deSChunfeng Yun struct list_head tt_endpoint; 8408e469deSChunfeng Yun struct mu3h_sch_tt *sch_tt; 8508e469deSChunfeng Yun u32 ep_type; 8608e469deSChunfeng Yun u32 maxpkt; 879132799dSChunfeng Yun struct usb_host_endpoint *ep; 88*6009bea0SChunfeng Yun enum usb_device_speed speed; 8954f6a8afSChunfeng Yun bool allocated; 900cbd4b34SChunfeng Yun /* 910cbd4b34SChunfeng Yun * mtk xHCI scheduling information put into reserved DWs 920cbd4b34SChunfeng Yun * in ep context 930cbd4b34SChunfeng Yun */ 940cbd4b34SChunfeng Yun u32 offset; 950cbd4b34SChunfeng Yun u32 repeat; 960cbd4b34SChunfeng Yun u32 pkts; 970cbd4b34SChunfeng Yun u32 cs_count; 980cbd4b34SChunfeng Yun u32 burst_mode; 996bc3f397SGustavo A. R. Silva u32 bw_budget_table[]; 1000cbd4b34SChunfeng Yun }; 1010cbd4b34SChunfeng Yun 1020cbd4b34SChunfeng Yun #define MU3C_U3_PORT_MAX 4 1030cbd4b34SChunfeng Yun #define MU3C_U2_PORT_MAX 5 1040cbd4b34SChunfeng Yun 1050cbd4b34SChunfeng Yun /** 1060cbd4b34SChunfeng Yun * struct mu3c_ippc_regs: MTK ssusb ip port control registers 1070cbd4b34SChunfeng Yun * @ip_pw_ctr0~3: ip power and clock control registers 1080cbd4b34SChunfeng Yun * @ip_pw_sts1~2: ip power and clock status registers 1090cbd4b34SChunfeng Yun * @ip_xhci_cap: ip xHCI capability register 1100cbd4b34SChunfeng Yun * @u3_ctrl_p[x]: ip usb3 port x control register, only low 4bytes are used 1110cbd4b34SChunfeng Yun * @u2_ctrl_p[x]: ip usb2 port x control register, only low 4bytes are used 1120cbd4b34SChunfeng Yun * @u2_phy_pll: usb2 phy pll control register 1130cbd4b34SChunfeng Yun */ 1140cbd4b34SChunfeng Yun struct mu3c_ippc_regs { 1150cbd4b34SChunfeng Yun __le32 ip_pw_ctr0; 1160cbd4b34SChunfeng Yun __le32 ip_pw_ctr1; 1170cbd4b34SChunfeng Yun __le32 ip_pw_ctr2; 1180cbd4b34SChunfeng Yun __le32 ip_pw_ctr3; 1190cbd4b34SChunfeng Yun __le32 ip_pw_sts1; 1200cbd4b34SChunfeng Yun __le32 ip_pw_sts2; 1210cbd4b34SChunfeng Yun __le32 reserved0[3]; 1220cbd4b34SChunfeng Yun __le32 ip_xhci_cap; 1230cbd4b34SChunfeng Yun __le32 reserved1[2]; 1240cbd4b34SChunfeng Yun __le64 u3_ctrl_p[MU3C_U3_PORT_MAX]; 1250cbd4b34SChunfeng Yun __le64 u2_ctrl_p[MU3C_U2_PORT_MAX]; 1260cbd4b34SChunfeng Yun __le32 reserved2; 1270cbd4b34SChunfeng Yun __le32 u2_phy_pll; 1280cbd4b34SChunfeng Yun __le32 reserved3[33]; /* 0x80 ~ 0xff */ 1290cbd4b34SChunfeng Yun }; 1300cbd4b34SChunfeng Yun 1310cbd4b34SChunfeng Yun struct xhci_hcd_mtk { 1320cbd4b34SChunfeng Yun struct device *dev; 1330cbd4b34SChunfeng Yun struct usb_hcd *hcd; 1340cbd4b34SChunfeng Yun struct mu3h_sch_bw_info *sch_array; 13554f6a8afSChunfeng Yun struct list_head bw_ep_chk_list; 1360cbd4b34SChunfeng Yun struct mu3c_ippc_regs __iomem *ippc_regs; 137065d48cfSChunfeng Yun bool has_ippc; 1380cbd4b34SChunfeng Yun int num_u2_ports; 1390cbd4b34SChunfeng Yun int num_u3_ports; 14055ba6e9eSChunfeng Yun int u3p_dis_msk; 1410cbd4b34SChunfeng Yun struct regulator *vusb33; 1420cbd4b34SChunfeng Yun struct regulator *vbus; 1430cbd4b34SChunfeng Yun struct clk *sys_clk; /* sys and mac clock */ 144b2fcb285SChunfeng Yun struct clk *xhci_clk; 1459c4afd42SChunfeng Yun struct clk *ref_clk; 146b6bb72cfSChunfeng Yun struct clk *mcu_clk; 147b6bb72cfSChunfeng Yun struct clk *dma_clk; 1480cbd4b34SChunfeng Yun struct regmap *pericfg; 1490cbd4b34SChunfeng Yun struct phy **phys; 1500cbd4b34SChunfeng Yun int num_phys; 1510cbd4b34SChunfeng Yun bool lpm_support; 152a2ecc4dfSChunfeng Yun /* usb remote wakeup */ 153a2ecc4dfSChunfeng Yun bool uwk_en; 154a2ecc4dfSChunfeng Yun struct regmap *uwk; 155a2ecc4dfSChunfeng Yun u32 uwk_reg_base; 156a2ecc4dfSChunfeng Yun u32 uwk_vers; 1570cbd4b34SChunfeng Yun }; 1580cbd4b34SChunfeng Yun 1590cbd4b34SChunfeng Yun static inline struct xhci_hcd_mtk *hcd_to_mtk(struct usb_hcd *hcd) 1600cbd4b34SChunfeng Yun { 1610cbd4b34SChunfeng Yun return dev_get_drvdata(hcd->self.controller); 1620cbd4b34SChunfeng Yun } 1630cbd4b34SChunfeng Yun 1640cbd4b34SChunfeng Yun #if IS_ENABLED(CONFIG_USB_XHCI_MTK) 1650cbd4b34SChunfeng Yun int xhci_mtk_sch_init(struct xhci_hcd_mtk *mtk); 1660cbd4b34SChunfeng Yun void xhci_mtk_sch_exit(struct xhci_hcd_mtk *mtk); 1670cbd4b34SChunfeng Yun int xhci_mtk_add_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev, 1680cbd4b34SChunfeng Yun struct usb_host_endpoint *ep); 1690cbd4b34SChunfeng Yun void xhci_mtk_drop_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev, 1700cbd4b34SChunfeng Yun struct usb_host_endpoint *ep); 1711d69f9d9SIkjoon Jang int xhci_mtk_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev); 1721d69f9d9SIkjoon Jang void xhci_mtk_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev); 1730cbd4b34SChunfeng Yun 1740cbd4b34SChunfeng Yun #else 1750cbd4b34SChunfeng Yun static inline int xhci_mtk_add_ep_quirk(struct usb_hcd *hcd, 1760cbd4b34SChunfeng Yun struct usb_device *udev, struct usb_host_endpoint *ep) 1770cbd4b34SChunfeng Yun { 1780cbd4b34SChunfeng Yun return 0; 1790cbd4b34SChunfeng Yun } 1800cbd4b34SChunfeng Yun 1810cbd4b34SChunfeng Yun static inline void xhci_mtk_drop_ep_quirk(struct usb_hcd *hcd, 1820cbd4b34SChunfeng Yun struct usb_device *udev, struct usb_host_endpoint *ep) 1830cbd4b34SChunfeng Yun { 1840cbd4b34SChunfeng Yun } 1850cbd4b34SChunfeng Yun 1861d69f9d9SIkjoon Jang static inline int xhci_mtk_check_bandwidth(struct usb_hcd *hcd, 1871d69f9d9SIkjoon Jang struct usb_device *udev) 1881d69f9d9SIkjoon Jang { 1891d69f9d9SIkjoon Jang return 0; 1901d69f9d9SIkjoon Jang } 1911d69f9d9SIkjoon Jang 1921d69f9d9SIkjoon Jang static inline void xhci_mtk_reset_bandwidth(struct usb_hcd *hcd, 1931d69f9d9SIkjoon Jang struct usb_device *udev) 1941d69f9d9SIkjoon Jang { 1951d69f9d9SIkjoon Jang } 1960cbd4b34SChunfeng Yun #endif 1970cbd4b34SChunfeng Yun 1980cbd4b34SChunfeng Yun #endif /* _XHCI_MTK_H_ */ 199