From: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
To: linus.walleij@linaro.org, robh+dt@kernel.org, afaerber@suse.de
Cc: liuwei@actions-semi.com, mp-cs@actions-semi.com,
96boards@ucrobotics.com, devicetree@vger.kernel.org,
andy.shevchenko@gmail.com, daniel.thompson@linaro.org,
amit.kucheria@linaro.org, linux-arm-kernel@lists.infradead.org,
linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
hzhang@ucrobotics.com, bdong@ucrobotics.com,
manivannanece23@gmail.com,
Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Subject: [PATCH v6 7/9] gpio: Add gpio driver for Actions OWL S900 SoC
Date: Wed, 28 Mar 2018 23:17:01 +0530 [thread overview]
Message-ID: <20180328174703.19778-8-manivannan.sadhasivam@linaro.org> (raw)
In-Reply-To: <20180328174703.19778-1-manivannan.sadhasivam@linaro.org>
Add gpio driver for Actions Semi OWL family S900 SoC. Set of registers
controlling the gpio shares the same register range with pinctrl block.
GPIO registers are organized as 6 banks and each bank controls the
maximum of 32 gpios.
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
---
drivers/gpio/Kconfig | 8 +++
drivers/gpio/Makefile | 1 +
drivers/gpio/gpio-owl.c | 168 ++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 177 insertions(+)
create mode 100644 drivers/gpio/gpio-owl.c
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 8dbb2280538d..75533f55ad0e 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -364,6 +364,14 @@ config GPIO_OMAP
help
Say yes here to enable GPIO support for TI OMAP SoCs.
+config GPIO_OWL
+ tristate "Actions Semi OWL GPIO support"
+ default ARCH_ACTIONS
+ depends on ARCH_ACTIONS || COMPILE_TEST
+ depends on OF_GPIO
+ help
+ Say yes here to enable GPIO support for Actions Semi OWL SoCs.
+
config GPIO_PL061
bool "PrimeCell PL061 GPIO support"
depends on ARM_AMBA
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index cccb0d40846c..b2bb11d4675f 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -91,6 +91,7 @@ obj-$(CONFIG_GPIO_MXC) += gpio-mxc.o
obj-$(CONFIG_GPIO_MXS) += gpio-mxs.o
obj-$(CONFIG_GPIO_OCTEON) += gpio-octeon.o
obj-$(CONFIG_GPIO_OMAP) += gpio-omap.o
+obj-$(CONFIG_GPIO_OWL) += gpio-owl.o
obj-$(CONFIG_GPIO_PCA953X) += gpio-pca953x.o
obj-$(CONFIG_GPIO_PCF857X) += gpio-pcf857x.o
obj-$(CONFIG_GPIO_PCH) += gpio-pch.o
diff --git a/drivers/gpio/gpio-owl.c b/drivers/gpio/gpio-owl.c
new file mode 100644
index 000000000000..459ebcdd9174
--- /dev/null
+++ b/drivers/gpio/gpio-owl.c
@@ -0,0 +1,168 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * OWL SoC's GPIO driver
+ *
+ * Copyright (c) 2018 Linaro Ltd.
+ * Author: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
+ */
+
+#include <linux/bitops.h>
+#include <linux/err.h>
+#include <linux/gpio/driver.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/of_address.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+
+#define GPIO_OUTEN 0x0000
+#define GPIO_INEN 0x0004
+#define GPIO_DAT 0x0008
+
+struct owl_gpio {
+ struct gpio_chip gpio;
+ void __iomem *base;
+};
+
+static void owl_gpio_update_reg(void __iomem *base, unsigned int pin, int flag)
+{
+ u32 val;
+
+ val = readl_relaxed(base);
+
+ if (flag)
+ val |= BIT(pin);
+ else
+ val &= ~BIT(pin);
+
+ writel_relaxed(val, base);
+}
+
+static int owl_gpio_request(struct gpio_chip *chip, unsigned int offset)
+{
+ struct owl_gpio *gpio = gpiochip_get_data(chip);
+
+ /*
+ * GPIOs have higher priority over other modules, so either setting
+ * them as OUT or IN is sufficient
+ */
+ owl_gpio_update_reg(gpio->base + GPIO_OUTEN, offset, true);
+
+ return 0;
+}
+
+static void owl_gpio_free(struct gpio_chip *chip, unsigned int offset)
+{
+ struct owl_gpio *gpio = gpiochip_get_data(chip);
+
+ /* disable gpio output */
+ owl_gpio_update_reg(gpio->base + GPIO_OUTEN, offset, false);
+
+ /* disable gpio input */
+ owl_gpio_update_reg(gpio->base + GPIO_INEN, offset, false);
+}
+
+static int owl_gpio_get(struct gpio_chip *chip, unsigned int offset)
+{
+ struct owl_gpio *gpio = gpiochip_get_data(chip);
+ u32 val;
+
+ val = readl_relaxed(gpio->base + GPIO_DAT);
+
+ return !!(val & BIT(offset));
+}
+
+static void owl_gpio_set(struct gpio_chip *chip, unsigned int offset, int value)
+{
+ struct owl_gpio *gpio = gpiochip_get_data(chip);
+
+ owl_gpio_update_reg(gpio->base + GPIO_DAT, offset, value);
+}
+
+static int owl_gpio_direction_input(struct gpio_chip *chip, unsigned int offset)
+{
+ struct owl_gpio *gpio = gpiochip_get_data(chip);
+
+ owl_gpio_update_reg(gpio->base + GPIO_OUTEN, offset, false);
+ owl_gpio_update_reg(gpio->base + GPIO_INEN, offset, true);
+
+ return 0;
+}
+
+static int owl_gpio_direction_output(struct gpio_chip *chip,
+ unsigned int offset, int value)
+{
+ struct owl_gpio *gpio = gpiochip_get_data(chip);
+
+ owl_gpio_update_reg(gpio->base + GPIO_INEN, offset, false);
+ owl_gpio_update_reg(gpio->base + GPIO_OUTEN, offset, true);
+ owl_gpio_update_reg(gpio->base + GPIO_DAT, offset, value);
+
+ return 0;
+}
+
+static int owl_gpio_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct owl_gpio *gpio;
+ u32 ngpios;
+ int ret;
+
+ gpio = devm_kzalloc(dev, sizeof(*gpio), GFP_KERNEL);
+ if (!gpio)
+ return -ENOMEM;
+
+ gpio->base = of_iomap(dev->of_node, 0);
+ if (IS_ERR(gpio->base))
+ return PTR_ERR(gpio->base);
+
+ /*
+ * Get the number of gpio's for this bank. If none specified,
+ * then fall back to 32.
+ */
+ ret = of_property_read_u32(dev->of_node, "ngpios", &ngpios);
+ if (ret)
+ ngpios = 32;
+
+ gpio->gpio.request = owl_gpio_request;
+ gpio->gpio.free = owl_gpio_free;
+ gpio->gpio.get = owl_gpio_get;
+ gpio->gpio.set = owl_gpio_set;
+ gpio->gpio.direction_input = owl_gpio_direction_input;
+ gpio->gpio.direction_output = owl_gpio_direction_output;
+
+ gpio->gpio.base = -1;
+ gpio->gpio.parent = dev;
+ gpio->gpio.label = dev_name(dev);
+ gpio->gpio.ngpio = ngpios;
+
+ platform_set_drvdata(pdev, gpio);
+
+ ret = devm_gpiochip_add_data(dev, &gpio->gpio, gpio);
+ if (ret < 0) {
+ dev_err(&pdev->dev, "Failed to register gpiochip\n");
+ return ret;
+ }
+
+ return 0;
+}
+
+static const struct of_device_id owl_gpio_of_match[] = {
+ { .compatible = "actions,s900-gpio", },
+ { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, owl_gpio_of_match);
+
+static struct platform_driver owl_gpio_driver = {
+ .driver = {
+ .name = "owl-gpio",
+ .of_match_table = owl_gpio_of_match,
+ },
+ .probe = owl_gpio_probe
+};
+module_platform_driver(owl_gpio_driver);
+
+MODULE_AUTHOR("Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>");
+MODULE_DESCRIPTION("Actions Semi OWL SoCs GPIO driver");
+MODULE_LICENSE("GPL");
--
2.14.1
next prev parent reply other threads:[~2018-03-28 17:54 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-28 17:46 [PATCH v6 0/9] Add Actions Semi S900 pinctrl and gpio support Manivannan Sadhasivam
2018-03-28 17:46 ` [PATCH v6 1/9] arm64: dts: actions: Add pinctrl node for S900 Manivannan Sadhasivam
2018-03-28 17:46 ` [PATCH v6 2/9] arm64: actions: Enable PINCTRL in platforms Kconfig Manivannan Sadhasivam
2018-03-28 17:46 ` [PATCH v6 3/9] pinctrl: actions: Add Actions S900 pinctrl driver Manivannan Sadhasivam
2018-03-30 21:16 ` Andy Shevchenko
2018-04-03 17:00 ` Manivannan Sadhasivam
2018-04-03 17:03 ` Andreas Färber
2018-04-03 17:14 ` Manivannan Sadhasivam
2018-04-06 14:01 ` Andy Shevchenko
2018-03-28 17:46 ` [PATCH v6 4/9] dt-bindings: gpio: Add gpio nodes for Actions S900 SoC Manivannan Sadhasivam
2018-04-12 8:54 ` Linus Walleij
2018-03-28 17:46 ` [PATCH v6 5/9] arm64: dts: actions: Add S900 gpio nodes Manivannan Sadhasivam
2018-03-28 17:47 ` [PATCH v6 6/9] arm64: dts: actions: Add gpio line names to Bubblegum-96 board Manivannan Sadhasivam
2018-03-28 17:47 ` Manivannan Sadhasivam [this message]
2018-03-30 21:04 ` [PATCH v6 7/9] gpio: Add gpio driver for Actions OWL S900 SoC Andy Shevchenko
2018-03-28 17:47 ` [PATCH v6 8/9] MAINTAINERS: Add reviewer for ACTIONS platforms Manivannan Sadhasivam
2018-03-28 17:47 ` [PATCH v6 9/9] MAINTAINERS: Add Actions Semi S900 pinctrl and gpio entries Manivannan Sadhasivam
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=20180328174703.19778-8-manivannan.sadhasivam@linaro.org \
--to=manivannan.sadhasivam@linaro.org \
--cc=96boards@ucrobotics.com \
--cc=afaerber@suse.de \
--cc=amit.kucheria@linaro.org \
--cc=andy.shevchenko@gmail.com \
--cc=bdong@ucrobotics.com \
--cc=daniel.thompson@linaro.org \
--cc=devicetree@vger.kernel.org \
--cc=hzhang@ucrobotics.com \
--cc=linus.walleij@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liuwei@actions-semi.com \
--cc=manivannanece23@gmail.com \
--cc=mp-cs@actions-semi.com \
--cc=robh+dt@kernel.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;
as well as URLs for NNTP newsgroup(s).