17733f6c3SPawel Laszczak /* SPDX-License-Identifier: GPL-2.0 */
27733f6c3SPawel Laszczak /*
33d829045SPawel Laszczak * Cadence USBSS and USBSSP DRD Header File.
47733f6c3SPawel Laszczak *
57733f6c3SPawel Laszczak * Copyright (C) 2017-2018 NXP
67733f6c3SPawel Laszczak * Copyright (C) 2018-2019 Cadence.
77733f6c3SPawel Laszczak *
87733f6c3SPawel Laszczak * Authors: Peter Chen <peter.chen@nxp.com>
97733f6c3SPawel Laszczak * Pawel Laszczak <pawell@cadence.com>
107733f6c3SPawel Laszczak */
117733f6c3SPawel Laszczak #ifndef __LINUX_CDNS3_CORE_H
127733f6c3SPawel Laszczak #define __LINUX_CDNS3_CORE_H
137733f6c3SPawel Laszczak
14cd33707dSIngo Molnar #include <linux/usb/otg.h>
15cd33707dSIngo Molnar #include <linux/usb/role.h>
16cd33707dSIngo Molnar
170b490046SPawel Laszczak struct cdns;
187733f6c3SPawel Laszczak
197733f6c3SPawel Laszczak /**
200b490046SPawel Laszczak * struct cdns_role_driver - host/gadget role driver
217733f6c3SPawel Laszczak * @start: start this role
227733f6c3SPawel Laszczak * @stop: stop this role
237733f6c3SPawel Laszczak * @suspend: suspend callback for this role
247733f6c3SPawel Laszczak * @resume: resume callback for this role
257733f6c3SPawel Laszczak * @irq: irq handler for this role
267733f6c3SPawel Laszczak * @name: role name string (host/gadget)
277733f6c3SPawel Laszczak * @state: current state
287733f6c3SPawel Laszczak */
290b490046SPawel Laszczak struct cdns_role_driver {
300b490046SPawel Laszczak int (*start)(struct cdns *cdns);
310b490046SPawel Laszczak void (*stop)(struct cdns *cdns);
320b490046SPawel Laszczak int (*suspend)(struct cdns *cdns, bool do_wakeup);
330b490046SPawel Laszczak int (*resume)(struct cdns *cdns, bool hibernated);
347733f6c3SPawel Laszczak const char *name;
350b490046SPawel Laszczak #define CDNS_ROLE_STATE_INACTIVE 0
360b490046SPawel Laszczak #define CDNS_ROLE_STATE_ACTIVE 1
377733f6c3SPawel Laszczak int state;
387733f6c3SPawel Laszczak };
397733f6c3SPawel Laszczak
400b490046SPawel Laszczak #define CDNS_XHCI_RESOURCES_NUM 2
41b1234e3bSPeter Chen
42b1234e3bSPeter Chen struct cdns3_platform_data {
43b1234e3bSPeter Chen int (*platform_suspend)(struct device *dev,
44b1234e3bSPeter Chen bool suspend, bool wakeup);
457cea9657SPeter Chen unsigned long quirks;
467cea9657SPeter Chen #define CDNS3_DEFAULT_PM_RUNTIME_ALLOW BIT(0)
47*43fb5b09SRoger Quadros #define CDNS3_DRD_SUSPEND_RESIDENCY_ENABLE BIT(1)
48b1234e3bSPeter Chen };
49b1234e3bSPeter Chen
507733f6c3SPawel Laszczak /**
510b490046SPawel Laszczak * struct cdns - Representation of Cadence USB3 DRD controller.
527733f6c3SPawel Laszczak * @dev: pointer to Cadence device struct
537733f6c3SPawel Laszczak * @xhci_regs: pointer to base of xhci registers
547733f6c3SPawel Laszczak * @xhci_res: the resource for xhci
557733f6c3SPawel Laszczak * @dev_regs: pointer to base of dev registers
567733f6c3SPawel Laszczak * @otg_res: the resource for otg
577733f6c3SPawel Laszczak * @otg_v0_regs: pointer to base of v0 otg registers
587733f6c3SPawel Laszczak * @otg_v1_regs: pointer to base of v1 otg registers
59db8892bbSPawel Laszczak * @otg_cdnsp_regs: pointer to base of CDNSP otg registers
607733f6c3SPawel Laszczak * @otg_regs: pointer to base of otg registers
61db8892bbSPawel Laszczak * @otg_irq_regs: pointer to interrupt registers
627733f6c3SPawel Laszczak * @otg_irq: irq number for otg controller
637733f6c3SPawel Laszczak * @dev_irq: irq number for device controller
64b1234e3bSPeter Chen * @wakeup_irq: irq number for wakeup event, it is optional
657733f6c3SPawel Laszczak * @roles: array of supported roles for this controller
667733f6c3SPawel Laszczak * @role: current role
670b490046SPawel Laszczak * @host_dev: the child host device pointer for cdns core
68ac5bca14SPawel Laszczak * @gadget_dev: the child gadget device pointer
697733f6c3SPawel Laszczak * @usb2_phy: pointer to USB2 PHY
707733f6c3SPawel Laszczak * @usb3_phy: pointer to USB3 PHY
717733f6c3SPawel Laszczak * @mutex: the mutex for concurrent code at driver
727733f6c3SPawel Laszczak * @dr_mode: supported mode of operation it can be only Host, only Device
737733f6c3SPawel Laszczak * or OTG mode that allow to switch between Device and Host mode.
747733f6c3SPawel Laszczak * This field based on firmware setting, kernel configuration
757733f6c3SPawel Laszczak * and hardware configuration.
767733f6c3SPawel Laszczak * @role_sw: pointer to role switch object.
77b1234e3bSPeter Chen * @in_lpm: indicate the controller is in low power mode
78b1234e3bSPeter Chen * @wakeup_pending: wakeup interrupt pending
79b1234e3bSPeter Chen * @pdata: platform data from glue layer
80b1234e3bSPeter Chen * @lock: spinlock structure
817cea9657SPeter Chen * @xhci_plat_data: xhci private data structure pointer
82394c3a14SPawel Laszczak * @gadget_init: pointer to gadget initialization function
837733f6c3SPawel Laszczak */
840b490046SPawel Laszczak struct cdns {
857733f6c3SPawel Laszczak struct device *dev;
867733f6c3SPawel Laszczak void __iomem *xhci_regs;
870b490046SPawel Laszczak struct resource xhci_res[CDNS_XHCI_RESOURCES_NUM];
887733f6c3SPawel Laszczak struct cdns3_usb_regs __iomem *dev_regs;
897733f6c3SPawel Laszczak
907733f6c3SPawel Laszczak struct resource otg_res;
916500f30bSPawel Laszczak struct cdns3_otg_legacy_regs __iomem *otg_v0_regs;
926500f30bSPawel Laszczak struct cdns3_otg_regs __iomem *otg_v1_regs;
936500f30bSPawel Laszczak struct cdnsp_otg_regs __iomem *otg_cdnsp_regs;
946500f30bSPawel Laszczak struct cdns_otg_common_regs __iomem *otg_regs;
956500f30bSPawel Laszczak struct cdns_otg_irq_regs __iomem *otg_irq_regs;
967733f6c3SPawel Laszczak #define CDNS3_CONTROLLER_V0 0
977733f6c3SPawel Laszczak #define CDNS3_CONTROLLER_V1 1
98db8892bbSPawel Laszczak #define CDNSP_CONTROLLER_V2 2
997733f6c3SPawel Laszczak u32 version;
1002eae2dfdSPawel Laszczak bool phyrst_a_enable;
1017733f6c3SPawel Laszczak
1027733f6c3SPawel Laszczak int otg_irq;
1037733f6c3SPawel Laszczak int dev_irq;
104b1234e3bSPeter Chen int wakeup_irq;
1050b490046SPawel Laszczak struct cdns_role_driver *roles[USB_ROLE_DEVICE + 1];
1067733f6c3SPawel Laszczak enum usb_role role;
1077733f6c3SPawel Laszczak struct platform_device *host_dev;
108ac5bca14SPawel Laszczak void *gadget_dev;
1097733f6c3SPawel Laszczak struct phy *usb2_phy;
1107733f6c3SPawel Laszczak struct phy *usb3_phy;
1117733f6c3SPawel Laszczak /* mutext used in workqueue*/
1127733f6c3SPawel Laszczak struct mutex mutex;
1137733f6c3SPawel Laszczak enum usb_dr_mode dr_mode;
1147733f6c3SPawel Laszczak struct usb_role_switch *role_sw;
115b1234e3bSPeter Chen bool in_lpm;
116b1234e3bSPeter Chen bool wakeup_pending;
117b1234e3bSPeter Chen struct cdns3_platform_data *pdata;
118b1234e3bSPeter Chen spinlock_t lock;
1197cea9657SPeter Chen struct xhci_plat_priv *xhci_plat_data;
120394c3a14SPawel Laszczak
1210b490046SPawel Laszczak int (*gadget_init)(struct cdns *cdns);
1227733f6c3SPawel Laszczak };
1237733f6c3SPawel Laszczak
1240b490046SPawel Laszczak int cdns_hw_role_switch(struct cdns *cdns);
1250b490046SPawel Laszczak int cdns_init(struct cdns *cdns);
1260b490046SPawel Laszczak int cdns_remove(struct cdns *cdns);
1277733f6c3SPawel Laszczak
128f7389572SPawel Laszczak #ifdef CONFIG_PM_SLEEP
1292319b9c8SXiaolei Wang int cdns_resume(struct cdns *cdns);
1300b490046SPawel Laszczak int cdns_suspend(struct cdns *cdns);
1312319b9c8SXiaolei Wang void cdns_set_active(struct cdns *cdns, u8 set_active);
13228a25ba3SRandy Dunlap #else /* CONFIG_PM_SLEEP */
cdns_resume(struct cdns * cdns)1332319b9c8SXiaolei Wang static inline int cdns_resume(struct cdns *cdns)
1342319b9c8SXiaolei Wang { return 0; }
cdns_set_active(struct cdns * cdns,u8 set_active)1359f35d612SXiaolei Wang static inline void cdns_set_active(struct cdns *cdns, u8 set_active) { }
cdns_suspend(struct cdns * cdns)13628a25ba3SRandy Dunlap static inline int cdns_suspend(struct cdns *cdns)
13728a25ba3SRandy Dunlap { return 0; }
138f7389572SPawel Laszczak #endif /* CONFIG_PM_SLEEP */
1397733f6c3SPawel Laszczak #endif /* __LINUX_CDNS3_CORE_H */
140