From: "Yu-Chun Lin [林祐君]" <eleanor.lin@realtek.com>
To: "Michael Walle" <mwalle@kernel.org>,
"linusw@kernel.org" <linusw@kernel.org>,
"andriy.shevchenko@intel.com" <andriy.shevchenko@intel.com>,
"brgl@kernel.org" <brgl@kernel.org>,
"TY_Chang[張子逸]" <tychang@realtek.com>,
"wbg@kernel.org" <wbg@kernel.org>,
"mathieu.dubois-briand@bootlin.com"
<mathieu.dubois-briand@bootlin.com>,
"nuno.sa@analog.com" <nuno.sa@analog.com>,
"Michael.Hennerich@analog.com" <Michael.Hennerich@analog.com>,
"jic23@kernel.org" <jic23@kernel.org>,
"andy@kernel.org" <andy@kernel.org>,
"u.kleine-koenig@baylibre.com" <u.kleine-koenig@baylibre.com>,
"dakr@kernel.org" <dakr@kernel.org>,
"bhelgaas@google.com" <bhelgaas@google.com>,
"o-takashi@sakamocchi.jp" <o-takashi@sakamocchi.jp>
Cc: "dlechner@baylibre.com" <dlechner@baylibre.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-gpio@vger.kernel.org" <linux-gpio@vger.kernel.org>,
"linux@analog.com" <linux@analog.com>,
"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
"CY_Huang[黃鉦晏]" <cy.huang@realtek.com>,
"James Tai [戴志峰]" <james.tai@realtek.com>
Subject: RE: [PATCH v7 5/9] gpio: regmap: Add gpio_regmap_operation to extend reg_mask_xlate callback
Date: Thu, 23 Jul 2026 11:14:14 +0000 [thread overview]
Message-ID: <f4b79d5510b64ad3bc2d716a51d21cfe@realtek.com> (raw)
In-Reply-To: <DK5R2VCAK468.2GAEC7VG8OJBZ@kernel.org>
Hi Michael,
>
>> @@ -71,7 +73,7 @@ static int gpio_regmap_simple_xlate(struct
>> gpio_regmap *gpio, static int gpio_regmap_get(struct gpio_chip *chip,
>> unsigned int offset) {
>> struct gpio_regmap *gpio = gpiochip_get_data(chip);
>> - unsigned int base, val, reg, mask;
>> + unsigned int base, val, reg, mask, dir_mask;
>> int ret;
>>
>> /* we might not have an output register if we are input only */ @@
>> -80,7 +82,18 @@ static int gpio_regmap_get(struct gpio_chip *chip, unsigned int offset)
>> else
>> base = gpio_regmap_addr(gpio->reg_set_base);
>>
>> - ret = gpio->reg_mask_xlate(gpio, base, offset, ®, &mask);
>> + ret = gpio->reg_mask_xlate(gpio, GPIO_REGMAP_GET_OP, base, offset, ®, &dir_mask);
>> + if (ret)
>> + return ret;
>> +
>> + ret = regmap_read(gpio->regmap, reg, &val);
>> + if (ret)
>> + return ret;
>> +
>> + if (val & dir_mask)
>> + ret = gpio->reg_mask_xlate(gpio, GPIO_REGMAP_OUT, base, offset, ®, &mask);
>> + else
>> + ret = gpio->reg_mask_xlate(gpio, GPIO_REGMAP_IN, base, offset,
>> +®, &mask);
>
> What's going on here? Looks like I've missed this in the previous
> patches. All the other drivers we are now reading the value twice.
> In the regmap_read() above and the one that follows just after this
> hunk.
>
> Has the gpio controller two different bits, one for output and one
> for input? Are you sure, the input bit doesn't reflect the output
> bit if it's configured as an output?
>
> IMHO this shouldn't be part of the core. rtd1625_reg_mask_xlate()
> should either return RTD1625_GPIO_IN or RTD1625_GPIO_OUT depending
> on the mode, if that's needed at all. I'd guess RTD1625_GPIO_IN
> will just work fine and will actually fetch the actual line state.
>
> -michael
>
Regarding the hardware, this controller indeed has dedicated and separate
bits for IN, OUT, and DIR. If configured as an output, reading the IN bit
does not reflect the actual state, so we must check the DIR bit first to
know which bit to read.
As you pointed out, my implementation would cause other drivers to read
twice. Therefore, I will keep GPIO_REGMAP_GET_OP, drop GPIO_REGMAP_IN and
GPIO_REGMAP_OUT, and move the register reading logic into my custom
reg_mask_xlate().
Best Regards,
Yu-Chun
>>
>> > if (ret)
>> > return ret;
>>
>...
>
>>
>> +/**
>> + * enum gpio_regmap_operation - Operation type for reg_mask_xlate
>> +callback
>> + *
>> + * Traditionally, the operation type was inferred from the base register.
>> + * However, that approach does not always work — for example, when
>> +all control
>> + * bits of a single GPIO reside in the same register. This enum
>> +allows the
>> + * reg_mask_xlate callback to explicitly distinguish between operation types.
>> + * The user is free to choose which method to use.
>> + *
>> + * Value operations:
>> + * @GPIO_REGMAP_GET_OP: Mask for reading direction to detect if GPIO is input or
>> + * output. Used in gpio_regmap_get() to determine the GPIO
>> + * direction.
>
> This is also not very intuitive. I'd expect there is only one
> operation for the gpio_regmap_get and that is exactly this one.
>
>> + * @GPIO_REGMAP_IN: Mask for reading input value. Used when GPIO is configured as
>> + * input.
>> + * @GPIO_REGMAP_OUT: Mask for reading output value. Used when GPIO is configured as
>> + * output.
>> + *
>> + * Output operations:
>> + * @GPIO_REGMAP_SET_OP: Mask for setting GPIO output value.
>> + *
>> + * Direction operations:
>> + * @GPIO_REGMAP_GET_DIR_OP: Mask for reading GPIO direction (input/output).
>> + * @GPIO_REGMAP_SET_DIR_OP: Mask for setting GPIO direction (input/output).
>> + */
>> +enum gpio_regmap_operation {
>> + GPIO_REGMAP_GET_OP,
>> + GPIO_REGMAP_SET_OP,
>> + GPIO_REGMAP_GET_DIR_OP,
>> + GPIO_REGMAP_SET_DIR_OP,
>> + GPIO_REGMAP_IN,
>> + GPIO_REGMAP_OUT,
>> +};
next prev parent reply other threads:[~2026-07-23 11:14 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-23 3:42 [PATCH v7 0/9] gpio: realtek: Add support for Realtek DHC RTD1625 Yu-Chun Lin
2026-07-23 3:42 ` [PATCH v7 1/9] Revert "gpio: realtek: Add driver for Realtek DHC RTD1625 SoC" Yu-Chun Lin
2026-07-23 21:09 ` Linus Walleij
2026-07-23 3:42 ` [PATCH v7 2/9] gpio: regmap: Provide default IRQ resource request and release callbacks Yu-Chun Lin
2026-07-23 21:10 ` Linus Walleij
2026-07-23 3:42 ` [PATCH v7 3/9] gpio: regmap: Apply default resource callbacks for regmap IRQ chip Yu-Chun Lin
2026-07-23 16:36 ` Mathieu Dubois-Briand
2026-07-23 21:11 ` Linus Walleij
2026-07-23 3:42 ` [PATCH v7 4/9] gpio: regmap: Order kernel-doc descriptions with the actual appearance Yu-Chun Lin
2026-07-23 21:11 ` Linus Walleij
2026-07-23 3:42 ` [PATCH v7 5/9] gpio: regmap: Add gpio_regmap_operation to extend reg_mask_xlate callback Yu-Chun Lin
2026-07-23 6:51 ` Michael Walle
2026-07-23 11:14 ` Yu-Chun Lin [林祐君] [this message]
2026-07-23 11:20 ` Michael Walle
2026-07-24 5:47 ` Yu-Chun Lin [林祐君]
2026-07-24 10:22 ` William Breathitt Gray
2026-07-25 21:47 ` Jonathan Cameron
2026-07-23 3:42 ` [PATCH v7 6/9] gpio: regmap: Add value_xlate callback Yu-Chun Lin
2026-07-23 6:54 ` Michael Walle
2026-07-23 21:14 ` Linus Walleij
2026-07-23 3:42 ` [PATCH v7 7/9] gpio: regmap: Add set_config callback Yu-Chun Lin
2026-07-23 7:01 ` Michael Walle
2026-07-23 21:15 ` Linus Walleij
2026-07-23 3:42 ` [PATCH v7 8/9] gpio: regmap: Add IRQ enable/disable helpers Yu-Chun Lin
2026-07-23 21:15 ` Linus Walleij
2026-07-23 3:42 ` [PATCH v7 9/9] gpio: realtek: Add driver for Realtek DHC RTD1625 SoC Yu-Chun Lin
2026-07-23 16:22 ` Mathieu Dubois-Briand
2026-07-24 5:49 ` Yu-Chun Lin [林祐君]
2026-07-25 13:56 ` Linus Walleij
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f4b79d5510b64ad3bc2d716a51d21cfe@realtek.com \
--to=eleanor.lin@realtek.com \
--cc=Michael.Hennerich@analog.com \
--cc=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=bhelgaas@google.com \
--cc=brgl@kernel.org \
--cc=cy.huang@realtek.com \
--cc=dakr@kernel.org \
--cc=dlechner@baylibre.com \
--cc=james.tai@realtek.com \
--cc=jic23@kernel.org \
--cc=linusw@kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@analog.com \
--cc=mathieu.dubois-briand@bootlin.com \
--cc=mwalle@kernel.org \
--cc=nuno.sa@analog.com \
--cc=o-takashi@sakamocchi.jp \
--cc=tychang@realtek.com \
--cc=u.kleine-koenig@baylibre.com \
--cc=wbg@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome