Skip to contentSkip to conversation

mmc: sunxi: Fix misuse of gpio_direction_input()

PATCH New Axel Lin 3 participants 4 messages Dec 20, 2014 – Dec 22, 2014

Subsystems (3)
lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/1 mmc: sunxi: Fix misuse of gpio_direction_input()

It does not make sense to make gpio_direction_input() return the gpio input status. The return value of gpio_direction_input() is inconsistent if CONFIG_DM_GPIO is defined.
And we don't need to call gpio_direction_input() int sunxi_mmc_getcd(). Just init the gpio once in mmc_resource_init() is enough.

---
Only compile tested, so please test this patch.
Thanks.

 drivers/gpio/sunxi_gpio.c | 2 +-
 drivers/mmc/sunxi_mmc.c   | 7 +++++--
 2 files changed, 6 insertions(+), 3 deletions(-)
drivers/gpio/sunxi_gpio.c +1 -1
index 44135e5..2fa50f9 100644
@@ -75,7 +75,7 @@ int gpio_direction_input(unsigned gpio)
 {
 	sunxi_gpio_set_cfgpin(gpio, SUNXI_GPIO_INPUT);
 
-	return sunxi_gpio_input(gpio);
+	return 0;
 }
 
 int gpio_direction_output(unsigned gpio, int value)
drivers/mmc/sunxi_mmc.c +5 -2
index 231f0a0..0353355 100644
@@ -73,8 +73,11 @@ static int mmc_resource_init(int sdc_no)
 	mmchost->mmc_no = sdc_no;
 
 	cd_pin = sunxi_mmc_getcd_gpio(sdc_no);
-	if (cd_pin != -1)
+	if (cd_pin != -1) {
 		ret = gpio_request(cd_pin, "mmc_cd");
+		if (!ret)
+			ret = gpio_direction_input(cd_pin);
+	}
 
 	return ret;
 }
@@ -373,7 +376,7 @@ static int sunxi_mmc_getcd(struct mmc *mmc)
 	if (cd_pin == -1)
 		return 1;
 
-	return !gpio_direction_input(cd_pin);
+	return !gpio_get_value(cd_pin);
 }
 
 static const struct mmc_ops sunxi_mmc_ops = {
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/1 mmc: sunxi: Fix misuse of gpio_direction_input()

Quoted 6 lines · Axel Lin

It does not make sense to make gpio_direction_input() return the gpio input status. The return value of gpio_direction_input() is inconsistent if CONFIG_DM_GPIO is defined.
And we don't need to call gpio_direction_input() int sunxi_mmc_getcd(). Just init the gpio once in mmc_resource_init() is enough.

Quoted 7 lines

---
Only compile tested, so please test this patch.
Thanks.

 drivers/gpio/sunxi_gpio.c | 2 +-
 drivers/mmc/sunxi_mmc.c   | 7 +++++--
 2 files changed, 6 insertions(+), 3 deletions(-)
#2 lore raw

PATCH 1/1 mmc: sunxi: Fix misuse of gpio_direction_input()

Quoted 15 lines · Simon Glass
Quoted 6 lines · Axel Lin

It does not make sense to make gpio_direction_input() return the gpio input status. The return value of gpio_direction_input() is inconsistent if CONFIG_DM_GPIO is defined.
And we don't need to call gpio_direction_input() int sunxi_mmc_getcd(). Just init the gpio once in mmc_resource_init() is enough.

Quoted 7 lines

---
Only compile tested, so please test this patch.
Thanks.

 drivers/gpio/sunxi_gpio.c | 2 +-
 drivers/mmc/sunxi_mmc.c   | 7 +++++--
 2 files changed, 6 insertions(+), 3 deletions(-)
Quoted 1 line

Thanks, I booted it on my cubietruck and I could still see the mmc, so I've queued to u-boot-sunxi#next.

I don't think we need to rush this into v2015.01, but do shout if you think we do.

Ian.

author
#3 lore raw

PATCH 1/1 mmc: sunxi: Fix misuse of gpio_direction_input()

2014-12-22 20:59 GMT+08:00 Ian Campbell <[email protected]>:

Quoted 16 lines · Simon Glass
Quoted 15 lines · Axel Lin
Quoted 13 lines

It does not make sense to make gpio_direction_input() return the gpio input status. The return value of gpio_direction_input() is inconsistent if CONFIG_DM_GPIO is defined.
And we don't need to call gpio_direction_input() int sunxi_mmc_getcd(). Just init the gpio once in mmc_resource_init() is enough.

---
Only compile tested, so please test this patch.
Thanks.

 drivers/gpio/sunxi_gpio.c | 2 +-
 drivers/mmc/sunxi_mmc.c   | 7 +++++--
 2 files changed, 6 insertions(+), 3 deletions(-)
Quoted 7 lines
Quoted 1 line

Thanks, I booted it on my cubietruck and I could still see the mmc, so I've queued to u-boot-sunxi#next.

I don't think we need to rush this into v2015.01, but do shout if you think we do.

Hi Ian,
It's fine for v2015.01.

Thanks,
Axel