From patchwork Wed Mar 21 16:58:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 10299863 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EC6BC60385 for ; Wed, 21 Mar 2018 16:59:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E32C8285F5 for ; Wed, 21 Mar 2018 16:59:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D7136286AB; Wed, 21 Mar 2018 16:59:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5799D285F5 for ; Wed, 21 Mar 2018 16:59:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=bVqYUeN9CrWX5Qz8Veqn7CTHqvnxMWNUPg+TtNeeZts=; b=DB3lWRLhou4o7uERcL+fHyQ3Re 9NRch2UCsVJA2l+DMMIgDFvyUytQjCUQz3eCTUfiMKNwZ63ASFh1oU+GJk3SwUkMwsZrH7F9HOSBJ fX7PqX8NFWowePWZE6rDdkVR3Yr4bpavni9dkXcCw/X0BwgY+jxk259D904bmqnyXW4LB5S3zMufT MTClNvrz1JqUzFF9to542VQGKWQrYcO7X1J0jZ2Rs6uwSZGH7bo33mLKWLxYZDQpp1bT/8lpUF6qJ YbEfAOVygAg5+qRpebZuWwno4MAVszy6gfDvgvSmc7NwdFHNZfmif7jCkoAoPoFzyCL7u5XLrqrlc hf4Oqmww==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1eyh5F-0000tJ-8U; Wed, 21 Mar 2018 16:59:29 +0000 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1eyh4n-0000bF-ST for linux-arm-kernel@lists.infradead.org; Wed, 21 Mar 2018 16:59:04 +0000 Received: by mail-pg0-x243.google.com with SMTP id m15so2168785pgc.1 for ; Wed, 21 Mar 2018 09:58:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Pd45ONlBRVfl7OnQvb7vYtWuUyQEYLzIYWuKrG6wNO0=; b=ETnaWS8hcMqLoIO9CZe1SDAZXt7/bb/iD6pCMZC1Bwrq8DTdvgns4Vptf+MHLa/DKy IutUkzoCP32yY2lvkQv8xANiOPshIL5OiKkjY7NCXd+NFwPF43+07YLptFw6yJJOt/Qu 5vrczz9cDxbmYKGqq+vETSSGmov0yN6GAUyNg= 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=Pd45ONlBRVfl7OnQvb7vYtWuUyQEYLzIYWuKrG6wNO0=; b=f5ckU4d/CbawNR3PKNDfTA8pyPU9qgviYsw48bZS2sAwnslR7J2ECEAu78uNif7zlO 4TtWxv7i6Y2uCN2ZeQbItmj1Z8B4tQS/hpCDpkLXMrmuAQ+hRCB/2xcILkoZcsI7HI1T owfYJ2FJUt0x3zi/gnI9Pv268q/idHymwQJCRkgb5xYqWOFy8U2sfbujEibx+UdJYe51 Roinr7GvcB3z9y2FmCWBdP89W9QEkATEY8FHYNj1uY78lADj9khT8V3P6Z4VNEB3QQbH 5CtXZhEEOa6Y23+kwHYiWHxHc2nfOR8IIwMgXS16KgowesxkbbtNxyYBqckaeVmH1jEA atRw== X-Gm-Message-State: AElRT7G7r8NEOBfvwdF1NPVb70dDSjOoP0Cuk6LvyXmaf2Kmyfjcb2Na 1fin4itc/DH0gf2n7iht8416aw== X-Google-Smtp-Source: AG47ELs7hLz4Lg7ZCBQLbMa7YhHj4qu+Nc9gOCl26K7mn/Pw9316i3ORNauNLF5U+caB3MWssRqKQw== X-Received: by 10.98.89.23 with SMTP id n23mr8637976pfb.211.1521651534094; Wed, 21 Mar 2018 09:58:54 -0700 (PDT) Received: from swboyd.mtv.corp.google.com ([2620:0:1000:1511:d30e:62c6:f82c:ff40]) by smtp.gmail.com with ESMTPSA id u28sm10121806pfl.19.2018.03.21.09.58.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Mar 2018 09:58:53 -0700 (PDT) From: Stephen Boyd To: Linus Walleij Subject: [PATCH v3 3/3] pinctrl: qcom: Don't allow protected pins to be requested Date: Wed, 21 Mar 2018 09:58:48 -0700 Message-Id: <20180321165848.89751-4-swboyd@chromium.org> X-Mailer: git-send-email 2.16.2.804.g6dcf76e118-goog In-Reply-To: <20180321165848.89751-1-swboyd@chromium.org> References: <20180321165848.89751-1-swboyd@chromium.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180321_095902_095817_BE74A378 X-CRM114-Status: GOOD ( 18.96 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, linux-arm-msm@vger.kernel.org, Timur Tabi , Stephen Boyd , linux-kernel@vger.kernel.org, Bjorn Andersson , Grant Likely , linux-gpio@vger.kernel.org, Andy Shevchenko , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Stephen Boyd 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 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..bc9cda0da886 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_line_is_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_line_is_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_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->valid_mask, max_gpios); + for (i = 0; i < len; i++) + set_bit(tmp[i], chip->valid_mask); + + return 0; + } + + return 0; +} + +static bool msm_gpio_needs_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->need_valid_mask = msm_gpio_needs_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_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");