config.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /*
  2. * linux/arch/m68k/hp300/config.c
  3. *
  4. * Copyright (C) 1998 Philip Blundell <philb@gnu.org>
  5. *
  6. * This file contains the HP300-specific initialisation code. It gets
  7. * called by setup.c.
  8. */
  9. #include <linux/module.h>
  10. #include <linux/init.h>
  11. #include <linux/string.h>
  12. #include <linux/kernel.h>
  13. #include <linux/console.h>
  14. #include <asm/bootinfo.h>
  15. #include <asm/machdep.h>
  16. #include <asm/blinken.h>
  17. #include <asm/io.h> /* readb() and writeb() */
  18. #include <asm/hp300hw.h>
  19. #include <asm/rtc.h>
  20. #include "time.h"
  21. unsigned long hp300_model;
  22. unsigned long hp300_uart_scode = -1;
  23. unsigned char hp300_ledstate;
  24. EXPORT_SYMBOL(hp300_ledstate);
  25. static char s_hp330[] __initdata = "330";
  26. static char s_hp340[] __initdata = "340";
  27. static char s_hp345[] __initdata = "345";
  28. static char s_hp360[] __initdata = "360";
  29. static char s_hp370[] __initdata = "370";
  30. static char s_hp375[] __initdata = "375";
  31. static char s_hp380[] __initdata = "380";
  32. static char s_hp385[] __initdata = "385";
  33. static char s_hp400[] __initdata = "400";
  34. static char s_hp425t[] __initdata = "425t";
  35. static char s_hp425s[] __initdata = "425s";
  36. static char s_hp425e[] __initdata = "425e";
  37. static char s_hp433t[] __initdata = "433t";
  38. static char s_hp433s[] __initdata = "433s";
  39. static char *hp300_models[] __initdata = {
  40. [HP_320] = NULL,
  41. [HP_330] = s_hp330,
  42. [HP_340] = s_hp340,
  43. [HP_345] = s_hp345,
  44. [HP_350] = NULL,
  45. [HP_360] = s_hp360,
  46. [HP_370] = s_hp370,
  47. [HP_375] = s_hp375,
  48. [HP_380] = s_hp380,
  49. [HP_385] = s_hp385,
  50. [HP_400] = s_hp400,
  51. [HP_425T] = s_hp425t,
  52. [HP_425S] = s_hp425s,
  53. [HP_425E] = s_hp425e,
  54. [HP_433T] = s_hp433t,
  55. [HP_433S] = s_hp433s,
  56. };
  57. static char hp300_model_name[13] = "HP9000/";
  58. extern void hp300_reset(void);
  59. #ifdef CONFIG_SERIAL_8250_CONSOLE
  60. extern int hp300_setup_serial_console(void) __init;
  61. #endif
  62. int __init hp300_parse_bootinfo(const struct bi_record *record)
  63. {
  64. int unknown = 0;
  65. const unsigned long *data = record->data;
  66. switch (record->tag) {
  67. case BI_HP300_MODEL:
  68. hp300_model = *data;
  69. break;
  70. case BI_HP300_UART_SCODE:
  71. hp300_uart_scode = *data;
  72. break;
  73. case BI_HP300_UART_ADDR:
  74. /* serial port address: ignored here */
  75. break;
  76. default:
  77. unknown = 1;
  78. }
  79. return unknown;
  80. }
  81. #ifdef CONFIG_HEARTBEAT
  82. static void hp300_pulse(int x)
  83. {
  84. if (x)
  85. blinken_leds(0x10, 0);
  86. else
  87. blinken_leds(0, 0x10);
  88. }
  89. #endif
  90. static void hp300_get_model(char *model)
  91. {
  92. strcpy(model, hp300_model_name);
  93. }
  94. #define RTCBASE 0xf0420000
  95. #define RTC_DATA 0x1
  96. #define RTC_CMD 0x3
  97. #define RTC_BUSY 0x02
  98. #define RTC_DATA_RDY 0x01
  99. #define rtc_busy() (in_8(RTCBASE + RTC_CMD) & RTC_BUSY)
  100. #define rtc_data_available() (in_8(RTCBASE + RTC_CMD) & RTC_DATA_RDY)
  101. #define rtc_status() (in_8(RTCBASE + RTC_CMD))
  102. #define rtc_command(x) out_8(RTCBASE + RTC_CMD, (x))
  103. #define rtc_read_data() (in_8(RTCBASE + RTC_DATA))
  104. #define rtc_write_data(x) out_8(RTCBASE + RTC_DATA, (x))
  105. #define RTC_SETREG 0xe0
  106. #define RTC_WRITEREG 0xc2
  107. #define RTC_READREG 0xc3
  108. #define RTC_REG_SEC2 0
  109. #define RTC_REG_SEC1 1
  110. #define RTC_REG_MIN2 2
  111. #define RTC_REG_MIN1 3
  112. #define RTC_REG_HOUR2 4
  113. #define RTC_REG_HOUR1 5
  114. #define RTC_REG_WDAY 6
  115. #define RTC_REG_DAY2 7
  116. #define RTC_REG_DAY1 8
  117. #define RTC_REG_MON2 9
  118. #define RTC_REG_MON1 10
  119. #define RTC_REG_YEAR2 11
  120. #define RTC_REG_YEAR1 12
  121. #define RTC_HOUR1_24HMODE 0x8
  122. #define RTC_STAT_MASK 0xf0
  123. #define RTC_STAT_RDY 0x40
  124. static inline unsigned char hp300_rtc_read(unsigned char reg)
  125. {
  126. unsigned char s, ret;
  127. unsigned long flags;
  128. local_irq_save(flags);
  129. while (rtc_busy());
  130. rtc_command(RTC_SETREG);
  131. while (rtc_busy());
  132. rtc_write_data(reg);
  133. while (rtc_busy());
  134. rtc_command(RTC_READREG);
  135. do {
  136. while (!rtc_data_available());
  137. s = rtc_status();
  138. ret = rtc_read_data();
  139. } while ((s & RTC_STAT_MASK) != RTC_STAT_RDY);
  140. local_irq_restore(flags);
  141. return ret;
  142. }
  143. static inline unsigned char hp300_rtc_write(unsigned char reg,
  144. unsigned char val)
  145. {
  146. unsigned char s, ret;
  147. unsigned long flags;
  148. local_irq_save(flags);
  149. while (rtc_busy());
  150. rtc_command(RTC_SETREG);
  151. while (rtc_busy());
  152. rtc_write_data((val << 4) | reg);
  153. while (rtc_busy());
  154. rtc_command(RTC_WRITEREG);
  155. while (rtc_busy());
  156. rtc_command(RTC_READREG);
  157. do {
  158. while (!rtc_data_available());
  159. s = rtc_status();
  160. ret = rtc_read_data();
  161. } while ((s & RTC_STAT_MASK) != RTC_STAT_RDY);
  162. local_irq_restore(flags);
  163. return ret;
  164. }
  165. static int hp300_hwclk(int op, struct rtc_time *t)
  166. {
  167. if (!op) { /* read */
  168. t->tm_sec = hp300_rtc_read(RTC_REG_SEC1) * 10 +
  169. hp300_rtc_read(RTC_REG_SEC2);
  170. t->tm_min = hp300_rtc_read(RTC_REG_MIN1) * 10 +
  171. hp300_rtc_read(RTC_REG_MIN2);
  172. t->tm_hour = (hp300_rtc_read(RTC_REG_HOUR1) & 3) * 10 +
  173. hp300_rtc_read(RTC_REG_HOUR2);
  174. t->tm_wday = -1;
  175. t->tm_mday = hp300_rtc_read(RTC_REG_DAY1) * 10 +
  176. hp300_rtc_read(RTC_REG_DAY2);
  177. t->tm_mon = hp300_rtc_read(RTC_REG_MON1) * 10 +
  178. hp300_rtc_read(RTC_REG_MON2) - 1;
  179. t->tm_year = hp300_rtc_read(RTC_REG_YEAR1) * 10 +
  180. hp300_rtc_read(RTC_REG_YEAR2);
  181. if (t->tm_year <= 69)
  182. t->tm_year += 100;
  183. } else {
  184. hp300_rtc_write(RTC_REG_SEC1, t->tm_sec / 10);
  185. hp300_rtc_write(RTC_REG_SEC2, t->tm_sec % 10);
  186. hp300_rtc_write(RTC_REG_MIN1, t->tm_min / 10);
  187. hp300_rtc_write(RTC_REG_MIN2, t->tm_min % 10);
  188. hp300_rtc_write(RTC_REG_HOUR1,
  189. ((t->tm_hour / 10) & 3) | RTC_HOUR1_24HMODE);
  190. hp300_rtc_write(RTC_REG_HOUR2, t->tm_hour % 10);
  191. hp300_rtc_write(RTC_REG_DAY1, t->tm_mday / 10);
  192. hp300_rtc_write(RTC_REG_DAY2, t->tm_mday % 10);
  193. hp300_rtc_write(RTC_REG_MON1, (t->tm_mon + 1) / 10);
  194. hp300_rtc_write(RTC_REG_MON2, (t->tm_mon + 1) % 10);
  195. if (t->tm_year >= 100)
  196. t->tm_year -= 100;
  197. hp300_rtc_write(RTC_REG_YEAR1, t->tm_year / 10);
  198. hp300_rtc_write(RTC_REG_YEAR2, t->tm_year % 10);
  199. }
  200. return 0;
  201. }
  202. static unsigned int hp300_get_ss(void)
  203. {
  204. return hp300_rtc_read(RTC_REG_SEC1) * 10 +
  205. hp300_rtc_read(RTC_REG_SEC2);
  206. }
  207. static void __init hp300_init_IRQ(void)
  208. {
  209. }
  210. void __init config_hp300(void)
  211. {
  212. mach_sched_init = hp300_sched_init;
  213. mach_init_IRQ = hp300_init_IRQ;
  214. mach_get_model = hp300_get_model;
  215. mach_gettimeoffset = hp300_gettimeoffset;
  216. mach_hwclk = hp300_hwclk;
  217. mach_get_ss = hp300_get_ss;
  218. mach_reset = hp300_reset;
  219. #ifdef CONFIG_HEARTBEAT
  220. mach_heartbeat = hp300_pulse;
  221. #endif
  222. mach_max_dma_address = 0xffffffff;
  223. if (hp300_model >= HP_330 && hp300_model <= HP_433S && hp300_model != HP_350) {
  224. printk(KERN_INFO "Detected HP9000 model %s\n", hp300_models[hp300_model-HP_320]);
  225. strcat(hp300_model_name, hp300_models[hp300_model-HP_320]);
  226. }
  227. else {
  228. panic("Unknown HP9000 Model");
  229. }
  230. #ifdef CONFIG_SERIAL_8250_CONSOLE
  231. hp300_setup_serial_console();
  232. #endif
  233. }