From patchwork Wed Apr 4 17:22:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 132828 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp5308478ljb; Wed, 4 Apr 2018 10:25:15 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+Zba0aInEbKlQZehTNDqiaCT2oWXpIoQSOO4S6y8tspjH69EZRN9O8Z4wltogVhkdl6zvl X-Received: by 10.101.98.196 with SMTP id m4mr1218291pgv.329.1522862715769; Wed, 04 Apr 2018 10:25:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522862715; cv=none; d=google.com; s=arc-20160816; b=IZr+cLoayMAT3+3mULpcHaE8fqhVOJxVrRq9vmsko41AfryLvr8NWIpiq/FByH7N0v 4na7MwLFCqY0FGYnuJR8kPuVdtxJGq007nGOqft8xVCb6d5cCSlmIrhxi1UX1HXYqDe8 9CwepWtFnPRgbQUsBIy1gvlqOBg2HmEU5+zaQbrXLsfhP4SDpfaB2wrysyd9dQUhO/dc nKiA55EDmpOAS3a77Zx0G/AAERtH5diwL0cFy2IjYkVCN1+FezILw+77wWZFSAjflGJA AtoudTznsFVr6++6mnEzr6kCCYM4ownqBqGpB5txpOHXh1srvbZR0j1M0w8e9m9ODQA4 Cafg== 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=79fkHFqwafWO4Y9s6ATm0Hzlv8D96ZrA+UGwyt1AFXU=; b=iuXyOoO3Ebt+ryG7vK0m1NbPYIfzWoWAhjZqktdQx6aHHkv8mYQwRl6nlyahmhyYdp hXU/yMR3GKiiDFUWo5ioO/OObgfRZ02VIBvSFz1aKInPUEqnd5l3M7dqyY51ypJHEdqw wsbzouOxHNe2gA+nMXVX2rZiq9IJivWEIsnmoeFf9lUjkPDjA1U1iPCA0Z6dpYsgakUN jSKu4FSZN2e/WwxKbTiRtYxS+OSsQlakNUJJbTESXsHvAP4B/TBURrkCfMucURJQ5vSL w2br6B4OLNJpa7X0yEoRyAB5mJVNX3TV7cAmUoIHHIRyKqnL/2pAr18DcwJBCnrnbe1C 2fQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QhU9ay69; 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 k14si3925946pgt.32.2018.04.04.10.25.15; Wed, 04 Apr 2018 10:25:15 -0700 (PDT) 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=QhU9ay69; 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 S1751813AbeDDRZN (ORCPT + 29 others); Wed, 4 Apr 2018 13:25:13 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:40173 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751713AbeDDRZJ (ORCPT ); Wed, 4 Apr 2018 13:25:09 -0400 Received: by mail-pl0-f67.google.com with SMTP id x4-v6so14978352pln.7 for ; Wed, 04 Apr 2018 10:25:08 -0700 (PDT) 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=79fkHFqwafWO4Y9s6ATm0Hzlv8D96ZrA+UGwyt1AFXU=; b=QhU9ay691jOSRUiZb+lS1n+FUTK+EqEsOYGja3mDJLlKfvXNXLpqWLCWVKxUHoXaI/ ZygTGgC/Z/SWnrPdGFDyDj5mqMoctN6VXnNQbEoHmBIC3+46G5LWGAb1zjGpPvmN/B1w 3Jt2w+tt7tEHUei+3WdYkxkvE6bAxPw33SFkY= 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=79fkHFqwafWO4Y9s6ATm0Hzlv8D96ZrA+UGwyt1AFXU=; b=lUmn475UVD6G7Zjc4pYL2op5ZFcT6ZH7t8cPOb9whb76kmxVixkvYBw22fMIIOIp3F omFYHnPC8WR00EDGCOExlYzReR5dBH0ae3GZUOjT4vLZTfurzhD+eGm4uOizeGMq+xog 9t77kur8c6N/WKS3P+Zk2WCLdPgzRxDdNZQSczrEIOuFfJdDJwOz73ppKGvDG6e3N48D MpEQJPTd/NPjtgukLt+E0em28zeum+AYUsmtPsM7wugL2xYeyrVL+ko6ku+rzy7vrjgC Wbc+ZF3dKp1tHlBFLKwpTEMKFVKXd6ybtwrkFHDORENpHLxFS+DqgtLOLdhM/8Hqw5/d N93A== X-Gm-Message-State: AElRT7GXiMcmJ7XBZ2Mmpmezj9wuhxJ1Gn8QNw0dJvZzRKzncZ1gci6V c1SSHenx/iBhmxlZbYPN3nEY X-Received: by 2002:a17:902:9308:: with SMTP id bc8-v6mr19429209plb.189.1522862708465; Wed, 04 Apr 2018 10:25:08 -0700 (PDT) Received: from localhost.localdomain ([2405:204:730d:2b78:a8cb:9f26:6eed:eba5]) by smtp.gmail.com with ESMTPSA id t5sm10791384pgr.69.2018.04.04.10.25.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Apr 2018 10:25:07 -0700 (PDT) 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 v7 7/9] gpio: Add gpio driver for Actions OWL S900 SoC Date: Wed, 4 Apr 2018 22:52:56 +0530 Message-Id: <20180404172258.7678-8-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180404172258.7678-1-manivannan.sadhasivam@linaro.org> References: <20180404172258.7678-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 | 184 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 193 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..354636229fee --- /dev/null +++ b/drivers/gpio/gpio-owl.c @@ -0,0 +1,184 @@ +// 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 +#include + +#define GPIO_OUTEN 0x0000 +#define GPIO_INEN 0x0004 +#define GPIO_DAT 0x0008 + +struct owl_gpio { + struct gpio_chip gpio; + void __iomem *base; + spinlock_t lock; +}; + +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 + */ + spin_lock(&gpio->lock); + owl_gpio_update_reg(gpio->base + GPIO_OUTEN, offset, true); + spin_unlock(&gpio->lock); + + return 0; +} + +static void owl_gpio_free(struct gpio_chip *chip, unsigned int offset) +{ + struct owl_gpio *gpio = gpiochip_get_data(chip); + + spin_lock(&gpio->lock); + /* 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); + spin_unlock(&gpio->lock); +} + +static int owl_gpio_get(struct gpio_chip *chip, unsigned int offset) +{ + struct owl_gpio *gpio = gpiochip_get_data(chip); + u32 val; + + spin_lock(&gpio->lock); + val = readl_relaxed(gpio->base + GPIO_DAT); + spin_unlock(&gpio->lock); + + 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); + + spin_lock(&gpio->lock); + owl_gpio_update_reg(gpio->base + GPIO_DAT, offset, value); + spin_unlock(&gpio->lock); +} + +static int owl_gpio_direction_input(struct gpio_chip *chip, unsigned int offset) +{ + struct owl_gpio *gpio = gpiochip_get_data(chip); + + spin_lock(&gpio->lock); + owl_gpio_update_reg(gpio->base + GPIO_OUTEN, offset, false); + owl_gpio_update_reg(gpio->base + GPIO_INEN, offset, true); + spin_unlock(&gpio->lock); + + 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); + + spin_lock(&gpio->lock); + 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); + spin_unlock(&gpio->lock); + + 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; + + spin_lock_init(&gpio->lock); + + 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");