Source-Changes-HG archive

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

[src/trunk]: src/sys Add support Microchip SST25VF016B.



details:   https://anonhg.NetBSD.org/src/rev/f0d96525f881
branches:  trunk
changeset: 825935:f0d96525f881
user:      hkenken <hkenken%NetBSD.org@localhost>
date:      Mon Aug 07 09:24:43 2017 +0000

description:
Add support Microchip SST25VF016B.
- Fixed imxspi send and receive bugs.

diffstat:

 sys/arch/arm/imx/imxspi.c      |  24 ++++++++++++------------
 sys/arch/evbarm/conf/NETWALKER |   6 +++---
 sys/dev/spi/m25p.c             |  34 ++++++++++++++++++++++------------
 3 files changed, 37 insertions(+), 27 deletions(-)

diffs (197 lines):

diff -r 3930d05bced2 -r f0d96525f881 sys/arch/arm/imx/imxspi.c
--- a/sys/arch/arm/imx/imxspi.c Mon Aug 07 08:54:54 2017 +0000
+++ b/sys/arch/arm/imx/imxspi.c Mon Aug 07 09:24:43 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: imxspi.c,v 1.2 2014/03/29 12:00:27 hkenken Exp $       */
+/*     $NetBSD: imxspi.c,v 1.3 2017/08/07 09:24:43 hkenken Exp $       */
 
 /*-
  * Copyright (c) 2014  Genetec Corporation.  All rights reserved.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: imxspi.c,v 1.2 2014/03/29 12:00:27 hkenken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: imxspi.c,v 1.3 2017/08/07 09:24:43 hkenken Exp $");
 
 #include "opt_imx.h"
 #include "opt_imxspi.h"
@@ -256,7 +256,7 @@
                while (chunk->chunk_wresid) {
                        /* transmit fifo full? */
                        if (READ_REG(sc, STATREG) & IMXSPI(STAT_TF))
-                               return;
+                               goto out;
 
                        if (chunk->chunk_wptr) {
                                data = *chunk->chunk_wptr;
@@ -271,7 +271,7 @@
                /* advance to next transfer */
                sc->sc_wchunk = sc->sc_wchunk->chunk_next;
        }
-
+out:
        if (!(READ_REG(sc, STATREG) & IMXSPI(INTR_TE_EN)))
                WRITE_REG(sc, CONREG, READ_REG(sc, CONREG) | IMXSPI(CON_XCH));
 }
@@ -321,7 +321,7 @@
                        sc->sc_tag->spi_cs_enable(sc->sc_tag->cookie,
                            st->st_slave);
 
-               /*chip slect*/
+               /* chip slect */
                chipselect = READ_REG(sc, CONREG);
                chipselect &= ~IMXSPI(CON_CS);
                chipselect |= __SHIFTIN(st->st_slave, IMXSPI(CON_CS));
@@ -382,19 +382,19 @@
                return 0;
        }
 
+       /* RXFIFO ready? */
+       if (sr & IMXSPI(INTR_RR_EN)) {
+               imxspi_recv(sc);
+               if (sc->sc_wchunk == NULL && sc->sc_rchunk == NULL)
+                       imxspi_done(sc, err);
+       }
+
        /* Transfer Conplete? */
        if (sr & IMXSPI(INTR_TC_EN)) {
                /* complete TX */
                imxspi_send(sc);
        }
 
-       /* RXFIFO ready */
-       if (sr & IMXSPI(INTR_RR_EN)) {
-               imxspi_recv(sc);
-               if (sc->sc_wchunk == NULL && sc->sc_rchunk == NULL)
-                       imxspi_done(sc, err);
-       }
-
        /* status register clear */
        WRITE_REG(sc, STATREG, sr);
 
diff -r 3930d05bced2 -r f0d96525f881 sys/arch/evbarm/conf/NETWALKER
--- a/sys/arch/evbarm/conf/NETWALKER    Mon Aug 07 08:54:54 2017 +0000
+++ b/sys/arch/evbarm/conf/NETWALKER    Mon Aug 07 09:24:43 2017 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: NETWALKER,v 1.35 2015/12/21 04:26:29 hkenken Exp $
+#      $NetBSD: NETWALKER,v 1.36 2017/08/07 09:24:43 hkenken Exp $
 #
 #      NETWALKER -- http://www.sharp.co.jp/netwalker/
 #
@@ -113,8 +113,8 @@
 imxpwm0                at axi? addr 0x73FB4000 irq 61
 
 # SPI NOR-Flash
-#spiflash0     at spiflashbus?
-#m25p0         at spi0 slave 1
+spiflash0      at spiflashbus?
+m25p0          at spi0 slave 1
 
 # SD/MMC
 sdhc0          at axi? addr 0x70004000 irq 1        # eSDHC1
diff -r 3930d05bced2 -r f0d96525f881 sys/dev/spi/m25p.c
--- a/sys/dev/spi/m25p.c        Mon Aug 07 08:54:54 2017 +0000
+++ b/sys/dev/spi/m25p.c        Mon Aug 07 09:24:43 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: m25p.c,v 1.4 2013/10/26 15:18:21 rkujawa Exp $ */
+/* $NetBSD: m25p.c,v 1.5 2017/08/07 09:24:43 hkenken Exp $ */
 
 /*-
  * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
@@ -42,7 +42,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: m25p.c,v 1.4 2013/10/26 15:18:21 rkujawa Exp $");
+__KERNEL_RCSID(0, "$NetBSD: m25p.c,v 1.5 2017/08/07 09:24:43 hkenken Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -60,6 +60,7 @@
 
 static int m25p_match(device_t , cfdata_t , void *);
 static void m25p_attach(device_t , device_t , void *);
+static void m25p_doattach(device_t);
 static const char *m25p_getname(void *);
 static struct spi_handle *m25p_gethandle(void *);
 static int m25p_getflags(void *);
@@ -95,7 +96,8 @@
        { 0x14, 0x20, 0x2015, "STMicro M25P16", 2048, 64 },     /* 16Mbit */
        { 0x12, 0x20, 0x2013, "STMicro M25P40", 512, 64 },      /* 4Mbit */
        { 0xc0, 0x20, 0x7117, "STMicro M25PX64", 8192, 64 },    /* 64Mbit */
-       { 0x0, 0x20, 0xBB18, "Numonyx N25Q128", 16384, 64 },    /* 128Mbit */
+       { 0x00, 0x20, 0xBB18, "Numonyx N25Q128", 16384, 64 },   /* 128Mbit */
+       { 0x00, 0xBF, 0x2541, "Microchip SST25VF016B", 2048, 64 }, /* 16Mbit */
        { 0 }
 };
 
@@ -116,20 +118,27 @@
 {
        struct m25p_softc *sc = device_private(self);
        struct spi_attach_args *sa = aux;
+
+       sc->sc_sh = sa->sa_handle;
+
+       config_interrupts(self, m25p_doattach);
+}
+
+static void
+m25p_doattach(device_t self)
+{
+       struct m25p_softc *sc = device_private(self);
        const struct m25p_info *info;
-       uint8_t  buf[4];
+       uint8_t buf[4];
        uint8_t cmd;
        uint8_t mfgid;
        uint8_t sig;
        uint16_t devid;
 
-       sc->sc_sh = sa->sa_handle;
-
        /* first we try JEDEC ID read */
-       
        cmd = SPIFLASH_CMD_RDJI;
-       if (spi_send_recv(sa->sa_handle, 1, &cmd, 3, buf)) {
-               aprint_error(": failed to get JEDEC identification\n"); 
+       if (spi_send_recv(sc->sc_sh, 1, &cmd, 3, buf)) {
+               aprint_error(": failed to get JEDEC identification\n");
                return;
        }
        mfgid = buf[0];
@@ -137,7 +146,7 @@
 
        if ((mfgid == 0xff) || (mfgid == 0)) {
                cmd = SPIFLASH_CMD_RDID;
-               if (spi_send_recv(sa->sa_handle, 1, &cmd, 4, buf)) {
+               if (spi_send_recv(sc->sc_sh, 1, &cmd, 4, buf)) {
                        aprint_error(": failed to get legacy signature\n");
                        return;
                }
@@ -150,7 +159,7 @@
        for (info = m25p_infos; info->name; info++) {
                if ((info->mfgid == mfgid) && (info->devid == devid))
                        break;
-               if (sig == info->sig)
+               if ((sig != 0) && (sig == info->sig))
                        break;
        }
 
@@ -160,7 +169,6 @@
        }
 
        sc->sc_name = info->name;
-       sc->sc_sh = sa->sa_handle;
        sc->sc_sizes[SPIFLASH_SIZE_DEVICE] = info->size * 1024;
        sc->sc_sizes[SPIFLASH_SIZE_ERASE] = info->sector * 1024;
        sc->sc_sizes[SPIFLASH_SIZE_WRITE] = 256;
@@ -168,6 +176,8 @@
 
        sc->sc_flags = SPIFLASH_FLAG_FAST_READ;
 
+       aprint_normal_dev(self, "JEDEC ID mfgid:0x%02X, devid:0x%04X",
+           mfgid, devid);
        aprint_normal("\n");
 
        spiflash_attach_mi(&m25p_hw_if, sc, self);



Home | Main Index | Thread Index | Old Index