mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Baolin Wang <baolin.wang@linux.alibaba.com>
To: Chunyan Zhang <zhang.lyra@gmail.com>
Cc: Wenhua Lin <Wenhua.Lin@unisoc.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Andy Shevchenko <andy@kernel.org>,
	Bartosz Golaszewski <brgl@bgdev.pl>,
	Orson Zhai <orsonzhai@gmail.com>,
	linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
	wenhua lin <wenhua.lin1994@gmail.com>,
	Xiongpeng Wu <xiongpeng.wu@unisoc.com>
Subject: Re: [PATCH V2 1/2] gpio: pmic-eic-sprd: Two-dimensional arrays maintain pmic eic
Date: Wed, 27 Sep 2023 17:49:11 +0800	[thread overview]
Message-ID: <99dc2f99-cb03-bec8-b538-3ad21750adff@linux.alibaba.com> (raw)
In-Reply-To: <CAAfSe-tDFJtq77zw2vHsHAvrwXSy4KFwAEPnVJ6fP8e4PgRF6A@mail.gmail.com>



On 9/27/2023 5:24 PM, Chunyan Zhang wrote:
> On Wed, 27 Sept 2023 at 17:04, Baolin Wang
> <baolin.wang@linux.alibaba.com> wrote:
>>
>>
>>
>> On 9/21/2023 8:25 PM, Wenhua Lin wrote:
>>> A bank PMIC EIC contains 16 EICs, and the operating registers
>>> are BIT0-BIT15, such as BIT0 of the register operated by EIC0.
>>> Using the one-dimensional array reg[CACHE_NR_REGS] for maintenance
>>> will cause the configuration of other EICs to be affected when
>>> operating a certain EIC. In order to solve this problem, the register
>>> operation bits of each PMIC EIC are maintained through the two-dimensional
>>> array reg[SPRD_PMIC_EIC_NR][CACHE_NR_REGS] to avoid mutual interference.
>>
>> LGTM. And this also deserves a Fixes tag.
> 
> Do we really need a two-dimensional array to save 16-bit value?

I also considering this, but after more thinking, I think this patch is 
a simple fix.

Now I realized the problem is that, if we use one array to cache a bank 
of EICs' status, the pmic_eic->reg[] array can contain incorrect 
configuration for other EICs in the same bank.

Yes, we can have another fix, for example, setting the pmic_eic->reg[] 
to some invalid values (maybe -1) in sprd_pmic_eic_bus_sync_unlock() 
after setting one EIC. Thus when setting another EIC, we can validate if 
the cached reg is a valid value, if not, we do not need to set the 
register. But like I said above, this seems more complicated.

>> Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
>>
>>> Signed-off-by: Wenhua Lin <Wenhua.Lin@unisoc.com>
>>> ---
>>>    drivers/gpio/gpio-pmic-eic-sprd.c | 21 +++++++++++----------
>>>    1 file changed, 11 insertions(+), 10 deletions(-)
>>>
>>> diff --git a/drivers/gpio/gpio-pmic-eic-sprd.c b/drivers/gpio/gpio-pmic-eic-sprd.c
>>> index c3e4d90f6b18..442968bb2490 100644
>>> --- a/drivers/gpio/gpio-pmic-eic-sprd.c
>>> +++ b/drivers/gpio/gpio-pmic-eic-sprd.c
>>> @@ -57,7 +57,7 @@ struct sprd_pmic_eic {
>>>        struct gpio_chip chip;
>>>        struct regmap *map;
>>>        u32 offset;
>>> -     u8 reg[CACHE_NR_REGS];
>>> +     u8 reg[SPRD_PMIC_EIC_NR][CACHE_NR_REGS];
>>>        struct mutex buslock;
>>>        int irq;
>>>    };
>>> @@ -151,8 +151,8 @@ static void sprd_pmic_eic_irq_mask(struct irq_data *data)
>>>        struct sprd_pmic_eic *pmic_eic = gpiochip_get_data(chip);
>>>        u32 offset = irqd_to_hwirq(data);
>>>
>>> -     pmic_eic->reg[REG_IE] = 0;
>>> -     pmic_eic->reg[REG_TRIG] = 0;
>>> +     pmic_eic->reg[offset][REG_IE] = 0;
>>> +     pmic_eic->reg[offset][REG_TRIG] = 0;
>>>
>>>        gpiochip_disable_irq(chip, offset);
>>>    }
>>> @@ -165,8 +165,8 @@ static void sprd_pmic_eic_irq_unmask(struct irq_data *data)
>>>
>>>        gpiochip_enable_irq(chip, offset);
>>>
>>> -     pmic_eic->reg[REG_IE] = 1;
>>> -     pmic_eic->reg[REG_TRIG] = 1;
>>> +     pmic_eic->reg[offset][REG_IE] = 1;
>>> +     pmic_eic->reg[offset][REG_TRIG] = 1;
>>>    }
>>>
>>>    static int sprd_pmic_eic_irq_set_type(struct irq_data *data,
>>> @@ -174,13 +174,14 @@ static int sprd_pmic_eic_irq_set_type(struct irq_data *data,
>>>    {
>>>        struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
>>>        struct sprd_pmic_eic *pmic_eic = gpiochip_get_data(chip);
>>> +     u32 offset = irqd_to_hwirq(data);
>>>
>>>        switch (flow_type) {
>>>        case IRQ_TYPE_LEVEL_HIGH:
>>> -             pmic_eic->reg[REG_IEV] = 1;
>>> +             pmic_eic->reg[offset][REG_IEV] = 1;
>>>                break;
>>>        case IRQ_TYPE_LEVEL_LOW:
>>> -             pmic_eic->reg[REG_IEV] = 0;
>>> +             pmic_eic->reg[offset][REG_IEV] = 0;
>>>                break;
>>>        case IRQ_TYPE_EDGE_RISING:
>>>        case IRQ_TYPE_EDGE_FALLING:
>>> @@ -222,15 +223,15 @@ static void sprd_pmic_eic_bus_sync_unlock(struct irq_data *data)
>>>                        sprd_pmic_eic_update(chip, offset, SPRD_PMIC_EIC_IEV, 1);
>>>        } else {
>>>                sprd_pmic_eic_update(chip, offset, SPRD_PMIC_EIC_IEV,
>>> -                                  pmic_eic->reg[REG_IEV]);
>>> +                                  pmic_eic->reg[offset][REG_IEV]);
>>>        }
>>>
>>>        /* Set irq unmask */
>>>        sprd_pmic_eic_update(chip, offset, SPRD_PMIC_EIC_IE,
>>> -                          pmic_eic->reg[REG_IE]);
>>> +                          pmic_eic->reg[offset][REG_IE]);
>>>        /* Generate trigger start pulse for debounce EIC */
>>>        sprd_pmic_eic_update(chip, offset, SPRD_PMIC_EIC_TRIG,
>>> -                          pmic_eic->reg[REG_TRIG]);
>>> +                          pmic_eic->reg[offset][REG_TRIG]);
>>>
>>>        mutex_unlock(&pmic_eic->buslock);
>>>    }

  reply	other threads:[~2023-09-27  9:49 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-21 12:25 [PATCH V2 0/2] gpio: pmic-eic-sprd: Modification of UNISOC Platform PMIC EIC Driver Wenhua Lin
2023-09-21 12:25 ` [PATCH V2 1/2] gpio: pmic-eic-sprd: Two-dimensional arrays maintain pmic eic Wenhua Lin
2023-09-27  7:21   ` Bartosz Golaszewski
2023-09-27  9:04   ` Baolin Wang
2023-09-27  9:24     ` Chunyan Zhang
2023-09-27  9:49       ` Baolin Wang [this message]
2023-09-28  9:00   ` Chunyan Zhang
2024-01-02  7:29     ` wenhua lin
2023-09-21 12:25 ` [PATCH V2 2/2] gpio: pmic-eic-sprd: Add can_sleep flag for PMIC EIC chip Wenhua Lin
2023-09-21 15:39   ` Andy Shevchenko
2023-09-27  7:13     ` Bartosz Golaszewski
2023-09-27  9:05   ` Baolin Wang

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=99dc2f99-cb03-bec8-b538-3ad21750adff@linux.alibaba.com \
    --to=baolin.wang@linux.alibaba.com \
    --cc=Wenhua.Lin@unisoc.com \
    --cc=andy@kernel.org \
    --cc=brgl@bgdev.pl \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=orsonzhai@gmail.com \
    --cc=wenhua.lin1994@gmail.com \
    --cc=xiongpeng.wu@unisoc.com \
    --cc=zhang.lyra@gmail.com \
    /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

all inboxes | Powered by JetHome®