All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Guenter Roeck <linux@roeck-us.net>
Cc: Hans de Goede <hdegoede@redhat.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-usb@vger.kernel.org
Subject: [v2,2/8] usb: typec: fusb302: Refactor / simplify tcpm_set_cc()
Date: Fri, 8 Mar 2019 09:33:04 +0200	[thread overview]
Message-ID: <20190308073304.GC28103@kuha.fi.intel.com> (raw)

On Thu, Mar 07, 2019 at 10:12:59AM -0800, Guenter Roeck wrote:
> On Thu, Mar 07, 2019 at 05:36:01PM +0100, Hans de Goede wrote:
> > After commit ea3b4d5523bc ("usb: typec: fusb302: Resolve fixed power role
> > contract setup"), tcpm_set_cc always calls fusb302_set_toggling.
> > 
> > Before this refactor tcpm_set_cc does the following:
> > 
> > 1) fusb302_set_toggling(TOGGLING_MODE_OFF),
> >    this sets both FUSB_REG_MASK_BC_LVL and FUSB_REG_MASK_COMP_CHNG.
> > 2) fusb302_set_cc_pull(...).
> > 3) "reset cc status".
> > 4) if pull-up fusb302_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 both FUSB_REG_MASK_BC_LVL and FUSB_REG_MASK_COMP_CHNG disabling
> >    the just enabled irq. fusb302_set_toggling is skipped when the new
> >    toggling mode is TOGGLING_MODE_OFF because 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_pull will be ignored
> > until we turn toggling off, so we can safely move the fusb302_set_cc_pull
> > call to before setting TOGGLING_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_toggling undoes the effects of step 5,
> > we can skip step 5, the bc-lvl resp comp-chng irq wil be enabled by
> > fusb302_handle_togdone_snk resp. fusb302_handle_togdone_src when 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 <hdegoede@redhat.com>
> 
> 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 <linux@roeck-us.net>

I'll test this series with my GPD win board today.

thanks,

             reply	other threads:[~2019-03-08  7:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-08  7:33 Heikki Krogerus [this message]
  -- strict thread matches above, loose matches on Subject: below --
2019-03-08 11:04 [v2,2/8] usb: typec: fusb302: Refactor / simplify tcpm_set_cc() Heikki Krogerus
2019-03-08 10:58 Hans de Goede
2019-03-07 18:12 Guenter Roeck
2019-03-07 16:36 Hans de Goede

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190308073304.GC28103@kuha.fi.intel.com \
    --to=heikki.krogerus@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hdegoede@redhat.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=linux@roeck-us.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.