Lines Matching +full:reg +full:- +full:rc
2 * Copyright (c) 2019-2020 Peter Bigot Consulting, LLC
4 * SPDX-License-Identifier: Apache-2.0
33 /* Return lower 32-bits of time as counter value */
107 * such an operation, or when doing a no-notify synchronize
148 struct ds3231_data *data = dev->data; in sc_ctrl()
149 const struct ds3231_config *cfg = dev->config; in sc_ctrl()
150 struct register_map *rp = &data->registers; in sc_ctrl()
151 uint8_t ctrl = (rp->ctrl & ~clear) | set; in sc_ctrl()
152 int rc = ctrl; in sc_ctrl() local
154 if (rp->ctrl != ctrl) { in sc_ctrl()
159 rc = i2c_write_dt(&cfg->bus, buf, sizeof(buf)); in sc_ctrl()
160 if (rc >= 0) { in sc_ctrl()
161 rp->ctrl = ctrl; in sc_ctrl()
162 rc = ctrl; in sc_ctrl()
165 return rc; in sc_ctrl()
172 struct ds3231_data *data = dev->data; in maxim_ds3231_ctrl_update()
174 k_sem_take(&data->lock, K_FOREVER); in maxim_ds3231_ctrl_update()
176 int rc = sc_ctrl(dev, set_bits, clear_bits); in maxim_ds3231_ctrl_update() local
178 k_sem_give(&data->lock); in maxim_ds3231_ctrl_update()
180 return rc; in maxim_ds3231_ctrl_update()
200 struct ds3231_data *data = dev->data; in rsc_stat()
201 const struct ds3231_config *cfg = dev->config; in rsc_stat()
202 struct register_map *rp = &data->registers; in rsc_stat()
204 int rc; in rsc_stat() local
206 rc = i2c_write_read_dt(&cfg->bus, &addr, sizeof(addr), &rp->ctrl_stat, in rsc_stat()
207 sizeof(rp->ctrl_stat)); in rsc_stat()
208 if (rc >= 0) { in rsc_stat()
209 uint8_t stat = rp->ctrl_stat & ~clear; in rsc_stat()
211 if (rp->ctrl_stat != stat) { in rsc_stat()
216 rc = i2c_write_dt(&cfg->bus, buf, sizeof(buf)); in rsc_stat()
218 if (rc >= 0) { in rsc_stat()
219 rc = rp->ctrl_stat; in rsc_stat()
222 return rc; in rsc_stat()
229 struct ds3231_data *data = dev->data; in maxim_ds3231_stat_update()
231 k_sem_take(&data->lock, K_FOREVER); in maxim_ds3231_stat_update()
235 k_sem_give(&data->lock); in maxim_ds3231_stat_update()
241 * Look for current users of the interrupt/square-wave signal and
246 struct ds3231_data *data = dev->data; in validate_isw_monitoring()
247 const struct ds3231_config *cfg = dev->config; in validate_isw_monitoring()
248 const struct register_map *rp = &data->registers; in validate_isw_monitoring()
251 if (rp->ctrl & (MAXIM_DS3231_ALARM1 | MAXIM_DS3231_ALARM2)) { in validate_isw_monitoring()
254 if (data->sync_state != SYNCSM_IDLE) { in validate_isw_monitoring()
257 LOG_DBG("ISW %p : %d ?= %d", cfg->isw_gpios.port, isw_mon_req, in validate_isw_monitoring()
258 data->isw_mon_req); in validate_isw_monitoring()
259 if ((cfg->isw_gpios.port != NULL) in validate_isw_monitoring()
260 && (isw_mon_req != data->isw_mon_req)) { in validate_isw_monitoring()
261 int rc = 0; in validate_isw_monitoring() local
264 rc = gpio_pin_interrupt_configure_dt(&cfg->isw_gpios, in validate_isw_monitoring()
267 if ((rc >= 0) in validate_isw_monitoring()
269 != (data->isw_mon_req & ISW_MON_REQ_Sync))) { in validate_isw_monitoring()
271 rc = sc_ctrl(dev, 0, in validate_isw_monitoring()
275 rc = sc_ctrl(dev, MAXIM_DS3231_REG_CTRL_INTCN, 0); in validate_isw_monitoring()
279 data->isw_mon_req = isw_mon_req; in validate_isw_monitoring()
282 if ((rc >= 0) && (isw_mon_req != 0)) { in validate_isw_monitoring()
283 rc = gpio_pin_interrupt_configure_dt( in validate_isw_monitoring()
284 &cfg->isw_gpios, GPIO_INT_EDGE_TO_ACTIVE); in validate_isw_monitoring()
287 LOG_INF("ISW reconfigure to %x: %d", isw_mon_req, rc); in validate_isw_monitoring()
295 uint8_t reg; in decode_time() local
298 reg = *rp++; in decode_time()
300 tp->tm_sec = bcd2bin(reg & 0x7F); in decode_time()
303 reg = *rp++; in decode_time()
304 tp->tm_min = bcd2bin(reg & 0x7F); in decode_time()
306 reg = *rp++; in decode_time()
307 tp->tm_hour = (reg & 0x0F); in decode_time()
308 if (REG_HOURS_12H & reg) { in decode_time()
309 /* 12-hour */ in decode_time()
310 if (REG_HOURS_10 & reg) { in decode_time()
311 tp->tm_hour += 10; in decode_time()
313 if (REG_HOURS_PM & reg) { in decode_time()
314 tp->tm_hour += 12; in decode_time()
318 tp->tm_hour += 10 * ((reg >> 4) & 0x03); in decode_time()
329 /* tm_year zero is 1900 with underflows a 32-bit counter in decode_alarm()
330 * representation. Use 1978-01, the first January after the in decode_alarm()
347 * 1978-01 that will produce the correct tm_wday. in decode_alarm()
350 tm.tm_wday = tm.tm_mday - 1; in decode_alarm()
361 if (dp-- == ap) { in decode_alarm()
388 return -EINVAL; in encode_alarm()
429 const struct register_map *rp = &data->registers; in decode_rtc()
432 decode_time(&tm, &rp->sec, true); in decode_rtc()
433 tm.tm_wday = (rp->dow & 0x07) - 1; in decode_rtc()
434 tm.tm_mday = bcd2bin(rp->dom & 0x3F); in decode_rtc()
435 tm.tm_mon = 10 * (((0xF0 & ~REG_MONCEN_CENTURY) & rp->moncen) >> 4) in decode_rtc()
436 + (rp->moncen & 0x0F) - 1; in decode_rtc()
437 tm.tm_year = bcd2bin(rp->year); in decode_rtc()
438 if (REG_MONCEN_CENTURY & rp->moncen) { in decode_rtc()
448 struct ds3231_data *data = dev->data; in update_registers()
449 const struct ds3231_config *cfg = dev->config; in update_registers()
451 int rc; in update_registers() local
454 data->syncclock_base = maxim_ds3231_read_syncclock(dev); in update_registers()
455 rc = i2c_write_read_dt(&cfg->bus, &addr, sizeof(addr), &data->registers, in update_registers()
456 sizeof(data->registers)); in update_registers()
458 if (rc < 0) { in update_registers()
459 return rc; in update_registers()
469 struct ds3231_data *data = dev->data; in maxim_ds3231_get_alarm()
470 const struct ds3231_config *cfg = dev->config; in maxim_ds3231_get_alarm()
477 len = sizeof(data->registers.alarm1); in maxim_ds3231_get_alarm()
478 } else if (id < cfg->generic.channels) { in maxim_ds3231_get_alarm()
480 len = sizeof(data->registers.alarm2); in maxim_ds3231_get_alarm()
482 rv = -EINVAL; in maxim_ds3231_get_alarm()
486 k_sem_take(&data->lock, K_FOREVER); in maxim_ds3231_get_alarm()
489 uint8_t *rbp = &data->registers.sec + addr; in maxim_ds3231_get_alarm()
491 rv = i2c_write_read_dt(&cfg->bus, &addr, sizeof(addr), rbp, len); in maxim_ds3231_get_alarm()
499 cp->flags = decode_alarm(rbp, (id == 0), &cp->time); in maxim_ds3231_get_alarm()
500 cp->handler = data->alarm_handler[id]; in maxim_ds3231_get_alarm()
501 cp->user_data = data->alarm_user_data[id]; in maxim_ds3231_get_alarm()
504 k_sem_give(&data->lock); in maxim_ds3231_get_alarm()
513 struct ds3231_data *data = dev->data; in cancel_alarm()
515 data->alarm_handler[id] = NULL; in cancel_alarm()
516 data->alarm_user_data[id] = NULL; in cancel_alarm()
524 struct ds3231_data *data = dev->data; in ds3231_counter_cancel_alarm()
525 const struct ds3231_config *cfg = dev->config; in ds3231_counter_cancel_alarm()
528 if (id >= cfg->generic.channels) { in ds3231_counter_cancel_alarm()
529 rv = -EINVAL; in ds3231_counter_cancel_alarm()
533 k_sem_take(&data->lock, K_FOREVER); in ds3231_counter_cancel_alarm()
537 k_sem_give(&data->lock); in ds3231_counter_cancel_alarm()
552 struct ds3231_data *data = dev->data; in set_alarm()
553 const struct ds3231_config *cfg = dev->config; in set_alarm()
559 len = sizeof(data->registers.alarm1); in set_alarm()
560 } else if (id < cfg->generic.channels) { in set_alarm()
562 len = sizeof(data->registers.alarm2); in set_alarm()
564 return -EINVAL; in set_alarm()
568 int rc = encode_alarm(buf + 1, (id == 0), cp->time, cp->flags); in set_alarm() local
570 if (rc < 0) { in set_alarm()
571 return rc; in set_alarm()
578 rc = rsc_stat(dev, 0U, (MAXIM_DS3231_ALARM1 << id)); in set_alarm()
579 if (rc >= 0) { in set_alarm()
580 rc = i2c_write_dt(&cfg->bus, buf, len + 1); in set_alarm()
582 if ((rc >= 0) in set_alarm()
583 && (cp->handler != NULL)) { in set_alarm()
584 rc = sc_ctrl(dev, MAXIM_DS3231_ALARM1 << id, 0); in set_alarm()
586 if (rc >= 0) { in set_alarm()
587 memmove(&data->registers.sec + addr, buf + 1, len); in set_alarm()
588 data->alarm_handler[id] = cp->handler; in set_alarm()
589 data->alarm_user_data[id] = cp->user_data; in set_alarm()
590 data->alarm_flags[id] = cp->flags; in set_alarm()
594 return rc; in set_alarm()
601 struct ds3231_data *data = dev->data; in maxim_ds3231_set_alarm()
603 k_sem_take(&data->lock, K_FOREVER); in maxim_ds3231_set_alarm()
605 int rc = set_alarm(dev, id, cp); in maxim_ds3231_set_alarm() local
607 k_sem_give(&data->lock); in maxim_ds3231_set_alarm()
609 return rc; in maxim_ds3231_set_alarm()
614 struct ds3231_data *data = dev->data; in maxim_ds3231_check_alarms()
615 const struct register_map *rp = &data->registers; in maxim_ds3231_check_alarms()
618 k_sem_take(&data->lock, K_FOREVER); in maxim_ds3231_check_alarms()
621 * interrupt-enabled. in maxim_ds3231_check_alarms()
623 int rv = rsc_stat(dev, 0U, (rp->ctrl & mask) ^ mask); in maxim_ds3231_check_alarms()
629 k_sem_give(&data->lock); in maxim_ds3231_check_alarms()
636 struct ds3231_data *data = dev->data; in check_handled_alarms()
637 const struct register_map *rp = &data->registers; in check_handled_alarms()
641 * interrupt-enabled. Leave any flags that are not enabled; in check_handled_alarms()
644 mask &= rp->ctrl; in check_handled_alarms()
667 const struct device *ds3231 = data->ds3231; in alarm_worker()
668 const struct ds3231_config *cfg = ds3231->config; in alarm_worker()
670 k_sem_take(&data->lock, K_FOREVER); in alarm_worker()
677 for (id = 0; id < cfg->generic.channels; ++id) { in alarm_worker()
684 = data->alarm_handler[id]; in alarm_worker()
685 void *ud = data->alarm_user_data[id]; in alarm_worker()
687 if (data->alarm_flags[id] & MAXIM_DS3231_ALARM_FLAGS_AUTODISABLE) { in alarm_worker()
688 int rc = cancel_alarm(ds3231, id); in alarm_worker() local
690 LOG_DBG("autodisable %d: %d", id, rc); in alarm_worker()
695 counter_alarm_callback_t cb = data->counter_handler[id]; in alarm_worker()
696 uint32_t ticks = data->counter_ticks[id]; in alarm_worker()
698 data->counter_handler[id] = NULL; in alarm_worker()
699 data->counter_ticks[id] = 0; in alarm_worker()
702 k_sem_give(&data->lock); in alarm_worker()
706 k_sem_take(&data->lock, K_FOREVER); in alarm_worker()
710 k_sem_give(&data->lock); in alarm_worker()
712 handler(ds3231, id, data->isw_syncclock, ud); in alarm_worker()
714 k_sem_take(&data->lock, K_FOREVER); in alarm_worker()
720 k_sem_give(&data->lock); in alarm_worker()
727 LOG_DBG("ALARM %02x at %u latency %u", af, data->isw_syncclock, in alarm_worker()
728 maxim_ds3231_read_syncclock(ds3231) - data->isw_syncclock); in alarm_worker()
734 uint32_t syncclock = maxim_ds3231_read_syncclock(data->ds3231); in sqw_worker()
736 /* This is a placeholder for potential application-controlled in sqw_worker()
739 LOG_DBG("SQW %u latency %u", data->isw_syncclock, in sqw_worker()
740 syncclock - data->isw_syncclock); in sqw_worker()
746 struct ds3231_data *data = dev->data; in read_time()
747 const struct ds3231_config *cfg = dev->config; in read_time()
750 int rc = i2c_write_read_dt(&cfg->bus, &addr, sizeof(addr), in read_time() local
751 &data->registers, 7); in read_time()
753 if (rc >= 0) { in read_time()
757 return rc; in read_time()
763 struct ds3231_data *data = dev->data; in ds3231_counter_get_value()
766 k_sem_take(&data->lock, K_FOREVER); in ds3231_counter_get_value()
768 int rc = read_time(dev, &time); in ds3231_counter_get_value() local
770 k_sem_give(&data->lock); in ds3231_counter_get_value()
772 if (rc >= 0) { in ds3231_counter_get_value()
776 return rc; in ds3231_counter_get_value()
780 int rc) in sync_finish() argument
782 struct ds3231_data *data = dev->data; in sync_finish()
786 if (data->sync_signal) { in sync_finish()
787 signal = data->sync.signal; in sync_finish()
789 notify = data->sync.notify; in sync_finish()
791 data->sync.ptr = NULL; in sync_finish()
792 data->sync_signal = false; in sync_finish()
793 data->sync_state = SYNCSM_IDLE; in sync_finish()
796 LOG_DBG("sync complete, notify %d to %p or %p\n", rc, notify, signal); in sync_finish()
797 k_sem_give(&data->lock); in sync_finish()
801 (maxim_ds3231_notify_callback)sys_notify_finalize(notify, rc); in sync_finish()
804 cb(dev, notify, rc); in sync_finish()
807 k_poll_signal_raise(signal, rc); in sync_finish()
813 struct ds3231_data *data = dev->data; in sync_prep_read()
814 int rc = sc_ctrl(dev, 0U, MAXIM_DS3231_REG_CTRL_INTCN in sync_prep_read() local
817 if (rc < 0) { in sync_prep_read()
818 sync_finish(dev, rc); in sync_prep_read()
821 data->sync_state = SYNCSM_FINISH_READ; in sync_prep_read()
827 struct ds3231_data *data = dev->data; in sync_finish_read()
831 data->syncpoint.rtc.tv_sec = time; in sync_finish_read()
832 data->syncpoint.rtc.tv_nsec = 0; in sync_finish_read()
833 data->syncpoint.syncclock = data->isw_syncclock; in sync_finish_read()
843 k_work_submit(&data->sync_work); in sync_timer_handler()
848 struct ds3231_data *data = dev->data; in sync_prep_write()
850 uint32_t offset = syncclock - data->new_sp.syncclock; in sync_prep_write()
854 time_t when = data->new_sp.rtc.tv_sec; in sync_prep_write()
857 offset_ms += data->new_sp.rtc.tv_nsec / NSEC_PER_USEC / USEC_PER_MSEC; in sync_prep_write()
859 offset_ms -= MSEC_PER_SEC; in sync_prep_write()
864 uint32_t rem_ms = MSEC_PER_SEC - offset_ms; in sync_prep_write()
870 data->new_sp.rtc.tv_sec = when; in sync_prep_write()
871 data->new_sp.rtc.tv_nsec = 0; in sync_prep_write()
873 data->sync_state = SYNCSM_FINISH_WRITE; in sync_prep_write()
874 k_timer_start(&data->sync_timer, K_MSEC(rem_ms), K_NO_WAIT); in sync_prep_write()
880 struct ds3231_data *data = dev->data; in sync_finish_write()
881 const struct ds3231_config *cfg = dev->config; in sync_finish_write()
882 time_t when = data->new_sp.rtc.tv_sec; in sync_finish_write()
908 tm.tm_year -= 100; in sync_finish_write()
917 int rc = i2c_write_dt(&cfg->bus, buf, bp - buf); in sync_finish_write() local
919 if (rc >= 0) { in sync_finish_write()
920 data->syncpoint.rtc.tv_sec = when; in sync_finish_write()
921 data->syncpoint.rtc.tv_nsec = 0; in sync_finish_write()
922 data->syncpoint.syncclock = syncclock; in sync_finish_write()
925 sync_finish(dev, rc); in sync_finish_write()
931 uint32_t syncclock = maxim_ds3231_read_syncclock(data->ds3231); in sync_worker()
934 k_sem_take(&data->lock, K_FOREVER); in sync_worker()
936 LOG_DBG("SYNC.%u %u latency %u", data->sync_state, data->isw_syncclock, in sync_worker()
937 syncclock - data->isw_syncclock); in sync_worker()
938 switch (data->sync_state) { in sync_worker()
943 sync_prep_read(data->ds3231); in sync_worker()
946 sync_finish_read(data->ds3231); in sync_worker()
949 sync_prep_write(data->ds3231); in sync_worker()
952 sync_finish_write(data->ds3231); in sync_worker()
958 k_sem_give(&data->lock); in sync_worker()
969 data->isw_syncclock = maxim_ds3231_read_syncclock(data->ds3231); in isw_gpio_callback()
970 if (data->registers.ctrl & MAXIM_DS3231_REG_CTRL_INTCN) { in isw_gpio_callback()
971 k_work_submit(&data->alarm_work); in isw_gpio_callback()
972 } else if (data->sync_state != SYNCSM_IDLE) { in isw_gpio_callback()
973 k_work_submit(&data->sync_work); in isw_gpio_callback()
975 k_work_submit(&data->sqw_work); in isw_gpio_callback()
982 struct ds3231_data *data = dev->data; in z_impl_maxim_ds3231_get_syncpoint()
985 k_sem_take(&data->lock, K_FOREVER); in z_impl_maxim_ds3231_get_syncpoint()
987 if (data->syncpoint.rtc.tv_sec == 0) { in z_impl_maxim_ds3231_get_syncpoint()
988 rv = -ENOENT; in z_impl_maxim_ds3231_get_syncpoint()
991 *syncpoint = data->syncpoint; in z_impl_maxim_ds3231_get_syncpoint()
994 k_sem_give(&data->lock); in z_impl_maxim_ds3231_get_syncpoint()
1002 const struct ds3231_config *cfg = dev->config; in maxim_ds3231_synchronize()
1003 struct ds3231_data *data = dev->data; in maxim_ds3231_synchronize()
1007 rv = -EINVAL; in maxim_ds3231_synchronize()
1011 if (cfg->isw_gpios.port == NULL) { in maxim_ds3231_synchronize()
1012 rv = -ENOTSUP; in maxim_ds3231_synchronize()
1016 k_sem_take(&data->lock, K_FOREVER); in maxim_ds3231_synchronize()
1018 if (data->sync_state != SYNCSM_IDLE) { in maxim_ds3231_synchronize()
1019 rv = -EBUSY; in maxim_ds3231_synchronize()
1023 data->sync_signal = false; in maxim_ds3231_synchronize()
1024 data->sync.notify = notify; in maxim_ds3231_synchronize()
1025 data->sync_state = SYNCSM_PREP_READ; in maxim_ds3231_synchronize()
1028 k_sem_give(&data->lock); in maxim_ds3231_synchronize()
1031 k_work_submit(&data->sync_work); in maxim_ds3231_synchronize()
1041 const struct ds3231_config *cfg = dev->config; in z_impl_maxim_ds3231_req_syncpoint()
1042 struct ds3231_data *data = dev->data; in z_impl_maxim_ds3231_req_syncpoint()
1045 if (cfg->isw_gpios.port == NULL) { in z_impl_maxim_ds3231_req_syncpoint()
1046 rv = -ENOTSUP; in z_impl_maxim_ds3231_req_syncpoint()
1050 k_sem_take(&data->lock, K_FOREVER); in z_impl_maxim_ds3231_req_syncpoint()
1052 if (data->sync_state != SYNCSM_IDLE) { in z_impl_maxim_ds3231_req_syncpoint()
1053 rv = -EBUSY; in z_impl_maxim_ds3231_req_syncpoint()
1057 data->sync_signal = true; in z_impl_maxim_ds3231_req_syncpoint()
1058 data->sync.signal = sig; in z_impl_maxim_ds3231_req_syncpoint()
1059 data->sync_state = SYNCSM_PREP_READ; in z_impl_maxim_ds3231_req_syncpoint()
1062 k_sem_give(&data->lock); in z_impl_maxim_ds3231_req_syncpoint()
1065 k_work_submit(&data->sync_work); in z_impl_maxim_ds3231_req_syncpoint()
1076 const struct ds3231_config *cfg = dev->config; in maxim_ds3231_set()
1077 struct ds3231_data *data = dev->data; in maxim_ds3231_set()
1082 rv = -EINVAL; in maxim_ds3231_set()
1085 if (cfg->isw_gpios.port == NULL) { in maxim_ds3231_set()
1086 rv = -ENOTSUP; in maxim_ds3231_set()
1090 k_sem_take(&data->lock, K_FOREVER); in maxim_ds3231_set()
1092 if (data->sync_state != SYNCSM_IDLE) { in maxim_ds3231_set()
1093 rv = -EBUSY; in maxim_ds3231_set()
1097 data->new_sp = *syncpoint; in maxim_ds3231_set()
1098 data->sync_signal = false; in maxim_ds3231_set()
1099 data->sync.notify = notify; in maxim_ds3231_set()
1100 data->sync_state = SYNCSM_PREP_WRITE; in maxim_ds3231_set()
1103 k_sem_give(&data->lock); in maxim_ds3231_set()
1106 k_work_submit(&data->sync_work); in maxim_ds3231_set()
1115 struct ds3231_data *data = dev->data; in ds3231_init()
1116 const struct ds3231_config *cfg = dev->config; in ds3231_init()
1117 int rc; in ds3231_init() local
1120 k_sem_init(&data->lock, 0, 1); in ds3231_init()
1122 data->ds3231 = dev; in ds3231_init()
1123 if (!device_is_ready(cfg->bus.bus)) { in ds3231_init()
1125 rc = -ENODEV; in ds3231_init()
1129 rc = update_registers(dev); in ds3231_init()
1130 if (rc < 0) { in ds3231_init()
1131 LOG_WRN("Failed to fetch registers: %d", rc); in ds3231_init()
1135 /* INTCN and AxIE to power-up default, RS to 1 Hz */ in ds3231_init()
1136 rc = sc_ctrl(dev, in ds3231_init()
1140 if (rc < 0) { in ds3231_init()
1141 LOG_WRN("Failed to reset config: %d", rc); in ds3231_init()
1150 if (cfg->isw_gpios.port != NULL) { in ds3231_init()
1151 if (!gpio_is_ready_dt(&cfg->isw_gpios)) { in ds3231_init()
1153 rc = -ENODEV; in ds3231_init()
1157 k_timer_init(&data->sync_timer, sync_timer_handler, NULL); in ds3231_init()
1158 k_work_init(&data->alarm_work, alarm_worker); in ds3231_init()
1159 k_work_init(&data->sqw_work, sqw_worker); in ds3231_init()
1160 k_work_init(&data->sync_work, sync_worker); in ds3231_init()
1161 gpio_init_callback(&data->isw_callback, in ds3231_init()
1163 BIT(cfg->isw_gpios.pin)); in ds3231_init()
1165 rc = gpio_pin_configure_dt(&cfg->isw_gpios, GPIO_INPUT); in ds3231_init()
1166 if (rc >= 0) { in ds3231_init()
1167 rc = gpio_pin_interrupt_configure_dt(&cfg->isw_gpios, in ds3231_init()
1170 if (rc >= 0) { in ds3231_init()
1171 rc = gpio_add_callback(cfg->isw_gpios.port, in ds3231_init()
1172 &data->isw_callback); in ds3231_init()
1173 if (rc < 0) { in ds3231_init()
1175 rc); in ds3231_init()
1181 k_sem_give(&data->lock); in ds3231_init()
1183 LOG_DBG("Initialized %d", rc); in ds3231_init()
1184 if (rc > 0) { in ds3231_init()
1185 rc = 0; in ds3231_init()
1188 return rc; in ds3231_init()
1193 return -EALREADY; in ds3231_counter_start()
1198 return -ENOTSUP; in ds3231_counter_stop()
1205 struct ds3231_data *data = dev->data; in ds3231_counter_set_alarm()
1206 const struct register_map *rp = &data->registers; in ds3231_counter_set_alarm()
1207 const struct ds3231_config *cfg = dev->config; in ds3231_counter_set_alarm()
1209 int rc = 0; in ds3231_counter_set_alarm() local
1211 if (id >= cfg->generic.channels) { in ds3231_counter_set_alarm()
1212 rc = -ENOTSUP; in ds3231_counter_set_alarm()
1216 k_sem_take(&data->lock, K_FOREVER); in ds3231_counter_set_alarm()
1218 if (rp->ctrl & (MAXIM_DS3231_ALARM1 << id)) { in ds3231_counter_set_alarm()
1219 rc = -EBUSY; in ds3231_counter_set_alarm()
1223 if ((alarm_cfg->flags & COUNTER_ALARM_CFG_ABSOLUTE) == 0) { in ds3231_counter_set_alarm()
1224 rc = read_time(dev, &when); in ds3231_counter_set_alarm()
1225 if (rc >= 0) { in ds3231_counter_set_alarm()
1226 when += alarm_cfg->ticks; in ds3231_counter_set_alarm()
1229 when = alarm_cfg->ticks; in ds3231_counter_set_alarm()
1235 .user_data = alarm_cfg->user_data, in ds3231_counter_set_alarm()
1239 if (rc >= 0) { in ds3231_counter_set_alarm()
1240 data->counter_handler[id] = alarm_cfg->callback; in ds3231_counter_set_alarm()
1241 data->counter_ticks[id] = COUNTER_GET(alarm.time); in ds3231_counter_set_alarm()
1242 rc = set_alarm(dev, id, &alarm); in ds3231_counter_set_alarm()
1246 k_sem_give(&data->lock); in ds3231_counter_set_alarm()
1250 if (rc >= 0) { in ds3231_counter_set_alarm()
1251 rc = 0; in ds3231_counter_set_alarm()
1254 return rc; in ds3231_counter_set_alarm()
1270 return -ENOTSUP; in ds3231_counter_set_top_value()