18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Cadence USBSS DRD Header File.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2017-2018 NXP
68c2ecf20Sopenharmony_ci * Copyright (C) 2018-2019 Cadence.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * Authors: Peter Chen <peter.chen@nxp.com>
98c2ecf20Sopenharmony_ci *          Pawel Laszczak <pawell@cadence.com>
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci#include <linux/usb/otg.h>
128c2ecf20Sopenharmony_ci#include <linux/usb/role.h>
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#ifndef __LINUX_CDNS3_CORE_H
158c2ecf20Sopenharmony_ci#define __LINUX_CDNS3_CORE_H
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_cistruct cdns3;
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci/**
208c2ecf20Sopenharmony_ci * struct cdns3_role_driver - host/gadget role driver
218c2ecf20Sopenharmony_ci * @start: start this role
228c2ecf20Sopenharmony_ci * @stop: stop this role
238c2ecf20Sopenharmony_ci * @suspend: suspend callback for this role
248c2ecf20Sopenharmony_ci * @resume: resume callback for this role
258c2ecf20Sopenharmony_ci * @irq: irq handler for this role
268c2ecf20Sopenharmony_ci * @name: role name string (host/gadget)
278c2ecf20Sopenharmony_ci * @state: current state
288c2ecf20Sopenharmony_ci */
298c2ecf20Sopenharmony_cistruct cdns3_role_driver {
308c2ecf20Sopenharmony_ci	int (*start)(struct cdns3 *cdns);
318c2ecf20Sopenharmony_ci	void (*stop)(struct cdns3 *cdns);
328c2ecf20Sopenharmony_ci	int (*suspend)(struct cdns3 *cdns, bool do_wakeup);
338c2ecf20Sopenharmony_ci	int (*resume)(struct cdns3 *cdns, bool hibernated);
348c2ecf20Sopenharmony_ci	const char *name;
358c2ecf20Sopenharmony_ci#define CDNS3_ROLE_STATE_INACTIVE	0
368c2ecf20Sopenharmony_ci#define CDNS3_ROLE_STATE_ACTIVE		1
378c2ecf20Sopenharmony_ci	int state;
388c2ecf20Sopenharmony_ci};
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci#define CDNS3_XHCI_RESOURCES_NUM	2
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_cistruct cdns3_platform_data {
438c2ecf20Sopenharmony_ci	int (*platform_suspend)(struct device *dev,
448c2ecf20Sopenharmony_ci			bool suspend, bool wakeup);
458c2ecf20Sopenharmony_ci	unsigned long quirks;
468c2ecf20Sopenharmony_ci#define CDNS3_DEFAULT_PM_RUNTIME_ALLOW	BIT(0)
478c2ecf20Sopenharmony_ci};
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci/**
508c2ecf20Sopenharmony_ci * struct cdns3 - Representation of Cadence USB3 DRD controller.
518c2ecf20Sopenharmony_ci * @dev: pointer to Cadence device struct
528c2ecf20Sopenharmony_ci * @xhci_regs: pointer to base of xhci registers
538c2ecf20Sopenharmony_ci * @xhci_res: the resource for xhci
548c2ecf20Sopenharmony_ci * @dev_regs: pointer to base of dev registers
558c2ecf20Sopenharmony_ci * @otg_res: the resource for otg
568c2ecf20Sopenharmony_ci * @otg_v0_regs: pointer to base of v0 otg registers
578c2ecf20Sopenharmony_ci * @otg_v1_regs: pointer to base of v1 otg registers
588c2ecf20Sopenharmony_ci * @otg_cdnsp_regs: pointer to base of CDNSP otg registers
598c2ecf20Sopenharmony_ci * @otg_regs: pointer to base of otg registers
608c2ecf20Sopenharmony_ci * @otg_irq_regs: pointer to interrupt registers
618c2ecf20Sopenharmony_ci * @otg_irq: irq number for otg controller
628c2ecf20Sopenharmony_ci * @dev_irq: irq number for device controller
638c2ecf20Sopenharmony_ci * @wakeup_irq: irq number for wakeup event, it is optional
648c2ecf20Sopenharmony_ci * @roles: array of supported roles for this controller
658c2ecf20Sopenharmony_ci * @role: current role
668c2ecf20Sopenharmony_ci * @host_dev: the child host device pointer for cdns3 core
678c2ecf20Sopenharmony_ci * @gadget_dev: the child gadget device pointer for cdns3 core
688c2ecf20Sopenharmony_ci * @usb2_phy: pointer to USB2 PHY
698c2ecf20Sopenharmony_ci * @usb3_phy: pointer to USB3 PHY
708c2ecf20Sopenharmony_ci * @mutex: the mutex for concurrent code at driver
718c2ecf20Sopenharmony_ci * @dr_mode: supported mode of operation it can be only Host, only Device
728c2ecf20Sopenharmony_ci *           or OTG mode that allow to switch between Device and Host mode.
738c2ecf20Sopenharmony_ci *           This field based on firmware setting, kernel configuration
748c2ecf20Sopenharmony_ci *           and hardware configuration.
758c2ecf20Sopenharmony_ci * @role_sw: pointer to role switch object.
768c2ecf20Sopenharmony_ci * @in_lpm: indicate the controller is in low power mode
778c2ecf20Sopenharmony_ci * @wakeup_pending: wakeup interrupt pending
788c2ecf20Sopenharmony_ci * @pdata: platform data from glue layer
798c2ecf20Sopenharmony_ci * @lock: spinlock structure
808c2ecf20Sopenharmony_ci * @xhci_plat_data: xhci private data structure pointer
818c2ecf20Sopenharmony_ci */
828c2ecf20Sopenharmony_cistruct cdns3 {
838c2ecf20Sopenharmony_ci	struct device			*dev;
848c2ecf20Sopenharmony_ci	void __iomem			*xhci_regs;
858c2ecf20Sopenharmony_ci	struct resource			xhci_res[CDNS3_XHCI_RESOURCES_NUM];
868c2ecf20Sopenharmony_ci	struct cdns3_usb_regs __iomem	*dev_regs;
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci	struct resource			otg_res;
898c2ecf20Sopenharmony_ci	struct cdns3_otg_legacy_regs	*otg_v0_regs;
908c2ecf20Sopenharmony_ci	struct cdns3_otg_regs		*otg_v1_regs;
918c2ecf20Sopenharmony_ci	struct cdnsp_otg_regs		*otg_cdnsp_regs;
928c2ecf20Sopenharmony_ci	struct cdns3_otg_common_regs	*otg_regs;
938c2ecf20Sopenharmony_ci	struct cdns3_otg_irq_regs	*otg_irq_regs;
948c2ecf20Sopenharmony_ci#define CDNS3_CONTROLLER_V0	0
958c2ecf20Sopenharmony_ci#define CDNS3_CONTROLLER_V1	1
968c2ecf20Sopenharmony_ci#define CDNSP_CONTROLLER_V2	2
978c2ecf20Sopenharmony_ci	u32				version;
988c2ecf20Sopenharmony_ci	bool				phyrst_a_enable;
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci	int				otg_irq;
1018c2ecf20Sopenharmony_ci	int				dev_irq;
1028c2ecf20Sopenharmony_ci	int				wakeup_irq;
1038c2ecf20Sopenharmony_ci	struct cdns3_role_driver	*roles[USB_ROLE_DEVICE + 1];
1048c2ecf20Sopenharmony_ci	enum usb_role			role;
1058c2ecf20Sopenharmony_ci	struct platform_device		*host_dev;
1068c2ecf20Sopenharmony_ci	struct cdns3_device		*gadget_dev;
1078c2ecf20Sopenharmony_ci	struct phy			*usb2_phy;
1088c2ecf20Sopenharmony_ci	struct phy			*usb3_phy;
1098c2ecf20Sopenharmony_ci	/* mutext used in workqueue*/
1108c2ecf20Sopenharmony_ci	struct mutex			mutex;
1118c2ecf20Sopenharmony_ci	enum usb_dr_mode		dr_mode;
1128c2ecf20Sopenharmony_ci	struct usb_role_switch		*role_sw;
1138c2ecf20Sopenharmony_ci	bool				in_lpm;
1148c2ecf20Sopenharmony_ci	bool				wakeup_pending;
1158c2ecf20Sopenharmony_ci	struct cdns3_platform_data	*pdata;
1168c2ecf20Sopenharmony_ci	spinlock_t			lock;
1178c2ecf20Sopenharmony_ci	struct xhci_plat_priv		*xhci_plat_data;
1188c2ecf20Sopenharmony_ci};
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ciint cdns3_hw_role_switch(struct cdns3 *cdns);
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci#endif /* __LINUX_CDNS3_CORE_H */
123