USB: add SPDX identifiers to all remaining files in drivers/usb/
[linux-2.6-block.git] / drivers / usb / renesas_usbhs / mod.h
1 // SPDX-License-Identifier: GPL-1.0+
2 /*
3  * Renesas USB driver
4  *
5  * Copyright (C) 2011 Renesas Solutions Corp.
6  * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
16  *
17  */
18 #ifndef RENESAS_USB_MOD_H
19 #define RENESAS_USB_MOD_H
20
21 #include <linux/spinlock.h>
22 #include <linux/usb/renesas_usbhs.h>
23 #include "common.h"
24
25 /*
26  *      struct
27  */
28 struct usbhs_irq_state {
29         u16 intsts0;
30         u16 intsts1;
31         u16 brdysts;
32         u16 nrdysts;
33         u16 bempsts;
34 };
35
36 struct usbhs_mod {
37         char *name;
38
39         /*
40          * entry point from common.c
41          */
42         int (*start)(struct usbhs_priv *priv);
43         int (*stop)(struct usbhs_priv *priv);
44
45         /*
46          * INTSTS0
47          */
48
49         /* DVST (DVSQ) */
50         int (*irq_dev_state)(struct usbhs_priv *priv,
51                              struct usbhs_irq_state *irq_state);
52
53         /* CTRT (CTSQ) */
54         int (*irq_ctrl_stage)(struct usbhs_priv *priv,
55                               struct usbhs_irq_state *irq_state);
56
57         /* BEMP / BEMPSTS */
58         int (*irq_empty)(struct usbhs_priv *priv,
59                          struct usbhs_irq_state *irq_state);
60         u16 irq_bempsts;
61
62         /* BRDY / BRDYSTS */
63         int (*irq_ready)(struct usbhs_priv *priv,
64                          struct usbhs_irq_state *irq_state);
65         u16 irq_brdysts;
66
67         /*
68          * INTSTS1
69          */
70
71         /* ATTCHE */
72         int (*irq_attch)(struct usbhs_priv *priv,
73                          struct usbhs_irq_state *irq_state);
74
75         /* DTCHE */
76         int (*irq_dtch)(struct usbhs_priv *priv,
77                         struct usbhs_irq_state *irq_state);
78
79         /* SIGN */
80         int (*irq_sign)(struct usbhs_priv *priv,
81                         struct usbhs_irq_state *irq_state);
82
83         /* SACK */
84         int (*irq_sack)(struct usbhs_priv *priv,
85                         struct usbhs_irq_state *irq_state);
86
87         struct usbhs_priv *priv;
88 };
89
90 struct usbhs_mod_info {
91         struct usbhs_mod *mod[USBHS_MAX];
92         struct usbhs_mod *curt; /* current mod */
93
94         /*
95          * INTSTS0 :: VBINT
96          *
97          * This function will be used as autonomy mode
98          * when platform cannot call notify_hotplug.
99          *
100          * This callback cannot be member of "struct usbhs_mod"
101          * because it will be used even though
102          * host/gadget has not been selected.
103          */
104         int (*irq_vbus)(struct usbhs_priv *priv,
105                         struct usbhs_irq_state *irq_state);
106 };
107
108 /*
109  *              for host/gadget module
110  */
111 struct usbhs_mod *usbhs_mod_get(struct usbhs_priv *priv, int id);
112 struct usbhs_mod *usbhs_mod_get_current(struct usbhs_priv *priv);
113 void usbhs_mod_register(struct usbhs_priv *priv, struct usbhs_mod *usb, int id);
114 int usbhs_mod_is_host(struct usbhs_priv *priv);
115 int usbhs_mod_change(struct usbhs_priv *priv, int id);
116 int usbhs_mod_probe(struct usbhs_priv *priv);
117 void usbhs_mod_remove(struct usbhs_priv *priv);
118
119 void usbhs_mod_autonomy_mode(struct usbhs_priv *priv);
120
121 /*
122  *              status functions
123  */
124 int usbhs_status_get_device_state(struct usbhs_irq_state *irq_state);
125 int usbhs_status_get_ctrl_stage(struct usbhs_irq_state *irq_state);
126
127 /*
128  *              callback functions
129  */
130 void usbhs_irq_callback_update(struct usbhs_priv *priv, struct usbhs_mod *mod);
131
132
133 #define usbhs_mod_call(priv, func, param...)            \
134         ({                                              \
135                 struct usbhs_mod *mod;                  \
136                 mod = usbhs_mod_get_current(priv);      \
137                 !mod            ? -ENODEV :             \
138                 !mod->func      ? 0 :                   \
139                  mod->func(param);                      \
140         })
141
142 /*
143  * host / gadget control
144  */
145 #if     defined(CONFIG_USB_RENESAS_USBHS_HCD) || \
146         defined(CONFIG_USB_RENESAS_USBHS_HCD_MODULE)
147 extern int usbhs_mod_host_probe(struct usbhs_priv *priv);
148 extern int usbhs_mod_host_remove(struct usbhs_priv *priv);
149 #else
150 static inline int usbhs_mod_host_probe(struct usbhs_priv *priv)
151 {
152         return 0;
153 }
154 static inline void usbhs_mod_host_remove(struct usbhs_priv *priv)
155 {
156 }
157 #endif
158
159 #if     defined(CONFIG_USB_RENESAS_USBHS_UDC) || \
160         defined(CONFIG_USB_RENESAS_USBHS_UDC_MODULE)
161 extern int usbhs_mod_gadget_probe(struct usbhs_priv *priv);
162 extern void usbhs_mod_gadget_remove(struct usbhs_priv *priv);
163 #else
164 static inline int usbhs_mod_gadget_probe(struct usbhs_priv *priv)
165 {
166         return 0;
167 }
168 static inline void usbhs_mod_gadget_remove(struct usbhs_priv *priv)
169 {
170 }
171 #endif
172
173 #endif /* RENESAS_USB_MOD_H */