mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Antony Pavlov <antonynpavlov@gmail.com>
To: barebox@lists.infradead.org
Subject: [PATCH 5/9] gpio: add driver for Canon DIGIC
Date: Sun, 27 Jul 2014 13:47:24 +0400	[thread overview]
Message-ID: <1406454448-10645-6-git-send-email-antonynpavlov@gmail.com> (raw)
In-Reply-To: <1406454448-10645-1-git-send-email-antonynpavlov@gmail.com>

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
 drivers/gpio/Kconfig      |   4 ++
 drivers/gpio/Makefile     |   1 +
 drivers/gpio/gpio-digic.c | 180 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 185 insertions(+)

diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 6928fcb..0ca7df4 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -9,6 +9,10 @@ menu "GPIO"
 config GPIO_GENERIC
 	bool
 
+config GPIO_DIGIC
+	bool "GPIO support for Canon DIGIC"
+	depends on ARCH_DIGIC
+
 config GPIO_BCM2835
 	bool "GPIO support for BCM2835"
 	depends on ARCH_BCM2835
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index ece5efd..510d146 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -3,6 +3,7 @@ obj-$(CONFIG_GPIOLIB)		+= gpiolib.o
 obj-$(CONFIG_GPIO_BCM2835)	+= gpio-bcm2835.o
 obj-$(CONFIG_GPIO_DAVINCI)	+= gpio-davinci.o
 obj-$(CONFIG_GPIO_CLPS711X)	+= gpio-clps711x.o
+obj-$(CONFIG_GPIO_DIGIC)	+= gpio-digic.o
 obj-$(CONFIG_GPIO_GENERIC)	+= gpio-generic.o
 obj-$(CONFIG_GPIO_IMX)		+= gpio-imx.o
 obj-$(CONFIG_GPIO_JZ4740)	+= gpio-jz4740.o
diff --git a/drivers/gpio/gpio-digic.c b/drivers/gpio/gpio-digic.c
new file mode 100644
index 0000000..468aaa7
--- /dev/null
+++ b/drivers/gpio/gpio-digic.c
@@ -0,0 +1,180 @@
+/*
+ * Copyright (C) 2013 Antony Pavlov <antonynpavlov@gmail.com>
+ *
+ * This file is part of barebox.
+ * See file CREDITS for list of people who contributed to this project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * 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 <malloc.h>
+#include <errno.h>
+#include <io.h>
+#include <gpio.h>
+#include <init.h>
+
+/*
+ * See http://magiclantern.wikia.com/wiki/Register_Map#GPIO_Ports
+ */
+
+#define DIGIC_GPIO_IN_LVL	1
+#define DIGIC_GPIO_OUT_LVL	2
+#define DIGIC_GPIO_DIR	4
+#define DIGIC_GPIO_TRISTATE	8
+
+struct digic_gpio_chip {
+	void __iomem		*base;
+	struct gpio_chip	gc;
+};
+
+#define to_digic_gpio_chip(c) container_of(c, struct digic_gpio_chip, gc)
+
+static inline uint32_t digic_gpio_readl(struct digic_gpio_chip *chip,
+					uint32_t offset)
+{
+	return readl(chip->base + 4 * offset);
+}
+
+static inline void digic_gpio_writel(struct digic_gpio_chip *chip,
+					uint32_t value, uint32_t offset)
+{
+	writel(value, chip->base + 4 * offset);
+}
+
+static int digic_gpio_get_value(struct gpio_chip *gc, unsigned offset)
+{
+	struct digic_gpio_chip *chip = to_digic_gpio_chip(gc);
+
+	if (offset >= gc->ngpio)
+		return -EINVAL;
+
+	return digic_gpio_readl(chip, offset) & DIGIC_GPIO_IN_LVL;
+}
+
+static void digic_gpio_set_value(struct gpio_chip *gc, unsigned offset,
+					int value)
+{
+	struct digic_gpio_chip *chip = to_digic_gpio_chip(gc);
+	uint32_t t;
+
+	if (offset >= gc->ngpio)
+		return;
+
+	t = digic_gpio_readl(chip, offset);
+	/* Port direction (1 = OUT, 0 = IN) */
+	if (value)
+		t |= DIGIC_GPIO_OUT_LVL;
+	else
+		t &= ~(DIGIC_GPIO_OUT_LVL);
+	digic_gpio_writel(chip, t, offset);
+}
+
+static int digic_gpio_direction_input(struct gpio_chip *gc, unsigned offset)
+{
+	struct digic_gpio_chip *chip = to_digic_gpio_chip(gc);
+	uint32_t t;
+
+	if (offset >= gc->ngpio)
+		return -EINVAL;
+
+	t = digic_gpio_readl(chip, offset);
+	/* Port direction (1 = OUT, 0 = IN) */
+	t &= ~(DIGIC_GPIO_DIR);
+	digic_gpio_writel(chip, t, offset);
+
+	return 0;
+}
+
+static int digic_gpio_direction_output(struct gpio_chip *gc, unsigned offset,
+		int value)
+{
+	struct digic_gpio_chip *chip = to_digic_gpio_chip(gc);
+	uint32_t t;
+
+	if (offset >= gc->ngpio)
+		return -EINVAL;
+
+	t = digic_gpio_readl(chip, offset);
+	/* Port direction (1 = OUT, 0 = IN) */
+	t |= DIGIC_GPIO_DIR;
+	digic_gpio_writel(chip, t, offset);
+
+	digic_gpio_set_value(gc, offset, value);
+
+	return 0;
+}
+
+static struct gpio_ops digic_gpio_ops = {
+	.direction_input = digic_gpio_direction_input,
+	.direction_output = digic_gpio_direction_output,
+	.get = digic_gpio_get_value,
+	.set = digic_gpio_set_value,
+};
+
+static int digic_gpio_probe(struct device_d *dev)
+{
+	struct digic_gpio_chip *chip;
+	struct resource *res;
+	resource_size_t rsize;
+	int ret = -EINVAL;
+
+	chip = xzalloc(sizeof(*chip));
+
+	res = dev_get_resource(dev, IORESOURCE_MEM, 0);
+	if (!res)
+		goto err;
+
+	rsize = resource_size(res);
+	chip->gc.ngpio = rsize / sizeof(int32_t);
+
+	chip->base = dev_request_mem_region(dev, 0);
+	chip->gc.ops = &digic_gpio_ops;
+	chip->gc.base = 0;
+
+	chip->gc.dev = dev;
+
+	ret = gpiochip_add(&chip->gc);
+	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, chip->gc.base);
+
+	return 0;
+
+err:
+	kfree(chip);
+
+	return ret;
+}
+
+static __maybe_unused struct of_device_id digic_gpio_dt_ids[] = {
+	{
+		.compatible = "canon,digic-gpio",
+	}, {
+		/* sentinel */
+	}
+};
+
+static struct driver_d digic_gpio_driver = {
+	.name = "digic-gpio",
+	.probe = digic_gpio_probe,
+	.of_compatible = DRV_OF_COMPAT(digic_gpio_dt_ids),
+};
+
+static int digic_gpio_init(void)
+{
+	return platform_driver_register(&digic_gpio_driver);
+}
+coredevice_initcall(digic_gpio_init);
-- 
2.0.1


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

  parent reply	other threads:[~2014-07-27  9:48 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-27  9:47 [PATCH 0/9] ARM: add support for Canon DIGIC chips and Canon PowerShot A1100 IS Antony Pavlov
2014-07-27  9:47 ` [PATCH 1/9] ARM: add ARM946E-S CPU type Antony Pavlov
2014-07-27  9:47 ` [PATCH 2/9] ARM: add very initial support for Canon DIGIC chips Antony Pavlov
2014-07-28  6:09   ` Sascha Hauer
2014-07-27  9:47 ` [PATCH 3/9] clocksource: add driver for Canon DIGIC timer Antony Pavlov
2014-07-27  9:47 ` [PATCH 4/9] serial: add driver for Canon DIGIC UART Antony Pavlov
2014-07-27  9:47 ` Antony Pavlov [this message]
2014-07-27  9:47 ` [PATCH 6/9] ARM: DIGIC: add Canon PowerShot A1100 IS support Antony Pavlov
2014-07-27  9:47 ` [PATCH 7/9] ARM: add Canon A1100 ROM image generation Antony Pavlov
2014-07-27  9:47 ` [PATCH 8/9] ARM: DIGIC: add canon-a1100_defconfig Antony Pavlov
2014-07-27  9:47 ` [PATCH 9/9] Documentation: add QEMU Canon A1100 barebox mini-howto Antony Pavlov
2014-07-28  6:16   ` Sascha Hauer
2014-07-28  7:00     ` Antony Pavlov
2014-07-28 11:48     ` Antony Pavlov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1406454448-10645-6-git-send-email-antonynpavlov@gmail.com \
    --to=antonynpavlov@gmail.com \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox