Skip to content

Commit b28f95c

Browse files
bijudasbebarino
authored andcommitted
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Stephen Boyd <[email protected]>
1 parent ebcae17 commit b28f95c

File tree

1 file changed

+15
-36
lines changed

1 file changed

+15
-36
lines changed

drivers/clk/clk-si544.c

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,11 @@
5656
#define DELTA_M_FRAC_NUM 19
5757
#define DELTA_M_FRAC_DEN 20000
5858

59-
enum si544_speed_grade {
60-
si544a,
61-
si544b,
62-
si544c,
63-
};
64-
6559
struct clk_si544 {
6660
struct clk_hw hw;
6761
struct regmap *regmap;
6862
struct i2c_client *i2c_client;
69-
enum si544_speed_grade speed_grade;
63+
unsigned long max_freq;
7064
};
7165
#define to_clk_si544(_hw) container_of(_hw, struct clk_si544, hw)
7266

@@ -196,24 +190,10 @@ static int si544_set_muldiv(struct clk_si544 *data,
196190
static bool is_valid_frequency(const struct clk_si544 *data,
197191
unsigned long frequency)
198192
{
199-
unsigned long max_freq = 0;
200-
201193
if (frequency < SI544_MIN_FREQ)
202194
return false;
203195

204-
switch (data->speed_grade) {
205-
case si544a:
206-
max_freq = 1500000000;
207-
break;
208-
case si544b:
209-
max_freq = 800000000;
210-
break;
211-
case si544c:
212-
max_freq = 350000000;
213-
break;
214-
}
215-
216-
return frequency <= max_freq;
196+
return frequency <= data->max_freq;
217197
}
218198

219199
/* Calculate divider settings for a given frequency */
@@ -451,19 +431,10 @@ static const struct regmap_config si544_regmap_config = {
451431
.volatile_reg = si544_regmap_is_volatile,
452432
};
453433

454-
static const struct i2c_device_id si544_id[] = {
455-
{ "si544a", si544a },
456-
{ "si544b", si544b },
457-
{ "si544c", si544c },
458-
{ }
459-
};
460-
MODULE_DEVICE_TABLE(i2c, si544_id);
461-
462434
static int si544_probe(struct i2c_client *client)
463435
{
464436
struct clk_si544 *data;
465437
struct clk_init_data init;
466-
const struct i2c_device_id *id = i2c_match_id(si544_id, client);
467438
int err;
468439

469440
data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
@@ -475,7 +446,7 @@ static int si544_probe(struct i2c_client *client)
475446
init.num_parents = 0;
476447
data->hw.init = &init;
477448
data->i2c_client = client;
478-
data->speed_grade = id->driver_data;
449+
data->max_freq = (uintptr_t)i2c_get_match_data(client);
479450

480451
if (of_property_read_string(client->dev.of_node, "clock-output-names",
481452
&init.name))
@@ -507,11 +478,19 @@ static int si544_probe(struct i2c_client *client)
507478
return 0;
508479
}
509480

481+
static const struct i2c_device_id si544_id[] = {
482+
{ "si544a", 1500000000 },
483+
{ "si544b", 800000000 },
484+
{ "si544c", 350000000 },
485+
{ }
486+
};
487+
MODULE_DEVICE_TABLE(i2c, si544_id);
488+
510489
static const struct of_device_id clk_si544_of_match[] = {
511-
{ .compatible = "silabs,si544a" },
512-
{ .compatible = "silabs,si544b" },
513-
{ .compatible = "silabs,si544c" },
514-
{ },
490+
{ .compatible = "silabs,si544a", .data = (void *)1500000000 },
491+
{ .compatible = "silabs,si544b", .data = (void *)800000000 },
492+
{ .compatible = "silabs,si544c", .data = (void *)350000000 },
493+
{ }
515494
};
516495
MODULE_DEVICE_TABLE(of, clk_si544_of_match);
517496

0 commit comments

Comments
 (0)