All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marek Vasut <marek.vasut@gmail.com>
To: linux-gpio@vger.kernel.org
Cc: linux-renesas-soc@vger.kernel.org,
	Marek Vasut <marek.vasut+renesas@gmail.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>
Subject: [PATCH 06/14] gpio: pca953x: Unify pca953x_{read,write}_regs_{8,mul}()
Date: Sun,  2 Dec 2018 20:35:45 +0100	[thread overview]
Message-ID: <20181202193553.29704-6-marek.vasut+renesas@gmail.com> (raw)
In-Reply-To: <20181202193553.29704-1-marek.vasut+renesas@gmail.com>

At this point, the pca953x_{read,write}_regs_mul() can read single bank
PCA953x GPIO chips as well. Merge the _8 and _mul functions together to
simplify the code a bit.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 drivers/gpio/gpio-pca953x.c | 54 ++++++-------------------------------
 1 file changed, 8 insertions(+), 46 deletions(-)

diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index 551fa69661b2..09fd8cde9ca9 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -154,9 +154,6 @@ struct pca953x_chip {
 	struct regulator *regulator;
 
 	const struct pca953x_reg_config *regs;
-
-	int (*write_regs)(struct pca953x_chip *, int, u8 *);
-	int (*read_regs)(struct pca953x_chip *, int, u8 *);
 };
 
 static int pca953x_bank_shift(struct pca953x_chip *chip)
@@ -201,17 +198,13 @@ static int pca953x_write_single(struct pca953x_chip *chip, int reg, u32 val,
 	return 0;
 }
 
-static int pca953x_write_regs_8(struct pca953x_chip *chip, int reg, u8 *val)
-{
-	return i2c_smbus_write_byte_data(chip->client, reg, *val);
-}
-
-static int pca953x_write_regs_mul(struct pca953x_chip *chip, int reg, u8 *val)
+static int pca953x_write_regs(struct pca953x_chip *chip, int reg, u8 *val)
 {
 	int bank_shift = pca953x_bank_shift(chip);
 	int addr = (reg & PCAL_GPIO_MASK) << bank_shift;
 	int pinctrl = (reg & PCAL_PINCTRL_MASK) << 1;
 	u8 regaddr = pinctrl | addr;
+	int ret;
 
 	/* Chips with 24 and more GPIOs always support Auto Increment */
 	if (NBANK(chip) > 2)
@@ -221,15 +214,8 @@ static int pca953x_write_regs_mul(struct pca953x_chip *chip, int reg, u8 *val)
 	if (PCA_CHIP_TYPE(chip->driver_data) == PCA957X_TYPE)
 		regaddr |= REG_ADDR_AI;
 
-	return i2c_smbus_write_i2c_block_data(chip->client, regaddr,
-					      NBANK(chip), val);
-}
-
-static int pca953x_write_regs(struct pca953x_chip *chip, int reg, u8 *val)
-{
-	int ret = 0;
-
-	ret = chip->write_regs(chip, reg, val);
+	ret = i2c_smbus_write_i2c_block_data(chip->client, regaddr,
+					     NBANK(chip), val);
 	if (ret < 0) {
 		dev_err(&chip->client->dev, "failed writing register\n");
 		return ret;
@@ -238,36 +224,20 @@ static int pca953x_write_regs(struct pca953x_chip *chip, int reg, u8 *val)
 	return 0;
 }
 
-static int pca953x_read_regs_8(struct pca953x_chip *chip, int reg, u8 *val)
-{
-	int ret;
-
-	ret = i2c_smbus_read_byte_data(chip->client, reg);
-	*val = ret;
-
-	return ret;
-}
-
-static int pca953x_read_regs_mul(struct pca953x_chip *chip, int reg, u8 *val)
+static int pca953x_read_regs(struct pca953x_chip *chip, int reg, u8 *val)
 {
 	int bank_shift = pca953x_bank_shift(chip);
 	int addr = (reg & PCAL_GPIO_MASK) << bank_shift;
 	int pinctrl = (reg & PCAL_PINCTRL_MASK) << 1;
 	u8 regaddr = pinctrl | addr;
+	int ret;
 
 	/* Chips with 24 and more GPIOs always support Auto Increment */
 	if (NBANK(chip) > 2)
 		regaddr |= REG_ADDR_AI;
 
-	return i2c_smbus_read_i2c_block_data(chip->client, regaddr,
-					     NBANK(chip), val);
-}
-
-static int pca953x_read_regs(struct pca953x_chip *chip, int reg, u8 *val)
-{
-	int ret;
-
-	ret = chip->read_regs(chip, reg, val);
+	ret = i2c_smbus_read_i2c_block_data(chip->client, regaddr,
+					    NBANK(chip), val);
 	if (ret < 0) {
 		dev_err(&chip->client->dev, "failed reading register\n");
 		return ret;
@@ -872,14 +842,6 @@ static int pca953x_probe(struct i2c_client *client,
 	 */
 	pca953x_setup_gpio(chip, chip->driver_data & PCA_GPIO_MASK);
 
-	if (chip->gpio_chip.ngpio <= 8) {
-		chip->write_regs = pca953x_write_regs_8;
-		chip->read_regs = pca953x_read_regs_8;
-	} else {
-		chip->write_regs = pca953x_write_regs_mul;
-		chip->read_regs = pca953x_read_regs_mul;
-	}
-
 	if (PCA_CHIP_TYPE(chip->driver_data) == PCA953X_TYPE)
 		ret = device_pca953x_init(chip, invert);
 	else
-- 
2.18.0

  parent reply	other threads:[~2018-12-02 19:36 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-02 19:35 [PATCH 01/14] gpio: pca953x: Deduplicate the bank_size Marek Vasut
2018-12-02 19:35 ` [PATCH 02/14] gpio: pca953x: Fix AI overflow on PCAL6524 Marek Vasut
2018-12-03  9:37   ` Bartosz Golaszewski
2018-12-02 19:35 ` [PATCH 03/14] gpio: pca953x: Repair multi-byte IO address increment on PCA9575 Marek Vasut
2018-12-03 10:09   ` Geert Uytterhoeven
2018-12-02 19:35 ` [PATCH 04/14] gpio: pca953x: Unify pca95{3,7}x_write_regs_16() Marek Vasut
2018-12-02 19:35 ` [PATCH 05/14] gpio: pca953x: Unify pca953x_{read,write}_regs_{16,24}() Marek Vasut
2018-12-02 19:35 ` Marek Vasut [this message]
2018-12-02 19:35 ` [PATCH 07/14] gpio: pca953x: Factor out common code from device_pca95xx_init() Marek Vasut
2018-12-02 19:35 ` [PATCH 08/14] gpio: pca953x: Zap ad-hoc I2C block write in multi GPIO set Marek Vasut
2018-12-02 19:35 ` [PATCH 09/14] gpio: pca953x: Extract the register address mangling to single function Marek Vasut
2018-12-02 19:35 ` [PATCH 10/14] gpio: pca953x: Perform basic regmap conversion Marek Vasut
2018-12-02 19:35 ` [PATCH 11/14] gpio: pca953x: Zap ad-hoc reg_direction cache Marek Vasut
2018-12-02 19:35 ` [PATCH 12/14] gpio: pca953x: Zap ad-hoc reg_output cache Marek Vasut
2018-12-02 19:35 ` [PATCH 13/14] gpio: pca953x: Zap single use of pca953x_read_single() Marek Vasut
2018-12-02 19:35 ` [PATCH 14/14] gpio: pca953x: Restore registers after suspend/resume cycle Marek Vasut
2018-12-03 17:55   ` Geert Uytterhoeven
2018-12-03 21:42     ` Marek Vasut
2018-12-18 12:57     ` Geert Uytterhoeven
2018-12-18 13:43       ` Geert Uytterhoeven
2018-12-05 14:39   ` Geert Uytterhoeven
2018-12-05 14:45     ` Marek Vasut
2018-12-03  9:36 ` [PATCH 01/14] gpio: pca953x: Deduplicate the bank_size Bartosz Golaszewski
2018-12-03 11:00   ` Marek Vasut

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=20181202193553.29704-6-marek.vasut+renesas@gmail.com \
    --to=marek.vasut@gmail.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=marek.vasut+renesas@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 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.