Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp814125ybx; Thu, 31 Oct 2019 01:04:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqyKKM97EwpkFzkIm/B8Wrn5QHTpB6U7IXNYAenjIrvNbgWCjGnu+SqTo1MWoLOPHXawc99E X-Received: by 2002:aa7:c590:: with SMTP id g16mr4438936edq.292.1572509078187; Thu, 31 Oct 2019 01:04:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572509078; cv=none; d=google.com; s=arc-20160816; b=lup4b1/dAXoQFoOYl0EM9oslijVoT5pc/pXnuKH1exh0TppZXSiChBtNO2gDR6IrWG ZIodoelB8O7E7rPKudKcQko4OWayl7ALsEvTphsqA/iXji5CRvhwl17ZMGeYeGenB+YB 58mdSVNZbcUnFYG0wDB1LSH90Gake0hZhKbtFSbylKvwwWT6+BnTwUHpK1oO/7pksr2x WscGPs9JJPo9UeUYbPpRh8HOSgWvKrKwoA1YzViFiVFHipLTKOsONXdqpHsgRJr8iJ6p T22L8cd1U9HSX/p5Z2b7yYljusutjVHGKTUGtdic9YcTXQ0ewFH2TQTmnKln02HWVCi0 MMjg== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=TKe46EoF1J60ShuFHgR4qomu3QEwz48sNCBTYx/91/g=; b=wd9YtefVk9zxsfOUQ/FG8/BYwj0E3tzv4BbVT306Cqr/tvmrxykjtl7yZ8FlQ2ZYcD eeWfgZOkPPstB7010p7C7VKfR7DYFckWL29ngfTZe7MeTUiY5k6E8uhw5u+HMCCPCLMJ vDH1y4aGzfH80YN9cNcet5xEy0yrogcY7dPDXbncc22kRKbBnKt4+lIM5w6vDHkxQNui Ja+S43LtWM5mzAUaZ3C2aDs9xqR5ctutN/wS2jcypmDB/8fnUtJOIJpIKCJStV9yfHrT I9GGamBMuItS7YoqwgYhjEvAy+9fmYcC4sxDAzIW8IgcE1Vpsy1O6+oRvxd0KcUIzkaL sPfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=Z82auzUS; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g4si3579681edb.41.2019.10.31.01.04.12; Thu, 31 Oct 2019 01:04:38 -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=@ti.com header.s=ti-com-17Q1 header.b=Z82auzUS; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727041AbfJaIBF (ORCPT + 99 others); Thu, 31 Oct 2019 04:01:05 -0400 Received: from fllv0016.ext.ti.com ([198.47.19.142]:35736 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726698AbfJaIBF (ORCPT ); Thu, 31 Oct 2019 04:01:05 -0400 Received: from fllv0034.itg.ti.com ([10.64.40.246]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id x9V80tYr099287; Thu, 31 Oct 2019 03:00:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1572508855; bh=TKe46EoF1J60ShuFHgR4qomu3QEwz48sNCBTYx/91/g=; h=Subject:To:CC:References:From:Date:In-Reply-To; b=Z82auzUS36CE6SDIajfIV5GVqXyvm0MdUM2vZQwy7QPNnOg7JRHukjfaOarY/WBY5 iQh3/UuGeO55Qlkz/v23GMqgbe4oBFuaJa/fnJt3sBs+p6ipEwo9jCN1YENffpxO+S zKUZkRnJQ2yT2AORtx6k2wFA686JgUYWYe1YRkys= Received: from DLEE106.ent.ti.com (dlee106.ent.ti.com [157.170.170.36]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x9V80sEM067010 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 31 Oct 2019 03:00:55 -0500 Received: from DLEE106.ent.ti.com (157.170.170.36) by DLEE106.ent.ti.com (157.170.170.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Thu, 31 Oct 2019 03:00:54 -0500 Received: from lelv0327.itg.ti.com (10.180.67.183) by DLEE106.ent.ti.com (157.170.170.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5 via Frontend Transport; Thu, 31 Oct 2019 03:00:54 -0500 Received: from [192.168.2.6] (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0327.itg.ti.com (8.15.2/8.15.2) with ESMTP id x9V80pDA057797; Thu, 31 Oct 2019 03:00:52 -0500 Subject: Re: [RFC v2 0/2] gpio: Support for shared GPIO lines on boards To: Rob Herring CC: Mark Brown , Linus Walleij , Bartosz Golaszewski , "open list:GPIO SUBSYSTEM" , "linux-kernel@vger.kernel.org" , Marek Szyprowski , Tero Kristo , Maxime Ripard , Philipp Zabel , References: <20191030120440.3699-1-peter.ujfalusi@ti.com> <5bca4eb6-6379-394f-c95e-5bbbba5308f1@ti.com> <20191030141736.GN4568@sirena.org.uk> From: Peter Ujfalusi Message-ID: <1258a5bf-a829-d47a-902f-bf2c3db07513@ti.com> Date: Thu, 31 Oct 2019 10:01:59 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 the >>>>> 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 the >> 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. 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 level: 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? 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. 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éter Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki