summaryrefslogtreecommitdiffstats
path: root/sys/dev/nand
diff options
context:
space:
mode:
authorian <ian@FreeBSD.org>2014-05-14 20:31:54 +0000
committerian <ian@FreeBSD.org>2014-05-14 20:31:54 +0000
commitb817c837ca9b5c346e601b0f7de335729c8873dd (patch)
treedd55122a6ff8c3e8ce3bfc4febb09841f07ea4ec /sys/dev/nand
parent15a8c9db44075b3dd6e16714daaee4053182a01e (diff)
downloadFreeBSD-src-b817c837ca9b5c346e601b0f7de335729c8873dd.zip
FreeBSD-src-b817c837ca9b5c346e601b0f7de335729c8873dd.tar.gz
MFC r260695, r260696, r260884, r260885, r260886, r260887
Provide a simplified way to specify GPIO pins for the Atmel port. Add at91 data so we can convert a PIO unit number into a base address. Add at91 standard memory controller helper functions. Generalize AT91 NAND support a bit. Connect NAND for the SAM9260EK eval board, as well as the HotE HL-201. Add nand device and NANDFS into the mix for those at91 boards that have support for it at the moment.
Diffstat (limited to 'sys/dev/nand')
-rw-r--r--sys/dev/nand/nfc_at91.c42
-rw-r--r--sys/dev/nand/nfc_at91.h50
2 files changed, 81 insertions, 11 deletions
diff --git a/sys/dev/nand/nfc_at91.c b/sys/dev/nand/nfc_at91.c
index cdf8524..7357cdb 100644
--- a/sys/dev/nand/nfc_at91.c
+++ b/sys/dev/nand/nfc_at91.c
@@ -54,23 +54,29 @@ __FBSDID("$FreeBSD$");
#include <dev/nand/nandbus.h>
#include "nfc_if.h"
+#include <dev/nand/nfc_at91.h>
+#include <arm/at91/at91_smc.h>
+
/*
* Data cycles are triggered by access to any address within the EBI CS3 region
* that has A21 and A22 clear. Command cycles are any access with bit A21
- * asserted. Address cycles are any access with bit A22 asserted.
- *
- * XXX The atmel docs say that any address bits can be used instead of A21 and
- * A22; these values should be configurable.
+ * asserted. Address cycles are any access with bit A22 asserted. Or vice versa.
+ * We get these parameters from the nand_param that the board is required to
+ * call at91_enable_nand, and enable the GPIO lines properly (that will be moved
+ * into at91_enable_nand when the great GPIO pin renumbering happens). We use
+ * ale (Address Latch Enable) and cle (Comand Latch Enable) to match the hardware
+ * names used in NAND.
*/
#define AT91_NAND_DATA 0
-#define AT91_NAND_COMMAND (1 << 21)
-#define AT91_NAND_ADDRESS (1 << 22)
struct at91_nand_softc {
struct nand_softc nand_sc;
struct resource *res;
+ struct at91_nand_params *nand_param;
};
+static struct at91_nand_params nand_param;
+
static int at91_nand_attach(device_t);
static int at91_nand_probe(device_t);
static uint8_t at91_nand_read_byte(device_t);
@@ -81,6 +87,12 @@ static int at91_nand_send_command(device_t, uint8_t);
static int at91_nand_send_address(device_t, uint8_t);
static void at91_nand_write_buf(device_t, void *, uint32_t);
+void
+at91_enable_nand(const struct at91_nand_params *np)
+{
+ nand_param = *np;
+}
+
static inline u_int8_t
dev_read_1(struct at91_nand_softc *sc, bus_size_t offset)
{
@@ -108,6 +120,14 @@ at91_nand_attach(device_t dev)
int err, rid;
sc = device_get_softc(dev);
+ sc->nand_param = &nand_param;
+ if (sc->nand_param->width != 8 && sc->nand_param->width != 16) {
+ device_printf(dev, "Bad bus width (%d) defaulting to 8 bits\n",
+ sc->nand_param->width);
+ sc->nand_param->width = 8;
+ }
+ at91_ebi_enable(sc->nand_param->cs);
+
rid = 0;
sc->res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
RF_ACTIVE);
@@ -128,10 +148,10 @@ at91_nand_send_command(device_t dev, uint8_t command)
{
struct at91_nand_softc *sc;
- /* nand_debug(NDBG_DRV,"at91_nand_send_command: 0x%02x", command); */
+ nand_debug(NDBG_DRV,"at91_nand_send_command: 0x%02x", command);
sc = device_get_softc(dev);
- dev_write_1(sc, AT91_NAND_COMMAND, command);
+ dev_write_1(sc, sc->nand_param->cle, command);
return (0);
}
@@ -140,10 +160,10 @@ at91_nand_send_address(device_t dev, uint8_t addr)
{
struct at91_nand_softc *sc;
- /* nand_debug(NDBG_DRV,"at91_nand_send_address: x%02x", addr); */
+ nand_debug(NDBG_DRV,"at91_nand_send_address: x%02x", addr);
sc = device_get_softc(dev);
- dev_write_1(sc, AT91_NAND_ADDRESS, addr);
+ dev_write_1(sc, sc->nand_param->ale, addr);
return (0);
}
@@ -156,7 +176,7 @@ at91_nand_read_byte(device_t dev)
sc = device_get_softc(dev);
data = dev_read_1(sc, AT91_NAND_DATA);
- /* nand_debug(NDBG_DRV,"at91_nand_read_byte: 0x%02x", data); */
+ nand_debug(NDBG_DRV,"at91_nand_read_byte: 0x%02x", data);
return (data);
}
diff --git a/sys/dev/nand/nfc_at91.h b/sys/dev/nand/nfc_at91.h
new file mode 100644
index 0000000..ae06e69
--- /dev/null
+++ b/sys/dev/nand/nfc_at91.h
@@ -0,0 +1,50 @@
+/*-
+ * Copyright (C) 2014 Warner Losh.
+ * 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 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 AUTHOR 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.
+ *
+ * $FreeBSD$
+ */
+
+/*
+ * Atmel at91-family integrated NAND controller driver.
+ *
+ * Interface to board setup code to set parameters.
+ */
+
+#ifndef DEV_NAND_NFC_AT91_H
+#define DEV_NAND_NFC_AT91_H 1
+
+struct at91_nand_params
+{
+ uint32_t ale; /* Address for ALE (address) NAND cycles */
+ uint32_t cle; /* Address for CLE (command) NAND cycles */
+ uint32_t width; /* 8 or 16 bits (specify in bits) */
+ uint32_t cs; /* Chip Select NAND is connected to */
+ uint32_t rnb_pin; /* GPIO pin # for Read/notBusy */
+ uint32_t nce_pin; /* GPIO pin # for CE (active low) */
+};
+
+void at91_enable_nand(const struct at91_nand_params *);
+
+#endif /* DEV_NAND_NFC_AT91_H */
OpenPOWER on IntegriCloud