2019-08-26 19:19:30 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
/*
|
2020-12-07 18:32:24 +08:00
|
|
|
* Cadence USBSS and USBSSP DRD Header File.
|
2019-08-26 19:19:30 +08:00
|
|
|
*
|
|
|
|
* Copyright (C) 2017-2018 NXP
|
|
|
|
* Copyright (C) 2018-2019 Cadence.
|
|
|
|
*
|
|
|
|
* Authors: Peter Chen <peter.chen@nxp.com>
|
|
|
|
* Pawel Laszczak <pawell@cadence.com>
|
|
|
|
*/
|
|
|
|
#include <linux/usb/otg.h>
|
|
|
|
#include <linux/usb/role.h>
|
|
|
|
|
|
|
|
#ifndef __LINUX_CDNS3_CORE_H
|
|
|
|
#define __LINUX_CDNS3_CORE_H
|
|
|
|
|
2020-12-07 18:32:21 +08:00
|
|
|
struct cdns;
|
2019-08-26 19:19:30 +08:00
|
|
|
|
|
|
|
/**
|
2020-12-07 18:32:21 +08:00
|
|
|
* struct cdns_role_driver - host/gadget role driver
|
2019-08-26 19:19:30 +08:00
|
|
|
* @start: start this role
|
|
|
|
* @stop: stop this role
|
|
|
|
* @suspend: suspend callback for this role
|
|
|
|
* @resume: resume callback for this role
|
|
|
|
* @irq: irq handler for this role
|
|
|
|
* @name: role name string (host/gadget)
|
|
|
|
* @state: current state
|
|
|
|
*/
|
2020-12-07 18:32:21 +08:00
|
|
|
struct cdns_role_driver {
|
|
|
|
int (*start)(struct cdns *cdns);
|
|
|
|
void (*stop)(struct cdns *cdns);
|
|
|
|
int (*suspend)(struct cdns *cdns, bool do_wakeup);
|
|
|
|
int (*resume)(struct cdns *cdns, bool hibernated);
|
2019-08-26 19:19:30 +08:00
|
|
|
const char *name;
|
2020-12-07 18:32:21 +08:00
|
|
|
#define CDNS_ROLE_STATE_INACTIVE 0
|
|
|
|
#define CDNS_ROLE_STATE_ACTIVE 1
|
2019-08-26 19:19:30 +08:00
|
|
|
int state;
|
|
|
|
};
|
|
|
|
|
2020-12-07 18:32:21 +08:00
|
|
|
#define CDNS_XHCI_RESOURCES_NUM 2
|
2020-09-02 17:57:32 +08:00
|
|
|
|
|
|
|
struct cdns3_platform_data {
|
|
|
|
int (*platform_suspend)(struct device *dev,
|
|
|
|
bool suspend, bool wakeup);
|
2020-09-28 15:20:03 +08:00
|
|
|
unsigned long quirks;
|
|
|
|
#define CDNS3_DEFAULT_PM_RUNTIME_ALLOW BIT(0)
|
2020-09-02 17:57:32 +08:00
|
|
|
};
|
|
|
|
|
2019-08-26 19:19:30 +08:00
|
|
|
/**
|
2020-12-07 18:32:21 +08:00
|
|
|
* struct cdns - Representation of Cadence USB3 DRD controller.
|
2019-08-26 19:19:30 +08:00
|
|
|
* @dev: pointer to Cadence device struct
|
|
|
|
* @xhci_regs: pointer to base of xhci registers
|
|
|
|
* @xhci_res: the resource for xhci
|
|
|
|
* @dev_regs: pointer to base of dev registers
|
|
|
|
* @otg_res: the resource for otg
|
|
|
|
* @otg_v0_regs: pointer to base of v0 otg registers
|
|
|
|
* @otg_v1_regs: pointer to base of v1 otg registers
|
2020-12-07 18:32:18 +08:00
|
|
|
* @otg_cdnsp_regs: pointer to base of CDNSP otg registers
|
2019-08-26 19:19:30 +08:00
|
|
|
* @otg_regs: pointer to base of otg registers
|
2020-12-07 18:32:18 +08:00
|
|
|
* @otg_irq_regs: pointer to interrupt registers
|
2019-08-26 19:19:30 +08:00
|
|
|
* @otg_irq: irq number for otg controller
|
|
|
|
* @dev_irq: irq number for device controller
|
2020-09-02 17:57:32 +08:00
|
|
|
* @wakeup_irq: irq number for wakeup event, it is optional
|
2019-08-26 19:19:30 +08:00
|
|
|
* @roles: array of supported roles for this controller
|
|
|
|
* @role: current role
|
2020-12-07 18:32:21 +08:00
|
|
|
* @host_dev: the child host device pointer for cdns core
|
2020-12-07 18:32:22 +08:00
|
|
|
* @gadget_dev: the child gadget device pointer
|
2019-08-26 19:19:30 +08:00
|
|
|
* @usb2_phy: pointer to USB2 PHY
|
|
|
|
* @usb3_phy: pointer to USB3 PHY
|
|
|
|
* @mutex: the mutex for concurrent code at driver
|
|
|
|
* @dr_mode: supported mode of operation it can be only Host, only Device
|
|
|
|
* or OTG mode that allow to switch between Device and Host mode.
|
|
|
|
* This field based on firmware setting, kernel configuration
|
|
|
|
* and hardware configuration.
|
|
|
|
* @role_sw: pointer to role switch object.
|
2020-09-02 17:57:32 +08:00
|
|
|
* @in_lpm: indicate the controller is in low power mode
|
|
|
|
* @wakeup_pending: wakeup interrupt pending
|
|
|
|
* @pdata: platform data from glue layer
|
|
|
|
* @lock: spinlock structure
|
2020-09-28 15:20:03 +08:00
|
|
|
* @xhci_plat_data: xhci private data structure pointer
|
2020-12-07 18:32:20 +08:00
|
|
|
* @gadget_init: pointer to gadget initialization function
|
2019-08-26 19:19:30 +08:00
|
|
|
*/
|
2020-12-07 18:32:21 +08:00
|
|
|
struct cdns {
|
2019-08-26 19:19:30 +08:00
|
|
|
struct device *dev;
|
|
|
|
void __iomem *xhci_regs;
|
2020-12-07 18:32:21 +08:00
|
|
|
struct resource xhci_res[CDNS_XHCI_RESOURCES_NUM];
|
2019-08-26 19:19:30 +08:00
|
|
|
struct cdns3_usb_regs __iomem *dev_regs;
|
|
|
|
|
2020-12-15 18:27:09 +08:00
|
|
|
struct resource otg_res;
|
|
|
|
struct cdns3_otg_legacy_regs __iomem *otg_v0_regs;
|
|
|
|
struct cdns3_otg_regs __iomem *otg_v1_regs;
|
|
|
|
struct cdnsp_otg_regs __iomem *otg_cdnsp_regs;
|
|
|
|
struct cdns_otg_common_regs __iomem *otg_regs;
|
|
|
|
struct cdns_otg_irq_regs __iomem *otg_irq_regs;
|
2019-08-26 19:19:30 +08:00
|
|
|
#define CDNS3_CONTROLLER_V0 0
|
|
|
|
#define CDNS3_CONTROLLER_V1 1
|
2020-12-07 18:32:18 +08:00
|
|
|
#define CDNSP_CONTROLLER_V2 2
|
2019-08-26 19:19:30 +08:00
|
|
|
u32 version;
|
2020-09-15 19:45:43 +08:00
|
|
|
bool phyrst_a_enable;
|
2019-08-26 19:19:30 +08:00
|
|
|
|
|
|
|
int otg_irq;
|
|
|
|
int dev_irq;
|
2020-09-02 17:57:32 +08:00
|
|
|
int wakeup_irq;
|
2020-12-07 18:32:21 +08:00
|
|
|
struct cdns_role_driver *roles[USB_ROLE_DEVICE + 1];
|
2019-08-26 19:19:30 +08:00
|
|
|
enum usb_role role;
|
|
|
|
struct platform_device *host_dev;
|
2020-12-07 18:32:22 +08:00
|
|
|
void *gadget_dev;
|
2019-08-26 19:19:30 +08:00
|
|
|
struct phy *usb2_phy;
|
|
|
|
struct phy *usb3_phy;
|
|
|
|
/* mutext used in workqueue*/
|
|
|
|
struct mutex mutex;
|
|
|
|
enum usb_dr_mode dr_mode;
|
|
|
|
struct usb_role_switch *role_sw;
|
2020-09-02 17:57:32 +08:00
|
|
|
bool in_lpm;
|
|
|
|
bool wakeup_pending;
|
|
|
|
struct cdns3_platform_data *pdata;
|
|
|
|
spinlock_t lock;
|
2020-09-28 15:20:03 +08:00
|
|
|
struct xhci_plat_priv *xhci_plat_data;
|
2020-12-07 18:32:20 +08:00
|
|
|
|
2020-12-07 18:32:21 +08:00
|
|
|
int (*gadget_init)(struct cdns *cdns);
|
2019-08-26 19:19:30 +08:00
|
|
|
};
|
|
|
|
|
2020-12-07 18:32:21 +08:00
|
|
|
int cdns_hw_role_switch(struct cdns *cdns);
|
|
|
|
int cdns_init(struct cdns *cdns);
|
|
|
|
int cdns_remove(struct cdns *cdns);
|
2019-08-26 19:19:30 +08:00
|
|
|
|
2020-12-07 18:32:19 +08:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
2020-12-07 18:32:21 +08:00
|
|
|
int cdns_resume(struct cdns *cdns, u8 set_active);
|
|
|
|
int cdns_suspend(struct cdns *cdns);
|
2020-12-09 03:55:35 +08:00
|
|
|
#else /* CONFIG_PM_SLEEP */
|
|
|
|
static inline int cdns_resume(struct cdns *cdns, u8 set_active)
|
|
|
|
{ return 0; }
|
|
|
|
static inline int cdns_suspend(struct cdns *cdns)
|
|
|
|
{ return 0; }
|
2020-12-07 18:32:19 +08:00
|
|
|
#endif /* CONFIG_PM_SLEEP */
|
2019-08-26 19:19:30 +08:00
|
|
|
#endif /* __LINUX_CDNS3_CORE_H */
|