[{"id":3688400,"web_url":"http://patchwork.ozlabs.org/comment/3688400/","msgid":"<6f15ed94-c52d-41c6-9e96-68e96c70d287@riscstar.com>","list_archive_url":null,"date":"2026-05-08T13:03:43","subject":"Re: [PATCH v2 1/2] gpio: regmap: Support sparsed fixed direction","submitter":{"id":89551,"url":"http://patchwork.ozlabs.org/api/people/89551/","name":"Alex Elder","email":"elder@riscstar.com"},"content":"On 5/8/26 7:51 AM, Linus Walleij wrote:\n> On some regmapped GPIOs apparently only a sparser selection\n> of the lines (not all) are actually fixed direction.\n> \n> Support this situation by adding an optional bitmap indicating\n> which GPIOs are actually fixed direction and which are not.\n> \n> Cc: Alex Elder <elder@riscstar.com>\n> Link: https://lore.kernel.org/linux-gpio/20260501155421.3329862-10-elder@riscstar.com/\n> Tested-by: Alex Elder <elder@riscstar.com>\n> Signed-off-by: Linus Walleij <linusw@kernel.org>\n\n\n\nIn addition, it would be fine with me if you merged this together\niwth your new patch:\n\n  \nhttps://lore.kernel.org/lkml/20260508-regmap-gpio-sparse-fixed-dir-v2-2-deee84df3027@kernel.org/\n\nIt makes sense and it is logically part of the same change.\n\nI even tested with that change applied, even though I know\njust by inspection it will do what's desired.\n\nAnyway, for both (or a combined single patch), these apply:\n\nTested-by: Alex Elder <elder@riscstar.com>\nReviewed-by: Alex Elder <elder@riscstar.com>\n\n\n\t\t\t\t\t-Alex\n\n> ---\n>   drivers/gpio/gpio-regmap.c  | 37 +++++++++++++++++++++++++++++++++----\n>   include/linux/gpio/regmap.h |  7 +++++++\n>   2 files changed, 40 insertions(+), 4 deletions(-)\n> \n> diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c\n> index 9ae4a41a2427..f45a432e8ebe 100644\n> --- a/drivers/gpio/gpio-regmap.c\n> +++ b/drivers/gpio/gpio-regmap.c\n> @@ -31,6 +31,7 @@ struct gpio_regmap {\n>   \tunsigned int reg_clr_base;\n>   \tunsigned int reg_dir_in_base;\n>   \tunsigned int reg_dir_out_base;\n> +\tunsigned long *fixed_direction_sparse;\n>   \tunsigned long *fixed_direction_output;\n>   \n>   #ifdef CONFIG_REGMAP_IRQ\n> @@ -138,6 +139,20 @@ static int gpio_regmap_set_with_clear(struct gpio_chip *chip,\n>   \treturn regmap_write(gpio->regmap, reg, mask);\n>   }\n>   \n> +static bool gpio_regmap_fixed_direction(struct gpio_regmap *gpio,\n> +\t\t\t\t\tunsigned int offset)\n> +{\n> +\tif (!gpio->fixed_direction_output)\n> +\t\treturn false;\n> +\n> +\t/* In this case only some GPIOs are fixed as input/output */\n> +\tif (gpio->fixed_direction_sparse &&\n> +\t    !test_bit(offset, gpio->fixed_direction_sparse))\n> +\t\treturn false;\n> +\n> +\treturn true;\n> +}\n> +\n>   static int gpio_regmap_get_direction(struct gpio_chip *chip,\n>   \t\t\t\t     unsigned int offset)\n>   {\n> @@ -145,7 +160,7 @@ static int gpio_regmap_get_direction(struct gpio_chip *chip,\n>   \tunsigned int base, val, reg, mask;\n>   \tint invert, ret;\n>   \n> -\tif (gpio->fixed_direction_output) {\n> +\tif (gpio_regmap_fixed_direction(gpio, offset)) {\n>   \t\tif (test_bit(offset, gpio->fixed_direction_output))\n>   \t\t\treturn GPIO_LINE_DIRECTION_OUT;\n>   \t\telse\n> @@ -302,12 +317,23 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config\n>   \t\t\tgoto err_free_gpio;\n>   \t}\n>   \n> +\tif (config->fixed_direction_sparse) {\n> +\t\tgpio->fixed_direction_sparse = bitmap_alloc(chip->ngpio,\n> +\t\t\t\t\t\t\t    GFP_KERNEL);\n> +\t\tif (!gpio->fixed_direction_sparse) {\n> +\t\t\tret = -ENOMEM;\n> +\t\t\tgoto err_free_gpio;\n> +\t\t}\n> +\t\tbitmap_copy(gpio->fixed_direction_sparse,\n> +\t\t\t    config->fixed_direction_sparse, chip->ngpio);\n> +\t}\n> +\n>   \tif (config->fixed_direction_output) {\n>   \t\tgpio->fixed_direction_output = bitmap_alloc(chip->ngpio,\n>   \t\t\t\t\t\t\t    GFP_KERNEL);\n>   \t\tif (!gpio->fixed_direction_output) {\n>   \t\t\tret = -ENOMEM;\n> -\t\t\tgoto err_free_gpio;\n> +\t\t\tgoto err_free_bitmap_sparse;\n>   \t\t}\n>   \t\tbitmap_copy(gpio->fixed_direction_output,\n>   \t\t\t    config->fixed_direction_output, chip->ngpio);\n> @@ -329,7 +355,7 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config\n>   \n>   \tret = gpiochip_add_data(chip, gpio);\n>   \tif (ret < 0)\n> -\t\tgoto err_free_bitmap;\n> +\t\tgoto err_free_bitmap_output;\n>   \n>   #ifdef CONFIG_REGMAP_IRQ\n>   \tif (config->regmap_irq_chip) {\n> @@ -355,8 +381,10 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config\n>   \n>   err_remove_gpiochip:\n>   \tgpiochip_remove(chip);\n> -err_free_bitmap:\n> +err_free_bitmap_output:\n>   \tbitmap_free(gpio->fixed_direction_output);\n> +err_free_bitmap_sparse:\n> +\tbitmap_free(gpio->fixed_direction_sparse);\n>   err_free_gpio:\n>   \tkfree(gpio);\n>   \treturn ERR_PTR(ret);\n> @@ -376,6 +404,7 @@ void gpio_regmap_unregister(struct gpio_regmap *gpio)\n>   \n>   \tgpiochip_remove(&gpio->gpio_chip);\n>   \tbitmap_free(gpio->fixed_direction_output);\n> +\tbitmap_free(gpio->fixed_direction_sparse);\n>   \tkfree(gpio);\n>   }\n>   EXPORT_SYMBOL_GPL(gpio_regmap_unregister);\n> diff --git a/include/linux/gpio/regmap.h b/include/linux/gpio/regmap.h\n> index 12d154732ca9..ff00b4aeaf1c 100644\n> --- a/include/linux/gpio/regmap.h\n> +++ b/include/linux/gpio/regmap.h\n> @@ -38,6 +38,12 @@ struct regmap;\n>    *\t\t\toffset to a register/bitmask pair. If not\n>    *\t\t\tgiven the default gpio_regmap_simple_xlate()\n>    *\t\t\tis used.\n> + * @fixed_direction_sparse:\n> + *\t\t\t(Optional) Bitmap representing the GPIO lines that\n> + *\t\t\tmake use of the @fixed_direction_output list to\n> + *\t\t\tenforce direction of the GPIO. If this is NULL\n> + *\t\t\tand @fixed_direction_output is defined, ALL GPIOs\n> + *\t\t\tare assumed to be fixed direction (out or in).\n>    * @fixed_direction_output:\n>    *\t\t\t(Optional) Bitmap representing the fixed direction of\n>    *\t\t\tthe GPIO lines. Useful when there are GPIO lines with a\n> @@ -89,6 +95,7 @@ struct gpio_regmap_config {\n>   \tint reg_stride;\n>   \tint ngpio_per_reg;\n>   \tstruct irq_domain *irq_domain;\n> +\tunsigned long *fixed_direction_sparse;\n>   \tunsigned long *fixed_direction_output;\n>   \n>   #ifdef CONFIG_REGMAP_IRQ\n>","headers":{"Return-Path":"\n <linux-gpio+bounces-36464-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-gpio@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=riscstar-com.20251104.gappssmtp.com\n header.i=@riscstar-com.20251104.gappssmtp.com header.a=rsa-sha256\n header.s=20251104 header.b=qtRUiz5Z;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c04:e001:36c::12fc:5321; helo=tor.lore.kernel.org;\n envelope-from=linux-gpio+bounces-36464-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=riscstar-com.20251104.gappssmtp.com\n header.i=@riscstar-com.20251104.gappssmtp.com header.b=\"qtRUiz5Z\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=209.85.161.41","smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=riscstar.com","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=riscstar.com"],"Received":["from tor.lore.kernel.org (tor.lore.kernel.org\n [IPv6:2600:3c04:e001:36c::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4gBq9C658sz1yCg\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 08 May 2026 23:05:19 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby tor.lore.kernel.org (Postfix) with ESMTP id 6E0D6306CB1D\n\tfor <incoming@patchwork.ozlabs.org>; Fri,  8 May 2026 13:03:53 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id AE1F53E1220;\n\tFri,  8 May 2026 13:03:49 +0000 (UTC)","from mail-oo1-f41.google.com (mail-oo1-f41.google.com\n [209.85.161.41])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id C7F202773CA\n\tfor <linux-gpio@vger.kernel.org>; Fri,  8 May 2026 13:03:46 +0000 (UTC)","by mail-oo1-f41.google.com with SMTP id\n 006d021491bc7-682fce74c06so1324446eaf.3\n        for <linux-gpio@vger.kernel.org>;\n Fri, 08 May 2026 06:03:46 -0700 (PDT)","from [172.22.22.28] (c-75-72-117-212.hsd1.mn.comcast.net.\n [75.72.117.212])\n        by smtp.gmail.com with ESMTPSA id\n 6a1803df08f44-8bf39c7dd09sm17034776d6.31.2026.05.08.06.03.44\n        (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n        Fri, 08 May 2026 06:03:44 -0700 (PDT)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1778245429; cv=none;\n b=go4MaVJVhcd6iDJ/W0CoXvRdvRTwm5CpKFXOmyEa2yLqKDt6F103ydvBsAlDm1EapwqfhIGOUJwvPuYQvMJwARZWGobrzimlDcJ+XdCVyNqWN/jN4/tQOWl6k8/OS8GR9fFTd29ZjFgGBmmR6jy8uYPzK4EOElNt0vwAuwZhc5U=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1778245429; c=relaxed/simple;\n\tbh=pt7XlsbOA9tv1TtrGt/RRq/85eL+D59/sDcgqu5C8XY=;\n\th=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From:\n\t In-Reply-To:Content-Type;\n b=qgMqpc72q2gktvZhcoq+EipdGgIpKjxv/r9pO7CtlTmgvPbqHXh3NkUTFl3+UumBnnojRj3hqAlHWr8vWcQtpRlqUTAF9rU7rbiAQXtvWE4Tdz7ewYGz9ajAImZP8cYqEeUNl9c0zEiRXPR7IdBXrNZY3rxhlzN2LT0jwV/IPyM=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=riscstar.com;\n spf=pass smtp.mailfrom=riscstar.com;\n dkim=pass (2048-bit key) header.d=riscstar-com.20251104.gappssmtp.com\n header.i=@riscstar-com.20251104.gappssmtp.com header.b=qtRUiz5Z;\n arc=none smtp.client-ip=209.85.161.41","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=riscstar-com.20251104.gappssmtp.com; s=20251104; t=1778245426;\n x=1778850226; darn=vger.kernel.org;\n        h=content-transfer-encoding:in-reply-to:from:content-language\n         :references:cc:to:subject:user-agent:mime-version:date:message-id\n         :from:to:cc:subject:date:message-id:reply-to;\n        bh=4uYSKJlZDlhRVMvkmCmHZTLX4HWfRTth6fnS9HRLT2Q=;\n        b=qtRUiz5Zogp3NkjZ8rJ1gsIAuVw4z0S3IiBZ+KIRiR5dMd9eY60gnVWlS8uCwYSMMy\n         vJoEu9JeREoEWV4aicuzkk43TKP6iN8SjivnhOLOBaYIQpJH3YUXY7fNJ5bM50OKazoo\n         Vgneib5nQaxVDJZyBXZZmSVgZ44auQlUElKIrrGJFiGjDb/kqoFSe0h3Vsaymy8hpdCX\n         RG5n/dWMxi+ghJdmHCMQBPQLXBQOUPHjam2PvCnJV8M1wW6QQuS1/xNGwJFBuV3CpkAo\n         A9YVOOAhFpTMcA5uyQQe8x+iS7Cwh6Q5APAMtG/Y120qrx/3SejU42+F1hyKU9P2HH1R\n         Il2g==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=1e100.net; s=20251104; t=1778245426; x=1778850226;\n        h=content-transfer-encoding:in-reply-to:from:content-language\n         :references:cc:to:subject:user-agent:mime-version:date:message-id\n         :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id\n         :reply-to;\n        bh=4uYSKJlZDlhRVMvkmCmHZTLX4HWfRTth6fnS9HRLT2Q=;\n        b=cA197GMtbCvwvLQXbemVNISwDbNr2hrQ4wb7pFTp5rbnEB872pzii8tSeGWajjggaH\n         CpI6+BVLBFpvoDfCcjma72Y2RyT+IwoFKrCiHuTqW0fGjeo+U33Buva1fbTcCbUlSsR5\n         6xUiNct7006F0dv7gEKXeEmuw8+AOldlfCwl1L6YsVKhsSFmn9x1Xp5k/7l8HiGua7hL\n         ZuWTGKL/QhmI9ULFFr2eau59pqEXr2YNLVH2kk+XN3EWSpvS/6wNQAghJH4DAuplmxX2\n         QqcwBOJySC/VoPnNmxKxTGCoZRtJa1nVk8jOqTCyjMmW5CVdg0AT3KOglgLo0VJ1yV2g\n         /lmw==","X-Gm-Message-State":"AOJu0YylRqBhQReTPnJLcAEJrUViN5B6loLpqQmav3oWmhx0FZ9/rCA+\n\txU2OIVqaUthiWYJdsK4iXKSkY3oBxYXDYYgw4PmVWAHw0zCHdIXigLcOifZsG4JnBEA=","X-Gm-Gg":"AeBDieuwEZBvsHfmhEWzlwO8tcun8h7tm+Upu/8+d7CSZNnlBEW7lEKx08qAAlGNorF\n\tgFBazWM88YI6zVKtueNRxwzTfhSoZNhqExkUfU5khZeK1nfFqnY1j7+D+L1SCmQPeM3yH9/ViYo\n\tVnxwwVisri2ibXv1tbFtK2NsEmObl+M08eb+k1Wdhbgl4iC3varRcWxRNQtOyh/eRB9/Irn4KkA\n\t9ap2JVsE5y8JyptkvvXkmfR2g4LLXkFV08WuLYSofkSmndsHARidFVhnxHo1N1atSBsPQitSI8P\n\twEqP5ryvzP82Wehz4D8nbE5fiSAM+9dbz1r38eLykp1wMu+rOCq8rTXghidzpSLfCUQ69V2JpNa\n\t/+4zHZuEdWMg58BJuWZ2eUasRGbrvFtEjK0nbgAVLidRCDMSRi/IOSEZsh6QeP6QHgJ+pPpaLNf\n\tLsCCqVRT6R5N8VJa9gkj+FwAAG3uWiKzerzlcErsdi9liMPTQ3jt5q0qREPzYT4LKf+Do9axSQr\n\tg==","X-Received":"by 2002:a05:6820:160a:b0:680:89db:fd86 with SMTP id\n 006d021491bc7-69998cd7cd3mr7066137eaf.13.1778245425501;\n        Fri, 08 May 2026 06:03:45 -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-gpio@vger.kernel.org","List-Id":"<linux-gpio.vger.kernel.org>","List-Subscribe":"<mailto:linux-gpio+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-gpio+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v2 1/2] gpio: regmap: Support sparsed fixed direction","To":"Linus Walleij <linusw@kernel.org>, Michael Walle <mwalle@kernel.org>,\n Bartosz Golaszewski <brgl@kernel.org>","Cc":"linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org","References":"\n <20260508-regmap-gpio-sparse-fixed-dir-v2-0-deee84df3027@kernel.org>\n <20260508-regmap-gpio-sparse-fixed-dir-v2-1-deee84df3027@kernel.org>","Content-Language":"en-US","From":"Alex Elder <elder@riscstar.com>","In-Reply-To":"\n <20260508-regmap-gpio-sparse-fixed-dir-v2-1-deee84df3027@kernel.org>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit"}}]