mostek.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /* $Id: mostek.h,v 1.13 2001/01/11 15:07:09 davem Exp $
  2. * mostek.h: Describes the various Mostek time of day clock registers.
  3. *
  4. * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
  5. * Copyright (C) 1996 Thomas K. Dyas (tdyas@eden.rutgers.edu)
  6. * Added intersil code 05/25/98 Chris Davis (cdavis@cois.on.ca)
  7. */
  8. #ifndef _SPARC_MOSTEK_H
  9. #define _SPARC_MOSTEK_H
  10. #include <asm/idprom.h>
  11. #include <asm/io.h>
  12. /* M48T02 Register Map (adapted from Sun NVRAM/Hostid FAQ)
  13. *
  14. * Data
  15. * Address Function
  16. * Bit 7 Bit 6 Bit 5 Bit 4Bit 3 Bit 2 Bit 1 Bit 0
  17. * 7ff - - - - - - - - Year 00-99
  18. * 7fe 0 0 0 - - - - - Month 01-12
  19. * 7fd 0 0 - - - - - - Date 01-31
  20. * 7fc 0 FT 0 0 0 - - - Day 01-07
  21. * 7fb KS 0 - - - - - - Hours 00-23
  22. * 7fa 0 - - - - - - - Minutes 00-59
  23. * 7f9 ST - - - - - - - Seconds 00-59
  24. * 7f8 W R S - - - - - Control
  25. *
  26. * * ST is STOP BIT
  27. * * W is WRITE BIT
  28. * * R is READ BIT
  29. * * S is SIGN BIT
  30. * * FT is FREQ TEST BIT
  31. * * KS is KICK START BIT
  32. */
  33. /* The Mostek 48t02 real time clock and NVRAM chip. The registers
  34. * other than the control register are in binary coded decimal. Some
  35. * control bits also live outside the control register.
  36. */
  37. #define mostek_read(_addr) readb(_addr)
  38. #define mostek_write(_addr,_val) writeb(_val, _addr)
  39. #define MOSTEK_EEPROM 0x0000UL
  40. #define MOSTEK_IDPROM 0x07d8UL
  41. #define MOSTEK_CREG 0x07f8UL
  42. #define MOSTEK_SEC 0x07f9UL
  43. #define MOSTEK_MIN 0x07faUL
  44. #define MOSTEK_HOUR 0x07fbUL
  45. #define MOSTEK_DOW 0x07fcUL
  46. #define MOSTEK_DOM 0x07fdUL
  47. #define MOSTEK_MONTH 0x07feUL
  48. #define MOSTEK_YEAR 0x07ffUL
  49. struct mostek48t02 {
  50. volatile char eeprom[2008]; /* This is the eeprom, don't touch! */
  51. struct idprom idprom; /* The idprom lives here. */
  52. volatile unsigned char creg; /* Control register */
  53. volatile unsigned char sec; /* Seconds (0-59) */
  54. volatile unsigned char min; /* Minutes (0-59) */
  55. volatile unsigned char hour; /* Hour (0-23) */
  56. volatile unsigned char dow; /* Day of the week (1-7) */
  57. volatile unsigned char dom; /* Day of the month (1-31) */
  58. volatile unsigned char month; /* Month of year (1-12) */
  59. volatile unsigned char year; /* Year (0-99) */
  60. };
  61. extern spinlock_t mostek_lock;
  62. extern void __iomem *mstk48t02_regs;
  63. /* Control register values. */
  64. #define MSTK_CREG_WRITE 0x80 /* Must set this before placing values. */
  65. #define MSTK_CREG_READ 0x40 /* Stop updates to allow a clean read. */
  66. #define MSTK_CREG_SIGN 0x20 /* Slow/speed clock in calibration mode. */
  67. /* Control bits that live in the other registers. */
  68. #define MSTK_STOP 0x80 /* Stop the clock oscillator. (sec) */
  69. #define MSTK_KICK_START 0x80 /* Kick start the clock chip. (hour) */
  70. #define MSTK_FREQ_TEST 0x40 /* Frequency test mode. (day) */
  71. #define MSTK_YEAR_ZERO 1968 /* If year reg has zero, it is 1968. */
  72. #define MSTK_CVT_YEAR(yr) ((yr) + MSTK_YEAR_ZERO)
  73. /* Masks that define how much space each value takes up. */
  74. #define MSTK_SEC_MASK 0x7f
  75. #define MSTK_MIN_MASK 0x7f
  76. #define MSTK_HOUR_MASK 0x3f
  77. #define MSTK_DOW_MASK 0x07
  78. #define MSTK_DOM_MASK 0x3f
  79. #define MSTK_MONTH_MASK 0x1f
  80. #define MSTK_YEAR_MASK 0xffU
  81. /* Binary coded decimal conversion macros. */
  82. #define MSTK_REGVAL_TO_DECIMAL(x) (((x) & 0x0F) + 0x0A * ((x) >> 0x04))
  83. #define MSTK_DECIMAL_TO_REGVAL(x) ((((x) / 0x0A) << 0x04) + ((x) % 0x0A))
  84. /* Generic register set and get macros for internal use. */
  85. #define MSTK_GET(regs,var,mask) (MSTK_REGVAL_TO_DECIMAL(((struct mostek48t02 *)regs)->var & MSTK_ ## mask ## _MASK))
  86. #define MSTK_SET(regs,var,value,mask) do { ((struct mostek48t02 *)regs)->var &= ~(MSTK_ ## mask ## _MASK); ((struct mostek48t02 *)regs)->var |= MSTK_DECIMAL_TO_REGVAL(value) & (MSTK_ ## mask ## _MASK); } while (0)
  87. /* Macros to make register access easier on our fingers. These give you
  88. * the decimal value of the register requested if applicable. You pass
  89. * the a pointer to a 'struct mostek48t02'.
  90. */
  91. #define MSTK_REG_CREG(regs) (((struct mostek48t02 *)regs)->creg)
  92. #define MSTK_REG_SEC(regs) MSTK_GET(regs,sec,SEC)
  93. #define MSTK_REG_MIN(regs) MSTK_GET(regs,min,MIN)
  94. #define MSTK_REG_HOUR(regs) MSTK_GET(regs,hour,HOUR)
  95. #define MSTK_REG_DOW(regs) MSTK_GET(regs,dow,DOW)
  96. #define MSTK_REG_DOM(regs) MSTK_GET(regs,dom,DOM)
  97. #define MSTK_REG_MONTH(regs) MSTK_GET(regs,month,MONTH)
  98. #define MSTK_REG_YEAR(regs) MSTK_GET(regs,year,YEAR)
  99. #define MSTK_SET_REG_SEC(regs,value) MSTK_SET(regs,sec,value,SEC)
  100. #define MSTK_SET_REG_MIN(regs,value) MSTK_SET(regs,min,value,MIN)
  101. #define MSTK_SET_REG_HOUR(regs,value) MSTK_SET(regs,hour,value,HOUR)
  102. #define MSTK_SET_REG_DOW(regs,value) MSTK_SET(regs,dow,value,DOW)
  103. #define MSTK_SET_REG_DOM(regs,value) MSTK_SET(regs,dom,value,DOM)
  104. #define MSTK_SET_REG_MONTH(regs,value) MSTK_SET(regs,month,value,MONTH)
  105. #define MSTK_SET_REG_YEAR(regs,value) MSTK_SET(regs,year,value,YEAR)
  106. /* The Mostek 48t08 clock chip. Found on Sun4m's I think. It has the
  107. * same (basically) layout of the 48t02 chip except for the extra
  108. * NVRAM on board (8 KB against the 48t02's 2 KB).
  109. */
  110. struct mostek48t08 {
  111. char offset[6*1024]; /* Magic things may be here, who knows? */
  112. struct mostek48t02 regs; /* Here is what we are interested in. */
  113. };
  114. extern enum sparc_clock_type sp_clock_typ;
  115. #ifdef CONFIG_SUN4
  116. enum sparc_clock_type { MSTK48T02, MSTK48T08, \
  117. INTERSIL, MSTK_INVALID };
  118. #else
  119. enum sparc_clock_type { MSTK48T02, MSTK48T08, \
  120. MSTK_INVALID };
  121. #endif
  122. #ifdef CONFIG_SUN4
  123. /* intersil on a sun 4/260 code data from harris doc */
  124. struct intersil_dt {
  125. volatile unsigned char int_csec;
  126. volatile unsigned char int_hour;
  127. volatile unsigned char int_min;
  128. volatile unsigned char int_sec;
  129. volatile unsigned char int_month;
  130. volatile unsigned char int_day;
  131. volatile unsigned char int_year;
  132. volatile unsigned char int_dow;
  133. };
  134. struct intersil {
  135. struct intersil_dt clk;
  136. struct intersil_dt cmp;
  137. volatile unsigned char int_intr_reg;
  138. volatile unsigned char int_cmd_reg;
  139. };
  140. #define INTERSIL_STOP 0x0
  141. #define INTERSIL_START 0x8
  142. #define INTERSIL_INTR_DISABLE 0x0
  143. #define INTERSIL_INTR_ENABLE 0x10
  144. #define INTERSIL_32K 0x0
  145. #define INTERSIL_NORMAL 0x0
  146. #define INTERSIL_24H 0x4
  147. #define INTERSIL_INT_100HZ 0x2
  148. /* end of intersil info */
  149. #endif
  150. #endif /* !(_SPARC_MOSTEK_H) */