CVS commit: src/sys/arch/evbmips/loongson/dev

2021-02-17 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Wed Feb 17 08:19:06 UTC 2021

Modified Files:
src/sys/arch/evbmips/loongson/dev: glx.c

Log Message:
Trailing whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/evbmips/loongson/dev/glx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/evbmips/loongson/dev/glx.c
diff -u src/sys/arch/evbmips/loongson/dev/glx.c:1.7 src/sys/arch/evbmips/loongson/dev/glx.c:1.8
--- src/sys/arch/evbmips/loongson/dev/glx.c:1.7	Wed Feb 17 08:18:39 2021
+++ src/sys/arch/evbmips/loongson/dev/glx.c	Wed Feb 17 08:19:06 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: glx.c,v 1.7 2021/02/17 08:18:39 skrll Exp $	*/
+/*	$NetBSD: glx.c,v 1.8 2021/02/17 08:19:06 skrll Exp $	*/
 /*	$OpenBSD: glx.c,v 1.6 2010/10/14 21:23:04 pirofti Exp $	*/
 
 /*
@@ -22,7 +22,7 @@
  * XXX too many hardcoded numbers... need to expand glxreg.h
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: glx.c,v 1.7 2021/02/17 08:18:39 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: glx.c,v 1.8 2021/02/17 08:19:06 skrll Exp $");
 
 #include 
 #include 
@@ -273,7 +273,7 @@ glx_pci_write_hook(void *v, pcitag_t tag
 		gen_pci_conf_write(v, tag, offset, data);
 		return;
 	}
-		
+
 
 	pci_decompose_tag(glxbase_pc, tag, , , );
 	if (bus != 0 || dev != glxbase_dev) {



CVS commit: src/sys/arch/evbmips/loongson/dev

2021-02-17 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Wed Feb 17 08:18:39 UTC 2021

Modified Files:
src/sys/arch/evbmips/loongson/dev: glx.c

Log Message:
Use the PCI_MAPREG_TYPE macro.  Same binary after change.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/evbmips/loongson/dev/glx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/evbmips/loongson/dev/glx.c
diff -u src/sys/arch/evbmips/loongson/dev/glx.c:1.6 src/sys/arch/evbmips/loongson/dev/glx.c:1.7
--- src/sys/arch/evbmips/loongson/dev/glx.c:1.6	Thu Feb  8 09:05:17 2018
+++ src/sys/arch/evbmips/loongson/dev/glx.c	Wed Feb 17 08:18:39 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: glx.c,v 1.6 2018/02/08 09:05:17 dholland Exp $	*/
+/*	$NetBSD: glx.c,v 1.7 2021/02/17 08:18:39 skrll Exp $	*/
 /*	$OpenBSD: glx.c,v 1.6 2010/10/14 21:23:04 pirofti Exp $	*/
 
 /*
@@ -22,7 +22,7 @@
  * XXX too many hardcoded numbers... need to expand glxreg.h
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: glx.c,v 1.6 2018/02/08 09:05:17 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: glx.c,v 1.7 2021/02/17 08:18:39 skrll Exp $");
 
 #include 
 #include 
@@ -460,8 +460,7 @@ glx_fn0_write(int reg, pcireg_t data)
 		if (data == 0x) {
 			pcib_bar_values[index] = data;
 		} else if (pcib_bar_msr[index] != 0) {
-			if ((data & PCI_MAPREG_TYPE_MASK) ==
-			PCI_MAPREG_TYPE_IO) {
+			if (PCI_MAPREG_TYPE(data) == PCI_MAPREG_TYPE_IO) {
 data &= PCI_MAPREG_IO_ADDR_MASK;
 data &= ~(pcib_bar_sizes[index] - 1);
 wrmsr(pcib_bar_msr[index],
@@ -573,8 +572,7 @@ glx_fn2_write(int reg, pcireg_t data)
 		if (data == 0x) {
 			pciide_bar_value = data;
 		} else {
-			if ((data & PCI_MAPREG_TYPE_MASK) ==
-			PCI_MAPREG_TYPE_IO) {
+			if (PCI_MAPREG_TYPE(data) == PCI_MAPREG_TYPE_IO) {
 data &= PCI_MAPREG_IO_ADDR_MASK;
 msr = (uint32_t)data & 0xfff0;
 wrmsr(GCSC_IDE_IO_BAR, msr);
@@ -686,8 +684,7 @@ glx_fn3_write(int reg, pcireg_t data)
 		if (data == 0x) {
 			ac97_bar_value = data;
 		} else {
-			if ((data & PCI_MAPREG_TYPE_MASK) ==
-			PCI_MAPREG_TYPE_IO) {
+			if (PCI_MAPREG_TYPE(data) == PCI_MAPREG_TYPE_IO) {
 data &= PCI_MAPREG_IO_ADDR_MASK;
 msr = rdmsr(GCSC_GLIU_IOD_BM1);
 msr &= 0x0f00ULL;
@@ -799,8 +796,7 @@ glx_fn4_write(int reg, pcireg_t data)
 		if (data == 0x) {
 			ohci_bar_value = data;
 		} else {
-			if ((data & PCI_MAPREG_TYPE_MASK) ==
-			PCI_MAPREG_TYPE_MEM) {
+			if (PCI_MAPREG_TYPE(data) == PCI_MAPREG_TYPE_MEM) {
 data &= PCI_MAPREG_MEM_ADDR_MASK;
 msr = rdmsr(GCSC_GLIU_P2D_BM3);
 msr &= 0x0f00ULL;
@@ -925,9 +921,8 @@ glx_fn5_write(int reg, pcireg_t data)
 		if (data == 0x) {
 			ehci_bar_value = data;
 		} else {
-			if ((data & PCI_MAPREG_TYPE_MASK) ==
-			PCI_MAPREG_TYPE_MEM) {
-data &= PCI_MAPREG_MEM_ADDR_MASK;
+			if (PCI_MAPREG_TYPE(data) == PCI_MAPREG_TYPE_MEM) {
+data = PCI_MAPREG_MEM_ADDR(data);
 msr = rdmsr(GCSC_GLIU_P2D_BM4);
 msr &= 0x0f00ULL;
 msr |= 2ULL << 61;	/* USB */



CVS commit: src/sys/arch/evbmips/loongson/dev

2020-05-25 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 25 17:56:19 UTC 2020

Modified Files:
src/sys/arch/evbmips/loongson/dev: kb3310.c

Log Message:
Switch to CFATTACH_DECL_NEW.

This driver doesn't compile -- never has since it was imported from
OpenBSD -- but in case anyone wants to make it work, let's leave fewer
landmines to step on.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/evbmips/loongson/dev/kb3310.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/evbmips/loongson/dev/kb3310.c
diff -u src/sys/arch/evbmips/loongson/dev/kb3310.c:1.2 src/sys/arch/evbmips/loongson/dev/kb3310.c:1.3
--- src/sys/arch/evbmips/loongson/dev/kb3310.c:1.2	Sat Oct 27 17:17:50 2012
+++ src/sys/arch/evbmips/loongson/dev/kb3310.c	Mon May 25 17:56:19 2020
@@ -99,9 +99,8 @@ extern void loongson_set_isa_imr(uint);
 int	ykbec_match(device_t, cfdata_t, void *);
 void	ykbec_attach(device_t, device_t, void *);
 
-const struct cfattach ykbec_ca = {
-	sizeof(struct ykbec_softc), ykbec_match, ykbec_attach
-};
+CFATTACH_DECL_NEW(ykbec, sizeof(struct ykbec_softc),
+ykbec_match, ykbec_attach, NULL, NULL);
 
 int	ykbec_apminfo(struct apm_power_info *);
 void	ykbec_bell(void *, u_int, u_int, u_int, int);



CVS commit: src/sys/arch/evbmips/loongson/dev

2018-03-08 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Mar  8 18:48:25 UTC 2018

Modified Files:
src/sys/arch/evbmips/loongson/dev: pcib.c

Log Message:
The PCI_PRODUCT_VIATECH_VT82C686A_SMB has been renamed, adjust.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/evbmips/loongson/dev/pcib.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/evbmips/loongson/dev/pcib.c
diff -u src/sys/arch/evbmips/loongson/dev/pcib.c:1.1 src/sys/arch/evbmips/loongson/dev/pcib.c:1.2
--- src/sys/arch/evbmips/loongson/dev/pcib.c:1.1	Sat Aug 27 13:42:46 2011
+++ src/sys/arch/evbmips/loongson/dev/pcib.c	Thu Mar  8 18:48:25 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: pcib.c,v 1.1 2011/08/27 13:42:46 bouyer Exp $	*/
+/*	$NetBSD: pcib.c,v 1.2 2018/03/08 18:48:25 martin Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1998 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pcib.c,v 1.1 2011/08/27 13:42:46 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pcib.c,v 1.2 2018/03/08 18:48:25 martin Exp $");
 
 #include 
 #include 
@@ -83,7 +83,7 @@ pcibmatch(device_t parent, cfdata_t matc
 		break;
 	case PCI_VENDOR_VIATECH:
 		switch (PCI_PRODUCT(pa->pa_id)) {
-		case PCI_PRODUCT_VIATECH_VT82C686A_SMB:
+		case PCI_PRODUCT_VIATECH_VT82C686A_PWR:
 			/* mis-identifies itself as a ISA bridge */
 			return (0);
 		}



CVS commit: src/sys/arch/evbmips/loongson

2016-08-26 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Aug 27 05:53:40 UTC 2016

Modified Files:
src/sys/arch/evbmips/loongson: loongson_intr.c

Log Message:
Trailing whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/evbmips/loongson/loongson_intr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/evbmips/loongson/loongson_intr.c
diff -u src/sys/arch/evbmips/loongson/loongson_intr.c:1.5 src/sys/arch/evbmips/loongson/loongson_intr.c:1.6
--- src/sys/arch/evbmips/loongson/loongson_intr.c:1.5	Fri Aug 26 15:45:48 2016
+++ src/sys/arch/evbmips/loongson/loongson_intr.c	Sat Aug 27 05:53:40 2016
@@ -1,4 +1,4 @@
-/*  $NetBSD: loongson_intr.c,v 1.5 2016/08/26 15:45:48 skrll Exp $  */
+/*  $NetBSD: loongson_intr.c,v 1.6 2016/08/27 05:53:40 skrll Exp $  */
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: loongson_intr.c,v 1.5 2016/08/26 15:45:48 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: loongson_intr.c,v 1.6 2016/08/27 05:53:40 skrll Exp $");
 
 #define __INTR_PRIVATE
 
@@ -179,7 +179,7 @@ void *
 loongson_pciide_compat_intr_establish(void *v, device_t dev,
 const struct pci_attach_args *pa, int chan, int (*func)(void *), void *arg)
 {
-	pci_chipset_tag_t pc = pa->pa_pc; 
+	pci_chipset_tag_t pc = pa->pa_pc;
 	void *cookie;
 	int bus, irq;
 	char buf[PCI_INTRSTR_LEN];
@@ -235,7 +235,7 @@ loongson_pci_intr_map(const struct pci_a
 const char *
 loongson_pci_intr_string(void *v, pci_intr_handle_t ih, char *buf, size_t len)
 {
-	
+
 	const struct bonito_config *bc = v;
 	return loongson_intr_string(bc, ih, buf, len);
 }



CVS commit: src/sys/arch/evbmips/loongson

2016-08-26 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Aug 26 13:58:27 UTC 2016

Modified Files:
src/sys/arch/evbmips/loongson: mainbus.c

Log Message:
Make PCI_NETBSD_CONFIGURE compile


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/evbmips/loongson/mainbus.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/evbmips/loongson/mainbus.c
diff -u src/sys/arch/evbmips/loongson/mainbus.c:1.1 src/sys/arch/evbmips/loongson/mainbus.c:1.2
--- src/sys/arch/evbmips/loongson/mainbus.c:1.1	Sat Aug 27 13:42:45 2011
+++ src/sys/arch/evbmips/loongson/mainbus.c	Fri Aug 26 13:58:27 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: mainbus.c,v 1.1 2011/08/27 13:42:45 bouyer Exp $	*/
+/*	$NetBSD: mainbus.c,v 1.2 2016/08/26 13:58:27 skrll Exp $	*/
 
 /*
  * Copyright 2002 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.1 2011/08/27 13:42:45 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.2 2016/08/26 13:58:27 skrll Exp $");
 
 #include "opt_pci.h"
 
@@ -59,6 +59,9 @@ __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 
 #include 
 
 #include 
+#if defined(PCI_NETBSD_CONFIGURE)
+#include 
+#endif
 
 #include "locators.h"
 #include "pci.h"
@@ -100,19 +103,16 @@ mainbus_attach(device_t parent, device_t
 	aprint_normal("\n");
 
 #if defined(PCI_NETBSD_CONFIGURE)
-	{
-		struct extent *ioext, *memext;
-
-		ioext = extent_create("pciio",  0x1000, 0x3fff,
-		M_DEVBUF, NULL, 0, EX_NOWAIT);
-		memext = extent_create("pcimem", 0, BONITO_PCILO_SIZE,
-		M_DEVBUF, NULL, 0, EX_NOWAIT);
-
-		pci_configure_bus(_configuration.gc_pc, ioext, memext,
-		NULL, 0, mips_dcache_align);
-		extent_destroy(ioext);
-		extent_destroy(memext);
-	}
+	struct extent *ioext = extent_create("pciio",  0x1000, 0x3fff,
+	NULL, 0, EX_NOWAIT);
+	struct extent *memext = extent_create("pcimem", 0, BONITO_PCILO_SIZE,
+	NULL, 0, EX_NOWAIT);
+	struct mips_cache_info * const mci = _cache_info;
+
+	pci_configure_bus(_pc, ioext, memext,
+	NULL, 0, mci->mci_dcache_align);
+	extent_destroy(ioext);
+	extent_destroy(memext);
 #endif /* PCI_NETBSD_CONFIGURE */
 
 	for (i = 0; i < __arraycount(mainbusdevs); i++) {



CVS commit: src/sys/arch/evbmips/loongson

2016-07-09 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Jul 10 00:14:37 UTC 2016

Modified Files:
src/sys/arch/evbmips/loongson: yeeloong_machdep.c

Log Message:
The version of PMON on my 8089B (LM8089-1.4.9a) configures OHCI but doesn't
enable memory space access. Enable it before the ohci driver attaches to
allow low- and full-speed devices to work.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/evbmips/loongson/yeeloong_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/evbmips/loongson/yeeloong_machdep.c
diff -u src/sys/arch/evbmips/loongson/yeeloong_machdep.c:1.7 src/sys/arch/evbmips/loongson/yeeloong_machdep.c:1.8
--- src/sys/arch/evbmips/loongson/yeeloong_machdep.c:1.7	Tue Jun  9 16:29:01 2015
+++ src/sys/arch/evbmips/loongson/yeeloong_machdep.c	Sun Jul 10 00:14:36 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: yeeloong_machdep.c,v 1.7 2015/06/09 16:29:01 macallan Exp $	*/
+/*	$NetBSD: yeeloong_machdep.c,v 1.8 2016/07/10 00:14:36 jmcneill Exp $	*/
 /*	$OpenBSD: yeeloong_machdep.c,v 1.16 2011/04/15 20:40:06 deraadt Exp $	*/
 
 /*
@@ -23,7 +23,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: yeeloong_machdep.c,v 1.7 2015/06/09 16:29:01 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: yeeloong_machdep.c,v 1.8 2016/07/10 00:14:36 jmcneill Exp $");
 
 #include 
 #include 
@@ -559,6 +559,18 @@ lemote_device_register(device_t dev, voi
 	if (device_class(dev) != bootdev_class)
 		return;
 
+	/* OHCI memory space access may not be enabled by the BIOS */
+	if (device_is_a(dev, "ohci")) {
+		struct pci_attach_args *pa = aux;
+		pcireg_t csr = pci_conf_read(pa->pa_pc, pa->pa_tag,
+		PCI_COMMAND_STATUS_REG);
+		if ((csr & PCI_COMMAND_MEM_ENABLE) == 0) {
+			csr |= PCI_COMMAND_MEM_ENABLE;
+			pci_conf_write(pa->pa_pc, pa->pa_tag,
+			PCI_COMMAND_STATUS_REG, csr);
+		}
+	}
+
 	/* 
 	 * The device numbering must match. There's no way
 	 * pmon tells us more info. Depending on the usb slot



CVS commit: src/sys/arch/evbmips/loongson

2016-06-24 Thread Michael Lorenz
Module Name:src
Committed By:   macallan
Date:   Fri Jun 24 21:41:37 UTC 2016

Added Files:
src/sys/arch/evbmips/loongson: loongson_clock.c

Log Message:
alternate clock.c implementation for loongson2f which supports
CPU clock scaling. Based on pwmclock but uses the cycle counter interrupt
instead, so it is no longer gdium-specific.
This will likely need changes to support other loongson models.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/arch/evbmips/loongson/loongson_clock.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Added files:

Index: src/sys/arch/evbmips/loongson/loongson_clock.c
diff -u /dev/null src/sys/arch/evbmips/loongson/loongson_clock.c:1.1
--- /dev/null	Fri Jun 24 21:41:37 2016
+++ src/sys/arch/evbmips/loongson/loongson_clock.c	Fri Jun 24 21:41:37 2016
@@ -0,0 +1,391 @@
+/*	$NetBSD: loongson_clock.c,v 1.1 2016/06/24 21:41:37 macallan Exp $	*/
+
+/*
+ * Copyright (c) 2011, 2016 Michael Lorenz
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include 
+__KERNEL_RCSID(0, "$NetBSD: loongson_clock.c,v 1.1 2016/06/24 21:41:37 macallan Exp $");
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#ifdef LOONGSON_CLOCK_DEBUG
+#define DPRINTF aprint_error
+#else
+#define DPRINTF while (0) printf
+#endif
+
+static uint32_t sc_last;
+static uint32_t sc_scale[8];
+static uint32_t sc_count;	/* should probably be 64 bit */
+static int sc_step = 7;
+static int sc_step_wanted = 7;
+static void *sc_shutdown_cookie;
+
+/* 0, 1/4, 3/8, 1/2, 5/8, 3/4, 7/8, 1 */
+static int scale_m[] = {1, 1, 3, 1, 5, 3, 7, 1};
+static int scale_d[] = {0, 4, 8, 2, 8, 4, 8, 1};
+static int cycles[8];
+
+#define scale(x, f) (x * scale_d[f] / scale_m[f])
+#define rscale(x, f) (x * scale_m[f] / scale_d[f])
+
+static void loongson_set_speed(int);
+static int  loongson_cpuspeed_temp(SYSCTLFN_ARGS);
+static int  loongson_cpuspeed_cur(SYSCTLFN_ARGS);
+static int  loongson_cpuspeed_available(SYSCTLFN_ARGS);
+
+static void loongson_clock_shutdown(void *);
+static u_int get_loongson_timecount(struct timecounter *);
+void	loongson_delay(int);
+void	loongson_setstatclockrate(int);
+voidloongson_initclocks(void);
+
+static struct timecounter loongson_timecounter = {
+	get_loongson_timecount,	/* get_timecount */
+	0,			/* no poll_pps */
+	0x,		/* counter_mask */
+	0,			/* frequency */
+	"loongson",		/* name */
+	100,			/* quality */
+	NULL,			/* tc_priv */
+	NULL			/* tc_next */
+};
+
+void
+loongson_initclocks(void)
+{
+	const struct sysctlnode *sysctl_node, *me, *freq;
+	int clk;
+
+	/*
+	 * Establish a hook so on shutdown we can set the CPU clock back to
+	 * full speed. This is necessary because PMON doesn't change the 
+	 * clock scale register on a warm boot, the MIPS clock code gets
+	 * confused if we're too slow and the loongson-specific bits run
+	 * too late in the boot process
+	 */
+	sc_shutdown_cookie = shutdownhook_establish(loongson_clock_shutdown, NULL);
+
+	for (clk = 1; clk < 8; clk++) {
+		sc_scale[clk] = rscale(curcpu()->ci_cpu_freq / 100, clk);
+		cycles[clk] =
+		(rscale(curcpu()->ci_cpu_freq, clk) + hz / 2) / (2 * hz);
+	}
+#ifdef LOONGSON_CLOCK_DEBUG
+	for (clk = 1; clk < 8; clk++) {
+		aprint_normal("frequencies: %d/8: %d\n", clk + 1,
+		sc_scale[clk]);
+	}
+#endif
+
+	/* now setup sysctl */
+	if (sysctl_createv(NULL, 0, NULL, 
+	, 
+	CTLFLAG_READWRITE, CTLTYPE_NODE, "loongson", NULL, NULL,
+	0, NULL, 0, CTL_MACHDEP, CTL_CREATE, CTL_EOL) != 0)
+		aprint_error("couldn't create 'loongson' node\n");
+
+	if (sysctl_createv(NULL, 0, NULL, 
+	, 
+	

CVS commit: src/sys/arch/evbmips/loongson/dev

2016-02-29 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Feb 29 18:24:31 UTC 2016

Modified Files:
src/sys/arch/evbmips/loongson/dev: stvii.c

Log Message:
PR/50869: David Binderman: Use logical and instead of arithmetic


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/evbmips/loongson/dev/stvii.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/evbmips/loongson/dev/stvii.c
diff -u src/sys/arch/evbmips/loongson/dev/stvii.c:1.4 src/sys/arch/evbmips/loongson/dev/stvii.c:1.5
--- src/sys/arch/evbmips/loongson/dev/stvii.c:1.4	Thu Feb 28 08:21:15 2013
+++ src/sys/arch/evbmips/loongson/dev/stvii.c	Mon Feb 29 13:24:31 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: stvii.c,v 1.4 2013/02/28 13:21:15 macallan Exp $	*/
+/*	$NetBSD: stvii.c,v 1.5 2016/02/29 18:24:31 christos Exp $	*/
 
 /*-
  * Copyright (C) 2011 Michael Lorenz.
@@ -30,7 +30,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: stvii.c,v 1.4 2013/02/28 13:21:15 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: stvii.c,v 1.5 2016/02/29 18:24:31 christos Exp $");
 
 #include 
 #include 
@@ -303,10 +303,10 @@ stvii_worker(void *cookie)
 			nctrl = sc->sc_control & ~(STC_TRICKLE | STC_CHARGE_ENABLE);
 			bl = stvii_battery_level(sc);
 			sc->sc_bat_level = bl;
-			if (charging & (bl > BAT_FULL)) {
+			if (charging && (bl > BAT_FULL)) {
 /* stop charging, we're full */
 charging = 0;
-			} else if (!charging & (bl < BAT_LOW)) {
+			} else if (!charging && (bl < BAT_LOW)) {
 charging = 1;
 			}
 			if (st & STS_AC_AVAILABLE) {



CVS commit: src/sys/arch/evbmips/loongson

2015-06-09 Thread Michael Lorenz
Module Name:src
Committed By:   macallan
Date:   Tue Jun  9 16:10:48 UTC 2015

Modified Files:
src/sys/arch/evbmips/loongson: gdium_machdep.c generic2e_machdep.c
isa_machdep.c

Log Message:
more cpuregs.h


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/evbmips/loongson/gdium_machdep.c
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/evbmips/loongson/generic2e_machdep.c
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/evbmips/loongson/isa_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/evbmips/loongson/gdium_machdep.c
diff -u src/sys/arch/evbmips/loongson/gdium_machdep.c:1.6 src/sys/arch/evbmips/loongson/gdium_machdep.c:1.7
--- src/sys/arch/evbmips/loongson/gdium_machdep.c:1.6	Wed Mar 13 21:18:35 2013
+++ src/sys/arch/evbmips/loongson/gdium_machdep.c	Tue Jun  9 16:10:48 2015
@@ -25,6 +25,7 @@
 #include sys/device.h
 #include sys/types.h
 
+#include mips/cpuregs.h
 #include evbmips/loongson/autoconf.h
 #include evbmips/loongson/loongson_intr.h
 

Index: src/sys/arch/evbmips/loongson/generic2e_machdep.c
diff -u src/sys/arch/evbmips/loongson/generic2e_machdep.c:1.4 src/sys/arch/evbmips/loongson/generic2e_machdep.c:1.5
--- src/sys/arch/evbmips/loongson/generic2e_machdep.c:1.4	Sat Mar 29 19:28:28 2014
+++ src/sys/arch/evbmips/loongson/generic2e_machdep.c	Tue Jun  9 16:10:48 2015
@@ -48,7 +48,7 @@
  * Generic Loongson 2E code and configuration data.
  */
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: generic2e_machdep.c,v 1.4 2014/03/29 19:28:28 christos Exp $);
+__KERNEL_RCSID(0, $NetBSD: generic2e_machdep.c,v 1.5 2015/06/09 16:10:48 macallan Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -65,6 +65,7 @@ __KERNEL_RCSID(0, $NetBSD: generic2e_ma
 #include dev/pci/pcivar.h
 #include dev/pci/pcidevs.h
 
+#include mips/cpuregs.h
 #include mips/bonito/bonitoreg.h
 #include mips/bonito/bonitovar.h
 

Index: src/sys/arch/evbmips/loongson/isa_machdep.c
diff -u src/sys/arch/evbmips/loongson/isa_machdep.c:1.1 src/sys/arch/evbmips/loongson/isa_machdep.c:1.2
--- src/sys/arch/evbmips/loongson/isa_machdep.c:1.1	Sat Aug 27 13:42:45 2011
+++ src/sys/arch/evbmips/loongson/isa_machdep.c	Tue Jun  9 16:10:48 2015
@@ -24,6 +24,7 @@
 #include sys/systm.h
 #include sys/device.h
 
+#include mips/cpuregs.h
 #include evbmips/loongson/autoconf.h
 #include machine/intr.h
 



CVS commit: src/sys/arch/evbmips/loongson

2015-06-09 Thread Michael Lorenz
Module Name:src
Committed By:   macallan
Date:   Tue Jun  9 16:29:01 UTC 2015

Modified Files:
src/sys/arch/evbmips/loongson: yeeloong_machdep.c

Log Message:
another cpuregs.h


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/evbmips/loongson/yeeloong_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/evbmips/loongson/yeeloong_machdep.c
diff -u src/sys/arch/evbmips/loongson/yeeloong_machdep.c:1.6 src/sys/arch/evbmips/loongson/yeeloong_machdep.c:1.7
--- src/sys/arch/evbmips/loongson/yeeloong_machdep.c:1.6	Sat Mar 29 19:28:28 2014
+++ src/sys/arch/evbmips/loongson/yeeloong_machdep.c	Tue Jun  9 16:29:01 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: yeeloong_machdep.c,v 1.6 2014/03/29 19:28:28 christos Exp $	*/
+/*	$NetBSD: yeeloong_machdep.c,v 1.7 2015/06/09 16:29:01 macallan Exp $	*/
 /*	$OpenBSD: yeeloong_machdep.c,v 1.16 2011/04/15 20:40:06 deraadt Exp $	*/
 
 /*
@@ -23,13 +23,14 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: yeeloong_machdep.c,v 1.6 2014/03/29 19:28:28 christos Exp $);
+__KERNEL_RCSID(0, $NetBSD: yeeloong_machdep.c,v 1.7 2015/06/09 16:29:01 macallan Exp $);
 
 #include sys/param.h
 #include sys/systm.h
 #include sys/device.h
 #include sys/types.h
 
+#include mips/cpuregs.h
 #include evbmips/loongson/autoconf.h
 #include mips/pmon/pmon.h
 #include evbmips/loongson/loongson_intr.h



CVS commit: src/sys/arch/evbmips/loongson

2015-01-10 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Jan 10 14:07:26 UTC 2015

Modified Files:
src/sys/arch/evbmips/loongson: autoconf.c

Log Message:
if MEMORY_DISK_IS_ROOT is defined, dont try to guess the root device


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/evbmips/loongson/autoconf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/evbmips/loongson/autoconf.c
diff -u src/sys/arch/evbmips/loongson/autoconf.c:1.5 src/sys/arch/evbmips/loongson/autoconf.c:1.6
--- src/sys/arch/evbmips/loongson/autoconf.c:1.5	Wed Mar 13 21:17:43 2013
+++ src/sys/arch/evbmips/loongson/autoconf.c	Sat Jan 10 14:07:26 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: autoconf.c,v 1.5 2013/03/13 21:17:43 macallan Exp $	*/
+/*	$NetBSD: autoconf.c,v 1.6 2015/01/10 14:07:26 jmcneill Exp $	*/
 
 /*
  * Copyright 2002 Wasabi Systems, Inc.
@@ -35,8 +35,10 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include opt_md.h
+
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: autoconf.c,v 1.5 2013/03/13 21:17:43 macallan Exp $);
+__KERNEL_RCSID(0, $NetBSD: autoconf.c,v 1.6 2015/01/10 14:07:26 jmcneill Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -46,7 +48,9 @@ __KERNEL_RCSID(0, $NetBSD: autoconf.c,v
 #include sys/cpu.h
 #include evbmips/loongson/autoconf.h
 
+#ifndef MEMORY_DISK_IS_ROOT
 static void	findroot(void);
+#endif
 
 enum devclass bootdev_class = DV_DULL;
 char  bootdev[16];
@@ -74,7 +78,9 @@ cpu_configure(void)
 void
 cpu_rootconf(void)
 {
+#ifndef MEMORY_DISK_IS_ROOT
 	findroot();
+#endif
 
 	printf(boot device: %s\n,
 		booted_device ? device_xname(booted_device) : unknown);
@@ -85,6 +91,7 @@ cpu_rootconf(void)
 extern char	bootstring[];
 extern int	netboot;
 
+#ifndef MEMORY_DISK_IS_ROOT
 static void
 findroot(void)
 {
@@ -111,6 +118,7 @@ findroot(void)
 
 	return;
 }
+#endif
 
 void
 device_register(device_t dev, void *aux)



CVS commit: src/sys/arch/evbmips/loongson

2013-03-13 Thread Michael Lorenz
Module Name:src
Committed By:   macallan
Date:   Wed Mar 13 21:17:43 UTC 2013

Modified Files:
src/sys/arch/evbmips/loongson: autoconf.c

Log Message:
remove half-assed gdium-specific code in device_register and actually call
sys_platform-device_register()
how in Cthulhu's name did this ever work?


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/evbmips/loongson/autoconf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/evbmips/loongson/autoconf.c
diff -u src/sys/arch/evbmips/loongson/autoconf.c:1.4 src/sys/arch/evbmips/loongson/autoconf.c:1.5
--- src/sys/arch/evbmips/loongson/autoconf.c:1.4	Sat Oct 27 17:17:50 2012
+++ src/sys/arch/evbmips/loongson/autoconf.c	Wed Mar 13 21:17:43 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: autoconf.c,v 1.4 2012/10/27 17:17:50 chs Exp $	*/
+/*	$NetBSD: autoconf.c,v 1.5 2013/03/13 21:17:43 macallan Exp $	*/
 
 /*
  * Copyright 2002 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: autoconf.c,v 1.4 2012/10/27 17:17:50 chs Exp $);
+__KERNEL_RCSID(0, $NetBSD: autoconf.c,v 1.5 2013/03/13 21:17:43 macallan Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -44,11 +44,13 @@ __KERNEL_RCSID(0, $NetBSD: autoconf.c,v
 #include sys/conf.h
 #include sys/device.h
 #include sys/cpu.h
+#include evbmips/loongson/autoconf.h
 
 static void	findroot(void);
 
 enum devclass bootdev_class = DV_DULL;
 char  bootdev[16];
+extern const struct platform *sys_platform;
 
 void
 cpu_configure(void)
@@ -118,19 +120,12 @@ device_register(device_t dev, void *aux)
 	if ((booted_device == NULL)  (netboot == 1))
 		if (device_class(dev) == DV_IFNET)
 			booted_device = dev;
-	if (device_is_a(dev, genfb)) {
-		dict = device_properties(dev);
-		/*
-		 * this is a hack
-		 * is_console and address need to be checked against reality
-		 */
-		prop_dictionary_set_bool(dict, is_console, 1);
-		prop_dictionary_set_uint32(dict, width, 1024);
-		prop_dictionary_set_uint32(dict, height, 600);
-		prop_dictionary_set_uint32(dict, depth, 16);
-		prop_dictionary_set_uint32(dict, linebytes, 2048);
-		prop_dictionary_set_uint32(dict, address, 0x0400);
+
+	if (sys_platform-device_register != NULL) {
+		sys_platform-device_register(dev, aux);
 	}
+
+	/* is this yeeloong specific? */
 	if (device_is_a(dev, lynxfb)) {
 		dict = device_properties(dev);
 		/*



CVS commit: src/sys/arch/evbmips/loongson

2013-03-13 Thread Michael Lorenz
Module Name:src
Committed By:   macallan
Date:   Wed Mar 13 21:18:35 UTC 2013

Modified Files:
src/sys/arch/evbmips/loongson: gdium_machdep.c

Log Message:
make sure device properties for genfb or voyagerfb actually get set


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/evbmips/loongson/gdium_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/evbmips/loongson/gdium_machdep.c
diff -u src/sys/arch/evbmips/loongson/gdium_machdep.c:1.5 src/sys/arch/evbmips/loongson/gdium_machdep.c:1.6
--- src/sys/arch/evbmips/loongson/gdium_machdep.c:1.5	Sat Oct 27 17:17:50 2012
+++ src/sys/arch/evbmips/loongson/gdium_machdep.c	Wed Mar 13 21:18:35 2013
@@ -240,6 +240,20 @@ gdium_device_register(device_t dev, void
 	static int gkey_chain_pos = 0;
 	static device_t lastparent = NULL;
 
+	if (device_is_a(dev, genfb) || device_is_a(dev, voyagerfb)) {
+		dict = device_properties(dev);
+		/*
+		 * this is a hack
+		 * is_console needs to be checked against reality
+		 */
+		prop_dictionary_set_bool(dict, is_console, 1);
+		prop_dictionary_set_uint32(dict, width, 1024);
+		prop_dictionary_set_uint32(dict, height, 600);
+		prop_dictionary_set_uint32(dict, depth, 16);
+		prop_dictionary_set_uint32(dict, linebytes, 2048);
+		if (fb_addr != 0)
+			prop_dictionary_set_uint32(dict, address, fb_addr);
+	}
 	if (device_parent(dev) != lastparent  gkey_chain_pos != 0)
 		return;
 
@@ -284,21 +298,6 @@ gdium_device_register(device_t dev, void
 		break;
 	}
 
-	if (device_is_a(dev, genfb) || device_is_a(dev, voyagerfb)) {
-		dict = device_properties(dev);
-		/*
-		 * this is a hack
-		 * is_console needs to be checked against reality
-		 */
-		prop_dictionary_set_bool(dict, is_console, 1);
-		prop_dictionary_set_uint32(dict, width, 1024);
-		prop_dictionary_set_uint32(dict, height, 600);
-		prop_dictionary_set_uint32(dict, depth, 16);
-		prop_dictionary_set_uint32(dict, linebytes, 2048);
-		if (fb_addr != 0)
-			prop_dictionary_set_uint32(dict, address, fb_addr);
-	}
-
 	return;
 
 advance:



CVS commit: src/sys/arch/evbmips/loongson

2013-02-28 Thread Michael Lorenz
Module Name:src
Committed By:   macallan
Date:   Thu Feb 28 13:22:36 UTC 2013

Modified Files:
src/sys/arch/evbmips/loongson: yeeloong_machdep.c

Log Message:
make this compile without ISA support in the kernel


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/evbmips/loongson/yeeloong_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/evbmips/loongson/yeeloong_machdep.c
diff -u src/sys/arch/evbmips/loongson/yeeloong_machdep.c:1.4 src/sys/arch/evbmips/loongson/yeeloong_machdep.c:1.5
--- src/sys/arch/evbmips/loongson/yeeloong_machdep.c:1.4	Sat Oct 27 17:17:50 2012
+++ src/sys/arch/evbmips/loongson/yeeloong_machdep.c	Thu Feb 28 13:22:36 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: yeeloong_machdep.c,v 1.4 2012/10/27 17:17:50 chs Exp $	*/
+/*	$NetBSD: yeeloong_machdep.c,v 1.5 2013/02/28 13:22:36 macallan Exp $	*/
 /*	$OpenBSD: yeeloong_machdep.c,v 1.16 2011/04/15 20:40:06 deraadt Exp $	*/
 
 /*
@@ -23,7 +23,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: yeeloong_machdep.c,v 1.4 2012/10/27 17:17:50 chs Exp $);
+__KERNEL_RCSID(0, $NetBSD: yeeloong_machdep.c,v 1.5 2013/02/28 13:22:36 macallan Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -235,8 +235,9 @@ const struct platform yeeloong_platform 
 #endif
 };
 
+#if NISA  0
 static int stray_intr[BONITO_NISA];
-
+#endif
 /*
  * PCI model specific routines
  */
@@ -354,7 +355,7 @@ lemote_intr_map(int dev, int fn, int pin
 /*
  * ISA model specific routines
  */
-
+#if NISA  0
 void
 lemote_isa_attach_hook(device_t parent, device_t self,
 struct isabus_attach_args *iba)
@@ -407,7 +408,7 @@ lemote_isa_intr_string(void *v, int irq)
 
 	return loongson_intr_string(lemote_bonito, BONITO_ISA_IRQ(irq));
 }
-
+#endif
 /*
  * Legacy (ISA) interrupt handling
  */



CVS commit: src/sys/arch/evbmips/loongson

2012-02-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Feb 14 21:34:46 UTC 2012

Modified Files:
src/sys/arch/evbmips/loongson: gdium_machdep.c

Log Message:
add prototypes.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/evbmips/loongson/gdium_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/evbmips/loongson/gdium_machdep.c
diff -u src/sys/arch/evbmips/loongson/gdium_machdep.c:1.3 src/sys/arch/evbmips/loongson/gdium_machdep.c:1.4
--- src/sys/arch/evbmips/loongson/gdium_machdep.c:1.3	Tue Sep 20 01:57:11 2011
+++ src/sys/arch/evbmips/loongson/gdium_machdep.c	Tue Feb 14 16:34:46 2012
@@ -307,7 +307,7 @@ advance:
 }
 
 void
-gdium_powerdown()
+gdium_powerdown(void)
 {
 	REGVAL(BONITO_GPIODATA) |= 0x0002;
 	REGVAL(BONITO_GPIOIE) = ~0x0002;
@@ -316,7 +316,7 @@ gdium_powerdown()
 }
 
 void
-gdium_reset()
+gdium_reset(void)
 {
 	REGVAL(BONITO_GPIODATA) = ~0x0002;
 	REGVAL(BONITO_GPIOIE) = ~0x0002;



CVS commit: src/sys/arch/evbmips/loongson

2012-02-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Feb 14 21:41:02 UTC 2012

Modified Files:
src/sys/arch/evbmips/loongson: generic2e_machdep.c

Log Message:
fix proto


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/evbmips/loongson/generic2e_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/evbmips/loongson/generic2e_machdep.c
diff -u src/sys/arch/evbmips/loongson/generic2e_machdep.c:1.1 src/sys/arch/evbmips/loongson/generic2e_machdep.c:1.2
--- src/sys/arch/evbmips/loongson/generic2e_machdep.c:1.1	Sat Aug 27 09:42:44 2011
+++ src/sys/arch/evbmips/loongson/generic2e_machdep.c	Tue Feb 14 16:41:02 2012
@@ -48,7 +48,7 @@
  * Generic Loongson 2E code and configuration data.
  */
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: generic2e_machdep.c,v 1.1 2011/08/27 13:42:44 bouyer Exp $);
+__KERNEL_RCSID(0, $NetBSD: generic2e_machdep.c,v 1.2 2012/02/14 21:41:02 christos Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -355,7 +355,7 @@ generic2e_isa_intr(int ipl, vaddr_t pc, 
  */
 
 void
-generic2e_reset()
+generic2e_reset(void)
 {
 	REGVAL(BONITO_BONGENCFG) = ~BONITO_BONGENCFG_CPUSELFRESET;
 	REGVAL(BONITO_BONGENCFG) |= BONITO_BONGENCFG_CPUSELFRESET;



CVS commit: src/sys/arch/evbmips/loongson

2012-02-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Feb 14 21:42:22 UTC 2012

Modified Files:
src/sys/arch/evbmips/loongson: yeeloong_machdep.c

Log Message:
prototypes


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/evbmips/loongson/yeeloong_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/evbmips/loongson/yeeloong_machdep.c
diff -u src/sys/arch/evbmips/loongson/yeeloong_machdep.c:1.1 src/sys/arch/evbmips/loongson/yeeloong_machdep.c:1.2
--- src/sys/arch/evbmips/loongson/yeeloong_machdep.c:1.1	Sat Aug 27 09:42:45 2011
+++ src/sys/arch/evbmips/loongson/yeeloong_machdep.c	Tue Feb 14 16:42:22 2012
@@ -474,7 +474,7 @@ lemote_isa_intr(int ipl, vaddr_t pc, uin
 }
 
 uint
-lemote_get_isa_imr()
+lemote_get_isa_imr(void)
 {
 	uint imr1, imr2;
 
@@ -486,7 +486,7 @@ lemote_get_isa_imr()
 }
 
 uint
-lemote_get_isa_isr()
+lemote_get_isa_isr(void)
 {
 	uint isr1, isr2 = 0;
 
@@ -502,7 +502,7 @@ lemote_get_isa_isr()
  */
 
 void
-fuloong_powerdown()
+fuloong_powerdown(void)
 {
 	vaddr_t gpiobase;
 
@@ -514,14 +514,14 @@ fuloong_powerdown()
 }
 
 void
-yeeloong_powerdown()
+yeeloong_powerdown(void)
 {
 	REGVAL(BONITO_GPIODATA) = ~0x0001;
 	REGVAL(BONITO_GPIOIE) = ~0x0001;
 }
 
 void
-lemote_reset()
+lemote_reset(void)
 {
 	wrmsr(GCSC_GLCP_SYS_RST, rdmsr(GCSC_GLCP_SYS_RST) | 1);
 }



CVS commit: src/sys/arch/evbmips/loongson/dev

2012-02-14 Thread Michael Lorenz
Module Name:src
Committed By:   macallan
Date:   Tue Feb 14 22:22:45 UTC 2012

Modified Files:
src/sys/arch/evbmips/loongson/dev: glx.c

Log Message:
fix 'old style function definition' warning:
blah() - blah(void)
ok riz


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/evbmips/loongson/dev/glx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/evbmips/loongson/dev/glx.c
diff -u src/sys/arch/evbmips/loongson/dev/glx.c:1.1 src/sys/arch/evbmips/loongson/dev/glx.c:1.2
--- src/sys/arch/evbmips/loongson/dev/glx.c:1.1	Sat Aug 27 13:42:45 2011
+++ src/sys/arch/evbmips/loongson/dev/glx.c	Tue Feb 14 22:22:45 2012
@@ -21,7 +21,7 @@
  * XXX too many hardcoded numbers... need to expand glxreg.h
  */
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: glx.c,v 1.1 2011/08/27 13:42:45 bouyer Exp $);
+__KERNEL_RCSID(0, $NetBSD: glx.c,v 1.2 2012/02/14 22:22:45 macallan Exp $);
 
 
 #include sys/param.h
@@ -295,7 +295,7 @@ glx_pci_write_hook(void *v, pcitag_t tag
 }
 
 pcireg_t
-glx_get_status()
+glx_get_status(void)
 {
 	uint64_t msr;
 	pcireg_t data;



CVS commit: src/sys/arch/evbmips/loongson

2011-09-19 Thread Michael Lorenz
Module Name:src
Committed By:   macallan
Date:   Tue Sep 20 05:41:59 UTC 2011

Modified Files:
src/sys/arch/evbmips/loongson: gdium_machdep.c

Log Message:
move the early console code over from ../gdium
This is kinda hackish but it works and it's not like there will be new Gdium
revisions anyway.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/evbmips/loongson/gdium_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/evbmips/loongson/gdium_machdep.c
diff -u src/sys/arch/evbmips/loongson/gdium_machdep.c:1.1 src/sys/arch/evbmips/loongson/gdium_machdep.c:1.2
--- src/sys/arch/evbmips/loongson/gdium_machdep.c:1.1	Sat Aug 27 13:42:44 2011
+++ src/sys/arch/evbmips/loongson/gdium_machdep.c	Tue Sep 20 05:41:58 2011
@@ -35,7 +35,14 @@
 #include mips/bonito/bonitoreg.h
 #include mips/bonito/bonitovar.h
 
+#include dev/wscons/wsconsio.h
+#include dev/wscons/wsdisplayvar.h
+#include dev/rasops/rasops.h
+#include dev/wsfont/wsfont.h
+#include dev/wscons/wsdisplay_vconsvar.h
+
 int	gdium_revision = 0;
+static pcireg_t fb_addr = 0;
 
 void	gdium_attach_hook(device_t, device_t, struct pcibus_attach_args *);
 void	gdium_device_register(struct device *, void *);
@@ -78,6 +85,12 @@
 	.reset = gdium_reset
 };
 
+static struct vcons_screen gdium_console_screen;
+
+static struct wsscreen_descr gdium_stdscreen = {
+	.name = std,
+};
+
 void
 gdium_attach_hook(device_t parent, device_t self,
 struct pcibus_attach_args *pba)
@@ -223,6 +236,7 @@
 void
 gdium_device_register(struct device *dev, void *aux)
 {
+	prop_dictionary_t dict;
 	static int gkey_chain_pos = 0;
 	static struct device *lastparent = NULL;
 
@@ -270,6 +284,21 @@
 		break;
 	}
 
+	if (device_is_a(dev, genfb) || device_is_a(dev, voyagerfb)) {
+		dict = device_properties(dev);
+		/*
+		 * this is a hack
+		 * is_console needs to be checked against reality
+		 */
+		prop_dictionary_set_bool(dict, is_console, 1);
+		prop_dictionary_set_uint32(dict, width, 1024);
+		prop_dictionary_set_uint32(dict, height, 600);
+		prop_dictionary_set_uint32(dict, depth, 16);
+		prop_dictionary_set_uint32(dict, linebytes, 2048);
+		if (fb_addr != 0)
+			prop_dictionary_set_uint32(dict, address, fb_addr);
+	}
+
 	return;
 
 advance:
@@ -290,3 +319,60 @@
 	REGVAL(BONITO_GPIODATA) = ~0x0002;
 	REGVAL(BONITO_GPIOIE) = ~0x0002;
 }
+
+/*
+ * Early console code
+ */
+
+int
+gdium_cnattach(bus_space_tag_t memt, bus_space_tag_t iot,
+pci_chipset_tag_t pc, pcitag_t tag, pcireg_t id)
+{
+	struct rasops_info * const ri = gdium_console_screen.scr_ri;
+	long defattr;
+	pcireg_t reg;
+
+
+	/* filter out unrecognized devices */
+	switch (id) {
+	default:
+		return ENODEV;
+	case PCI_ID_CODE(PCI_VENDOR_SILMOTION, PCI_PRODUCT_SILMOTION_SM502):
+		break;
+	}
+
+	wsfont_init();
+	
+	/* set up rasops */
+	ri-ri_width = 1024;
+	ri-ri_height = 600;
+	ri-ri_depth = 16;
+	ri-ri_stride = 0x800;
+
+	/* read the mapping register for the frame buffer */
+	reg = pci_conf_read(pc, tag, PCI_MAPREG_START);
+	fb_addr = reg;
+
+	ri-ri_bits = (char *)MIPS_PHYS_TO_KSEG1(BONITO_PCILO_BASE + reg);
+	ri-ri_flg = RI_CENTER | RI_NO_AUTO;
+
+	memset(ri-ri_bits, 0, 0x20);
+
+	/* use as much of the screen as the font permits */
+	rasops_init(ri, 30, 80);
+
+	rasops_reconfig(ri, ri-ri_height / ri-ri_font-fontheight,
+	ri-ri_width / ri-ri_font-fontwidth);
+
+	gdium_stdscreen.nrows = ri-ri_rows;
+	gdium_stdscreen.ncols = ri-ri_cols;
+	gdium_stdscreen.textops = ri-ri_ops;
+	gdium_stdscreen.capabilities = ri-ri_caps;
+
+	ri-ri_ops.allocattr(ri, 0, ri-ri_rows - 1, 0, defattr);
+
+	wsdisplay_preattach(gdium_stdscreen, ri, 0, 0, defattr);
+	
+	return 0;
+
+}



CVS commit: src/sys/arch/evbmips/loongson

2011-09-19 Thread Michael Lorenz
Module Name:src
Committed By:   macallan
Date:   Tue Sep 20 05:50:17 UTC 2011

Modified Files:
src/sys/arch/evbmips/loongson: machdep.c

Log Message:
make this work with NCOM == 0


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/evbmips/loongson/machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/evbmips/loongson/machdep.c
diff -u src/sys/arch/evbmips/loongson/machdep.c:1.1 src/sys/arch/evbmips/loongson/machdep.c:1.2
--- src/sys/arch/evbmips/loongson/machdep.c:1.1	Sat Aug 27 13:42:45 2011
+++ src/sys/arch/evbmips/loongson/machdep.c	Tue Sep 20 05:50:17 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.1 2011/08/27 13:42:45 bouyer Exp $	*/
+/*	$NetBSD: machdep.c,v 1.2 2011/09/20 05:50:17 macallan Exp $	*/
 
 /*
  * Copyright 2001, 2002 Wasabi Systems, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.1 2011/08/27 13:42:45 bouyer Exp $);
+__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.2 2011/09/20 05:50:17 macallan Exp $);
 
 #include opt_ddb.h
 #include opt_execfmt.h
@@ -140,6 +140,11 @@
 #include dev/ic/comreg.h
 #include dev/ic/comvar.h
 
+bus_space_tag_t comconsiot;
+bus_addr_t comconsaddr;
+int comconsrate = 0;
+#endif /* NCOM  0 */
+
 #ifdef LOW_DEBUG
 #define DPRINTF(x) printf x
 #define DPPRINTF(x) pmon_printf x
@@ -148,11 +153,6 @@
 #define DPPRINTF(x)
 #endif
 
-bus_space_tag_t comconsiot;
-bus_addr_t comconsaddr;
-int comconsrate = 0;
-#endif /* NCOM  0 */
-
 #include sisfb.h
 
 



CVS commit: src/sys/arch/evbmips/loongson

2011-09-19 Thread Michael Lorenz
Module Name:src
Committed By:   macallan
Date:   Tue Sep 20 05:51:34 UTC 2011

Modified Files:
src/sys/arch/evbmips/loongson: autoconf.h machdep.c

Log Message:
call gdium_cnattach()
Now this actually boots on Gdium.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/evbmips/loongson/autoconf.h
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/evbmips/loongson/machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/evbmips/loongson/autoconf.h
diff -u src/sys/arch/evbmips/loongson/autoconf.h:1.1 src/sys/arch/evbmips/loongson/autoconf.h:1.2
--- src/sys/arch/evbmips/loongson/autoconf.h:1.1	Sat Aug 27 13:42:44 2011
+++ src/sys/arch/evbmips/loongson/autoconf.h	Tue Sep 20 05:51:34 2011
@@ -104,4 +104,7 @@
 extern phys_ram_seg_t mem_clusters[];
 extern int mem_cluster_cnt;
 
+int gdium_cnattach(bus_space_tag_t, bus_space_tag_t,
+pci_chipset_tag_t, pcitag_t, pcireg_t);
+
 #endif /* _MACHINE_AUTOCONF_H_ */

Index: src/sys/arch/evbmips/loongson/machdep.c
diff -u src/sys/arch/evbmips/loongson/machdep.c:1.2 src/sys/arch/evbmips/loongson/machdep.c:1.3
--- src/sys/arch/evbmips/loongson/machdep.c:1.2	Tue Sep 20 05:50:17 2011
+++ src/sys/arch/evbmips/loongson/machdep.c	Tue Sep 20 05:51:34 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.2 2011/09/20 05:50:17 macallan Exp $	*/
+/*	$NetBSD: machdep.c,v 1.3 2011/09/20 05:51:34 macallan Exp $	*/
 
 /*
  * Copyright 2001, 2002 Wasabi Systems, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.2 2011/09/20 05:50:17 macallan Exp $);
+__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.3 2011/09/20 05:51:34 macallan Exp $);
 
 #include opt_ddb.h
 #include opt_execfmt.h
@@ -513,6 +513,9 @@
 			sisfb_cnattach(bonito_memt, bonito_iot, bonito_pc, 
 			pcitag, reg);
 #endif
+		if (cn_tab == pmoncons)
+			gdium_cnattach(bonito_memt, bonito_iot, bonito_pc, 
+			pcitag, reg);
 	}
 	DPRINTF((\n));
 



CVS commit: src/sys/arch/evbmips/loongson

2011-09-19 Thread Michael Lorenz
Module Name:src
Committed By:   macallan
Date:   Tue Sep 20 05:57:11 UTC 2011

Modified Files:
src/sys/arch/evbmips/loongson: gdium_machdep.c

Log Message:
wait after twiddling the gpio to power down, it takes a few seconds for it to
take effect. Without this we would run into gdium_reset() and reboot instead
of powering down.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/evbmips/loongson/gdium_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/evbmips/loongson/gdium_machdep.c
diff -u src/sys/arch/evbmips/loongson/gdium_machdep.c:1.2 src/sys/arch/evbmips/loongson/gdium_machdep.c:1.3
--- src/sys/arch/evbmips/loongson/gdium_machdep.c:1.2	Tue Sep 20 05:41:58 2011
+++ src/sys/arch/evbmips/loongson/gdium_machdep.c	Tue Sep 20 05:57:11 2011
@@ -311,6 +311,8 @@
 {
 	REGVAL(BONITO_GPIODATA) |= 0x0002;
 	REGVAL(BONITO_GPIOIE) = ~0x0002;
+	printf(Powering down...\n);
+	while(1) delay(1000);
 }
 
 void



CVS commit: src/sys/arch/evbmips/loongson/dev

2011-09-15 Thread Michael Lorenz
Module Name:src
Committed By:   macallan
Date:   Thu Sep 15 19:29:23 UTC 2011

Modified Files:
src/sys/arch/evbmips/loongson/dev: stvii.c

Log Message:
add envsys support


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/evbmips/loongson/dev/stvii.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/evbmips/loongson/dev/stvii.c
diff -u src/sys/arch/evbmips/loongson/dev/stvii.c:1.2 src/sys/arch/evbmips/loongson/dev/stvii.c:1.3
--- src/sys/arch/evbmips/loongson/dev/stvii.c:1.2	Wed Sep  7 13:37:49 2011
+++ src/sys/arch/evbmips/loongson/dev/stvii.c	Thu Sep 15 19:29:23 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: stvii.c,v 1.2 2011/09/07 13:37:49 macallan Exp $	*/
+/*	$NetBSD: stvii.c,v 1.3 2011/09/15 19:29:23 macallan Exp $	*/
 
 /*-
  * Copyright (C) 2011 Michael Lorenz.
@@ -30,7 +30,7 @@
 
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: stvii.c,v 1.2 2011/09/07 13:37:49 macallan Exp $);
+__KERNEL_RCSID(0, $NetBSD: stvii.c,v 1.3 2011/09/15 19:29:23 macallan Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -94,6 +94,7 @@
 	i2c_tag_t sc_i2c;
 	int sc_address, sc_version;
 	int sc_sleep;
+	int sc_flags, sc_charge;
 	struct sysmon_envsys *sc_sme;
 	envsys_data_t sc_sensor[BAT_NSENSORS];
 	struct sysmon_pswitch sc_sm_acpower;
@@ -106,6 +107,8 @@
 static void stvii_writereg(struct stvii_softc *, int, uint8_t);
 static int stvii_readreg(struct stvii_softc *, int);
 static void stvii_worker(void *);
+static void stvii_setup_envsys(struct stvii_softc *);
+static void stvii_refresh(struct sysmon_envsys *, envsys_data_t *);
 
 CFATTACH_DECL_NEW(stvii, sizeof(struct stvii_softc),
 stvii_match, stvii_attach, NULL, NULL);
@@ -181,6 +184,7 @@
 	if (sysmon_pswitch_register(sc-sc_sm_powerbutton) != 0)
 		printf(%s: unable to register power button with sysmon\n,
 		device_xname(sc-sc_dev));
+	stvii_setup_envsys(sc);
 }
 
 static void
@@ -222,11 +226,13 @@
 static int
 stvii_battery_level(struct stvii_softc *sc)
 {
-	int bl, bh;
+	int bl, bh, ret;
 
 	bl = stvii_readreg(sc, ST7_BATTERY_L);
 	bh = stvii_readreg(sc, ST7_BATTERY_H);
-	return (bl  3) | (bh  2);	
+	ret = (bl  3) | (bh  2);
+	ret = ((ret * 1) / 1024) * 1000;
+	return ret;
 }
 
 static void
@@ -274,6 +280,7 @@
 			}
 			status = st;
 		}
+		sc-sc_flags = status;
 		if (0) {
 			bl = stvii_battery_level(sc);
 			if (bl != battery_level) {
@@ -284,3 +291,81 @@
 		tsleep(sc-sc_sleep, 0, stvii, hz / 2);
 	}
 }
+
+#define INITDATA(index, unit, string)	\
+	sc-sc_sensor[index].units = unit; \
+	sc-sc_sensor[index].state = ENVSYS_SINVALID;			\
+	snprintf(sc-sc_sensor[index].desc,\
+	sizeof(sc-sc_sensor[index].desc), %s, string);
+
+static void
+stvii_setup_envsys(struct stvii_softc *sc)
+{
+	int i;
+
+	sc-sc_sme = sysmon_envsys_create();
+
+	INITDATA(BAT_AC_PRESENT, ENVSYS_INDICATOR, AC present);
+	INITDATA(BAT_BATTERY_PRESENT, ENVSYS_INDICATOR, Battery present);
+	INITDATA(BAT_CHARGING, ENVSYS_BATTERY_CHARGE, Battery charging);
+	INITDATA(BAT_CHARGE, ENVSYS_SVOLTS_DC, Battery voltage);
+	INITDATA(BAT_MAX_CHARGE, ENVSYS_SVOLTS_DC, Battery design cap);
+#undef INITDATA
+
+	for (i = 0; i  BAT_NSENSORS; i++) {
+		if (sysmon_envsys_sensor_attach(sc-sc_sme,
+		sc-sc_sensor[i])) {
+			sysmon_envsys_destroy(sc-sc_sme);
+			return;
+		}
+	}
+
+	sc-sc_sme-sme_name = device_xname(sc-sc_dev);
+	sc-sc_sme-sme_cookie = sc;
+	sc-sc_sme-sme_refresh = stvii_refresh;
+
+	if (sysmon_envsys_register(sc-sc_sme)) {
+		aprint_error_dev(sc-sc_dev,
+		unable to register with sysmon\n);
+		sysmon_envsys_destroy(sc-sc_sme);
+	}
+}
+
+static void
+stvii_refresh(struct sysmon_envsys *sme, envsys_data_t *edata)
+{
+	struct stvii_softc *sc = sme-sme_cookie;
+	int which = edata-sensor, ctl, bat;
+
+	edata-state = ENVSYS_SINVALID;
+	switch (which) {
+	case BAT_AC_PRESENT:
+		edata-value_cur = (sc-sc_flags  STS_AC_AVAILABLE);
+		edata-state = ENVSYS_SVALID;
+		break;
+	case BAT_BATTERY_PRESENT:
+		edata-value_cur = (sc-sc_flags  STS_BATTERY_PRESENT);
+		edata-state = ENVSYS_SVALID;
+		break;
+	case BAT_CHARGE:
+		if (sc-sc_flags  STS_BATTERY_PRESENT) {
+			bat = stvii_battery_level(sc);
+			edata-value_cur = bat;
+			edata-state = ENVSYS_SVALID;
+		}
+		break;
+	case BAT_MAX_CHARGE:
+		if (sc-sc_flags  STS_BATTERY_PRESENT) {
+			edata-value_cur = 830;
+			/*edata-state = ENVSYS_SVALID;*/
+		}
+		break;
+	case BAT_CHARGING:
+		ctl = stvii_readreg(sc, ST7_CONTROL);
+		if (ctl != -1) {
+			edata-value_cur = ctl  STC_CHARGE_ENABLE;
+		}
+		edata-state = ENVSYS_SVALID;
+		break;
+	}
+}



CVS commit: src/sys/arch/evbmips/loongson/dev

2011-09-07 Thread Michael Lorenz
Module Name:src
Committed By:   macallan
Date:   Wed Sep  7 13:37:49 UTC 2011

Modified Files:
src/sys/arch/evbmips/loongson/dev: stvii.c

Log Message:
report power button events to sysmon


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/evbmips/loongson/dev/stvii.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/evbmips/loongson/dev/stvii.c
diff -u src/sys/arch/evbmips/loongson/dev/stvii.c:1.1 src/sys/arch/evbmips/loongson/dev/stvii.c:1.2
--- src/sys/arch/evbmips/loongson/dev/stvii.c:1.1	Thu Sep  1 14:07:37 2011
+++ src/sys/arch/evbmips/loongson/dev/stvii.c	Wed Sep  7 13:37:49 2011
@@ -1,7 +1,7 @@
-/*	$NetBSD: stvii.c,v 1.1 2011/09/01 14:07:37 macallan Exp $	*/
+/*	$NetBSD: stvii.c,v 1.2 2011/09/07 13:37:49 macallan Exp $	*/
 
 /*-
- * Copyright (C) 2005 Michael Lorenz.
+ * Copyright (C) 2011 Michael Lorenz.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -30,7 +30,7 @@
 
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: stvii.c,v 1.1 2011/09/01 14:07:37 macallan Exp $);
+__KERNEL_RCSID(0, $NetBSD: stvii.c,v 1.2 2011/09/07 13:37:49 macallan Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -92,18 +92,19 @@
 struct stvii_softc {
 	device_t sc_dev;
 	i2c_tag_t sc_i2c;
-	int sc_address;
+	int sc_address, sc_version;
 	int sc_sleep;
 	struct sysmon_envsys *sc_sme;
 	envsys_data_t sc_sensor[BAT_NSENSORS];
 	struct sysmon_pswitch sc_sm_acpower;
 	struct sysmon_pswitch sc_sm_lid;
+	struct sysmon_pswitch sc_sm_powerbutton;
 };
 
 static void stvii_attach(device_t, device_t, void *);
 static int stvii_match(device_t, cfdata_t, void *);
 static void stvii_writereg(struct stvii_softc *, int, uint8_t);
-static uint8_t stvii_readreg(struct stvii_softc *, int);
+static int stvii_readreg(struct stvii_softc *, int);
 static void stvii_worker(void *);
 
 CFATTACH_DECL_NEW(stvii, sizeof(struct stvii_softc),
@@ -139,7 +140,7 @@
 	aprint_normal(: ST7 Microcontroller\n);
 	sc-sc_i2c = args-ia_tag;
 	ver = stvii_readreg(sc, ST7_VERSION);
-
+	sc-sc_version = ver;
 	aprint_normal_dev(sc-sc_dev, firmware version %d.%d\n, (ver  4)  0xf, ver  0xf);
 #ifdef STVII_DEBUG
 	{
@@ -174,6 +175,12 @@
 	if (sysmon_pswitch_register(sc-sc_sm_lid) != 0)
 		printf(%s: unable to register lid switch with sysmon\n,
 		device_xname(sc-sc_dev));
+	memset(sc-sc_sm_powerbutton, 0, sizeof(struct sysmon_pswitch));
+	sc-sc_sm_powerbutton.smpsw_name = Power Button;
+	sc-sc_sm_powerbutton.smpsw_type = PSWITCH_TYPE_POWER;
+	if (sysmon_pswitch_register(sc-sc_sm_powerbutton) != 0)
+		printf(%s: unable to register power button with sysmon\n,
+		device_xname(sc-sc_dev));
 }
 
 static void
@@ -189,19 +196,26 @@
 	iic_release_bus(sc-sc_i2c, 0);
 }
 
-static uint8_t
+static int
 stvii_readreg(struct stvii_softc *sc, int reg)
 {
 	uint8_t inreg[1], outreg[1];
+	int ret = 1, bail = 0;
 
 	if ((reg  0) || (reg  5))
 		return 0xff;
 	inreg[0] = 0x77;
 	outreg[0] = reg;
 	iic_acquire_bus(sc-sc_i2c, 0);
-	iic_exec(sc-sc_i2c, I2C_OP_READ_WITH_STOP, sc-sc_address, outreg,
-	1, inreg, 1, 0);
+	while ((ret != 0)  (bail  10)) {
+		ret = iic_exec(sc-sc_i2c, I2C_OP_READ_WITH_STOP,
+		sc-sc_address, outreg, 1, inreg, 1, 0);
+		bail++;
+		delay(10);
+	}
 	iic_release_bus(sc-sc_i2c, 0);
+	if (ret != 0)
+		return -1;
 	return inreg[0];
 }
 
@@ -219,13 +233,27 @@
 stvii_worker(void *cookie)
 {
 	struct stvii_softc *sc = cookie;
-	uint8_t status = 0, st;
+	int status = 0, st;
 	int battery_level = 0, bl;
 	int ok = TRUE;
 
 	while (ok) {
 		st = stvii_readreg(sc, ST7_STATUS);
-		if (st != status) {
+		/*
+		 * I get i2c timeouts when the power button is pressed.
+		 * According to the linux driver this happens on firmware
+		 * version 0x13 and newer, mine is 0x16.
+		 * So, when we see read errors on the right version we assume
+		 * it's the power button as long as the lid is open
+		 * ( the button is inside the lid )
+		 */
+		if ((st == -1)  (sc-sc_version = 0x13)) {
+			if ((status  (STS_LID_CLOSED | STS_POWER_BTN_DOWN) )
+			== 0) {
+				st = status | STS_POWER_BTN_DOWN;
+			}
+		}
+		if ((st != -1)  (st != status)) {
 			if ((status ^ st)  STS_LID_CLOSED) {
 sysmon_pswitch_event(sc-sc_sm_lid, 
 ((st  STS_LID_CLOSED) ?
@@ -238,6 +266,12 @@
  PSWITCH_EVENT_PRESSED :
  PSWITCH_EVENT_RELEASED));
 			}
+			if ((status ^ st)  STS_POWER_BTN_DOWN) {
+sysmon_pswitch_event(sc-sc_sm_powerbutton, 
+((st  STS_POWER_BTN_DOWN) ?
+ PSWITCH_EVENT_PRESSED :
+ PSWITCH_EVENT_RELEASED));
+			}
 			status = st;
 		}
 		if (0) {