2 * Dallas Semiconductors 1603 RTC driver
4 * Brian Murphy <brian@murphy.dk>
7 #include <linux/kernel.h>
8 #include <asm/lasat/lasat.h>
9 #include <linux/delay.h>
10 #include <asm/lasat/ds1603.h>
14 #define READ_TIME_CMD 0x81
15 #define SET_TIME_CMD 0x80
16 #define TRIMMER_SET_CMD 0xC0
17 #define TRIMMER_VALUE_MASK 0x38
18 #define TRIMMER_SHIFT 3
20 struct ds_defs *ds1603 = NULL;
22 /* HW specific register functions */
23 static void rtc_reg_write(unsigned long val)
28 static unsigned long rtc_reg_read(void)
30 unsigned long tmp = *ds1603->reg;
34 static unsigned long rtc_datareg_read(void)
36 unsigned long tmp = *ds1603->data_reg;
40 static void rtc_nrst_high(void)
42 rtc_reg_write(rtc_reg_read() | ds1603->rst);
45 static void rtc_nrst_low(void)
47 rtc_reg_write(rtc_reg_read() & ~ds1603->rst);
50 static void rtc_cycle_clock(unsigned long data)
55 if (ds1603->data_reversed)
56 data &= ~ds1603->data;
61 lasat_ndelay(250 + ds1603->huge_delay);
64 static void rtc_write_databit(unsigned int bit)
66 unsigned long data = rtc_reg_read();
67 if (ds1603->data_reversed)
72 data &= ~ds1603->data;
75 lasat_ndelay(50 + ds1603->huge_delay);
76 rtc_cycle_clock(data);
79 static unsigned int rtc_read_databit(void)
83 data = (rtc_datareg_read() & (1 << ds1603->data_read_shift))
84 >> ds1603->data_read_shift;
85 rtc_cycle_clock(rtc_reg_read());
89 static void rtc_write_byte(unsigned int byte)
93 for (i = 0; i<=7; i++) {
94 rtc_write_databit(byte & 1L);
99 static void rtc_write_word(unsigned long word)
103 for (i = 0; i<=31; i++) {
104 rtc_write_databit(word & 1L);
109 static unsigned long rtc_read_word(void)
112 unsigned long word = 0;
113 unsigned long shift = 0;
115 for (i = 0; i<=31; i++) {
116 word |= rtc_read_databit() << shift;
122 static void rtc_init_op(void)
126 rtc_reg_write(rtc_reg_read() & ~ds1603->clk);
131 static void rtc_end_op(void)
138 unsigned long ds1603_read(void)
142 rtc_write_byte(READ_TIME_CMD);
143 word = rtc_read_word();
148 int ds1603_set(unsigned long time)
151 rtc_write_byte(SET_TIME_CMD);
152 rtc_write_word(time);
158 void ds1603_set_trimmer(unsigned int trimval)
161 rtc_write_byte(((trimval << TRIMMER_SHIFT) & TRIMMER_VALUE_MASK)
162 | (TRIMMER_SET_CMD));
166 void ds1603_disable(void)
168 ds1603_set_trimmer(TRIMMER_DISABLE_RTC);
171 void ds1603_enable(void)
173 ds1603_set_trimmer(TRIMMER_DEFAULT);