ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / include / asm-i386 / upd4990a.h
1 /*
2  *  Architecture dependent definitions
3  *  for NEC uPD4990A serial I/O real-time clock.
4  *
5  *  Copyright 2001  TAKAI Kousuke <tak@kmc.kyoto-u.ac.jp>
6  *                  Kyoto University Microcomputer Club (KMC).
7  *
8  *  References:
9  *      uPD4990A serial I/O real-time clock users' manual (Japanese)
10  *      No. S12828JJ4V0UM00 (4th revision), NEC Corporation, 1999.
11  */
12
13 #ifndef _ASM_I386_uPD4990A_H
14 #define _ASM_I386_uPD4990A_H
15
16 #include <asm/io.h>
17
18 #define UPD4990A_IO             (0x0020)
19 #define UPD4990A_IO_DATAOUT     (0x0033)
20
21 #define UPD4990A_OUTPUT_DATA_CLK(data, clk)             \
22         outb((((data) & 1) << 5) | (((clk) & 1) << 4)   \
23               | UPD4990A_PAR_SERIAL_MODE, UPD4990A_IO)
24
25 #define UPD4990A_OUTPUT_CLK(clk)        UPD4990A_OUTPUT_DATA_CLK(0, (clk))
26
27 #define UPD4990A_OUTPUT_STROBE(stb) \
28         outb(((stb) << 3) | UPD4990A_PAR_SERIAL_MODE, UPD4990A_IO)
29
30 /*
31  * Note: udelay() is *not* usable for UPD4990A_DELAY because
32  *       the Linux kernel reads uPD4990A to set up system clock
33  *       before calibrating delay...
34  */
35 #define UPD4990A_DELAY(usec)                                            \
36         do {                                                            \
37                 if (__builtin_constant_p((usec)) && (usec) < 5) \
38                         __asm__ (".rept %c1\n\toutb %%al,%0\n\t.endr"   \
39                                  : : "N" (0x5F),                        \
40                                      "i" (((usec) * 10 + 5) / 6));      \
41                 else {                                                  \
42                         int _count = ((usec) * 10 + 5) / 6;             \
43                         __asm__ volatile ("1: outb %%al,%1\n\tloop 1b"  \
44                                           : "=c" (_count)               \
45                                           : "N" (0x5F), "0" (_count));  \
46                 }                                                       \
47         } while (0)
48
49 /* Caller should ignore all bits except bit0 */
50 #define UPD4990A_READ_DATA()    inb(UPD4990A_IO_DATAOUT)
51
52 #endif