From patchwork Thu Oct 5 11:03:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 114913 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp455890qgn; Thu, 5 Oct 2017 04:03:30 -0700 (PDT) X-Received: by 10.99.128.195 with SMTP id j186mr6447096pgd.70.1507201410609; Thu, 05 Oct 2017 04:03:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507201410; cv=none; d=google.com; s=arc-20160816; b=AnBO5OtP2DlQYQWrsmBYs+dNRX2jS+rdu6v0iqp8qahEJtmlQqKapEj3TpH3Ybs7TN n66zZEWYFIH+DR0KCtt67gm1+RrAWeRTOUC7nGoi7JHDL0oNZrDwmUIv0Zafozyk5ZWf RAp82QpqiC6arzcXD5zhsehtvMpz9TFmO2sTUNkVcb1jNVKazyHTgn+maGvf3KzEIzea Ig3KWpSQ5oRg0YHCJOIcKz8j4vbe7xxCIRpuT6ExrstGT0cDabFFgfo0KtfwnbLB0air Wdni1YSj/0WIM+uzIZMo97dwKNMZTtDKtLjtpfbmqL/XgH4hvLMhfQ89ngoOMvBAoc5C kgig== 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=yZMtQlmxWqp/JnrkDV7LO3NLx+ezqXIjwYjdZMRPstA=; b=e/w2ftI5E6rF/uBF0krpc4Yr7AtRTZvMczoF0hmCORMvsXzc49btEHMBg4Rcmf77r1 z7sxDlYJlriNv7IZpgfGbGYuXyWxz7gi/cJfU7c4msXUWnd7Pw3pB53amN9ZAMEPhJWT UT0424Ecwwh1yCTyzG2/XGGEa5iJ0klC63mY434zLpV6JMTq6JZdhfVk+SvGmJKh/L7j 6XK9Kb3htjnUOa10Bxw3Y9XvFTTqCmYFW9/9hYQyIfs+oLoNPV2xcscoiKj+/1rOUKaY bp0+ERlDujuP6pkjCNzxBo+HsK1AsH6cRDaNYfBxoOjkAp2Zmt8Q7pOHyoYpVK5qEtPk Hn9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=ZZimbrva; 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 y20si11131092pll.66.2017.10.05.04.03.30; Thu, 05 Oct 2017 04:03:30 -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=ZZimbrva; 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 S1751892AbdJELD3 (ORCPT + 5 others); Thu, 5 Oct 2017 07:03:29 -0400 Received: from mail-wr0-f170.google.com ([209.85.128.170]:46114 "EHLO mail-wr0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751869AbdJELD2 (ORCPT ); Thu, 5 Oct 2017 07:03:28 -0400 Received: by mail-wr0-f170.google.com with SMTP id z1so1758165wre.3 for ; Thu, 05 Oct 2017 04:03:28 -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=e0LHRluLq+WFqV8aomeH++a/DPXxEebLML36cqt8G1c=; b=ZZimbrvaSpyGvLritM7XukBbbdfHFrALRC0p6/I/Hm//huhFXW8yC1vPeqxm79RLbw De2Zkhpo0e/4aEh0mB3ATRixsXgVGZLQF//Bd3KU1qrFhQ4d64nbQ1W0KGjSNNrcgtrP SJ/52e6x//DVAC9NvzO3JWoOryLJJYNMSAoR0= 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=e0LHRluLq+WFqV8aomeH++a/DPXxEebLML36cqt8G1c=; b=NYDEAOZ7OzFpkIScVyMZWnvxRxqZTLfpC8U/9/+GQL+bHfuKSNCg0scSmL5aYfW56/ uhf5hHgsZyFjuSBbYJh3D/aA4MDmGzx+NiEMFR2RyvQxAqeKqBKanoqd5xIhZLPbM66Z usK7WIE1E+uHiZi0ZFw+X70EBVKAmbWGgh+WS1dVJsiCT6PaWQsZk3px6Tw1eoX4cynd CZ+5YCMMVtH7F3rPJroZk8ucF1qpvhhVPLljc0PsaYCKvJJe9DtIgs49giRM4LPhtIFi OVmyawE0gEKnHApaPC9mxbDWmPCCbSbbaO3WunAP5PsyYBh4MZbjwK6qCqPeFGQLDvjv UgtQ== X-Gm-Message-State: AMCzsaUDn2mTY0RgONcUI5PvSBgNGinqj3qW7V5D8N+LsdPdt0tcOT2g nOH2pHCUBK64NIYs3aXvr60zAEBquSE= X-Google-Smtp-Source: AOwi7QDdBudbgw4jhR8WtBWHMWxZU0whDvSx5wb/Q6DYUU6Uxkqnl0xPAMdlhGpUPf3G/pTLyUn5Eg== X-Received: by 10.223.134.154 with SMTP id 26mr5102338wrx.137.1507201407549; Thu, 05 Oct 2017 04:03:27 -0700 (PDT) Received: from genomnajs.local (catv-80-98-18-187.catv.broadband.hu. [80.98.18.187]) by smtp.gmail.com with ESMTPSA id e134sm17336478wma.31.2017.10.05.04.03.26 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 05 Oct 2017 04:03:26 -0700 (PDT) From: Linus Walleij To: Wolfram Sang , linux-i2c@vger.kernel.org Cc: Linus Walleij , linux-gpio@vger.kernel.org Subject: [PATCH 2/7 v3] gpio: Make it possible for consumers to enforce open drain Date: Thu, 5 Oct 2017 13:03:05 +0200 Message-Id: <20171005110310.5900-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20171005110310.5900-1-linus.walleij@linaro.org> References: <20171005110310.5900-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 Tested-by: Geert Uytterhoeven Signed-off-by: Linus Walleij --- ChangeLog v1->v3: - Rebased 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 eb80dac4e26a..c952ef1b2f46 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -3264,8 +3264,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