Skip to content

Commit 15f5e2e

Browse files
bijudasbebarino
authored andcommitted
clk: si570: Simplify probe
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 adding struct clk_si570_info as match data instead of clk_si570_variant and replace the ID lookup table for the match data by i2c_get_match_data(). This allows to simplify probe(). Drop enum clk_si570_variant 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 f234f02 commit 15f5e2e

File tree

1 file changed

+38
-29
lines changed

1 file changed

+38
-29
lines changed

drivers/clk/clk-si570.c

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,22 @@
4949

5050
#define SI570_FREEZE_DCO (1 << 4)
5151

52+
/**
53+
* struct clk_si570_info:
54+
* @max_freq: Maximum frequency for this device
55+
* @has_temperature_stability: Device support temperature stability
56+
*/
57+
struct clk_si570_info {
58+
u64 max_freq;
59+
bool has_temperature_stability;
60+
};
61+
5262
/**
5363
* struct clk_si570:
5464
* @hw: Clock hw struct
5565
* @regmap: Device's regmap
5666
* @div_offset: Rgister offset for dividers
57-
* @max_freq: Maximum frequency for this device
67+
* @info: Device info
5868
* @fxtal: Factory xtal frequency
5969
* @n1: Clock divider N1
6070
* @hs_div: Clock divider HSDIV
@@ -66,7 +76,7 @@ struct clk_si570 {
6676
struct clk_hw hw;
6777
struct regmap *regmap;
6878
unsigned int div_offset;
69-
u64 max_freq;
79+
const struct clk_si570_info *info;
7080
u64 fxtal;
7181
unsigned int n1;
7282
unsigned int hs_div;
@@ -76,11 +86,6 @@ struct clk_si570 {
7686
};
7787
#define to_clk_si570(_hw) container_of(_hw, struct clk_si570, hw)
7888

79-
enum clk_si570_variant {
80-
si57x,
81-
si59x
82-
};
83-
8489
/**
8590
* si570_get_divs() - Read clock dividers from HW
8691
* @data: Pointer to struct clk_si570
@@ -341,7 +346,7 @@ static int si570_set_rate(struct clk_hw *hw, unsigned long rate,
341346
struct i2c_client *client = data->i2c_client;
342347
int err;
343348

344-
if (rate < SI570_MIN_FREQ || rate > data->max_freq) {
349+
if (rate < SI570_MIN_FREQ || rate > data->info->max_freq) {
345350
dev_err(&client->dev,
346351
"requested frequency %lu Hz is out of range\n", rate);
347352
return -EINVAL;
@@ -398,24 +403,13 @@ static const struct regmap_config si570_regmap_config = {
398403
.volatile_reg = si570_regmap_is_volatile,
399404
};
400405

401-
static const struct i2c_device_id si570_id[] = {
402-
{ "si570", si57x },
403-
{ "si571", si57x },
404-
{ "si598", si59x },
405-
{ "si599", si59x },
406-
{ }
407-
};
408-
MODULE_DEVICE_TABLE(i2c, si570_id);
409-
410406
static int si570_probe(struct i2c_client *client)
411407
{
412408
struct clk_si570 *data;
413409
struct clk_init_data init;
414-
const struct i2c_device_id *id = i2c_match_id(si570_id, client);
415410
u32 initial_fout, factory_fout, stability;
416411
bool skip_recall;
417412
int err;
418-
enum clk_si570_variant variant = id->driver_data;
419413

420414
data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
421415
if (!data)
@@ -427,7 +421,8 @@ static int si570_probe(struct i2c_client *client)
427421
data->hw.init = &init;
428422
data->i2c_client = client;
429423

430-
if (variant == si57x) {
424+
data->info = i2c_get_match_data(client);
425+
if (data->info->has_temperature_stability) {
431426
err = of_property_read_u32(client->dev.of_node,
432427
"temperature-stability", &stability);
433428
if (err) {
@@ -438,10 +433,6 @@ static int si570_probe(struct i2c_client *client)
438433
/* adjust register offsets for 7ppm devices */
439434
if (stability == 7)
440435
data->div_offset = SI570_DIV_OFFSET_7PPM;
441-
442-
data->max_freq = SI570_MAX_FREQ;
443-
} else {
444-
data->max_freq = SI598_MAX_FREQ;
445436
}
446437

447438
if (of_property_read_string(client->dev.of_node, "clock-output-names",
@@ -496,12 +487,30 @@ static int si570_probe(struct i2c_client *client)
496487
return 0;
497488
}
498489

490+
static const struct clk_si570_info clk_si570_info = {
491+
.max_freq = SI570_MAX_FREQ,
492+
.has_temperature_stability = true,
493+
};
494+
495+
static const struct clk_si570_info clk_si590_info = {
496+
.max_freq = SI598_MAX_FREQ,
497+
};
498+
499+
static const struct i2c_device_id si570_id[] = {
500+
{ "si570", (kernel_ulong_t)&clk_si570_info },
501+
{ "si571", (kernel_ulong_t)&clk_si570_info },
502+
{ "si598", (kernel_ulong_t)&clk_si590_info },
503+
{ "si599", (kernel_ulong_t)&clk_si590_info },
504+
{ }
505+
};
506+
MODULE_DEVICE_TABLE(i2c, si570_id);
507+
499508
static const struct of_device_id clk_si570_of_match[] = {
500-
{ .compatible = "silabs,si570" },
501-
{ .compatible = "silabs,si571" },
502-
{ .compatible = "silabs,si598" },
503-
{ .compatible = "silabs,si599" },
504-
{ },
509+
{ .compatible = "silabs,si570", .data = &clk_si570_info },
510+
{ .compatible = "silabs,si571", .data = &clk_si570_info },
511+
{ .compatible = "silabs,si598", .data = &clk_si590_info },
512+
{ .compatible = "silabs,si599", .data = &clk_si590_info },
513+
{ }
505514
};
506515
MODULE_DEVICE_TABLE(of, clk_si570_of_match);
507516

0 commit comments

Comments
 (0)