Received: by 10.223.176.46 with SMTP id f43csp49973wra; Thu, 25 Jan 2018 17:15:47 -0800 (PST) X-Google-Smtp-Source: AH8x226C2omNRTbaFgroQ72FbuS9LUlpO56PhjqRx002ciuwct6SPRk59y5eQOfA+D3v22if5WK+ X-Received: by 2002:a17:902:8e8a:: with SMTP id bg10-v6mr13253499plb.162.1516929347320; Thu, 25 Jan 2018 17:15:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516929347; cv=none; d=google.com; s=arc-20160816; b=X0vhGaHhKCIjnHc9f+d+2+0viqqnJQ+MmNhNEBQBruSrl0jEmXHRwPjNAYxdaFbmCW rRB3ZAtlUeGLTJ01yIlHl3LsJCR+MYgUtgpD2hFSlgoicybSaa6P429YFQOIcVghvdU8 sHSa29Y29tWdIcx/CfUZxLYtk9m+zyRo7IXvUSY+DDB+4aYAuztRj3HZ6tGZsOdU5+Tc mAnsGI4eyNWRsFIHthUvCoX+McWiGqmDD9c5htxS2jHuIrxWqrw0Hgd3dHqaSwT8MVx2 +kGEqCXIqtAucJqjtKeKhw8bGPxG7c98g0ePTa6FGqo0ejsYQ36ScuylyhLfEdPTMjLd pukQ== 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:dmarc-filter:dkim-signature:dkim-signature :arc-authentication-results; bh=xp/sOfROljB5K+xWY44d+zygHxPuZy8rdzc5RQlIAsY=; b=IjyxNkdo9BSeciJxV/Lh5Z4ci2mHd+YvjmJmpPLmM+OR78eEFj1z5kj5zpC1DnoI4g U/NjI+teWU8Q+lglHRYUuGWkJ0pjcDWHbVINEDr9ozzmy0Up5UljFOcOLRrBrTaOLBHo 88P/OCz86yn0I6qIH38eWU4uaBqcirjFqLzmth+9ypndmWeOB8MRbEMuQyMUrzRdwi+q Uw/Jd4XVuYyp0SjU4TUfgEWvO5cvjmBnvmI2px8onlO7glKD5+8aZmT46UqTQel8196q LQ4X++JXn54XJXBS442yAoT6EyW+cigQBvXBE6xFWSOQyHuOD1XnEDFO1DlyKZORgTJY 98Ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=nUzVEDTU; dkim=pass header.i=@codeaurora.org header.s=default header.b=gVUoEp8Y; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c24-v6si2868207plo.608.2018.01.25.17.15.33; Thu, 25 Jan 2018 17:15:47 -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=@codeaurora.org header.s=default header.b=nUzVEDTU; dkim=pass header.i=@codeaurora.org header.s=default header.b=gVUoEp8Y; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751964AbeAZBOr (ORCPT + 99 others); Thu, 25 Jan 2018 20:14:47 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:39418 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751539AbeAZBOE (ORCPT ); Thu, 25 Jan 2018 20:14:04 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 201B660ACE; Fri, 26 Jan 2018 01:14:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1516929244; bh=6BMfLRrdLOgDHQBtU49/yOhvYvBgZlxntIeJilFfdqc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nUzVEDTUkHh6WHrR06E32bRLbFMK7usklOXTSgtBOSDtULNUvG6WOero95q/bqWmo ks5SghnWJXcY+Rni/Urt7RGpE7X45J9eYTeIX2Pa4h02uDMi1O++llXXBkL1kM6ZHD 6Ic6PaD3//Ydwrv1cmy3Tss5+wk4syc/Ugy5mypE= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from sboyd-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: sboyd@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id D635D60A65; Fri, 26 Jan 2018 01:14:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1516929243; bh=6BMfLRrdLOgDHQBtU49/yOhvYvBgZlxntIeJilFfdqc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gVUoEp8Ym5iAzBvDyDc4lhKlMPtKkpjSv/8FOMsnvYZQJupkIL2xCPr977jco5w0m ONM3N9AI9vUamg3UXyKNQsGFVnVZfgnDocvzrjlLbWqCv8DRyrsnJxqHMBwSd18+TM Qhz8Sr3hKovLTwGUaHWH7QD+V+83CTsgL0cPBtQw= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org D635D60A65 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=sboyd@codeaurora.org From: Stephen Boyd To: Linus Walleij Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Timur Tabi , Andy Shevchenko , Bjorn Andersson , linux-gpio@vger.kernel.org, Grant Likely , devicetree@vger.kernel.org Subject: [PATCH v2 3/3] pinctrl: qcom: Don't allow protected pins to be requested Date: Thu, 25 Jan 2018 17:14:00 -0800 Message-Id: <20180126011400.2191-4-sboyd@codeaurora.org> X-Mailer: git-send-email 2.15.0.374.g5f9953d2c365 In-Reply-To: <20180126011400.2191-1-sboyd@codeaurora.org> References: <20180126011400.2191-1-sboyd@codeaurora.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some qcom platforms make some GPIOs or pins unavailable for use by non-secure operating systems, and thus reading or writing the registers for those pins will cause access control issues and reset the device. With a DT/ACPI property to describe the set of pins that are available for use, parse the available pins and set the irq valid bits for gpiolib to know what to consider 'valid'. This should avoid any issues with gpiolib. Furthermore, implement the pinmux_ops::request function so that pinmux can also make sure to not use pins that are unavailable. Signed-off-by: Stephen Boyd --- drivers/pinctrl/qcom/pinctrl-msm.c | 69 +++++++++++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 4 deletions(-) diff --git a/drivers/pinctrl/qcom/pinctrl-msm.c b/drivers/pinctrl/qcom/pinctrl-msm.c index 495432f3341b..c7901def5f2c 100644 --- a/drivers/pinctrl/qcom/pinctrl-msm.c +++ b/drivers/pinctrl/qcom/pinctrl-msm.c @@ -105,6 +105,17 @@ static const struct pinctrl_ops msm_pinctrl_ops = { .dt_free_map = pinctrl_utils_free_map, }; +static int msm_pinmux_request(struct pinctrl_dev *pctldev, unsigned offset) +{ + struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); + struct gpio_chip *chip = &pctrl->chip; + + if (gpiochip_irqchip_irq_valid(chip, offset)) + return 0; + + return -EINVAL; +} + static int msm_get_functions_count(struct pinctrl_dev *pctldev) { struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); @@ -166,6 +177,7 @@ static int msm_pinmux_set_mux(struct pinctrl_dev *pctldev, } static const struct pinmux_ops msm_pinmux_ops = { + .request = msm_pinmux_request, .get_functions_count = msm_get_functions_count, .get_function_name = msm_get_function_name, .get_function_groups = msm_get_function_groups, @@ -506,6 +518,9 @@ static void msm_gpio_dbg_show_one(struct seq_file *s, "pull up" }; + if (!gpiochip_irqchip_irq_valid(chip, offset)) + return; + g = &pctrl->soc->groups[offset]; ctl_reg = readl(pctrl->regs + g->ctl_reg); @@ -516,7 +531,7 @@ static void msm_gpio_dbg_show_one(struct seq_file *s, seq_printf(s, " %-8s: %-3s %d", g->name, is_out ? "out" : "in", func); seq_printf(s, " %dmA", msm_regval_to_drive(drive)); - seq_printf(s, " %s", pulls[pull]); + seq_printf(s, " %s\n", pulls[pull]); } static void msm_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) @@ -524,10 +539,8 @@ static void msm_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) unsigned gpio = chip->base; unsigned i; - for (i = 0; i < chip->ngpio; i++, gpio++) { + for (i = 0; i < chip->ngpio; i++, gpio++) msm_gpio_dbg_show_one(s, NULL, chip, i, gpio); - seq_puts(s, "\n"); - } } #else @@ -808,6 +821,46 @@ static void msm_gpio_irq_handler(struct irq_desc *desc) chained_irq_exit(chip, desc); } +static int msm_gpio_init_irq_valid_mask(struct gpio_chip *chip, + struct msm_pinctrl *pctrl) +{ + int ret; + unsigned int len, i; + unsigned int max_gpios = pctrl->soc->ngpios; + + /* The number of GPIOs in the ACPI tables */ + ret = device_property_read_u16_array(pctrl->dev, "gpios", NULL, 0); + if (ret > 0 && ret < max_gpios) { + u16 *tmp; + + len = ret; + tmp = kmalloc_array(len, sizeof(tmp[0]), GFP_KERNEL); + if (!tmp) + return -ENOMEM; + + ret = device_property_read_u16_array(pctrl->dev, "gpios", tmp, + len); + if (ret < 0) { + dev_err(pctrl->dev, "could not read list of GPIOs\n"); + kfree(tmp); + return ret; + } + + bitmap_zero(chip->irq.valid_mask, max_gpios); + for (i = 0; i < len; i++) + set_bit(tmp[i], chip->irq.valid_mask); + + return 0; + } + + return 0; +} + +static bool msm_gpio_needs_irq_valid_mask(struct msm_pinctrl *pctrl) +{ + return device_property_read_u16_array(pctrl->dev, "gpios", NULL, 0) > 0; +} + static int msm_gpio_init(struct msm_pinctrl *pctrl) { struct gpio_chip *chip; @@ -824,6 +877,7 @@ static int msm_gpio_init(struct msm_pinctrl *pctrl) chip->parent = pctrl->dev; chip->owner = THIS_MODULE; chip->of_node = pctrl->dev->of_node; + chip->irq.need_valid_mask = msm_gpio_needs_irq_valid_mask(pctrl); ret = gpiochip_add_data(&pctrl->chip, pctrl); if (ret) { @@ -831,6 +885,13 @@ static int msm_gpio_init(struct msm_pinctrl *pctrl) return ret; } + ret = msm_gpio_init_irq_valid_mask(chip, pctrl); + if (ret) { + dev_err(pctrl->dev, "Failed to setup irq valid bits\n"); + gpiochip_remove(&pctrl->chip); + 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"); -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project