mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/1] Animeo IP: use gpiolib ip to detect the hw version
@ 2013-01-26  0:08 Jean-Christophe PLAGNIOL-VILLARD
  2013-01-27 11:19 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-01-26  0:08 UTC (permalink / raw)
  To: barebox

if err assume
SubCo
SDN

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 arch/arm/boards/animeo_ip/init.c |   50 +++++++++++++++++++++++++++++---------
 1 file changed, 39 insertions(+), 11 deletions(-)

diff --git a/arch/arm/boards/animeo_ip/init.c b/arch/arm/boards/animeo_ip/init.c
index e5e8694..9063567 100644
--- a/arch/arm/boards/animeo_ip/init.c
+++ b/arch/arm/boards/animeo_ip/init.c
@@ -29,28 +29,56 @@
 static bool animeo_ip_is_buco;
 static bool animeo_ip_is_io;
 
+static int animeo_ip_get_pio_revision(int gpio, char *name)
+{
+	int ret;
+
+	ret = gpio_request(gpio, name);
+	if (ret) {
+		pr_err("animeo_ip: can not request gpio %d as %s (%d)\n",
+			gpio, name, ret);
+		return ret;
+	}
+
+	ret = gpio_direction_input(gpio);
+
+	if (ret) {
+		pr_err("animeo_ip: can configure gpio %d (%s) as input (%d)\n",
+			gpio, name, ret);
+		return ret;
+	}
+
+	return gpio_get_value(gpio);
+}
+
 static void animeo_ip_detect_version(void)
 {
 	struct device_d *dev = NULL;
 	char *model, *version;
+	int val;
 
-	at91_set_gpio_input(AT91_PIN_PC20, 0);
-	at91_set_gpio_input(AT91_PIN_PC21, 0);
-
-	animeo_ip_is_buco = !!gpio_get_value(AT91_PIN_PC20);
-	animeo_ip_is_io = !!gpio_get_value(AT91_PIN_PC21);
+	animeo_ip_is_io = false;
+	animeo_ip_is_buco = false;
+	model = "SubCo";
+	version = "SDN";
 
 	dev = add_generic_device_res("animeo_ip", DEVICE_ID_SINGLE, NULL, 0, NULL);
 
-	if (animeo_ip_is_buco)
-		model = "BuCo";
-	else
+	val = animeo_ip_get_pio_revision(AT91_PIN_PC20, "is_buco");
+	if (val < 0) {
+		pr_warn("Can not detect model use %s by default\n", model);
+	} else if (val) {
+		animeo_ip_is_buco = true;
 		model = "SubCo";
+	}
 
-	if (animeo_ip_is_io)
+	val = animeo_ip_get_pio_revision(AT91_PIN_PC21, "is_io");
+	if (val < 0) {
+		pr_warn("Can not detect version use %s by default\n", model);
+	} else if (val) {
+		animeo_ip_is_io = true;
 		version = "IO";
-	else
-		version = "SDN";
+	}
 
 	dev_add_param_fixed(dev, "model", model);
 	dev_add_param_fixed(dev, "version", version);
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-01-27 11:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-26  0:08 [PATCH 1/1] Animeo IP: use gpiolib ip to detect the hw version Jean-Christophe PLAGNIOL-VILLARD
2013-01-27 11:19 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox