Received: by 10.223.185.116 with SMTP id b49csp1056031wrg; Fri, 16 Feb 2018 11:36:27 -0800 (PST) X-Google-Smtp-Source: AH8x227cNaIdIs7hFgTMh1KyPyHi55mgFHtIaWv2HzIcub16AS4Bfm6vrt4hDD4Y3ZYqgthhgQmK X-Received: by 10.101.92.196 with SMTP id b4mr5875875pgt.27.1518809787712; Fri, 16 Feb 2018 11:36:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518809787; cv=none; d=google.com; s=arc-20160816; b=mhDIYMPkqAyL7ntMjcadnJNjoYYgzUl0h5lQSVUrFFeJYVvgVTdlYtdD3CDqxEplDL pIu8YzEdjknJ1DgYz/WMDfqJLWCLroUo2iIyEfiPCHngkAXWcd5GDTciWLBOmuc5tmV4 a9SO7d9vtJRpXa27LBSpdGrtGdlUw9Ksvu3t+TxtBU7JXA6sG0vvMFvDQa16C9KDdYZX djQWUMkxcqcaC9qWI+ZrkLtNxtCYDsmzGKZnUf/zPO9zuVF2hPrB4aaxm7DujK7S9w9g ZPpOtQfDUdPkHs3dFLah1XPW25yw97GZ+1b2rrFwj99daBOgTKKfyq+JE/D1ghkqb5qY /U/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:message-id:date:subject:cc:from :dkim-signature:arc-authentication-results; bh=VtyIZN+J+k8fly5mv3n1O6Swx02wGj/RFawNqMnWmPw=; b=mg0P3PJK7LXObUnyvJtmGSkr7NVg+PNy9VzhWQkfuOGMnypc8h/hqjzLIUOCwNrzLZ 1cIL+EqV5h+6W8NNCLglsfaymkc2T5ZPHOi7mJnG/b7eklEpmihTfly7uQmxoPJOQdos j4ihpQgMRTxGNd3rqhotaLTjHmqdcXPfdwId8hf25hG0QkM50nWLYoGd/2IRdVdRAGZ5 hs+R/ln04q5J8EE3GikWVFnhjnOaVRNDey2yqcIV6dlUIsZ7QkoOeUxp0BB2oMc6ERZh 0kybHWQa1+HOZG6OyVUAAArxAOOSeEZoccNzmKVKuA5L0y8033K3yWjwAjcaGUjjvAiQ T2Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@chromium.org header.s=google header.b=KWVUBIyL; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n10-v6si1751076plk.255.2018.02.16.11.36.13; Fri, 16 Feb 2018 11:36:27 -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=fail header.i=@chromium.org header.s=google header.b=KWVUBIyL; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753161AbeBPTMt (ORCPT + 99 others); Fri, 16 Feb 2018 14:12:49 -0500 Received: from mail-oi0-f68.google.com ([209.85.218.68]:44186 "EHLO mail-oi0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753133AbeBPTMq (ORCPT ); Fri, 16 Feb 2018 14:12:46 -0500 Received: by mail-oi0-f68.google.com with SMTP id b3so3039454oib.11 for ; Fri, 16 Feb 2018 11:12:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=VtyIZN+J+k8fly5mv3n1O6Swx02wGj/RFawNqMnWmPw=; b=KWVUBIyLOv3lwnXl9zpuyvk47HFCBrbd8x+/AFwIPNEj4cbpJ22vCoQx8VGSWNgl9y ZPyzydDaHnIcOWZVNUDDZR2vplKbVdreH0W0OLI/AtfQB2L4KRC4/evSwDXIg6kyjvS1 dLP8I3y55gYoeB+YJuQbU0WC5LNPVfe1j5cks= 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; bh=VtyIZN+J+k8fly5mv3n1O6Swx02wGj/RFawNqMnWmPw=; b=iB8sYW9iAjteIOYLF6S2C5SmZUkx4XUxzn6G6KtLY0AdfaZ2yfP7V5sC7O8bWeUrC9 i19TxT+uwT0lQbyje8nWVE35ijSW0u6PALACCQmePUq0JfZmarCrLaBadZLCO1Qb+Uy+ TJsYHfS6wiNjFZFLeT8vc6HIIDMMdepEbFRP8T/SxngQn9zQS/GBeul9kiNCCwU8RFbF CrDHJlMGmWkhGwvOLHAGewWTHDWi+5sZ3ZLDCyi3T25ithFOVw3QoQskH0X/BJMsSLUN 8DxxQlhDUA+Niz1kTsiXsxZkTFT0Bpi0GfpQnnsvOgva2kuBPBpceeaWtwkdVYpKwdw1 SY2g== X-Gm-Message-State: APf1xPCrW3BWbXVL2vNkT6AYVOUsiZTCstmX1pCtvKnZdPdjCsWOsigQ sDygYDUqMWFOI2ddMD39i8Sjug== X-Received: by 10.202.67.138 with SMTP id q132mr5238290oia.245.1518808365823; Fri, 16 Feb 2018 11:12:45 -0800 (PST) Received: from djkurtz2.bld.corp.google.com ([2620:15c:183:0:1cfd:61a5:7215:5f9c]) by smtp.gmail.com with ESMTPSA id w62sm8943912oig.2.2018.02.16.11.12.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Feb 2018 11:12:45 -0800 (PST) From: Daniel Kurtz Cc: Daniel Kurtz , Linus Walleij , linux-gpio@vger.kernel.org (open list:PIN CONTROL SUBSYSTEM), linux-kernel@vger.kernel.org (open list) Subject: [PATCH] pinctrl/amd: add get_direction handler Date: Fri, 16 Feb 2018 12:12:43 -0700 Message-Id: <20180216191243.129130-1-djkurtz@chromium.org> X-Mailer: git-send-email 2.16.1.291.g4437f3f132-goog To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On boot, gpiochip_add_data() initializes the FLAG_IS_OUT bit in desc->flags iff its gpio_chip does not have ->direction_input() handler, else it is initialized to 0, which implies the GPIO is an "input". Later, the sysfs "direction" handler will use gpiod_get_direction() to get the current direction, but if no ->get_direction() handler is installed, the result will just be the current (initial) value of flags, which will always be OUT irregardless of the initial register value. Add a get_direction() handler to pinctrl-amd to fix this and always provide the correct value for direction. Signed-off-by: Daniel Kurtz --- drivers/pinctrl/pinctrl-amd.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/pinctrl/pinctrl-amd.c b/drivers/pinctrl/pinctrl-amd.c index 61d830c2bc17..281b700fe7e9 100644 --- a/drivers/pinctrl/pinctrl-amd.c +++ b/drivers/pinctrl/pinctrl-amd.c @@ -40,6 +40,19 @@ #include "pinctrl-utils.h" #include "pinctrl-amd.h" +static int amd_gpio_get_direction(struct gpio_chip *gc, unsigned offset) +{ + unsigned long flags; + u32 pin_reg; + struct amd_gpio *gpio_dev = gpiochip_get_data(gc); + + raw_spin_lock_irqsave(&gpio_dev->lock, flags); + pin_reg = readl(gpio_dev->base + offset * 4); + raw_spin_unlock_irqrestore(&gpio_dev->lock, flags); + + return !(pin_reg & BIT(OUTPUT_ENABLE_OFF)); +} + static int amd_gpio_direction_input(struct gpio_chip *gc, unsigned offset) { unsigned long flags; @@ -845,6 +858,7 @@ static int amd_gpio_probe(struct platform_device *pdev) #endif gpio_dev->pdev = pdev; + gpio_dev->gc.get_direction = amd_gpio_get_direction; gpio_dev->gc.direction_input = amd_gpio_direction_input; gpio_dev->gc.direction_output = amd_gpio_direction_output; gpio_dev->gc.get = amd_gpio_get_value; -- 2.16.1.291.g4437f3f132-goog