diff target-utils/libcommon/uartsel.c @ 0:e7502631a0f9

initial import from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 11 Jun 2016 00:13:35 +0000
parents
children 2942c5ef76ed
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/target-utils/libcommon/uartsel.c	Sat Jun 11 00:13:35 2016 +0000
@@ -0,0 +1,54 @@
+/*
+ * uart_select_init() figures out which UART was used to load us
+ * through the boot ROM, and sets things up for us to use the same
+ * UART for our communication.
+ */
+
+#include "types.h"
+#include "romvars.h"
+#include "ns16550.h"
+#include "halt.h"
+
+extern struct ns16550_regs *uart_base;
+
+static u16 rom_version;
+static struct boot_rom_vars *rom_vars;
+static char *uart_name;
+
+uart_select_init()
+{
+	rom_version = *(u16 *)0x1FFE;
+
+	switch (rom_version) {
+	case 0x0200:
+		rom_vars = (struct boot_rom_vars *) 0x800504;
+		break;
+	case 0x0300:
+		rom_vars = (struct boot_rom_vars *) 0x800518;
+		break;
+	default:
+		_exit(HALTCODE_BOOTROMVER);
+	}
+
+	switch (rom_vars->uart_id) {
+	case 0:
+		uart_base = (struct ns16550_regs *) 0xFFFF5800;
+		uart_name = "MODEM";
+		break;
+	case 1:
+		uart_base = (struct ns16550_regs *) 0xFFFF5000;
+		uart_name = "IrDA";
+		break;
+	default:
+		_exit(HALTCODE_INVALIDUART);
+	}
+}
+
+print_boot_rom_info()
+{
+	printf("Loaded via boot ROM v%04X, UART %d (%s) at baud rate #%d\n",
+		rom_version, rom_vars->uart_id, uart_name,
+		rom_vars->baud_rate_code);
+	printf("CLKTCXO input autodetected to be %d MHz\n",
+		rom_vars->clktcxo_13mhz ? 13 : 26);
+}