Lines Matching +full:backup +full:- +full:regs
4 * SPDX-License-Identifier: Apache-2.0
120 /* The RV3028 only supports two-digit years. Leap years are correctly handled from 2000 to 2099 */
121 #define RV3028_YEAR_OFFSET (2000 - 1900)
140 /* Helper macro to guard int-gpios related code */
152 uint8_t backup; member
175 struct rv3028_data *data = dev->data; in rv3028_lock_sem()
177 (void)k_sem_take(&data->lock, K_FOREVER); in rv3028_lock_sem()
182 struct rv3028_data *data = dev->data; in rv3028_unlock_sem()
184 k_sem_give(&data->lock); in rv3028_unlock_sem()
189 const struct rv3028_config *config = dev->config; in rv3028_read_regs()
192 err = i2c_write_read_dt(&config->i2c, &addr, sizeof(addr), buf, len); in rv3028_read_regs()
208 const struct rv3028_config *config = dev->config; in rv3028_write_regs()
215 err = i2c_write_dt(&config->i2c, block, sizeof(block)); in rv3028_write_regs()
231 const struct rv3028_config *config = dev->config; in rv3028_update_reg8()
234 err = i2c_reg_update_byte_dt(&config->i2c, addr, mask, val); in rv3028_update_reg8()
262 return -ETIME; in rv3028_eeprom_wait_busy()
384 const struct device *dev = data->dev; in rv3028_work_cb()
394 err = rv3028_read_reg8(data->dev, RV3028_REG_STATUS, &status); in rv3028_work_cb()
400 if ((status & RV3028_STATUS_AF) && data->alarm_callback != NULL) { in rv3028_work_cb()
402 alarm_callback = data->alarm_callback; in rv3028_work_cb()
403 alarm_user_data = data->alarm_user_data; in rv3028_work_cb()
408 if ((status & RV3028_STATUS_UF) && data->update_callback != NULL) { in rv3028_work_cb()
410 update_callback = data->update_callback; in rv3028_work_cb()
411 update_user_data = data->update_user_data; in rv3028_work_cb()
429 k_work_submit(&data->work); in rv3028_work_cb()
454 k_work_submit(&data->work); in rv3028_int_handler()
466 (timeptr->tm_year < RV3028_YEAR_OFFSET)) { in rv3028_set_time()
468 return -EINVAL; in rv3028_set_time()
475 timeptr->tm_year, timeptr->tm_mon, timeptr->tm_mday, timeptr->tm_wday, in rv3028_set_time()
476 timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec); in rv3028_set_time()
478 date[0] = bin2bcd(timeptr->tm_sec) & RV3028_SECONDS_MASK; in rv3028_set_time()
479 date[1] = bin2bcd(timeptr->tm_min) & RV3028_MINUTES_MASK; in rv3028_set_time()
480 date[2] = bin2bcd(timeptr->tm_hour) & RV3028_HOURS_24H_MASK; in rv3028_set_time()
481 date[3] = timeptr->tm_wday & RV3028_WEEKDAY_MASK; in rv3028_set_time()
482 date[4] = bin2bcd(timeptr->tm_mday) & RV3028_DATE_MASK; in rv3028_set_time()
483 date[5] = bin2bcd(timeptr->tm_mon + RV3028_MONTH_OFFSET) & RV3028_MONTH_MASK; in rv3028_set_time()
484 date[6] = bin2bcd(timeptr->tm_year - RV3028_YEAR_OFFSET) & RV3028_YEAR_MASK; in rv3028_set_time()
507 return -EINVAL; in rv3028_get_time()
517 return -ENODATA; in rv3028_get_time()
526 timeptr->tm_sec = bcd2bin(date[0] & RV3028_SECONDS_MASK); in rv3028_get_time()
527 timeptr->tm_min = bcd2bin(date[1] & RV3028_MINUTES_MASK); in rv3028_get_time()
528 timeptr->tm_hour = bcd2bin(date[2] & RV3028_HOURS_24H_MASK); in rv3028_get_time()
529 timeptr->tm_wday = date[3] & RV3028_WEEKDAY_MASK; in rv3028_get_time()
530 timeptr->tm_mday = bcd2bin(date[4] & RV3028_DATE_MASK); in rv3028_get_time()
531 timeptr->tm_mon = bcd2bin(date[5] & RV3028_MONTH_MASK) - RV3028_MONTH_OFFSET; in rv3028_get_time()
532 timeptr->tm_year = bcd2bin(date[6] & RV3028_YEAR_MASK) + RV3028_YEAR_OFFSET; in rv3028_get_time()
533 timeptr->tm_yday = -1; in rv3028_get_time()
534 timeptr->tm_isdst = -1; in rv3028_get_time()
538 timeptr->tm_year, timeptr->tm_mon, timeptr->tm_mday, timeptr->tm_wday, in rv3028_get_time()
539 timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec); in rv3028_get_time()
552 return -EINVAL; in rv3028_alarm_get_supported_fields()
563 uint8_t regs[3]; in rv3028_alarm_set_time() local
567 return -EINVAL; in rv3028_alarm_set_time()
572 return -EINVAL; in rv3028_alarm_set_time()
577 return -EINVAL; in rv3028_alarm_set_time()
581 regs[0] = bin2bcd(timeptr->tm_min) & RV3028_ALARM_MINUTES_MASK; in rv3028_alarm_set_time()
583 regs[0] = RV3028_ALARM_MINUTES_AE_M; in rv3028_alarm_set_time()
587 regs[1] = bin2bcd(timeptr->tm_hour) & RV3028_ALARM_HOURS_24H_MASK; in rv3028_alarm_set_time()
589 regs[1] = RV3028_ALARM_HOURS_AE_H; in rv3028_alarm_set_time()
593 regs[2] = bin2bcd(timeptr->tm_mday) & RV3028_ALARM_DATE_MASK; in rv3028_alarm_set_time()
595 regs[2] = RV3028_ALARM_DATE_AE_WD; in rv3028_alarm_set_time()
599 timeptr->tm_mday, timeptr->tm_hour, timeptr->tm_min, mask); in rv3028_alarm_set_time()
602 return rv3028_write_regs(dev, RV3028_REG_ALARM_MINUTES, ®s, sizeof(regs)); in rv3028_alarm_set_time()
608 uint8_t regs[3]; in rv3028_alarm_get_time() local
613 return -EINVAL; in rv3028_alarm_get_time()
617 err = rv3028_read_regs(dev, RV3028_REG_ALARM_MINUTES, ®s, sizeof(regs)); in rv3028_alarm_get_time()
625 if ((regs[0] & RV3028_ALARM_MINUTES_AE_M) == 0) { in rv3028_alarm_get_time()
626 timeptr->tm_min = bcd2bin(regs[0] & RV3028_ALARM_MINUTES_MASK); in rv3028_alarm_get_time()
630 if ((regs[1] & RV3028_ALARM_HOURS_AE_H) == 0) { in rv3028_alarm_get_time()
631 timeptr->tm_hour = bcd2bin(regs[1] & RV3028_ALARM_HOURS_24H_MASK); in rv3028_alarm_get_time()
635 if ((regs[2] & RV3028_ALARM_DATE_AE_WD) == 0) { in rv3028_alarm_get_time()
636 timeptr->tm_mday = bcd2bin(regs[2] & RV3028_ALARM_DATE_MASK); in rv3028_alarm_get_time()
641 timeptr->tm_mday, timeptr->tm_hour, timeptr->tm_min, *mask); in rv3028_alarm_get_time()
653 return -EINVAL; in rv3028_alarm_is_pending()
691 return -ENOTSUP; in rv3028_alarm_set_callback()
693 const struct rv3028_config *config = dev->config; in rv3028_alarm_set_callback()
694 struct rv3028_data *data = dev->data; in rv3028_alarm_set_callback()
697 if (config->gpio_int.port == NULL) { in rv3028_alarm_set_callback()
698 return -ENOTSUP; in rv3028_alarm_set_callback()
703 return -EINVAL; in rv3028_alarm_set_callback()
708 data->alarm_callback = callback; in rv3028_alarm_set_callback()
709 data->alarm_user_data = user_data; in rv3028_alarm_set_callback()
721 k_work_submit(&data->work); in rv3028_alarm_set_callback()
734 const struct rv3028_config *config = dev->config; in rv3028_update_set_callback()
735 struct rv3028_data *data = dev->data; in rv3028_update_set_callback()
738 if (config->gpio_int.port == NULL) { in rv3028_update_set_callback()
739 return -ENOTSUP; in rv3028_update_set_callback()
744 data->update_callback = callback; in rv3028_update_set_callback()
745 data->update_user_data = user_data; in rv3028_update_set_callback()
757 k_work_submit(&data->work); in rv3028_update_set_callback()
766 const struct rv3028_config *config = dev->config; in rv3028_init()
767 struct rv3028_data *data = dev->data; in rv3028_init()
768 uint8_t regs[3]; in rv3028_init() local
772 k_sem_init(&data->lock, 1, 1); in rv3028_init()
774 if (!i2c_is_ready_dt(&config->i2c)) { in rv3028_init()
776 return -ENODEV; in rv3028_init()
781 return -ENODEV; in rv3028_init()
787 if (config->gpio_int.port != NULL) { in rv3028_init()
788 if (!gpio_is_ready_dt(&config->gpio_int)) { in rv3028_init()
790 return -ENODEV; in rv3028_init()
793 err = gpio_pin_configure_dt(&config->gpio_int, GPIO_INPUT); in rv3028_init()
796 return -ENODEV; in rv3028_init()
799 err = gpio_pin_interrupt_configure_dt(&config->gpio_int, GPIO_INT_EDGE_TO_ACTIVE); in rv3028_init()
805 gpio_init_callback(&data->int_callback, rv3028_int_handler, in rv3028_init()
806 BIT(config->gpio_int.pin)); in rv3028_init()
808 err = gpio_add_callback_dt(&config->gpio_int, &data->int_callback); in rv3028_init()
811 return -ENODEV; in rv3028_init()
814 data->dev = dev; in rv3028_init()
815 data->work.handler = rv3028_work_cb; in rv3028_init()
821 return -ENODEV; in rv3028_init()
831 return -ENODEV; in rv3028_init()
835 return -ENODEV; in rv3028_init()
839 val = FIELD_PREP(RV3028_CLKOUT_FD, config->cof) | in rv3028_init()
840 (config->cof != RV3028_CLKOUT_FD_LOW ? RV3028_CLKOUT_CLKOE : 0); in rv3028_init()
846 return -ENODEV; in rv3028_init()
852 config->backup); in rv3028_init()
854 return -ENODEV; in rv3028_init()
860 return -ENODEV; in rv3028_init()
869 return -ENODEV; in rv3028_init()
872 err = rv3028_read_regs(dev, RV3028_REG_ALARM_MINUTES, regs, sizeof(regs)); in rv3028_init()
874 return -ENODEV; in rv3028_init()
877 regs[0] |= RV3028_ALARM_MINUTES_AE_M; in rv3028_init()
878 regs[1] |= RV3028_ALARM_HOURS_AE_H; in rv3028_init()
879 regs[2] |= RV3028_ALARM_DATE_AE_WD; in rv3028_init()
881 err = rv3028_write_regs(dev, RV3028_REG_ALARM_MINUTES, regs, sizeof(regs)); in rv3028_init()
883 return -ENODEV; in rv3028_init()
916 .backup = RV3028_BACKUP_FROM_DT_INST(inst), \