config.c 6.9 KB

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