All of lore.kernel.org
 help / color / mirror / Atom feed
From: "TY_Chang[張子逸]" <tychang@realtek.com>
To: Andy Shevchenko <andy@kernel.org>
Cc: Linus Walleij <linus.walleij@linaro.org>,
	Bartosz Golaszewski <brgl@bgdev.pl>,
	Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Conor Dooley <conor+dt@kernel.org>,
	"linux-gpio@vger.kernel.org" <linux-gpio@vger.kernel.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH v4 2/2] Add GPIO support for Realtek DHC(Digital Home Center) RTD SoCs.
Date: Thu, 28 Dec 2023 02:27:06 +0000	[thread overview]
Message-ID: <532f905a4df6444c85c7932bca60aeca@realtek.com> (raw)
In-Reply-To: <ZYxOLXiV6IQQ7IlD@smile.fi.intel.com>

Hi Andy,

>On Tue, Dec 26, 2023 at 07:34:37AM +0000, TY_Chang[張子逸] wrote:
>> >On Fri, Dec 22, 2023 at 03:58:12PM +0800, Tzuyi Chang wrote:
>
>...
>
>> >> +static int rtd_gpio_gpa_offset(struct rtd_gpio *data, unsigned int
>> >> +offset) {
>> >> +     return data->info->gpa_offset[offset / 31]; }
>> >> +
>> >> +static int rtd_gpio_gpda_offset(struct rtd_gpio *data, unsigned
>> >> +int
>> >> +offset) {
>> >> +     return data->info->gpda_offset[offset / 31]; }
>> >
>> >The / 31 so-o-o counter intuitive, please add a comment in each case
>> >to explain why [it's not 32 or other power-of-2].
>> >
>>
>> In our hardware design, the bit 0 of the gpda and gpa status registers does not
>correspond to a GPIO.
>> If bit 0 is set to 1, the other bit can be set to 1 by writing 1.
>> If bit 0 is set to 0, the other bit can be clear to 0 by writing 1.
>>
>> Therefore, each status register only contains the status of 31 GPIOs. I will add
>the comment for this.
>
>Yes, please add in all places, while it's a dup, it helps understanding the point
>without looking around for a while.
>
>...
>
>> >> +     for (i = 0; i < data->info->num_gpios; i += 31) {
>> >
>> >Same, add explanation why 31.
>> >
>> >Note, I actually prefer to see use of valid_mask instead of this weirdness.
>> >Then you will need to comment only once and use 32 (almost?) everywhere.
>> >
>>
>> The reason remains consistent with the previous explanation. Each
>> status register exclusively holds the status of 31 GPIOs.
>
>As per above, add a comment.
>
>> >> +             reg_offset = get_reg_offset(data, i);
>> >> +
>> >> +             status = readl_relaxed(data->irq_base + reg_offset) >> 1;
>> >> +             writel_relaxed(status << 1, data->irq_base +
>> >> + reg_offset);
>> >> +
>> >> +             for_each_set_bit(j, &status, 31) {
>> >> +                     hwirq = i + j;
>> >
>> >Nice, but you can do better
>> >
>> >                /* Bit 0 is special... bla-bla-bla... */
>> >                status = readl_relaxed(data->irq_base + reg_offset);
>> >                status &= ~BIT(0);
>> >                writel_relaxed(status, data->irq_base + reg_offset);
>> >
>> >                for_each_set_bit(j, &status, 32) {
>> >                        hwirq = i + j - 1;
>> >
>>
>> Given that each status register accommodates the status of only 31
>> GPIOs, I think utilizing the upper format and including explanatory
>> comments would be appropriate. It can indicate the status registers only
>contains 31 GPIOs.
>> Please correct me if my understanding is incorrect.
>
>The above is just a code hack to help bitops to optimise. 32 is power-of-2 which
>might be treated better by the compiler and hence produce better code.
>
>Yet, it's an interrupt handler where we want to have the ops as shorter as
>possible, so even micro-optimizations are good to have here (I don't insist to
>follow the same idea elsewhere).
>

I understand. Thank you for explaining. I will revise it.

>> >> +                     }
>> >> +             }
>> >> +     }
>

Thanks,
Tzuyi Chang

  reply	other threads:[~2023-12-28  2:27 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-22  7:58 [PATCH v4 0/2] Add gpio driver support for Realtek DHC SoCs Tzuyi Chang
2023-12-22  7:58 ` [PATCH v4 1/2] dt-bindings: gpio: realtek: Add realtek,rtd-gpio Tzuyi Chang
2023-12-23 14:19   ` Krzysztof Kozlowski
2023-12-22  7:58 ` [PATCH v4 2/2] Add GPIO support for Realtek DHC(Digital Home Center) RTD SoCs Tzuyi Chang
2023-12-22 13:13   ` Andy Shevchenko
2023-12-26  7:34     ` TY_Chang[張子逸]
2023-12-27 16:17       ` Andy Shevchenko
2023-12-28  2:27         ` TY_Chang[張子逸] [this message]
2023-12-23 14:19   ` Krzysztof Kozlowski
2023-12-25 19:52     ` Andy Shevchenko
2023-12-26  7:34     ` TY_Chang[張子逸]

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=532f905a4df6444c85c7932bca60aeca@realtek.com \
    --to=tychang@realtek.com \
    --cc=andy@kernel.org \
    --cc=brgl@bgdev.pl \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh+dt@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.