Commit e42add561b6cfe1fa8a03a3ff64c72b5ea4a725f

Authored by Chen-Yu Tsai
Committed by Hans de Goede
1 parent 1986c4ca0b

sunxi: musb: Support checking VBUS using AXP221 PMIC

This enables the musb glue layer to use the AXP221's VBUS detection
function to check for VBUS. This fixes otg support on the A23 q8h
tablets.

Note that u-boot never calls musb_shutdown(), so once VBUS is enabled,
it is never disabled until the system is powered off, or the OS does
so. This can be used to our advantage to keep VBUS powered into the
OS, where support for AXP221 is not available yet.

Fixes: 52defe8f6570 ("sunxi: musb: Check Vbus-det before enabling otg port power")
Signed-off-by: Chen-Yu Tsai <wens@csie.org>
Acked-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>

Showing 1 changed file with 38 additions and 14 deletions Side-by-side Diff

drivers/usb/musb-new/sunxi.c
... ... @@ -27,6 +27,15 @@
27 27 #include <asm-generic/gpio.h>
28 28 #include "linux-compat.h"
29 29 #include "musb_core.h"
  30 +#ifdef CONFIG_AXP152_POWER
  31 +#include <axp152.h>
  32 +#endif
  33 +#ifdef CONFIG_AXP209_POWER
  34 +#include <axp209.h>
  35 +#endif
  36 +#ifdef CONFIG_AXP221_POWER
  37 +#include <axp221.h>
  38 +#endif
30 39  
31 40 /******************************************************************************
32 41 ******************************************************************************
33 42  
34 43  
35 44  
36 45  
37 46  
38 47  
39 48  
... ... @@ -228,29 +237,44 @@
228 237  
229 238 if (is_host_enabled(musb)) {
230 239 int vbus_det = sunxi_name_to_gpio(CONFIG_USB0_VBUS_DET);
231   - if (vbus_det == -1) {
232   - eprintf("Error invalid Vusb-det pin\n");
233   - return -EINVAL;
234   - }
235 240  
236   - err = gpio_request(vbus_det, "vbus0_det");
237   - if (err)
238   - return err;
  241 +#ifdef AXP_VBUS_DETECT
  242 + if (!strcmp(CONFIG_USB0_VBUS_DET, "axp_vbus_detect")) {
  243 + err = axp_get_vbus();
  244 + if (err < 0)
  245 + return err;
  246 + } else {
  247 +#endif
  248 + if (vbus_det == -1) {
  249 + eprintf("Error invalid Vusb-det pin\n");
  250 + return -EINVAL;
  251 + }
239 252  
240   - err = gpio_direction_input(vbus_det);
241   - if (err) {
  253 + err = gpio_request(vbus_det, "vbus0_det");
  254 + if (err)
  255 + return err;
  256 +
  257 + err = gpio_direction_input(vbus_det);
  258 + if (err) {
  259 + gpio_free(vbus_det);
  260 + return err;
  261 + }
  262 +
  263 + err = gpio_get_value(vbus_det);
  264 + if (err) {
  265 + gpio_free(vbus_det);
  266 + return -EIO;
  267 + }
  268 +
242 269 gpio_free(vbus_det);
243   - return err;
  270 +#ifdef AXP_VBUS_DETECT
244 271 }
  272 +#endif
245 273  
246   - err = gpio_get_value(vbus_det);
247 274 if (err) {
248 275 eprintf("Error: A charger is plugged into the OTG\n");
249   - gpio_free(vbus_det);
250 276 return -EIO;
251 277 }
252   -
253   - gpio_free(vbus_det);
254 278 }
255 279  
256 280 err = sunxi_usbc_request_resources(0);