Received: by 10.223.185.116 with SMTP id b49csp6514666wrg; Wed, 28 Feb 2018 10:40:40 -0800 (PST) X-Google-Smtp-Source: AG47ELuH5p+XjfGFq5xGqkFxDdUEzFKD9FkETmhmLkLC9fe5lkIK8bv4mNkNGtV0gwHn32hRW7X5 X-Received: by 2002:a17:902:7088:: with SMTP id z8-v6mr9898297plk.174.1519843240017; Wed, 28 Feb 2018 10:40:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519843239; cv=none; d=google.com; s=arc-20160816; b=aHjw2GN8dHor5heTQSu5WxLu/cUj0oVDS031AaF9lrHi0dXYRMa7m8UhJLbj150D1v qukXJ+u45upUPBWzM2MapUNefXZwOYOoo7qFt93xgiO5K0DFXExId3benM4ORebSDyme oFRmU2KksGurhIBsxzjCxfE0zJrcrF4b2tdGzCg7V9FQkpA9uaKojsRtIefvTOuxjvav G3rKpKFJhuDvSZrZjrig+BytP+H9pen3wFMR3XOmREjctN0r5jdTYex5XfwXyGPp0cby 15VyYYU/x6fcReQi2xZcrm3b2PoVcuIG6UTsK9s2t1V/XrcALoo5s6VwPmIhUUWv/+5E 5T8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=xbNzU1SepFTqe9h/BjUUVdhZFzfNuf2mAxi+jU3V1ms=; b=TkywMrSoIqALNKW7XNCWf8yiQ48chNk0VcvhsvhtN9YxzduKJErSPMA225LfwM4D3V jsDZi2SuYuc+Xr2hlca3FPDFigzjQoxpUIBAq0kX8eiWpHANaVdK+3xYZnc/JJmKRP94 QgzWov6gHv5t9toaQhqRpb7G3+khO3/Xk3mKYJrVDPcu6p3LEJaGWV0+KTmv3Hv4EQi0 5pP1FGhOFETO/vcUxJba0zEd4jwJEXde9Cd6I9KdBHVfA2P3ISsUeZQsQPx2ORjFvt8F EZxN/8rxlcNqP/1GbYTaZIsbIPxGMI7aRBTVIrOybFxuMwMLojsETcmK5+FBSIzbythD 8BfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JHzRQUWR; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 7-v6si362675plb.573.2018.02.28.10.40.24; Wed, 28 Feb 2018 10:40:39 -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=@gmail.com header.s=20161025 header.b=JHzRQUWR; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933034AbeB1Sjg (ORCPT + 99 others); Wed, 28 Feb 2018 13:39:36 -0500 Received: from mail-qk0-f195.google.com ([209.85.220.195]:36522 "EHLO mail-qk0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932851AbeB1Sjd (ORCPT ); Wed, 28 Feb 2018 13:39:33 -0500 Received: by mail-qk0-f195.google.com with SMTP id d206so4274404qkb.3; Wed, 28 Feb 2018 10:39:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=xbNzU1SepFTqe9h/BjUUVdhZFzfNuf2mAxi+jU3V1ms=; b=JHzRQUWR2WhobjdkmbrJxQ+GzaFPC1l5vhFYF7e+nKJJYD0shuR0In7fmFAVhPlLjZ fOwsZXZuk0TOmNtTO4KKY9QF9320IVzXlwyrtTi3met9AxzEE4afOLjF8BjKpP2287LL Xe6pjwZAcV3F8ZBthr/ez8R9POsQMOymx+ERis3ABEqzB+4Hldoz1CucJQ8W/S0wsdnW L3nI2Li0q8a0Zfr7KqutKn3pdL/NedgQCfgbDEijircg0DlepZP+DUL5B0+9+6OdB8CZ IM9GP7Mf1N9ohzfO7aoj6XqDIqrzCFoHkh0JqGi85FTRS3j1BP199N3KowUZePBLSYUJ KClg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=xbNzU1SepFTqe9h/BjUUVdhZFzfNuf2mAxi+jU3V1ms=; b=WESZiYuVxxy/2iOZXitBuYKt7i+/Sg2lL+CNdQiiEh/6s248CzdGnz3HxIOfo75m0a u5QTJ2+3Lq0MGgqjHMwYxpotdm6VvbQ+b3q94hqo7/BHrfi8fj+cKQXG4j91Hd1vMKb0 brugj5efk/hfPHOJm96C4Hh3locEJocaFY/598ZdslTyV+X8QYZPImTUwHgpMJf6QzaG 8ON7NWvF2SpJOXCF3MqyHoARrctpfkBsSv+hOwyEzz2rWgwDlv1QHtGn8+qcCqRhgVIn W5Hz0CmwVIVvDA5mDqNoSUeWUIdqa9YhwKWSSbUsjGa9kjyT9qIC0753wKzzkX7FUmbB tImA== X-Gm-Message-State: APf1xPBPXwAStMaZEpmyf4vuHn+qIZUfiQrDnD6f9HHb+N7rUV0cuntg WdO3dvOJECDWB1lYcTixOlBEVAsa7EdA4k4klCY= X-Received: by 10.55.15.147 with SMTP id 19mr28011663qkp.301.1519843172094; Wed, 28 Feb 2018 10:39:32 -0800 (PST) MIME-Version: 1.0 Received: by 10.12.195.80 with HTTP; Wed, 28 Feb 2018 10:39:31 -0800 (PST) In-Reply-To: <20180228181432.26847-9-manivannan.sadhasivam@linaro.org> References: <20180228181432.26847-1-manivannan.sadhasivam@linaro.org> <20180228181432.26847-9-manivannan.sadhasivam@linaro.org> From: Andy Shevchenko Date: Wed, 28 Feb 2018 20:39:31 +0200 Message-ID: Subject: Re: [PATCH v3 08/10] gpio: Add gpio driver for Actions OWL S900 SoC To: Manivannan Sadhasivam Cc: Linus Walleij , Rob Herring , =?UTF-8?Q?Andreas_F=C3=A4rber?= , =?UTF-8?B?5YiY54Kc?= , mp-cs@actions-semi.com, 96boards@ucrobotics.com, devicetree , Daniel Thompson , amit.kucheria@linaro.org, linux-arm Mailing List , "open list:GPIO SUBSYSTEM" , Linux Kernel Mailing List , hzhang@ucrobotics.com, bdong@ucrobotics.com, manivannanece23@gmail.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 28, 2018 at 8:14 PM, Manivannan Sadhasivam wrote: > 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. > FWIW, Reviewed-by: Andy Shevchenko P.S. Comma in terminator line is not needed. > Signed-off-by: Manivannan Sadhasivam > --- > drivers/gpio/Kconfig | 8 ++ > drivers/gpio/Makefile | 1 + > drivers/gpio/gpio-owl.c | 218 ++++++++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 227 insertions(+) > create mode 100644 drivers/gpio/gpio-owl.c > > 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..98f2e98197bc > --- /dev/null > +++ b/drivers/gpio/gpio-owl.c > @@ -0,0 +1,218 @@ > +// 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; > + > + 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); > + 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_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); > + const struct owl_gpio_port *port = gpio->port; > + void __iomem *gpio_base = gpio->base + port->offset; > + 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); > + 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"); > -- > 2.14.1 > -- With Best Regards, Andy Shevchenko