config.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * linux/arch/m68k/hp300/config.c
  4. *
  5. * Copyright (C) 1998 Philip Blundell <philb@gnu.org>
  6. *
  7. * This file contains the HP300-specific initialisation code. It gets
  8. * called by setup.c.
  9. */
  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 <linux/rtc.h>
  16. #include <asm/bootinfo.h>
  17. #include <asm/bootinfo-hp300.h>
  18. #include <asm/byteorder.h>
  19. #include <asm/machdep.h>
  20. #include <asm/blinken.h>
  21. #include <asm/io.h> /* readb() and writeb() */
  22. #include <asm/hp300hw.h>
  23. #include "time.h"
  24. unsigned long hp300_model;
  25. unsigned long hp300_uart_scode = -1;
  26. unsigned char hp300_ledstate;
  27. EXPORT_SYMBOL(hp300_ledstate);
  28. static char s_hp330[] __initdata = "330";
  29. static char s_hp340[] __initdata = "340";
  30. static char s_hp345[] __initdata = "345";
  31. static char s_hp360[] __initdata = "360";
  32. static char s_hp370[] __initdata = "370";
  33. static char s_hp375[] __initdata = "375";
  34. static char s_hp380[] __initdata = "380";
  35. static char s_hp385[] __initdata = "385";
  36. static char s_hp400[] __initdata = "400";
  37. static char s_hp425t[] __initdata = "425t";
  38. static char s_hp425s[] __initdata = "425s";
  39. static char s_hp425e[] __initdata = "425e";
  40. static char s_hp433t[] __initdata = "433t";
  41. static char s_hp433s[] __initdata = "433s";
  42. static char *hp300_models[] __initdata = {
  43. [HP_320] = NULL,
  44. [HP_330] = s_hp330,
  45. [HP_340] = s_hp340,
  46. [HP_345] = s_hp345,
  47. [HP_350] = NULL,
  48. [HP_360] = s_hp360,
  49. [HP_370] = s_hp370,
  50. [HP_375] = s_hp375,
  51. [HP_380] = s_hp380,
  52. [HP_385] = s_hp385,
  53. [HP_400] = s_hp400,
  54. [HP_425T] = s_hp425t,
  55. [HP_425S] = s_hp425s,
  56. [HP_425E] = s_hp425e,
  57. [HP_433T] = s_hp433t,
  58. [HP_433S] = s_hp433s,
  59. };
  60. static char hp300_model_name[13] = "HP9000/";
  61. extern void hp300_reset(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 void *data = record->data;
  69. switch (be16_to_cpu(record->tag)) {
  70. case BI_HP300_MODEL:
  71. hp300_model = be32_to_cpup(data);
  72. break;
  73. case BI_HP300_UART_SCODE:
  74. hp300_uart_scode = be32_to_cpup(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. static void __init hp300_init_IRQ(void)
  211. {
  212. }
  213. void __init config_hp300(void)
  214. {
  215. mach_sched_init = hp300_sched_init;
  216. mach_init_IRQ = hp300_init_IRQ;
  217. mach_get_model = hp300_get_model;
  218. arch_gettimeoffset = hp300_gettimeoffset;
  219. mach_hwclk = hp300_hwclk;
  220. mach_get_ss = hp300_get_ss;
  221. mach_reset = hp300_reset;
  222. #ifdef CONFIG_HEARTBEAT
  223. mach_heartbeat = hp300_pulse;
  224. #endif
  225. mach_max_dma_address = 0xffffffff;
  226. if (hp300_model >= HP_330 && hp300_model <= HP_433S &&
  227. hp300_model != HP_350) {
  228. pr_info("Detected HP9000 model %s\n",
  229. hp300_models[hp300_model-HP_320]);
  230. strcat(hp300_model_name, hp300_models[hp300_model-HP_320]);
  231. } else {
  232. panic("Unknown HP9000 Model");
  233. }
  234. #ifdef CONFIG_SERIAL_8250_CONSOLE
  235. hp300_setup_serial_console();
  236. #endif
  237. }