From patchwork Wed Feb 21 16:00:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 129100 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp783667ljc; Wed, 21 Feb 2018 08:04:26 -0800 (PST) X-Google-Smtp-Source: AH8x226JPWoE0S+EJwcDIcQUs9Ddpj2fF4nK0TK3q5ssDzN2hAZJR//t3Tz7My7l2vr7TZdP3Csl X-Received: by 10.98.153.157 with SMTP id t29mr3784619pfk.201.1519229066391; Wed, 21 Feb 2018 08:04:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519229066; cv=none; d=google.com; s=arc-20160816; b=v1nKtyy5M8KlDjk6xk9fa8msjcjcCyPYioCSvD/8SLIsAF44fRvcZubFtARpnvefJQ znI2lrg3yyPwWxK2dEr9n8S/9LpgBq4NcQLKqCFLrbZGMCL70k75vRSIun7G0dz6kWoa TThq3qX91Si/5y5hfUDNLmrQFfZZ7fY68yRQQ99eOS8+eyMFTPc2ifpUvtcslQ4J56DP uq0ZzuMLU3PnSWpcaAXrmP1qyiz9qu2HLA9rqM8fvXTKbvXJ6nC2ZsDtc2JdoJjJukto d6wEyVNSNXC1/HPZErMymVf8JAkgbASCo25Qt8T0LOSkqPXOY5z0wvkzQzyt6piZVECj QFAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=tRROaHi4JgKlV4mQy153Gdkik8fj6lBSeNpt+UP9xjk=; b=EUzp9mZUdMK53a/cZxokb5Aw1AP7kuZqYsFdG/RrppPB2Wb1j/9+v7IRt6SxJuT2vQ rP01I1mTCxfF6b1p+HFyF6W6SaaD6CW8fRIK/UXybG6hOu00f5IHqWf0Ux/yS98/gWtZ jdVq1dK0G7V+vpuwxPw8TkRlMLCXQ6T5CECgqnNJtQFrG2/+wjBR5ofWxP0G2oEsH4cL e77rY6tMVqGKVUw2iy40/lGiU5KLOviqCbKHYPLL+mvVmYpnyoxX+iXE17OaoHz1Ibo9 /Ua6ovwWq/eYMxODWlGtEIzAReDZZFl3n4SBkEjcnwlMmZXujX1yHv2ZOznEnVsLbcYj PwFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=bj+bNPll; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k9si1345414pgo.42.2018.02.21.08.04.26; Wed, 21 Feb 2018 08:04:26 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=bj+bNPll; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934652AbeBUQEY (ORCPT + 6 others); Wed, 21 Feb 2018 11:04:24 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:46525 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966191AbeBUQD3 (ORCPT ); Wed, 21 Feb 2018 11:03:29 -0500 Received: by mail-pf0-f193.google.com with SMTP id z24so814477pfh.13 for ; Wed, 21 Feb 2018 08:03:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=9VUvw6ASmiGcXdK0Fr/Xz8hMRnF5k/TpJ9EiJPPHy88=; b=bj+bNPll7eP7Ge7mdJj0I6cZxFrZoHezvyCjiX9ofOwfxGqIlapFHkMez88CY2xV/5 qXkmNJFy5UIVObpTfDq8Q3v8owdGlF4JRa1W//R+RR0U3OAMhNYgUEJGj8G6k0gZ7zVv oHoFOxejh6ZX7QD0Uhb9GQRncY4f5yyCPoQK0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=9VUvw6ASmiGcXdK0Fr/Xz8hMRnF5k/TpJ9EiJPPHy88=; b=sSbEyLoal48WggSWTnpoCNpRoTCNZE5iLl1xREmphgPT/r/zKX0jhiwQog6a7oDHwY cV2C38EYQLcEpXULHbbTjCz5Sgquc6d7ZZTjS89YxoU6kCbvCIeeKvjqgwPlwAkTm95x jy8tTD7w5YlulDalCnV5fL6YAXmUazzgt2GZYSGXAX6PvZubH78lmH5OqBZw/KfYHRBS Era/3/2ybMUpAlVnYSKfIXnnod9KftWF41XgwO0ll9IMK45T+B8rwtM9rlTyFANeLCBb iWAS862co72TOpwts9oDUCNMBNcMV5iSBXmWnWMDS2JvH2PzWjB9P1Afi5jktlmx+miE JHcQ== X-Gm-Message-State: APf1xPDEn+Or+5raDWKE3VIy2bTBSN/O74SZjUp1JKSo4OJDGvOBQF/B vMXf/fNa9MrTsNDnjvDg+/JK X-Received: by 10.98.93.87 with SMTP id r84mr3761800pfb.131.1519229008087; Wed, 21 Feb 2018 08:03:28 -0800 (PST) Received: from localhost.localdomain ([2405:204:7346:6848:3cb8:23ad:d761:239e]) by smtp.gmail.com with ESMTPSA id s67sm43068910pfg.104.2018.02.21.08.03.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Feb 2018 08:03:27 -0800 (PST) From: Manivannan Sadhasivam 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, 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, Manivannan Sadhasivam Subject: [PATCH v2 08/10] gpio: Add gpio driver for Actions OWL S900 SoC Date: Wed, 21 Feb 2018 21:30:42 +0530 Message-Id: <20180221160044.15089-9-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180221160044.15089-1-manivannan.sadhasivam@linaro.org> References: <20180221160044.15089-1-manivannan.sadhasivam@linaro.org> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.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 --- drivers/gpio/Kconfig | 8 ++ drivers/gpio/Makefile | 1 + drivers/gpio/gpio-owl.c | 219 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 228 insertions(+) create mode 100644 drivers/gpio/gpio-owl.c -- 2.14.1 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 8dbb2280538d..09ceb98e2434 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 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 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..0464c08e0422 --- /dev/null +++ b/drivers/gpio/gpio-owl.c @@ -0,0 +1,219 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * OWL SoC's GPIO driver + * + * Copyright (c) 2018 Linaro Ltd. + * Author: Manivannan Sadhasivam + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define GPIO_OUTEN 0x0000 +#define GPIO_INEN 0x0004 +#define GPIO_DAT 0x0008 + +#define OWL_GPIO_PORT_A 0 +#define OWL_GPIO_PORT_B 1 +#define OWL_GPIO_PORT_C 2 +#define OWL_GPIO_PORT_D 3 +#define OWL_GPIO_PORT_E 4 +#define OWL_GPIO_PORT_F 5 + +struct owl_gpio_port { + const char *name; + unsigned int offset; + unsigned int pins; +}; + +struct owl_gpio { + struct gpio_chip gpio; + const struct owl_gpio_port *port; + void __iomem *base; + int id; +}; + +static void owl_gpio_set_reg(void __iomem *base, unsigned int pin, int flag) +{ + u32 val; + + if (flag) { + val = readl(base); + val |= BIT(pin); + writel(val, base); + } else { + val = readl(base); + val &= ~BIT(pin); + writel(val, base); + } +} + +static int owl_gpio_request(struct gpio_chip *chip, unsigned int offset) +{ + struct owl_gpio *gpio = gpiochip_get_data(chip); + const struct owl_gpio_port *port = gpio->port; + void __iomem *gpio_base = gpio->base + port->offset; + + /* + * GPIOs have higher priority over other modules, so either setting + * them as OUT or IN is sufficient + */ + owl_gpio_set_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); + const struct owl_gpio_port *port = gpio->port; + void __iomem *gpio_base = gpio->base + port->offset; + + /* disable gpio output */ + owl_gpio_set_reg(gpio_base + GPIO_OUTEN, offset, false); + + /* disable gpio input */ + owl_gpio_set_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); + const struct owl_gpio_port *port = gpio->port; + void __iomem *gpio_base = gpio->base + port->offset; + u32 val; + + val = readl(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); + const struct owl_gpio_port *port = gpio->port; + void __iomem *gpio_base = gpio->base + port->offset; + u32 val; + + val = readl(gpio_base + GPIO_DAT); + + if (value) + val |= BIT(offset); + else + val &= ~BIT(offset); + + writel(val, gpio_base + GPIO_DAT); +} + +static int owl_gpio_direction_input(struct gpio_chip *chip, unsigned int offset) +{ + struct owl_gpio *gpio = gpiochip_get_data(chip); + const struct owl_gpio_port *port = gpio->port; + void __iomem *gpio_base = gpio->base + port->offset; + + owl_gpio_set_reg(gpio_base + GPIO_OUTEN, offset, false); + owl_gpio_set_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); + const struct owl_gpio_port *port = gpio->port; + void __iomem *gpio_base = gpio->base + port->offset; + + owl_gpio_set_reg(gpio_base + GPIO_INEN, offset, false); + owl_gpio_set_reg(gpio_base + GPIO_OUTEN, offset, true); + owl_gpio_set(chip, offset, value); + + return 0; +} + +#define OWL_GPIO_PORT(port, base, count) \ + [OWL_GPIO_PORT_##port] = { \ + .name = #port, \ + .offset = base, \ + .pins = count, \ + } + +static const struct owl_gpio_port s900_gpio_ports[] = { + OWL_GPIO_PORT(A, 0x0000, 32), + OWL_GPIO_PORT(B, 0x000C, 32), + OWL_GPIO_PORT(C, 0x0018, 12), + OWL_GPIO_PORT(D, 0x0024, 30), + OWL_GPIO_PORT(E, 0x0030, 32), + OWL_GPIO_PORT(F, 0x00F0, 8), +}; + +static int owl_gpio_probe(struct platform_device *pdev) +{ + struct owl_gpio *gpio; + const struct owl_gpio_port *port; + int ret; + + gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); + if (!gpio) + return -ENOMEM; + + gpio->base = of_iomap(pdev->dev.of_node, 0); + if (IS_ERR(gpio->base)) + return PTR_ERR(gpio->base); + + gpio->id = of_alias_get_id(pdev->dev.of_node, "gpio"); + if (gpio->id < 0) + return gpio->id; + + port = &s900_gpio_ports[gpio->id]; + + 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 = &pdev->dev; + gpio->gpio.label = port->name; + gpio->gpio.ngpio = port->pins; + + gpio->port = port; + + platform_set_drvdata(pdev, gpio); + + ret = devm_gpiochip_add_data(&pdev->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 "); +MODULE_DESCRIPTION("Actions Semi OWL SoCs GPIO driver"); +MODULE_LICENSE("GPL");