[U-Boot] [PATCH 1/2] power: axp209: VBUS detect

Hans de Goede hdegoede at redhat.com
Sat Mar 21 13:01:57 CET 2015


Hi Paul,

On 15-03-15 18:29, Paul Kocialkowski wrote:
> Signed-off-by: Paul Kocialkowski <contact at paulk.fr>
> ---
>   drivers/power/axp209.c | 13 +++++++++++++
>   include/axp209.h       |  3 +++
>   2 files changed, 16 insertions(+)
>
> diff --git a/drivers/power/axp209.c b/drivers/power/axp209.c
> index 4565398..11fe9d7 100644
> --- a/drivers/power/axp209.c
> +++ b/drivers/power/axp209.c
> @@ -31,6 +31,7 @@ enum axp209_reg {
>   };
>
>   #define AXP209_POWER_STATUS_ON_BY_DC	(1 << 0)
> +#define AXP209_POWER_STATUS_VBUS_USABLE	(1 << 4)
>
>   #define AXP209_IRQ5_PEK_UP		(1 << 6)
>   #define AXP209_IRQ5_PEK_DOWN		(1 << 5)
> @@ -249,3 +250,15 @@ int axp_gpio_set_value(unsigned int pin, unsigned int val)
>   {
>   	return axp_gpio_direction_output(pin, val);
>   }
> +
> +int axp_get_vbus(void)
> +{
> +	u8 val;
> +	int rc;
> +
> +	rc = axp209_read(AXP209_POWER_STATUS, &val);
> +	if (rc)
> +		return rc;
> +
> +	return (val & AXP209_POWER_STATUS_VBUS_USABLE) ? 1 : 0;
> +}
> diff --git a/include/axp209.h b/include/axp209.h
> index 0436249..a007958 100644
> --- a/include/axp209.h
> +++ b/include/axp209.h
> @@ -5,6 +5,7 @@
>    */
>
>   #define AXP_GPIO
> +#define AXP_VBUS_DETECT
>
>   extern int axp209_set_dcdc2(int mvolt);
>   extern int axp209_set_dcdc3(int mvolt);
> @@ -19,3 +20,5 @@ extern int axp_gpio_direction_input(unsigned int pin);
>   extern int axp_gpio_direction_output(unsigned int pin, unsigned int val);
>   extern int axp_gpio_get_value(unsigned int pin);
>   extern int axp_gpio_set_value(unsigned int pin, unsigned int val);
> +
> +extern int axp_get_vbus(void);
>

Thanks for this patch and for all your other sunxi u-boot patches, unfortunately
I'm afraid that I cannot take this patch as is, this stuff with all the special
axp handling is becoming too messy IMHO.

I know I started doing things this way myself, but we need to fix this and it
is better to draw a line here, and fix things right now before they become even
more messy.

What I would like to see is to have the axp vbus detect / ctrl code changed to
simply export the axp_vbus detect as a read only gpio, and vbus ctrl as a
regular gpio.

I would like to see 2 defines added to arch/arm/include/asm/arch-sunxi/gpio.h:

#define SUNXI_GPIO_AXP_VBUS_DETECT 8
#define SUNXI_GPIO_AXP_VBUS_ENABLE 9

And then in drivers/gpio/sunxi_gpio.c: sunxi_name_to_gpio() :

	if (strncasecmp(name, "AXP0-", 5) == 0) {
		name += 5;
		if (strcmp(name, "VBUS-DETECT") == 0)
			return SUNXI_GPIO_AXP0_START + SUNXI_GPIO_AXP_VBUS_DETECT;
		if (strcmp(name, "VBUS-ENABLE") == 0)
			return SUNXI_GPIO_AXP0_START + SUNXI_GPIO_AXP_VBUS_ENABLE;
		pin = simple_strtol(name, &eptr, 10);
		...
	}

Where the 2 "if (strcmp(...) ..." blocks are new.

And then in drivers/power/axp221.c add gpio functions which only handle the vbus stuff
for now, e.g. :

int axp_gpio_direction_input(unsigned int pin)
{
	switch (pin) {
	case SUNXI_GPIO_AXP_VBUS_DETECT:
	case SUNXI_GPIO_AXP_VBUS_ENABLE:
		return 0;
	default:
		return -EINVAL;
	}
}

int axp_gpio_direction_output(unsigned int pin, unsigned int val)
{
	int ret;

	switch (pin) {
	case SUNXI_GPIO_AXP_VBUS_ENABLE:
		/* Set N_VBUSEN pin to output / DRIVEBUS function */
		ret = axp221_clrbits(AXP221_MISC_CTRL, AXP221_MISC_CTRL_N_VBUSEN_FUNC);
		if (ret)
			return ret;
		return axp_gpio_set_value(pin, val);
	default:
		return -EINVAL;
	}
}

And similar additions of axp_gpio_get_value /  axp_gpio_set_value

And the remove the axp handling magic (and the includes) from
drivers/usb/musb-new/sunxi.c, only leaving regular gpio calls in there.

You may not have access to an axp221 using device, that is no problem, if
you can prepare a compile-tested (build for Ippo_q8h_v1_2_defconfig) patch-set
with this cleanup then I can test it and fix it up if necessary.

And then on top of this cleanup you can add axp209 vbus detect support
extending the existing axp209 gpio functions.

Regards,

Hans


More information about the U-Boot mailing list