Skip to content

Commit 29ac4ce

Browse files
panantoni01alexandrebelloni
authored andcommitted
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>
1 parent b265cb1 commit 29ac4ce

1 file changed

Lines changed: 70 additions & 27 deletions

File tree

drivers/rtc/rtc-pcf85063.c

Lines changed: 70 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -559,12 +559,12 @@ static const struct pcf85063_config config_rv8263 = {
559559
.force_cap_7000 = 1,
560560
};
561561

562-
static int pcf85063_probe(struct i2c_client *client)
562+
static int pcf85063_probe(struct device *dev, struct regmap *regmap, int irq,
563+
const struct pcf85063_config *config)
563564
{
564565
struct pcf85063 *pcf85063;
565566
unsigned int tmp;
566567
int err;
567-
const struct pcf85063_config *config;
568568
struct nvmem_config nvmem_cfg = {
569569
.name = "pcf85063_nvram",
570570
.reg_read = pcf85063_nvmem_read,
@@ -573,28 +573,22 @@ static int pcf85063_probe(struct i2c_client *client)
573573
.size = 1,
574574
};
575575

576-
dev_dbg(&client->dev, "%s\n", __func__);
576+
dev_dbg(dev, "%s\n", __func__);
577577

578-
pcf85063 = devm_kzalloc(&client->dev, sizeof(struct pcf85063),
578+
pcf85063 = devm_kzalloc(dev, sizeof(struct pcf85063),
579579
GFP_KERNEL);
580580
if (!pcf85063)
581581
return -ENOMEM;
582582

583-
config = i2c_get_match_data(client);
584-
if (!config)
585-
return -ENODEV;
586-
587-
pcf85063->regmap = devm_regmap_init_i2c(client, &config->regmap);
588-
if (IS_ERR(pcf85063->regmap))
589-
return PTR_ERR(pcf85063->regmap);
583+
pcf85063->regmap = regmap;
590584

591-
i2c_set_clientdata(client, pcf85063);
585+
dev_set_drvdata(dev, pcf85063);
592586

593587
err = regmap_read(pcf85063->regmap, PCF85063_REG_SC, &tmp);
594588
if (err)
595-
return dev_err_probe(&client->dev, err, "RTC chip is not present\n");
589+
return dev_err_probe(dev, err, "RTC chip is not present\n");
596590

597-
pcf85063->rtc = devm_rtc_allocate_device(&client->dev);
591+
pcf85063->rtc = devm_rtc_allocate_device(dev);
598592
if (IS_ERR(pcf85063->rtc))
599593
return PTR_ERR(pcf85063->rtc);
600594

@@ -605,19 +599,17 @@ static int pcf85063_probe(struct i2c_client *client)
605599
* of the registers after the automatic power-on reset...
606600
*/
607601
if (tmp & PCF85063_REG_SC_OS) {
608-
dev_warn(&client->dev,
609-
"POR issue detected, sending a SW reset\n");
602+
dev_warn(dev, "POR issue detected, sending a SW reset\n");
610603
err = regmap_write(pcf85063->regmap, PCF85063_REG_CTRL1,
611604
PCF85063_REG_CTRL1_SWR);
612605
if (err < 0)
613-
dev_warn(&client->dev,
614-
"SW reset failed, trying to continue\n");
606+
dev_warn(dev, "SW reset failed, trying to continue\n");
615607
}
616608

617-
err = pcf85063_load_capacitance(pcf85063, client->dev.of_node,
609+
err = pcf85063_load_capacitance(pcf85063, dev->of_node,
618610
config->force_cap_7000 ? 7000 : 0);
619611
if (err < 0)
620-
dev_warn(&client->dev, "failed to set xtal load capacitance: %d",
612+
dev_warn(dev, "failed to set xtal load capacitance: %d",
621613
err);
622614

623615
pcf85063->rtc->ops = &pcf85063_rtc_ops;
@@ -627,13 +619,13 @@ static int pcf85063_probe(struct i2c_client *client)
627619
clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, pcf85063->rtc->features);
628620
clear_bit(RTC_FEATURE_ALARM, pcf85063->rtc->features);
629621

630-
if (config->has_alarms && client->irq > 0) {
622+
if (config->has_alarms && irq > 0) {
631623
unsigned long irqflags = IRQF_TRIGGER_LOW;
632624

633-
if (dev_fwnode(&client->dev))
625+
if (dev_fwnode(dev))
634626
irqflags = 0;
635627

636-
err = devm_request_threaded_irq(&client->dev, client->irq,
628+
err = devm_request_threaded_irq(dev, irq,
637629
NULL, pcf85063_rtc_handle_irq,
638630
irqflags | IRQF_ONESHOT,
639631
"pcf85063", pcf85063);
@@ -642,8 +634,8 @@ static int pcf85063_probe(struct i2c_client *client)
642634
"unable to request IRQ, alarms disabled\n");
643635
} else {
644636
set_bit(RTC_FEATURE_ALARM, pcf85063->rtc->features);
645-
device_init_wakeup(&client->dev, true);
646-
err = dev_pm_set_wake_irq(&client->dev, client->irq);
637+
device_init_wakeup(dev, true);
638+
err = dev_pm_set_wake_irq(dev, irq);
647639
if (err)
648640
dev_err(&pcf85063->rtc->dev,
649641
"failed to enable irq wake\n");
@@ -661,6 +653,8 @@ static int pcf85063_probe(struct i2c_client *client)
661653
return devm_rtc_register_device(pcf85063->rtc);
662654
}
663655

656+
#if IS_ENABLED(CONFIG_I2C)
657+
664658
static const struct i2c_device_id pcf85063_ids[] = {
665659
{ "pca85073a", .driver_data = (kernel_ulong_t)&config_pcf85063a },
666660
{ "pcf85063", .driver_data = (kernel_ulong_t)&config_pcf85063 },
@@ -683,16 +677,65 @@ static const struct of_device_id pcf85063_of_match[] = {
683677
MODULE_DEVICE_TABLE(of, pcf85063_of_match);
684678
#endif
685679

680+
static int pcf85063_i2c_probe(struct i2c_client *client)
681+
{
682+
const struct pcf85063_config *config;
683+
struct regmap *regmap;
684+
685+
config = i2c_get_match_data(client);
686+
if (!config)
687+
return -ENODEV;
688+
689+
regmap = devm_regmap_init_i2c(client, &config->regmap);
690+
if (IS_ERR(regmap))
691+
return PTR_ERR(regmap);
692+
693+
return pcf85063_probe(&client->dev, regmap, client->irq, config);
694+
}
695+
686696
static struct i2c_driver pcf85063_driver = {
687697
.driver = {
688698
.name = "rtc-pcf85063",
689699
.of_match_table = of_match_ptr(pcf85063_of_match),
690700
},
691-
.probe = pcf85063_probe,
701+
.probe = pcf85063_i2c_probe,
692702
.id_table = pcf85063_ids,
693703
};
694704

695-
module_i2c_driver(pcf85063_driver);
705+
static int pcf85063_register_driver(void)
706+
{
707+
return i2c_add_driver(&pcf85063_driver);
708+
}
709+
710+
static void pcf85063_unregister_driver(void)
711+
{
712+
i2c_del_driver(&pcf85063_driver);
713+
}
714+
715+
#else
716+
717+
static int pcf85063_register_driver(void)
718+
{
719+
return 0;
720+
}
721+
722+
static void pcf85063_unregister_driver(void)
723+
{
724+
}
725+
726+
#endif /* IS_ENABLED(CONFIG_I2C) */
727+
728+
static int __init pcf85063_init(void)
729+
{
730+
return pcf85063_register_driver();
731+
}
732+
module_init(pcf85063_init);
733+
734+
static void __exit pcf85063_exit(void)
735+
{
736+
pcf85063_unregister_driver();
737+
}
738+
module_exit(pcf85063_exit);
696739

697740
MODULE_AUTHOR("Søren Andersen <san@rosetechnology.dk>");
698741
MODULE_DESCRIPTION("PCF85063 RTC driver");

0 commit comments

Comments
 (0)