Module Name:    src
Committed By:   nisimura
Date:           Thu Feb 10 13:54:45 UTC 2011

Modified Files:
        src/sys/arch/sandpoint: README.NAS
        src/sys/arch/sandpoint/pci: pci_machdep.c
        src/sys/arch/sandpoint/sandpoint: satmgr.c

Log Message:
- add D-Link EPIC defition to pci_machdep.c
- change the way to reboot/pwroff to make satmgr.c more flexible for
  a multiple byte sat protocol.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/sandpoint/README.NAS
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/sandpoint/pci/pci_machdep.c
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/sandpoint/sandpoint/satmgr.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/sandpoint/README.NAS
diff -u src/sys/arch/sandpoint/README.NAS:1.11 src/sys/arch/sandpoint/README.NAS:1.12
--- src/sys/arch/sandpoint/README.NAS:1.11	Tue Feb  8 12:21:26 2011
+++ src/sys/arch/sandpoint/README.NAS	Thu Feb 10 13:54:45 2011
@@ -1,4 +1,4 @@
-$NetBSD: README.NAS,v 1.11 2011/02/08 12:21:26 phx Exp $
+$NetBSD: README.NAS,v 1.12 2011/02/10 13:54:45 nisimura Exp $
 
 //// MPC8241/8245 NAS products ////
 
@@ -41,7 +41,7 @@
 Synology	12, 13, 14, 15	-> 4, 0, 1, 2
 QNAP		13, 14, 15, 16	-> 0, 1, 2, 3
 StorCenter	12, 13, 14, 15  -> 0, 1, 2, 3
-DLink		13, 14, 15, 16	-> 0, 1, 2, 3
+DLink		13, 14, 15, 16	-> 0, 1, 3, 4
 
 - USB EHCI is a multiple function PCI device which has
   pin assignment A, B and C.

Index: src/sys/arch/sandpoint/pci/pci_machdep.c
diff -u src/sys/arch/sandpoint/pci/pci_machdep.c:1.21 src/sys/arch/sandpoint/pci/pci_machdep.c:1.22
--- src/sys/arch/sandpoint/pci/pci_machdep.c:1.21	Mon Feb  7 13:35:21 2011
+++ src/sys/arch/sandpoint/pci/pci_machdep.c	Thu Feb 10 13:54:45 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: pci_machdep.c,v 1.21 2011/02/07 13:35:21 nisimura Exp $	*/
+/*	$NetBSD: pci_machdep.c,v 1.22 2011/02/10 13:54:45 nisimura Exp $	*/
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
@@ -43,7 +43,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.21 2011/02/07 13:35:21 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.22 2011/02/10 13:54:45 nisimura Exp $");
 
 #include "opt_pci.h"
 
@@ -95,6 +95,7 @@
 #define BRD_QNAPTS101		101
 #define BRD_SYNOLOGY		102
 #define BRD_STORCENTER		103
+#define BRD_DLINKDSM		104
 #define BRD_UNKNOWN		-1
 
 #define	PCI_CONFIG_ENABLE	0x80000000UL
@@ -104,7 +105,7 @@
     struct pcibus_attach_args *pba)
 {
 	pcitag_t tag;
-	pcireg_t dev11, dev22, dev15, dev13;
+	pcireg_t dev11, dev22, dev15, dev13, dev16;
 
 	tag = pci_make_tag(pba->pba_pc, pba->pba_bus, 11, 0);
 	dev11 = pci_conf_read(pba->pba_pc, tag, PCI_CLASS_REG);
@@ -150,7 +151,14 @@
 		brdtype = BRD_STORCENTER;
 		return;
 	}
-	
+	tag = pci_make_tag(pba->pba_pc, pba->pba_bus, 16, 0);
+	dev16 = pci_conf_read(pba->pba_pc, tag, PCI_ID_REG);
+	if (PCI_VENDOR(dev16) == PCI_VENDOR_ACARD) {
+		/* ACARD ATP865 at dev 16 */
+		brdtype = BRD_DLINKDSM;
+		return;
+	}
+
 	brdtype = BRD_UNKNOWN;
 }
 
@@ -336,6 +344,10 @@
 		/* map line 12,13-15 to EPIC IRQ4,0-2 */
 		*ihp = (line == 12) ? 4 : line - 13;
 		break;
+	case BRD_DLINKDSM:
+		/* map line 13,14,15,16 to EPIC IRQ0,1,3,4 */
+		*ihp = (line < 15) ? line - 13 : line - 12;
+		break;
 	case BRD_STORCENTER:
 	default:
 		/* map line 12-15 to EPIC IRQ0-3 */

Index: src/sys/arch/sandpoint/sandpoint/satmgr.c
diff -u src/sys/arch/sandpoint/sandpoint/satmgr.c:1.2 src/sys/arch/sandpoint/sandpoint/satmgr.c:1.3
--- src/sys/arch/sandpoint/sandpoint/satmgr.c:1.2	Thu Jun  3 10:44:21 2010
+++ src/sys/arch/sandpoint/sandpoint/satmgr.c	Thu Feb 10 13:54:45 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: satmgr.c,v 1.2 2010/06/03 10:44:21 phx Exp $ */
+/* $NetBSD: satmgr.c,v 1.3 2011/02/10 13:54:45 nisimura Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -55,6 +55,9 @@
 #include <sandpoint/sandpoint/eumbvar.h>
 #include "locators.h"
 
+
+struct satops;
+
 struct satmgr_softc {
 	device_t		sc_dev;
 	bus_space_tag_t		sc_iot;
@@ -71,6 +74,8 @@
 	char sc_rd_buf[16], *sc_rd_lim, *sc_rd_cur, *sc_rd_ptr;
 	char sc_wr_buf[16], *sc_wr_lim, *sc_wr_cur, *sc_wr_ptr;
 	int sc_rd_cnt, sc_wr_cnt;
+	int sc_btnstate;
+	struct satops		*sc_ops;
 };
 
 static int  satmgr_match(device_t, cfdata_t, void *);
@@ -104,24 +109,30 @@
 static void txintr(struct satmgr_softc *);
 static void startoutput(struct satmgr_softc *);
 static void swintr(void *);
+static void kreboot(struct satmgr_softc *);
+static void sreboot(struct satmgr_softc *);
+static void qreboot(struct satmgr_softc *);
+static void kpwroff(struct satmgr_softc *);
+static void spwroff(struct satmgr_softc *);
+static void qpwroff(struct satmgr_softc *);
 static void kbutton(struct satmgr_softc *, int);
 static void sbutton(struct satmgr_softc *, int);
 static void qbutton(struct satmgr_softc *, int);
 static void guarded_pbutton(void *);
 static void sched_sysmon_pbutton(void *);
 
-struct satmsg {
+struct satops {
 	const char *family;
-	const char *reboot, *poweroff;
+	void (*reboot)(struct satmgr_softc *);
+	void (*pwroff)(struct satmgr_softc *);
 	void (*dispatch)(struct satmgr_softc *, int);
 };
 
-static const struct satmsg satmodel[] = {
-    { "kurobox",  "CCGG", "EEGG", kbutton },
-    { "synology", "C",    "1",    sbutton },
-    { "qnap",     "f",    "A",    qbutton }
+static struct satops satmodel[] = {
+    { "kurobox",  kreboot, kpwroff, kbutton },
+    { "synology", sreboot, spwroff, sbutton },
+    { "qnap",     qreboot, qpwroff, qbutton }
 };
-static const struct satmsg *satmgr_msg;
 
 /* single byte stride register layout */
 #define RBR		0
@@ -156,23 +167,24 @@
 	struct eumb_attach_args *eaa = aux;
 	struct satmgr_softc *sc = device_private(self);
 	struct btinfo_prodfamily *pfam;
+	struct satops *ops;
 	int i, sataddr, epicirq;
 
 	found = 1;
 	
 	if ((pfam = lookup_bootinfo(BTINFO_PRODFAMILY)) == NULL)
 		goto notavail;
-	satmgr_msg = NULL;
+	ops = NULL;
 	for (i = 0; i < (int)(sizeof(satmodel)/sizeof(satmodel[0])); i++) {
 		if (strcmp(pfam->name, satmodel[i].family) == 0) {
-			satmgr_msg = &satmodel[i];
+			ops = &satmodel[i];
 			break;
 		}
 	}
-	if (satmgr_msg == NULL)
+	if (ops == NULL)
 		goto notavail;
-	
-	aprint_normal(": button manager (%s)\n", satmgr_msg->family);
+	aprint_normal(": button manager (%s)\n", ops->family);
+	sc->sc_ops = ops;
 
 	sc->sc_dev = self;
 	sataddr = (eaa->eumb_unit == 0) ? 0x4500 : 0x4600;
@@ -192,6 +204,7 @@
 	mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_HIGH);
 	cv_init(&sc->sc_rdcv, "satrd");
 	cv_init(&sc->sc_wrcv, "satwr");
+	sc->sc_btnstate = 0;
 
 	epicirq = (eaa->eumb_unit == 0) ? 24 : 25;
 	intr_establish(epicirq + 16, IST_LEVEL, IPL_SERIAL, hwintr, sc);
@@ -210,7 +223,7 @@
 		aprint_error_dev(sc->sc_dev,
 		    "unable to register power button with sysmon\n");
 
-	if (strcmp(satmgr_msg->family, "kurobox") == 0) {
+	if (strcmp(ops->family, "kurobox") == 0) {
 		const struct sysctlnode *rnode;
 		struct sysctllog *clog;
 
@@ -244,14 +257,12 @@
 static void
 satmgr_reboot(int howto)
 {
-	const char *msg;
 	struct satmgr_softc *sc = device_lookup_private(&satmgr_cd, 0);
-
+	
 	if ((howto & RB_POWERDOWN) == RB_AUTOBOOT)
-		msg = satmgr_msg->reboot;	/* REBOOT */
+		(*sc->sc_ops->reboot)(sc);	/* REBOOT */
 	else
-		msg = satmgr_msg->poweroff;	/* HALT or POWERDOWN */
-	send_sat(sc, msg);
+		(*sc->sc_ops->pwroff)(sc);	/* HALT or POWERDOWN */
 	tsleep(satmgr_reboot, PWAIT, "reboot", 0);
 	/*NOTREACHED*/
 }
@@ -576,7 +587,7 @@
 	mutex_spin_enter(&sc->sc_lock);
 	ptr = sc->sc_rd_ptr;
 	for (n = 0; n < sc->sc_rd_cnt; n++) {
-		(*satmgr_msg->dispatch)(sc, *ptr);
+		(*sc->sc_ops->dispatch)(sc, *ptr);
 		if (++ptr == sc->sc_rd_lim)
 			ptr = &sc->sc_rd_buf[0];
 	}
@@ -592,6 +603,20 @@
 }
 
 static void
+kreboot(struct satmgr_softc *sc)
+{
+
+	send_sat(sc, "CCGG");
+}
+
+static void
+kpwroff(struct satmgr_softc *sc)
+{
+
+	send_sat(sc, "EEGG");
+}
+
+static void
 kbutton(struct satmgr_softc *sc, int ch)
 {
 
@@ -616,6 +641,20 @@
 }
 
 static void
+sreboot(struct satmgr_softc *sc)
+{
+
+	send_sat(sc, "C");
+}
+
+static void
+spwroff(struct satmgr_softc *sc)
+{
+
+	send_sat(sc, "1");
+}
+
+static void
 sbutton(struct satmgr_softc *sc, int ch)
 {
 
@@ -631,6 +670,20 @@
 }
 
 static void
+qreboot(struct satmgr_softc *sc)
+{
+
+	send_sat(sc, "f");
+}
+
+static void
+qpwroff(struct satmgr_softc *sc)
+{
+
+	send_sat(sc, "A");
+}
+
+static void
 qbutton(struct satmgr_softc *sc, int ch)
 {
 	/* research in progress */

Reply via email to