Commit 1c1b3098 authored by Marc Ferland's avatar Marc Ferland Committed by Alexandre Belloni

rtc: pcf85063: add i2c_device_id name matching support

The pcf85063 driver regsitration currently supports the "compatible"
property type of matching (for DT).

This patch adds "matching by name" support to the driver by defining
an i2c_device_id table and setting the id_table parameter in the
i2c_driver struct.

This will, for example, make the driver easier to instantiate on
systems where CONFIG_OF is not enabled (x86 in my case).
Signed-off-by: default avatarMarc Ferland <ferlandm@amotus.ca>
Reported-by: default avatarkernel test robot <lkp@intel.com>
Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20211116164733.17149-1-ferlandm@amotus.ca
parent f601aa79
...@@ -514,21 +514,56 @@ static struct clk *pcf85063_clkout_register_clk(struct pcf85063 *pcf85063) ...@@ -514,21 +514,56 @@ static struct clk *pcf85063_clkout_register_clk(struct pcf85063 *pcf85063)
} }
#endif #endif
static const struct pcf85063_config pcf85063tp_config = { enum pcf85063_type {
.regmap = { PCF85063,
.reg_bits = 8, PCF85063TP,
.val_bits = 8, PCF85063A,
.max_register = 0x0a, RV8263,
PCF85063_LAST_ID
};
static struct pcf85063_config pcf85063_cfg[] = {
[PCF85063] = {
.regmap = {
.reg_bits = 8,
.val_bits = 8,
.max_register = 0x0a,
},
},
[PCF85063TP] = {
.regmap = {
.reg_bits = 8,
.val_bits = 8,
.max_register = 0x0a,
},
},
[PCF85063A] = {
.regmap = {
.reg_bits = 8,
.val_bits = 8,
.max_register = 0x11,
},
.has_alarms = 1,
},
[RV8263] = {
.regmap = {
.reg_bits = 8,
.val_bits = 8,
.max_register = 0x11,
},
.has_alarms = 1,
.force_cap_7000 = 1,
}, },
}; };
static const struct i2c_device_id pcf85063_ids[];
static int pcf85063_probe(struct i2c_client *client) static int pcf85063_probe(struct i2c_client *client)
{ {
struct pcf85063 *pcf85063; struct pcf85063 *pcf85063;
unsigned int tmp; unsigned int tmp;
int err; int err;
const struct pcf85063_config *config = &pcf85063tp_config; const struct pcf85063_config *config;
const void *data = of_device_get_match_data(&client->dev);
struct nvmem_config nvmem_cfg = { struct nvmem_config nvmem_cfg = {
.name = "pcf85063_nvram", .name = "pcf85063_nvram",
.reg_read = pcf85063_nvmem_read, .reg_read = pcf85063_nvmem_read,
...@@ -544,8 +579,17 @@ static int pcf85063_probe(struct i2c_client *client) ...@@ -544,8 +579,17 @@ static int pcf85063_probe(struct i2c_client *client)
if (!pcf85063) if (!pcf85063)
return -ENOMEM; return -ENOMEM;
if (data) if (client->dev.of_node) {
config = data; config = of_device_get_match_data(&client->dev);
if (!config)
return -ENODEV;
} else {
enum pcf85063_type type =
i2c_match_id(pcf85063_ids, client)->driver_data;
if (type >= PCF85063_LAST_ID)
return -ENODEV;
config = &pcf85063_cfg[type];
}
pcf85063->regmap = devm_regmap_init_i2c(client, &config->regmap); pcf85063->regmap = devm_regmap_init_i2c(client, &config->regmap);
if (IS_ERR(pcf85063->regmap)) if (IS_ERR(pcf85063->regmap))
...@@ -604,31 +648,21 @@ static int pcf85063_probe(struct i2c_client *client) ...@@ -604,31 +648,21 @@ static int pcf85063_probe(struct i2c_client *client)
return devm_rtc_register_device(pcf85063->rtc); return devm_rtc_register_device(pcf85063->rtc);
} }
#ifdef CONFIG_OF static const struct i2c_device_id pcf85063_ids[] = {
static const struct pcf85063_config pcf85063a_config = { { "pcf85063", PCF85063 },
.regmap = { { "pcf85063tp", PCF85063TP },
.reg_bits = 8, { "pcf85063a", PCF85063A },
.val_bits = 8, { "rv8263", RV8263 },
.max_register = 0x11, {}
},
.has_alarms = 1,
};
static const struct pcf85063_config rv8263_config = {
.regmap = {
.reg_bits = 8,
.val_bits = 8,
.max_register = 0x11,
},
.has_alarms = 1,
.force_cap_7000 = 1,
}; };
MODULE_DEVICE_TABLE(i2c, pcf85063_ids);
#ifdef CONFIG_OF
static const struct of_device_id pcf85063_of_match[] = { static const struct of_device_id pcf85063_of_match[] = {
{ .compatible = "nxp,pcf85063", .data = &pcf85063tp_config }, { .compatible = "nxp,pcf85063", .data = &pcf85063_cfg[PCF85063] },
{ .compatible = "nxp,pcf85063tp", .data = &pcf85063tp_config }, { .compatible = "nxp,pcf85063tp", .data = &pcf85063_cfg[PCF85063TP] },
{ .compatible = "nxp,pcf85063a", .data = &pcf85063a_config }, { .compatible = "nxp,pcf85063a", .data = &pcf85063_cfg[PCF85063A] },
{ .compatible = "microcrystal,rv8263", .data = &rv8263_config }, { .compatible = "microcrystal,rv8263", .data = &pcf85063_cfg[RV8263] },
{} {}
}; };
MODULE_DEVICE_TABLE(of, pcf85063_of_match); MODULE_DEVICE_TABLE(of, pcf85063_of_match);
...@@ -640,6 +674,7 @@ static struct i2c_driver pcf85063_driver = { ...@@ -640,6 +674,7 @@ static struct i2c_driver pcf85063_driver = {
.of_match_table = of_match_ptr(pcf85063_of_match), .of_match_table = of_match_ptr(pcf85063_of_match),
}, },
.probe_new = pcf85063_probe, .probe_new = pcf85063_probe,
.id_table = pcf85063_ids,
}; };
module_i2c_driver(pcf85063_driver); module_i2c_driver(pcf85063_driver);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment