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