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