162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (C) 2011 Marvell International Ltd. All rights reserved.
462306a36Sopenharmony_ci */
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci#ifndef	__MV_USB_OTG_CONTROLLER__
762306a36Sopenharmony_ci#define	__MV_USB_OTG_CONTROLLER__
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#include <linux/types.h>
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci/* Command Register Bit Masks */
1262306a36Sopenharmony_ci#define USBCMD_RUN_STOP			(0x00000001)
1362306a36Sopenharmony_ci#define USBCMD_CTRL_RESET		(0x00000002)
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci/* otgsc Register Bit Masks */
1662306a36Sopenharmony_ci#define OTGSC_CTRL_VUSB_DISCHARGE		0x00000001
1762306a36Sopenharmony_ci#define OTGSC_CTRL_VUSB_CHARGE			0x00000002
1862306a36Sopenharmony_ci#define OTGSC_CTRL_OTG_TERM			0x00000008
1962306a36Sopenharmony_ci#define OTGSC_CTRL_DATA_PULSING			0x00000010
2062306a36Sopenharmony_ci#define OTGSC_STS_USB_ID			0x00000100
2162306a36Sopenharmony_ci#define OTGSC_STS_A_VBUS_VALID			0x00000200
2262306a36Sopenharmony_ci#define OTGSC_STS_A_SESSION_VALID		0x00000400
2362306a36Sopenharmony_ci#define OTGSC_STS_B_SESSION_VALID		0x00000800
2462306a36Sopenharmony_ci#define OTGSC_STS_B_SESSION_END			0x00001000
2562306a36Sopenharmony_ci#define OTGSC_STS_1MS_TOGGLE			0x00002000
2662306a36Sopenharmony_ci#define OTGSC_STS_DATA_PULSING			0x00004000
2762306a36Sopenharmony_ci#define OTGSC_INTSTS_USB_ID			0x00010000
2862306a36Sopenharmony_ci#define OTGSC_INTSTS_A_VBUS_VALID		0x00020000
2962306a36Sopenharmony_ci#define OTGSC_INTSTS_A_SESSION_VALID		0x00040000
3062306a36Sopenharmony_ci#define OTGSC_INTSTS_B_SESSION_VALID		0x00080000
3162306a36Sopenharmony_ci#define OTGSC_INTSTS_B_SESSION_END		0x00100000
3262306a36Sopenharmony_ci#define OTGSC_INTSTS_1MS			0x00200000
3362306a36Sopenharmony_ci#define OTGSC_INTSTS_DATA_PULSING		0x00400000
3462306a36Sopenharmony_ci#define OTGSC_INTR_USB_ID			0x01000000
3562306a36Sopenharmony_ci#define OTGSC_INTR_A_VBUS_VALID			0x02000000
3662306a36Sopenharmony_ci#define OTGSC_INTR_A_SESSION_VALID		0x04000000
3762306a36Sopenharmony_ci#define OTGSC_INTR_B_SESSION_VALID		0x08000000
3862306a36Sopenharmony_ci#define OTGSC_INTR_B_SESSION_END		0x10000000
3962306a36Sopenharmony_ci#define OTGSC_INTR_1MS_TIMER			0x20000000
4062306a36Sopenharmony_ci#define OTGSC_INTR_DATA_PULSING			0x40000000
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci#define CAPLENGTH_MASK		(0xff)
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ci/* Timer's interval, unit 10ms */
4562306a36Sopenharmony_ci#define T_A_WAIT_VRISE		100
4662306a36Sopenharmony_ci#define T_A_WAIT_BCON		2000
4762306a36Sopenharmony_ci#define T_A_AIDL_BDIS		100
4862306a36Sopenharmony_ci#define T_A_BIDL_ADIS		20
4962306a36Sopenharmony_ci#define T_B_ASE0_BRST		400
5062306a36Sopenharmony_ci#define T_B_SE0_SRP		300
5162306a36Sopenharmony_ci#define T_B_SRP_FAIL		2000
5262306a36Sopenharmony_ci#define T_B_DATA_PLS		10
5362306a36Sopenharmony_ci#define T_B_SRP_INIT		100
5462306a36Sopenharmony_ci#define T_A_SRP_RSPNS		10
5562306a36Sopenharmony_ci#define T_A_DRV_RSM		5
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_cienum otg_function {
5862306a36Sopenharmony_ci	OTG_B_DEVICE = 0,
5962306a36Sopenharmony_ci	OTG_A_DEVICE
6062306a36Sopenharmony_ci};
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_cienum mv_otg_timer {
6362306a36Sopenharmony_ci	A_WAIT_BCON_TIMER = 0,
6462306a36Sopenharmony_ci	OTG_TIMER_NUM
6562306a36Sopenharmony_ci};
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci/* PXA OTG state machine */
6862306a36Sopenharmony_cistruct mv_otg_ctrl {
6962306a36Sopenharmony_ci	/* internal variables */
7062306a36Sopenharmony_ci	u8 a_set_b_hnp_en;	/* A-Device set b_hnp_en */
7162306a36Sopenharmony_ci	u8 b_srp_done;
7262306a36Sopenharmony_ci	u8 b_hnp_en;
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci	/* OTG inputs */
7562306a36Sopenharmony_ci	u8 a_bus_drop;
7662306a36Sopenharmony_ci	u8 a_bus_req;
7762306a36Sopenharmony_ci	u8 a_clr_err;
7862306a36Sopenharmony_ci	u8 a_bus_resume;
7962306a36Sopenharmony_ci	u8 a_bus_suspend;
8062306a36Sopenharmony_ci	u8 a_conn;
8162306a36Sopenharmony_ci	u8 a_sess_vld;
8262306a36Sopenharmony_ci	u8 a_srp_det;
8362306a36Sopenharmony_ci	u8 a_vbus_vld;
8462306a36Sopenharmony_ci	u8 b_bus_req;		/* B-Device Require Bus */
8562306a36Sopenharmony_ci	u8 b_bus_resume;
8662306a36Sopenharmony_ci	u8 b_bus_suspend;
8762306a36Sopenharmony_ci	u8 b_conn;
8862306a36Sopenharmony_ci	u8 b_se0_srp;
8962306a36Sopenharmony_ci	u8 b_sess_end;
9062306a36Sopenharmony_ci	u8 b_sess_vld;
9162306a36Sopenharmony_ci	u8 id;
9262306a36Sopenharmony_ci	u8 a_suspend_req;
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ci	/*Timer event */
9562306a36Sopenharmony_ci	u8 a_aidl_bdis_timeout;
9662306a36Sopenharmony_ci	u8 b_ase0_brst_timeout;
9762306a36Sopenharmony_ci	u8 a_bidl_adis_timeout;
9862306a36Sopenharmony_ci	u8 a_wait_bcon_timeout;
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_ci	struct timer_list timer[OTG_TIMER_NUM];
10162306a36Sopenharmony_ci};
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_ci#define VUSBHS_MAX_PORTS	8
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_cistruct mv_otg_regs {
10662306a36Sopenharmony_ci	u32 usbcmd;		/* Command register */
10762306a36Sopenharmony_ci	u32 usbsts;		/* Status register */
10862306a36Sopenharmony_ci	u32 usbintr;		/* Interrupt enable */
10962306a36Sopenharmony_ci	u32 frindex;		/* Frame index */
11062306a36Sopenharmony_ci	u32 reserved1[1];
11162306a36Sopenharmony_ci	u32 deviceaddr;		/* Device Address */
11262306a36Sopenharmony_ci	u32 eplistaddr;		/* Endpoint List Address */
11362306a36Sopenharmony_ci	u32 ttctrl;		/* HOST TT status and control */
11462306a36Sopenharmony_ci	u32 burstsize;		/* Programmable Burst Size */
11562306a36Sopenharmony_ci	u32 txfilltuning;	/* Host Transmit Pre-Buffer Packet Tuning */
11662306a36Sopenharmony_ci	u32 reserved[4];
11762306a36Sopenharmony_ci	u32 epnak;		/* Endpoint NAK */
11862306a36Sopenharmony_ci	u32 epnaken;		/* Endpoint NAK Enable */
11962306a36Sopenharmony_ci	u32 configflag;		/* Configured Flag register */
12062306a36Sopenharmony_ci	u32 portsc[VUSBHS_MAX_PORTS];	/* Port Status/Control x, x = 1..8 */
12162306a36Sopenharmony_ci	u32 otgsc;
12262306a36Sopenharmony_ci	u32 usbmode;		/* USB Host/Device mode */
12362306a36Sopenharmony_ci	u32 epsetupstat;	/* Endpoint Setup Status */
12462306a36Sopenharmony_ci	u32 epprime;		/* Endpoint Initialize */
12562306a36Sopenharmony_ci	u32 epflush;		/* Endpoint De-initialize */
12662306a36Sopenharmony_ci	u32 epstatus;		/* Endpoint Status */
12762306a36Sopenharmony_ci	u32 epcomplete;		/* Endpoint Interrupt On Complete */
12862306a36Sopenharmony_ci	u32 epctrlx[16];	/* Endpoint Control, where x = 0.. 15 */
12962306a36Sopenharmony_ci	u32 mcr;		/* Mux Control */
13062306a36Sopenharmony_ci	u32 isr;		/* Interrupt Status */
13162306a36Sopenharmony_ci	u32 ier;		/* Interrupt Enable */
13262306a36Sopenharmony_ci};
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_cistruct mv_otg {
13562306a36Sopenharmony_ci	struct usb_phy phy;
13662306a36Sopenharmony_ci	struct mv_otg_ctrl otg_ctrl;
13762306a36Sopenharmony_ci
13862306a36Sopenharmony_ci	/* base address */
13962306a36Sopenharmony_ci	void __iomem *phy_regs;
14062306a36Sopenharmony_ci	void __iomem *cap_regs;
14162306a36Sopenharmony_ci	struct mv_otg_regs __iomem *op_regs;
14262306a36Sopenharmony_ci
14362306a36Sopenharmony_ci	struct platform_device *pdev;
14462306a36Sopenharmony_ci	int irq;
14562306a36Sopenharmony_ci	u32 irq_status;
14662306a36Sopenharmony_ci	u32 irq_en;
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_ci	struct delayed_work work;
14962306a36Sopenharmony_ci	struct workqueue_struct *qwork;
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_ci	spinlock_t wq_lock;
15262306a36Sopenharmony_ci
15362306a36Sopenharmony_ci	struct mv_usb_platform_data *pdata;
15462306a36Sopenharmony_ci
15562306a36Sopenharmony_ci	unsigned int active;
15662306a36Sopenharmony_ci	unsigned int clock_gating;
15762306a36Sopenharmony_ci	struct clk *clk;
15862306a36Sopenharmony_ci};
15962306a36Sopenharmony_ci
16062306a36Sopenharmony_ci#endif
161