All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [PATCH v7 1/2] gpio: i2c-gpio: Drop use of dm_gpio_set_dir()
Date: Tue, 23 Mar 2021 14:52:06 +1300	[thread overview]
Message-ID: <20210323145145.v7.1.I1fce8ee9237ecc894504e2c22e7069dc6acc9e8c@changeid> (raw)
In-Reply-To: <20210323015207.3230029-1-sjg@chromium.org>

This is the only driver that uses this function. Update it to use the
alternative which is dm_gpio_clrset_flags().

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Harm Berntsen <harm.berntsen@nedap.com>
---

Changes in v7:
- Update commit message to mention dm_gpio_clrset_flags()

Changes in v6:
- Use dm_gpio_clrset_flags() so that direction can be changed
- Simplify the code since masking is not needed

 drivers/i2c/i2c-gpio.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/i2c/i2c-gpio.c b/drivers/i2c/i2c-gpio.c
index a301a4460b3..cf8f8f40359 100644
--- a/drivers/i2c/i2c-gpio.c
+++ b/drivers/i2c/i2c-gpio.c
@@ -48,12 +48,13 @@ static int i2c_gpio_sda_get(struct i2c_gpio_bus *bus)
 static void i2c_gpio_sda_set(struct i2c_gpio_bus *bus, int bit)
 {
 	struct gpio_desc *sda = &bus->gpios[PIN_SDA];
+	ulong flags;
 
 	if (bit)
-		sda->flags = (sda->flags & ~GPIOD_IS_OUT) | GPIOD_IS_IN;
+		flags = GPIOD_IS_IN;
 	else
-		sda->flags = (sda->flags & (~GPIOD_IS_IN & ~GPIOD_IS_OUT_ACTIVE)) | GPIOD_IS_OUT;
-	dm_gpio_set_dir(sda);
+		flags = GPIOD_IS_OUT;
+	dm_gpio_clrset_flags(sda, GPIOD_MASK_DIR, flags);
 }
 
 static void i2c_gpio_scl_set(struct i2c_gpio_bus *bus, int bit)
@@ -62,16 +63,14 @@ static void i2c_gpio_scl_set(struct i2c_gpio_bus *bus, int bit)
 	int count = 0;
 
 	if (bit) {
-		scl->flags = (scl->flags & ~GPIOD_IS_OUT) | GPIOD_IS_IN;
-		dm_gpio_set_dir(scl);
+		dm_gpio_clrset_flags(scl, GPIOD_MASK_DIR, GPIOD_IS_IN);
 		while (!dm_gpio_get_value(scl) && count++ < 100000)
 			udelay(1);
 
 		if (!dm_gpio_get_value(scl))
 			pr_err("timeout waiting on slave to release scl\n");
 	} else {
-		scl->flags = (scl->flags & (~GPIOD_IS_IN & ~GPIOD_IS_OUT_ACTIVE)) | GPIOD_IS_OUT;
-		dm_gpio_set_dir(scl);
+		dm_gpio_clrset_flags(scl, GPIOD_MASK_DIR, GPIOD_IS_OUT);
 	}
 }
 
@@ -79,11 +78,11 @@ static void i2c_gpio_scl_set(struct i2c_gpio_bus *bus, int bit)
 static void i2c_gpio_scl_set_output_only(struct i2c_gpio_bus *bus, int bit)
 {
 	struct gpio_desc *scl = &bus->gpios[PIN_SCL];
-	scl->flags = (scl->flags & (~GPIOD_IS_IN & ~GPIOD_IS_OUT_ACTIVE)) | GPIOD_IS_OUT;
+	ulong flags = GPIOD_IS_OUT;
 
 	if (bit)
-		scl->flags |= GPIOD_IS_OUT_ACTIVE;
-	dm_gpio_set_dir(scl);
+		flags |= GPIOD_IS_OUT_ACTIVE;
+	dm_gpio_clrset_flags(scl, GPIOD_MASK_DIR, flags);
 }
 
 static void i2c_gpio_write_bit(struct i2c_gpio_bus *bus, int delay, uchar bit)
-- 
2.31.0.rc2.261.g7f71774620-goog

  reply	other threads:[~2021-03-23  1:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-23  1:52 [PATCH v7 0/2] gpio: Update and simplify the uclass API Simon Glass
2021-03-23  1:52 ` Simon Glass [this message]
2021-04-13 14:29   ` [PATCH v7 1/2] gpio: i2c-gpio: Drop use of dm_gpio_set_dir() Tom Rini
2021-03-23  1:52 ` [PATCH v7 2/2] gpio: Drop dm_gpio_set_dir() Simon Glass
2021-04-13 14:29   ` Tom Rini

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=20210323145145.v7.1.I1fce8ee9237ecc894504e2c22e7069dc6acc9e8c@changeid \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /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.