Skip to content

Commit 71dacb2

Browse files
geertuAndi Shyti
authored andcommitted
i2c: riic: Simplify unsupported bus speed handling
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 <[email protected]> Reviewed-by: Claudiu Beznea <[email protected]> Tested-by: Claudiu Beznea <[email protected]> Reviewed-by: Wolfram Sang <[email protected]> Signed-off-by: Andi Shyti <[email protected]>
1 parent bc07fb4 commit 71dacb2

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

drivers/i2c/busses/i2c-riic.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -316,16 +316,13 @@ static int riic_init_hw(struct riic_dev *riic)
316316
struct i2c_timings *t = &riic->i2c_t;
317317
struct device *dev = riic->adapter.dev.parent;
318318
bool fast_mode_plus = riic->info->fast_mode_plus;
319+
u32 max_freq = fast_mode_plus ? I2C_MAX_FAST_MODE_PLUS_FREQ
320+
: I2C_MAX_FAST_MODE_FREQ;
319321

320-
if ((!fast_mode_plus && t->bus_freq_hz > I2C_MAX_FAST_MODE_FREQ) ||
321-
(fast_mode_plus && t->bus_freq_hz > I2C_MAX_FAST_MODE_PLUS_FREQ)) {
322-
dev_err(&riic->adapter.dev,
323-
"unsupported bus speed (%dHz). %d max\n",
324-
t->bus_freq_hz,
325-
fast_mode_plus ? I2C_MAX_FAST_MODE_PLUS_FREQ :
326-
I2C_MAX_FAST_MODE_FREQ);
327-
return -EINVAL;
328-
}
322+
if (t->bus_freq_hz > max_freq)
323+
return dev_err_probe(&riic->adapter.dev, -EINVAL,
324+
"unsupported bus speed %uHz (%u max)\n",
325+
t->bus_freq_hz, max_freq);
329326

330327
rate = clk_get_rate(riic->clk);
331328

0 commit comments

Comments
 (0)