Commit | Line | Data |
---|---|---|
d28e6171 | 1 | /* SPDX-License-Identifier: GPL-1.0+ */ |
f1407d5c KM |
2 | /* |
3 | * Renesas USB driver | |
4 | * | |
5 | * Copyright (C) 2011 Renesas Solutions Corp. | |
8fac4fee | 6 | * Copyright (C) 2019 Renesas Electronics Corporation |
f1407d5c | 7 | * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> |
f1407d5c KM |
8 | */ |
9 | #ifndef RENESAS_USB_MOD_H | |
10 | #define RENESAS_USB_MOD_H | |
11 | ||
12 | #include <linux/spinlock.h> | |
13 | #include <linux/usb/renesas_usbhs.h> | |
cc502bb7 | 14 | #include "common.h" |
f1407d5c KM |
15 | |
16 | /* | |
17 | * struct | |
18 | */ | |
19 | struct usbhs_irq_state { | |
20 | u16 intsts0; | |
21 | u16 intsts1; | |
22 | u16 brdysts; | |
23 | u16 nrdysts; | |
24 | u16 bempsts; | |
f1407d5c KM |
25 | }; |
26 | ||
27 | struct usbhs_mod { | |
28 | char *name; | |
29 | ||
30 | /* | |
31 | * entry point from common.c | |
32 | */ | |
33 | int (*start)(struct usbhs_priv *priv); | |
34 | int (*stop)(struct usbhs_priv *priv); | |
35 | ||
89c1d2e7 KM |
36 | /* |
37 | * INTSTS0 | |
38 | */ | |
39 | ||
40 | /* DVST (DVSQ) */ | |
f1407d5c KM |
41 | int (*irq_dev_state)(struct usbhs_priv *priv, |
42 | struct usbhs_irq_state *irq_state); | |
43 | ||
89c1d2e7 | 44 | /* CTRT (CTSQ) */ |
f1407d5c KM |
45 | int (*irq_ctrl_stage)(struct usbhs_priv *priv, |
46 | struct usbhs_irq_state *irq_state); | |
47 | ||
89c1d2e7 | 48 | /* BEMP / BEMPSTS */ |
f1407d5c KM |
49 | int (*irq_empty)(struct usbhs_priv *priv, |
50 | struct usbhs_irq_state *irq_state); | |
51 | u16 irq_bempsts; | |
52 | ||
89c1d2e7 | 53 | /* BRDY / BRDYSTS */ |
f1407d5c KM |
54 | int (*irq_ready)(struct usbhs_priv *priv, |
55 | struct usbhs_irq_state *irq_state); | |
56 | u16 irq_brdysts; | |
57 | ||
89c1d2e7 KM |
58 | /* |
59 | * INTSTS1 | |
60 | */ | |
61 | ||
62 | /* ATTCHE */ | |
63 | int (*irq_attch)(struct usbhs_priv *priv, | |
64 | struct usbhs_irq_state *irq_state); | |
65 | ||
66 | /* DTCHE */ | |
67 | int (*irq_dtch)(struct usbhs_priv *priv, | |
68 | struct usbhs_irq_state *irq_state); | |
69 | ||
70 | /* SIGN */ | |
71 | int (*irq_sign)(struct usbhs_priv *priv, | |
72 | struct usbhs_irq_state *irq_state); | |
73 | ||
74 | /* SACK */ | |
75 | int (*irq_sack)(struct usbhs_priv *priv, | |
76 | struct usbhs_irq_state *irq_state); | |
77 | ||
f1407d5c KM |
78 | struct usbhs_priv *priv; |
79 | }; | |
80 | ||
81 | struct usbhs_mod_info { | |
82 | struct usbhs_mod *mod[USBHS_MAX]; | |
83 | struct usbhs_mod *curt; /* current mod */ | |
b002ff6e KM |
84 | |
85 | /* | |
86 | * INTSTS0 :: VBINT | |
87 | * | |
8fac4fee YS |
88 | * This function will be used as autonomy mode (runtime_pwctrl == 0) |
89 | * when the platform doesn't have own get_vbus function. | |
b002ff6e | 90 | * |
8fac4fee YS |
91 | * This callback cannot be member of "struct usbhs_mod" because it |
92 | * will be used even though host/gadget has not been selected. | |
b002ff6e KM |
93 | */ |
94 | int (*irq_vbus)(struct usbhs_priv *priv, | |
95 | struct usbhs_irq_state *irq_state); | |
ccc3264c YS |
96 | |
97 | /* | |
98 | * This function will be used on any gadget mode. To simplify the code, | |
99 | * this member is in here. | |
100 | */ | |
101 | int (*get_vbus)(struct platform_device *pdev); | |
f1407d5c KM |
102 | }; |
103 | ||
104 | /* | |
105 | * for host/gadget module | |
106 | */ | |
107 | struct usbhs_mod *usbhs_mod_get(struct usbhs_priv *priv, int id); | |
108 | struct usbhs_mod *usbhs_mod_get_current(struct usbhs_priv *priv); | |
109 | void usbhs_mod_register(struct usbhs_priv *priv, struct usbhs_mod *usb, int id); | |
0deb3e77 | 110 | int usbhs_mod_is_host(struct usbhs_priv *priv); |
f1407d5c KM |
111 | int usbhs_mod_change(struct usbhs_priv *priv, int id); |
112 | int usbhs_mod_probe(struct usbhs_priv *priv); | |
113 | void usbhs_mod_remove(struct usbhs_priv *priv); | |
114 | ||
b002ff6e | 115 | void usbhs_mod_autonomy_mode(struct usbhs_priv *priv); |
ccc3264c | 116 | void usbhs_mod_non_autonomy_mode(struct usbhs_priv *priv); |
b002ff6e | 117 | |
f1407d5c KM |
118 | /* |
119 | * status functions | |
120 | */ | |
f1407d5c KM |
121 | int usbhs_status_get_device_state(struct usbhs_irq_state *irq_state); |
122 | int usbhs_status_get_ctrl_stage(struct usbhs_irq_state *irq_state); | |
123 | ||
124 | /* | |
125 | * callback functions | |
126 | */ | |
127 | void usbhs_irq_callback_update(struct usbhs_priv *priv, struct usbhs_mod *mod); | |
128 | ||
129 | ||
130 | #define usbhs_mod_call(priv, func, param...) \ | |
131 | ({ \ | |
132 | struct usbhs_mod *mod; \ | |
133 | mod = usbhs_mod_get_current(priv); \ | |
134 | !mod ? -ENODEV : \ | |
135 | !mod->func ? 0 : \ | |
136 | mod->func(param); \ | |
137 | }) | |
138 | ||
edcf2b2c YS |
139 | #define usbhs_priv_to_modinfo(priv) (&priv->mod_info) |
140 | #define usbhs_mod_info_call(priv, func, param...) \ | |
141 | ({ \ | |
142 | struct usbhs_mod_info *info; \ | |
143 | info = usbhs_priv_to_modinfo(priv); \ | |
144 | !info->func ? 0 : \ | |
145 | info->func(param); \ | |
146 | }) | |
147 | ||
2f98382d | 148 | /* |
034d7c13 | 149 | * host / gadget control |
2f98382d | 150 | */ |
951fe829 KM |
151 | #if defined(CONFIG_USB_RENESAS_USBHS_HCD) || \ |
152 | defined(CONFIG_USB_RENESAS_USBHS_HCD_MODULE) | |
b7a8d17d KM |
153 | extern int usbhs_mod_host_probe(struct usbhs_priv *priv); |
154 | extern int usbhs_mod_host_remove(struct usbhs_priv *priv); | |
034d7c13 KM |
155 | #else |
156 | static inline int usbhs_mod_host_probe(struct usbhs_priv *priv) | |
157 | { | |
158 | return 0; | |
159 | } | |
160 | static inline void usbhs_mod_host_remove(struct usbhs_priv *priv) | |
161 | { | |
162 | } | |
163 | #endif | |
164 | ||
951fe829 KM |
165 | #if defined(CONFIG_USB_RENESAS_USBHS_UDC) || \ |
166 | defined(CONFIG_USB_RENESAS_USBHS_UDC_MODULE) | |
b7a8d17d KM |
167 | extern int usbhs_mod_gadget_probe(struct usbhs_priv *priv); |
168 | extern void usbhs_mod_gadget_remove(struct usbhs_priv *priv); | |
2f98382d KM |
169 | #else |
170 | static inline int usbhs_mod_gadget_probe(struct usbhs_priv *priv) | |
171 | { | |
172 | return 0; | |
173 | } | |
174 | static inline void usbhs_mod_gadget_remove(struct usbhs_priv *priv) | |
175 | { | |
176 | } | |
177 | #endif | |
178 | ||
f1407d5c | 179 | #endif /* RENESAS_USB_MOD_H */ |