42 #include <linux/module.h>
44 #include <linux/rtc.h>
50 #define DRV_NAME "rs5c313"
51 #define DRV_VERSION "1.13"
53 #ifdef CONFIG_SH_LANDISK
58 #define SCSMR1 0xFFE00000
59 #define SCSCR1 0xFFE00008
60 #define SCSMR1_CA 0x80
61 #define SCSCR1_CKE 0x03
62 #define SCSPTR1 0xFFE0001C
63 #define SCSPTR1_EIO 0x80
64 #define SCSPTR1_SPB1IO 0x08
65 #define SCSPTR1_SPB1DT 0x04
66 #define SCSPTR1_SPB0IO 0x02
67 #define SCSPTR1_SPB0DT 0x01
69 #define SDA_OEN SCSPTR1_SPB1IO
70 #define SDA SCSPTR1_SPB1DT
71 #define SCL_OEN SCSPTR1_SPB0IO
72 #define SCL SCSPTR1_SPB0DT
75 #define RS5C313_CE 0xB0000003
78 #define RS5C313_CE_RTCCE 0x02
81 unsigned char scsptr1_data;
83 #define RS5C313_CEENABLE __raw_writeb(RS5C313_CE_RTCCE, RS5C313_CE);
84 #define RS5C313_CEDISABLE __raw_writeb(0x00, RS5C313_CE)
85 #define RS5C313_MISCOP __raw_writeb(0x02, 0xB0000008)
87 static void rs5c313_init_port(
void)
101 static void rs5c313_write_data(
unsigned char data)
105 for (i = 0; i < 8; i++) {
107 scsptr1_data = (scsptr1_data & ~
SDA) |
108 ((((0x80 >> i) & data) >> (7 - i)) << 2);
111 scsptr1_data |= SDA_OEN;
115 scsptr1_data &= ~
SCL;
122 scsptr1_data &= ~SDA_OEN;
126 static unsigned char rs5c313_read_data(
void)
129 unsigned char data = 0;
131 for (i = 0; i < 8; i++) {
135 scsptr1_data &= ~
SCL;
151 #define RS5C313_ADDR_SEC 0x00
152 #define RS5C313_ADDR_SEC10 0x01
153 #define RS5C313_ADDR_MIN 0x02
154 #define RS5C313_ADDR_MIN10 0x03
155 #define RS5C313_ADDR_HOUR 0x04
156 #define RS5C313_ADDR_HOUR10 0x05
157 #define RS5C313_ADDR_WEEK 0x06
158 #define RS5C313_ADDR_INTINTVREG 0x07
159 #define RS5C313_ADDR_DAY 0x08
160 #define RS5C313_ADDR_DAY10 0x09
161 #define RS5C313_ADDR_MON 0x0A
162 #define RS5C313_ADDR_MON10 0x0B
163 #define RS5C313_ADDR_YEAR 0x0C
164 #define RS5C313_ADDR_YEAR10 0x0D
165 #define RS5C313_ADDR_CNTREG 0x0E
166 #define RS5C313_ADDR_TESTREG 0x0F
169 #define RS5C313_CNTREG_ADJ_BSY 0x01
170 #define RS5C313_CNTREG_WTEN_XSTP 0x02
171 #define RS5C313_CNTREG_12_24 0x04
172 #define RS5C313_CNTREG_CTFG 0x08
175 #define RS5C313_TESTREG_TEST 0x01
178 #define RS5C313_CNTBIT_READ 0x40
179 #define RS5C313_CNTBIT_AD 0x20
180 #define RS5C313_CNTBIT_DT 0x10
182 static unsigned char rs5c313_read_reg(
unsigned char addr)
186 return rs5c313_read_data();
189 static void rs5c313_write_reg(
unsigned char addr,
unsigned char data)
197 static inline unsigned char rs5c313_read_cntreg(
void)
202 static inline void rs5c313_write_cntreg(
unsigned char data)
207 static inline void rs5c313_write_intintvreg(
unsigned char data)
222 rs5c313_write_cntreg(0x04);
231 dev_err(dev,
"%s: timeout error\n", __func__);
272 static int rs5c313_rtc_set_time(
struct device *dev,
struct rtc_time *tm)
283 rs5c313_write_cntreg(0x04);
292 dev_err(dev,
"%s: timeout error\n", __func__);
330 static void rs5c313_check_xstp_bit(
void)
338 rs5c313_write_intintvreg(0x00);
340 rs5c313_write_cntreg(0x07);
343 for (cnt = 0; cnt < 100; cnt++) {
354 rs5c313_rtc_set_time(
NULL, &tm);
363 .read_time = rs5c313_rtc_read_time,
364 .set_time = rs5c313_rtc_set_time,
375 platform_set_drvdata(pdev, rtc);
382 struct rtc_device *rtc = platform_get_drvdata( pdev );
394 .probe = rs5c313_rtc_probe,
398 static int __init rs5c313_rtc_init(
void)
407 rs5c313_check_xstp_bit();
412 static void __exit rs5c313_rtc_exit(
void)