2 * rtc-ds1305.c -- driver for DS1305 and DS1306 SPI RTC chips
4 * Copyright (C) 2008 David Brownell
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/bcd.h>
14 #include <linux/slab.h>
15 #include <linux/rtc.h>
16 #include <linux/workqueue.h>
18 #include <linux/spi/spi.h>
19 #include <linux/spi/ds1305.h>
23 * Registers ... mask DS1305_WRITE into register address to write,
24 * otherwise you're reading it. All non-bitmask values are BCD.
26 #define DS1305_WRITE 0x80
29 /* RTC date/time ... the main special cases are that we:
30 * - Need fancy "hours" encoding in 12hour mode
31 * - Don't rely on the "day-of-week" field (or tm_wday)
32 * - Are a 21st-century clock (2000 <= year < 2100)
34 #define DS1305_RTC_LEN 7 /* bytes for RTC regs */
36 #define DS1305_SEC 0x00 /* register addresses */
37 #define DS1305_MIN 0x01
38 #define DS1305_HOUR 0x02
39 # define DS1305_HR_12 0x40 /* set == 12 hr mode */
40 # define DS1305_HR_PM 0x20 /* set == PM (12hr mode) */
41 #define DS1305_WDAY 0x03
42 #define DS1305_MDAY 0x04
43 #define DS1305_MON 0x05
44 #define DS1305_YEAR 0x06
47 /* The two alarms have only sec/min/hour/wday fields (ALM_LEN).
48 * DS1305_ALM_DISABLE disables a match field (some combos are bad).
50 * NOTE that since we don't use WDAY, we limit ourselves to alarms
51 * only one day into the future (vs potentially up to a week).
53 * NOTE ALSO that while we could generate once-a-second IRQs (UIE), we
54 * don't currently support them. We'd either need to do it only when
55 * no alarm is pending (not the standard model), or to use the second
56 * alarm (implying that this is a DS1305 not DS1306, *and* that either
57 * it's wired up a second IRQ we know, or that INTCN is set)
59 #define DS1305_ALM_LEN 4 /* bytes for ALM regs */
60 #define DS1305_ALM_DISABLE 0x80
62 #define DS1305_ALM0(r) (0x07 + (r)) /* register addresses */
63 #define DS1305_ALM1(r) (0x0b + (r))
66 /* three control registers */
67 #define DS1305_CONTROL_LEN 3 /* bytes of control regs */
69 #define DS1305_CONTROL 0x0f /* register addresses */
70 # define DS1305_nEOSC 0x80 /* low enables oscillator */
71 # define DS1305_WP 0x40 /* write protect */
72 # define DS1305_INTCN 0x04 /* clear == only int0 used */
73 # define DS1306_1HZ 0x04 /* enable 1Hz output */
74 # define DS1305_AEI1 0x02 /* enable ALM1 IRQ */
75 # define DS1305_AEI0 0x01 /* enable ALM0 IRQ */
76 #define DS1305_STATUS 0x10
77 /* status has just AEIx bits, mirrored as IRQFx */
78 #define DS1305_TRICKLE 0x11
79 /* trickle bits are defined in <linux/spi/ds1305.h> */
81 /* a bunch of NVRAM */
82 #define DS1305_NVRAM_LEN 96 /* bytes of NVRAM */
84 #define DS1305_NVRAM 0x20 /* register addresses */
88 struct spi_device *spi;
89 struct rtc_device *rtc;
91 struct work_struct work;
94 #define FLAG_EXITING 0
97 u8 ctrl[DS1305_CONTROL_LEN];
101 /*----------------------------------------------------------------------*/
104 * Utilities ... tolerate 12-hour AM/PM notation in case of non-Linux
105 * software (like a bootloader) which may require it.
108 static unsigned bcd2hour(u8 bcd)
110 if (bcd & DS1305_HR_12) {
113 bcd &= ~DS1305_HR_12;
114 if (bcd & DS1305_HR_PM) {
116 bcd &= ~DS1305_HR_PM;
118 hour += bcd2bin(bcd);
124 static u8 hour2bcd(bool hr12, int hour)
129 return DS1305_HR_12 | bin2bcd(hour);
131 return DS1305_HR_12 | DS1305_HR_PM | bin2bcd(hour);
133 return bin2bcd(hour);
136 /*----------------------------------------------------------------------*/
139 * Interface to RTC framework
142 #ifdef CONFIG_RTC_INTF_DEV
145 * Context: caller holds rtc->ops_lock (to protect ds1305->ctrl)
147 static int ds1305_ioctl(struct device *dev, unsigned cmd, unsigned long arg)
149 struct ds1305 *ds1305 = dev_get_drvdata(dev);
151 int status = -ENOIOCTLCMD;
153 buf[0] = DS1305_WRITE | DS1305_CONTROL;
154 buf[1] = ds1305->ctrl[0];
159 if (!(buf[1] & DS1305_AEI0))
161 buf[1] &= ~DS1305_AEI0;
166 if (ds1305->ctrl[0] & DS1305_AEI0)
168 buf[1] |= DS1305_AEI0;
172 status = spi_write_then_read(ds1305->spi, buf, sizeof buf,
175 ds1305->ctrl[0] = buf[1];
183 #define ds1305_ioctl NULL
187 * Get/set of date and time is pretty normal.
190 static int ds1305_get_time(struct device *dev, struct rtc_time *time)
192 struct ds1305 *ds1305 = dev_get_drvdata(dev);
193 u8 addr = DS1305_SEC;
194 u8 buf[DS1305_RTC_LEN];
197 /* Use write-then-read to get all the date/time registers
198 * since dma from stack is nonportable
200 status = spi_write_then_read(ds1305->spi, &addr, sizeof addr,
205 dev_vdbg(dev, "%s: %02x %02x %02x, %02x %02x %02x %02x\n",
206 "read", buf[0], buf[1], buf[2], buf[3],
207 buf[4], buf[5], buf[6]);
209 /* Decode the registers */
210 time->tm_sec = bcd2bin(buf[DS1305_SEC]);
211 time->tm_min = bcd2bin(buf[DS1305_MIN]);
212 time->tm_hour = bcd2hour(buf[DS1305_HOUR]);
213 time->tm_wday = buf[DS1305_WDAY] - 1;
214 time->tm_mday = bcd2bin(buf[DS1305_MDAY]);
215 time->tm_mon = bcd2bin(buf[DS1305_MON]) - 1;
216 time->tm_year = bcd2bin(buf[DS1305_YEAR]) + 100;
218 dev_vdbg(dev, "%s secs=%d, mins=%d, "
219 "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n",
220 "read", time->tm_sec, time->tm_min,
221 time->tm_hour, time->tm_mday,
222 time->tm_mon, time->tm_year, time->tm_wday);
224 /* Time may not be set */
225 return rtc_valid_tm(time);
228 static int ds1305_set_time(struct device *dev, struct rtc_time *time)
230 struct ds1305 *ds1305 = dev_get_drvdata(dev);
231 u8 buf[1 + DS1305_RTC_LEN];
234 dev_vdbg(dev, "%s secs=%d, mins=%d, "
235 "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n",
236 "write", time->tm_sec, time->tm_min,
237 time->tm_hour, time->tm_mday,
238 time->tm_mon, time->tm_year, time->tm_wday);
240 /* Write registers starting at the first time/date address. */
241 *bp++ = DS1305_WRITE | DS1305_SEC;
243 *bp++ = bin2bcd(time->tm_sec);
244 *bp++ = bin2bcd(time->tm_min);
245 *bp++ = hour2bcd(ds1305->hr12, time->tm_hour);
246 *bp++ = (time->tm_wday < 7) ? (time->tm_wday + 1) : 1;
247 *bp++ = bin2bcd(time->tm_mday);
248 *bp++ = bin2bcd(time->tm_mon + 1);
249 *bp++ = bin2bcd(time->tm_year - 100);
251 dev_dbg(dev, "%s: %02x %02x %02x, %02x %02x %02x %02x\n",
252 "write", buf[1], buf[2], buf[3],
253 buf[4], buf[5], buf[6], buf[7]);
255 /* use write-then-read since dma from stack is nonportable */
256 return spi_write_then_read(ds1305->spi, buf, sizeof buf,
261 * Get/set of alarm is a bit funky:
263 * - First there's the inherent raciness of getting the (partitioned)
264 * status of an alarm that could trigger while we're reading parts
267 * - Second there's its limited range (we could increase it a bit by
268 * relying on WDAY), which means it will easily roll over.
270 * - Third there's the choice of two alarms and alarm signals.
271 * Here we use ALM0 and expect that nINT0 (open drain) is used;
272 * that's the only real option for DS1306 runtime alarms, and is
275 * - Fourth, there's also ALM1, and a second interrupt signal:
276 * + On DS1305 ALM1 uses nINT1 (when INTCN=1) else nINT0;
277 * + On DS1306 ALM1 only uses INT1 (an active high pulse)
278 * and it won't work when VCC1 is active.
280 * So to be most general, we should probably set both alarms to the
281 * same value, letting ALM1 be the wakeup event source on DS1306
282 * and handling several wiring options on DS1305.
284 * - Fifth, we support the polled mode (as well as possible; why not?)
285 * even when no interrupt line is wired to an IRQ.
289 * Context: caller holds rtc->ops_lock (to protect ds1305->ctrl)
291 static int ds1305_get_alarm(struct device *dev, struct rtc_wkalrm *alm)
293 struct ds1305 *ds1305 = dev_get_drvdata(dev);
294 struct spi_device *spi = ds1305->spi;
297 u8 buf[DS1305_ALM_LEN];
299 /* Refresh control register cache BEFORE reading ALM0 registers,
300 * since reading alarm registers acks any pending IRQ. That
301 * makes returning "pending" status a bit of a lie, but that bit
302 * of EFI status is at best fragile anyway (given IRQ handlers).
304 addr = DS1305_CONTROL;
305 status = spi_write_then_read(spi, &addr, sizeof addr,
306 ds1305->ctrl, sizeof ds1305->ctrl);
310 alm->enabled = !!(ds1305->ctrl[0] & DS1305_AEI0);
311 alm->pending = !!(ds1305->ctrl[1] & DS1305_AEI0);
313 /* get and check ALM0 registers */
314 addr = DS1305_ALM0(DS1305_SEC);
315 status = spi_write_then_read(spi, &addr, sizeof addr,
320 dev_vdbg(dev, "%s: %02x %02x %02x %02x\n",
321 "alm0 read", buf[DS1305_SEC], buf[DS1305_MIN],
322 buf[DS1305_HOUR], buf[DS1305_WDAY]);
324 if ((DS1305_ALM_DISABLE & buf[DS1305_SEC])
325 || (DS1305_ALM_DISABLE & buf[DS1305_MIN])
326 || (DS1305_ALM_DISABLE & buf[DS1305_HOUR]))
329 /* Stuff these values into alm->time and let RTC framework code
330 * fill in the rest ... and also handle rollover to tomorrow when
333 alm->time.tm_sec = bcd2bin(buf[DS1305_SEC]);
334 alm->time.tm_min = bcd2bin(buf[DS1305_MIN]);
335 alm->time.tm_hour = bcd2hour(buf[DS1305_HOUR]);
336 alm->time.tm_mday = -1;
337 alm->time.tm_mon = -1;
338 alm->time.tm_year = -1;
339 /* next three fields are unused by Linux */
340 alm->time.tm_wday = -1;
341 alm->time.tm_mday = -1;
342 alm->time.tm_isdst = -1;
348 * Context: caller holds rtc->ops_lock (to protect ds1305->ctrl)
350 static int ds1305_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
352 struct ds1305 *ds1305 = dev_get_drvdata(dev);
353 struct spi_device *spi = ds1305->spi;
354 unsigned long now, later;
357 u8 buf[1 + DS1305_ALM_LEN];
359 /* convert desired alarm to time_t */
360 status = rtc_tm_to_time(&alm->time, &later);
364 /* Read current time as time_t */
365 status = ds1305_get_time(dev, &tm);
368 status = rtc_tm_to_time(&tm, &now);
372 /* make sure alarm fires within the next 24 hours */
375 if ((later - now) > 24 * 60 * 60)
378 /* disable alarm if needed */
379 if (ds1305->ctrl[0] & DS1305_AEI0) {
380 ds1305->ctrl[0] &= ~DS1305_AEI0;
382 buf[0] = DS1305_WRITE | DS1305_CONTROL;
383 buf[1] = ds1305->ctrl[0];
384 status = spi_write_then_read(ds1305->spi, buf, 2, NULL, 0);
390 buf[0] = DS1305_WRITE | DS1305_ALM0(DS1305_SEC);
391 buf[1 + DS1305_SEC] = bin2bcd(alm->time.tm_sec);
392 buf[1 + DS1305_MIN] = bin2bcd(alm->time.tm_min);
393 buf[1 + DS1305_HOUR] = hour2bcd(ds1305->hr12, alm->time.tm_hour);
394 buf[1 + DS1305_WDAY] = DS1305_ALM_DISABLE;
396 dev_dbg(dev, "%s: %02x %02x %02x %02x\n",
397 "alm0 write", buf[1 + DS1305_SEC], buf[1 + DS1305_MIN],
398 buf[1 + DS1305_HOUR], buf[1 + DS1305_WDAY]);
400 status = spi_write_then_read(spi, buf, sizeof buf, NULL, 0);
404 /* enable alarm if requested */
406 ds1305->ctrl[0] |= DS1305_AEI0;
408 buf[0] = DS1305_WRITE | DS1305_CONTROL;
409 buf[1] = ds1305->ctrl[0];
410 status = spi_write_then_read(ds1305->spi, buf, 2, NULL, 0);
416 #ifdef CONFIG_PROC_FS
418 static int ds1305_proc(struct device *dev, struct seq_file *seq)
420 struct ds1305 *ds1305 = dev_get_drvdata(dev);
422 char *resistors = "";
424 /* ctrl[2] is treated as read-only; no locking needed */
425 if ((ds1305->ctrl[2] & 0xf0) == DS1305_TRICKLE_MAGIC) {
426 switch (ds1305->ctrl[2] & 0x0c) {
427 case DS1305_TRICKLE_DS2:
428 diodes = "2 diodes, ";
430 case DS1305_TRICKLE_DS1:
431 diodes = "1 diode, ";
436 switch (ds1305->ctrl[2] & 0x03) {
437 case DS1305_TRICKLE_2K:
438 resistors = "2k Ohm";
440 case DS1305_TRICKLE_4K:
441 resistors = "4k Ohm";
443 case DS1305_TRICKLE_8K:
444 resistors = "8k Ohm";
453 return seq_printf(seq,
454 "trickle_charge\t: %s%s\n",
459 #define ds1305_proc NULL
462 static const struct rtc_class_ops ds1305_ops = {
463 .ioctl = ds1305_ioctl,
464 .read_time = ds1305_get_time,
465 .set_time = ds1305_set_time,
466 .read_alarm = ds1305_get_alarm,
467 .set_alarm = ds1305_set_alarm,
471 static void ds1305_work(struct work_struct *work)
473 struct ds1305 *ds1305 = container_of(work, struct ds1305, work);
474 struct mutex *lock = &ds1305->rtc->ops_lock;
475 struct spi_device *spi = ds1305->spi;
479 /* lock to protect ds1305->ctrl */
482 /* Disable the IRQ, and clear its status ... for now, we "know"
483 * that if more than one alarm is active, they're in sync.
484 * Note that reading ALM data registers also clears IRQ status.
486 ds1305->ctrl[0] &= ~(DS1305_AEI1 | DS1305_AEI0);
489 buf[0] = DS1305_WRITE | DS1305_CONTROL;
490 buf[1] = ds1305->ctrl[0];
493 status = spi_write_then_read(spi, buf, sizeof buf,
496 dev_dbg(&spi->dev, "clear irq --> %d\n", status);
500 if (!test_bit(FLAG_EXITING, &ds1305->flags))
501 enable_irq(spi->irq);
503 rtc_update_irq(ds1305->rtc, 1, RTC_AF | RTC_IRQF);
507 * This "real" IRQ handler hands off to a workqueue mostly to allow
508 * mutex locking for ds1305->ctrl ... unlike I2C, we could issue async
509 * I/O requests in IRQ context (to clear the IRQ status).
511 static irqreturn_t ds1305_irq(int irq, void *p)
513 struct ds1305 *ds1305 = p;
516 schedule_work(&ds1305->work);
520 /*----------------------------------------------------------------------*/
523 * Interface for NVRAM
526 static void msg_init(struct spi_message *m, struct spi_transfer *x,
527 u8 *addr, size_t count, char *tx, char *rx)
530 memset(x, 0, 2 * sizeof(*x));
534 spi_message_add_tail(x, m);
541 spi_message_add_tail(x, m);
545 ds1305_nvram_read(struct kobject *kobj, struct bin_attribute *attr,
546 char *buf, loff_t off, size_t count)
548 struct spi_device *spi;
550 struct spi_message m;
551 struct spi_transfer x[2];
554 spi = container_of(kobj, struct spi_device, dev.kobj);
556 if (unlikely(off >= DS1305_NVRAM_LEN))
558 if (count >= DS1305_NVRAM_LEN)
559 count = DS1305_NVRAM_LEN;
560 if ((off + count) > DS1305_NVRAM_LEN)
561 count = DS1305_NVRAM_LEN - off;
562 if (unlikely(!count))
565 addr = DS1305_NVRAM + off;
566 msg_init(&m, x, &addr, count, NULL, buf);
568 status = spi_sync(spi, &m);
570 dev_err(&spi->dev, "nvram %s error %d\n", "read", status);
571 return (status < 0) ? status : count;
575 ds1305_nvram_write(struct kobject *kobj, struct bin_attribute *attr,
576 char *buf, loff_t off, size_t count)
578 struct spi_device *spi;
580 struct spi_message m;
581 struct spi_transfer x[2];
584 spi = container_of(kobj, struct spi_device, dev.kobj);
586 if (unlikely(off >= DS1305_NVRAM_LEN))
588 if (count >= DS1305_NVRAM_LEN)
589 count = DS1305_NVRAM_LEN;
590 if ((off + count) > DS1305_NVRAM_LEN)
591 count = DS1305_NVRAM_LEN - off;
592 if (unlikely(!count))
595 addr = (DS1305_WRITE | DS1305_NVRAM) + off;
596 msg_init(&m, x, &addr, count, buf, NULL);
598 status = spi_sync(spi, &m);
600 dev_err(&spi->dev, "nvram %s error %d\n", "write", status);
601 return (status < 0) ? status : count;
604 static struct bin_attribute nvram = {
605 .attr.name = "nvram",
606 .attr.mode = S_IRUGO | S_IWUSR,
607 .read = ds1305_nvram_read,
608 .write = ds1305_nvram_write,
609 .size = DS1305_NVRAM_LEN,
612 /*----------------------------------------------------------------------*/
615 * Interface to SPI stack
618 static int __devinit ds1305_probe(struct spi_device *spi)
620 struct ds1305 *ds1305;
623 struct ds1305_platform_data *pdata = spi->dev.platform_data;
624 bool write_ctrl = false;
626 /* Sanity check board setup data. This may be hooked up
627 * in 3wire mode, but we don't care. Note that unless
628 * there's an inverter in place, this needs SPI_CS_HIGH!
630 if ((spi->bits_per_word && spi->bits_per_word != 8)
631 || (spi->max_speed_hz > 2000000)
632 || !(spi->mode & SPI_CPHA))
635 /* set up driver data */
636 ds1305 = kzalloc(sizeof *ds1305, GFP_KERNEL);
640 spi_set_drvdata(spi, ds1305);
642 /* read and cache control registers */
643 addr = DS1305_CONTROL;
644 status = spi_write_then_read(spi, &addr, sizeof addr,
645 ds1305->ctrl, sizeof ds1305->ctrl);
647 dev_dbg(&spi->dev, "can't %s, %d\n",
652 dev_dbg(&spi->dev, "ctrl %s: %02x %02x %02x\n",
653 "read", ds1305->ctrl[0],
654 ds1305->ctrl[1], ds1305->ctrl[2]);
656 /* Sanity check register values ... partially compensating for the
657 * fact that SPI has no device handshake. A pullup on MISO would
658 * make these tests fail; but not all systems will have one. If
659 * some register is neither 0x00 nor 0xff, a chip is likely there.
661 if ((ds1305->ctrl[0] & 0x38) != 0 || (ds1305->ctrl[1] & 0xfc) != 0) {
662 dev_dbg(&spi->dev, "RTC chip is not present\n");
666 if (ds1305->ctrl[2] == 0)
667 dev_dbg(&spi->dev, "chip may not be present\n");
669 /* enable writes if needed ... if we were paranoid it would
670 * make sense to enable them only when absolutely necessary.
672 if (ds1305->ctrl[0] & DS1305_WP) {
675 ds1305->ctrl[0] &= ~DS1305_WP;
677 buf[0] = DS1305_WRITE | DS1305_CONTROL;
678 buf[1] = ds1305->ctrl[0];
679 status = spi_write_then_read(spi, buf, sizeof buf, NULL, 0);
681 dev_dbg(&spi->dev, "clear WP --> %d\n", status);
686 /* on DS1305, maybe start oscillator; like most low power
687 * oscillators, it may take a second to stabilize
689 if (ds1305->ctrl[0] & DS1305_nEOSC) {
690 ds1305->ctrl[0] &= ~DS1305_nEOSC;
692 dev_warn(&spi->dev, "SET TIME!\n");
695 /* ack any pending IRQs */
696 if (ds1305->ctrl[1]) {
701 /* this may need one-time (re)init */
703 /* maybe enable trickle charge */
704 if (((ds1305->ctrl[2] & 0xf0) != DS1305_TRICKLE_MAGIC)) {
705 ds1305->ctrl[2] = DS1305_TRICKLE_MAGIC
710 /* on DS1306, configure 1 Hz signal */
711 if (pdata->is_ds1306) {
713 if (!(ds1305->ctrl[0] & DS1306_1HZ)) {
714 ds1305->ctrl[0] |= DS1306_1HZ;
718 if (ds1305->ctrl[0] & DS1306_1HZ) {
719 ds1305->ctrl[0] &= ~DS1306_1HZ;
729 buf[0] = DS1305_WRITE | DS1305_CONTROL;
730 buf[1] = ds1305->ctrl[0];
731 buf[2] = ds1305->ctrl[1];
732 buf[3] = ds1305->ctrl[2];
733 status = spi_write_then_read(spi, buf, sizeof buf, NULL, 0);
735 dev_dbg(&spi->dev, "can't %s, %d\n",
740 dev_dbg(&spi->dev, "ctrl %s: %02x %02x %02x\n",
741 "write", ds1305->ctrl[0],
742 ds1305->ctrl[1], ds1305->ctrl[2]);
745 /* see if non-Linux software set up AM/PM mode */
747 status = spi_write_then_read(spi, &addr, sizeof addr,
748 &value, sizeof value);
750 dev_dbg(&spi->dev, "read HOUR --> %d\n", status);
754 ds1305->hr12 = (DS1305_HR_12 & value) != 0;
756 dev_dbg(&spi->dev, "AM/PM\n");
758 /* register RTC ... from here on, ds1305->ctrl needs locking */
759 ds1305->rtc = rtc_device_register("ds1305", &spi->dev,
760 &ds1305_ops, THIS_MODULE);
761 if (IS_ERR(ds1305->rtc)) {
762 status = PTR_ERR(ds1305->rtc);
763 dev_dbg(&spi->dev, "register rtc --> %d\n", status);
767 /* Maybe set up alarm IRQ; be ready to handle it triggering right
768 * away. NOTE that we don't share this. The signal is active low,
769 * and we can't ack it before a SPI message delay. We temporarily
770 * disable the IRQ until it's acked, which lets us work with more
771 * IRQ trigger modes (not all IRQ controllers can do falling edge).
774 INIT_WORK(&ds1305->work, ds1305_work);
775 status = request_irq(spi->irq, ds1305_irq,
776 0, dev_name(&ds1305->rtc->dev), ds1305);
778 dev_dbg(&spi->dev, "request_irq %d --> %d\n",
783 device_set_wakeup_capable(&spi->dev, 1);
787 status = sysfs_create_bin_file(&spi->dev.kobj, &nvram);
789 dev_dbg(&spi->dev, "register nvram --> %d\n", status);
796 free_irq(spi->irq, ds1305);
798 rtc_device_unregister(ds1305->rtc);
804 static int __devexit ds1305_remove(struct spi_device *spi)
806 struct ds1305 *ds1305 = spi_get_drvdata(spi);
808 sysfs_remove_bin_file(&spi->dev.kobj, &nvram);
810 /* carefully shut down irq and workqueue, if present */
812 set_bit(FLAG_EXITING, &ds1305->flags);
813 free_irq(spi->irq, ds1305);
814 flush_scheduled_work();
817 rtc_device_unregister(ds1305->rtc);
818 spi_set_drvdata(spi, NULL);
823 static struct spi_driver ds1305_driver = {
824 .driver.name = "rtc-ds1305",
825 .driver.owner = THIS_MODULE,
826 .probe = ds1305_probe,
827 .remove = __devexit_p(ds1305_remove),
828 /* REVISIT add suspend/resume */
831 static int __init ds1305_init(void)
833 return spi_register_driver(&ds1305_driver);
835 module_init(ds1305_init);
837 static void __exit ds1305_exit(void)
839 spi_unregister_driver(&ds1305_driver);
841 module_exit(ds1305_exit);
843 MODULE_DESCRIPTION("RTC driver for DS1305 and DS1306 chips");
844 MODULE_LICENSE("GPL");
845 MODULE_ALIAS("spi:rtc-ds1305");