From patchwork Tue Apr 5 13:16:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 65069 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp459126lbc; Tue, 5 Apr 2016 06:16:55 -0700 (PDT) X-Received: by 10.66.66.73 with SMTP id d9mr62070437pat.117.1459862214921; Tue, 05 Apr 2016 06:16:54 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e17si1039968pag.63.2016.04.05.06.16.54; Tue, 05 Apr 2016 06:16:54 -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=neutral (body hash did not verify) header.i=@linaro.org; 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=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752362AbcDENQy (ORCPT + 4 others); Tue, 5 Apr 2016 09:16:54 -0400 Received: from mail-lb0-f172.google.com ([209.85.217.172]:36266 "EHLO mail-lb0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751976AbcDENQx (ORCPT ); Tue, 5 Apr 2016 09:16:53 -0400 Received: by mail-lb0-f172.google.com with SMTP id qe11so9057764lbc.3 for ; Tue, 05 Apr 2016 06:16:52 -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; bh=uieFib/xGpN6D1v6Eq+a22RM5x+np0e1YcL2YTqn0eY=; b=QC6EWfBYao2itSaBzHD04id7dAE32BxWTpDYbaxYWqUUIOLSPMaaf/ZKaYZUawaAJI 3G2BRlc05ykaBZds8XyqYN8/YJc8zlrRfTYzL4u4vZ3lSPg77MqZ48muN+dMxXcabB4B ztS+fzmK7roS2mJ24J/HbxMZLGE9TOjLzhtAs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=uieFib/xGpN6D1v6Eq+a22RM5x+np0e1YcL2YTqn0eY=; b=HAx0iY3eCE6khCwmEwySDsywb9cuWNq7yOFYZhj/1Eys7WF/fVQMonzVGfa4+kCqG9 r6rQM2W1cPkvXSb6W08qG1jJ75YSW5iWk/78KziHGFL+dhBHIaMrdn8Ze7kx5u/MyATb j+tK3ZWfzEn2EXTbhwje0sr9zIfd94m1m4RPOTHkZNdxvW/jngS8c6ZnNcqtw9XCZF2j QVGcd3byqBTI5wQRj6ZBefSimnZJxWa9h/gjZIwe1UZjdM+m+nKOaLCWUSs3qU190hl5 a/pZsy584Wv75RyBIYvOU3SQ5LDTOlUaTw389z4Mnv6bYrfO/Hgpqc60zbSpIUyFvedE I5bQ== X-Gm-Message-State: AD7BkJKvHhMj9T9bu5gXBSJjAvDRIj/ukrpZ/qCosIfIIQr//G1Pvjq82QVjGbpZXWVj+E3z X-Received: by 10.112.63.196 with SMTP id i4mr10968346lbs.93.1459862211670; Tue, 05 Apr 2016 06:16:51 -0700 (PDT) Received: from localhost.localdomain ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id jo1sm2920731lbc.3.2016.04.05.06.16.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Apr 2016 06:16:50 -0700 (PDT) From: Linus Walleij To: linux-gpio@vger.kernel.org, Alexandre Courbot Cc: Linus Walleij , Michael Hennerich Subject: [PATCH] gpio: tc3589x: implement open drain/source callback Date: Tue, 5 Apr 2016 15:16:47 +0200 Message-Id: <1459862207-3560-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 2.4.3 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org This makes use of the new .set_single_ended() callback to set the GPIO line as open drain/open source using hardware. The TC3589x can do this by either disabling the N-MOS transistor (open drain) or the P-MOS transistor (open source) of the output driver stage, in the first case making the signal drive actively low and high impedance as "high" and in the second case actively high and high impedance, which is as close to native open drain support as we come. Cc: Michael Hennerich Signed-off-by: Linus Walleij --- drivers/gpio/gpio-tc3589x.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) -- 2.4.3 -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/gpio/gpio-tc3589x.c b/drivers/gpio/gpio-tc3589x.c index 67332943e09a..03086e5c81cb 100644 --- a/drivers/gpio/gpio-tc3589x.c +++ b/drivers/gpio/gpio-tc3589x.c @@ -85,6 +85,46 @@ static int tc3589x_gpio_direction_input(struct gpio_chip *chip, return tc3589x_set_bits(tc3589x, reg, BIT(pos), 0); } +static int tc3589x_gpio_single_ended(struct gpio_chip *chip, + unsigned offset, + enum single_ended_mode mode) +{ + struct tc3589x_gpio *tc3589x_gpio = gpiochip_get_data(chip); + struct tc3589x *tc3589x = tc3589x_gpio->tc3589x; + /* + * These registers are alterated at each second address + * ODM bit 0 = drive to GND or Hi-Z (open drain) + * ODM bit 1 = drive to VDD or Hi-Z (open source) + */ + u8 odmreg = TC3589x_GPIOODM0 + (offset / 8) * 2; + u8 odereg = TC3589x_GPIOODE0 + (offset / 8) * 2; + unsigned pos = offset % 8; + int ret; + + switch(mode) { + case LINE_MODE_OPEN_DRAIN: + /* Set open drain mode */ + ret = tc3589x_set_bits(tc3589x, odmreg, BIT(pos), 0); + if (ret) + return ret; + /* Enable open drain/source mode */ + return tc3589x_set_bits(tc3589x, odereg, BIT(pos), BIT(pos)); + case LINE_MODE_OPEN_SOURCE: + /* Set open source mode */ + ret = tc3589x_set_bits(tc3589x, odmreg, BIT(pos), BIT(pos)); + if (ret) + return ret; + /* Enable open drain/source mode */ + return tc3589x_set_bits(tc3589x, odereg, BIT(pos), BIT(pos)); + case LINE_MODE_PUSH_PULL: + /* Disable open drain/source mode */ + return tc3589x_set_bits(tc3589x, odereg, BIT(pos), 0); + default: + break; + } + return -ENOTSUPP; +} + static struct gpio_chip template_chip = { .label = "tc3589x", .owner = THIS_MODULE, @@ -92,6 +132,7 @@ static struct gpio_chip template_chip = { .get = tc3589x_gpio_get, .direction_output = tc3589x_gpio_direction_output, .set = tc3589x_gpio_set, + .set_single_ended = tc3589x_gpio_single_ended, .can_sleep = true, };