From patchwork Tue Dec 19 02:39:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 10122113 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 6808360390 for ; Tue, 19 Dec 2017 02:39:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4FB7828A02 for ; Tue, 19 Dec 2017 02:39:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 41B6928A0A; Tue, 19 Dec 2017 02:39:58 +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=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.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 3E48E28A02 for ; Tue, 19 Dec 2017 02:39:56 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=uOA1Cmu1zDACqPVtWfzgsJ5ninWgwDOqtFJZO8cgOzM=; b=BVcQ2sQfLpO0A2 Fvf9z4nKXLSm2Oi5CajG7+Zbkwopw92XjFaYa6YskY6jBlgqPn21MMTUC55BIRHQ46GLQKQmnZlxG hgtmDnIW775WVhB3cnEQql2xBz8tbH2+0dkrIT5SNkS0Ys7WN+yx3D9uLguEP63AmYMRo6Z6aEnFT S1dKW84S0qdE3dcJ2Cs9tOElbi8Dq2wWPcdbdw6bzmFzfCy63udV1FQgZRp02QJRn2UF6UyqWO7Kg PeeUZxw6HRBYlYovUFFndleG+UKDBTWS1K97UFsSrAkExjnG/prnHNCwszNgh/ZMXYAnkMc+PgGNg TPtQclMAP7iJKwcHmhCg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eR7ou-0000dE-Pf; Tue, 19 Dec 2017 02:39:52 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eR7oq-0000XK-Ks for linux-arm-kernel@lists.infradead.org; Tue, 19 Dec 2017 02:39:51 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id F3B206079C; Tue, 19 Dec 2017 02:39:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1513651177; bh=LWdV7/A6EKu8meuqbGZ86AFFy7X/hM3uFIerYkaAbkI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=e2OV/Ol6tlOdgQWMQhLW3Al0jh3ahn0wx8LIMUOx1SYc+oujkryBMAf52dlHEy9xu uTN1LoiL4efGJxcRIDZ8NKPIS0HU6jcPh9p/LddY/l15Oa7t7vQoawcXUZYaM7Eg59 ea0sK/psPpM29vQpK7GCfA/5vKy+Y8yfkwiCeJ34= Received: from localhost (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: sboyd@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id AF9F66024A; Tue, 19 Dec 2017 02:39:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1513651175; bh=LWdV7/A6EKu8meuqbGZ86AFFy7X/hM3uFIerYkaAbkI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=bQzcCcCNTebW2ll5aTA3tln/6hrWy31xuNWt8zHtXjWr0YNY2zF3E2+DgLHp4rJwI cKrzoRYF8gUNeEAzFHhprDzC4jG2fV1qGHAQ/VP9GUb/bvZG0j+AMmX8buutb9Ivf1 XSXMA7XZYvZgWuAyk58suv6H4shQP78+P+AUqHIw= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org AF9F66024A 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 Date: Mon, 18 Dec 2017 18:39:35 -0800 From: Stephen Boyd To: Timur Tabi Subject: Re: [PATCH 3/3] [v6] pinctrl: qcom: qdf2xxx: add support for new ACPI HID QCOM8002 Message-ID: <20171219023935.GA17456@codeaurora.org> References: <1513189818-7384-1-git-send-email-timur@codeaurora.org> <1513189818-7384-4-git-send-email-timur@codeaurora.org> <20171213230155.GS7997@codeaurora.org> <6ca3b4a6-90b9-0481-beb8-29a95c86f07c@codeaurora.org> <615426d4-7c46-9671-87ef-790fb5733385@codeaurora.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <615426d4-7c46-9671-87ef-790fb5733385@codeaurora.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171218_183949_563386_0EC620BC X-CRM114-Status: GOOD ( 30.77 ) 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: Archit Taneja , david.brown@linaro.org, linux-arm-msm@vger.kernel.org, Linus Walleij , Bjorn Andersson , linux-gpio@vger.kernel.org, thierry.reding@gmail.com, andy.gross@linaro.org, Andy Shevchenko , Mika Westerberg , Varadarajan Narayanan , linux-arm-kernel@lists.infradead.org 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 On 12/18, Timur Tabi wrote: > Stephen, any follow-up to this? I'd like to get these patches into > 4.16 if at all possible. Thanks. > Ah I missed that the u16 array can't be iterated through. Any chance the ACPI tables can be changed to list pin ranges, like <33 3>, <90 2>, to indicate that pins 33, 34, 35 and pins 90, 91 are available? That would allow us to put that into the core pinctrl-msm.c file a little better and then only expose pins on the gpiochip when call gpiochip_add_pin_range(). If we want to support this in DT, I think we would have a DT property like available-gpios = <33 3>, <90 2>, <100 34> that we can then iterate through and add only these pins to the gpiochip. That's better than a bitmap in DT and is still compressed somewhat. Without going all the way down into that path, here's my patch to make your patch smaller, but perhaps we can just look for the ACPI property or the DT property in the pinctrl-msm.c core and then add pin ranges directly. Then this ACPI driver doesn't really need to change besides for the ID update. We can expose all the pins and offsets, etc. from the hardware driver but cut out gpios in the core layer in a generic way. ---8<--- From: Timur Tabi Newer versions of the firmware for the Qualcomm Datacenter Technologies QDF2400 restricts access to a subset of the GPIOs on the TLMM. To prevent older kernels from accidentally accessing the restricted GPIOs, we change the ACPI HID for the TLMM block from QCOM8001 to QCOM8002, and introduce a new property "gpios". This property is an array of specific GPIOs that are accessible. When an older kernel boots on newer (restricted) firmware, it will fail to probe. To implement the sparse GPIO map, we register all of the GPIOs, but set the pin count for the unavailable GPIOs to zero. The pinctrl-msm driver will block those unavailable GPIOs from being accessed. To allow newer kernels to support older firmware, the driver retains support for QCOM8001. Signed-off-by: Timur Tabi Signed-off-by: Stephen Boyd --- drivers/pinctrl/qcom/pinctrl-qdf2xxx.c | 89 +++++++++++++++++++++++++++++----- 1 file changed, 77 insertions(+), 12 deletions(-) diff --git a/drivers/pinctrl/qcom/pinctrl-qdf2xxx.c b/drivers/pinctrl/qcom/pinctrl-qdf2xxx.c index bb3ce5c3e18b..2ca2f40719b3 100644 --- a/drivers/pinctrl/qcom/pinctrl-qdf2xxx.c +++ b/drivers/pinctrl/qcom/pinctrl-qdf2xxx.c @@ -38,45 +38,107 @@ static struct msm_pinctrl_soc_data qdf2xxx_pinctrl; /* maximum size of each gpio name (enough room for "gpioXXX" + null) */ #define NAME_SIZE 8 +enum { + QDF2XXX_V1, + QDF2XXX_V2, +}; + static int qdf2xxx_pinctrl_probe(struct platform_device *pdev) { + const struct acpi_device_id *id; struct pinctrl_pin_desc *pins; struct msm_pingroup *groups; char (*names)[NAME_SIZE]; - unsigned int i; + unsigned int i, j; u32 num_gpios; + unsigned int avail_gpios; /* The number of GPIOs we support */ + u16 *gpios = NULL; /* An array of supported GPIOs */ int ret; /* Query the number of GPIOs from ACPI */ ret = device_property_read_u32(&pdev->dev, "num-gpios", &num_gpios); if (ret < 0) { - dev_warn(&pdev->dev, "missing num-gpios property\n"); + dev_err(&pdev->dev, "missing 'num-gpios' property\n"); return ret; } - if (!num_gpios || num_gpios > MAX_GPIOS) { - dev_warn(&pdev->dev, "invalid num-gpios property\n"); + dev_err(&pdev->dev, "invalid 'num-gpios' property\n"); return -ENODEV; } + /* + * The QCOM8001 HID contains only the number of GPIOs, and assumes + * that all of them are available. avail_gpios is the same as num_gpios. + * + * The QCOM8002 HID introduces the 'gpios' DSD, which lists + * specific GPIOs that the driver is allowed to access. + * + * The make the common code simpler, in both cases we create an + * array of GPIOs that are accessible. So for QCOM8001, that would + * be all of the GPIOs. + */ + id = acpi_match_device(pdev->dev.driver->acpi_match_table, &pdev->dev); + + if (id->driver_data == QDF2XXX_V1) { + avail_gpios = num_gpios; + } else { + /* The number of GPIOs in the approved list */ + ret = device_property_read_u16_array(&pdev->dev, "gpios", + NULL, 0); + if (ret < 0) { + dev_err(&pdev->dev, "missing 'gpios' property\n"); + return ret; + } + /* + * The number of available GPIOs should be non-zero, and no + * more than the total number of GPIOS. + */ + if (!ret || ret > num_gpios) { + dev_err(&pdev->dev, "invalid 'gpios' property\n"); + return -ENODEV; + } + avail_gpios = ret; + + gpios = devm_kmalloc_array(&pdev->dev, avail_gpios, + sizeof(gpios[0]), GFP_KERNEL); + if (!gpios) + return -ENOMEM; + + /* Assume the array of available GPIOs is sorted */ + ret = device_property_read_u16_array(&pdev->dev, "gpios", gpios, + avail_gpios); + if (ret < 0) { + dev_err(&pdev->dev, "could not read list of GPIOs\n"); + return ret; + } + } + pins = devm_kcalloc(&pdev->dev, num_gpios, sizeof(struct pinctrl_pin_desc), GFP_KERNEL); groups = devm_kcalloc(&pdev->dev, num_gpios, sizeof(struct msm_pingroup), GFP_KERNEL); - names = devm_kcalloc(&pdev->dev, num_gpios, NAME_SIZE, GFP_KERNEL); + names = devm_kcalloc(&pdev->dev, avail_gpios, NAME_SIZE, GFP_KERNEL); if (!pins || !groups || !names) return -ENOMEM; - for (i = 0; i < num_gpios; i++) { - snprintf(names[i], NAME_SIZE, "gpio%u", i); - + /* + * Initialize the array. GPIOs not listed in the 'gpios' bitmap + * still need a number, but nothing else. + */ + for (i = 0, j = 0; i < num_gpios; i++) { pins[i].number = i; - pins[i].name = names[i]; + groups[i].pins = &pins[i].number; + + /* Only expose GPIOs that are available */ + if (gpios && gpios[j] != i) + continue; groups[i].npins = 1; - groups[i].name = names[i]; - groups[i].pins = &pins[i].number; + snprintf(names[j], NAME_SIZE, "gpio%u", i); + pins[i].name = names[j]; + groups[i].name = names[j]; + j++; groups[i].ctl_reg = 0x10000 * i; groups[i].io_reg = 0x04 + 0x10000 * i; @@ -100,6 +162,8 @@ static int qdf2xxx_pinctrl_probe(struct platform_device *pdev) groups[i].intr_detection_width = 2; } + devm_kfree(&pdev->dev, gpios); + qdf2xxx_pinctrl.pins = pins; qdf2xxx_pinctrl.groups = groups; qdf2xxx_pinctrl.npins = num_gpios; @@ -110,7 +174,8 @@ static int qdf2xxx_pinctrl_probe(struct platform_device *pdev) } static const struct acpi_device_id qdf2xxx_acpi_ids[] = { - {"QCOM8001"}, + {"QCOM8001", QDF2XXX_V1}, + {"QCOM8002", QDF2XXX_V2}, {}, }; MODULE_DEVICE_TABLE(acpi, qdf2xxx_acpi_ids);