* [PATCH] i2c: riic: Simplify unsupported bus speed handling
@ 2024-08-22 14:45 Geert Uytterhoeven
2024-08-22 16:01 ` claudiu beznea
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Geert Uytterhoeven @ 2024-08-22 14:45 UTC (permalink / raw)
To: Chris Brandt, Claudiu Beznea, Wolfram Sang, Andi Shyti
Cc: linux-i2c, linux-renesas-soc, Geert Uytterhoeven
Simplify checking for unsupported bus speeds and reporting errors by
factoring out the calculation of the maximum bus speed, and by using the
dev_err_probe() helper.
While at it, use "%u" for u32, and improve the error message.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
drivers/i2c/busses/i2c-riic.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/drivers/i2c/busses/i2c-riic.c b/drivers/i2c/busses/i2c-riic.c
index a6996f3c17110dd7..c7f3a4c02470238c 100644
--- a/drivers/i2c/busses/i2c-riic.c
+++ b/drivers/i2c/busses/i2c-riic.c
@@ -316,16 +316,13 @@ static int riic_init_hw(struct riic_dev *riic)
struct i2c_timings *t = &riic->i2c_t;
struct device *dev = riic->adapter.dev.parent;
bool fast_mode_plus = riic->info->fast_mode_plus;
+ u32 max_freq = fast_mode_plus ? I2C_MAX_FAST_MODE_PLUS_FREQ
+ : I2C_MAX_FAST_MODE_FREQ;
- if ((!fast_mode_plus && t->bus_freq_hz > I2C_MAX_FAST_MODE_FREQ) ||
- (fast_mode_plus && t->bus_freq_hz > I2C_MAX_FAST_MODE_PLUS_FREQ)) {
- dev_err(&riic->adapter.dev,
- "unsupported bus speed (%dHz). %d max\n",
- t->bus_freq_hz,
- fast_mode_plus ? I2C_MAX_FAST_MODE_PLUS_FREQ :
- I2C_MAX_FAST_MODE_FREQ);
- return -EINVAL;
- }
+ if (t->bus_freq_hz > max_freq)
+ return dev_err_probe(&riic->adapter.dev, -EINVAL,
+ "unsupported bus speed %uHz (%u max)\n",
+ t->bus_freq_hz, max_freq);
rate = clk_get_rate(riic->clk);
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] i2c: riic: Simplify unsupported bus speed handling
2024-08-22 14:45 [PATCH] i2c: riic: Simplify unsupported bus speed handling Geert Uytterhoeven
@ 2024-08-22 16:01 ` claudiu beznea
2024-08-23 0:47 ` Andi Shyti
2024-08-26 9:12 ` Wolfram Sang
2 siblings, 0 replies; 4+ messages in thread
From: claudiu beznea @ 2024-08-22 16:01 UTC (permalink / raw)
To: Geert Uytterhoeven, Chris Brandt, Claudiu Beznea, Wolfram Sang,
Andi Shyti
Cc: linux-i2c, linux-renesas-soc
On 22.08.2024 17:45, Geert Uytterhoeven wrote:
> Simplify checking for unsupported bus speeds and reporting errors by
> factoring out the calculation of the maximum bus speed, and by using the
> dev_err_probe() helper.
>
> While at it, use "%u" for u32, and improve the error message.
>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Tested-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
> ---
> drivers/i2c/busses/i2c-riic.c | 15 ++++++---------
> 1 file changed, 6 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-riic.c b/drivers/i2c/busses/i2c-riic.c
> index a6996f3c17110dd7..c7f3a4c02470238c 100644
> --- a/drivers/i2c/busses/i2c-riic.c
> +++ b/drivers/i2c/busses/i2c-riic.c
> @@ -316,16 +316,13 @@ static int riic_init_hw(struct riic_dev *riic)
> struct i2c_timings *t = &riic->i2c_t;
> struct device *dev = riic->adapter.dev.parent;
> bool fast_mode_plus = riic->info->fast_mode_plus;
> + u32 max_freq = fast_mode_plus ? I2C_MAX_FAST_MODE_PLUS_FREQ
> + : I2C_MAX_FAST_MODE_FREQ;
>
> - if ((!fast_mode_plus && t->bus_freq_hz > I2C_MAX_FAST_MODE_FREQ) ||
> - (fast_mode_plus && t->bus_freq_hz > I2C_MAX_FAST_MODE_PLUS_FREQ)) {
> - dev_err(&riic->adapter.dev,
> - "unsupported bus speed (%dHz). %d max\n",
> - t->bus_freq_hz,
> - fast_mode_plus ? I2C_MAX_FAST_MODE_PLUS_FREQ :
> - I2C_MAX_FAST_MODE_FREQ);
> - return -EINVAL;
> - }
> + if (t->bus_freq_hz > max_freq)
> + return dev_err_probe(&riic->adapter.dev, -EINVAL,
> + "unsupported bus speed %uHz (%u max)\n",
> + t->bus_freq_hz, max_freq);
>
> rate = clk_get_rate(riic->clk);
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] i2c: riic: Simplify unsupported bus speed handling
2024-08-22 14:45 [PATCH] i2c: riic: Simplify unsupported bus speed handling Geert Uytterhoeven
2024-08-22 16:01 ` claudiu beznea
@ 2024-08-23 0:47 ` Andi Shyti
2024-08-26 9:12 ` Wolfram Sang
2 siblings, 0 replies; 4+ messages in thread
From: Andi Shyti @ 2024-08-23 0:47 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Chris Brandt, Claudiu Beznea, Wolfram Sang, linux-i2c,
linux-renesas-soc
Hi Geert,
On Thu, Aug 22, 2024 at 04:45:54PM GMT, Geert Uytterhoeven wrote:
> Simplify checking for unsupported bus speeds and reporting errors by
> factoring out the calculation of the maximum bus speed, and by using the
> dev_err_probe() helper.
>
> While at it, use "%u" for u32, and improve the error message.
>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Thanks for the cleanup, I missed the cleaner way during code
review :-)
Merged to i2c/i2c-host.
Andi
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] i2c: riic: Simplify unsupported bus speed handling
2024-08-22 14:45 [PATCH] i2c: riic: Simplify unsupported bus speed handling Geert Uytterhoeven
2024-08-22 16:01 ` claudiu beznea
2024-08-23 0:47 ` Andi Shyti
@ 2024-08-26 9:12 ` Wolfram Sang
2 siblings, 0 replies; 4+ messages in thread
From: Wolfram Sang @ 2024-08-26 9:12 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Chris Brandt, Claudiu Beznea, Andi Shyti, linux-i2c,
linux-renesas-soc
[-- Attachment #1: Type: text/plain, Size: 455 bytes --]
On Thu, Aug 22, 2024 at 04:45:54PM +0200, Geert Uytterhoeven wrote:
> Simplify checking for unsupported bus speeds and reporting errors by
> factoring out the calculation of the maximum bus speed, and by using the
> dev_err_probe() helper.
>
> While at it, use "%u" for u32, and improve the error message.
>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Nice!
Reviewed-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-08-26 9:12 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-22 14:45 [PATCH] i2c: riic: Simplify unsupported bus speed handling Geert Uytterhoeven
2024-08-22 16:01 ` claudiu beznea
2024-08-23 0:47 ` Andi Shyti
2024-08-26 9:12 ` Wolfram Sang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox