Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp5495442ybe; Tue, 17 Sep 2019 08:49:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqxotEolO5uTox5rp+bW6Z9iTell5F6+KXFjwkROW5mPFsPjGD/CorztE/16n+RBBVoI5hx3 X-Received: by 2002:a17:906:d050:: with SMTP id bo16mr5540341ejb.146.1568735379865; Tue, 17 Sep 2019 08:49:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568735379; cv=none; d=google.com; s=arc-20160816; b=lxdh3IzirGOgsfD/Q3/kOUFz3Yd0nffaIsvGiGPIXh+5E8POciTE+8roMujOoaC+U8 7KIBFJVMZSDeV1Cx/rpfWfizOUfgeZzyZbYqDlu1w+TEuPaUSPw5M0w/E2uffx+xTrYA ZWksH2gWb3HY8IfQFcgqcrXUYu7NNAA3D/LO28XM7qQPaGlViYP420ZdfUOnUqYjbz4E Ux3n+SozKJ7aTEJTFEVNKMBktw5DZsQNQzJFwSFOD4BGmVipQed+0GeOHgL/ktD7b3Mu x0WStiDU8NvBhCAepH/gI+q8k+UzAH5X7NaG5eNwzF591IJFcQ1DbpToMJmnxrypBf9S nbuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=1MfI2BUn+6tqfZ16hSgU4bHuPAnYWosgljP1K/jNAUk=; b=qymW4jUnE/jTJJvIvBSXSsL+udmWel46FKDCYR3o/Tp7ECs3RQUamdY9Db/mGxZTRe yNf5UAvfdWnOFA/jQ243xNe14LTTjSydsDHQY9lPCbM1wl17ORbLx43eH82J3m/SVY15 uxUbgIpla9d0OMU6brvhZ7fVXWzdef8uVUt08NEpt/dY3ZZLDHNlbvXF5dPWxCdTUucU LDaAVuo+YqCy+wGwxS6w2K8eg+VAHK7bP2CIZn0CZMl031JS5n+Y6lWgD7pdWKRa0paA dRrabbQEMo33QqeBe+79l6b5nQUL2Y6F1aXDmyIjkZrDQM/7r3rZ1h2hNYkUO5FwPaE+ 1Ezw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=uMSa9ByB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v39si1568041edc.234.2019.09.17.08.49.14; Tue, 17 Sep 2019 08:49:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=uMSa9ByB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729889AbfIQHyq (ORCPT + 99 others); Tue, 17 Sep 2019 03:54:46 -0400 Received: from mail-io1-f67.google.com ([209.85.166.67]:43161 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727437AbfIQHyq (ORCPT ); Tue, 17 Sep 2019 03:54:46 -0400 Received: by mail-io1-f67.google.com with SMTP id v2so5297095iob.10 for ; Tue, 17 Sep 2019 00:54:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=1MfI2BUn+6tqfZ16hSgU4bHuPAnYWosgljP1K/jNAUk=; b=uMSa9ByBd5dZn3HsLuGCW9jH2ynOvuqc23ArZOwf1C/HIYpOHrBluhzFD8ADkdFMXz 6eK4kgbEp8EleCubq0fuMB8+TN9Z6jXgudV9sh9FiGXJRkU6cONyLwhb1sdkzctHfmwS vn5bbrOIuwN7fQPHJ8GE4IwGJwW1AS5MD9ymqcpDE/Kl6aGzvuAgojp5qXBGPkTy381b bT+dtwnV3I+2eHpueB2qB45h2GiMFjVbHyXfyJCz1M0vP/3hyD5iHrBKMqtynSf16Lvr njj4zxLBH3o8Hn38PgmMS/XL7i/G4KGkWxZ+S+iJAUyYer70u3Une0N0F+33PIhSlWpf ks8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=1MfI2BUn+6tqfZ16hSgU4bHuPAnYWosgljP1K/jNAUk=; b=UnlZ+xm+oqldi8Vms+AeEgP7vPT6EVKKQSYUENOBQYcQDexGwQUpRAddPaBEF7FC0P tYz4FTx4vBnABZKEZ/BgowN7p1AJWZFehYYYfuZ0Ba/FXcMoxYzw62bY86E5BV6ZFojt jtVRumvBl9K5HH3rUyq5cIHbkmN7gEu71E/ppErJIn3S2c2rDyWKAc2ZfxOAh7H0dTw4 5a0CxOdE+qWcjCycUEOUKrYHIK4GwWsDNckt8Antw9O/bJ0Y3TwhrA1HcVlIx5IwAa/r S+/nhkHo75EbVMyGPL0vHOzWfLDJwdS408ZmDQp/Y2ycb0gVzpUfd1mjkftOUSbiErQx 0Eog== X-Gm-Message-State: APjAAAUrftpHKes9lusNAnNg58KxtCR7iH2YwCMECICZrD4epEp8ZHxI XeClK7yEU9m9impxPDMB+158Nfo51fK0NHLIWNyVtg== X-Received: by 2002:a5e:a812:: with SMTP id c18mr2251967ioa.220.1568706885178; Tue, 17 Sep 2019 00:54:45 -0700 (PDT) MIME-Version: 1.0 References: <20190910082138.30193-1-brgl@bgdev.pl> In-Reply-To: <20190910082138.30193-1-brgl@bgdev.pl> From: Bartosz Golaszewski Date: Tue, 17 Sep 2019 09:54:34 +0200 Message-ID: Subject: Re: [PATCH] gpiolib: don't clear FLAG_IS_OUT when emulating open-drain/open-source To: Linus Walleij Cc: "open list:GPIO SUBSYSTEM" , Linux Kernel Mailing List , Bartosz Golaszewski , stable , Kent Gibson Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org wt., 10 wrz 2019 o 10:22 Bartosz Golaszewski napisa=C5=82(a= ): > > From: Bartosz Golaszewski > > When emulating open-drain/open-source by not actively driving the output > lines - we're simply changing their mode to input. This is wrong as it > will then make it impossible to change the value of such line - it's now > considered to actually be in input mode. If we want to still use the > direction_input() callback for simplicity then we need to set FLAG_IS_OUT > manually in gpiod_direction_output() and not clear it in > gpio_set_open_drain_value_commit() and > gpio_set_open_source_value_commit(). > > Fixes: c663e5f56737 ("gpio: support native single-ended hardware drivers"= ) > Cc: stable@vger.kernel.org > Reported-by: Kent Gibson > Signed-off-by: Bartosz Golaszewski > --- > drivers/gpio/gpiolib.c | 27 +++++++++++++++++++-------- > 1 file changed, 19 insertions(+), 8 deletions(-) > > diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c > index cca749010cd0..6bb4191d3844 100644 > --- a/drivers/gpio/gpiolib.c > +++ b/drivers/gpio/gpiolib.c > @@ -2769,8 +2769,10 @@ int gpiod_direction_output(struct gpio_desc *desc,= int value) > if (!ret) > goto set_output_value; > /* Emulate open drain by not actively driving the line hi= gh */ > - if (value) > - return gpiod_direction_input(desc); > + if (value) { > + ret =3D gpiod_direction_input(desc); > + goto set_output_flag; > + } > } > else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) { > ret =3D gpio_set_config(gc, gpio_chip_hwgpio(desc), > @@ -2778,8 +2780,10 @@ int gpiod_direction_output(struct gpio_desc *desc,= int value) > if (!ret) > goto set_output_value; > /* Emulate open source by not actively driving the line l= ow */ > - if (!value) > - return gpiod_direction_input(desc); > + if (!value) { > + ret =3D gpiod_direction_input(desc); > + goto set_output_flag; > + } > } else { > gpio_set_config(gc, gpio_chip_hwgpio(desc), > PIN_CONFIG_DRIVE_PUSH_PULL); > @@ -2787,6 +2791,17 @@ int gpiod_direction_output(struct gpio_desc *desc,= int value) > > set_output_value: > return gpiod_direction_output_raw_commit(desc, value); > + > +set_output_flag: > + /* > + * When emulating open-source or open-drain functionalities by no= t > + * actively driving the line (setting mode to input) we still nee= d to > + * set the IS_OUT flag or otherwise we won't be able to set the l= ine > + * value anymore. > + */ > + if (ret =3D=3D 0) > + set_bit(FLAG_IS_OUT, &desc->flags); > + return ret; > } > EXPORT_SYMBOL_GPL(gpiod_direction_output); > > @@ -3147,8 +3162,6 @@ static void gpio_set_open_drain_value_commit(struct= gpio_desc *desc, bool value) > > if (value) { > err =3D chip->direction_input(chip, offset); > - if (!err) > - clear_bit(FLAG_IS_OUT, &desc->flags); > } else { > err =3D chip->direction_output(chip, offset, 0); > if (!err) > @@ -3178,8 +3191,6 @@ static void gpio_set_open_source_value_commit(struc= t gpio_desc *desc, bool value > set_bit(FLAG_IS_OUT, &desc->flags); > } else { > err =3D chip->direction_input(chip, offset); > - if (!err) > - clear_bit(FLAG_IS_OUT, &desc->flags); > } > trace_gpio_direction(desc_to_gpio(desc), !value, err); > if (err < 0) > -- > 2.21.0 > Queued for fixes. Bart