From mboxrd@z Thu Jan 1 00:00:00 1970 From: "H. Nikolaus Schaller" Subject: Re: [PATCH v5 5/7] gpio: pca953x: fix address calculation for pcal6524 Date: Wed, 2 May 2018 14:35:24 +0200 Message-ID: <4F016FCD-04B0-4EE1-A9F4-5A182DD437EF@goldelico.com> References: Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org To: Andy Shevchenko Cc: Kumar Gala , Rob Herring , Pawel Moll , Mark Rutland , Ian Campbell , Linus Walleij , Alexandre Courbot , devicetree , "open list:GPIO SUBSYSTEM" , Linux Kernel Mailing List , Discussions about the Letux Kernel , kernel@pyra-handheld.com List-Id: linux-gpio@vger.kernel.org Hi Andy, > Am 02.05.2018 um 14:28 schrieb Andy Shevchenko = : >=20 > On Sat, Apr 28, 2018 at 7:31 PM, H. Nikolaus Schaller = 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. >>=20 >> Now, the pcal6524 has 3 banks which means the relative offset >> is multiplied by 4 for the standard registers. >>=20 >> Simply applying the bit shift to the extended registers gives >> a wrong result, since the base offset is already included in >> the offset. >>=20 >> Therefore, we add code to the 24 bit accessor functions to >> adjust the register number for these exended registers. >>=20 >=20 > 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 >=20 >> Signed-off-by: H. Nikolaus Schaller >> --- >> drivers/gpio/gpio-pca953x.c | 8 ++++++-- >> 1 file changed, 6 insertions(+), 2 deletions(-) >>=20 >> 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 =3D fls((chip->gpio_chip.ngpio - 1) / BANK_SZ); >> + int addr =3D (reg & PCAL_GPIO_MASK) << bank_shift; >> + int pinctrl =3D (reg & PCAL_PINCTRL_MASK) << 1; >>=20 >> return i2c_smbus_write_i2c_block_data(chip->client, >> - (reg << bank_shift) | = REG_ADDR_AI, >> + pinctrl | addr | = REG_ADDR_AI, >> NBANK(chip), val); >> } >>=20 >> @@ -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 =3D fls((chip->gpio_chip.ngpio - 1) / BANK_SZ); >> + int addr =3D (reg & PCAL_GPIO_MASK) << bank_shift; >> + int pinctrl =3D (reg & PCAL_PINCTRL_MASK) << 1; >>=20 >> return i2c_smbus_read_i2c_block_data(chip->client, >> - (reg << bank_shift) | = REG_ADDR_AI, >> + pinctrl | addr | = REG_ADDR_AI, >> NBANK(chip), val); >> } >>=20 >> -- >> 2.12.2 >>=20 >=20 >=20 >=20 > --=20 > With Best Regards, > Andy Shevchenko