All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mateusz Kulikowski <mateusz.kulikowski@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RFC PATCH 02/11] gpio: Add support for Qualcomm gpio controller
Date: Thu, 10 Dec 2015 22:41:38 +0100	[thread overview]
Message-ID: <1449783707-23594-3-git-send-email-mateusz.kulikowski@gmail.com> (raw)
In-Reply-To: <1449783707-23594-1-git-send-email-mateusz.kulikowski@gmail.com>

Add support for gpio controllers on Qualcomm Snapdragon devices.
This devices are usually called Top Level Mode Multiplexing in
Qualcomm documentation.

Signed-off-by: Mateusz Kulikowski <mateusz.kulikowski@gmail.com>
---

 drivers/gpio/Kconfig    |   7 +++
 drivers/gpio/Makefile   |   2 +-
 drivers/gpio/msm_gpio.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 123 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpio/msm_gpio.c

diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index e60e9fd..1d9443b 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -46,6 +46,13 @@ config LPC32XX_GPIO
 	help
 	  Support for the LPC32XX GPIO driver.
 
+config MSM_GPIO
+	bool "Qualcomm GPIO driver"
+	depends on DM_GPIO
+	default n
+	help
+	  Support GPIO controllers on Qualcomm Snapdragon family of SoCs.
+
 config ROCKCHIP_GPIO
 	bool "Rockchip GPIO driver"
 	depends on DM_GPIO
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index fb4fd25..9520b1e 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -46,4 +46,4 @@ obj-$(CONFIG_STM32_GPIO)	+= stm32_gpio.o
 obj-$(CONFIG_ZYNQ_GPIO)		+= zynq_gpio.o
 obj-$(CONFIG_VYBRID_GPIO)	+= vybrid_gpio.o
 obj-$(CONFIG_HIKEY_GPIO)	+= hi6220_gpio.o
-
+obj-$(CONFIG_MSM_GPIO)		+= msm_gpio.o
diff --git a/drivers/gpio/msm_gpio.c b/drivers/gpio/msm_gpio.c
new file mode 100644
index 0000000..9bb9e89
--- /dev/null
+++ b/drivers/gpio/msm_gpio.c
@@ -0,0 +1,115 @@
+/*
+ * Qualcomm GPIO driver
+ *
+ * (C) Copyright 2015 Mateusz Kulikowski <mateusz.kulikowski@gmail.com>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <asm/gpio.h>
+#include <asm/io.h>
+#include <errno.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+struct msm_gpio_bank {
+	phys_addr_t base;
+};
+
+static int msm_gpio_direction_input(struct udevice *dev, unsigned int gpio)
+{
+	struct msm_gpio_bank *priv = dev_get_priv(dev);
+	phys_addr_t reg = priv->base + GPIO_CONFIG_OFF(gpio);
+
+	/* Disable OE bit */
+	writel((readl(reg) & ~GPIO_OE_MASK) | GPIO_OE_DISABLE , reg);
+	return 0;
+}
+
+static int msm_gpio_set_value(struct udevice *dev, unsigned gpio, int value)
+{
+	struct msm_gpio_bank *priv = dev_get_priv(dev);
+
+	value = !!value;
+	/* set value */
+	writel(value << GPIO_OUT, priv->base + GPIO_IN_OUT_OFF(gpio));
+	return 0;
+}
+
+static int msm_gpio_direction_output(struct udevice *dev, unsigned gpio,
+				     int value)
+{
+	struct msm_gpio_bank *priv = dev_get_priv(dev);
+	phys_addr_t reg = priv->base + GPIO_CONFIG_OFF(gpio);
+
+	value = !!value;
+	/* set value */
+	writel(value << GPIO_OUT, priv->base + GPIO_IN_OUT_OFF(gpio));
+	/* switch direction */
+	writel((readl(reg) & ~GPIO_OE_MASK) | GPIO_OE_ENABLE , reg);
+	return 0;
+}
+
+static int msm_gpio_get_value(struct udevice *dev, unsigned gpio)
+{
+	struct msm_gpio_bank *priv = dev_get_priv(dev);
+
+	return !!(readl(priv->base + GPIO_IN_OUT_OFF(gpio)) >> GPIO_IN);
+}
+
+static int msm_gpio_get_function(struct udevice *dev, unsigned offset)
+{
+	struct msm_gpio_bank *priv = dev_get_priv(dev);
+
+	if (readl(priv->base + GPIO_CONFIG_OFF(offset)) & GPIO_OE_ENABLE)
+		return GPIOF_OUTPUT;
+	return GPIOF_INPUT;
+}
+
+static const struct dm_gpio_ops gpio_msm_ops = {
+	.direction_input	= msm_gpio_direction_input,
+	.direction_output	= msm_gpio_direction_output,
+	.get_value		= msm_gpio_get_value,
+	.set_value		= msm_gpio_set_value,
+	.get_function		= msm_gpio_get_function,
+};
+
+static int msm_gpio_probe(struct udevice *dev)
+{
+	struct msm_gpio_bank *priv = dev_get_priv(dev);
+
+	priv->base = dev_get_addr(dev);
+	return priv->base == FDT_ADDR_T_NONE;
+}
+
+static int msm_gpio_ofdata_to_platdata(struct udevice *dev)
+{
+	struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
+
+	uc_priv->gpio_count = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+					     "gpio-count", 0);
+	uc_priv->bank_name = fdt_getprop(gd->fdt_blob, dev->of_offset,
+					 "gpio-bank-name", NULL);
+	if (uc_priv->bank_name == NULL)
+		uc_priv->bank_name = "soc";
+	return 0;
+}
+
+static const struct udevice_id msm_gpio_ids[] = {
+	{ .compatible = "qcom,msm8916-pinctrl" },
+	{ }
+};
+
+U_BOOT_DRIVER(gpio_msm) = {
+	.name	= "gpio_msm",
+	.id	= UCLASS_GPIO,
+	.of_match = msm_gpio_ids,
+	.ofdata_to_platdata = msm_gpio_ofdata_to_platdata,
+	.probe	= msm_gpio_probe,
+	.ops	= &gpio_msm_ops,
+	.priv_auto_alloc_size = sizeof(struct msm_gpio_bank),
+};
+
+
-- 
2.5.0

  parent reply	other threads:[~2015-12-10 21:41 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-10 21:41 [U-Boot] [RFC PATCH 00/11] Add support for 96boards Dragonboard410C board Mateusz Kulikowski
2015-12-10 21:41 ` [U-Boot] [RFC PATCH 01/11] serial: Add support for Qualcomm serial port Mateusz Kulikowski
2015-12-15 18:58   ` Simon Glass
2015-12-16 22:19     ` Mateusz Kulikowski
2015-12-21  6:50     ` Masahiro Yamada
2015-12-22 20:23       ` Simon Glass
2015-12-23  3:52         ` Masahiro Yamada
2015-12-27 16:51           ` Mateusz Kulikowski
2015-12-28 17:09             ` Masahiro Yamada
2015-12-28  4:29           ` Simon Glass
2015-12-28 17:13             ` Masahiro Yamada
2015-12-10 21:41 ` Mateusz Kulikowski [this message]
2015-12-15 18:58   ` [U-Boot] [RFC PATCH 02/11] gpio: Add support for Qualcomm gpio controller Simon Glass
2015-12-10 21:41 ` [U-Boot] [RFC PATCH 03/11] mmc: Add support for Qualcomm SDHCI controller Mateusz Kulikowski
2015-12-15 18:58   ` Simon Glass
2015-12-16 22:46     ` Mateusz Kulikowski
2015-12-18 22:41       ` Simon Glass
2015-12-19 11:21         ` Mateusz Kulikowski
2015-12-10 21:41 ` [U-Boot] [RFC PATCH 04/11] ehci-hcd: Add init_after_reset Mateusz Kulikowski
2015-12-10 23:14   ` Marek Vasut
2015-12-16 22:30   ` Tom Rini
2015-12-10 21:41 ` [U-Boot] [RFC PATCH 05/11] ehci: Add support for Qualcomm EHCI Mateusz Kulikowski
2015-12-10 23:22   ` Marek Vasut
2015-12-13 12:38     ` Mateusz Kulikowski
2015-12-13 15:48       ` Marek Vasut
2015-12-16 22:51         ` Mateusz Kulikowski
2015-12-10 21:41 ` [U-Boot] [RFC PATCH 06/11] drivers: Add SPMI bus uclass Mateusz Kulikowski
2015-12-15 18:58   ` Simon Glass
2015-12-16 23:09     ` Mateusz Kulikowski
2015-12-10 21:41 ` [U-Boot] [RFC PATCH 07/11] drivers: spmi: Add support for Qualcomm SPMI bus driver Mateusz Kulikowski
2015-12-10 21:41 ` [U-Boot] [RFC PATCH 08/11] pmic: Add support for Qualcomm PM8916 PMIC Mateusz Kulikowski
2015-12-15 18:58   ` Simon Glass
2015-12-10 21:41 ` [U-Boot] [RFC PATCH 09/11] gpio: Add support for Qualcomm PM8916 gpios Mateusz Kulikowski
2015-12-15 18:58   ` Simon Glass
2015-12-10 21:41 ` [U-Boot] [RFC PATCH 10/11] arm: Add support for Qualcomm Snapdragon family Mateusz Kulikowski
2015-12-16 22:29   ` Simon Glass
2015-12-19 12:12     ` Mateusz Kulikowski
2015-12-10 21:41 ` [U-Boot] [RFC PATCH 11/11] board: Add Qualcomm Dragonboard 410C support Mateusz Kulikowski
2015-12-16 22:29   ` Simon Glass
2015-12-19 12:24     ` Mateusz Kulikowski
2015-12-19 20:29       ` Simon Glass
2015-12-15 18:57 ` [U-Boot] [RFC PATCH 00/11] Add support for 96boards Dragonboard410C board sk.syed2
2015-12-15 21:25   ` Mateusz Kulikowski

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=1449783707-23594-3-git-send-email-mateusz.kulikowski@gmail.com \
    --to=mateusz.kulikowski@gmail.com \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.