* [PATCH 1/2] pinctrl: cy8c95x0: Use cleanup.h
@ 2024-06-26 8:45 Patrick Rudolph
2024-06-26 8:45 ` [PATCH 2/2] pinctrl: cy8c95x0: Update cache modification Patrick Rudolph
2024-07-03 11:14 ` [PATCH 1/2] pinctrl: cy8c95x0: Use cleanup.h Linus Walleij
0 siblings, 2 replies; 4+ messages in thread
From: Patrick Rudolph @ 2024-06-26 8:45 UTC (permalink / raw)
To: Patrick Rudolph, Linus Walleij
Cc: naresh.solanki, andy.shevchenko, broonie, linux-gpio,
linux-kernel
Use the guard mutex from cleanup.h to make the code more readable.
Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
---
drivers/pinctrl/pinctrl-cy8c95x0.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/drivers/pinctrl/pinctrl-cy8c95x0.c b/drivers/pinctrl/pinctrl-cy8c95x0.c
index 4efb8b5cc2d3..781949e0e09e 100644
--- a/drivers/pinctrl/pinctrl-cy8c95x0.c
+++ b/drivers/pinctrl/pinctrl-cy8c95x0.c
@@ -9,6 +9,7 @@
#include <linux/acpi.h>
#include <linux/bitmap.h>
+#include <linux/cleanup.h>
#include <linux/dmi.h>
#include <linux/gpio/driver.h>
#include <linux/gpio/consumer.h>
@@ -480,8 +481,6 @@ static inline int cy8c95x0_regmap_update_bits_base(struct cy8c95x0_pinctrl *chip
if (reg == CY8C95X0_PORTSEL)
return -EINVAL;
- mutex_lock(&chip->i2c_lock);
-
/* Registers behind the PORTSEL mux have their own range in regmap */
if (cy8c95x0_muxed_register(reg)) {
off = CY8C95X0_MUX_REGMAP_TO_OFFSET(reg, port);
@@ -492,10 +491,11 @@ static inline int cy8c95x0_regmap_update_bits_base(struct cy8c95x0_pinctrl *chip
else
off = reg;
}
+ guard(mutex)(&chip->i2c_lock);
ret = regmap_update_bits_base(chip->regmap, off, mask, val, change, async, force);
if (ret < 0)
- goto out;
+ return ret;
/* Update the cache when a WC bit is written */
if (cy8c95x0_wc_register(reg) && (mask & val)) {
@@ -516,8 +516,6 @@ static inline int cy8c95x0_regmap_update_bits_base(struct cy8c95x0_pinctrl *chip
regcache_cache_only(chip->regmap, false);
}
}
-out:
- mutex_unlock(&chip->i2c_lock);
return ret;
}
@@ -591,8 +589,6 @@ static int cy8c95x0_regmap_read(struct cy8c95x0_pinctrl *chip, unsigned int reg,
{
int off, ret;
- mutex_lock(&chip->i2c_lock);
-
/* Registers behind the PORTSEL mux have their own range in regmap */
if (cy8c95x0_muxed_register(reg)) {
off = CY8C95X0_MUX_REGMAP_TO_OFFSET(reg, port);
@@ -603,11 +599,10 @@ static int cy8c95x0_regmap_read(struct cy8c95x0_pinctrl *chip, unsigned int reg,
else
off = reg;
}
+ guard(mutex)(&chip->i2c_lock);
ret = regmap_read(chip->regmap, off, read_val);
- mutex_unlock(&chip->i2c_lock);
-
return ret;
}
--
2.44.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 2/2] pinctrl: cy8c95x0: Update cache modification
2024-06-26 8:45 [PATCH 1/2] pinctrl: cy8c95x0: Use cleanup.h Patrick Rudolph
@ 2024-06-26 8:45 ` Patrick Rudolph
2024-07-03 11:15 ` Linus Walleij
2024-07-03 11:14 ` [PATCH 1/2] pinctrl: cy8c95x0: Use cleanup.h Linus Walleij
1 sibling, 1 reply; 4+ messages in thread
From: Patrick Rudolph @ 2024-06-26 8:45 UTC (permalink / raw)
To: Patrick Rudolph, Linus Walleij
Cc: naresh.solanki, andy.shevchenko, broonie, linux-gpio,
linux-kernel
In the previous review cycle the regmap cache update code was
questioned since it seems and odd way of using regmap_update_bits().
Thus update the regmap cache modification code to better explain
what it does and why it's done. This is no functional change, but
it's improving code maintainability.
Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
---
drivers/pinctrl/pinctrl-cy8c95x0.c | 22 +++++++++-------------
1 file changed, 9 insertions(+), 13 deletions(-)
diff --git a/drivers/pinctrl/pinctrl-cy8c95x0.c b/drivers/pinctrl/pinctrl-cy8c95x0.c
index 781949e0e09e..9a92707d2525 100644
--- a/drivers/pinctrl/pinctrl-cy8c95x0.c
+++ b/drivers/pinctrl/pinctrl-cy8c95x0.c
@@ -475,7 +475,7 @@ static inline int cy8c95x0_regmap_update_bits_base(struct cy8c95x0_pinctrl *chip
bool *change, bool async,
bool force)
{
- int ret, off, i, read_val;
+ int ret, off, i;
/* Caller should never modify PORTSEL directly */
if (reg == CY8C95X0_PORTSEL)
@@ -497,24 +497,20 @@ static inline int cy8c95x0_regmap_update_bits_base(struct cy8c95x0_pinctrl *chip
if (ret < 0)
return ret;
- /* Update the cache when a WC bit is written */
+ /* Mimic what hardware does and update the cache when a WC bit is written.
+ * Allows to mark the registers as non-volatile and reduces I/O cycles.
+ */
if (cy8c95x0_wc_register(reg) && (mask & val)) {
+ /* Writing a 1 clears set bits in the other drive mode registers */
+ regcache_cache_only(chip->regmap, true);
for (i = CY8C95X0_DRV_PU; i <= CY8C95X0_DRV_HIZ; i++) {
if (i == reg)
continue;
- off = CY8C95X0_MUX_REGMAP_TO_OFFSET(i, port);
-
- ret = regmap_read(chip->regmap, off, &read_val);
- if (ret < 0)
- continue;
- if (!(read_val & mask & val))
- continue;
-
- regcache_cache_only(chip->regmap, true);
- regmap_update_bits(chip->regmap, off, mask & val, 0);
- regcache_cache_only(chip->regmap, false);
+ off = CY8C95X0_MUX_REGMAP_TO_OFFSET(i, port);
+ regmap_clear_bits(chip->regmap, off, mask & val);
}
+ regcache_cache_only(chip->regmap, false);
}
return ret;
--
2.44.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH 2/2] pinctrl: cy8c95x0: Update cache modification
2024-06-26 8:45 ` [PATCH 2/2] pinctrl: cy8c95x0: Update cache modification Patrick Rudolph
@ 2024-07-03 11:15 ` Linus Walleij
0 siblings, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2024-07-03 11:15 UTC (permalink / raw)
To: Patrick Rudolph
Cc: naresh.solanki, andy.shevchenko, broonie, linux-gpio,
linux-kernel
On Wed, Jun 26, 2024 at 10:45 AM Patrick Rudolph
<patrick.rudolph@9elements.com> wrote:
> In the previous review cycle the regmap cache update code was
> questioned since it seems and odd way of using regmap_update_bits().
> Thus update the regmap cache modification code to better explain
> what it does and why it's done. This is no functional change, but
> it's improving code maintainability.
>
> Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
Patch applied.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] pinctrl: cy8c95x0: Use cleanup.h
2024-06-26 8:45 [PATCH 1/2] pinctrl: cy8c95x0: Use cleanup.h Patrick Rudolph
2024-06-26 8:45 ` [PATCH 2/2] pinctrl: cy8c95x0: Update cache modification Patrick Rudolph
@ 2024-07-03 11:14 ` Linus Walleij
1 sibling, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2024-07-03 11:14 UTC (permalink / raw)
To: Patrick Rudolph
Cc: naresh.solanki, andy.shevchenko, broonie, linux-gpio,
linux-kernel
On Wed, Jun 26, 2024 at 10:45 AM Patrick Rudolph
<patrick.rudolph@9elements.com> wrote:
> Use the guard mutex from cleanup.h to make the code more readable.
>
> Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
Patch applied.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-07-03 11:15 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-26 8:45 [PATCH 1/2] pinctrl: cy8c95x0: Use cleanup.h Patrick Rudolph
2024-06-26 8:45 ` [PATCH 2/2] pinctrl: cy8c95x0: Update cache modification Patrick Rudolph
2024-07-03 11:15 ` Linus Walleij
2024-07-03 11:14 ` [PATCH 1/2] pinctrl: cy8c95x0: Use cleanup.h Linus Walleij
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).