Received: by 2002:a17:90a:88:0:0:0:0 with SMTP id a8csp138727pja; Fri, 22 Nov 2019 04:34:25 -0800 (PST) X-Google-Smtp-Source: APXvYqxCqwJ8fndkG2n5+6cfuCGjkaSlow6rwDaBDE92pr+tToNkyebSfHtaAUJ/sK1rfnRs0CwU X-Received: by 2002:aa7:c303:: with SMTP id l3mr744673edq.89.1574426065374; Fri, 22 Nov 2019 04:34:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574426065; cv=none; d=google.com; s=arc-20160816; b=qEfBklQ7v0KAXUZ/itmlO0E8X1y2nMWT64lqhwYRBb9lCU4YddVxYpAULDEt5VBEUt N2Up28NIBzvmGgsW7rpfcr2+3RXYIY4DoETMG8S3eo4suf6+QFwH1rZfvjE7THZ5R7y/ rO/KWpF1crNP0chcF4sgccyo1jIQMBKlkTzRW4lVQgUmQJBddNPvk0QNGyp9f6AmYUno wQOL6jWA0QAoFzuTr3QoZT+COz8UmiVGWtlDioclyKmk3FWE+6uMN2/P7lnUTcmAREWf 5Bvpxi6PJ6eGmbuhOnu8Wt93hvO7PGLIbZhp4594+9cBqW7r26DTGzxgpcdDaE3dKiEc ghiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Nmv33MELYtHNW1JfSh62V5xviPKhtu29GeC7rSDHuak=; b=VwfyfIa7rIKVEcHU82DokFH/JHH0Hg7acbkPA4S41XBcMeZXl1mxildp8SmopF7SPn BMolYJ2GxFmh/kYzP2oGxrT6/VRfDz59zfEGlXOj4y8+ro6cDNDG3aWHgDZyk8aOOmDR PA7TA+xOi9Qvfzn/ph4bI05RdBtE5iLAUpooMQhMAfqGnn0JiikHvRunIGBtv827U5X7 VJiODDS6JDLhZkPgadMtBh3dgExoR1zhOkVEQQj75dYP8BimzYpi7C9q6R5X+t9R50jf Sk6UvUyOlIeRQ150YpPDAYhs/XTz2/D0Pw6BA6w9+iuuRCEDtD904Decp+pI/+h6TALd 7L7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ldxD3IhY; 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; dmarc=pass (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 w5si499771edl.299.2019.11.22.04.34.01; Fri, 22 Nov 2019 04:34:25 -0800 (PST) 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=@linaro.org header.s=google header.b=ldxD3IhY; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727498AbfKVMWh (ORCPT + 99 others); Fri, 22 Nov 2019 07:22:37 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:41339 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726739AbfKVMWh (ORCPT ); Fri, 22 Nov 2019 07:22:37 -0500 Received: by mail-lj1-f195.google.com with SMTP id m4so7125455ljj.8 for ; Fri, 22 Nov 2019 04:22:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Nmv33MELYtHNW1JfSh62V5xviPKhtu29GeC7rSDHuak=; b=ldxD3IhYiBpXt0HtDqPy+vLU768rI80wemhHlXIxuozaMFv5BDMGXKOwBdiTtG9qrR K7zRO7F/VgnMzk8I8ViyED5oc2rFQNjKTHMCKLQzSVexza+EwBbDstq+EFImT/WDe/zG 503aY643zXLckIPlmPcnJgLOZJdjVCE1nglK67MKhx6dB+GbBLtRnybiR8UXj6qrbp9x dqZlKECSFxFo0Hoi4CrvCufy4IpzUbDbldl2pNTGpKSx5NJLQo5vB78ttUb88d8B/gwV ogwPci75B5adEZt65PD+NaL85SKKIgd2iVepO5qxnX7cs08JeYbvg5nc8A2VuhY8jRZr KH+Q== 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; bh=Nmv33MELYtHNW1JfSh62V5xviPKhtu29GeC7rSDHuak=; b=HeLqK1DVTiDIP/qCQSZWLup2rFRKcWBpusLevMJSOEir08D+WDfhPXZg2Dj5K4SiIb SjVWh/ZTv8/dSS6vXELVXJ8RNOO+ejGZWR1eXKKMzQiconHtmnh+rEY2ACLy1HnAL7bt novpnymSIfQLSgrzjBlftubHxAwfW+lIcF8ZLQ93edl5eDCc46YgLd/3w7gakGJeGuaj hjtK7TGo98LyrMxXMkAKwljt4n1d0sNzH+LfVpcz7cyTYp7mB2D2j+j4fbOyT1hErRll qhzlurV+vPGJ9isXYvU9D39cCcC5nI3pT/gKFGqroc5uO6lrUjqc0kn/FWu1E21wXY3Y Oh3w== X-Gm-Message-State: APjAAAVnCT0NXyY57CPYiApM4RkGGqjTj/0YcDpE/EsuZW2dWdK2lVgb PnsHWRHD43Kj9PuAbUOpq6AzTSsxSC9X2k7z6f/JdJdodn4= X-Received: by 2002:a2e:8597:: with SMTP id b23mr12114009lji.218.1574425354454; Fri, 22 Nov 2019 04:22:34 -0800 (PST) MIME-Version: 1.0 References: <20191120133409.9217-1-peter.ujfalusi@ti.com> <20191120133409.9217-3-peter.ujfalusi@ti.com> In-Reply-To: <20191120133409.9217-3-peter.ujfalusi@ti.com> From: Linus Walleij Date: Fri, 22 Nov 2019 13:22:23 +0100 Message-ID: Subject: Re: [RFC 2/2] gpiolib: Support for (output only) shared GPIO line To: Peter Ujfalusi Cc: Bartosz Golaszewski , Rob Herring , "open list:GPIO SUBSYSTEM" , "linux-kernel@vger.kernel.org" , Marek Szyprowski , Mark Brown , Maxime Ripard , Philipp Zabel , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 20, 2019 at 2:34 PM Peter Ujfalusi wrote: > This patch adds basic support for handling shared GPIO lines in the core. > The line must be configured with a child node in DT. > Based on the configuration the core will use different strategy to manage > the shared line: > refcounted low: Keep the line low as long as there is at least one low > request is registered > refcounted high: Keep the line high as long as there is at least one high > request is registered > pass through: all requests are allowed to go through without refcounting. > > The pass through mode is equivalent to how currently the > GPIOD_FLAGS_BIT_NONEXCLUSIVE is handled. > > Signed-off-by: Peter Ujfalusi This is a good start! Some ideas on how I'd like this to develop. > drivers/gpio/gpiolib-of.c | 28 ++++++-- > drivers/gpio/gpiolib.c | 132 +++++++++++++++++++++++++++++++++++--- Please put this API under its own Kconfig option and in its own file in drivers/gpio/gpiolib-refcounted.c local header in drivers/gpio/gpiolib-refcounted.h only built in if the appropriate Kconfig is selected. Consumer header in include/linux/gpio/reference-counted.h And add external driver API to this last file. > --- a/drivers/gpio/gpiolib-of.c No commenting on this because as pointed out in the binding patch I want this done by simply detecting the same GPIO being referenced by several <&gpio N> phandles. > diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h > index ca9bc1e4803c..0eec0857e3a8 100644 > --- a/drivers/gpio/gpiolib.h > +++ b/drivers/gpio/gpiolib.h > @@ -111,11 +111,18 @@ struct gpio_desc { > #define FLAG_PULL_UP 13 /* GPIO has pull up enabled */ > #define FLAG_PULL_DOWN 14 /* GPIO has pull down enabled */ > #define FLAG_BIAS_DISABLE 15 /* GPIO has pull disabled */ > +#define FLAG_IS_SHARED 16 /* GPIO is shared */ This is a good way of flagging that this is a refcounted GPIO I would call it FLAG_IS_REFERENCE_COUNTED as it is more precise to what it means. > +#define FLAG_REFCOUNT_LOW 17 /* Shared GPIO is refcounted for raw low */ > +#define FLAG_REFCOUNT_HIGH 18 /* Shared GPIO is refcounted for raw high */ Do not put this here, keep it in the local refcounted GPIO struct gpio_refcount_desc. > /* Connection label */ > const char *label; > /* Name of the GPIO */ > const char *name; > + /* Number of users of a shared GPIO */ > + int shared_users; > + /* Reference counter for shared GPIO (low or high level) */ > + int level_refcount; We can't expand this struct for everyone on the planet like this. In the local header drivers/gpio/gpiolib-refcount.h create something like: struct gpio_refcount_desc { struct gpio_desc *gd; int shared_users; int level_refcount; }; This should be the opaque cookie returned to consumers of this new refcounted API. It defines the reference counted API as separate and optional from the non-reference counted API, also using its own API. The only effect on the core gpiolib will be the single flag in struct gpio_desc; and some calls into the shared code with stubs if the support for systems that do not enable the reference counting API. Yours, Linus Walleij