All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paul Kocialkowski <contact@paulk.fr>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 3/4] sunxi: common VBUS detection logic in usbc
Date: Sun, 15 Mar 2015 22:54:05 +0100	[thread overview]
Message-ID: <1426456445.5178.13.camel@collins> (raw)
In-Reply-To: <201503151919.52419.marex@denx.de>

Le dimanche 15 mars 2015 ? 19:19 +0100, Marek Vasut a ?crit :
> On Sunday, March 15, 2015 at 06:27:46 PM, Paul Kocialkowski wrote:
> > VBUS detection could be needed not only by the musb code (to prevent host
> > mode), but also by e.g. gadget drivers to start only when a cable is
> > connected.
> > 
> > In addition, this allows more flexibility in vbus detection, as it could
> > easily be extended to other USBC indexes. Eventually, this would help
> > making musb support independent from a hardcoded USB controller index (0).
> > 
> > Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
> 
> Hi!
> 
> [...]
> 
> > @@ -113,6 +120,17 @@ static int get_vbus_gpio(int index)
> >  	return -1;
> >  }
> > 
> > +static int get_vbus_detect_gpio(int index)
> > +{
> > +	if (use_axp_vbus_detect(index))
> > +		return -1;
> > +
> > +	switch (index) {
> > +	case 0: return sunxi_name_to_gpio(CONFIG_USB0_VBUS_DET);
> 
> What happens if the index != 0 here ? Default branch with some error
> report might be a good idea here.

Well, I'm going to have a very stupid answer here, that is: I copied
what was already being done nearby, namely in get_vbus_gpio for this
one. So I think that we should modify both functions accordingly.

I don't think it makes so much sense to print an error here because this
will never be called directly, but instead through
sunxi_usbc_request_resources which will make noise when it fails.
We could perhaps add some error printing in sunxi_usbc_request_resources
to make it clear what failed, but I'm not really for it.

> > +	}
> > +	return -1;
> > +}
> > +
> 
> [...]
> 
> > @@ -270,3 +297,34 @@ void sunxi_usbc_vbus_disable(int index)
> >  	if (sunxi_usbc->gpio_vbus != -1)
> >  		gpio_direction_output(sunxi_usbc->gpio_vbus, 0);
> >  }
> > +
> > +int sunxi_usbc_vbus_detect(int index)
> > +{
> > +	struct sunxi_usbc_hcd *sunxi_usbc = &sunxi_usbc_hcd[index];
> > +	int err;
> > +
> > +#ifdef AXP_VBUS_DETECT
> 
> Can't you just wrap this ifdef into use_axp_vbus_detect(), so the
> code isn't so riddled with the ifdeffery ?

I agree those ifdefs are not used consistently and should be moved to
one place. Your suggestion looks fine to me.

> > +	if (use_axp_vbus_detect(index)) {
> > +		err = axp_get_vbus();
> > +		if (err < 0)
> > +			return err;
> > +	} else {
> > +#endif
> > +		if (sunxi_usbc->gpio_vbus_det == -1) {
> > +			eprintf("Error: invalid vbus detection pin\n");
> > +			return -1;
> > +		}
> > +
> > +		err = gpio_direction_input(sunxi_usbc->gpio_vbus_det);
> > +		if (err)
> > +			return err;
> > +
> > +		err = gpio_get_value(sunxi_usbc->gpio_vbus_det);
> > +		if (err < 0)
> > +			return err;
> > +#ifdef AXP_VBUS_DETECT
> > +	}
> > +#endif
> > +
> > +	return err;
> 
> [...]

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150315/1d7fa5a1/attachment.sig>

  reply	other threads:[~2015-03-15 21:54 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-15 17:27 [U-Boot] [PATCH 1/4] sunxi: musb: Return early on VBUS GPIO error instead of on a positive value Paul Kocialkowski
2015-03-15 17:27 ` [U-Boot] [PATCH 2/4] sunxi: Avoid any assumption between musb gadget and host but fallback to host Paul Kocialkowski
2015-03-21 13:14   ` Hans de Goede
2015-03-22 10:54     ` Paul Kocialkowski
2015-03-15 17:27 ` [U-Boot] [PATCH 3/4] sunxi: common VBUS detection logic in usbc Paul Kocialkowski
2015-03-15 18:19   ` Marek Vasut
2015-03-15 21:54     ` Paul Kocialkowski [this message]
2015-03-15 23:31       ` Marek Vasut
2015-03-21 13:15   ` Hans de Goede
2015-03-15 17:27 ` [U-Boot] [PATCH 4/4] board: sunxi: USB download gadget cable detection Paul Kocialkowski
2015-03-21 12:56 ` [U-Boot] [PATCH 1/4] sunxi: musb: Return early on VBUS GPIO error instead of on a positive value 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=1426456445.5178.13.camel@collins \
    --to=contact@paulk.fr \
    --cc=u-boot@lists.denx.de \
    /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.