usb: typec: fusb302: Refactor / simplify tcpm_set_cc()
PATCH v2 2/8 usb: typec: fusb302: Refactor / simplify tcpm_set_cc()
Quoted 42 lines · Guenter Roeck
Quoted 41 lines · Hans de Goede
After commit
ea3b4d5523bc("usb: typec: fusb302: Resolve fixed power role contract setup"),tcpm_set_ccalways callsfusb302_set_toggling.Before this refactor
tcpm_set_ccdoes the following:1)
fusb302_set_toggling(TOGGLING_MODE_OFF),
this sets bothFUSB_REG_MASK_BC_LVLandFUSB_REG_MASK_COMP_CHNG.
2)fusb302_set_cc_pull(...).
3) "reset cc status".
4) if pull-upfusb302_set_src_current(...).
5) if pull-up or pull-down enable bc-lvl resp comp-chng irq.
6)fusb302_set_toggling(new-toggling-mode), which again
sets bothFUSB_REG_MASK_BC_LVLandFUSB_REG_MASK_COMP_CHNGdisabling the just enabled irq.fusb302_set_togglingis skipped when the new toggling mode isTOGGLING_MODE_OFFbecause this is already done in 1, note in this case 5) is a no-op.When we are toggling the bits set by
fusb302_set_cc_pullwill be ignored until we turn toggling off, so we can safely move thefusb302_set_cc_pullcall to before settingTOGGLING_MODE_OFF.Either we are not toggling yet, or the src-current has already been set, so we can also safely set the src-current earlier, allowing us to do the
fusb302_set_toggling(TOGGLING_MODE_OFF)call at the same time as we set the other toggling modes. Also setting the src-current is a no-op when not enabling pull-ups, so we can drop the if.And since the second
fusb302_set_togglingundoes the effects of step 5, we can skip step 5, the bc-lvl resp comp-chng irq wil be enabled byfusb302_handle_togdone_snkresp.fusb302_handle_togdone_srcwhen toggling is done.Together this allows us to simplify things to:
1)
fusb302_set_cc_pull(...)
2) "reset cc status"
3)fusb302_set_src_current(...)
4)fusb302_set_toggling(new-toggling-mode)This commit does this, leading to a nice cleanup.
Quoted 7 lines
Quoted 1 line
Signed-off-by Hans de Goede <[email protected]>I think I understand the logic, but I think it would be really beneficial if this (and the rest of the series) can be tested independently (ie by someone with hardware).
Reviewed-by Guenter Roeck <[email protected]>
I'll test this series with my GPD win board today.
thanks,