Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

clk: clk-si544: Simplify probe() and is_valid_frequency()

The driver has an OF match table, still, it uses an ID lookup table for
retrieving match data. Currently, the driver is working on the
assumption that an I2C device registered via OF will always match a
legacy I2C device ID. The correct approach is to have an OF device ID
table using i2c_get_match_data() if the devices are registered via OF/ID.

Unify the OF/ID table by using max_freq as match data instead of
enum si544_speed_grade and replace the ID lookup table for
the match data by i2c_get_match_data(). This allows to simplify both
probe() and is_valid_frequency().

Drop enum si544_speed_grade as there is no user.

While at it, remove the trailing comma in the terminator entry for the OF
table making code robust against (theoretical) misrebases or other similar
things where the new entry goes _after_ the termination without the
compiler noticing.

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
Link: https://lore.kernel.org/r/20230909155418.24426-1-biju.das.jz@bp.renesas.com
Signed-off-by: Stephen Boyd <sboyd@kernel.org>

authored by

Biju Das and committed by
Stephen Boyd
b28f95c6 ebcae17f

+15 -36
+15 -36
drivers/clk/clk-si544.c
··· 56 56 #define DELTA_M_FRAC_NUM 19 57 57 #define DELTA_M_FRAC_DEN 20000 58 58 59 - enum si544_speed_grade { 60 - si544a, 61 - si544b, 62 - si544c, 63 - }; 64 - 65 59 struct clk_si544 { 66 60 struct clk_hw hw; 67 61 struct regmap *regmap; 68 62 struct i2c_client *i2c_client; 69 - enum si544_speed_grade speed_grade; 63 + unsigned long max_freq; 70 64 }; 71 65 #define to_clk_si544(_hw) container_of(_hw, struct clk_si544, hw) 72 66 ··· 190 196 static bool is_valid_frequency(const struct clk_si544 *data, 191 197 unsigned long frequency) 192 198 { 193 - unsigned long max_freq = 0; 194 - 195 199 if (frequency < SI544_MIN_FREQ) 196 200 return false; 197 201 198 - switch (data->speed_grade) { 199 - case si544a: 200 - max_freq = 1500000000; 201 - break; 202 - case si544b: 203 - max_freq = 800000000; 204 - break; 205 - case si544c: 206 - max_freq = 350000000; 207 - break; 208 - } 209 - 210 - return frequency <= max_freq; 202 + return frequency <= data->max_freq; 211 203 } 212 204 213 205 /* Calculate divider settings for a given frequency */ ··· 431 451 .volatile_reg = si544_regmap_is_volatile, 432 452 }; 433 453 434 - static const struct i2c_device_id si544_id[] = { 435 - { "si544a", si544a }, 436 - { "si544b", si544b }, 437 - { "si544c", si544c }, 438 - { } 439 - }; 440 - MODULE_DEVICE_TABLE(i2c, si544_id); 441 - 442 454 static int si544_probe(struct i2c_client *client) 443 455 { 444 456 struct clk_si544 *data; 445 457 struct clk_init_data init; 446 - const struct i2c_device_id *id = i2c_match_id(si544_id, client); 447 458 int err; 448 459 449 460 data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); ··· 446 475 init.num_parents = 0; 447 476 data->hw.init = &init; 448 477 data->i2c_client = client; 449 - data->speed_grade = id->driver_data; 478 + data->max_freq = (uintptr_t)i2c_get_match_data(client); 450 479 451 480 if (of_property_read_string(client->dev.of_node, "clock-output-names", 452 481 &init.name)) ··· 478 507 return 0; 479 508 } 480 509 510 + static const struct i2c_device_id si544_id[] = { 511 + { "si544a", 1500000000 }, 512 + { "si544b", 800000000 }, 513 + { "si544c", 350000000 }, 514 + { } 515 + }; 516 + MODULE_DEVICE_TABLE(i2c, si544_id); 517 + 481 518 static const struct of_device_id clk_si544_of_match[] = { 482 - { .compatible = "silabs,si544a" }, 483 - { .compatible = "silabs,si544b" }, 484 - { .compatible = "silabs,si544c" }, 485 - { }, 519 + { .compatible = "silabs,si544a", .data = (void *)1500000000 }, 520 + { .compatible = "silabs,si544b", .data = (void *)800000000 }, 521 + { .compatible = "silabs,si544c", .data = (void *)350000000 }, 522 + { } 486 523 }; 487 524 MODULE_DEVICE_TABLE(of, clk_si544_of_match); 488 525