usb: phy: fsm: don't depend on indirect includes
[platform/adaptation/renesas_rcar/renesas_kernel.git] / drivers / usb / phy / phy-fsm-usb.h
1 /* Copyright (C) 2007,2008 Freescale Semiconductor, Inc.
2  *
3  * This program is free software; you can redistribute  it and/or modify it
4  * under  the terms of  the GNU General  Public License as published by the
5  * Free Software Foundation;  either version 2 of the  License, or (at your
6  * option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the  GNU General Public License along
14  * with this program; if not, write  to the Free Software Foundation, Inc.,
15  * 675 Mass Ave, Cambridge, MA 02139, USA.
16  */
17
18 #include <linux/spinlock.h>
19 #include <linux/errno.h>
20
21 #undef VERBOSE
22
23 #ifdef VERBOSE
24 #define VDBG(fmt, args...) pr_debug("[%s]  " fmt , \
25                                  __func__, ## args)
26 #else
27 #define VDBG(stuff...)  do {} while (0)
28 #endif
29
30 #ifdef VERBOSE
31 #define MPC_LOC printk("Current Location [%s]:[%d]\n", __FILE__, __LINE__)
32 #else
33 #define MPC_LOC do {} while (0)
34 #endif
35
36 #define PROTO_UNDEF     (0)
37 #define PROTO_HOST      (1)
38 #define PROTO_GADGET    (2)
39
40 enum otg_fsm_timer {
41         /* Standard OTG timers */
42         A_WAIT_VRISE,
43         A_WAIT_VFALL,
44         A_WAIT_BCON,
45         A_AIDL_BDIS,
46         B_ASE0_BRST,
47         A_BIDL_ADIS,
48
49         /* Auxiliary timers */
50         B_SE0_SRP,
51         B_SRP_FAIL,
52         A_WAIT_ENUM,
53
54         NUM_OTG_FSM_TIMERS,
55 };
56
57 /* OTG state machine according to the OTG spec */
58 struct otg_fsm {
59         /* Input */
60         int id;
61         int adp_change;
62         int power_up;
63         int test_device;
64         int a_bus_drop;
65         int a_bus_req;
66         int a_srp_det;
67         int a_vbus_vld;
68         int b_conn;
69         int a_bus_resume;
70         int a_bus_suspend;
71         int a_conn;
72         int b_bus_req;
73         int b_se0_srp;
74         int b_ssend_srp;
75         int b_sess_vld;
76         /* Auxilary inputs */
77         int a_sess_vld;
78         int b_bus_resume;
79         int b_bus_suspend;
80
81         /* Output */
82         int data_pulse;
83         int drv_vbus;
84         int loc_conn;
85         int loc_sof;
86         int adp_prb;
87         int adp_sns;
88
89         /* Internal variables */
90         int a_set_b_hnp_en;
91         int b_srp_done;
92         int b_hnp_enable;
93         int a_clr_err;
94
95         /* Informative variables */
96         int a_bus_drop_inf;
97         int a_bus_req_inf;
98         int a_clr_err_inf;
99         int b_bus_req_inf;
100         /* Auxilary informative variables */
101         int a_suspend_req_inf;
102
103         /* Timeout indicator for timers */
104         int a_wait_vrise_tmout;
105         int a_wait_vfall_tmout;
106         int a_wait_bcon_tmout;
107         int a_aidl_bdis_tmout;
108         int b_ase0_brst_tmout;
109         int a_bidl_adis_tmout;
110
111         struct otg_fsm_ops *ops;
112         struct usb_otg *otg;
113
114         /* Current usb protocol used: 0:undefine; 1:host; 2:client */
115         int protocol;
116         spinlock_t lock;
117 };
118
119 struct otg_fsm_ops {
120         void    (*chrg_vbus)(struct otg_fsm *fsm, int on);
121         void    (*drv_vbus)(struct otg_fsm *fsm, int on);
122         void    (*loc_conn)(struct otg_fsm *fsm, int on);
123         void    (*loc_sof)(struct otg_fsm *fsm, int on);
124         void    (*start_pulse)(struct otg_fsm *fsm);
125         void    (*start_adp_prb)(struct otg_fsm *fsm);
126         void    (*start_adp_sns)(struct otg_fsm *fsm);
127         void    (*add_timer)(struct otg_fsm *fsm, enum otg_fsm_timer timer);
128         void    (*del_timer)(struct otg_fsm *fsm, enum otg_fsm_timer timer);
129         int     (*start_host)(struct otg_fsm *fsm, int on);
130         int     (*start_gadget)(struct otg_fsm *fsm, int on);
131 };
132
133
134 static inline int otg_chrg_vbus(struct otg_fsm *fsm, int on)
135 {
136         if (!fsm->ops->chrg_vbus)
137                 return -EOPNOTSUPP;
138         fsm->ops->chrg_vbus(fsm, on);
139         return 0;
140 }
141
142 static inline int otg_drv_vbus(struct otg_fsm *fsm, int on)
143 {
144         if (!fsm->ops->drv_vbus)
145                 return -EOPNOTSUPP;
146         if (fsm->drv_vbus != on) {
147                 fsm->drv_vbus = on;
148                 fsm->ops->drv_vbus(fsm, on);
149         }
150         return 0;
151 }
152
153 static inline int otg_loc_conn(struct otg_fsm *fsm, int on)
154 {
155         if (!fsm->ops->loc_conn)
156                 return -EOPNOTSUPP;
157         if (fsm->loc_conn != on) {
158                 fsm->loc_conn = on;
159                 fsm->ops->loc_conn(fsm, on);
160         }
161         return 0;
162 }
163
164 static inline int otg_loc_sof(struct otg_fsm *fsm, int on)
165 {
166         if (!fsm->ops->loc_sof)
167                 return -EOPNOTSUPP;
168         if (fsm->loc_sof != on) {
169                 fsm->loc_sof = on;
170                 fsm->ops->loc_sof(fsm, on);
171         }
172         return 0;
173 }
174
175 static inline int otg_start_pulse(struct otg_fsm *fsm)
176 {
177         if (!fsm->ops->start_pulse)
178                 return -EOPNOTSUPP;
179         if (!fsm->data_pulse) {
180                 fsm->data_pulse = 1;
181                 fsm->ops->start_pulse(fsm);
182         }
183         return 0;
184 }
185
186 static inline int otg_start_adp_prb(struct otg_fsm *fsm)
187 {
188         if (!fsm->ops->start_adp_prb)
189                 return -EOPNOTSUPP;
190         if (!fsm->adp_prb) {
191                 fsm->adp_sns = 0;
192                 fsm->adp_prb = 1;
193                 fsm->ops->start_adp_prb(fsm);
194         }
195         return 0;
196 }
197
198 static inline int otg_start_adp_sns(struct otg_fsm *fsm)
199 {
200         if (!fsm->ops->start_adp_sns)
201                 return -EOPNOTSUPP;
202         if (!fsm->adp_sns) {
203                 fsm->adp_sns = 1;
204                 fsm->ops->start_adp_sns(fsm);
205         }
206         return 0;
207 }
208
209 static inline int otg_add_timer(struct otg_fsm *fsm, enum otg_fsm_timer timer)
210 {
211         if (!fsm->ops->add_timer)
212                 return -EOPNOTSUPP;
213         fsm->ops->add_timer(fsm, timer);
214         return 0;
215 }
216
217 static inline int otg_del_timer(struct otg_fsm *fsm, enum otg_fsm_timer timer)
218 {
219         if (!fsm->ops->del_timer)
220                 return -EOPNOTSUPP;
221         fsm->ops->del_timer(fsm, timer);
222         return 0;
223 }
224
225 static inline int otg_start_host(struct otg_fsm *fsm, int on)
226 {
227         if (!fsm->ops->start_host)
228                 return -EOPNOTSUPP;
229         return fsm->ops->start_host(fsm, on);
230 }
231
232 static inline int otg_start_gadget(struct otg_fsm *fsm, int on)
233 {
234         if (!fsm->ops->start_gadget)
235                 return -EOPNOTSUPP;
236         return fsm->ops->start_gadget(fsm, on);
237 }
238
239 int otg_statemachine(struct otg_fsm *fsm);