Module Name:    src
Committed By:   phx
Date:           Sat Dec 17 20:20:38 UTC 2011

Modified Files:
        src/sys/arch/sandpoint/conf: GENERIC files.sandpoint
        src/sys/arch/sandpoint/include: bus_funcs.h
        src/sys/arch/sandpoint/sandpoint: machdep.c mainbus.c
Added Files:
        src/sys/arch/sandpoint/include: autoconf.h
        src/sys/arch/sandpoint/sandpoint: flash_cfi.c
Removed Files:
        src/sys/arch/sandpoint/include: bus.h

Log Message:
Added NOR flash driver, using nor(4) and flash(4).


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/sys/arch/sandpoint/conf/GENERIC
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/sandpoint/conf/files.sandpoint
cvs rdiff -u -r0 -r1.1 src/sys/arch/sandpoint/include/autoconf.h
cvs rdiff -u -r1.8 -r0 src/sys/arch/sandpoint/include/bus.h
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/sandpoint/include/bus_funcs.h
cvs rdiff -u -r0 -r1.1 src/sys/arch/sandpoint/sandpoint/flash_cfi.c
cvs rdiff -u -r1.59 -r1.60 src/sys/arch/sandpoint/sandpoint/machdep.c
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/sandpoint/sandpoint/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/sandpoint/conf/GENERIC
diff -u src/sys/arch/sandpoint/conf/GENERIC:1.61 src/sys/arch/sandpoint/conf/GENERIC:1.62
--- src/sys/arch/sandpoint/conf/GENERIC:1.61	Tue Nov 22 21:25:34 2011
+++ src/sys/arch/sandpoint/conf/GENERIC	Sat Dec 17 20:20:37 2011
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.61 2011/11/22 21:25:34 tls Exp $
+# $NetBSD: GENERIC,v 1.62 2011/12/17 20:20:37 phx Exp $
 #
 # machine description file for GENERIC NAS
 # 
@@ -22,7 +22,7 @@ include 	"arch/sandpoint/conf/std.sandpo
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-#ident 		"GENERIC-$Revision: 1.61 $"
+#ident 		"GENERIC-$Revision: 1.62 $"
 
 maxusers	32
 
@@ -174,8 +174,12 @@ options 	RTC_OFFSET=0	# hardware clock i
 mainbus0	at root
 
 cpu*		at mainbus0
-pci*		at mainbus0 bus ?
 
+cfi0		at mainbus0
+nor*		at cfi?
+flash*		at nor?
+
+pci*		at mainbus0 bus ?
 pchb*		at pci? dev ? function ?	# PCI host bridge
 
 eumb*		at mainbus0
@@ -197,6 +201,7 @@ cmdide* 	at pci? dev ? function ?	# CMD 
 iteide* 	at pci? dev ? function ?	# IT Express IDE controllers
 satalink*	at pci? dev ? function ?	# SiI SATALink controllers
 viaide*		at pci? dev ? function ?	# VIA IDE controllers
+#options 	WDC_NO_IDS			# fix Iomega viaide VT6410
 
 # ATA (IDE) bus support
 atabus* at ata?

Index: src/sys/arch/sandpoint/conf/files.sandpoint
diff -u src/sys/arch/sandpoint/conf/files.sandpoint:1.29 src/sys/arch/sandpoint/conf/files.sandpoint:1.30
--- src/sys/arch/sandpoint/conf/files.sandpoint:1.29	Tue Mar  1 09:17:07 2011
+++ src/sys/arch/sandpoint/conf/files.sandpoint	Sat Dec 17 20:20:37 2011
@@ -1,4 +1,4 @@
-#	$NetBSD: files.sandpoint,v 1.29 2011/03/01 09:17:07 phx Exp $
+#	$NetBSD: files.sandpoint,v 1.30 2011/12/17 20:20:37 phx Exp $
 #
 # Motorola's "SandPoint" evaluation board and multiplied descendents.
 #
@@ -39,19 +39,30 @@ file dev/md_root.c	memory_disk_hooks
 define mainbus { }
 device	mainbus: isabus, pcibus, mainbus
 attach	mainbus at root
+
 device	cpu
 attach	cpu at mainbus
 file	arch/sandpoint/sandpoint/mainbus.c	mainbus|cpu needs-flag
 
+device	cfi: norbus
+attach	cfi at mainbus with sandpointcfi
+file	arch/sandpoint/sandpoint/flash_cfi.c	sandpointcfi
+
 device eumb { [ unit = -1 ] }: mainbus
 attach eumb at mainbus
 file	arch/sandpoint/sandpoint/eumb.c		eumb
+
 attach com at eumb with com_eumb
 file	arch/sandpoint/sandpoint/com_eumb.c	com_eumb needs-flag
+
 device	ociic: motoi2c, i2cbus
 attach ociic at eumb with iic_eumb
 file	arch/sandpoint/sandpoint/iic_eumb.c	iic_eumb
 
+device	satmgr: sysmon_power, sysmon_taskq
+attach	satmgr at eumb
+file	arch/sandpoint/sandpoint/satmgr.c	satmgr
+
 #
 # PCI-only drivers
 # XXX MUST BE INCLUDED BEFORE files.isa, as long as files.isa attaches
@@ -104,8 +115,4 @@ attach	fd at fdc
 
 include	"dev/usb/files.usb"
 
-device	satmgr: sysmon_power, sysmon_taskq
-attach	satmgr at eumb
-file	arch/sandpoint/sandpoint/satmgr.c	satmgr
-
 include "arch/powerpc/conf/majors.powerpc"

Index: src/sys/arch/sandpoint/include/bus_funcs.h
diff -u src/sys/arch/sandpoint/include/bus_funcs.h:1.1 src/sys/arch/sandpoint/include/bus_funcs.h:1.2
--- src/sys/arch/sandpoint/include/bus_funcs.h:1.1	Fri Jul  1 17:10:00 2011
+++ src/sys/arch/sandpoint/include/bus_funcs.h	Sat Dec 17 20:20:37 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: bus_funcs.h,v 1.1 2011/07/01 17:10:00 dyoung Exp $	*/
+/*	$NetBSD: bus_funcs.h,v 1.2 2011/12/17 20:20:37 phx Exp $	*/
 /*	$OpenBSD: bus.h,v 1.1 1997/10/13 10:53:42 pefo Exp $	*/
 
 #ifndef _SANDPOINT_BUS_FUNCS_H_
@@ -10,6 +10,7 @@ extern struct powerpc_bus_space genppc_i
 extern struct powerpc_bus_space sandpoint_mem_space_tag;
 extern struct powerpc_bus_space genppc_isa_mem_space_tag;
 extern struct powerpc_bus_space sandpoint_eumb_space_tag;
+extern struct powerpc_bus_space sandpoint_flash_space_tag;
 #endif
 
 #include <powerpc/bus_funcs.h>

Index: src/sys/arch/sandpoint/sandpoint/machdep.c
diff -u src/sys/arch/sandpoint/sandpoint/machdep.c:1.59 src/sys/arch/sandpoint/sandpoint/machdep.c:1.60
--- src/sys/arch/sandpoint/sandpoint/machdep.c:1.59	Tue Nov 22 16:56:29 2011
+++ src/sys/arch/sandpoint/sandpoint/machdep.c	Sat Dec 17 20:20:38 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.59 2011/11/22 16:56:29 phx Exp $	*/
+/*	$NetBSD: machdep.c,v 1.60 2011/12/17 20:20:38 phx Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.59 2011/11/22 16:56:29 phx Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.60 2011/12/17 20:20:38 phx Exp $");
 
 #include "opt_compat_netbsd.h"
 #include "opt_ddb.h"
@@ -438,7 +438,7 @@ struct powerpc_bus_space genppc_isa_io_s
 };
 struct powerpc_bus_space sandpoint_mem_space_tag = {
 	_BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE,
-	0x00000000, 0x80000000, 0xfbffffff,
+	0x00000000, 0x80000000, 0xfc000000,
 };
 struct powerpc_bus_space genppc_isa_mem_space_tag = {
 	_BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE,
@@ -448,8 +448,12 @@ struct powerpc_bus_space sandpoint_eumb_
 	_BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE,
 	0xfc000000, 0x00000000, 0x00100000,
 };
+struct powerpc_bus_space sandpoint_flash_space_tag = {
+	_BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE,
+	0x00000000, 0xff000000, 0x00000000,
+};
 
-static char ex_storage[5][EXTENT_FIXED_STORAGE_SIZE(8)]
+static char ex_storage[6][EXTENT_FIXED_STORAGE_SIZE(8)]
     __attribute__((aligned(8)));
 
 void
@@ -487,6 +491,11 @@ sandpoint_bus_space_init(void)
 	    ex_storage[4], sizeof(ex_storage[4]));
 	if (error)
 		panic("sandpoint_bus_space_init: can't init eumb tag");
+
+	error = bus_space_init(&sandpoint_flash_space_tag, "flash",
+	    ex_storage[5], sizeof(ex_storage[5]));
+	if (error)
+		panic("sandpoint_bus_space_init: can't init flash tag");
 }
 
 #define MPC107_EUMBBAR		0x78	/* Eumb base address */
@@ -527,7 +536,7 @@ mpc107memsize(void)
 	end |= ((val >> bankn) & 0xff) << 20;
 	end |= 0xfffff;					       /* bit 19:00 */
 
-	return (end + 1); /* recongize this as the amount of SDRAM */
+	return (end + 1); /* recognize this as the amount of SDRAM */
 }
 
 /* XXX XXX debug purpose only XXX XXX */

Index: src/sys/arch/sandpoint/sandpoint/mainbus.c
diff -u src/sys/arch/sandpoint/sandpoint/mainbus.c:1.24 src/sys/arch/sandpoint/sandpoint/mainbus.c:1.25
--- src/sys/arch/sandpoint/sandpoint/mainbus.c:1.24	Fri Jul  1 19:16:06 2011
+++ src/sys/arch/sandpoint/sandpoint/mainbus.c	Sat Dec 17 20:20:38 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: mainbus.c,v 1.24 2011/07/01 19:16:06 dyoung Exp $	*/
+/*	$NetBSD: mainbus.c,v 1.25 2011/12/17 20:20:38 phx Exp $	*/
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.24 2011/07/01 19:16:06 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.25 2011/12/17 20:20:38 phx Exp $");
 
 #include "opt_pci.h"
 #include "pci.h"
@@ -42,12 +42,13 @@ __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 
 #include <sys/malloc.h>
 #include <sys/systm.h>
 
-#include <sys/bus.h>
+#include <machine/autoconf.h>
 #include <machine/isa_machdep.h>
 
 #include <dev/pci/pcivar.h>
 #include <dev/pci/pciconf.h>
 
+/* XXX go away! */
 struct conf_args {
 	const char *ca_name;
 };
@@ -78,18 +79,25 @@ void
 mainbus_attach(device_t parent, device_t self, void *aux)
 {
 	struct conf_args ca;
+	struct mainbus_attach_args mba;
 	struct pcibus_attach_args pba;
 #if defined(PCI_NETBSD_CONFIGURE)
 	struct extent *ioext, *memext;
 #endif
 
-	printf("\n");
+	aprint_naive("\n");
+	aprint_normal("\n");
 
 	ca.ca_name = "cpu";
 	config_found_ia(self, "mainbus", &ca, mainbus_print);
 	ca.ca_name = "eumb";
 	config_found_ia(self, "mainbus", &ca, mainbus_print);
 
+	mba.ma_name = "cfi";
+	mba.ma_bst = &sandpoint_flash_space_tag;
+	mba.ma_addr = 0xffe00000; /* smallest flash is 2 MiB */
+	config_found_ia(self, "mainbus", &mba, mainbus_print);
+
 	/*
 	 * XXX Note also that the presence of a PCI bus should
 	 * XXX _always_ be checked, and if present the bus should be
@@ -125,8 +133,7 @@ mainbus_attach(device_t parent, device_t
 static int	cpu_match(device_t, cfdata_t, void *);
 static void	cpu_attach(device_t, device_t, void *);
 
-CFATTACH_DECL_NEW(cpu, 0,
-    cpu_match, cpu_attach, NULL, NULL);
+CFATTACH_DECL_NEW(cpu, 0, cpu_match, cpu_attach, NULL, NULL);
 
 extern struct cfdriver cpu_cd;
 

Added files:

Index: src/sys/arch/sandpoint/include/autoconf.h
diff -u /dev/null src/sys/arch/sandpoint/include/autoconf.h:1.1
--- /dev/null	Sat Dec 17 20:20:38 2011
+++ src/sys/arch/sandpoint/include/autoconf.h	Sat Dec 17 20:20:37 2011
@@ -0,0 +1,37 @@
+/* $NetBSD: autoconf.h,v 1.1 2011/12/17 20:20:37 phx Exp $ */
+
+/*-
+ * Copyright (c) 2011 Frank Wille.
+ * All rights reserved.
+ *
+ * Written by Frank Wille for The NetBSD Project.
+ *
+ * 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``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 FOUNDATION OR CONTRIBUTORS
+ * 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 <sys/bus.h>
+
+struct mainbus_attach_args {
+	const char		*ma_name;
+	bus_space_tag_t		ma_bst;
+	bus_addr_t		ma_addr;
+};

Index: src/sys/arch/sandpoint/sandpoint/flash_cfi.c
diff -u /dev/null src/sys/arch/sandpoint/sandpoint/flash_cfi.c:1.1
--- /dev/null	Sat Dec 17 20:20:38 2011
+++ src/sys/arch/sandpoint/sandpoint/flash_cfi.c	Sat Dec 17 20:20:38 2011
@@ -0,0 +1,172 @@
+/* $NetBSD: flash_cfi.c,v 1.1 2011/12/17 20:20:38 phx Exp $ */
+
+/*-
+ * Copyright (c) 2011 Frank Wille.
+ * All rights reserved.
+ *
+ * Written by Frank Wille for The NetBSD Project.
+ *
+ * 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``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 FOUNDATION OR CONTRIBUTORS
+ * 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.
+ */
+
+/*
+ * NOR CFI driver support for sandpoint
+ */
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: flash_cfi.c,v 1.1 2011/12/17 20:20:38 phx Exp $");
+
+#include <sys/param.h>
+#include <sys/device.h>
+
+#include <machine/autoconf.h>
+
+#include <dev/nor/nor.h>
+#include <dev/nor/cfi.h>
+
+
+static int  sandpointcfi_probe(device_t, cfdata_t, void *);
+static void sandpointcfi_attach(device_t, device_t, void *);
+static int  sandpointcfi_detach(device_t, int);
+
+struct sandpointcfi_softc {
+	device_t		sc_dev;
+	device_t		sc_nordev;
+	struct cfi		sc_cfi;
+	bus_size_t		sc_size;
+	struct nor_interface	sc_nor_if;
+};
+
+CFATTACH_DECL_NEW(sandpointcfi, sizeof(struct sandpointcfi_softc),
+    sandpointcfi_probe, sandpointcfi_attach, sandpointcfi_detach, NULL);
+
+static int
+sandpointcfi_probe(device_t parent, cfdata_t cf, void *aux)
+{
+	extern struct cfdriver cfi_cd;
+	struct mainbus_attach_args *ma = aux;
+	const bus_size_t tmpsize = CFI_QRY_MIN_MAP_SIZE;
+	struct cfi cfi;
+	int error, rv;
+
+	if (strcmp(ma->ma_name, cfi_cd.cd_name) != 0)
+		return 0;
+
+	KASSERT(ma->ma_bst != NULL);
+
+	cfi.cfi_bst = ma->ma_bst;
+
+	error = bus_space_map(cfi.cfi_bst, ma->ma_addr, tmpsize, 0,
+	    &cfi.cfi_bsh);
+	if (error != 0) {
+		aprint_error("%s: cannot map %d at offset %#x, error %d\n",
+		    __func__, tmpsize, ma->ma_addr, error);
+		return 0;
+	}
+
+	/* probe for NOR flash */
+	if (!cfi_probe(&cfi)) {
+		aprint_debug("%s: probe addr %#x, CFI not found\n",
+		    __func__, ma->ma_addr);
+		rv = 0;
+	} else
+		rv = 1;
+
+	bus_space_unmap(cfi.cfi_bst, cfi.cfi_bsh, tmpsize);
+	return rv;
+}
+
+static void
+sandpointcfi_attach(device_t parent, device_t self, void *aux)
+{
+	struct mainbus_attach_args *ma = aux;
+	struct sandpointcfi_softc *sc;
+	const bus_size_t tmpsize = CFI_QRY_MIN_MAP_SIZE;
+	bus_addr_t addr;
+	bool found;
+	int error;
+
+	aprint_naive("\n");
+	aprint_normal("\n");
+
+	sc = device_private(self);
+	sc->sc_dev = self;
+	sc->sc_cfi.cfi_bst = ma->ma_bst;
+
+	/* map enough to identify, remap later when size is known */
+	error = bus_space_map(sc->sc_cfi.cfi_bst, ma->ma_addr, tmpsize, 0,
+	    &sc->sc_cfi.cfi_bsh);
+	if (error != 0) {
+		aprint_error_dev(self, "could not map error %d\n", error);
+		return;
+	}
+
+	/* identify the NOR flash */
+	found = cfi_identify(&sc->sc_cfi);
+
+	bus_space_unmap(sc->sc_cfi.cfi_bst, sc->sc_cfi.cfi_bsh, tmpsize);
+	if (!found) {
+		/* should not happen, we already probed OK in match */
+		aprint_error_dev(self, "could not map error %d\n", error);
+		return;
+	}
+
+	/* get size of flash in bytes */
+	sc->sc_size = 1 << sc->sc_cfi.cfi_qry_data.device_size;
+
+	/* real base address */
+	addr = (0xffffffff - sc->sc_size) + 1;
+
+	sc->sc_nor_if = nor_interface_cfi;
+	sc->sc_nor_if.private = &sc->sc_cfi;
+	sc->sc_nor_if.access_width = (1 << sc->sc_cfi.cfi_portwidth);
+
+	cfi_print(self, &sc->sc_cfi);
+
+	error = bus_space_map(sc->sc_cfi.cfi_bst, addr, sc->sc_size, 0,
+		&sc->sc_cfi.cfi_bsh);
+	if (error != 0) {
+		aprint_error_dev(self, "could not map error %d\n", error);
+		return;
+	}
+
+	if (!pmf_device_register1(self, NULL, NULL, NULL))
+		aprint_error_dev(self, "couldn't establish power handler\n");
+
+	sc->sc_nordev = nor_attach_mi(&sc->sc_nor_if, self);
+}
+
+static int
+sandpointcfi_detach(device_t self, int flags)
+{
+	struct sandpointcfi_softc *sc;
+	int rv;
+
+	pmf_device_deregister(self);
+	sc = device_private(self);
+	rv = 0;
+
+	if (sc->sc_nordev != NULL)
+		rv = config_detach(sc->sc_nordev, flags);
+
+	bus_space_unmap(sc->sc_cfi.cfi_bst, sc->sc_cfi.cfi_bsh, sc->sc_size);
+	return rv;
+}

Reply via email to