From patchwork Sun Sep 17 09:39:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 112823 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp2503447qgf; Sun, 17 Sep 2017 02:39:28 -0700 (PDT) X-Received: by 10.99.109.68 with SMTP id i65mr30032879pgc.335.1505641168786; Sun, 17 Sep 2017 02:39:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505641168; cv=none; d=google.com; s=arc-20160816; b=rifsiedZIfVvr1DzPw9hFPlrSRvNvpCCPllYziX+z8yJns5fCM17ukaVQzUxOoiafZ /oqYfPZ9tB9HNGooiLSPdQW99539GFa+TKP2Wwo8fqDnd0/OiYf+EKCmSD/7rb2FxqFQ GQEjQKTr2+EG+n5cSka9/B+kNdts/Ue3mCpAxsEz6/VNeglxcS5C082lpe5jHknKoRlA BQiRlwJtUNrN7Bklwf/v7e1ENTgsI3HT2tPGROlhVBuvU3+ZurSw8adiSR6kGj4t61Tu /7i3N7p+tEmsjwXcG50n6a1yncTemGOSm77qdyMBsL95asi03hhYj+fk516zjImYQJZk grXQ== 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=ELCtNJmtjxc5l0ySjAYxHROzzrSIM8GBKSTeRAxLB74=; b=WRi7VPlkcUuKIxJsBbo3MUksuJbNUovVhCtNAtK+6cmLCNHIT1OGLvz8IQmgbO9e0k tbjvKT9zLSmKlaTVndmP6x0xqQbstaAhwo/ovcooHZ21vXU7IE1kEjuWhvwx22S69CEz 5D+7Xvdr1tkn+7PO66dTUK3BCPCmIBL06Ra3bOu3gEEBnkByYjQ8PMi34mswKUf64E70 d35F9unnH3vf/6z2hT8A5HngxYA3SUHht9Hg4GowNavT/vRCzGS9Vn4xOcpglRW2PRFT nSKh9wphvWxODgyAdkVIF3ov4etZhB8mInQpTN/ksE7PMIKsh6qMndYaX8MLCS3hLvYG pO9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=h9o1eW8j; 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 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 t8si3374838plz.730.2017.09.17.02.39.28; Sun, 17 Sep 2017 02:39:28 -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 header.s=google header.b=h9o1eW8j; 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 sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751282AbdIQJj1 (ORCPT + 5 others); Sun, 17 Sep 2017 05:39:27 -0400 Received: from mail-lf0-f43.google.com ([209.85.215.43]:49078 "EHLO mail-lf0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750995AbdIQJjZ (ORCPT ); Sun, 17 Sep 2017 05:39:25 -0400 Received: by mail-lf0-f43.google.com with SMTP id q132so5568261lfe.5 for ; Sun, 17 Sep 2017 02:39:24 -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=3OzOMaHhrE0eXAmi4wMrtmLcwMGHbnzFG+tb1ouVSTM=; b=h9o1eW8jpHAdZRteNgk3OksD3HJWw663mjRBWmmNyIHff5s+xBarw9TE+HFb5b1x1w WyzpyrXB+qKN2yZeCDuYhY5nCMd2SGlj/rZ+DIIdmwPJmuHeGo7i/auorH5GcF7F+66e aL5vmIk4L+ZXCv5Wp/qU1RJetRj52flGYPYU4= 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=3OzOMaHhrE0eXAmi4wMrtmLcwMGHbnzFG+tb1ouVSTM=; b=KpIYyvk0L/Fuy9B37E2ClydK7A3tCmrT33TiwiQma2+UCBopX+WR85YuXi/uUC1BIr mz9o6R8t0JdZU62ExoHjdIekd597KL5U9w9zhGxmi2bMV8PVbWpBm1CmRzidAcBtS+Up zfCJa6CqUfx0ZTDx1U/zdoeVZB8vHGeEVf9bGJQwPQtyE2W+74098wDgK6vBwgeUeGyM 8XRIspgtGdTmPxwQD76led1VdRWXz/vdzA63D8TwShy7tUOY/EyEQdADOgrj5J4+ZQCu jGz9Vc/wT18O7wRzyOdVQjsHQ8vGkHxwDjPeF9wEA6HvwyMTAmO/wJoIt/tF6em77i1d ASQw== X-Gm-Message-State: AHPjjUgOi0TrvEdZ/IyOLqC4cTpeS+/iVWjZ1+UCV4i2kgZBWskIWt4W aBq3K/XhP1Peh012 X-Google-Smtp-Source: ADKCNb5Brd7VoUyl0ngq6CMN/j7kCfCH46P0c10w9FdvCkcHeSgEskHY4h6tl/MKq05hEom4EkVa3g== X-Received: by 10.46.70.10 with SMTP id t10mr11890246lja.30.1505641163837; Sun, 17 Sep 2017 02:39:23 -0700 (PDT) Received: from fabina.bredbandsbolaget.se (c-2209e055.014-348-6c756e10.cust.bredbandsbolaget.se. [85.224.9.34]) by smtp.gmail.com with ESMTPSA id t84sm974559lfi.21.2017.09.17.02.39.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 17 Sep 2017 02:39:23 -0700 (PDT) From: Linus Walleij To: Wolfram Sang , linux-i2c@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-mips@linux-mips.org, adi-buildroot-devel@lists.sourceforge.net, Geert Uytterhoeven , Linus Walleij , linux-gpio@vger.kernel.org Subject: [PATCH 2/7] gpio: Make it possible for consumers to enforce open drain Date: Sun, 17 Sep 2017 11:39:01 +0200 Message-Id: <20170917093906.16325-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170917093906.16325-1-linus.walleij@linaro.org> References: <20170917093906.16325-1-linus.walleij@linaro.org> Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Some busses, like I2C, strictly need to have the line handled as open drain, i.e. not actively driven high. For this reason the i2c-gpio.c bit-banged I2C driver is reimplementing open drain handling outside of gpiolib. This is not very optimal. Instead make it possible for a consumer to explcitly express that the line must be handled as open drain instead of allowing local hacks papering over this issue. The descriptor tables, whether DT, ACPI or board files, should of course have flagged these lines as open drain. E.g.: enum gpio_lookup_flags GPIO_OPEN_DRAIN for a board file, or gpios = <&foo 42 GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN>; in a device tree using But more often than not, these descriptors are wrong. So we need to make it possible for consumers to enforce this open drain behaviour. We now have two new enumerated GPIO descriptor config flags: GPIOD_OUT_LOW_OPEN_DRAIN and GPIOD_OUT_HIGH_OPEN_DRAIN that will set up the lined enforced as open drain as output low or high, using open drain (if the driver supports it) or using open drain emulation (setting the line as input to drive it high) from the gpiolib core. Cc: linux-gpio@vger.kernel.org Signed-off-by: Linus Walleij --- Obviously I authorize this patch to be applied directly to the I2C tree as part of the refactorings. --- drivers/gpio/gpiolib.c | 13 +++++++++++++ include/linux/gpio/consumer.h | 6 ++++++ 2 files changed, 19 insertions(+) -- 2.13.5 -- 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/gpiolib.c b/drivers/gpio/gpiolib.c index cd003b74512f..cb73a50a5d5d 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -3228,8 +3228,21 @@ int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id, if (lflags & GPIO_ACTIVE_LOW) set_bit(FLAG_ACTIVE_LOW, &desc->flags); + if (lflags & GPIO_OPEN_DRAIN) set_bit(FLAG_OPEN_DRAIN, &desc->flags); + else if (dflags & GPIOD_FLAGS_BIT_OPEN_DRAIN) { + /* + * This enforces open drain mode from the consumer side. + * This is necessary for some busses like I2C, but the lookup + * should *REALLY* have specified them as open drain in the + * first place, so print a little warning here. + */ + set_bit(FLAG_OPEN_DRAIN, &desc->flags); + gpiod_warn(desc, + "enforced open drain please flag it properly in DT/ACPI DSDT/board file\n"); + } + if (lflags & GPIO_OPEN_SOURCE) set_bit(FLAG_OPEN_SOURCE, &desc->flags); if (lflags & GPIO_SLEEP_MAY_LOOSE_VALUE) diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h index 8f702fcbe485..5f72a49d1aa3 100644 --- a/include/linux/gpio/consumer.h +++ b/include/linux/gpio/consumer.h @@ -28,6 +28,7 @@ struct gpio_descs { #define GPIOD_FLAGS_BIT_DIR_SET BIT(0) #define GPIOD_FLAGS_BIT_DIR_OUT BIT(1) #define GPIOD_FLAGS_BIT_DIR_VAL BIT(2) +#define GPIOD_FLAGS_BIT_OPEN_DRAIN BIT(3) /** * Optional flags that can be passed to one of gpiod_* to configure direction @@ -39,6 +40,11 @@ enum gpiod_flags { GPIOD_OUT_LOW = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT, GPIOD_OUT_HIGH = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT | GPIOD_FLAGS_BIT_DIR_VAL, + GPIOD_OUT_LOW_OPEN_DRAIN = GPIOD_FLAGS_BIT_DIR_SET | + GPIOD_FLAGS_BIT_DIR_OUT | GPIOD_FLAGS_BIT_OPEN_DRAIN, + GPIOD_OUT_HIGH_OPEN_DRAIN = GPIOD_FLAGS_BIT_DIR_SET | + GPIOD_FLAGS_BIT_DIR_OUT | GPIOD_FLAGS_BIT_DIR_VAL | + GPIOD_FLAGS_BIT_OPEN_DRAIN, }; #ifdef CONFIG_GPIOLIB