Merge tag 'for-linus-20190706' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / rtc / rtc-rv3028.c
blob06884ebb7a61512f0e5a4bab5fa944647b45441f
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * RTC driver for the Micro Crystal RV3028
5 * Copyright (C) 2019 Micro Crystal SA
7 * Alexandre Belloni <alexandre.belloni@bootlin.com>
9 */
11 #include <linux/bcd.h>
12 #include <linux/bitops.h>
13 #include <linux/i2c.h>
14 #include <linux/interrupt.h>
15 #include <linux/kernel.h>
16 #include <linux/log2.h>
17 #include <linux/module.h>
18 #include <linux/of_device.h>
19 #include <linux/regmap.h>
20 #include <linux/rtc.h>
22 #define RV3028_SEC 0x00
23 #define RV3028_MIN 0x01
24 #define RV3028_HOUR 0x02
25 #define RV3028_WDAY 0x03
26 #define RV3028_DAY 0x04
27 #define RV3028_MONTH 0x05
28 #define RV3028_YEAR 0x06
29 #define RV3028_ALARM_MIN 0x07
30 #define RV3028_ALARM_HOUR 0x08
31 #define RV3028_ALARM_DAY 0x09
32 #define RV3028_STATUS 0x0E
33 #define RV3028_CTRL1 0x0F
34 #define RV3028_CTRL2 0x10
35 #define RV3028_EVT_CTRL 0x13
36 #define RV3028_TS_COUNT 0x14
37 #define RV3028_TS_SEC 0x15
38 #define RV3028_RAM1 0x1F
39 #define RV3028_EEPROM_ADDR 0x25
40 #define RV3028_EEPROM_DATA 0x26
41 #define RV3028_EEPROM_CMD 0x27
42 #define RV3028_CLKOUT 0x35
43 #define RV3028_OFFSET 0x36
44 #define RV3028_BACKUP 0x37
46 #define RV3028_STATUS_PORF BIT(0)
47 #define RV3028_STATUS_EVF BIT(1)
48 #define RV3028_STATUS_AF BIT(2)
49 #define RV3028_STATUS_TF BIT(3)
50 #define RV3028_STATUS_UF BIT(4)
51 #define RV3028_STATUS_BSF BIT(5)
52 #define RV3028_STATUS_CLKF BIT(6)
53 #define RV3028_STATUS_EEBUSY BIT(7)
55 #define RV3028_CTRL1_EERD BIT(3)
56 #define RV3028_CTRL1_WADA BIT(5)
58 #define RV3028_CTRL2_RESET BIT(0)
59 #define RV3028_CTRL2_12_24 BIT(1)
60 #define RV3028_CTRL2_EIE BIT(2)
61 #define RV3028_CTRL2_AIE BIT(3)
62 #define RV3028_CTRL2_TIE BIT(4)
63 #define RV3028_CTRL2_UIE BIT(5)
64 #define RV3028_CTRL2_TSE BIT(7)
66 #define RV3028_EVT_CTRL_TSR BIT(2)
68 #define RV3028_EEPROM_CMD_WRITE 0x21
69 #define RV3028_EEPROM_CMD_READ 0x22
71 #define RV3028_EEBUSY_POLL 10000
72 #define RV3028_EEBUSY_TIMEOUT 100000
74 #define RV3028_BACKUP_TCE BIT(5)
75 #define RV3028_BACKUP_TCR_MASK GENMASK(1,0)
77 #define OFFSET_STEP_PPT 953674
79 enum rv3028_type {
80 rv_3028,
83 struct rv3028_data {
84 struct regmap *regmap;
85 struct rtc_device *rtc;
86 enum rv3028_type type;
89 static u16 rv3028_trickle_resistors[] = {1000, 3000, 6000, 11000};
91 static ssize_t timestamp0_store(struct device *dev,
92 struct device_attribute *attr,
93 const char *buf, size_t count)
95 struct rv3028_data *rv3028 = dev_get_drvdata(dev->parent);
97 regmap_update_bits(rv3028->regmap, RV3028_EVT_CTRL, RV3028_EVT_CTRL_TSR,
98 RV3028_EVT_CTRL_TSR);
100 return count;
103 static ssize_t timestamp0_show(struct device *dev,
104 struct device_attribute *attr, char *buf)
106 struct rv3028_data *rv3028 = dev_get_drvdata(dev->parent);
107 struct rtc_time tm;
108 int ret, count;
109 u8 date[6];
111 ret = regmap_read(rv3028->regmap, RV3028_TS_COUNT, &count);
112 if (ret)
113 return ret;
115 if (!count)
116 return 0;
118 ret = regmap_bulk_read(rv3028->regmap, RV3028_TS_SEC, date,
119 sizeof(date));
120 if (ret)
121 return ret;
123 tm.tm_sec = bcd2bin(date[0]);
124 tm.tm_min = bcd2bin(date[1]);
125 tm.tm_hour = bcd2bin(date[2]);
126 tm.tm_mday = bcd2bin(date[3]);
127 tm.tm_mon = bcd2bin(date[4]) - 1;
128 tm.tm_year = bcd2bin(date[5]) + 100;
130 ret = rtc_valid_tm(&tm);
131 if (ret)
132 return ret;
134 return sprintf(buf, "%llu\n",
135 (unsigned long long)rtc_tm_to_time64(&tm));
138 static DEVICE_ATTR_RW(timestamp0);
140 static ssize_t timestamp0_count_show(struct device *dev,
141 struct device_attribute *attr, char *buf)
143 struct rv3028_data *rv3028 = dev_get_drvdata(dev->parent);
144 int ret, count;
146 ret = regmap_read(rv3028->regmap, RV3028_TS_COUNT, &count);
147 if (ret)
148 return ret;
150 return sprintf(buf, "%u\n", count);
153 static DEVICE_ATTR_RO(timestamp0_count);
155 static struct attribute *rv3028_attrs[] = {
156 &dev_attr_timestamp0.attr,
157 &dev_attr_timestamp0_count.attr,
158 NULL
161 static const struct attribute_group rv3028_attr_group = {
162 .attrs = rv3028_attrs,
165 static irqreturn_t rv3028_handle_irq(int irq, void *dev_id)
167 struct rv3028_data *rv3028 = dev_id;
168 unsigned long events = 0;
169 u32 status = 0, ctrl = 0;
171 if (regmap_read(rv3028->regmap, RV3028_STATUS, &status) < 0 ||
172 status == 0) {
173 return IRQ_NONE;
176 if (status & RV3028_STATUS_PORF)
177 dev_warn(&rv3028->rtc->dev, "Voltage low, data loss detected.\n");
179 if (status & RV3028_STATUS_TF) {
180 status |= RV3028_STATUS_TF;
181 ctrl |= RV3028_CTRL2_TIE;
182 events |= RTC_PF;
185 if (status & RV3028_STATUS_AF) {
186 status |= RV3028_STATUS_AF;
187 ctrl |= RV3028_CTRL2_AIE;
188 events |= RTC_AF;
191 if (status & RV3028_STATUS_UF) {
192 status |= RV3028_STATUS_UF;
193 ctrl |= RV3028_CTRL2_UIE;
194 events |= RTC_UF;
197 if (events) {
198 rtc_update_irq(rv3028->rtc, 1, events);
199 regmap_update_bits(rv3028->regmap, RV3028_STATUS, status, 0);
200 regmap_update_bits(rv3028->regmap, RV3028_CTRL2, ctrl, 0);
203 if (status & RV3028_STATUS_EVF) {
204 sysfs_notify(&rv3028->rtc->dev.kobj, NULL,
205 dev_attr_timestamp0.attr.name);
206 dev_warn(&rv3028->rtc->dev, "event detected");
209 return IRQ_HANDLED;
212 static int rv3028_get_time(struct device *dev, struct rtc_time *tm)
214 struct rv3028_data *rv3028 = dev_get_drvdata(dev);
215 u8 date[7];
216 int ret, status;
218 ret = regmap_read(rv3028->regmap, RV3028_STATUS, &status);
219 if (ret < 0)
220 return ret;
222 if (status & RV3028_STATUS_PORF) {
223 dev_warn(dev, "Voltage low, data is invalid.\n");
224 return -EINVAL;
227 ret = regmap_bulk_read(rv3028->regmap, RV3028_SEC, date, sizeof(date));
228 if (ret)
229 return ret;
231 tm->tm_sec = bcd2bin(date[RV3028_SEC] & 0x7f);
232 tm->tm_min = bcd2bin(date[RV3028_MIN] & 0x7f);
233 tm->tm_hour = bcd2bin(date[RV3028_HOUR] & 0x3f);
234 tm->tm_wday = ilog2(date[RV3028_WDAY] & 0x7f);
235 tm->tm_mday = bcd2bin(date[RV3028_DAY] & 0x3f);
236 tm->tm_mon = bcd2bin(date[RV3028_MONTH] & 0x1f) - 1;
237 tm->tm_year = bcd2bin(date[RV3028_YEAR]) + 100;
239 return 0;
242 static int rv3028_set_time(struct device *dev, struct rtc_time *tm)
244 struct rv3028_data *rv3028 = dev_get_drvdata(dev);
245 u8 date[7];
246 int ret;
248 date[RV3028_SEC] = bin2bcd(tm->tm_sec);
249 date[RV3028_MIN] = bin2bcd(tm->tm_min);
250 date[RV3028_HOUR] = bin2bcd(tm->tm_hour);
251 date[RV3028_WDAY] = 1 << (tm->tm_wday);
252 date[RV3028_DAY] = bin2bcd(tm->tm_mday);
253 date[RV3028_MONTH] = bin2bcd(tm->tm_mon + 1);
254 date[RV3028_YEAR] = bin2bcd(tm->tm_year - 100);
257 * Writing to the Seconds register has the same effect as setting RESET
258 * bit to 1
260 ret = regmap_bulk_write(rv3028->regmap, RV3028_SEC, date,
261 sizeof(date));
262 if (ret)
263 return ret;
265 ret = regmap_update_bits(rv3028->regmap, RV3028_STATUS,
266 RV3028_STATUS_PORF, 0);
268 return ret;
271 static int rv3028_get_alarm(struct device *dev, struct rtc_wkalrm *alrm)
273 struct rv3028_data *rv3028 = dev_get_drvdata(dev);
274 u8 alarmvals[3];
275 int status, ctrl, ret;
277 ret = regmap_bulk_read(rv3028->regmap, RV3028_ALARM_MIN, alarmvals,
278 sizeof(alarmvals));
279 if (ret)
280 return ret;
282 ret = regmap_read(rv3028->regmap, RV3028_STATUS, &status);
283 if (ret < 0)
284 return ret;
286 ret = regmap_read(rv3028->regmap, RV3028_CTRL2, &ctrl);
287 if (ret < 0)
288 return ret;
290 alrm->time.tm_sec = 0;
291 alrm->time.tm_min = bcd2bin(alarmvals[0] & 0x7f);
292 alrm->time.tm_hour = bcd2bin(alarmvals[1] & 0x3f);
293 alrm->time.tm_mday = bcd2bin(alarmvals[2] & 0x3f);
295 alrm->enabled = !!(ctrl & RV3028_CTRL2_AIE);
296 alrm->pending = (status & RV3028_STATUS_AF) && alrm->enabled;
298 return 0;
301 static int rv3028_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
303 struct rv3028_data *rv3028 = dev_get_drvdata(dev);
304 u8 alarmvals[3];
305 u8 ctrl = 0;
306 int ret;
308 /* The alarm has no seconds, round up to nearest minute */
309 if (alrm->time.tm_sec) {
310 time64_t alarm_time = rtc_tm_to_time64(&alrm->time);
312 alarm_time += 60 - alrm->time.tm_sec;
313 rtc_time64_to_tm(alarm_time, &alrm->time);
316 ret = regmap_update_bits(rv3028->regmap, RV3028_CTRL2,
317 RV3028_CTRL2_AIE | RV3028_CTRL2_UIE, 0);
318 if (ret)
319 return ret;
321 alarmvals[0] = bin2bcd(alrm->time.tm_min);
322 alarmvals[1] = bin2bcd(alrm->time.tm_hour);
323 alarmvals[2] = bin2bcd(alrm->time.tm_mday);
325 ret = regmap_update_bits(rv3028->regmap, RV3028_STATUS,
326 RV3028_STATUS_AF, 0);
327 if (ret)
328 return ret;
330 ret = regmap_bulk_write(rv3028->regmap, RV3028_ALARM_MIN, alarmvals,
331 sizeof(alarmvals));
332 if (ret)
333 return ret;
335 if (alrm->enabled) {
336 if (rv3028->rtc->uie_rtctimer.enabled)
337 ctrl |= RV3028_CTRL2_UIE;
338 if (rv3028->rtc->aie_timer.enabled)
339 ctrl |= RV3028_CTRL2_AIE;
342 ret = regmap_update_bits(rv3028->regmap, RV3028_CTRL2,
343 RV3028_CTRL2_UIE | RV3028_CTRL2_AIE, ctrl);
345 return ret;
348 static int rv3028_alarm_irq_enable(struct device *dev, unsigned int enabled)
350 struct rv3028_data *rv3028 = dev_get_drvdata(dev);
351 int ctrl = 0, ret;
353 if (enabled) {
354 if (rv3028->rtc->uie_rtctimer.enabled)
355 ctrl |= RV3028_CTRL2_UIE;
356 if (rv3028->rtc->aie_timer.enabled)
357 ctrl |= RV3028_CTRL2_AIE;
360 ret = regmap_update_bits(rv3028->regmap, RV3028_STATUS,
361 RV3028_STATUS_AF | RV3028_STATUS_UF, 0);
362 if (ret)
363 return ret;
365 ret = regmap_update_bits(rv3028->regmap, RV3028_CTRL2,
366 RV3028_CTRL2_UIE | RV3028_CTRL2_AIE, ctrl);
367 if (ret)
368 return ret;
370 return 0;
373 static int rv3028_read_offset(struct device *dev, long *offset)
375 struct rv3028_data *rv3028 = dev_get_drvdata(dev);
376 int ret, value, steps;
378 ret = regmap_read(rv3028->regmap, RV3028_OFFSET, &value);
379 if (ret < 0)
380 return ret;
382 steps = sign_extend32(value << 1, 8);
384 ret = regmap_read(rv3028->regmap, RV3028_BACKUP, &value);
385 if (ret < 0)
386 return ret;
388 steps += value >> 7;
390 *offset = DIV_ROUND_CLOSEST(steps * OFFSET_STEP_PPT, 1000);
392 return 0;
395 static int rv3028_set_offset(struct device *dev, long offset)
397 struct rv3028_data *rv3028 = dev_get_drvdata(dev);
398 int ret;
400 offset = clamp(offset, -244141L, 243187L) * 1000;
401 offset = DIV_ROUND_CLOSEST(offset, OFFSET_STEP_PPT);
403 ret = regmap_write(rv3028->regmap, RV3028_OFFSET, offset >> 1);
404 if (ret < 0)
405 return ret;
407 return regmap_update_bits(rv3028->regmap, RV3028_BACKUP, BIT(7),
408 offset << 7);
411 static int rv3028_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
413 struct rv3028_data *rv3028 = dev_get_drvdata(dev);
414 int status, ret = 0;
416 switch (cmd) {
417 case RTC_VL_READ:
418 ret = regmap_read(rv3028->regmap, RV3028_STATUS, &status);
419 if (ret < 0)
420 return ret;
422 if (status & RV3028_STATUS_PORF)
423 dev_warn(&rv3028->rtc->dev, "Voltage low, data loss detected.\n");
425 status &= RV3028_STATUS_PORF;
427 if (copy_to_user((void __user *)arg, &status, sizeof(int)))
428 return -EFAULT;
430 return 0;
432 case RTC_VL_CLR:
433 ret = regmap_update_bits(rv3028->regmap, RV3028_STATUS,
434 RV3028_STATUS_PORF, 0);
436 return ret;
438 default:
439 return -ENOIOCTLCMD;
443 static int rv3028_nvram_write(void *priv, unsigned int offset, void *val,
444 size_t bytes)
446 return regmap_bulk_write(priv, RV3028_RAM1 + offset, val, bytes);
449 static int rv3028_nvram_read(void *priv, unsigned int offset, void *val,
450 size_t bytes)
452 return regmap_bulk_read(priv, RV3028_RAM1 + offset, val, bytes);
455 static int rv3028_eeprom_write(void *priv, unsigned int offset, void *val,
456 size_t bytes)
458 u32 status, ctrl1;
459 int i, ret, err;
460 u8 *buf = val;
462 ret = regmap_read(priv, RV3028_CTRL1, &ctrl1);
463 if (ret)
464 return ret;
466 if (!(ctrl1 & RV3028_CTRL1_EERD)) {
467 ret = regmap_update_bits(priv, RV3028_CTRL1,
468 RV3028_CTRL1_EERD, RV3028_CTRL1_EERD);
469 if (ret)
470 return ret;
472 ret = regmap_read_poll_timeout(priv, RV3028_STATUS, status,
473 !(status & RV3028_STATUS_EEBUSY),
474 RV3028_EEBUSY_POLL,
475 RV3028_EEBUSY_TIMEOUT);
476 if (ret)
477 goto restore_eerd;
480 for (i = 0; i < bytes; i++) {
481 ret = regmap_write(priv, RV3028_EEPROM_ADDR, offset + i);
482 if (ret)
483 goto restore_eerd;
485 ret = regmap_write(priv, RV3028_EEPROM_DATA, buf[i]);
486 if (ret)
487 goto restore_eerd;
489 ret = regmap_write(priv, RV3028_EEPROM_CMD, 0x0);
490 if (ret)
491 goto restore_eerd;
493 ret = regmap_write(priv, RV3028_EEPROM_CMD,
494 RV3028_EEPROM_CMD_WRITE);
495 if (ret)
496 goto restore_eerd;
498 usleep_range(RV3028_EEBUSY_POLL, RV3028_EEBUSY_TIMEOUT);
500 ret = regmap_read_poll_timeout(priv, RV3028_STATUS, status,
501 !(status & RV3028_STATUS_EEBUSY),
502 RV3028_EEBUSY_POLL,
503 RV3028_EEBUSY_TIMEOUT);
504 if (ret)
505 goto restore_eerd;
508 restore_eerd:
509 if (!(ctrl1 & RV3028_CTRL1_EERD))
511 err = regmap_update_bits(priv, RV3028_CTRL1, RV3028_CTRL1_EERD,
513 if (err && !ret)
514 ret = err;
517 return ret;
520 static int rv3028_eeprom_read(void *priv, unsigned int offset, void *val,
521 size_t bytes)
523 u32 status, ctrl1, data;
524 int i, ret, err;
525 u8 *buf = val;
527 ret = regmap_read(priv, RV3028_CTRL1, &ctrl1);
528 if (ret)
529 return ret;
531 if (!(ctrl1 & RV3028_CTRL1_EERD)) {
532 ret = regmap_update_bits(priv, RV3028_CTRL1,
533 RV3028_CTRL1_EERD, RV3028_CTRL1_EERD);
534 if (ret)
535 return ret;
537 ret = regmap_read_poll_timeout(priv, RV3028_STATUS, status,
538 !(status & RV3028_STATUS_EEBUSY),
539 RV3028_EEBUSY_POLL,
540 RV3028_EEBUSY_TIMEOUT);
541 if (ret)
542 goto restore_eerd;
545 for (i = 0; i < bytes; i++) {
546 ret = regmap_write(priv, RV3028_EEPROM_ADDR, offset + i);
547 if (ret)
548 goto restore_eerd;
550 ret = regmap_write(priv, RV3028_EEPROM_CMD, 0x0);
551 if (ret)
552 goto restore_eerd;
554 ret = regmap_write(priv, RV3028_EEPROM_CMD,
555 RV3028_EEPROM_CMD_READ);
556 if (ret)
557 goto restore_eerd;
559 ret = regmap_read_poll_timeout(priv, RV3028_STATUS, status,
560 !(status & RV3028_STATUS_EEBUSY),
561 RV3028_EEBUSY_POLL,
562 RV3028_EEBUSY_TIMEOUT);
563 if (ret)
564 goto restore_eerd;
566 ret = regmap_read(priv, RV3028_EEPROM_DATA, &data);
567 if (ret)
568 goto restore_eerd;
569 buf[i] = data;
572 restore_eerd:
573 if (!(ctrl1 & RV3028_CTRL1_EERD))
575 err = regmap_update_bits(priv, RV3028_CTRL1, RV3028_CTRL1_EERD,
577 if (err && !ret)
578 ret = err;
581 return ret;
584 static struct rtc_class_ops rv3028_rtc_ops = {
585 .read_time = rv3028_get_time,
586 .set_time = rv3028_set_time,
587 .read_offset = rv3028_read_offset,
588 .set_offset = rv3028_set_offset,
589 .ioctl = rv3028_ioctl,
592 static const struct regmap_config regmap_config = {
593 .reg_bits = 8,
594 .val_bits = 8,
595 .max_register = 0x37,
598 static int rv3028_probe(struct i2c_client *client)
600 struct rv3028_data *rv3028;
601 int ret, status;
602 u32 ohms;
603 struct nvmem_config nvmem_cfg = {
604 .name = "rv3028_nvram",
605 .word_size = 1,
606 .stride = 1,
607 .size = 2,
608 .type = NVMEM_TYPE_BATTERY_BACKED,
609 .reg_read = rv3028_nvram_read,
610 .reg_write = rv3028_nvram_write,
612 struct nvmem_config eeprom_cfg = {
613 .name = "rv3028_eeprom",
614 .word_size = 1,
615 .stride = 1,
616 .size = 43,
617 .type = NVMEM_TYPE_EEPROM,
618 .reg_read = rv3028_eeprom_read,
619 .reg_write = rv3028_eeprom_write,
622 rv3028 = devm_kzalloc(&client->dev, sizeof(struct rv3028_data),
623 GFP_KERNEL);
624 if (!rv3028)
625 return -ENOMEM;
627 rv3028->regmap = devm_regmap_init_i2c(client, &regmap_config);
629 i2c_set_clientdata(client, rv3028);
631 ret = regmap_read(rv3028->regmap, RV3028_STATUS, &status);
632 if (ret < 0)
633 return ret;
635 if (status & RV3028_STATUS_PORF)
636 dev_warn(&client->dev, "Voltage low, data loss detected.\n");
638 if (status & RV3028_STATUS_AF)
639 dev_warn(&client->dev, "An alarm may have been missed.\n");
641 rv3028->rtc = devm_rtc_allocate_device(&client->dev);
642 if (IS_ERR(rv3028->rtc)) {
643 return PTR_ERR(rv3028->rtc);
646 if (client->irq > 0) {
647 ret = devm_request_threaded_irq(&client->dev, client->irq,
648 NULL, rv3028_handle_irq,
649 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
650 "rv3028", rv3028);
651 if (ret) {
652 dev_warn(&client->dev, "unable to request IRQ, alarms disabled\n");
653 client->irq = 0;
654 } else {
655 rv3028_rtc_ops.read_alarm = rv3028_get_alarm;
656 rv3028_rtc_ops.set_alarm = rv3028_set_alarm;
657 rv3028_rtc_ops.alarm_irq_enable = rv3028_alarm_irq_enable;
661 ret = regmap_update_bits(rv3028->regmap, RV3028_CTRL1,
662 RV3028_CTRL1_WADA, RV3028_CTRL1_WADA);
663 if (ret)
664 return ret;
666 /* setup timestamping */
667 ret = regmap_update_bits(rv3028->regmap, RV3028_CTRL2,
668 RV3028_CTRL2_EIE | RV3028_CTRL2_TSE,
669 RV3028_CTRL2_EIE | RV3028_CTRL2_TSE);
670 if (ret)
671 return ret;
673 /* setup trickle charger */
674 if (!device_property_read_u32(&client->dev, "trickle-resistor-ohms",
675 &ohms)) {
676 int i;
678 for (i = 0; i < ARRAY_SIZE(rv3028_trickle_resistors); i++)
679 if (ohms == rv3028_trickle_resistors[i])
680 break;
682 if (i < ARRAY_SIZE(rv3028_trickle_resistors)) {
683 ret = regmap_update_bits(rv3028->regmap, RV3028_BACKUP,
684 RV3028_BACKUP_TCE |
685 RV3028_BACKUP_TCR_MASK,
686 RV3028_BACKUP_TCE | i);
687 if (ret)
688 return ret;
689 } else {
690 dev_warn(&client->dev, "invalid trickle resistor value\n");
694 ret = rtc_add_group(rv3028->rtc, &rv3028_attr_group);
695 if (ret)
696 return ret;
698 rv3028->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
699 rv3028->rtc->range_max = RTC_TIMESTAMP_END_2099;
700 rv3028->rtc->ops = &rv3028_rtc_ops;
701 ret = rtc_register_device(rv3028->rtc);
702 if (ret)
703 return ret;
705 nvmem_cfg.priv = rv3028->regmap;
706 rtc_nvmem_register(rv3028->rtc, &nvmem_cfg);
707 eeprom_cfg.priv = rv3028->regmap;
708 rtc_nvmem_register(rv3028->rtc, &eeprom_cfg);
710 rv3028->rtc->max_user_freq = 1;
712 return 0;
715 static const struct of_device_id rv3028_of_match[] = {
716 { .compatible = "microcrystal,rv3028", },
719 MODULE_DEVICE_TABLE(of, rv3028_of_match);
721 static struct i2c_driver rv3028_driver = {
722 .driver = {
723 .name = "rtc-rv3028",
724 .of_match_table = of_match_ptr(rv3028_of_match),
726 .probe_new = rv3028_probe,
728 module_i2c_driver(rv3028_driver);
730 MODULE_AUTHOR("Alexandre Belloni <alexandre.belloni@bootlin.com>");
731 MODULE_DESCRIPTION("Micro Crystal RV3028 RTC driver");
732 MODULE_LICENSE("GPL v2");