15fd54aceSGreg Kroah-Hartman // 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 /** 2308e469deSChunfeng Yun * @split_bit_map: used to avoid split microframes overlay 2408e469deSChunfeng Yun * @ep_list: Endpoints using this TT 2508e469deSChunfeng Yun * @usb_tt: usb TT related 2608e469deSChunfeng Yun * @tt_port: TT port number 2708e469deSChunfeng Yun */ 2808e469deSChunfeng Yun struct mu3h_sch_tt { 2908e469deSChunfeng Yun DECLARE_BITMAP(split_bit_map, XHCI_MTK_MAX_ESIT); 3008e469deSChunfeng Yun struct list_head ep_list; 3108e469deSChunfeng Yun struct usb_tt *usb_tt; 3208e469deSChunfeng Yun int tt_port; 3308e469deSChunfeng Yun }; 3408e469deSChunfeng Yun 3508e469deSChunfeng Yun /** 360cbd4b34SChunfeng Yun * struct mu3h_sch_bw_info: schedule information for bandwidth domain 370cbd4b34SChunfeng Yun * 380cbd4b34SChunfeng Yun * @bus_bw: array to keep track of bandwidth already used at each uframes 390cbd4b34SChunfeng Yun * @bw_ep_list: eps in the bandwidth domain 400cbd4b34SChunfeng Yun * 410cbd4b34SChunfeng Yun * treat a HS root port as a bandwidth domain, but treat a SS root port as 420cbd4b34SChunfeng Yun * two bandwidth domains, one for IN eps and another for OUT eps. 430cbd4b34SChunfeng Yun */ 440cbd4b34SChunfeng Yun struct mu3h_sch_bw_info { 450cbd4b34SChunfeng Yun u32 bus_bw[XHCI_MTK_MAX_ESIT]; 460cbd4b34SChunfeng Yun struct list_head bw_ep_list; 470cbd4b34SChunfeng Yun }; 480cbd4b34SChunfeng Yun 490cbd4b34SChunfeng Yun /** 500cbd4b34SChunfeng Yun * struct mu3h_sch_ep_info: schedule information for endpoint 510cbd4b34SChunfeng Yun * 520cbd4b34SChunfeng Yun * @esit: unit is 125us, equal to 2 << Interval field in ep-context 530cbd4b34SChunfeng Yun * @num_budget_microframes: number of continuous uframes 540cbd4b34SChunfeng Yun * (@repeat==1) scheduled within the interval 550cbd4b34SChunfeng Yun * @bw_cost_per_microframe: bandwidth cost per microframe 560cbd4b34SChunfeng Yun * @endpoint: linked into bandwidth domain which it belongs to 5708e469deSChunfeng Yun * @tt_endpoint: linked into mu3h_sch_tt's list which it belongs to 5808e469deSChunfeng Yun * @sch_tt: mu3h_sch_tt linked into 5908e469deSChunfeng Yun * @ep_type: endpoint type 6008e469deSChunfeng Yun * @maxpkt: max packet size of endpoint 610cbd4b34SChunfeng Yun * @ep: address of usb_host_endpoint struct 620cbd4b34SChunfeng Yun * @offset: which uframe of the interval that transfer should be 630cbd4b34SChunfeng Yun * scheduled first time within the interval 640cbd4b34SChunfeng Yun * @repeat: the time gap between two uframes that transfers are 650cbd4b34SChunfeng Yun * scheduled within a interval. in the simple algorithm, only 660cbd4b34SChunfeng Yun * assign 0 or 1 to it; 0 means using only one uframe in a 670cbd4b34SChunfeng Yun * interval, and 1 means using @num_budget_microframes 680cbd4b34SChunfeng Yun * continuous uframes 690cbd4b34SChunfeng Yun * @pkts: number of packets to be transferred in the scheduled uframes 700cbd4b34SChunfeng Yun * @cs_count: number of CS that host will trigger 710cbd4b34SChunfeng Yun * @burst_mode: burst mode for scheduling. 0: normal burst mode, 720cbd4b34SChunfeng Yun * distribute the bMaxBurst+1 packets for a single burst 730cbd4b34SChunfeng Yun * according to @pkts and @repeat, repeate the burst multiple 740cbd4b34SChunfeng Yun * times; 1: distribute the (bMaxBurst+1)*(Mult+1) packets 750cbd4b34SChunfeng Yun * according to @pkts and @repeat. normal mode is used by 760cbd4b34SChunfeng Yun * default 7795b516c1SChunfeng Yun * @bw_budget_table: table to record bandwidth budget per microframe 780cbd4b34SChunfeng Yun */ 790cbd4b34SChunfeng Yun struct mu3h_sch_ep_info { 800cbd4b34SChunfeng Yun u32 esit; 810cbd4b34SChunfeng Yun u32 num_budget_microframes; 820cbd4b34SChunfeng Yun u32 bw_cost_per_microframe; 830cbd4b34SChunfeng Yun struct list_head endpoint; 8408e469deSChunfeng Yun struct list_head tt_endpoint; 8508e469deSChunfeng Yun struct mu3h_sch_tt *sch_tt; 8608e469deSChunfeng Yun u32 ep_type; 8708e469deSChunfeng Yun u32 maxpkt; 880cbd4b34SChunfeng Yun void *ep; 890cbd4b34SChunfeng Yun /* 900cbd4b34SChunfeng Yun * mtk xHCI scheduling information put into reserved DWs 910cbd4b34SChunfeng Yun * in ep context 920cbd4b34SChunfeng Yun */ 930cbd4b34SChunfeng Yun u32 offset; 940cbd4b34SChunfeng Yun u32 repeat; 950cbd4b34SChunfeng Yun u32 pkts; 960cbd4b34SChunfeng Yun u32 cs_count; 970cbd4b34SChunfeng Yun u32 burst_mode; 9895b516c1SChunfeng Yun u32 bw_budget_table[0]; 990cbd4b34SChunfeng Yun }; 1000cbd4b34SChunfeng Yun 1010cbd4b34SChunfeng Yun #define MU3C_U3_PORT_MAX 4 1020cbd4b34SChunfeng Yun #define MU3C_U2_PORT_MAX 5 1030cbd4b34SChunfeng Yun 1040cbd4b34SChunfeng Yun /** 1050cbd4b34SChunfeng Yun * struct mu3c_ippc_regs: MTK ssusb ip port control registers 1060cbd4b34SChunfeng Yun * @ip_pw_ctr0~3: ip power and clock control registers 1070cbd4b34SChunfeng Yun * @ip_pw_sts1~2: ip power and clock status registers 1080cbd4b34SChunfeng Yun * @ip_xhci_cap: ip xHCI capability register 1090cbd4b34SChunfeng Yun * @u3_ctrl_p[x]: ip usb3 port x control register, only low 4bytes are used 1100cbd4b34SChunfeng Yun * @u2_ctrl_p[x]: ip usb2 port x control register, only low 4bytes are used 1110cbd4b34SChunfeng Yun * @u2_phy_pll: usb2 phy pll control register 1120cbd4b34SChunfeng Yun */ 1130cbd4b34SChunfeng Yun struct mu3c_ippc_regs { 1140cbd4b34SChunfeng Yun __le32 ip_pw_ctr0; 1150cbd4b34SChunfeng Yun __le32 ip_pw_ctr1; 1160cbd4b34SChunfeng Yun __le32 ip_pw_ctr2; 1170cbd4b34SChunfeng Yun __le32 ip_pw_ctr3; 1180cbd4b34SChunfeng Yun __le32 ip_pw_sts1; 1190cbd4b34SChunfeng Yun __le32 ip_pw_sts2; 1200cbd4b34SChunfeng Yun __le32 reserved0[3]; 1210cbd4b34SChunfeng Yun __le32 ip_xhci_cap; 1220cbd4b34SChunfeng Yun __le32 reserved1[2]; 1230cbd4b34SChunfeng Yun __le64 u3_ctrl_p[MU3C_U3_PORT_MAX]; 1240cbd4b34SChunfeng Yun __le64 u2_ctrl_p[MU3C_U2_PORT_MAX]; 1250cbd4b34SChunfeng Yun __le32 reserved2; 1260cbd4b34SChunfeng Yun __le32 u2_phy_pll; 1270cbd4b34SChunfeng Yun __le32 reserved3[33]; /* 0x80 ~ 0xff */ 1280cbd4b34SChunfeng Yun }; 1290cbd4b34SChunfeng Yun 1300cbd4b34SChunfeng Yun struct xhci_hcd_mtk { 1310cbd4b34SChunfeng Yun struct device *dev; 1320cbd4b34SChunfeng Yun struct usb_hcd *hcd; 1330cbd4b34SChunfeng Yun struct mu3h_sch_bw_info *sch_array; 1340cbd4b34SChunfeng Yun struct mu3c_ippc_regs __iomem *ippc_regs; 135065d48cfSChunfeng Yun bool has_ippc; 1360cbd4b34SChunfeng Yun int num_u2_ports; 1370cbd4b34SChunfeng Yun int num_u3_ports; 13855ba6e9eSChunfeng Yun int u3p_dis_msk; 1390cbd4b34SChunfeng Yun struct regulator *vusb33; 1400cbd4b34SChunfeng Yun struct regulator *vbus; 1410cbd4b34SChunfeng Yun struct clk *sys_clk; /* sys and mac clock */ 1429c4afd42SChunfeng Yun struct clk *ref_clk; 143b6bb72cfSChunfeng Yun struct clk *mcu_clk; 144b6bb72cfSChunfeng Yun struct clk *dma_clk; 1450cbd4b34SChunfeng Yun struct regmap *pericfg; 1460cbd4b34SChunfeng Yun struct phy **phys; 1470cbd4b34SChunfeng Yun int num_phys; 1480cbd4b34SChunfeng Yun bool lpm_support; 149a2ecc4dfSChunfeng Yun /* usb remote wakeup */ 150a2ecc4dfSChunfeng Yun bool uwk_en; 151a2ecc4dfSChunfeng Yun struct regmap *uwk; 152a2ecc4dfSChunfeng Yun u32 uwk_reg_base; 153a2ecc4dfSChunfeng Yun u32 uwk_vers; 1540cbd4b34SChunfeng Yun }; 1550cbd4b34SChunfeng Yun 1560cbd4b34SChunfeng Yun static inline struct xhci_hcd_mtk *hcd_to_mtk(struct usb_hcd *hcd) 1570cbd4b34SChunfeng Yun { 1580cbd4b34SChunfeng Yun return dev_get_drvdata(hcd->self.controller); 1590cbd4b34SChunfeng Yun } 1600cbd4b34SChunfeng Yun 1610cbd4b34SChunfeng Yun #if IS_ENABLED(CONFIG_USB_XHCI_MTK) 1620cbd4b34SChunfeng Yun int xhci_mtk_sch_init(struct xhci_hcd_mtk *mtk); 1630cbd4b34SChunfeng Yun void xhci_mtk_sch_exit(struct xhci_hcd_mtk *mtk); 1640cbd4b34SChunfeng Yun int xhci_mtk_add_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev, 1650cbd4b34SChunfeng Yun struct usb_host_endpoint *ep); 1660cbd4b34SChunfeng Yun void xhci_mtk_drop_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev, 1670cbd4b34SChunfeng Yun struct usb_host_endpoint *ep); 1680cbd4b34SChunfeng Yun 1690cbd4b34SChunfeng Yun #else 1700cbd4b34SChunfeng Yun static inline int xhci_mtk_add_ep_quirk(struct usb_hcd *hcd, 1710cbd4b34SChunfeng Yun struct usb_device *udev, struct usb_host_endpoint *ep) 1720cbd4b34SChunfeng Yun { 1730cbd4b34SChunfeng Yun return 0; 1740cbd4b34SChunfeng Yun } 1750cbd4b34SChunfeng Yun 1760cbd4b34SChunfeng Yun static inline void xhci_mtk_drop_ep_quirk(struct usb_hcd *hcd, 1770cbd4b34SChunfeng Yun struct usb_device *udev, struct usb_host_endpoint *ep) 1780cbd4b34SChunfeng Yun { 1790cbd4b34SChunfeng Yun } 1800cbd4b34SChunfeng Yun 1810cbd4b34SChunfeng Yun #endif 1820cbd4b34SChunfeng Yun 1830cbd4b34SChunfeng Yun #endif /* _XHCI_MTK_H_ */ 184