usb: typec: fusb302: Refactor / simplify tcpm_set_cc()
PATCH v2 2/8 usb: typec: fusb302: Refactor / simplify tcpm_set_cc()
Quoted 61 lines · Hans de Goede
Hi,
Quoted 45 lines · Heikki Krogerus
Quoted 44 lines · Guenter Roeck
Quoted 42 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.
Signed-off-by Hans de Goede <[email protected]>Quoted 7 lines
Quoted 5 lines
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.
Note I've already tested this series on both a GPD win and a GPD pocket.
Also Guenter's reviewed has shown that a small error has crept up in patch 5, patch 5 adds 2:
Quoted 7 lines
usleep_range(5000, 10000);lines which should be:
usleep_range(50, 100);So if you test please make that change, or wait for v3 of the series.
OK.
thanks,