blob: 0e2c5b695820838b8dbc0b9cdad325656d81ec3a [file] [log] [blame]
Kuninori Morimotof1407d52011-04-04 13:44:59 +09001/*
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 */
27struct usbhs_irq_state {
28 u16 intsts0;
29 u16 intsts1;
30 u16 brdysts;
31 u16 nrdysts;
32 u16 bempsts;
Kuninori Morimotof1407d52011-04-04 13:44:59 +090033};
34
35struct 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
67struct usbhs_mod_info {
68 struct usbhs_mod *mod[USBHS_MAX];
69 struct usbhs_mod *curt; /* current mod */
Kuninori Morimotob002ff62011-04-28 16:41:20 +090070
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);
Kuninori Morimotof1407d52011-04-04 13:44:59 +090083};
84
85/*
86 * for host/gadget module
87 */
88struct usbhs_mod *usbhs_mod_get(struct usbhs_priv *priv, int id);
89struct usbhs_mod *usbhs_mod_get_current(struct usbhs_priv *priv);
90void usbhs_mod_register(struct usbhs_priv *priv, struct usbhs_mod *usb, int id);
Kuninori Morimoto0deb3e72011-10-10 22:02:45 -070091int usbhs_mod_is_host(struct usbhs_priv *priv);
Kuninori Morimotof1407d52011-04-04 13:44:59 +090092int usbhs_mod_change(struct usbhs_priv *priv, int id);
93int usbhs_mod_probe(struct usbhs_priv *priv);
94void usbhs_mod_remove(struct usbhs_priv *priv);
95
Kuninori Morimotob002ff62011-04-28 16:41:20 +090096void usbhs_mod_autonomy_mode(struct usbhs_priv *priv);
97
Kuninori Morimotof1407d52011-04-04 13:44:59 +090098/*
99 * status functions
100 */
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900101int usbhs_status_get_device_state(struct usbhs_irq_state *irq_state);
102int usbhs_status_get_ctrl_stage(struct usbhs_irq_state *irq_state);
103
104/*
105 * callback functions
106 */
107void 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
Kuninori Morimoto2f983822011-04-05 11:40:54 +0900119/*
120 * gadget control
121 */
122#ifdef CONFIG_USB_RENESAS_USBHS_UDC
123extern int __devinit usbhs_mod_gadget_probe(struct usbhs_priv *priv);
124extern void __devexit usbhs_mod_gadget_remove(struct usbhs_priv *priv);
125#else
126static inline int usbhs_mod_gadget_probe(struct usbhs_priv *priv)
127{
128 return 0;
129}
130static inline void usbhs_mod_gadget_remove(struct usbhs_priv *priv)
131{
132}
133#endif
134
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900135#endif /* RENESAS_USB_MOD_H */