Lines Matching full:pcf2127

3  * An I2C and SPI driver for the NXP PCF2127/29/31 RTC
16 * Datasheets: https://www.nxp.com/docs/en/data-sheet/PCF2127.pdf
73 * PCF2127 has 512 bytes general-purpose static RAM (SRAM) that is
83 /* PCF2127/29 watchdog timer value constants */
155 PCF2127, enumerator
202 struct pcf2127 { struct
213 * In the routines that deal directly with the pcf2127 hardware, we use argument
218 struct pcf2127 *pcf2127 = dev_get_drvdata(dev); in pcf2127_rtc_read_time() local
226 ret = regmap_bulk_read(pcf2127->regmap, pcf2127->cfg->reg_time_base, in pcf2127_rtc_read_time()
269 struct pcf2127 *pcf2127 = dev_get_drvdata(dev); in pcf2127_rtc_set_time() local
293 * PCF2127/29: no special action required. in pcf2127_rtc_set_time()
297 if (pcf2127->cfg->type == PCF2131) { in pcf2127_rtc_set_time()
298 err = regmap_update_bits(pcf2127->regmap, PCF2127_REG_CTRL1, in pcf2127_rtc_set_time()
306 err = regmap_write(pcf2127->regmap, PCF2131_REG_SR_RESET, in pcf2127_rtc_set_time()
315 err = regmap_bulk_write(pcf2127->regmap, pcf2127->cfg->reg_time_base, buf, i); in pcf2127_rtc_set_time()
321 if (pcf2127->cfg->type == PCF2131) { in pcf2127_rtc_set_time()
323 err = regmap_update_bits(pcf2127->regmap, PCF2127_REG_CTRL1, in pcf2127_rtc_set_time()
337 struct pcf2127 *pcf2127 = dev_get_drvdata(dev); in pcf2127_rtc_ioctl() local
343 ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL3, &val); in pcf2127_rtc_ioctl()
356 return regmap_update_bits(pcf2127->regmap, PCF2127_REG_CTRL3, in pcf2127_rtc_ioctl()
367 struct pcf2127 *pcf2127 = priv; in pcf2127_nvmem_read() local
371 ret = regmap_bulk_write(pcf2127->regmap, PCF2127_REG_RAM_ADDR_MSB, in pcf2127_nvmem_read()
376 return regmap_bulk_read(pcf2127->regmap, PCF2127_REG_RAM_RD_CMD, in pcf2127_nvmem_read()
383 struct pcf2127 *pcf2127 = priv; in pcf2127_nvmem_write() local
387 ret = regmap_bulk_write(pcf2127->regmap, PCF2127_REG_RAM_ADDR_MSB, in pcf2127_nvmem_write()
392 return regmap_bulk_write(pcf2127->regmap, PCF2127_REG_RAM_WRT_CMD, in pcf2127_nvmem_write()
401 struct pcf2127 *pcf2127 = watchdog_get_drvdata(wdd); in pcf2127_wdt_ping() local
407 wd_val = ((wdd->timeout * pcf2127->cfg->wdd_clock_hz_x1000) / 1000) + 1; in pcf2127_wdt_ping()
409 return regmap_write(pcf2127->regmap, pcf2127->cfg->reg_wd_val, wd_val); in pcf2127_wdt_ping()
441 struct pcf2127 *pcf2127 = watchdog_get_drvdata(wdd); in pcf2127_wdt_stop() local
443 return regmap_write(pcf2127->regmap, pcf2127->cfg->reg_wd_val, in pcf2127_wdt_stop()
459 .identity = "NXP PCF2127/PCF2129 Watchdog",
475 * The PCF2127/29 datasheet gives t as:
488 static int pcf2127_watchdog_init(struct device *dev, struct pcf2127 *pcf2127) in pcf2127_watchdog_init() argument
496 pcf2127->wdd.parent = dev; in pcf2127_watchdog_init()
497 pcf2127->wdd.info = &pcf2127_wdt_info; in pcf2127_watchdog_init()
498 pcf2127->wdd.ops = &pcf2127_watchdog_ops; in pcf2127_watchdog_init()
500 pcf2127->wdd.min_timeout = in pcf2127_watchdog_init()
502 2, pcf2127->cfg->wdd_clock_hz_x1000); in pcf2127_watchdog_init()
503 pcf2127->wdd.max_timeout = in pcf2127_watchdog_init()
505 255, pcf2127->cfg->wdd_clock_hz_x1000); in pcf2127_watchdog_init()
506 pcf2127->wdd.timeout = PCF2127_WD_DEFAULT_TIMEOUT_S; in pcf2127_watchdog_init()
509 pcf2127->cfg->wdd_clock_hz_x1000); in pcf2127_watchdog_init()
511 pcf2127->wdd.min_hw_heartbeat_ms = pcf2127->cfg->wdd_min_hw_heartbeat_ms; in pcf2127_watchdog_init()
512 pcf2127->wdd.status = WATCHDOG_NOWAYOUT_INIT_STATUS; in pcf2127_watchdog_init()
514 watchdog_set_drvdata(&pcf2127->wdd, pcf2127); in pcf2127_watchdog_init()
517 if (pcf2127->cfg->wd_val_reg_readable) { in pcf2127_watchdog_init()
520 ret = regmap_read(pcf2127->regmap, pcf2127->cfg->reg_wd_val, in pcf2127_watchdog_init()
526 set_bit(WDOG_HW_RUNNING, &pcf2127->wdd.status); in pcf2127_watchdog_init()
529 return devm_watchdog_register_device(dev, &pcf2127->wdd); in pcf2127_watchdog_init()
535 struct pcf2127 *pcf2127 = dev_get_drvdata(dev); in pcf2127_rtc_read_alarm() local
540 ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL2, &ctrl2); in pcf2127_rtc_read_alarm()
544 ret = pcf2127_wdt_active_ping(&pcf2127->wdd); in pcf2127_rtc_read_alarm()
548 ret = regmap_bulk_read(pcf2127->regmap, pcf2127->cfg->regs_alarm_base, in pcf2127_rtc_read_alarm()
566 struct pcf2127 *pcf2127 = dev_get_drvdata(dev); in pcf2127_rtc_alarm_irq_enable() local
569 ret = regmap_update_bits(pcf2127->regmap, PCF2127_REG_CTRL2, in pcf2127_rtc_alarm_irq_enable()
575 return pcf2127_wdt_active_ping(&pcf2127->wdd); in pcf2127_rtc_alarm_irq_enable()
580 struct pcf2127 *pcf2127 = dev_get_drvdata(dev); in pcf2127_rtc_set_alarm() local
584 ret = regmap_update_bits(pcf2127->regmap, PCF2127_REG_CTRL2, in pcf2127_rtc_set_alarm()
589 ret = pcf2127_wdt_active_ping(&pcf2127->wdd); in pcf2127_rtc_set_alarm()
599 ret = regmap_bulk_write(pcf2127->regmap, pcf2127->cfg->regs_alarm_base, in pcf2127_rtc_set_alarm()
614 struct pcf2127 *pcf2127 = dev_get_drvdata(dev); in pcf2127_rtc_ts_read() local
619 ret = regmap_bulk_read(pcf2127->regmap, pcf2127->cfg->ts[ts_id].reg_base, in pcf2127_rtc_ts_read()
652 struct pcf2127 *pcf2127 = dev_get_drvdata(dev); in pcf2127_rtc_ts_snapshot() local
655 if (ts_id >= pcf2127->cfg->ts_count) in pcf2127_rtc_ts_snapshot()
659 if (pcf2127->ts_valid[ts_id]) in pcf2127_rtc_ts_snapshot()
662 ret = pcf2127_rtc_ts_read(dev, &pcf2127->ts[ts_id], ts_id); in pcf2127_rtc_ts_snapshot()
664 pcf2127->ts_valid[ts_id] = true; in pcf2127_rtc_ts_snapshot()
669 struct pcf2127 *pcf2127 = dev_get_drvdata(dev); in pcf2127_rtc_irq() local
673 ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL2, &ctrl2); in pcf2127_rtc_irq()
677 if (pcf2127->cfg->ts_count == 1) { in pcf2127_rtc_irq()
678 /* PCF2127/29 */ in pcf2127_rtc_irq()
681 ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL1, &ctrl1); in pcf2127_rtc_irq()
692 regmap_write(pcf2127->regmap, PCF2127_REG_CTRL1, in pcf2127_rtc_irq()
696 regmap_write(pcf2127->regmap, PCF2127_REG_CTRL2, in pcf2127_rtc_irq()
702 ret = regmap_read(pcf2127->regmap, PCF2131_REG_CTRL4, &ctrl4); in pcf2127_rtc_irq()
713 for (i = 0; i < pcf2127->cfg->ts_count; i++) { in pcf2127_rtc_irq()
720 regmap_write(pcf2127->regmap, PCF2131_REG_CTRL4, in pcf2127_rtc_irq()
725 regmap_write(pcf2127->regmap, PCF2127_REG_CTRL2, in pcf2127_rtc_irq()
730 rtc_update_irq(pcf2127->rtc, 1, RTC_IRQF | RTC_AF); in pcf2127_rtc_irq()
732 pcf2127_wdt_active_ping(&pcf2127->wdd); in pcf2127_rtc_irq()
752 struct pcf2127 *pcf2127 = dev_get_drvdata(dev->parent); in timestamp_store() local
755 if (ts_id >= pcf2127->cfg->ts_count) in timestamp_store()
758 if (pcf2127->irq_enabled) { in timestamp_store()
759 pcf2127->ts_valid[ts_id] = false; in timestamp_store()
762 ret = regmap_update_bits(pcf2127->regmap, in timestamp_store()
763 pcf2127->cfg->ts[ts_id].gnd_detect_reg, in timestamp_store()
764 pcf2127->cfg->ts[ts_id].gnd_detect_bit, in timestamp_store()
772 if (pcf2127->cfg->ts[ts_id].inter_detect_bit) { in timestamp_store()
774 ret = regmap_update_bits(pcf2127->regmap, in timestamp_store()
775 pcf2127->cfg->ts[ts_id].inter_detect_reg, in timestamp_store()
776 pcf2127->cfg->ts[ts_id].inter_detect_bit, in timestamp_store()
785 ret = pcf2127_wdt_active_ping(&pcf2127->wdd); in timestamp_store()
825 struct pcf2127 *pcf2127 = dev_get_drvdata(dev->parent); in timestamp_show() local
829 if (ts_id >= pcf2127->cfg->ts_count) in timestamp_show()
832 if (pcf2127->irq_enabled) { in timestamp_show()
833 if (!pcf2127->ts_valid[ts_id]) in timestamp_show()
835 ts = pcf2127->ts[ts_id]; in timestamp_show()
844 ret = regmap_read(pcf2127->regmap, in timestamp_show()
845 pcf2127->cfg->ts[ts_id].gnd_detect_reg, in timestamp_show()
850 valid_low = ctrl & pcf2127->cfg->ts[ts_id].gnd_detect_bit; in timestamp_show()
852 if (pcf2127->cfg->ts[ts_id].inter_detect_bit) { in timestamp_show()
856 ret = regmap_read(pcf2127->regmap, in timestamp_show()
857 pcf2127->cfg->ts[ts_id].inter_detect_reg, in timestamp_show()
862 valid_inter = ctrl & pcf2127->cfg->ts[ts_id].inter_detect_bit; in timestamp_show()
872 ret = pcf2127_wdt_active_ping(&pcf2127->wdd); in timestamp_show()
922 [PCF2127] = {
923 .type = PCF2127,
1036 struct pcf2127 *pcf2127 = dev_get_drvdata(dev); in pcf2127_enable_ts() local
1039 if (ts_id >= pcf2127->cfg->ts_count) { in pcf2127_enable_ts()
1046 ret = regmap_update_bits(pcf2127->regmap, in pcf2127_enable_ts()
1047 pcf2127->cfg->ts[ts_id].reg_base, in pcf2127_enable_ts()
1062 ret = regmap_update_bits(pcf2127->regmap, pcf2127->cfg->ts[ts_id].ie_reg, in pcf2127_enable_ts()
1063 pcf2127->cfg->ts[ts_id].ie_bit, in pcf2127_enable_ts()
1064 pcf2127->cfg->ts[ts_id].ie_bit); in pcf2127_enable_ts()
1077 struct pcf2127 *pcf2127 = dev_get_drvdata(dev); in pcf2127_configure_interrupt_pins() local
1083 ret = regmap_write(pcf2127->regmap, in pcf2127_configure_interrupt_pins()
1088 ret = regmap_write(pcf2127->regmap, in pcf2127_configure_interrupt_pins()
1099 struct pcf2127 *pcf2127; in pcf2127_probe() local
1105 pcf2127 = devm_kzalloc(dev, sizeof(*pcf2127), GFP_KERNEL); in pcf2127_probe()
1106 if (!pcf2127) in pcf2127_probe()
1109 pcf2127->regmap = regmap; in pcf2127_probe()
1110 pcf2127->cfg = config; in pcf2127_probe()
1112 dev_set_drvdata(dev, pcf2127); in pcf2127_probe()
1114 pcf2127->rtc = devm_rtc_allocate_device(dev); in pcf2127_probe()
1115 if (IS_ERR(pcf2127->rtc)) in pcf2127_probe()
1116 return PTR_ERR(pcf2127->rtc); in pcf2127_probe()
1118 pcf2127->rtc->ops = &pcf2127_rtc_ops; in pcf2127_probe()
1119 pcf2127->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; in pcf2127_probe()
1120 pcf2127->rtc->range_max = RTC_TIMESTAMP_END_2099; in pcf2127_probe()
1121 pcf2127->rtc->set_start_time = true; /* Sets actual start to 1970 */ in pcf2127_probe()
1124 * PCF2127/29 do not work correctly when setting alarms at 1s intervals. in pcf2127_probe()
1127 if (pcf2127->cfg->type == PCF2127 || pcf2127->cfg->type == PCF2129) { in pcf2127_probe()
1128 set_bit(RTC_FEATURE_ALARM_RES_2S, pcf2127->rtc->features); in pcf2127_probe()
1129 clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, pcf2127->rtc->features); in pcf2127_probe()
1132 clear_bit(RTC_FEATURE_ALARM, pcf2127->rtc->features); in pcf2127_probe()
1154 pcf2127->irq_enabled = true; in pcf2127_probe()
1159 set_bit(RTC_FEATURE_ALARM, pcf2127->rtc->features); in pcf2127_probe()
1162 if (pcf2127->cfg->has_int_a_b) { in pcf2127_probe()
1171 if (pcf2127->cfg->has_nvmem) { in pcf2127_probe()
1173 .priv = pcf2127, in pcf2127_probe()
1179 ret = devm_rtc_nvmem_register(pcf2127->rtc, &nvmem_cfg); in pcf2127_probe()
1186 ret = regmap_clear_bits(pcf2127->regmap, PCF2127_REG_CTRL1, in pcf2127_probe()
1191 ret = regmap_read(pcf2127->regmap, pcf2127->cfg->reg_clkout, &val); in pcf2127_probe()
1196 ret = regmap_set_bits(pcf2127->regmap, pcf2127->cfg->reg_clkout, in pcf2127_probe()
1213 ret = regmap_update_bits(pcf2127->regmap, pcf2127->cfg->reg_wd_ctl, in pcf2127_probe()
1219 (pcf2127->cfg->has_bit_wd_ctl_cd0 ? PCF2127_BIT_WD_CTL_CD0 : 0) | in pcf2127_probe()
1226 pcf2127_watchdog_init(dev, pcf2127); in pcf2127_probe()
1234 ret = regmap_update_bits(pcf2127->regmap, PCF2127_REG_CTRL3, in pcf2127_probe()
1247 for (int i = 0; i < pcf2127->cfg->ts_count; i++) { in pcf2127_probe()
1253 ret = rtc_add_group(pcf2127->rtc, &pcf2127->cfg->attribute_group); in pcf2127_probe()
1260 return devm_rtc_register_device(pcf2127->rtc); in pcf2127_probe()
1265 { .compatible = "nxp,pcf2127", .data = &pcf21xx_cfg[PCF2127] },
1353 { "pcf2127", PCF2127 },
1401 .name = "rtc-pcf2127-i2c",
1472 { "pcf2127", PCF2127 },
1482 .name = "rtc-pcf2127-spi",
1518 pr_err("Failed to register pcf2127 i2c driver: %d\n", ret); in pcf2127_init()
1524 pr_err("Failed to register pcf2127 spi driver: %d\n", ret); in pcf2127_init()
1540 MODULE_DESCRIPTION("NXP PCF2127/29/31 RTC driver");