rtc: m41t80: add the use of 'BIT' macro
[deliverable/linux.git] / drivers / rtc / rtc-m41t80.c
1 /*
2 * I2C client/driver for the ST M41T80 family of i2c rtc chips.
3 *
4 * Author: Alexander Bigga <ab@mycable.de>
5 *
6 * Based on m41t00.c by Mark A. Greer <mgreer@mvista.com>
7 *
8 * 2006 (c) mycable GmbH
9 *
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.
13 *
14 */
15
16 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
17
18 #include <linux/bcd.h>
19 #include <linux/i2c.h>
20 #include <linux/init.h>
21 #include <linux/kernel.h>
22 #include <linux/module.h>
23 #include <linux/rtc.h>
24 #include <linux/slab.h>
25 #include <linux/mutex.h>
26 #include <linux/string.h>
27 #ifdef CONFIG_RTC_DRV_M41T80_WDT
28 #include <linux/fs.h>
29 #include <linux/ioctl.h>
30 #include <linux/miscdevice.h>
31 #include <linux/reboot.h>
32 #include <linux/watchdog.h>
33 #endif
34
35 #define M41T80_REG_SSEC 0x00
36 #define M41T80_REG_SEC 0x01
37 #define M41T80_REG_MIN 0x02
38 #define M41T80_REG_HOUR 0x03
39 #define M41T80_REG_WDAY 0x04
40 #define M41T80_REG_DAY 0x05
41 #define M41T80_REG_MON 0x06
42 #define M41T80_REG_YEAR 0x07
43 #define M41T80_REG_ALARM_MON 0x0a
44 #define M41T80_REG_ALARM_DAY 0x0b
45 #define M41T80_REG_ALARM_HOUR 0x0c
46 #define M41T80_REG_ALARM_MIN 0x0d
47 #define M41T80_REG_ALARM_SEC 0x0e
48 #define M41T80_REG_FLAGS 0x0f
49 #define M41T80_REG_SQW 0x13
50
51 #define M41T80_DATETIME_REG_SIZE (M41T80_REG_YEAR + 1)
52 #define M41T80_ALARM_REG_SIZE \
53 (M41T80_REG_ALARM_SEC + 1 - M41T80_REG_ALARM_MON)
54
55 #define M41T80_SEC_ST BIT(7) /* ST: Stop Bit */
56 #define M41T80_ALMON_AFE BIT(7) /* AFE: AF Enable Bit */
57 #define M41T80_ALMON_SQWE BIT(6) /* SQWE: SQW Enable Bit */
58 #define M41T80_ALHOUR_HT BIT(6) /* HT: Halt Update Bit */
59 #define M41T80_FLAGS_AF BIT(6) /* AF: Alarm Flag Bit */
60 #define M41T80_FLAGS_BATT_LOW BIT(4) /* BL: Battery Low Bit */
61 #define M41T80_WATCHDOG_RB2 BIT(7) /* RB: Watchdog resolution */
62 #define M41T80_WATCHDOG_RB1 BIT(1) /* RB: Watchdog resolution */
63 #define M41T80_WATCHDOG_RB0 BIT(0) /* RB: Watchdog resolution */
64
65 #define M41T80_FEATURE_HT BIT(0) /* Halt feature */
66 #define M41T80_FEATURE_BL BIT(1) /* Battery low indicator */
67 #define M41T80_FEATURE_SQ BIT(2) /* Squarewave feature */
68 #define M41T80_FEATURE_WD BIT(3) /* Extra watchdog resolution */
69 #define M41T80_FEATURE_SQ_ALT BIT(4) /* RSx bits are in reg 4 */
70
71 static DEFINE_MUTEX(m41t80_rtc_mutex);
72 static const struct i2c_device_id m41t80_id[] = {
73 { "m41t62", M41T80_FEATURE_SQ | M41T80_FEATURE_SQ_ALT },
74 { "m41t65", M41T80_FEATURE_HT | M41T80_FEATURE_WD },
75 { "m41t80", M41T80_FEATURE_SQ },
76 { "m41t81", M41T80_FEATURE_HT | M41T80_FEATURE_SQ},
77 { "m41t81s", M41T80_FEATURE_HT | M41T80_FEATURE_BL | M41T80_FEATURE_SQ },
78 { "m41t82", M41T80_FEATURE_HT | M41T80_FEATURE_BL | M41T80_FEATURE_SQ },
79 { "m41t83", M41T80_FEATURE_HT | M41T80_FEATURE_BL | M41T80_FEATURE_SQ },
80 { "m41st84", M41T80_FEATURE_HT | M41T80_FEATURE_BL | M41T80_FEATURE_SQ },
81 { "m41st85", M41T80_FEATURE_HT | M41T80_FEATURE_BL | M41T80_FEATURE_SQ },
82 { "m41st87", M41T80_FEATURE_HT | M41T80_FEATURE_BL | M41T80_FEATURE_SQ },
83 { "rv4162", M41T80_FEATURE_SQ | M41T80_FEATURE_WD | M41T80_FEATURE_SQ_ALT },
84 { }
85 };
86 MODULE_DEVICE_TABLE(i2c, m41t80_id);
87
88 struct m41t80_data {
89 u8 features;
90 struct rtc_device *rtc;
91 };
92
93 static int m41t80_get_datetime(struct i2c_client *client,
94 struct rtc_time *tm)
95 {
96 unsigned char buf[8];
97 int err;
98
99 err = i2c_smbus_read_i2c_block_data(client, M41T80_REG_SSEC,
100 sizeof(buf), buf);
101 if (err < 0) {
102 dev_err(&client->dev, "Unable to read date\n");
103 return -EIO;
104 }
105
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;
112
113 /* assume 20YY not 19YY, and ignore the Century Bit */
114 tm->tm_year = bcd2bin(buf[M41T80_REG_YEAR]) + 100;
115 return rtc_valid_tm(tm);
116 }
117
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)
120 {
121 unsigned char buf[8];
122 int err;
123
124 if (tm->tm_year < 100 || tm->tm_year > 199)
125 return -EINVAL;
126
127 buf[M41T80_REG_SSEC] = 0;
128 buf[M41T80_REG_SEC] = bin2bcd(tm->tm_sec);
129 buf[M41T80_REG_MIN] = bin2bcd(tm->tm_min);
130 buf[M41T80_REG_HOUR] = bin2bcd(tm->tm_hour);
131 buf[M41T80_REG_DAY] = bin2bcd(tm->tm_mday);
132 buf[M41T80_REG_MON] = bin2bcd(tm->tm_mon + 1);
133 buf[M41T80_REG_YEAR] = bin2bcd(tm->tm_year - 100);
134 buf[M41T80_REG_WDAY] = tm->tm_wday;
135
136 err = i2c_smbus_write_i2c_block_data(client, M41T80_REG_SSEC,
137 sizeof(buf), buf);
138 if (err < 0) {
139 dev_err(&client->dev, "Unable to write to date registers\n");
140 return err;
141 }
142
143 return err;
144 }
145
146 static int m41t80_rtc_proc(struct device *dev, struct seq_file *seq)
147 {
148 struct i2c_client *client = to_i2c_client(dev);
149 struct m41t80_data *clientdata = i2c_get_clientdata(client);
150 u8 reg;
151
152 if (clientdata->features & M41T80_FEATURE_BL) {
153 reg = i2c_smbus_read_byte_data(client, M41T80_REG_FLAGS);
154 seq_printf(seq, "battery\t\t: %s\n",
155 (reg & M41T80_FLAGS_BATT_LOW) ? "exhausted" : "ok");
156 }
157 return 0;
158 }
159
160 static int m41t80_rtc_read_time(struct device *dev, struct rtc_time *tm)
161 {
162 return m41t80_get_datetime(to_i2c_client(dev), tm);
163 }
164
165 static int m41t80_rtc_set_time(struct device *dev, struct rtc_time *tm)
166 {
167 return m41t80_set_datetime(to_i2c_client(dev), tm);
168 }
169
170 /*
171 * XXX - m41t80 alarm functionality is reported broken.
172 * until it is fixed, don't register alarm functions.
173 */
174 static struct rtc_class_ops m41t80_rtc_ops = {
175 .read_time = m41t80_rtc_read_time,
176 .set_time = m41t80_rtc_set_time,
177 .proc = m41t80_rtc_proc,
178 };
179
180 static ssize_t flags_show(struct device *dev,
181 struct device_attribute *attr, char *buf)
182 {
183 struct i2c_client *client = to_i2c_client(dev);
184 int val;
185
186 val = i2c_smbus_read_byte_data(client, M41T80_REG_FLAGS);
187 if (val < 0)
188 return val;
189 return sprintf(buf, "%#x\n", val);
190 }
191 static DEVICE_ATTR_RO(flags);
192
193 static ssize_t sqwfreq_show(struct device *dev,
194 struct device_attribute *attr, char *buf)
195 {
196 struct i2c_client *client = to_i2c_client(dev);
197 struct m41t80_data *clientdata = i2c_get_clientdata(client);
198 int val, reg_sqw;
199
200 if (!(clientdata->features & M41T80_FEATURE_SQ))
201 return -EINVAL;
202
203 reg_sqw = M41T80_REG_SQW;
204 if (clientdata->features & M41T80_FEATURE_SQ_ALT)
205 reg_sqw = M41T80_REG_WDAY;
206 val = i2c_smbus_read_byte_data(client, reg_sqw);
207 if (val < 0)
208 return val;
209 val = (val >> 4) & 0xf;
210 switch (val) {
211 case 0:
212 break;
213 case 1:
214 val = 32768;
215 break;
216 default:
217 val = 32768 >> val;
218 }
219 return sprintf(buf, "%d\n", val);
220 }
221
222 static ssize_t sqwfreq_store(struct device *dev,
223 struct device_attribute *attr,
224 const char *buf, size_t count)
225 {
226 struct i2c_client *client = to_i2c_client(dev);
227 struct m41t80_data *clientdata = i2c_get_clientdata(client);
228 int almon, sqw, reg_sqw, rc;
229 int val = simple_strtoul(buf, NULL, 0);
230
231 if (!(clientdata->features & M41T80_FEATURE_SQ))
232 return -EINVAL;
233
234 if (val) {
235 if (!is_power_of_2(val))
236 return -EINVAL;
237 val = ilog2(val);
238 if (val == 15)
239 val = 1;
240 else if (val < 14)
241 val = 15 - val;
242 else
243 return -EINVAL;
244 }
245 /* disable SQW, set SQW frequency & re-enable */
246 almon = i2c_smbus_read_byte_data(client, M41T80_REG_ALARM_MON);
247 if (almon < 0)
248 return almon;
249 reg_sqw = M41T80_REG_SQW;
250 if (clientdata->features & M41T80_FEATURE_SQ_ALT)
251 reg_sqw = M41T80_REG_WDAY;
252 sqw = i2c_smbus_read_byte_data(client, reg_sqw);
253 if (sqw < 0)
254 return sqw;
255 sqw = (sqw & 0x0f) | (val << 4);
256
257 rc = i2c_smbus_write_byte_data(client, M41T80_REG_ALARM_MON,
258 almon & ~M41T80_ALMON_SQWE);
259 if (rc < 0)
260 return rc;
261
262 if (val) {
263 rc = i2c_smbus_write_byte_data(client, reg_sqw, sqw);
264 if (rc < 0)
265 return rc;
266
267 rc = i2c_smbus_write_byte_data(client, M41T80_REG_ALARM_MON,
268 almon | M41T80_ALMON_SQWE);
269 if (rc <0)
270 return rc;
271 }
272 return count;
273 }
274 static DEVICE_ATTR_RW(sqwfreq);
275
276 static struct attribute *attrs[] = {
277 &dev_attr_flags.attr,
278 &dev_attr_sqwfreq.attr,
279 NULL,
280 };
281 static struct attribute_group attr_group = {
282 .attrs = attrs,
283 };
284
285 #ifdef CONFIG_RTC_DRV_M41T80_WDT
286 /*
287 *****************************************************************************
288 *
289 * Watchdog Driver
290 *
291 *****************************************************************************
292 */
293 static struct i2c_client *save_client;
294
295 /* Default margin */
296 #define WD_TIMO 60 /* 1..31 seconds */
297
298 static int wdt_margin = WD_TIMO;
299 module_param(wdt_margin, int, 0);
300 MODULE_PARM_DESC(wdt_margin, "Watchdog timeout in seconds (default 60s)");
301
302 static unsigned long wdt_is_open;
303 static int boot_flag;
304
305 /**
306 * wdt_ping:
307 *
308 * Reload counter one with the watchdog timeout. We don't bother reloading
309 * the cascade counter.
310 */
311 static void wdt_ping(void)
312 {
313 unsigned char i2c_data[2];
314 struct i2c_msg msgs1[1] = {
315 {
316 .addr = save_client->addr,
317 .flags = 0,
318 .len = 2,
319 .buf = i2c_data,
320 },
321 };
322 struct m41t80_data *clientdata = i2c_get_clientdata(save_client);
323
324 i2c_data[0] = 0x09; /* watchdog register */
325
326 if (wdt_margin > 31)
327 i2c_data[1] = (wdt_margin & 0xFC) | 0x83; /* resolution = 4s */
328 else
329 /*
330 * WDS = 1 (0x80), mulitplier = WD_TIMO, resolution = 1s (0x02)
331 */
332 i2c_data[1] = wdt_margin<<2 | 0x82;
333
334 /*
335 * M41T65 has three bits for watchdog resolution. Don't set bit 7, as
336 * that would be an invalid resolution.
337 */
338 if (clientdata->features & M41T80_FEATURE_WD)
339 i2c_data[1] &= ~M41T80_WATCHDOG_RB2;
340
341 i2c_transfer(save_client->adapter, msgs1, 1);
342 }
343
344 /**
345 * wdt_disable:
346 *
347 * disables watchdog.
348 */
349 static void wdt_disable(void)
350 {
351 unsigned char i2c_data[2], i2c_buf[0x10];
352 struct i2c_msg msgs0[2] = {
353 {
354 .addr = save_client->addr,
355 .flags = 0,
356 .len = 1,
357 .buf = i2c_data,
358 },
359 {
360 .addr = save_client->addr,
361 .flags = I2C_M_RD,
362 .len = 1,
363 .buf = i2c_buf,
364 },
365 };
366 struct i2c_msg msgs1[1] = {
367 {
368 .addr = save_client->addr,
369 .flags = 0,
370 .len = 2,
371 .buf = i2c_data,
372 },
373 };
374
375 i2c_data[0] = 0x09;
376 i2c_transfer(save_client->adapter, msgs0, 2);
377
378 i2c_data[0] = 0x09;
379 i2c_data[1] = 0x00;
380 i2c_transfer(save_client->adapter, msgs1, 1);
381 }
382
383 /**
384 * wdt_write:
385 * @file: file handle to the watchdog
386 * @buf: buffer to write (unused as data does not matter here
387 * @count: count of bytes
388 * @ppos: pointer to the position to write. No seeks allowed
389 *
390 * A write to a watchdog device is defined as a keepalive signal. Any
391 * write of data will do, as we we don't define content meaning.
392 */
393 static ssize_t wdt_write(struct file *file, const char __user *buf,
394 size_t count, loff_t *ppos)
395 {
396 if (count) {
397 wdt_ping();
398 return 1;
399 }
400 return 0;
401 }
402
403 static ssize_t wdt_read(struct file *file, char __user *buf,
404 size_t count, loff_t *ppos)
405 {
406 return 0;
407 }
408
409 /**
410 * wdt_ioctl:
411 * @inode: inode of the device
412 * @file: file handle to the device
413 * @cmd: watchdog command
414 * @arg: argument pointer
415 *
416 * The watchdog API defines a common set of functions for all watchdogs
417 * according to their available features. We only actually usefully support
418 * querying capabilities and current status.
419 */
420 static int wdt_ioctl(struct file *file, unsigned int cmd,
421 unsigned long arg)
422 {
423 int new_margin, rv;
424 static struct watchdog_info ident = {
425 .options = WDIOF_POWERUNDER | WDIOF_KEEPALIVEPING |
426 WDIOF_SETTIMEOUT,
427 .firmware_version = 1,
428 .identity = "M41T80 WTD"
429 };
430
431 switch (cmd) {
432 case WDIOC_GETSUPPORT:
433 return copy_to_user((struct watchdog_info __user *)arg, &ident,
434 sizeof(ident)) ? -EFAULT : 0;
435
436 case WDIOC_GETSTATUS:
437 case WDIOC_GETBOOTSTATUS:
438 return put_user(boot_flag, (int __user *)arg);
439 case WDIOC_KEEPALIVE:
440 wdt_ping();
441 return 0;
442 case WDIOC_SETTIMEOUT:
443 if (get_user(new_margin, (int __user *)arg))
444 return -EFAULT;
445 /* Arbitrary, can't find the card's limits */
446 if (new_margin < 1 || new_margin > 124)
447 return -EINVAL;
448 wdt_margin = new_margin;
449 wdt_ping();
450 /* Fall */
451 case WDIOC_GETTIMEOUT:
452 return put_user(wdt_margin, (int __user *)arg);
453
454 case WDIOC_SETOPTIONS:
455 if (copy_from_user(&rv, (int __user *)arg, sizeof(int)))
456 return -EFAULT;
457
458 if (rv & WDIOS_DISABLECARD) {
459 pr_info("disable watchdog\n");
460 wdt_disable();
461 }
462
463 if (rv & WDIOS_ENABLECARD) {
464 pr_info("enable watchdog\n");
465 wdt_ping();
466 }
467
468 return -EINVAL;
469 }
470 return -ENOTTY;
471 }
472
473 static long wdt_unlocked_ioctl(struct file *file, unsigned int cmd,
474 unsigned long arg)
475 {
476 int ret;
477
478 mutex_lock(&m41t80_rtc_mutex);
479 ret = wdt_ioctl(file, cmd, arg);
480 mutex_unlock(&m41t80_rtc_mutex);
481
482 return ret;
483 }
484
485 /**
486 * wdt_open:
487 * @inode: inode of device
488 * @file: file handle to device
489 *
490 */
491 static int wdt_open(struct inode *inode, struct file *file)
492 {
493 if (MINOR(inode->i_rdev) == WATCHDOG_MINOR) {
494 mutex_lock(&m41t80_rtc_mutex);
495 if (test_and_set_bit(0, &wdt_is_open)) {
496 mutex_unlock(&m41t80_rtc_mutex);
497 return -EBUSY;
498 }
499 /*
500 * Activate
501 */
502 wdt_is_open = 1;
503 mutex_unlock(&m41t80_rtc_mutex);
504 return nonseekable_open(inode, file);
505 }
506 return -ENODEV;
507 }
508
509 /**
510 * wdt_close:
511 * @inode: inode to board
512 * @file: file handle to board
513 *
514 */
515 static int wdt_release(struct inode *inode, struct file *file)
516 {
517 if (MINOR(inode->i_rdev) == WATCHDOG_MINOR)
518 clear_bit(0, &wdt_is_open);
519 return 0;
520 }
521
522 /**
523 * notify_sys:
524 * @this: our notifier block
525 * @code: the event being reported
526 * @unused: unused
527 *
528 * Our notifier is called on system shutdowns. We want to turn the card
529 * off at reboot otherwise the machine will reboot again during memory
530 * test or worse yet during the following fsck. This would suck, in fact
531 * trust me - if it happens it does suck.
532 */
533 static int wdt_notify_sys(struct notifier_block *this, unsigned long code,
534 void *unused)
535 {
536 if (code == SYS_DOWN || code == SYS_HALT)
537 /* Disable Watchdog */
538 wdt_disable();
539 return NOTIFY_DONE;
540 }
541
542 static const struct file_operations wdt_fops = {
543 .owner = THIS_MODULE,
544 .read = wdt_read,
545 .unlocked_ioctl = wdt_unlocked_ioctl,
546 .write = wdt_write,
547 .open = wdt_open,
548 .release = wdt_release,
549 .llseek = no_llseek,
550 };
551
552 static struct miscdevice wdt_dev = {
553 .minor = WATCHDOG_MINOR,
554 .name = "watchdog",
555 .fops = &wdt_fops,
556 };
557
558 /*
559 * The WDT card needs to learn about soft shutdowns in order to
560 * turn the timebomb registers off.
561 */
562 static struct notifier_block wdt_notifier = {
563 .notifier_call = wdt_notify_sys,
564 };
565 #endif /* CONFIG_RTC_DRV_M41T80_WDT */
566
567 /*
568 *****************************************************************************
569 *
570 * Driver Interface
571 *
572 *****************************************************************************
573 */
574
575 static void m41t80_remove_sysfs_group(void *_dev)
576 {
577 struct device *dev = _dev;
578
579 sysfs_remove_group(&dev->kobj, &attr_group);
580 }
581
582 static int m41t80_probe(struct i2c_client *client,
583 const struct i2c_device_id *id)
584 {
585 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
586 int rc = 0;
587 struct rtc_device *rtc = NULL;
588 struct rtc_time tm;
589 struct m41t80_data *clientdata = NULL;
590
591 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK |
592 I2C_FUNC_SMBUS_BYTE_DATA)) {
593 dev_err(&adapter->dev, "doesn't support I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_I2C_BLOCK\n");
594 return -ENODEV;
595 }
596
597 clientdata = devm_kzalloc(&client->dev, sizeof(*clientdata),
598 GFP_KERNEL);
599 if (!clientdata)
600 return -ENOMEM;
601
602 clientdata->features = id->driver_data;
603 i2c_set_clientdata(client, clientdata);
604
605 rtc = devm_rtc_device_register(&client->dev, client->name,
606 &m41t80_rtc_ops, THIS_MODULE);
607 if (IS_ERR(rtc))
608 return PTR_ERR(rtc);
609
610 clientdata->rtc = rtc;
611
612 /* Make sure HT (Halt Update) bit is cleared */
613 rc = i2c_smbus_read_byte_data(client, M41T80_REG_ALARM_HOUR);
614
615 if (rc >= 0 && rc & M41T80_ALHOUR_HT) {
616 if (clientdata->features & M41T80_FEATURE_HT) {
617 m41t80_get_datetime(client, &tm);
618 dev_info(&client->dev, "HT bit was set!\n");
619 dev_info(&client->dev,
620 "Power Down at "
621 "%04i-%02i-%02i %02i:%02i:%02i\n",
622 tm.tm_year + 1900,
623 tm.tm_mon + 1, tm.tm_mday, tm.tm_hour,
624 tm.tm_min, tm.tm_sec);
625 }
626 rc = i2c_smbus_write_byte_data(client, M41T80_REG_ALARM_HOUR,
627 rc & ~M41T80_ALHOUR_HT);
628 }
629
630 if (rc < 0) {
631 dev_err(&client->dev, "Can't clear HT bit\n");
632 return rc;
633 }
634
635 /* Make sure ST (stop) bit is cleared */
636 rc = i2c_smbus_read_byte_data(client, M41T80_REG_SEC);
637
638 if (rc >= 0 && rc & M41T80_SEC_ST)
639 rc = i2c_smbus_write_byte_data(client, M41T80_REG_SEC,
640 rc & ~M41T80_SEC_ST);
641 if (rc < 0) {
642 dev_err(&client->dev, "Can't clear ST bit\n");
643 return rc;
644 }
645
646 /* Export sysfs entries */
647 rc = sysfs_create_group(&(&client->dev)->kobj, &attr_group);
648 if (rc) {
649 dev_err(&client->dev, "Failed to create sysfs group: %d\n", rc);
650 return rc;
651 }
652
653 rc = devm_add_action(&client->dev, m41t80_remove_sysfs_group,
654 &client->dev);
655 if (rc) {
656 m41t80_remove_sysfs_group(&client->dev);
657 dev_err(&client->dev,
658 "Failed to add sysfs cleanup action: %d\n", rc);
659 return rc;
660 }
661
662 #ifdef CONFIG_RTC_DRV_M41T80_WDT
663 if (clientdata->features & M41T80_FEATURE_HT) {
664 save_client = client;
665 rc = misc_register(&wdt_dev);
666 if (rc)
667 return rc;
668 rc = register_reboot_notifier(&wdt_notifier);
669 if (rc) {
670 misc_deregister(&wdt_dev);
671 return rc;
672 }
673 }
674 #endif
675 return 0;
676 }
677
678 static int m41t80_remove(struct i2c_client *client)
679 {
680 #ifdef CONFIG_RTC_DRV_M41T80_WDT
681 struct m41t80_data *clientdata = i2c_get_clientdata(client);
682
683 if (clientdata->features & M41T80_FEATURE_HT) {
684 misc_deregister(&wdt_dev);
685 unregister_reboot_notifier(&wdt_notifier);
686 }
687 #endif
688
689 return 0;
690 }
691
692 static struct i2c_driver m41t80_driver = {
693 .driver = {
694 .name = "rtc-m41t80",
695 },
696 .probe = m41t80_probe,
697 .remove = m41t80_remove,
698 .id_table = m41t80_id,
699 };
700
701 module_i2c_driver(m41t80_driver);
702
703 MODULE_AUTHOR("Alexander Bigga <ab@mycable.de>");
704 MODULE_DESCRIPTION("ST Microelectronics M41T80 series RTC I2C Client Driver");
705 MODULE_LICENSE("GPL");
This page took 0.044964 seconds and 6 git commands to generate.