Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v4.14-rc2 323 lines 8.8 kB view raw
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#ifndef __LINUX_USB_OTG_FSM_H 19#define __LINUX_USB_OTG_FSM_H 20 21#include <linux/mutex.h> 22#include <linux/errno.h> 23 24#define PROTO_UNDEF (0) 25#define PROTO_HOST (1) 26#define PROTO_GADGET (2) 27 28#define OTG_STS_SELECTOR 0xF000 /* OTG status selector, according to 29 * OTG and EH 2.0 Chapter 6.2.3 30 * Table:6-4 31 */ 32 33#define HOST_REQUEST_FLAG 1 /* Host request flag, according to 34 * OTG and EH 2.0 Charpter 6.2.3 35 * Table:6-5 36 */ 37 38#define T_HOST_REQ_POLL (1500) /* 1500ms, HNP polling interval */ 39 40enum 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 B_AIDL_BDIS, 49 50 /* Auxiliary timers */ 51 B_SE0_SRP, 52 B_SRP_FAIL, 53 A_WAIT_ENUM, 54 B_DATA_PLS, 55 B_SSEND_SRP, 56 57 NUM_OTG_FSM_TIMERS, 58}; 59 60/** 61 * struct otg_fsm - OTG state machine according to the OTG spec 62 * 63 * OTG hardware Inputs 64 * 65 * Common inputs for A and B device 66 * @id: TRUE for B-device, FALSE for A-device. 67 * @adp_change: TRUE when current ADP measurement (n) value, compared to the 68 * ADP measurement taken at n-2, differs by more than CADP_THR 69 * @power_up: TRUE when the OTG device first powers up its USB system and 70 * ADP measurement taken if ADP capable 71 * 72 * A-Device state inputs 73 * @a_srp_det: TRUE if the A-device detects SRP 74 * @a_vbus_vld: TRUE when VBUS voltage is in regulation 75 * @b_conn: TRUE if the A-device detects connection from the B-device 76 * @a_bus_resume: TRUE when the B-device detects that the A-device is signaling 77 * a resume (K state) 78 * B-Device state inputs 79 * @a_bus_suspend: TRUE when the B-device detects that the A-device has put the 80 * bus into suspend 81 * @a_conn: TRUE if the B-device detects a connection from the A-device 82 * @b_se0_srp: TRUE when the line has been at SE0 for more than the minimum 83 * time before generating SRP 84 * @b_ssend_srp: TRUE when the VBUS has been below VOTG_SESS_VLD for more than 85 * the minimum time before generating SRP 86 * @b_sess_vld: TRUE when the B-device detects that the voltage on VBUS is 87 * above VOTG_SESS_VLD 88 * @test_device: TRUE when the B-device switches to B-Host and detects an OTG 89 * test device. This must be set by host/hub driver 90 * 91 * Application inputs (A-Device) 92 * @a_bus_drop: TRUE when A-device application needs to power down the bus 93 * @a_bus_req: TRUE when A-device application wants to use the bus. 94 * FALSE to suspend the bus 95 * 96 * Application inputs (B-Device) 97 * @b_bus_req: TRUE during the time that the Application running on the 98 * B-device wants to use the bus 99 * 100 * Auxilary inputs (OTG v1.3 only. Obsolete now.) 101 * @a_sess_vld: TRUE if the A-device detects that VBUS is above VA_SESS_VLD 102 * @b_bus_suspend: TRUE when the A-device detects that the B-device has put 103 * the bus into suspend 104 * @b_bus_resume: TRUE when the A-device detects that the B-device is signaling 105 * resume on the bus 106 * 107 * OTG Output status. Read only for users. Updated by OTG FSM helpers defined 108 * in this file 109 * 110 * Outputs for Both A and B device 111 * @drv_vbus: TRUE when A-device is driving VBUS 112 * @loc_conn: TRUE when the local device has signaled that it is connected 113 * to the bus 114 * @loc_sof: TRUE when the local device is generating activity on the bus 115 * @adp_prb: TRUE when the local device is in the process of doing 116 * ADP probing 117 * 118 * Outputs for B-device state 119 * @adp_sns: TRUE when the B-device is in the process of carrying out 120 * ADP sensing 121 * @data_pulse: TRUE when the B-device is performing data line pulsing 122 * 123 * Internal Variables 124 * 125 * a_set_b_hnp_en: TRUE when the A-device has successfully set the 126 * b_hnp_enable bit in the B-device. 127 * Unused as OTG fsm uses otg->host->b_hnp_enable instead 128 * b_srp_done: TRUE when the B-device has completed initiating SRP 129 * b_hnp_enable: TRUE when the B-device has accepted the 130 * SetFeature(b_hnp_enable) B-device. 131 * Unused as OTG fsm uses otg->gadget->b_hnp_enable instead 132 * a_clr_err: Asserted (by application ?) to clear a_vbus_err due to an 133 * overcurrent condition and causes the A-device to transition 134 * to a_wait_vfall 135 */ 136struct otg_fsm { 137 /* Input */ 138 int id; 139 int adp_change; 140 int power_up; 141 int a_srp_det; 142 int a_vbus_vld; 143 int b_conn; 144 int a_bus_resume; 145 int a_bus_suspend; 146 int a_conn; 147 int b_se0_srp; 148 int b_ssend_srp; 149 int b_sess_vld; 150 int test_device; 151 int a_bus_drop; 152 int a_bus_req; 153 int b_bus_req; 154 155 /* Auxilary inputs */ 156 int a_sess_vld; 157 int b_bus_resume; 158 int b_bus_suspend; 159 160 /* Output */ 161 int drv_vbus; 162 int loc_conn; 163 int loc_sof; 164 int adp_prb; 165 int adp_sns; 166 int data_pulse; 167 168 /* Internal variables */ 169 int a_set_b_hnp_en; 170 int b_srp_done; 171 int b_hnp_enable; 172 int a_clr_err; 173 174 /* Informative variables. All unused as of now */ 175 int a_bus_drop_inf; 176 int a_bus_req_inf; 177 int a_clr_err_inf; 178 int b_bus_req_inf; 179 /* Auxilary informative variables */ 180 int a_suspend_req_inf; 181 182 /* Timeout indicator for timers */ 183 int a_wait_vrise_tmout; 184 int a_wait_vfall_tmout; 185 int a_wait_bcon_tmout; 186 int a_aidl_bdis_tmout; 187 int b_ase0_brst_tmout; 188 int a_bidl_adis_tmout; 189 190 struct otg_fsm_ops *ops; 191 struct usb_otg *otg; 192 193 /* Current usb protocol used: 0:undefine; 1:host; 2:client */ 194 int protocol; 195 struct mutex lock; 196 u8 *host_req_flag; 197 struct delayed_work hnp_polling_work; 198 bool state_changed; 199}; 200 201struct otg_fsm_ops { 202 void (*chrg_vbus)(struct otg_fsm *fsm, int on); 203 void (*drv_vbus)(struct otg_fsm *fsm, int on); 204 void (*loc_conn)(struct otg_fsm *fsm, int on); 205 void (*loc_sof)(struct otg_fsm *fsm, int on); 206 void (*start_pulse)(struct otg_fsm *fsm); 207 void (*start_adp_prb)(struct otg_fsm *fsm); 208 void (*start_adp_sns)(struct otg_fsm *fsm); 209 void (*add_timer)(struct otg_fsm *fsm, enum otg_fsm_timer timer); 210 void (*del_timer)(struct otg_fsm *fsm, enum otg_fsm_timer timer); 211 int (*start_host)(struct otg_fsm *fsm, int on); 212 int (*start_gadget)(struct otg_fsm *fsm, int on); 213}; 214 215 216static inline int otg_chrg_vbus(struct otg_fsm *fsm, int on) 217{ 218 if (!fsm->ops->chrg_vbus) 219 return -EOPNOTSUPP; 220 fsm->ops->chrg_vbus(fsm, on); 221 return 0; 222} 223 224static inline int otg_drv_vbus(struct otg_fsm *fsm, int on) 225{ 226 if (!fsm->ops->drv_vbus) 227 return -EOPNOTSUPP; 228 if (fsm->drv_vbus != on) { 229 fsm->drv_vbus = on; 230 fsm->ops->drv_vbus(fsm, on); 231 } 232 return 0; 233} 234 235static inline int otg_loc_conn(struct otg_fsm *fsm, int on) 236{ 237 if (!fsm->ops->loc_conn) 238 return -EOPNOTSUPP; 239 if (fsm->loc_conn != on) { 240 fsm->loc_conn = on; 241 fsm->ops->loc_conn(fsm, on); 242 } 243 return 0; 244} 245 246static inline int otg_loc_sof(struct otg_fsm *fsm, int on) 247{ 248 if (!fsm->ops->loc_sof) 249 return -EOPNOTSUPP; 250 if (fsm->loc_sof != on) { 251 fsm->loc_sof = on; 252 fsm->ops->loc_sof(fsm, on); 253 } 254 return 0; 255} 256 257static inline int otg_start_pulse(struct otg_fsm *fsm) 258{ 259 if (!fsm->ops->start_pulse) 260 return -EOPNOTSUPP; 261 if (!fsm->data_pulse) { 262 fsm->data_pulse = 1; 263 fsm->ops->start_pulse(fsm); 264 } 265 return 0; 266} 267 268static inline int otg_start_adp_prb(struct otg_fsm *fsm) 269{ 270 if (!fsm->ops->start_adp_prb) 271 return -EOPNOTSUPP; 272 if (!fsm->adp_prb) { 273 fsm->adp_sns = 0; 274 fsm->adp_prb = 1; 275 fsm->ops->start_adp_prb(fsm); 276 } 277 return 0; 278} 279 280static inline int otg_start_adp_sns(struct otg_fsm *fsm) 281{ 282 if (!fsm->ops->start_adp_sns) 283 return -EOPNOTSUPP; 284 if (!fsm->adp_sns) { 285 fsm->adp_sns = 1; 286 fsm->ops->start_adp_sns(fsm); 287 } 288 return 0; 289} 290 291static inline int otg_add_timer(struct otg_fsm *fsm, enum otg_fsm_timer timer) 292{ 293 if (!fsm->ops->add_timer) 294 return -EOPNOTSUPP; 295 fsm->ops->add_timer(fsm, timer); 296 return 0; 297} 298 299static inline int otg_del_timer(struct otg_fsm *fsm, enum otg_fsm_timer timer) 300{ 301 if (!fsm->ops->del_timer) 302 return -EOPNOTSUPP; 303 fsm->ops->del_timer(fsm, timer); 304 return 0; 305} 306 307static inline int otg_start_host(struct otg_fsm *fsm, int on) 308{ 309 if (!fsm->ops->start_host) 310 return -EOPNOTSUPP; 311 return fsm->ops->start_host(fsm, on); 312} 313 314static inline int otg_start_gadget(struct otg_fsm *fsm, int on) 315{ 316 if (!fsm->ops->start_gadget) 317 return -EOPNOTSUPP; 318 return fsm->ops->start_gadget(fsm, on); 319} 320 321int otg_statemachine(struct otg_fsm *fsm); 322 323#endif /* __LINUX_USB_OTG_FSM_H */