From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f174.google.com (mail-qt1-f174.google.com [209.85.160.174]) (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 66B323537C7 for ; Thu, 7 May 2026 22:13:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778192032; cv=none; b=oyj9GuXAr9V7yA+U7HNJ6NTTFlR8wMOzldT2sBaxgrZ3Oa07GIf5gUBTXq+8iOx9a/r9MY0zQExeYk7yOqAfjX89lrk2qQytPZfqLnBcizPjcwiby0RCAXfBGA+0rwKI6/njrlCGPoBuZPQIUJqNTGjB5Y4OqfZMgNY/a4JG3og= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778192032; c=relaxed/simple; bh=i2goPQ+5CehJtzewck9sJw/d7QO5lIUAOCoZXH/u9HU=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=sbNkHWyCzjpMABPMKww5sZg4d5qBBPGYYva9AZM0DrjpHIU3xSg/u3hERHjx4E0c3dN8E+Z0jCXUdPnljWDY45J3vjflxE26Z1D4caf+1vk4RuX2noyCtiBd2hiiWnjgMAiHV/cn3iWDdLazYgOfDl0MBQbyKF+jbhSy8RJghkY= 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=wBf0LIcx; arc=none smtp.client-ip=209.85.160.174 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="wBf0LIcx" Received: by mail-qt1-f174.google.com with SMTP id d75a77b69052e-50d6ab4476eso12115211cf.2 for ; Thu, 07 May 2026 15:13:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riscstar-com.20251104.gappssmtp.com; s=20251104; t=1778192029; x=1778796829; 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=+YmVAR6P2lvdU3Vlv0mh6Jm+l1RNrUJm94KlauQmZsc=; b=wBf0LIcx0i/NMUaRL+2KM1wMKehZlIwYwLzS1uI1S0WCkJxEQm24pEdlwV5Q/ZdKQo tcUAfaEK5JIF0pecJ7/YBquY7xQF5EcH2rESBarITPryRKSDbNTWNUxvouQ3Y6lzV7eG eqYMQ/nEu0xg/+xsFmZOVTT9x3JwGikNejSWD75ipCLXng6bAqr6bKlzPLwSMRaN9Ggs KCEYLo55iUsr8VGswmB4KcpOILi1HAhCGx2UyIF9EVvB61YZD5T17fjNQU1Kon886U8o Nm4nbZWXEB2zzSzRdAeCu11rgCPshnVkvR/6YsxCL88X8Tv4kmLO6+cnTq34rddAOkDE WZew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778192029; x=1778796829; 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=+YmVAR6P2lvdU3Vlv0mh6Jm+l1RNrUJm94KlauQmZsc=; b=eiTWVDUpcG9kiOP068HCQ6FGm0n/AemtkOQUPNj8qeqGpWmRLH+epGHyPKMXQ+tJv/ /gBph3yZ1UIQxRlGTZIOsZOetmMSREAtc2iqIx9AbZs61Kf38x9osCIYgwdtJ+FgXWIt VJeOKoQjV+K0t3JWnWjRqd1KFWxStaGNPlmCQO6TrBij6YGKU09UFyu4QZfjeCeUoOg3 RN1Irz1xwvEkWG5EAFQ8pjare7r3YsUjA4Ju/FusvIaX7pgR6eMkpGzfSriX3MAioypx oezZKmkvy2uEk2xCUWllFs0rEpy0be//i7jimwVOv0ASQ/skWcD5E+M3K9NiddR/wQd5 LEuw== X-Forwarded-Encrypted: i=1; AFNElJ8/0K1GRl6h7h/jCH0b2c7ae2gUTyik8OOkYiZSnkNGnSypOtSGpJFsOA88tNBIOl70rh3Ln1lP6jile5g=@vger.kernel.org X-Gm-Message-State: AOJu0YyKhmtsbEHyC85cSfXqZgR4cADA+liliwLttSdNc315tNby5FeA 9JoQ1rhPbfaYmg8BpY8xBlodWbVpvMoTbvgegMNkiClbhpJHuHjsqJVRDMar7Kofd7w= X-Gm-Gg: AeBDiev9Pc+2vA5tlu6UnEXYDtjjoii09yWvNv4FbmXkcaRiLoxh4ZrhEJfYHnXOanW yohGXPVrdrvkaVeAQm0oWXi3DlYnkNjOJXpKH5U7bIFzxpZZHwxL0v/WWHedUF+eXuZ3xVC1h1k xqc8Kcd/N3bEnl7xehlr3X7Vyz1D10MPato4bHXox/EwuqyizQARn+DPUt9HDPQjdYcfFqwxeAV noB1sAytL+NZqFjwmEQYvayRuYKUGh3hCKboEb9X4VoLWVS4gZLyr6HdU509o2dGJLNV3teJlCi KhAt3bsk35b/O6fewzu49ZPK7swP78WvLOakls0MFn7/fXHDWfcp48nLgp5ffWETrLjh7CqYz/4 oWch3p0+hVCyDWbgCrbtcYns5zTlXfKFnl8WVmjahDEYcwRh5GD/Pq/nT3+JVtLnLAtKM8VgCfr 22FFqtZSCZ2iQT0EiuQ7aPYdVyuDu55eRl9kYDWtaDYZNtlMRCjQQHmxgC4Kepq0CC3IKLOzgi0 1g= X-Received: by 2002:a05:622a:598a:b0:50f:b69a:f4b9 with SMTP id d75a77b69052e-51461e38c5cmr147244991cf.27.1778192029287; Thu, 07 May 2026 15:13:49 -0700 (PDT) Received: from [172.22.22.234] (c-75-72-117-212.hsd1.mn.comcast.net. [75.72.117.212]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-5148e677e63sm619611cf.12.2026.05.07.15.13.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 May 2026 15:13:48 -0700 (PDT) Message-ID: <3728c4d0-4961-4696-9e7b-29efb7a8a427@riscstar.com> Date: Thu, 7 May 2026 17:13:47 -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] 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: <20260507-regmap-gpio-sparse-fixed-dir-v1-1-a2e5855e2701@kernel.org> Content-Language: en-US From: Alex Elder In-Reply-To: <20260507-regmap-gpio-sparse-fixed-dir-v1-1-a2e5855e2701@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 5/7/26 7:10 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/ > Signed-off-by: Linus Walleij Tested-by: Alex Elder > --- > drivers/gpio/gpio-regmap.c | 38 +++++++++++++++++++++++++++++++++----- > include/linux/gpio/regmap.h | 7 +++++++ > 2 files changed, 40 insertions(+), 5 deletions(-) > > diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c > index 9ae4a41a2427..37568dc611f5 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,14 +139,27 @@ 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) > { > struct gpio_regmap *gpio = gpiochip_get_data(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 +316,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 +354,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 +380,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 +403,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 > > --- > base-commit: 254f49634ee16a731174d2ae34bc50bd5f45e731 > change-id: 20260507-regmap-gpio-sparse-fixed-dir-1d5c0d2e2c6f > > Best regards, > -- > Linus Walleij >