Skip to contentSkip to conversation

Add GPIO DT support to s3c24xx

PATCH In review Domenico Andreoli 1 participant 1 message Apr 21, 2011 1 message not in the archive

Subsystems (4)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 2/2 Add GPIO DT support to s3c24xx

From: Domenico Andreoli <[email protected]>

Assign proper OF node (= with matching physical base address) to each s3c24xx GPIO chip.

---
 arch/arm/plat-s3c24xx/gpiolib.c |   36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
arch/arm/plat-s3c24xx/gpiolib.c +36 -0
Index: b/arch/arm/plat-s3c24xx/gpiolib.c
===================================================================
@@ -19,6 +19,8 @@
 #include <linux/ioport.h>
 #include <linux/io.h>
 #include <linux/gpio.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
 
 #include <plat/gpio-core.h>
 #include <plat/gpio-cfg.h>
@@ -210,6 +212,39 @@
 	},
 };
 
+#ifdef CONFIG_OF_GPIO
+
+static void s3c24xx_attach_of_node(struct s3c_gpio_chip *chip)
+{
+	struct device_node *dn;
+	struct resource res;
+	const char *dt_compat;
+
+	if (chip->base == S3C2410_GPACON)
+		dt_compat = "samsung,s3c2410-gpio-a";
+	else
+		dt_compat = "samsung,s3c2410-gpio";
+
+	for_each_compatible_node(dn, NULL, dt_compat) {
+		if (of_address_to_resource(dn, 0, &res) < 0) {
+			printk(KERN_ERR "%s: unable to translate DT address\n", dn->full_name);
+			continue;
+		}
+
+		if (chip->base == (res.start - S3C24XX_PA_GPIO + S3C24XX_VA_GPIO)) {
+			chip->chip.of_node = dn;
+			break;
+		}
+	}
+}
+
+#else
+
+static void s3c24xx_attach_of_node(struct s3c_gpio_chip *chip)
+{
+}
+
+#endif
 
 static __init int s3c24xx_gpiolib_init(void)
 {
@@ -220,6 +255,7 @@
 		if (!chip->config)
 			chip->config = &s3c24xx_gpiocfg_default;
 
+		s3c24xx_attach_of_node(chip);
 		s3c_gpiolib_add(chip);
 	}