From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marek Vasut Date: Sun, 15 Mar 2015 19:19:52 +0100 Subject: [U-Boot] [PATCH 3/4] sunxi: common VBUS detection logic in usbc In-Reply-To: <1426440467-4525-3-git-send-email-contact@paulk.fr> References: <1426440467-4525-1-git-send-email-contact@paulk.fr> <1426440467-4525-3-git-send-email-contact@paulk.fr> Message-ID: <201503151919.52419.marex@denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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 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. > + } > + 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 ? > + 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; [...]