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

Signed-off-by: Paul Kocialkowski contact@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);

Signed-off-by: Paul Kocialkowski contact@paulk.fr --- board/sunxi/MAINTAINERS | 5 +++++ configs/Ainol_AW1_defconfig | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 configs/Ainol_AW1_defconfig
diff --git a/board/sunxi/MAINTAINERS b/board/sunxi/MAINTAINERS index ef3c937..e486458 100644 --- a/board/sunxi/MAINTAINERS +++ b/board/sunxi/MAINTAINERS @@ -50,6 +50,11 @@ S: Maintained F: board/sunxi/dram_a20_olinuxino_l2.c F: configs/A20-OLinuXino-Lime2_defconfig
+AINOL AW1 BOARD +M: Paul Kocialkowski contact@paulk.fr +S: Maintained +F: configs/Ainol_AW1_defconfig + AMPE A76 BOARD M: Paul Kocialkowski contact@paulk.fr S: Maintained diff --git a/configs/Ainol_AW1_defconfig b/configs/Ainol_AW1_defconfig new file mode 100644 index 0000000..e37e6c8 --- /dev/null +++ b/configs/Ainol_AW1_defconfig @@ -0,0 +1,16 @@ +CONFIG_SPL=y +CONFIG_SYS_EXTRA_OPTIONS="AXP209_POWER" +CONFIG_FDTFILE="sun7i-a20-ainol-aw1.dtb" +CONFIG_USB_MUSB_SUNXI=y +CONFIG_USB0_VBUS_PIN="PB9" +CONFIG_USB0_VBUS_DET="axp_vbus_detect" +CONFIG_VIDEO_LCD_MODE="x:800,y:480,depth:18,pclk_khz:40000,le:87,ri:112,up:38,lo:141,hs:1,vs:1,sync:3,vmode:0" +CONFIG_VIDEO_LCD_POWER="PH8" +CONFIG_VIDEO_LCD_BL_EN="PH7" +CONFIG_VIDEO_LCD_BL_PWM="PB2" ++S:CONFIG_ARM=y ++S:CONFIG_ARCH_SUNXI=y ++S:CONFIG_MACH_SUN7I=y ++S:CONFIG_DRAM_CLK=432 ++S:CONFIG_DRAM_ZQ=123 ++S:CONFIG_DRAM_EMR1=4

Hi,
On 15-03-15 18:29, Paul Kocialkowski wrote:
Signed-off-by: Paul Kocialkowski contact@paulk.fr
board/sunxi/MAINTAINERS | 5 +++++ configs/Ainol_AW1_defconfig | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 configs/Ainol_AW1_defconfig
diff --git a/board/sunxi/MAINTAINERS b/board/sunxi/MAINTAINERS index ef3c937..e486458 100644 --- a/board/sunxi/MAINTAINERS +++ b/board/sunxi/MAINTAINERS @@ -50,6 +50,11 @@ S: Maintained F: board/sunxi/dram_a20_olinuxino_l2.c F: configs/A20-OLinuXino-Lime2_defconfig
+AINOL AW1 BOARD +M: Paul Kocialkowski contact@paulk.fr +S: Maintained +F: configs/Ainol_AW1_defconfig
- AMPE A76 BOARD M: Paul Kocialkowski contact@paulk.fr S: Maintained
diff --git a/configs/Ainol_AW1_defconfig b/configs/Ainol_AW1_defconfig new file mode 100644 index 0000000..e37e6c8 --- /dev/null +++ b/configs/Ainol_AW1_defconfig @@ -0,0 +1,16 @@ +CONFIG_SPL=y +CONFIG_SYS_EXTRA_OPTIONS="AXP209_POWER" +CONFIG_FDTFILE="sun7i-a20-ainol-aw1.dtb" +CONFIG_USB_MUSB_SUNXI=y +CONFIG_USB0_VBUS_PIN="PB9" +CONFIG_USB0_VBUS_DET="axp_vbus_detect" +CONFIG_VIDEO_LCD_MODE="x:800,y:480,depth:18,pclk_khz:40000,le:87,ri:112,up:38,lo:141,hs:1,vs:1,sync:3,vmode:0" +CONFIG_VIDEO_LCD_POWER="PH8" +CONFIG_VIDEO_LCD_BL_EN="PH7" +CONFIG_VIDEO_LCD_BL_PWM="PB2" ++S:CONFIG_ARM=y ++S:CONFIG_ARCH_SUNXI=y ++S:CONFIG_MACH_SUN7I=y ++S:CONFIG_DRAM_CLK=432 ++S:CONFIG_DRAM_ZQ=123 ++S:CONFIG_DRAM_EMR1=4
Thanks for the patch, looks good, but needs adjustment for the discussed changes to treat axp vbus-detect / vbus-enable as regular gpios.
Also we no longer use the +S: magic in defconfig files as there now is a single .config for both the SPL and regular u-boot builds, so when you resubmit together with the axp cleanups, please remove the +S: prefixes.
Regards,
Hans

Hi Paul,
On 15-03-15 18:29, Paul Kocialkowski wrote:
Signed-off-by: Paul Kocialkowski contact@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
participants (2)
-
Hans de Goede
-
Paul Kocialkowski