From patchwork Mon Jul 17 23:43:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timur Tabi X-Patchwork-Id: 9846465 X-Patchwork-Delegate: agross@codeaurora.org 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 6AA8F6037F for ; Mon, 17 Jul 2017 23:44:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 851B226224 for ; Mon, 17 Jul 2017 23:44:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7952A269DA; Mon, 17 Jul 2017 23:44:10 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2FDBF26224 for ; Mon, 17 Jul 2017 23:44:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751671AbdGQXoI (ORCPT ); Mon, 17 Jul 2017 19:44:08 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:35162 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751615AbdGQXoH (ORCPT ); Mon, 17 Jul 2017 19:44:07 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 0CE4A607A7; Mon, 17 Jul 2017 23:44:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1500335047; bh=BWwThiAxnOLafsUmyltQ4eTMKVlXZLVTS4fofBhLPj4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zb2x3oeRfsch57Sg4mXz/Bxlz3jqUReM3nNYTCIfbHyuiCr/WgaeKXegqNvxqmDjS NffgChGzT/4rsukR6fd4StLTO5maowVAARwzP3iv7l2H6PM1T2jfMYptgxOp4z/yi3 RpB3yRy2t1qrk9guEWtQiXJfjpIqYKToBT1WFky4= Received: from timur-ubuntu.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: timur@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id A65B8607A7; Mon, 17 Jul 2017 23:44:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1500335046; bh=BWwThiAxnOLafsUmyltQ4eTMKVlXZLVTS4fofBhLPj4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NW+mrmzDmeefZC89CQmloDHZKxfLvNzh5E61p4O9SzTDIx+ZCo75L/GDJ3hpawyAA xAmmiqWEskMNjWh4U98+xnnzaXdPlh6H1uNcasHdQdvqBb0L5ydty+1ex1OI4+wCTG AjqSiQoEStdAkkuzXwOybTFX4+UMVpyCEUNJwRr0= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org A65B8607A7 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=timur@codeaurora.org From: Timur Tabi To: andy.gross@linaro.org, david.brown@linaro.org, Linus Walleij , Bjorn Andersson , linux-gpio@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: timur@codeaurora.org Subject: [PATCH 1/3] gliolib: request the gpio before querying its direction Date: Mon, 17 Jul 2017 18:43:59 -0500 Message-Id: <1500335041-32711-2-git-send-email-timur@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500335041-32711-1-git-send-email-timur@codeaurora.org> References: <1500335041-32711-1-git-send-email-timur@codeaurora.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Before querying a GPIO to determine its direction, the GPIO should be formally requested. This allows the GPIO driver to block access to unavailable GPIOs, which makes it easier for some drivers to support sparse GPIO maps. Signed-off-by: Timur Tabi --- drivers/gpio/gpiolib.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 9568708..3b4e1e8 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1202,6 +1202,14 @@ int gpiochip_add_data(struct gpio_chip *chip, void *data) struct gpio_desc *desc = &gdev->descs[i]; desc->gdev = gdev; + + if (chip->request) { + status = chip->request(chip, i); + if (status < 0) + /* The GPIO is unavailable, so skip it */ + continue; + } + /* * REVISIT: most hardware initializes GPIOs as inputs * (often with pullups enabled) so power usage is @@ -1227,6 +1235,9 @@ int gpiochip_add_data(struct gpio_chip *chip, void *data) */ set_bit(FLAG_IS_OUT, &desc->flags); } + + if (chip->free) + chip->free(chip, i); } #ifdef CONFIG_PINCTRL