All of lore.kernel.org
 help / color / mirror / Atom feed
From: "H. Nikolaus Schaller" <hns@goldelico.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Kumar Gala <galak@codeaurora.org>,
	Rob Herring <robh+dt@kernel.org>, Pawel Moll <pawel.moll@arm.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Ian Campbell <ijc+devicetree@hellion.org.uk>,
	Linus Walleij <linus.walleij@linaro.org>,
	Alexandre Courbot <gnurou@gmail.com>,
	devicetree <devicetree@vger.kernel.org>,
	"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Discussions about the Letux Kernel <letux-kernel@openphoenux.org>,
	kernel@pyra-handheld.com
Subject: Re: [PATCH v5 5/7] gpio: pca953x: fix address calculation for pcal6524
Date: Wed, 2 May 2018 14:35:24 +0200	[thread overview]
Message-ID: <4F016FCD-04B0-4EE1-A9F4-5A182DD437EF@goldelico.com> (raw)
In-Reply-To: <CAHp75VfD4gYesEw2n4JMycmr=qcAtqSkAAjwCViJZRYC6kVUVg@mail.gmail.com>

Hi Andy,

> Am 02.05.2018 um 14:28 schrieb Andy Shevchenko <andy.shevchenko@gmail.com>:
> 
> On Sat, Apr 28, 2018 at 7:31 PM, H. Nikolaus Schaller <hns@goldelico.com> wrote:
>> The register constants are so far defined in a way that they fit
>> for the pcal9555a when shifted by the number of banks, i.e. are
>> multiplied by 2 in the accessor function.
>> 
>> Now, the pcal6524 has 3 banks which means the relative offset
>> is multiplied by 4 for the standard registers.
>> 
>> Simply applying the bit shift to the extended registers gives
>> a wrong result, since the base offset is already included in
>> the offset.
>> 
>> Therefore, we add code to the 24 bit accessor functions to
>> adjust the register number for these exended registers.
>> 
> 
> Suggested-by ?

Detecting that we need to adjust the registers generally was from me,
but your suggestion of an improved formula should of course be mentioned
and appreciated!

I'll think about a good formulation for v6.

BR and thanks,
Nikolaus

> 
>> Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com>
>> ---
>> drivers/gpio/gpio-pca953x.c | 8 ++++++--
>> 1 file changed, 6 insertions(+), 2 deletions(-)
>> 
>> diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
>> index fc863faa3ce4..4194495a7990 100644
>> --- a/drivers/gpio/gpio-pca953x.c
>> +++ b/drivers/gpio/gpio-pca953x.c
>> @@ -221,9 +221,11 @@ static int pca957x_write_regs_16(struct pca953x_chip *chip, int reg, u8 *val)
>> static int pca953x_write_regs_24(struct pca953x_chip *chip, int reg, u8 *val)
>> {
>>        int bank_shift = fls((chip->gpio_chip.ngpio - 1) / BANK_SZ);
>> +       int addr = (reg & PCAL_GPIO_MASK) << bank_shift;
>> +       int pinctrl = (reg & PCAL_PINCTRL_MASK) << 1;
>> 
>>        return i2c_smbus_write_i2c_block_data(chip->client,
>> -                                             (reg << bank_shift) | REG_ADDR_AI,
>> +                                             pinctrl | addr | REG_ADDR_AI,
>>                                              NBANK(chip), val);
>> }
>> 
>> @@ -263,9 +265,11 @@ static int pca953x_read_regs_16(struct pca953x_chip *chip, int reg, u8 *val)
>> static int pca953x_read_regs_24(struct pca953x_chip *chip, int reg, u8 *val)
>> {
>>        int bank_shift = fls((chip->gpio_chip.ngpio - 1) / BANK_SZ);
>> +       int addr = (reg & PCAL_GPIO_MASK) << bank_shift;
>> +       int pinctrl = (reg & PCAL_PINCTRL_MASK) << 1;
>> 
>>        return i2c_smbus_read_i2c_block_data(chip->client,
>> -                                            (reg << bank_shift) | REG_ADDR_AI,
>> +                                            pinctrl | addr | REG_ADDR_AI,
>>                                             NBANK(chip), val);
>> }
>> 
>> --
>> 2.12.2
>> 
> 
> 
> 
> -- 
> With Best Regards,
> Andy Shevchenko

  reply	other threads:[~2018-05-02 12:35 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-28 16:31 [PATCH v5 0/7] pcal6524 extensions and fixes for pca953x driver H. Nikolaus Schaller
2018-04-28 16:31 ` [PATCH v5 1/7] gpio: pca953x: convert register constants to hex H. Nikolaus Schaller
2018-05-16 11:49   ` Linus Walleij
2018-04-28 16:31 ` [PATCH v5 2/7] gpio: pca953x: add more register definitions for pcal953x H. Nikolaus Schaller
2018-05-16 11:51   ` Linus Walleij
2018-04-28 16:31 ` [PATCH v5 3/7] gpio: pca953x: add more register definitions for pcal6524 H. Nikolaus Schaller
2018-05-16 11:52   ` Linus Walleij
2018-04-28 16:31 ` [PATCH v5 4/7] gpio: pca953x: define masks for addressing common and extended registers H. Nikolaus Schaller
2018-05-02 12:29   ` Andy Shevchenko
2018-05-02 12:36     ` H. Nikolaus Schaller
2018-05-04  7:33       ` H. Nikolaus Schaller
2018-04-28 16:31 ` [PATCH v5 5/7] gpio: pca953x: fix address calculation for pcal6524 H. Nikolaus Schaller
2018-05-02 12:28   ` Andy Shevchenko
2018-05-02 12:35     ` H. Nikolaus Schaller [this message]
2018-05-04  7:30       ` H. Nikolaus Schaller
2018-05-05 10:29         ` Andy Shevchenko
2018-04-28 16:31 ` [PATCH v5 6/7] DTS: Bindings: pca953x add an optional vcc-supply property H. Nikolaus Schaller
2018-05-16 11:55   ` Linus Walleij
2018-04-28 16:31 ` [PATCH v5 7/7] DTS: Bindings: pca953x: add example how to use interrupt-controller and gpio-controller H. Nikolaus Schaller
2018-05-16 11:56   ` Linus Walleij
2018-05-02 11:53 ` [PATCH v5 0/7] pcal6524 extensions and fixes for pca953x driver Linus Walleij
2018-05-02 12:32 ` Andy Shevchenko
2018-05-16 11:53 ` Linus Walleij
2018-05-16 11:56   ` Linus Walleij
2018-05-16 13:32   ` H. Nikolaus Schaller
2018-05-16 14:31     ` Linus Walleij
2018-05-16 14:37       ` H. Nikolaus Schaller

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=4F016FCD-04B0-4EE1-A9F4-5A182DD437EF@goldelico.com \
    --to=hns@goldelico.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=galak@codeaurora.org \
    --cc=gnurou@gmail.com \
    --cc=ijc+devicetree@hellion.org.uk \
    --cc=kernel@pyra-handheld.com \
    --cc=letux-kernel@openphoenux.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=pawel.moll@arm.com \
    --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.