linux-rtc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/5] rtc: add new VL flag for backup switchover
@ 2020-05-05 20:13 Alexandre Belloni
  2020-05-05 20:13 ` [PATCH 2/5] rtc: pcf2127: let the core handle rtc range Alexandre Belloni
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Alexandre Belloni @ 2020-05-05 20:13 UTC (permalink / raw)
  To: linux-rtc
  Cc: Rasmus Villemoes, Per Nørgaard Christensen, linux-kernel,
	Alexandre Belloni

A new flag RTC_VL_BACKUP_SWITCH means that a backup switchover happened
since last flag clear.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 include/uapi/linux/rtc.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/uapi/linux/rtc.h b/include/uapi/linux/rtc.h
index 83bba58d47f4..fa9aff91cbf2 100644
--- a/include/uapi/linux/rtc.h
+++ b/include/uapi/linux/rtc.h
@@ -99,6 +99,7 @@ struct rtc_pll_info {
 #define RTC_VL_BACKUP_LOW	_BITUL(1) /* Backup voltage is low */
 #define RTC_VL_BACKUP_EMPTY	_BITUL(2) /* Backup empty or not present */
 #define RTC_VL_ACCURACY_LOW	_BITUL(3) /* Voltage is low, RTC accuracy is reduced */
+#define RTC_VL_BACKUP_SWITCH	_BITUL(4) /* Backup switchover happened */
 
 #define RTC_VL_READ	_IOR('p', 0x13, unsigned int)	/* Voltage low detection */
 #define RTC_VL_CLR	_IO('p', 0x14)		/* Clear voltage low information */
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/5] rtc: pcf2127: let the core handle rtc range
  2020-05-05 20:13 [PATCH 1/5] rtc: add new VL flag for backup switchover Alexandre Belloni
@ 2020-05-05 20:13 ` Alexandre Belloni
  2020-05-05 20:13 ` [PATCH 3/5] rtc: pcf2127: remove unnecessary #ifdef Alexandre Belloni
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Alexandre Belloni @ 2020-05-05 20:13 UTC (permalink / raw)
  To: linux-rtc
  Cc: Rasmus Villemoes, Per Nørgaard Christensen, linux-kernel,
	Alexandre Belloni

Let the core handle offsetting and windowing the RTC range.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/rtc/rtc-pcf2127.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c
index 4e50d6768f13..136709baaa88 100644
--- a/drivers/rtc/rtc-pcf2127.c
+++ b/drivers/rtc/rtc-pcf2127.c
@@ -137,8 +137,7 @@ static int pcf2127_rtc_read_time(struct device *dev, struct rtc_time *tm)
 	tm->tm_wday = buf[PCF2127_REG_DW] & 0x07;
 	tm->tm_mon = bcd2bin(buf[PCF2127_REG_MO] & 0x1F) - 1; /* rtc mn 1-12 */
 	tm->tm_year = bcd2bin(buf[PCF2127_REG_YR]);
-	if (tm->tm_year < 70)
-		tm->tm_year += 100;	/* assume we are in 1970...2069 */
+	tm->tm_year += 100;
 
 	dev_dbg(dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
 		"mday=%d, mon=%d, year=%d, wday=%d\n",
@@ -172,7 +171,7 @@ static int pcf2127_rtc_set_time(struct device *dev, struct rtc_time *tm)
 	buf[i++] = bin2bcd(tm->tm_mon + 1);
 
 	/* year */
-	buf[i++] = bin2bcd(tm->tm_year % 100);
+	buf[i++] = bin2bcd(tm->tm_year - 100);
 
 	/* write register's data */
 	err = regmap_bulk_write(pcf2127->regmap, PCF2127_REG_SC, buf, i);
@@ -433,6 +432,9 @@ static int pcf2127_probe(struct device *dev, struct regmap *regmap,
 		return PTR_ERR(pcf2127->rtc);
 
 	pcf2127->rtc->ops = &pcf2127_rtc_ops;
+	pcf2127->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
+	pcf2127->rtc->range_max = RTC_TIMESTAMP_END_2099;
+	pcf2127->rtc->set_start_time = true; /* Sets actual start to 1970 */
 
 	pcf2127->wdd.parent = dev;
 	pcf2127->wdd.info = &pcf2127_wdt_info;
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/5] rtc: pcf2127: remove unnecessary #ifdef
  2020-05-05 20:13 [PATCH 1/5] rtc: add new VL flag for backup switchover Alexandre Belloni
  2020-05-05 20:13 ` [PATCH 2/5] rtc: pcf2127: let the core handle rtc range Alexandre Belloni
@ 2020-05-05 20:13 ` Alexandre Belloni
  2020-05-05 20:13 ` [PATCH 4/5] rtc: pcf2127: set regmap max_register Alexandre Belloni
  2020-05-05 20:13 ` [PATCH 5/5] rtc: pcf2127: report battery switch over Alexandre Belloni
  3 siblings, 0 replies; 7+ messages in thread
From: Alexandre Belloni @ 2020-05-05 20:13 UTC (permalink / raw)
  To: linux-rtc
  Cc: Rasmus Villemoes, Per Nørgaard Christensen, linux-kernel,
	Alexandre Belloni

There is not point in setting .ioctl to NULL when CONFIG_RTC_INTF_DEV is
not defined because it would not be called anyway.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/rtc/rtc-pcf2127.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c
index 136709baaa88..5ac996578523 100644
--- a/drivers/rtc/rtc-pcf2127.c
+++ b/drivers/rtc/rtc-pcf2127.c
@@ -184,7 +184,6 @@ static int pcf2127_rtc_set_time(struct device *dev, struct rtc_time *tm)
 	return 0;
 }
 
-#ifdef CONFIG_RTC_INTF_DEV
 static int pcf2127_rtc_ioctl(struct device *dev,
 				unsigned int cmd, unsigned long arg)
 {
@@ -205,9 +204,6 @@ static int pcf2127_rtc_ioctl(struct device *dev,
 		return -ENOIOCTLCMD;
 	}
 }
-#else
-#define pcf2127_rtc_ioctl NULL
-#endif
 
 static const struct rtc_class_ops pcf2127_rtc_ops = {
 	.ioctl		= pcf2127_rtc_ioctl,
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/5] rtc: pcf2127: set regmap max_register
  2020-05-05 20:13 [PATCH 1/5] rtc: add new VL flag for backup switchover Alexandre Belloni
  2020-05-05 20:13 ` [PATCH 2/5] rtc: pcf2127: let the core handle rtc range Alexandre Belloni
  2020-05-05 20:13 ` [PATCH 3/5] rtc: pcf2127: remove unnecessary #ifdef Alexandre Belloni
@ 2020-05-05 20:13 ` Alexandre Belloni
  2020-05-05 20:13 ` [PATCH 5/5] rtc: pcf2127: report battery switch over Alexandre Belloni
  3 siblings, 0 replies; 7+ messages in thread
From: Alexandre Belloni @ 2020-05-05 20:13 UTC (permalink / raw)
  To: linux-rtc
  Cc: Rasmus Villemoes, Per Nørgaard Christensen, linux-kernel,
	Alexandre Belloni

Set regmap max_register to ease debugging and enforce the register range.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/rtc/rtc-pcf2127.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c
index 5ac996578523..039078029bd4 100644
--- a/drivers/rtc/rtc-pcf2127.c
+++ b/drivers/rtc/rtc-pcf2127.c
@@ -634,6 +634,7 @@ static int pcf2127_i2c_probe(struct i2c_client *client,
 	static const struct regmap_config config = {
 		.reg_bits = 8,
 		.val_bits = 8,
+		.max_register = 0x1d,
 	};
 
 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
@@ -701,6 +702,7 @@ static int pcf2127_spi_probe(struct spi_device *spi)
 		.val_bits = 8,
 		.read_flag_mask = 0xa0,
 		.write_flag_mask = 0x20,
+		.max_register = 0x1d,
 	};
 	struct regmap *regmap;
 
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 5/5] rtc: pcf2127: report battery switch over
  2020-05-05 20:13 [PATCH 1/5] rtc: add new VL flag for backup switchover Alexandre Belloni
                   ` (2 preceding siblings ...)
  2020-05-05 20:13 ` [PATCH 4/5] rtc: pcf2127: set regmap max_register Alexandre Belloni
@ 2020-05-05 20:13 ` Alexandre Belloni
  2020-05-05 21:30   ` Rasmus Villemoes
  3 siblings, 1 reply; 7+ messages in thread
From: Alexandre Belloni @ 2020-05-05 20:13 UTC (permalink / raw)
  To: linux-rtc
  Cc: Rasmus Villemoes, Per Nørgaard Christensen, linux-kernel,
	Alexandre Belloni

Add support for the RTC_VL_BACKUP_SWITCH flag to report battery switch over
events.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/rtc/rtc-pcf2127.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c
index 039078029bd4..967de68e1b03 100644
--- a/drivers/rtc/rtc-pcf2127.c
+++ b/drivers/rtc/rtc-pcf2127.c
@@ -188,18 +188,27 @@ static int pcf2127_rtc_ioctl(struct device *dev,
 				unsigned int cmd, unsigned long arg)
 {
 	struct pcf2127 *pcf2127 = dev_get_drvdata(dev);
-	int touser;
+	int val, touser = 0;
 	int ret;
 
 	switch (cmd) {
 	case RTC_VL_READ:
-		ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL3, &touser);
+		ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL3, &val);
 		if (ret)
 			return ret;
 
-		touser = touser & PCF2127_BIT_CTRL3_BLF ? RTC_VL_BACKUP_LOW : 0;
+		if (val & PCF2127_BIT_CTRL3_BLF)
+			touser = RTC_VL_BACKUP_LOW;
+
+		if (val & PCF2127_BIT_CTRL3_BF)
+			touser |= RTC_VL_BACKUP_SWITCH;
 
 		return put_user(touser, (unsigned int __user *)arg);
+
+	case RTC_VL_CLR:
+		return regmap_update_bits(pcf2127->regmap, PCF2127_REG_CTRL3,
+					  PCF2127_BIT_CTRL3_BF, 0);
+
 	default:
 		return -ENOIOCTLCMD;
 	}
@@ -493,7 +502,6 @@ static int pcf2127_probe(struct device *dev, struct regmap *regmap,
 	 */
 	ret = regmap_update_bits(pcf2127->regmap, PCF2127_REG_CTRL3,
 				 PCF2127_BIT_CTRL3_BTSE |
-				 PCF2127_BIT_CTRL3_BF |
 				 PCF2127_BIT_CTRL3_BIE |
 				 PCF2127_BIT_CTRL3_BLIE, 0);
 	if (ret) {
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 5/5] rtc: pcf2127: report battery switch over
  2020-05-05 20:13 ` [PATCH 5/5] rtc: pcf2127: report battery switch over Alexandre Belloni
@ 2020-05-05 21:30   ` Rasmus Villemoes
  2020-05-05 22:09     ` Alexandre Belloni
  0 siblings, 1 reply; 7+ messages in thread
From: Rasmus Villemoes @ 2020-05-05 21:30 UTC (permalink / raw)
  To: Alexandre Belloni, linux-rtc; +Cc: Per Nørgaard Christensen, linux-kernel

On 05/05/2020 22.13, Alexandre Belloni wrote:
> Add support for the RTC_VL_BACKUP_SWITCH flag to report battery switch over
> events.
> 
> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
> ---
>  drivers/rtc/rtc-pcf2127.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c
> index 039078029bd4..967de68e1b03 100644
> --- a/drivers/rtc/rtc-pcf2127.c
> +++ b/drivers/rtc/rtc-pcf2127.c
> @@ -188,18 +188,27 @@ static int pcf2127_rtc_ioctl(struct device *dev,
>  				unsigned int cmd, unsigned long arg)
>  {
>  	struct pcf2127 *pcf2127 = dev_get_drvdata(dev);
> -	int touser;
> +	int val, touser = 0;
>  	int ret;
>  
>  	switch (cmd) {
>  	case RTC_VL_READ:
> -		ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL3, &touser);
> +		ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL3, &val);
>  		if (ret)
>  			return ret;
>  
> -		touser = touser & PCF2127_BIT_CTRL3_BLF ? RTC_VL_BACKUP_LOW : 0;
> +		if (val & PCF2127_BIT_CTRL3_BLF)
> +			touser = RTC_VL_BACKUP_LOW;
> +
> +		if (val & PCF2127_BIT_CTRL3_BF)
> +			touser |= RTC_VL_BACKUP_SWITCH;

I think it's a bit easier to read if you use |= in both cases.

Re patch 3, one saves a little .text by eliding the ioctl function when,
as you say, it cannot be called anyway. No strong opinion either way, I
don't think anybody actually builds without CONFIG_RTC_INTF_DEV, but
those that do are probably the ones that care about having a tiny vmlinux.

Other than that, the series looks good to me.

Thanks,
Rasmus

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 5/5] rtc: pcf2127: report battery switch over
  2020-05-05 21:30   ` Rasmus Villemoes
@ 2020-05-05 22:09     ` Alexandre Belloni
  0 siblings, 0 replies; 7+ messages in thread
From: Alexandre Belloni @ 2020-05-05 22:09 UTC (permalink / raw)
  To: Rasmus Villemoes; +Cc: linux-rtc, Per Nørgaard Christensen, linux-kernel

On 05/05/2020 23:30:18+0200, Rasmus Villemoes wrote:
> On 05/05/2020 22.13, Alexandre Belloni wrote:
> > Add support for the RTC_VL_BACKUP_SWITCH flag to report battery switch over
> > events.
> > 
> > Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
> > ---
> >  drivers/rtc/rtc-pcf2127.c | 16 ++++++++++++----
> >  1 file changed, 12 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c
> > index 039078029bd4..967de68e1b03 100644
> > --- a/drivers/rtc/rtc-pcf2127.c
> > +++ b/drivers/rtc/rtc-pcf2127.c
> > @@ -188,18 +188,27 @@ static int pcf2127_rtc_ioctl(struct device *dev,
> >  				unsigned int cmd, unsigned long arg)
> >  {
> >  	struct pcf2127 *pcf2127 = dev_get_drvdata(dev);
> > -	int touser;
> > +	int val, touser = 0;
> >  	int ret;
> >  
> >  	switch (cmd) {
> >  	case RTC_VL_READ:
> > -		ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL3, &touser);
> > +		ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL3, &val);
> >  		if (ret)
> >  			return ret;
> >  
> > -		touser = touser & PCF2127_BIT_CTRL3_BLF ? RTC_VL_BACKUP_LOW : 0;
> > +		if (val & PCF2127_BIT_CTRL3_BLF)
> > +			touser = RTC_VL_BACKUP_LOW;
> > +
> > +		if (val & PCF2127_BIT_CTRL3_BF)
> > +			touser |= RTC_VL_BACKUP_SWITCH;
> 
> I think it's a bit easier to read if you use |= in both cases.
> 
> Re patch 3, one saves a little .text by eliding the ioctl function when,
> as you say, it cannot be called anyway. No strong opinion either way, I
> don't think anybody actually builds without CONFIG_RTC_INTF_DEV, but
> those that do are probably the ones that care about having a tiny vmlinux.
> 

Honestly, I don't think it is worth doing that. On armv7, this only
removes 248 bytes. Also, compiling without CONFIG_RTC_INTF_DEV simply
makes the RTC unusable. There are no tools actually using the sysfs
interface instead of the char device interface. I prefer keeping
CONFIG_RTC_INTF_DEV private to the core.

-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-05-05 22:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-05 20:13 [PATCH 1/5] rtc: add new VL flag for backup switchover Alexandre Belloni
2020-05-05 20:13 ` [PATCH 2/5] rtc: pcf2127: let the core handle rtc range Alexandre Belloni
2020-05-05 20:13 ` [PATCH 3/5] rtc: pcf2127: remove unnecessary #ifdef Alexandre Belloni
2020-05-05 20:13 ` [PATCH 4/5] rtc: pcf2127: set regmap max_register Alexandre Belloni
2020-05-05 20:13 ` [PATCH 5/5] rtc: pcf2127: report battery switch over Alexandre Belloni
2020-05-05 21:30   ` Rasmus Villemoes
2020-05-05 22:09     ` Alexandre Belloni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).