162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Cadence USBSS and USBSSP DRD Header File. 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright (C) 2017-2018 NXP 662306a36Sopenharmony_ci * Copyright (C) 2018-2019 Cadence. 762306a36Sopenharmony_ci * 862306a36Sopenharmony_ci * Authors: Peter Chen <peter.chen@nxp.com> 962306a36Sopenharmony_ci * Pawel Laszczak <pawell@cadence.com> 1062306a36Sopenharmony_ci */ 1162306a36Sopenharmony_ci#ifndef __LINUX_CDNS3_CORE_H 1262306a36Sopenharmony_ci#define __LINUX_CDNS3_CORE_H 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci#include <linux/usb/otg.h> 1562306a36Sopenharmony_ci#include <linux/usb/role.h> 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_cistruct cdns; 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci/** 2062306a36Sopenharmony_ci * struct cdns_role_driver - host/gadget role driver 2162306a36Sopenharmony_ci * @start: start this role 2262306a36Sopenharmony_ci * @stop: stop this role 2362306a36Sopenharmony_ci * @suspend: suspend callback for this role 2462306a36Sopenharmony_ci * @resume: resume callback for this role 2562306a36Sopenharmony_ci * @irq: irq handler for this role 2662306a36Sopenharmony_ci * @name: role name string (host/gadget) 2762306a36Sopenharmony_ci * @state: current state 2862306a36Sopenharmony_ci */ 2962306a36Sopenharmony_cistruct cdns_role_driver { 3062306a36Sopenharmony_ci int (*start)(struct cdns *cdns); 3162306a36Sopenharmony_ci void (*stop)(struct cdns *cdns); 3262306a36Sopenharmony_ci int (*suspend)(struct cdns *cdns, bool do_wakeup); 3362306a36Sopenharmony_ci int (*resume)(struct cdns *cdns, bool hibernated); 3462306a36Sopenharmony_ci const char *name; 3562306a36Sopenharmony_ci#define CDNS_ROLE_STATE_INACTIVE 0 3662306a36Sopenharmony_ci#define CDNS_ROLE_STATE_ACTIVE 1 3762306a36Sopenharmony_ci int state; 3862306a36Sopenharmony_ci}; 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ci#define CDNS_XHCI_RESOURCES_NUM 2 4162306a36Sopenharmony_ci 4262306a36Sopenharmony_cistruct cdns3_platform_data { 4362306a36Sopenharmony_ci int (*platform_suspend)(struct device *dev, 4462306a36Sopenharmony_ci bool suspend, bool wakeup); 4562306a36Sopenharmony_ci unsigned long quirks; 4662306a36Sopenharmony_ci#define CDNS3_DEFAULT_PM_RUNTIME_ALLOW BIT(0) 4762306a36Sopenharmony_ci}; 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ci/** 5062306a36Sopenharmony_ci * struct cdns - Representation of Cadence USB3 DRD controller. 5162306a36Sopenharmony_ci * @dev: pointer to Cadence device struct 5262306a36Sopenharmony_ci * @xhci_regs: pointer to base of xhci registers 5362306a36Sopenharmony_ci * @xhci_res: the resource for xhci 5462306a36Sopenharmony_ci * @dev_regs: pointer to base of dev registers 5562306a36Sopenharmony_ci * @otg_res: the resource for otg 5662306a36Sopenharmony_ci * @otg_v0_regs: pointer to base of v0 otg registers 5762306a36Sopenharmony_ci * @otg_v1_regs: pointer to base of v1 otg registers 5862306a36Sopenharmony_ci * @otg_cdnsp_regs: pointer to base of CDNSP otg registers 5962306a36Sopenharmony_ci * @otg_regs: pointer to base of otg registers 6062306a36Sopenharmony_ci * @otg_irq_regs: pointer to interrupt registers 6162306a36Sopenharmony_ci * @otg_irq: irq number for otg controller 6262306a36Sopenharmony_ci * @dev_irq: irq number for device controller 6362306a36Sopenharmony_ci * @wakeup_irq: irq number for wakeup event, it is optional 6462306a36Sopenharmony_ci * @roles: array of supported roles for this controller 6562306a36Sopenharmony_ci * @role: current role 6662306a36Sopenharmony_ci * @host_dev: the child host device pointer for cdns core 6762306a36Sopenharmony_ci * @gadget_dev: the child gadget device pointer 6862306a36Sopenharmony_ci * @usb2_phy: pointer to USB2 PHY 6962306a36Sopenharmony_ci * @usb3_phy: pointer to USB3 PHY 7062306a36Sopenharmony_ci * @mutex: the mutex for concurrent code at driver 7162306a36Sopenharmony_ci * @dr_mode: supported mode of operation it can be only Host, only Device 7262306a36Sopenharmony_ci * or OTG mode that allow to switch between Device and Host mode. 7362306a36Sopenharmony_ci * This field based on firmware setting, kernel configuration 7462306a36Sopenharmony_ci * and hardware configuration. 7562306a36Sopenharmony_ci * @role_sw: pointer to role switch object. 7662306a36Sopenharmony_ci * @in_lpm: indicate the controller is in low power mode 7762306a36Sopenharmony_ci * @wakeup_pending: wakeup interrupt pending 7862306a36Sopenharmony_ci * @pdata: platform data from glue layer 7962306a36Sopenharmony_ci * @lock: spinlock structure 8062306a36Sopenharmony_ci * @xhci_plat_data: xhci private data structure pointer 8162306a36Sopenharmony_ci * @gadget_init: pointer to gadget initialization function 8262306a36Sopenharmony_ci */ 8362306a36Sopenharmony_cistruct cdns { 8462306a36Sopenharmony_ci struct device *dev; 8562306a36Sopenharmony_ci void __iomem *xhci_regs; 8662306a36Sopenharmony_ci struct resource xhci_res[CDNS_XHCI_RESOURCES_NUM]; 8762306a36Sopenharmony_ci struct cdns3_usb_regs __iomem *dev_regs; 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ci struct resource otg_res; 9062306a36Sopenharmony_ci struct cdns3_otg_legacy_regs __iomem *otg_v0_regs; 9162306a36Sopenharmony_ci struct cdns3_otg_regs __iomem *otg_v1_regs; 9262306a36Sopenharmony_ci struct cdnsp_otg_regs __iomem *otg_cdnsp_regs; 9362306a36Sopenharmony_ci struct cdns_otg_common_regs __iomem *otg_regs; 9462306a36Sopenharmony_ci struct cdns_otg_irq_regs __iomem *otg_irq_regs; 9562306a36Sopenharmony_ci#define CDNS3_CONTROLLER_V0 0 9662306a36Sopenharmony_ci#define CDNS3_CONTROLLER_V1 1 9762306a36Sopenharmony_ci#define CDNSP_CONTROLLER_V2 2 9862306a36Sopenharmony_ci u32 version; 9962306a36Sopenharmony_ci bool phyrst_a_enable; 10062306a36Sopenharmony_ci 10162306a36Sopenharmony_ci int otg_irq; 10262306a36Sopenharmony_ci int dev_irq; 10362306a36Sopenharmony_ci int wakeup_irq; 10462306a36Sopenharmony_ci struct cdns_role_driver *roles[USB_ROLE_DEVICE + 1]; 10562306a36Sopenharmony_ci enum usb_role role; 10662306a36Sopenharmony_ci struct platform_device *host_dev; 10762306a36Sopenharmony_ci void *gadget_dev; 10862306a36Sopenharmony_ci struct phy *usb2_phy; 10962306a36Sopenharmony_ci struct phy *usb3_phy; 11062306a36Sopenharmony_ci /* mutext used in workqueue*/ 11162306a36Sopenharmony_ci struct mutex mutex; 11262306a36Sopenharmony_ci enum usb_dr_mode dr_mode; 11362306a36Sopenharmony_ci struct usb_role_switch *role_sw; 11462306a36Sopenharmony_ci bool in_lpm; 11562306a36Sopenharmony_ci bool wakeup_pending; 11662306a36Sopenharmony_ci struct cdns3_platform_data *pdata; 11762306a36Sopenharmony_ci spinlock_t lock; 11862306a36Sopenharmony_ci struct xhci_plat_priv *xhci_plat_data; 11962306a36Sopenharmony_ci 12062306a36Sopenharmony_ci int (*gadget_init)(struct cdns *cdns); 12162306a36Sopenharmony_ci}; 12262306a36Sopenharmony_ci 12362306a36Sopenharmony_ciint cdns_hw_role_switch(struct cdns *cdns); 12462306a36Sopenharmony_ciint cdns_init(struct cdns *cdns); 12562306a36Sopenharmony_ciint cdns_remove(struct cdns *cdns); 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_ci#ifdef CONFIG_PM_SLEEP 12862306a36Sopenharmony_ciint cdns_resume(struct cdns *cdns); 12962306a36Sopenharmony_ciint cdns_suspend(struct cdns *cdns); 13062306a36Sopenharmony_civoid cdns_set_active(struct cdns *cdns, u8 set_active); 13162306a36Sopenharmony_ci#else /* CONFIG_PM_SLEEP */ 13262306a36Sopenharmony_cistatic inline int cdns_resume(struct cdns *cdns) 13362306a36Sopenharmony_ci{ return 0; } 13462306a36Sopenharmony_cistatic inline void cdns_set_active(struct cdns *cdns, u8 set_active) { } 13562306a36Sopenharmony_cistatic inline int cdns_suspend(struct cdns *cdns) 13662306a36Sopenharmony_ci{ return 0; } 13762306a36Sopenharmony_ci#endif /* CONFIG_PM_SLEEP */ 13862306a36Sopenharmony_ci#endif /* __LINUX_CDNS3_CORE_H */ 139