diff mbox

[U-Boot,03/21] sunxi: usbc: Fix vbus gpio handling to work with the device-model

Message ID 1429883310-22441-4-git-send-email-hdegoede@redhat.com
State Accepted
Delegated to: Hans de Goede
Headers show

Commit Message

Hans de Goede April 24, 2015, 1:48 p.m. UTC
The device-model gpio functions may return another value then -1 as error,
make the sunxi usbc properly handle this.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 arch/arm/cpu/armv7/sunxi/usbc.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

Comments

Fabio Estevam April 24, 2015, 6:10 p.m. UTC | #1
On Fri, Apr 24, 2015 at 10:48 AM, Hans de Goede <hdegoede@redhat.com> wrote:

>         sunxi_usbc->gpio_vbus = get_vbus_gpio(index);
> -       if (sunxi_usbc->gpio_vbus != -1) {
> +       if (sunxi_usbc->gpio_vbus >= 0) {

What about using dm_gpio_is_valid() instead?

Regards,

Fabio Estevam
Hans de Goede April 24, 2015, 6:15 p.m. UTC | #2
Hi,

On 24-04-15 20:10, Fabio Estevam wrote:
> On Fri, Apr 24, 2015 at 10:48 AM, Hans de Goede <hdegoede@redhat.com> wrote:
>
>>          sunxi_usbc->gpio_vbus = get_vbus_gpio(index);
>> -       if (sunxi_usbc->gpio_vbus != -1) {
>> +       if (sunxi_usbc->gpio_vbus >= 0) {
>
> What about using dm_gpio_is_valid() instead?

dm_gpio_is_valid takes a struct gpio_desc *, where as this code is using
good old gpio indexes (int). We will likely want to convert this to getting
the gpio from devicetree directly in the future, but first we need this
patch-set to convert all sunxi boards to the device-model, so that we can
make such changes without the need to introduce a whole lot of #ifdef-s

Regards,

Hans
Simon Glass April 24, 2015, 11:23 p.m. UTC | #3
On 24 April 2015 at 12:15, Hans de Goede <hdegoede@redhat.com> wrote:
> Hi,
>
>
> On 24-04-15 20:10, Fabio Estevam wrote:
>>
>> On Fri, Apr 24, 2015 at 10:48 AM, Hans de Goede <hdegoede@redhat.com>
>> wrote:
>>
>>>          sunxi_usbc->gpio_vbus = get_vbus_gpio(index);
>>> -       if (sunxi_usbc->gpio_vbus != -1) {
>>> +       if (sunxi_usbc->gpio_vbus >= 0) {
>>
>>
>> What about using dm_gpio_is_valid() instead?
>
>
> dm_gpio_is_valid takes a struct gpio_desc *, where as this code is using
> good old gpio indexes (int). We will likely want to convert this to getting
> the gpio from devicetree directly in the future, but first we need this
> patch-set to convert all sunxi boards to the device-model, so that we can
> make such changes without the need to introduce a whole lot of #ifdef-s
>

I think this is a good first step, but have the same concern.

Reviewed-by: Simon Glass <sjg@chromium.org>

> Regards,
>
> Hans
Ian Campbell April 26, 2015, 3:16 a.m. UTC | #4
On Fri, 2015-04-24 at 15:48 +0200, Hans de Goede wrote:
> The device-model gpio functions may return another value then -1 as error,
> make the sunxi usbc properly handle this.
> 
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>

Acked-by: Ian Campbell <ijc@hellion.org.uk>
diff mbox

Patch

diff --git a/arch/arm/cpu/armv7/sunxi/usbc.c b/arch/arm/cpu/armv7/sunxi/usbc.c
index 515549d..39452a7 100644
--- a/arch/arm/cpu/armv7/sunxi/usbc.c
+++ b/arch/arm/cpu/armv7/sunxi/usbc.c
@@ -17,6 +17,7 @@ 
 #include <asm/gpio.h>
 #include <asm/io.h>
 #include <common.h>
+#include <errno.h>
 #ifdef CONFIG_AXP152_POWER
 #include <axp152.h>
 #endif
@@ -90,7 +91,7 @@  static int get_vbus_gpio(int index)
 	case 1: return sunxi_name_to_gpio(CONFIG_USB1_VBUS_PIN);
 	case 2: return sunxi_name_to_gpio(CONFIG_USB2_VBUS_PIN);
 	}
-	return -1;
+	return -EINVAL;
 }
 
 static int get_vbus_detect_gpio(int index)
@@ -187,13 +188,13 @@  int sunxi_usbc_request_resources(int index)
 	int ret = 0;
 
 	sunxi_usbc->gpio_vbus = get_vbus_gpio(index);
-	if (sunxi_usbc->gpio_vbus != -1) {
+	if (sunxi_usbc->gpio_vbus >= 0) {
 		ret |= gpio_request(sunxi_usbc->gpio_vbus, "usbc_vbus");
 		ret |= gpio_direction_output(sunxi_usbc->gpio_vbus, 0);
 	}
 
 	sunxi_usbc->gpio_vbus_det = get_vbus_detect_gpio(index);
-	if (sunxi_usbc->gpio_vbus_det != -1) {
+	if (sunxi_usbc->gpio_vbus_det >= 0) {
 		ret |= gpio_request(sunxi_usbc->gpio_vbus_det, "usbc_vbus_det");
 		ret |= gpio_direction_input(sunxi_usbc->gpio_vbus_det);
 	}
@@ -206,10 +207,10 @@  int sunxi_usbc_free_resources(int index)
 	struct sunxi_usbc_hcd *sunxi_usbc = &sunxi_usbc_hcd[index];
 	int ret = 0;
 
-	if (sunxi_usbc->gpio_vbus != -1)
+	if (sunxi_usbc->gpio_vbus >= 0)
 		ret |= gpio_free(sunxi_usbc->gpio_vbus);
 
-	if (sunxi_usbc->gpio_vbus_det != -1)
+	if (sunxi_usbc->gpio_vbus_det >= 0)
 		ret |= gpio_free(sunxi_usbc->gpio_vbus_det);
 
 	return ret;
@@ -263,7 +264,7 @@  void sunxi_usbc_vbus_enable(int index)
 {
 	struct sunxi_usbc_hcd *sunxi_usbc = &sunxi_usbc_hcd[index];
 
-	if (sunxi_usbc->gpio_vbus != -1)
+	if (sunxi_usbc->gpio_vbus >= 0)
 		gpio_set_value(sunxi_usbc->gpio_vbus, 1);
 }
 
@@ -271,7 +272,7 @@  void sunxi_usbc_vbus_disable(int index)
 {
 	struct sunxi_usbc_hcd *sunxi_usbc = &sunxi_usbc_hcd[index];
 
-	if (sunxi_usbc->gpio_vbus != -1)
+	if (sunxi_usbc->gpio_vbus >= 0)
 		gpio_set_value(sunxi_usbc->gpio_vbus, 0);
 }
 
@@ -280,9 +281,9 @@  int sunxi_usbc_vbus_detect(int index)
 	struct sunxi_usbc_hcd *sunxi_usbc = &sunxi_usbc_hcd[index];
 	int err, retries = 3;
 
-	if (sunxi_usbc->gpio_vbus_det == -1) {
+	if (sunxi_usbc->gpio_vbus_det < 0) {
 		eprintf("Error: invalid vbus detection pin\n");
-		return -1;
+		return sunxi_usbc->gpio_vbus_det;
 	}
 
 	err = gpio_get_value(sunxi_usbc->gpio_vbus_det);