From patchwork Fri May 18 02:30:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 136227 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp671572lji; Thu, 17 May 2018 19:32:47 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoO38EWzHAitQM5VNOMJ6aKd6CJQKwsl7bIBOjCGATl+6C2bxICtxQt+7QHGwqffyXF9zxE X-Received: by 2002:a62:1d52:: with SMTP id d79-v6mr7480419pfd.230.1526610767019; Thu, 17 May 2018 19:32:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526610767; cv=none; d=google.com; s=arc-20160816; b=JTK6FJVMbP6Culx5LIoLnNXP3vvbzLwlE7MhD9EQKXiVp2NnMGRKp1RnU+kK+va1rC yQkwQSPLa2RyVSpt6y3B7h+Tse0CPil/7nObmbR9cCgvNjsNkiACAGFZ2ihq7rJVdmLR fh7KMmfsmCrfuuOeuPkJQ6piYcIzhOB8tEUxcI9VzI+eZNYrAxn41R/dPhYiRkaZaDvg cUEXYZVb7jPeywWofa4fd5VOSh1Efx9h/E16yPjpwEFbLOeiRTsO9OFJ4teloszjSDr+ b/nQiFBcdWOT9SiR4yQ2WYSwYRB792hjqK2pzbtCH40gyWq8NuZ6aPYp2cAUdQNIqshj qBjg== 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=jtAZ4G3jDki4e61rUwUZTYjm2gbTAhGhAa9MVqWDeN8=; b=aKJBpeyQvvI8EPRQo+Oz42NeqyAHnWH/FqwWuiVlvM6Kx6h8oNSRx/LuVurWu6srmZ Pleot18pySlmoS/yATIxOCzeArFK3F/ITlkc/83jWQn5Xt/d98U4WSlBzXMZcWWyk6qP ETj1O/GO5otJndyUvwVmt6jwXwZj+eH5v/9LtToHFdcvPZSI/gkHQqZm6YWfAgOeuiSM R1vT1J0LxoHAvE9a7eWKC3V2VVwdzw7Hns26zhYiHnP3PEAwRysXs/mhsH/xkl1wkgsy mGAjOhdX8XYHcQtEjg5W9laMUkF19rYZflY5eBcwFbKw4uBAXEEC3yQbjLdnrj7gYAxE DJLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=EvsPxGjX; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=fail (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 s88-v6si6490666pfe.290.2018.05.17.19.32.46; Thu, 17 May 2018 19:32:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=EvsPxGjX; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752317AbeERCcp (ORCPT + 5 others); Thu, 17 May 2018 22:32:45 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:40387 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752320AbeERCcn (ORCPT ); Thu, 17 May 2018 22:32:43 -0400 Received: by mail-pf0-f196.google.com with SMTP id f189-v6so3000308pfa.7 for ; Thu, 17 May 2018 19:32:43 -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=kSKU4+02W7qUB3WQVunXWteskGCT0UUz2vtvOjsH5a4=; b=EvsPxGjXpMRuJh6R8xtUIdUTE1ikoRCkDS4O6wrB22Fm/digSVg1G+MHSy8DOlQQ0i NyaeLEb0iQXRoPUZt+nRTuES5M0Jc4fiMttAK5No7H925REBBxcaWWii8sxFa14fXSZ2 8TkKK/xM5A3owj2PN3RSureJcydH/RHaGdPIA= 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=kSKU4+02W7qUB3WQVunXWteskGCT0UUz2vtvOjsH5a4=; b=poqBHR0uI0zky7T0mn0k2xJCqLh3gUqClcz7MypjuwF/8DA5fGwAqgABMg1UP2yiQ5 H23wZLrwcSXrnEFVxDAU3fDahGQ9+4h2yT65bsHXJQZK6bBcj3xZf2/JI6rv4/3JiuLH 4rWnzdTEiIafa3u6CXQQQp4RwkV6mGEHt5ha7h0ALrJ8ZKWFxdPcsP+dFSqNPiiDsGXy aoXR1Us1USFfZ/s2fWeOOuQpTm0K6sj0PrCrmhYif0rYc2TNYCnRLWPIsASaSnCOargr /O9lk0WhIiEuKXp3UG2a62YhQj+9fN3C5uEutf0Z68qFBKACCVQufTuxNnQO0HMZpJRo KOaw== X-Gm-Message-State: ALKqPwfAHH1ejn2aXA6z6pLw4apQ+baCI1l+ziedv3c6/XRECKakGRrC 7h6W2MZ655R+zT30lVdqGnw1 X-Received: by 2002:a63:a312:: with SMTP id s18-v6mr5855158pge.187.1526610762663; Thu, 17 May 2018 19:32:42 -0700 (PDT) Received: from localhost.localdomain ([2405:204:724c:fe7b:a56e:eddc:eaff:36b1]) by smtp.gmail.com with ESMTPSA id z15-v6sm8671085pgr.55.2018.05.17.19.32.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 May 2018 19:32:42 -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 4/5] pinctrl: actions: Add gpio support for Actions S900 SoC Date: Fri, 18 May 2018 08:00:55 +0530 Message-Id: <20180518023056.7869-5-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180518023056.7869-1-manivannan.sadhasivam@linaro.org> References: <20180518023056.7869-1-manivannan.sadhasivam@linaro.org> Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Add gpio support to pinctrl driver for Actions Semi S900 SoC. 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(-) -- 2.14.1 -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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)