2021-11-04 13:44:51

by Marc Ferland

[permalink] [raw]
Subject: [PATCH] rtc: pcf85063: add i2c_device_id name matching support

From: Marc Ferland <[email protected]>

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: Marc Ferland <[email protected]>
---
drivers/rtc/rtc-pcf85063.c | 92 +++++++++++++++++++++++++-------------
1 file changed, 61 insertions(+), 31 deletions(-)

diff --git a/drivers/rtc/rtc-pcf85063.c b/drivers/rtc/rtc-pcf85063.c
index 14da4ab30104..521607213ada 100644
--- a/drivers/rtc/rtc-pcf85063.c
+++ b/drivers/rtc/rtc-pcf85063.c
@@ -500,21 +500,56 @@ static struct clk *pcf85063_clkout_register_clk(struct pcf85063 *pcf85063)
}
#endif

-static const struct pcf85063_config pcf85063tp_config = {
- .regmap = {
- .reg_bits = 8,
- .val_bits = 8,
- .max_register = 0x0a,
+enum pcf85063_type {
+ PCF85063,
+ PCF85063TP,
+ PCF85063A,
+ RV8263,
+};
+
+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)
{
struct pcf85063 *pcf85063;
unsigned int tmp;
int err;
- const struct pcf85063_config *config = &pcf85063tp_config;
- const void *data = of_device_get_match_data(&client->dev);
+ const struct pcf85063_config *config;
+ enum pcf85063_type type;
struct nvmem_config nvmem_cfg = {
.name = "pcf85063_nvram",
.reg_read = pcf85063_nvmem_read,
@@ -530,8 +565,12 @@ static int pcf85063_probe(struct i2c_client *client)
if (!pcf85063)
return -ENOMEM;

- if (data)
- config = data;
+ if (client->dev.of_node)
+ type = (enum pcf85063_type)of_device_get_match_data(&client->dev);
+ else
+ type = i2c_match_id(pcf85063_ids, client)->driver_data;
+
+ config = &pcf85063_cfg[type];

pcf85063->regmap = devm_regmap_init_i2c(client, &config->regmap);
if (IS_ERR(pcf85063->regmap))
@@ -590,31 +629,21 @@ static int pcf85063_probe(struct i2c_client *client)
return devm_rtc_register_device(pcf85063->rtc);
}

-#ifdef CONFIG_OF
-static const struct pcf85063_config pcf85063a_config = {
- .regmap = {
- .reg_bits = 8,
- .val_bits = 8,
- .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,
+static const struct i2c_device_id pcf85063_ids[] = {
+ { "pcf85063", PCF85063 },
+ { "pcf85063tp", PCF85063TP },
+ { "pcf85063a", PCF85063A },
+ { "rv8263", RV8263 },
+ {}
};
+MODULE_DEVICE_TABLE(i2c, pcf85063_ids);

+#ifdef CONFIG_OF
static const struct of_device_id pcf85063_of_match[] = {
- { .compatible = "nxp,pcf85063", .data = &pcf85063tp_config },
- { .compatible = "nxp,pcf85063tp", .data = &pcf85063tp_config },
- { .compatible = "nxp,pcf85063a", .data = &pcf85063a_config },
- { .compatible = "microcrystal,rv8263", .data = &rv8263_config },
+ { .compatible = "nxp,pcf85063", .data = (void *)PCF85063 },
+ { .compatible = "nxp,pcf85063tp", .data = (void *)PCF85063TP },
+ { .compatible = "nxp,pcf85063a", .data = (void *)PCF85063A },
+ { .compatible = "microcrystal,rv8263", .data = (void *)RV8263 },
{}
};
MODULE_DEVICE_TABLE(of, pcf85063_of_match);
@@ -626,6 +655,7 @@ static struct i2c_driver pcf85063_driver = {
.of_match_table = of_match_ptr(pcf85063_of_match),
},
.probe_new = pcf85063_probe,
+ .id_table = pcf85063_ids,
};

module_i2c_driver(pcf85063_driver);
--
2.30.2


2021-11-05 04:52:56

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] rtc: pcf85063: add i2c_device_id name matching support

Hi,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on abelloni/rtc-next]
[also build test WARNING on v5.15 next-20211104]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url: https://github.com/0day-ci/linux/commits/ferlandm-amotus-ca/rtc-pcf85063-add-i2c_device_id-name-matching-support/20211104-214400
base: https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux.git rtc-next
config: x86_64-randconfig-r034-20211105 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 847a6807332b13f43704327c2d30103ec0347c77)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/daa69a83cd9857be2bd3c58bfeb7f028253e6a4f
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review ferlandm-amotus-ca/rtc-pcf85063-add-i2c_device_id-name-matching-support/20211104-214400
git checkout daa69a83cd9857be2bd3c58bfeb7f028253e6a4f
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 ARCH=x86_64

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>

All warnings (new ones prefixed by >>):

>> drivers/rtc/rtc-pcf85063.c:583:10: warning: cast to smaller integer type 'enum pcf85063_type' from 'const void *' [-Wvoid-pointer-to-enum-cast]
type = (enum pcf85063_type)of_device_get_match_data(&client->dev);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.


vim +583 drivers/rtc/rtc-pcf85063.c

559
560 static int pcf85063_probe(struct i2c_client *client)
561 {
562 struct pcf85063 *pcf85063;
563 unsigned int tmp;
564 int err;
565 const struct pcf85063_config *config;
566 enum pcf85063_type type;
567 struct nvmem_config nvmem_cfg = {
568 .name = "pcf85063_nvram",
569 .reg_read = pcf85063_nvmem_read,
570 .reg_write = pcf85063_nvmem_write,
571 .type = NVMEM_TYPE_BATTERY_BACKED,
572 .size = 1,
573 };
574
575 dev_dbg(&client->dev, "%s\n", __func__);
576
577 pcf85063 = devm_kzalloc(&client->dev, sizeof(struct pcf85063),
578 GFP_KERNEL);
579 if (!pcf85063)
580 return -ENOMEM;
581
582 if (client->dev.of_node)
> 583 type = (enum pcf85063_type)of_device_get_match_data(&client->dev);
584 else
585 type = i2c_match_id(pcf85063_ids, client)->driver_data;
586
587 config = &pcf85063_cfg[type];
588
589 pcf85063->regmap = devm_regmap_init_i2c(client, &config->regmap);
590 if (IS_ERR(pcf85063->regmap))
591 return PTR_ERR(pcf85063->regmap);
592
593 i2c_set_clientdata(client, pcf85063);
594
595 err = regmap_read(pcf85063->regmap, PCF85063_REG_CTRL1, &tmp);
596 if (err) {
597 dev_err(&client->dev, "RTC chip is not present\n");
598 return err;
599 }
600
601 pcf85063->rtc = devm_rtc_allocate_device(&client->dev);
602 if (IS_ERR(pcf85063->rtc))
603 return PTR_ERR(pcf85063->rtc);
604
605 err = pcf85063_load_capacitance(pcf85063, client->dev.of_node,
606 config->force_cap_7000 ? 7000 : 0);
607 if (err < 0)
608 dev_warn(&client->dev, "failed to set xtal load capacitance: %d",
609 err);
610
611 pcf85063->rtc->ops = &pcf85063_rtc_ops;
612 pcf85063->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
613 pcf85063->rtc->range_max = RTC_TIMESTAMP_END_2099;
614 pcf85063->rtc->uie_unsupported = 1;
615 clear_bit(RTC_FEATURE_ALARM, pcf85063->rtc->features);
616
617 if (config->has_alarms && client->irq > 0) {
618 err = devm_request_threaded_irq(&client->dev, client->irq,
619 NULL, pcf85063_rtc_handle_irq,
620 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
621 "pcf85063", pcf85063);
622 if (err) {
623 dev_warn(&pcf85063->rtc->dev,
624 "unable to request IRQ, alarms disabled\n");
625 } else {
626 set_bit(RTC_FEATURE_ALARM, pcf85063->rtc->features);
627 device_init_wakeup(&client->dev, true);
628 err = dev_pm_set_wake_irq(&client->dev, client->irq);
629 if (err)
630 dev_err(&pcf85063->rtc->dev,
631 "failed to enable irq wake\n");
632 }
633 }
634
635 nvmem_cfg.priv = pcf85063->regmap;
636 devm_rtc_nvmem_register(pcf85063->rtc, &nvmem_cfg);
637

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]


Attachments:
(No filename) (4.86 kB)
.config.gz (31.65 kB)
Download all attachments

2021-11-16 16:48:33

by Marc Ferland

[permalink] [raw]
Subject: [PATCH v2] rtc: pcf85063: add i2c_device_id name matching support

From: Marc Ferland <[email protected]>

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: Marc Ferland <[email protected]>
Reported-by: kernel test robot <[email protected]>
---
Changes in v2:
- rebased on rtc-next
- fix compile warning reported by kernel test robot
- use --base as suggested by kernel test robot

drivers/rtc/rtc-pcf85063.c | 97 ++++++++++++++++++++++++++------------
1 file changed, 66 insertions(+), 31 deletions(-)

diff --git a/drivers/rtc/rtc-pcf85063.c b/drivers/rtc/rtc-pcf85063.c
index 15e50bb10cf0..df2b072c394d 100644
--- a/drivers/rtc/rtc-pcf85063.c
+++ b/drivers/rtc/rtc-pcf85063.c
@@ -514,21 +514,56 @@ static struct clk *pcf85063_clkout_register_clk(struct pcf85063 *pcf85063)
}
#endif

-static const struct pcf85063_config pcf85063tp_config = {
- .regmap = {
- .reg_bits = 8,
- .val_bits = 8,
- .max_register = 0x0a,
+enum pcf85063_type {
+ PCF85063,
+ PCF85063TP,
+ PCF85063A,
+ 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)
{
struct pcf85063 *pcf85063;
unsigned int tmp;
int err;
- const struct pcf85063_config *config = &pcf85063tp_config;
- const void *data = of_device_get_match_data(&client->dev);
+ const struct pcf85063_config *config;
struct nvmem_config nvmem_cfg = {
.name = "pcf85063_nvram",
.reg_read = pcf85063_nvmem_read,
@@ -544,8 +579,17 @@ static int pcf85063_probe(struct i2c_client *client)
if (!pcf85063)
return -ENOMEM;

- if (data)
- config = data;
+ if (client->dev.of_node) {
+ 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);
if (IS_ERR(pcf85063->regmap))
@@ -604,31 +648,21 @@ static int pcf85063_probe(struct i2c_client *client)
return devm_rtc_register_device(pcf85063->rtc);
}

-#ifdef CONFIG_OF
-static const struct pcf85063_config pcf85063a_config = {
- .regmap = {
- .reg_bits = 8,
- .val_bits = 8,
- .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,
+static const struct i2c_device_id pcf85063_ids[] = {
+ { "pcf85063", PCF85063 },
+ { "pcf85063tp", PCF85063TP },
+ { "pcf85063a", PCF85063A },
+ { "rv8263", RV8263 },
+ {}
};
+MODULE_DEVICE_TABLE(i2c, pcf85063_ids);

+#ifdef CONFIG_OF
static const struct of_device_id pcf85063_of_match[] = {
- { .compatible = "nxp,pcf85063", .data = &pcf85063tp_config },
- { .compatible = "nxp,pcf85063tp", .data = &pcf85063tp_config },
- { .compatible = "nxp,pcf85063a", .data = &pcf85063a_config },
- { .compatible = "microcrystal,rv8263", .data = &rv8263_config },
+ { .compatible = "nxp,pcf85063", .data = &pcf85063_cfg[PCF85063] },
+ { .compatible = "nxp,pcf85063tp", .data = &pcf85063_cfg[PCF85063TP] },
+ { .compatible = "nxp,pcf85063a", .data = &pcf85063_cfg[PCF85063A] },
+ { .compatible = "microcrystal,rv8263", .data = &pcf85063_cfg[RV8263] },
{}
};
MODULE_DEVICE_TABLE(of, pcf85063_of_match);
@@ -640,6 +674,7 @@ static struct i2c_driver pcf85063_driver = {
.of_match_table = of_match_ptr(pcf85063_of_match),
},
.probe_new = pcf85063_probe,
+ .id_table = pcf85063_ids,
};

module_i2c_driver(pcf85063_driver);

base-commit: fa55b7dcdc43c1aa1ba12bca9d2dd4318c2a0dbf
--
2.30.2

2021-11-30 23:08:08

by Alexandre Belloni

[permalink] [raw]
Subject: Re: [PATCH v2] rtc: pcf85063: add i2c_device_id name matching support

On Tue, 16 Nov 2021 11:47:33 -0500, [email protected] wrote:
> From: Marc Ferland <[email protected]>
>
> 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.
>
> [...]

Applied, thanks!

[1/1] rtc: pcf85063: add i2c_device_id name matching support
commit: 1c1b3098ae1e0d9725d0d4d49986e0edebba443a

Best regards,
--
Alexandre Belloni <[email protected]>