From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) (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 45D343B6352 for ; Mon, 11 May 2026 21:06:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778533621; cv=none; b=kVMnHGCcar9OtUYbF7f+NfTkDJKlEbPk90KA9ocqBxmClIpLer68aMDDaChVX8mOlFYlpbWGH/SYaTw2+VsmuN/jSfM137pVny4I1uU0M4XvOQ3LNQEBsxSWrmYKK4hKDvT0NiYnaLJxsbHE97UoLf8REjk0gyaFxkEio8vuvhw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778533621; c=relaxed/simple; bh=2Gs3sD4cUcV1m3zrsiNa0/wpHJ847EmZare339tInT8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=foekBoGu7UQdPDgGZHWr+C7MnreUOidcQrzoPgsc9+I+danlklqmeZmchWG108yCRNPxGqtji0TfiLENP8P97ljEA/EFN1IqrquCWCA/1uPgo/2QY/q8MjJX5rjHYsGGI3vKnoBDtkRjCaK/P91iq+pvGIOAbVNMxM1SyF6mmwE= 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=FN2cb5rV; arc=none smtp.client-ip=209.85.222.181 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="FN2cb5rV" Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-90cbb2b50ccso26631085a.0 for ; Mon, 11 May 2026 14:06:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riscstar-com.20251104.gappssmtp.com; s=20251104; t=1778533618; x=1779138418; 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=OUMPxU9bBh07KOMeBhluYcUNfni6GhtS4Gt4qkqJTIY=; b=FN2cb5rVo1Nw/iDNuchsos7OWM0RmTcQO6knzbqF1T9EYIyctZ8pYFp8By2ZaA32VD 1YHhBzd6/IqAWaNGYAchxFxvLw9AfjjPoRcJ0+mP/5O6s5w69Ox//bWljTTA1GnsaGVF ptL9qJVSSO7IlcMP8eLg/4CwhLDiTjyO86RNJQ5a1GauGGtyZngEGjb5AvXfttenM5Dk yN/UqaoxepEvql7WtgH2og1YoRogXYusXYRH57X8MfnGy7jrKxmuf55c45I1Emk4EnpV u+4WN95L6iqWgfyeu2chha/sqeHnOp1x/BpEpjVBN0NWHAoo6dBmscoFucRwX4Xqu8d+ D8Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778533618; x=1779138418; 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=OUMPxU9bBh07KOMeBhluYcUNfni6GhtS4Gt4qkqJTIY=; b=nsPWNANrR2ptFSRFtg+KLfa6CDaBd6geJVsiIe/mQ+f3efp2eYDSsD71s9iBdLzARo AEQqclN3wnf5kmrl+1GhYNkkqQsqfT728u8xV9R2Wn6ak8G5105ty4oqHVewAsoY6wAK 7gKs901MiwKcta6JU+p5wbS7XPTmv6hnDX5sgrvJ+QyTNWITqtjj846KsxyufT/o4/kv pkIj0FFYWlBxvspWJc75o/JrKydmH8WTJzhvH5noQOpsBatON3G1Xhv0asBbZhHN5wV3 lYrTCDOdz6KAelQL7KJ4nMvr2jMm2APDWVawlaKXYDdIWwvC27DTBC7obi2xi6WGFtVC IthQ== X-Forwarded-Encrypted: i=1; AFNElJ+JPmCggKued4/8v6DVw4NVPwUG7ADQDqEbvjmvL8kONO7hZ5eqTa/JC8Lou0nJ9t+gcjK5WVoW8xYMACM=@vger.kernel.org X-Gm-Message-State: AOJu0YyyMGtn4UA/lNxqUeIxTKxuu1g4XpQ4DuNaQ9F7AalHhPKJXXzF 4Y8RaV1vSN2FIjPCYAO2qttG+pDIj9ew4mQuouDOCf50OEInUSZ7gc+QI+EJ0acZSM7xhNESN5C Y4b+y X-Gm-Gg: Acq92OFQpBcIDjMRjKAYmuaVs3dxVMF2m+03XNvKnlJFJfDKUqkwhzVJ/W6bAP4MYif 5cg+9P4ceUBGb6hRRcKpA1Oh3frYPgML5DiqxD/MVZKQylTkWDuOV3UCfbsJZ1a2yiyC+cZe4aK 6F+w3YWytILfmZmeGHo5FkkPpfpHNcES025D+RamtJD1XaCVwWJ/d9UDWfjLKxC/CIP5tFGhLhI 7XZ6B24XgrbGw0ijCLeRY/Ds+GyztDbHWSiIHOD110DrIjSkugsdyuBsFHeszoO1Lalar+13HKX nzK6A8F6Ewzduw7a4eiU/c77lIVdsbU1MEjzt/qCrKS8ENiToUKNwd9Oj17Xy1gTdxEsRUpbUji efNx8dNuDm8nQhfu/qe2nKapbVwlMv4zAAf+tHRhBGfZAhf43vt6VDt99gU5vSU/Imifb4GyT3N oOxIsUO6yJRaG53roPnluH0gzCH0ua+vEjVqU04FmNU99Oz0+jvZrJ0QnzRrqhFto= X-Received: by 2002:a05:620a:6989:b0:8d6:2958:ec16 with SMTP id af79cd13be357-909111f13ebmr1539111385a.60.1778533618038; Mon, 11 May 2026 14:06:58 -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 af79cd13be357-907b977274csm1123387985a.6.2026.05.11.14.06.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 11 May 2026 14:06:57 -0700 (PDT) Message-ID: Date: Mon, 11 May 2026 16:06:56 -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 v3 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: <20260511-regmap-gpio-sparse-fixed-dir-v3-0-1429ec453be7@kernel.org> <20260511-regmap-gpio-sparse-fixed-dir-v3-1-1429ec453be7@kernel.org> Content-Language: en-US From: Alex Elder In-Reply-To: <20260511-regmap-gpio-sparse-fixed-dir-v3-1-1429ec453be7@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 5/11/26 2:43 PM, 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 Reviewed-by: Alex Elder You renamed "test_direction_sparse" so I had to do that too, but I tested this again as well. > --- > 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..b3b4e77ec147 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_mask; > 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_mask && > + !test_bit(offset, gpio->fixed_direction_mask)) > + 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_mask) { > + gpio->fixed_direction_mask = bitmap_alloc(chip->ngpio, > + GFP_KERNEL); > + if (!gpio->fixed_direction_mask) { > + ret = -ENOMEM; > + goto err_free_gpio; > + } > + bitmap_copy(gpio->fixed_direction_mask, > + config->fixed_direction_mask, 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_dirmask; > } > 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_dirmask: > + bitmap_free(gpio->fixed_direction_mask); > 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_mask); > kfree(gpio); > } > EXPORT_SYMBOL_GPL(gpio_regmap_unregister); > diff --git a/include/linux/gpio/regmap.h b/include/linux/gpio/regmap.h > index 12d154732ca9..06255756710d 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_mask: > + * (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_mask; > unsigned long *fixed_direction_output; > > #ifdef CONFIG_REGMAP_IRQ >