2 * RTC class driver for "CMOS RTC": PCs, ACPI, etc
4 * Copyright (C) 1996 Paul Gortmaker (drivers/char/rtc.c)
5 * Copyright (C) 2006 David Brownell (convert to new framework)
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
14 * The original "cmos clock" chip was an MC146818 chip, now obsolete.
15 * That defined the register interface now provided by all PCs, some
16 * non-PC systems, and incorporated into ACPI. Modern PC chipsets
17 * integrate an MC146818 clone in their southbridge, and boards use
18 * that instead of discrete clones like the DS12887 or M48T86. There
19 * are also clones that connect using the LPC bus.
21 * That register API is also used directly by various other drivers
22 * (notably for integrated NVRAM), infrastructure (x86 has code to
23 * bypass the RTC framework, directly reading the RTC during boot
24 * and updating minutes/seconds for systems using NTP synch) and
25 * utilities (like userspace 'hwclock', if no /dev node exists).
27 * So **ALL** calls to CMOS_READ and CMOS_WRITE must be done with
28 * interrupts disabled, holding the global rtc_lock, to exclude those
29 * other drivers and utilities on correctly configured systems.
31 #include <linux/kernel.h>
32 #include <linux/module.h>
33 #include <linux/init.h>
34 #include <linux/interrupt.h>
35 #include <linux/spinlock.h>
36 #include <linux/platform_device.h>
37 #include <linux/mod_devicetable.h>
39 /* this is for "generic access to PC-style RTC" using CMOS_READ/CMOS_WRITE */
40 #include <asm-generic/rtc.h>
44 struct rtc_device *rtc;
47 struct resource *iomem;
49 void (*wake_on)(struct device *);
50 void (*wake_off)(struct device *);
55 /* newer hardware extends the original register set */
61 /* both platform and pnp busses use negative numbers for invalid irqs */
62 #define is_valid_irq(n) ((n) >= 0)
64 static const char driver_name[] = "rtc_cmos";
66 /* The RTC_INTR register may have e.g. RTC_PF set even if RTC_PIE is clear;
67 * always mask it against the irq enable bits in RTC_CONTROL. Bit values
68 * are the same: PF==PIE, AF=AIE, UF=UIE; so RTC_IRQMASK works with both.
70 #define RTC_IRQMASK (RTC_PF | RTC_AF | RTC_UF)
72 static inline int is_intr(u8 rtc_intr)
74 if (!(rtc_intr & RTC_IRQF))
76 return rtc_intr & RTC_IRQMASK;
79 /*----------------------------------------------------------------*/
81 static int cmos_read_time(struct device *dev, struct rtc_time *t)
83 /* REVISIT: if the clock has a "century" register, use
84 * that instead of the heuristic in get_rtc_time().
85 * That'll make Y3K compatility (year > 2070) easy!
91 static int cmos_set_time(struct device *dev, struct rtc_time *t)
93 /* REVISIT: set the "century" register if available
95 * NOTE: this ignores the issue whereby updating the seconds
96 * takes effect exactly 500ms after we write the register.
97 * (Also queueing and other delays before we get this far.)
99 return set_rtc_time(t);
102 static int cmos_read_alarm(struct device *dev, struct rtc_wkalrm *t)
104 struct cmos_rtc *cmos = dev_get_drvdata(dev);
105 unsigned char rtc_control;
107 if (!is_valid_irq(cmos->irq))
110 /* Basic alarms only support hour, minute, and seconds fields.
111 * Some also support day and month, for alarms up to a year in
114 t->time.tm_mday = -1;
117 spin_lock_irq(&rtc_lock);
118 t->time.tm_sec = CMOS_READ(RTC_SECONDS_ALARM);
119 t->time.tm_min = CMOS_READ(RTC_MINUTES_ALARM);
120 t->time.tm_hour = CMOS_READ(RTC_HOURS_ALARM);
122 if (cmos->day_alrm) {
123 /* ignore upper bits on readback per ACPI spec */
124 t->time.tm_mday = CMOS_READ(cmos->day_alrm) & 0x3f;
125 if (!t->time.tm_mday)
126 t->time.tm_mday = -1;
128 if (cmos->mon_alrm) {
129 t->time.tm_mon = CMOS_READ(cmos->mon_alrm);
135 rtc_control = CMOS_READ(RTC_CONTROL);
136 spin_unlock_irq(&rtc_lock);
138 /* REVISIT this assumes PC style usage: always BCD */
140 if (((unsigned)t->time.tm_sec) < 0x60)
141 t->time.tm_sec = BCD2BIN(t->time.tm_sec);
144 if (((unsigned)t->time.tm_min) < 0x60)
145 t->time.tm_min = BCD2BIN(t->time.tm_min);
148 if (((unsigned)t->time.tm_hour) < 0x24)
149 t->time.tm_hour = BCD2BIN(t->time.tm_hour);
151 t->time.tm_hour = -1;
153 if (cmos->day_alrm) {
154 if (((unsigned)t->time.tm_mday) <= 0x31)
155 t->time.tm_mday = BCD2BIN(t->time.tm_mday);
157 t->time.tm_mday = -1;
158 if (cmos->mon_alrm) {
159 if (((unsigned)t->time.tm_mon) <= 0x12)
160 t->time.tm_mon = BCD2BIN(t->time.tm_mon) - 1;
165 t->time.tm_year = -1;
167 t->enabled = !!(rtc_control & RTC_AIE);
173 static int cmos_set_alarm(struct device *dev, struct rtc_wkalrm *t)
175 struct cmos_rtc *cmos = dev_get_drvdata(dev);
176 unsigned char mon, mday, hrs, min, sec;
177 unsigned char rtc_control, rtc_intr;
179 if (!is_valid_irq(cmos->irq))
182 /* REVISIT this assumes PC style usage: always BCD */
184 /* Writing 0xff means "don't care" or "match all". */
186 mon = t->time.tm_mon;
187 mon = (mon < 12) ? BIN2BCD(mon) : 0xff;
190 mday = t->time.tm_mday;
191 mday = (mday >= 1 && mday <= 31) ? BIN2BCD(mday) : 0xff;
193 hrs = t->time.tm_hour;
194 hrs = (hrs < 24) ? BIN2BCD(hrs) : 0xff;
196 min = t->time.tm_min;
197 min = (min < 60) ? BIN2BCD(min) : 0xff;
199 sec = t->time.tm_sec;
200 sec = (sec < 60) ? BIN2BCD(sec) : 0xff;
202 spin_lock_irq(&rtc_lock);
204 /* next rtc irq must not be from previous alarm setting */
205 rtc_control = CMOS_READ(RTC_CONTROL);
206 rtc_control &= ~RTC_AIE;
207 CMOS_WRITE(rtc_control, RTC_CONTROL);
208 rtc_intr = CMOS_READ(RTC_INTR_FLAGS);
209 rtc_intr &= (rtc_control & RTC_IRQMASK) | RTC_IRQF;
210 if (is_intr(rtc_intr))
211 rtc_update_irq(cmos->rtc, 1, rtc_intr);
214 CMOS_WRITE(hrs, RTC_HOURS_ALARM);
215 CMOS_WRITE(min, RTC_MINUTES_ALARM);
216 CMOS_WRITE(sec, RTC_SECONDS_ALARM);
218 /* the system may support an "enhanced" alarm */
219 if (cmos->day_alrm) {
220 CMOS_WRITE(mday, cmos->day_alrm);
222 CMOS_WRITE(mon, cmos->mon_alrm);
226 rtc_control |= RTC_AIE;
227 CMOS_WRITE(rtc_control, RTC_CONTROL);
228 rtc_intr = CMOS_READ(RTC_INTR_FLAGS);
229 rtc_intr &= (rtc_control & RTC_IRQMASK) | RTC_IRQF;
230 if (is_intr(rtc_intr))
231 rtc_update_irq(cmos->rtc, 1, rtc_intr);
234 spin_unlock_irq(&rtc_lock);
239 static int cmos_irq_set_freq(struct device *dev, int freq)
241 struct cmos_rtc *cmos = dev_get_drvdata(dev);
245 if (!is_valid_irq(cmos->irq))
248 /* 0 = no irqs; 1 = 2^15 Hz ... 15 = 2^0 Hz */
254 spin_lock_irqsave(&rtc_lock, flags);
255 CMOS_WRITE(RTC_REF_CLCK_32KHZ | f, RTC_FREQ_SELECT);
256 spin_unlock_irqrestore(&rtc_lock, flags);
261 static int cmos_irq_set_state(struct device *dev, int enabled)
263 struct cmos_rtc *cmos = dev_get_drvdata(dev);
264 unsigned char rtc_control, rtc_intr;
267 if (!is_valid_irq(cmos->irq))
270 spin_lock_irqsave(&rtc_lock, flags);
271 rtc_control = CMOS_READ(RTC_CONTROL);
274 rtc_control |= RTC_PIE;
276 rtc_control &= ~RTC_PIE;
278 CMOS_WRITE(rtc_control, RTC_CONTROL);
280 rtc_intr = CMOS_READ(RTC_INTR_FLAGS);
281 rtc_intr &= (rtc_control & RTC_IRQMASK) | RTC_IRQF;
282 if (is_intr(rtc_intr))
283 rtc_update_irq(cmos->rtc, 1, rtc_intr);
285 spin_unlock_irqrestore(&rtc_lock, flags);
289 #if defined(CONFIG_RTC_INTF_DEV) || defined(CONFIG_RTC_INTF_DEV_MODULE)
292 cmos_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
294 struct cmos_rtc *cmos = dev_get_drvdata(dev);
295 unsigned char rtc_control, rtc_intr;
305 if (!is_valid_irq(cmos->irq))
312 spin_lock_irqsave(&rtc_lock, flags);
313 rtc_control = CMOS_READ(RTC_CONTROL);
315 case RTC_AIE_OFF: /* alarm off */
316 rtc_control &= ~RTC_AIE;
318 case RTC_AIE_ON: /* alarm on */
319 rtc_control |= RTC_AIE;
321 case RTC_UIE_OFF: /* update off */
322 rtc_control &= ~RTC_UIE;
324 case RTC_UIE_ON: /* update on */
325 rtc_control |= RTC_UIE;
327 case RTC_PIE_OFF: /* periodic off */
328 rtc_control &= ~RTC_PIE;
330 case RTC_PIE_ON: /* periodic on */
331 rtc_control |= RTC_PIE;
334 CMOS_WRITE(rtc_control, RTC_CONTROL);
335 rtc_intr = CMOS_READ(RTC_INTR_FLAGS);
336 rtc_intr &= (rtc_control & RTC_IRQMASK) | RTC_IRQF;
337 if (is_intr(rtc_intr))
338 rtc_update_irq(cmos->rtc, 1, rtc_intr);
339 spin_unlock_irqrestore(&rtc_lock, flags);
344 #define cmos_rtc_ioctl NULL
347 #if defined(CONFIG_RTC_INTF_PROC) || defined(CONFIG_RTC_INTF_PROC_MODULE)
349 static int cmos_procfs(struct device *dev, struct seq_file *seq)
351 struct cmos_rtc *cmos = dev_get_drvdata(dev);
352 unsigned char rtc_control, valid;
354 spin_lock_irq(&rtc_lock);
355 rtc_control = CMOS_READ(RTC_CONTROL);
356 valid = CMOS_READ(RTC_VALID);
357 spin_unlock_irq(&rtc_lock);
359 /* NOTE: at least ICH6 reports battery status using a different
360 * (non-RTC) bit; and SQWE is ignored on many current systems.
362 return seq_printf(seq,
363 "periodic_IRQ\t: %s\n"
365 // "square_wave\t: %s\n"
368 "periodic_freq\t: %d\n"
369 "batt_status\t: %s\n",
370 (rtc_control & RTC_PIE) ? "yes" : "no",
371 (rtc_control & RTC_UIE) ? "yes" : "no",
372 // (rtc_control & RTC_SQWE) ? "yes" : "no",
373 // (rtc_control & RTC_DM_BINARY) ? "no" : "yes",
374 (rtc_control & RTC_DST_EN) ? "yes" : "no",
376 (valid & RTC_VRT) ? "okay" : "dead");
380 #define cmos_procfs NULL
383 static const struct rtc_class_ops cmos_rtc_ops = {
384 .ioctl = cmos_rtc_ioctl,
385 .read_time = cmos_read_time,
386 .set_time = cmos_set_time,
387 .read_alarm = cmos_read_alarm,
388 .set_alarm = cmos_set_alarm,
390 .irq_set_freq = cmos_irq_set_freq,
391 .irq_set_state = cmos_irq_set_state,
394 /*----------------------------------------------------------------*/
397 * All these chips have at least 64 bytes of address space, shared by
398 * RTC registers and NVRAM. Most of those bytes of NVRAM are used
399 * by boot firmware. Modern chips have 128 or 256 bytes.
402 #define NVRAM_OFFSET (RTC_REG_D + 1)
405 cmos_nvram_read(struct kobject *kobj, struct bin_attribute *attr,
406 char *buf, loff_t off, size_t count)
410 if (unlikely(off >= attr->size))
412 if ((off + count) > attr->size)
413 count = attr->size - off;
415 spin_lock_irq(&rtc_lock);
416 for (retval = 0, off += NVRAM_OFFSET; count--; retval++, off++)
417 *buf++ = CMOS_READ(off);
418 spin_unlock_irq(&rtc_lock);
424 cmos_nvram_write(struct kobject *kobj, struct bin_attribute *attr,
425 char *buf, loff_t off, size_t count)
427 struct cmos_rtc *cmos;
430 cmos = dev_get_drvdata(container_of(kobj, struct device, kobj));
431 if (unlikely(off >= attr->size))
433 if ((off + count) > attr->size)
434 count = attr->size - off;
436 /* NOTE: on at least PCs and Ataris, the boot firmware uses a
437 * checksum on part of the NVRAM data. That's currently ignored
438 * here. If userspace is smart enough to know what fields of
439 * NVRAM to update, updating checksums is also part of its job.
441 spin_lock_irq(&rtc_lock);
442 for (retval = 0, off += NVRAM_OFFSET; count--; retval++, off++) {
443 /* don't trash RTC registers */
444 if (off == cmos->day_alrm
445 || off == cmos->mon_alrm
446 || off == cmos->century)
449 CMOS_WRITE(*buf++, off);
451 spin_unlock_irq(&rtc_lock);
456 static struct bin_attribute nvram = {
459 .mode = S_IRUGO | S_IWUSR,
460 .owner = THIS_MODULE,
463 .read = cmos_nvram_read,
464 .write = cmos_nvram_write,
465 /* size gets set up later */
468 /*----------------------------------------------------------------*/
470 static struct cmos_rtc cmos_rtc;
472 static irqreturn_t cmos_interrupt(int irq, void *p)
476 spin_lock(&rtc_lock);
477 irqstat = CMOS_READ(RTC_INTR_FLAGS);
478 irqstat &= (CMOS_READ(RTC_CONTROL) & RTC_IRQMASK) | RTC_IRQF;
479 spin_unlock(&rtc_lock);
481 if (is_intr(irqstat)) {
482 rtc_update_irq(p, 1, irqstat);
492 #define INITSECTION __init
495 static int INITSECTION
496 cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
498 struct cmos_rtc_board_info *info = dev->platform_data;
500 unsigned char rtc_control;
501 unsigned address_space;
503 /* there can be only one ... */
510 /* Claim I/O ports ASAP, minimizing conflict with legacy driver.
512 * REVISIT non-x86 systems may instead use memory space resources
513 * (needing ioremap etc), not i/o space resources like this ...
515 ports = request_region(ports->start,
516 ports->end + 1 - ports->start,
519 dev_dbg(dev, "i/o registers already in use\n");
523 cmos_rtc.irq = rtc_irq;
524 cmos_rtc.iomem = ports;
526 /* Heuristic to deduce NVRAM size ... do what the legacy NVRAM
527 * driver did, but don't reject unknown configs. Old hardware
528 * won't address 128 bytes, and for now we ignore the way newer
529 * chips can address 256 bytes (using two more i/o ports).
531 #if defined(CONFIG_ATARI)
533 #elif defined(__i386__) || defined(__x86_64__) || defined(__arm__)
536 #warning Assuming 128 bytes of RTC+NVRAM address space, not 64 bytes.
540 /* For ACPI systems extension info comes from the FADT. On others,
541 * board specific setup provides it as appropriate. Systems where
542 * the alarm IRQ isn't automatically a wakeup IRQ (like ACPI, and
543 * some almost-clones) can provide hooks to make that behave.
545 * Note that ACPI doesn't preclude putting these registers into
546 * "extended" areas of the chip, including some that we won't yet
547 * expect CMOS_READ and friends to handle.
550 if (info->rtc_day_alarm && info->rtc_day_alarm < 128)
551 cmos_rtc.day_alrm = info->rtc_day_alarm;
552 if (info->rtc_mon_alarm && info->rtc_mon_alarm < 128)
553 cmos_rtc.mon_alrm = info->rtc_mon_alarm;
554 if (info->rtc_century && info->rtc_century < 128)
555 cmos_rtc.century = info->rtc_century;
557 if (info->wake_on && info->wake_off) {
558 cmos_rtc.wake_on = info->wake_on;
559 cmos_rtc.wake_off = info->wake_off;
563 cmos_rtc.rtc = rtc_device_register(driver_name, dev,
564 &cmos_rtc_ops, THIS_MODULE);
565 if (IS_ERR(cmos_rtc.rtc)) {
566 retval = PTR_ERR(cmos_rtc.rtc);
571 dev_set_drvdata(dev, &cmos_rtc);
572 rename_region(ports, cmos_rtc.rtc->dev.bus_id);
574 spin_lock_irq(&rtc_lock);
576 /* force periodic irq to CMOS reset default of 1024Hz;
578 * REVISIT it's been reported that at least one x86_64 ALI mobo
579 * doesn't use 32KHz here ... for portability we might need to
580 * do something about other clock frequencies.
582 CMOS_WRITE(RTC_REF_CLCK_32KHZ | 0x06, RTC_FREQ_SELECT);
583 cmos_rtc.rtc->irq_freq = 1024;
587 * NOTE after changing RTC_xIE bits we always read INTR_FLAGS;
588 * allegedly some older rtcs need that to handle irqs properly
590 rtc_control = CMOS_READ(RTC_CONTROL);
591 rtc_control &= ~(RTC_PIE | RTC_AIE | RTC_UIE);
592 CMOS_WRITE(rtc_control, RTC_CONTROL);
593 CMOS_READ(RTC_INTR_FLAGS);
595 spin_unlock_irq(&rtc_lock);
597 /* FIXME teach the alarm code how to handle binary mode;
598 * <asm-generic/rtc.h> doesn't know 12-hour mode either.
600 if (!(rtc_control & RTC_24H) || (rtc_control & (RTC_DM_BINARY))) {
601 dev_dbg(dev, "only 24-hr BCD mode supported\n");
606 if (is_valid_irq(rtc_irq))
607 retval = request_irq(rtc_irq, cmos_interrupt, IRQF_DISABLED,
608 cmos_rtc.rtc->dev.bus_id,
611 dev_dbg(dev, "IRQ %d is already in use\n", rtc_irq);
615 /* export at least the first block of NVRAM */
616 nvram.size = address_space - NVRAM_OFFSET;
617 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
619 dev_dbg(dev, "can't create nvram file? %d\n", retval);
623 pr_info("%s: alarms up to one %s%s\n",
624 cmos_rtc.rtc->dev.bus_id,
625 is_valid_irq(rtc_irq)
631 cmos_rtc.century ? ", y3k" : ""
637 if (is_valid_irq(rtc_irq))
638 free_irq(rtc_irq, cmos_rtc.rtc);
641 rtc_device_unregister(cmos_rtc.rtc);
643 release_region(ports->start, ports->end + 1 - ports->start);
647 static void cmos_do_shutdown(void)
649 unsigned char rtc_control;
651 spin_lock_irq(&rtc_lock);
652 rtc_control = CMOS_READ(RTC_CONTROL);
653 rtc_control &= ~(RTC_PIE|RTC_AIE|RTC_UIE);
654 CMOS_WRITE(rtc_control, RTC_CONTROL);
655 CMOS_READ(RTC_INTR_FLAGS);
656 spin_unlock_irq(&rtc_lock);
659 static void __exit cmos_do_remove(struct device *dev)
661 struct cmos_rtc *cmos = dev_get_drvdata(dev);
662 struct resource *ports;
666 sysfs_remove_bin_file(&dev->kobj, &nvram);
668 if (is_valid_irq(cmos->irq))
669 free_irq(cmos->irq, cmos->rtc);
671 rtc_device_unregister(cmos->rtc);
675 release_region(ports->start, ports->end + 1 - ports->start);
679 dev_set_drvdata(dev, NULL);
684 static int cmos_suspend(struct device *dev, pm_message_t mesg)
686 struct cmos_rtc *cmos = dev_get_drvdata(dev);
687 int do_wake = device_may_wakeup(dev);
690 /* only the alarm might be a wakeup event source */
691 spin_lock_irq(&rtc_lock);
692 cmos->suspend_ctrl = tmp = CMOS_READ(RTC_CONTROL);
693 if (tmp & (RTC_PIE|RTC_AIE|RTC_UIE)) {
694 unsigned char irqstat;
697 tmp &= ~(RTC_PIE|RTC_UIE);
699 tmp &= ~(RTC_PIE|RTC_AIE|RTC_UIE);
700 CMOS_WRITE(tmp, RTC_CONTROL);
701 irqstat = CMOS_READ(RTC_INTR_FLAGS);
702 irqstat &= (tmp & RTC_IRQMASK) | RTC_IRQF;
703 if (is_intr(irqstat))
704 rtc_update_irq(cmos->rtc, 1, irqstat);
706 spin_unlock_irq(&rtc_lock);
709 cmos->enabled_wake = 1;
713 enable_irq_wake(cmos->irq);
716 pr_debug("%s: suspend%s, ctrl %02x\n",
717 cmos_rtc.rtc->dev.bus_id,
718 (tmp & RTC_AIE) ? ", alarm may wake" : "",
724 static int cmos_resume(struct device *dev)
726 struct cmos_rtc *cmos = dev_get_drvdata(dev);
727 unsigned char tmp = cmos->suspend_ctrl;
729 /* re-enable any irqs previously active */
730 if (tmp & (RTC_PIE|RTC_AIE|RTC_UIE)) {
732 if (cmos->enabled_wake) {
736 disable_irq_wake(cmos->irq);
737 cmos->enabled_wake = 0;
740 spin_lock_irq(&rtc_lock);
741 CMOS_WRITE(tmp, RTC_CONTROL);
742 tmp = CMOS_READ(RTC_INTR_FLAGS);
743 tmp &= (cmos->suspend_ctrl & RTC_IRQMASK) | RTC_IRQF;
745 rtc_update_irq(cmos->rtc, 1, tmp);
746 spin_unlock_irq(&rtc_lock);
749 pr_debug("%s: resume, ctrl %02x\n",
750 cmos_rtc.rtc->dev.bus_id,
758 #define cmos_suspend NULL
759 #define cmos_resume NULL
762 /*----------------------------------------------------------------*/
764 /* On non-x86 systems, a "CMOS" RTC lives most naturally on platform_bus.
765 * ACPI systems always list these as PNPACPI devices, and pre-ACPI PCs
766 * probably list them in similar PNPBIOS tables; so PNP is more common.
768 * We don't use legacy "poke at the hardware" probing. Ancient PCs that
769 * predate even PNPBIOS should set up platform_bus devices.
774 #include <linux/pnp.h>
777 cmos_pnp_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
779 /* REVISIT paranoia argues for a shutdown notifier, since PNP
780 * drivers can't provide shutdown() methods to disable IRQs.
781 * Or better yet, fix PNP to allow those methods...
783 if (pnp_port_start(pnp,0) == 0x70 && !pnp_irq_valid(pnp,0))
784 /* Some machines contain a PNP entry for the RTC, but
785 * don't define the IRQ. It should always be safe to
786 * hardcode it in these cases
788 return cmos_do_probe(&pnp->dev, &pnp->res.port_resource[0], 8);
790 return cmos_do_probe(&pnp->dev,
791 &pnp->res.port_resource[0],
792 pnp->res.irq_resource[0].start);
795 static void __exit cmos_pnp_remove(struct pnp_dev *pnp)
797 cmos_do_remove(&pnp->dev);
802 static int cmos_pnp_suspend(struct pnp_dev *pnp, pm_message_t mesg)
804 return cmos_suspend(&pnp->dev, mesg);
807 static int cmos_pnp_resume(struct pnp_dev *pnp)
809 return cmos_resume(&pnp->dev);
813 #define cmos_pnp_suspend NULL
814 #define cmos_pnp_resume NULL
818 static const struct pnp_device_id rtc_ids[] = {
819 { .id = "PNP0b00", },
820 { .id = "PNP0b01", },
821 { .id = "PNP0b02", },
824 MODULE_DEVICE_TABLE(pnp, rtc_ids);
826 static struct pnp_driver cmos_pnp_driver = {
827 .name = (char *) driver_name,
829 .probe = cmos_pnp_probe,
830 .remove = __exit_p(cmos_pnp_remove),
832 /* flag ensures resume() gets called, and stops syslog spam */
833 .flags = PNP_DRIVER_RES_DO_NOT_CHANGE,
834 .suspend = cmos_pnp_suspend,
835 .resume = cmos_pnp_resume,
838 static int __init cmos_init(void)
840 return pnp_register_driver(&cmos_pnp_driver);
842 module_init(cmos_init);
844 static void __exit cmos_exit(void)
846 pnp_unregister_driver(&cmos_pnp_driver);
848 module_exit(cmos_exit);
852 /*----------------------------------------------------------------*/
854 /* Platform setup should have set up an RTC device, when PNP is
855 * unavailable ... this could happen even on (older) PCs.
858 static int __init cmos_platform_probe(struct platform_device *pdev)
860 return cmos_do_probe(&pdev->dev,
861 platform_get_resource(pdev, IORESOURCE_IO, 0),
862 platform_get_irq(pdev, 0));
865 static int __exit cmos_platform_remove(struct platform_device *pdev)
867 cmos_do_remove(&pdev->dev);
871 static void cmos_platform_shutdown(struct platform_device *pdev)
876 static struct platform_driver cmos_platform_driver = {
877 .remove = __exit_p(cmos_platform_remove),
878 .shutdown = cmos_platform_shutdown,
880 .name = (char *) driver_name,
881 .suspend = cmos_suspend,
882 .resume = cmos_resume,
886 static int __init cmos_init(void)
888 return platform_driver_probe(&cmos_platform_driver,
889 cmos_platform_probe);
891 module_init(cmos_init);
893 static void __exit cmos_exit(void)
895 platform_driver_unregister(&cmos_platform_driver);
897 module_exit(cmos_exit);
902 MODULE_AUTHOR("David Brownell");
903 MODULE_DESCRIPTION("Driver for PC-style 'CMOS' RTCs");
904 MODULE_LICENSE("GPL");