From patchwork Mon Sep 3 08:15:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 145748 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp2214052ljw; Mon, 3 Sep 2018 01:22:39 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZQO9JOid/orlaggC3ykN+uwyCdj0xkNCj2jwAhal0F08bGLAJBWX26YqT9iw3k2OF7ibNu X-Received: by 2002:a17:902:2804:: with SMTP id e4-v6mr27080506plb.327.1535962958918; Mon, 03 Sep 2018 01:22:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535962958; cv=none; d=google.com; s=arc-20160816; b=nk5xCNGuVB8HyABvz/ge/sJAV7w8QvA5aeGog4d60vV6oYWE8+XCN1plzt3NXScNUX 3vBNyod5ri28EUdbiEfhiBU1wKh62t5svkPzYMtn9KIRiSqsxLdE9JP3Z4P+JXwP+SlF cPggQ2kdi7prvNX3VDLu7sRqZ08ER9JgdAw4Y3+7IApZ/m+pcZaGeNXQT7SjItXavIcG 9UBhBLP8VLdcKNezmvRjd0AKYYGYMHdvH21nIE/WW8Zxc0NGQOCY+0PUI+Ufe0YiyVY+ ryf3QOHM3kBH3vgWCe7RWtHDWF6GchJCu25VeI2BKNAbMwmVIhjnTzTwSZcWaZiM7xT8 m8TQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=XEcpm+3WaXTYPG5fNwNiSZCQyxPLqp3yFr9WS/uz8xg=; b=rcNJAJFYY5cBiJN3MmFkaNJA9V/MWVgCh8N7ghsZeWn/E9ZHKBIzwhVZZbLNT4r/Ve 7PirRgMok8loJheJqhmpTQiPzECtTGAnF+Q/s8oF89K/WXF3581JLNfQNn4yH2wK851S nZU6gl+po7t+E9UDAR9FvRrfaDKiNn/8YbVcn7B2pmrOLfmGtsp7Y2yTxvFCv4t7ft8j Oa3WNjRhGSLB8GwYKmILS4ziGqkBaZ9imGCWgTYL+vSWLhnlHA7MWRdLImrVoVZLyryw w933PqlaVimZkHkLJyEiOLAmTqe4ib/XUAkEf/9pKzhhKtFByGBEFaM4ubcFXbCTVih/ Sn9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="HH18ON/s"; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x61-v6si18233629plb.216.2018.09.03.01.22.38; Mon, 03 Sep 2018 01:22:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="HH18ON/s"; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725984AbeICMlk (ORCPT + 5 others); Mon, 3 Sep 2018 08:41:40 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:43430 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725901AbeICMlk (ORCPT ); Mon, 3 Sep 2018 08:41:40 -0400 Received: by mail-lj1-f193.google.com with SMTP id m84-v6so14631119lje.10 for ; Mon, 03 Sep 2018 01:22:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XEcpm+3WaXTYPG5fNwNiSZCQyxPLqp3yFr9WS/uz8xg=; b=HH18ON/s6T1YZTJiYMlqlonpu6QUf+U4NoiECCsAz6rJrKr4cjqPubiv4dDduTMeLy rHpVgTvqQ07Tq6P0IXMsiomTY0AZ3m5E3tnmSSwckDrg8OZ+GoUHuwT2Mc/Jd1rEKfHW tTPX6e6M+0TvsGKs1Y4+JhMMY6fcYiETVe3r4= 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=XEcpm+3WaXTYPG5fNwNiSZCQyxPLqp3yFr9WS/uz8xg=; b=FbPtfDgY3lr7mOz+hcYyYxCrSbeNrdoU7uSbkD8OHB5EItoffO6lDcqwC41gI9mdqN dgLiEPDf/ALdRF7olP0wGE4rmHAjbZlX85FLJndkfP4UtmW206e5lwWIZFp6BUShujwC PJ7tUGEGChwPJUM+TZnsm1aDyB9/4/2FmWo85XylOHC1EvE/oASSPHA51xzWUjbUKF2P Fx+nxrRLxDxIapiw8DZbQXU2xwG7zr2sUkPB3GbBQh5UbB0QmnTwB+v1RL9hq5EN3vXO BRSOqT+iBp1hETbpvdi1VDoK8NPdAY2LMp1+AmHalsRUoVVcVmpQZaylaiJCcP46LWjk KdIQ== X-Gm-Message-State: APzg51BYdsy3pItQQYkKsfQDrwVdJNkMXXD9nj+X+aC7TjMiDSHlyVmJ VI8z82inyvd9dyl9Fi109YlFRt+eSMuutg== X-Received: by 2002:a2e:870b:: with SMTP id m11-v6mr18028425lji.2.1535962955918; Mon, 03 Sep 2018 01:22:35 -0700 (PDT) Received: from localhost.localdomain (c-ae7b71d5.014-348-6c756e10.bbcust.telenor.se. [213.113.123.174]) by smtp.gmail.com with ESMTPSA id r70-v6sm3316035lff.0.2018.09.03.01.22.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Sep 2018 01:22:34 -0700 (PDT) From: Linus Walleij To: linux-gpio@vger.kernel.org Cc: Linus Walleij , Tony Lindgren Subject: [PATCH 3/7] gpio: twl4030: Implement .get_direction() Date: Mon, 3 Sep 2018 10:15:52 +0200 Message-Id: <20180903081556.1411-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180903081556.1411-1-linus.walleij@linaro.org> References: <20180903081556.1411-1-linus.walleij@linaro.org> Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org It's nice to be able to read back the direction of the GPIO line from the hardware so implement .get_direction() for twl4030. Cc: Tony Lindgren Signed-off-by: Linus Walleij --- drivers/gpio/gpio-twl4030.c | 42 ++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/drivers/gpio/gpio-twl4030.c b/drivers/gpio/gpio-twl4030.c index 1e47ddff33f6..fbfb648d3502 100644 --- a/drivers/gpio/gpio-twl4030.c +++ b/drivers/gpio/gpio-twl4030.c @@ -154,6 +154,23 @@ static int twl4030_set_gpio_direction(int gpio, int is_input) return ret; } +static int twl4030_get_gpio_direction(int gpio) +{ + u8 d_bnk = gpio >> 3; + u8 d_msk = BIT(gpio & 0x7); + u8 base = REG_GPIODATADIR1 + d_bnk; + int ret = 0; + + ret = gpio_twl4030_read(base); + if (ret < 0) + return ret; + + /* 1 = output, but gpiolib semantics are inverse so invert */ + ret = !(ret & d_msk); + + return ret; +} + static int twl4030_set_gpio_dataout(int gpio, int enable) { u8 d_bnk = gpio >> 3; @@ -359,6 +376,28 @@ static int twl_direction_out(struct gpio_chip *chip, unsigned offset, int value) return ret; } +static int twl_get_direction(struct gpio_chip *chip, unsigned offset) +{ + struct gpio_twl4030_priv *priv = gpiochip_get_data(chip); + /* + * Default 0 = output + * LED GPIOs >= TWL4030_GPIO_MAX are always output + */ + int ret = 0; + + mutex_lock(&priv->mutex); + if (offset < TWL4030_GPIO_MAX) { + ret = twl4030_get_gpio_direction(offset); + if (ret) { + mutex_unlock(&priv->mutex); + return ret; + } + } + mutex_unlock(&priv->mutex); + + return ret; +} + static int twl_to_irq(struct gpio_chip *chip, unsigned offset) { struct gpio_twl4030_priv *priv = gpiochip_get_data(chip); @@ -374,8 +413,9 @@ static const struct gpio_chip template_chip = { .request = twl_request, .free = twl_free, .direction_input = twl_direction_in, - .get = twl_get, .direction_output = twl_direction_out, + .get_direction = twl_get_direction, + .get = twl_get, .set = twl_set, .to_irq = twl_to_irq, .can_sleep = true,