From patchwork Wed Apr 6 12:34:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keguang Zhang X-Patchwork-Id: 8762061 Return-Path: X-Original-To: patchwork-dmaengine@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B60EE9FC89 for ; Wed, 6 Apr 2016 12:36:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B15EB201DD for ; Wed, 6 Apr 2016 12:36:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4CEA9201FA for ; Wed, 6 Apr 2016 12:36:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932277AbcDFMgJ (ORCPT ); Wed, 6 Apr 2016 08:36:09 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:34712 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933026AbcDFMgE (ORCPT ); Wed, 6 Apr 2016 08:36:04 -0400 Received: by mail-pf0-f195.google.com with SMTP id d184so4149466pfc.1; Wed, 06 Apr 2016 05:36:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=JC7zsajJLXSVzpUQTYhQ0oE2RTby2CvnAHzZ+a88xlU=; b=n/HPgChfuzjKa5IpS+5CCW43EDXRzmoHpVuB0mQUZFq5tV7BC5ooYbi++804J2DRNZ 2JAjk0V2OXZvWVP3C+1rtrlM09so3CALYTSpxLpz8QhHWXu/1ESIklZeRoIRMZ/joscH lNKXNoI2ncIGCw6Q3tkuoALNrn8rMa2GiWi1k+CoBwimCRpJ3tpzGT8lQbFeN0ncH1BR fYm12gW4gqn845su7ji3GcktqtrnuZMAhq2Ha4Y7+qQVJ4zA5u0zjKKTZdNi79ci0KIA TYJJxt2jKueDSM5qaJeKfMUa3nYqpWNCs2ymbmUf+eV9E9Uy0FLqm6XuSqeyJkNMUBNC +SMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=JC7zsajJLXSVzpUQTYhQ0oE2RTby2CvnAHzZ+a88xlU=; b=FGf2bnoufW3muy/EakojLdWkzLbkfUWeqZnPhIZc8R8CwG+XWkButN2jGzCYnYmYpH 4kYiox57we7Dy73n6s+aMunl3ARcuZlSmPasJAxAIHSBTJnK3BETHx4OKSA7clYqQuaN lli3OfTk8OHDLBQ/KG87hjcjn9SkjTXg+ayEJ8x8ymEynEsLRjwGIQTTd9TxiioJ5vxn n/tdxLaV+1M8tJOGgc0VHxSHCfb4qyKwzCTL4Z4MxrEEoui4w8FIZk0dW6cl4Z3DHDQM RoVhl9/2J3L1sjd5D4UZnrfWZPbX+j3nBokDlbIELq/eYvmEWhTUhf1SMKJ9dms2RSjH um5g== X-Gm-Message-State: AD7BkJKlC3bonDhuAOJDUux0srM69E9eB4MwctbVBunaYUArHYrIQSFj64xVodSTrN0sIg== X-Received: by 10.98.10.29 with SMTP id s29mr38496860pfi.166.1459946163687; Wed, 06 Apr 2016 05:36:03 -0700 (PDT) Received: from localhost.localdomain ([175.111.195.49]) by smtp.gmail.com with ESMTPSA id 27sm4851789pfo.58.2016.04.06.05.35.57 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 06 Apr 2016 05:36:02 -0700 (PDT) From: Keguang Zhang To: linux-mips@linux-mips.org, linux-clk@vger.kernel.org, linux-pm@vger.kernel.org, dmaengine@vger.kernel.org, linux-gpio@vger.kernel.org, linux-mtd@lists.infradead.org Cc: Ralf Baechle , Michael Turquette , Stephen Boyd , "Rafael J. Wysocki" , Viresh Kumar , Vinod Koul , Dan Williams , Linus Walleij , Alexandre Courbot , Boris Brezillon , Richard Weinberger , David Woodhouse , Brian Norris , Kelvin Cheung Subject: [PATCH V1 5/7] gpio: Loongson1: add Loongson1 GPIO driver Date: Wed, 6 Apr 2016 20:34:53 +0800 Message-Id: <1459946095-7637-6-git-send-email-keguang.zhang@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1459946095-7637-1-git-send-email-keguang.zhang@gmail.com> References: <1459946095-7637-1-git-send-email-keguang.zhang@gmail.com> Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Kelvin Cheung This patch adds GPIO driver for Loongson1B. Signed-off-by: Kelvin Cheung --- drivers/gpio/Kconfig | 7 +++ drivers/gpio/Makefile | 1 + drivers/gpio/gpio-loongson1.c | 102 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 drivers/gpio/gpio-loongson1.c diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 5f3429f..373b8a7 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -510,6 +510,13 @@ config GPIO_ZX help Say yes here to support the GPIO device on ZTE ZX SoCs. +config GPIO_LOONGSON1 + tristate "Loongson1 GPIO support" + depends on MACH_LOONGSON32 + select GPIO_GENERIC + help + Say Y or M here to support GPIO on Loongson1 SoCs. + endmenu menu "Port-mapped I/O GPIO drivers" diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index 1e0b74f..40ab913 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile @@ -127,3 +127,4 @@ obj-$(CONFIG_GPIO_XTENSA) += gpio-xtensa.o obj-$(CONFIG_GPIO_ZEVIO) += gpio-zevio.o obj-$(CONFIG_GPIO_ZYNQ) += gpio-zynq.o obj-$(CONFIG_GPIO_ZX) += gpio-zx.o +obj-$(CONFIG_GPIO_LOONGSON1) += gpio-loongson1.o diff --git a/drivers/gpio/gpio-loongson1.c b/drivers/gpio/gpio-loongson1.c new file mode 100644 index 0000000..10c09bd --- /dev/null +++ b/drivers/gpio/gpio-loongson1.c @@ -0,0 +1,102 @@ +/* + * GPIO Driver for Loongson 1 SoC + * + * Copyright (C) 2015-2016 Zhang, Keguang + * + * This file is licensed under the terms of the GNU General Public + * License version 2. This program is licensed "as is" without any + * warranty of any kind, whether express or implied. + */ + +#include +#include + +/* Loongson 1 GPIO Register Definitions */ +#define GPIO_CFG 0x0 +#define GPIO_DIR 0x10 +#define GPIO_DATA 0x20 +#define GPIO_OUTPUT 0x30 + +static void __iomem *gpio_reg_base; + +static int ls1x_gpio_request(struct gpio_chip *gc, unsigned int offset) +{ + unsigned long pinmask = gc->pin2mask(gc, offset); + unsigned long flags; + + spin_lock_irqsave(&gc->bgpio_lock, flags); + __raw_writel(__raw_readl(gpio_reg_base + GPIO_CFG) | pinmask, + gpio_reg_base + GPIO_CFG); + spin_unlock_irqrestore(&gc->bgpio_lock, flags); + + return 0; +} + +static void ls1x_gpio_free(struct gpio_chip *gc, unsigned int offset) +{ + unsigned long pinmask = gc->pin2mask(gc, offset); + unsigned long flags; + + spin_lock_irqsave(&gc->bgpio_lock, flags); + __raw_writel(__raw_readl(gpio_reg_base + GPIO_CFG) & ~pinmask, + gpio_reg_base + GPIO_CFG); + spin_unlock_irqrestore(&gc->bgpio_lock, flags); +} + +static int ls1x_gpio_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct gpio_chip *gc; + struct resource *res; + int ret; + + gc = devm_kzalloc(dev, sizeof(*gc), GFP_KERNEL); + if (!gc) + return -ENOMEM; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) { + dev_err(dev, "failed to get I/O memory\n"); + return -EINVAL; + } + + gpio_reg_base = devm_ioremap_resource(dev, res); + if (IS_ERR(gpio_reg_base)) + return PTR_ERR(gpio_reg_base); + + ret = bgpio_init(gc, dev, 4, gpio_reg_base + GPIO_DATA, + gpio_reg_base + GPIO_OUTPUT, NULL, + NULL, gpio_reg_base + GPIO_DIR, 0); + if (ret) + goto err; + + gc->owner = THIS_MODULE; + gc->request = ls1x_gpio_request; + gc->free = ls1x_gpio_free; + gc->base = pdev->id * 32; + + ret = devm_gpiochip_add_data(dev, gc, NULL); + if (ret) + goto err; + + platform_set_drvdata(pdev, gc); + dev_info(dev, "Loongson1 GPIO driver registered\n"); + + return 0; +err: + dev_err(dev, "failed to register GPIO device\n"); + return ret; +} + +static struct platform_driver ls1x_gpio_driver = { + .probe = ls1x_gpio_probe, + .driver = { + .name = "ls1x-gpio", + }, +}; + +module_platform_driver(ls1x_gpio_driver); + +MODULE_AUTHOR("Kelvin Cheung "); +MODULE_DESCRIPTION("Loongson1 GPIO driver"); +MODULE_LICENSE("GPL");