config.c 6.6 KB

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