Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Add support for CFI NOR, using MPC8536DS as initial exam...
details: https://anonhg.NetBSD.org/src/rev/edb41ad73cfe
branches: trunk
changeset: 767328:edb41ad73cfe
user: cliff <cliff%NetBSD.org@localhost>
date: Fri Jul 15 19:19:55 2011 +0000
description:
Add support for CFI NOR, using MPC8536DS as initial example.
Only AMD/Fujitsu command set is suported so far.
This is still work in progress, be advised.
diffstat:
sys/arch/evbppc/conf/MPC8536DS | 16 +-
sys/arch/powerpc/booke/dev/pq3cfi.c | 173 +++++++++
sys/arch/powerpc/conf/files.booke | 6 +-
sys/conf/files | 7 +-
sys/dev/flash/flash.c | 74 +--
sys/dev/flash/flash.h | 12 +-
sys/dev/flash/flash_io.c | 8 +-
sys/dev/flash/flash_io.h | 3 +-
sys/dev/nand/nand.c | 18 +-
sys/dev/nand/nand.h | 41 +-
sys/dev/nand/nand_micron.c | 8 +-
sys/dev/nor/cfi.c | 684 ++++++++++++++++++++++++++++++++++++
sys/dev/nor/cfi.h | 240 ++++++++++++-
sys/dev/nor/cfi_0002.c | 608 ++++++++++++++++++++++++++++++++
sys/dev/nor/cfi_0002.h | 46 ++
sys/dev/nor/files.nor | 4 +-
sys/dev/nor/nor.h | 267 +++++++------
17 files changed, 1997 insertions(+), 218 deletions(-)
diffs (truncated from 2909 to 300 lines):
diff -r 4a92081405a3 -r edb41ad73cfe sys/arch/evbppc/conf/MPC8536DS
--- a/sys/arch/evbppc/conf/MPC8536DS Fri Jul 15 14:59:33 2011 +0000
+++ b/sys/arch/evbppc/conf/MPC8536DS Fri Jul 15 19:19:55 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: MPC8536DS,v 1.6 2011/06/30 20:09:29 wiz Exp $
+# $NetBSD: MPC8536DS,v 1.7 2011/07/15 19:19:55 cliff Exp $
#
# MPC8536DS -- everything that's currently supported
#
@@ -7,7 +7,7 @@
options INCLUDE_CONFIG_FILE # embed config file in kernel binary
-ident "MPC8536DS-$Revision: 1.6 $"
+ident "MPC8536DS-$Revision: 1.7 $"
maxusers 32
@@ -149,6 +149,12 @@
obio0 at cpunode? # On-chip Peripheral Bus
#mkclock0 at obio0 addr 0xf8000000 size 8192
+# NOR Flash
+#options NOR_VERBOSE
+pq3cfi0 at obio0 cs 0
+nor* at pq3cfi?
+flash* at nor? offset 0 size 0x8000000
+
e500wdog* at cpunode? # Watchdog timer
duart* at cpunode?
@@ -190,9 +196,9 @@
scsibus* at umass? channel ?
sd* at scsibus? target ? lun ?
-sdhc* at cpunode? # sdmmc
-sdmmc* at sdhc? # SD/MMC bus
-ld* at sdmmc?
+#sdhc* at cpunode? # sdmmc
+#sdmmc* at sdhc? # SD/MMC bus
+#ld* at sdmmc?
#siisata* at pci? dev ? function ?
#atabus* at siisata? channel ?
diff -r 4a92081405a3 -r edb41ad73cfe sys/arch/powerpc/booke/dev/pq3cfi.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/powerpc/booke/dev/pq3cfi.c Fri Jul 15 19:19:55 2011 +0000
@@ -0,0 +1,173 @@
+/* $NetBSD: pq3cfi.c,v 1.1 2011/07/15 19:19:56 cliff Exp $ */
+
+/*
+ * NOR CFI driver support for booke
+ */
+
+#include "opt_flash.h"
+#include "locators.h"
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: pq3cfi.c,v 1.1 2011/07/15 19:19:56 cliff Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/cdefs.h>
+#include <sys/device.h>
+#include <sys/endian.h>
+
+#include <machine/bus.h>
+
+#include <powerpc/booke/cpuvar.h>
+
+#include <dev/nor/nor.h>
+#include <dev/nor/cfi.h>
+
+
+static int pq3cfi_match(device_t, cfdata_t, void *);
+static void pq3cfi_attach(device_t, device_t, void *);
+static int pq3cfi_detach(device_t, int);
+
+struct pq3cfi_softc {
+ device_t sc_dev;
+ device_t sc_nordev;
+ struct cfi sc_cfi;
+ bus_addr_t sc_addr;
+ bus_size_t sc_size;
+ struct nor_interface sc_nor_if;
+};
+
+CFATTACH_DECL_NEW(pq3cfi, sizeof(struct pq3cfi_softc), pq3cfi_match,
+ pq3cfi_attach, pq3cfi_detach, NULL);
+
+/*
+ * pq3cfi_addr - return bus address for the CFI NOR flash
+ *
+ * if the chip select not specified, use address from attach args
+ * otherwise use address from the chip select.
+ */
+static inline bus_addr_t
+pq3cfi_addr(struct generic_attach_args *ga)
+{
+ bus_addr_t addr_aa = ga->ga_addr;
+
+ if (ga->ga_cs != OBIOCF_CS_DEFAULT) {
+#ifdef NOTYET
+ bus_addr_t addr_cs = get_addr_from_cs(ga->ga_cs);
+ if (addr_aa != addr_cs)
+ aprint_warn("%s: configured addr %#x, CS%d addr %#x\n",
+ __func__, addr_aa, ga->ga_cs, addr_cs);
+ return addr_cs;
+#endif
+ }
+ return addr_aa;
+}
+
+static int
+pq3cfi_match(device_t parent, cfdata_t match, void *aux)
+{
+ struct generic_attach_args *ga = aux;
+ bus_size_t tmpsize = CFI_QRY_MIN_MAP_SIZE;
+ bus_addr_t addr;
+ struct cfi cfi;
+ int rv;
+
+ KASSERT(ga->ga_bst != NULL);
+
+ addr = pq3cfi_addr(ga);
+ if (addr == OBIOCF_ADDR_DEFAULT) {
+ aprint_error("%s: no base address\n", __func__);
+ return 0;
+ }
+
+ cfi.cfi_bst = ga->ga_bst;
+ int error = bus_space_map(cfi.cfi_bst, addr, tmpsize, 0, &cfi.cfi_bsh);
+ if (error != 0) {
+ aprint_error("%s: cannot map %d at offset %#x, error %d\n", __func__, tmpsize, addr, error);
+ return false;
+ }
+
+ if (! cfi_probe(&cfi)) {
+ aprint_debug("%s: probe addr %#x, CFI not found\n",
+ __func__, addr);
+ rv = 0;
+ } else {
+ rv = 1;
+ }
+
+ bus_space_unmap(cfi.cfi_bst, cfi.cfi_bsh, tmpsize);
+
+ return rv;
+}
+
+static void
+pq3cfi_attach(device_t parent, device_t self, void *aux)
+{
+ struct pq3cfi_softc *sc = device_private(self);
+ struct generic_attach_args *ga = aux;
+ struct cfi_query_data * const qryp = &sc->sc_cfi.cfi_qry_data;
+ const bus_size_t tmpsize = CFI_QRY_MIN_MAP_SIZE;
+ bool found;
+ int error;
+
+ aprint_normal("\n");
+
+ sc->sc_dev = self;
+ sc->sc_cfi.cfi_bst = ga->ga_bst;
+ sc->sc_addr = pq3cfi_addr(ga);
+
+ /* map enough to identify, remap later when size is known */
+ error = bus_space_map(sc->sc_cfi.cfi_bst, sc->sc_addr, tmpsize,
+ 0, &sc->sc_cfi.cfi_bsh);
+ if (error != 0) {
+ aprint_error_dev(self, "could not map error %d\n", error);
+ return;
+ }
+
+ 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;
+ }
+
+ sc->sc_size = 1 << qryp->device_size;
+
+ 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, sc->sc_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
+pq3cfi_detach(device_t self, int flags)
+{
+ struct pq3cfi_softc *sc = device_private(self);
+ int rv = 0;
+
+ pmf_device_deregister(self);
+
+ 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;
+}
diff -r 4a92081405a3 -r edb41ad73cfe sys/arch/powerpc/conf/files.booke
--- a/sys/arch/powerpc/conf/files.booke Fri Jul 15 14:59:33 2011 +0000
+++ b/sys/arch/powerpc/conf/files.booke Fri Jul 15 19:19:55 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.booke,v 1.3 2011/05/02 01:48:05 matt Exp $
+# $NetBSD: files.booke,v 1.4 2011/07/15 19:19:56 cliff Exp $
#
# PPC BookE specific configuration info
@@ -58,6 +58,10 @@
attach obio at cpunode with pq3obio
file arch/powerpc/booke/dev/pq3obio.c pq3obio
+device pq3cfi: norbus
+attach pq3cfi at obio
+file arch/powerpc/booke/dev/pq3cfi.c nor
+
device nandfcm: nandbus
attach nandfcm at obio with pq3nandfcm
file arch/powerpc/booke/dev/pq3nandfcm.c pq3nandfcm
diff -r 4a92081405a3 -r edb41ad73cfe sys/conf/files
--- a/sys/conf/files Fri Jul 15 14:59:33 2011 +0000
+++ b/sys/conf/files Fri Jul 15 19:19:55 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files,v 1.1019 2011/07/09 14:48:12 jmcneill Exp $
+# $NetBSD: files,v 1.1020 2011/07/15 19:19:56 cliff Exp $
# @(#)files.newconf 7.5 (Berkeley) 5/10/93
version 20100430
@@ -1723,6 +1723,11 @@
include "dev/nand/files.nand"
#
+# NOR subsytem
+#
+include "dev/nor/files.nor"
+
+#
# DTV subsystem
#
include "dev/dtv/files.dtv"
diff -r 4a92081405a3 -r edb41ad73cfe sys/dev/flash/flash.c
--- a/sys/dev/flash/flash.c Fri Jul 15 14:59:33 2011 +0000
+++ b/sys/dev/flash/flash.c Fri Jul 15 19:19:55 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: flash.c,v 1.7 2011/06/28 18:14:11 ahoka Exp $ */
+/* $NetBSD: flash.c,v 1.8 2011/07/15 19:19:57 cliff Exp $ */
/*-
* Copyright (c) 2011 Department of Software Engineering,
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: flash.c,v 1.7 2011/06/28 18:14:11 ahoka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: flash.c,v 1.8 2011/07/15 19:19:57 cliff Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -81,9 +81,6 @@
int flash_nsectors(struct buf *bp);
int flash_sector(struct buf *bp);
-static inline flash_off_t flash_get_part_offset(struct flash_softc *fl,
- size_t poffset);
-
int flash_match(device_t parent, cfdata_t match, void *aux);
void flash_attach(device_t parent, device_t self, void *aux);
int flash_detach(device_t device, int flags);
@@ -133,8 +130,8 @@
void
flash_attach(device_t parent, device_t self, void *aux)
{
- struct flash_softc *sc = device_private(self);
- struct flash_attach_args *faa = aux;
+ struct flash_softc * const sc = device_private(self);
+ struct flash_attach_args * const faa = aux;
char pbuf[2][sizeof("9999 KB")];
Home |
Main Index |
Thread Index |
Old Index