2 * I2C client/driver for the ST M41T80 family of i2c rtc chips.
4 * Author: Alexander Bigga <ab@mycable.de>
6 * Based on m41t00.c by Mark A. Greer <mgreer@mvista.com>
8 * 2006 (c) mycable GmbH
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
16 #include <linux/module.h>
17 #include <linux/init.h>
18 #include <linux/kernel.h>
19 #include <linux/slab.h>
20 #include <linux/string.h>
21 #include <linux/i2c.h>
22 #include <linux/rtc.h>
23 #include <linux/bcd.h>
24 #ifdef CONFIG_RTC_DRV_M41T80_WDT
25 #include <linux/miscdevice.h>
26 #include <linux/watchdog.h>
27 #include <linux/reboot.h>
29 #include <linux/ioctl.h>
32 #define M41T80_REG_SSEC 0
33 #define M41T80_REG_SEC 1
34 #define M41T80_REG_MIN 2
35 #define M41T80_REG_HOUR 3
36 #define M41T80_REG_WDAY 4
37 #define M41T80_REG_DAY 5
38 #define M41T80_REG_MON 6
39 #define M41T80_REG_YEAR 7
40 #define M41T80_REG_ALARM_MON 0xa
41 #define M41T80_REG_ALARM_DAY 0xb
42 #define M41T80_REG_ALARM_HOUR 0xc
43 #define M41T80_REG_ALARM_MIN 0xd
44 #define M41T80_REG_ALARM_SEC 0xe
45 #define M41T80_REG_FLAGS 0xf
46 #define M41T80_REG_SQW 0x13
48 #define M41T80_DATETIME_REG_SIZE (M41T80_REG_YEAR + 1)
49 #define M41T80_ALARM_REG_SIZE \
50 (M41T80_REG_ALARM_SEC + 1 - M41T80_REG_ALARM_MON)
52 #define M41T80_SEC_ST (1 << 7) /* ST: Stop Bit */
53 #define M41T80_ALMON_AFE (1 << 7) /* AFE: AF Enable Bit */
54 #define M41T80_ALMON_SQWE (1 << 6) /* SQWE: SQW Enable Bit */
55 #define M41T80_ALHOUR_HT (1 << 6) /* HT: Halt Update Bit */
56 #define M41T80_FLAGS_AF (1 << 6) /* AF: Alarm Flag Bit */
57 #define M41T80_FLAGS_BATT_LOW (1 << 4) /* BL: Battery Low Bit */
59 #define M41T80_FEATURE_HT (1 << 0)
60 #define M41T80_FEATURE_BL (1 << 1)
62 #define DRV_VERSION "0.05"
64 static const struct i2c_device_id m41t80_id
[] = {
66 { "m41t81", M41T80_FEATURE_HT
},
67 { "m41t81s", M41T80_FEATURE_HT
| M41T80_FEATURE_BL
},
68 { "m41t82", M41T80_FEATURE_HT
| M41T80_FEATURE_BL
},
69 { "m41t83", M41T80_FEATURE_HT
| M41T80_FEATURE_BL
},
70 { "m41st84", M41T80_FEATURE_HT
| M41T80_FEATURE_BL
},
71 { "m41st85", M41T80_FEATURE_HT
| M41T80_FEATURE_BL
},
72 { "m41st87", M41T80_FEATURE_HT
| M41T80_FEATURE_BL
},
75 MODULE_DEVICE_TABLE(i2c
, m41t80_id
);
79 struct rtc_device
*rtc
;
82 static int m41t80_get_datetime(struct i2c_client
*client
,
85 u8 buf
[M41T80_DATETIME_REG_SIZE
], dt_addr
[1] = { M41T80_REG_SEC
};
86 struct i2c_msg msgs
[] = {
96 .len
= M41T80_DATETIME_REG_SIZE
- M41T80_REG_SEC
,
97 .buf
= buf
+ M41T80_REG_SEC
,
101 if (i2c_transfer(client
->adapter
, msgs
, 2) < 0) {
102 dev_err(&client
->dev
, "read error\n");
106 tm
->tm_sec
= BCD2BIN(buf
[M41T80_REG_SEC
] & 0x7f);
107 tm
->tm_min
= BCD2BIN(buf
[M41T80_REG_MIN
] & 0x7f);
108 tm
->tm_hour
= BCD2BIN(buf
[M41T80_REG_HOUR
] & 0x3f);
109 tm
->tm_mday
= BCD2BIN(buf
[M41T80_REG_DAY
] & 0x3f);
110 tm
->tm_wday
= buf
[M41T80_REG_WDAY
] & 0x07;
111 tm
->tm_mon
= BCD2BIN(buf
[M41T80_REG_MON
] & 0x1f) - 1;
113 /* assume 20YY not 19YY, and ignore the Century Bit */
114 tm
->tm_year
= BCD2BIN(buf
[M41T80_REG_YEAR
]) + 100;
118 /* Sets the given date and time to the real time clock. */
119 static int m41t80_set_datetime(struct i2c_client
*client
, struct rtc_time
*tm
)
121 u8 wbuf
[1 + M41T80_DATETIME_REG_SIZE
];
123 u8 dt_addr
[1] = { M41T80_REG_SEC
};
124 struct i2c_msg msgs_in
[] = {
126 .addr
= client
->addr
,
132 .addr
= client
->addr
,
134 .len
= M41T80_DATETIME_REG_SIZE
- M41T80_REG_SEC
,
135 .buf
= buf
+ M41T80_REG_SEC
,
138 struct i2c_msg msgs
[] = {
140 .addr
= client
->addr
,
142 .len
= 1 + M41T80_DATETIME_REG_SIZE
,
147 /* Read current reg values into buf[1..7] */
148 if (i2c_transfer(client
->adapter
, msgs_in
, 2) < 0) {
149 dev_err(&client
->dev
, "read error\n");
153 wbuf
[0] = 0; /* offset into rtc's regs */
154 /* Merge time-data and register flags into buf[0..7] */
155 buf
[M41T80_REG_SSEC
] = 0;
156 buf
[M41T80_REG_SEC
] =
157 BIN2BCD(tm
->tm_sec
) | (buf
[M41T80_REG_SEC
] & ~0x7f);
158 buf
[M41T80_REG_MIN
] =
159 BIN2BCD(tm
->tm_min
) | (buf
[M41T80_REG_MIN
] & ~0x7f);
160 buf
[M41T80_REG_HOUR
] =
161 BIN2BCD(tm
->tm_hour
) | (buf
[M41T80_REG_HOUR
] & ~0x3f) ;
162 buf
[M41T80_REG_WDAY
] =
163 (tm
->tm_wday
& 0x07) | (buf
[M41T80_REG_WDAY
] & ~0x07);
164 buf
[M41T80_REG_DAY
] =
165 BIN2BCD(tm
->tm_mday
) | (buf
[M41T80_REG_DAY
] & ~0x3f);
166 buf
[M41T80_REG_MON
] =
167 BIN2BCD(tm
->tm_mon
+ 1) | (buf
[M41T80_REG_MON
] & ~0x1f);
168 /* assume 20YY not 19YY */
169 buf
[M41T80_REG_YEAR
] = BIN2BCD(tm
->tm_year
% 100);
171 if (i2c_transfer(client
->adapter
, msgs
, 1) != 1) {
172 dev_err(&client
->dev
, "write error\n");
178 #if defined(CONFIG_RTC_INTF_PROC) || defined(CONFIG_RTC_INTF_PROC_MODULE)
179 static int m41t80_rtc_proc(struct device
*dev
, struct seq_file
*seq
)
181 struct i2c_client
*client
= to_i2c_client(dev
);
182 struct m41t80_data
*clientdata
= i2c_get_clientdata(client
);
185 if (clientdata
->features
& M41T80_FEATURE_BL
) {
186 reg
= i2c_smbus_read_byte_data(client
, M41T80_REG_FLAGS
);
187 seq_printf(seq
, "battery\t\t: %s\n",
188 (reg
& M41T80_FLAGS_BATT_LOW
) ? "exhausted" : "ok");
193 #define m41t80_rtc_proc NULL
196 static int m41t80_rtc_read_time(struct device
*dev
, struct rtc_time
*tm
)
198 return m41t80_get_datetime(to_i2c_client(dev
), tm
);
201 static int m41t80_rtc_set_time(struct device
*dev
, struct rtc_time
*tm
)
203 return m41t80_set_datetime(to_i2c_client(dev
), tm
);
206 #if defined(CONFIG_RTC_INTF_DEV) || defined(CONFIG_RTC_INTF_DEV_MODULE)
208 m41t80_rtc_ioctl(struct device
*dev
, unsigned int cmd
, unsigned long arg
)
210 struct i2c_client
*client
= to_i2c_client(dev
);
221 rc
= i2c_smbus_read_byte_data(client
, M41T80_REG_ALARM_MON
);
226 rc
&= ~M41T80_ALMON_AFE
;
229 rc
|= M41T80_ALMON_AFE
;
232 if (i2c_smbus_write_byte_data(client
, M41T80_REG_ALARM_MON
, rc
) < 0)
239 #define m41t80_rtc_ioctl NULL
242 static int m41t80_rtc_set_alarm(struct device
*dev
, struct rtc_wkalrm
*t
)
244 struct i2c_client
*client
= to_i2c_client(dev
);
245 u8 wbuf
[1 + M41T80_ALARM_REG_SIZE
];
247 u8
*reg
= buf
- M41T80_REG_ALARM_MON
;
248 u8 dt_addr
[1] = { M41T80_REG_ALARM_MON
};
249 struct i2c_msg msgs_in
[] = {
251 .addr
= client
->addr
,
257 .addr
= client
->addr
,
259 .len
= M41T80_ALARM_REG_SIZE
,
263 struct i2c_msg msgs
[] = {
265 .addr
= client
->addr
,
267 .len
= 1 + M41T80_ALARM_REG_SIZE
,
272 if (i2c_transfer(client
->adapter
, msgs_in
, 2) < 0) {
273 dev_err(&client
->dev
, "read error\n");
276 reg
[M41T80_REG_ALARM_MON
] &= ~(0x1f | M41T80_ALMON_AFE
);
277 reg
[M41T80_REG_ALARM_DAY
] = 0;
278 reg
[M41T80_REG_ALARM_HOUR
] &= ~(0x3f | 0x80);
279 reg
[M41T80_REG_ALARM_MIN
] = 0;
280 reg
[M41T80_REG_ALARM_SEC
] = 0;
282 wbuf
[0] = M41T80_REG_ALARM_MON
; /* offset into rtc's regs */
283 reg
[M41T80_REG_ALARM_SEC
] |= t
->time
.tm_sec
>= 0 ?
284 BIN2BCD(t
->time
.tm_sec
) : 0x80;
285 reg
[M41T80_REG_ALARM_MIN
] |= t
->time
.tm_min
>= 0 ?
286 BIN2BCD(t
->time
.tm_min
) : 0x80;
287 reg
[M41T80_REG_ALARM_HOUR
] |= t
->time
.tm_hour
>= 0 ?
288 BIN2BCD(t
->time
.tm_hour
) : 0x80;
289 reg
[M41T80_REG_ALARM_DAY
] |= t
->time
.tm_mday
>= 0 ?
290 BIN2BCD(t
->time
.tm_mday
) : 0x80;
291 if (t
->time
.tm_mon
>= 0)
292 reg
[M41T80_REG_ALARM_MON
] |= BIN2BCD(t
->time
.tm_mon
+ 1);
294 reg
[M41T80_REG_ALARM_DAY
] |= 0x40;
296 if (i2c_transfer(client
->adapter
, msgs
, 1) != 1) {
297 dev_err(&client
->dev
, "write error\n");
302 reg
[M41T80_REG_ALARM_MON
] |= M41T80_ALMON_AFE
;
303 if (i2c_smbus_write_byte_data(client
, M41T80_REG_ALARM_MON
,
304 reg
[M41T80_REG_ALARM_MON
]) < 0) {
305 dev_err(&client
->dev
, "write error\n");
312 static int m41t80_rtc_read_alarm(struct device
*dev
, struct rtc_wkalrm
*t
)
314 struct i2c_client
*client
= to_i2c_client(dev
);
315 u8 buf
[M41T80_ALARM_REG_SIZE
+ 1]; /* all alarm regs and flags */
316 u8 dt_addr
[1] = { M41T80_REG_ALARM_MON
};
317 u8
*reg
= buf
- M41T80_REG_ALARM_MON
;
318 struct i2c_msg msgs
[] = {
320 .addr
= client
->addr
,
326 .addr
= client
->addr
,
328 .len
= M41T80_ALARM_REG_SIZE
+ 1,
333 if (i2c_transfer(client
->adapter
, msgs
, 2) < 0) {
334 dev_err(&client
->dev
, "read error\n");
339 t
->time
.tm_hour
= -1;
340 t
->time
.tm_mday
= -1;
342 if (!(reg
[M41T80_REG_ALARM_SEC
] & 0x80))
343 t
->time
.tm_sec
= BCD2BIN(reg
[M41T80_REG_ALARM_SEC
] & 0x7f);
344 if (!(reg
[M41T80_REG_ALARM_MIN
] & 0x80))
345 t
->time
.tm_min
= BCD2BIN(reg
[M41T80_REG_ALARM_MIN
] & 0x7f);
346 if (!(reg
[M41T80_REG_ALARM_HOUR
] & 0x80))
347 t
->time
.tm_hour
= BCD2BIN(reg
[M41T80_REG_ALARM_HOUR
] & 0x3f);
348 if (!(reg
[M41T80_REG_ALARM_DAY
] & 0x80))
349 t
->time
.tm_mday
= BCD2BIN(reg
[M41T80_REG_ALARM_DAY
] & 0x3f);
350 if (!(reg
[M41T80_REG_ALARM_DAY
] & 0x40))
351 t
->time
.tm_mon
= BCD2BIN(reg
[M41T80_REG_ALARM_MON
] & 0x1f) - 1;
352 t
->time
.tm_year
= -1;
353 t
->time
.tm_wday
= -1;
354 t
->time
.tm_yday
= -1;
355 t
->time
.tm_isdst
= -1;
356 t
->enabled
= !!(reg
[M41T80_REG_ALARM_MON
] & M41T80_ALMON_AFE
);
357 t
->pending
= !!(reg
[M41T80_REG_FLAGS
] & M41T80_FLAGS_AF
);
361 static struct rtc_class_ops m41t80_rtc_ops
= {
362 .read_time
= m41t80_rtc_read_time
,
363 .set_time
= m41t80_rtc_set_time
,
364 .read_alarm
= m41t80_rtc_read_alarm
,
365 .set_alarm
= m41t80_rtc_set_alarm
,
366 .proc
= m41t80_rtc_proc
,
367 .ioctl
= m41t80_rtc_ioctl
,
370 #if defined(CONFIG_RTC_INTF_SYSFS) || defined(CONFIG_RTC_INTF_SYSFS_MODULE)
371 static ssize_t
m41t80_sysfs_show_flags(struct device
*dev
,
372 struct device_attribute
*attr
, char *buf
)
374 struct i2c_client
*client
= to_i2c_client(dev
);
377 val
= i2c_smbus_read_byte_data(client
, M41T80_REG_FLAGS
);
380 return sprintf(buf
, "%#x\n", val
);
382 static DEVICE_ATTR(flags
, S_IRUGO
, m41t80_sysfs_show_flags
, NULL
);
384 static ssize_t
m41t80_sysfs_show_sqwfreq(struct device
*dev
,
385 struct device_attribute
*attr
, char *buf
)
387 struct i2c_client
*client
= to_i2c_client(dev
);
390 val
= i2c_smbus_read_byte_data(client
, M41T80_REG_SQW
);
393 val
= (val
>> 4) & 0xf;
403 return sprintf(buf
, "%d\n", val
);
405 static ssize_t
m41t80_sysfs_set_sqwfreq(struct device
*dev
,
406 struct device_attribute
*attr
,
407 const char *buf
, size_t count
)
409 struct i2c_client
*client
= to_i2c_client(dev
);
411 int val
= simple_strtoul(buf
, NULL
, 0);
414 if (!is_power_of_2(val
))
424 /* disable SQW, set SQW frequency & re-enable */
425 almon
= i2c_smbus_read_byte_data(client
, M41T80_REG_ALARM_MON
);
428 sqw
= i2c_smbus_read_byte_data(client
, M41T80_REG_SQW
);
431 sqw
= (sqw
& 0x0f) | (val
<< 4);
432 if (i2c_smbus_write_byte_data(client
, M41T80_REG_ALARM_MON
,
433 almon
& ~M41T80_ALMON_SQWE
) < 0 ||
434 i2c_smbus_write_byte_data(client
, M41T80_REG_SQW
, sqw
) < 0)
436 if (val
&& i2c_smbus_write_byte_data(client
, M41T80_REG_ALARM_MON
,
437 almon
| M41T80_ALMON_SQWE
) < 0)
441 static DEVICE_ATTR(sqwfreq
, S_IRUGO
| S_IWUSR
,
442 m41t80_sysfs_show_sqwfreq
, m41t80_sysfs_set_sqwfreq
);
444 static struct attribute
*attrs
[] = {
445 &dev_attr_flags
.attr
,
446 &dev_attr_sqwfreq
.attr
,
449 static struct attribute_group attr_group
= {
453 static int m41t80_sysfs_register(struct device
*dev
)
455 return sysfs_create_group(&dev
->kobj
, &attr_group
);
458 static int m41t80_sysfs_register(struct device
*dev
)
464 #ifdef CONFIG_RTC_DRV_M41T80_WDT
466 *****************************************************************************
470 *****************************************************************************
472 static struct i2c_client
*save_client
;
475 #define WD_TIMO 60 /* 1..31 seconds */
477 static int wdt_margin
= WD_TIMO
;
478 module_param(wdt_margin
, int, 0);
479 MODULE_PARM_DESC(wdt_margin
, "Watchdog timeout in seconds (default 60s)");
481 static unsigned long wdt_is_open
;
482 static int boot_flag
;
487 * Reload counter one with the watchdog timeout. We don't bother reloading
488 * the cascade counter.
490 static void wdt_ping(void)
492 unsigned char i2c_data
[2];
493 struct i2c_msg msgs1
[1] = {
495 .addr
= save_client
->addr
,
501 i2c_data
[0] = 0x09; /* watchdog register */
504 i2c_data
[1] = (wdt_margin
& 0xFC) | 0x83; /* resolution = 4s */
507 * WDS = 1 (0x80), mulitplier = WD_TIMO, resolution = 1s (0x02)
509 i2c_data
[1] = wdt_margin
<<2 | 0x82;
511 i2c_transfer(save_client
->adapter
, msgs1
, 1);
519 static void wdt_disable(void)
521 unsigned char i2c_data
[2], i2c_buf
[0x10];
522 struct i2c_msg msgs0
[2] = {
524 .addr
= save_client
->addr
,
530 .addr
= save_client
->addr
,
536 struct i2c_msg msgs1
[1] = {
538 .addr
= save_client
->addr
,
546 i2c_transfer(save_client
->adapter
, msgs0
, 2);
550 i2c_transfer(save_client
->adapter
, msgs1
, 1);
555 * @file: file handle to the watchdog
556 * @buf: buffer to write (unused as data does not matter here
557 * @count: count of bytes
558 * @ppos: pointer to the position to write. No seeks allowed
560 * A write to a watchdog device is defined as a keepalive signal. Any
561 * write of data will do, as we we don't define content meaning.
563 static ssize_t
wdt_write(struct file
*file
, const char __user
*buf
,
564 size_t count
, loff_t
*ppos
)
566 /* Can't seek (pwrite) on this device
567 if (ppos != &file->f_pos)
577 static ssize_t
wdt_read(struct file
*file
, char __user
*buf
,
578 size_t count
, loff_t
*ppos
)
585 * @inode: inode of the device
586 * @file: file handle to the device
587 * @cmd: watchdog command
588 * @arg: argument pointer
590 * The watchdog API defines a common set of functions for all watchdogs
591 * according to their available features. We only actually usefully support
592 * querying capabilities and current status.
594 static int wdt_ioctl(struct inode
*inode
, struct file
*file
, unsigned int cmd
,
598 static struct watchdog_info ident
= {
599 .options
= WDIOF_POWERUNDER
| WDIOF_KEEPALIVEPING
|
601 .firmware_version
= 1,
602 .identity
= "M41T80 WTD"
606 case WDIOC_GETSUPPORT
:
607 return copy_to_user((struct watchdog_info __user
*)arg
, &ident
,
608 sizeof(ident
)) ? -EFAULT
: 0;
610 case WDIOC_GETSTATUS
:
611 case WDIOC_GETBOOTSTATUS
:
612 return put_user(boot_flag
, (int __user
*)arg
);
613 case WDIOC_KEEPALIVE
:
616 case WDIOC_SETTIMEOUT
:
617 if (get_user(new_margin
, (int __user
*)arg
))
619 /* Arbitrary, can't find the card's limits */
620 if (new_margin
< 1 || new_margin
> 124)
622 wdt_margin
= new_margin
;
625 case WDIOC_GETTIMEOUT
:
626 return put_user(wdt_margin
, (int __user
*)arg
);
628 case WDIOC_SETOPTIONS
:
629 if (copy_from_user(&rv
, (int __user
*)arg
, sizeof(int)))
632 if (rv
& WDIOS_DISABLECARD
) {
634 "rtc-m41t80: disable watchdog\n");
638 if (rv
& WDIOS_ENABLECARD
) {
640 "rtc-m41t80: enable watchdog\n");
651 * @inode: inode of device
652 * @file: file handle to device
655 static int wdt_open(struct inode
*inode
, struct file
*file
)
657 if (MINOR(inode
->i_rdev
) == WATCHDOG_MINOR
) {
658 if (test_and_set_bit(0, &wdt_is_open
))
671 * @inode: inode to board
672 * @file: file handle to board
675 static int wdt_release(struct inode
*inode
, struct file
*file
)
677 if (MINOR(inode
->i_rdev
) == WATCHDOG_MINOR
)
678 clear_bit(0, &wdt_is_open
);
684 * @this: our notifier block
685 * @code: the event being reported
688 * Our notifier is called on system shutdowns. We want to turn the card
689 * off at reboot otherwise the machine will reboot again during memory
690 * test or worse yet during the following fsck. This would suck, in fact
691 * trust me - if it happens it does suck.
693 static int wdt_notify_sys(struct notifier_block
*this, unsigned long code
,
696 if (code
== SYS_DOWN
|| code
== SYS_HALT
)
697 /* Disable Watchdog */
702 static const struct file_operations wdt_fops
= {
703 .owner
= THIS_MODULE
,
708 .release
= wdt_release
,
711 static struct miscdevice wdt_dev
= {
712 .minor
= WATCHDOG_MINOR
,
718 * The WDT card needs to learn about soft shutdowns in order to
719 * turn the timebomb registers off.
721 static struct notifier_block wdt_notifier
= {
722 .notifier_call
= wdt_notify_sys
,
724 #endif /* CONFIG_RTC_DRV_M41T80_WDT */
727 *****************************************************************************
731 *****************************************************************************
733 static int m41t80_probe(struct i2c_client
*client
,
734 const struct i2c_device_id
*id
)
737 struct rtc_device
*rtc
= NULL
;
739 struct m41t80_data
*clientdata
= NULL
;
741 if (!i2c_check_functionality(client
->adapter
, I2C_FUNC_I2C
742 | I2C_FUNC_SMBUS_BYTE_DATA
)) {
747 dev_info(&client
->dev
,
748 "chip found, driver version " DRV_VERSION
"\n");
750 clientdata
= kzalloc(sizeof(*clientdata
), GFP_KERNEL
);
756 rtc
= rtc_device_register(client
->name
, &client
->dev
,
757 &m41t80_rtc_ops
, THIS_MODULE
);
764 clientdata
->rtc
= rtc
;
765 clientdata
->features
= id
->driver_data
;
766 i2c_set_clientdata(client
, clientdata
);
768 /* Make sure HT (Halt Update) bit is cleared */
769 rc
= i2c_smbus_read_byte_data(client
, M41T80_REG_ALARM_HOUR
);
773 if (rc
& M41T80_ALHOUR_HT
) {
774 if (clientdata
->features
& M41T80_FEATURE_HT
) {
775 m41t80_get_datetime(client
, &tm
);
776 dev_info(&client
->dev
, "HT bit was set!\n");
777 dev_info(&client
->dev
,
779 "%04i-%02i-%02i %02i:%02i:%02i\n",
781 tm
.tm_mon
+ 1, tm
.tm_mday
, tm
.tm_hour
,
782 tm
.tm_min
, tm
.tm_sec
);
784 if (i2c_smbus_write_byte_data(client
,
785 M41T80_REG_ALARM_HOUR
,
786 rc
& ~M41T80_ALHOUR_HT
) < 0)
790 /* Make sure ST (stop) bit is cleared */
791 rc
= i2c_smbus_read_byte_data(client
, M41T80_REG_SEC
);
795 if (rc
& M41T80_SEC_ST
) {
796 if (i2c_smbus_write_byte_data(client
, M41T80_REG_SEC
,
797 rc
& ~M41T80_SEC_ST
) < 0)
801 rc
= m41t80_sysfs_register(&client
->dev
);
805 #ifdef CONFIG_RTC_DRV_M41T80_WDT
806 if (clientdata
->features
& M41T80_FEATURE_HT
) {
807 save_client
= client
;
808 rc
= misc_register(&wdt_dev
);
811 rc
= register_reboot_notifier(&wdt_notifier
);
813 misc_deregister(&wdt_dev
);
822 dev_err(&client
->dev
, "Can't clear ST bit\n");
826 dev_err(&client
->dev
, "Can't clear HT bit\n");
831 rtc_device_unregister(rtc
);
836 static int m41t80_remove(struct i2c_client
*client
)
838 struct m41t80_data
*clientdata
= i2c_get_clientdata(client
);
839 struct rtc_device
*rtc
= clientdata
->rtc
;
841 #ifdef CONFIG_RTC_DRV_M41T80_WDT
842 if (clientdata
->features
& M41T80_FEATURE_HT
) {
843 misc_deregister(&wdt_dev
);
844 unregister_reboot_notifier(&wdt_notifier
);
848 rtc_device_unregister(rtc
);
854 static struct i2c_driver m41t80_driver
= {
856 .name
= "rtc-m41t80",
858 .probe
= m41t80_probe
,
859 .remove
= m41t80_remove
,
860 .id_table
= m41t80_id
,
863 static int __init
m41t80_rtc_init(void)
865 return i2c_add_driver(&m41t80_driver
);
868 static void __exit
m41t80_rtc_exit(void)
870 i2c_del_driver(&m41t80_driver
);
873 MODULE_AUTHOR("Alexander Bigga <ab@mycable.de>");
874 MODULE_DESCRIPTION("ST Microelectronics M41T80 series RTC I2C Client Driver");
875 MODULE_LICENSE("GPL");
876 MODULE_VERSION(DRV_VERSION
);
878 module_init(m41t80_rtc_init
);
879 module_exit(m41t80_rtc_exit
);