Skip to contentSkip to conversation

Exynos5: Pinmux: Add fdt for pinmux

PATCH Superseded Akshay Saraswat 2 participants 2 messages Feb 25, 2013 – Feb 28, 2013

Subsystems (3)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 Exynos5: Pinmux: Add fdt for pinmux

This patch adds fdt nodes for peripherals which require pin muxing and configuration. Device tree bindings for pinctrl are kept same as required for Linux. Existing pinmux code modified to retrieve gpio range and function related info from fdt.

Depends-on: [U-Boot] [PATCH 0/4 V3] EXYNOS5: Add GPIO numbering feature
URL: http://lists.denx.de/pipermail/u-boot/2013-February/146151.html

---
Changes since v3:
- Added comments to reduce ambiguity and increase readability.
- Fixed few other nits.

 arch/arm/cpu/armv7/exynos/pinmux.c           |  404 +++++++++++----
 arch/arm/dts/exynos5250-pinctrl.dtsi         |  675 ++++++++++++++++++++++++++
 arch/arm/dts/exynos5250.dtsi                 |    1 +
 doc/device-tree-bindings/samsung-pinctrl.txt |  253 ++++++++++
 include/fdtdec.h                             |    1 +
 lib/fdtdec.c                                 |    1 +
 6 files changed, 1229 insertions(+), 106 deletions(-)
 create mode 100644 arch/arm/dts/exynos5250-pinctrl.dtsi
 create mode 100644 doc/device-tree-bindings/samsung-pinctrl.txt
arch/arm/cpu/armv7/exynos/pinmux.c +298 -106
index a01ce0c..ba34560 100644
@@ -27,6 +27,21 @@
 #include <asm/arch/pinmux.h>
 #include <asm/arch/sromc.h>
 
+DECLARE_GLOBAL_DATA_PTR;
+
+/*
+ * Struct for temporarily storing pin numbers and
+ * pin function related info.
+ */
+struct pin_group {
+	void *dev_name;			/* Name of the Peripheral device */
+	int npins;			/* Number of pins to be configured */
+	int function;			/* Pin function */
+	int pull_mode;			/* Pin pull mode */
+	int drive_strength;		/* Pin drive strength */
+	enum exynos5_gpio_pin gpio[];	/* Pin numbers to be configured */
+};
+
 struct gpio_name_num_table exynos5_gpio_table[] = {
 	{ 'a', GPIO_A00 },
 	{ 'b', GPIO_B00 },
@@ -42,87 +57,224 @@ struct gpio_name_num_table exynos5_gpio_table[] = {
 	{ 'z', GPIO_Z0 },
 };
 
-static void exynos5_uart_config(int peripheral)
+/* Populate exynos5_gpio_pin array in a particular pin_group */
+static void pinmux_get_pin_numbers(const struct fdt_property *fprop,
+						struct pin_group *pingrp)
+{
+	int i;
+	char gpio[5];
+
+	pingrp->npins = 0;
+
+	/*
+	 * Get all the pin names from fdt and fill the gpio array
+	 * with corresponding enum values(Pin numbers).
+	 */
+	for (i = 0; !(fprop->data[i] == (int)NULL &&
+				fprop->data[i-1] == (int)NULL); i += 7) {
+		int pin_num = -1;
+
+		/*
+		 * Modify pin name retrieved from fdt,
+		 * so that name_to_gpio may understand.
+		 */
+		gpio[0] = fprop->data[i];
+		gpio[1] = fprop->data[i + 1];
+		gpio[2] = fprop->data[i + 2];
+		gpio[3] = fprop->data[i + 3];
+		gpio[4] = fprop->data[i + 5];
+
+		pin_num = name_to_gpio(gpio);
+
+		/*
+		 * If pin number is valid, add it to the pin array
+		 * and increment pin count.
+		 */
+		if (pin_num >= 0) {
+			pingrp->gpio[pingrp->npins] = pin_num;
+			pingrp->npins++;
+		}
+	}
+}
+
+/* Extract all the config info for a node from fdt */
+static int pinmux_get_fdt_values(struct pin_group *pingrp)
 {
-	int i, start, count;
+	int node, subnode;
+	const struct fdt_property *fprop;
+
+	/* Loop for all pinctrl nodes in fdt */
+	for (node = fdtdec_next_compatible(gd->fdt_blob, 0,
+			COMPAT_SAMSUNG_PINCTRL); node >= 0;
+			node = fdtdec_next_compatible(gd->fdt_blob, node,
+						COMPAT_SAMSUNG_PINCTRL)) {
+		/* Get the subnode from FDT for this peripheral*/
+		subnode = fdt_subnode_offset(gd->fdt_blob,
+						node, pingrp->dev_name);
+		if (subnode < 0)
+			continue;
+
+		/* Get names of pins to be configured from fdt */
+		fprop = fdt_get_property(gd->fdt_blob,
+					subnode, "samsung,pins", NULL);
+
+		/* Convert pin names to pin numbers */
+		pinmux_get_pin_numbers(fprop, pingrp);
+
+		/* Get the pin function from fdt */
+		pingrp->function = fdtdec_get_int(gd->fdt_blob,
+					subnode, "samsung,pin-function", 0);
+
+		/* Get the pull mode for pins from fdt */
+		pingrp->pull_mode = fdtdec_get_int(gd->fdt_blob,
+					subnode, "samsung,pin-pud", 0);
+
+		/* Get the drive strength for pins from fdt */
+		pingrp->drive_strength = fdtdec_get_int(gd->fdt_blob,
+					subnode, "samsung,pin-drv", 0);
+
+		return 0;
+	}
+
+	debug("PINCTRL: Subnode for %s is missing\n",
+					(const char *)pingrp->dev_name);
+
+	return -1;
+}
+
+/* Set configuration for all pins as per fdt node */
+static void pinmux_group_set(struct pin_group *pingrp)
+{
+	int i;
+
+	for (i = 0; i < pingrp->npins; i++) {
+		gpio_cfg_pin(pingrp->gpio[i], S5P_GPIO_FUNC(pingrp->function));
+		gpio_set_pull(pingrp->gpio[i], pingrp->pull_mode);
+		gpio_set_drv(pingrp->gpio[i], pingrp->drive_strength);
+	}
+}
+
+static int exynos5_uart_config(int peripheral)
+{
+	char *data, *fctl = NULL;
+	struct pin_group pingrp;
 
 	switch (peripheral) {
 	case PERIPH_ID_UART0:
-		start = GPIO_A00;
-		count = 4;
+		data = "uart0-data";
+		fctl = "uart0-fctl";
 		break;
 	case PERIPH_ID_UART1:
-		start = GPIO_D00;
-		count = 4;
+		data = "uart1-data";
+		fctl = "uart1-fctl";
 		break;
 	case PERIPH_ID_UART2:
-		start = GPIO_A10;
-		count = 4;
+		data = "uart2-data";
+		fctl = "uart2-fctl";
 		break;
 	case PERIPH_ID_UART3:
-		start = GPIO_A14;
-		count = 2;
+		data = "uart3-data";
 		break;
 	}
-	for (i = start; i < start + count; i++) {
-		gpio_set_pull(i, S5P_GPIO_PULL_NONE);
-		gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
+
+	pingrp.dev_name = data;
+
+	/*
+	 * Retrieve and apply pin config details
+	 * from fdt for this UART's data line.
+	 */
+	if (pinmux_get_fdt_values(&pingrp))
+		return -1;
+
+	pinmux_group_set(&pingrp);
+
+	if (peripheral != PERIPH_ID_UART3) {
+		pingrp.dev_name = fctl;
+
+		/*
+		 * Retrieve and apply pin config details
+		 * from fdt for this UART's fctl.
+		 */
+		if (pinmux_get_fdt_values(&pingrp))
+			return -1;
+
+		pinmux_group_set(&pingrp);
 	}
+
+	return 0;
 }
 
 static int exynos5_mmc_config(int peripheral, int flags)
 {
-	int i, start, start_ext, gpio_func = 0;
+	char *periph_name = NULL;
+	struct pin_group pingrp;
 
 	switch (peripheral) {
 	case PERIPH_ID_SDMMC0:
-		start = GPIO_C00;
-		start_ext = GPIO_C10;
-		gpio_func = S5P_GPIO_FUNC(0x2);
+		periph_name = "sd0";
 		break;
 	case PERIPH_ID_SDMMC1:
-		start = GPIO_C20;
-		start_ext = 0;
+		periph_name = "sd1";
 		break;
 	case PERIPH_ID_SDMMC2:
-		start = GPIO_C30;
-		start_ext = GPIO_C43;
-		gpio_func = S5P_GPIO_FUNC(0x3);
+		periph_name = "sd2";
 		break;
 	case PERIPH_ID_SDMMC3:
-		start = GPIO_C40;
-		start_ext = 0;
+		periph_name = "sd3";
 		break;
 	}
-	if ((flags & PINMUX_FLAG_8BIT_MODE) && !start_ext) {
-		debug("SDMMC device %d does not support 8bit mode",
-				peripheral);
-		return -1;
-	}
+
 	if (flags & PINMUX_FLAG_8BIT_MODE) {
-		for (i = start_ext; i <= (start_ext + 3); i++) {
-			gpio_cfg_pin(i, gpio_func);
-			gpio_set_pull(i, S5P_GPIO_PULL_UP);
-			gpio_set_drv(i, S5P_GPIO_DRV_4X);
-		}
-	}
-	for (i = 0; i < 2; i++) {
-		gpio_cfg_pin(start + i, S5P_GPIO_FUNC(0x2));
-		gpio_set_pull(start + i, S5P_GPIO_PULL_NONE);
-		gpio_set_drv(start + i, S5P_GPIO_DRV_4X);
-	}
-	for (i = 3; i <= 6; i++) {
-		gpio_cfg_pin(start + i, S5P_GPIO_FUNC(0x2));
-		gpio_set_pull(start + i, S5P_GPIO_PULL_UP);
-		gpio_set_drv(start + i, S5P_GPIO_DRV_4X);
+		pingrp.dev_name = strcat(periph_name, "-bus-width8");
+		/*
+		 * Retrieve and apply pin config details from fdt
+		 * for remaining 4 bits if this sd has 8-bit bus.
+		 */
+		if (pinmux_get_fdt_values(&pingrp))
+			return -1;
+
+		pinmux_group_set(&pingrp);
 	}
 
+	pingrp.dev_name = strcat(periph_name, "-clk");
+
+	/*
+	 * Retrieve and apply pin config details
+	 * from fdt for this sd's clk.
+	 */
+	if (pinmux_get_fdt_values(&pingrp))
+		return -1;
+
+	pinmux_group_set(&pingrp);
+
+	pingrp.dev_name = strcat(periph_name, "-cmd");
+
+	/*
+	 * Retrieve and apply pin config details
+	 * from fdt for this sd's cmd.
+	 */
+	if (pinmux_get_fdt_values(&pingrp))
+		return -1;
+
+	pinmux_group_set(&pingrp);
+
+	pingrp.dev_name = strcat(periph_name, "-bus-width4");
+
+	/*
+	 * Retrieve and apply pin config details
+	 * from fdt for this sd's 4-bit bus.
+	 */
+	if (pinmux_get_fdt_values(&pingrp))
+		return -1;
+
+	pinmux_group_set(&pingrp);
+
 	return 0;
 }
 
-static void exynos5_sromc_config(int flags)
+static int exynos5_sromc_config(int flags)
 {
-	int i;
+	static struct pin_group pingrp;
 
 	/*
 	 * SROM:CS1 and EBI
@@ -139,13 +291,28 @@ static void exynos5_sromc_config(int flags)
 	 * GPY1[2]	SROM_WAIT(2)
 	 * GPY1[3]	EBI_DATA_RDn(2)
 	 */
-	gpio_cfg_pin(GPIO_Y00 + (flags & PINMUX_FLAG_BANK),
-				S5P_GPIO_FUNC(2));
-	gpio_cfg_pin(GPIO_Y04, S5P_GPIO_FUNC(2));
-	gpio_cfg_pin(GPIO_Y05, S5P_GPIO_FUNC(2));
+	pingrp.dev_name = "srom-cs1";
+
+	/*
+	 * Retrieve and apply pin config details
+	 * from fdt to enable SROM CS1.
+	 */
+	if (pinmux_get_fdt_values(&pingrp))
+		return -1;
+
+	pingrp.gpio[0] += (flags & PINMUX_FLAG_BANK);
+	pinmux_group_set(&pingrp);
+
+	pingrp.dev_name = "srom-ebi-enable";
+
+	/*
+	 * Retrieve and apply pin config details
+	 * from fdt to enable SROM EBI.
+	 */
+	if (pinmux_get_fdt_values(&pingrp))
+		return -1;
 
-	for (i = 0; i < 4; i++)
-		gpio_cfg_pin(GPIO_Y10 + i, S5P_GPIO_FUNC(2));
+	pinmux_group_set(&pingrp);
 
 	/*
 	 * EBI: 8 Addrss Lines
@@ -179,97 +346,124 @@ static void exynos5_sromc_config(int flags)
 	 * GPY6[6]	EBI_DATA[14](2)
 	 * GPY6[7]	EBI_DATA[15](2)
 	 */
-	for (i = 0; i < 8; i++) {
-		gpio_cfg_pin(GPIO_Y30 + i, S5P_GPIO_FUNC(2));
-		gpio_set_pull(GPIO_Y30 + i, S5P_GPIO_PULL_UP);
+	pingrp.dev_name = "srom-ebi-addr-lines";
 
-		gpio_cfg_pin(GPIO_Y50 + i, S5P_GPIO_FUNC(2));
-		gpio_set_pull(GPIO_Y50 + i, S5P_GPIO_PULL_UP);
+	/*
+	 * Retrieve and apply pin config details
+	 * from fdt for EBI address lines.
+	 */
+	if (pinmux_get_fdt_values(&pingrp))
+		return -1;
 
-		gpio_cfg_pin(GPIO_Y60 + i, S5P_GPIO_FUNC(2));
-		gpio_set_pull(GPIO_Y60 + i, S5P_GPIO_PULL_UP);
-	}
+	pinmux_group_set(&pingrp);
+
+	pingrp.dev_name = "srom-ebi-data-lines";
+
+	/*
+	 * Retrieve and apply pin config details
+	 * from fdt for EBI data lines.
+	 */
+	if (pinmux_get_fdt_values(&pingrp))
+		return -1;
+
+	pinmux_group_set(&pingrp);
+
+	return 0;
 }
 
-static void exynos5_i2c_config(int peripheral, int flags)
+static int exynos5_i2c_config(int peripheral, int flags)
 {
+	struct pin_group pingrp;
 
 	switch (peripheral) {
 	case PERIPH_ID_I2C0:
-		gpio_cfg_pin(GPIO_B30, S5P_GPIO_FUNC(0x2));
-		gpio_cfg_pin(GPIO_B31, S5P_GPIO_FUNC(0x2));
+		pingrp.dev_name = "i2c0-bus";
 		break;
 	case PERIPH_ID_I2C1:
-		gpio_cfg_pin(GPIO_B32, S5P_GPIO_FUNC(0x2));
-		gpio_cfg_pin(GPIO_B33, S5P_GPIO_FUNC(0x2));
+		pingrp.dev_name = "i2c1-bus";
 		break;
 	case PERIPH_ID_I2C2:
-		gpio_cfg_pin(GPIO_A06, S5P_GPIO_FUNC(0x3));
-		gpio_cfg_pin(GPIO_A07, S5P_GPIO_FUNC(0x3));
+		pingrp.dev_name = "i2c2-bus";
 		break;
 	case PERIPH_ID_I2C3:
-		gpio_cfg_pin(GPIO_A12, S5P_GPIO_FUNC(0x3));
-		gpio_cfg_pin(GPIO_A13, S5P_GPIO_FUNC(0x3));
+		pingrp.dev_name = "i2c3-bus";
 		break;
 	case PERIPH_ID_I2C4:
-		gpio_cfg_pin(GPIO_A20, S5P_GPIO_FUNC(0x3));
-		gpio_cfg_pin(GPIO_A21, S5P_GPIO_FUNC(0x3));
+		pingrp.dev_name = "i2c4-bus";
 		break;
 	case PERIPH_ID_I2C5:
-		gpio_cfg_pin(GPIO_A22, S5P_GPIO_FUNC(0x3));
-		gpio_cfg_pin(GPIO_A23, S5P_GPIO_FUNC(0x3));
+		pingrp.dev_name = "i2c5-bus";
 		break;
 	case PERIPH_ID_I2C6:
-		gpio_cfg_pin(GPIO_B13, S5P_GPIO_FUNC(0x4));
-		gpio_cfg_pin(GPIO_B14, S5P_GPIO_FUNC(0x4));
+		pingrp.dev_name = "i2c6-bus";
 		break;
 	case PERIPH_ID_I2C7:
-		gpio_cfg_pin(GPIO_B22, S5P_GPIO_FUNC(0x3));
-		gpio_cfg_pin(GPIO_B23, S5P_GPIO_FUNC(0x3));
+		pingrp.dev_name = "i2c7-bus";
 		break;
 	}
+
+	/*
+	 * Retrieve and apply pin config details
+	 * from fdt for this i2c bus.
+	 */
+	if (pinmux_get_fdt_values(&pingrp))
+		return -1;
+
+	pinmux_group_set(&pingrp);
+
+	return 0;
 }
 
-static void exynos5_i2s_config(int peripheral)
+static int exynos5_i2s_config(int peripheral)
 {
-	int i;
+	struct pin_group pingrp;
+
+	pingrp.dev_name = "i2s";
 
-	for (i = 0; i < 5; i++)
-		gpio_cfg_pin(GPIO_B00+i, S5P_GPIO_FUNC(0x02));
+	/*
+	 * Retrieve and apply pin config details
+	 * from fdt for i2s.
+	 */
+	if (pinmux_get_fdt_values(&pingrp))
+		return -1;
+
+	pinmux_group_set(&pingrp);
+
+	return 0;
 }
 
-void exynos5_spi_config(int peripheral)
+int exynos5_spi_config(int peripheral)
 {
-	int cfg = 0, pin = 0, i;
+	static struct pin_group pingrp;
 
 	switch (peripheral) {
 	case PERIPH_ID_SPI0:
-		cfg = S5P_GPIO_FUNC(0x2);
-		pin = GPIO_A20;
+		pingrp.dev_name = "spi0-bus";
 		break;
 	case PERIPH_ID_SPI1:
-		cfg = S5P_GPIO_FUNC(0x2);
-		pin = GPIO_A24;
+		pingrp.dev_name = "spi1-bus";
 		break;
 	case PERIPH_ID_SPI2:
-		cfg = S5P_GPIO_FUNC(0x5);
-		pin = GPIO_B11;
+		pingrp.dev_name = "spi2-bus";
 		break;
 	case PERIPH_ID_SPI3:
-		cfg = S5P_GPIO_FUNC(0x2);
-		pin = GPIO_F10;
+		pingrp.dev_name = "spi3-bus";
 		break;
 	case PERIPH_ID_SPI4:
-		for (i = 0; i < 2; i++) {
-			gpio_cfg_pin(GPIO_F02 + i, S5P_GPIO_FUNC(0x4));
-			gpio_cfg_pin(GPIO_E04 + i, S5P_GPIO_FUNC(0x4));
-		}
+		pingrp.dev_name = "spi4-bus";
 		break;
 	}
-	if (peripheral != PERIPH_ID_SPI4) {
-		for (i = pin; i < pin + 4; i++)
-			gpio_cfg_pin(i, cfg);
-	}
+
+	/*
+	 * Retrieve and apply pin config details
+	 * from fdt for this spi.
+	 */
+	if (pinmux_get_fdt_values(&pingrp))
+		return -1;
+
+	pinmux_group_set(&pingrp);
+
+	return 0;
 }
 
 static int exynos5_pinmux_config(int peripheral, int flags)
@@ -279,7 +473,7 @@ static int exynos5_pinmux_config(int peripheral, int flags)
 	case PERIPH_ID_UART1:
 	case PERIPH_ID_UART2:
 	case PERIPH_ID_UART3:
-		exynos5_uart_config(peripheral);
+		return exynos5_uart_config(peripheral);
 		break;
 	case PERIPH_ID_SDMMC0:
 	case PERIPH_ID_SDMMC1:
@@ -287,7 +481,7 @@ static int exynos5_pinmux_config(int peripheral, int flags)
 	case PERIPH_ID_SDMMC3:
 		return exynos5_mmc_config(peripheral, flags);
 	case PERIPH_ID_SROMC:
-		exynos5_sromc_config(flags);
+		return exynos5_sromc_config(flags);
 		break;
 	case PERIPH_ID_I2C0:
 	case PERIPH_ID_I2C1:
@@ -297,24 +491,22 @@ static int exynos5_pinmux_config(int peripheral, int flags)
 	case PERIPH_ID_I2C5:
 	case PERIPH_ID_I2C6:
 	case PERIPH_ID_I2C7:
-		exynos5_i2c_config(peripheral, flags);
+		return exynos5_i2c_config(peripheral, flags);
 		break;
 	case PERIPH_ID_I2S1:
-		exynos5_i2s_config(peripheral);
+		return exynos5_i2s_config(peripheral);
 		break;
 	case PERIPH_ID_SPI0:
 	case PERIPH_ID_SPI1:
 	case PERIPH_ID_SPI2:
 	case PERIPH_ID_SPI3:
 	case PERIPH_ID_SPI4:
-		exynos5_spi_config(peripheral);
+		return exynos5_spi_config(peripheral);
 		break;
 	default:
 		debug("%s: invalid peripheral %d", __func__, peripheral);
 		return -1;
 	}
-
-	return 0;
 }
 
 static void exynos4_i2c_config(int peripheral, int flags)
arch/arm/dts/exynos5250-pinctrl.dtsi new file +675 -0

675 lines not on this page · raw message

arch/arm/dts/exynos5250.dtsi +1 -0
index ed8c8dd..8fcf432 100644
@@ -18,6 +18,7 @@
 */
 
 /include/ "skeleton.dtsi"
+/include/ "exynos5250-pinctrl.dtsi"
 
 / {
 	compatible = "samsung,exynos5250";
doc/device-tree-bindings/samsung-pinctrl.txt new file +253 -0

253 lines not on this page · raw message

include/fdtdec.h +1 -0
index 77f244f..9c1bd82 100644
@@ -81,6 +81,7 @@ enum fdt_compat_id {
 	COMPAT_SAMSUNG_EXYNOS_EHCI,	/* Exynos EHCI controller */
 	COMPAT_SAMSUNG_EXYNOS_USB_PHY,	/* Exynos phy controller for usb2.0 */
 	COMPAT_MAXIM_MAX77686_PMIC,	/* MAX77686 PMIC */
+	COMPAT_SAMSUNG_PINCTRL,		/* PINCTRL */
 
 	COMPAT_COUNT,
 };
lib/fdtdec.c +1 -0
index 3ae348d..16dbdcd 100644
@@ -56,6 +56,7 @@ static const char * const compat_names[COMPAT_COUNT] = {
 	COMPAT(SAMSUNG_EXYNOS_EHCI, "samsung,exynos-ehci"),
 	COMPAT(SAMSUNG_EXYNOS_USB_PHY, "samsung,exynos-usb-phy"),
 	COMPAT(MAXIM_MAX77686_PMIC, "maxim,max77686_pmic"),
+	COMPAT(SAMSUNG_PINCTRL, "samsung,pinctrl"),
 };
 
 const char *fdtdec_get_compatible(enum fdt_compat_id id)
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v4 1/1 Exynos5: Pinmux: Add fdt for pinmux

Hi Akshay,

Quoted 51 lines · Akshay Saraswat

This patch adds fdt nodes for peripherals which require pin muxing and configuration. Device tree bindings for pinctrl are kept same as required for Linux. Existing pinmux code modified to retrieve gpio range and function related info from fdt.

Depends-on: [U-Boot] [PATCH 0/4 V3] EXYNOS5: Add GPIO numbering feature
URL: http://lists.denx.de/pipermail/u-boot/2013-February/146151.html

---
Changes since v3:
- Added comments to reduce ambiguity and increase readability.
- Fixed few other nits.

 arch/arm/cpu/armv7/exynos/pinmux.c           |  404 +++++++++++----
 arch/arm/dts/exynos5250-pinctrl.dtsi         |  675 ++++++++++++++++++++++++++
 arch/arm/dts/exynos5250.dtsi                 |    1 +
 doc/device-tree-bindings/samsung-pinctrl.txt |  253 ++++++++++
 include/fdtdec.h                             |    1 +
 lib/fdtdec.c                                 |    1 +
 6 files changed, 1229 insertions(+), 106 deletions(-)
 create mode 100644 arch/arm/dts/exynos5250-pinctrl.dtsi
 create mode 100644 doc/device-tree-bindings/samsung-pinctrl.txt
arch/arm/cpu/armv7/exynos/pinmux.c +15 -0
index a01ce0c..ba34560 100644
@@ -27,6 +27,21 @@
 #include <asm/arch/pinmux.h>
 #include <asm/arch/sromc.h>
 
+DECLARE_GLOBAL_DATA_PTR;
+
+/*
+ * Struct for temporarily storing pin numbers and
+ * pin function related info.
+ */
+struct pin_group {
+       void *dev_name;                 /* Name of the Peripheral device */
+       int npins;                      /* Number of pins to be configured */
+       int function;                   /* Pin function */
+       int pull_mode;                  /* Pin pull mode */
+       int drive_strength;             /* Pin drive strength */
+       enum exynos5_gpio_pin gpio[];   /* Pin numbers to be configured */
+};
+
 struct gpio_name_num_table exynos5_gpio_table[] = {
        { 'a', GPIO_A00 },
        { 'b', GPIO_B00 },

arch/arm/cpu/armv7/exynos/pinmux.c struct gpio_name_num_table exynos5_gpio_table[] = { · line 62

Quoted 7 lines
arch/arm/cpu/armv7/exynos/pinmux.c +3 -1
@@ -42,87 +57,224 @@ struct gpio_name_num_table exynos5_gpio_table[] = {
        { 'z', GPIO_Z0 },
 };
 
-static void exynos5_uart_config(int peripheral)
+/* Populate exynos5_gpio_pin array in a particular pin_group */
+static void pinmux_get_pin_numbers(const struct fdt_property *fprop,
+                                               struct pin_group *pingrp)

You only use fprop->data here, so you should pass that in instead of fprop.

Quoted 48 lines
arch/arm/cpu/armv7/exynos/pinmux.c +46 -1
+{
+       int i;
+       char gpio[5];
+
+       pingrp->npins = 0;
+
+       /*
+        * Get all the pin names from fdt and fill the gpio array
+        * with corresponding enum values(Pin numbers).
+        */
+       for (i = 0; !(fprop->data[i] == (int)NULL &&
+                               fprop->data[i-1] == (int)NULL); i += 7) {
+               int pin_num = -1;
+
+               /*
+                * Modify pin name retrieved from fdt,
+                * so that name_to_gpio may understand.
+                */
+               gpio[0] = fprop->data[i];
+               gpio[1] = fprop->data[i + 1];
+               gpio[2] = fprop->data[i + 2];
+               gpio[3] = fprop->data[i + 3];
+               gpio[4] = fprop->data[i + 5];
+
+               pin_num = name_to_gpio(gpio);
+
+               /*
+                * If pin number is valid, add it to the pin array
+                * and increment pin count.
+                */
+               if (pin_num >= 0) {
+                       pingrp->gpio[pingrp->npins] = pin_num;
+                       pingrp->npins++;
+               }
+       }
+}
+
+/* Extract all the config info for a node from fdt */
+static int pinmux_get_fdt_values(struct pin_group *pingrp)
 {
-       int i, start, count;
+       int node, subnode;
+       const struct fdt_property *fprop;
+
+       /* Loop for all pinctrl nodes in fdt */
+       for (node = fdtdec_next_compatible(gd->fdt_blob, 0,
+                       COMPAT_SAMSUNG_PINCTRL); node >= 0;
+                       node = fdtdec_next_compatible(gd->fdt_blob, node,

arch/arm/cpu/armv7/exynos/pinmux.c struct gpio_name_num_table exynos5_gpio_table[] = { · line 119

Quoted 10 lines
arch/arm/cpu/armv7/exynos/pinmux.c +10 -0
+                                               COMPAT_SAMSUNG_PINCTRL)) {
+               /* Get the subnode from FDT for this peripheral*/
+               subnode = fdt_subnode_offset(gd->fdt_blob,
+                                               node, pingrp->dev_name);
+               if (subnode < 0)
+                       continue;
+
+               /* Get names of pins to be configured from fdt */
+               fprop = fdt_get_property(gd->fdt_blob,
+                                       subnode, "samsung,pins", NULL);

Can you use fdt_getprop() here? Also you should check for a NULL return value.

Quoted 38 lines
arch/arm/cpu/armv7/exynos/pinmux.c +38 -0
+
+               /* Convert pin names to pin numbers */
+               pinmux_get_pin_numbers(fprop, pingrp);
+
+               /* Get the pin function from fdt */
+               pingrp->function = fdtdec_get_int(gd->fdt_blob,
+                                       subnode, "samsung,pin-function", 0);
+
+               /* Get the pull mode for pins from fdt */
+               pingrp->pull_mode = fdtdec_get_int(gd->fdt_blob,
+                                       subnode, "samsung,pin-pud", 0);
+
+               /* Get the drive strength for pins from fdt */
+               pingrp->drive_strength = fdtdec_get_int(gd->fdt_blob,
+                                       subnode, "samsung,pin-drv", 0);
+
+               return 0;
+       }
+
+       debug("PINCTRL: Subnode for %s is missing\n",
+                                       (const char *)pingrp->dev_name);
+
+       return -1;
+}
+
+/* Set configuration for all pins as per fdt node */
+static void pinmux_group_set(struct pin_group *pingrp)
+{
+       int i;
+
+       for (i = 0; i < pingrp->npins; i++) {
+               gpio_cfg_pin(pingrp->gpio[i], S5P_GPIO_FUNC(pingrp->function));
+               gpio_set_pull(pingrp->gpio[i], pingrp->pull_mode);
+               gpio_set_drv(pingrp->gpio[i], pingrp->drive_strength);
+       }
+}
+
+static int exynos5_uart_config(int peripheral)

arch/arm/cpu/armv7/exynos/pinmux.c struct gpio_name_num_table exynos5_gpio_table[] = { · line 165

Quoted 10 lines
arch/arm/cpu/armv7/exynos/pinmux.c +5 -2
+{
+       char *data, *fctl = NULL;
+       struct pin_group pingrp;
 
        switch (peripheral) {
        case PERIPH_ID_UART0:
-               start = GPIO_A00;
-               count = 4;
+               data = "uart0-data";
+               fctl = "uart0-fctl";

Is it not possible for these strings to come from the device' node eventually? Perhaps in a future patch?

Quoted 9 lines
arch/arm/cpu/armv7/exynos/pinmux.c +2 -3
                break;
        case PERIPH_ID_UART1:
-               start = GPIO_D00;
-               count = 4;
+               data = "uart1-data";
+               fctl = "uart1-fctl";
                break;
        case PERIPH_ID_UART2:
-               start = GPIO_A10;

arch/arm/cpu/armv7/exynos/pinmux.c struct gpio_name_num_table exynos5_gpio_table[] = { · line 178

Quoted 10 lines
arch/arm/cpu/armv7/exynos/pinmux.c +3 -3
-               count = 4;
+               data = "uart2-data";
+               fctl = "uart2-fctl";
                break;
        case PERIPH_ID_UART3:
-               start = GPIO_A14;
-               count = 2;
+               data = "uart3-data";
                break;
        }

Regards,
Simon