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 /** 230cbd4b34SChunfeng Yun * struct mu3h_sch_bw_info: schedule information for bandwidth domain 240cbd4b34SChunfeng Yun * 250cbd4b34SChunfeng Yun * @bus_bw: array to keep track of bandwidth already used at each uframes 260cbd4b34SChunfeng Yun * @bw_ep_list: eps in the bandwidth domain 270cbd4b34SChunfeng Yun * 280cbd4b34SChunfeng Yun * treat a HS root port as a bandwidth domain, but treat a SS root port as 290cbd4b34SChunfeng Yun * two bandwidth domains, one for IN eps and another for OUT eps. 300cbd4b34SChunfeng Yun */ 310cbd4b34SChunfeng Yun struct mu3h_sch_bw_info { 320cbd4b34SChunfeng Yun u32 bus_bw[XHCI_MTK_MAX_ESIT]; 330cbd4b34SChunfeng Yun struct list_head bw_ep_list; 340cbd4b34SChunfeng Yun }; 350cbd4b34SChunfeng Yun 360cbd4b34SChunfeng Yun /** 370cbd4b34SChunfeng Yun * struct mu3h_sch_ep_info: schedule information for endpoint 380cbd4b34SChunfeng Yun * 390cbd4b34SChunfeng Yun * @esit: unit is 125us, equal to 2 << Interval field in ep-context 400cbd4b34SChunfeng Yun * @num_budget_microframes: number of continuous uframes 410cbd4b34SChunfeng Yun * (@repeat==1) scheduled within the interval 420cbd4b34SChunfeng Yun * @bw_cost_per_microframe: bandwidth cost per microframe 430cbd4b34SChunfeng Yun * @endpoint: linked into bandwidth domain which it belongs to 440cbd4b34SChunfeng Yun * @ep: address of usb_host_endpoint struct 450cbd4b34SChunfeng Yun * @offset: which uframe of the interval that transfer should be 460cbd4b34SChunfeng Yun * scheduled first time within the interval 470cbd4b34SChunfeng Yun * @repeat: the time gap between two uframes that transfers are 480cbd4b34SChunfeng Yun * scheduled within a interval. in the simple algorithm, only 490cbd4b34SChunfeng Yun * assign 0 or 1 to it; 0 means using only one uframe in a 500cbd4b34SChunfeng Yun * interval, and 1 means using @num_budget_microframes 510cbd4b34SChunfeng Yun * continuous uframes 520cbd4b34SChunfeng Yun * @pkts: number of packets to be transferred in the scheduled uframes 530cbd4b34SChunfeng Yun * @cs_count: number of CS that host will trigger 540cbd4b34SChunfeng Yun * @burst_mode: burst mode for scheduling. 0: normal burst mode, 550cbd4b34SChunfeng Yun * distribute the bMaxBurst+1 packets for a single burst 560cbd4b34SChunfeng Yun * according to @pkts and @repeat, repeate the burst multiple 570cbd4b34SChunfeng Yun * times; 1: distribute the (bMaxBurst+1)*(Mult+1) packets 580cbd4b34SChunfeng Yun * according to @pkts and @repeat. normal mode is used by 590cbd4b34SChunfeng Yun * default 6095b516c1SChunfeng Yun * @bw_budget_table: table to record bandwidth budget per microframe 610cbd4b34SChunfeng Yun */ 620cbd4b34SChunfeng Yun struct mu3h_sch_ep_info { 630cbd4b34SChunfeng Yun u32 esit; 640cbd4b34SChunfeng Yun u32 num_budget_microframes; 650cbd4b34SChunfeng Yun u32 bw_cost_per_microframe; 660cbd4b34SChunfeng Yun struct list_head endpoint; 670cbd4b34SChunfeng Yun void *ep; 680cbd4b34SChunfeng Yun /* 690cbd4b34SChunfeng Yun * mtk xHCI scheduling information put into reserved DWs 700cbd4b34SChunfeng Yun * in ep context 710cbd4b34SChunfeng Yun */ 720cbd4b34SChunfeng Yun u32 offset; 730cbd4b34SChunfeng Yun u32 repeat; 740cbd4b34SChunfeng Yun u32 pkts; 750cbd4b34SChunfeng Yun u32 cs_count; 760cbd4b34SChunfeng Yun u32 burst_mode; 7795b516c1SChunfeng Yun u32 bw_budget_table[0]; 780cbd4b34SChunfeng Yun }; 790cbd4b34SChunfeng Yun 800cbd4b34SChunfeng Yun #define MU3C_U3_PORT_MAX 4 810cbd4b34SChunfeng Yun #define MU3C_U2_PORT_MAX 5 820cbd4b34SChunfeng Yun 830cbd4b34SChunfeng Yun /** 840cbd4b34SChunfeng Yun * struct mu3c_ippc_regs: MTK ssusb ip port control registers 850cbd4b34SChunfeng Yun * @ip_pw_ctr0~3: ip power and clock control registers 860cbd4b34SChunfeng Yun * @ip_pw_sts1~2: ip power and clock status registers 870cbd4b34SChunfeng Yun * @ip_xhci_cap: ip xHCI capability register 880cbd4b34SChunfeng Yun * @u3_ctrl_p[x]: ip usb3 port x control register, only low 4bytes are used 890cbd4b34SChunfeng Yun * @u2_ctrl_p[x]: ip usb2 port x control register, only low 4bytes are used 900cbd4b34SChunfeng Yun * @u2_phy_pll: usb2 phy pll control register 910cbd4b34SChunfeng Yun */ 920cbd4b34SChunfeng Yun struct mu3c_ippc_regs { 930cbd4b34SChunfeng Yun __le32 ip_pw_ctr0; 940cbd4b34SChunfeng Yun __le32 ip_pw_ctr1; 950cbd4b34SChunfeng Yun __le32 ip_pw_ctr2; 960cbd4b34SChunfeng Yun __le32 ip_pw_ctr3; 970cbd4b34SChunfeng Yun __le32 ip_pw_sts1; 980cbd4b34SChunfeng Yun __le32 ip_pw_sts2; 990cbd4b34SChunfeng Yun __le32 reserved0[3]; 1000cbd4b34SChunfeng Yun __le32 ip_xhci_cap; 1010cbd4b34SChunfeng Yun __le32 reserved1[2]; 1020cbd4b34SChunfeng Yun __le64 u3_ctrl_p[MU3C_U3_PORT_MAX]; 1030cbd4b34SChunfeng Yun __le64 u2_ctrl_p[MU3C_U2_PORT_MAX]; 1040cbd4b34SChunfeng Yun __le32 reserved2; 1050cbd4b34SChunfeng Yun __le32 u2_phy_pll; 1060cbd4b34SChunfeng Yun __le32 reserved3[33]; /* 0x80 ~ 0xff */ 1070cbd4b34SChunfeng Yun }; 1080cbd4b34SChunfeng Yun 1090cbd4b34SChunfeng Yun struct xhci_hcd_mtk { 1100cbd4b34SChunfeng Yun struct device *dev; 1110cbd4b34SChunfeng Yun struct usb_hcd *hcd; 1120cbd4b34SChunfeng Yun struct mu3h_sch_bw_info *sch_array; 1130cbd4b34SChunfeng Yun struct mu3c_ippc_regs __iomem *ippc_regs; 114065d48cfSChunfeng Yun bool has_ippc; 1150cbd4b34SChunfeng Yun int num_u2_ports; 1160cbd4b34SChunfeng Yun int num_u3_ports; 11755ba6e9eSChunfeng Yun int u3p_dis_msk; 1180cbd4b34SChunfeng Yun struct regulator *vusb33; 1190cbd4b34SChunfeng Yun struct regulator *vbus; 1200cbd4b34SChunfeng Yun struct clk *sys_clk; /* sys and mac clock */ 1219c4afd42SChunfeng Yun struct clk *ref_clk; 122b6bb72cfSChunfeng Yun struct clk *mcu_clk; 123b6bb72cfSChunfeng Yun struct clk *dma_clk; 1240cbd4b34SChunfeng Yun struct regmap *pericfg; 1250cbd4b34SChunfeng Yun struct phy **phys; 1260cbd4b34SChunfeng Yun int num_phys; 1270cbd4b34SChunfeng Yun bool lpm_support; 128a2ecc4dfSChunfeng Yun /* usb remote wakeup */ 129a2ecc4dfSChunfeng Yun bool uwk_en; 130a2ecc4dfSChunfeng Yun struct regmap *uwk; 131a2ecc4dfSChunfeng Yun u32 uwk_reg_base; 132a2ecc4dfSChunfeng Yun u32 uwk_vers; 1330cbd4b34SChunfeng Yun }; 1340cbd4b34SChunfeng Yun 1350cbd4b34SChunfeng Yun static inline struct xhci_hcd_mtk *hcd_to_mtk(struct usb_hcd *hcd) 1360cbd4b34SChunfeng Yun { 1370cbd4b34SChunfeng Yun return dev_get_drvdata(hcd->self.controller); 1380cbd4b34SChunfeng Yun } 1390cbd4b34SChunfeng Yun 1400cbd4b34SChunfeng Yun #if IS_ENABLED(CONFIG_USB_XHCI_MTK) 1410cbd4b34SChunfeng Yun int xhci_mtk_sch_init(struct xhci_hcd_mtk *mtk); 1420cbd4b34SChunfeng Yun void xhci_mtk_sch_exit(struct xhci_hcd_mtk *mtk); 1430cbd4b34SChunfeng Yun int xhci_mtk_add_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev, 1440cbd4b34SChunfeng Yun struct usb_host_endpoint *ep); 1450cbd4b34SChunfeng Yun void xhci_mtk_drop_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev, 1460cbd4b34SChunfeng Yun struct usb_host_endpoint *ep); 1470cbd4b34SChunfeng Yun 1480cbd4b34SChunfeng Yun #else 1490cbd4b34SChunfeng Yun static inline int xhci_mtk_add_ep_quirk(struct usb_hcd *hcd, 1500cbd4b34SChunfeng Yun struct usb_device *udev, struct usb_host_endpoint *ep) 1510cbd4b34SChunfeng Yun { 1520cbd4b34SChunfeng Yun return 0; 1530cbd4b34SChunfeng Yun } 1540cbd4b34SChunfeng Yun 1550cbd4b34SChunfeng Yun static inline void xhci_mtk_drop_ep_quirk(struct usb_hcd *hcd, 1560cbd4b34SChunfeng Yun struct usb_device *udev, struct usb_host_endpoint *ep) 1570cbd4b34SChunfeng Yun { 1580cbd4b34SChunfeng Yun } 1590cbd4b34SChunfeng Yun 1600cbd4b34SChunfeng Yun #endif 1610cbd4b34SChunfeng Yun 1620cbd4b34SChunfeng Yun #endif /* _XHCI_MTK_H_ */ 163