drivers/rtc/rtc-pcf2127.c | 81 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+)
From: Alexandre Belloni <alexandre.belloni@bootlin.com>
The pcf2127 encodes BSM, BLD and power fail detection in the same set of
bits so it is necessary to do some calculation when changing BSM to keep
the rest of the configuration as-is. However, when BSM is disabled, there
is no configuration with BLD enabled so this will be lost when coming back
to a mode with BSM enabled.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
drivers/rtc/rtc-pcf2127.c | 81 +++++++++++++++++++++++++++++++++++++++
1 file changed, 81 insertions(+)
diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c
index 9c04c4e1a49c..a7f73192d53d 100644
--- a/drivers/rtc/rtc-pcf2127.c
+++ b/drivers/rtc/rtc-pcf2127.c
@@ -48,6 +48,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_PM GENMASK(7, 5)
/* Time and date registers */
#define PCF2127_REG_TIME_BASE 0x03
#define PCF2127_BIT_SC_OSF BIT(7)
@@ -331,6 +332,84 @@ static int pcf2127_rtc_set_time(struct device *dev, struct rtc_time *tm)
return 0;
}
+static int pcf2127_param_get(struct device *dev, struct rtc_param *param)
+{
+ struct pcf2127 *pcf2127 = dev_get_drvdata(dev);
+ u32 value;
+ int ret;
+
+ switch (param->param) {
+ case RTC_PARAM_BACKUP_SWITCH_MODE:
+ ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL3, &value);
+ if (ret < 0)
+ return ret;
+
+ value = FIELD_GET(PCF2127_CTRL3_PM, value);
+
+ if (value < 0x3)
+ param->uvalue = RTC_BSM_LEVEL;
+ else if (value < 0x6)
+ param->uvalue = RTC_BSM_DIRECT;
+ else
+ param->uvalue = RTC_BSM_DISABLED;
+
+ break;
+
+ default:
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int pcf2127_param_set(struct device *dev, struct rtc_param *param)
+{
+ struct pcf2127 *pcf2127 = dev_get_drvdata(dev);
+ u8 mode = 0;
+ u32 value;
+ int ret;
+
+ switch (param->param) {
+ case RTC_PARAM_BACKUP_SWITCH_MODE:
+ ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL3, &value);
+ if (ret < 0)
+ return ret;
+
+ value = FIELD_GET(PCF2127_CTRL3_PM, value);
+
+ if (value > 5)
+ value -= 5;
+ else if (value > 2)
+ value -= 3;
+
+ switch (param->uvalue) {
+ case RTC_BSM_LEVEL:
+ break;
+ case RTC_BSM_DIRECT:
+ mode = 3;
+ break;
+ case RTC_BSM_DISABLED:
+ if (value == 0)
+ value = 1;
+ mode = 5;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ return regmap_update_bits(pcf2127->regmap, PCF2127_REG_CTRL3,
+ PCF2127_CTRL3_PM,
+ FIELD_PREP(PCF2127_CTRL3_PM, mode + value));
+
+ break;
+
+ default:
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
static int pcf2127_rtc_ioctl(struct device *dev,
unsigned int cmd, unsigned long arg)
{
@@ -741,6 +820,8 @@ static const struct rtc_class_ops pcf2127_rtc_ops = {
.read_alarm = pcf2127_rtc_read_alarm,
.set_alarm = pcf2127_rtc_set_alarm,
.alarm_irq_enable = pcf2127_rtc_alarm_irq_enable,
+ .param_get = pcf2127_param_get,
+ .param_set = pcf2127_param_set,
};
/* sysfs interface */
--
2.47.1
Hi,
kernel test robot noticed the following build errors:
[auto build test ERROR on abelloni/rtc-next]
[also build test ERROR on linus/master v6.13-rc6 next-20250110]
[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#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/alexandre-belloni-bootlin-com/rtc-pcf2127-add-BSM-support/20250109-214654
base: https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux.git rtc-next
patch link: https://lore.kernel.org/r/20250109134253.827796-1-alexandre.belloni%40bootlin.com
patch subject: [PATCH] rtc: pcf2127: add BSM support
config: i386-buildonly-randconfig-006-20250111 (https://download.01.org/0day-ci/archive/20250111/202501110609.EswlBu9L-lkp@intel.com/config)
compiler: clang version 19.1.3 (https://github.com/llvm/llvm-project ab51eccf88f5321e7c60591c5546b254b6afab99)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250111/202501110609.EswlBu9L-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202501110609.EswlBu9L-lkp@intel.com/
All errors (new ones prefixed by >>):
In file included from drivers/rtc/rtc-pcf2127.c:20:
In file included from include/linux/i2c.h:19:
In file included from include/linux/regulator/consumer.h:35:
In file included from include/linux/suspend.h:5:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:21:
In file included from include/linux/mm.h:2213:
include/linux/vmstat.h:518:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
518 | return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
| ~~~~~~~~~~~ ^ ~~~
>> drivers/rtc/rtc-pcf2127.c:347:11: error: call to undeclared function 'FIELD_GET'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
347 | value = FIELD_GET(PCF2127_CTRL3_PM, value);
| ^
drivers/rtc/rtc-pcf2127.c:378:11: error: call to undeclared function 'FIELD_GET'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
378 | value = FIELD_GET(PCF2127_CTRL3_PM, value);
| ^
>> drivers/rtc/rtc-pcf2127.c:402:8: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
402 | FIELD_PREP(PCF2127_CTRL3_PM, mode + value));
| ^
1 warning and 3 errors generated.
vim +/FIELD_GET +347 drivers/rtc/rtc-pcf2127.c
334
335 static int pcf2127_param_get(struct device *dev, struct rtc_param *param)
336 {
337 struct pcf2127 *pcf2127 = dev_get_drvdata(dev);
338 u32 value;
339 int ret;
340
341 switch (param->param) {
342 case RTC_PARAM_BACKUP_SWITCH_MODE:
343 ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL3, &value);
344 if (ret < 0)
345 return ret;
346
> 347 value = FIELD_GET(PCF2127_CTRL3_PM, value);
348
349 if (value < 0x3)
350 param->uvalue = RTC_BSM_LEVEL;
351 else if (value < 0x6)
352 param->uvalue = RTC_BSM_DIRECT;
353 else
354 param->uvalue = RTC_BSM_DISABLED;
355
356 break;
357
358 default:
359 return -EINVAL;
360 }
361
362 return 0;
363 }
364
365 static int pcf2127_param_set(struct device *dev, struct rtc_param *param)
366 {
367 struct pcf2127 *pcf2127 = dev_get_drvdata(dev);
368 u8 mode = 0;
369 u32 value;
370 int ret;
371
372 switch (param->param) {
373 case RTC_PARAM_BACKUP_SWITCH_MODE:
374 ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL3, &value);
375 if (ret < 0)
376 return ret;
377
378 value = FIELD_GET(PCF2127_CTRL3_PM, value);
379
380 if (value > 5)
381 value -= 5;
382 else if (value > 2)
383 value -= 3;
384
385 switch (param->uvalue) {
386 case RTC_BSM_LEVEL:
387 break;
388 case RTC_BSM_DIRECT:
389 mode = 3;
390 break;
391 case RTC_BSM_DISABLED:
392 if (value == 0)
393 value = 1;
394 mode = 5;
395 break;
396 default:
397 return -EINVAL;
398 }
399
400 return regmap_update_bits(pcf2127->regmap, PCF2127_REG_CTRL3,
401 PCF2127_CTRL3_PM,
> 402 FIELD_PREP(PCF2127_CTRL3_PM, mode + value));
403
404 break;
405
406 default:
407 return -EINVAL;
408 }
409
410 return 0;
411 }
412
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Hi,
kernel test robot noticed the following build errors:
[auto build test ERROR on abelloni/rtc-next]
[also build test ERROR on linus/master v6.13-rc6 next-20250110]
[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#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/alexandre-belloni-bootlin-com/rtc-pcf2127-add-BSM-support/20250109-214654
base: https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux.git rtc-next
patch link: https://lore.kernel.org/r/20250109134253.827796-1-alexandre.belloni%40bootlin.com
patch subject: [PATCH] rtc: pcf2127: add BSM support
config: hexagon-randconfig-002-20250111 (https://download.01.org/0day-ci/archive/20250111/202501110440.4RhjFZZA-lkp@intel.com/config)
compiler: clang version 15.0.7 (https://github.com/llvm/llvm-project 8dfdcc7b7bf66834a761bd8de445840ef68e4d1a)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250111/202501110440.4RhjFZZA-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202501110440.4RhjFZZA-lkp@intel.com/
All errors (new ones prefixed by >>):
In file included from drivers/rtc/rtc-pcf2127.c:20:
In file included from include/linux/i2c.h:19:
In file included from include/linux/regulator/consumer.h:35:
In file included from include/linux/suspend.h:5:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:13:
In file included from include/linux/cgroup.h:26:
In file included from include/linux/kernel_stat.h:8:
In file included from include/linux/interrupt.h:11:
In file included from include/linux/hardirq.h:11:
In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:14:
In file included from arch/hexagon/include/asm/io.h:328:
include/asm-generic/io.h:548:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __raw_readb(PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:561:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu'
#define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
^
In file included from drivers/rtc/rtc-pcf2127.c:20:
In file included from include/linux/i2c.h:19:
In file included from include/linux/regulator/consumer.h:35:
In file included from include/linux/suspend.h:5:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:13:
In file included from include/linux/cgroup.h:26:
In file included from include/linux/kernel_stat.h:8:
In file included from include/linux/interrupt.h:11:
In file included from include/linux/hardirq.h:11:
In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:14:
In file included from arch/hexagon/include/asm/io.h:328:
include/asm-generic/io.h:574:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu'
#define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
^
In file included from drivers/rtc/rtc-pcf2127.c:20:
In file included from include/linux/i2c.h:19:
In file included from include/linux/regulator/consumer.h:35:
In file included from include/linux/suspend.h:5:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:13:
In file included from include/linux/cgroup.h:26:
In file included from include/linux/kernel_stat.h:8:
In file included from include/linux/interrupt.h:11:
In file included from include/linux/hardirq.h:11:
In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:14:
In file included from arch/hexagon/include/asm/io.h:328:
include/asm-generic/io.h:585:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writeb(value, PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:595:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:605:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
>> drivers/rtc/rtc-pcf2127.c:347:11: error: call to undeclared function 'FIELD_GET'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration]
value = FIELD_GET(PCF2127_CTRL3_PM, value);
^
drivers/rtc/rtc-pcf2127.c:378:11: error: call to undeclared function 'FIELD_GET'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration]
value = FIELD_GET(PCF2127_CTRL3_PM, value);
^
>> drivers/rtc/rtc-pcf2127.c:402:8: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration]
FIELD_PREP(PCF2127_CTRL3_PM, mode + value));
^
6 warnings and 3 errors generated.
vim +/FIELD_GET +347 drivers/rtc/rtc-pcf2127.c
334
335 static int pcf2127_param_get(struct device *dev, struct rtc_param *param)
336 {
337 struct pcf2127 *pcf2127 = dev_get_drvdata(dev);
338 u32 value;
339 int ret;
340
341 switch (param->param) {
342 case RTC_PARAM_BACKUP_SWITCH_MODE:
343 ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL3, &value);
344 if (ret < 0)
345 return ret;
346
> 347 value = FIELD_GET(PCF2127_CTRL3_PM, value);
348
349 if (value < 0x3)
350 param->uvalue = RTC_BSM_LEVEL;
351 else if (value < 0x6)
352 param->uvalue = RTC_BSM_DIRECT;
353 else
354 param->uvalue = RTC_BSM_DISABLED;
355
356 break;
357
358 default:
359 return -EINVAL;
360 }
361
362 return 0;
363 }
364
365 static int pcf2127_param_set(struct device *dev, struct rtc_param *param)
366 {
367 struct pcf2127 *pcf2127 = dev_get_drvdata(dev);
368 u8 mode = 0;
369 u32 value;
370 int ret;
371
372 switch (param->param) {
373 case RTC_PARAM_BACKUP_SWITCH_MODE:
374 ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL3, &value);
375 if (ret < 0)
376 return ret;
377
378 value = FIELD_GET(PCF2127_CTRL3_PM, value);
379
380 if (value > 5)
381 value -= 5;
382 else if (value > 2)
383 value -= 3;
384
385 switch (param->uvalue) {
386 case RTC_BSM_LEVEL:
387 break;
388 case RTC_BSM_DIRECT:
389 mode = 3;
390 break;
391 case RTC_BSM_DISABLED:
392 if (value == 0)
393 value = 1;
394 mode = 5;
395 break;
396 default:
397 return -EINVAL;
398 }
399
400 return regmap_update_bits(pcf2127->regmap, PCF2127_REG_CTRL3,
401 PCF2127_CTRL3_PM,
> 402 FIELD_PREP(PCF2127_CTRL3_PM, mode + value));
403
404 break;
405
406 default:
407 return -EINVAL;
408 }
409
410 return 0;
411 }
412
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
© 2016 - 2025 Red Hat, Inc.