rtc: Unify RTC_VL_READ meaning
Alexandre Belloni
maintainercover rtc: Unify RTC_VL_READ meaning
Hi,
This series unifies the meaning of RTC_VL_READ by redefining it as a bitfield and defining the values of the various bits. This doesn't break compatibility with userspaceas long as the return value was used as a boolean, which should be the case.
The series also ensures RTC_VL_CLR doesn't clear the information when it is about the data being invalid so the following rtc reads will properly fail.
Alexandre Belloni (17):
rtc: define RTC_VL_READ values
rtc: Document RTC_VL_READ and RTC_VL_CLR ioctls
rtc: abx80x: return meaningful value for RTC_VL_READ
rtc: pcf2127: return meaningful value for RTC_VL_READ
rtc: pcf8523: return meaningful value for RTC_VL_READ
rtc: pcf8563: remove RTC_VL_CLR handling
rtc: pcf8563: remove conditional compilation
rtc: pcf8563: stop caching voltage_low
rtc: pcf8563: return meaningful value for RTC_VL_READ
rtc: pcf85063: remove RTC_VL_CLR handling
rtc: pcf85063: return meaningful value for RTC_VL_READ
rtc: rv3028: remove RTC_VL_CLR handling
rtc: rv3028: return meaningful value for RTC_VL_READ
rtc: rv8803: avoid clearing RV8803_FLAG_V2F in RTC_VL_CLR
rtc: rv8803: return meaningful value for RTC_VL_READ
rtc: rx8010: remove RTC_VL_CLR handling
rtc: rx8010: return meaningful value for RTC_VL_READ
Documentation/ABI/testing/rtc-cdev | 8 +++++++ drivers/rtc/rtc-abx80x.c | 7 ++---- drivers/rtc/rtc-pcf2127.c | 6 ++--- drivers/rtc/rtc-pcf85063.c | 16 ++----------- drivers/rtc/rtc-pcf8523.c | 6 ++--- drivers/rtc/rtc-pcf8563.c | 36 ++++++------------------------ drivers/rtc/rtc-rv3028.c | 17 ++------------ drivers/rtc/rtc-rv8803.c | 16 ++++++------- drivers/rtc/rtc-rx8010.c | 23 +++---------------- include/uapi/linux/rtc.h | 7 +++++- 10 files changed, 42 insertions(+), 100 deletions(-)
Signature · 1 line
2.23.0
Alexandre Belloni
maintainerPATCH 1/17 rtc: define RTC_VL_READ values
Currently, the meaning of the value returned by RTC_VL_READ is undocumented and left to the driver implementation. In order to get more meaningful values, define a set of values to use as to make clear to userspace what is the status of the various voltages feeding the RTC.
--- include/uapi/linux/rtc.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
include/uapi/linux/rtc.h +6 -1
@@ -92,7 +92,12 @@ struct rtc_pll_info {#define RTC_PLL_GET _IOR('p', 0x11, struct rtc_pll_info)/* Get PLL correction */ #define RTC_PLL_SET _IOW('p', 0x12, struct rtc_pll_info)/* Set PLL correction */ -#define RTC_VL_READ _IOR('p', 0x13, int)/* Voltage low detector */ +#define RTC_VL_DATA_INVALID BIT(0)/* Voltage too low, RTC data is invalid */ +#define RTC_VL_BACKUP_LOW BIT(1)/* Backup voltage is low */ +#define RTC_VL_BACKUP_EMPTY BIT(2)/* Backup empty or not present */ +#define RTC_VL_ACCURACY_LOW BIT(3)/* Voltage is low, RTC accuracy is reduced */ + +#define RTC_VL_READ _IOR('p', 0x13, unsigned int)/* Voltage low detection */ #define RTC_VL_CLR _IO('p', 0x14)/* Clear voltage low information */ /* interrupt flags */
Signature · 1 line
2.23.0
Alexandre Belloni
maintainerPATCH 2/17 rtc: Document RTC_VL_READ and RTC_VL_CLR ioctls
In reply to Alexandre BelloniRTC_VL_READ and RTC_VL_CLR have been introduced in 2012 with commit 0f20b767e20a ("drivers/rtc/rtc-pcf8563.c: add RTC_VL_READ/RTC_VL_CLR ioctl feature")
Document them now that they have been unified.
--- Documentation/ABI/testing/rtc-cdev | 8 ++++++++ 1 file changed, 8 insertions(+)
Documentation/ABI/testing/rtc-cdev +8 -0
@@ -33,6 +33,14 @@ Description: Requires a separate RTC_PIE_ON call to enable the periodic interrupts. + * RTC_VL_READ: Read the voltage inputs status of the RTC when + supported. The value is a bit field of RTC_VL_*, giving the + status of the main and backup voltages. + + * RTC_VL_CLEAR: Clear the voltage status of the RTC. Some RTCs + need user interaction when the backup power provider is + replaced or charged to be able to clear the status. + The ioctl() calls supported by the older /dev/rtc interface are also supported by the newer RTC class framework. However, because the chips and systems are not standardized, some PC/AT
Signature · 1 line
2.23.0
Alexandre Belloni
maintainerPATCH 3/17 rtc: abx80x: return meaningful value for RTC_VL_READ
In reply to Alexandre BelloniABX8XX_STATUS_BLF indicates the battery is low and needs to be replaced soon.
--- drivers/rtc/rtc-abx80x.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/rtc/rtc-abx80x.c +2 -5
@@ -523,12 +523,9 @@ static int abx80x_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)if (status <0 )return status; - tmp = !!(status &ABX8XX_STATUS_BLF ); + tmp = status &ABX8XX_STATUS_BLF ?RTC_VL_BACKUP_LOW :0 ; -if (copy_to_user ((void __user *)arg, &tmp,sizeof (int ))) -return -EFAULT ; - -return 0 ; +return put_user (tmp, (unsigned int __user *)arg);case RTC_VL_CLR : status =i2c_smbus_read_byte_data (client,ABX8XX_REG_STATUS );
Signature · 1 line
2.23.0
Alexandre Belloni
maintainerPATCH 4/17 rtc: pcf2127: return meaningful value for RTC_VL_READ
In reply to Alexandre BelloniPCF2127_BIT_CTRL3_BLF indicates the battery is low and needs to be replaced soon.
--- drivers/rtc/rtc-pcf2127.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/rtc/rtc-pcf2127.c +2 -4
@@ -197,11 +197,9 @@ static int pcf2127_rtc_ioctl(struct device *dev,if (ret)return ret; - touser = touser &PCF2127_BIT_CTRL3_BLF ?1 :0 ; + touser = touser &PCF2127_BIT_CTRL3_BLF ?RTC_VL_BACKUP_LOW :0 ; -if (copy_to_user ((void __user *)arg, &touser,sizeof (int ))) -return -EFAULT ; -return 0 ; +return put_user (touser, (unsigned int __user *)arg);default :return -ENOIOCTLCMD ; }
Signature · 1 line
2.23.0
Alexandre Belloni
maintainerPATCH 5/17 rtc: pcf8523: return meaningful value for RTC_VL_READ
In reply to Alexandre BelloniREG_CONTROL3_BLF indicates the battery is low and needs to be replaced soon.
--- drivers/rtc/rtc-pcf8523.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/rtc/rtc-pcf8523.c +3 -3
@@ -282,11 +282,11 @@ static int pcf8523_rtc_ioctl(struct device *dev, unsigned int cmd, ret =pcf8523_voltage_low (client);if (ret <0 )return ret; +if (ret) + ret =RTC_VL_BACKUP_LOW ; -if (copy_to_user ((void __user *)arg, &ret,sizeof (int ))) -return -EFAULT ; +return put_user (ret, (unsigned int __user *)arg); -return 0 ;default :return -ENOIOCTLCMD ; }
Signature · 1 line
2.23.0
Alexandre Belloni
maintainerPATCH 6/17 rtc: pcf8563: remove RTC_VL_CLR handling
In reply to Alexandre BelloniRemove RTC_VL_CLR handling because it is a disservice to userspace as it removes the important information that the RTC data is invalid. This may lead userspace to set an invalid system time later on.
--- drivers/rtc/rtc-pcf8563.c | 15 --------------- 1 file changed, 15 deletions(-)
drivers/rtc/rtc-pcf8563.c +0 -15
@@ -291,21 +291,6 @@ static int pcf8563_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long sizeof(int)))return -EFAULT ;return 0 ; -case RTC_VL_CLR : -/* -* Clear the VL bit in the seconds register in case -* the time has not been set already (which would -* have cleared it). This does not really matter -* because of the cached voltage_low value but do it -* anyway for consistency. -*/ -if (pcf8563_rtc_read_time (dev, &tm)) -pcf8563_rtc_set_time (dev, &tm); - -/* Clear the cached value. */ - pcf8563->voltage_low =0 ; - -return 0 ;default :return -ENOIOCTLCMD ; }
Signature · 1 line
2.23.0
Alexandre Belloni
maintainerPATCH 7/17 rtc: pcf8563: remove conditional compilation
In reply to Alexandre BelloniAlways compile pcf8563_rtc_ioctl as we are sure that CONFIG_RTC_INTF_DEV is selected on actual kernel configurations.
--- drivers/rtc/rtc-pcf8563.c | 5 ----- 1 file changed, 5 deletions(-)
drivers/rtc/rtc-pcf8563.c +0 -5
@@ -276,11 +276,9 @@ static int pcf8563_rtc_set_time(struct device *dev, struct rtc_time *tm) 9 - PCF8563_REG_SC, buf + PCF8563_REG_SC); } -#ifdef CONFIG_RTC_INTF_DEV static int pcf8563_rtc_ioctl (struct device *dev,unsigned int cmd,unsigned long arg) {struct pcf8563 *pcf8563 =i2c_get_clientdata (to_i2c_client (dev)); -struct rtc_time tm;switch (cmd) {case RTC_VL_READ :
@@ -295,9 +293,6 @@ static int pcf8563_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned longreturn -ENOIOCTLCMD ; } } -#else -#define pcf8563_rtc_ioctl NULL -#endif static int pcf8563_rtc_read_alarm (struct device *dev,struct rtc_wkalrm *tm) {
Signature · 1 line
2.23.0
Alexandre Belloni
maintainerPATCH 8/17 rtc: pcf8563: stop caching voltage_low
In reply to Alexandre Bellonivoltage_low is only updated when reading the time, this means that using RTC_VL_READ will miss the VL flag if the time has not been read before using the ioctl. Always read the status from the hardware.
--- drivers/rtc/rtc-pcf8563.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/rtc/rtc-pcf8563.c +9 -7
@@ -76,7 +76,6 @@ struct pcf8563 {* 1970...2069. */ int c_polarity;/* 0: MO_C=1 means 19xx, otherwise MO_C=1 means 20xx */ -int voltage_low;/* incicates if a low_voltage was detected */ struct i2c_client *client;#ifdef CONFIG_COMMON_CLK
@@ -208,7 +207,6 @@ static int pcf8563_rtc_read_time(struct device *dev, struct rtc_time *tm)return err;if (buf[PCF8563_REG_SC ] &PCF8563_SC_LV ) { - pcf8563->voltage_low =1 ;dev_err (&client->dev,"low voltage detected, date/time is not reliable.\n" );return -EINVAL ;
@@ -278,15 +276,19 @@ static int pcf8563_rtc_set_time(struct device *dev, struct rtc_time *tm)static int pcf8563_rtc_ioctl (struct device *dev,unsigned int cmd,unsigned long arg) { -struct pcf8563 *pcf8563 =i2c_get_clientdata (to_i2c_client (dev)); +struct i2c_client *client =to_i2c_client (dev); +int vl, ret;switch (cmd) {case RTC_VL_READ : -if (pcf8563->voltage_low) -dev_info (dev,"low voltage detected, date/time is not reliable.\n" ); -if (copy_to_user ((void __user *)arg, &pcf8563->voltage_low, -sizeof (int ))) + ret =i2c_smbus_read_byte_data (client,PCF8563_REG_SC ); +if (ret <0 ) +return ret; + + vl = ret &PCF8563_SC_LV ?1 :0 ; + +if (copy_to_user ((void __user *)arg, &vl,sizeof (int )))return -EFAULT ;return 0 ;default :
Signature · 1 line
2.23.0
Alexandre Belloni
maintainerPATCH 9/17 rtc: pcf8563: return meaningful value for RTC_VL_READ
In reply to Alexandre BelloniPCF8563_SC_LV means the voltage dropped too low and data has been lost.
--- drivers/rtc/rtc-pcf8563.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/rtc/rtc-pcf8563.c +3 -7
@@ -277,20 +277,16 @@ static int pcf8563_rtc_set_time(struct device *dev, struct rtc_time *tm)static int pcf8563_rtc_ioctl (struct device *dev,unsigned int cmd,unsigned long arg) {struct i2c_client *client =to_i2c_client (dev); -int vl, ret; +int ret;switch (cmd) {case RTC_VL_READ : - ret =i2c_smbus_read_byte_data (client,PCF8563_REG_SC );if (ret <0 )return ret; - vl = ret &PCF8563_SC_LV ?1 :0 ; - -if (copy_to_user ((void __user *)arg, &vl,sizeof (int ))) -return -EFAULT ; -return 0 ; +return put_user (ret &PCF8563_SC_LV ?RTC_VL_DATA_INVALID :0 , + (unsigned int __user *)arg);default :return -ENOIOCTLCMD ; }
Signature · 1 line
2.23.0
Alexandre Belloni
maintainerPATCH 10/17 rtc: pcf85063: remove RTC_VL_CLR handling
In reply to Alexandre BelloniRemove RTC_VL_CLR handling because it is a disservice to userspace as it removes the important information that the RTC data is invalid. This may lead userspace to set an invalid system time later on.
--- drivers/rtc/rtc-pcf85063.c | 6 ------ 1 file changed, 6 deletions(-)
drivers/rtc/rtc-pcf85063.c +0 -6
@@ -299,12 +299,6 @@ static int pcf85063_ioctl(struct device *dev, unsigned int cmd,return 0 ; -case RTC_VL_CLR : - ret =regmap_update_bits (pcf85063->regmap,PCF85063_REG_SC , -PCF85063_REG_SC_OS ,0 ); - -return ret; -default :return -ENOIOCTLCMD ; }
Signature · 1 line
2.23.0
Alexandre Belloni
maintainerPATCH 11/17 rtc: pcf85063: return meaningful value for RTC_VL_READ
In reply to Alexandre BelloniPCF85063_REG_SC_OS means the voltage dropped too low and data has been lost.
--- drivers/rtc/rtc-pcf85063.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/rtc/rtc-pcf85063.c +2 -8
@@ -289,15 +289,9 @@ static int pcf85063_ioctl(struct device *dev, unsigned int cmd,if (ret <0 )return ret; -if (status &PCF85063_REG_SC_OS ) -dev_warn (&pcf85063->rtc->dev,"Voltage low, data loss detected.\n" ); + status = status &PCF85063_REG_SC_OS ?RTC_VL_DATA_INVALID :0 ; - status &=PCF85063_REG_SC_OS ; - -if (copy_to_user ((void __user *)arg, &status,sizeof (int ))) -return -EFAULT ; - -return 0 ; +return put_user (status, (unsigned int __user *)arg);default :return -ENOIOCTLCMD ;
Signature · 1 line
2.23.0
Alexandre Belloni
maintainerPATCH 12/17 rtc: rv3028: remove RTC_VL_CLR handling
In reply to Alexandre BelloniRemove RTC_VL_CLR handling because it is a disservice to userspace as it removes the important information that the RTC data is invalid. This may lead userspace to set an invalid system time later on.
--- drivers/rtc/rtc-rv3028.c | 6 ------ 1 file changed, 6 deletions(-)
drivers/rtc/rtc-rv3028.c +0 -6
@@ -438,12 +438,6 @@ static int rv3028_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)return 0 ; -case RTC_VL_CLR : - ret =regmap_update_bits (rv3028->regmap,RV3028_STATUS , -RV3028_STATUS_PORF ,0 ); - -return ret; -default :return -ENOIOCTLCMD ; }
Signature · 1 line
2.23.0
Alexandre Belloni
maintainerPATCH 13/17 rtc: rv3028: return meaningful value for RTC_VL_READ
In reply to Alexandre BelloniRV3028_STATUS_PORF means the voltage dropped too low and data has been lost.
--- drivers/rtc/rtc-rv3028.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/rtc/rtc-rv3028.c +2 -9
@@ -428,15 +428,8 @@ static int rv3028_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)if (ret <0 )return ret; -if (status &RV3028_STATUS_PORF ) -dev_warn (&rv3028->rtc->dev,"Voltage low, data loss detected.\n" ); - - status &=RV3028_STATUS_PORF ; - -if (copy_to_user ((void __user *)arg, &status,sizeof (int ))) -return -EFAULT ; - -return 0 ; + status = status &RV3028_STATUS_PORF ?RTC_VL_DATA_INVALID :0 ; +return put_user (status, (unsigned int __user *)arg);default :return -ENOIOCTLCMD ;
Signature · 1 line
2.23.0
Alexandre Belloni
maintainerPATCH 14/17 rtc: rv8803: avoid clearing RV8803_FLAG_V2F in RTC_VL_CLR
In reply to Alexandre BelloniStop clearing RV8803_FLAG_V2F in RTC_VL_CLR because it is a disservice to userspace as it removes the important information that the RTC data is invalid. This may lead userspace to set an invalid system time later on.
--- drivers/rtc/rtc-rv8803.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/rtc/rtc-rv8803.c +1 -1
@@ -440,7 +440,7 @@ static int rv8803_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)return flags; } - flags &= ~(RV8803_FLAG_V1F |RV8803_FLAG_V2F ); + flags &= ~RV8803_FLAG_V1F ; ret =rv8803_write_reg (client,RV8803_FLAG , flags);mutex_unlock (&rv8803->flags_lock);if (ret)
Signature · 1 line
2.23.0
Alexandre Belloni
maintainerPATCH 15/17 rtc: rv8803: return meaningful value for RTC_VL_READ
In reply to Alexandre BelloniRV8803_FLAG_V1F means the voltage is too low to keep the temperature compensation running and the accuracy of the RTC is affected.
RV8803_FLAG_V2F means the voltage dropped so low that data is now invalid.
--- drivers/rtc/rtc-rv8803.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/rtc/rtc-rv8803.c +6 -8
@@ -411,6 +411,7 @@ static int rv8803_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) {struct i2c_client *client =to_i2c_client (dev);struct rv8803_data *rv8803 =dev_get_drvdata (dev); +unsigned int vl =0 ;int flags, ret =0 ;switch (cmd) {
@@ -419,18 +420,15 @@ static int rv8803_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)if (flags <0 )return flags; -if (flags &RV8803_FLAG_V1F ) +if (flags &RV8803_FLAG_V1F ) {dev_warn (&client->dev,"Voltage low, temperature compensation stopped.\n" ); + vl =RTC_VL_ACCURACY_LOW ; + }if (flags &RV8803_FLAG_V2F ) -dev_warn (&client->dev,"Voltage low, data loss detected.\n" ); - - flags &=RV8803_FLAG_V1F |RV8803_FLAG_V2F ; + vl |=RTC_VL_DATA_INVALID ; -if (copy_to_user ((void __user *)arg, &flags,sizeof (int ))) -return -EFAULT ; - -return 0 ; +return put_user (vl, (unsigned int __user *)arg);case RTC_VL_CLR :mutex_lock (&rv8803->flags_lock);
Signature · 1 line
2.23.0
Alexandre Belloni
maintainerPATCH 16/17 rtc: rx8010: remove RTC_VL_CLR handling
In reply to Alexandre BelloniRemove RTC_VL_CLR handling because it is a disservice to userspace as it removes the important information that the RTC data is invalid. This may lead userspace to set an invalid system time later on.
--- drivers/rtc/rtc-rx8010.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-)
drivers/rtc/rtc-rx8010.c +1 -15
@@ -389,9 +389,8 @@ static int rx8010_alarm_irq_enable(struct device *dev,static int rx8010_ioctl (struct device *dev,unsigned int cmd,unsigned long arg) { -struct i2c_client *client =to_i2c_client (dev);struct rx8010_data *rx8010 =dev_get_drvdata (dev); -int ret, tmp; +int tmp;int flagreg;switch (cmd) {
@@ -406,19 +405,6 @@ static int rx8010_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)return 0 ; -case RTC_VL_CLR : - flagreg =i2c_smbus_read_byte_data (rx8010->client,RX8010_FLAG ); -if (flagreg <0 ) { -return flagreg; - } - - flagreg &= ~RX8010_FLAG_VLF ; - ret =i2c_smbus_write_byte_data (client,RX8010_FLAG , flagreg); -if (ret <0 ) -return ret; - -return 0 ; -default :return -ENOIOCTLCMD ; }
Signature · 1 line
2.23.0
Alexandre Belloni
maintainerPATCH 17/17 rtc: rx8010: return meaningful value for RTC_VL_READ
In reply to Alexandre BelloniRX8010_FLAG_VLF means the voltage dropped too low and data has been lost.
--- drivers/rtc/rtc-rx8010.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/rtc/rtc-rx8010.c +2 -5
@@ -399,11 +399,8 @@ static int rx8010_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)if (flagreg <0 )return flagreg; - tmp = !!(flagreg &RX8010_FLAG_VLF ); -if (copy_to_user ((void __user *)arg, &tmp,sizeof (int ))) -return -EFAULT ; - -return 0 ; + tmp = flagreg &RX8010_FLAG_VLF ?RTC_VL_DATA_INVALID :0 ; +return put_user (tmp, (unsigned int __user *)arg);default :return -ENOIOCTLCMD ;
Signature · 1 line
2.23.0