1 // SPDX-License-Identifier: GPL-2.0
3 * A driver for the I2C members of the Abracon AB x8xx RTC family,
4 * and compatible: AB 1805 and AB 0805
6 * Copyright 2014-2015 Macq S.A.
8 * Author: Philippe De Muyter <phdm@macqel.be>
9 * Author: Alexandre Belloni <alexandre.belloni@bootlin.com>
13 #include <linux/bcd.h>
14 #include <linux/i2c.h>
15 #include <linux/module.h>
16 #include <linux/rtc.h>
17 #include <linux/watchdog.h>
19 #define ABX8XX_REG_HTH 0x00
20 #define ABX8XX_REG_SC 0x01
21 #define ABX8XX_REG_MN 0x02
22 #define ABX8XX_REG_HR 0x03
23 #define ABX8XX_REG_DA 0x04
24 #define ABX8XX_REG_MO 0x05
25 #define ABX8XX_REG_YR 0x06
26 #define ABX8XX_REG_WD 0x07
28 #define ABX8XX_REG_AHTH 0x08
29 #define ABX8XX_REG_ASC 0x09
30 #define ABX8XX_REG_AMN 0x0a
31 #define ABX8XX_REG_AHR 0x0b
32 #define ABX8XX_REG_ADA 0x0c
33 #define ABX8XX_REG_AMO 0x0d
34 #define ABX8XX_REG_AWD 0x0e
36 #define ABX8XX_REG_STATUS 0x0f
37 #define ABX8XX_STATUS_AF BIT(2)
38 #define ABX8XX_STATUS_BLF BIT(4)
39 #define ABX8XX_STATUS_WDT BIT(6)
41 #define ABX8XX_REG_CTRL1 0x10
42 #define ABX8XX_CTRL_WRITE BIT(0)
43 #define ABX8XX_CTRL_ARST BIT(2)
44 #define ABX8XX_CTRL_12_24 BIT(6)
46 #define ABX8XX_REG_CTRL2 0x11
47 #define ABX8XX_CTRL2_RSVD BIT(5)
49 #define ABX8XX_REG_IRQ 0x12
50 #define ABX8XX_IRQ_AIE BIT(2)
51 #define ABX8XX_IRQ_IM_1_4 (0x3 << 5)
53 #define ABX8XX_REG_CD_TIMER_CTL 0x18
55 #define ABX8XX_REG_OSC 0x1c
56 #define ABX8XX_OSC_FOS BIT(3)
57 #define ABX8XX_OSC_BOS BIT(4)
58 #define ABX8XX_OSC_ACAL_512 BIT(5)
59 #define ABX8XX_OSC_ACAL_1024 BIT(6)
61 #define ABX8XX_OSC_OSEL BIT(7)
63 #define ABX8XX_REG_OSS 0x1d
64 #define ABX8XX_OSS_OF BIT(1)
65 #define ABX8XX_OSS_OMODE BIT(4)
67 #define ABX8XX_REG_WDT 0x1b
68 #define ABX8XX_WDT_WDS BIT(7)
69 #define ABX8XX_WDT_BMB_MASK 0x7c
70 #define ABX8XX_WDT_BMB_SHIFT 2
71 #define ABX8XX_WDT_MAX_TIME (ABX8XX_WDT_BMB_MASK >> ABX8XX_WDT_BMB_SHIFT)
72 #define ABX8XX_WDT_WRB_MASK 0x03
73 #define ABX8XX_WDT_WRB_1HZ 0x02
75 #define ABX8XX_REG_CFG_KEY 0x1f
76 #define ABX8XX_CFG_KEY_OSC 0xa1
77 #define ABX8XX_CFG_KEY_MISC 0x9d
79 #define ABX8XX_REG_ID0 0x28
81 #define ABX8XX_REG_OUT_CTRL 0x30
82 #define ABX8XX_OUT_CTRL_EXDS BIT(4)
84 #define ABX8XX_REG_TRICKLE 0x20
85 #define ABX8XX_TRICKLE_CHARGE_ENABLE 0xa0
86 #define ABX8XX_TRICKLE_STANDARD_DIODE 0x8
87 #define ABX8XX_TRICKLE_SCHOTTKY_DIODE 0x4
89 static u8 trickle_resistors
[] = {0, 3, 6, 11};
91 enum abx80x_chip
{AB0801
, AB0803
, AB0804
, AB0805
,
92 AB1801
, AB1803
, AB1804
, AB1805
, RV1805
, ABX80X
};
100 static struct abx80x_cap abx80x_caps
[] = {
101 [AB0801
] = {.pn
= 0x0801},
102 [AB0803
] = {.pn
= 0x0803},
103 [AB0804
] = {.pn
= 0x0804, .has_tc
= true, .has_wdog
= true},
104 [AB0805
] = {.pn
= 0x0805, .has_tc
= true, .has_wdog
= true},
105 [AB1801
] = {.pn
= 0x1801},
106 [AB1803
] = {.pn
= 0x1803},
107 [AB1804
] = {.pn
= 0x1804, .has_tc
= true, .has_wdog
= true},
108 [AB1805
] = {.pn
= 0x1805, .has_tc
= true, .has_wdog
= true},
109 [RV1805
] = {.pn
= 0x1805, .has_tc
= true, .has_wdog
= true},
114 struct rtc_device
*rtc
;
115 struct i2c_client
*client
;
116 struct watchdog_device wdog
;
119 static int abx80x_is_rc_mode(struct i2c_client
*client
)
123 flags
= i2c_smbus_read_byte_data(client
, ABX8XX_REG_OSS
);
125 dev_err(&client
->dev
,
126 "Failed to read autocalibration attribute\n");
130 return (flags
& ABX8XX_OSS_OMODE
) ? 1 : 0;
133 static int abx80x_enable_trickle_charger(struct i2c_client
*client
,
139 * Write the configuration key register to enable access to the Trickle
142 err
= i2c_smbus_write_byte_data(client
, ABX8XX_REG_CFG_KEY
,
143 ABX8XX_CFG_KEY_MISC
);
145 dev_err(&client
->dev
, "Unable to write configuration key\n");
149 err
= i2c_smbus_write_byte_data(client
, ABX8XX_REG_TRICKLE
,
150 ABX8XX_TRICKLE_CHARGE_ENABLE
|
153 dev_err(&client
->dev
, "Unable to write trickle register\n");
160 static int abx80x_rtc_read_time(struct device
*dev
, struct rtc_time
*tm
)
162 struct i2c_client
*client
= to_i2c_client(dev
);
163 unsigned char buf
[8];
164 int err
, flags
, rc_mode
= 0;
166 /* Read the Oscillator Failure only in XT mode */
167 rc_mode
= abx80x_is_rc_mode(client
);
172 flags
= i2c_smbus_read_byte_data(client
, ABX8XX_REG_OSS
);
176 if (flags
& ABX8XX_OSS_OF
) {
177 dev_err(dev
, "Oscillator failure, data is invalid.\n");
182 err
= i2c_smbus_read_i2c_block_data(client
, ABX8XX_REG_HTH
,
185 dev_err(&client
->dev
, "Unable to read date\n");
189 tm
->tm_sec
= bcd2bin(buf
[ABX8XX_REG_SC
] & 0x7F);
190 tm
->tm_min
= bcd2bin(buf
[ABX8XX_REG_MN
] & 0x7F);
191 tm
->tm_hour
= bcd2bin(buf
[ABX8XX_REG_HR
] & 0x3F);
192 tm
->tm_wday
= buf
[ABX8XX_REG_WD
] & 0x7;
193 tm
->tm_mday
= bcd2bin(buf
[ABX8XX_REG_DA
] & 0x3F);
194 tm
->tm_mon
= bcd2bin(buf
[ABX8XX_REG_MO
] & 0x1F) - 1;
195 tm
->tm_year
= bcd2bin(buf
[ABX8XX_REG_YR
]) + 100;
200 static int abx80x_rtc_set_time(struct device
*dev
, struct rtc_time
*tm
)
202 struct i2c_client
*client
= to_i2c_client(dev
);
203 unsigned char buf
[8];
206 if (tm
->tm_year
< 100)
209 buf
[ABX8XX_REG_HTH
] = 0;
210 buf
[ABX8XX_REG_SC
] = bin2bcd(tm
->tm_sec
);
211 buf
[ABX8XX_REG_MN
] = bin2bcd(tm
->tm_min
);
212 buf
[ABX8XX_REG_HR
] = bin2bcd(tm
->tm_hour
);
213 buf
[ABX8XX_REG_DA
] = bin2bcd(tm
->tm_mday
);
214 buf
[ABX8XX_REG_MO
] = bin2bcd(tm
->tm_mon
+ 1);
215 buf
[ABX8XX_REG_YR
] = bin2bcd(tm
->tm_year
- 100);
216 buf
[ABX8XX_REG_WD
] = tm
->tm_wday
;
218 err
= i2c_smbus_write_i2c_block_data(client
, ABX8XX_REG_HTH
,
221 dev_err(&client
->dev
, "Unable to write to date registers\n");
225 /* Clear the OF bit of Oscillator Status Register */
226 flags
= i2c_smbus_read_byte_data(client
, ABX8XX_REG_OSS
);
230 err
= i2c_smbus_write_byte_data(client
, ABX8XX_REG_OSS
,
231 flags
& ~ABX8XX_OSS_OF
);
233 dev_err(&client
->dev
, "Unable to write oscillator status register\n");
240 static irqreturn_t
abx80x_handle_irq(int irq
, void *dev_id
)
242 struct i2c_client
*client
= dev_id
;
243 struct abx80x_priv
*priv
= i2c_get_clientdata(client
);
244 struct rtc_device
*rtc
= priv
->rtc
;
247 status
= i2c_smbus_read_byte_data(client
, ABX8XX_REG_STATUS
);
251 if (status
& ABX8XX_STATUS_AF
)
252 rtc_update_irq(rtc
, 1, RTC_AF
| RTC_IRQF
);
255 * It is unclear if we'll get an interrupt before the external
258 if (status
& ABX8XX_STATUS_WDT
)
259 dev_alert(&client
->dev
, "watchdog timeout interrupt.\n");
261 i2c_smbus_write_byte_data(client
, ABX8XX_REG_STATUS
, 0);
266 static int abx80x_read_alarm(struct device
*dev
, struct rtc_wkalrm
*t
)
268 struct i2c_client
*client
= to_i2c_client(dev
);
269 unsigned char buf
[7];
273 if (client
->irq
<= 0)
276 err
= i2c_smbus_read_i2c_block_data(client
, ABX8XX_REG_ASC
,
281 irq_mask
= i2c_smbus_read_byte_data(client
, ABX8XX_REG_IRQ
);
285 t
->time
.tm_sec
= bcd2bin(buf
[0] & 0x7F);
286 t
->time
.tm_min
= bcd2bin(buf
[1] & 0x7F);
287 t
->time
.tm_hour
= bcd2bin(buf
[2] & 0x3F);
288 t
->time
.tm_mday
= bcd2bin(buf
[3] & 0x3F);
289 t
->time
.tm_mon
= bcd2bin(buf
[4] & 0x1F) - 1;
290 t
->time
.tm_wday
= buf
[5] & 0x7;
292 t
->enabled
= !!(irq_mask
& ABX8XX_IRQ_AIE
);
293 t
->pending
= (buf
[6] & ABX8XX_STATUS_AF
) && t
->enabled
;
298 static int abx80x_set_alarm(struct device
*dev
, struct rtc_wkalrm
*t
)
300 struct i2c_client
*client
= to_i2c_client(dev
);
304 if (client
->irq
<= 0)
308 alarm
[1] = bin2bcd(t
->time
.tm_sec
);
309 alarm
[2] = bin2bcd(t
->time
.tm_min
);
310 alarm
[3] = bin2bcd(t
->time
.tm_hour
);
311 alarm
[4] = bin2bcd(t
->time
.tm_mday
);
312 alarm
[5] = bin2bcd(t
->time
.tm_mon
+ 1);
314 err
= i2c_smbus_write_i2c_block_data(client
, ABX8XX_REG_AHTH
,
315 sizeof(alarm
), alarm
);
317 dev_err(&client
->dev
, "Unable to write alarm registers\n");
322 err
= i2c_smbus_write_byte_data(client
, ABX8XX_REG_IRQ
,
332 static int abx80x_rtc_set_autocalibration(struct device
*dev
,
335 struct i2c_client
*client
= to_i2c_client(dev
);
336 int retval
, flags
= 0;
338 if ((autocalibration
!= 0) && (autocalibration
!= 1024) &&
339 (autocalibration
!= 512)) {
340 dev_err(dev
, "autocalibration value outside permitted range\n");
344 flags
= i2c_smbus_read_byte_data(client
, ABX8XX_REG_OSC
);
348 if (autocalibration
== 0) {
349 flags
&= ~(ABX8XX_OSC_ACAL_512
| ABX8XX_OSC_ACAL_1024
);
350 } else if (autocalibration
== 1024) {
351 /* 1024 autocalibration is 0x10 */
352 flags
|= ABX8XX_OSC_ACAL_1024
;
353 flags
&= ~(ABX8XX_OSC_ACAL_512
);
355 /* 512 autocalibration is 0x11 */
356 flags
|= (ABX8XX_OSC_ACAL_1024
| ABX8XX_OSC_ACAL_512
);
359 /* Unlock write access to Oscillator Control Register */
360 retval
= i2c_smbus_write_byte_data(client
, ABX8XX_REG_CFG_KEY
,
363 dev_err(dev
, "Failed to write CONFIG_KEY register\n");
367 retval
= i2c_smbus_write_byte_data(client
, ABX8XX_REG_OSC
, flags
);
372 static int abx80x_rtc_get_autocalibration(struct device
*dev
)
374 struct i2c_client
*client
= to_i2c_client(dev
);
375 int flags
= 0, autocalibration
;
377 flags
= i2c_smbus_read_byte_data(client
, ABX8XX_REG_OSC
);
381 if (flags
& ABX8XX_OSC_ACAL_512
)
382 autocalibration
= 512;
383 else if (flags
& ABX8XX_OSC_ACAL_1024
)
384 autocalibration
= 1024;
388 return autocalibration
;
391 static ssize_t
autocalibration_store(struct device
*dev
,
392 struct device_attribute
*attr
,
393 const char *buf
, size_t count
)
396 unsigned long autocalibration
= 0;
398 retval
= kstrtoul(buf
, 10, &autocalibration
);
400 dev_err(dev
, "Failed to store RTC autocalibration attribute\n");
404 retval
= abx80x_rtc_set_autocalibration(dev
->parent
, autocalibration
);
406 return retval
? retval
: count
;
409 static ssize_t
autocalibration_show(struct device
*dev
,
410 struct device_attribute
*attr
, char *buf
)
412 int autocalibration
= 0;
414 autocalibration
= abx80x_rtc_get_autocalibration(dev
->parent
);
415 if (autocalibration
< 0) {
416 dev_err(dev
, "Failed to read RTC autocalibration\n");
418 return autocalibration
;
421 return sprintf(buf
, "%d\n", autocalibration
);
424 static DEVICE_ATTR_RW(autocalibration
);
426 static ssize_t
oscillator_store(struct device
*dev
,
427 struct device_attribute
*attr
,
428 const char *buf
, size_t count
)
430 struct i2c_client
*client
= to_i2c_client(dev
->parent
);
431 int retval
, flags
, rc_mode
= 0;
433 if (strncmp(buf
, "rc", 2) == 0) {
435 } else if (strncmp(buf
, "xtal", 4) == 0) {
438 dev_err(dev
, "Oscillator selection value outside permitted ones\n");
442 flags
= i2c_smbus_read_byte_data(client
, ABX8XX_REG_OSC
);
447 flags
&= ~(ABX8XX_OSC_OSEL
);
449 flags
|= (ABX8XX_OSC_OSEL
);
451 /* Unlock write access on Oscillator Control register */
452 retval
= i2c_smbus_write_byte_data(client
, ABX8XX_REG_CFG_KEY
,
455 dev_err(dev
, "Failed to write CONFIG_KEY register\n");
459 retval
= i2c_smbus_write_byte_data(client
, ABX8XX_REG_OSC
, flags
);
461 dev_err(dev
, "Failed to write Oscillator Control register\n");
465 return retval
? retval
: count
;
468 static ssize_t
oscillator_show(struct device
*dev
,
469 struct device_attribute
*attr
, char *buf
)
472 struct i2c_client
*client
= to_i2c_client(dev
->parent
);
474 rc_mode
= abx80x_is_rc_mode(client
);
477 dev_err(dev
, "Failed to read RTC oscillator selection\n");
483 return sprintf(buf
, "rc\n");
485 return sprintf(buf
, "xtal\n");
488 static DEVICE_ATTR_RW(oscillator
);
490 static struct attribute
*rtc_calib_attrs
[] = {
491 &dev_attr_autocalibration
.attr
,
492 &dev_attr_oscillator
.attr
,
496 static const struct attribute_group rtc_calib_attr_group
= {
497 .attrs
= rtc_calib_attrs
,
500 static int abx80x_alarm_irq_enable(struct device
*dev
, unsigned int enabled
)
502 struct i2c_client
*client
= to_i2c_client(dev
);
506 err
= i2c_smbus_write_byte_data(client
, ABX8XX_REG_IRQ
,
510 err
= i2c_smbus_write_byte_data(client
, ABX8XX_REG_IRQ
,
515 static int abx80x_ioctl(struct device
*dev
, unsigned int cmd
, unsigned long arg
)
517 struct i2c_client
*client
= to_i2c_client(dev
);
522 status
= i2c_smbus_read_byte_data(client
, ABX8XX_REG_STATUS
);
526 tmp
= status
& ABX8XX_STATUS_BLF
? RTC_VL_BACKUP_LOW
: 0;
528 return put_user(tmp
, (unsigned int __user
*)arg
);
531 status
= i2c_smbus_read_byte_data(client
, ABX8XX_REG_STATUS
);
535 status
&= ~ABX8XX_STATUS_BLF
;
537 tmp
= i2c_smbus_write_byte_data(client
, ABX8XX_REG_STATUS
, 0);
548 static const struct rtc_class_ops abx80x_rtc_ops
= {
549 .read_time
= abx80x_rtc_read_time
,
550 .set_time
= abx80x_rtc_set_time
,
551 .read_alarm
= abx80x_read_alarm
,
552 .set_alarm
= abx80x_set_alarm
,
553 .alarm_irq_enable
= abx80x_alarm_irq_enable
,
554 .ioctl
= abx80x_ioctl
,
557 static int abx80x_dt_trickle_cfg(struct device_node
*np
)
564 ret
= of_property_read_string(np
, "abracon,tc-diode", &diode
);
568 if (!strcmp(diode
, "standard"))
569 trickle_cfg
|= ABX8XX_TRICKLE_STANDARD_DIODE
;
570 else if (!strcmp(diode
, "schottky"))
571 trickle_cfg
|= ABX8XX_TRICKLE_SCHOTTKY_DIODE
;
575 ret
= of_property_read_u32(np
, "abracon,tc-resistor", &tmp
);
579 for (i
= 0; i
< sizeof(trickle_resistors
); i
++)
580 if (trickle_resistors
[i
] == tmp
)
583 if (i
== sizeof(trickle_resistors
))
586 return (trickle_cfg
| i
);
589 #ifdef CONFIG_WATCHDOG
591 static inline u8
timeout_bits(unsigned int timeout
)
593 return ((timeout
<< ABX8XX_WDT_BMB_SHIFT
) & ABX8XX_WDT_BMB_MASK
) |
597 static int __abx80x_wdog_set_timeout(struct watchdog_device
*wdog
,
598 unsigned int timeout
)
600 struct abx80x_priv
*priv
= watchdog_get_drvdata(wdog
);
601 u8 val
= ABX8XX_WDT_WDS
| timeout_bits(timeout
);
604 * Writing any timeout to the WDT register resets the watchdog timer.
605 * Writing 0 disables it.
607 return i2c_smbus_write_byte_data(priv
->client
, ABX8XX_REG_WDT
, val
);
610 static int abx80x_wdog_set_timeout(struct watchdog_device
*wdog
,
611 unsigned int new_timeout
)
615 if (watchdog_hw_running(wdog
))
616 err
= __abx80x_wdog_set_timeout(wdog
, new_timeout
);
619 wdog
->timeout
= new_timeout
;
624 static int abx80x_wdog_ping(struct watchdog_device
*wdog
)
626 return __abx80x_wdog_set_timeout(wdog
, wdog
->timeout
);
629 static int abx80x_wdog_start(struct watchdog_device
*wdog
)
631 return __abx80x_wdog_set_timeout(wdog
, wdog
->timeout
);
634 static int abx80x_wdog_stop(struct watchdog_device
*wdog
)
636 return __abx80x_wdog_set_timeout(wdog
, 0);
639 static const struct watchdog_info abx80x_wdog_info
= {
640 .identity
= "abx80x watchdog",
641 .options
= WDIOF_KEEPALIVEPING
| WDIOF_SETTIMEOUT
| WDIOF_MAGICCLOSE
,
644 static const struct watchdog_ops abx80x_wdog_ops
= {
645 .owner
= THIS_MODULE
,
646 .start
= abx80x_wdog_start
,
647 .stop
= abx80x_wdog_stop
,
648 .ping
= abx80x_wdog_ping
,
649 .set_timeout
= abx80x_wdog_set_timeout
,
652 static int abx80x_setup_watchdog(struct abx80x_priv
*priv
)
654 priv
->wdog
.parent
= &priv
->client
->dev
;
655 priv
->wdog
.ops
= &abx80x_wdog_ops
;
656 priv
->wdog
.info
= &abx80x_wdog_info
;
657 priv
->wdog
.min_timeout
= 1;
658 priv
->wdog
.max_timeout
= ABX8XX_WDT_MAX_TIME
;
659 priv
->wdog
.timeout
= ABX8XX_WDT_MAX_TIME
;
661 watchdog_set_drvdata(&priv
->wdog
, priv
);
663 return devm_watchdog_register_device(&priv
->client
->dev
, &priv
->wdog
);
666 static int abx80x_setup_watchdog(struct abx80x_priv
*priv
)
672 static int abx80x_probe(struct i2c_client
*client
,
673 const struct i2c_device_id
*id
)
675 struct device_node
*np
= client
->dev
.of_node
;
676 struct abx80x_priv
*priv
;
677 int i
, data
, err
, trickle_cfg
= -EINVAL
;
679 unsigned int part
= id
->driver_data
;
680 unsigned int partnumber
;
681 unsigned int majrev
, minrev
;
686 if (!i2c_check_functionality(client
->adapter
, I2C_FUNC_I2C
))
689 err
= i2c_smbus_read_i2c_block_data(client
, ABX8XX_REG_ID0
,
692 dev_err(&client
->dev
, "Unable to read partnumber\n");
696 partnumber
= (buf
[0] << 8) | buf
[1];
697 majrev
= buf
[2] >> 3;
698 minrev
= buf
[2] & 0x7;
699 lot
= ((buf
[4] & 0x80) << 2) | ((buf
[6] & 0x80) << 1) | buf
[3];
700 uid
= ((buf
[4] & 0x7f) << 8) | buf
[5];
701 wafer
= (buf
[6] & 0x7c) >> 2;
702 dev_info(&client
->dev
, "model %04x, revision %u.%u, lot %x, wafer %x, uid %x\n",
703 partnumber
, majrev
, minrev
, lot
, wafer
, uid
);
705 data
= i2c_smbus_read_byte_data(client
, ABX8XX_REG_CTRL1
);
707 dev_err(&client
->dev
, "Unable to read control register\n");
711 err
= i2c_smbus_write_byte_data(client
, ABX8XX_REG_CTRL1
,
712 ((data
& ~(ABX8XX_CTRL_12_24
|
716 dev_err(&client
->dev
, "Unable to write control register\n");
720 /* Configure RV1805 specifics */
721 if (part
== RV1805
) {
723 * Avoid accidentally entering test mode. This can happen
724 * on the RV1805 in case the reserved bit 5 in control2
725 * register is set. RV-1805-C3 datasheet indicates that
726 * the bit should be cleared in section 11h - Control2.
728 data
= i2c_smbus_read_byte_data(client
, ABX8XX_REG_CTRL2
);
730 dev_err(&client
->dev
,
731 "Unable to read control2 register\n");
735 err
= i2c_smbus_write_byte_data(client
, ABX8XX_REG_CTRL2
,
736 data
& ~ABX8XX_CTRL2_RSVD
);
738 dev_err(&client
->dev
,
739 "Unable to write control2 register\n");
744 * Avoid extra power leakage. The RV1805 uses smaller
745 * 10pin package and the EXTI input is not present.
746 * Disable it to avoid leakage.
748 data
= i2c_smbus_read_byte_data(client
, ABX8XX_REG_OUT_CTRL
);
750 dev_err(&client
->dev
,
751 "Unable to read output control register\n");
756 * Write the configuration key register to enable access to
757 * the config2 register
759 err
= i2c_smbus_write_byte_data(client
, ABX8XX_REG_CFG_KEY
,
760 ABX8XX_CFG_KEY_MISC
);
762 dev_err(&client
->dev
,
763 "Unable to write configuration key\n");
767 err
= i2c_smbus_write_byte_data(client
, ABX8XX_REG_OUT_CTRL
,
768 data
| ABX8XX_OUT_CTRL_EXDS
);
770 dev_err(&client
->dev
,
771 "Unable to write output control register\n");
776 /* part autodetection */
777 if (part
== ABX80X
) {
778 for (i
= 0; abx80x_caps
[i
].pn
; i
++)
779 if (partnumber
== abx80x_caps
[i
].pn
)
781 if (abx80x_caps
[i
].pn
== 0) {
782 dev_err(&client
->dev
, "Unknown part: %04x\n",
789 if (partnumber
!= abx80x_caps
[part
].pn
) {
790 dev_err(&client
->dev
, "partnumber mismatch %04x != %04x\n",
791 partnumber
, abx80x_caps
[part
].pn
);
795 if (np
&& abx80x_caps
[part
].has_tc
)
796 trickle_cfg
= abx80x_dt_trickle_cfg(np
);
798 if (trickle_cfg
> 0) {
799 dev_info(&client
->dev
, "Enabling trickle charger: %02x\n",
801 abx80x_enable_trickle_charger(client
, trickle_cfg
);
804 err
= i2c_smbus_write_byte_data(client
, ABX8XX_REG_CD_TIMER_CTL
,
809 priv
= devm_kzalloc(&client
->dev
, sizeof(*priv
), GFP_KERNEL
);
813 priv
->rtc
= devm_rtc_allocate_device(&client
->dev
);
814 if (IS_ERR(priv
->rtc
))
815 return PTR_ERR(priv
->rtc
);
817 priv
->rtc
->ops
= &abx80x_rtc_ops
;
818 priv
->client
= client
;
820 i2c_set_clientdata(client
, priv
);
822 if (abx80x_caps
[part
].has_wdog
) {
823 err
= abx80x_setup_watchdog(priv
);
828 if (client
->irq
> 0) {
829 dev_info(&client
->dev
, "IRQ %d supplied\n", client
->irq
);
830 err
= devm_request_threaded_irq(&client
->dev
, client
->irq
, NULL
,
832 IRQF_SHARED
| IRQF_ONESHOT
,
836 dev_err(&client
->dev
, "unable to request IRQ, alarms disabled\n");
841 err
= rtc_add_group(priv
->rtc
, &rtc_calib_attr_group
);
843 dev_err(&client
->dev
, "Failed to create sysfs group: %d\n",
848 return rtc_register_device(priv
->rtc
);
851 static const struct i2c_device_id abx80x_id
[] = {
852 { "abx80x", ABX80X
},
853 { "ab0801", AB0801
},
854 { "ab0803", AB0803
},
855 { "ab0804", AB0804
},
856 { "ab0805", AB0805
},
857 { "ab1801", AB1801
},
858 { "ab1803", AB1803
},
859 { "ab1804", AB1804
},
860 { "ab1805", AB1805
},
861 { "rv1805", RV1805
},
864 MODULE_DEVICE_TABLE(i2c
, abx80x_id
);
866 static struct i2c_driver abx80x_driver
= {
868 .name
= "rtc-abx80x",
870 .probe
= abx80x_probe
,
871 .id_table
= abx80x_id
,
874 module_i2c_driver(abx80x_driver
);
876 MODULE_AUTHOR("Philippe De Muyter <phdm@macqel.be>");
877 MODULE_AUTHOR("Alexandre Belloni <alexandre.belloni@bootlin.com>");
878 MODULE_DESCRIPTION("Abracon ABX80X RTC driver");
879 MODULE_LICENSE("GPL v2");