Linux 6.13-rc4
[linux.git] / drivers / rtc / rtc-rv8803.c
blob1327251e527c21cae4a247a62791ec3cbf0df067
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * RTC driver for the Micro Crystal RV8803
5 * Copyright (C) 2015 Micro Crystal SA
6 * Alexandre Belloni <alexandre.belloni@bootlin.com>
8 */
10 #include <linux/bcd.h>
11 #include <linux/bitops.h>
12 #include <linux/bitfield.h>
13 #include <linux/log2.h>
14 #include <linux/i2c.h>
15 #include <linux/interrupt.h>
16 #include <linux/kernel.h>
17 #include <linux/module.h>
18 #include <linux/of.h>
19 #include <linux/rtc.h>
20 #include <linux/pm_wakeirq.h>
22 #define RV8803_I2C_TRY_COUNT 4
24 #define RV8803_SEC 0x00
25 #define RV8803_MIN 0x01
26 #define RV8803_HOUR 0x02
27 #define RV8803_WEEK 0x03
28 #define RV8803_DAY 0x04
29 #define RV8803_MONTH 0x05
30 #define RV8803_YEAR 0x06
31 #define RV8803_RAM 0x07
32 #define RV8803_ALARM_MIN 0x08
33 #define RV8803_ALARM_HOUR 0x09
34 #define RV8803_ALARM_WEEK_OR_DAY 0x0A
35 #define RV8803_EXT 0x0D
36 #define RV8803_FLAG 0x0E
37 #define RV8803_CTRL 0x0F
38 #define RV8803_OSC_OFFSET 0x2C
40 #define RV8803_EXT_WADA BIT(6)
42 #define RV8803_FLAG_V1F BIT(0)
43 #define RV8803_FLAG_V2F BIT(1)
44 #define RV8803_FLAG_AF BIT(3)
45 #define RV8803_FLAG_TF BIT(4)
46 #define RV8803_FLAG_UF BIT(5)
48 #define RV8803_CTRL_RESET BIT(0)
50 #define RV8803_CTRL_EIE BIT(2)
51 #define RV8803_CTRL_AIE BIT(3)
52 #define RV8803_CTRL_TIE BIT(4)
53 #define RV8803_CTRL_UIE BIT(5)
55 #define RX8803_CTRL_CSEL GENMASK(7, 6)
57 #define RX8900_BACKUP_CTRL 0x18
58 #define RX8900_FLAG_SWOFF BIT(2)
59 #define RX8900_FLAG_VDETOFF BIT(3)
61 enum rv8803_type {
62 rv_8803,
63 rx_8803,
64 rx_8804,
65 rx_8900
68 struct rv8803_data {
69 struct i2c_client *client;
70 struct rtc_device *rtc;
71 struct mutex flags_lock;
72 u8 ctrl;
73 u8 backup;
74 u8 alarm_invalid:1;
75 enum rv8803_type type;
78 static int rv8803_read_reg(const struct i2c_client *client, u8 reg)
80 int try = RV8803_I2C_TRY_COUNT;
81 s32 ret;
84 * There is a 61µs window during which the RTC does not acknowledge I2C
85 * transfers. In that case, ensure that there are multiple attempts.
88 ret = i2c_smbus_read_byte_data(client, reg);
89 while ((ret == -ENXIO || ret == -EIO) && --try);
90 if (ret < 0)
91 dev_err(&client->dev, "Unable to read register 0x%02x\n", reg);
93 return ret;
96 static int rv8803_read_regs(const struct i2c_client *client,
97 u8 reg, u8 count, u8 *values)
99 int try = RV8803_I2C_TRY_COUNT;
100 s32 ret;
103 ret = i2c_smbus_read_i2c_block_data(client, reg, count, values);
104 while ((ret == -ENXIO || ret == -EIO) && --try);
105 if (ret != count) {
106 dev_err(&client->dev,
107 "Unable to read registers 0x%02x..0x%02x\n",
108 reg, reg + count - 1);
109 return ret < 0 ? ret : -EIO;
112 return 0;
115 static int rv8803_write_reg(const struct i2c_client *client, u8 reg, u8 value)
117 int try = RV8803_I2C_TRY_COUNT;
118 s32 ret;
121 ret = i2c_smbus_write_byte_data(client, reg, value);
122 while ((ret == -ENXIO || ret == -EIO) && --try);
123 if (ret)
124 dev_err(&client->dev, "Unable to write register 0x%02x\n", reg);
126 return ret;
129 static int rv8803_write_regs(const struct i2c_client *client,
130 u8 reg, u8 count, const u8 *values)
132 int try = RV8803_I2C_TRY_COUNT;
133 s32 ret;
136 ret = i2c_smbus_write_i2c_block_data(client, reg, count,
137 values);
138 while ((ret == -ENXIO || ret == -EIO) && --try);
139 if (ret)
140 dev_err(&client->dev,
141 "Unable to write registers 0x%02x..0x%02x\n",
142 reg, reg + count - 1);
144 return ret;
147 static int rv8803_regs_init(struct rv8803_data *rv8803)
149 int ret;
151 ret = rv8803_write_reg(rv8803->client, RV8803_OSC_OFFSET, 0x00);
152 if (ret)
153 return ret;
155 ret = rv8803_write_reg(rv8803->client, RV8803_CTRL,
156 FIELD_PREP(RX8803_CTRL_CSEL, 1)); /* 2s */
157 if (ret)
158 return ret;
160 ret = rv8803_write_regs(rv8803->client, RV8803_ALARM_MIN, 3,
161 (u8[]){ 0, 0, 0 });
162 if (ret)
163 return ret;
165 return rv8803_write_reg(rv8803->client, RV8803_RAM, 0x00);
168 static int rv8803_regs_configure(struct rv8803_data *rv8803);
170 static int rv8803_regs_reset(struct rv8803_data *rv8803, bool full)
173 * The RV-8803 resets all registers to POR defaults after voltage-loss,
174 * the Epson RTCs don't, so we manually reset the remainder here.
176 if (full || rv8803->type == rx_8803 || rv8803->type == rx_8900) {
177 int ret = rv8803_regs_init(rv8803);
178 if (ret)
179 return ret;
182 return rv8803_regs_configure(rv8803);
185 static irqreturn_t rv8803_handle_irq(int irq, void *dev_id)
187 struct i2c_client *client = dev_id;
188 struct rv8803_data *rv8803 = i2c_get_clientdata(client);
189 unsigned long events = 0;
190 int flags;
192 mutex_lock(&rv8803->flags_lock);
194 flags = rv8803_read_reg(client, RV8803_FLAG);
195 if (flags <= 0) {
196 mutex_unlock(&rv8803->flags_lock);
197 return IRQ_NONE;
200 if (flags & RV8803_FLAG_V1F)
201 dev_warn(&client->dev, "Voltage low, temperature compensation stopped.\n");
203 if (flags & RV8803_FLAG_V2F)
204 dev_warn(&client->dev, "Voltage low, data loss detected.\n");
206 if (flags & RV8803_FLAG_TF) {
207 flags &= ~RV8803_FLAG_TF;
208 rv8803->ctrl &= ~RV8803_CTRL_TIE;
209 events |= RTC_PF;
212 if (flags & RV8803_FLAG_AF) {
213 flags &= ~RV8803_FLAG_AF;
214 rv8803->ctrl &= ~RV8803_CTRL_AIE;
215 events |= RTC_AF;
218 if (flags & RV8803_FLAG_UF) {
219 flags &= ~RV8803_FLAG_UF;
220 rv8803->ctrl &= ~RV8803_CTRL_UIE;
221 events |= RTC_UF;
224 if (events) {
225 rtc_update_irq(rv8803->rtc, 1, events);
226 rv8803_write_reg(client, RV8803_FLAG, flags);
227 rv8803_write_reg(rv8803->client, RV8803_CTRL, rv8803->ctrl);
230 mutex_unlock(&rv8803->flags_lock);
232 return IRQ_HANDLED;
235 static int rv8803_get_time(struct device *dev, struct rtc_time *tm)
237 struct rv8803_data *rv8803 = dev_get_drvdata(dev);
238 u8 date1[7];
239 u8 date2[7];
240 u8 *date = date1;
241 int ret, flags;
243 if (rv8803->alarm_invalid) {
244 dev_warn(dev, "Corruption detected, data may be invalid.\n");
245 return -EINVAL;
248 flags = rv8803_read_reg(rv8803->client, RV8803_FLAG);
249 if (flags < 0)
250 return flags;
252 if (flags & RV8803_FLAG_V2F) {
253 dev_warn(dev, "Voltage low, data is invalid.\n");
254 return -EINVAL;
257 ret = rv8803_read_regs(rv8803->client, RV8803_SEC, 7, date);
258 if (ret)
259 return ret;
261 if ((date1[RV8803_SEC] & 0x7f) == bin2bcd(59)) {
262 ret = rv8803_read_regs(rv8803->client, RV8803_SEC, 7, date2);
263 if (ret)
264 return ret;
266 if ((date2[RV8803_SEC] & 0x7f) != bin2bcd(59))
267 date = date2;
270 tm->tm_sec = bcd2bin(date[RV8803_SEC] & 0x7f);
271 tm->tm_min = bcd2bin(date[RV8803_MIN] & 0x7f);
272 tm->tm_hour = bcd2bin(date[RV8803_HOUR] & 0x3f);
273 tm->tm_wday = ilog2(date[RV8803_WEEK] & 0x7f);
274 tm->tm_mday = bcd2bin(date[RV8803_DAY] & 0x3f);
275 tm->tm_mon = bcd2bin(date[RV8803_MONTH] & 0x1f) - 1;
276 tm->tm_year = bcd2bin(date[RV8803_YEAR]) + 100;
278 return 0;
281 static int rv8803_set_time(struct device *dev, struct rtc_time *tm)
283 struct rv8803_data *rv8803 = dev_get_drvdata(dev);
284 u8 date[7];
285 int ctrl, flags, ret;
287 ctrl = rv8803_read_reg(rv8803->client, RV8803_CTRL);
288 if (ctrl < 0)
289 return ctrl;
291 /* Stop the clock */
292 ret = rv8803_write_reg(rv8803->client, RV8803_CTRL,
293 ctrl | RV8803_CTRL_RESET);
294 if (ret)
295 return ret;
297 date[RV8803_SEC] = bin2bcd(tm->tm_sec);
298 date[RV8803_MIN] = bin2bcd(tm->tm_min);
299 date[RV8803_HOUR] = bin2bcd(tm->tm_hour);
300 date[RV8803_WEEK] = 1 << (tm->tm_wday);
301 date[RV8803_DAY] = bin2bcd(tm->tm_mday);
302 date[RV8803_MONTH] = bin2bcd(tm->tm_mon + 1);
303 date[RV8803_YEAR] = bin2bcd(tm->tm_year - 100);
305 ret = rv8803_write_regs(rv8803->client, RV8803_SEC, 7, date);
306 if (ret)
307 return ret;
309 /* Restart the clock */
310 ret = rv8803_write_reg(rv8803->client, RV8803_CTRL,
311 ctrl & ~RV8803_CTRL_RESET);
312 if (ret)
313 return ret;
315 mutex_lock(&rv8803->flags_lock);
317 flags = rv8803_read_reg(rv8803->client, RV8803_FLAG);
318 if (flags < 0) {
319 mutex_unlock(&rv8803->flags_lock);
320 return flags;
323 if ((flags & RV8803_FLAG_V2F) || rv8803->alarm_invalid) {
325 * If we sense corruption in the alarm registers, but see no
326 * voltage loss flag, we can't rely on other registers having
327 * sensible values. Reset them fully.
329 ret = rv8803_regs_reset(rv8803, rv8803->alarm_invalid);
330 if (ret) {
331 mutex_unlock(&rv8803->flags_lock);
332 return ret;
335 rv8803->alarm_invalid = false;
338 ret = rv8803_write_reg(rv8803->client, RV8803_FLAG,
339 flags & ~(RV8803_FLAG_V1F | RV8803_FLAG_V2F));
341 mutex_unlock(&rv8803->flags_lock);
343 return ret;
346 static int rv8803_get_alarm(struct device *dev, struct rtc_wkalrm *alrm)
348 struct rv8803_data *rv8803 = dev_get_drvdata(dev);
349 struct i2c_client *client = rv8803->client;
350 u8 alarmvals[3];
351 int flags, ret;
353 ret = rv8803_read_regs(client, RV8803_ALARM_MIN, 3, alarmvals);
354 if (ret)
355 return ret;
357 flags = rv8803_read_reg(client, RV8803_FLAG);
358 if (flags < 0)
359 return flags;
361 alarmvals[0] &= 0x7f;
362 alarmvals[1] &= 0x3f;
363 alarmvals[2] &= 0x3f;
365 if (!bcd_is_valid(alarmvals[0]) ||
366 !bcd_is_valid(alarmvals[1]) ||
367 !bcd_is_valid(alarmvals[2]))
368 goto err_invalid;
370 alrm->time.tm_sec = 0;
371 alrm->time.tm_min = bcd2bin(alarmvals[0]);
372 alrm->time.tm_hour = bcd2bin(alarmvals[1]);
373 alrm->time.tm_mday = bcd2bin(alarmvals[2]);
375 alrm->enabled = !!(rv8803->ctrl & RV8803_CTRL_AIE);
376 alrm->pending = (flags & RV8803_FLAG_AF) && alrm->enabled;
378 if ((unsigned int)alrm->time.tm_mday > 31 ||
379 (unsigned int)alrm->time.tm_hour >= 24 ||
380 (unsigned int)alrm->time.tm_min >= 60)
381 goto err_invalid;
383 return 0;
385 err_invalid:
386 rv8803->alarm_invalid = true;
387 return -EINVAL;
390 static int rv8803_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
392 struct i2c_client *client = to_i2c_client(dev);
393 struct rv8803_data *rv8803 = dev_get_drvdata(dev);
394 u8 alarmvals[3];
395 u8 ctrl[2];
396 int ret, err;
398 /* The alarm has no seconds, round up to nearest minute */
399 if (alrm->time.tm_sec) {
400 time64_t alarm_time = rtc_tm_to_time64(&alrm->time);
402 alarm_time += 60 - alrm->time.tm_sec;
403 rtc_time64_to_tm(alarm_time, &alrm->time);
406 mutex_lock(&rv8803->flags_lock);
408 ret = rv8803_read_regs(client, RV8803_FLAG, 2, ctrl);
409 if (ret) {
410 mutex_unlock(&rv8803->flags_lock);
411 return ret;
414 alarmvals[0] = bin2bcd(alrm->time.tm_min);
415 alarmvals[1] = bin2bcd(alrm->time.tm_hour);
416 alarmvals[2] = bin2bcd(alrm->time.tm_mday);
418 if (rv8803->ctrl & (RV8803_CTRL_AIE | RV8803_CTRL_UIE)) {
419 rv8803->ctrl &= ~(RV8803_CTRL_AIE | RV8803_CTRL_UIE);
420 err = rv8803_write_reg(rv8803->client, RV8803_CTRL,
421 rv8803->ctrl);
422 if (err) {
423 mutex_unlock(&rv8803->flags_lock);
424 return err;
428 ctrl[0] &= ~RV8803_FLAG_AF;
429 err = rv8803_write_reg(rv8803->client, RV8803_FLAG, ctrl[0]);
430 mutex_unlock(&rv8803->flags_lock);
431 if (err)
432 return err;
434 err = rv8803_write_regs(rv8803->client, RV8803_ALARM_MIN, 3, alarmvals);
435 if (err)
436 return err;
438 if (alrm->enabled) {
439 if (rv8803->rtc->uie_rtctimer.enabled)
440 rv8803->ctrl |= RV8803_CTRL_UIE;
441 if (rv8803->rtc->aie_timer.enabled)
442 rv8803->ctrl |= RV8803_CTRL_AIE;
444 err = rv8803_write_reg(rv8803->client, RV8803_CTRL,
445 rv8803->ctrl);
446 if (err)
447 return err;
450 return 0;
453 static int rv8803_alarm_irq_enable(struct device *dev, unsigned int enabled)
455 struct i2c_client *client = to_i2c_client(dev);
456 struct rv8803_data *rv8803 = dev_get_drvdata(dev);
457 int ctrl, flags, err;
459 ctrl = rv8803->ctrl;
461 if (enabled) {
462 if (rv8803->rtc->uie_rtctimer.enabled)
463 ctrl |= RV8803_CTRL_UIE;
464 if (rv8803->rtc->aie_timer.enabled)
465 ctrl |= RV8803_CTRL_AIE;
466 } else {
467 if (!rv8803->rtc->uie_rtctimer.enabled)
468 ctrl &= ~RV8803_CTRL_UIE;
469 if (!rv8803->rtc->aie_timer.enabled)
470 ctrl &= ~RV8803_CTRL_AIE;
473 mutex_lock(&rv8803->flags_lock);
474 flags = rv8803_read_reg(client, RV8803_FLAG);
475 if (flags < 0) {
476 mutex_unlock(&rv8803->flags_lock);
477 return flags;
479 flags &= ~(RV8803_FLAG_AF | RV8803_FLAG_UF);
480 err = rv8803_write_reg(client, RV8803_FLAG, flags);
481 mutex_unlock(&rv8803->flags_lock);
482 if (err)
483 return err;
485 if (ctrl != rv8803->ctrl) {
486 rv8803->ctrl = ctrl;
487 err = rv8803_write_reg(client, RV8803_CTRL, rv8803->ctrl);
488 if (err)
489 return err;
492 return 0;
495 static int rv8803_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
497 struct i2c_client *client = to_i2c_client(dev);
498 struct rv8803_data *rv8803 = dev_get_drvdata(dev);
499 unsigned int vl = 0;
500 int flags, ret = 0;
502 switch (cmd) {
503 case RTC_VL_READ:
504 flags = rv8803_read_reg(client, RV8803_FLAG);
505 if (flags < 0)
506 return flags;
508 if (flags & RV8803_FLAG_V1F) {
509 dev_warn(&client->dev, "Voltage low, temperature compensation stopped.\n");
510 vl = RTC_VL_ACCURACY_LOW;
513 if (flags & RV8803_FLAG_V2F)
514 vl |= RTC_VL_DATA_INVALID;
516 return put_user(vl, (unsigned int __user *)arg);
518 case RTC_VL_CLR:
519 mutex_lock(&rv8803->flags_lock);
520 flags = rv8803_read_reg(client, RV8803_FLAG);
521 if (flags < 0) {
522 mutex_unlock(&rv8803->flags_lock);
523 return flags;
526 flags &= ~RV8803_FLAG_V1F;
527 ret = rv8803_write_reg(client, RV8803_FLAG, flags);
528 mutex_unlock(&rv8803->flags_lock);
529 if (ret)
530 return ret;
532 return 0;
534 default:
535 return -ENOIOCTLCMD;
539 static int rv8803_nvram_write(void *priv, unsigned int offset, void *val,
540 size_t bytes)
542 return rv8803_write_reg(priv, RV8803_RAM, *(u8 *)val);
545 static int rv8803_nvram_read(void *priv, unsigned int offset,
546 void *val, size_t bytes)
548 int ret;
550 ret = rv8803_read_reg(priv, RV8803_RAM);
551 if (ret < 0)
552 return ret;
554 *(u8 *)val = ret;
556 return 0;
559 static const struct rtc_class_ops rv8803_rtc_ops = {
560 .read_time = rv8803_get_time,
561 .set_time = rv8803_set_time,
562 .ioctl = rv8803_ioctl,
563 .read_alarm = rv8803_get_alarm,
564 .set_alarm = rv8803_set_alarm,
565 .alarm_irq_enable = rv8803_alarm_irq_enable,
568 static int rx8900_trickle_charger_init(struct rv8803_data *rv8803)
570 struct i2c_client *client = rv8803->client;
571 struct device_node *node = client->dev.of_node;
572 int err;
573 u8 flags;
575 if (!node)
576 return 0;
578 if (rv8803->type != rx_8900)
579 return 0;
581 err = i2c_smbus_read_byte_data(rv8803->client, RX8900_BACKUP_CTRL);
582 if (err < 0)
583 return err;
585 flags = (u8)err;
586 flags &= ~(RX8900_FLAG_VDETOFF | RX8900_FLAG_SWOFF);
587 flags |= rv8803->backup;
589 return i2c_smbus_write_byte_data(rv8803->client, RX8900_BACKUP_CTRL,
590 flags);
593 /* configure registers with values different than the Power-On reset defaults */
594 static int rv8803_regs_configure(struct rv8803_data *rv8803)
596 int err;
598 err = rv8803_write_reg(rv8803->client, RV8803_EXT, RV8803_EXT_WADA);
599 if (err)
600 return err;
602 err = rx8900_trickle_charger_init(rv8803);
603 if (err) {
604 dev_err(&rv8803->client->dev, "failed to init charger\n");
605 return err;
608 return 0;
611 static int rv8803_resume(struct device *dev)
613 struct rv8803_data *rv8803 = dev_get_drvdata(dev);
615 if (rv8803->client->irq > 0 && device_may_wakeup(dev))
616 disable_irq_wake(rv8803->client->irq);
618 return 0;
621 static int rv8803_suspend(struct device *dev)
623 struct rv8803_data *rv8803 = dev_get_drvdata(dev);
625 if (rv8803->client->irq > 0 && device_may_wakeup(dev))
626 enable_irq_wake(rv8803->client->irq);
628 return 0;
631 static DEFINE_SIMPLE_DEV_PM_OPS(rv8803_pm_ops, rv8803_suspend, rv8803_resume);
633 static const struct i2c_device_id rv8803_id[] = {
634 { "rv8803", rv_8803 },
635 { "rv8804", rx_8804 },
636 { "rx8803", rx_8803 },
637 { "rx8900", rx_8900 },
640 MODULE_DEVICE_TABLE(i2c, rv8803_id);
642 static int rv8803_probe(struct i2c_client *client)
644 struct i2c_adapter *adapter = client->adapter;
645 struct rv8803_data *rv8803;
646 int err, flags;
647 struct nvmem_config nvmem_cfg = {
648 .name = "rv8803_nvram",
649 .word_size = 1,
650 .stride = 1,
651 .size = 1,
652 .reg_read = rv8803_nvram_read,
653 .reg_write = rv8803_nvram_write,
654 .priv = client,
657 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
658 I2C_FUNC_SMBUS_I2C_BLOCK)) {
659 dev_err(&adapter->dev, "doesn't support I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_I2C_BLOCK\n");
660 return -EIO;
663 rv8803 = devm_kzalloc(&client->dev, sizeof(struct rv8803_data),
664 GFP_KERNEL);
665 if (!rv8803)
666 return -ENOMEM;
668 mutex_init(&rv8803->flags_lock);
669 rv8803->client = client;
670 if (client->dev.of_node) {
671 rv8803->type = (uintptr_t)of_device_get_match_data(&client->dev);
672 } else {
673 const struct i2c_device_id *id = i2c_match_id(rv8803_id, client);
675 rv8803->type = id->driver_data;
677 i2c_set_clientdata(client, rv8803);
679 flags = rv8803_read_reg(client, RV8803_FLAG);
680 if (flags < 0)
681 return flags;
683 if (flags & RV8803_FLAG_V1F)
684 dev_warn(&client->dev, "Voltage low, temperature compensation stopped.\n");
686 if (flags & RV8803_FLAG_V2F)
687 dev_warn(&client->dev, "Voltage low, data loss detected.\n");
689 if (flags & RV8803_FLAG_AF)
690 dev_warn(&client->dev, "An alarm maybe have been missed.\n");
692 rv8803->rtc = devm_rtc_allocate_device(&client->dev);
693 if (IS_ERR(rv8803->rtc))
694 return PTR_ERR(rv8803->rtc);
696 if (client->irq > 0) {
697 unsigned long irqflags = IRQF_TRIGGER_LOW;
699 if (dev_fwnode(&client->dev))
700 irqflags = 0;
702 err = devm_request_threaded_irq(&client->dev, client->irq,
703 NULL, rv8803_handle_irq,
704 irqflags | IRQF_ONESHOT,
705 "rv8803", client);
706 if (err) {
707 dev_warn(&client->dev, "unable to request IRQ, alarms disabled\n");
708 client->irq = 0;
709 } else {
710 device_init_wakeup(&client->dev, true);
711 err = dev_pm_set_wake_irq(&client->dev, client->irq);
712 if (err)
713 dev_err(&client->dev, "failed to set wake IRQ\n");
715 } else {
716 if (device_property_read_bool(&client->dev, "wakeup-source"))
717 device_init_wakeup(&client->dev, true);
718 else
719 clear_bit(RTC_FEATURE_ALARM, rv8803->rtc->features);
722 if (of_property_read_bool(client->dev.of_node, "epson,vdet-disable"))
723 rv8803->backup |= RX8900_FLAG_VDETOFF;
725 if (of_property_read_bool(client->dev.of_node, "trickle-diode-disable"))
726 rv8803->backup |= RX8900_FLAG_SWOFF;
728 err = rv8803_regs_configure(rv8803);
729 if (err)
730 return err;
732 rv8803->rtc->ops = &rv8803_rtc_ops;
733 rv8803->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
734 rv8803->rtc->range_max = RTC_TIMESTAMP_END_2099;
735 err = devm_rtc_register_device(rv8803->rtc);
736 if (err)
737 return err;
739 devm_rtc_nvmem_register(rv8803->rtc, &nvmem_cfg);
741 rv8803->rtc->max_user_freq = 1;
743 return 0;
746 static const __maybe_unused struct of_device_id rv8803_of_match[] = {
748 .compatible = "microcrystal,rv8803",
749 .data = (void *)rv_8803
752 .compatible = "epson,rx8803",
753 .data = (void *)rx_8803
756 .compatible = "epson,rx8804",
757 .data = (void *)rx_8804
760 .compatible = "epson,rx8900",
761 .data = (void *)rx_8900
765 MODULE_DEVICE_TABLE(of, rv8803_of_match);
767 static struct i2c_driver rv8803_driver = {
768 .driver = {
769 .name = "rtc-rv8803",
770 .of_match_table = of_match_ptr(rv8803_of_match),
771 .pm = &rv8803_pm_ops,
773 .probe = rv8803_probe,
774 .id_table = rv8803_id,
776 module_i2c_driver(rv8803_driver);
778 MODULE_AUTHOR("Alexandre Belloni <alexandre.belloni@bootlin.com>");
779 MODULE_DESCRIPTION("Micro Crystal RV8803 RTC driver");
780 MODULE_LICENSE("GPL v2");