2 * Micro Crystal RV-3029 rtc class driver
4 * Author: Gregory Hermant <gregory.hermant@calao-systems.com>
5 * Michael Buesch <m@bues.ch>
7 * based on previously existing rtc class drivers
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
15 #include <linux/module.h>
16 #include <linux/i2c.h>
17 #include <linux/bcd.h>
18 #include <linux/rtc.h>
19 #include <linux/delay.h>
21 #include <linux/hwmon.h>
22 #include <linux/hwmon-sysfs.h>
27 #define RV3029_ONOFF_CTRL 0x00
28 #define RV3029_ONOFF_CTRL_WE BIT(0)
29 #define RV3029_ONOFF_CTRL_TE BIT(1)
30 #define RV3029_ONOFF_CTRL_TAR BIT(2)
31 #define RV3029_ONOFF_CTRL_EERE BIT(3)
32 #define RV3029_ONOFF_CTRL_SRON BIT(4)
33 #define RV3029_ONOFF_CTRL_TD0 BIT(5)
34 #define RV3029_ONOFF_CTRL_TD1 BIT(6)
35 #define RV3029_ONOFF_CTRL_CLKINT BIT(7)
36 #define RV3029_IRQ_CTRL 0x01
37 #define RV3029_IRQ_CTRL_AIE BIT(0)
38 #define RV3029_IRQ_CTRL_TIE BIT(1)
39 #define RV3029_IRQ_CTRL_V1IE BIT(2)
40 #define RV3029_IRQ_CTRL_V2IE BIT(3)
41 #define RV3029_IRQ_CTRL_SRIE BIT(4)
42 #define RV3029_IRQ_FLAGS 0x02
43 #define RV3029_IRQ_FLAGS_AF BIT(0)
44 #define RV3029_IRQ_FLAGS_TF BIT(1)
45 #define RV3029_IRQ_FLAGS_V1IF BIT(2)
46 #define RV3029_IRQ_FLAGS_V2IF BIT(3)
47 #define RV3029_IRQ_FLAGS_SRF BIT(4)
48 #define RV3029_STATUS 0x03
49 #define RV3029_STATUS_VLOW1 BIT(2)
50 #define RV3029_STATUS_VLOW2 BIT(3)
51 #define RV3029_STATUS_SR BIT(4)
52 #define RV3029_STATUS_PON BIT(5)
53 #define RV3029_STATUS_EEBUSY BIT(7)
54 #define RV3029_RST_CTRL 0x04
55 #define RV3029_RST_CTRL_SYSR BIT(4)
56 #define RV3029_CONTROL_SECTION_LEN 0x05
59 #define RV3029_W_SEC 0x08
60 #define RV3029_W_MINUTES 0x09
61 #define RV3029_W_HOURS 0x0A
62 #define RV3029_REG_HR_12_24 BIT(6) /* 24h/12h mode */
63 #define RV3029_REG_HR_PM BIT(5) /* PM/AM bit in 12h mode */
64 #define RV3029_W_DATE 0x0B
65 #define RV3029_W_DAYS 0x0C
66 #define RV3029_W_MONTHS 0x0D
67 #define RV3029_W_YEARS 0x0E
68 #define RV3029_WATCH_SECTION_LEN 0x07
71 #define RV3029_A_SC 0x10
72 #define RV3029_A_MN 0x11
73 #define RV3029_A_HR 0x12
74 #define RV3029_A_DT 0x13
75 #define RV3029_A_DW 0x14
76 #define RV3029_A_MO 0x15
77 #define RV3029_A_YR 0x16
78 #define RV3029_ALARM_SECTION_LEN 0x07
81 #define RV3029_TIMER_LOW 0x18
82 #define RV3029_TIMER_HIGH 0x19
84 /* temperature section */
85 #define RV3029_TEMP_PAGE 0x20
87 /* eeprom data section */
88 #define RV3029_E2P_EEDATA1 0x28
89 #define RV3029_E2P_EEDATA2 0x29
90 #define RV3029_E2PDATA_SECTION_LEN 0x02
92 /* eeprom control section */
93 #define RV3029_CONTROL_E2P_EECTRL 0x30
94 #define RV3029_EECTRL_THP BIT(0) /* temp scan interval */
95 #define RV3029_EECTRL_THE BIT(1) /* thermometer enable */
96 #define RV3029_EECTRL_FD0 BIT(2) /* CLKOUT */
97 #define RV3029_EECTRL_FD1 BIT(3) /* CLKOUT */
98 #define RV3029_TRICKLE_1K BIT(4) /* 1.5K resistance */
99 #define RV3029_TRICKLE_5K BIT(5) /* 5K resistance */
100 #define RV3029_TRICKLE_20K BIT(6) /* 20K resistance */
101 #define RV3029_TRICKLE_80K BIT(7) /* 80K resistance */
102 #define RV3029_TRICKLE_MASK (RV3029_TRICKLE_1K |\
104 RV3029_TRICKLE_20K |\
106 #define RV3029_TRICKLE_SHIFT 4
107 #define RV3029_CONTROL_E2P_XOFFS 0x31 /* XTAL offset */
108 #define RV3029_CONTROL_E2P_XOFFS_SIGN BIT(7) /* Sign: 1->pos, 0->neg */
109 #define RV3029_CONTROL_E2P_QCOEF 0x32 /* XTAL temp drift coef */
110 #define RV3029_CONTROL_E2P_TURNOVER 0x33 /* XTAL turnover temp (in *C) */
111 #define RV3029_CONTROL_E2P_TOV_MASK 0x3F /* XTAL turnover temp mask */
113 /* user ram section */
114 #define RV3029_USR1_RAM_PAGE 0x38
115 #define RV3029_USR1_SECTION_LEN 0x04
116 #define RV3029_USR2_RAM_PAGE 0x3C
117 #define RV3029_USR2_SECTION_LEN 0x04
120 rv3029_i2c_read_regs(struct i2c_client
*client
, u8 reg
, u8
*buf
,
125 if ((reg
> RV3029_USR1_RAM_PAGE
+ 7) ||
126 (reg
+ len
> RV3029_USR1_RAM_PAGE
+ 8))
129 ret
= i2c_smbus_read_i2c_block_data(client
, reg
, len
, buf
);
138 rv3029_i2c_write_regs(struct i2c_client
*client
, u8 reg
, u8
const buf
[],
141 if ((reg
> RV3029_USR1_RAM_PAGE
+ 7) ||
142 (reg
+ len
> RV3029_USR1_RAM_PAGE
+ 8))
145 return i2c_smbus_write_i2c_block_data(client
, reg
, len
, buf
);
149 rv3029_i2c_update_bits(struct i2c_client
*client
, u8 reg
, u8 mask
, u8 set
)
154 ret
= rv3029_i2c_read_regs(client
, reg
, &buf
, 1);
159 ret
= rv3029_i2c_write_regs(client
, reg
, &buf
, 1);
167 rv3029_i2c_get_sr(struct i2c_client
*client
, u8
*buf
)
169 int ret
= rv3029_i2c_read_regs(client
, RV3029_STATUS
, buf
, 1);
173 dev_dbg(&client
->dev
, "status = 0x%.2x (%d)\n", buf
[0], buf
[0]);
178 rv3029_i2c_set_sr(struct i2c_client
*client
, u8 val
)
184 sr
= rv3029_i2c_write_regs(client
, RV3029_STATUS
, buf
, 1);
185 dev_dbg(&client
->dev
, "status = 0x%.2x (%d)\n", buf
[0], buf
[0]);
191 static int rv3029_eeprom_busywait(struct i2c_client
*client
)
196 for (i
= 100; i
> 0; i
--) {
197 ret
= rv3029_i2c_get_sr(client
, &sr
);
200 if (!(sr
& RV3029_STATUS_EEBUSY
))
202 usleep_range(1000, 10000);
205 dev_err(&client
->dev
, "EEPROM busy wait timeout.\n");
212 static int rv3029_eeprom_exit(struct i2c_client
*client
)
214 /* Re-enable eeprom refresh */
215 return rv3029_i2c_update_bits(client
, RV3029_ONOFF_CTRL
,
216 RV3029_ONOFF_CTRL_EERE
,
217 RV3029_ONOFF_CTRL_EERE
);
220 static int rv3029_eeprom_enter(struct i2c_client
*client
)
225 /* Check whether we are in the allowed voltage range. */
226 ret
= rv3029_i2c_get_sr(client
, &sr
);
229 if (sr
& (RV3029_STATUS_VLOW1
| RV3029_STATUS_VLOW2
)) {
230 /* We clear the bits and retry once just in case
231 * we had a brown out in early startup.
233 sr
&= ~RV3029_STATUS_VLOW1
;
234 sr
&= ~RV3029_STATUS_VLOW2
;
235 ret
= rv3029_i2c_set_sr(client
, sr
);
238 usleep_range(1000, 10000);
239 ret
= rv3029_i2c_get_sr(client
, &sr
);
242 if (sr
& (RV3029_STATUS_VLOW1
| RV3029_STATUS_VLOW2
)) {
243 dev_err(&client
->dev
,
244 "Supply voltage is too low to safely access the EEPROM.\n");
249 /* Disable eeprom refresh. */
250 ret
= rv3029_i2c_update_bits(client
, RV3029_ONOFF_CTRL
,
251 RV3029_ONOFF_CTRL_EERE
, 0);
255 /* Wait for any previous eeprom accesses to finish. */
256 ret
= rv3029_eeprom_busywait(client
);
258 rv3029_eeprom_exit(client
);
263 static int rv3029_eeprom_read(struct i2c_client
*client
, u8 reg
,
264 u8 buf
[], size_t len
)
268 err
= rv3029_eeprom_enter(client
);
272 ret
= rv3029_i2c_read_regs(client
, reg
, buf
, len
);
274 err
= rv3029_eeprom_exit(client
);
281 static int rv3029_eeprom_write(struct i2c_client
*client
, u8 reg
,
282 u8
const buf
[], size_t len
)
288 err
= rv3029_eeprom_enter(client
);
292 for (i
= 0; i
< len
; i
++, reg
++) {
293 ret
= rv3029_i2c_read_regs(client
, reg
, &tmp
, 1);
297 ret
= rv3029_i2c_write_regs(client
, reg
, &buf
[i
], 1);
301 ret
= rv3029_eeprom_busywait(client
);
306 err
= rv3029_eeprom_exit(client
);
313 static int rv3029_eeprom_update_bits(struct i2c_client
*client
,
314 u8 reg
, u8 mask
, u8 set
)
319 ret
= rv3029_eeprom_read(client
, reg
, &buf
, 1);
324 ret
= rv3029_eeprom_write(client
, reg
, &buf
, 1);
332 rv3029_i2c_read_time(struct i2c_client
*client
, struct rtc_time
*tm
)
336 u8 regs
[RV3029_WATCH_SECTION_LEN
] = { 0, };
338 ret
= rv3029_i2c_get_sr(client
, buf
);
340 dev_err(&client
->dev
, "%s: reading SR failed\n", __func__
);
344 ret
= rv3029_i2c_read_regs(client
, RV3029_W_SEC
, regs
,
345 RV3029_WATCH_SECTION_LEN
);
347 dev_err(&client
->dev
, "%s: reading RTC section failed\n",
352 tm
->tm_sec
= bcd2bin(regs
[RV3029_W_SEC
-RV3029_W_SEC
]);
353 tm
->tm_min
= bcd2bin(regs
[RV3029_W_MINUTES
-RV3029_W_SEC
]);
355 /* HR field has a more complex interpretation */
357 const u8 _hr
= regs
[RV3029_W_HOURS
-RV3029_W_SEC
];
359 if (_hr
& RV3029_REG_HR_12_24
) {
361 tm
->tm_hour
= bcd2bin(_hr
& 0x1f);
362 if (_hr
& RV3029_REG_HR_PM
) /* PM flag set */
364 } else /* 24h format */
365 tm
->tm_hour
= bcd2bin(_hr
& 0x3f);
368 tm
->tm_mday
= bcd2bin(regs
[RV3029_W_DATE
-RV3029_W_SEC
]);
369 tm
->tm_mon
= bcd2bin(regs
[RV3029_W_MONTHS
-RV3029_W_SEC
]) - 1;
370 tm
->tm_year
= bcd2bin(regs
[RV3029_W_YEARS
-RV3029_W_SEC
]) + 100;
371 tm
->tm_wday
= bcd2bin(regs
[RV3029_W_DAYS
-RV3029_W_SEC
]) - 1;
376 static int rv3029_rtc_read_time(struct device
*dev
, struct rtc_time
*tm
)
378 return rv3029_i2c_read_time(to_i2c_client(dev
), tm
);
382 rv3029_i2c_read_alarm(struct i2c_client
*client
, struct rtc_wkalrm
*alarm
)
384 struct rtc_time
*const tm
= &alarm
->time
;
388 ret
= rv3029_i2c_get_sr(client
, regs
);
390 dev_err(&client
->dev
, "%s: reading SR failed\n", __func__
);
394 ret
= rv3029_i2c_read_regs(client
, RV3029_A_SC
, regs
,
395 RV3029_ALARM_SECTION_LEN
);
398 dev_err(&client
->dev
, "%s: reading alarm section failed\n",
403 tm
->tm_sec
= bcd2bin(regs
[RV3029_A_SC
-RV3029_A_SC
] & 0x7f);
404 tm
->tm_min
= bcd2bin(regs
[RV3029_A_MN
-RV3029_A_SC
] & 0x7f);
405 tm
->tm_hour
= bcd2bin(regs
[RV3029_A_HR
-RV3029_A_SC
] & 0x3f);
406 tm
->tm_mday
= bcd2bin(regs
[RV3029_A_DT
-RV3029_A_SC
] & 0x3f);
407 tm
->tm_mon
= bcd2bin(regs
[RV3029_A_MO
-RV3029_A_SC
] & 0x1f) - 1;
408 tm
->tm_year
= bcd2bin(regs
[RV3029_A_YR
-RV3029_A_SC
] & 0x7f) + 100;
409 tm
->tm_wday
= bcd2bin(regs
[RV3029_A_DW
-RV3029_A_SC
] & 0x07) - 1;
415 rv3029_rtc_read_alarm(struct device
*dev
, struct rtc_wkalrm
*alarm
)
417 return rv3029_i2c_read_alarm(to_i2c_client(dev
), alarm
);
420 static int rv3029_rtc_i2c_alarm_set_irq(struct i2c_client
*client
,
425 /* enable/disable AIE irq */
426 ret
= rv3029_i2c_update_bits(client
, RV3029_IRQ_CTRL
,
428 (enable
? RV3029_IRQ_CTRL_AIE
: 0));
430 dev_err(&client
->dev
, "can't update INT reg\n");
437 static int rv3029_rtc_i2c_set_alarm(struct i2c_client
*client
,
438 struct rtc_wkalrm
*alarm
)
440 struct rtc_time
*const tm
= &alarm
->time
;
445 * The clock has an 8 bit wide bcd-coded register (they never learn)
446 * for the year. tm_year is an offset from 1900 and we are interested
447 * in the 2000-2099 range, so any value less than 100 is invalid.
449 if (tm
->tm_year
< 100)
452 ret
= rv3029_i2c_get_sr(client
, regs
);
454 dev_err(&client
->dev
, "%s: reading SR failed\n", __func__
);
457 regs
[RV3029_A_SC
-RV3029_A_SC
] = bin2bcd(tm
->tm_sec
& 0x7f);
458 regs
[RV3029_A_MN
-RV3029_A_SC
] = bin2bcd(tm
->tm_min
& 0x7f);
459 regs
[RV3029_A_HR
-RV3029_A_SC
] = bin2bcd(tm
->tm_hour
& 0x3f);
460 regs
[RV3029_A_DT
-RV3029_A_SC
] = bin2bcd(tm
->tm_mday
& 0x3f);
461 regs
[RV3029_A_MO
-RV3029_A_SC
] = bin2bcd((tm
->tm_mon
& 0x1f) - 1);
462 regs
[RV3029_A_DW
-RV3029_A_SC
] = bin2bcd((tm
->tm_wday
& 7) - 1);
463 regs
[RV3029_A_YR
-RV3029_A_SC
] = bin2bcd((tm
->tm_year
& 0x7f) - 100);
465 ret
= rv3029_i2c_write_regs(client
, RV3029_A_SC
, regs
,
466 RV3029_ALARM_SECTION_LEN
);
470 if (alarm
->enabled
) {
472 ret
= rv3029_i2c_update_bits(client
, RV3029_IRQ_FLAGS
,
473 RV3029_IRQ_FLAGS_AF
, 0);
475 dev_err(&client
->dev
, "can't clear alarm flag\n");
479 ret
= rv3029_rtc_i2c_alarm_set_irq(client
, 1);
483 dev_dbg(&client
->dev
, "alarm IRQ armed\n");
485 /* disable AIE irq */
486 ret
= rv3029_rtc_i2c_alarm_set_irq(client
, 0);
490 dev_dbg(&client
->dev
, "alarm IRQ disabled\n");
496 static int rv3029_rtc_set_alarm(struct device
*dev
, struct rtc_wkalrm
*alarm
)
498 return rv3029_rtc_i2c_set_alarm(to_i2c_client(dev
), alarm
);
502 rv3029_i2c_set_time(struct i2c_client
*client
, struct rtc_time
const *tm
)
508 * The clock has an 8 bit wide bcd-coded register (they never learn)
509 * for the year. tm_year is an offset from 1900 and we are interested
510 * in the 2000-2099 range, so any value less than 100 is invalid.
512 if (tm
->tm_year
< 100)
515 regs
[RV3029_W_SEC
-RV3029_W_SEC
] = bin2bcd(tm
->tm_sec
);
516 regs
[RV3029_W_MINUTES
-RV3029_W_SEC
] = bin2bcd(tm
->tm_min
);
517 regs
[RV3029_W_HOURS
-RV3029_W_SEC
] = bin2bcd(tm
->tm_hour
);
518 regs
[RV3029_W_DATE
-RV3029_W_SEC
] = bin2bcd(tm
->tm_mday
);
519 regs
[RV3029_W_MONTHS
-RV3029_W_SEC
] = bin2bcd(tm
->tm_mon
+1);
520 regs
[RV3029_W_DAYS
-RV3029_W_SEC
] = bin2bcd((tm
->tm_wday
& 7)+1);
521 regs
[RV3029_W_YEARS
-RV3029_W_SEC
] = bin2bcd(tm
->tm_year
- 100);
523 ret
= rv3029_i2c_write_regs(client
, RV3029_W_SEC
, regs
,
524 RV3029_WATCH_SECTION_LEN
);
528 ret
= rv3029_i2c_get_sr(client
, regs
);
530 dev_err(&client
->dev
, "%s: reading SR failed\n", __func__
);
534 ret
= rv3029_i2c_set_sr(client
, (regs
[0] & ~RV3029_STATUS_PON
));
536 dev_err(&client
->dev
, "%s: reading SR failed\n", __func__
);
543 static int rv3029_rtc_set_time(struct device
*dev
, struct rtc_time
*tm
)
545 return rv3029_i2c_set_time(to_i2c_client(dev
), tm
);
548 static const struct rv3029_trickle_tab_elem
{
549 u32 r
; /* resistance in ohms */
550 u8 conf
; /* trickle config bits */
551 } rv3029_trickle_tab
[] = {
554 .conf
= RV3029_TRICKLE_1K
| RV3029_TRICKLE_5K
|
555 RV3029_TRICKLE_20K
| RV3029_TRICKLE_80K
,
558 .conf
= RV3029_TRICKLE_1K
| RV3029_TRICKLE_5K
|
562 .conf
= RV3029_TRICKLE_1K
| RV3029_TRICKLE_5K
|
566 .conf
= RV3029_TRICKLE_1K
| RV3029_TRICKLE_5K
,
569 .conf
= RV3029_TRICKLE_1K
| RV3029_TRICKLE_20K
|
573 .conf
= RV3029_TRICKLE_1K
| RV3029_TRICKLE_20K
,
576 .conf
= RV3029_TRICKLE_1K
| RV3029_TRICKLE_80K
,
579 .conf
= RV3029_TRICKLE_1K
,
582 .conf
= RV3029_TRICKLE_5K
| RV3029_TRICKLE_20K
|
586 .conf
= RV3029_TRICKLE_5K
| RV3029_TRICKLE_20K
,
589 .conf
= RV3029_TRICKLE_5K
| RV3029_TRICKLE_80K
,
592 .conf
= RV3029_TRICKLE_5K
,
595 .conf
= RV3029_TRICKLE_20K
| RV3029_TRICKLE_80K
,
598 .conf
= RV3029_TRICKLE_20K
,
601 .conf
= RV3029_TRICKLE_80K
,
605 static void rv3029_trickle_config(struct i2c_client
*client
)
607 struct device_node
*of_node
= client
->dev
.of_node
;
608 const struct rv3029_trickle_tab_elem
*elem
;
616 /* Configure the trickle charger. */
617 err
= of_property_read_u32(of_node
, "trickle-resistor-ohms", &ohms
);
619 /* Disable trickle charger. */
620 trickle_set_bits
= 0;
622 /* Enable trickle charger. */
623 for (i
= 0; i
< ARRAY_SIZE(rv3029_trickle_tab
); i
++) {
624 elem
= &rv3029_trickle_tab
[i
];
628 trickle_set_bits
= elem
->conf
;
629 dev_info(&client
->dev
,
630 "Trickle charger enabled at %d ohms resistance.\n",
633 err
= rv3029_eeprom_update_bits(client
, RV3029_CONTROL_E2P_EECTRL
,
637 dev_err(&client
->dev
,
638 "Failed to update trickle charger config\n");
642 #ifdef CONFIG_RTC_DRV_RV3029_HWMON
644 static int rv3029_read_temp(struct i2c_client
*client
, int *temp_mC
)
649 ret
= rv3029_i2c_read_regs(client
, RV3029_TEMP_PAGE
, &temp
, 1);
653 *temp_mC
= ((int)temp
- 60) * 1000;
658 static ssize_t
rv3029_hwmon_show_temp(struct device
*dev
,
659 struct device_attribute
*attr
,
662 struct i2c_client
*client
= dev_get_drvdata(dev
);
665 ret
= rv3029_read_temp(client
, &temp_mC
);
669 return sprintf(buf
, "%d\n", temp_mC
);
672 static ssize_t
rv3029_hwmon_set_update_interval(struct device
*dev
,
673 struct device_attribute
*attr
,
677 struct i2c_client
*client
= dev_get_drvdata(dev
);
678 unsigned long interval_ms
;
682 ret
= kstrtoul(buf
, 10, &interval_ms
);
686 if (interval_ms
!= 0) {
687 th_set_bits
|= RV3029_EECTRL_THE
;
688 if (interval_ms
>= 16000)
689 th_set_bits
|= RV3029_EECTRL_THP
;
691 ret
= rv3029_eeprom_update_bits(client
, RV3029_CONTROL_E2P_EECTRL
,
692 RV3029_EECTRL_THE
| RV3029_EECTRL_THP
,
700 static ssize_t
rv3029_hwmon_show_update_interval(struct device
*dev
,
701 struct device_attribute
*attr
,
704 struct i2c_client
*client
= dev_get_drvdata(dev
);
705 int ret
, interval_ms
;
708 ret
= rv3029_eeprom_read(client
, RV3029_CONTROL_E2P_EECTRL
,
713 if (eectrl
& RV3029_EECTRL_THE
) {
714 if (eectrl
& RV3029_EECTRL_THP
)
722 return sprintf(buf
, "%d\n", interval_ms
);
725 static SENSOR_DEVICE_ATTR(temp1_input
, S_IRUGO
, rv3029_hwmon_show_temp
,
727 static SENSOR_DEVICE_ATTR(update_interval
, S_IWUSR
| S_IRUGO
,
728 rv3029_hwmon_show_update_interval
,
729 rv3029_hwmon_set_update_interval
, 0);
731 static struct attribute
*rv3029_hwmon_attrs
[] = {
732 &sensor_dev_attr_temp1_input
.dev_attr
.attr
,
733 &sensor_dev_attr_update_interval
.dev_attr
.attr
,
736 ATTRIBUTE_GROUPS(rv3029_hwmon
);
738 static void rv3029_hwmon_register(struct i2c_client
*client
)
740 struct device
*hwmon_dev
;
742 hwmon_dev
= devm_hwmon_device_register_with_groups(
743 &client
->dev
, client
->name
, client
, rv3029_hwmon_groups
);
744 if (IS_ERR(hwmon_dev
)) {
745 dev_warn(&client
->dev
,
746 "unable to register hwmon device %ld\n",
751 #else /* CONFIG_RTC_DRV_RV3029_HWMON */
753 static void rv3029_hwmon_register(struct i2c_client
*client
)
757 #endif /* CONFIG_RTC_DRV_RV3029_HWMON */
759 static const struct rtc_class_ops rv3029_rtc_ops
= {
760 .read_time
= rv3029_rtc_read_time
,
761 .set_time
= rv3029_rtc_set_time
,
762 .read_alarm
= rv3029_rtc_read_alarm
,
763 .set_alarm
= rv3029_rtc_set_alarm
,
766 static struct i2c_device_id rv3029_id
[] = {
771 MODULE_DEVICE_TABLE(i2c
, rv3029_id
);
773 static int rv3029_probe(struct i2c_client
*client
,
774 const struct i2c_device_id
*id
)
776 struct rtc_device
*rtc
;
780 if (!i2c_check_functionality(client
->adapter
, I2C_FUNC_SMBUS_EMUL
))
783 rc
= rv3029_i2c_get_sr(client
, buf
);
785 dev_err(&client
->dev
, "reading status failed\n");
789 rv3029_trickle_config(client
);
790 rv3029_hwmon_register(client
);
792 rtc
= devm_rtc_device_register(&client
->dev
, client
->name
,
793 &rv3029_rtc_ops
, THIS_MODULE
);
798 i2c_set_clientdata(client
, rtc
);
803 static struct i2c_driver rv3029_driver
= {
805 .name
= "rtc-rv3029c2",
807 .probe
= rv3029_probe
,
808 .id_table
= rv3029_id
,
811 module_i2c_driver(rv3029_driver
);
813 MODULE_AUTHOR("Gregory Hermant <gregory.hermant@calao-systems.com>");
814 MODULE_AUTHOR("Michael Buesch <m@bues.ch>");
815 MODULE_DESCRIPTION("Micro Crystal RV3029 RTC driver");
816 MODULE_LICENSE("GPL");