Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Antoni Pokusinski and committed by
Alexandre Belloni
29ac4ced b265cb1d

+70 -27
+70 -27
drivers/rtc/rtc-pcf85063.c
··· 559 559 .force_cap_7000 = 1, 560 560 }; 561 561 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) 563 564 { 564 565 struct pcf85063 *pcf85063; 565 566 unsigned int tmp; 566 567 int err; 567 - const struct pcf85063_config *config; 568 568 struct nvmem_config nvmem_cfg = { 569 569 .name = "pcf85063_nvram", 570 570 .reg_read = pcf85063_nvmem_read, ··· 573 573 .size = 1, 574 574 }; 575 575 576 - dev_dbg(&client->dev, "%s\n", __func__); 576 + dev_dbg(dev, "%s\n", __func__); 577 577 578 - pcf85063 = devm_kzalloc(&client->dev, sizeof(struct pcf85063), 578 + pcf85063 = devm_kzalloc(dev, sizeof(struct pcf85063), 579 579 GFP_KERNEL); 580 580 if (!pcf85063) 581 581 return -ENOMEM; 582 582 583 - config = i2c_get_match_data(client); 584 - if (!config) 585 - return -ENODEV; 583 + pcf85063->regmap = regmap; 586 584 587 - pcf85063->regmap = devm_regmap_init_i2c(client, &config->regmap); 588 - if (IS_ERR(pcf85063->regmap)) 589 - return PTR_ERR(pcf85063->regmap); 590 - 591 - i2c_set_clientdata(client, pcf85063); 585 + dev_set_drvdata(dev, pcf85063); 592 586 593 587 err = regmap_read(pcf85063->regmap, PCF85063_REG_SC, &tmp); 594 588 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"); 596 590 597 - pcf85063->rtc = devm_rtc_allocate_device(&client->dev); 591 + pcf85063->rtc = devm_rtc_allocate_device(dev); 598 592 if (IS_ERR(pcf85063->rtc)) 599 593 return PTR_ERR(pcf85063->rtc); 600 594 ··· 599 605 * of the registers after the automatic power-on reset... 600 606 */ 601 607 if (tmp & PCF85063_REG_SC_OS) { 602 - dev_warn(&client->dev, 603 - "POR issue detected, sending a SW reset\n"); 608 + dev_warn(dev, "POR issue detected, sending a SW reset\n"); 604 609 err = regmap_write(pcf85063->regmap, PCF85063_REG_CTRL1, 605 610 PCF85063_REG_CTRL1_SWR); 606 611 if (err < 0) 607 - dev_warn(&client->dev, 608 - "SW reset failed, trying to continue\n"); 612 + dev_warn(dev, "SW reset failed, trying to continue\n"); 609 613 } 610 614 611 - err = pcf85063_load_capacitance(pcf85063, client->dev.of_node, 615 + err = pcf85063_load_capacitance(pcf85063, dev->of_node, 612 616 config->force_cap_7000 ? 7000 : 0); 613 617 if (err < 0) 614 - dev_warn(&client->dev, "failed to set xtal load capacitance: %d", 618 + dev_warn(dev, "failed to set xtal load capacitance: %d", 615 619 err); 616 620 617 621 pcf85063->rtc->ops = &pcf85063_rtc_ops; ··· 619 627 clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, pcf85063->rtc->features); 620 628 clear_bit(RTC_FEATURE_ALARM, pcf85063->rtc->features); 621 629 622 - if (config->has_alarms && client->irq > 0) { 630 + if (config->has_alarms && irq > 0) { 623 631 unsigned long irqflags = IRQF_TRIGGER_LOW; 624 632 625 - if (dev_fwnode(&client->dev)) 633 + if (dev_fwnode(dev)) 626 634 irqflags = 0; 627 635 628 - err = devm_request_threaded_irq(&client->dev, client->irq, 636 + err = devm_request_threaded_irq(dev, irq, 629 637 NULL, pcf85063_rtc_handle_irq, 630 638 irqflags | IRQF_ONESHOT, 631 639 "pcf85063", pcf85063); ··· 634 642 "unable to request IRQ, alarms disabled\n"); 635 643 } else { 636 644 set_bit(RTC_FEATURE_ALARM, pcf85063->rtc->features); 637 - device_init_wakeup(&client->dev, true); 638 - err = dev_pm_set_wake_irq(&client->dev, client->irq); 645 + device_init_wakeup(dev, true); 646 + err = dev_pm_set_wake_irq(dev, irq); 639 647 if (err) 640 648 dev_err(&pcf85063->rtc->dev, 641 649 "failed to enable irq wake\n"); ··· 652 660 653 661 return devm_rtc_register_device(pcf85063->rtc); 654 662 } 663 + 664 + #if IS_ENABLED(CONFIG_I2C) 655 665 656 666 static const struct i2c_device_id pcf85063_ids[] = { 657 667 { "pca85073a", .driver_data = (kernel_ulong_t)&config_pcf85063a }, ··· 677 683 MODULE_DEVICE_TABLE(of, pcf85063_of_match); 678 684 #endif 679 685 686 + static int pcf85063_i2c_probe(struct i2c_client *client) 687 + { 688 + const struct pcf85063_config *config; 689 + struct regmap *regmap; 690 + 691 + config = i2c_get_match_data(client); 692 + if (!config) 693 + return -ENODEV; 694 + 695 + regmap = devm_regmap_init_i2c(client, &config->regmap); 696 + if (IS_ERR(regmap)) 697 + return PTR_ERR(regmap); 698 + 699 + return pcf85063_probe(&client->dev, regmap, client->irq, config); 700 + } 701 + 680 702 static struct i2c_driver pcf85063_driver = { 681 703 .driver = { 682 704 .name = "rtc-pcf85063", 683 705 .of_match_table = of_match_ptr(pcf85063_of_match), 684 706 }, 685 - .probe = pcf85063_probe, 707 + .probe = pcf85063_i2c_probe, 686 708 .id_table = pcf85063_ids, 687 709 }; 688 710 689 - module_i2c_driver(pcf85063_driver); 711 + static int pcf85063_register_driver(void) 712 + { 713 + return i2c_add_driver(&pcf85063_driver); 714 + } 715 + 716 + static void pcf85063_unregister_driver(void) 717 + { 718 + i2c_del_driver(&pcf85063_driver); 719 + } 720 + 721 + #else 722 + 723 + static int pcf85063_register_driver(void) 724 + { 725 + return 0; 726 + } 727 + 728 + static void pcf85063_unregister_driver(void) 729 + { 730 + } 731 + 732 + #endif /* IS_ENABLED(CONFIG_I2C) */ 733 + 734 + static int __init pcf85063_init(void) 735 + { 736 + return pcf85063_register_driver(); 737 + } 738 + module_init(pcf85063_init); 739 + 740 + static void __exit pcf85063_exit(void) 741 + { 742 + pcf85063_unregister_driver(); 743 + } 744 + module_exit(pcf85063_exit); 690 745 691 746 MODULE_AUTHOR("Søren Andersen <san@rosetechnology.dk>"); 692 747 MODULE_DESCRIPTION("PCF85063 RTC driver");