Select Git revision
rtc-ds1305.c 20.29 KiB
/*
* rtc-ds1305.c -- driver for DS1305 and DS1306 SPI RTC chips
*
* Copyright (C) 2008 David Brownell
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
*/
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/bcd.h>
#include <linux/slab.h>
#include <linux/rtc.h>
#include <linux/workqueue.h>
#include <linux/spi/spi.h>
#include <linux/spi/ds1305.h>
#include <linux/module.h>
/*
* Registers ... mask DS1305_WRITE into register address to write,
* otherwise you're reading it. All non-bitmask values are BCD.
*/
#define DS1305_WRITE 0x80
/* RTC date/time ... the main special cases are that we:
* - Need fancy "hours" encoding in 12hour mode
* - Don't rely on the "day-of-week" field (or tm_wday)
* - Are a 21st-century clock (2000 <= year < 2100)
*/
#define DS1305_RTC_LEN 7 /* bytes for RTC regs */
#define DS1305_SEC 0x00 /* register addresses */
#define DS1305_MIN 0x01
#define DS1305_HOUR 0x02
# define DS1305_HR_12 0x40 /* set == 12 hr mode */
# define DS1305_HR_PM 0x20 /* set == PM (12hr mode) */
#define DS1305_WDAY 0x03
#define DS1305_MDAY 0x04
#define DS1305_MON 0x05
#define DS1305_YEAR 0x06
/* The two alarms have only sec/min/hour/wday fields (ALM_LEN).
* DS1305_ALM_DISABLE disables a match field (some combos are bad).
*
* NOTE that since we don't use WDAY, we limit ourselves to alarms
* only one day into the future (vs potentially up to a week).
*
* NOTE ALSO that while we could generate once-a-second IRQs (UIE), we
* don't currently support them. We'd either need to do it only when
* no alarm is pending (not the standard model), or to use the second
* alarm (implying that this is a DS1305 not DS1306, *and* that either
* it's wired up a second IRQ we know, or that INTCN is set)
*/
#define DS1305_ALM_LEN 4 /* bytes for ALM regs */
#define DS1305_ALM_DISABLE 0x80
#define DS1305_ALM0(r) (0x07 + (r)) /* register addresses */
#define DS1305_ALM1(r) (0x0b + (r))
/* three control registers */
#define DS1305_CONTROL_LEN 3 /* bytes of control regs */
#define DS1305_CONTROL 0x0f /* register addresses */