From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-vs1-f47.google.com (mail-vs1-f47.google.com [209.85.217.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A441519E968 for ; Sun, 10 May 2026 13:31:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.217.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778419894; cv=none; b=AbCHgG5XHYuP1CwAadT9e83tnokiddB32/vBMBnW9hEcH+wsuoevxDqaXR9T0IQvzO4G5tpUvU8Py28vINd2JKnoBOg9mc/1BoYuEe6gINJ9qlxNMLD3leqbweqmmZDnHhRRUJDWc2dhF+nSJCcUZ8K6kQhFukKj5JYxYQT1h4E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778419894; c=relaxed/simple; bh=6HAXn+kxF5eQoAzjkNG4BkPt+b4r7Coyev2Gi0HExgE=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=UxAFWwhI2S9VobMzKOA1avBrqXvhVn88x/m7FaDbDJDS+fB5Ulz8U4nVeXJLzLcodvIrEWreNypdsrRD0Zyk45I0N3136S9DVa5vqPmNgqINt0TUMNjMi3pJ15vKTccytFhZ5f5bBRU8idrruNz4dRErthMmhu1T/EGj1T85tbs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=riscstar.com; spf=pass smtp.mailfrom=riscstar.com; dkim=pass (2048-bit key) header.d=riscstar-com.20251104.gappssmtp.com header.i=@riscstar-com.20251104.gappssmtp.com header.b=wx2hFCYm; arc=none smtp.client-ip=209.85.217.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=riscstar.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=riscstar.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=riscstar-com.20251104.gappssmtp.com header.i=@riscstar-com.20251104.gappssmtp.com header.b="wx2hFCYm" Received: by mail-vs1-f47.google.com with SMTP id ada2fe7eead31-6314287380bso1343091137.3 for ; Sun, 10 May 2026 06:31:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riscstar-com.20251104.gappssmtp.com; s=20251104; t=1778419891; x=1779024691; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id:from:to :cc:subject:date:message-id:reply-to; bh=lhr6zcjHaIntrvl63ikySMmmCA16qxeIqmzRbDZIQ6I=; b=wx2hFCYmpE6FGvcx49T8M1M2sl6dHeYlJAYr3HtNY6brVFF6tRjhpAxizEgvaSP+jz uEg01P+T1EH1F//sBEZZOtZ7OaE8722MmujRyv3HvgkZbeKYCYMU3dgHEBqYQpJB5qpj IT/aDsfSqpnx/eipqb43+qleJ4HTPF/zd/5vgUtLG6C+xsirdrmLt2IDrV8V7ZqV/FQx e3g5QzGVSbpTfcSWRkwRTADko74CkQ27bnRB2dISL9us0upt/y1pLTNS3QNbjcVbS7xu WageXc+W1y55/VwAe11Uoduy27fmdtfGn1Jh4FGyZrGSE+NuB1vWpfE2Th0moINcvBCg pTBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778419891; x=1779024691; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lhr6zcjHaIntrvl63ikySMmmCA16qxeIqmzRbDZIQ6I=; b=GanwrlL6v0fNVR1M3HidnZ+O07ps3MKE3zWhyjWiPjmn2tR1Iw2JU2+iMlW2pPUJQp Z5N0qvPdrB4MOIJ2KaDkNt5denTzNpJBssk7r1C3/GUFdQdDT+mvBUZp5g5t74Hklnss fIHwK8tuad6ad09HJm3g3ILzsloPs96X4wjYpJPxjCJ+Win7m5Dc2rUFuV+JbHB28Dfm uxhZbJVJJp45jtYMLkx3sxhcHWBdoz3vFuyuGFleXIZO7hy6II/19BFg0OG6JQ2vBqbo /5K4Q3Br7s5oXV4MB3TcJzbnBxQZnmt/rboqQTmT/BaTnCTL5GYKK0l4B0NsTPdeSZ+u GcDA== X-Forwarded-Encrypted: i=1; AFNElJ9L1cpPEX6MmR+/emDxsx3vjxU5pyZaQWd+m6ILYZIfPDFfH6loQnzFABLsuvUkJLwoZUgqxzrh7XFRaTo=@vger.kernel.org X-Gm-Message-State: AOJu0YwCbtCb9Spe0xpA1Fiopjl6IfuBPBpyRDf5oJh/+1YKBTDvHLu2 biV3PVdkmHjyn6QqfCKlnlZZpa5qHKk3i/Igsww5oD3t3V0zYEaf8WKZJkHaUqY9qTU= X-Gm-Gg: Acq92OEiXEGU52ecsNztmz9eW4/88u6rZKzakXwSE/7Lr3VHHl3WgnjCUTquhLqd1Lo k2FsgtbpNeZa+HAJ/rw8oxZso9tEdhi6yx7e0yY/dauLhBM0kcYx8FpV4e0IlbgcMe5DH+h1qWG 9n+hGdaUkbcwcxrXSvgPjZfbf2SPY0K5jmwPIhAym3MH4Bjf7/HzyWT1f8AHC2y8CXC1HQ7zwTn h3WJ4YlC7x8drgeDY8/GglrSb/6ZSh40j8sp9INaii6AsJeC5mtyhDlaelKCGPiwcd3cnm4URRh h/VGaaiIxJLJ7giXlsYMIvk5HOJWog17jRTf8qlY/T5Og+D67CdF4F598ALEBrdXuNohKndAjj0 AdFpottLvA+G9+6dg34kEoQWuumiXY5H90PB1X2ajHjtJeyyLtFwvAD+d9adXpwp5kIZdBTT4Xo ygvNC6Zvv7Fjg3Dqe8HcNaeMD9gyjveZ7h7RQiAg5QnMqc302i/2tV1lBlqotyETuSUg1bC63uu ASP X-Received: by 2002:a05:6102:160f:b0:631:9366:da8c with SMTP id ada2fe7eead31-63193670d8bmr2967988137.14.1778419891397; Sun, 10 May 2026 06:31:31 -0700 (PDT) Received: from [10.211.55.5] (c-75-72-117-212.hsd1.mn.comcast.net. [75.72.117.212]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8fc2c91cdfbsm2864554785a.34.2026.05.10.06.31.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 10 May 2026 06:31:30 -0700 (PDT) Message-ID: <092e2eee-5fbd-413b-99f6-dd9b08512504@riscstar.com> Date: Sun, 10 May 2026 08:31:29 -0500 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 1/2] gpio: regmap: Support sparsed fixed direction From: Alex Elder To: Linus Walleij , Michael Walle , Bartosz Golaszewski Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org References: <20260508-regmap-gpio-sparse-fixed-dir-v2-0-deee84df3027@kernel.org> <20260508-regmap-gpio-sparse-fixed-dir-v2-1-deee84df3027@kernel.org> <6f15ed94-c52d-41c6-9e96-68e96c70d287@riscstar.com> Content-Language: en-US In-Reply-To: <6f15ed94-c52d-41c6-9e96-68e96c70d287@riscstar.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 5/8/26 8:03 AM, Alex Elder wrote: > On 5/8/26 7:51 AM, Linus Walleij wrote: >> On some regmapped GPIOs apparently only a sparser selection >> of the lines (not all) are actually fixed direction. >> >> Support this situation by adding an optional bitmap indicating >> which GPIOs are actually fixed direction and which are not. >> >> Cc: Alex Elder >> Link: https://lore.kernel.org/linux-gpio/20260501155421.3329862-10- >> elder@riscstar.com/ >> Tested-by: Alex Elder >> Signed-off-by: Linus Walleij > > > > In addition, it would be fine with me if you merged this together > iwth your new patch: > > > https://lore.kernel.org/lkml/20260508-regmap-gpio-sparse-fixed-dir-v2-2- > deee84df3027@kernel.org/ > > It makes sense and it is logically part of the same change. > > I even tested with that change applied, even though I know > just by inspection it will do what's desired. > > Anyway, for both (or a combined single patch), these apply: > > Tested-by: Alex Elder > Reviewed-by: Alex Elder > > >                     -Alex I had another look at this and I had two more comments. I don't care whether you address them or not, but I thought I'd mention them. The first is, in gpio_regmap_set_direction(), if a request to set the direction to something that isn't supported (e.g. set the direction to input on an output-only GPIO), shouldn't it return an error to indicate nothing happened? (-EINVAL or -ENOTSUP maybe?) Doing that might not be as simple as it seems, and maybe you just opted to keep it simple. gpio_regmap_direction_output() calls gpio_regmap_set() before setting the direction, so checking whether it's valid happens later than desired. The second is a missing blank line that I didn't expect, in gpio_regmap_get_direction(). I mention it in context below. -Alex >> --- >>   drivers/gpio/gpio-regmap.c  | 37 +++++++++++++++++++++++++++++++++---- >>   include/linux/gpio/regmap.h |  7 +++++++ >>   2 files changed, 40 insertions(+), 4 deletions(-) >> >> diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c >> index 9ae4a41a2427..f45a432e8ebe 100644 >> --- a/drivers/gpio/gpio-regmap.c >> +++ b/drivers/gpio/gpio-regmap.c >> @@ -31,6 +31,7 @@ struct gpio_regmap { >>       unsigned int reg_clr_base; >>       unsigned int reg_dir_in_base; >>       unsigned int reg_dir_out_base; >> +    unsigned long *fixed_direction_sparse; >>       unsigned long *fixed_direction_output; >>   #ifdef CONFIG_REGMAP_IRQ >> @@ -138,6 +139,20 @@ static int gpio_regmap_set_with_clear(struct >> gpio_chip *chip, >>       return regmap_write(gpio->regmap, reg, mask); >>   } >> +static bool gpio_regmap_fixed_direction(struct gpio_regmap *gpio, >> +                    unsigned int offset) >> +{ >> +    if (!gpio->fixed_direction_output) >> +        return false; >> + >> +    /* In this case only some GPIOs are fixed as input/output */ >> +    if (gpio->fixed_direction_sparse && >> +        !test_bit(offset, gpio->fixed_direction_sparse)) >> +        return false; >> + >> +    return true; >> +} >> + >>   static int gpio_regmap_get_direction(struct gpio_chip *chip, >>                        unsigned int offset) >>   { >> @@ -145,7 +160,7 @@ static int gpio_regmap_get_direction(struct >> gpio_chip *chip, >>       unsigned int base, val, reg, mask; >>       int invert, ret; This isn't new, but why is there no blank line here? >> -    if (gpio->fixed_direction_output) { >> +    if (gpio_regmap_fixed_direction(gpio, offset)) { >>           if (test_bit(offset, gpio->fixed_direction_output)) >>               return GPIO_LINE_DIRECTION_OUT; >>           else >> @@ -302,12 +317,23 @@ struct gpio_regmap *gpio_regmap_register(const >> struct gpio_regmap_config *config >>               goto err_free_gpio; >>       } >> +    if (config->fixed_direction_sparse) { >> +        gpio->fixed_direction_sparse = bitmap_alloc(chip->ngpio, >> +                                GFP_KERNEL); >> +        if (!gpio->fixed_direction_sparse) { >> +            ret = -ENOMEM; >> +            goto err_free_gpio; >> +        } >> +        bitmap_copy(gpio->fixed_direction_sparse, >> +                config->fixed_direction_sparse, chip->ngpio); >> +    } >> + >>       if (config->fixed_direction_output) { >>           gpio->fixed_direction_output = bitmap_alloc(chip->ngpio, >>                                   GFP_KERNEL); >>           if (!gpio->fixed_direction_output) { >>               ret = -ENOMEM; >> -            goto err_free_gpio; >> +            goto err_free_bitmap_sparse; >>           } >>           bitmap_copy(gpio->fixed_direction_output, >>                   config->fixed_direction_output, chip->ngpio); >> @@ -329,7 +355,7 @@ struct gpio_regmap *gpio_regmap_register(const >> struct gpio_regmap_config *config >>       ret = gpiochip_add_data(chip, gpio); >>       if (ret < 0) >> -        goto err_free_bitmap; >> +        goto err_free_bitmap_output; >>   #ifdef CONFIG_REGMAP_IRQ >>       if (config->regmap_irq_chip) { >> @@ -355,8 +381,10 @@ struct gpio_regmap *gpio_regmap_register(const >> struct gpio_regmap_config *config >>   err_remove_gpiochip: >>       gpiochip_remove(chip); >> -err_free_bitmap: >> +err_free_bitmap_output: >>       bitmap_free(gpio->fixed_direction_output); >> +err_free_bitmap_sparse: >> +    bitmap_free(gpio->fixed_direction_sparse); >>   err_free_gpio: >>       kfree(gpio); >>       return ERR_PTR(ret); >> @@ -376,6 +404,7 @@ void gpio_regmap_unregister(struct gpio_regmap *gpio) >>       gpiochip_remove(&gpio->gpio_chip); >>       bitmap_free(gpio->fixed_direction_output); >> +    bitmap_free(gpio->fixed_direction_sparse); >>       kfree(gpio); >>   } >>   EXPORT_SYMBOL_GPL(gpio_regmap_unregister); >> diff --git a/include/linux/gpio/regmap.h b/include/linux/gpio/regmap.h >> index 12d154732ca9..ff00b4aeaf1c 100644 >> --- a/include/linux/gpio/regmap.h >> +++ b/include/linux/gpio/regmap.h >> @@ -38,6 +38,12 @@ struct regmap; >>    *            offset to a register/bitmask pair. If not >>    *            given the default gpio_regmap_simple_xlate() >>    *            is used. >> + * @fixed_direction_sparse: >> + *            (Optional) Bitmap representing the GPIO lines that >> + *            make use of the @fixed_direction_output list to >> + *            enforce direction of the GPIO. If this is NULL >> + *            and @fixed_direction_output is defined, ALL GPIOs >> + *            are assumed to be fixed direction (out or in). >>    * @fixed_direction_output: >>    *            (Optional) Bitmap representing the fixed direction of >>    *            the GPIO lines. Useful when there are GPIO lines with a >> @@ -89,6 +95,7 @@ struct gpio_regmap_config { >>       int reg_stride; >>       int ngpio_per_reg; >>       struct irq_domain *irq_domain; >> +    unsigned long *fixed_direction_sparse; >>       unsigned long *fixed_direction_output; >>   #ifdef CONFIG_REGMAP_IRQ >> >