• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Cadence USBSS 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 #include <linux/compiler.h>
12 #include <linux/types.h>
13 #include <linux/usb/otg.h>
14 #include <generic-phy.h>
15 
16 #ifndef __LINUX_CDNS3_CORE_H
17 #define __LINUX_CDNS3_CORE_H
18 
19 enum usb_role {
20 	USB_ROLE_NONE,
21 	USB_ROLE_HOST,
22 	USB_ROLE_DEVICE,
23 };
24 
25 struct cdns3;
26 
27 /**
28  * struct cdns3_role_driver - host/gadget role driver
29  * @start: start this role
30  * @stop: stop this role
31  * @suspend: suspend callback for this role
32  * @resume: resume callback for this role
33  * @irq: irq handler for this role
34  * @name: role name string (host/gadget)
35  * @state: current state
36  */
37 struct cdns3_role_driver {
38 	int (*start)(struct cdns3 *cdns);
39 	void (*stop)(struct cdns3 *cdns);
40 	int (*suspend)(struct cdns3 *cdns, bool do_wakeup);
41 	int (*resume)(struct cdns3 *cdns, bool hibernated);
42 	const char *name;
43 #define CDNS3_ROLE_STATE_INACTIVE	0
44 #define CDNS3_ROLE_STATE_ACTIVE		1
45 	int state;
46 };
47 
48 #define CDNS3_XHCI_RESOURCES_NUM	2
49 /**
50  * struct cdns3 - Representation of Cadence USB3 DRD controller.
51  * @dev: pointer to Cadence device struct
52  * @xhci_regs: pointer to base of xhci registers
53  * @dev_regs: pointer to base of dev registers
54  * @otg_v0_regs: pointer to base of v0 otg registers
55  * @otg_v1_regs: pointer to base of v1 otg registers
56  * @otg_regs: pointer to base of otg registers
57  * @otg_irq: irq number for otg controller
58  * @dev_irq: irq number for device controller
59  * @roles: array of supported roles for this controller
60  * @role: current role
61  * @host_dev: the child host device pointer for cdns3 core
62  * @gadget_dev: the child gadget device pointer for cdns3 core
63  * @usb2_phy: pointer to USB2 PHY
64  * @usb3_phy: pointer to USB3 PHY
65  * @mutex: the mutex for concurrent code at driver
66  * @dr_mode: supported mode of operation it can be only Host, only Device
67  *           or OTG mode that allow to switch between Device and Host mode.
68  *           This field based on firmware setting, kernel configuration
69  *           and hardware configuration.
70  * @role_sw: pointer to role switch object.
71  * @role_override: set 1 if role rely on SW.
72  */
73 struct cdns3 {
74 	struct udevice			*dev;
75 	void __iomem			*xhci_regs;
76 	struct cdns3_usb_regs __iomem	*dev_regs;
77 
78 	struct cdns3_otg_legacy_regs	*otg_v0_regs;
79 	struct cdns3_otg_regs		*otg_v1_regs;
80 	struct cdns3_otg_common_regs	*otg_regs;
81 #define CDNS3_CONTROLLER_V0	0
82 #define CDNS3_CONTROLLER_V1	1
83 	u32				version;
84 
85 	int				otg_irq;
86 	int				dev_irq;
87 	struct cdns3_role_driver	*roles[USB_ROLE_DEVICE + 1];
88 	enum usb_role			role;
89 	struct cdns3_device		*gadget_dev;
90 	struct phy			usb2_phy;
91 	struct phy			usb3_phy;
92 	/* mutext used in workqueue*/
93 	struct mutex			mutex;
94 	enum usb_dr_mode		dr_mode;
95 	int				role_override;
96 };
97 
98 int cdns3_hw_role_switch(struct cdns3 *cdns);
99 
100 /**
101  * cdns3_bind - generic bind function
102  * @parent - pointer to parent udevice of which cdns3 USB controller
103  *           node is child of
104  *
105  * return 0 on success, negative errno otherwise
106  */
107 int cdns3_bind(struct udevice *dev);
108 #endif /* __LINUX_CDNS3_CORE_H */
109