Skip to contentSkip to conversation

ARM: davinci: use gpio descriptors for mmc pins

PATCH Applied Axel Haslam 2 participants 6 messages Nov 24, 2016 – Nov 28, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover ARM: davinci: use gpio descriptors for mmc pins

For the boards that use gpios managed by the davinci gpio driver, we can use gpio descriptors to control the the mmc pins.

This will let the mmc driver register an interrupt for the card detect pin, and also allows us to remove the dependency on platform callbacks for these boards.

For boards using a CPLD or an MSP the conversion is not yet done, and they still rely on the platform callbacks and polling. More work is needed to be able to manage those pins with gpio descriptors. Once that is done, we would be able to remove completely platform callbacks.

Changes v1->v2
*Convert da850-evm and da830-evm
*keep hack board pins as they are not compatible with lcdk (Sekhar)

Dependency:
This patch depends on a mmc driver patch currently in linux-next.
MMC: davinci: fix card detect and write protect
https://lkml.org/lkml/2016/11/15/592

Axel Haslam (3):
ARM: davinci: hawk: use gpio descriptor for card detect
ARM: davinci: da850-evm: use gpio descriptor for mmc pins
ARM: davinci: da830-evm: use gpio descriptor for mmc pins

 arch/arm/mach-davinci/board-da830-evm.c     | 41 ++++++++--------------------
 arch/arm/mach-davinci/board-da850-evm.c     | 35 +++++++-----------------
 arch/arm/mach-davinci/board-omapl138-hawk.c | 42 ++++++++---------------------
 3 files changed, 32 insertions(+), 86 deletions(-)
Signature · 1 line
2.9.3
#1 lore raw

PATCH v2 1/3 ARM: davinci: hawk: use gpio descriptor for mmc pins

Currently the mmc driver is polling the gpio to know if the card was removed.

By using a gpio descriptor instead of the platform callbacks, the driver will be able to register the gpio using the mmc core API's designed for this purpose.

This has the advantage that an irq will be registered, and polling is no longer needed. Also, a dependency on platform callbacks is removed for this board.

---
 arch/arm/mach-davinci/board-omapl138-hawk.c | 42 ++++++++---------------------
 1 file changed, 11 insertions(+), 31 deletions(-)
arch/arm/mach-davinci/board-omapl138-hawk.c +11 -31
index a4e8726..a2966d3 100644
@@ -15,6 +15,7 @@
 #include <linux/gpio.h>
 #include <linux/platform_data/gpio-davinci.h>
 #include <linux/regulator/machine.h>
+#include <linux/gpio/machine.h>
 
 #include <asm/mach-types.h>
 #include <asm/mach/arch.h>
@@ -25,8 +26,6 @@
 #include <mach/mux.h>
 
 #define HAWKBOARD_PHY_ID		"davinci_mdio-0:07"
-#define DA850_HAWK_MMCSD_CD_PIN		GPIO_TO_PIN(3, 12)
-#define DA850_HAWK_MMCSD_WP_PIN		GPIO_TO_PIN(3, 13)
 
 #define DA850_USB1_VBUS_PIN		GPIO_TO_PIN(2, 4)
 #define DA850_USB1_OC_PIN		GPIO_TO_PIN(6, 13)
@@ -123,19 +122,16 @@ static const short hawk_mmcsd0_pins[] = {
 	-1
 };
 
-static int da850_hawk_mmc_get_ro(int index)
-{
-	return gpio_get_value(DA850_HAWK_MMCSD_WP_PIN);
-}
-
-static int da850_hawk_mmc_get_cd(int index)
-{
-	return !gpio_get_value(DA850_HAWK_MMCSD_CD_PIN);
-}
+static struct gpiod_lookup_table mmc_gpios_table = {
+	.dev_id = "da830-mmc.0",
+	.table = {
+		/* CD: gpio3_12: gpio60: chip 1 contains gpio range 32-63*/
+		GPIO_LOOKUP("davinci_gpio.1", 28, "cd", GPIO_ACTIVE_LOW),
+		GPIO_LOOKUP("davinci_gpio.1", 29, "wp", GPIO_ACTIVE_LOW),
+	},
+};
 
 static struct davinci_mmc_config da850_mmc_config = {
-	.get_ro		= da850_hawk_mmc_get_ro,
-	.get_cd		= da850_hawk_mmc_get_cd,
 	.wires		= 4,
 	.max_freq	= 50000000,
 	.caps		= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED,
@@ -151,21 +147,7 @@ static __init void omapl138_hawk_mmc_init(void)
 		return;
 	}
 
-	ret = gpio_request_one(DA850_HAWK_MMCSD_CD_PIN,
-			GPIOF_DIR_IN, "MMC CD");
-	if (ret < 0) {
-		pr_warn("%s: can not open GPIO %d\n",
-			__func__, DA850_HAWK_MMCSD_CD_PIN);
-		return;
-	}
-
-	ret = gpio_request_one(DA850_HAWK_MMCSD_WP_PIN,
-			GPIOF_DIR_IN, "MMC WP");
-	if (ret < 0) {
-		pr_warn("%s: can not open GPIO %d\n",
-			__func__, DA850_HAWK_MMCSD_WP_PIN);
-		goto mmc_setup_wp_fail;
-	}
+	gpiod_add_lookup_table(&mmc_gpios_table);
 
 	ret = da8xx_register_mmcsd0(&da850_mmc_config);
 	if (ret) {
@@ -176,9 +158,7 @@ static __init void omapl138_hawk_mmc_init(void)
 	return;
 
 mmc_setup_mmcsd_fail:
-	gpio_free(DA850_HAWK_MMCSD_WP_PIN);
-mmc_setup_wp_fail:
-	gpio_free(DA850_HAWK_MMCSD_CD_PIN);
+	gpiod_remove_lookup_table(&mmc_gpios_table);
 }
 
 static irqreturn_t omapl138_hawk_usb_ocic_irq(int irq, void *dev_id);
Signature · 1 line
2.9.3
#3 lore raw

PATCH v2 2/3 ARM: davinci: da850-evm: use gpio descriptor for mmc pins

In reply to Axel Haslam

Currently the mmc driver is polling the gpio to know if the card was removed.

By using a gpio descriptor instead of the platform callbacks, the driver will be able to register the gpio using the mmc core API's designed for this purpose.

This has the advantage that an irq will be registered, and polling is no longer needed. Also, a dependency on platform callbacks is removed for this board.

---
 arch/arm/mach-davinci/board-da850-evm.c | 35 ++++++++++-----------------------
 1 file changed, 10 insertions(+), 25 deletions(-)
arch/arm/mach-davinci/board-da850-evm.c +10 -25
index ec5cb10..1a31ac3 100644
@@ -15,6 +15,7 @@
 #include <linux/delay.h>
 #include <linux/gpio.h>
 #include <linux/gpio_keys.h>
+#include <linux/gpio/machine.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/i2c.h>
@@ -56,9 +57,6 @@
 #define DA850_LCD_PWR_PIN		GPIO_TO_PIN(2, 8)
 #define DA850_LCD_BL_PIN		GPIO_TO_PIN(2, 15)
 
-#define DA850_MMCSD_CD_PIN		GPIO_TO_PIN(4, 0)
-#define DA850_MMCSD_WP_PIN		GPIO_TO_PIN(4, 1)
-
 #define DA850_MII_MDIO_CLKEN_PIN	GPIO_TO_PIN(2, 6)
 
 static struct mtd_partition da850evm_spiflash_part[] = {
@@ -776,19 +774,16 @@ static const short da850_evm_mcasp_pins[] __initconst = {
 	-1
 };
 
-static int da850_evm_mmc_get_ro(int index)
-{
-	return gpio_get_value(DA850_MMCSD_WP_PIN);
-}
-
-static int da850_evm_mmc_get_cd(int index)
-{
-	return !gpio_get_value(DA850_MMCSD_CD_PIN);
-}
+static struct gpiod_lookup_table mmc_gpios_table = {
+	.dev_id = "da830-mmc.0",
+	.table = {
+		/* gpio chip 2 contains gpio range 64-95 */
+		GPIO_LOOKUP("davinci_gpio.2", 0, "cd", GPIO_ACTIVE_LOW),
+		GPIO_LOOKUP("davinci_gpio.2", 1, "wp", GPIO_ACTIVE_LOW),
+	},
+};
 
 static struct davinci_mmc_config da850_mmc_config = {
-	.get_ro		= da850_evm_mmc_get_ro,
-	.get_cd		= da850_evm_mmc_get_cd,
 	.wires		= 4,
 	.max_freq	= 50000000,
 	.caps		= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED,
@@ -1383,17 +1378,7 @@ static __init void da850_evm_init(void)
 			pr_warn("%s: MMCSD0 mux setup failed: %d\n",
 				__func__, ret);
 
-		ret = gpio_request(DA850_MMCSD_CD_PIN, "MMC CD\n");
-		if (ret)
-			pr_warn("%s: can not open GPIO %d\n",
-				__func__, DA850_MMCSD_CD_PIN);
-		gpio_direction_input(DA850_MMCSD_CD_PIN);
-
-		ret = gpio_request(DA850_MMCSD_WP_PIN, "MMC WP\n");
-		if (ret)
-			pr_warn("%s: can not open GPIO %d\n",
-				__func__, DA850_MMCSD_WP_PIN);
-		gpio_direction_input(DA850_MMCSD_WP_PIN);
+		gpiod_add_lookup_table(&mmc_gpios_table);
 
 		ret = da8xx_register_mmcsd0(&da850_mmc_config);
 		if (ret)
Signature · 1 line
2.9.3
#5 lore raw

PATCH v2 3/3 ARM: davinci: da830-evm: use gpio descriptor for mmc pins

In reply to Axel Haslam

Currently the mmc driver is polling the gpio to know if the card was removed.

By using a gpio descriptor instead of the platform callbacks, the driver will be able to register the gpio using the mmc core API's designed for this purpose.

This has the advantage that an irq will be registered, and polling is no longer needed. Also, a dependency on platform callbacks is removed for this board.

---
 arch/arm/mach-davinci/board-da830-evm.c | 41 +++++++++------------------------
 1 file changed, 11 insertions(+), 30 deletions(-)
arch/arm/mach-davinci/board-da830-evm.c +11 -30
index 5db0901..5807562 100644
@@ -14,6 +14,7 @@
 #include <linux/console.h>
 #include <linux/interrupt.h>
 #include <linux/gpio.h>
+#include <linux/gpio/machine.h>
 #include <linux/platform_device.h>
 #include <linux/i2c.h>
 #include <linux/i2c/pcf857x.h>
@@ -204,22 +205,16 @@ static const short da830_evm_mmc_sd_pins[] = {
 	-1
 };
 
-#define DA830_MMCSD_WP_PIN		GPIO_TO_PIN(2, 1)
-#define DA830_MMCSD_CD_PIN		GPIO_TO_PIN(2, 2)
-
-static int da830_evm_mmc_get_ro(int index)
-{
-	return gpio_get_value(DA830_MMCSD_WP_PIN);
-}
-
-static int da830_evm_mmc_get_cd(int index)
-{
-	return !gpio_get_value(DA830_MMCSD_CD_PIN);
-}
+static struct gpiod_lookup_table mmc_gpios_table = {
+	.dev_id = "da830-mmc.0",
+	.table = {
+		/* gpio chip 1 contains gpio range 32-63 */
+		GPIO_LOOKUP("davinci_gpio.1", 2, "cd", GPIO_ACTIVE_LOW),
+		GPIO_LOOKUP("davinci_gpio.1", 1, "wp", GPIO_ACTIVE_LOW),
+	},
+};
 
 static struct davinci_mmc_config da830_evm_mmc_config = {
-	.get_ro			= da830_evm_mmc_get_ro,
-	.get_cd			= da830_evm_mmc_get_cd,
 	.wires			= 8,
 	.max_freq		= 50000000,
 	.caps			= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED,
@@ -235,26 +230,12 @@ static inline void da830_evm_init_mmc(void)
 		return;
 	}
 
-	ret = gpio_request(DA830_MMCSD_WP_PIN, "MMC WP");
-	if (ret) {
-		pr_warn("%s: can not open GPIO %d\n",
-			__func__, DA830_MMCSD_WP_PIN);
-		return;
-	}
-	gpio_direction_input(DA830_MMCSD_WP_PIN);
-
-	ret = gpio_request(DA830_MMCSD_CD_PIN, "MMC CD\n");
-	if (ret) {
-		pr_warn("%s: can not open GPIO %d\n",
-			__func__, DA830_MMCSD_CD_PIN);
-		return;
-	}
-	gpio_direction_input(DA830_MMCSD_CD_PIN);
+	gpiod_add_lookup_table(&mmc_gpios_table);
 
 	ret = da8xx_register_mmcsd0(&da830_evm_mmc_config);
 	if (ret) {
 		pr_warn("%s: mmc/sd registration failed: %d\n", __func__, ret);
-		gpio_free(DA830_MMCSD_WP_PIN);
+		gpiod_remove_lookup_table(&mmc_gpios_table);
 	}
 }
 
Signature · 1 line
2.9.3
Applied
#2 lore raw

Re: [PATCH v2 1/3] ARM: davinci: hawk: use gpio descriptor for mmc pins

In reply to Axel Haslam
Quoted 6 lines · Axel Haslam

Currently the mmc driver is polling the gpio to know if the card was removed.

By using a gpio descriptor instead of the platform callbacks, the driver will be able to register the gpio using the mmc core API's designed for this purpose.

s/API's/APIs

Quoted 15 lines

This has the advantage that an irq will be registered, and polling is no longer needed. Also, a dependency on platform callbacks is removed for this board.

---
 arch/arm/mach-davinci/board-omapl138-hawk.c | 42 ++++++++---------------------
 1 file changed, 11 insertions(+), 31 deletions(-)
arch/arm/mach-davinci/board-omapl138-hawk.c +0 -0
index a4e8726..a2966d3 100644

arch/arm/mach-davinci/board-omapl138-hawk.c line 18

Quoted 4 lines
arch/arm/mach-davinci/board-omapl138-hawk.c +1 -0
@@ -15,6 +15,7 @@
 #include <linux/gpio.h>
 #include <linux/platform_data/gpio-davinci.h>
 #include <linux/regulator/machine.h>
+#include <linux/gpio/machine.h>

Moved this include to below linux/gpio.h

Applied to v4.10/soc

Thanks,
Sekhar

Applied
#4 lore raw

Re: [PATCH v2 2/3] ARM: davinci: da850-evm: use gpio descriptor for mmc pins

In reply to Axel Haslam
Quoted 7 lines · Axel Haslam

Currently the mmc driver is polling the gpio to know if the card was removed.

By using a gpio descriptor instead of the platform callbacks, the driver will be able to register the gpio using the mmc core API's designed for this purpose.

Quoted 5 lines

This has the advantage that an irq will be registered, and polling is no longer needed. Also, a dependency on platform callbacks is removed for this board.

Applied.

Thanks,
Sekhar