Jakub Topic | 2efc447 | 2024-05-31 22:23:13 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2024 ANITRA system s.r.o. |
| 3 | * |
| 4 | * SPDX-License-Identifier: Apache-2.0 |
| 5 | */ |
| 6 | |
| 7 | #define DT_DRV_COMPAT microcrystal_rv3028 |
| 8 | |
| 9 | #include <zephyr/kernel.h> |
| 10 | #include <zephyr/drivers/gpio.h> |
| 11 | #include <zephyr/drivers/i2c.h> |
| 12 | #include <zephyr/drivers/rtc.h> |
| 13 | #include <zephyr/logging/log.h> |
| 14 | #include <zephyr/sys/util.h> |
| 15 | #include "rtc_utils.h" |
| 16 | |
| 17 | LOG_MODULE_REGISTER(rv3028, CONFIG_RTC_LOG_LEVEL); |
| 18 | |
| 19 | /* RV3028 RAM register addresses */ |
| 20 | #define RV3028_REG_SECONDS 0x00 |
| 21 | #define RV3028_REG_MINUTES 0x01 |
| 22 | #define RV3028_REG_HOURS 0x02 |
| 23 | #define RV3028_REG_WEEKDAY 0x03 |
| 24 | #define RV3028_REG_DATE 0x04 |
| 25 | #define RV3028_REG_MONTH 0x05 |
| 26 | #define RV3028_REG_YEAR 0x06 |
| 27 | #define RV3028_REG_ALARM_MINUTES 0x07 |
| 28 | #define RV3028_REG_ALARM_HOURS 0x08 |
| 29 | #define RV3028_REG_ALARM_WEEKDAY 0x09 |
| 30 | #define RV3028_REG_STATUS 0x0E |
| 31 | #define RV3028_REG_CONTROL1 0x0F |
| 32 | #define RV3028_REG_CONTROL2 0x10 |
| 33 | #define RV3028_REG_EVENT_CONTROL 0x13 |
| 34 | #define RV3028_REG_TS_COUNT 0x14 |
| 35 | #define RV3028_REG_TS_SECONDS 0x15 |
| 36 | #define RV3028_REG_TS_MINUTES 0x16 |
| 37 | #define RV3028_REG_TS_HOURS 0x17 |
| 38 | #define RV3028_REG_TS_DATE 0x18 |
| 39 | #define RV3028_REG_TS_MONTH 0x19 |
| 40 | #define RV3028_REG_TS_YEAR 0x1A |
| 41 | #define RV3028_REG_UNIXTIME0 0x1B |
| 42 | #define RV3028_REG_UNIXTIME1 0x1C |
| 43 | #define RV3028_REG_UNIXTIME2 0x1D |
| 44 | #define RV3028_REG_UNIXTIME3 0x1E |
| 45 | #define RV3028_REG_USER_RAM1 0x1F |
| 46 | #define RV3028_REG_USER_RAM2 0x20 |
| 47 | #define RV3028_REG_EEPROM_ADDRESS 0x25 |
| 48 | #define RV3028_REG_EEPROM_DATA 0x26 |
| 49 | #define RV3028_REG_EEPROM_COMMAND 0x27 |
| 50 | #define RV3028_REG_ID 0x28 |
| 51 | #define RV3028_REG_CLKOUT 0x35 |
| 52 | #define RV3028_REG_OFFSET 0x36 |
| 53 | #define RV3028_REG_BACKUP 0x37 |
| 54 | |
| 55 | #define RV3028_CONTROL1_TD BIT(0) |
| 56 | #define RV3028_CONTROL1_TE GENMASK(2, 1) |
| 57 | #define RV3028_CONTROL1_EERD BIT(3) |
| 58 | #define RV3028_CONTROL1_USEL BIT(4) |
| 59 | #define RV3028_CONTROL1_WADA BIT(5) |
| 60 | #define RV3028_CONTROL1_TRPT BIT(7) |
| 61 | |
| 62 | #define RV3028_CONTROL2_RESET BIT(0) |
| 63 | #define RV3028_CONTROL2_12_24 BIT(1) |
| 64 | #define RV3028_CONTROL2_EIE BIT(2) |
| 65 | #define RV3028_CONTROL2_AIE BIT(3) |
| 66 | #define RV3028_CONTROL2_TIE BIT(4) |
| 67 | #define RV3028_CONTROL2_UIE BIT(5) |
| 68 | #define RV3028_CONTROL2_TSE BIT(7) |
| 69 | |
| 70 | #define RV3028_STATUS_PORF BIT(0) |
| 71 | #define RV3028_STATUS_EVF BIT(1) |
| 72 | #define RV3028_STATUS_AF BIT(2) |
| 73 | #define RV3028_STATUS_TF BIT(3) |
| 74 | #define RV3028_STATUS_UF BIT(4) |
| 75 | #define RV3028_STATUS_BSF BIT(5) |
| 76 | #define RV3028_STATUS_CLKF BIT(6) |
| 77 | #define RV3028_STATUS_EEBUSY BIT(7) |
| 78 | |
| 79 | #define RV3028_CLKOUT_FD GENMASK(2, 0) |
| 80 | #define RV3028_CLKOUT_PORIE BIT(3) |
| 81 | #define RV3028_CLKOUT_CLKSY BIT(6) |
| 82 | #define RV3028_CLKOUT_CLKOE BIT(7) |
| 83 | |
| 84 | #define RV3028_CLKOUT_FD_LOW 0x7 |
| 85 | |
| 86 | #define RV3028_BACKUP_TCE BIT(5) |
| 87 | #define RV3028_BACKUP_TCR GENMASK(1, 0) |
| 88 | #define RV3028_BACKUP_BSM GENMASK(3, 2) |
| 89 | |
| 90 | #define RV3028_BSM_LEVEL 0x3 |
| 91 | #define RV3028_BSM_DIRECT 0x1 |
| 92 | #define RV3028_BSM_DISABLED 0x0 |
| 93 | |
| 94 | /* RV3028 EE command register values */ |
| 95 | #define RV3028_EEPROM_CMD_INIT 0x00 |
| 96 | #define RV3028_EEPROM_CMD_UPDATE 0x11 |
| 97 | #define RV3028_EEPROM_CMD_REFRESH 0x12 |
| 98 | #define RV3028_EEPROM_CMD_WRITE 0x21 |
| 99 | #define RV3028_EEPROM_CMD_READ 0x22 |
| 100 | |
| 101 | #define RV3028_SECONDS_MASK GENMASK(6, 0) |
| 102 | #define RV3028_MINUTES_MASK GENMASK(6, 0) |
| 103 | #define RV3028_HOURS_AMPM BIT(5) |
| 104 | #define RV3028_HOURS_12H_MASK GENMASK(4, 0) |
| 105 | #define RV3028_HOURS_24H_MASK GENMASK(5, 0) |
| 106 | #define RV3028_DATE_MASK GENMASK(5, 0) |
| 107 | #define RV3028_WEEKDAY_MASK GENMASK(2, 0) |
| 108 | #define RV3028_MONTH_MASK GENMASK(4, 0) |
| 109 | #define RV3028_YEAR_MASK GENMASK(7, 0) |
| 110 | |
| 111 | #define RV3028_ALARM_MINUTES_AE_M BIT(7) |
| 112 | #define RV3028_ALARM_MINUTES_MASK GENMASK(6, 0) |
| 113 | #define RV3028_ALARM_HOURS_AE_H BIT(7) |
| 114 | #define RV3028_ALARM_HOURS_AMPM BIT(5) |
| 115 | #define RV3028_ALARM_HOURS_12H_MASK GENMASK(4, 0) |
| 116 | #define RV3028_ALARM_HOURS_24H_MASK GENMASK(5, 0) |
| 117 | #define RV3028_ALARM_DATE_AE_WD BIT(7) |
| 118 | #define RV3028_ALARM_DATE_MASK GENMASK(5, 0) |
| 119 | |
| 120 | /* The RV3028 only supports two-digit years. Leap years are correctly handled from 2000 to 2099 */ |
| 121 | #define RV3028_YEAR_OFFSET (2000 - 1900) |
| 122 | |
| 123 | /* The RV3028 enumerates months 1 to 12 */ |
| 124 | #define RV3028_MONTH_OFFSET 1 |
| 125 | |
| 126 | #define RV3028_EEBUSY_POLL_US 10000 |
| 127 | #define RV3028_EEBUSY_TIMEOUT_MS 100 |
| 128 | |
| 129 | /* RTC alarm time fields supported by the RV3028 */ |
| 130 | #define RV3028_RTC_ALARM_TIME_MASK \ |
| 131 | (RTC_ALARM_TIME_MASK_MINUTE | RTC_ALARM_TIME_MASK_HOUR | RTC_ALARM_TIME_MASK_MONTHDAY) |
| 132 | |
| 133 | /* RTC time fields supported by the RV3028 */ |
| 134 | #define RV3028_RTC_TIME_MASK \ |
| 135 | (RTC_ALARM_TIME_MASK_SECOND | RTC_ALARM_TIME_MASK_MINUTE | RTC_ALARM_TIME_MASK_HOUR | \ |
Jakub Topic | 4fe32e1 | 2024-06-17 18:31:46 +0200 | [diff] [blame] | 136 | RTC_ALARM_TIME_MASK_MONTH | RTC_ALARM_TIME_MASK_MONTHDAY | RTC_ALARM_TIME_MASK_YEAR | \ |
| 137 | RTC_ALARM_TIME_MASK_WEEKDAY) |
Jakub Topic | 2efc447 | 2024-05-31 22:23:13 +0200 | [diff] [blame] | 138 | |
| 139 | /* Helper macro to guard int-gpios related code */ |
| 140 | #if DT_ANY_INST_HAS_PROP_STATUS_OKAY(int_gpios) && \ |
| 141 | (defined(CONFIG_RTC_ALARM) || defined(CONFIG_RTC_UPDATE)) |
| 142 | #define RV3028_INT_GPIOS_IN_USE 1 |
| 143 | #endif |
| 144 | |
| 145 | struct rv3028_config { |
| 146 | const struct i2c_dt_spec i2c; |
| 147 | #ifdef RV3028_INT_GPIOS_IN_USE |
| 148 | struct gpio_dt_spec gpio_int; |
| 149 | #endif /* RV3028_INT_GPIOS_IN_USE */ |
| 150 | uint8_t cof; |
| 151 | uint8_t backup; |
| 152 | }; |
| 153 | |
| 154 | struct rv3028_data { |
| 155 | struct k_sem lock; |
| 156 | #if RV3028_INT_GPIOS_IN_USE |
| 157 | const struct device *dev; |
| 158 | struct gpio_callback int_callback; |
| 159 | struct k_work work; |
| 160 | |
| 161 | #ifdef CONFIG_RTC_ALARM |
| 162 | rtc_alarm_callback alarm_callback; |
| 163 | void *alarm_user_data; |
| 164 | #endif /* CONFIG_RTC_ALARM */ |
| 165 | #ifdef CONFIG_RTC_UPDATE |
| 166 | rtc_update_callback update_callback; |
| 167 | void *update_user_data; |
| 168 | #endif /* CONFIG_RTC_UPDATE */ |
| 169 | #endif /* RV3028_INT_GPIOS_IN_USE */ |
| 170 | }; |
| 171 | |
| 172 | static void rv3028_lock_sem(const struct device *dev) |
| 173 | { |
| 174 | struct rv3028_data *data = dev->data; |
| 175 | |
| 176 | (void)k_sem_take(&data->lock, K_FOREVER); |
| 177 | } |
| 178 | |
| 179 | static void rv3028_unlock_sem(const struct device *dev) |
| 180 | { |
| 181 | struct rv3028_data *data = dev->data; |
| 182 | |
| 183 | k_sem_give(&data->lock); |
| 184 | } |
| 185 | |
| 186 | static int rv3028_read_regs(const struct device *dev, uint8_t addr, void *buf, size_t len) |
| 187 | { |
| 188 | const struct rv3028_config *config = dev->config; |
| 189 | int err; |
| 190 | |
| 191 | err = i2c_write_read_dt(&config->i2c, &addr, sizeof(addr), buf, len); |
| 192 | if (err) { |
| 193 | LOG_ERR("failed to read reg addr 0x%02x, len %d (err %d)", addr, len, err); |
| 194 | return err; |
| 195 | } |
| 196 | |
| 197 | return 0; |
| 198 | } |
| 199 | |
| 200 | static int rv3028_read_reg8(const struct device *dev, uint8_t addr, uint8_t *val) |
| 201 | { |
| 202 | return rv3028_read_regs(dev, addr, val, sizeof(*val)); |
| 203 | } |
| 204 | |
| 205 | static int rv3028_write_regs(const struct device *dev, uint8_t addr, void *buf, size_t len) |
| 206 | { |
| 207 | const struct rv3028_config *config = dev->config; |
| 208 | uint8_t block[sizeof(addr) + len]; |
| 209 | int err; |
| 210 | |
| 211 | block[0] = addr; |
| 212 | memcpy(&block[1], buf, len); |
| 213 | |
| 214 | err = i2c_write_dt(&config->i2c, block, sizeof(block)); |
| 215 | if (err) { |
| 216 | LOG_ERR("failed to write reg addr 0x%02x, len %d (err %d)", addr, len, err); |
| 217 | return err; |
| 218 | } |
| 219 | |
| 220 | return 0; |
| 221 | } |
| 222 | |
| 223 | static int rv3028_write_reg8(const struct device *dev, uint8_t addr, uint8_t val) |
| 224 | { |
| 225 | return rv3028_write_regs(dev, addr, &val, sizeof(val)); |
| 226 | } |
| 227 | |
| 228 | static int rv3028_update_reg8(const struct device *dev, uint8_t addr, uint8_t mask, uint8_t val) |
| 229 | { |
| 230 | const struct rv3028_config *config = dev->config; |
| 231 | int err; |
| 232 | |
| 233 | err = i2c_reg_update_byte_dt(&config->i2c, addr, mask, val); |
| 234 | if (err) { |
| 235 | LOG_ERR("failed to update reg addr 0x%02x, mask 0x%02x, val 0x%02x (err %d)", addr, |
| 236 | mask, val, err); |
| 237 | return err; |
| 238 | } |
| 239 | |
| 240 | return 0; |
| 241 | } |
| 242 | |
| 243 | static int rv3028_eeprom_wait_busy(const struct device *dev) |
| 244 | { |
| 245 | uint8_t status = 0; |
| 246 | int err; |
| 247 | int64_t timeout_time = k_uptime_get() + RV3028_EEBUSY_TIMEOUT_MS; |
| 248 | |
| 249 | /* Wait while the EEPROM is busy */ |
| 250 | for (;;) { |
| 251 | err = rv3028_read_reg8(dev, RV3028_REG_STATUS, &status); |
| 252 | if (err) { |
| 253 | return err; |
| 254 | } |
| 255 | |
| 256 | if (!(status & RV3028_STATUS_EEBUSY)) { |
| 257 | break; |
| 258 | } |
| 259 | |
| 260 | if (k_uptime_get() > timeout_time) { |
| 261 | return -ETIME; |
| 262 | } |
| 263 | |
| 264 | k_busy_wait(RV3028_EEBUSY_POLL_US); |
| 265 | } |
| 266 | |
| 267 | return 0; |
| 268 | } |
| 269 | |
| 270 | static int rv3028_exit_eerd(const struct device *dev) |
| 271 | { |
| 272 | return rv3028_update_reg8(dev, RV3028_REG_CONTROL1, RV3028_CONTROL1_EERD, 0); |
| 273 | } |
| 274 | |
| 275 | static int rv3028_enter_eerd(const struct device *dev) |
| 276 | { |
| 277 | uint8_t ctrl1; |
| 278 | bool eerd; |
| 279 | int ret; |
| 280 | |
| 281 | ret = rv3028_read_reg8(dev, RV3028_REG_CONTROL1, &ctrl1); |
| 282 | if (ret) { |
| 283 | return ret; |
| 284 | } |
| 285 | |
| 286 | eerd = ctrl1 & RV3028_CONTROL1_EERD; |
| 287 | if (eerd) { |
| 288 | return 0; |
| 289 | } |
| 290 | |
| 291 | ret = rv3028_update_reg8(dev, RV3028_REG_CONTROL1, RV3028_CONTROL1_EERD, |
| 292 | RV3028_CONTROL1_EERD); |
| 293 | |
| 294 | ret = rv3028_eeprom_wait_busy(dev); |
| 295 | if (ret) { |
| 296 | rv3028_exit_eerd(dev); |
| 297 | return ret; |
| 298 | } |
| 299 | |
| 300 | return ret; |
| 301 | } |
| 302 | |
| 303 | static int rv3028_eeprom_command(const struct device *dev, uint8_t command) |
| 304 | { |
| 305 | int err; |
| 306 | |
| 307 | err = rv3028_write_reg8(dev, RV3028_REG_EEPROM_COMMAND, RV3028_EEPROM_CMD_INIT); |
| 308 | if (err) { |
| 309 | return err; |
| 310 | } |
| 311 | |
| 312 | return rv3028_write_reg8(dev, RV3028_REG_EEPROM_COMMAND, command); |
| 313 | } |
| 314 | |
| 315 | static int rv3028_update(const struct device *dev) |
| 316 | { |
| 317 | int err; |
| 318 | |
| 319 | err = rv3028_eeprom_command(dev, RV3028_EEPROM_CMD_UPDATE); |
| 320 | if (err) { |
| 321 | goto exit_eerd; |
| 322 | } |
| 323 | |
| 324 | err = rv3028_eeprom_wait_busy(dev); |
| 325 | |
| 326 | exit_eerd: |
| 327 | rv3028_exit_eerd(dev); |
| 328 | |
| 329 | return err; |
| 330 | } |
| 331 | |
| 332 | static int rv3028_refresh(const struct device *dev) |
| 333 | { |
| 334 | int err; |
| 335 | |
| 336 | err = rv3028_eeprom_command(dev, RV3028_EEPROM_CMD_REFRESH); |
| 337 | if (err) { |
| 338 | goto exit_eerd; |
| 339 | } |
| 340 | |
| 341 | err = rv3028_eeprom_wait_busy(dev); |
| 342 | |
| 343 | exit_eerd: |
| 344 | rv3028_exit_eerd(dev); |
| 345 | |
| 346 | return err; |
| 347 | } |
| 348 | |
| 349 | static int rv3028_update_cfg(const struct device *dev, uint8_t addr, uint8_t mask, uint8_t val) |
| 350 | { |
| 351 | uint8_t val_old, val_new; |
| 352 | int err; |
| 353 | |
| 354 | err = rv3028_read_reg8(dev, addr, &val_old); |
| 355 | if (err) { |
| 356 | return err; |
| 357 | } |
| 358 | |
| 359 | val_new = (val_old & ~mask) | (val & mask); |
| 360 | if (val_new == val_old) { |
| 361 | return 0; |
| 362 | } |
| 363 | |
| 364 | err = rv3028_enter_eerd(dev); |
| 365 | if (err) { |
| 366 | return err; |
| 367 | } |
| 368 | |
| 369 | err = rv3028_write_reg8(dev, addr, val_new); |
| 370 | if (err) { |
| 371 | rv3028_exit_eerd(dev); |
| 372 | return err; |
| 373 | } |
| 374 | |
| 375 | return rv3028_update(dev); |
| 376 | } |
| 377 | |
| 378 | #if RV3028_INT_GPIOS_IN_USE |
| 379 | |
| 380 | static int rv3028_int_enable_unlocked(const struct device *dev, bool enable) |
| 381 | { |
| 382 | const struct rv3028_config *config = dev->config; |
| 383 | uint8_t clkout = 0; |
| 384 | int err; |
| 385 | |
| 386 | if (enable || config->cof == RV3028_CLKOUT_FD_LOW) { |
| 387 | /* Disable CLKOUT */ |
| 388 | clkout |= FIELD_PREP(RV3028_CLKOUT_FD, RV3028_CLKOUT_FD_LOW); |
| 389 | } else { |
| 390 | /* Configure CLKOUT frequency */ |
| 391 | clkout |= RV3028_CLKOUT_CLKOE | |
| 392 | FIELD_PREP(RV3028_CLKOUT_FD, config->cof); |
| 393 | } |
| 394 | |
| 395 | /* Configure the CLKOUT register */ |
| 396 | err = rv3028_update_cfg(dev, |
| 397 | RV3028_REG_CLKOUT, |
| 398 | RV3028_CLKOUT_FD | RV3028_CLKOUT_CLKOE, |
| 399 | clkout); |
| 400 | if (err) { |
| 401 | return err; |
| 402 | } |
| 403 | |
| 404 | err = gpio_pin_interrupt_configure_dt(&config->gpio_int, |
| 405 | enable ? GPIO_INT_EDGE_TO_ACTIVE : GPIO_INT_DISABLE); |
| 406 | if (err) { |
| 407 | LOG_ERR("failed to %s GPIO interrupt (err %d)", enable ? "enable" : "disable", err); |
| 408 | return err; |
| 409 | } |
| 410 | |
| 411 | return 0; |
| 412 | } |
| 413 | |
| 414 | static void rv3028_work_cb(struct k_work *work) |
| 415 | { |
| 416 | struct rv3028_data *data = CONTAINER_OF(work, struct rv3028_data, work); |
| 417 | const struct device *dev = data->dev; |
| 418 | rtc_alarm_callback alarm_callback = NULL; |
| 419 | void *alarm_user_data = NULL; |
| 420 | rtc_update_callback update_callback = NULL; |
| 421 | void *update_user_data = NULL; |
| 422 | uint8_t status; |
| 423 | int err; |
| 424 | |
| 425 | rv3028_lock_sem(dev); |
| 426 | |
| 427 | err = rv3028_read_reg8(data->dev, RV3028_REG_STATUS, &status); |
| 428 | if (err) { |
| 429 | goto unlock; |
| 430 | } |
| 431 | |
| 432 | #ifdef CONFIG_RTC_ALARM |
| 433 | if ((status & RV3028_STATUS_AF) && data->alarm_callback != NULL) { |
| 434 | status &= ~(RV3028_STATUS_AF); |
| 435 | alarm_callback = data->alarm_callback; |
| 436 | alarm_user_data = data->alarm_user_data; |
| 437 | } |
| 438 | #endif /* CONFIG_RTC_ALARM */ |
| 439 | |
| 440 | #ifdef CONFIG_RTC_UPDATE |
| 441 | if ((status & RV3028_STATUS_UF) && data->update_callback != NULL) { |
| 442 | status &= ~(RV3028_STATUS_UF); |
| 443 | update_callback = data->update_callback; |
| 444 | update_user_data = data->update_user_data; |
| 445 | } |
| 446 | #endif /* CONFIG_RTC_UPDATE */ |
| 447 | |
| 448 | err = rv3028_write_reg8(dev, RV3028_REG_STATUS, status); |
| 449 | if (err) { |
| 450 | goto unlock; |
| 451 | } |
| 452 | |
| 453 | /* Check if interrupt occurred between STATUS read/write */ |
| 454 | err = rv3028_read_reg8(dev, RV3028_REG_STATUS, &status); |
| 455 | if (err) { |
| 456 | goto unlock; |
| 457 | } |
| 458 | |
| 459 | if (((status & RV3028_STATUS_AF) && alarm_callback != NULL) || |
| 460 | ((status & RV3028_STATUS_UF) && update_callback != NULL)) { |
| 461 | /* Another interrupt occurred while servicing this one */ |
| 462 | k_work_submit(&data->work); |
| 463 | } |
| 464 | |
| 465 | unlock: |
| 466 | rv3028_unlock_sem(dev); |
| 467 | |
| 468 | if (alarm_callback != NULL) { |
| 469 | alarm_callback(dev, 0U, alarm_user_data); |
| 470 | alarm_callback = NULL; |
| 471 | } |
| 472 | |
| 473 | if (update_callback != NULL) { |
| 474 | update_callback(dev, update_user_data); |
| 475 | update_callback = NULL; |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | static void rv3028_int_handler(const struct device *port, struct gpio_callback *cb, |
| 480 | gpio_port_pins_t pins) |
| 481 | { |
| 482 | struct rv3028_data *data = CONTAINER_OF(cb, struct rv3028_data, int_callback); |
| 483 | |
| 484 | ARG_UNUSED(port); |
| 485 | ARG_UNUSED(pins); |
| 486 | |
| 487 | k_work_submit(&data->work); |
| 488 | } |
| 489 | |
| 490 | #endif /* RV3028_INT_GPIOS_IN_USE */ |
| 491 | |
| 492 | static int rv3028_set_time(const struct device *dev, const struct rtc_time *timeptr) |
| 493 | { |
| 494 | uint8_t date[7]; |
| 495 | int err; |
| 496 | |
| 497 | if (timeptr == NULL || |
| 498 | !rtc_utils_validate_rtc_time(timeptr, RV3028_RTC_TIME_MASK) || |
| 499 | (timeptr->tm_year < RV3028_YEAR_OFFSET)) { |
| 500 | LOG_ERR("invalid time"); |
| 501 | return -EINVAL; |
| 502 | } |
| 503 | |
| 504 | rv3028_lock_sem(dev); |
| 505 | |
| 506 | LOG_DBG("set time: year = %d, mon = %d, mday = %d, wday = %d, hour = %d, " |
| 507 | "min = %d, sec = %d", |
| 508 | timeptr->tm_year, timeptr->tm_mon, timeptr->tm_mday, timeptr->tm_wday, |
| 509 | timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec); |
| 510 | |
| 511 | date[0] = bin2bcd(timeptr->tm_sec) & RV3028_SECONDS_MASK; |
| 512 | date[1] = bin2bcd(timeptr->tm_min) & RV3028_MINUTES_MASK; |
| 513 | date[2] = bin2bcd(timeptr->tm_hour) & RV3028_HOURS_24H_MASK; |
| 514 | date[3] = bin2bcd(timeptr->tm_wday) & RV3028_WEEKDAY_MASK; |
| 515 | date[4] = bin2bcd(timeptr->tm_mday) & RV3028_DATE_MASK; |
| 516 | date[5] = bin2bcd(timeptr->tm_mon + RV3028_MONTH_OFFSET) & RV3028_MONTH_MASK; |
| 517 | date[6] = bin2bcd(timeptr->tm_year - RV3028_YEAR_OFFSET) & RV3028_YEAR_MASK; |
| 518 | |
| 519 | err = rv3028_write_regs(dev, RV3028_REG_SECONDS, &date, sizeof(date)); |
| 520 | if (err) { |
| 521 | goto unlock; |
| 522 | } |
| 523 | |
| 524 | /* Clear Power On Reset Flag */ |
| 525 | err = rv3028_update_reg8(dev, RV3028_REG_STATUS, RV3028_STATUS_PORF, 0); |
| 526 | |
| 527 | unlock: |
| 528 | rv3028_unlock_sem(dev); |
| 529 | |
| 530 | return err; |
| 531 | } |
| 532 | |
| 533 | static int rv3028_get_time(const struct device *dev, struct rtc_time *timeptr) |
| 534 | { |
| 535 | uint8_t status; |
| 536 | uint8_t date[7]; |
| 537 | int err; |
| 538 | |
| 539 | if (timeptr == NULL) { |
| 540 | return -EINVAL; |
| 541 | } |
| 542 | |
| 543 | err = rv3028_read_reg8(dev, RV3028_REG_STATUS, &status); |
| 544 | if (err) { |
| 545 | return err; |
| 546 | } |
| 547 | |
| 548 | if (status & RV3028_STATUS_PORF) { |
| 549 | /* Power On Reset Flag indicates invalid data */ |
| 550 | return -ENODATA; |
| 551 | } |
| 552 | |
| 553 | err = rv3028_read_regs(dev, RV3028_REG_SECONDS, date, sizeof(date)); |
| 554 | if (err) { |
| 555 | return err; |
| 556 | } |
| 557 | |
| 558 | memset(timeptr, 0U, sizeof(*timeptr)); |
| 559 | timeptr->tm_sec = bcd2bin(date[0] & RV3028_SECONDS_MASK); |
| 560 | timeptr->tm_min = bcd2bin(date[1] & RV3028_MINUTES_MASK); |
| 561 | timeptr->tm_hour = bcd2bin(date[2] & RV3028_HOURS_24H_MASK); |
| 562 | timeptr->tm_wday = bcd2bin(date[3] & RV3028_WEEKDAY_MASK); |
| 563 | timeptr->tm_mday = bcd2bin(date[4] & RV3028_DATE_MASK); |
| 564 | timeptr->tm_mon = bcd2bin(date[5] & RV3028_MONTH_MASK) - RV3028_MONTH_OFFSET; |
| 565 | timeptr->tm_year = bcd2bin(date[6] & RV3028_YEAR_MASK) + RV3028_YEAR_OFFSET; |
| 566 | timeptr->tm_yday = -1; |
| 567 | timeptr->tm_isdst = -1; |
| 568 | |
| 569 | LOG_DBG("get time: year = %d, mon = %d, mday = %d, wday = %d, hour = %d, " |
| 570 | "min = %d, sec = %d", |
| 571 | timeptr->tm_year, timeptr->tm_mon, timeptr->tm_mday, timeptr->tm_wday, |
| 572 | timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec); |
| 573 | |
| 574 | return 0; |
| 575 | } |
| 576 | |
| 577 | #ifdef CONFIG_RTC_ALARM |
| 578 | |
| 579 | static int rv3028_alarm_get_supported_fields(const struct device *dev, uint16_t id, uint16_t *mask) |
| 580 | { |
| 581 | ARG_UNUSED(dev); |
| 582 | |
| 583 | if (id != 0U) { |
| 584 | LOG_ERR("invalid alarm ID %d", id); |
| 585 | return -EINVAL; |
| 586 | } |
| 587 | |
| 588 | *mask = RV3028_RTC_ALARM_TIME_MASK; |
| 589 | |
| 590 | return 0; |
| 591 | } |
| 592 | |
| 593 | static int rv3028_alarm_set_time(const struct device *dev, uint16_t id, uint16_t mask, |
| 594 | const struct rtc_time *timeptr) |
| 595 | { |
| 596 | uint8_t regs[3]; |
| 597 | |
| 598 | if (id != 0U) { |
| 599 | LOG_ERR("invalid alarm ID %d", id); |
| 600 | return -EINVAL; |
| 601 | } |
| 602 | |
| 603 | if (mask & ~(RV3028_RTC_ALARM_TIME_MASK)) { |
| 604 | LOG_ERR("unsupported alarm field mask 0x%04x", mask); |
| 605 | return -EINVAL; |
| 606 | } |
| 607 | |
| 608 | if (!rtc_utils_validate_rtc_time(timeptr, mask)) { |
| 609 | LOG_ERR("invalid alarm time"); |
| 610 | return -EINVAL; |
| 611 | } |
| 612 | |
| 613 | if (mask & RTC_ALARM_TIME_MASK_MINUTE) { |
| 614 | regs[0] = bin2bcd(timeptr->tm_min) & RV3028_ALARM_MINUTES_MASK; |
| 615 | } else { |
| 616 | regs[0] = RTC_ALARM_TIME_MASK_MINUTE; |
| 617 | } |
| 618 | |
| 619 | if (mask & RTC_ALARM_TIME_MASK_HOUR) { |
| 620 | regs[1] = bin2bcd(timeptr->tm_hour) & RV3028_ALARM_HOURS_24H_MASK; |
| 621 | } else { |
| 622 | regs[1] = RV3028_ALARM_HOURS_AE_H; |
| 623 | } |
| 624 | |
| 625 | if (mask & RTC_ALARM_TIME_MASK_MONTHDAY) { |
| 626 | regs[2] = bin2bcd(timeptr->tm_mday) & RV3028_ALARM_DATE_MASK; |
| 627 | } else { |
| 628 | regs[2] = RV3028_ALARM_DATE_AE_WD; |
| 629 | } |
| 630 | |
| 631 | LOG_DBG("set alarm: mday = %d, hour = %d, min = %d, mask = 0x%04x", |
| 632 | timeptr->tm_mday, timeptr->tm_hour, timeptr->tm_min, mask); |
| 633 | |
| 634 | /* Write registers RV3028_REG_ALARM_MINUTES through RV3028_REG_ALARM_WEEKDAY */ |
| 635 | return rv3028_write_regs(dev, RV3028_REG_ALARM_MINUTES, ®s, sizeof(regs)); |
| 636 | } |
| 637 | |
| 638 | static int rv3028_alarm_get_time(const struct device *dev, uint16_t id, uint16_t *mask, |
| 639 | struct rtc_time *timeptr) |
| 640 | { |
| 641 | uint8_t regs[3]; |
| 642 | int err; |
| 643 | |
| 644 | if (id != 0U) { |
| 645 | LOG_ERR("invalid alarm ID %d", id); |
| 646 | return -EINVAL; |
| 647 | } |
| 648 | |
| 649 | /* Read registers RV3028_REG_ALARM_MINUTES through RV3028_REG_ALARM_WEEKDAY */ |
| 650 | err = rv3028_read_regs(dev, RV3028_REG_ALARM_MINUTES, ®s, sizeof(regs)); |
| 651 | if (err) { |
| 652 | return err; |
| 653 | } |
| 654 | |
| 655 | memset(timeptr, 0U, sizeof(*timeptr)); |
| 656 | *mask = 0U; |
| 657 | |
| 658 | if ((regs[0] & RV3028_ALARM_MINUTES_AE_M) == 0) { |
| 659 | timeptr->tm_min = bcd2bin(regs[0] & RV3028_ALARM_MINUTES_MASK); |
| 660 | *mask |= RTC_ALARM_TIME_MASK_MINUTE; |
| 661 | } |
| 662 | |
| 663 | if ((regs[1] & RV3028_ALARM_HOURS_AE_H) == 0) { |
| 664 | timeptr->tm_hour = bcd2bin(regs[1] & RV3028_ALARM_HOURS_24H_MASK); |
| 665 | *mask |= RTC_ALARM_TIME_MASK_HOUR; |
| 666 | } |
| 667 | |
| 668 | if ((regs[2] & RV3028_ALARM_DATE_AE_WD) == 0) { |
| 669 | timeptr->tm_mday = bcd2bin(regs[2] & RV3028_ALARM_DATE_MASK); |
| 670 | *mask |= RTC_ALARM_TIME_MASK_MONTHDAY; |
| 671 | } |
| 672 | |
| 673 | LOG_DBG("get alarm: mday = %d, hour = %d, min = %d, mask = 0x%04x", |
| 674 | timeptr->tm_mday, timeptr->tm_hour, timeptr->tm_min, *mask); |
| 675 | |
| 676 | return 0; |
| 677 | } |
| 678 | |
| 679 | static int rv3028_alarm_is_pending(const struct device *dev, uint16_t id) |
| 680 | { |
| 681 | uint8_t status; |
| 682 | int err; |
| 683 | |
| 684 | if (id != 0U) { |
| 685 | LOG_ERR("invalid alarm ID %d", id); |
| 686 | return -EINVAL; |
| 687 | } |
| 688 | |
| 689 | rv3028_lock_sem(dev); |
| 690 | |
| 691 | err = rv3028_read_reg8(dev, RV3028_REG_STATUS, &status); |
| 692 | if (err) { |
| 693 | goto unlock; |
| 694 | } |
| 695 | |
| 696 | if (status & RV3028_STATUS_AF) { |
| 697 | /* Clear alarm flag */ |
| 698 | status &= ~(RV3028_STATUS_AF); |
| 699 | |
| 700 | err = rv3028_write_reg8(dev, RV3028_REG_STATUS, status); |
| 701 | if (err) { |
| 702 | goto unlock; |
| 703 | } |
| 704 | |
| 705 | /* Alarm pending */ |
| 706 | err = 1; |
| 707 | } |
| 708 | |
| 709 | unlock: |
| 710 | rv3028_unlock_sem(dev); |
| 711 | |
| 712 | return err; |
| 713 | } |
| 714 | |
Jakub Topic | 2efc447 | 2024-05-31 22:23:13 +0200 | [diff] [blame] | 715 | static int rv3028_alarm_set_callback(const struct device *dev, uint16_t id, |
| 716 | rtc_alarm_callback callback, void *user_data) |
| 717 | { |
Jakub Topic | 7efd885 | 2024-06-13 15:26:22 +0200 | [diff] [blame] | 718 | #ifndef RV3028_INT_GPIOS_IN_USE |
| 719 | ARG_UNUSED(dev); |
| 720 | ARG_UNUSED(id); |
| 721 | ARG_UNUSED(callback); |
| 722 | ARG_UNUSED(user_data); |
| 723 | |
| 724 | return -ENOTSUP; |
| 725 | #else |
Jakub Topic | 2efc447 | 2024-05-31 22:23:13 +0200 | [diff] [blame] | 726 | const struct rv3028_config *config = dev->config; |
| 727 | struct rv3028_data *data = dev->data; |
| 728 | uint8_t control_2; |
| 729 | int err = 0; |
| 730 | |
| 731 | if (config->gpio_int.port == NULL) { |
| 732 | return -ENOTSUP; |
| 733 | } |
| 734 | |
| 735 | if (id != 0U) { |
| 736 | LOG_ERR("invalid alarm ID %d", id); |
| 737 | return -EINVAL; |
| 738 | } |
| 739 | |
| 740 | rv3028_lock_sem(dev); |
| 741 | |
| 742 | data->alarm_callback = callback; |
| 743 | data->alarm_user_data = user_data; |
| 744 | |
| 745 | err = rv3028_read_reg8(dev, RV3028_REG_CONTROL2, &control_2); |
| 746 | if (err) { |
| 747 | goto unlock; |
| 748 | } |
| 749 | |
| 750 | if (callback != NULL) { |
| 751 | control_2 |= RV3028_CONTROL2_AIE; |
| 752 | } else { |
| 753 | control_2 &= ~(RV3028_CONTROL2_AIE); |
| 754 | } |
| 755 | |
| 756 | if ((control_2 & RV3028_CONTROL2_UIE) == 0U) { |
| 757 | /* Only change INT GPIO if periodic time update interrupt not enabled */ |
| 758 | err = rv3028_int_enable_unlocked(dev, callback != NULL); |
| 759 | if (err) { |
| 760 | goto unlock; |
| 761 | } |
| 762 | } |
| 763 | |
| 764 | err = rv3028_write_reg8(dev, RV3028_REG_CONTROL2, control_2); |
| 765 | if (err) { |
| 766 | goto unlock; |
| 767 | } |
| 768 | |
| 769 | unlock: |
| 770 | rv3028_unlock_sem(dev); |
| 771 | |
| 772 | /* Alarm flag may already be set */ |
| 773 | k_work_submit(&data->work); |
| 774 | |
| 775 | return err; |
Jakub Topic | 7efd885 | 2024-06-13 15:26:22 +0200 | [diff] [blame] | 776 | #endif /* RV3028_INT_GPIOS_IN_USE */ |
Jakub Topic | 2efc447 | 2024-05-31 22:23:13 +0200 | [diff] [blame] | 777 | } |
| 778 | |
Jakub Topic | 2efc447 | 2024-05-31 22:23:13 +0200 | [diff] [blame] | 779 | #endif /* CONFIG_RTC_ALARM */ |
| 780 | |
| 781 | #if RV3028_INT_GPIOS_IN_USE && defined(CONFIG_RTC_UPDATE) |
| 782 | |
| 783 | static int rv3028_update_set_callback(const struct device *dev, rtc_update_callback callback, |
| 784 | void *user_data) |
| 785 | { |
| 786 | const struct rv3028_config *config = dev->config; |
| 787 | struct rv3028_data *data = dev->data; |
| 788 | uint8_t control_2; |
| 789 | int err; |
| 790 | |
| 791 | if (config->gpio_int.port == NULL) { |
| 792 | return -ENOTSUP; |
| 793 | } |
| 794 | |
| 795 | rv3028_lock_sem(dev); |
| 796 | |
| 797 | data->update_callback = callback; |
| 798 | data->update_user_data = user_data; |
| 799 | |
| 800 | err = rv3028_read_reg8(dev, RV3028_REG_CONTROL2, &control_2); |
| 801 | if (err) { |
| 802 | goto unlock; |
| 803 | } |
| 804 | |
| 805 | if (callback != NULL) { |
| 806 | control_2 |= RV3028_CONTROL2_UIE; |
| 807 | } else { |
| 808 | control_2 &= ~(RV3028_CONTROL2_UIE); |
| 809 | } |
| 810 | |
| 811 | if ((control_2 & RV3028_CONTROL2_AIE) == 0U) { |
| 812 | /* Only change INT GPIO if alarm interrupt not enabled */ |
| 813 | err = rv3028_int_enable_unlocked(dev, callback != NULL); |
| 814 | if (err) { |
| 815 | goto unlock; |
| 816 | } |
| 817 | } |
| 818 | |
| 819 | err = rv3028_write_reg8(dev, RV3028_REG_CONTROL2, control_2); |
| 820 | if (err) { |
| 821 | goto unlock; |
| 822 | } |
| 823 | |
| 824 | unlock: |
| 825 | rv3028_unlock_sem(dev); |
| 826 | |
| 827 | /* Seconds flag may already be set */ |
| 828 | k_work_submit(&data->work); |
| 829 | |
| 830 | return err; |
| 831 | } |
| 832 | |
| 833 | #endif /* RV3028_INT_GPIOS_IN_USE && defined(CONFIG_RTC_UPDATE) */ |
| 834 | |
| 835 | static int rv3028_init(const struct device *dev) |
| 836 | { |
| 837 | const struct rv3028_config *config = dev->config; |
| 838 | struct rv3028_data *data = dev->data; |
| 839 | uint8_t regs[3]; |
| 840 | uint8_t val; |
| 841 | int err; |
| 842 | |
| 843 | k_sem_init(&data->lock, 1, 1); |
| 844 | |
| 845 | if (!i2c_is_ready_dt(&config->i2c)) { |
| 846 | LOG_ERR("I2C bus not ready"); |
| 847 | return -ENODEV; |
| 848 | } |
| 849 | |
| 850 | err = rv3028_read_reg8(dev, RV3028_REG_ID, &val); |
| 851 | if (err) { |
| 852 | return -ENODEV; |
| 853 | } |
| 854 | |
| 855 | LOG_DBG("HID: 0x%02x, VID: 0x%02x", (val & 0xF0) >> 0x04, val & 0x0F); |
| 856 | |
| 857 | #if RV3028_INT_GPIOS_IN_USE |
| 858 | if (config->gpio_int.port != NULL) { |
| 859 | if (!gpio_is_ready_dt(&config->gpio_int)) { |
| 860 | LOG_ERR("GPIO not ready"); |
| 861 | return -ENODEV; |
| 862 | } |
| 863 | |
| 864 | err = gpio_pin_configure_dt(&config->gpio_int, GPIO_INPUT); |
| 865 | if (err) { |
| 866 | LOG_ERR("failed to configure GPIO (err %d)", err); |
| 867 | return -ENODEV; |
| 868 | } |
| 869 | |
| 870 | gpio_init_callback(&data->int_callback, rv3028_int_handler, |
| 871 | BIT(config->gpio_int.pin)); |
| 872 | |
| 873 | err = gpio_add_callback_dt(&config->gpio_int, &data->int_callback); |
| 874 | if (err) { |
| 875 | LOG_ERR("failed to add GPIO callback (err %d)", err); |
| 876 | return -ENODEV; |
| 877 | } |
| 878 | |
| 879 | data->dev = dev; |
| 880 | data->work.handler = rv3028_work_cb; |
| 881 | } |
| 882 | #endif /* RV3028_INT_GPIOS_IN_USE */ |
| 883 | |
| 884 | err = rv3028_read_reg8(dev, RV3028_REG_STATUS, &val); |
| 885 | if (err) { |
| 886 | return -ENODEV; |
| 887 | } |
| 888 | |
| 889 | if (val & RV3028_STATUS_AF) { |
| 890 | LOG_WRN("an alarm may have been missed"); |
| 891 | } |
| 892 | |
| 893 | /* Refresh the settings in the RAM with the settings from the EEPROM */ |
| 894 | err = rv3028_enter_eerd(dev); |
| 895 | if (err) { |
| 896 | return -ENODEV; |
| 897 | } |
| 898 | err = rv3028_refresh(dev); |
| 899 | if (err) { |
| 900 | return -ENODEV; |
| 901 | } |
| 902 | |
| 903 | /* Configure the CLKOUT register */ |
| 904 | val = FIELD_PREP(RV3028_CLKOUT_FD, config->cof) | |
| 905 | (config->cof != RV3028_CLKOUT_FD_LOW ? RV3028_CLKOUT_CLKOE : 0); |
| 906 | err = rv3028_update_cfg(dev, |
| 907 | RV3028_REG_CLKOUT, |
| 908 | RV3028_CLKOUT_FD | RV3028_CLKOUT_CLKOE, |
| 909 | val); |
| 910 | if (err) { |
| 911 | return -ENODEV; |
| 912 | } |
| 913 | |
| 914 | err = rv3028_update_cfg(dev, |
| 915 | RV3028_REG_BACKUP, |
| 916 | RV3028_BACKUP_TCE | RV3028_BACKUP_TCR | RV3028_BACKUP_BSM, |
| 917 | config->backup); |
| 918 | if (err) { |
| 919 | return -ENODEV; |
| 920 | } |
| 921 | |
| 922 | err = rv3028_update_reg8(dev, RV3028_REG_CONTROL1, RV3028_CONTROL1_WADA, |
| 923 | RV3028_CONTROL1_WADA); |
| 924 | if (err) { |
| 925 | return -ENODEV; |
| 926 | } |
| 927 | |
| 928 | /* Disable the alarms */ |
| 929 | err = rv3028_update_reg8(dev, |
| 930 | RV3028_REG_CONTROL2, |
| 931 | RV3028_CONTROL2_AIE | RV3028_CONTROL2_UIE, |
| 932 | 0); |
| 933 | if (err) { |
| 934 | return -ENODEV; |
| 935 | } |
| 936 | |
| 937 | err = rv3028_read_regs(dev, RV3028_REG_ALARM_MINUTES, regs, sizeof(regs)); |
| 938 | if (err) { |
| 939 | return -ENODEV; |
| 940 | } |
| 941 | |
| 942 | regs[0] |= RV3028_ALARM_MINUTES_AE_M; |
| 943 | regs[1] |= RV3028_ALARM_HOURS_AE_H; |
| 944 | regs[2] |= RV3028_ALARM_DATE_AE_WD; |
| 945 | |
| 946 | err = rv3028_write_regs(dev, RV3028_REG_ALARM_MINUTES, regs, sizeof(regs)); |
| 947 | if (err) { |
| 948 | return -ENODEV; |
| 949 | } |
| 950 | |
| 951 | return 0; |
| 952 | } |
| 953 | |
| 954 | static const struct rtc_driver_api rv3028_driver_api = { |
| 955 | .set_time = rv3028_set_time, |
| 956 | .get_time = rv3028_get_time, |
| 957 | #ifdef CONFIG_RTC_ALARM |
| 958 | .alarm_get_supported_fields = rv3028_alarm_get_supported_fields, |
| 959 | .alarm_set_time = rv3028_alarm_set_time, |
| 960 | .alarm_get_time = rv3028_alarm_get_time, |
| 961 | .alarm_is_pending = rv3028_alarm_is_pending, |
Jakub Topic | 2efc447 | 2024-05-31 22:23:13 +0200 | [diff] [blame] | 962 | .alarm_set_callback = rv3028_alarm_set_callback, |
Jakub Topic | 2efc447 | 2024-05-31 22:23:13 +0200 | [diff] [blame] | 963 | #endif /* CONFIG_RTC_ALARM */ |
| 964 | #if RV3028_INT_GPIOS_IN_USE && defined(CONFIG_RTC_UPDATE) |
| 965 | .update_set_callback = rv3028_update_set_callback, |
| 966 | #endif /* RV3028_INT_GPIOS_IN_USE && defined(CONFIG_RTC_UPDATE) */ |
| 967 | }; |
| 968 | |
| 969 | #define RV3028_BSM_FROM_DT_INST(inst) \ |
| 970 | UTIL_CAT(RV3028_BSM_, DT_INST_STRING_UPPER_TOKEN(inst, backup_switch_mode)) |
| 971 | |
| 972 | #define RV3028_BACKUP_FROM_DT_INST(inst) \ |
| 973 | ((FIELD_PREP(RV3028_BACKUP_BSM, RV3028_BSM_FROM_DT_INST(inst))) | \ |
| 974 | (FIELD_PREP(RV3028_BACKUP_TCR, DT_INST_ENUM_IDX_OR(inst, trickle_resistor_ohms, 0))) | \ |
| 975 | (DT_INST_NODE_HAS_PROP(inst, trickle_resistor_ohms) ? RV3028_BACKUP_TCE : 0)) |
| 976 | |
| 977 | #define RV3028_INIT(inst) \ |
| 978 | static const struct rv3028_config rv3028_config_##inst = { \ |
| 979 | .i2c = I2C_DT_SPEC_INST_GET(inst), \ |
| 980 | .cof = DT_INST_ENUM_IDX_OR(inst, clkout_frequency, RV3028_CLKOUT_FD_LOW), \ |
| 981 | .backup = RV3028_BACKUP_FROM_DT_INST(inst), \ |
| 982 | IF_ENABLED(RV3028_INT_GPIOS_IN_USE, \ |
| 983 | (.gpio_int = GPIO_DT_SPEC_INST_GET_OR(inst, int_gpios, {0})))}; \ |
| 984 | \ |
| 985 | static struct rv3028_data rv3028_data_##inst; \ |
| 986 | \ |
| 987 | DEVICE_DT_INST_DEFINE(inst, &rv3028_init, NULL, &rv3028_data_##inst, \ |
| 988 | &rv3028_config_##inst, POST_KERNEL, CONFIG_RTC_INIT_PRIORITY, \ |
| 989 | &rv3028_driver_api); |
| 990 | |
| 991 | DT_INST_FOREACH_STATUS_OKAY(RV3028_INIT) |