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/bcd.h>
17 #include <linux/i2c.h>
18 #include <linux/init.h>
19 #include <linux/kernel.h>
20 #include <linux/module.h>
21 #include <linux/rtc.h>
22 #include <linux/slab.h>
23 #include <linux/smp_lock.h>
24 #include <linux/string.h>
25 #ifdef CONFIG_RTC_DRV_M41T80_WDT
27 #include <linux/ioctl.h>
28 #include <linux/miscdevice.h>
29 #include <linux/reboot.h>
30 #include <linux/watchdog.h>
33 #define M41T80_REG_SSEC 0
34 #define M41T80_REG_SEC 1
35 #define M41T80_REG_MIN 2
36 #define M41T80_REG_HOUR 3
37 #define M41T80_REG_WDAY 4
38 #define M41T80_REG_DAY 5
39 #define M41T80_REG_MON 6
40 #define M41T80_REG_YEAR 7
41 #define M41T80_REG_ALARM_MON 0xa
42 #define M41T80_REG_ALARM_DAY 0xb
43 #define M41T80_REG_ALARM_HOUR 0xc
44 #define M41T80_REG_ALARM_MIN 0xd
45 #define M41T80_REG_ALARM_SEC 0xe
46 #define M41T80_REG_FLAGS 0xf
47 #define M41T80_REG_SQW 0x13
49 #define M41T80_DATETIME_REG_SIZE (M41T80_REG_YEAR + 1)
50 #define M41T80_ALARM_REG_SIZE \
51 (M41T80_REG_ALARM_SEC + 1 - M41T80_REG_ALARM_MON)
53 #define M41T80_SEC_ST (1 << 7) /* ST: Stop Bit */
54 #define M41T80_ALMON_AFE (1 << 7) /* AFE: AF Enable Bit */
55 #define M41T80_ALMON_SQWE (1 << 6) /* SQWE: SQW Enable Bit */
56 #define M41T80_ALHOUR_HT (1 << 6) /* HT: Halt Update Bit */
57 #define M41T80_FLAGS_AF (1 << 6) /* AF: Alarm Flag Bit */
58 #define M41T80_FLAGS_BATT_LOW (1 << 4) /* BL: Battery Low Bit */
60 #define M41T80_FEATURE_HT (1 << 0)
61 #define M41T80_FEATURE_BL (1 << 1)
63 #define DRV_VERSION "0.05"
65 static const struct i2c_device_id m41t80_id
[] = {
67 { "m41t81", M41T80_FEATURE_HT
},
68 { "m41t81s", M41T80_FEATURE_HT
| M41T80_FEATURE_BL
},
69 { "m41t82", M41T80_FEATURE_HT
| M41T80_FEATURE_BL
},
70 { "m41t83", M41T80_FEATURE_HT
| M41T80_FEATURE_BL
},
71 { "m41st84", M41T80_FEATURE_HT
| M41T80_FEATURE_BL
},
72 { "m41st85", M41T80_FEATURE_HT
| M41T80_FEATURE_BL
},
73 { "m41st87", M41T80_FEATURE_HT
| M41T80_FEATURE_BL
},
76 MODULE_DEVICE_TABLE(i2c
, m41t80_id
);
80 struct rtc_device
*rtc
;
83 static int m41t80_get_datetime(struct i2c_client
*client
,
86 u8 buf
[M41T80_DATETIME_REG_SIZE
], dt_addr
[1] = { M41T80_REG_SEC
};
87 struct i2c_msg msgs
[] = {
97 .len
= M41T80_DATETIME_REG_SIZE
- M41T80_REG_SEC
,
98 .buf
= buf
+ M41T80_REG_SEC
,
102 if (i2c_transfer(client
->adapter
, msgs
, 2) < 0) {
103 dev_err(&client
->dev
, "read error\n");
107 tm
->tm_sec
= BCD2BIN(buf
[M41T80_REG_SEC
] & 0x7f);
108 tm
->tm_min
= BCD2BIN(buf
[M41T80_REG_MIN
] & 0x7f);
109 tm
->tm_hour
= BCD2BIN(buf
[M41T80_REG_HOUR
] & 0x3f);
110 tm
->tm_mday
= BCD2BIN(buf
[M41T80_REG_DAY
] & 0x3f);
111 tm
->tm_wday
= buf
[M41T80_REG_WDAY
] & 0x07;
112 tm
->tm_mon
= BCD2BIN(buf
[M41T80_REG_MON
] & 0x1f) - 1;
114 /* assume 20YY not 19YY, and ignore the Century Bit */
115 tm
->tm_year
= BCD2BIN(buf
[M41T80_REG_YEAR
]) + 100;
119 /* Sets the given date and time to the real time clock. */
120 static int m41t80_set_datetime(struct i2c_client
*client
, struct rtc_time
*tm
)
122 u8 wbuf
[1 + M41T80_DATETIME_REG_SIZE
];
124 u8 dt_addr
[1] = { M41T80_REG_SEC
};
125 struct i2c_msg msgs_in
[] = {
127 .addr
= client
->addr
,
133 .addr
= client
->addr
,
135 .len
= M41T80_DATETIME_REG_SIZE
- M41T80_REG_SEC
,
136 .buf
= buf
+ M41T80_REG_SEC
,
139 struct i2c_msg msgs
[] = {
141 .addr
= client
->addr
,
143 .len
= 1 + M41T80_DATETIME_REG_SIZE
,
148 /* Read current reg values into buf[1..7] */
149 if (i2c_transfer(client
->adapter
, msgs_in
, 2) < 0) {
150 dev_err(&client
->dev
, "read error\n");
154 wbuf
[0] = 0; /* offset into rtc's regs */
155 /* Merge time-data and register flags into buf[0..7] */
156 buf
[M41T80_REG_SSEC
] = 0;
157 buf
[M41T80_REG_SEC
] =
158 BIN2BCD(tm
->tm_sec
) | (buf
[M41T80_REG_SEC
] & ~0x7f);
159 buf
[M41T80_REG_MIN
] =
160 BIN2BCD(tm
->tm_min
) | (buf
[M41T80_REG_MIN
] & ~0x7f);
161 buf
[M41T80_REG_HOUR
] =
162 BIN2BCD(tm
->tm_hour
) | (buf
[M41T80_REG_HOUR
] & ~0x3f) ;
163 buf
[M41T80_REG_WDAY
] =
164 (tm
->tm_wday
& 0x07) | (buf
[M41T80_REG_WDAY
] & ~0x07);
165 buf
[M41T80_REG_DAY
] =
166 BIN2BCD(tm
->tm_mday
) | (buf
[M41T80_REG_DAY
] & ~0x3f);
167 buf
[M41T80_REG_MON
] =
168 BIN2BCD(tm
->tm_mon
+ 1) | (buf
[M41T80_REG_MON
] & ~0x1f);
169 /* assume 20YY not 19YY */
170 buf
[M41T80_REG_YEAR
] = BIN2BCD(tm
->tm_year
% 100);
172 if (i2c_transfer(client
->adapter
, msgs
, 1) != 1) {
173 dev_err(&client
->dev
, "write error\n");
179 #if defined(CONFIG_RTC_INTF_PROC) || defined(CONFIG_RTC_INTF_PROC_MODULE)
180 static int m41t80_rtc_proc(struct device
*dev
, struct seq_file
*seq
)
182 struct i2c_client
*client
= to_i2c_client(dev
);
183 struct m41t80_data
*clientdata
= i2c_get_clientdata(client
);
186 if (clientdata
->features
& M41T80_FEATURE_BL
) {
187 reg
= i2c_smbus_read_byte_data(client
, M41T80_REG_FLAGS
);
188 seq_printf(seq
, "battery\t\t: %s\n",
189 (reg
& M41T80_FLAGS_BATT_LOW
) ? "exhausted" : "ok");
194 #define m41t80_rtc_proc NULL
197 static int m41t80_rtc_read_time(struct device
*dev
, struct rtc_time
*tm
)
199 return m41t80_get_datetime(to_i2c_client(dev
), tm
);
202 static int m41t80_rtc_set_time(struct device
*dev
, struct rtc_time
*tm
)
204 return m41t80_set_datetime(to_i2c_client(dev
), tm
);
207 #if defined(CONFIG_RTC_INTF_DEV) || defined(CONFIG_RTC_INTF_DEV_MODULE)
209 m41t80_rtc_ioctl(struct device
*dev
, unsigned int cmd
, unsigned long arg
)
211 struct i2c_client
*client
= to_i2c_client(dev
);
222 rc
= i2c_smbus_read_byte_data(client
, M41T80_REG_ALARM_MON
);
227 rc
&= ~M41T80_ALMON_AFE
;
230 rc
|= M41T80_ALMON_AFE
;
233 if (i2c_smbus_write_byte_data(client
, M41T80_REG_ALARM_MON
, rc
) < 0)
240 #define m41t80_rtc_ioctl NULL
243 static int m41t80_rtc_set_alarm(struct device
*dev
, struct rtc_wkalrm
*t
)
245 struct i2c_client
*client
= to_i2c_client(dev
);
246 u8 wbuf
[1 + M41T80_ALARM_REG_SIZE
];
248 u8
*reg
= buf
- M41T80_REG_ALARM_MON
;
249 u8 dt_addr
[1] = { M41T80_REG_ALARM_MON
};
250 struct i2c_msg msgs_in
[] = {
252 .addr
= client
->addr
,
258 .addr
= client
->addr
,
260 .len
= M41T80_ALARM_REG_SIZE
,
264 struct i2c_msg msgs
[] = {
266 .addr
= client
->addr
,
268 .len
= 1 + M41T80_ALARM_REG_SIZE
,
273 if (i2c_transfer(client
->adapter
, msgs_in
, 2) < 0) {
274 dev_err(&client
->dev
, "read error\n");
277 reg
[M41T80_REG_ALARM_MON
] &= ~(0x1f | M41T80_ALMON_AFE
);
278 reg
[M41T80_REG_ALARM_DAY
] = 0;
279 reg
[M41T80_REG_ALARM_HOUR
] &= ~(0x3f | 0x80);
280 reg
[M41T80_REG_ALARM_MIN
] = 0;
281 reg
[M41T80_REG_ALARM_SEC
] = 0;
283 wbuf
[0] = M41T80_REG_ALARM_MON
; /* offset into rtc's regs */
284 reg
[M41T80_REG_ALARM_SEC
] |= t
->time
.tm_sec
>= 0 ?
285 BIN2BCD(t
->time
.tm_sec
) : 0x80;
286 reg
[M41T80_REG_ALARM_MIN
] |= t
->time
.tm_min
>= 0 ?
287 BIN2BCD(t
->time
.tm_min
) : 0x80;
288 reg
[M41T80_REG_ALARM_HOUR
] |= t
->time
.tm_hour
>= 0 ?
289 BIN2BCD(t
->time
.tm_hour
) : 0x80;
290 reg
[M41T80_REG_ALARM_DAY
] |= t
->time
.tm_mday
>= 0 ?
291 BIN2BCD(t
->time
.tm_mday
) : 0x80;
292 if (t
->time
.tm_mon
>= 0)
293 reg
[M41T80_REG_ALARM_MON
] |= BIN2BCD(t
->time
.tm_mon
+ 1);
295 reg
[M41T80_REG_ALARM_DAY
] |= 0x40;
297 if (i2c_transfer(client
->adapter
, msgs
, 1) != 1) {
298 dev_err(&client
->dev
, "write error\n");
303 reg
[M41T80_REG_ALARM_MON
] |= M41T80_ALMON_AFE
;
304 if (i2c_smbus_write_byte_data(client
, M41T80_REG_ALARM_MON
,
305 reg
[M41T80_REG_ALARM_MON
]) < 0) {
306 dev_err(&client
->dev
, "write error\n");
313 static int m41t80_rtc_read_alarm(struct device
*dev
, struct rtc_wkalrm
*t
)
315 struct i2c_client
*client
= to_i2c_client(dev
);
316 u8 buf
[M41T80_ALARM_REG_SIZE
+ 1]; /* all alarm regs and flags */
317 u8 dt_addr
[1] = { M41T80_REG_ALARM_MON
};
318 u8
*reg
= buf
- M41T80_REG_ALARM_MON
;
319 struct i2c_msg msgs
[] = {
321 .addr
= client
->addr
,
327 .addr
= client
->addr
,
329 .len
= M41T80_ALARM_REG_SIZE
+ 1,
334 if (i2c_transfer(client
->adapter
, msgs
, 2) < 0) {
335 dev_err(&client
->dev
, "read error\n");
340 t
->time
.tm_hour
= -1;
341 t
->time
.tm_mday
= -1;
343 if (!(reg
[M41T80_REG_ALARM_SEC
] & 0x80))
344 t
->time
.tm_sec
= BCD2BIN(reg
[M41T80_REG_ALARM_SEC
] & 0x7f);
345 if (!(reg
[M41T80_REG_ALARM_MIN
] & 0x80))
346 t
->time
.tm_min
= BCD2BIN(reg
[M41T80_REG_ALARM_MIN
] & 0x7f);
347 if (!(reg
[M41T80_REG_ALARM_HOUR
] & 0x80))
348 t
->time
.tm_hour
= BCD2BIN(reg
[M41T80_REG_ALARM_HOUR
] & 0x3f);
349 if (!(reg
[M41T80_REG_ALARM_DAY
] & 0x80))
350 t
->time
.tm_mday
= BCD2BIN(reg
[M41T80_REG_ALARM_DAY
] & 0x3f);
351 if (!(reg
[M41T80_REG_ALARM_DAY
] & 0x40))
352 t
->time
.tm_mon
= BCD2BIN(reg
[M41T80_REG_ALARM_MON
] & 0x1f) - 1;
353 t
->time
.tm_year
= -1;
354 t
->time
.tm_wday
= -1;
355 t
->time
.tm_yday
= -1;
356 t
->time
.tm_isdst
= -1;
357 t
->enabled
= !!(reg
[M41T80_REG_ALARM_MON
] & M41T80_ALMON_AFE
);
358 t
->pending
= !!(reg
[M41T80_REG_FLAGS
] & M41T80_FLAGS_AF
);
362 static struct rtc_class_ops m41t80_rtc_ops
= {
363 .read_time
= m41t80_rtc_read_time
,
364 .set_time
= m41t80_rtc_set_time
,
365 .read_alarm
= m41t80_rtc_read_alarm
,
366 .set_alarm
= m41t80_rtc_set_alarm
,
367 .proc
= m41t80_rtc_proc
,
368 .ioctl
= m41t80_rtc_ioctl
,
371 #if defined(CONFIG_RTC_INTF_SYSFS) || defined(CONFIG_RTC_INTF_SYSFS_MODULE)
372 static ssize_t
m41t80_sysfs_show_flags(struct device
*dev
,
373 struct device_attribute
*attr
, char *buf
)
375 struct i2c_client
*client
= to_i2c_client(dev
);
378 val
= i2c_smbus_read_byte_data(client
, M41T80_REG_FLAGS
);
381 return sprintf(buf
, "%#x\n", val
);
383 static DEVICE_ATTR(flags
, S_IRUGO
, m41t80_sysfs_show_flags
, NULL
);
385 static ssize_t
m41t80_sysfs_show_sqwfreq(struct device
*dev
,
386 struct device_attribute
*attr
, char *buf
)
388 struct i2c_client
*client
= to_i2c_client(dev
);
391 val
= i2c_smbus_read_byte_data(client
, M41T80_REG_SQW
);
394 val
= (val
>> 4) & 0xf;
404 return sprintf(buf
, "%d\n", val
);
406 static ssize_t
m41t80_sysfs_set_sqwfreq(struct device
*dev
,
407 struct device_attribute
*attr
,
408 const char *buf
, size_t count
)
410 struct i2c_client
*client
= to_i2c_client(dev
);
412 int val
= simple_strtoul(buf
, NULL
, 0);
415 if (!is_power_of_2(val
))
425 /* disable SQW, set SQW frequency & re-enable */
426 almon
= i2c_smbus_read_byte_data(client
, M41T80_REG_ALARM_MON
);
429 sqw
= i2c_smbus_read_byte_data(client
, M41T80_REG_SQW
);
432 sqw
= (sqw
& 0x0f) | (val
<< 4);
433 if (i2c_smbus_write_byte_data(client
, M41T80_REG_ALARM_MON
,
434 almon
& ~M41T80_ALMON_SQWE
) < 0 ||
435 i2c_smbus_write_byte_data(client
, M41T80_REG_SQW
, sqw
) < 0)
437 if (val
&& i2c_smbus_write_byte_data(client
, M41T80_REG_ALARM_MON
,
438 almon
| M41T80_ALMON_SQWE
) < 0)
442 static DEVICE_ATTR(sqwfreq
, S_IRUGO
| S_IWUSR
,
443 m41t80_sysfs_show_sqwfreq
, m41t80_sysfs_set_sqwfreq
);
445 static struct attribute
*attrs
[] = {
446 &dev_attr_flags
.attr
,
447 &dev_attr_sqwfreq
.attr
,
450 static struct attribute_group attr_group
= {
454 static int m41t80_sysfs_register(struct device
*dev
)
456 return sysfs_create_group(&dev
->kobj
, &attr_group
);
459 static int m41t80_sysfs_register(struct device
*dev
)
465 #ifdef CONFIG_RTC_DRV_M41T80_WDT
467 *****************************************************************************
471 *****************************************************************************
473 static struct i2c_client
*save_client
;
476 #define WD_TIMO 60 /* 1..31 seconds */
478 static int wdt_margin
= WD_TIMO
;
479 module_param(wdt_margin
, int, 0);
480 MODULE_PARM_DESC(wdt_margin
, "Watchdog timeout in seconds (default 60s)");
482 static unsigned long wdt_is_open
;
483 static int boot_flag
;
488 * Reload counter one with the watchdog timeout. We don't bother reloading
489 * the cascade counter.
491 static void wdt_ping(void)
493 unsigned char i2c_data
[2];
494 struct i2c_msg msgs1
[1] = {
496 .addr
= save_client
->addr
,
502 i2c_data
[0] = 0x09; /* watchdog register */
505 i2c_data
[1] = (wdt_margin
& 0xFC) | 0x83; /* resolution = 4s */
508 * WDS = 1 (0x80), mulitplier = WD_TIMO, resolution = 1s (0x02)
510 i2c_data
[1] = wdt_margin
<<2 | 0x82;
512 i2c_transfer(save_client
->adapter
, msgs1
, 1);
520 static void wdt_disable(void)
522 unsigned char i2c_data
[2], i2c_buf
[0x10];
523 struct i2c_msg msgs0
[2] = {
525 .addr
= save_client
->addr
,
531 .addr
= save_client
->addr
,
537 struct i2c_msg msgs1
[1] = {
539 .addr
= save_client
->addr
,
547 i2c_transfer(save_client
->adapter
, msgs0
, 2);
551 i2c_transfer(save_client
->adapter
, msgs1
, 1);
556 * @file: file handle to the watchdog
557 * @buf: buffer to write (unused as data does not matter here
558 * @count: count of bytes
559 * @ppos: pointer to the position to write. No seeks allowed
561 * A write to a watchdog device is defined as a keepalive signal. Any
562 * write of data will do, as we we don't define content meaning.
564 static ssize_t
wdt_write(struct file
*file
, const char __user
*buf
,
565 size_t count
, loff_t
*ppos
)
567 /* Can't seek (pwrite) on this device
568 if (ppos != &file->f_pos)
578 static ssize_t
wdt_read(struct file
*file
, char __user
*buf
,
579 size_t count
, loff_t
*ppos
)
586 * @inode: inode of the device
587 * @file: file handle to the device
588 * @cmd: watchdog command
589 * @arg: argument pointer
591 * The watchdog API defines a common set of functions for all watchdogs
592 * according to their available features. We only actually usefully support
593 * querying capabilities and current status.
595 static int wdt_ioctl(struct inode
*inode
, struct file
*file
, unsigned int cmd
,
599 static struct watchdog_info ident
= {
600 .options
= WDIOF_POWERUNDER
| WDIOF_KEEPALIVEPING
|
602 .firmware_version
= 1,
603 .identity
= "M41T80 WTD"
607 case WDIOC_GETSUPPORT
:
608 return copy_to_user((struct watchdog_info __user
*)arg
, &ident
,
609 sizeof(ident
)) ? -EFAULT
: 0;
611 case WDIOC_GETSTATUS
:
612 case WDIOC_GETBOOTSTATUS
:
613 return put_user(boot_flag
, (int __user
*)arg
);
614 case WDIOC_KEEPALIVE
:
617 case WDIOC_SETTIMEOUT
:
618 if (get_user(new_margin
, (int __user
*)arg
))
620 /* Arbitrary, can't find the card's limits */
621 if (new_margin
< 1 || new_margin
> 124)
623 wdt_margin
= new_margin
;
626 case WDIOC_GETTIMEOUT
:
627 return put_user(wdt_margin
, (int __user
*)arg
);
629 case WDIOC_SETOPTIONS
:
630 if (copy_from_user(&rv
, (int __user
*)arg
, sizeof(int)))
633 if (rv
& WDIOS_DISABLECARD
) {
634 pr_info("rtc-m41t80: disable watchdog\n");
638 if (rv
& WDIOS_ENABLECARD
) {
639 pr_info("rtc-m41t80: enable watchdog\n");
650 * @inode: inode of device
651 * @file: file handle to device
654 static int wdt_open(struct inode
*inode
, struct file
*file
)
656 if (MINOR(inode
->i_rdev
) == WATCHDOG_MINOR
) {
658 if (test_and_set_bit(0, &wdt_is_open
)) {
674 * @inode: inode to board
675 * @file: file handle to board
678 static int wdt_release(struct inode
*inode
, struct file
*file
)
680 if (MINOR(inode
->i_rdev
) == WATCHDOG_MINOR
)
681 clear_bit(0, &wdt_is_open
);
687 * @this: our notifier block
688 * @code: the event being reported
691 * Our notifier is called on system shutdowns. We want to turn the card
692 * off at reboot otherwise the machine will reboot again during memory
693 * test or worse yet during the following fsck. This would suck, in fact
694 * trust me - if it happens it does suck.
696 static int wdt_notify_sys(struct notifier_block
*this, unsigned long code
,
699 if (code
== SYS_DOWN
|| code
== SYS_HALT
)
700 /* Disable Watchdog */
705 static const struct file_operations wdt_fops
= {
706 .owner
= THIS_MODULE
,
711 .release
= wdt_release
,
714 static struct miscdevice wdt_dev
= {
715 .minor
= WATCHDOG_MINOR
,
721 * The WDT card needs to learn about soft shutdowns in order to
722 * turn the timebomb registers off.
724 static struct notifier_block wdt_notifier
= {
725 .notifier_call
= wdt_notify_sys
,
727 #endif /* CONFIG_RTC_DRV_M41T80_WDT */
730 *****************************************************************************
734 *****************************************************************************
736 static int m41t80_probe(struct i2c_client
*client
,
737 const struct i2c_device_id
*id
)
740 struct rtc_device
*rtc
= NULL
;
742 struct m41t80_data
*clientdata
= NULL
;
744 if (!i2c_check_functionality(client
->adapter
, I2C_FUNC_I2C
745 | I2C_FUNC_SMBUS_BYTE_DATA
)) {
750 dev_info(&client
->dev
,
751 "chip found, driver version " DRV_VERSION
"\n");
753 clientdata
= kzalloc(sizeof(*clientdata
), GFP_KERNEL
);
759 rtc
= rtc_device_register(client
->name
, &client
->dev
,
760 &m41t80_rtc_ops
, THIS_MODULE
);
767 clientdata
->rtc
= rtc
;
768 clientdata
->features
= id
->driver_data
;
769 i2c_set_clientdata(client
, clientdata
);
771 /* Make sure HT (Halt Update) bit is cleared */
772 rc
= i2c_smbus_read_byte_data(client
, M41T80_REG_ALARM_HOUR
);
776 if (rc
& M41T80_ALHOUR_HT
) {
777 if (clientdata
->features
& M41T80_FEATURE_HT
) {
778 m41t80_get_datetime(client
, &tm
);
779 dev_info(&client
->dev
, "HT bit was set!\n");
780 dev_info(&client
->dev
,
782 "%04i-%02i-%02i %02i:%02i:%02i\n",
784 tm
.tm_mon
+ 1, tm
.tm_mday
, tm
.tm_hour
,
785 tm
.tm_min
, tm
.tm_sec
);
787 if (i2c_smbus_write_byte_data(client
,
788 M41T80_REG_ALARM_HOUR
,
789 rc
& ~M41T80_ALHOUR_HT
) < 0)
793 /* Make sure ST (stop) bit is cleared */
794 rc
= i2c_smbus_read_byte_data(client
, M41T80_REG_SEC
);
798 if (rc
& M41T80_SEC_ST
) {
799 if (i2c_smbus_write_byte_data(client
, M41T80_REG_SEC
,
800 rc
& ~M41T80_SEC_ST
) < 0)
804 rc
= m41t80_sysfs_register(&client
->dev
);
808 #ifdef CONFIG_RTC_DRV_M41T80_WDT
809 if (clientdata
->features
& M41T80_FEATURE_HT
) {
810 save_client
= client
;
811 rc
= misc_register(&wdt_dev
);
814 rc
= register_reboot_notifier(&wdt_notifier
);
816 misc_deregister(&wdt_dev
);
825 dev_err(&client
->dev
, "Can't clear ST bit\n");
829 dev_err(&client
->dev
, "Can't clear HT bit\n");
834 rtc_device_unregister(rtc
);
839 static int m41t80_remove(struct i2c_client
*client
)
841 struct m41t80_data
*clientdata
= i2c_get_clientdata(client
);
842 struct rtc_device
*rtc
= clientdata
->rtc
;
844 #ifdef CONFIG_RTC_DRV_M41T80_WDT
845 if (clientdata
->features
& M41T80_FEATURE_HT
) {
846 misc_deregister(&wdt_dev
);
847 unregister_reboot_notifier(&wdt_notifier
);
851 rtc_device_unregister(rtc
);
857 static struct i2c_driver m41t80_driver
= {
859 .name
= "rtc-m41t80",
861 .probe
= m41t80_probe
,
862 .remove
= m41t80_remove
,
863 .id_table
= m41t80_id
,
866 static int __init
m41t80_rtc_init(void)
868 return i2c_add_driver(&m41t80_driver
);
871 static void __exit
m41t80_rtc_exit(void)
873 i2c_del_driver(&m41t80_driver
);
876 MODULE_AUTHOR("Alexander Bigga <ab@mycable.de>");
877 MODULE_DESCRIPTION("ST Microelectronics M41T80 series RTC I2C Client Driver");
878 MODULE_LICENSE("GPL");
879 MODULE_VERSION(DRV_VERSION
);
881 module_init(m41t80_rtc_init
);
882 module_exit(m41t80_rtc_exit
);