From patchwork Sun Sep 10 21:44:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 812183 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="f13CFFUt"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3xr4N12555z9s4s for ; Mon, 11 Sep 2017 07:44:49 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751732AbdIJVor (ORCPT ); Sun, 10 Sep 2017 17:44:47 -0400 Received: from mail-lf0-f49.google.com ([209.85.215.49]:37169 "EHLO mail-lf0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751901AbdIJVop (ORCPT ); Sun, 10 Sep 2017 17:44:45 -0400 Received: by mail-lf0-f49.google.com with SMTP id 80so14425824lfy.4 for ; Sun, 10 Sep 2017 14:44:44 -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=f13CFFUtVyfsx5AcGsEqVgUFWW5TDbW6HKWikPTRqIHSH2wUOO+OlgOTRvUknjyOnK OdfuYEqlLGs3KBIOux40PqfeW8C9zXrUsWzjzfNA615n22sm02zpxRfSo8AJnwftFNae CnydNw11w+CGGgYpZZ3B5VGLmnwSWpDJJi1E8= 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=uOcRMMzyU1zlwWfOaFcmxO9Okm2sVD1vZdydT+VmnIWncrkYfZdeJsAWhfbYw+Cx3h p+wqss1nkfJwq/uVJX/XiNmBZzBWw/Te5F9ooWpiC1hhbt+25em0f1DYp4rOnmNI/OUK Nj9XhUMH0L1OlZyVSg9kAS86KIcmwbFjN7FIx3NNo2pxf2XDHMRtKLVxbJECAZ+HXY+c LIuJUJd9n3LhLWPbTX1Qo3knEjuzrNmNPTvhy9bvRu8B3UVpH7yq4lzLrhC4CUImF9Ve UM7lqfJ1/o+SYJ78yF+TzjXgYvcL1GlkphIxIDtafNYgfFk3Y+d9ucp/zPP51CSKrDSG QgDw== X-Gm-Message-State: AHPjjUhT3uwbFyFzw3qLDPcdF5gC9qPG9pofICGO14E0NRG8B+LXYUqj uOZ2tBR2HD3G27iPphtrnw== X-Google-Smtp-Source: ADKCNb5W6zIcbW16ATH6Qujab5EAE8VX7IQ2ZIqmOz4qsx8c10NUo7kV+LHavYyn+Znnh/Ph1Xk/CA== X-Received: by 10.46.69.194 with SMTP id s185mr3629566lja.102.1505079884086; Sun, 10 Sep 2017 14:44:44 -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 c69sm1461546ljd.42.2017.09.10.14.44.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 10 Sep 2017 14:44:43 -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, Linus Walleij , linux-gpio@vger.kernel.org Subject: [PATCH 2/5] gpio: Make it possible for consumers to enforce open drain Date: Sun, 10 Sep 2017 23:44:21 +0200 Message-Id: <20170910214424.14945-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170910214424.14945-1-linus.walleij@linaro.org> References: <20170910214424.14945-1-linus.walleij@linaro.org> Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@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(+) 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