13 #include <linux/module.h>
14 #include <linux/kernel.h>
16 #include <linux/rtc.h>
20 #define DRV_NAME "rtc-ds1302"
21 #define DRV_VERSION "0.1.1"
23 #define RTC_CMD_READ 0x81
24 #define RTC_CMD_WRITE 0x80
26 #define RTC_ADDR_RAM0 0x20
27 #define RTC_ADDR_TCR 0x08
28 #define RTC_ADDR_YEAR 0x06
29 #define RTC_ADDR_DAY 0x05
30 #define RTC_ADDR_MON 0x04
31 #define RTC_ADDR_DATE 0x03
32 #define RTC_ADDR_HOUR 0x02
33 #define RTC_ADDR_MIN 0x01
34 #define RTC_ADDR_SEC 0x00
36 #ifdef CONFIG_SH_SECUREEDGE5410
40 #define RTC_RESET 0x1000
41 #define RTC_IODATA 0x0800
42 #define RTC_SCLK 0x0400
44 #define set_dp(x) SECUREEDGE_WRITE_IOPORT(x, 0x1c00)
45 #define get_dp() SECUREEDGE_READ_IOPORT()
46 #define ds1302_set_tx()
47 #define ds1302_set_rx()
49 static inline int ds1302_hw_init(
void)
54 static inline void ds1302_reset(
void)
56 set_dp(get_dp() & ~(RTC_RESET | RTC_IODATA | RTC_SCLK));
59 static inline void ds1302_clock(
void)
61 set_dp(get_dp() | RTC_SCLK);
62 set_dp(get_dp() & ~RTC_SCLK);
65 static inline void ds1302_start(
void)
67 set_dp(get_dp() | RTC_RESET);
70 static inline void ds1302_stop(
void)
72 set_dp(get_dp() & ~RTC_RESET);
75 static inline void ds1302_txbit(
int bit)
77 set_dp((get_dp() & ~RTC_IODATA) | (bit ? RTC_IODATA : 0));
80 static inline int ds1302_rxbit(
void)
82 return !!(get_dp() & RTC_IODATA);
86 #error "Add support for your platform"
89 static void ds1302_sendbits(
unsigned int val)
95 for (i = 8; (
i); i--, val >>= 1) {
96 ds1302_txbit(val & 0x1);
101 static unsigned int ds1302_recvbits(
void)
108 for (i = 0, val = 0; (i < 8); i++) {
109 val |= (ds1302_rxbit() <<
i);
116 static unsigned int ds1302_readbyte(
unsigned int addr)
124 val = ds1302_recvbits();
130 static void ds1302_writebyte(
unsigned int addr,
unsigned int val)
136 ds1302_sendbits(val);
153 dev_dbg(dev,
"%s: tm is secs=%d, mins=%d, hours=%d, "
154 "mday=%d, mon=%d, year=%d, wday=%d\n",
162 static int ds1302_rtc_set_time(
struct device *dev,
struct rtc_time *tm)
181 static int ds1302_rtc_ioctl(
struct device *dev,
unsigned int cmd,
185 #ifdef RTC_SET_CHARGE
203 .read_time = ds1302_rtc_read_time,
204 .set_time = ds1302_rtc_set_time,
205 .ioctl = ds1302_rtc_ioctl,
212 if (ds1302_hw_init()) {
213 dev_err(&pdev->
dev,
"Failed to init communication channel");
232 platform_set_drvdata(pdev, rtc);
239 struct rtc_device *rtc = platform_get_drvdata(pdev);
242 platform_set_drvdata(pdev,
NULL);
255 static int __init ds1302_rtc_init(
void)
260 static void __exit ds1302_rtc_exit(
void)