rtc: pcf85063: create pcf85063_i2c_probe
Move the i2c-specific code from pcf85063_probe to the newly created function. This is a preparation for introducing the support for RV8063 real-time clock with SPI interface. Signed-off-by: Antoni Pokusinski <apokusinski01@gmail.com> Link: https://lore.kernel.org/r/20250413130755.159373-3-apokusinski01@gmail.com Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
This commit is contained in:
parent
b265cb1d68
commit
29ac4cedb0
@ -559,12 +559,12 @@ static const struct pcf85063_config config_rv8263 = {
|
||||
.force_cap_7000 = 1,
|
||||
};
|
||||
|
||||
static int pcf85063_probe(struct i2c_client *client)
|
||||
static int pcf85063_probe(struct device *dev, struct regmap *regmap, int irq,
|
||||
const struct pcf85063_config *config)
|
||||
{
|
||||
struct pcf85063 *pcf85063;
|
||||
unsigned int tmp;
|
||||
int err;
|
||||
const struct pcf85063_config *config;
|
||||
struct nvmem_config nvmem_cfg = {
|
||||
.name = "pcf85063_nvram",
|
||||
.reg_read = pcf85063_nvmem_read,
|
||||
@ -573,28 +573,22 @@ static int pcf85063_probe(struct i2c_client *client)
|
||||
.size = 1,
|
||||
};
|
||||
|
||||
dev_dbg(&client->dev, "%s\n", __func__);
|
||||
dev_dbg(dev, "%s\n", __func__);
|
||||
|
||||
pcf85063 = devm_kzalloc(&client->dev, sizeof(struct pcf85063),
|
||||
pcf85063 = devm_kzalloc(dev, sizeof(struct pcf85063),
|
||||
GFP_KERNEL);
|
||||
if (!pcf85063)
|
||||
return -ENOMEM;
|
||||
|
||||
config = i2c_get_match_data(client);
|
||||
if (!config)
|
||||
return -ENODEV;
|
||||
pcf85063->regmap = regmap;
|
||||
|
||||
pcf85063->regmap = devm_regmap_init_i2c(client, &config->regmap);
|
||||
if (IS_ERR(pcf85063->regmap))
|
||||
return PTR_ERR(pcf85063->regmap);
|
||||
|
||||
i2c_set_clientdata(client, pcf85063);
|
||||
dev_set_drvdata(dev, pcf85063);
|
||||
|
||||
err = regmap_read(pcf85063->regmap, PCF85063_REG_SC, &tmp);
|
||||
if (err)
|
||||
return dev_err_probe(&client->dev, err, "RTC chip is not present\n");
|
||||
return dev_err_probe(dev, err, "RTC chip is not present\n");
|
||||
|
||||
pcf85063->rtc = devm_rtc_allocate_device(&client->dev);
|
||||
pcf85063->rtc = devm_rtc_allocate_device(dev);
|
||||
if (IS_ERR(pcf85063->rtc))
|
||||
return PTR_ERR(pcf85063->rtc);
|
||||
|
||||
@ -605,19 +599,17 @@ static int pcf85063_probe(struct i2c_client *client)
|
||||
* of the registers after the automatic power-on reset...
|
||||
*/
|
||||
if (tmp & PCF85063_REG_SC_OS) {
|
||||
dev_warn(&client->dev,
|
||||
"POR issue detected, sending a SW reset\n");
|
||||
dev_warn(dev, "POR issue detected, sending a SW reset\n");
|
||||
err = regmap_write(pcf85063->regmap, PCF85063_REG_CTRL1,
|
||||
PCF85063_REG_CTRL1_SWR);
|
||||
if (err < 0)
|
||||
dev_warn(&client->dev,
|
||||
"SW reset failed, trying to continue\n");
|
||||
dev_warn(dev, "SW reset failed, trying to continue\n");
|
||||
}
|
||||
|
||||
err = pcf85063_load_capacitance(pcf85063, client->dev.of_node,
|
||||
err = pcf85063_load_capacitance(pcf85063, dev->of_node,
|
||||
config->force_cap_7000 ? 7000 : 0);
|
||||
if (err < 0)
|
||||
dev_warn(&client->dev, "failed to set xtal load capacitance: %d",
|
||||
dev_warn(dev, "failed to set xtal load capacitance: %d",
|
||||
err);
|
||||
|
||||
pcf85063->rtc->ops = &pcf85063_rtc_ops;
|
||||
@ -627,13 +619,13 @@ static int pcf85063_probe(struct i2c_client *client)
|
||||
clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, pcf85063->rtc->features);
|
||||
clear_bit(RTC_FEATURE_ALARM, pcf85063->rtc->features);
|
||||
|
||||
if (config->has_alarms && client->irq > 0) {
|
||||
if (config->has_alarms && irq > 0) {
|
||||
unsigned long irqflags = IRQF_TRIGGER_LOW;
|
||||
|
||||
if (dev_fwnode(&client->dev))
|
||||
if (dev_fwnode(dev))
|
||||
irqflags = 0;
|
||||
|
||||
err = devm_request_threaded_irq(&client->dev, client->irq,
|
||||
err = devm_request_threaded_irq(dev, irq,
|
||||
NULL, pcf85063_rtc_handle_irq,
|
||||
irqflags | IRQF_ONESHOT,
|
||||
"pcf85063", pcf85063);
|
||||
@ -642,8 +634,8 @@ static int pcf85063_probe(struct i2c_client *client)
|
||||
"unable to request IRQ, alarms disabled\n");
|
||||
} else {
|
||||
set_bit(RTC_FEATURE_ALARM, pcf85063->rtc->features);
|
||||
device_init_wakeup(&client->dev, true);
|
||||
err = dev_pm_set_wake_irq(&client->dev, client->irq);
|
||||
device_init_wakeup(dev, true);
|
||||
err = dev_pm_set_wake_irq(dev, irq);
|
||||
if (err)
|
||||
dev_err(&pcf85063->rtc->dev,
|
||||
"failed to enable irq wake\n");
|
||||
@ -661,6 +653,8 @@ static int pcf85063_probe(struct i2c_client *client)
|
||||
return devm_rtc_register_device(pcf85063->rtc);
|
||||
}
|
||||
|
||||
#if IS_ENABLED(CONFIG_I2C)
|
||||
|
||||
static const struct i2c_device_id pcf85063_ids[] = {
|
||||
{ "pca85073a", .driver_data = (kernel_ulong_t)&config_pcf85063a },
|
||||
{ "pcf85063", .driver_data = (kernel_ulong_t)&config_pcf85063 },
|
||||
@ -683,16 +677,65 @@ static const struct of_device_id pcf85063_of_match[] = {
|
||||
MODULE_DEVICE_TABLE(of, pcf85063_of_match);
|
||||
#endif
|
||||
|
||||
static int pcf85063_i2c_probe(struct i2c_client *client)
|
||||
{
|
||||
const struct pcf85063_config *config;
|
||||
struct regmap *regmap;
|
||||
|
||||
config = i2c_get_match_data(client);
|
||||
if (!config)
|
||||
return -ENODEV;
|
||||
|
||||
regmap = devm_regmap_init_i2c(client, &config->regmap);
|
||||
if (IS_ERR(regmap))
|
||||
return PTR_ERR(regmap);
|
||||
|
||||
return pcf85063_probe(&client->dev, regmap, client->irq, config);
|
||||
}
|
||||
|
||||
static struct i2c_driver pcf85063_driver = {
|
||||
.driver = {
|
||||
.name = "rtc-pcf85063",
|
||||
.of_match_table = of_match_ptr(pcf85063_of_match),
|
||||
},
|
||||
.probe = pcf85063_probe,
|
||||
.probe = pcf85063_i2c_probe,
|
||||
.id_table = pcf85063_ids,
|
||||
};
|
||||
|
||||
module_i2c_driver(pcf85063_driver);
|
||||
static int pcf85063_register_driver(void)
|
||||
{
|
||||
return i2c_add_driver(&pcf85063_driver);
|
||||
}
|
||||
|
||||
static void pcf85063_unregister_driver(void)
|
||||
{
|
||||
i2c_del_driver(&pcf85063_driver);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static int pcf85063_register_driver(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void pcf85063_unregister_driver(void)
|
||||
{
|
||||
}
|
||||
|
||||
#endif /* IS_ENABLED(CONFIG_I2C) */
|
||||
|
||||
static int __init pcf85063_init(void)
|
||||
{
|
||||
return pcf85063_register_driver();
|
||||
}
|
||||
module_init(pcf85063_init);
|
||||
|
||||
static void __exit pcf85063_exit(void)
|
||||
{
|
||||
pcf85063_unregister_driver();
|
||||
}
|
||||
module_exit(pcf85063_exit);
|
||||
|
||||
MODULE_AUTHOR("Søren Andersen <san@rosetechnology.dk>");
|
||||
MODULE_DESCRIPTION("PCF85063 RTC driver");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user