[U-Boot] [PATCH 2/3] LaCie/common: add support for the GPIO extension bus
Simon Guinot
simon.guinot at sequanux.org
Mon Jun 17 22:58:03 CEST 2013
This patch adds support for the GPIO extension bus found on some LaCie
boards (as the 2Big/5Big Network v2 and the 2Big NAS). This bus allows
to configure the devices (mostly the LEDs) connected to a CPLD via two
GPIO-based registers (address and data).
Signed-off-by: Simon Guinot <simon.guinot at sequanux.org>
---
board/LaCie/common/gpio-ext.c | 47 +++++++++++++++++++++++++++++++++++++++++
board/LaCie/common/gpio-ext.h | 24 +++++++++++++++++++++
2 files changed, 71 insertions(+)
create mode 100644 board/LaCie/common/gpio-ext.c
create mode 100644 board/LaCie/common/gpio-ext.h
diff --git a/board/LaCie/common/gpio-ext.c b/board/LaCie/common/gpio-ext.c
new file mode 100644
index 0000000..1e1b7ff
--- /dev/null
+++ b/board/LaCie/common/gpio-ext.c
@@ -0,0 +1,47 @@
+/*
+ * gpio-ext.c: provides support for the GPIO extension bus found on some
+ * LaCie boards (as the 2Big/5Big Network v2 and the 2Big NAS). This bus
+ * allows to configure the devices (mostly the LEDs) connected to a CPLD
+ * via two GPIO-based registers (address and data).
+ *
+ * Copyright (C) 2013 Simon Guinot <simon.guinot at sequanux.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ */
+
+#include <asm/arch/gpio.h>
+#include "gpio-ext.h"
+
+static void gpio_ext_set_addr(struct gpio_ext *gpio_ext, unsigned addr)
+{
+ int pin;
+
+ for (pin = 0; pin < gpio_ext->num_addr; pin++)
+ kw_gpio_set_value(gpio_ext->addr[pin], (addr >> pin) & 1);
+}
+
+static void gpio_ext_set_data(struct gpio_ext *gpio_ext, unsigned data)
+{
+ int pin;
+
+ for (pin = 0; pin < gpio_ext->num_data; pin++)
+ kw_gpio_set_value(gpio_ext->data[pin], (data >> pin) & 1);
+}
+
+static void gpio_ext_enable_select(struct gpio_ext *gpio_ext)
+{
+ /* The transfer is enabled on the raising edge. */
+ kw_gpio_set_value(gpio_ext->enable, 0);
+ kw_gpio_set_value(gpio_ext->enable, 1);
+}
+
+void gpio_ext_set_value(struct gpio_ext *gpio_ext,
+ unsigned addr, unsigned value)
+{
+ gpio_ext_set_addr(gpio_ext, addr);
+ gpio_ext_set_data(gpio_ext, value);
+ gpio_ext_enable_select(gpio_ext);
+}
diff --git a/board/LaCie/common/gpio-ext.h b/board/LaCie/common/gpio-ext.h
new file mode 100644
index 0000000..09fa271
--- /dev/null
+++ b/board/LaCie/common/gpio-ext.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2013 Simon Guinot <simon.guinot at sequanux.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ */
+
+#ifndef _LACIE_GPIO_EXT_H
+#define _LACIE_GPIO_EXT_H
+
+struct gpio_ext {
+ unsigned *addr;
+ unsigned num_addr;
+ unsigned *data;
+ unsigned num_data;
+ unsigned enable;
+};
+
+void gpio_ext_set_value(struct gpio_ext *gpio_ext,
+ unsigned addr, unsigned value);
+
+#endif /* _LACIE_GPIO_EXT_H */
--
1.7.10.4
More information about the U-Boot
mailing list