From patchwork Thu Oct 18 09:07:00 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haojian Zhuang X-Patchwork-Id: 1608761 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 24328DFB34 for ; Thu, 18 Oct 2012 09:10:11 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TOm4n-0001oR-LN; Thu, 18 Oct 2012 09:07:38 +0000 Received: from mail-pb0-f49.google.com ([209.85.160.49]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TOm4Q-0001dM-B5 for linux-arm-kernel@lists.infradead.org; Thu, 18 Oct 2012 09:07:16 +0000 Received: by mail-pb0-f49.google.com with SMTP id xa7so8472754pbc.36 for ; Thu, 18 Oct 2012 02:07:13 -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:x-mailer:in-reply-to:references; bh=rPgabfMPudktqcqUQovUKEZ3mssUfIRRO5Znn1HJ8E4=; b=HF2KrJJ4strL3MEXFTFZIGzlzvac09vhAtpwSWZuHL62CyQy7kpDYZeLjznfZ8r6Jd CqAer++w4KywIKCqqRQaIlKfOSEjXC7heh/RznLbvA3Jp1NUa8HUxqNJuOSkmh6T2uBR YitF89Fy76v9QsPCxCZUCpkmuP5CUr6rG10CyKCTYSa7dsEDJkQscVFzjEBxv1ndgmMG FbMomVA+zkFJKJz3WeKZrSl57P6ogMmHgclI1xrK6JeADS0CBQHcwnawwezynZ9Kn+bF EPnXw+lspv6TavT1YGP5SWNXWTFGT83bW+EwuzFY+7CbuwvJMR98IYSyEBjgtLE9XM7O o9qw== Received: by 10.68.233.196 with SMTP id ty4mr64260345pbc.23.1350551233321; Thu, 18 Oct 2012 02:07:13 -0700 (PDT) Received: from localhost ([58.39.221.134]) by mx.google.com with ESMTPS id mz10sm13939529pbc.37.2012.10.18.02.06.53 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 18 Oct 2012 02:07:12 -0700 (PDT) From: Haojian Zhuang To: linux-arm-kernel@lists.infradead.org, arnd@arndb.de, linus.walleij@linaro.org, tony@atomide.com, devicetree-discuss@lists.ozlabs.org Subject: [PATCH 06/10] pinctrl: single: support gpio request and free Date: Thu, 18 Oct 2012 17:07:00 +0800 Message-Id: <1350551224-12857-6-git-send-email-haojian.zhuang@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1350551224-12857-1-git-send-email-haojian.zhuang@gmail.com> References: <1350551224-12857-1-git-send-email-haojian.zhuang@gmail.com> X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.160.49 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (haojian.zhuang[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: Haojian Zhuang X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Marvell's PXA/MMP silicon also match the behavior of pinctrl-single. Each pin binds to one register. A lot of pins could be configured as gpio. Now add three properties in below. pinctrl-single,gpio-mask: mask of enable/disable value of gpio pinctrl-single,gpio-ranges: gpio range array pinctrl-single,gpio: pinctrl-single,gpio-enable: pinctrl-single,gpio-disable: Signed-off-by: Haojian Zhuang --- drivers/pinctrl/pinctrl-single.c | 140 +++++++++++++++++++++++++++++++++++++- 1 files changed, 138 insertions(+), 2 deletions(-) diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c index 64d109a..02cd412 100644 --- a/drivers/pinctrl/pinctrl-single.c +++ b/drivers/pinctrl/pinctrl-single.c @@ -29,6 +29,7 @@ #define PCS_MUX_NAME "pinctrl-single,pins" #define PCS_REG_NAME_LEN ((sizeof(unsigned long) * 2) + 1) #define PCS_OFF_DISABLED ~0U +#define PCS_MAX_GPIO_VALUES 3 /** * struct pcs_pingroup - pingroups for a function @@ -75,6 +76,26 @@ struct pcs_function { }; /** + * struct pcs_gpio_range - pinctrl gpio range + * @range: subrange of the GPIO number space + * @reg_en: register of enabling gpio function + * @reg_dis: register of disabling gpio function + * @val_en: enable value on gpio function + * @val_dis: disable value on gpio function + * @need_en: need to handle enable value on gpio function + * @need_dis: need to handle disable value on gpio function + */ +struct pcs_gpio_range { + struct pinctrl_gpio_range range; + u32 reg_en; + u32 reg_dis; + int val_en; + int val_dis; + unsigned need_en:1; + unsigned need_dis:1; +}; + +/** * struct pcs_data - wrapper for data needed by pinctrl framework * @pa: pindesc array * @cur: index to current element @@ -115,14 +136,17 @@ struct pcs_name { * @fshift: function register shift * @foff: value to turn mux off * @fmax: max number of functions in fmask + * @gmask: gpio control mask * @names: array of register names for pins * @pins: physical pins on the SoC * @pgtree: pingroup index radix tree * @ftree: function index radix tree * @pingroups: list of pingroups * @functions: list of functions + * @ranges: list of gpio ranges * @ngroups: number of pingroups * @nfuncs: number of functions + * @nranges: number of gpio ranges * @desc: pin controller descriptor * @read: register read function to use * @write: register write function to use @@ -139,14 +163,17 @@ struct pcs_device { unsigned fshift; unsigned foff; unsigned fmax; + unsigned gmask; struct pcs_name *names; struct pcs_data pins; struct radix_tree_root pgtree; struct radix_tree_root ftree; struct list_head pingroups; struct list_head functions; + struct list_head ranges; unsigned ngroups; unsigned nfuncs; + unsigned nranges; struct pinctrl_desc desc; unsigned (*read)(void __iomem *reg); void (*write)(unsigned val, void __iomem *reg); @@ -387,9 +414,48 @@ static void pcs_disable(struct pinctrl_dev *pctldev, unsigned fselector, } static int pcs_request_gpio(struct pinctrl_dev *pctldev, - struct pinctrl_gpio_range *range, unsigned offset) + struct pinctrl_gpio_range *range, unsigned offset) { - return -ENOTSUPP; + struct pcs_device *pcs = pinctrl_dev_get_drvdata(pctldev); + struct pcs_gpio_range *gpio = NULL; + int end; + unsigned data; + + gpio = container_of(range, struct pcs_gpio_range, range); + if (!gpio->need_en) + return 0; + end = range->pin_base + range->npins - 1; + if (offset < range->pin_base || offset > end) { + dev_err(pctldev->dev, "offset %d isn't in the range of " + "%d to %d\n", offset, range->pin_base, end); + return -EINVAL; + } + data = pcs_readl((void __iomem *)gpio->reg_en) & ~pcs->gmask; + data |= gpio->val_en; + pcs_writel(data, (void __iomem *)gpio->reg_en); + return 0; +} + +static void pcs_disable_gpio(struct pinctrl_dev *pctldev, + struct pinctrl_gpio_range *range, unsigned offset) +{ + struct pcs_device *pcs = pinctrl_dev_get_drvdata(pctldev); + struct pcs_gpio_range *gpio = NULL; + int end; + unsigned data; + + gpio = container_of(range, struct pcs_gpio_range, range); + if (!gpio->need_dis) + return; + end = range->pin_base + range->npins - 1; + if (offset < range->pin_base || offset > end) { + dev_err(pctldev->dev, "offset %d isn't in the range of " + "%d to %d\n", offset, range->pin_base, end); + return; + } + data = pcs_readl((void __iomem *)gpio->reg_dis) & ~pcs->gmask; + data |= gpio->val_dis; + pcs_writel(data, (void __iomem *)gpio->reg_dis); } static struct pinmux_ops pcs_pinmux_ops = { @@ -399,6 +465,7 @@ static struct pinmux_ops pcs_pinmux_ops = { .enable = pcs_enable, .disable = pcs_disable, .gpio_request_enable = pcs_request_gpio, + .gpio_disable_free = pcs_disable_gpio, }; static int pcs_pinconf_get(struct pinctrl_dev *pctldev, @@ -848,6 +915,70 @@ static void pcs_free_resources(struct pcs_device *pcs) static struct of_device_id pcs_of_match[]; +static int __devinit pcs_add_gpio_range(struct device_node *node, + struct pcs_device *pcs) +{ + struct pcs_gpio_range *gpio; + struct device_node *np; + const __be32 *list; + const char list_name[] = "pinctrl-single,gpio-ranges"; + const char name[] = "pinctrl-single"; + u32 gpiores[PCS_MAX_GPIO_VALUES]; + int ret, size, i, mux_bytes = 0; + + ret = of_property_read_u32(node, "pinctrl-single,gpio-mask", + &pcs->gmask); + if (ret < 0) + return 0; + list = of_get_property(node, list_name, &size); + if (!list) + return -ENOENT; + size = size / sizeof(*list); + for (i = 0; i < size; i++) { + np = of_parse_phandle(node, list_name, i); + memset(gpiores, 0, sizeof(u32) * PCS_MAX_GPIO_VALUES); + ret = of_property_read_u32_array(np, "pinctrl-single,gpio", + gpiores, PCS_MAX_GPIO_VALUES); + if (ret < 0) + return -ENOENT; + gpio = devm_kzalloc(pcs->dev, sizeof(*gpio), GFP_KERNEL); + if (!gpio) { + dev_err(pcs->dev, "failed to allocate pcs gpio\n"); + return -ENOMEM; + } + gpio->range.id = i; + gpio->range.base = gpiores[0]; + gpio->range.npins = gpiores[1]; + gpio->range.name = kmemdup(name, sizeof(name), GFP_KERNEL); + mux_bytes = pcs->width / BITS_PER_BYTE; + gpio->range.pin_base = gpiores[2] / mux_bytes; + memset(gpiores, 0, sizeof(u32) * PCS_MAX_GPIO_VALUES); + ret = of_property_read_u32_array(np, + "pinctrl-single,gpio-enable", gpiores, 2); + if (!ret) { + gpio->reg_en = (u32)pcs->base + gpiores[0]; + gpio->val_en = gpiores[1]; + gpio->need_en = 1; + } + memset(gpiores, 0, sizeof(u32) * PCS_MAX_GPIO_VALUES); + ret = of_property_read_u32_array(np, + "pinctrl-single,gpio-disable", gpiores, 2); + if (!ret) { + gpio->reg_dis = (u32)pcs->base + gpiores[0]; + gpio->val_dis = gpiores[1]; + gpio->need_dis = 1; + } + + mutex_lock(&pcs->mutex); + list_add_tail(&gpio->range.node, &pcs->ranges); + pcs->nranges++; + mutex_unlock(&pcs->mutex); + + pinctrl_add_gpio_range(pcs->pctl, &gpio->range); + } + return 0; +} + static int __devinit pcs_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; @@ -869,6 +1000,7 @@ static int __devinit pcs_probe(struct platform_device *pdev) mutex_init(&pcs->mutex); INIT_LIST_HEAD(&pcs->pingroups); INIT_LIST_HEAD(&pcs->functions); + INIT_LIST_HEAD(&pcs->ranges); PCS_GET_PROP_U32("pinctrl-single,register-width", &pcs->width, "register width not specified\n"); @@ -941,6 +1073,10 @@ static int __devinit pcs_probe(struct platform_device *pdev) goto free; } + ret = pcs_add_gpio_range(np, pcs); + if (ret < 0) + return ret; + dev_info(pcs->dev, "%i pins at pa %p size %u\n", pcs->desc.npins, pcs->base, pcs->size);