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)
37 /* OTG state machine according to the OTG spec */
54 /* Internal variables */
59 /* Timeout indicator for timers */
60 int a_wait_vrise_tmout
;
61 int a_wait_bcon_tmout
;
62 int a_aidl_bdis_tmout
;
63 int b_ase0_brst_tmout
;
65 /* Informative variables */
77 struct otg_fsm_ops
*ops
;
80 /* Current usb protocol used: 0:undefine; 1:host; 2:client */
86 void (*chrg_vbus
)(int on
);
87 void (*drv_vbus
)(int on
);
88 void (*loc_conn
)(int on
);
89 void (*loc_sof
)(int on
);
90 void (*start_pulse
)(void);
91 void (*add_timer
)(void *timer
);
92 void (*del_timer
)(void *timer
);
93 int (*start_host
)(struct otg_fsm
*fsm
, int on
);
94 int (*start_gadget
)(struct otg_fsm
*fsm
, int on
);
98 static inline void otg_chrg_vbus(struct otg_fsm
*fsm
, int on
)
100 fsm
->ops
->chrg_vbus(on
);
103 static inline void otg_drv_vbus(struct otg_fsm
*fsm
, int on
)
105 if (fsm
->drv_vbus
!= on
) {
107 fsm
->ops
->drv_vbus(on
);
111 static inline void otg_loc_conn(struct otg_fsm
*fsm
, int on
)
113 if (fsm
->loc_conn
!= on
) {
115 fsm
->ops
->loc_conn(on
);
119 static inline void otg_loc_sof(struct otg_fsm
*fsm
, int on
)
121 if (fsm
->loc_sof
!= on
) {
123 fsm
->ops
->loc_sof(on
);
127 static inline void otg_start_pulse(struct otg_fsm
*fsm
)
129 fsm
->ops
->start_pulse();
132 static inline void otg_add_timer(struct otg_fsm
*fsm
, void *timer
)
134 fsm
->ops
->add_timer(timer
);
137 static inline void otg_del_timer(struct otg_fsm
*fsm
, void *timer
)
139 fsm
->ops
->del_timer(timer
);
142 int otg_statemachine(struct otg_fsm
*fsm
);
144 /* Defined by device specific driver, for different timer implementation */
145 extern struct fsl_otg_timer
*a_wait_vrise_tmr
, *a_wait_bcon_tmr
,
146 *a_aidl_bdis_tmr
, *b_ase0_brst_tmr
, *b_se0_srp_tmr
, *b_srp_fail_tmr
,