summaryrefslogtreecommitdiff
path: root/sys/arch
diff options
context:
space:
mode:
authorgarbled <garbled@NetBSD.org>2007-11-13 19:17:30 +0000
committergarbled <garbled@NetBSD.org>2007-11-13 19:17:30 +0000
commit53a6c19ca52bd12d02f75d352a88d4a582ab2faf (patch)
tree9e4718338bef10f05ef814ce9ff965202f57a421 /sys/arch
parent61bbd00d3365616217a4dd40f310f366ae087472 (diff)
Add code to detect and initialize the com port correctly, so that we have an
actual real console when booting.
Diffstat (limited to 'sys/arch')
-rw-r--r--sys/arch/ofppc/include/autoconf.h3
-rw-r--r--sys/arch/ofppc/ofppc/machdep.c64
-rw-r--r--sys/arch/ofppc/pci/pegasospci.c5
3 files changed, 67 insertions, 5 deletions
diff --git a/sys/arch/ofppc/include/autoconf.h b/sys/arch/ofppc/include/autoconf.h
index dc82af7f11e..4c96e4b00d0 100644
--- a/sys/arch/ofppc/include/autoconf.h
+++ b/sys/arch/ofppc/include/autoconf.h
@@ -1,4 +1,4 @@
-/* $NetBSD: autoconf.h,v 1.8 2007/11/07 19:31:09 garbled Exp $ */
+/* $NetBSD: autoconf.h,v 1.9 2007/11/13 19:17:30 garbled Exp $ */
#ifndef _OFPPC_AUTOCONF_H_
#define _OFPPC_AUTOCONF_H_
@@ -30,6 +30,7 @@ void cpu_initclocks(void);
void decr_intr(struct clockframe *);
void setstatclockrate(int);
void init_interrupt(void);
+void ofppc_init_comcons(void);
int ofb_cnattach(void);
#endif /* _KERNEL */
diff --git a/sys/arch/ofppc/ofppc/machdep.c b/sys/arch/ofppc/ofppc/machdep.c
index bbf0291f52a..cc081e5478c 100644
--- a/sys/arch/ofppc/ofppc/machdep.c
+++ b/sys/arch/ofppc/ofppc/machdep.c
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.96 2007/11/04 16:28:28 garbled Exp $ */
+/* $NetBSD: machdep.c,v 1.97 2007/11/13 19:17:31 garbled Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -36,7 +36,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.96 2007/11/04 16:28:28 garbled Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.97 2007/11/13 19:17:31 garbled Exp $");
#include <sys/param.h>
#include <sys/buf.h>
@@ -59,8 +59,16 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.96 2007/11/04 16:28:28 garbled Exp $")
#include <powerpc/oea/bat.h>
#include <powerpc/ofw_cons.h>
+#include "com.h"
+#if (NCOM > 0)
+#include <sys/termios.h>
+#include <dev/ic/comreg.h>
+#include <dev/ic/comvar.h>
+#endif
+
struct pmap ofw_pmap;
char bootpath[256];
+extern int console_node;
void ofwppc_batinit(void);
void ofppc_bootstrap_console(void);
@@ -141,3 +149,55 @@ cpu_reboot(int howto, char *what)
*ap1 = 0;
ppc_boot(str);
}
+
+/*
+ */
+
+#define divrnd(n, q) (((n)*2/(q)+1)/2)
+
+void
+ofppc_init_comcons(void)
+{
+#if (NCOM > 0)
+ char name[64];
+ uint32_t reg[2], comfreq;
+ uint8_t dll, dlm;
+ int speed, rate, err;
+ bus_space_tag_t tag = &genppc_isa_io_space_tag;
+
+ /* if we have a serial cons, we have work to do */
+ memset(name, 0, sizeof(name));
+ OF_getprop(console_node, "device_type", name, sizeof(name));
+ if (strcmp(name, "serial") != 0)
+ return;
+
+ if (OF_getprop(console_node, "reg", reg, sizeof(reg)) == -1)
+ return;
+
+ if (OF_getprop(console_node, "clock-frequency", &comfreq, 4) == -1)
+ comfreq = 0;
+
+ if (comfreq == 0)
+ comfreq = COM_FREQ;
+
+ isa_outb(reg[1] + com_cfcr, LCR_DLAB);
+ dll = isa_inb(reg[1] + com_dlbl);
+ dlm = isa_inb(reg[1] + com_dlbh);
+ rate = dll | (dlm << 8);
+ isa_outb(reg[1] + com_cfcr, LCR_8BITS);
+ speed = divrnd((comfreq / 16), rate);
+ err = speed - (speed + 150)/300 * 300;
+ speed -= err;
+ if (err < 0)
+ err = -err;
+ if (err > 50)
+ speed = 9600;
+
+ /* Now we can attach the comcons */
+ aprint_verbose("Switching to COM console at speed %d", speed);
+ if (comcnattach(tag, reg[1], speed, comfreq, COM_TYPE_NORMAL,
+ ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8)))
+ panic("Can't init serial console");
+ aprint_verbose("\n");
+#endif /*NCOM*/
+}
diff --git a/sys/arch/ofppc/pci/pegasospci.c b/sys/arch/ofppc/pci/pegasospci.c
index 28a1a84b783..27c75e4fb56 100644
--- a/sys/arch/ofppc/pci/pegasospci.c
+++ b/sys/arch/ofppc/pci/pegasospci.c
@@ -1,4 +1,4 @@
-/* $NetBSD: pegasospci.c,v 1.5 2007/11/07 19:31:10 garbled Exp $ */
+/* $NetBSD: pegasospci.c,v 1.6 2007/11/13 19:17:31 garbled Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pegasospci.c,v 1.5 2007/11/07 19:31:10 garbled Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pegasospci.c,v 1.6 2007/11/13 19:17:31 garbled Exp $");
#include <sys/param.h>
#include <sys/device.h>
@@ -172,6 +172,7 @@ pegasospci_attach(struct device *parent, struct device *self, void *aux)
genppc_isa_io_space_tag = sc->sc_iot;
genppc_isa_mem_space_tag = sc->sc_memt;
map_isa_ioregs(sc->sc_iot.pbs_offset);
+ ofppc_init_comcons();
}
}