mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/5] BCM2835/Raspberry-Pi support
@ 2012-10-13 14:00 Carlo Caione
  2012-10-13 14:00 ` [PATCH 1/5] BCM2835: add clocksource driver Carlo Caione
                   ` (5 more replies)
  0 siblings, 6 replies; 15+ messages in thread
From: Carlo Caione @ 2012-10-13 14:00 UTC (permalink / raw)
  To: barebox

The set is the same as before except for patch 05/05

Carlo Caione (5):
  BCM2835: add clocksource driver
  BCM2835: add gpio driver
  ARM1176: add support
  BCM2835: add support (arch)
  Raspberry-Pi: add support (board)

 arch/arm/Kconfig                                   |   9 ++
 arch/arm/Makefile                                  |   2 +
 arch/arm/boards/raspberry-pi/Makefile              |   1 +
 arch/arm/boards/raspberry-pi/config.h              |   4 +
 .../arm/boards/raspberry-pi/env/init/bootargs-base |   8 +
 arch/arm/boards/raspberry-pi/env/init/hostname     |   8 +
 arch/arm/boards/raspberry-pi/rpi.c                 |  49 ++++++
 arch/arm/configs/rpi_defconfig                     |  40 +++++
 arch/arm/cpu/Kconfig                               |   5 +
 arch/arm/mach-bcm2835/Kconfig                      |  18 +++
 arch/arm/mach-bcm2835/Makefile                     |   2 +
 arch/arm/mach-bcm2835/clock.c                      |  39 +++++
 arch/arm/mach-bcm2835/core.c                       | 105 +++++++++++++
 arch/arm/mach-bcm2835/include/mach/clkdev.h        |   7 +
 arch/arm/mach-bcm2835/include/mach/clock.h         |   8 +
 arch/arm/mach-bcm2835/include/mach/core.h          |  27 ++++
 arch/arm/mach-bcm2835/include/mach/gpio.h          |   1 +
 arch/arm/mach-bcm2835/include/mach/platform.h      |  53 +++++++
 arch/arm/mach-bcm2835/include/mach/wd.h            |  50 +++++++
 drivers/clocksource/Kconfig                        |   4 +
 drivers/clocksource/Makefile                       |   1 +
 drivers/clocksource/bcm2835.c                      |  95 ++++++++++++
 drivers/gpio/Kconfig                               |   4 +
 drivers/gpio/Makefile                              |   1 +
 drivers/gpio/gpio-bcm2835.c                        | 165 +++++++++++++++++++++
 25 files changed, 706 insertions(+)
 create mode 100644 arch/arm/boards/raspberry-pi/Makefile
 create mode 100644 arch/arm/boards/raspberry-pi/config.h
 create mode 100644 arch/arm/boards/raspberry-pi/env/init/bootargs-base
 create mode 100644 arch/arm/boards/raspberry-pi/env/init/hostname
 create mode 100644 arch/arm/boards/raspberry-pi/rpi.c
 create mode 100644 arch/arm/configs/rpi_defconfig
 create mode 100644 arch/arm/mach-bcm2835/Kconfig
 create mode 100644 arch/arm/mach-bcm2835/Makefile
 create mode 100644 arch/arm/mach-bcm2835/clock.c
 create mode 100644 arch/arm/mach-bcm2835/core.c
 create mode 100644 arch/arm/mach-bcm2835/include/mach/clkdev.h
 create mode 100644 arch/arm/mach-bcm2835/include/mach/clock.h
 create mode 100644 arch/arm/mach-bcm2835/include/mach/core.h
 create mode 100644 arch/arm/mach-bcm2835/include/mach/gpio.h
 create mode 100644 arch/arm/mach-bcm2835/include/mach/platform.h
 create mode 100644 arch/arm/mach-bcm2835/include/mach/wd.h
 create mode 100644 drivers/clocksource/bcm2835.c
 create mode 100644 drivers/gpio/gpio-bcm2835.c

-- 
1.7.12.3


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

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

* [PATCH 1/5] BCM2835: add clocksource driver
  2012-10-13 14:00 [PATCH 0/5] BCM2835/Raspberry-Pi support Carlo Caione
@ 2012-10-13 14:00 ` Carlo Caione
  2012-10-13 14:00 ` [PATCH 2/5] BCM2835: add gpio driver Carlo Caione
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 15+ messages in thread
From: Carlo Caione @ 2012-10-13 14:00 UTC (permalink / raw)
  To: barebox

Signed-off-by: Carlo Caione <carlo.caione@gmail.com>
---
 drivers/clocksource/Kconfig   |  4 ++
 drivers/clocksource/Makefile  |  1 +
 drivers/clocksource/bcm2835.c | 95 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 100 insertions(+)
 create mode 100644 drivers/clocksource/bcm2835.c

diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
index 9d6d293..09acdd7 100644
--- a/drivers/clocksource/Kconfig
+++ b/drivers/clocksource/Kconfig
@@ -2,6 +2,10 @@ config ARM_SMP_TWD
 	bool
 	depends on ARM && CPU_V7
 
+config CLOCKSOURCE_BCM2835
+	bool
+	depends on ARCH_BCM2835
+
 config CLOCKSOURCE_NOMADIK
 	bool
 	depends on ARM
diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
index bef465c..92d7c13 100644
--- a/drivers/clocksource/Makefile
+++ b/drivers/clocksource/Makefile
@@ -1,2 +1,3 @@
 obj-$(CONFIG_ARM_SMP_TWD) += arm_smp_twd.o
+obj-$(CONFIG_CLOCKSOURCE_BCM2835) += bcm2835.o
 obj-$(CONFIG_CLOCKSOURCE_NOMADIK) += nomadik.o
diff --git a/drivers/clocksource/bcm2835.c b/drivers/clocksource/bcm2835.c
new file mode 100644
index 0000000..78f0cae
--- /dev/null
+++ b/drivers/clocksource/bcm2835.c
@@ -0,0 +1,95 @@
+/*
+ * Author: Carlo Caione <carlo@carlocaione.org>
+ *
+ * Based on clocksource for nomadik
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ */
+
+
+#include <common.h>
+#include <clock.h>
+#include <io.h>
+#include <init.h>
+#include <driver.h>
+#include <errno.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+
+/* Registers */
+#define ST_CLO	0x04
+
+static __iomem void *stc_base;
+
+static uint64_t stc_read_cycles(void)
+{
+	return readl(stc_base + ST_CLO);
+}
+
+static struct clocksource bcm2835_stc = {
+	.read = stc_read_cycles,
+	.mask = CLOCKSOURCE_MASK(32),
+};
+
+static int bcm2835_cs_probe(struct device_d *dev)
+{
+	static struct clk *stc_clk;
+	u32 rate;
+	int ret;
+
+	stc_clk = clk_get(dev, NULL);
+	if (IS_ERR(stc_clk)) {
+		ret = PTR_ERR(stc_clk);
+		dev_err(dev, "clock not found: %d\n", ret);
+		return ret;
+	}
+
+	ret = clk_enable(stc_clk);
+	if (ret) {
+		dev_err(dev, "clock failed to enable: %d\n", ret);
+		clk_put(stc_clk);
+		return ret;
+	}
+
+	rate = clk_get_rate(stc_clk);
+	stc_base = dev_request_mem_region(dev, 0);
+
+	clocks_calc_mult_shift(&bcm2835_stc.mult, &bcm2835_stc.shift, rate, NSEC_PER_SEC, 60);
+	init_clock(&bcm2835_stc);
+
+	return 0;
+}
+
+static __maybe_unused struct of_device_id bcm2835_cs_dt_ids[] = {
+	{
+			.compatible = "bcm,bcm2835-cs",
+	}, {
+			/* sentinel */
+	}
+};
+
+static struct driver_d bcm2835_cs_driver = {
+	.name = "bcm2835-cs",
+	.probe = bcm2835_cs_probe,
+	.of_compatible = DRV_OF_COMPAT(bcm2835_cs_dt_ids),
+};
+
+static int bcm2835_cs_init(void)
+{
+	return platform_driver_register(&bcm2835_cs_driver);
+}
+coredevice_initcall(bcm2835_cs_init);
-- 
1.7.12.3


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

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

* [PATCH 2/5] BCM2835: add gpio driver
  2012-10-13 14:00 [PATCH 0/5] BCM2835/Raspberry-Pi support Carlo Caione
  2012-10-13 14:00 ` [PATCH 1/5] BCM2835: add clocksource driver Carlo Caione
@ 2012-10-13 14:00 ` Carlo Caione
  2012-10-13 14:00 ` [PATCH 3/5] ARM1176: add support Carlo Caione
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 15+ messages in thread
From: Carlo Caione @ 2012-10-13 14:00 UTC (permalink / raw)
  To: barebox

Signed-off-by: Carlo Caione <carlo.caione@gmail.com>
---
 drivers/gpio/Kconfig        |   4 ++
 drivers/gpio/Makefile       |   1 +
 drivers/gpio/gpio-bcm2835.c | 165 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 170 insertions(+)
 create mode 100644 drivers/gpio/gpio-bcm2835.c

diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index a0e9b58..e8eeb6d 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -6,6 +6,10 @@ if GPIOLIB
 
 menu "GPIO                          "
 
+config GPIO_BCM2835
+	bool "GPIO support for BCM2835"
+	depends on ARCH_BCM2835
+
 config GPIO_PL061
 	bool "PrimeCell PL061 GPIO support"
 	depends on ARM_AMBA
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index e2e97d3..aecdf24 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -1,4 +1,5 @@
 obj-$(CONFIG_GPIOLIB) += gpio.o
 
+obj-$(CONFIG_GPIO_BCM2835)	+= gpio-bcm2835.o
 obj-$(CONFIG_GPIO_PL061)	+= gpio-pl061.o
 obj-$(CONFIG_GPIO_STMPE) += gpio-stmpe.o
diff --git a/drivers/gpio/gpio-bcm2835.c b/drivers/gpio/gpio-bcm2835.c
new file mode 100644
index 0000000..2a9bc59
--- /dev/null
+++ b/drivers/gpio/gpio-bcm2835.c
@@ -0,0 +1,165 @@
+/*
+ * Author: Carlo Caione <carlo@carlocaione.org>
+ *
+ * Based on linux/arch/arm/mach-bcm2708/bcm2708_gpio.c
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ */
+
+#include <common.h>
+#include <errno.h>
+#include <malloc.h>
+#include <io.h>
+#include <gpio.h>
+#include <init.h>
+#include <mach/platform.h>
+
+#define GPIOFSEL(x)  (0x00+(x)*4)
+#define GPIOSET(x)   (0x1c+(x)*4)
+#define GPIOCLR(x)   (0x28+(x)*4)
+#define GPIOLEV(x)   (0x34+(x)*4)
+#define GPIOEDS(x)   (0x40+(x)*4)
+#define GPIOREN(x)   (0x4c+(x)*4)
+#define GPIOFEN(x)   (0x58+(x)*4)
+#define GPIOHEN(x)   (0x64+(x)*4)
+#define GPIOLEN(x)   (0x70+(x)*4)
+#define GPIOAREN(x)  (0x7c+(x)*4)
+#define GPIOAFEN(x)  (0x88+(x)*4)
+#define GPIOUD(x)    (0x94+(x)*4)
+#define GPIOUDCLK(x) (0x98+(x)*4)
+
+enum {
+	GPIO_FSEL_INPUT, GPIO_FSEL_OUTPUT,
+	GPIO_FSEL_ALT5, GPIO_FSEL_ALT_4,
+	GPIO_FSEL_ALT0, GPIO_FSEL_ALT1,
+	GPIO_FSEL_ALT2, GPIO_FSEL_ALT3,
+};
+
+struct bcm2835_gpio_chip {
+	void __iomem *base;
+	struct gpio_chip chip;
+};
+
+static int bcm2835_set_function(struct gpio_chip *chip, unsigned gpio, int function)
+{
+	struct bcm2835_gpio_chip *bcmgpio = container_of(chip, struct bcm2835_gpio_chip, chip);
+	void __iomem *base = bcmgpio->base;
+	unsigned gpiodir;
+	unsigned gpio_bank = gpio / 10;
+	unsigned gpio_field_offset = (gpio - 10 * gpio_bank) * 3;
+
+	gpiodir = readl(base + GPIOFSEL(gpio_bank));
+	gpiodir &= ~(7 << gpio_field_offset);
+	gpiodir |= function << gpio_field_offset;
+	writel(gpiodir, base + GPIOFSEL(gpio_bank));
+	gpiodir = readl(base + GPIOFSEL(gpio_bank));
+
+	return 0;
+}
+
+static void bcm2835_gpio_set_value(struct gpio_chip *chip, unsigned gpio, int value)
+{
+	struct bcm2835_gpio_chip *bcmgpio = container_of(chip, struct bcm2835_gpio_chip, chip);
+	void __iomem *base = bcmgpio->base;
+	unsigned gpio_bank = gpio / 32;
+	unsigned gpio_field_offset = gpio % 32;
+
+	if (value)
+		writel(1 << gpio_field_offset, base + GPIOSET(gpio_bank));
+	else
+		writel(1 << gpio_field_offset, base + GPIOCLR(gpio_bank));
+}
+
+static int bcm2835_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
+{
+	struct bcm2835_gpio_chip *bcmgpio = container_of(chip, struct bcm2835_gpio_chip, chip);
+	void __iomem *base = bcmgpio->base;
+	unsigned gpio_bank = gpio / 32;
+	unsigned gpio_field_offset = gpio % 32;
+	unsigned lev;
+
+	lev = readl(base + GPIOLEV(gpio_bank));
+	return 0x1 & (lev >> gpio_field_offset);
+}
+
+static int bcm2835_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
+{
+	return bcm2835_set_function(chip, gpio, GPIO_FSEL_INPUT);
+}
+
+static int bcm2835_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, int value)
+{
+	bcm2835_set_function(chip, gpio, GPIO_FSEL_OUTPUT);
+	bcm2835_gpio_set_value(chip, gpio, value);
+
+	return 0;
+}
+
+static struct gpio_ops bcm2835_gpio_ops = {
+	.direction_input = bcm2835_gpio_direction_input,
+	.direction_output = bcm2835_gpio_direction_output,
+	.get = bcm2835_gpio_get_value,
+	.set = bcm2835_gpio_set_value,
+};
+
+static int bcm2835_gpio_probe(struct device_d *dev)
+{
+	struct bcm2835_gpio_chip *bcmgpio;
+	int ret;
+
+	bcmgpio = xzalloc(sizeof(*bcmgpio));
+	bcmgpio->base = dev_request_mem_region(dev, 0);
+	bcmgpio->chip.ops = &bcm2835_gpio_ops;
+	bcmgpio->chip.base = -1;
+	bcmgpio->chip.ngpio = 54;
+	bcmgpio->chip.dev = dev;
+
+	ret = gpiochip_add(&bcmgpio->chip);
+	if (ret) {
+		dev_err(dev, "couldn't add gpiochip, ret = %d\n", ret);
+		goto err;
+	}
+	dev_info(dev, "probed gpiochip%d with base %d\n", dev->id, bcmgpio->chip.base);
+
+	return 0;
+
+err:
+	kfree(bcmgpio);
+
+	return ret;
+}
+
+static __maybe_unused struct of_device_id bcm2835_gpio_dt_ids[] = {
+	{
+			.compatible = "bcm,bcm2835-gpio",
+	}, {
+			/* sentinel */
+	}
+};
+
+static struct driver_d bcm2835_gpio_driver = {
+	.name = "bcm2835-gpio",
+	.probe = bcm2835_gpio_probe,
+	.of_compatible = DRV_OF_COMPAT(bcm2835_gpio_dt_ids),
+};
+
+static int bcm2835_gpio_add(void)
+{
+	platform_driver_register(&bcm2835_gpio_driver);
+	return 0;
+}
+coredevice_initcall(bcm2835_gpio_add);
-- 
1.7.12.3


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

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

* [PATCH 3/5] ARM1176: add support
  2012-10-13 14:00 [PATCH 0/5] BCM2835/Raspberry-Pi support Carlo Caione
  2012-10-13 14:00 ` [PATCH 1/5] BCM2835: add clocksource driver Carlo Caione
  2012-10-13 14:00 ` [PATCH 2/5] BCM2835: add gpio driver Carlo Caione
@ 2012-10-13 14:00 ` Carlo Caione
  2012-10-13 14:00 ` [PATCH 4/5] BCM2835: add support (arch) Carlo Caione
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 15+ messages in thread
From: Carlo Caione @ 2012-10-13 14:00 UTC (permalink / raw)
  To: barebox

Signed-off-by: Carlo Caione <carlo.caione@gmail.com>
---
 arch/arm/cpu/Kconfig | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/arm/cpu/Kconfig b/arch/arm/cpu/Kconfig
index 2ed6789..d8a5fb1 100644
--- a/arch/arm/cpu/Kconfig
+++ b/arch/arm/cpu/Kconfig
@@ -8,6 +8,11 @@ config CPU_32
 # which CPUs we support in the kernel image, and the compiler instruction
 # optimiser behaviour.
 
+# ARM1176
+config CPU_ARM1176
+	bool
+	select CPU_V6
+
 # ARM920T
 config CPU_ARM920T
 	bool
-- 
1.7.12.3


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

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

* [PATCH 4/5] BCM2835: add support (arch)
  2012-10-13 14:00 [PATCH 0/5] BCM2835/Raspberry-Pi support Carlo Caione
                   ` (2 preceding siblings ...)
  2012-10-13 14:00 ` [PATCH 3/5] ARM1176: add support Carlo Caione
@ 2012-10-13 14:00 ` Carlo Caione
  2012-10-13 14:00 ` [PATCH 5/5] Raspberry-Pi: add support (board) Carlo Caione
  2012-10-15  6:56 ` [PATCH 0/5] BCM2835/Raspberry-Pi support Sascha Hauer
  5 siblings, 0 replies; 15+ messages in thread
From: Carlo Caione @ 2012-10-13 14:00 UTC (permalink / raw)
  To: barebox

Signed-off-by: Carlo Caione <carlo.caione@gmail.com>
---
 arch/arm/Kconfig                              |   9 +++
 arch/arm/Makefile                             |   1 +
 arch/arm/mach-bcm2835/Kconfig                 |   3 +
 arch/arm/mach-bcm2835/Makefile                |   2 +
 arch/arm/mach-bcm2835/clock.c                 |  39 ++++++++++
 arch/arm/mach-bcm2835/core.c                  | 105 ++++++++++++++++++++++++++
 arch/arm/mach-bcm2835/include/mach/clkdev.h   |   7 ++
 arch/arm/mach-bcm2835/include/mach/clock.h    |   8 ++
 arch/arm/mach-bcm2835/include/mach/core.h     |  27 +++++++
 arch/arm/mach-bcm2835/include/mach/gpio.h     |   1 +
 arch/arm/mach-bcm2835/include/mach/platform.h |  53 +++++++++++++
 arch/arm/mach-bcm2835/include/mach/wd.h       |  50 ++++++++++++
 12 files changed, 305 insertions(+)
 create mode 100644 arch/arm/mach-bcm2835/Kconfig
 create mode 100644 arch/arm/mach-bcm2835/Makefile
 create mode 100644 arch/arm/mach-bcm2835/clock.c
 create mode 100644 arch/arm/mach-bcm2835/core.c
 create mode 100644 arch/arm/mach-bcm2835/include/mach/clkdev.h
 create mode 100644 arch/arm/mach-bcm2835/include/mach/clock.h
 create mode 100644 arch/arm/mach-bcm2835/include/mach/core.h
 create mode 100644 arch/arm/mach-bcm2835/include/mach/gpio.h
 create mode 100644 arch/arm/mach-bcm2835/include/mach/platform.h
 create mode 100644 arch/arm/mach-bcm2835/include/mach/wd.h

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index ffeb4bf..de78b65 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -31,6 +31,14 @@ config ARCH_AT91
 	select HAS_DEBUG_LL
 	select HAVE_MACH_ARM_HEAD
 
+config ARCH_BCM2835
+	bool "Broadcom BCM2835 boards"
+	select GPIOLIB
+	select CPU_ARM1176
+	select CLKDEV_LOOKUP
+	select CLOCKSOURCE_BCM2835
+	select ARM_AMBA
+
 config ARCH_EP93XX
 	bool "Cirrus Logic EP93xx"
 	select CPU_ARM920T
@@ -102,6 +110,7 @@ endchoice
 
 source arch/arm/cpu/Kconfig
 source arch/arm/mach-at91/Kconfig
+source arch/arm/mach-bcm2835/Kconfig
 source arch/arm/mach-ep93xx/Kconfig
 source arch/arm/mach-imx/Kconfig
 source arch/arm/mach-mxs/Kconfig
diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index de570d7..3449fd7 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -52,6 +52,7 @@ AFLAGS   += -include asm/unified.h -msoft-float $(AFLAGS_THUMB2)
 # Machine directory name.  This list is sorted alphanumerically
 # by CONFIG_* macro name.
 machine-$(CONFIG_ARCH_AT91)		:= at91
+machine-$(CONFIG_ARCH_BCM2835)		:= bcm2835
 machine-$(CONFIG_ARCH_EP93XX)		:= ep93xx
 machine-$(CONFIG_ARCH_IMX)		:= imx
 machine-$(CONFIG_ARCH_MXS)		:= mxs
diff --git a/arch/arm/mach-bcm2835/Kconfig b/arch/arm/mach-bcm2835/Kconfig
new file mode 100644
index 0000000..c42fe1c
--- /dev/null
+++ b/arch/arm/mach-bcm2835/Kconfig
@@ -0,0 +1,3 @@
+if ARCH_BCM2835
+
+endif
diff --git a/arch/arm/mach-bcm2835/Makefile b/arch/arm/mach-bcm2835/Makefile
new file mode 100644
index 0000000..f0aa2e0
--- /dev/null
+++ b/arch/arm/mach-bcm2835/Makefile
@@ -0,0 +1,2 @@
+obj-y += core.o
+obj-y += clock.o
\ No newline at end of file
diff --git a/arch/arm/mach-bcm2835/clock.c b/arch/arm/mach-bcm2835/clock.c
new file mode 100644
index 0000000..31400ea
--- /dev/null
+++ b/arch/arm/mach-bcm2835/clock.c
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2009 Alessandro Rubini
+ */
+
+#include <common.h>
+#include <init.h>
+#include <linux/clkdev.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <mach/clock.h>
+
+int clk_enable(struct clk *clk)
+{
+	return 0;
+}
+EXPORT_SYMBOL(clk_enable);
+
+void clk_disable(struct clk *clk)
+{
+}
+EXPORT_SYMBOL(clk_disable);
+
+unsigned long clk_get_rate(struct clk *clk)
+{
+	return clk->rate;
+}
+EXPORT_SYMBOL(clk_get_rate);
+
+long clk_round_rate(struct clk *clk, unsigned long rate)
+{
+	return clk->rate;
+}
+EXPORT_SYMBOL(clk_round_rate);
+
+int clk_set_rate(struct clk *clk, unsigned long rate)
+{
+	return -EIO;
+}
+EXPORT_SYMBOL(clk_set_rate);
diff --git a/arch/arm/mach-bcm2835/core.c b/arch/arm/mach-bcm2835/core.c
new file mode 100644
index 0000000..4c1bf28
--- /dev/null
+++ b/arch/arm/mach-bcm2835/core.c
@@ -0,0 +1,105 @@
+/*
+ * Author: Carlo Caione <carlo@carlocaione.org>
+ *
+ * Based on mach-nomadik
+ * Copyright (C) 2009 Jean-Christophe PLAGNIOL-VILLARD <plagnio@jcrosoft.com>
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ */
+
+#include <common.h>
+#include <init.h>
+#include <clock.h>
+
+#include <linux/clkdev.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+
+#include <io.h>
+#include <asm/hardware/arm_timer.h>
+#include <asm/armlinux.h>
+#include <sizes.h>
+
+#include <mach/platform.h>
+#include <mach/wd.h>
+#include <mach/core.h>
+#include <mach/clock.h>
+#include <linux/amba/bus.h>
+
+static struct clk ref_3_clk = {
+	.rate = 3 * 1000 * 1000,
+};
+
+static struct clk ref_1_clk = {
+	.rate = 1 * 1000 * 1000,
+};
+
+static struct clk bcm2835_dummy;
+
+void bcm2835_add_device_sdram(u32 size)
+{
+	if (!size)
+		size = get_ram_size((ulong *) BCM2835_SDRAM_BASE, SZ_128M);
+
+	arm_add_mem_device("ram0", BCM2835_SDRAM_BASE, size);
+}
+
+static struct clk_lookup clocks_lookups[] = {
+	CLKDEV_CON_ID("apb_pclk", &bcm2835_dummy),
+	CLKDEV_DEV_ID("bcm2835-cs", &ref_1_clk),
+	CLKDEV_DEV_ID("uart0-pl0110", &ref_3_clk),
+};
+
+static int bcm2835_gpio_init(void)
+{
+	add_generic_device("bcm2835-gpio", 0, NULL, BCM2835_GPIO_BASE, 0xB0, IORESOURCE_MEM, NULL);
+	return 0;
+}
+coredevice_initcall(bcm2835_gpio_init);
+
+static int bcm2835_clkdev_init(void)
+{
+	clkdev_add_table(clocks_lookups, ARRAY_SIZE(clocks_lookups));
+	return 0;
+}
+postcore_initcall(bcm2835_clkdev_init);
+
+static int bcm2835_clocksource_init(void)
+{
+	add_generic_device("bcm2835-cs", DEVICE_ID_SINGLE, NULL, BCM2835_ST_BASE, 0x1C, IORESOURCE_MEM, NULL);
+	return 0;
+}
+coredevice_initcall(bcm2835_clocksource_init);
+
+void bcm2835_register_uart(void)
+{
+	amba_apb_device_add(NULL, "uart0-pl011", 0, BCM2835_UART0_BASE, 4096, NULL, 0);
+}
+
+#define RESET_TIMEOUT 10
+
+void __noreturn reset_cpu (unsigned long addr)
+{
+	uint32_t rstc;
+
+	rstc = readl(PM_RSTC);
+	rstc &= ~PM_RSTC_WRCFG_SET;
+	rstc |= PM_RSTC_WRCFG_FULL_RESET;
+	writel(PM_PASSWORD | RESET_TIMEOUT, PM_WDOG);
+	writel(PM_PASSWORD | rstc, PM_RSTC);
+}
+EXPORT_SYMBOL(reset_cpu);
diff --git a/arch/arm/mach-bcm2835/include/mach/clkdev.h b/arch/arm/mach-bcm2835/include/mach/clkdev.h
new file mode 100644
index 0000000..04b37a8
--- /dev/null
+++ b/arch/arm/mach-bcm2835/include/mach/clkdev.h
@@ -0,0 +1,7 @@
+#ifndef __ASM_MACH_CLKDEV_H
+#define __ASM_MACH_CLKDEV_H
+
+#define __clk_get(clk) ({ 1; })
+#define __clk_put(clk) do { } while (0)
+
+#endif
diff --git a/arch/arm/mach-bcm2835/include/mach/clock.h b/arch/arm/mach-bcm2835/include/mach/clock.h
new file mode 100644
index 0000000..0550bf1
--- /dev/null
+++ b/arch/arm/mach-bcm2835/include/mach/clock.h
@@ -0,0 +1,8 @@
+#ifndef _BCM2835_CLOCK_H
+#define _BCM2835_CLOCK_H
+
+struct clk {
+	unsigned long rate;
+};
+
+#endif
diff --git a/arch/arm/mach-bcm2835/include/mach/core.h b/arch/arm/mach-bcm2835/include/mach/core.h
new file mode 100644
index 0000000..e60d947
--- /dev/null
+++ b/arch/arm/mach-bcm2835/include/mach/core.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2009 Carlo Caione <carlo@carlocaione.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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ */
+
+#ifndef __BCM2835_CORE_H__
+#define __BCM2835_CORE_H__
+
+void bcm2835_register_uart(void);
+void bcm2835_add_device_sdram(u32 size);
+
+#endif
diff --git a/arch/arm/mach-bcm2835/include/mach/gpio.h b/arch/arm/mach-bcm2835/include/mach/gpio.h
new file mode 100644
index 0000000..306ab4c
--- /dev/null
+++ b/arch/arm/mach-bcm2835/include/mach/gpio.h
@@ -0,0 +1 @@
+#include <asm-generic/gpio.h>
diff --git a/arch/arm/mach-bcm2835/include/mach/platform.h b/arch/arm/mach-bcm2835/include/mach/platform.h
new file mode 100644
index 0000000..a058ec5
--- /dev/null
+++ b/arch/arm/mach-bcm2835/include/mach/platform.h
@@ -0,0 +1,53 @@
+/*
+ * Extract from arch/arm/mach-bcm2708/include/mach/platform.h
+ *
+ * Copyright (C) 2010 Broadcom
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef _BCM2835_PLATFORM_H
+#define _BCM2835_PLATFORM_H
+
+/*
+ *  SDRAM
+ */
+#define BCM2835_SDRAM_BASE	0x00000000
+
+/*
+ * Definitions and addresses for the ARM CONTROL logic
+ * This file is manually generated.
+ */
+
+#define BCM2835_PERI_BASE	0x20000000
+#define BCM2835_ST_BASE		(BCM2835_PERI_BASE + 0x3000)	/* System Timer */
+#define BCM2835_DMA_BASE	(BCM2835_PERI_BASE + 0x7000)	/* DMA controller */
+#define BCM2835_ARM_BASE	(BCM2835_PERI_BASE + 0xB000)	/* BCM2708 ARM control block */
+#define BCM2835_PM_BASE		(BCM2835_PERI_BASE + 0x100000)	/* Power Management, Reset controller and Watchdog registers */
+#define BCM2835_GPIO_BASE	(BCM2835_PERI_BASE + 0x200000)	/* GPIO */
+#define BCM2835_UART0_BASE	(BCM2835_PERI_BASE + 0x201000)	/* Uart 0 */
+#define BCM2835_MMCI0_BASE	(BCM2835_PERI_BASE + 0x202000)	/* MMC interface */
+#define BCM2835_SPI0_BASE	(BCM2835_PERI_BASE + 0x204000)	/* SPI0 */
+#define BCM2835_BSC0_BASE	(BCM2835_PERI_BASE + 0x205000)	/* BSC0 I2C/TWI */
+#define BCM2835_UART1_BASE	(BCM2835_PERI_BASE + 0x215000)	/* Uart 1 */
+#define BCM2835_EMMC_BASE	(BCM2835_PERI_BASE + 0x300000)	/* eMMC interface */
+#define BCM2835_SMI_BASE	(BCM2835_PERI_BASE + 0x600000)	/* SMI */
+#define BCM2835_BSC1_BASE	(BCM2835_PERI_BASE + 0x804000)	/* BSC1 I2C/TWI */
+#define BCM2835_USB_BASE	(BCM2835_PERI_BASE + 0x980000)	/* DTC_OTG USB controller */
+#define BCM2835_MCORE_BASE	(BCM2835_PERI_BASE + 0x0000)	/* Fake frame buffer device (actually the multicore sync block*/
+
+#endif
+
+/* END */
diff --git a/arch/arm/mach-bcm2835/include/mach/wd.h b/arch/arm/mach-bcm2835/include/mach/wd.h
new file mode 100644
index 0000000..8046734
--- /dev/null
+++ b/arch/arm/mach-bcm2835/include/mach/wd.h
@@ -0,0 +1,50 @@
+/*
+ * Extract from arch/arm/mach-bcm2708/include/mach/platform.h
+ *
+ * Copyright (C) 2010 Broadcom
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef _WD_H
+#define _WD_H
+
+/*
+ * Watchdog
+ */
+#define PM_RSTC		(BCM2835_PM_BASE+0x1c)
+#define PM_RSTS		(BCM2835_PM_BASE+0x20)
+#define PM_WDOG		(BCM2835_PM_BASE+0x24)
+
+#define PM_WDOG_RESET				0000000000
+#define PM_PASSWORD				0x5a000000
+#define PM_WDOG_TIME_SET			0x000fffff
+#define PM_RSTC_WRCFG_CLR			0xffffffcf
+#define PM_RSTC_WRCFG_SET			0x00000030
+#define PM_RSTC_WRCFG_FULL_RESET		0x00000020
+#define PM_RSTC_RESET				0x00000102
+
+#define PM_RSTS_HADPOR_SET			0x00001000
+#define PM_RSTS_HADSRH_SET			0x00000400
+#define PM_RSTS_HADSRF_SET			0x00000200
+#define PM_RSTS_HADSRQ_SET			0x00000100
+#define PM_RSTS_HADWRH_SET			0x00000040
+#define PM_RSTS_HADWRF_SET			0x00000020
+#define PM_RSTS_HADWRQ_SET			0x00000010
+#define PM_RSTS_HADDRH_SET			0x00000004
+#define PM_RSTS_HADDRF_SET			0x00000002
+#define PM_RSTS_HADDRQ_SET			0x00000001
+
+#endif
-- 
1.7.12.3


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

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

* [PATCH 5/5] Raspberry-Pi: add support (board)
  2012-10-13 14:00 [PATCH 0/5] BCM2835/Raspberry-Pi support Carlo Caione
                   ` (3 preceding siblings ...)
  2012-10-13 14:00 ` [PATCH 4/5] BCM2835: add support (arch) Carlo Caione
@ 2012-10-13 14:00 ` Carlo Caione
  2012-10-15  6:56 ` [PATCH 0/5] BCM2835/Raspberry-Pi support Sascha Hauer
  5 siblings, 0 replies; 15+ messages in thread
From: Carlo Caione @ 2012-10-13 14:00 UTC (permalink / raw)
  To: barebox

Tested-By: Jan Luebbe <jlu@pengutronix.de>
Signed-off-by: Carlo Caione <carlo.caione@gmail.com>
---
 arch/arm/Makefile                                  |  1 +
 arch/arm/boards/raspberry-pi/Makefile              |  1 +
 arch/arm/boards/raspberry-pi/config.h              |  4 ++
 .../arm/boards/raspberry-pi/env/init/bootargs-base |  8 ++++
 arch/arm/boards/raspberry-pi/env/init/hostname     |  8 ++++
 arch/arm/boards/raspberry-pi/rpi.c                 | 49 ++++++++++++++++++++++
 arch/arm/configs/rpi_defconfig                     | 40 ++++++++++++++++++
 arch/arm/mach-bcm2835/Kconfig                      | 15 +++++++
 8 files changed, 126 insertions(+)
 create mode 100644 arch/arm/boards/raspberry-pi/Makefile
 create mode 100644 arch/arm/boards/raspberry-pi/config.h
 create mode 100644 arch/arm/boards/raspberry-pi/env/init/bootargs-base
 create mode 100644 arch/arm/boards/raspberry-pi/env/init/hostname
 create mode 100644 arch/arm/boards/raspberry-pi/rpi.c
 create mode 100644 arch/arm/configs/rpi_defconfig

diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index 3449fd7..ec9898c 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -114,6 +114,7 @@ board-$(CONFIG_MACH_PCM043)			:= pcm043
 board-$(CONFIG_MACH_PM9261)			:= pm9261
 board-$(CONFIG_MACH_PM9263)			:= pm9263
 board-$(CONFIG_MACH_PM9G45)			:= pm9g45
+board-$(CONFIG_MACH_RPI)			:= raspberry-pi
 board-$(CONFIG_MACH_SCB9328)			:= scb9328
 board-$(CONFIG_MACH_NESO)			:= guf-neso
 board-$(CONFIG_MACH_MX23EVK)			:= freescale-mx23-evk
diff --git a/arch/arm/boards/raspberry-pi/Makefile b/arch/arm/boards/raspberry-pi/Makefile
new file mode 100644
index 0000000..6ce5ede
--- /dev/null
+++ b/arch/arm/boards/raspberry-pi/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_MACH_RPI) += rpi.o
diff --git a/arch/arm/boards/raspberry-pi/config.h b/arch/arm/boards/raspberry-pi/config.h
new file mode 100644
index 0000000..ca15136
--- /dev/null
+++ b/arch/arm/boards/raspberry-pi/config.h
@@ -0,0 +1,4 @@
+#ifndef __CONFIG_H
+#define __CONFIG_H
+
+#endif	/* __CONFIG_H */
diff --git a/arch/arm/boards/raspberry-pi/env/init/bootargs-base b/arch/arm/boards/raspberry-pi/env/init/bootargs-base
new file mode 100644
index 0000000..d869754
--- /dev/null
+++ b/arch/arm/boards/raspberry-pi/env/init/bootargs-base
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+if [ "$1" = menu ]; then
+	init-menu-add-entry "$0" "Base bootargs"
+	exit
+fi
+
+global.linux.bootargs.base="console=ttymxc0,115200"
diff --git a/arch/arm/boards/raspberry-pi/env/init/hostname b/arch/arm/boards/raspberry-pi/env/init/hostname
new file mode 100644
index 0000000..7e8f294
--- /dev/null
+++ b/arch/arm/boards/raspberry-pi/env/init/hostname
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+if [ "$1" = menu ]; then
+	init-menu-add-entry "$0" "hostname"
+	exit
+fi
+
+global.hostname=Raspberry-Pi
diff --git a/arch/arm/boards/raspberry-pi/rpi.c b/arch/arm/boards/raspberry-pi/rpi.c
new file mode 100644
index 0000000..6c94dcd
--- /dev/null
+++ b/arch/arm/boards/raspberry-pi/rpi.c
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2009 Carlo Caione <carlo@carlocaione.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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ */
+
+#include <common.h>
+#include <init.h>
+#include <asm/armlinux.h>
+#include <generated/mach-types.h>
+
+#include <mach/core.h>
+
+static int rpi_mem_init(void)
+{
+	bcm2835_add_device_sdram(0);
+	return 0;
+}
+mem_initcall(rpi_mem_init);
+
+static int rpi_console_init(void)
+{
+	bcm2835_register_uart();
+	return 0;
+}
+console_initcall(rpi_console_init);
+
+static int rpi_devices_init(void)
+{
+	armlinux_set_architecture(MACH_TYPE_BCM2708);
+	armlinux_set_bootparams((void *)(0x00000100));
+	return 0;
+}
+
+device_initcall(rpi_devices_init);
diff --git a/arch/arm/configs/rpi_defconfig b/arch/arm/configs/rpi_defconfig
new file mode 100644
index 0000000..bca3d25
--- /dev/null
+++ b/arch/arm/configs/rpi_defconfig
@@ -0,0 +1,40 @@
+CONFIG_ARCH_BCM2835=y
+CONFIG_GPIO_BCM2835=y
+CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
+CONFIG_PROMPT="R-Pi> "
+CONFIG_LONGHELP=y
+CONFIG_GLOB=y
+CONFIG_HUSH_FANCY_PROMPT=y
+CONFIG_CMDLINE_EDITING=y
+CONFIG_AUTO_COMPLETE=y
+CONFIG_MENU=y
+CONFIG_PARTITION=y
+CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW=y
+CONFIG_DEFAULT_ENVIRONMENT_PATH="arch/arm/boards/raspberry-pi/env"
+CONFIG_CMD_EDIT=y
+CONFIG_CMD_SLEEP=y
+CONFIG_CMD_SAVEENV=y
+CONFIG_CMD_LOADENV=y
+CONFIG_CMD_EXPORT=y
+CONFIG_CMD_PRINTENV=y
+CONFIG_CMD_READLINE=y
+CONFIG_CMD_MENU=y
+CONFIG_CMD_MENU_MANAGEMENT=y
+CONFIG_CMD_PASSWD=y
+CONFIG_CMD_ECHO_E=y
+CONFIG_CMD_LOADB=y
+CONFIG_CMD_MEMINFO=y
+CONFIG_CMD_MTEST=y
+CONFIG_CMD_MTEST_ALTERNATIVE=y
+CONFIG_CMD_BOOTM_ZLIB=y
+CONFIG_CMD_BOOTM_BZLIB=y
+CONFIG_CMD_BOOTM_SHOW_TYPE=y
+CONFIG_CMD_RESET=y
+CONFIG_CMD_GO=y
+CONFIG_CMD_TIMEOUT=y
+CONFIG_CMD_PARTITION=y
+CONFIG_CMD_UNCOMPRESS=y
+CONFIG_CMD_GPIO=y
+CONFIG_SERIAL_AMBA_PL011=y
+CONFIG_SHA1=y
+CONFIG_SHA256=y
diff --git a/arch/arm/mach-bcm2835/Kconfig b/arch/arm/mach-bcm2835/Kconfig
index c42fe1c..9d97aea 100644
--- a/arch/arm/mach-bcm2835/Kconfig
+++ b/arch/arm/mach-bcm2835/Kconfig
@@ -1,3 +1,18 @@
 if ARCH_BCM2835
 
+config ARCH_TEXT_BASE
+	hex
+	default 0x04000000 if MACH_RPI
+
+config BOARDINFO
+	default "RaspberryPi (BCM2835/ARM1176JZF-S)" if MACH_RPI
+
+choice
+	prompt "Broadcom Board type"
+
+config MACH_RPI
+	bool "RaspberryPi (BCM2835/ARM1176JZF-S)"
+
+endchoice
+
 endif
-- 
1.7.12.3


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

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

* Re: [PATCH 0/5] BCM2835/Raspberry-Pi support
  2012-10-13 14:00 [PATCH 0/5] BCM2835/Raspberry-Pi support Carlo Caione
                   ` (4 preceding siblings ...)
  2012-10-13 14:00 ` [PATCH 5/5] Raspberry-Pi: add support (board) Carlo Caione
@ 2012-10-15  6:56 ` Sascha Hauer
  2012-10-15 12:43   ` Jean-Christophe PLAGNIOL-VILLARD
  5 siblings, 1 reply; 15+ messages in thread
From: Sascha Hauer @ 2012-10-15  6:56 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox


Jean-Christophe,

Since you reviewed this series can I assume you give your Acked-by once
you are happy with it?

Sascha

On Sat, Oct 13, 2012 at 04:00:11PM +0200, Carlo Caione wrote:
> The set is the same as before except for patch 05/05
> 
> Carlo Caione (5):
>   BCM2835: add clocksource driver
>   BCM2835: add gpio driver
>   ARM1176: add support
>   BCM2835: add support (arch)
>   Raspberry-Pi: add support (board)
> 
>  arch/arm/Kconfig                                   |   9 ++
>  arch/arm/Makefile                                  |   2 +
>  arch/arm/boards/raspberry-pi/Makefile              |   1 +
>  arch/arm/boards/raspberry-pi/config.h              |   4 +
>  .../arm/boards/raspberry-pi/env/init/bootargs-base |   8 +
>  arch/arm/boards/raspberry-pi/env/init/hostname     |   8 +
>  arch/arm/boards/raspberry-pi/rpi.c                 |  49 ++++++
>  arch/arm/configs/rpi_defconfig                     |  40 +++++
>  arch/arm/cpu/Kconfig                               |   5 +
>  arch/arm/mach-bcm2835/Kconfig                      |  18 +++
>  arch/arm/mach-bcm2835/Makefile                     |   2 +
>  arch/arm/mach-bcm2835/clock.c                      |  39 +++++
>  arch/arm/mach-bcm2835/core.c                       | 105 +++++++++++++
>  arch/arm/mach-bcm2835/include/mach/clkdev.h        |   7 +
>  arch/arm/mach-bcm2835/include/mach/clock.h         |   8 +
>  arch/arm/mach-bcm2835/include/mach/core.h          |  27 ++++
>  arch/arm/mach-bcm2835/include/mach/gpio.h          |   1 +
>  arch/arm/mach-bcm2835/include/mach/platform.h      |  53 +++++++
>  arch/arm/mach-bcm2835/include/mach/wd.h            |  50 +++++++
>  drivers/clocksource/Kconfig                        |   4 +
>  drivers/clocksource/Makefile                       |   1 +
>  drivers/clocksource/bcm2835.c                      |  95 ++++++++++++
>  drivers/gpio/Kconfig                               |   4 +
>  drivers/gpio/Makefile                              |   1 +
>  drivers/gpio/gpio-bcm2835.c                        | 165 +++++++++++++++++++++
>  25 files changed, 706 insertions(+)
>  create mode 100644 arch/arm/boards/raspberry-pi/Makefile
>  create mode 100644 arch/arm/boards/raspberry-pi/config.h
>  create mode 100644 arch/arm/boards/raspberry-pi/env/init/bootargs-base
>  create mode 100644 arch/arm/boards/raspberry-pi/env/init/hostname
>  create mode 100644 arch/arm/boards/raspberry-pi/rpi.c
>  create mode 100644 arch/arm/configs/rpi_defconfig
>  create mode 100644 arch/arm/mach-bcm2835/Kconfig
>  create mode 100644 arch/arm/mach-bcm2835/Makefile
>  create mode 100644 arch/arm/mach-bcm2835/clock.c
>  create mode 100644 arch/arm/mach-bcm2835/core.c
>  create mode 100644 arch/arm/mach-bcm2835/include/mach/clkdev.h
>  create mode 100644 arch/arm/mach-bcm2835/include/mach/clock.h
>  create mode 100644 arch/arm/mach-bcm2835/include/mach/core.h
>  create mode 100644 arch/arm/mach-bcm2835/include/mach/gpio.h
>  create mode 100644 arch/arm/mach-bcm2835/include/mach/platform.h
>  create mode 100644 arch/arm/mach-bcm2835/include/mach/wd.h
>  create mode 100644 drivers/clocksource/bcm2835.c
>  create mode 100644 drivers/gpio/gpio-bcm2835.c
> 
> -- 
> 1.7.12.3
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

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

* Re: [PATCH 0/5] BCM2835/Raspberry-Pi support
  2012-10-15  6:56 ` [PATCH 0/5] BCM2835/Raspberry-Pi support Sascha Hauer
@ 2012-10-15 12:43   ` Jean-Christophe PLAGNIOL-VILLARD
  2012-10-15 14:20     ` Carlo Caione
  0 siblings, 1 reply; 15+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-10-15 12:43 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On 08:56 Mon 15 Oct     , Sascha Hauer wrote:
> 
> Jean-Christophe,
> 
> Since you reviewed this series can I assume you give your Acked-by once
> you are happy with it?
I'm happy with it except one point that I just check with the mainline kernel
the DT

the timer as example is "brcm,bcm2835-system-timer" not "brcm,bcm2835-cs"

for gpio it's the right one

as we can agree to dt must be in sync

Best Regards,
J.
> 
> Sascha
> 
> On Sat, Oct 13, 2012 at 04:00:11PM +0200, Carlo Caione wrote:
> > The set is the same as before except for patch 05/05
> > 
> > Carlo Caione (5):
> >   BCM2835: add clocksource driver
> >   BCM2835: add gpio driver
> >   ARM1176: add support
> >   BCM2835: add support (arch)
> >   Raspberry-Pi: add support (board)
> > 
> >  arch/arm/Kconfig                                   |   9 ++
> >  arch/arm/Makefile                                  |   2 +
> >  arch/arm/boards/raspberry-pi/Makefile              |   1 +
> >  arch/arm/boards/raspberry-pi/config.h              |   4 +
> >  .../arm/boards/raspberry-pi/env/init/bootargs-base |   8 +
> >  arch/arm/boards/raspberry-pi/env/init/hostname     |   8 +
> >  arch/arm/boards/raspberry-pi/rpi.c                 |  49 ++++++
> >  arch/arm/configs/rpi_defconfig                     |  40 +++++
> >  arch/arm/cpu/Kconfig                               |   5 +
> >  arch/arm/mach-bcm2835/Kconfig                      |  18 +++
> >  arch/arm/mach-bcm2835/Makefile                     |   2 +
> >  arch/arm/mach-bcm2835/clock.c                      |  39 +++++
> >  arch/arm/mach-bcm2835/core.c                       | 105 +++++++++++++
> >  arch/arm/mach-bcm2835/include/mach/clkdev.h        |   7 +
> >  arch/arm/mach-bcm2835/include/mach/clock.h         |   8 +
> >  arch/arm/mach-bcm2835/include/mach/core.h          |  27 ++++
> >  arch/arm/mach-bcm2835/include/mach/gpio.h          |   1 +
> >  arch/arm/mach-bcm2835/include/mach/platform.h      |  53 +++++++
> >  arch/arm/mach-bcm2835/include/mach/wd.h            |  50 +++++++
> >  drivers/clocksource/Kconfig                        |   4 +
> >  drivers/clocksource/Makefile                       |   1 +
> >  drivers/clocksource/bcm2835.c                      |  95 ++++++++++++
> >  drivers/gpio/Kconfig                               |   4 +
> >  drivers/gpio/Makefile                              |   1 +
> >  drivers/gpio/gpio-bcm2835.c                        | 165 +++++++++++++++++++++
> >  25 files changed, 706 insertions(+)
> >  create mode 100644 arch/arm/boards/raspberry-pi/Makefile
> >  create mode 100644 arch/arm/boards/raspberry-pi/config.h
> >  create mode 100644 arch/arm/boards/raspberry-pi/env/init/bootargs-base
> >  create mode 100644 arch/arm/boards/raspberry-pi/env/init/hostname
> >  create mode 100644 arch/arm/boards/raspberry-pi/rpi.c
> >  create mode 100644 arch/arm/configs/rpi_defconfig
> >  create mode 100644 arch/arm/mach-bcm2835/Kconfig
> >  create mode 100644 arch/arm/mach-bcm2835/Makefile
> >  create mode 100644 arch/arm/mach-bcm2835/clock.c
> >  create mode 100644 arch/arm/mach-bcm2835/core.c
> >  create mode 100644 arch/arm/mach-bcm2835/include/mach/clkdev.h
> >  create mode 100644 arch/arm/mach-bcm2835/include/mach/clock.h
> >  create mode 100644 arch/arm/mach-bcm2835/include/mach/core.h
> >  create mode 100644 arch/arm/mach-bcm2835/include/mach/gpio.h
> >  create mode 100644 arch/arm/mach-bcm2835/include/mach/platform.h
> >  create mode 100644 arch/arm/mach-bcm2835/include/mach/wd.h
> >  create mode 100644 drivers/clocksource/bcm2835.c
> >  create mode 100644 drivers/gpio/gpio-bcm2835.c
> > 
> > -- 
> > 1.7.12.3
> > 
> > 
> > _______________________________________________
> > barebox mailing list
> > barebox@lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/barebox
> > 
> 
> -- 
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

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

* Re: [PATCH 0/5] BCM2835/Raspberry-Pi support
  2012-10-15 12:43   ` Jean-Christophe PLAGNIOL-VILLARD
@ 2012-10-15 14:20     ` Carlo Caione
  0 siblings, 0 replies; 15+ messages in thread
From: Carlo Caione @ 2012-10-15 14:20 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On 10/15/2012 02:43 PM, Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 08:56 Mon 15 Oct     , Sascha Hauer wrote:
>>
>> Jean-Christophe,
>>
>> Since you reviewed this series can I assume you give your Acked-by once
>> you are happy with it?
> I'm happy with it except one point that I just check with the mainline kernel
> the DT
>
> the timer as example is "brcm,bcm2835-system-timer" not "brcm,bcm2835-cs"
>
> for gpio it's the right one
>
> as we can agree to dt must be in sync

You are definitely right.
I'll resubmit the patches.
Thank you for your review, it is greatly appreciated.

Best,

--
Carlo Caione

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

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

* [PATCH 2/5] BCM2835: add gpio driver
  2012-10-18 19:42 Carlo Caione
@ 2012-10-18 19:42 ` Carlo Caione
  0 siblings, 0 replies; 15+ messages in thread
From: Carlo Caione @ 2012-10-18 19:42 UTC (permalink / raw)
  To: barebox

Signed-off-by: Carlo Caione <carlo.caione@gmail.com>
---
 drivers/gpio/Kconfig        |   4 ++
 drivers/gpio/Makefile       |   1 +
 drivers/gpio/gpio-bcm2835.c | 158 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 163 insertions(+)
 create mode 100644 drivers/gpio/gpio-bcm2835.c

diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index a0e9b58..e8eeb6d 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -6,6 +6,10 @@ if GPIOLIB
 
 menu "GPIO                          "
 
+config GPIO_BCM2835
+	bool "GPIO support for BCM2835"
+	depends on ARCH_BCM2835
+
 config GPIO_PL061
 	bool "PrimeCell PL061 GPIO support"
 	depends on ARM_AMBA
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index e2e97d3..aecdf24 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -1,4 +1,5 @@
 obj-$(CONFIG_GPIOLIB) += gpio.o
 
+obj-$(CONFIG_GPIO_BCM2835)	+= gpio-bcm2835.o
 obj-$(CONFIG_GPIO_PL061)	+= gpio-pl061.o
 obj-$(CONFIG_GPIO_STMPE) += gpio-stmpe.o
diff --git a/drivers/gpio/gpio-bcm2835.c b/drivers/gpio/gpio-bcm2835.c
new file mode 100644
index 0000000..cec15c9
--- /dev/null
+++ b/drivers/gpio/gpio-bcm2835.c
@@ -0,0 +1,158 @@
+/*
+ * Author: Carlo Caione <carlo@carlocaione.org>
+ *
+ * Based on linux/arch/arm/mach-bcm2708/bcm2708_gpio.c
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <common.h>
+#include <errno.h>
+#include <malloc.h>
+#include <io.h>
+#include <gpio.h>
+#include <init.h>
+
+#define GPIOFSEL(x)  (0x00+(x)*4)
+#define GPIOSET(x)   (0x1c+(x)*4)
+#define GPIOCLR(x)   (0x28+(x)*4)
+#define GPIOLEV(x)   (0x34+(x)*4)
+#define GPIOEDS(x)   (0x40+(x)*4)
+#define GPIOREN(x)   (0x4c+(x)*4)
+#define GPIOFEN(x)   (0x58+(x)*4)
+#define GPIOHEN(x)   (0x64+(x)*4)
+#define GPIOLEN(x)   (0x70+(x)*4)
+#define GPIOAREN(x)  (0x7c+(x)*4)
+#define GPIOAFEN(x)  (0x88+(x)*4)
+#define GPIOUD(x)    (0x94+(x)*4)
+#define GPIOUDCLK(x) (0x98+(x)*4)
+
+enum {
+	GPIO_FSEL_INPUT, GPIO_FSEL_OUTPUT,
+	GPIO_FSEL_ALT5, GPIO_FSEL_ALT_4,
+	GPIO_FSEL_ALT0, GPIO_FSEL_ALT1,
+	GPIO_FSEL_ALT2, GPIO_FSEL_ALT3,
+};
+
+struct bcm2835_gpio_chip {
+	void __iomem *base;
+	struct gpio_chip chip;
+};
+
+static int bcm2835_set_function(struct gpio_chip *chip, unsigned gpio, int function)
+{
+	struct bcm2835_gpio_chip *bcmgpio = container_of(chip, struct bcm2835_gpio_chip, chip);
+	void __iomem *base = bcmgpio->base;
+	unsigned gpiodir;
+	unsigned gpio_bank = gpio / 10;
+	unsigned gpio_field_offset = (gpio - 10 * gpio_bank) * 3;
+
+	gpiodir = readl(base + GPIOFSEL(gpio_bank));
+	gpiodir &= ~(7 << gpio_field_offset);
+	gpiodir |= function << gpio_field_offset;
+	writel(gpiodir, base + GPIOFSEL(gpio_bank));
+	gpiodir = readl(base + GPIOFSEL(gpio_bank));
+
+	return 0;
+}
+
+static void bcm2835_gpio_set_value(struct gpio_chip *chip, unsigned gpio, int value)
+{
+	struct bcm2835_gpio_chip *bcmgpio = container_of(chip, struct bcm2835_gpio_chip, chip);
+	void __iomem *base = bcmgpio->base;
+	unsigned gpio_bank = gpio / 32;
+	unsigned gpio_field_offset = gpio % 32;
+
+	if (value)
+		writel(1 << gpio_field_offset, base + GPIOSET(gpio_bank));
+	else
+		writel(1 << gpio_field_offset, base + GPIOCLR(gpio_bank));
+}
+
+static int bcm2835_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
+{
+	struct bcm2835_gpio_chip *bcmgpio = container_of(chip, struct bcm2835_gpio_chip, chip);
+	void __iomem *base = bcmgpio->base;
+	unsigned gpio_bank = gpio / 32;
+	unsigned gpio_field_offset = gpio % 32;
+	unsigned lev;
+
+	lev = readl(base + GPIOLEV(gpio_bank));
+	return 0x1 & (lev >> gpio_field_offset);
+}
+
+static int bcm2835_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
+{
+	return bcm2835_set_function(chip, gpio, GPIO_FSEL_INPUT);
+}
+
+static int bcm2835_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, int value)
+{
+	bcm2835_set_function(chip, gpio, GPIO_FSEL_OUTPUT);
+	bcm2835_gpio_set_value(chip, gpio, value);
+
+	return 0;
+}
+
+static struct gpio_ops bcm2835_gpio_ops = {
+	.direction_input = bcm2835_gpio_direction_input,
+	.direction_output = bcm2835_gpio_direction_output,
+	.get = bcm2835_gpio_get_value,
+	.set = bcm2835_gpio_set_value,
+};
+
+static int bcm2835_gpio_probe(struct device_d *dev)
+{
+	struct bcm2835_gpio_chip *bcmgpio;
+	int ret;
+
+	bcmgpio = xzalloc(sizeof(*bcmgpio));
+	bcmgpio->base = dev_request_mem_region(dev, 0);
+	bcmgpio->chip.ops = &bcm2835_gpio_ops;
+	bcmgpio->chip.base = 0;
+	bcmgpio->chip.ngpio = 54;
+	bcmgpio->chip.dev = dev;
+
+	ret = gpiochip_add(&bcmgpio->chip);
+	if (ret) {
+		dev_err(dev, "couldn't add gpiochip, ret = %d\n", ret);
+		goto err;
+	}
+	dev_info(dev, "probed gpiochip%d with base %d\n", dev->id, bcmgpio->chip.base);
+
+	return 0;
+
+err:
+	kfree(bcmgpio);
+
+	return ret;
+}
+
+static __maybe_unused struct of_device_id bcm2835_gpio_dt_ids[] = {
+	{
+		.compatible = "brcm,bcm2835-gpio",
+	}, {
+		/* sentinel */
+	}
+};
+
+static struct driver_d bcm2835_gpio_driver = {
+	.name = "bcm2835-gpio",
+	.probe = bcm2835_gpio_probe,
+	.of_compatible = DRV_OF_COMPAT(bcm2835_gpio_dt_ids),
+};
+
+static int bcm2835_gpio_add(void)
+{
+	return platform_driver_register(&bcm2835_gpio_driver);
+}
+coredevice_initcall(bcm2835_gpio_add);
-- 
1.7.12.3


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

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

* Re: [PATCH 2/5] BCM2835: add gpio driver
  2012-10-16 18:04 ` [PATCH 2/5] BCM2835: add gpio driver Carlo Caione
@ 2012-10-16 21:09   ` Sascha Hauer
  0 siblings, 0 replies; 15+ messages in thread
From: Sascha Hauer @ 2012-10-16 21:09 UTC (permalink / raw)
  To: Carlo Caione; +Cc: barebox

Hi Carlo,

I had an additional look before applying it, but there are still
some things that deserve a cleanup.

On Tue, Oct 16, 2012 at 08:04:42PM +0200, Carlo Caione wrote:
> +#include <common.h>
> +#include <errno.h>
> +#include <malloc.h>
> +#include <io.h>
> +#include <gpio.h>
> +#include <init.h>
> +#include <mach/platform.h>

Is this needed? I think not as this file only defines some base
addresses.

> +static int bcm2835_gpio_probe(struct device_d *dev)
> +{
> +	struct bcm2835_gpio_chip *bcmgpio;
> +	int ret;
> +
> +	bcmgpio = xzalloc(sizeof(*bcmgpio));
> +	bcmgpio->base = dev_request_mem_region(dev, 0);
> +	bcmgpio->chip.ops = &bcm2835_gpio_ops;
> +	bcmgpio->chip.base = -1;

Better to use 0 for base of the SoC internal gpios (or something like
dev->id * 32) to get a known base for the gpios. Board code will likely
depend on fixed numbers.

> +
> +static __maybe_unused struct of_device_id bcm2835_gpio_dt_ids[] = {
> +	{
> +			.compatible = "brcm,bcm2835-gpio",

Too many whitespaces here.

Sascha

> +static int bcm2835_gpio_add(void)
> +{
> +	platform_driver_register(&bcm2835_gpio_driver);
> +	return 0;

return platform_device_register() please. We had a time when barebox
just paniced when an initcall failed, hence we never returned
unsuccesful. Now we just print an error message, so when the register
for some reason fails you will see it.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

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

* [PATCH 2/5] BCM2835: add gpio driver
  2012-10-16 18:04 [PATCH 0/5] BCM2835/Raspberry-Pi support Carlo Caione
@ 2012-10-16 18:04 ` Carlo Caione
  2012-10-16 21:09   ` Sascha Hauer
  0 siblings, 1 reply; 15+ messages in thread
From: Carlo Caione @ 2012-10-16 18:04 UTC (permalink / raw)
  To: barebox

Signed-off-by: Carlo Caione <carlo.caione@gmail.com>
---
 drivers/gpio/Kconfig        |   4 ++
 drivers/gpio/Makefile       |   1 +
 drivers/gpio/gpio-bcm2835.c | 165 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 170 insertions(+)
 create mode 100644 drivers/gpio/gpio-bcm2835.c

diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index a0e9b58..e8eeb6d 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -6,6 +6,10 @@ if GPIOLIB
 
 menu "GPIO                          "
 
+config GPIO_BCM2835
+	bool "GPIO support for BCM2835"
+	depends on ARCH_BCM2835
+
 config GPIO_PL061
 	bool "PrimeCell PL061 GPIO support"
 	depends on ARM_AMBA
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index e2e97d3..aecdf24 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -1,4 +1,5 @@
 obj-$(CONFIG_GPIOLIB) += gpio.o
 
+obj-$(CONFIG_GPIO_BCM2835)	+= gpio-bcm2835.o
 obj-$(CONFIG_GPIO_PL061)	+= gpio-pl061.o
 obj-$(CONFIG_GPIO_STMPE) += gpio-stmpe.o
diff --git a/drivers/gpio/gpio-bcm2835.c b/drivers/gpio/gpio-bcm2835.c
new file mode 100644
index 0000000..ad0e392
--- /dev/null
+++ b/drivers/gpio/gpio-bcm2835.c
@@ -0,0 +1,165 @@
+/*
+ * Author: Carlo Caione <carlo@carlocaione.org>
+ *
+ * Based on linux/arch/arm/mach-bcm2708/bcm2708_gpio.c
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ */
+
+#include <common.h>
+#include <errno.h>
+#include <malloc.h>
+#include <io.h>
+#include <gpio.h>
+#include <init.h>
+#include <mach/platform.h>
+
+#define GPIOFSEL(x)  (0x00+(x)*4)
+#define GPIOSET(x)   (0x1c+(x)*4)
+#define GPIOCLR(x)   (0x28+(x)*4)
+#define GPIOLEV(x)   (0x34+(x)*4)
+#define GPIOEDS(x)   (0x40+(x)*4)
+#define GPIOREN(x)   (0x4c+(x)*4)
+#define GPIOFEN(x)   (0x58+(x)*4)
+#define GPIOHEN(x)   (0x64+(x)*4)
+#define GPIOLEN(x)   (0x70+(x)*4)
+#define GPIOAREN(x)  (0x7c+(x)*4)
+#define GPIOAFEN(x)  (0x88+(x)*4)
+#define GPIOUD(x)    (0x94+(x)*4)
+#define GPIOUDCLK(x) (0x98+(x)*4)
+
+enum {
+	GPIO_FSEL_INPUT, GPIO_FSEL_OUTPUT,
+	GPIO_FSEL_ALT5, GPIO_FSEL_ALT_4,
+	GPIO_FSEL_ALT0, GPIO_FSEL_ALT1,
+	GPIO_FSEL_ALT2, GPIO_FSEL_ALT3,
+};
+
+struct bcm2835_gpio_chip {
+	void __iomem *base;
+	struct gpio_chip chip;
+};
+
+static int bcm2835_set_function(struct gpio_chip *chip, unsigned gpio, int function)
+{
+	struct bcm2835_gpio_chip *bcmgpio = container_of(chip, struct bcm2835_gpio_chip, chip);
+	void __iomem *base = bcmgpio->base;
+	unsigned gpiodir;
+	unsigned gpio_bank = gpio / 10;
+	unsigned gpio_field_offset = (gpio - 10 * gpio_bank) * 3;
+
+	gpiodir = readl(base + GPIOFSEL(gpio_bank));
+	gpiodir &= ~(7 << gpio_field_offset);
+	gpiodir |= function << gpio_field_offset;
+	writel(gpiodir, base + GPIOFSEL(gpio_bank));
+	gpiodir = readl(base + GPIOFSEL(gpio_bank));
+
+	return 0;
+}
+
+static void bcm2835_gpio_set_value(struct gpio_chip *chip, unsigned gpio, int value)
+{
+	struct bcm2835_gpio_chip *bcmgpio = container_of(chip, struct bcm2835_gpio_chip, chip);
+	void __iomem *base = bcmgpio->base;
+	unsigned gpio_bank = gpio / 32;
+	unsigned gpio_field_offset = gpio % 32;
+
+	if (value)
+		writel(1 << gpio_field_offset, base + GPIOSET(gpio_bank));
+	else
+		writel(1 << gpio_field_offset, base + GPIOCLR(gpio_bank));
+}
+
+static int bcm2835_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
+{
+	struct bcm2835_gpio_chip *bcmgpio = container_of(chip, struct bcm2835_gpio_chip, chip);
+	void __iomem *base = bcmgpio->base;
+	unsigned gpio_bank = gpio / 32;
+	unsigned gpio_field_offset = gpio % 32;
+	unsigned lev;
+
+	lev = readl(base + GPIOLEV(gpio_bank));
+	return 0x1 & (lev >> gpio_field_offset);
+}
+
+static int bcm2835_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
+{
+	return bcm2835_set_function(chip, gpio, GPIO_FSEL_INPUT);
+}
+
+static int bcm2835_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, int value)
+{
+	bcm2835_set_function(chip, gpio, GPIO_FSEL_OUTPUT);
+	bcm2835_gpio_set_value(chip, gpio, value);
+
+	return 0;
+}
+
+static struct gpio_ops bcm2835_gpio_ops = {
+	.direction_input = bcm2835_gpio_direction_input,
+	.direction_output = bcm2835_gpio_direction_output,
+	.get = bcm2835_gpio_get_value,
+	.set = bcm2835_gpio_set_value,
+};
+
+static int bcm2835_gpio_probe(struct device_d *dev)
+{
+	struct bcm2835_gpio_chip *bcmgpio;
+	int ret;
+
+	bcmgpio = xzalloc(sizeof(*bcmgpio));
+	bcmgpio->base = dev_request_mem_region(dev, 0);
+	bcmgpio->chip.ops = &bcm2835_gpio_ops;
+	bcmgpio->chip.base = -1;
+	bcmgpio->chip.ngpio = 54;
+	bcmgpio->chip.dev = dev;
+
+	ret = gpiochip_add(&bcmgpio->chip);
+	if (ret) {
+		dev_err(dev, "couldn't add gpiochip, ret = %d\n", ret);
+		goto err;
+	}
+	dev_info(dev, "probed gpiochip%d with base %d\n", dev->id, bcmgpio->chip.base);
+
+	return 0;
+
+err:
+	kfree(bcmgpio);
+
+	return ret;
+}
+
+static __maybe_unused struct of_device_id bcm2835_gpio_dt_ids[] = {
+	{
+			.compatible = "brcm,bcm2835-gpio",
+	}, {
+			/* sentinel */
+	}
+};
+
+static struct driver_d bcm2835_gpio_driver = {
+	.name = "bcm2835-gpio",
+	.probe = bcm2835_gpio_probe,
+	.of_compatible = DRV_OF_COMPAT(bcm2835_gpio_dt_ids),
+};
+
+static int bcm2835_gpio_add(void)
+{
+	platform_driver_register(&bcm2835_gpio_driver);
+	return 0;
+}
+coredevice_initcall(bcm2835_gpio_add);
-- 
1.7.12.3


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

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

* [PATCH 2/5] BCM2835: add gpio driver
  2012-10-13 11:22 [PATCH 0/5] BCM2835/Raspberry-Pi Carlo Caione
@ 2012-10-13 11:22 ` Carlo Caione
  0 siblings, 0 replies; 15+ messages in thread
From: Carlo Caione @ 2012-10-13 11:22 UTC (permalink / raw)
  To: barebox

Signed-off-by: Carlo Caione <carlo.caione@gmail.com>
---
 drivers/gpio/Kconfig        |   4 ++
 drivers/gpio/Makefile       |   1 +
 drivers/gpio/gpio-bcm2835.c | 165 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 170 insertions(+)
 create mode 100644 drivers/gpio/gpio-bcm2835.c

diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index a0e9b58..e8eeb6d 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -6,6 +6,10 @@ if GPIOLIB
 
 menu "GPIO                          "
 
+config GPIO_BCM2835
+	bool "GPIO support for BCM2835"
+	depends on ARCH_BCM2835
+
 config GPIO_PL061
 	bool "PrimeCell PL061 GPIO support"
 	depends on ARM_AMBA
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index e2e97d3..aecdf24 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -1,4 +1,5 @@
 obj-$(CONFIG_GPIOLIB) += gpio.o
 
+obj-$(CONFIG_GPIO_BCM2835)	+= gpio-bcm2835.o
 obj-$(CONFIG_GPIO_PL061)	+= gpio-pl061.o
 obj-$(CONFIG_GPIO_STMPE) += gpio-stmpe.o
diff --git a/drivers/gpio/gpio-bcm2835.c b/drivers/gpio/gpio-bcm2835.c
new file mode 100644
index 0000000..2a9bc59
--- /dev/null
+++ b/drivers/gpio/gpio-bcm2835.c
@@ -0,0 +1,165 @@
+/*
+ * Author: Carlo Caione <carlo@carlocaione.org>
+ *
+ * Based on linux/arch/arm/mach-bcm2708/bcm2708_gpio.c
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ */
+
+#include <common.h>
+#include <errno.h>
+#include <malloc.h>
+#include <io.h>
+#include <gpio.h>
+#include <init.h>
+#include <mach/platform.h>
+
+#define GPIOFSEL(x)  (0x00+(x)*4)
+#define GPIOSET(x)   (0x1c+(x)*4)
+#define GPIOCLR(x)   (0x28+(x)*4)
+#define GPIOLEV(x)   (0x34+(x)*4)
+#define GPIOEDS(x)   (0x40+(x)*4)
+#define GPIOREN(x)   (0x4c+(x)*4)
+#define GPIOFEN(x)   (0x58+(x)*4)
+#define GPIOHEN(x)   (0x64+(x)*4)
+#define GPIOLEN(x)   (0x70+(x)*4)
+#define GPIOAREN(x)  (0x7c+(x)*4)
+#define GPIOAFEN(x)  (0x88+(x)*4)
+#define GPIOUD(x)    (0x94+(x)*4)
+#define GPIOUDCLK(x) (0x98+(x)*4)
+
+enum {
+	GPIO_FSEL_INPUT, GPIO_FSEL_OUTPUT,
+	GPIO_FSEL_ALT5, GPIO_FSEL_ALT_4,
+	GPIO_FSEL_ALT0, GPIO_FSEL_ALT1,
+	GPIO_FSEL_ALT2, GPIO_FSEL_ALT3,
+};
+
+struct bcm2835_gpio_chip {
+	void __iomem *base;
+	struct gpio_chip chip;
+};
+
+static int bcm2835_set_function(struct gpio_chip *chip, unsigned gpio, int function)
+{
+	struct bcm2835_gpio_chip *bcmgpio = container_of(chip, struct bcm2835_gpio_chip, chip);
+	void __iomem *base = bcmgpio->base;
+	unsigned gpiodir;
+	unsigned gpio_bank = gpio / 10;
+	unsigned gpio_field_offset = (gpio - 10 * gpio_bank) * 3;
+
+	gpiodir = readl(base + GPIOFSEL(gpio_bank));
+	gpiodir &= ~(7 << gpio_field_offset);
+	gpiodir |= function << gpio_field_offset;
+	writel(gpiodir, base + GPIOFSEL(gpio_bank));
+	gpiodir = readl(base + GPIOFSEL(gpio_bank));
+
+	return 0;
+}
+
+static void bcm2835_gpio_set_value(struct gpio_chip *chip, unsigned gpio, int value)
+{
+	struct bcm2835_gpio_chip *bcmgpio = container_of(chip, struct bcm2835_gpio_chip, chip);
+	void __iomem *base = bcmgpio->base;
+	unsigned gpio_bank = gpio / 32;
+	unsigned gpio_field_offset = gpio % 32;
+
+	if (value)
+		writel(1 << gpio_field_offset, base + GPIOSET(gpio_bank));
+	else
+		writel(1 << gpio_field_offset, base + GPIOCLR(gpio_bank));
+}
+
+static int bcm2835_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
+{
+	struct bcm2835_gpio_chip *bcmgpio = container_of(chip, struct bcm2835_gpio_chip, chip);
+	void __iomem *base = bcmgpio->base;
+	unsigned gpio_bank = gpio / 32;
+	unsigned gpio_field_offset = gpio % 32;
+	unsigned lev;
+
+	lev = readl(base + GPIOLEV(gpio_bank));
+	return 0x1 & (lev >> gpio_field_offset);
+}
+
+static int bcm2835_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
+{
+	return bcm2835_set_function(chip, gpio, GPIO_FSEL_INPUT);
+}
+
+static int bcm2835_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, int value)
+{
+	bcm2835_set_function(chip, gpio, GPIO_FSEL_OUTPUT);
+	bcm2835_gpio_set_value(chip, gpio, value);
+
+	return 0;
+}
+
+static struct gpio_ops bcm2835_gpio_ops = {
+	.direction_input = bcm2835_gpio_direction_input,
+	.direction_output = bcm2835_gpio_direction_output,
+	.get = bcm2835_gpio_get_value,
+	.set = bcm2835_gpio_set_value,
+};
+
+static int bcm2835_gpio_probe(struct device_d *dev)
+{
+	struct bcm2835_gpio_chip *bcmgpio;
+	int ret;
+
+	bcmgpio = xzalloc(sizeof(*bcmgpio));
+	bcmgpio->base = dev_request_mem_region(dev, 0);
+	bcmgpio->chip.ops = &bcm2835_gpio_ops;
+	bcmgpio->chip.base = -1;
+	bcmgpio->chip.ngpio = 54;
+	bcmgpio->chip.dev = dev;
+
+	ret = gpiochip_add(&bcmgpio->chip);
+	if (ret) {
+		dev_err(dev, "couldn't add gpiochip, ret = %d\n", ret);
+		goto err;
+	}
+	dev_info(dev, "probed gpiochip%d with base %d\n", dev->id, bcmgpio->chip.base);
+
+	return 0;
+
+err:
+	kfree(bcmgpio);
+
+	return ret;
+}
+
+static __maybe_unused struct of_device_id bcm2835_gpio_dt_ids[] = {
+	{
+			.compatible = "bcm,bcm2835-gpio",
+	}, {
+			/* sentinel */
+	}
+};
+
+static struct driver_d bcm2835_gpio_driver = {
+	.name = "bcm2835-gpio",
+	.probe = bcm2835_gpio_probe,
+	.of_compatible = DRV_OF_COMPAT(bcm2835_gpio_dt_ids),
+};
+
+static int bcm2835_gpio_add(void)
+{
+	platform_driver_register(&bcm2835_gpio_driver);
+	return 0;
+}
+coredevice_initcall(bcm2835_gpio_add);
-- 
1.7.12.3


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

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

* Re: [PATCH 2/5] BCM2835: add gpio driver
  2012-10-11 21:52 ` [PATCH 2/5] BCM2835: add gpio driver Carlo Caione
@ 2012-10-12  9:30   ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 15+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-10-12  9:30 UTC (permalink / raw)
  To: Carlo Caione; +Cc: barebox

On 23:52 Thu 11 Oct     , Carlo Caione wrote:
> Signed-off-by: Carlo Caione <carlo.caione@gmail.com>
> ---
>  drivers/gpio/Kconfig        |   4 ++
>  drivers/gpio/Makefile       |   1 +
>  drivers/gpio/gpio-bcm2835.c | 166 ++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 171 insertions(+)
>  create mode 100644 drivers/gpio/gpio-bcm2835.c
> 
> diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
> index a0e9b58..e8eeb6d 100644
> --- a/drivers/gpio/Kconfig
> +++ b/drivers/gpio/Kconfig
> @@ -6,6 +6,10 @@ if GPIOLIB
>  
>  menu "GPIO                          "
>  
> +config GPIO_BCM2835
> +	bool "GPIO support for BCM2835"
> +	depends on ARCH_BCM2835
> +
>  config GPIO_PL061
>  	bool "PrimeCell PL061 GPIO support"
>  	depends on ARM_AMBA
> diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
> index e2e97d3..aecdf24 100644
> --- a/drivers/gpio/Makefile
> +++ b/drivers/gpio/Makefile
> @@ -1,4 +1,5 @@
>  obj-$(CONFIG_GPIOLIB) += gpio.o
>  
> +obj-$(CONFIG_GPIO_BCM2835)	+= gpio-bcm2835.o
>  obj-$(CONFIG_GPIO_PL061)	+= gpio-pl061.o
>  obj-$(CONFIG_GPIO_STMPE) += gpio-stmpe.o
> diff --git a/drivers/gpio/gpio-bcm2835.c b/drivers/gpio/gpio-bcm2835.c
> new file mode 100644
> index 0000000..e31894c
> --- /dev/null
> +++ b/drivers/gpio/gpio-bcm2835.c
> @@ -0,0 +1,166 @@
> +/*
> + * Author: Carlo Caione <carlo@carlocaione.org>
> + *
> + * Based on linux/arch/arm/mach-bcm2708/bcm2708_gpio.c
> + *
> + * 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.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
> + * MA 02111-1307 USA
> + *
> + */
> +
> +#include <common.h>
> +#include <errno.h>
> +#include <malloc.h>
> +#include <io.h>
> +#include <gpio.h>
> +#include <init.h>
> +#include <mach/platform.h>
> +
> +#define GPIOFSEL(x)  (0x00+(x)*4)
> +#define GPIOSET(x)   (0x1c+(x)*4)
> +#define GPIOCLR(x)   (0x28+(x)*4)
> +#define GPIOLEV(x)   (0x34+(x)*4)
> +#define GPIOEDS(x)   (0x40+(x)*4)
> +#define GPIOREN(x)   (0x4c+(x)*4)
> +#define GPIOFEN(x)   (0x58+(x)*4)
> +#define GPIOHEN(x)   (0x64+(x)*4)
> +#define GPIOLEN(x)   (0x70+(x)*4)
> +#define GPIOAREN(x)  (0x7c+(x)*4)
> +#define GPIOAFEN(x)  (0x88+(x)*4)
> +#define GPIOUD(x)    (0x94+(x)*4)
> +#define GPIOUDCLK(x) (0x98+(x)*4)
> +
> +enum {
> +	GPIO_FSEL_INPUT, GPIO_FSEL_OUTPUT,
> +	GPIO_FSEL_ALT5, GPIO_FSEL_ALT_4,
> +	GPIO_FSEL_ALT0, GPIO_FSEL_ALT1,
> +	GPIO_FSEL_ALT2, GPIO_FSEL_ALT3,
> +};
> +
> +struct bcm2835_gpio_chip {
> +	void __iomem *base;
> +	struct gpio_chip chip;
> +};
> +
> +static int bcm2835_set_function(struct gpio_chip *chip, unsigned gpio, int function)
> +{
> +	struct bcm2835_gpio_chip *bcmgpio = container_of(chip, struct bcm2835_gpio_chip, chip);
> +	void __iomem *base = bcmgpio->base;
> +	unsigned gpiodir;
> +	unsigned gpio_bank = gpio / 10;
> +	unsigned gpio_field_offset = (gpio - 10 * gpio_bank) * 3;
> +
> +	gpiodir = readl(base + GPIOFSEL(gpio_bank));
> +	gpiodir &= ~(7 << gpio_field_offset);
> +	gpiodir |= function << gpio_field_offset;
> +	writel(gpiodir, base + GPIOFSEL(gpio_bank));
> +	gpiodir = readl(base + GPIOFSEL(gpio_bank));
> +
> +	return 0;
> +}
> +
> +static void bcm2835_gpio_set_value(struct gpio_chip *chip, unsigned gpio, int value)
> +{
> +	struct bcm2835_gpio_chip *bcmgpio = container_of(chip, struct bcm2835_gpio_chip, chip);
> +	void __iomem *base = bcmgpio->base;
> +	unsigned gpio_bank = gpio / 32;
> +	unsigned gpio_field_offset = gpio % 32;
> +
> +	if (value)
> +		writel(1 << gpio_field_offset, base + GPIOSET(gpio_bank));
> +	else
> +		writel(1 << gpio_field_offset, base + GPIOCLR(gpio_bank));
> +}
> +
> +static int bcm2835_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
> +{
> +	struct bcm2835_gpio_chip *bcmgpio = container_of(chip, struct bcm2835_gpio_chip, chip);
> +	void __iomem *base = bcmgpio->base;
> +	unsigned gpio_bank = gpio / 32;
> +	unsigned gpio_field_offset = gpio % 32;
> +	unsigned lev;
> +
> +	lev = readl(base + GPIOLEV(gpio_bank));
> +	return 0x1 & (lev >> gpio_field_offset);
> +}
> +
> +static int bcm2835_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
> +{
> +	return bcm2835_set_function(chip, gpio, GPIO_FSEL_INPUT);
> +}
> +
> +static int bcm2835_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, int value)
> +{
> +	int ret;
missing empty line
> +	ret =  bcm2835_set_function(chip, gpio, GPIO_FSEL_OUTPUT);
always return 0
> +	if (ret >= 0)
> +		bcm2835_gpio_set_value(chip, gpio, value);
> +	return ret;
> +}
> +
Best Regards,
J.

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

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

* [PATCH 2/5] BCM2835: add gpio driver
  2012-10-11 21:52 [PATCH 0/5] BCM2835/RPi support Carlo Caione
@ 2012-10-11 21:52 ` Carlo Caione
  2012-10-12  9:30   ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 1 reply; 15+ messages in thread
From: Carlo Caione @ 2012-10-11 21:52 UTC (permalink / raw)
  To: barebox

Signed-off-by: Carlo Caione <carlo.caione@gmail.com>
---
 drivers/gpio/Kconfig        |   4 ++
 drivers/gpio/Makefile       |   1 +
 drivers/gpio/gpio-bcm2835.c | 166 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 171 insertions(+)
 create mode 100644 drivers/gpio/gpio-bcm2835.c

diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index a0e9b58..e8eeb6d 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -6,6 +6,10 @@ if GPIOLIB
 
 menu "GPIO                          "
 
+config GPIO_BCM2835
+	bool "GPIO support for BCM2835"
+	depends on ARCH_BCM2835
+
 config GPIO_PL061
 	bool "PrimeCell PL061 GPIO support"
 	depends on ARM_AMBA
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index e2e97d3..aecdf24 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -1,4 +1,5 @@
 obj-$(CONFIG_GPIOLIB) += gpio.o
 
+obj-$(CONFIG_GPIO_BCM2835)	+= gpio-bcm2835.o
 obj-$(CONFIG_GPIO_PL061)	+= gpio-pl061.o
 obj-$(CONFIG_GPIO_STMPE) += gpio-stmpe.o
diff --git a/drivers/gpio/gpio-bcm2835.c b/drivers/gpio/gpio-bcm2835.c
new file mode 100644
index 0000000..e31894c
--- /dev/null
+++ b/drivers/gpio/gpio-bcm2835.c
@@ -0,0 +1,166 @@
+/*
+ * Author: Carlo Caione <carlo@carlocaione.org>
+ *
+ * Based on linux/arch/arm/mach-bcm2708/bcm2708_gpio.c
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ */
+
+#include <common.h>
+#include <errno.h>
+#include <malloc.h>
+#include <io.h>
+#include <gpio.h>
+#include <init.h>
+#include <mach/platform.h>
+
+#define GPIOFSEL(x)  (0x00+(x)*4)
+#define GPIOSET(x)   (0x1c+(x)*4)
+#define GPIOCLR(x)   (0x28+(x)*4)
+#define GPIOLEV(x)   (0x34+(x)*4)
+#define GPIOEDS(x)   (0x40+(x)*4)
+#define GPIOREN(x)   (0x4c+(x)*4)
+#define GPIOFEN(x)   (0x58+(x)*4)
+#define GPIOHEN(x)   (0x64+(x)*4)
+#define GPIOLEN(x)   (0x70+(x)*4)
+#define GPIOAREN(x)  (0x7c+(x)*4)
+#define GPIOAFEN(x)  (0x88+(x)*4)
+#define GPIOUD(x)    (0x94+(x)*4)
+#define GPIOUDCLK(x) (0x98+(x)*4)
+
+enum {
+	GPIO_FSEL_INPUT, GPIO_FSEL_OUTPUT,
+	GPIO_FSEL_ALT5, GPIO_FSEL_ALT_4,
+	GPIO_FSEL_ALT0, GPIO_FSEL_ALT1,
+	GPIO_FSEL_ALT2, GPIO_FSEL_ALT3,
+};
+
+struct bcm2835_gpio_chip {
+	void __iomem *base;
+	struct gpio_chip chip;
+};
+
+static int bcm2835_set_function(struct gpio_chip *chip, unsigned gpio, int function)
+{
+	struct bcm2835_gpio_chip *bcmgpio = container_of(chip, struct bcm2835_gpio_chip, chip);
+	void __iomem *base = bcmgpio->base;
+	unsigned gpiodir;
+	unsigned gpio_bank = gpio / 10;
+	unsigned gpio_field_offset = (gpio - 10 * gpio_bank) * 3;
+
+	gpiodir = readl(base + GPIOFSEL(gpio_bank));
+	gpiodir &= ~(7 << gpio_field_offset);
+	gpiodir |= function << gpio_field_offset;
+	writel(gpiodir, base + GPIOFSEL(gpio_bank));
+	gpiodir = readl(base + GPIOFSEL(gpio_bank));
+
+	return 0;
+}
+
+static void bcm2835_gpio_set_value(struct gpio_chip *chip, unsigned gpio, int value)
+{
+	struct bcm2835_gpio_chip *bcmgpio = container_of(chip, struct bcm2835_gpio_chip, chip);
+	void __iomem *base = bcmgpio->base;
+	unsigned gpio_bank = gpio / 32;
+	unsigned gpio_field_offset = gpio % 32;
+
+	if (value)
+		writel(1 << gpio_field_offset, base + GPIOSET(gpio_bank));
+	else
+		writel(1 << gpio_field_offset, base + GPIOCLR(gpio_bank));
+}
+
+static int bcm2835_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
+{
+	struct bcm2835_gpio_chip *bcmgpio = container_of(chip, struct bcm2835_gpio_chip, chip);
+	void __iomem *base = bcmgpio->base;
+	unsigned gpio_bank = gpio / 32;
+	unsigned gpio_field_offset = gpio % 32;
+	unsigned lev;
+
+	lev = readl(base + GPIOLEV(gpio_bank));
+	return 0x1 & (lev >> gpio_field_offset);
+}
+
+static int bcm2835_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
+{
+	return bcm2835_set_function(chip, gpio, GPIO_FSEL_INPUT);
+}
+
+static int bcm2835_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, int value)
+{
+	int ret;
+	ret =  bcm2835_set_function(chip, gpio, GPIO_FSEL_OUTPUT);
+	if (ret >= 0)
+		bcm2835_gpio_set_value(chip, gpio, value);
+	return ret;
+}
+
+static struct gpio_ops bcm2835_gpio_ops = {
+	.direction_input = bcm2835_gpio_direction_input,
+	.direction_output = bcm2835_gpio_direction_output,
+	.get = bcm2835_gpio_get_value,
+	.set = bcm2835_gpio_set_value,
+};
+
+static int bcm2835_gpio_probe(struct device_d *dev)
+{
+	struct bcm2835_gpio_chip *bcmgpio;
+	int ret;
+
+	bcmgpio = xzalloc(sizeof(*bcmgpio));
+	bcmgpio->base = dev_request_mem_region(dev, 0);
+	bcmgpio->chip.ops = &bcm2835_gpio_ops;
+	bcmgpio->chip.base = -1;
+	bcmgpio->chip.ngpio = 54;
+	bcmgpio->chip.dev = dev;
+
+	ret = gpiochip_add(&bcmgpio->chip);
+	if (ret) {
+		dev_err(dev, "couldn't add gpiochip, ret = %d\n", ret);
+		goto err;
+	}
+	dev_info(dev, "probed gpiochip%d with base %d\n", dev->id, bcmgpio->chip.base);
+
+	return 0;
+
+err:
+	kfree(bcmgpio);
+
+	return ret;
+}
+
+static __maybe_unused struct of_device_id bcm2835_gpio_dt_ids[] = {
+	{
+			.compatible = "bcm,bcm2835-gpio",
+	}, {
+			/* sentinel */
+	}
+};
+
+static struct driver_d bcm2835_gpio_driver = {
+	.name = "bcm2835-gpio",
+	.probe = bcm2835_gpio_probe,
+	.of_compatible = DRV_OF_COMPAT(bcm2835_gpio_dt_ids),
+};
+
+static int bcm2835_gpio_add(void)
+{
+	platform_driver_register(&bcm2835_gpio_driver);
+	return 0;
+}
+coredevice_initcall(bcm2835_gpio_add);
-- 
1.7.12.3


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

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

end of thread, other threads:[~2012-10-18 19:42 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-13 14:00 [PATCH 0/5] BCM2835/Raspberry-Pi support Carlo Caione
2012-10-13 14:00 ` [PATCH 1/5] BCM2835: add clocksource driver Carlo Caione
2012-10-13 14:00 ` [PATCH 2/5] BCM2835: add gpio driver Carlo Caione
2012-10-13 14:00 ` [PATCH 3/5] ARM1176: add support Carlo Caione
2012-10-13 14:00 ` [PATCH 4/5] BCM2835: add support (arch) Carlo Caione
2012-10-13 14:00 ` [PATCH 5/5] Raspberry-Pi: add support (board) Carlo Caione
2012-10-15  6:56 ` [PATCH 0/5] BCM2835/Raspberry-Pi support Sascha Hauer
2012-10-15 12:43   ` Jean-Christophe PLAGNIOL-VILLARD
2012-10-15 14:20     ` Carlo Caione
  -- strict thread matches above, loose matches on Subject: below --
2012-10-18 19:42 Carlo Caione
2012-10-18 19:42 ` [PATCH 2/5] BCM2835: add gpio driver Carlo Caione
2012-10-16 18:04 [PATCH 0/5] BCM2835/Raspberry-Pi support Carlo Caione
2012-10-16 18:04 ` [PATCH 2/5] BCM2835: add gpio driver Carlo Caione
2012-10-16 21:09   ` Sascha Hauer
2012-10-13 11:22 [PATCH 0/5] BCM2835/Raspberry-Pi Carlo Caione
2012-10-13 11:22 ` [PATCH 2/5] BCM2835: add gpio driver Carlo Caione
2012-10-11 21:52 [PATCH 0/5] BCM2835/RPi support Carlo Caione
2012-10-11 21:52 ` [PATCH 2/5] BCM2835: add gpio driver Carlo Caione
2012-10-12  9:30   ` Jean-Christophe PLAGNIOL-VILLARD

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