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.
21 #define VDBG(fmt, args...) pr_debug("[%s] " fmt , \
24 #define VDBG(stuff...) do {} while (0)
28 #define MPC_LOC printk("Current Location [%s]:[%d]\n", __FILE__, __LINE__)
30 #define MPC_LOC do {} while (0)
33 #define PROTO_UNDEF (0)
34 #define PROTO_HOST (1)
35 #define PROTO_GADGET (2)
38 /* Standard OTG timers */
46 /* Auxiliary timers */
54 /* OTG state machine according to the OTG spec */
74 /* Internal variables */
80 /* Timeout indicator for timers */
81 int a_wait_vrise_tmout;
82 int a_wait_vfall_tmout;
83 int a_wait_bcon_tmout;
84 int a_aidl_bdis_tmout;
85 int b_ase0_brst_tmout;
86 int a_bidl_adis_tmout;
88 /* Informative variables */
92 int a_suspend_req_inf;
100 struct otg_fsm_ops *ops;
103 /* Current usb protocol used: 0:undefine; 1:host; 2:client */
109 void (*chrg_vbus)(struct otg_fsm *fsm, int on);
110 void (*drv_vbus)(struct otg_fsm *fsm, int on);
111 void (*loc_conn)(struct otg_fsm *fsm, int on);
112 void (*loc_sof)(struct otg_fsm *fsm, int on);
113 void (*start_pulse)(struct otg_fsm *fsm);
114 void (*add_timer)(struct otg_fsm *fsm, enum otg_fsm_timer timer);
115 void (*del_timer)(struct otg_fsm *fsm, enum otg_fsm_timer timer);
116 int (*start_host)(struct otg_fsm *fsm, int on);
117 int (*start_gadget)(struct otg_fsm *fsm, int on);
121 static inline int otg_chrg_vbus(struct otg_fsm *fsm, int on)
123 if (!fsm->ops->chrg_vbus)
125 fsm->ops->chrg_vbus(fsm, on);
129 static inline int otg_drv_vbus(struct otg_fsm *fsm, int on)
131 if (!fsm->ops->drv_vbus)
133 if (fsm->drv_vbus != on) {
135 fsm->ops->drv_vbus(fsm, on);
140 static inline int otg_loc_conn(struct otg_fsm *fsm, int on)
142 if (!fsm->ops->loc_conn)
144 if (fsm->loc_conn != on) {
146 fsm->ops->loc_conn(fsm, on);
151 static inline int otg_loc_sof(struct otg_fsm *fsm, int on)
153 if (!fsm->ops->loc_sof)
155 if (fsm->loc_sof != on) {
157 fsm->ops->loc_sof(fsm, on);
162 static inline int otg_start_pulse(struct otg_fsm *fsm)
164 if (!fsm->ops->start_pulse)
166 fsm->ops->start_pulse(fsm);
170 static inline int otg_add_timer(struct otg_fsm *fsm, enum otg_fsm_timer timer)
172 if (!fsm->ops->add_timer)
174 fsm->ops->add_timer(fsm, timer);
178 static inline int otg_del_timer(struct otg_fsm *fsm, enum otg_fsm_timer timer)
180 if (!fsm->ops->del_timer)
182 fsm->ops->del_timer(fsm, timer);
186 static inline int otg_start_host(struct otg_fsm *fsm, int on)
188 if (!fsm->ops->start_host)
190 return fsm->ops->start_host(fsm, on);
193 static inline int otg_start_gadget(struct otg_fsm *fsm, int on)
195 if (!fsm->ops->start_gadget)
197 return fsm->ops->start_gadget(fsm, on);
200 int otg_statemachine(struct otg_fsm *fsm);