Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2425158imm; Thu, 11 Oct 2018 10:02:15 -0700 (PDT) X-Google-Smtp-Source: ACcGV62cceOhcxfz/U6h4WaBMqUhpJhbeB3BKjC7Df7SUYq3WAOiJsW/F1DUIH1KZx7okAfQMHmX X-Received: by 2002:a63:1b0b:: with SMTP id b11-v6mr2142125pgb.66.1539277335488; Thu, 11 Oct 2018 10:02:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539277335; cv=none; d=google.com; s=arc-20160816; b=CO9fGXV9U2Dj1TU96EUyJqNAA+ho6VZoQvA24cRzD/Zzun9Q4GKi9PS/Swv/mJnBFK +ZhRzmQQ0egKm7UU5A/3EnzaWQLjLvOQPiak+iKilpBO2W6LjYLWpzA/8QzCxtP+7eeN ErhlAlfwMH367kESjK48WYiEJpYEt5mZumbB6CWZuBF8s9nsud9YNh4a4jIX2Mur5SM6 c4yBAqfBzA+Z2kDjnz9cdn5nWpsLCpD8EWABXvi6DNatiFKfwmvmfvWvR1PBXSgwrQH+ E8PjX1KbAjXYaQxKCUYEQ5cEFKiRx/373xlMpf4bzwNuHtDeARq6AlImkfusoJcL+Det rX2Q== 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=gOtASjkTmL8BxytzRxSIubYq0ixql2iNYSNXitfRfTo=; b=sMG0nQXUlng2iNyIvwl50k33Y1FU3aF4NotHZLX4Cf1pQvcGS1AY7X8+7PHPzKCIIV W0b3hXJMtkPGrnPGqykXJb8cWAdYWDXqseskBLfmc+RbGExgPVRdKKDO5XFoCXe4OjqV 3usPEz+edlnibTwyCC/skNhJ3hVERfMbeVwPaNBnztGbzOx7Jl6JZSMpADJqNI3nDSpx zYau6nxOeEE359BLxevaXsATHxoizHknMGHKvHS6VCRXsL+ElRrMPI8D1/QLW/czP475 Lv8Av3zH7FdjV3czFdCtulpt9hnPfxSRIKkgjm8VPB0+GY1DdNnwdeprepC5ODt0u4UF iKRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZX7DIOnK; 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 r21-v6si20557876pgo.506.2018.10.11.10.02.00; Thu, 11 Oct 2018 10:02:15 -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=@linaro.org header.s=google header.b=ZX7DIOnK; 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 S1730518AbeJLA3c (ORCPT + 99 others); Thu, 11 Oct 2018 20:29:32 -0400 Received: from mail-it1-f196.google.com ([209.85.166.196]:53260 "EHLO mail-it1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725984AbeJLA3c (ORCPT ); Thu, 11 Oct 2018 20:29:32 -0400 Received: by mail-it1-f196.google.com with SMTP id q70-v6so14575983itb.3 for ; Thu, 11 Oct 2018 10:01:26 -0700 (PDT) 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=gOtASjkTmL8BxytzRxSIubYq0ixql2iNYSNXitfRfTo=; b=ZX7DIOnKJy4Oum7YN43bbaADP+6WgUgJ4fxzmWm2SWOvL+EjQwcq2QPeH6Tm0wHrEG 5dhpVvGCof0Lv1/T2QpovztzpZbtt8SMRYRdGBd9l875Iz84j1TpP/VP1Kz2vWu4RqR5 lVdLprt8pqjLlQOyR6XKsHQeKVEZ65P4Fhk/8= 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=gOtASjkTmL8BxytzRxSIubYq0ixql2iNYSNXitfRfTo=; b=rKczaOXDQypdIJWM4AiHbbGewYvHsuM1vlrZNPv2ZF5IasDVzOBGzVeDzhjrAvUu7w Kw4X+aOtvZevXGidUibMwax9NJ69V7DH7LWZaG8B/uBLIgXjEMYlk13gLWO1EUVZqRju L5UFRteT3F//EiByy5bA/2xw3bobkJeETFBbxH3zL4v6okgBpDLWGTRwGmwANO89Lk9j MW5Nlq9W0keaOJAEg8r9vsoCDqRcqpH+EfnicOSum0dQPtFk5gEN/eHNqi0xOQ0d6pMz w34nLIwTdR/nbpabgtEVmSneBKlOpHYTSjaYrjZNtr9mg03syvIzSb0GkANHS/2ytf0X H5LQ== X-Gm-Message-State: ABuFfoh8cjQu3Xj0u3jtfYmSrrRH+dqV9JVU+jnnnacbnHVNEnYMq030 +r3xEaXqzbYjkhOmzAWvz58ZGugRqNRtgR/q+VsPhQ== X-Received: by 2002:a24:7b50:: with SMTP id q77-v6mr1816333itc.154.1539277285998; Thu, 11 Oct 2018 10:01:25 -0700 (PDT) MIME-Version: 1.0 References: <20181011143531.7195-1-linus.walleij@linaro.org> <20181011144330.GF25351@sirena.org.uk> In-Reply-To: <20181011144330.GF25351@sirena.org.uk> From: Linus Walleij Date: Thu, 11 Oct 2018 19:01:13 +0200 Message-ID: Subject: Re: [PATCH] gpio/regulator: Allow nonexclusive GPIO access To: Mark Brown Cc: Liam Girdwood , "linux-kernel@vger.kernel.org" , Marek Szyprowski 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 Thu, Oct 11, 2018 at 4:43 PM Mark Brown wrote: > On Thu, Oct 11, 2018 at 04:35:31PM +0200, Linus Walleij wrote: > > > + /* > > + * Some fixed regulators share the enable line between two > > + * regulators which makes it necessary to get a handle on the > > + * same descriptor for two different consumers. This will get > > + * the GPIO descriptor, but only the first call will initialize > > + * it so any flags such as inversion or open drain will only > > + * be set up by the first caller and assumed identical on the > > + * next caller. > > + * > > + * FIXME: find a better way to deal with this. > > + */ > > + gflags |= GPIOD_FLAGS_BIT_NONEXCLUSIVE; > > + > > It's not just fixed regulators that do this, often regulators with > register control can do this as well. Yeah I thought that was implicit since the comment is inside fixed.c but I can change it, or you can edit when applying if you like. > Since power up is often a > performance critical path but regulators tend to be controlled via slow > buses like I2C it's common to have register control combined with a GPIO > enable line so you don't need to use the bus to do the enables. That > should just be a case of adding this flag to all the drivers that have > already been converted to gpiod (including the core code that's in > regulator_ena_gpio_request() which I thought was coping with this > already) unless I'm missing something? Sorry if I don't get it... we already have code in the core to check if the same gpiod is used by two regulators. regulator_ena_gpio_request() does this: if (config->ena_gpiod) gpiod = config->ena_gpiod; else gpiod = gpio_to_desc(config->ena_gpio); So after the change I made to fixed.c this comes in through config->ena_gpiod. Later in this function: list_for_each_entry(pin, ®ulator_ena_gpio_list, list) { if (pin->gpiod == gpiod) { rdev_dbg(rdev, "GPIO %d is already used\n", config->ena_gpio); So there is the reference counting code, where we identify that the same descriptor is already in use. The only change this patch really does is make it possible for the same gpiod to come in twice from fixed.c (as is proper). If it's a simple and single consumer enable/disable disable line all is fine and it doesn't get reference counted etc, since there is one and only one consumer for the GPIO. gpiod_get[_optional]() is just fine in these cases. When I straight out the FIXME:s I would add code to check that the flags passed to gpiolib are coherent and maybe store all users in an array instead of a simple char * inside the gpio descriptor, so we properly handle more than one user in gpiolib. Possibly the reference counting should be moved over from regulator core as well: this would apply if there are more subsystems than regulator using the same GPIO with multiple consumers. But that is for the future fixups. Yours, Linus Walleij