1 /* Copyright (C) 2007,2008 Freescale Semiconductor, Inc.
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.
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.
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.
18 #include <linux/spinlock.h>
19 #include <linux/errno.h>
24 #define VDBG(fmt, args...) pr_debug("[%s] " fmt , \
27 #define VDBG(stuff...) do {} while (0)
31 #define MPC_LOC printk("Current Location [%s]:[%d]\n", __FILE__, __LINE__)
33 #define MPC_LOC do {} while (0)
36 #define PROTO_UNDEF (0)
37 #define PROTO_HOST (1)
38 #define PROTO_GADGET (2)
41 /* Standard OTG timers */
49 /* Auxiliary timers */
57 /* OTG state machine according to the OTG spec */
89 /* Internal variables */
95 /* Informative variables */
100 /* Auxilary informative variables */
101 int a_suspend_req_inf;
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;
111 struct otg_fsm_ops *ops;
114 /* Current usb protocol used: 0:undefine; 1:host; 2:client */
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);
134 static inline int otg_chrg_vbus(struct otg_fsm *fsm, int on)
136 if (!fsm->ops->chrg_vbus)
138 fsm->ops->chrg_vbus(fsm, on);
142 static inline int otg_drv_vbus(struct otg_fsm *fsm, int on)
144 if (!fsm->ops->drv_vbus)
146 if (fsm->drv_vbus != on) {
148 fsm->ops->drv_vbus(fsm, on);
153 static inline int otg_loc_conn(struct otg_fsm *fsm, int on)
155 if (!fsm->ops->loc_conn)
157 if (fsm->loc_conn != on) {
159 fsm->ops->loc_conn(fsm, on);
164 static inline int otg_loc_sof(struct otg_fsm *fsm, int on)
166 if (!fsm->ops->loc_sof)
168 if (fsm->loc_sof != on) {
170 fsm->ops->loc_sof(fsm, on);
175 static inline int otg_start_pulse(struct otg_fsm *fsm)
177 if (!fsm->ops->start_pulse)
179 if (!fsm->data_pulse) {
181 fsm->ops->start_pulse(fsm);
186 static inline int otg_start_adp_prb(struct otg_fsm *fsm)
188 if (!fsm->ops->start_adp_prb)
193 fsm->ops->start_adp_prb(fsm);
198 static inline int otg_start_adp_sns(struct otg_fsm *fsm)
200 if (!fsm->ops->start_adp_sns)
204 fsm->ops->start_adp_sns(fsm);
209 static inline int otg_add_timer(struct otg_fsm *fsm, enum otg_fsm_timer timer)
211 if (!fsm->ops->add_timer)
213 fsm->ops->add_timer(fsm, timer);
217 static inline int otg_del_timer(struct otg_fsm *fsm, enum otg_fsm_timer timer)
219 if (!fsm->ops->del_timer)
221 fsm->ops->del_timer(fsm, timer);
225 static inline int otg_start_host(struct otg_fsm *fsm, int on)
227 if (!fsm->ops->start_host)
229 return fsm->ops->start_host(fsm, on);
232 static inline int otg_start_gadget(struct otg_fsm *fsm, int on)
234 if (!fsm->ops->start_gadget)
236 return fsm->ops->start_gadget(fsm, on);
239 int otg_statemachine(struct otg_fsm *fsm);