mostek_64.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /* mostek.h: Describes the various Mostek time of day clock registers.
  2. *
  3. * Copyright (C) 1995 David S. Miller (davem@davemloft.net)
  4. * Copyright (C) 1996 Thomas K. Dyas (tdyas@eden.rutgers.edu)
  5. */
  6. #ifndef _SPARC64_MOSTEK_H
  7. #define _SPARC64_MOSTEK_H
  8. #include <asm/idprom.h>
  9. /* M48T02 Register Map (adapted from Sun NVRAM/Hostid FAQ)
  10. *
  11. * Data
  12. * Address Function
  13. * Bit 7 Bit 6 Bit 5 Bit 4Bit 3 Bit 2 Bit 1 Bit 0
  14. * 7ff - - - - - - - - Year 00-99
  15. * 7fe 0 0 0 - - - - - Month 01-12
  16. * 7fd 0 0 - - - - - - Date 01-31
  17. * 7fc 0 FT 0 0 0 - - - Day 01-07
  18. * 7fb KS 0 - - - - - - Hours 00-23
  19. * 7fa 0 - - - - - - - Minutes 00-59
  20. * 7f9 ST - - - - - - - Seconds 00-59
  21. * 7f8 W R S - - - - - Control
  22. *
  23. * * ST is STOP BIT
  24. * * W is WRITE BIT
  25. * * R is READ BIT
  26. * * S is SIGN BIT
  27. * * FT is FREQ TEST BIT
  28. * * KS is KICK START BIT
  29. */
  30. /* The Mostek 48t02 real time clock and NVRAM chip. The registers
  31. * other than the control register are in binary coded decimal. Some
  32. * control bits also live outside the control register.
  33. *
  34. * We now deal with physical addresses for I/O to the chip. -DaveM
  35. */
  36. static inline u8 mostek_read(void __iomem *addr)
  37. {
  38. u8 ret;
  39. __asm__ __volatile__("lduba [%1] %2, %0"
  40. : "=r" (ret)
  41. : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
  42. return ret;
  43. }
  44. static inline void mostek_write(void __iomem *addr, u8 val)
  45. {
  46. __asm__ __volatile__("stba %0, [%1] %2"
  47. : /* no outputs */
  48. : "r" (val), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
  49. }
  50. #define MOSTEK_EEPROM 0x0000UL
  51. #define MOSTEK_IDPROM 0x07d8UL
  52. #define MOSTEK_CREG 0x07f8UL
  53. #define MOSTEK_SEC 0x07f9UL
  54. #define MOSTEK_MIN 0x07faUL
  55. #define MOSTEK_HOUR 0x07fbUL
  56. #define MOSTEK_DOW 0x07fcUL
  57. #define MOSTEK_DOM 0x07fdUL
  58. #define MOSTEK_MONTH 0x07feUL
  59. #define MOSTEK_YEAR 0x07ffUL
  60. extern spinlock_t mostek_lock;
  61. extern void __iomem *mstk48t02_regs;
  62. /* Control register values. */
  63. #define MSTK_CREG_WRITE 0x80 /* Must set this before placing values. */
  64. #define MSTK_CREG_READ 0x40 /* Stop updates to allow a clean read. */
  65. #define MSTK_CREG_SIGN 0x20 /* Slow/speed clock in calibration mode. */
  66. /* Control bits that live in the other registers. */
  67. #define MSTK_STOP 0x80 /* Stop the clock oscillator. (sec) */
  68. #define MSTK_KICK_START 0x80 /* Kick start the clock chip. (hour) */
  69. #define MSTK_FREQ_TEST 0x40 /* Frequency test mode. (day) */
  70. #define MSTK_YEAR_ZERO 1968 /* If year reg has zero, it is 1968. */
  71. #define MSTK_CVT_YEAR(yr) ((yr) + MSTK_YEAR_ZERO)
  72. /* Masks that define how much space each value takes up. */
  73. #define MSTK_SEC_MASK 0x7f
  74. #define MSTK_MIN_MASK 0x7f
  75. #define MSTK_HOUR_MASK 0x3f
  76. #define MSTK_DOW_MASK 0x07
  77. #define MSTK_DOM_MASK 0x3f
  78. #define MSTK_MONTH_MASK 0x1f
  79. #define MSTK_YEAR_MASK 0xffU
  80. /* Binary coded decimal conversion macros. */
  81. #define MSTK_REGVAL_TO_DECIMAL(x) (((x) & 0x0F) + 0x0A * ((x) >> 0x04))
  82. #define MSTK_DECIMAL_TO_REGVAL(x) ((((x) / 0x0A) << 0x04) + ((x) % 0x0A))
  83. /* Generic register set and get macros for internal use. */
  84. #define MSTK_GET(regs,name) \
  85. (MSTK_REGVAL_TO_DECIMAL(mostek_read(regs + MOSTEK_ ## name) & MSTK_ ## name ## _MASK))
  86. #define MSTK_SET(regs,name,value) \
  87. do { u8 __val = mostek_read(regs + MOSTEK_ ## name); \
  88. __val &= ~(MSTK_ ## name ## _MASK); \
  89. __val |= (MSTK_DECIMAL_TO_REGVAL(value) & \
  90. (MSTK_ ## name ## _MASK)); \
  91. mostek_write(regs + MOSTEK_ ## name, __val); \
  92. } while(0)
  93. /* Macros to make register access easier on our fingers. These give you
  94. * the decimal value of the register requested if applicable. You pass
  95. * the a pointer to a 'struct mostek48t02'.
  96. */
  97. #define MSTK_REG_CREG(regs) (mostek_read((regs) + MOSTEK_CREG))
  98. #define MSTK_REG_SEC(regs) MSTK_GET(regs,SEC)
  99. #define MSTK_REG_MIN(regs) MSTK_GET(regs,MIN)
  100. #define MSTK_REG_HOUR(regs) MSTK_GET(regs,HOUR)
  101. #define MSTK_REG_DOW(regs) MSTK_GET(regs,DOW)
  102. #define MSTK_REG_DOM(regs) MSTK_GET(regs,DOM)
  103. #define MSTK_REG_MONTH(regs) MSTK_GET(regs,MONTH)
  104. #define MSTK_REG_YEAR(regs) MSTK_GET(regs,YEAR)
  105. #define MSTK_SET_REG_SEC(regs,value) MSTK_SET(regs,SEC,value)
  106. #define MSTK_SET_REG_MIN(regs,value) MSTK_SET(regs,MIN,value)
  107. #define MSTK_SET_REG_HOUR(regs,value) MSTK_SET(regs,HOUR,value)
  108. #define MSTK_SET_REG_DOW(regs,value) MSTK_SET(regs,DOW,value)
  109. #define MSTK_SET_REG_DOM(regs,value) MSTK_SET(regs,DOM,value)
  110. #define MSTK_SET_REG_MONTH(regs,value) MSTK_SET(regs,MONTH,value)
  111. #define MSTK_SET_REG_YEAR(regs,value) MSTK_SET(regs,YEAR,value)
  112. /* The Mostek 48t08 clock chip. Found on Sun4m's I think. It has the
  113. * same (basically) layout of the 48t02 chip except for the extra
  114. * NVRAM on board (8 KB against the 48t02's 2 KB).
  115. */
  116. #define MOSTEK_48T08_OFFSET 0x0000UL /* Lower NVRAM portions */
  117. #define MOSTEK_48T08_48T02 0x1800UL /* Offset to 48T02 chip */
  118. /* SUN5 systems usually have 48t59 model clock chipsets. But we keep the older
  119. * clock chip definitions around just in case.
  120. */
  121. #define MOSTEK_48T59_OFFSET 0x0000UL /* Lower NVRAM portions */
  122. #define MOSTEK_48T59_48T02 0x1800UL /* Offset to 48T02 chip */
  123. #endif /* !(_SPARC64_MOSTEK_H) */