From: Hugo Villeneuve <[email protected]>
Default PWRMNG[2:0] bits are set to 000b for PCF2127/29, but to
111b for PCF2131.
Set these bits to 000b to select same mode as PCF2127/29.
Signed-off-by: Hugo Villeneuve <[email protected]>
---
drivers/rtc/rtc-pcf2127.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c
index 68af4d0438b8..241189ee4a05 100644
--- a/drivers/rtc/rtc-pcf2127.c
+++ b/drivers/rtc/rtc-pcf2127.c
@@ -53,6 +53,7 @@
#define PCF2127_BIT_CTRL3_BLF BIT(2)
#define PCF2127_BIT_CTRL3_BF BIT(3)
#define PCF2127_BIT_CTRL3_BTSE BIT(4)
+#define PCF2127_CTRL3_PWRMNG_MASK GENMASK(7, 5)
/* Control register 4 */
#define PCF2131_REG_CTRL4 0x03
#define PCF2131_BIT_CTRL4_TSF4 BIT(4)
@@ -1129,6 +1130,20 @@ static int pcf2127_probe(struct device *dev, struct regmap *regmap,
regmap_clear_bits(pcf2127->regmap, PCF2127_REG_CTRL1,
PCF2127_BIT_CTRL1_POR_OVRD);
+ /* Make sure PWRMNG[2:0] is set to 000b. This is the default for
+ * PCF2127/29, but not for PCF2131 (default of 111b).
+ *
+ * PWRMNG[2:0] = 000b:
+ * battery switch-over function is enabled in standard mode;
+ * battery low detection function is enabled
+ */
+ ret = regmap_clear_bits(pcf2127->regmap, PCF2127_REG_CTRL3,
+ PCF2127_CTRL3_PWRMNG_MASK);
+ if (ret < 0) {
+ dev_err(dev, "PWRMNG config failed\n");
+ return ret;
+ }
+
ret = regmap_read(pcf2127->regmap, pcf2127->cfg->reg_clkout, &val);
if (ret < 0)
return ret;
--
2.30.2
Den tor. 15. dec. 2022 kl. 16.19 skrev Hugo Villeneuve <[email protected]>:
>
> From: Hugo Villeneuve <[email protected]>
>
> Default PWRMNG[2:0] bits are set to 000b for PCF2127/29, but to
> 111b for PCF2131.
>
> Set these bits to 000b to select same mode as PCF2127/29.
>
> Signed-off-by: Hugo Villeneuve <[email protected]>
Reviewed-by: Bruno Thomsen <[email protected]>
I think it's a good idea[1] but there have been concerns about
setting default values in the past[2]. In case somebody needs
a different behaviour they should add a device tree property.
[1] https://lore.kernel.org/linux-rtc/[email protected]/
[2] https://lore.kernel.org/linux-rtc/[email protected]/
> ---
> drivers/rtc/rtc-pcf2127.c | 15 +++++++++++++++
> 1 file changed, 15 insertions(+)
>
> diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c
> index 68af4d0438b8..241189ee4a05 100644
> --- a/drivers/rtc/rtc-pcf2127.c
> +++ b/drivers/rtc/rtc-pcf2127.c
> @@ -53,6 +53,7 @@
> #define PCF2127_BIT_CTRL3_BLF BIT(2)
> #define PCF2127_BIT_CTRL3_BF BIT(3)
> #define PCF2127_BIT_CTRL3_BTSE BIT(4)
> +#define PCF2127_CTRL3_PWRMNG_MASK GENMASK(7, 5)
> /* Control register 4 */
> #define PCF2131_REG_CTRL4 0x03
> #define PCF2131_BIT_CTRL4_TSF4 BIT(4)
> @@ -1129,6 +1130,20 @@ static int pcf2127_probe(struct device *dev, struct regmap *regmap,
> regmap_clear_bits(pcf2127->regmap, PCF2127_REG_CTRL1,
> PCF2127_BIT_CTRL1_POR_OVRD);
>
> + /* Make sure PWRMNG[2:0] is set to 000b. This is the default for
> + * PCF2127/29, but not for PCF2131 (default of 111b).
> + *
> + * PWRMNG[2:0] = 000b:
> + * battery switch-over function is enabled in standard mode;
> + * battery low detection function is enabled
> + */
> + ret = regmap_clear_bits(pcf2127->regmap, PCF2127_REG_CTRL3,
> + PCF2127_CTRL3_PWRMNG_MASK);
> + if (ret < 0) {
> + dev_err(dev, "PWRMNG config failed\n");
> + return ret;
> + }
> +
> ret = regmap_read(pcf2127->regmap, pcf2127->cfg->reg_clkout, &val);
> if (ret < 0)
> return ret;
> --
> 2.30.2
>
Hello,
On 07/01/2023 19:36:06+0100, Bruno Thomsen wrote:
> Den tor. 15. dec. 2022 kl. 16.19 skrev Hugo Villeneuve <[email protected]>:
> >
> > From: Hugo Villeneuve <[email protected]>
> >
> > Default PWRMNG[2:0] bits are set to 000b for PCF2127/29, but to
> > 111b for PCF2131.
> >
> > Set these bits to 000b to select same mode as PCF2127/29.
> >
> > Signed-off-by: Hugo Villeneuve <[email protected]>
>
> Reviewed-by: Bruno Thomsen <[email protected]>
>
> I think it's a good idea[1] but there have been concerns about
> setting default values in the past[2]. In case somebody needs
> a different behaviour they should add a device tree property.
>
> [1] https://lore.kernel.org/linux-rtc/[email protected]/
> [2] https://lore.kernel.org/linux-rtc/[email protected]/
I confirm this is still my point of view and I won't take this patch as
this may break existing users.
>
> > ---
> > drivers/rtc/rtc-pcf2127.c | 15 +++++++++++++++
> > 1 file changed, 15 insertions(+)
> >
> > diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c
> > index 68af4d0438b8..241189ee4a05 100644
> > --- a/drivers/rtc/rtc-pcf2127.c
> > +++ b/drivers/rtc/rtc-pcf2127.c
> > @@ -53,6 +53,7 @@
> > #define PCF2127_BIT_CTRL3_BLF BIT(2)
> > #define PCF2127_BIT_CTRL3_BF BIT(3)
> > #define PCF2127_BIT_CTRL3_BTSE BIT(4)
> > +#define PCF2127_CTRL3_PWRMNG_MASK GENMASK(7, 5)
> > /* Control register 4 */
> > #define PCF2131_REG_CTRL4 0x03
> > #define PCF2131_BIT_CTRL4_TSF4 BIT(4)
> > @@ -1129,6 +1130,20 @@ static int pcf2127_probe(struct device *dev, struct regmap *regmap,
> > regmap_clear_bits(pcf2127->regmap, PCF2127_REG_CTRL1,
> > PCF2127_BIT_CTRL1_POR_OVRD);
> >
> > + /* Make sure PWRMNG[2:0] is set to 000b. This is the default for
> > + * PCF2127/29, but not for PCF2131 (default of 111b).
> > + *
> > + * PWRMNG[2:0] = 000b:
> > + * battery switch-over function is enabled in standard mode;
> > + * battery low detection function is enabled
> > + */
> > + ret = regmap_clear_bits(pcf2127->regmap, PCF2127_REG_CTRL3,
> > + PCF2127_CTRL3_PWRMNG_MASK);
> > + if (ret < 0) {
> > + dev_err(dev, "PWRMNG config failed\n");
> > + return ret;
> > + }
> > +
> > ret = regmap_read(pcf2127->regmap, pcf2127->cfg->reg_clkout, &val);
> > if (ret < 0)
> > return ret;
> > --
> > 2.30.2
> >
--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
On Fri, 20 Jan 2023 17:39:17 +0100
Alexandre Belloni <[email protected]> wrote:
> Hello,
>
> On 07/01/2023 19:36:06+0100, Bruno Thomsen wrote:
> > Den tor. 15. dec. 2022 kl. 16.19 skrev Hugo Villeneuve <[email protected]>:
> > >
> > > From: Hugo Villeneuve <[email protected]>
> > >
> > > Default PWRMNG[2:0] bits are set to 000b for PCF2127/29, but to
> > > 111b for PCF2131.
> > >
> > > Set these bits to 000b to select same mode as PCF2127/29.
> > >
> > > Signed-off-by: Hugo Villeneuve <[email protected]>
> >
> > Reviewed-by: Bruno Thomsen <[email protected]>
> >
> > I think it's a good idea[1] but there have been concerns about
> > setting default values in the past[2]. In case somebody needs
> > a different behaviour they should add a device tree property.
> >
> > [1] https://lore.kernel.org/linux-rtc/[email protected]/
> > [2] https://lore.kernel.org/linux-rtc/[email protected]/
>
> I confirm this is still my point of view and I won't take this patch as
> this may break existing users.
Patch dropped.
> >
> > > ---
> > > drivers/rtc/rtc-pcf2127.c | 15 +++++++++++++++
> > > 1 file changed, 15 insertions(+)
> > >
> > > diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c
> > > index 68af4d0438b8..241189ee4a05 100644
> > > --- a/drivers/rtc/rtc-pcf2127.c
> > > +++ b/drivers/rtc/rtc-pcf2127.c
> > > @@ -53,6 +53,7 @@
> > > #define PCF2127_BIT_CTRL3_BLF BIT(2)
> > > #define PCF2127_BIT_CTRL3_BF BIT(3)
> > > #define PCF2127_BIT_CTRL3_BTSE BIT(4)
> > > +#define PCF2127_CTRL3_PWRMNG_MASK GENMASK(7, 5)
> > > /* Control register 4 */
> > > #define PCF2131_REG_CTRL4 0x03
> > > #define PCF2131_BIT_CTRL4_TSF4 BIT(4)
> > > @@ -1129,6 +1130,20 @@ static int pcf2127_probe(struct device *dev, struct regmap *regmap,
> > > regmap_clear_bits(pcf2127->regmap, PCF2127_REG_CTRL1,
> > > PCF2127_BIT_CTRL1_POR_OVRD);
> > >
> > > + /* Make sure PWRMNG[2:0] is set to 000b. This is the default for
> > > + * PCF2127/29, but not for PCF2131 (default of 111b).
> > > + *
> > > + * PWRMNG[2:0] = 000b:
> > > + * battery switch-over function is enabled in standard mode;
> > > + * battery low detection function is enabled
> > > + */
> > > + ret = regmap_clear_bits(pcf2127->regmap, PCF2127_REG_CTRL3,
> > > + PCF2127_CTRL3_PWRMNG_MASK);
> > > + if (ret < 0) {
> > > + dev_err(dev, "PWRMNG config failed\n");
> > > + return ret;
> > > + }
> > > +
> > > ret = regmap_read(pcf2127->regmap, pcf2127->cfg->reg_clkout, &val);
> > > if (ret < 0)
> > > return ret;
> > > --
> > > 2.30.2
> > >
>
> --
> Alexandre Belloni, co-owner and COO, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com
>
--
Hugo Villeneuve <[email protected]>