All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 0/3] sunxi: Ippo_q8h: Enable OTG VBUS detection using AXP223
@ 2015-03-09  7:44 Chen-Yu Tsai
  2015-03-09  7:44 ` [U-Boot] [PATCH 1/3] sunxi: axp221: Add VBUS detection support Chen-Yu Tsai
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Chen-Yu Tsai @ 2015-03-09  7:44 UTC (permalink / raw)
  To: u-boot

Hi Hans,

This series fixes otg support on the A23 q8h tablets. It adds support
for the AXP's (AXP221/223 for now) VBUS detection function.

I've tested this with a USB wireless keyboard dongle, which works fine.
More importantly, I'm using this and your mainline kernel musb work plus
a few A23 dts patches to get musb working on my q8h tablet in host mode.
I have an ethernet dongle plugged in, which works reasonably well.

Note that U-Boot never calls musb_shutdown() to do proper cleanup, like
disabling VBUS, so the current state carries on into Linux.


Regards
ChenYu


Chen-Yu Tsai (3):
  sunxi: axp221: Add VBUS detection support
  sunxi: musb: Support checking VBUS using AXP221 PMIC
  sunxi: Ippo_q8h defconfigs: Enable otg vbus detection using AXP223
    PMIC

 configs/Ippo_q8h_v1_2_defconfig |  1 +
 configs/Ippo_q8h_v5_defconfig   |  1 +
 drivers/power/axp221.c          | 16 +++++++++++++
 drivers/usb/musb-new/sunxi.c    | 52 ++++++++++++++++++++++++++++++-----------
 include/axp221.h                |  7 ++++++
 5 files changed, 63 insertions(+), 14 deletions(-)

-- 
2.1.4

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [U-Boot] [PATCH 1/3] sunxi: axp221: Add VBUS detection support
  2015-03-09  7:44 [U-Boot] [PATCH 0/3] sunxi: Ippo_q8h: Enable OTG VBUS detection using AXP223 Chen-Yu Tsai
@ 2015-03-09  7:44 ` Chen-Yu Tsai
  2015-03-09  7:44 ` [U-Boot] [PATCH 2/3] sunxi: musb: Support checking VBUS using AXP221 PMIC Chen-Yu Tsai
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Chen-Yu Tsai @ 2015-03-09  7:44 UTC (permalink / raw)
  To: u-boot

Some of the AXP PMICs support VBUS detection, i.e. checking whether
VBUS power input is available and usable (supplied by an external
source). A few boards use this instead of a separate GPIO to detect
VBUS on USB OTG.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 drivers/power/axp221.c | 16 ++++++++++++++++
 include/axp221.h       |  7 +++++++
 2 files changed, 23 insertions(+)

diff --git a/drivers/power/axp221.c b/drivers/power/axp221.c
index 3e07f23..c2c3988 100644
--- a/drivers/power/axp221.c
+++ b/drivers/power/axp221.c
@@ -385,6 +385,22 @@ int axp221_get_sid(unsigned int *sid)
 	return 0;
 }
 
+int axp_get_vbus(void)
+{
+	int ret;
+	u8 val;
+
+	ret = axp221_init();
+	if (ret)
+		return ret;
+
+	ret = pmic_bus_read(AXP221_POWER_STATUS, &val);
+	if (ret)
+		return ret;
+
+	return (val & AXP221_POWER_STATUS_VBUS_USABLE) ? 1 : 0;
+}
+
 static int axp_drivebus_setup(void)
 {
 	int ret;
diff --git a/include/axp221.h b/include/axp221.h
index a20e25c..be6058e 100644
--- a/include/axp221.h
+++ b/include/axp221.h
@@ -14,6 +14,9 @@
 #define AXP223_RUNTIME_ADDR 0x2d
 
 /* Page 0 addresses */
+#define AXP221_POWER_STATUS	0x00
+#define AXP221_POWER_STATUS_VBUS_AVAIL	(1 << 5)
+#define AXP221_POWER_STATUS_VBUS_USABLE	(1 << 4)
 #define AXP221_CHIP_ID		0x03
 #define AXP221_OUTPUT_CTRL1	0x10
 #define AXP221_OUTPUT_CTRL1_DCDC0_EN	(1 << 0)
@@ -59,6 +62,9 @@
 /* Page 1 addresses */
 #define AXP221_SID		0x20
 
+/* We support vbus detection */
+#define AXP_VBUS_DETECT
+
 /* We support drivebus control */
 #define AXP_DRIVEBUS
 
@@ -77,5 +83,6 @@ int axp221_set_aldo3(unsigned int mvolt);
 int axp221_set_eldo(int eldo_num, unsigned int mvolt);
 int axp221_init(void);
 int axp221_get_sid(unsigned int *sid);
+int axp_get_vbus(void);
 int axp_drivebus_enable(void);
 int axp_drivebus_disable(void);
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [U-Boot] [PATCH 2/3] sunxi: musb: Support checking VBUS using AXP221 PMIC
  2015-03-09  7:44 [U-Boot] [PATCH 0/3] sunxi: Ippo_q8h: Enable OTG VBUS detection using AXP223 Chen-Yu Tsai
  2015-03-09  7:44 ` [U-Boot] [PATCH 1/3] sunxi: axp221: Add VBUS detection support Chen-Yu Tsai
@ 2015-03-09  7:44 ` Chen-Yu Tsai
  2015-03-09  7:44 ` [U-Boot] [PATCH 3/3] sunxi: Ippo_q8h defconfigs: Enable otg vbus detection using AXP223 PMIC Chen-Yu Tsai
  2015-03-10 11:08 ` [U-Boot] [PATCH 0/3] sunxi: Ippo_q8h: Enable OTG VBUS detection using AXP223 Hans de Goede
  3 siblings, 0 replies; 6+ messages in thread
From: Chen-Yu Tsai @ 2015-03-09  7:44 UTC (permalink / raw)
  To: u-boot

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>
---

A large portion of this patch is whitespace changes.

---
 drivers/usb/musb-new/sunxi.c | 52 ++++++++++++++++++++++++++++++++------------
 1 file changed, 38 insertions(+), 14 deletions(-)

diff --git a/drivers/usb/musb-new/sunxi.c b/drivers/usb/musb-new/sunxi.c
index fe45db1..4d8c15a 100644
--- a/drivers/usb/musb-new/sunxi.c
+++ b/drivers/usb/musb-new/sunxi.c
@@ -27,6 +27,15 @@
 #include <asm-generic/gpio.h>
 #include "linux-compat.h"
 #include "musb_core.h"
+#ifdef CONFIG_AXP152_POWER
+#include <axp152.h>
+#endif
+#ifdef CONFIG_AXP209_POWER
+#include <axp209.h>
+#endif
+#ifdef CONFIG_AXP221_POWER
+#include <axp221.h>
+#endif
 
 /******************************************************************************
  ******************************************************************************
@@ -228,29 +237,44 @@ static int sunxi_musb_init(struct musb *musb)
 
 	if (is_host_enabled(musb)) {
 		int vbus_det = sunxi_name_to_gpio(CONFIG_USB0_VBUS_DET);
-		if (vbus_det == -1) {
-			eprintf("Error invalid Vusb-det pin\n");
-			return -EINVAL;
-		}
 
-		err = gpio_request(vbus_det, "vbus0_det");
-		if (err)
-			return err;
+#ifdef AXP_VBUS_DETECT
+		if (!strcmp(CONFIG_USB0_VBUS_DET, "axp_vbus_detect")) {
+			err = axp_get_vbus();
+			if (err < 0)
+				return err;
+		} else {
+#endif
+			if (vbus_det == -1) {
+				eprintf("Error invalid Vusb-det pin\n");
+				return -EINVAL;
+			}
+
+			err = gpio_request(vbus_det, "vbus0_det");
+			if (err)
+				return err;
+
+			err = gpio_direction_input(vbus_det);
+			if (err) {
+				gpio_free(vbus_det);
+				return err;
+			}
+
+			err = gpio_get_value(vbus_det);
+			if (err) {
+				gpio_free(vbus_det);
+				return -EIO;
+			}
 
-		err = gpio_direction_input(vbus_det);
-		if (err) {
 			gpio_free(vbus_det);
-			return err;
+#ifdef AXP_VBUS_DETECT
 		}
+#endif
 
-		err = gpio_get_value(vbus_det);
 		if (err) {
 			eprintf("Error: A charger is plugged into the OTG\n");
-			gpio_free(vbus_det);
 			return -EIO;
 		}
-
-		gpio_free(vbus_det);
 	}
 
 	err = sunxi_usbc_request_resources(0);
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [U-Boot] [PATCH 3/3] sunxi: Ippo_q8h defconfigs: Enable otg vbus detection using AXP223 PMIC
  2015-03-09  7:44 [U-Boot] [PATCH 0/3] sunxi: Ippo_q8h: Enable OTG VBUS detection using AXP223 Chen-Yu Tsai
  2015-03-09  7:44 ` [U-Boot] [PATCH 1/3] sunxi: axp221: Add VBUS detection support Chen-Yu Tsai
  2015-03-09  7:44 ` [U-Boot] [PATCH 2/3] sunxi: musb: Support checking VBUS using AXP221 PMIC Chen-Yu Tsai
@ 2015-03-09  7:44 ` Chen-Yu Tsai
  2015-03-10 11:08 ` [U-Boot] [PATCH 0/3] sunxi: Ippo_q8h: Enable OTG VBUS detection using AXP223 Hans de Goede
  3 siblings, 0 replies; 6+ messages in thread
From: Chen-Yu Tsai @ 2015-03-09  7:44 UTC (permalink / raw)
  To: u-boot

Use the AXP223 PMIC to detect VBUS for musb otg support.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 configs/Ippo_q8h_v1_2_defconfig | 1 +
 configs/Ippo_q8h_v5_defconfig   | 1 +
 2 files changed, 2 insertions(+)

diff --git a/configs/Ippo_q8h_v1_2_defconfig b/configs/Ippo_q8h_v1_2_defconfig
index 192a461..9b0d0dd 100644
--- a/configs/Ippo_q8h_v1_2_defconfig
+++ b/configs/Ippo_q8h_v1_2_defconfig
@@ -3,6 +3,7 @@ CONFIG_SYS_EXTRA_OPTIONS="CONS_INDEX=5"
 CONFIG_FDTFILE="sun8i-a23-ippo-q8h-v1.2.dtb"
 CONFIG_USB_MUSB_SUNXI=y
 CONFIG_USB0_VBUS_PIN="axp_drivebus"
+CONFIG_USB0_VBUS_DET="axp_vbus_detect"
 CONFIG_VIDEO_LCD_MODE="x:800,y:480,depth:18,pclk_khz:33000,le:87,ri:167,up:31,lo:13,hs:1,vs:1,sync:3,vmode:0"
 CONFIG_VIDEO_LCD_DCLK_PHASE=0
 CONFIG_VIDEO_LCD_POWER="PH7"
diff --git a/configs/Ippo_q8h_v5_defconfig b/configs/Ippo_q8h_v5_defconfig
index 4786202..5bc90ce 100644
--- a/configs/Ippo_q8h_v5_defconfig
+++ b/configs/Ippo_q8h_v5_defconfig
@@ -3,6 +3,7 @@ CONFIG_SYS_EXTRA_OPTIONS="CONS_INDEX=5"
 CONFIG_FDTFILE="sun8i-a23-ippo-q8h-v5.dtb"
 CONFIG_USB_MUSB_SUNXI=y
 CONFIG_USB0_VBUS_PIN="axp_drivebus"
+CONFIG_USB0_VBUS_DET="axp_vbus_detect"
 CONFIG_VIDEO_LCD_MODE="x:800,y:480,depth:18,pclk_khz:33000,le:87,ri:168,up:31,lo:13,hs:1,vs:1,sync:3,vmode:0"
 CONFIG_VIDEO_LCD_DCLK_PHASE=0
 CONFIG_VIDEO_LCD_POWER="PH7"
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [U-Boot] [PATCH 0/3] sunxi: Ippo_q8h: Enable OTG VBUS detection using AXP223
  2015-03-09  7:44 [U-Boot] [PATCH 0/3] sunxi: Ippo_q8h: Enable OTG VBUS detection using AXP223 Chen-Yu Tsai
                   ` (2 preceding siblings ...)
  2015-03-09  7:44 ` [U-Boot] [PATCH 3/3] sunxi: Ippo_q8h defconfigs: Enable otg vbus detection using AXP223 PMIC Chen-Yu Tsai
@ 2015-03-10 11:08 ` Hans de Goede
  2015-03-10 11:49   ` Chen-Yu Tsai
  3 siblings, 1 reply; 6+ messages in thread
From: Hans de Goede @ 2015-03-10 11:08 UTC (permalink / raw)
  To: u-boot

Hi,

On 09-03-15 08:44, Chen-Yu Tsai wrote:
> Hi Hans,
>
> This series fixes otg support on the A23 q8h tablets. It adds support
> for the AXP's (AXP221/223 for now) VBUS detection function.
>
> I've tested this with a USB wireless keyboard dongle, which works fine.
> More importantly, I'm using this and your mainline kernel musb work plus
> a few A23 dts patches to get musb working on my q8h tablet in host mode.
> I have an ethernet dongle plugged in, which works reasonably well.

Thanks for working on this, I've merged this into u-boot-sunxi/next
and I plan to send a pull-req for this to get it into v2015.4-rc# soon,
as this fixes a regression which I (deliberately) introduced.

It would be cool if you do similar patches for the mainline kernel, for
the mainline kernel I would really like to see the status bit exported
as part of the gpio-chip which we still need to add to the axp2xx code for
the axp2xx gpio pins, this way the existing kernel musb code can just use
it.

I also believe that Ian was right when he said that we should probably
also make these bits special gpio-s in u-boot rather then using custom
API-s for them. But this is something which we can fix later, for now
this fixes the regression and as such is good enough.

> Note that U-Boot never calls musb_shutdown() to do proper cleanup, like
> disabling VBUS, so the current state carries on into Linux.

Hmm true, I guess that is not necessarily a problem, but something which
we do need to keep in mind.

Regards,

Hans

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [U-Boot] [PATCH 0/3] sunxi: Ippo_q8h: Enable OTG VBUS detection using AXP223
  2015-03-10 11:08 ` [U-Boot] [PATCH 0/3] sunxi: Ippo_q8h: Enable OTG VBUS detection using AXP223 Hans de Goede
@ 2015-03-10 11:49   ` Chen-Yu Tsai
  0 siblings, 0 replies; 6+ messages in thread
From: Chen-Yu Tsai @ 2015-03-10 11:49 UTC (permalink / raw)
  To: u-boot

Hi,

On Tue, Mar 10, 2015 at 7:08 PM, Hans de Goede <hdegoede@redhat.com> wrote:
> Hi,
>
> On 09-03-15 08:44, Chen-Yu Tsai wrote:
>>
>> Hi Hans,
>>
>> This series fixes otg support on the A23 q8h tablets. It adds support
>> for the AXP's (AXP221/223 for now) VBUS detection function.
>>
>> I've tested this with a USB wireless keyboard dongle, which works fine.
>> More importantly, I'm using this and your mainline kernel musb work plus
>> a few A23 dts patches to get musb working on my q8h tablet in host mode.
>> I have an ethernet dongle plugged in, which works reasonably well.
>
>
> Thanks for working on this, I've merged this into u-boot-sunxi/next
> and I plan to send a pull-req for this to get it into v2015.4-rc# soon,
> as this fixes a regression which I (deliberately) introduced.
>
> It would be cool if you do similar patches for the mainline kernel, for
> the mainline kernel I would really like to see the status bit exported
> as part of the gpio-chip which we still need to add to the axp2xx code for
> the axp2xx gpio pins, this way the existing kernel musb code can just use
> it.

Not sure this is going to fly with the maintainers. It is pretty much
a part of the power supply, which would have it's own driver.

Now I wanted to do the GPIOs, but then I went and did all the new
SoC stuff. Also the regular GPIOs are muxed with the GPIO regulators,
which is a bit nasty considering we might not have the driver core to
handle them. I haven't figured that part out yet. I suppose we could
just do kind of a hack where the pin is claimed by the regulator and
the regulator driver is free to change the mux.

I'll probably tackle this after AXP221 is merged and RSB is figured
out, and if no other things pop up.

> I also believe that Ian was right when he said that we should probably
> also make these bits special gpio-s in u-boot rather then using custom
> API-s for them. But this is something which we can fix later, for now
> this fixes the regression and as such is good enough.

I must have missed his comment. I do think a cleanup of the AXP code
is needed.

>> Note that U-Boot never calls musb_shutdown() to do proper cleanup, like
>> disabling VBUS, so the current state carries on into Linux.
>
>
> Hmm true, I guess that is not necessarily a problem, but something which
> we do need to keep in mind.

It's a bit like having regulators kept on for ethernet or simplefb, a
nice to have side-effect. :)


Regards
ChenYu

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-03-10 11:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-09  7:44 [U-Boot] [PATCH 0/3] sunxi: Ippo_q8h: Enable OTG VBUS detection using AXP223 Chen-Yu Tsai
2015-03-09  7:44 ` [U-Boot] [PATCH 1/3] sunxi: axp221: Add VBUS detection support Chen-Yu Tsai
2015-03-09  7:44 ` [U-Boot] [PATCH 2/3] sunxi: musb: Support checking VBUS using AXP221 PMIC Chen-Yu Tsai
2015-03-09  7:44 ` [U-Boot] [PATCH 3/3] sunxi: Ippo_q8h defconfigs: Enable otg vbus detection using AXP223 PMIC Chen-Yu Tsai
2015-03-10 11:08 ` [U-Boot] [PATCH 0/3] sunxi: Ippo_q8h: Enable OTG VBUS detection using AXP223 Hans de Goede
2015-03-10 11:49   ` Chen-Yu Tsai

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.