Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Cadence USBSS and USBSSP DRD Header File.
0004  *
0005  * Copyright (C) 2017-2018 NXP
0006  * Copyright (C) 2018-2019 Cadence.
0007  *
0008  * Authors: Peter Chen <peter.chen@nxp.com>
0009  *          Pawel Laszczak <pawell@cadence.com>
0010  */
0011 #ifndef __LINUX_CDNS3_CORE_H
0012 #define __LINUX_CDNS3_CORE_H
0013 
0014 #include <linux/usb/otg.h>
0015 #include <linux/usb/role.h>
0016 
0017 struct cdns;
0018 
0019 /**
0020  * struct cdns_role_driver - host/gadget role driver
0021  * @start: start this role
0022  * @stop: stop this role
0023  * @suspend: suspend callback for this role
0024  * @resume: resume callback for this role
0025  * @irq: irq handler for this role
0026  * @name: role name string (host/gadget)
0027  * @state: current state
0028  */
0029 struct cdns_role_driver {
0030     int (*start)(struct cdns *cdns);
0031     void (*stop)(struct cdns *cdns);
0032     int (*suspend)(struct cdns *cdns, bool do_wakeup);
0033     int (*resume)(struct cdns *cdns, bool hibernated);
0034     const char *name;
0035 #define CDNS_ROLE_STATE_INACTIVE    0
0036 #define CDNS_ROLE_STATE_ACTIVE      1
0037     int state;
0038 };
0039 
0040 #define CDNS_XHCI_RESOURCES_NUM 2
0041 
0042 struct cdns3_platform_data {
0043     int (*platform_suspend)(struct device *dev,
0044             bool suspend, bool wakeup);
0045     unsigned long quirks;
0046 #define CDNS3_DEFAULT_PM_RUNTIME_ALLOW  BIT(0)
0047 };
0048 
0049 /**
0050  * struct cdns - Representation of Cadence USB3 DRD controller.
0051  * @dev: pointer to Cadence device struct
0052  * @xhci_regs: pointer to base of xhci registers
0053  * @xhci_res: the resource for xhci
0054  * @dev_regs: pointer to base of dev registers
0055  * @otg_res: the resource for otg
0056  * @otg_v0_regs: pointer to base of v0 otg registers
0057  * @otg_v1_regs: pointer to base of v1 otg registers
0058  * @otg_cdnsp_regs: pointer to base of CDNSP otg registers
0059  * @otg_regs: pointer to base of otg registers
0060  * @otg_irq_regs: pointer to interrupt registers
0061  * @otg_irq: irq number for otg controller
0062  * @dev_irq: irq number for device controller
0063  * @wakeup_irq: irq number for wakeup event, it is optional
0064  * @roles: array of supported roles for this controller
0065  * @role: current role
0066  * @host_dev: the child host device pointer for cdns core
0067  * @gadget_dev: the child gadget device pointer
0068  * @usb2_phy: pointer to USB2 PHY
0069  * @usb3_phy: pointer to USB3 PHY
0070  * @mutex: the mutex for concurrent code at driver
0071  * @dr_mode: supported mode of operation it can be only Host, only Device
0072  *           or OTG mode that allow to switch between Device and Host mode.
0073  *           This field based on firmware setting, kernel configuration
0074  *           and hardware configuration.
0075  * @role_sw: pointer to role switch object.
0076  * @in_lpm: indicate the controller is in low power mode
0077  * @wakeup_pending: wakeup interrupt pending
0078  * @pdata: platform data from glue layer
0079  * @lock: spinlock structure
0080  * @xhci_plat_data: xhci private data structure pointer
0081  * @gadget_init: pointer to gadget initialization function
0082  */
0083 struct cdns {
0084     struct device           *dev;
0085     void __iomem            *xhci_regs;
0086     struct resource         xhci_res[CDNS_XHCI_RESOURCES_NUM];
0087     struct cdns3_usb_regs __iomem   *dev_regs;
0088 
0089     struct resource             otg_res;
0090     struct cdns3_otg_legacy_regs __iomem    *otg_v0_regs;
0091     struct cdns3_otg_regs __iomem       *otg_v1_regs;
0092     struct cdnsp_otg_regs __iomem       *otg_cdnsp_regs;
0093     struct cdns_otg_common_regs __iomem *otg_regs;
0094     struct cdns_otg_irq_regs __iomem    *otg_irq_regs;
0095 #define CDNS3_CONTROLLER_V0 0
0096 #define CDNS3_CONTROLLER_V1 1
0097 #define CDNSP_CONTROLLER_V2 2
0098     u32             version;
0099     bool                phyrst_a_enable;
0100 
0101     int             otg_irq;
0102     int             dev_irq;
0103     int             wakeup_irq;
0104     struct cdns_role_driver *roles[USB_ROLE_DEVICE + 1];
0105     enum usb_role           role;
0106     struct platform_device      *host_dev;
0107     void                *gadget_dev;
0108     struct phy          *usb2_phy;
0109     struct phy          *usb3_phy;
0110     /* mutext used in workqueue*/
0111     struct mutex            mutex;
0112     enum usb_dr_mode        dr_mode;
0113     struct usb_role_switch      *role_sw;
0114     bool                in_lpm;
0115     bool                wakeup_pending;
0116     struct cdns3_platform_data  *pdata;
0117     spinlock_t          lock;
0118     struct xhci_plat_priv       *xhci_plat_data;
0119 
0120     int (*gadget_init)(struct cdns *cdns);
0121 };
0122 
0123 int cdns_hw_role_switch(struct cdns *cdns);
0124 int cdns_init(struct cdns *cdns);
0125 int cdns_remove(struct cdns *cdns);
0126 
0127 #ifdef CONFIG_PM_SLEEP
0128 int cdns_resume(struct cdns *cdns, u8 set_active);
0129 int cdns_suspend(struct cdns *cdns);
0130 #else /* CONFIG_PM_SLEEP */
0131 static inline int cdns_resume(struct cdns *cdns, u8 set_active)
0132 { return 0; }
0133 static inline int cdns_suspend(struct cdns *cdns)
0134 { return 0; }
0135 #endif /* CONFIG_PM_SLEEP */
0136 #endif /* __LINUX_CDNS3_CORE_H */