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 */
86 /* Internal variables */
92 /* Informative variables */
97 /* Auxilary informative variables */
98 int a_suspend_req_inf;
100 /* Timeout indicator for timers */
101 int a_wait_vrise_tmout;
102 int a_wait_vfall_tmout;
103 int a_wait_bcon_tmout;
104 int a_aidl_bdis_tmout;
105 int b_ase0_brst_tmout;
106 int a_bidl_adis_tmout;
108 struct otg_fsm_ops *ops;
111 /* Current usb protocol used: 0:undefine; 1:host; 2:client */
117 void (*chrg_vbus)(struct otg_fsm *fsm, int on);
118 void (*drv_vbus)(struct otg_fsm *fsm, int on);
119 void (*loc_conn)(struct otg_fsm *fsm, int on);
120 void (*loc_sof)(struct otg_fsm *fsm, int on);
121 void (*start_pulse)(struct otg_fsm *fsm);
122 void (*start_adp_prb)(struct otg_fsm *fsm);
123 void (*start_adp_sns)(struct otg_fsm *fsm);
124 void (*add_timer)(struct otg_fsm *fsm, enum otg_fsm_timer timer);
125 void (*del_timer)(struct otg_fsm *fsm, enum otg_fsm_timer timer);
126 int (*start_host)(struct otg_fsm *fsm, int on);
127 int (*start_gadget)(struct otg_fsm *fsm, int on);
131 static inline int otg_chrg_vbus(struct otg_fsm *fsm, int on)
133 if (!fsm->ops->chrg_vbus)
135 fsm->ops->chrg_vbus(fsm, on);
139 static inline int otg_drv_vbus(struct otg_fsm *fsm, int on)
141 if (!fsm->ops->drv_vbus)
143 if (fsm->drv_vbus != on) {
145 fsm->ops->drv_vbus(fsm, on);
150 static inline int otg_loc_conn(struct otg_fsm *fsm, int on)
152 if (!fsm->ops->loc_conn)
154 if (fsm->loc_conn != on) {
156 fsm->ops->loc_conn(fsm, on);
161 static inline int otg_loc_sof(struct otg_fsm *fsm, int on)
163 if (!fsm->ops->loc_sof)
165 if (fsm->loc_sof != on) {
167 fsm->ops->loc_sof(fsm, on);
172 static inline int otg_start_pulse(struct otg_fsm *fsm)
174 if (!fsm->ops->start_pulse)
176 if (!fsm->data_pulse) {
178 fsm->ops->start_pulse(fsm);
183 static inline int otg_start_adp_prb(struct otg_fsm *fsm)
185 if (!fsm->ops->start_adp_prb)
190 fsm->ops->start_adp_prb(fsm);
195 static inline int otg_start_adp_sns(struct otg_fsm *fsm)
197 if (!fsm->ops->start_adp_sns)
201 fsm->ops->start_adp_sns(fsm);
206 static inline int otg_add_timer(struct otg_fsm *fsm, enum otg_fsm_timer timer)
208 if (!fsm->ops->add_timer)
210 fsm->ops->add_timer(fsm, timer);
214 static inline int otg_del_timer(struct otg_fsm *fsm, enum otg_fsm_timer timer)
216 if (!fsm->ops->del_timer)
218 fsm->ops->del_timer(fsm, timer);
222 static inline int otg_start_host(struct otg_fsm *fsm, int on)
224 if (!fsm->ops->start_host)
226 return fsm->ops->start_host(fsm, on);
229 static inline int otg_start_gadget(struct otg_fsm *fsm, int on)
231 if (!fsm->ops->start_gadget)
233 return fsm->ops->start_gadget(fsm, on);
236 int otg_statemachine(struct otg_fsm *fsm);