From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oo1-f53.google.com (mail-oo1-f53.google.com [209.85.161.53]) (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 D500E3DCD99 for ; Fri, 8 May 2026 13:03:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778245428; cv=none; b=VmbCuKkl5R2Riuc1U8CMWWyYtZDbQLh5qmsY8DyMVs41fsgik0FEng4d6KyYudDsgaGKPiX5/YjSMh35Xa3b+rk0rV68oFftVZARzn0BvxxioyWtouzB7dBAmO0GJwFhfA/SyNZBFoGdWGu25EoJErv9yiCBn4SRyxpQrk29oGg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778245428; c=relaxed/simple; bh=pt7XlsbOA9tv1TtrGt/RRq/85eL+D59/sDcgqu5C8XY=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=n9sedFvnzBiLtWD31H+YT2+3yctYg2YeluIUOwdijob2IDdyEmuWLU5t8y5VSV2RFy4r+K3Csafmkk9Jdv0ZLmwbSi0Sm3wgZx+D5Qq+/UlpEjt7YA5QEKCEffZisfK8wydQybCjhckQD9TOwBVcvqrdtoPTTM4ZDNcFp25rKoY= 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=qtRUiz5Z; arc=none smtp.client-ip=209.85.161.53 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="qtRUiz5Z" Received: by mail-oo1-f53.google.com with SMTP id 006d021491bc7-68470763896so1032614eaf.1 for ; Fri, 08 May 2026 06:03:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riscstar-com.20251104.gappssmtp.com; s=20251104; t=1778245426; x=1778850226; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=4uYSKJlZDlhRVMvkmCmHZTLX4HWfRTth6fnS9HRLT2Q=; b=qtRUiz5Zogp3NkjZ8rJ1gsIAuVw4z0S3IiBZ+KIRiR5dMd9eY60gnVWlS8uCwYSMMy vJoEu9JeREoEWV4aicuzkk43TKP6iN8SjivnhOLOBaYIQpJH3YUXY7fNJ5bM50OKazoo Vgneib5nQaxVDJZyBXZZmSVgZ44auQlUElKIrrGJFiGjDb/kqoFSe0h3Vsaymy8hpdCX RG5n/dWMxi+ghJdmHCMQBPQLXBQOUPHjam2PvCnJV8M1wW6QQuS1/xNGwJFBuV3CpkAo A9YVOOAhFpTMcA5uyQQe8x+iS7Cwh6Q5APAMtG/Y120qrx/3SejU42+F1hyKU9P2HH1R Il2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778245426; x=1778850226; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to: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=4uYSKJlZDlhRVMvkmCmHZTLX4HWfRTth6fnS9HRLT2Q=; b=eFVSzuy/03GLIAP1vpyEoTFXOOxf/50g2LHrefM8auMAPuL3IrYHgfEnRyo1d7YQBt OFLD/FP0CPceThnrSbOYOfnL+HWnEYNBEFWySn2As0SsqohNK0xQuw9B57vaVT3tkTqw mlDKy/2JPeuTlQ6bPp15vDuEGLrnT/XbM+XaWPhoBQ4SBZBEMrxdc2kehTamtgPLmHtK YV45zRoZRUNHbJragvZqaAEciduawqX8xlC/CfNQ2DgQ72tfq0Y2pE/ihkPQ5VC2DMZ8 3OmMR/AojShijUtgZsFS8kyK0Jv1kK7f0/rYc/s6z3ig3kTmfBGK7dhdckg/ihYX3O4i zdAQ== X-Forwarded-Encrypted: i=1; AFNElJ9DHKDsjKqwBiUHWCMm58PmDHvqR294/OGINQkMiJxVscRA0mU2O+yDudQHwHjLqdGjD26dg/XWCu7Dx/8=@vger.kernel.org X-Gm-Message-State: AOJu0Yxvn06j4lmIA+AFh62yuxnn6X5L2xyiYdHoAANpSrLe3Gw6qJLb KaSmtJcJymqdMHIPxggqPpzlpdFSREdvnVZ0QNxV+Vbeg0AfEg6TSKSoO1OVPARZ6Os= X-Gm-Gg: AeBDiesZl2I8R6X+cCeaX2Q666NXJl0zV+OddpcrBZoip2NXoMuoNtueyjysiwW//LO y72MpGEtJnEwEdZFqAmtiZDFx3kSSCl7TvWdEm3W0bMdU69Xww7WPUoXchRxJZEIGACZ70HU+dW awpz61k03jkMwVuMlkQVFrde8vQRL1/1Bqb3Dnh8WtUADYHBl4S/1XKB698F9f0OLRIhVaNkPn8 JQrQosNJZcSgZ08xYBQDQkdbWLVNZL+LH6bOboas6OsznDaUneBRb2zSFzrpUYldoN7rmNaj9zJ gVzqwd4fWypKx+dj4hxB4FdwyIqg39m0vQbk+0RviZdNiP3zv6P6KGM6i4nLnvRcOPWzMGDZVRV Zccd67gUrH6JGAY5m8T3jRecwI56i1x+ENclehAIQeFFnYUiG5JtjcJljAeIJFIBFUl6I/JsYCD nLlDXIkur5EWBzkhOgl8/gYcCrImviLrnz7zulkqJ37LBln43aBj7rZmxl/afK9yUhd+epN6yr4 g== X-Received: by 2002:a05:6820:160a:b0:680:89db:fd86 with SMTP id 006d021491bc7-69998cd7cd3mr7066137eaf.13.1778245425501; Fri, 08 May 2026 06:03:45 -0700 (PDT) Received: from [172.22.22.28] (c-75-72-117-212.hsd1.mn.comcast.net. [75.72.117.212]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8bf39c7dd09sm17034776d6.31.2026.05.08.06.03.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 08 May 2026 06:03:44 -0700 (PDT) Message-ID: <6f15ed94-c52d-41c6-9e96-68e96c70d287@riscstar.com> Date: Fri, 8 May 2026 08:03:43 -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 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> Content-Language: en-US From: Alex Elder In-Reply-To: <20260508-regmap-gpio-sparse-fixed-dir-v2-1-deee84df3027@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 > --- > 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; > > - 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 >