Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp5004515imm; Fri, 18 May 2018 14:44:12 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrGmzvpr0EyZatU+mgeOWSw8iJ94H6Ataq6hoxCvnmDofLCbNVZbCQITW+ozFoOinbJU7nS X-Received: by 2002:a17:902:9a4b:: with SMTP id x11-v6mr11281182plv.176.1526679852899; Fri, 18 May 2018 14:44:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526679852; cv=none; d=google.com; s=arc-20160816; b=P8ouMTxgFIB36f6s4Hody8mzzc8cEzhCkg0pr6pagnvSUJ8WaUJZtFUxMUXjugsx8j ZgxsEzsVpUWeocezhao7aYFcxc26mpiBvkp3tklDbEcGsJnclH1txLXODFG4LDqHMJjf jFllIMq9nAQNWzVO7l5Nmuc7/63Vo95uR0MRjcmOX5ugqw1w3hIA+yKdx02a63M7w/VF GaddSzPbCWw1t8eBLk13YDx9Z/GGUCCB+/VMe1TRmipKS0DYIhNu1VjR/vWd7fAhDrhF mGP4Jq3uPktFkNXJRmovRXcoLVjLxTp8nrmQQaoLP2fHv1xm/XECUn1WTaRUMrHA5sxU H+IA== 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=AkRRTI80EtIOdH1sYVAEwsX/hS5tI6wn/tmViJEAI64=; b=HioZByGlCOEWw4d7lm2YbIQiwbTghE/JeR5tWwdIgX6bnVFTVj4uIFiXE7Xhj46RKV iFlzZjp8lOL/9JldBPKtcMrYjsafH2azp+1FXwYBSmq+sZwiflPBlW78hq2kOqDgPyBE if1v7xCSOZHtSRQb/2zSGxR9DZIl0w+yyuUx7j4MLCTHEwMlP2+awDVC5XiCLkEZBaYt I3SG8KXFTH9ubkMRDBQPzucMX7WItLqW/del3ooqwxfvMX+kSc3kg1lP0f2djI9L2+uc vgReKp8TXzg7o70Hy1wqdCpspa+cSrLW9Pl4fES0N4UArckUYgxWhOfwwMzhjk1iF4sD kjDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=KkPUrl1m; 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 r26-v6si2054267pgn.373.2018.05.18.14.43.58; Fri, 18 May 2018 14:44:12 -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=@gmail.com header.s=20161025 header.b=KkPUrl1m; 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 S1751815AbeERVno (ORCPT + 99 others); Fri, 18 May 2018 17:43:44 -0400 Received: from mail-qt0-f196.google.com ([209.85.216.196]:47094 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751009AbeERVnm (ORCPT ); Fri, 18 May 2018 17:43:42 -0400 Received: by mail-qt0-f196.google.com with SMTP id m16-v6so12159553qtg.13; Fri, 18 May 2018 14:43:41 -0700 (PDT) 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=AkRRTI80EtIOdH1sYVAEwsX/hS5tI6wn/tmViJEAI64=; b=KkPUrl1m78kkbJmATNUjaPqrVQcCEPUoMTW5wvnttd03UnoIELrbLKuy7g0HB0dZMy Q5l8Y7mdetufsOlsKxeAOwA83c9bJ5rXAKEKCTYp9cRTvdx19g7ybvNbjDe9KwnPIKW5 DuVh/R+wJWYWbtYCJC5sj7i6TUszniR1F9LZyNLx8K0OmJI1yY/4fDDwpxjn1dLGQHxQ M7n8U6eyI4K5qNF06+MGqp0avDWeUO2eRR3jxceL59Z9piWWN9KcwGPxeCNjNAA6dTSW k2dGiKTuUm9f0dWOCy0BZ/WLWe7XUSI3h+XH7kg5dQcG8fOLMudQioTNJhZQ7s7DfzgI wt0Q== 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=AkRRTI80EtIOdH1sYVAEwsX/hS5tI6wn/tmViJEAI64=; b=fL5xg3mkk3k/XRA8M2c0/w6jSJSyidtZtKIbMA8iW8wgw1Lx7+kQRkrcZyGbw7ZWTg ENuBPJnCRVL2kECiq+oo/vScbZo+M1efMqI3Ok5ZxxIoZYqQSFOVo3LKWE9Ruqe4bM8e CD3TPcG354e6luidJbrN4m06DFRU2WxAA5IlhmA6D7lTuRGyAtOSn9rPmoBTUbXK4CUq kjzQrO/B5n8O7MXxJyHsMAtrDHkqmn1CCmxXd2ytZi8OMZywx4XGPLI8dGO6x9C016ty 5tCZSEvWUq1h7/fiBclTteVP0ohOjvwD9VtJxE6owo0urm9zk4Tv/LOxiV3uTZudb4E7 KcUQ== X-Gm-Message-State: ALKqPwf8TrLh11mjufpofXb//ze2jrYWD9dQIM8T4kZGXoOfZHWYwoZN XI9/blH/ULTjRtpylYIRHLbviAUzjVvhWSXPoB8= X-Received: by 2002:aed:2c43:: with SMTP id f61-v6mr10883569qtd.105.1526679821333; Fri, 18 May 2018 14:43:41 -0700 (PDT) MIME-Version: 1.0 Received: by 10.12.152.150 with HTTP; Fri, 18 May 2018 14:43:40 -0700 (PDT) In-Reply-To: <20180518023056.7869-5-manivannan.sadhasivam@linaro.org> References: <20180518023056.7869-1-manivannan.sadhasivam@linaro.org> <20180518023056.7869-5-manivannan.sadhasivam@linaro.org> From: Andy Shevchenko Date: Sat, 19 May 2018 00:43:40 +0300 Message-ID: Subject: Re: [PATCH 4/5] pinctrl: actions: Add gpio support for Actions 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, Mani Sadhasivam 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 Fri, May 18, 2018 at 5:30 AM, Manivannan Sadhasivam wrote: > Add gpio support to pinctrl driver for Actions Semi S900 SoC. > LGTM, Reviewed-by: Andy Shevchenko > Signed-off-by: Manivannan Sadhasivam > --- > drivers/pinctrl/actions/Kconfig | 1 + > drivers/pinctrl/actions/pinctrl-owl.c | 206 +++++++++++++++++++++++++++++++++ > drivers/pinctrl/actions/pinctrl-owl.h | 20 ++++ > drivers/pinctrl/actions/pinctrl-s900.c | 29 ++++- > 4 files changed, 255 insertions(+), 1 deletion(-) > > diff --git a/drivers/pinctrl/actions/Kconfig b/drivers/pinctrl/actions/Kconfig > index ede97cdbbc12..490927b4ea76 100644 > --- a/drivers/pinctrl/actions/Kconfig > +++ b/drivers/pinctrl/actions/Kconfig > @@ -4,6 +4,7 @@ config PINCTRL_OWL > select PINMUX > select PINCONF > select GENERIC_PINCONF > + select GPIOLIB > help > Say Y here to enable Actions Semi OWL pinctrl driver > > diff --git a/drivers/pinctrl/actions/pinctrl-owl.c b/drivers/pinctrl/actions/pinctrl-owl.c > index ee090697b1e9..4942e34c8b76 100644 > --- a/drivers/pinctrl/actions/pinctrl-owl.c > +++ b/drivers/pinctrl/actions/pinctrl-owl.c > @@ -11,6 +11,7 @@ > > #include > #include > +#include > #include > #include > #include > @@ -31,6 +32,7 @@ > * struct owl_pinctrl - pinctrl state of the device > * @dev: device handle > * @pctrldev: pinctrl handle > + * @chip: gpio chip > * @lock: spinlock to protect registers > * @soc: reference to soc_data > * @base: pinctrl register base address > @@ -38,6 +40,7 @@ > struct owl_pinctrl { > struct device *dev; > struct pinctrl_dev *pctrldev; > + struct gpio_chip chip; > raw_spinlock_t lock; > struct clk *clk; > const struct owl_pinctrl_soc_data *soc; > @@ -536,6 +539,198 @@ static struct pinctrl_desc owl_pinctrl_desc = { > .owner = THIS_MODULE, > }; > > +static const struct owl_gpio_port * > +owl_gpio_get_port(struct owl_pinctrl *pctrl, unsigned int *pin) > +{ > + unsigned int start = 0, i; > + > + for (i = 0; i < pctrl->soc->nports; i++) { > + const struct owl_gpio_port *port = &pctrl->soc->ports[i]; > + > + if (*pin >= start && *pin < start + port->pins) { > + *pin -= start; > + return port; > + } > + > + start += port->pins; > + } > + > + return NULL; > +} > + > +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_pinctrl *pctrl = gpiochip_get_data(chip); > + const struct owl_gpio_port *port; > + void __iomem *gpio_base; > + unsigned long flags; > + > + port = owl_gpio_get_port(pctrl, &offset); > + if (WARN_ON(port == NULL)) > + return -ENODEV; > + > + gpio_base = pctrl->base + port->offset; > + > + /* > + * GPIOs have higher priority over other modules, so either setting > + * them as OUT or IN is sufficient > + */ > + raw_spin_lock_irqsave(&pctrl->lock, flags); > + owl_gpio_update_reg(gpio_base + port->outen, offset, true); > + raw_spin_unlock_irqrestore(&pctrl->lock, flags); > + > + return 0; > +} > + > +static void owl_gpio_free(struct gpio_chip *chip, unsigned int offset) > +{ > + struct owl_pinctrl *pctrl = gpiochip_get_data(chip); > + const struct owl_gpio_port *port; > + void __iomem *gpio_base; > + unsigned long flags; > + > + port = owl_gpio_get_port(pctrl, &offset); > + if (WARN_ON(port == NULL)) > + return; > + > + gpio_base = pctrl->base + port->offset; > + > + raw_spin_lock_irqsave(&pctrl->lock, flags); > + /* disable gpio output */ > + owl_gpio_update_reg(gpio_base + port->outen, offset, false); > + > + /* disable gpio input */ > + owl_gpio_update_reg(gpio_base + port->inen, offset, false); > + raw_spin_unlock_irqrestore(&pctrl->lock, flags); > +} > + > +static int owl_gpio_get(struct gpio_chip *chip, unsigned int offset) > +{ > + struct owl_pinctrl *pctrl = gpiochip_get_data(chip); > + const struct owl_gpio_port *port; > + void __iomem *gpio_base; > + unsigned long flags; > + u32 val; > + > + port = owl_gpio_get_port(pctrl, &offset); > + if (WARN_ON(port == NULL)) > + return -ENODEV; > + > + gpio_base = pctrl->base + port->offset; > + > + raw_spin_lock_irqsave(&pctrl->lock, flags); > + val = readl_relaxed(gpio_base + port->dat); > + raw_spin_unlock_irqrestore(&pctrl->lock, flags); > + > + return !!(val & BIT(offset)); > +} > + > +static void owl_gpio_set(struct gpio_chip *chip, unsigned int offset, int value) > +{ > + struct owl_pinctrl *pctrl = gpiochip_get_data(chip); > + const struct owl_gpio_port *port; > + void __iomem *gpio_base; > + unsigned long flags; > + > + port = owl_gpio_get_port(pctrl, &offset); > + if (WARN_ON(port == NULL)) > + return; > + > + gpio_base = pctrl->base + port->offset; > + > + raw_spin_lock_irqsave(&pctrl->lock, flags); > + owl_gpio_update_reg(gpio_base + port->dat, offset, value); > + raw_spin_unlock_irqrestore(&pctrl->lock, flags); > +} > + > +static int owl_gpio_direction_input(struct gpio_chip *chip, unsigned int offset) > +{ > + struct owl_pinctrl *pctrl = gpiochip_get_data(chip); > + const struct owl_gpio_port *port; > + void __iomem *gpio_base; > + unsigned long flags; > + > + port = owl_gpio_get_port(pctrl, &offset); > + if (WARN_ON(port == NULL)) > + return -ENODEV; > + > + gpio_base = pctrl->base + port->offset; > + > + raw_spin_lock_irqsave(&pctrl->lock, flags); > + owl_gpio_update_reg(gpio_base + port->outen, offset, false); > + owl_gpio_update_reg(gpio_base + port->inen, offset, true); > + raw_spin_unlock_irqrestore(&pctrl->lock, flags); > + > + return 0; > +} > + > +static int owl_gpio_direction_output(struct gpio_chip *chip, > + unsigned int offset, int value) > +{ > + struct owl_pinctrl *pctrl = gpiochip_get_data(chip); > + const struct owl_gpio_port *port; > + void __iomem *gpio_base; > + unsigned long flags; > + > + port = owl_gpio_get_port(pctrl, &offset); > + if (WARN_ON(port == NULL)) > + return -ENODEV; > + > + gpio_base = pctrl->base + port->offset; > + > + raw_spin_lock_irqsave(&pctrl->lock, flags); > + owl_gpio_update_reg(gpio_base + port->inen, offset, false); > + owl_gpio_update_reg(gpio_base + port->outen, offset, true); > + owl_gpio_update_reg(gpio_base + port->dat, offset, value); > + raw_spin_unlock_irqrestore(&pctrl->lock, flags); > + > + return 0; > +} > + > +static int owl_gpio_init(struct owl_pinctrl *pctrl) > +{ > + struct gpio_chip *chip; > + int ret; > + > + chip = &pctrl->chip; > + chip->base = -1; > + chip->ngpio = pctrl->soc->ngpios; > + chip->label = dev_name(pctrl->dev); > + chip->parent = pctrl->dev; > + chip->owner = THIS_MODULE; > + chip->of_node = pctrl->dev->of_node; > + > + ret = gpiochip_add_data(&pctrl->chip, pctrl); > + if (ret) { > + dev_err(pctrl->dev, "failed to register gpiochip\n"); > + return ret; > + } > + > + ret = gpiochip_add_pin_range(&pctrl->chip, dev_name(pctrl->dev), > + 0, 0, chip->ngpio); > + if (ret) { > + dev_err(pctrl->dev, "failed to add pin range\n"); > + gpiochip_remove(&pctrl->chip); > + return ret; > + } > + > + return 0; > +} > + > int owl_pinctrl_probe(struct platform_device *pdev, > struct owl_pinctrl_soc_data *soc_data) > { > @@ -571,6 +766,13 @@ int owl_pinctrl_probe(struct platform_device *pdev, > owl_pinctrl_desc.pins = soc_data->pins; > owl_pinctrl_desc.npins = soc_data->npins; > > + pctrl->chip.direction_input = owl_gpio_direction_input; > + pctrl->chip.direction_output = owl_gpio_direction_output; > + pctrl->chip.get = owl_gpio_get; > + pctrl->chip.set = owl_gpio_set; > + pctrl->chip.request = owl_gpio_request; > + pctrl->chip.free = owl_gpio_free; > + > pctrl->soc = soc_data; > pctrl->dev = &pdev->dev; > > @@ -581,6 +783,10 @@ int owl_pinctrl_probe(struct platform_device *pdev, > return PTR_ERR(pctrl->pctrldev); > } > > + ret = owl_gpio_init(pctrl); > + if (ret) > + return ret; > + > platform_set_drvdata(pdev, pctrl); > > return 0; > diff --git a/drivers/pinctrl/actions/pinctrl-owl.h b/drivers/pinctrl/actions/pinctrl-owl.h > index 448f81a6db3b..74342378937c 100644 > --- a/drivers/pinctrl/actions/pinctrl-owl.h > +++ b/drivers/pinctrl/actions/pinctrl-owl.h > @@ -114,6 +114,22 @@ struct owl_pinmux_func { > unsigned int ngroups; > }; > > +/** > + * struct owl_gpio_port - Actions GPIO port info > + * @offset: offset of the GPIO port. > + * @pins: number of pins belongs to the GPIO port. > + * @outen: offset of the output enable register. > + * @inen: offset of the input enable register. > + * @dat: offset of the data register. > + */ > +struct owl_gpio_port { > + unsigned int offset; > + unsigned int pins; > + unsigned int outen; > + unsigned int inen; > + unsigned int dat; > +}; > + > /** > * struct owl_pinctrl_soc_data - Actions pin controller driver configuration > * @pins: array describing all pins of the pin controller. > @@ -124,6 +140,8 @@ struct owl_pinmux_func { > * @ngroups: number of entries in @groups. > * @padinfo: array describing the pad info of this SoC. > * @ngpios: number of pingroups the driver should expose as GPIOs. > + * @port: array describing all GPIO ports of this SoC. > + * @nports: number of GPIO ports in this SoC. > */ > struct owl_pinctrl_soc_data { > const struct pinctrl_pin_desc *pins; > @@ -134,6 +152,8 @@ struct owl_pinctrl_soc_data { > unsigned int ngroups; > const struct owl_padinfo *padinfo; > unsigned int ngpios; > + const struct owl_gpio_port *ports; > + unsigned int nports; > }; > > int owl_pinctrl_probe(struct platform_device *pdev, > diff --git a/drivers/pinctrl/actions/pinctrl-s900.c b/drivers/pinctrl/actions/pinctrl-s900.c > index 08d93f8fc086..5503c7945764 100644 > --- a/drivers/pinctrl/actions/pinctrl-s900.c > +++ b/drivers/pinctrl/actions/pinctrl-s900.c > @@ -33,6 +33,13 @@ > #define PAD_SR1 (0x0274) > #define PAD_SR2 (0x0278) > > +#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 > + > #define _GPIOA(offset) (offset) > #define _GPIOB(offset) (32 + (offset)) > #define _GPIOC(offset) (64 + (offset)) > @@ -1814,6 +1821,24 @@ static struct owl_padinfo s900_padinfo[NUM_PADS] = { > [SGPIO3] = PAD_INFO_PULLCTL_ST(SGPIO3) > }; > > +#define OWL_GPIO_PORT(port, base, count, _outen, _inen, _dat) \ > + [OWL_GPIO_PORT_##port] = { \ > + .offset = base, \ > + .pins = count, \ > + .outen = _outen, \ > + .inen = _inen, \ > + .dat = _dat, \ > + } > + > +static const struct owl_gpio_port s900_gpio_ports[] = { > + OWL_GPIO_PORT(A, 0x0000, 32, 0x0, 0x4, 0x8), > + OWL_GPIO_PORT(B, 0x000C, 32, 0x0, 0x4, 0x8), > + OWL_GPIO_PORT(C, 0x0018, 12, 0x0, 0x4, 0x8), > + OWL_GPIO_PORT(D, 0x0024, 30, 0x0, 0x4, 0x8), > + OWL_GPIO_PORT(E, 0x0030, 32, 0x0, 0x4, 0x8), > + OWL_GPIO_PORT(F, 0x00F0, 8, 0x0, 0x4, 0x8) > +}; > + > static struct owl_pinctrl_soc_data s900_pinctrl_data = { > .padinfo = s900_padinfo, > .pins = (const struct pinctrl_pin_desc *)s900_pads, > @@ -1822,7 +1847,9 @@ static struct owl_pinctrl_soc_data s900_pinctrl_data = { > .nfunctions = ARRAY_SIZE(s900_functions), > .groups = s900_groups, > .ngroups = ARRAY_SIZE(s900_groups), > - .ngpios = NUM_GPIOS > + .ngpios = NUM_GPIOS, > + .ports = s900_gpio_ports, > + .nports = ARRAY_SIZE(s900_gpio_ports) > }; > > static int s900_pinctrl_probe(struct platform_device *pdev) > -- > 2.14.1 > -- With Best Regards, Andy Shevchenko