diff mbox

[U-Boot,2/6] sunxi: Add mmc card-detect functionality

Message ID 1412348759-4599-3-git-send-email-hdegoede@redhat.com
State Superseded
Delegated to: Ian Campbell
Headers show

Commit Message

Hans de Goede Oct. 3, 2014, 3:05 p.m. UTC
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 board/sunxi/Kconfig     | 27 +++++++++++++++++++++++++++
 drivers/mmc/sunxi_mmc.c | 20 ++++++++++++++++++++
 2 files changed, 47 insertions(+)

Comments

Ian Campbell Oct. 4, 2014, 8:30 a.m. UTC | #1
On Fri, 2014-10-03 at 17:05 +0200, Hans de Goede wrote:
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  board/sunxi/Kconfig     | 27 +++++++++++++++++++++++++++
>  drivers/mmc/sunxi_mmc.c | 20 ++++++++++++++++++++
>  2 files changed, 47 insertions(+)
> 
> diff --git a/board/sunxi/Kconfig b/board/sunxi/Kconfig
> index 622f7b4..72d6dfa 100644
> --- a/board/sunxi/Kconfig
> +++ b/board/sunxi/Kconfig
> @@ -32,4 +32,31 @@ config USB_KEYBOARD
>  	Say Y here to add support for using a USB keyboard (typically used
>  	in combination with a graphical console on HDMI).
>  
> +config MMC0_CD_PIN
> +	int "Card detect pin for mmc0"
> +	default -1
> +	---help---
> +	Set the card detect pin for mmc0, set to -1 to not use cd. The pins
> +	are numbered as follows PA0 - PA17 are pin number 0 - 17, PB0 - PB23
> +	are 32 - 55, PC0 - PC24 are 64 - 88, etc. Most boards use PH1 for
> +	mmc0 cd, which is pin nr 225.

Is there any way we could use the same trick as for SATAPWR and allow
this to be specified as something like GPx(y) instead of requiring this
complex mapping in the help text? Might be possible with some
combination of Kconfig and cpp trickery?

Maybe the simplest solution is to make this a string and pass it to
name_to_gpio at runtime (e.g gpio = name_to_gpio(CONFIG_MMC0_CD_PIN)),
although that has the disadvantage of being runtime only check.

Ian.
Hans de Goede Oct. 5, 2014, 2:58 p.m. UTC | #2
Hi,

On 10/04/2014 10:30 AM, Ian Campbell wrote:
> On Fri, 2014-10-03 at 17:05 +0200, Hans de Goede wrote:
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
>>  board/sunxi/Kconfig     | 27 +++++++++++++++++++++++++++
>>  drivers/mmc/sunxi_mmc.c | 20 ++++++++++++++++++++
>>  2 files changed, 47 insertions(+)
>>
>> diff --git a/board/sunxi/Kconfig b/board/sunxi/Kconfig
>> index 622f7b4..72d6dfa 100644
>> --- a/board/sunxi/Kconfig
>> +++ b/board/sunxi/Kconfig
>> @@ -32,4 +32,31 @@ config USB_KEYBOARD
>>  	Say Y here to add support for using a USB keyboard (typically used
>>  	in combination with a graphical console on HDMI).
>>  
>> +config MMC0_CD_PIN
>> +	int "Card detect pin for mmc0"
>> +	default -1
>> +	---help---
>> +	Set the card detect pin for mmc0, set to -1 to not use cd. The pins
>> +	are numbered as follows PA0 - PA17 are pin number 0 - 17, PB0 - PB23
>> +	are 32 - 55, PC0 - PC24 are 64 - 88, etc. Most boards use PH1 for
>> +	mmc0 cd, which is pin nr 225.
> 
> Is there any way we could use the same trick as for SATAPWR and allow
> this to be specified as something like GPx(y) instead of requiring this
> complex mapping in the help text? Might be possible with some
> combination of Kconfig and cpp trickery?
> 
> Maybe the simplest solution is to make this a string and pass it to
> name_to_gpio at runtime (e.g gpio = name_to_gpio(CONFIG_MMC0_CD_PIN)),
> although that has the disadvantage of being runtime only check.

I agree that being able to use symbolic names is much better, but I
could not find a Kconfig / cpp trickery way to do this. I think that
using name_to_gpio is a good solution for this, so that is what I'll
do for v2.

Regards,

Hans
diff mbox

Patch

diff --git a/board/sunxi/Kconfig b/board/sunxi/Kconfig
index 622f7b4..72d6dfa 100644
--- a/board/sunxi/Kconfig
+++ b/board/sunxi/Kconfig
@@ -32,4 +32,31 @@  config USB_KEYBOARD
 	Say Y here to add support for using a USB keyboard (typically used
 	in combination with a graphical console on HDMI).
 
+config MMC0_CD_PIN
+	int "Card detect pin for mmc0"
+	default -1
+	---help---
+	Set the card detect pin for mmc0, set to -1 to not use cd. The pins
+	are numbered as follows PA0 - PA17 are pin number 0 - 17, PB0 - PB23
+	are 32 - 55, PC0 - PC24 are 64 - 88, etc. Most boards use PH1 for
+	mmc0 cd, which is pin nr 225.
+
+config MMC1_CD_PIN
+	int "Card detect pin for mmc1"
+	default -1
+	---help---
+	See MMC0_CD_PIN help text.
+
+config MMC2_CD_PIN
+	int "Card detect pin for mmc2"
+	default -1
+	---help---
+	See MMC0_CD_PIN help text.
+
+config MMC3_CD_PIN
+	int "Card detect pin for mmc3"
+	default -1
+	---help---
+	See MMC0_CD_PIN help text.
+
 endif
diff --git a/drivers/mmc/sunxi_mmc.c b/drivers/mmc/sunxi_mmc.c
index bc2c4b3..a397b86 100644
--- a/drivers/mmc/sunxi_mmc.c
+++ b/drivers/mmc/sunxi_mmc.c
@@ -14,6 +14,7 @@ 
 #include <asm/io.h>
 #include <asm/arch/clock.h>
 #include <asm/arch/cpu.h>
+#include <asm/arch/gpio.h>
 #include <asm/arch/mmc.h>
 
 struct sunxi_mmc_host {
@@ -343,10 +344,29 @@  out:
 	return error;
 }
 
+static int sunxi_mmc_getcd(struct mmc *mmc)
+{
+	struct sunxi_mmc_host *mmchost = mmc->priv;
+	int cd_pin = -1;
+
+	switch (mmchost->mmc_no) {
+	case 0: cd_pin = CONFIG_MMC0_CD_PIN; break;
+	case 1: cd_pin = CONFIG_MMC1_CD_PIN; break;
+	case 2: cd_pin = CONFIG_MMC2_CD_PIN; break;
+	case 3: cd_pin = CONFIG_MMC3_CD_PIN; break;
+	}
+
+	if (cd_pin == -1)
+		return 1;
+
+	return !sunxi_gpio_get_val(cd_pin);
+}
+
 static const struct mmc_ops sunxi_mmc_ops = {
 	.send_cmd	= mmc_send_cmd,
 	.set_ios	= mmc_set_ios,
 	.init		= mmc_core_init,
+	.getcd		= sunxi_mmc_getcd,
 };
 
 int sunxi_mmc_init(int sdc_no)