From patchwork Fri Mar 9 05:13:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 131083 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp573615lja; Thu, 8 Mar 2018 21:15:48 -0800 (PST) X-Google-Smtp-Source: AG47ELs5vfQr6KsSfqiXgQFEQVArfwUpAaEUoQiu+lb0xEqmS0Bk3rf6ncK95NmcP8h+OFXKRVPj X-Received: by 10.98.34.143 with SMTP id p15mr28984201pfj.101.1520572548540; Thu, 08 Mar 2018 21:15:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520572548; cv=none; d=google.com; s=arc-20160816; b=O9hUYwKq6fizJwyLAGryBPTHLOdTrWQFHNeQhU3ERmwDNQwT/MsQfN8N67IDIWIdPW p1VPhyrHhlSTW/P3WdVHeCQvczTsa/NFT2z8h5ZrynFftY+CI/V0PbgfZIl9XW6K2V7u EY/jKLjxB825K98SZIHRcXot3ow5jOIUfNuhphtTAuBfulAQQ6n9cDrImXAKpgcNibXL 2cK/XpSEIvQ+xKMMBzdqJXj46/X7GWFk0M81dIdbmxTS2rcKZUAhcI9jAP54ERgi+Oif 3QZzTU4bMIMrFd+dwxXT2qdnGNQtUDuPIyg7lhpP8A5GJcA/Ca2OecdzEkOcnUmYRgn6 rAJg== 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=7CDeGfke3BImfWDYxP/TBd10Lc9R129+KC0JLqbCR9I=; b=rDhpjKr1UbxImt/vRm5UcSOyZREIhKbOjusgLXHnXBzTz/t82TzWFSnRwpoF9gbcLt dbTVeYTBsKZVrJXvImLl/vtVBQkLuYdAohL278FkuMXesF2pWFnIo1tjfONkErGEhvei m9jf0jnPyUq5BDWSB//ZBROkF8IQaozVJPLIolNqOKpbW7ZJJYWGD9t+fH32cJFyy6ms Kv4Ux9ktOFhzbTYim3VxhS/Nf5I193OBpZ5wGD3ur3G3JDUhyXUVB8I3mn6mjI8WSfoC K7gHEeJ0Hn71FAwiOgRCWHDIC9R6YQqW8HqBCcuzK1Oj9MA8n4Bu0+tx6XKqFCL8FPYf kTWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=d6Oxn8W2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (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 5si252941pfx.208.2018.03.08.21.15.48; Thu, 08 Mar 2018 21:15:48 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=d6Oxn8W2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932124AbeCIFPp (ORCPT + 28 others); Fri, 9 Mar 2018 00:15:45 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:33227 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932099AbeCIFPm (ORCPT ); Fri, 9 Mar 2018 00:15:42 -0500 Received: by mail-pg0-f66.google.com with SMTP id g12so3181321pgs.0 for ; Thu, 08 Mar 2018 21:15:41 -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=7CDeGfke3BImfWDYxP/TBd10Lc9R129+KC0JLqbCR9I=; b=d6Oxn8W2yGMzy1viHgcRD3TnTNanyP8z222OTrLVHSZOLqppKrsXPSoqMFnNoUlNrY NJ64kakckulbK4yK7eNRsn3ItakFYSBLh3J5qFn/QJe9n6+drSeHtAGqhohdJt6/xs7S FSPhgow9ZVNw4nIEQ01a4rrpSZhaRFTyukkmk= 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=7CDeGfke3BImfWDYxP/TBd10Lc9R129+KC0JLqbCR9I=; b=t/0tlOj5R9nQXeep5lRPemPN+TxbDi60zawlqepSVaTItFt2TTLfpW4ePKK5M0iQt/ i4xxYpLt9oF8ljqFo6aQgVNrcxOtW9t31AWl9e/eCrwf36cgozJZTZUHusXVOeScGjkm +TKGl/CXuY0TOscxSvtNGRa7Bj6OC+KJLGa7pQuRV4fsx93WjKtvsLtVcayW4S0TpBvG mLuPWMvLMv8sgmR7NW9iAkmE92drENEd8R1Zhgyhj/CsnEU2xWT34p4LajJRrIF67jXF NuvrsU2L2A0hLih6bvnlznhuI9LO7h3rymW80fEeH0+UkdMt+mLvnCyhk4cEHXHH1C2d bxWg== X-Gm-Message-State: APf1xPAxUDoOKc8cVBg5Us/NlmIuegY4HuAcAhO2O6R3MvB46nZCQgDb e4fH1aWNQ6gKKAhAvdY4PMoN X-Received: by 10.101.75.140 with SMTP id t12mr23866711pgq.442.1520572541370; Thu, 08 Mar 2018 21:15:41 -0800 (PST) Received: from localhost.localdomain ([2405:204:7081:af21:ac40:fc54:f562:4008]) by smtp.gmail.com with ESMTPSA id i186sm635182pfg.25.2018.03.08.21.15.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Mar 2018 21:15:40 -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, 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 Subject: [PATCH v5 7/9] gpio: Add gpio driver for Actions OWL S900 SoC Date: Fri, 9 Mar 2018 10:43:43 +0530 Message-Id: <20180309051345.1011-8-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180309051345.1011-1-manivannan.sadhasivam@linaro.org> References: <20180309051345.1011-1-manivannan.sadhasivam@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 Reviewed-by: Andy Shevchenko --- drivers/gpio/Kconfig | 8 +++ drivers/gpio/Makefile | 1 + drivers/gpio/gpio-owl.c | 172 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 181 insertions(+) create mode 100644 drivers/gpio/gpio-owl.c -- 2.14.1 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..38449586ecc7 --- /dev/null +++ b/drivers/gpio/gpio-owl.c @@ -0,0 +1,172 @@ +// 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 + +struct owl_gpio { + struct gpio_chip gpio; + void __iomem *base; +}; + +static void owl_gpio_set_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_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); + + /* 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); + 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); + u32 val; + + val = readl_relaxed(gpio->base + GPIO_DAT); + + if (value) + val |= BIT(offset); + else + val &= ~BIT(offset); + + writel_relaxed(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); + + 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); + + 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; +} + +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); + + ret = of_property_read_u32(dev->of_node, "ngpios", &ngpios); + if (ret) + return ret; + + 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 "); +MODULE_DESCRIPTION("Actions Semi OWL SoCs GPIO driver"); +MODULE_LICENSE("GPL");