Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp522246ybx; Fri, 1 Nov 2019 07:12:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqwQ1UAIRp0TlThGE2y/Vg3jdE+749rhLC5brRT2T9HgDS9eOClcTRgZ9JxKrUQCgV28xrkS X-Received: by 2002:a17:906:4dd5:: with SMTP id f21mr9698435ejw.203.1572617520691; Fri, 01 Nov 2019 07:12:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572617520; cv=none; d=google.com; s=arc-20160816; b=QODbMhknLpghHp0AQUHWoplVNN+QbeCpVVGrmQnm++WphD84yrmSwCyAo8Skm9mCQC NqjLFD+hwhixnb7BMFwt6mE5sBlIETz/kpkA6IEDDfGI60h2D6GRC1hKp5iH5KR3dkgF 4hOsDHuNJS9xpH8E/qjseB3cH3k349ULh2096OdJDhZmYKj2Xj3HRYaSTFaQNfxoCffP cf8LAP+eQT8iZpGUXxQQ3kxDCF1XYWSUAiJRJGZRMJpDQbz/5//CmJDBplXLVRlUHfg1 k1VF2AmtNSPx0NpNtKeyCnHG4v3kk7e6toe8itRnC5e43DBxDrpff9FO/RL2QYotmhfb 4r9w== 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=lswMlSOEv3IVKL2o6g/0/MZB83V2bKNcQKcLhOteMKY=; b=k9z33JJH50LqNW4Uu41WsgWM58oSxEGRA+sppqH9YYPBJfnGyDVSg6z/R/q/6J50bA 3z/wz46wb1oh2vh2RNXD39lg2HO6+k4rCWu+1UI9gG1SiYAGCV7sjPx2oniST6sIFm14 kbTkKiLVxs+fus0sXEJaON3LahssB8Jj7D+LXsoqnxiEn2qA+9ZU3ZH2Wh1FDwGN1MEW BjoRKGbR1v6jxHJEE9aTAhNtUffawKNBF9Q3+PB2TYhLg7KIY1jq2Hklr5VlYKZTnuvT fukNWxXaWFEnuu3562727f3bHO7eZOkcQZ9t8OP3f0zpiCEd3sNzachd7JpM2yYplk+0 9JlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2VkCgmkJ; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k51si398580edb.411.2019.11.01.07.11.37; Fri, 01 Nov 2019 07:12:00 -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=@kernel.org header.s=default header.b=2VkCgmkJ; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727466AbfKANqV (ORCPT + 99 others); Fri, 1 Nov 2019 09:46:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:35358 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727296AbfKANqV (ORCPT ); Fri, 1 Nov 2019 09:46:21 -0400 Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C43E6217D9; Fri, 1 Nov 2019 13:46:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572615979; bh=lswMlSOEv3IVKL2o6g/0/MZB83V2bKNcQKcLhOteMKY=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=2VkCgmkJqOKWH5d+9KDukIcRTAHgjVukLo7+WnDE3TtykYaRb7rHNveONlNIa8z7C Wvf1s2hGqg8xK0DzjTHvWERd5B6QiJWEpQb02QETpjyRKih31rBLTX7nsrqGZryAfR nhqGnY7r7catGAEwdtg/1KASZ0QhIN/rBtzM7asA= Received: by mail-qt1-f182.google.com with SMTP id g50so13011584qtb.4; Fri, 01 Nov 2019 06:46:19 -0700 (PDT) X-Gm-Message-State: APjAAAWegAhA0MSmZ56hns4n8acGINgkS5bridDXXvlZhRaj0c6Ie/jc HWSteslGUTa/Kp8rUhF6fL4v6jMTPkJM0eM0PA== X-Received: by 2002:ac8:458c:: with SMTP id l12mr84256qtn.300.1572615978901; Fri, 01 Nov 2019 06:46:18 -0700 (PDT) MIME-Version: 1.0 References: <20191030120440.3699-1-peter.ujfalusi@ti.com> <5bca4eb6-6379-394f-c95e-5bbbba5308f1@ti.com> <20191030141736.GN4568@sirena.org.uk> <1258a5bf-a829-d47a-902f-bf2c3db07513@ti.com> In-Reply-To: <1258a5bf-a829-d47a-902f-bf2c3db07513@ti.com> From: Rob Herring Date: Fri, 1 Nov 2019 08:46:06 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC v2 0/2] gpio: Support for shared GPIO lines on boards To: Peter Ujfalusi Cc: Mark Brown , Linus Walleij , Bartosz Golaszewski , "open list:GPIO SUBSYSTEM" , "linux-kernel@vger.kernel.org" , Marek Szyprowski , Tero Kristo , Maxime Ripard , Philipp Zabel , devicetree@vger.kernel.org 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 On Thu, Oct 31, 2019 at 3:00 AM Peter Ujfalusi wrot= e: > > > > On 30/10/2019 20.49, Rob Herring wrote: > > On Wed, Oct 30, 2019 at 9:30 AM Peter Ujfalusi = wrote: > >> > >> > >> > >> On 30/10/2019 16.17, Mark Brown wrote: > >>> On Wed, Oct 30, 2019 at 03:32:09PM +0200, Peter Ujfalusi wrote: > >>>> On 30/10/2019 15.12, Rob Herring wrote: > >>> > >>>>> Why can't we just add a shared flag like we have for interrupts? > >>>>> Effectively, we have that for resets too, it's just hardcoded in th= e > >>>>> the drivers. > >>> > >>>> This would be kind of the same thing what the > >>>> GPIOD_FLAGS_BIT_NONEXCLUSIVE does, which was a quick workaround for > >>>> fixed-regulators afaik. > >>> > >>> The theory with that was that any usage of this would need the > >>> higher level code using the GPIO to cooperate so they didn't step > >>> on each other's toes so the GPIO code should just punt to it. > >> > >> But from the client driver point of view a GPIO is still GPIO and if t= he > >> components are unrelated then it is hard to patch things together from > >> the top. > > > > You can't escape a driver being aware. If a driver depends on that > > GPIO to actually be set to states the driver says, then it can't be > > guaranteed to work. For example, maybe the driver assumes the device > > is in reset state after toggling reset and doesn't work if not in > > reset state. The driver has to be aware no matter what you do in DT. > > That's true for some device, but it is also true that some can not > tolerate being reset without them knowing it. You mean a reset when the driver is not loaded would not work? How could that ever work? I don't think you can have any reset control in the drivers in that case. > If all users of the shared GPIO have full control over it then they can > just toggle it whatever way they want. How would a regulator, codec, > amplifier would negotiate on what to do with the shared GPIO? > > Another not uncommon setup is when the two components needs different lev= el: > C1: ENABLE is high active > C2: RESET is high active > > To enable C1, the GPIO should be high. To enable C2 the GPIO must be low. > In the board one of the branch of the shared GPIO needs (and have) a > logic inverter. > > If they both control the same GPIO then they must have requested it with > different GPIO_ACTIVE_ since the drivers are written according to chip > spec, so C1 sets the GPIO to 1, C2 sets it to 0, the inversion for one > of them must happen in gpio core, right? No, drivers are written to set the state to active/inactive. The DT GPIO_ACTIVE_ flags can depend on an inverter being present (BTW, there was a recent attempt to do an inverter binding). > It should be possible to add pass-through mode for gpio-shared so that > all requests would propagate to the root GPIO if that's what needed for > some setups. > > That way the gpio-shared would nicely handle the GPIO inversions, would > be able to handle cases to avoid unwanted reset/enable of components or > allow components to be ninja-reset. What does ninja-reset mean? > I think it would be possible to add gpiod_is_shared(struct gpio_desc > *desc) so users can check if the GPIO is shared - it would only return > true if the gpio-shared is not in pass-through mode so they can know > that the state they see on their gpio desc is not necessary matching > with reality. > Probably another gpiod_shared_get_root_value() to fetch the root's state? > > I intentionally not returning that in the driver as clients might skip a > gpio_set_value() seeing that the GPIO line is already in a state they > would want it, but that would not register their needs for the level. > > - P=C3=A9ter > > Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. > Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki