162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * mtu3.h - MediaTek USB3 DRD header 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright (C) 2016 MediaTek Inc. 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * Author: Chunfeng Yun <chunfeng.yun@mediatek.com> 862306a36Sopenharmony_ci */ 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#ifndef __MTU3_H__ 1162306a36Sopenharmony_ci#define __MTU3_H__ 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci#include <linux/clk.h> 1462306a36Sopenharmony_ci#include <linux/device.h> 1562306a36Sopenharmony_ci#include <linux/dmapool.h> 1662306a36Sopenharmony_ci#include <linux/extcon.h> 1762306a36Sopenharmony_ci#include <linux/interrupt.h> 1862306a36Sopenharmony_ci#include <linux/list.h> 1962306a36Sopenharmony_ci#include <linux/of.h> 2062306a36Sopenharmony_ci#include <linux/phy/phy.h> 2162306a36Sopenharmony_ci#include <linux/regulator/consumer.h> 2262306a36Sopenharmony_ci#include <linux/usb.h> 2362306a36Sopenharmony_ci#include <linux/usb/ch9.h> 2462306a36Sopenharmony_ci#include <linux/usb/gadget.h> 2562306a36Sopenharmony_ci#include <linux/usb/otg.h> 2662306a36Sopenharmony_ci#include <linux/usb/role.h> 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_cistruct mtu3; 2962306a36Sopenharmony_cistruct mtu3_ep; 3062306a36Sopenharmony_cistruct mtu3_request; 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci#include "mtu3_hw_regs.h" 3362306a36Sopenharmony_ci#include "mtu3_qmu.h" 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci#define MU3D_EP_TXCR0(epnum) (U3D_TX1CSR0 + (((epnum) - 1) * 0x10)) 3662306a36Sopenharmony_ci#define MU3D_EP_TXCR1(epnum) (U3D_TX1CSR1 + (((epnum) - 1) * 0x10)) 3762306a36Sopenharmony_ci#define MU3D_EP_TXCR2(epnum) (U3D_TX1CSR2 + (((epnum) - 1) * 0x10)) 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_ci#define MU3D_EP_RXCR0(epnum) (U3D_RX1CSR0 + (((epnum) - 1) * 0x10)) 4062306a36Sopenharmony_ci#define MU3D_EP_RXCR1(epnum) (U3D_RX1CSR1 + (((epnum) - 1) * 0x10)) 4162306a36Sopenharmony_ci#define MU3D_EP_RXCR2(epnum) (U3D_RX1CSR2 + (((epnum) - 1) * 0x10)) 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci#define USB_QMU_TQHIAR(epnum) (U3D_TXQHIAR1 + (((epnum) - 1) * 0x4)) 4462306a36Sopenharmony_ci#define USB_QMU_RQHIAR(epnum) (U3D_RXQHIAR1 + (((epnum) - 1) * 0x4)) 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ci#define USB_QMU_RQCSR(epnum) (U3D_RXQCSR1 + (((epnum) - 1) * 0x10)) 4762306a36Sopenharmony_ci#define USB_QMU_RQSAR(epnum) (U3D_RXQSAR1 + (((epnum) - 1) * 0x10)) 4862306a36Sopenharmony_ci#define USB_QMU_RQCPR(epnum) (U3D_RXQCPR1 + (((epnum) - 1) * 0x10)) 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_ci#define USB_QMU_TQCSR(epnum) (U3D_TXQCSR1 + (((epnum) - 1) * 0x10)) 5162306a36Sopenharmony_ci#define USB_QMU_TQSAR(epnum) (U3D_TXQSAR1 + (((epnum) - 1) * 0x10)) 5262306a36Sopenharmony_ci#define USB_QMU_TQCPR(epnum) (U3D_TXQCPR1 + (((epnum) - 1) * 0x10)) 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_ci#define SSUSB_U3_CTRL(p) (U3D_SSUSB_U3_CTRL_0P + ((p) * 0x08)) 5562306a36Sopenharmony_ci#define SSUSB_U2_CTRL(p) (U3D_SSUSB_U2_CTRL_0P + ((p) * 0x08)) 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ci#define MTU3_DRIVER_NAME "mtu3" 5862306a36Sopenharmony_ci#define DMA_ADDR_INVALID (~(dma_addr_t)0) 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci#define MTU3_EP_ENABLED BIT(0) 6162306a36Sopenharmony_ci#define MTU3_EP_STALL BIT(1) 6262306a36Sopenharmony_ci#define MTU3_EP_WEDGE BIT(2) 6362306a36Sopenharmony_ci#define MTU3_EP_BUSY BIT(3) 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ci#define MTU3_U3_IP_SLOT_DEFAULT 2 6662306a36Sopenharmony_ci#define MTU3_U2_IP_SLOT_DEFAULT 1 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ci/** 6962306a36Sopenharmony_ci * IP TRUNK version 7062306a36Sopenharmony_ci * from 0x1003 version, USB3 Gen2 is supported, two changes affect driver: 7162306a36Sopenharmony_ci * 1. MAXPKT and MULTI bits layout of TXCSR1 and RXCSR1 are adjusted, 7262306a36Sopenharmony_ci * but not backward compatible 7362306a36Sopenharmony_ci * 2. QMU extend buffer length supported 7462306a36Sopenharmony_ci */ 7562306a36Sopenharmony_ci#define MTU3_TRUNK_VERS_1003 0x1003 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ci/** 7862306a36Sopenharmony_ci * Normally the device works on HS or SS, to simplify fifo management, 7962306a36Sopenharmony_ci * devide fifo into some 512B parts, use bitmap to manage it; And 8062306a36Sopenharmony_ci * 128 bits size of bitmap is large enough, that means it can manage 8162306a36Sopenharmony_ci * up to 64KB fifo size. 8262306a36Sopenharmony_ci * NOTE: MTU3_EP_FIFO_UNIT should be power of two 8362306a36Sopenharmony_ci */ 8462306a36Sopenharmony_ci#define MTU3_EP_FIFO_UNIT (1 << 9) 8562306a36Sopenharmony_ci#define MTU3_FIFO_BIT_SIZE 128 8662306a36Sopenharmony_ci#define MTU3_U2_IP_EP0_FIFO_SIZE 64 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_ci/** 8962306a36Sopenharmony_ci * Maximum size of ep0 response buffer for ch9 requests, 9062306a36Sopenharmony_ci * the SET_SEL request uses 6 so far, and GET_STATUS is 2 9162306a36Sopenharmony_ci */ 9262306a36Sopenharmony_ci#define EP0_RESPONSE_BUF 6 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_ci#define BULK_CLKS_CNT 6 9562306a36Sopenharmony_ci 9662306a36Sopenharmony_ci/* device operated link and speed got from DEVICE_CONF register */ 9762306a36Sopenharmony_cienum mtu3_speed { 9862306a36Sopenharmony_ci MTU3_SPEED_INACTIVE = 0, 9962306a36Sopenharmony_ci MTU3_SPEED_FULL = 1, 10062306a36Sopenharmony_ci MTU3_SPEED_HIGH = 3, 10162306a36Sopenharmony_ci MTU3_SPEED_SUPER = 4, 10262306a36Sopenharmony_ci MTU3_SPEED_SUPER_PLUS = 5, 10362306a36Sopenharmony_ci}; 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_ci/** 10662306a36Sopenharmony_ci * @MU3D_EP0_STATE_SETUP: waits for SETUP or received a SETUP 10762306a36Sopenharmony_ci * without data stage. 10862306a36Sopenharmony_ci * @MU3D_EP0_STATE_TX: IN data stage 10962306a36Sopenharmony_ci * @MU3D_EP0_STATE_RX: OUT data stage 11062306a36Sopenharmony_ci * @MU3D_EP0_STATE_TX_END: the last IN data is transferred, and 11162306a36Sopenharmony_ci * waits for its completion interrupt 11262306a36Sopenharmony_ci * @MU3D_EP0_STATE_STALL: ep0 is in stall status, will be auto-cleared 11362306a36Sopenharmony_ci * after receives a SETUP. 11462306a36Sopenharmony_ci */ 11562306a36Sopenharmony_cienum mtu3_g_ep0_state { 11662306a36Sopenharmony_ci MU3D_EP0_STATE_SETUP = 1, 11762306a36Sopenharmony_ci MU3D_EP0_STATE_TX, 11862306a36Sopenharmony_ci MU3D_EP0_STATE_RX, 11962306a36Sopenharmony_ci MU3D_EP0_STATE_TX_END, 12062306a36Sopenharmony_ci MU3D_EP0_STATE_STALL, 12162306a36Sopenharmony_ci}; 12262306a36Sopenharmony_ci 12362306a36Sopenharmony_ci/** 12462306a36Sopenharmony_ci * MTU3_DR_FORCE_NONE: automatically switch host and periperal mode 12562306a36Sopenharmony_ci * by IDPIN signal. 12662306a36Sopenharmony_ci * MTU3_DR_FORCE_HOST: force to enter host mode and override OTG 12762306a36Sopenharmony_ci * IDPIN signal. 12862306a36Sopenharmony_ci * MTU3_DR_FORCE_DEVICE: force to enter peripheral mode. 12962306a36Sopenharmony_ci */ 13062306a36Sopenharmony_cienum mtu3_dr_force_mode { 13162306a36Sopenharmony_ci MTU3_DR_FORCE_NONE = 0, 13262306a36Sopenharmony_ci MTU3_DR_FORCE_HOST, 13362306a36Sopenharmony_ci MTU3_DR_FORCE_DEVICE, 13462306a36Sopenharmony_ci}; 13562306a36Sopenharmony_ci 13662306a36Sopenharmony_ci/** 13762306a36Sopenharmony_ci * @base: the base address of fifo 13862306a36Sopenharmony_ci * @limit: the bitmap size in bits 13962306a36Sopenharmony_ci * @bitmap: fifo bitmap in unit of @MTU3_EP_FIFO_UNIT 14062306a36Sopenharmony_ci */ 14162306a36Sopenharmony_cistruct mtu3_fifo_info { 14262306a36Sopenharmony_ci u32 base; 14362306a36Sopenharmony_ci u32 limit; 14462306a36Sopenharmony_ci DECLARE_BITMAP(bitmap, MTU3_FIFO_BIT_SIZE); 14562306a36Sopenharmony_ci}; 14662306a36Sopenharmony_ci 14762306a36Sopenharmony_ci/** 14862306a36Sopenharmony_ci * General Purpose Descriptor (GPD): 14962306a36Sopenharmony_ci * The format of TX GPD is a little different from RX one. 15062306a36Sopenharmony_ci * And the size of GPD is 16 bytes. 15162306a36Sopenharmony_ci * 15262306a36Sopenharmony_ci * @dw0_info: 15362306a36Sopenharmony_ci * bit0: Hardware Own (HWO) 15462306a36Sopenharmony_ci * bit1: Buffer Descriptor Present (BDP), always 0, BD is not supported 15562306a36Sopenharmony_ci * bit2: Bypass (BPS), 1: HW skips this GPD if HWO = 1 15662306a36Sopenharmony_ci * bit6: [EL] Zero Length Packet (ZLP), moved from @dw3_info[29] 15762306a36Sopenharmony_ci * bit7: Interrupt On Completion (IOC) 15862306a36Sopenharmony_ci * bit[31:16]: ([EL] bit[31:12]) allow data buffer length (RX ONLY), 15962306a36Sopenharmony_ci * the buffer length of the data to receive 16062306a36Sopenharmony_ci * bit[23:16]: ([EL] bit[31:24]) extension address (TX ONLY), 16162306a36Sopenharmony_ci * lower 4 bits are extension bits of @buffer, 16262306a36Sopenharmony_ci * upper 4 bits are extension bits of @next_gpd 16362306a36Sopenharmony_ci * @next_gpd: Physical address of the next GPD 16462306a36Sopenharmony_ci * @buffer: Physical address of the data buffer 16562306a36Sopenharmony_ci * @dw3_info: 16662306a36Sopenharmony_ci * bit[15:0]: ([EL] bit[19:0]) data buffer length, 16762306a36Sopenharmony_ci * (TX): the buffer length of the data to transmit 16862306a36Sopenharmony_ci * (RX): The total length of data received 16962306a36Sopenharmony_ci * bit[23:16]: ([EL] bit[31:24]) extension address (RX ONLY), 17062306a36Sopenharmony_ci * lower 4 bits are extension bits of @buffer, 17162306a36Sopenharmony_ci * upper 4 bits are extension bits of @next_gpd 17262306a36Sopenharmony_ci * bit29: ([EL] abandoned) Zero Length Packet (ZLP) (TX ONLY) 17362306a36Sopenharmony_ci */ 17462306a36Sopenharmony_cistruct qmu_gpd { 17562306a36Sopenharmony_ci __le32 dw0_info; 17662306a36Sopenharmony_ci __le32 next_gpd; 17762306a36Sopenharmony_ci __le32 buffer; 17862306a36Sopenharmony_ci __le32 dw3_info; 17962306a36Sopenharmony_ci} __packed; 18062306a36Sopenharmony_ci 18162306a36Sopenharmony_ci/** 18262306a36Sopenharmony_ci* dma: physical base address of GPD segment 18362306a36Sopenharmony_ci* start: virtual base address of GPD segment 18462306a36Sopenharmony_ci* end: the last GPD element 18562306a36Sopenharmony_ci* enqueue: the first empty GPD to use 18662306a36Sopenharmony_ci* dequeue: the first completed GPD serviced by ISR 18762306a36Sopenharmony_ci* NOTE: the size of GPD ring should be >= 2 18862306a36Sopenharmony_ci*/ 18962306a36Sopenharmony_cistruct mtu3_gpd_ring { 19062306a36Sopenharmony_ci dma_addr_t dma; 19162306a36Sopenharmony_ci struct qmu_gpd *start; 19262306a36Sopenharmony_ci struct qmu_gpd *end; 19362306a36Sopenharmony_ci struct qmu_gpd *enqueue; 19462306a36Sopenharmony_ci struct qmu_gpd *dequeue; 19562306a36Sopenharmony_ci}; 19662306a36Sopenharmony_ci 19762306a36Sopenharmony_ci/** 19862306a36Sopenharmony_ci* @vbus: vbus 5V used by host mode 19962306a36Sopenharmony_ci* @edev: external connector used to detect vbus and iddig changes 20062306a36Sopenharmony_ci* @id_nb : notifier for iddig(idpin) detection 20162306a36Sopenharmony_ci* @dr_work : work for drd mode switch, used to avoid sleep in atomic context 20262306a36Sopenharmony_ci* @desired_role : role desired to switch 20362306a36Sopenharmony_ci* @default_role : default mode while usb role is USB_ROLE_NONE 20462306a36Sopenharmony_ci* @role_sw : use USB Role Switch to support dual-role switch, can't use 20562306a36Sopenharmony_ci* extcon at the same time, and extcon is deprecated. 20662306a36Sopenharmony_ci* @role_sw_used : true when the USB Role Switch is used. 20762306a36Sopenharmony_ci* @is_u3_drd: whether port0 supports usb3.0 dual-role device or not 20862306a36Sopenharmony_ci* @manual_drd_enabled: it's true when supports dual-role device by debugfs 20962306a36Sopenharmony_ci* to switch host/device modes depending on user input. 21062306a36Sopenharmony_ci*/ 21162306a36Sopenharmony_cistruct otg_switch_mtk { 21262306a36Sopenharmony_ci struct regulator *vbus; 21362306a36Sopenharmony_ci struct extcon_dev *edev; 21462306a36Sopenharmony_ci struct notifier_block id_nb; 21562306a36Sopenharmony_ci struct work_struct dr_work; 21662306a36Sopenharmony_ci enum usb_role desired_role; 21762306a36Sopenharmony_ci enum usb_role default_role; 21862306a36Sopenharmony_ci struct usb_role_switch *role_sw; 21962306a36Sopenharmony_ci bool role_sw_used; 22062306a36Sopenharmony_ci bool is_u3_drd; 22162306a36Sopenharmony_ci bool manual_drd_enabled; 22262306a36Sopenharmony_ci}; 22362306a36Sopenharmony_ci 22462306a36Sopenharmony_ci/** 22562306a36Sopenharmony_ci * @mac_base: register base address of device MAC, exclude xHCI's 22662306a36Sopenharmony_ci * @ippc_base: register base address of IP Power and Clock interface (IPPC) 22762306a36Sopenharmony_ci * @vusb33: usb3.3V shared by device/host IP 22862306a36Sopenharmony_ci * @dr_mode: works in which mode: 22962306a36Sopenharmony_ci * host only, device only or dual-role mode 23062306a36Sopenharmony_ci * @u2_ports: number of usb2.0 host ports 23162306a36Sopenharmony_ci * @u3_ports: number of usb3.0 host ports 23262306a36Sopenharmony_ci * @u2p_dis_msk: mask of disabling usb2 ports, e.g. bit0==1 to 23362306a36Sopenharmony_ci * disable u2port0, bit1==1 to disable u2port1,... etc, 23462306a36Sopenharmony_ci * but when use dual-role mode, can't disable u2port0 23562306a36Sopenharmony_ci * @u3p_dis_msk: mask of disabling usb3 ports, for example, bit0==1 to 23662306a36Sopenharmony_ci * disable u3port0, bit1==1 to disable u3port1,... etc 23762306a36Sopenharmony_ci * @dbgfs_root: only used when supports manual dual-role switch via debugfs 23862306a36Sopenharmony_ci * @uwk_en: it's true when supports remote wakeup in host mode 23962306a36Sopenharmony_ci * @uwk: syscon including usb wakeup glue layer between SSUSB IP and SPM 24062306a36Sopenharmony_ci * @uwk_reg_base: the base address of the wakeup glue layer in @uwk 24162306a36Sopenharmony_ci * @uwk_vers: the version of the wakeup glue layer 24262306a36Sopenharmony_ci */ 24362306a36Sopenharmony_cistruct ssusb_mtk { 24462306a36Sopenharmony_ci struct device *dev; 24562306a36Sopenharmony_ci struct mtu3 *u3d; 24662306a36Sopenharmony_ci void __iomem *mac_base; 24762306a36Sopenharmony_ci void __iomem *ippc_base; 24862306a36Sopenharmony_ci struct phy **phys; 24962306a36Sopenharmony_ci int num_phys; 25062306a36Sopenharmony_ci int wakeup_irq; 25162306a36Sopenharmony_ci /* common power & clock */ 25262306a36Sopenharmony_ci struct regulator *vusb33; 25362306a36Sopenharmony_ci struct clk_bulk_data clks[BULK_CLKS_CNT]; 25462306a36Sopenharmony_ci /* otg */ 25562306a36Sopenharmony_ci struct otg_switch_mtk otg_switch; 25662306a36Sopenharmony_ci enum usb_dr_mode dr_mode; 25762306a36Sopenharmony_ci bool is_host; 25862306a36Sopenharmony_ci int u2_ports; 25962306a36Sopenharmony_ci int u3_ports; 26062306a36Sopenharmony_ci int u2p_dis_msk; 26162306a36Sopenharmony_ci int u3p_dis_msk; 26262306a36Sopenharmony_ci struct dentry *dbgfs_root; 26362306a36Sopenharmony_ci /* usb wakeup for host mode */ 26462306a36Sopenharmony_ci bool uwk_en; 26562306a36Sopenharmony_ci struct regmap *uwk; 26662306a36Sopenharmony_ci u32 uwk_reg_base; 26762306a36Sopenharmony_ci u32 uwk_vers; 26862306a36Sopenharmony_ci}; 26962306a36Sopenharmony_ci 27062306a36Sopenharmony_ci/** 27162306a36Sopenharmony_ci * @fifo_size: it is (@slot + 1) * @fifo_seg_size 27262306a36Sopenharmony_ci * @fifo_seg_size: it is roundup_pow_of_two(@maxp) 27362306a36Sopenharmony_ci */ 27462306a36Sopenharmony_cistruct mtu3_ep { 27562306a36Sopenharmony_ci struct usb_ep ep; 27662306a36Sopenharmony_ci char name[12]; 27762306a36Sopenharmony_ci struct mtu3 *mtu; 27862306a36Sopenharmony_ci u8 epnum; 27962306a36Sopenharmony_ci u8 type; 28062306a36Sopenharmony_ci u8 is_in; 28162306a36Sopenharmony_ci u16 maxp; 28262306a36Sopenharmony_ci int slot; 28362306a36Sopenharmony_ci u32 fifo_size; 28462306a36Sopenharmony_ci u32 fifo_addr; 28562306a36Sopenharmony_ci u32 fifo_seg_size; 28662306a36Sopenharmony_ci struct mtu3_fifo_info *fifo; 28762306a36Sopenharmony_ci 28862306a36Sopenharmony_ci struct list_head req_list; 28962306a36Sopenharmony_ci struct mtu3_gpd_ring gpd_ring; 29062306a36Sopenharmony_ci const struct usb_ss_ep_comp_descriptor *comp_desc; 29162306a36Sopenharmony_ci const struct usb_endpoint_descriptor *desc; 29262306a36Sopenharmony_ci 29362306a36Sopenharmony_ci int flags; 29462306a36Sopenharmony_ci}; 29562306a36Sopenharmony_ci 29662306a36Sopenharmony_cistruct mtu3_request { 29762306a36Sopenharmony_ci struct usb_request request; 29862306a36Sopenharmony_ci struct list_head list; 29962306a36Sopenharmony_ci struct mtu3_ep *mep; 30062306a36Sopenharmony_ci struct mtu3 *mtu; 30162306a36Sopenharmony_ci struct qmu_gpd *gpd; 30262306a36Sopenharmony_ci int epnum; 30362306a36Sopenharmony_ci}; 30462306a36Sopenharmony_ci 30562306a36Sopenharmony_cistatic inline struct ssusb_mtk *dev_to_ssusb(struct device *dev) 30662306a36Sopenharmony_ci{ 30762306a36Sopenharmony_ci return dev_get_drvdata(dev); 30862306a36Sopenharmony_ci} 30962306a36Sopenharmony_ci 31062306a36Sopenharmony_ci/** 31162306a36Sopenharmony_ci * struct mtu3 - device driver instance data. 31262306a36Sopenharmony_ci * @slot: MTU3_U2_IP_SLOT_DEFAULT for U2 IP only, 31362306a36Sopenharmony_ci * MTU3_U3_IP_SLOT_DEFAULT for U3 IP 31462306a36Sopenharmony_ci * @may_wakeup: means device's remote wakeup is enabled 31562306a36Sopenharmony_ci * @is_self_powered: is reported in device status and the config descriptor 31662306a36Sopenharmony_ci * @delayed_status: true when function drivers ask for delayed status 31762306a36Sopenharmony_ci * @gen2cp: compatible with USB3 Gen2 IP 31862306a36Sopenharmony_ci * @ep0_req: dummy request used while handling standard USB requests 31962306a36Sopenharmony_ci * for GET_STATUS and SET_SEL 32062306a36Sopenharmony_ci * @setup_buf: ep0 response buffer for GET_STATUS and SET_SEL requests 32162306a36Sopenharmony_ci * @u3_capable: is capable of supporting USB3 32262306a36Sopenharmony_ci */ 32362306a36Sopenharmony_cistruct mtu3 { 32462306a36Sopenharmony_ci spinlock_t lock; 32562306a36Sopenharmony_ci struct ssusb_mtk *ssusb; 32662306a36Sopenharmony_ci struct device *dev; 32762306a36Sopenharmony_ci void __iomem *mac_base; 32862306a36Sopenharmony_ci void __iomem *ippc_base; 32962306a36Sopenharmony_ci int irq; 33062306a36Sopenharmony_ci 33162306a36Sopenharmony_ci struct mtu3_fifo_info tx_fifo; 33262306a36Sopenharmony_ci struct mtu3_fifo_info rx_fifo; 33362306a36Sopenharmony_ci 33462306a36Sopenharmony_ci struct mtu3_ep *ep_array; 33562306a36Sopenharmony_ci struct mtu3_ep *in_eps; 33662306a36Sopenharmony_ci struct mtu3_ep *out_eps; 33762306a36Sopenharmony_ci struct mtu3_ep *ep0; 33862306a36Sopenharmony_ci int num_eps; 33962306a36Sopenharmony_ci int slot; 34062306a36Sopenharmony_ci int active_ep; 34162306a36Sopenharmony_ci 34262306a36Sopenharmony_ci struct dma_pool *qmu_gpd_pool; 34362306a36Sopenharmony_ci enum mtu3_g_ep0_state ep0_state; 34462306a36Sopenharmony_ci struct usb_gadget g; /* the gadget */ 34562306a36Sopenharmony_ci struct usb_gadget_driver *gadget_driver; 34662306a36Sopenharmony_ci struct mtu3_request ep0_req; 34762306a36Sopenharmony_ci u8 setup_buf[EP0_RESPONSE_BUF]; 34862306a36Sopenharmony_ci enum usb_device_speed max_speed; 34962306a36Sopenharmony_ci enum usb_device_speed speed; 35062306a36Sopenharmony_ci 35162306a36Sopenharmony_ci unsigned is_active:1; 35262306a36Sopenharmony_ci unsigned may_wakeup:1; 35362306a36Sopenharmony_ci unsigned is_self_powered:1; 35462306a36Sopenharmony_ci unsigned test_mode:1; 35562306a36Sopenharmony_ci unsigned softconnect:1; 35662306a36Sopenharmony_ci unsigned u1_enable:1; 35762306a36Sopenharmony_ci unsigned u2_enable:1; 35862306a36Sopenharmony_ci unsigned u3_capable:1; 35962306a36Sopenharmony_ci unsigned delayed_status:1; 36062306a36Sopenharmony_ci unsigned gen2cp:1; 36162306a36Sopenharmony_ci unsigned connected:1; 36262306a36Sopenharmony_ci unsigned async_callbacks:1; 36362306a36Sopenharmony_ci unsigned separate_fifo:1; 36462306a36Sopenharmony_ci 36562306a36Sopenharmony_ci u8 address; 36662306a36Sopenharmony_ci u8 test_mode_nr; 36762306a36Sopenharmony_ci u32 hw_version; 36862306a36Sopenharmony_ci}; 36962306a36Sopenharmony_ci 37062306a36Sopenharmony_cistatic inline struct mtu3 *gadget_to_mtu3(struct usb_gadget *g) 37162306a36Sopenharmony_ci{ 37262306a36Sopenharmony_ci return container_of(g, struct mtu3, g); 37362306a36Sopenharmony_ci} 37462306a36Sopenharmony_ci 37562306a36Sopenharmony_cistatic inline struct mtu3_request *to_mtu3_request(struct usb_request *req) 37662306a36Sopenharmony_ci{ 37762306a36Sopenharmony_ci return req ? container_of(req, struct mtu3_request, request) : NULL; 37862306a36Sopenharmony_ci} 37962306a36Sopenharmony_ci 38062306a36Sopenharmony_cistatic inline struct mtu3_ep *to_mtu3_ep(struct usb_ep *ep) 38162306a36Sopenharmony_ci{ 38262306a36Sopenharmony_ci return ep ? container_of(ep, struct mtu3_ep, ep) : NULL; 38362306a36Sopenharmony_ci} 38462306a36Sopenharmony_ci 38562306a36Sopenharmony_cistatic inline struct mtu3_request *next_request(struct mtu3_ep *mep) 38662306a36Sopenharmony_ci{ 38762306a36Sopenharmony_ci return list_first_entry_or_null(&mep->req_list, struct mtu3_request, 38862306a36Sopenharmony_ci list); 38962306a36Sopenharmony_ci} 39062306a36Sopenharmony_ci 39162306a36Sopenharmony_cistatic inline void mtu3_writel(void __iomem *base, u32 offset, u32 data) 39262306a36Sopenharmony_ci{ 39362306a36Sopenharmony_ci writel(data, base + offset); 39462306a36Sopenharmony_ci} 39562306a36Sopenharmony_ci 39662306a36Sopenharmony_cistatic inline u32 mtu3_readl(void __iomem *base, u32 offset) 39762306a36Sopenharmony_ci{ 39862306a36Sopenharmony_ci return readl(base + offset); 39962306a36Sopenharmony_ci} 40062306a36Sopenharmony_ci 40162306a36Sopenharmony_cistatic inline void mtu3_setbits(void __iomem *base, u32 offset, u32 bits) 40262306a36Sopenharmony_ci{ 40362306a36Sopenharmony_ci void __iomem *addr = base + offset; 40462306a36Sopenharmony_ci u32 tmp = readl(addr); 40562306a36Sopenharmony_ci 40662306a36Sopenharmony_ci writel((tmp | (bits)), addr); 40762306a36Sopenharmony_ci} 40862306a36Sopenharmony_ci 40962306a36Sopenharmony_cistatic inline void mtu3_clrbits(void __iomem *base, u32 offset, u32 bits) 41062306a36Sopenharmony_ci{ 41162306a36Sopenharmony_ci void __iomem *addr = base + offset; 41262306a36Sopenharmony_ci u32 tmp = readl(addr); 41362306a36Sopenharmony_ci 41462306a36Sopenharmony_ci writel((tmp & ~(bits)), addr); 41562306a36Sopenharmony_ci} 41662306a36Sopenharmony_ci 41762306a36Sopenharmony_ciint ssusb_check_clocks(struct ssusb_mtk *ssusb, u32 ex_clks); 41862306a36Sopenharmony_cistruct usb_request *mtu3_alloc_request(struct usb_ep *ep, gfp_t gfp_flags); 41962306a36Sopenharmony_civoid mtu3_free_request(struct usb_ep *ep, struct usb_request *req); 42062306a36Sopenharmony_civoid mtu3_req_complete(struct mtu3_ep *mep, 42162306a36Sopenharmony_ci struct usb_request *req, int status); 42262306a36Sopenharmony_ci 42362306a36Sopenharmony_ciint mtu3_config_ep(struct mtu3 *mtu, struct mtu3_ep *mep, 42462306a36Sopenharmony_ci int interval, int burst, int mult); 42562306a36Sopenharmony_civoid mtu3_deconfig_ep(struct mtu3 *mtu, struct mtu3_ep *mep); 42662306a36Sopenharmony_civoid mtu3_ep_stall_set(struct mtu3_ep *mep, bool set); 42762306a36Sopenharmony_civoid mtu3_start(struct mtu3 *mtu); 42862306a36Sopenharmony_civoid mtu3_stop(struct mtu3 *mtu); 42962306a36Sopenharmony_civoid mtu3_dev_on_off(struct mtu3 *mtu, int is_on); 43062306a36Sopenharmony_ci 43162306a36Sopenharmony_ciint mtu3_gadget_setup(struct mtu3 *mtu); 43262306a36Sopenharmony_civoid mtu3_gadget_cleanup(struct mtu3 *mtu); 43362306a36Sopenharmony_civoid mtu3_gadget_reset(struct mtu3 *mtu); 43462306a36Sopenharmony_civoid mtu3_gadget_suspend(struct mtu3 *mtu); 43562306a36Sopenharmony_civoid mtu3_gadget_resume(struct mtu3 *mtu); 43662306a36Sopenharmony_civoid mtu3_gadget_disconnect(struct mtu3 *mtu); 43762306a36Sopenharmony_ci 43862306a36Sopenharmony_ciirqreturn_t mtu3_ep0_isr(struct mtu3 *mtu); 43962306a36Sopenharmony_ciextern const struct usb_ep_ops mtu3_ep0_ops; 44062306a36Sopenharmony_ci 44162306a36Sopenharmony_ci#endif 442