config.c 6.4 KB

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