1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Cadence USBSS and USBSSP DRD Header File. 4 * 5 * Copyright (C) 2017-2018 NXP 6 * Copyright (C) 2018-2019 Cadence. 7 * 8 * Authors: Peter Chen <peter.chen@nxp.com> 9 * Pawel Laszczak <pawell@cadence.com> 10 */ 11 #ifndef __LINUX_CDNS3_CORE_H 12 #define __LINUX_CDNS3_CORE_H 13 14 #include <linux/usb/otg.h> 15 #include <linux/usb/role.h> 16 17 struct cdns; 18 19 /** 20 * struct cdns_role_driver - host/gadget role driver 21 * @start: start this role 22 * @stop: stop this role 23 * @suspend: suspend callback for this role 24 * @resume: resume callback for this role 25 * @irq: irq handler for this role 26 * @name: role name string (host/gadget) 27 * @state: current state 28 */ 29 struct cdns_role_driver { 30 int (*start)(struct cdns *cdns); 31 void (*stop)(struct cdns *cdns); 32 int (*suspend)(struct cdns *cdns, bool do_wakeup); 33 int (*resume)(struct cdns *cdns, bool lost_power); 34 const char *name; 35 #define CDNS_ROLE_STATE_INACTIVE 0 36 #define CDNS_ROLE_STATE_ACTIVE 1 37 int state; 38 }; 39 40 #define CDNS_XHCI_RESOURCES_NUM 2 41 42 struct cdns3_platform_data { 43 int (*platform_suspend)(struct device *dev, 44 bool suspend, bool wakeup); 45 unsigned long quirks; 46 #define CDNS3_DEFAULT_PM_RUNTIME_ALLOW BIT(0) 47 #define CDNS3_DRD_SUSPEND_RESIDENCY_ENABLE BIT(1) 48 u32 override_apb_timeout; /* 0 = use default (e.g. for PCI) */ 49 }; 50 51 /** 52 * struct cdns - Representation of Cadence USB3 DRD controller. 53 * @dev: pointer to Cadence device struct 54 * @xhci_regs: pointer to base of xhci registers 55 * @xhci_res: the resource for xhci 56 * @dev_regs: pointer to base of dev registers 57 * @otg_res: the resource for otg 58 * @otg_v0_regs: pointer to base of v0 otg registers 59 * @otg_v1_regs: pointer to base of v1 otg registers 60 * @otg_cdnsp_regs: pointer to base of CDNSP otg registers 61 * @otg_regs: pointer to base of otg registers 62 * @otg_irq_regs: pointer to interrupt registers 63 * @otg_irq: irq number for otg controller 64 * @dev_irq: irq number for device controller 65 * @wakeup_irq: irq number for wakeup event, it is optional 66 * @roles: array of supported roles for this controller 67 * @role: current role 68 * @host_dev: the child host device pointer for cdns core 69 * @gadget_dev: the child gadget device pointer 70 * @usb2_phy: pointer to USB2 PHY 71 * @usb3_phy: pointer to USB3 PHY 72 * @mutex: the mutex for concurrent code at driver 73 * @dr_mode: supported mode of operation it can be only Host, only Device 74 * or OTG mode that allow to switch between Device and Host mode. 75 * This field based on firmware setting, kernel configuration 76 * and hardware configuration. 77 * @role_sw: pointer to role switch object. 78 * @in_lpm: indicate the controller is in low power mode 79 * @wakeup_pending: wakeup interrupt pending 80 * @pdata: platform data from glue layer 81 * @lock: spinlock structure 82 * @xhci_plat_data: xhci private data structure pointer 83 * @override_apb_timeout: hold value of APB timeout. For value 0 the default 84 * value in CHICKEN_BITS_3 will be preserved. 85 * @gadget_init: pointer to gadget initialization function 86 * @host_init: pointer to host initialization function 87 * @no_drd: DRD register block is inaccessible. The controller is hardwired to 88 * single role (host or device) or the logic for role switching is 89 * missing. 90 */ 91 struct cdns { 92 struct device *dev; 93 void __iomem *xhci_regs; 94 struct resource xhci_res[CDNS_XHCI_RESOURCES_NUM]; 95 struct cdns3_usb_regs __iomem *dev_regs; 96 97 struct resource otg_res; 98 struct cdns3_otg_legacy_regs __iomem *otg_v0_regs; 99 struct cdns3_otg_regs __iomem *otg_v1_regs; 100 struct cdnsp_otg_regs __iomem *otg_cdnsp_regs; 101 struct cdns_otg_common_regs __iomem *otg_regs; 102 struct cdns_otg_irq_regs __iomem *otg_irq_regs; 103 #define CDNS3_CONTROLLER_V0 0 104 #define CDNS3_CONTROLLER_V1 1 105 #define CDNSP_CONTROLLER_V2 2 106 u32 version; 107 bool phyrst_a_enable; 108 109 int otg_irq; 110 int dev_irq; 111 int wakeup_irq; 112 struct cdns_role_driver *roles[USB_ROLE_DEVICE + 1]; 113 enum usb_role role; 114 struct platform_device *host_dev; 115 void *gadget_dev; 116 struct phy *usb2_phy; 117 struct phy *usb3_phy; 118 /* mutext used in workqueue*/ 119 struct mutex mutex; 120 enum usb_dr_mode dr_mode; 121 struct usb_role_switch *role_sw; 122 bool in_lpm; 123 bool wakeup_pending; 124 struct cdns3_platform_data *pdata; 125 spinlock_t lock; 126 struct xhci_plat_priv *xhci_plat_data; 127 u32 override_apb_timeout; 128 int (*gadget_init)(struct cdns *cdns); 129 int (*host_init)(struct cdns *cdns); 130 bool no_drd; 131 }; 132 133 int cdns_hw_role_switch(struct cdns *cdns); 134 int cdns_init(struct cdns *cdns); 135 int cdns_remove(struct cdns *cdns); 136 int cdns_core_init_role(struct cdns *cdns); 137 138 #ifdef CONFIG_PM_SLEEP 139 int cdns_resume(struct cdns *cdns); 140 int cdns_suspend(struct cdns *cdns); 141 void cdns_set_active(struct cdns *cdns, u8 set_active); 142 #else /* CONFIG_PM_SLEEP */ 143 static inline int cdns_resume(struct cdns *cdns) 144 { return 0; } 145 static inline void cdns_set_active(struct cdns *cdns, u8 set_active) { } 146 static inline int cdns_suspend(struct cdns *cdns) 147 { return 0; } 148 #endif /* CONFIG_PM_SLEEP */ 149 #endif /* __LINUX_CDNS3_CORE_H */ 150