STRUCT OTG_FSM(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… NAME

struct otg_fsm β€” the OTG state machine, built exactly the way the OTG spec says, no cap. It's from the Kernel API Manual, section 9, and it's lowkey the blueprint for how a device flips between host and gadget energy. ✨


🌸 SYNOPSIS

struct otg_fsm {
    int id;
    int adp_change;
    int power_up;
    int a_srp_det;
    int a_vbus_vld;
    int b_conn;
    int a_bus_resume;
    int a_bus_suspend;
    int a_conn;
    int b_se0_srp;
    int b_ssend_srp;
    int b_sess_vld;
    int test_device;
    int a_bus_drop;
    int a_bus_req;
    int b_bus_req;
    int a_sess_vld;
    int b_bus_resume;
    int b_bus_suspend;
    int drv_vbus;
    int loc_conn;
    int loc_sof;
    int adp_prb;
    int adp_sns;
    int data_pulse;
    int a_set_b_hnp_en;
    int b_srp_done;
    int b_hnp_enable;
    int a_clr_err;
    int a_bus_drop_inf;
    int a_bus_req_inf;
    int a_clr_err_inf;
    int b_bus_req_inf;
    int a_suspend_req_inf;
    int a_wait_vrise_tmout;
    int a_wait_vfall_tmout;
    int a_wait_bcon_tmout;
    int a_aidl_bdis_tmout;
    int b_ase0_brst_tmout;
    int a_bidl_adis_tmout;
    struct otg_fsm_ops *ops;
    struct usb_otg *otg;
    int protocol;
    struct mutex lock;
    u8 *host_req_flag;
    struct delayed_work hnp_polling_work;
    bool hnp_work_inited;
    bool state_changed;
 };

πŸ¦‹ MEMBERS

Okay bestie, here's the full roster β€” every field, every vibe, nothing skipped. 🫢

  • id β€” TRUE for B-device, FALSE for A-device. That's the whole personality check right there.
  • adp_change β€” TRUE when the current ADP measurement (n), compared to the ADP measurement taken at n-2, differs by more than CADP_THR. Yes, it's doing math behind your back. πŸ™ˆ
  • power_up β€” TRUE when the OTG device first powers up its USB system and an ADP measurement is taken if ADP capable.
  • a_srp_det β€” TRUE if the A-device detects SRP.
  • a_vbus_vld β€” TRUE when VBUS voltage is in regulation. Iconic, stable, well-behaved. πŸ’…
  • b_conn β€” TRUE if the A-device detects a connection from the B-device.
  • a_bus_resume β€” TRUE when the B-device detects that the A-device is signaling a resume (K state) B-Device state inputs.
  • a_bus_suspend β€” TRUE when the B-device detects that the A-device has put the bus into suspend.
  • a_conn β€” TRUE if the B-device detects a connection from the A-device.
  • b_se0_srp β€” TRUE when the line has been at SE0 for more than the minimum time before generating SRP.
  • b_ssend_srp β€” TRUE when the VBUS has been below VOTG_SESS_VLD for more than the minimum time before generating SRP.
  • b_sess_vld β€” TRUE when the B-device detects that the voltage on VBUS is above VOTG_SESS_VLD.
  • test_device β€” TRUE when the B-device switches to B-Host and detects an OTG test device. This must be set by the host/hub driver β€” no freelancing, fr fr.
  • a_bus_drop β€” TRUE when the A-device application needs to power down the bus.
  • a_bus_req β€” TRUE when the A-device application wants to use the bus. FALSE to suspend the bus.
  • b_bus_req β€” TRUE during the time that the Application running on the B-device wants to use the bus.
  • a_sess_vld β€” TRUE if the A-device detects that VBUS is above VA_SESS_VLD.
  • b_bus_resume β€” TRUE when the A-device detects that the B-device is signaling resume on the bus.
  • b_bus_suspend β€” TRUE when the A-device detects that the B-device has put the bus into suspend.
  • drv_vbus β€” TRUE when the A-device is driving VBUS.
  • loc_conn β€” TRUE when the local device has signaled that it is connected to the bus.
  • loc_sof β€” TRUE when the local device is generating activity on the bus.
  • adp_prb β€” TRUE when the local device is in the process of doing ADP probing.
  • adp_sns β€” TRUE when the B-device is in the process of carrying out ADP sensing.
  • data_pulse β€” TRUE when the B-device is performing data line pulsing.
  • a_set_b_hnp_en β€” covered down in Internal Variables, keep scrolling bestie πŸ‘€
  • b_srp_done β€” also internal, it's down there ⬇️
  • b_hnp_enable β€” internal too πŸ’«
  • a_clr_err β€” internal, but spicy 🌢️

✨ DESCRIPTION ✨

Here's the lil map of the whole struct, grouped exactly how the kernel groups it. πŸ—ΊοΈ

OTG hardware Inputs

Common inputs for A and B device

A-Device state inputs

Application inputs (A-Device)

Application inputs (B-Device)

Auxiliary inputs (OTG v1.3 only. Obsolete now.)

Heads up πŸŽ€ β€” that last group is OTG v1.3 only and obsolete now. It's giving "kept around for the lore".

OTG Output status. Read only for users. Updated by OTG FSM helpers defined in this file

Read-only for users, okay? πŸ‘‘ The OTG FSM helpers in this file do the updating β€” you do not touch.

Outputs for Both A and B device

Outputs for B-device state

Internal Variables

These are the ones living in the walls, but we still stan them:

  • a_set_b_hnp_en β€” TRUE when the A-device has successfully set the b_hnp_enable bit in the B-device. Unused as OTG fsm uses otg->host->b_hnp_enable instead.
  • b_srp_done β€” TRUE when the B-device has completed initiating SRP.
  • b_hnp_enable β€” TRUE when the B-device has accepted the SetFeature(b_hnp_enable) B-device. Unused as OTG fsm uses otg->gadget->b_hnp_enable instead.
  • a_clr_err β€” Asserted (by application ?) to clear a_vbus_err due to an overcurrent condition and causes the A-device to transition to a_wait_vfall.

πŸ‘€ SEE ALSO

  • Kernel file ./include/linux/usb/otg-fsm.h β€” go read it, iykyk 🧚

That's the whole page, bestie β€” no notes, no crumbs left behind. πŸ’œ This gem comes to you from ./include/linux/usb, dated October 2026, and it goes by struct otg_fsm(9). Slay it responsibly. πŸŽ€πŸ”₯

πŸ“¦ where this page comes from