All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bruno Thomsen <bruno.thomsen@gmail.com>
To: Hugo Villeneuve <hugo@hugovil.com>
Cc: a.zummo@towertech.it, alexandre.belloni@bootlin.com,
	robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org,
	linux-rtc@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Hugo Villeneuve <hvilleneuve@dimonoff.com>
Subject: Re: [PATCH v3 01/14] rtc: pcf2127: add variant-specific configuration structure
Date: Mon, 19 Dec 2022 18:17:45 +0100	[thread overview]
Message-ID: <CAH+2xPC5MvrAiMOpjm8D2aeJEMmNJghMSg1zoeDb=DO-dBue7w@mail.gmail.com> (raw)
In-Reply-To: <20221219101526.ab27daa0971e827128d51a15@hugovil.com>

Hi Hugo,

Looking more into it I think you based it against the right tree,
but if you use --base= when doing format-patch it's easier to spot :)
I only use torvalds tree when testing patches on a device.

/Bruno

Den man. 19. dec. 2022 kl. 16.15 skrev Hugo Villeneuve <hugo@hugovil.com>:
>
> On Mon, 19 Dec 2022 10:05:53 +0100
> Bruno Thomsen <bruno.thomsen@gmail.com> wrote:
>
> > Den tor. 15. dec. 2022 kl. 16.19 skrev Hugo Villeneuve <hugo@hugovil.com>:
> > >
> > > From: Hugo Villeneuve <hvilleneuve@dimonoff.com>
> > >
> > > Create variant-specific configuration structures to simplify the
> > > implementation of new variants into this driver. It will also avoid
> > > to have too many tests for a specific variant, or a list of variants
> > > for new devices, inside the code itself.
> > >
> > > Add configuration options for the support of the NVMEM, bit CD0 in
> > > register WD_CTL as well as the maximum number of registers for each
> > > variant, instead of hardcoding the variant (PCF2127) inside the
> > > i2c_device_id and spi_device_id structures.
> > >
> > > Also specify a different maximum number of registers (max_register)
> > > for the PCF2129.
> > >
> > > Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
> > > ---
> > >  drivers/rtc/rtc-pcf2127.c | 95 +++++++++++++++++++++++++++++++--------
> > >  1 file changed, 76 insertions(+), 19 deletions(-)
> > >
> > > diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c
> > > index 87f4fc9df68b..b9a5d47a439f 100644
> > > --- a/drivers/rtc/rtc-pcf2127.c
> > > +++ b/drivers/rtc/rtc-pcf2127.c
> > > @@ -21,6 +21,7 @@
> > >  #include <linux/module.h>
> > >  #include <linux/of.h>
> > >  #include <linux/of_irq.h>
> > > +#include <linux/of_device.h>
> > >  #include <linux/regmap.h>
> > >  #include <linux/watchdog.h>
> > >
> > > @@ -101,10 +102,17 @@
> > >                 PCF2127_BIT_CTRL2_WDTF | \
> > >                 PCF2127_BIT_CTRL2_TSF2)
> > >
> > > +struct pcf21xx_config {
> > > +       int max_register;
> > > +       unsigned int has_nvmem:1;
> > > +       unsigned int has_bit_wd_ctl_cd0:1;
> > > +};
> > > +
> > >  struct pcf2127 {
> > >         struct rtc_device *rtc;
> > >         struct watchdog_device wdd;
> > >         struct regmap *regmap;
> > > +       const struct pcf21xx_config *cfg;
> > >         time64_t ts;
> > >         bool ts_valid;
> > >         bool irq_enabled;
> > > @@ -631,8 +639,27 @@ static const struct attribute_group pcf2127_attr_group = {
> > >         .attrs  = pcf2127_attrs,
> > >  };
> > >
> > > +enum pcf21xx_type {
> > > +       PCF2127,
> > > +       PCF2129,
> > > +       PCF21XX_LAST_ID
> > > +};
> > > +
> > > +static struct pcf21xx_config pcf21xx_cfg[] = {
> > > +       [PCF2127] = {
> > > +               .max_register = 0x1d,
> > > +               .has_nvmem = 1,
> > > +               .has_bit_wd_ctl_cd0 = 1,
> > > +       },
> > > +       [PCF2129] = {
> > > +               .max_register = 0x19,
> > > +               .has_nvmem = 0,
> > > +               .has_bit_wd_ctl_cd0 = 0,
> > > +       },
> > > +};
> > > +
> > >  static int pcf2127_probe(struct device *dev, struct regmap *regmap,
> > > -                        int alarm_irq, const char *name, bool is_pcf2127)
> > > +                        int alarm_irq, const char *name, const struct pcf21xx_config *config)
> > >  {
> > >         struct pcf2127 *pcf2127;
> > >         int ret = 0;
> > > @@ -645,6 +672,7 @@ static int pcf2127_probe(struct device *dev, struct regmap *regmap,
> > >                 return -ENOMEM;
> > >
> > >         pcf2127->regmap = regmap;
> > > +       pcf2127->cfg = config;
> > >
> > >         dev_set_drvdata(dev, pcf2127);
> > >
> > > @@ -688,7 +716,7 @@ static int pcf2127_probe(struct device *dev, struct regmap *regmap,
> > >                 set_bit(RTC_FEATURE_ALARM, pcf2127->rtc->features);
> > >         }
> > >
> > > -       if (is_pcf2127) {
> > > +       if (pcf2127->cfg->has_nvmem) {
> > >                 struct nvmem_config nvmem_cfg = {
> > >                         .priv = pcf2127,
> > >                         .reg_read = pcf2127_nvmem_read,
> > > @@ -734,7 +762,7 @@ static int pcf2127_probe(struct device *dev, struct regmap *regmap,
> > >                                  PCF2127_BIT_WD_CTL_TF1 |
> > >                                  PCF2127_BIT_WD_CTL_TF0,
> > >                                  PCF2127_BIT_WD_CTL_CD1 |
> > > -                                (is_pcf2127 ? PCF2127_BIT_WD_CTL_CD0 : 0) |
> > > +                                (pcf2127->cfg->has_bit_wd_ctl_cd0 ? PCF2127_BIT_WD_CTL_CD0 : 0) |
> > >                                  PCF2127_BIT_WD_CTL_TF1);
> > >         if (ret) {
> > >                 dev_err(dev, "%s: watchdog config (wd_ctl) failed\n", __func__);
> > > @@ -799,9 +827,9 @@ static int pcf2127_probe(struct device *dev, struct regmap *regmap,
> > >
> > >  #ifdef CONFIG_OF
> > >  static const struct of_device_id pcf2127_of_match[] = {
> > > -       { .compatible = "nxp,pcf2127" },
> > > -       { .compatible = "nxp,pcf2129" },
> > > -       { .compatible = "nxp,pca2129" },
> > > +       { .compatible = "nxp,pcf2127", .data = &pcf21xx_cfg[PCF2127] },
> > > +       { .compatible = "nxp,pcf2129", .data = &pcf21xx_cfg[PCF2129] },
> > > +       { .compatible = "nxp,pca2129", .data = &pcf21xx_cfg[PCF2129] },
> > >         {}
> > >  };
> > >  MODULE_DEVICE_TABLE(of, pcf2127_of_match);
> > > @@ -886,26 +914,40 @@ static const struct regmap_bus pcf2127_i2c_regmap = {
> > >  static struct i2c_driver pcf2127_i2c_driver;
> > >
> > >  static const struct i2c_device_id pcf2127_i2c_id[] = {
> > > -       { "pcf2127", 1 },
> > > -       { "pcf2129", 0 },
> > > -       { "pca2129", 0 },
> > > +       { "pcf2127", PCF2127 },
> > > +       { "pcf2129", PCF2129 },
> > > +       { "pca2129", PCF2129 },
> > >         { }
> > >  };
> > >  MODULE_DEVICE_TABLE(i2c, pcf2127_i2c_id);
> > >
> > >  static int pcf2127_i2c_probe(struct i2c_client *client)
> > >  {
> > > -       const struct i2c_device_id *id = i2c_match_id(pcf2127_i2c_id, client);
> > >         struct regmap *regmap;
> > > -       static const struct regmap_config config = {
> > > +       static struct regmap_config config = {
> > >                 .reg_bits = 8,
> > >                 .val_bits = 8,
> > > -               .max_register = 0x1d,
> > >         };
> > > +       const struct pcf21xx_config *variant;
> >
> > Hi Hugo,
> >
> > Patch series does not apply on 6.1 tree as pcf2127_i2c_probe() call
> > signature does not match[1].
> >
> > static int pcf2127_i2c_probe(struct i2c_client *client,
> >       const struct i2c_device_id *id)
> >
> >
> > [1] https://elixir.bootlin.com/linux/v6.1/source/drivers/rtc/rtc-pcf2127.c#L888
> >
> > /Bruno
>
> Hi Bruno,
> I based my driver on the git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux.git repo, as indicated in the MAINTAINERS file for the RTC subsystem (T: entry). I used the rtc-next branch on this repo.
>
> Can you tell me exactly which repo and branch I need to use to resubmit the driver?
>
> Thank you, Hugo.
>
>
> > >         if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
> > >                 return -ENODEV;
> > >
> > > +       if (client->dev.of_node) {
> > > +               variant = of_device_get_match_data(&client->dev);
> > > +               if (!variant)
> > > +                       return -ENODEV;
> > > +       } else {
> > > +               enum pcf21xx_type type =
> > > +                       i2c_match_id(pcf2127_i2c_id, client)->driver_data;
> > > +
> > > +               if (type >= PCF21XX_LAST_ID)
> > > +                       return -ENODEV;
> > > +               variant = &pcf21xx_cfg[type];
> > > +       }
> > > +
> > > +       config.max_register = variant->max_register,
> > > +
> > >         regmap = devm_regmap_init(&client->dev, &pcf2127_i2c_regmap,
> > >                                         &client->dev, &config);
> > >         if (IS_ERR(regmap)) {
> > > @@ -915,7 +957,7 @@ static int pcf2127_i2c_probe(struct i2c_client *client)
> > >         }
> > >
> > >         return pcf2127_probe(&client->dev, regmap, client->irq,
> > > -                            pcf2127_i2c_driver.driver.name, id->driver_data);
> > > +                            pcf2127_i2c_driver.driver.name, variant);
> > >  }
> > >
> > >  static struct i2c_driver pcf2127_i2c_driver = {
> > > @@ -953,17 +995,32 @@ static void pcf2127_i2c_unregister_driver(void)
> > >  #if IS_ENABLED(CONFIG_SPI_MASTER)
> > >
> > >  static struct spi_driver pcf2127_spi_driver;
> > > +static const struct spi_device_id pcf2127_spi_id[];
> > >
> > >  static int pcf2127_spi_probe(struct spi_device *spi)
> > >  {
> > > -       static const struct regmap_config config = {
> > > +       static struct regmap_config config = {
> > >                 .reg_bits = 8,
> > >                 .val_bits = 8,
> > >                 .read_flag_mask = 0xa0,
> > >                 .write_flag_mask = 0x20,
> > > -               .max_register = 0x1d,
> > >         };
> > >         struct regmap *regmap;
> > > +       const struct pcf21xx_config *variant;
> > > +
> > > +       if (spi->dev.of_node) {
> > > +               variant = of_device_get_match_data(&spi->dev);
> > > +               if (!variant)
> > > +                       return -ENODEV;
> > > +       } else {
> > > +               enum pcf21xx_type type = spi_get_device_id(spi)->driver_data;
> > > +
> > > +               if (type >= PCF21XX_LAST_ID)
> > > +                       return -ENODEV;
> > > +               variant = &pcf21xx_cfg[type];
> > > +       }
> > > +
> > > +       config.max_register = variant->max_register,
> > >
> > >         regmap = devm_regmap_init_spi(spi, &config);
> > >         if (IS_ERR(regmap)) {
> > > @@ -974,13 +1031,13 @@ static int pcf2127_spi_probe(struct spi_device *spi)
> > >
> > >         return pcf2127_probe(&spi->dev, regmap, spi->irq,
> > >                              pcf2127_spi_driver.driver.name,
> > > -                            spi_get_device_id(spi)->driver_data);
> > > +                            variant);
> > >  }
> > >
> > >  static const struct spi_device_id pcf2127_spi_id[] = {
> > > -       { "pcf2127", 1 },
> > > -       { "pcf2129", 0 },
> > > -       { "pca2129", 0 },
> > > +       { "pcf2127", PCF2127 },
> > > +       { "pcf2129", PCF2129 },
> > > +       { "pca2129", PCF2129 },
> > >         { }
> > >  };
> > >  MODULE_DEVICE_TABLE(spi, pcf2127_spi_id);
> > > --
> > > 2.30.2
> > >
> >
>
>
> --
> Hugo Villeneuve <hugo@hugovil.com>

  reply	other threads:[~2022-12-19 17:18 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-15 15:02 [PATCH v3 00/14] rtc: pcf2127: add PCF2131 driver Hugo Villeneuve
2022-12-15 15:02 ` [PATCH v3 01/14] rtc: pcf2127: add variant-specific configuration structure Hugo Villeneuve
2022-12-19  9:05   ` Bruno Thomsen
2022-12-19 15:15     ` Hugo Villeneuve
2022-12-19 17:17       ` Bruno Thomsen [this message]
2022-12-19 18:30         ` Hugo Villeneuve
2023-01-07 16:52   ` Bruno Thomsen
2022-12-15 15:02 ` [PATCH v3 02/14] rtc: pcf2127: adapt for time/date registers at any offset Hugo Villeneuve
2022-12-19  9:34   ` Bruno Thomsen
2022-12-19 16:27     ` Hugo Villeneuve
2023-01-07 16:49     ` Bruno Thomsen
2023-01-20 18:47   ` Alexandre Belloni
2023-01-23 15:54     ` Hugo Villeneuve
2023-06-21 18:18       ` Alexandre Belloni
2022-12-15 15:02 ` [PATCH v3 03/14] rtc: pcf2127: adapt for alarm " Hugo Villeneuve
2023-01-07 16:57   ` Bruno Thomsen
2023-01-20 17:10   ` Alexandre Belloni
2023-01-23 16:02     ` Hugo Villeneuve
2022-12-15 15:02 ` [PATCH v3 04/14] rtc: pcf2127: adapt for WD " Hugo Villeneuve
2023-01-07 16:59   ` Bruno Thomsen
2022-12-15 15:02 ` [PATCH v3 05/14] rtc: pcf2127: adapt for CLKOUT register " Hugo Villeneuve
2023-01-07 17:01   ` Bruno Thomsen
2022-12-15 15:02 ` [PATCH v3 06/14] rtc: pcf2127: add support for multiple TS functions Hugo Villeneuve
2023-01-07 17:58   ` Bruno Thomsen
2023-01-23 20:41     ` Hugo Villeneuve
2022-12-15 15:02 ` [PATCH v3 07/14] rtc: pcf2127: add support for PCF2131 RTC Hugo Villeneuve
2023-01-07 18:15   ` Bruno Thomsen
2023-01-23 19:06     ` Hugo Villeneuve
2023-01-20 18:57   ` Alexandre Belloni
2023-01-23 17:27     ` Hugo Villeneuve
2022-12-15 15:02 ` [PATCH v3 08/14] rtc: pcf2127: add support for PCF2131 interrupts on output INT_A Hugo Villeneuve
2023-01-07 18:17   ` Bruno Thomsen
2023-01-20 16:56   ` Alexandre Belloni
2023-01-23 20:52     ` Hugo Villeneuve
2023-05-11 17:19       ` Hugo Villeneuve
2023-06-21 19:24         ` Alexandre Belloni
2023-06-21 19:26           ` Alexandre Belloni
2023-06-22 14:21             ` Hugo Villeneuve
2022-12-15 15:02 ` [PATCH v3 09/14] rtc: pcf2127: set PWRMNG value for PCF2131 Hugo Villeneuve
2023-01-07 18:36   ` Bruno Thomsen
2023-01-20 16:39     ` Alexandre Belloni
2023-01-23 22:07       ` Hugo Villeneuve
2022-12-15 15:02 ` [PATCH v3 10/14] rtc: pcf2127: read and validate PCF2131 device signature Hugo Villeneuve
2023-01-20 17:01   ` Alexandre Belloni
2023-01-23 17:31     ` Hugo Villeneuve
2022-12-15 15:02 ` [PATCH v3 11/14] rtc: pcf2127: adapt time/date registers write sequence for PCF2131 Hugo Villeneuve
2023-01-07 18:44   ` Bruno Thomsen
2023-01-23 20:55     ` Hugo Villeneuve
2023-01-20 17:09   ` Alexandre Belloni
2023-01-23 21:57     ` Hugo Villeneuve
2023-06-21 19:36       ` Alexandre Belloni
2022-12-15 15:02 ` [PATCH v3 12/14] rtc: pcf2127: support generic watchdog timing configuration Hugo Villeneuve
2023-01-18 13:23   ` Philipp Rosenberger
2023-01-19 17:48     ` Hugo Villeneuve
2023-01-20  8:06       ` Philipp Rosenberger
2023-01-20 14:44         ` Hugo Villeneuve
2022-12-15 15:02 ` [PATCH v3 13/14] rtc: pcf2127: add flag for watchdog register value read support Hugo Villeneuve
2023-01-07 18:47   ` Bruno Thomsen
2022-12-15 15:02 ` [PATCH v3 14/14] dt-bindings: rtc: pcf2127: add PCF2131 Hugo Villeneuve
2022-12-16 13:24   ` Krzysztof Kozlowski
2022-12-19  9:14   ` Bruno Thomsen
2022-12-19 16:25     ` Hugo Villeneuve
2022-12-19 17:18       ` Bruno Thomsen
2022-12-19 18:31         ` Hugo Villeneuve
2023-01-20 19:05 ` [PATCH v3 00/14] rtc: pcf2127: add PCF2131 driver Alexandre Belloni
2023-01-23 15:51   ` Hugo Villeneuve
2023-06-21 14:14   ` Hugo Villeneuve
2023-06-21 16:59     ` Hugo Villeneuve
2023-06-21 18:14       ` Alexandre Belloni
2023-06-21 18:28         ` Hugo Villeneuve
2023-07-05 13:40           ` Hugo Villeneuve
2023-07-07 14:16             ` Alexandre Belloni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH+2xPC5MvrAiMOpjm8D2aeJEMmNJghMSg1zoeDb=DO-dBue7w@mail.gmail.com' \
    --to=bruno.thomsen@gmail.com \
    --cc=a.zummo@towertech.it \
    --cc=alexandre.belloni@bootlin.com \
    --cc=devicetree@vger.kernel.org \
    --cc=hugo@hugovil.com \
    --cc=hvilleneuve@dimonoff.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.