From patchwork Thu Jul 27 18:19:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timur Tabi X-Patchwork-Id: 794542 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=codeaurora.org header.i=@codeaurora.org header.b="CLVBGk0L"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=codeaurora.org header.i=@codeaurora.org header.b="CLVBGk0L"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3xJKxx49QVz9s0g for ; Fri, 28 Jul 2017 04:19:33 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751530AbdG0STc (ORCPT ); Thu, 27 Jul 2017 14:19:32 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:57360 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751446AbdG0STb (ORCPT ); Thu, 27 Jul 2017 14:19:31 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id B4452608EA; Thu, 27 Jul 2017 18:19:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1501179570; bh=BWwThiAxnOLafsUmyltQ4eTMKVlXZLVTS4fofBhLPj4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CLVBGk0LHZV2Ds6a9EQi1M7q8EVrwMPNIG9rdtjIvvhxnXybMPMAsWw3Q65jy/ONY O2r8qfP6qTA6c7dxs5X83AqEjFV9Py170W9iNHDkY234BRnI37dIf1EeHzCt6uo0cM QOvPALYFCWiLQYIQMaXHI7G0ON+2cqDBnxpPGnCQ= 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 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 8B7646080A; Thu, 27 Jul 2017 18:19:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1501179570; bh=BWwThiAxnOLafsUmyltQ4eTMKVlXZLVTS4fofBhLPj4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CLVBGk0LHZV2Ds6a9EQi1M7q8EVrwMPNIG9rdtjIvvhxnXybMPMAsWw3Q65jy/ONY O2r8qfP6qTA6c7dxs5X83AqEjFV9Py170W9iNHDkY234BRnI37dIf1EeHzCt6uo0cM QOvPALYFCWiLQYIQMaXHI7G0ON+2cqDBnxpPGnCQ= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 8B7646080A 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: Thu, 27 Jul 2017 13:19:23 -0500 Message-Id: <1501179565-26466-2-git-send-email-timur@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1501179565-26466-1-git-send-email-timur@codeaurora.org> References: <1501179565-26466-1-git-send-email-timur@codeaurora.org> Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org 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