Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch Add a driver for RDC's vortex86/PMX-1000 SoC PCI/IS...



details:   https://anonhg.NetBSD.org/src/rev/70919b0611d8
branches:  trunk
changeset: 763799:70919b0611d8
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Mon Apr 04 17:09:39 2011 +0000

description:
Add a driver for RDC's vortex86/PMX-1000 SoC PCI/ISA bridge, with support
for the integrated watchdog timer.

diffstat:

 sys/arch/i386/conf/ALL     |    6 +-
 sys/arch/i386/conf/GENERIC |    7 +-
 sys/arch/x86/pci/files.pci |    8 +-
 sys/arch/x86/pci/rdcpcib.c |  301 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 316 insertions(+), 6 deletions(-)

diffs (truncated from 403 to 300 lines):

diff -r 093fa1cb5fa5 -r 70919b0611d8 sys/arch/i386/conf/ALL
--- a/sys/arch/i386/conf/ALL    Mon Apr 04 16:41:34 2011 +0000
+++ b/sys/arch/i386/conf/ALL    Mon Apr 04 17:09:39 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: ALL,v 1.302 2011/04/04 14:33:51 bouyer Exp $
+# $NetBSD: ALL,v 1.303 2011/04/04 17:09:39 bouyer Exp $
 # From NetBSD: GENERIC,v 1.787 2006/10/01 18:37:54 bouyer Exp
 #
 # ALL machine description file
@@ -17,7 +17,7 @@
 
 options        INCLUDE_CONFIG_FILE     # embed config file in kernel binary
 
-#ident                 "ALL-$Revision: 1.302 $"
+#ident                 "ALL-$Revision: 1.303 $"
 
 maxusers       64              # estimated number of users
 
@@ -487,6 +487,7 @@
 gscpcib* at pci? dev ? function ?      # NS Geode PCI-ISA w/ GPIO support
 viapcib* at pci? dev ? function ?      # VIA VT8235 PCI-ISA w/ SMBus support
 iic*   at viapcib?
+rdcpcib* at pci? dev ? function ?      # RDC Vortex86/PMX-1000 PCI-ISA w/
 pchb*  at pci? dev ? function ?        # PCI-Host bridges
 pceb*  at pci? dev ? function ?        # PCI-EISA bridges
 pcib*  at pci? dev ? function ?        # PCI-ISA bridges
@@ -509,6 +510,7 @@
 isa0   at piixpcib?
 isa0   at gscpcib?
 isa0   at viapcib?
+isa0   at rdcpcib?
 isa0   at mainbus?
 isa0   at pceb?
 isa0   at pcib?
diff -r 093fa1cb5fa5 -r 70919b0611d8 sys/arch/i386/conf/GENERIC
--- a/sys/arch/i386/conf/GENERIC        Mon Apr 04 16:41:34 2011 +0000
+++ b/sys/arch/i386/conf/GENERIC        Mon Apr 04 17:09:39 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.1028 2011/04/04 14:33:51 bouyer Exp $
+# $NetBSD: GENERIC,v 1.1029 2011/04/04 17:09:39 bouyer Exp $
 #
 # GENERIC machine description file
 #
@@ -22,7 +22,7 @@
 
 options        INCLUDE_CONFIG_FILE     # embed config file in kernel binary
 
-#ident                 "GENERIC-$Revision: 1.1028 $"
+#ident                 "GENERIC-$Revision: 1.1029 $"
 
 maxusers       64              # estimated number of users
 
@@ -467,6 +467,8 @@
 #gscpcib* at pci? dev ? function ?     # NS Geode PCI-ISA w/ GPIO support
 viapcib* at pci? dev ? function ?      # VIA VT8235 PCI-ISA w/ SMBus support
 iic*   at viapcib?
+rdcpcib* at pci? dev ? function ?      # RDC Vortex86/PMX-1000 PCI-ISA w/
+                                       # watchdog
 pchb*  at pci? dev ? function ?        # PCI-Host bridges
 pceb*  at pci? dev ? function ?        # PCI-EISA bridges
 pcib*  at pci? dev ? function ?        # PCI-ISA bridges
@@ -489,6 +491,7 @@
 #isa0  at piixpcib?
 #isa0  at gscpcib?
 isa0   at viapcib?
+isa0   at rdcpcib?
 isa0   at mainbus?
 isa0   at pceb?
 isa0   at pcib?
diff -r 093fa1cb5fa5 -r 70919b0611d8 sys/arch/x86/pci/files.pci
--- a/sys/arch/x86/pci/files.pci        Mon Apr 04 16:41:34 2011 +0000
+++ b/sys/arch/x86/pci/files.pci        Mon Apr 04 17:09:39 2011 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.pci,v 1.10 2010/07/23 00:43:21 jakllsch Exp $
+#      $NetBSD: files.pci,v 1.11 2011/04/04 17:09:39 bouyer Exp $
 
 device         aapic
 attach         aapic at pci
@@ -16,7 +16,7 @@
 device pcib: isabus
 attach pcib at pci
 file   arch/x86/pci/pcib.c             pcib | ichlpcib | gscpcib | piixpcib |
-                                       viapcib | amdpcib | gcscpcib
+                                       viapcib | amdpcib | gcscpcib | rdcpcib
 
 device amdpcib {} : isabus
 attach amdpcib at pci
@@ -31,6 +31,10 @@
 file   arch/x86/pci/amdtemp.c          amdtemp
 
 # PCI-LPC bridges
+device rdcpcib: isabus, sysmon_wdog
+attach rdcpcib at pci
+file   arch/x86/pci/rdcpcib.c          rdcpcib
+
 define fwhichbus {}
 define hpetichbus {}
 device ichlpcib: acpipmtimer, isabus, sysmon_wdog, fwhichbus, hpetichbus, gpiobus
diff -r 093fa1cb5fa5 -r 70919b0611d8 sys/arch/x86/pci/rdcpcib.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/x86/pci/rdcpcib.c        Mon Apr 04 17:09:39 2011 +0000
@@ -0,0 +1,301 @@
+/*     $NetBSD: rdcpcib.c,v 1.1 2011/04/04 17:09:39 bouyer Exp $       */
+
+/*
+ * Copyright (c) 2011 Manuel Bouyer.
+ *
+ * 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.
+ */
+
+/*
+ * driver for the RDC vortex86/PMX-1000 SoC PCI-ISA bridge, which also drives
+ * the watchdog timer
+ */
+
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: rdcpcib.c,v 1.1 2011/04/04 17:09:39 bouyer Exp $");
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/sysctl.h>
+#include <sys/timetc.h>
+#include <sys/gpio.h>
+#include <machine/bus.h>
+
+#include <dev/pci/pcivar.h>
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcidevs.h>
+
+#include <dev/gpio/gpiovar.h>
+#include <dev/sysmon/sysmonvar.h>
+
+#include "pcibvar.h"
+
+/*
+ * special registers: iospace-registers for indirect access to timer and GPIO
+ */
+#define RDC_IND_BASE 0x22
+#define RDC_IND_SIZE 0x2
+#define RDC_IND_ADDR 0
+#define RDC_IND_DATA 1
+
+struct rdcpcib_softc {
+       struct pcib_softc       rdc_pcib;
+       
+       /* indirect registers mapping */
+       bus_space_tag_t         rdc_iot;
+       bus_space_handle_t      rdc_ioh;
+
+       /* Watchdog suppoprt */
+       struct sysmon_wdog      rdc_smw;
+};
+
+static int rdcpcibmatch(device_t, cfdata_t, void *);
+static void rdcpcibattach(device_t, device_t, void *);
+static int rdcpcibdetach(device_t, int);
+
+static uint8_t rdc_ind_read(struct rdcpcib_softc *, uint8_t);
+static void rdc_ind_write(struct rdcpcib_softc *, uint8_t, uint8_t);
+
+static void rdc_wdtimer_configure(device_t);
+static int rdc_wdtimer_unconfigure(device_t, int);
+static int rdc_wdtimer_setmode(struct sysmon_wdog *);
+static int rdc_wdtimer_tickle(struct sysmon_wdog *);
+static void rdc_wdtimer_stop(struct rdcpcib_softc *);
+static void rdc_wdtimer_start(struct rdcpcib_softc *);
+
+CFATTACH_DECL2_NEW(rdcpcib, sizeof(struct rdcpcib_softc),
+    rdcpcibmatch, rdcpcibattach, rdcpcibdetach, NULL,
+    pcibrescan, pcibchilddet);
+
+static int
+rdcpcibmatch(device_t parent, cfdata_t match, void *aux)
+{
+       struct pci_attach_args *pa = aux;
+
+       if (PCI_CLASS(pa->pa_class) != PCI_CLASS_BRIDGE ||
+           PCI_SUBCLASS(pa->pa_class) != PCI_SUBCLASS_BRIDGE_ISA)
+               return 0;
+
+       if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_RDC &&
+           PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_RDC_PCIB)
+                       return 10;
+
+       return 0;
+}
+
+static void
+rdcpcibattach(device_t parent, device_t self, void *aux)
+{
+       struct rdcpcib_softc *sc = device_private(self);
+
+       /* generic PCI/ISA bridge */
+       pcibattach(parent, self, aux);
+
+       /* map indirect registers */
+       sc->rdc_iot = x86_bus_space_io;
+       if (bus_space_map(sc->rdc_iot, RDC_IND_BASE, RDC_IND_SIZE, 0,
+           &sc->rdc_ioh) != 0) {
+               aprint_error_dev(self, "couldn't map indirect registers\n");
+               return;
+       }
+
+       /* Set up the watchdog. */
+       rdc_wdtimer_configure(self);
+
+       /* Install power handler XXX */
+       if (!pmf_device_register(self, NULL, NULL))
+               aprint_error_dev(self, "couldn't establish power handler\n");
+}
+
+static int
+rdcpcibdetach(device_t self, int flags)
+{
+       struct rdcpcib_softc *sc = device_private(self);
+       int rc;
+
+       pmf_device_deregister(self);
+
+       if ((rc = rdc_wdtimer_unconfigure(self, flags)) != 0)
+               return rc;
+
+       bus_space_unmap(sc->rdc_iot, sc->rdc_ioh, RDC_IND_SIZE);
+       return pcibdetach(self, flags);
+}
+
+/* indirect registers read/write */
+static uint8_t
+rdc_ind_read(struct rdcpcib_softc *sc, uint8_t addr)
+{
+       bus_space_write_1(sc->rdc_iot, sc->rdc_ioh, RDC_IND_ADDR, addr);
+       return bus_space_read_1(sc->rdc_iot, sc->rdc_ioh, RDC_IND_DATA);
+}
+
+static void
+rdc_ind_write(struct rdcpcib_softc *sc, uint8_t addr, uint8_t data)
+{
+       bus_space_write_1(sc->rdc_iot, sc->rdc_ioh, RDC_IND_ADDR, addr);
+       bus_space_write_1(sc->rdc_iot, sc->rdc_ioh, RDC_IND_DATA, data);
+}
+
+/*
+ * watchdog timer registers
+ */
+
+/* control */
+#define RDC_WDT0_CTRL  0x37
+#define RDC_WDT0_CTRL_EN       0x40
+
+/* signal select */
+#define RDC_WDT0_SSEL  0x38
+#define RDC_WDT0_SSEL_MSK      0xf0
+#define RDC_WDT0_SSEL_NMI      0xc0
+#define RDC_WDT0_SSEL_RST      0xd0
+
+/* counter */
+#define RDC_WDT0_CNTL  0x39
+#define RDC_WDT0_CNTH  0x3A
+#define RDC_WDT0_CNTU  0x3B
+#define RDC_WDT0_FREQ          32768 /* Hz */
+#define RDC_WDT0_PERIOD_MAX    (1 << 24)
+
+/* clear counter */
+#define RDC_WDT0_CTRL1 0x3c
+#define RDC_WDT0_CTRL1_RELOAD  0x40
+#define RDC_WDT0_CRTL1_FIRE    0x80
+
+
+/*
+ * Initialize the watchdog timer.
+ */
+static void
+rdc_wdtimer_configure(device_t self)
+{
+       struct rdcpcib_softc *sc = device_private(self);
+       uint8_t reg;
+
+       /* Explicitly stop the timer. */
+       rdc_wdtimer_stop(sc);



Home | Main Index | Thread Index | Old Index