Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/nor - In cfi_probe() iterate over all chip widths fo...
details: https://anonhg.NetBSD.org/src/rev/f2f56b7f6682
branches: trunk
changeset: 772091:f2f56b7f6682
user: phx <phx%NetBSD.org@localhost>
date: Sat Dec 17 19:42:41 2011 +0000
description:
- In cfi_probe() iterate over all chip widths for every port width to find
x8/x16 configurations, or two x8 chips forming a x16 port width.
- The offset in cfi_cmd() is now always given for 64-bit port width.
It will be scaled down for the actual port width to avoid problems
with 0x2aa -> 0x554 instead of 0x555.
- Added missing cfi_reset_default() in cfi_jedec_id(). The reset is
needed, because the chip was still in CFI-Query mode.
- Removed everything dealing with cfi_opmodes. It only complicates things
and I found no reason for keeping them. The port width and chip width
is known, so I just introduced a new cfi_read_qry() function which reads
a single word using bus_space_read_N() from the QRY structure, which
can be checked for 'Q', 'R' and 'Y'. That's all we need, before
reading and unpacking the whole QRY and PRI structures.
- Added two new fields, cfi_unlock_addr1 and cfi_unlock_addr2 to
the cfi struct. The unlock offsets should be kept variable, depending
on the manufacturer or command set version.
Changes have been discussed with cliff@.
diffstat:
sys/dev/nor/cfi.c | 335 ++++++++++++++++++++----------------------------
sys/dev/nor/cfi.h | 32 +---
sys/dev/nor/cfi_0002.c | 46 +++---
3 files changed, 172 insertions(+), 241 deletions(-)
diffs (truncated from 744 to 300 lines):
diff -r e6f23f44cbbc -r f2f56b7f6682 sys/dev/nor/cfi.c
--- a/sys/dev/nor/cfi.c Sat Dec 17 19:34:07 2011 +0000
+++ b/sys/dev/nor/cfi.c Sat Dec 17 19:42:41 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cfi.c,v 1.6 2011/08/02 03:37:25 cliff Exp $ */
+/* $NetBSD: cfi.c,v 1.7 2011/12/17 19:42:41 phx Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -33,7 +33,7 @@
#include "opt_cfi.h"
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cfi.c,v 1.6 2011/08/02 03:37:25 cliff Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cfi.c,v 1.7 2011/12/17 19:42:41 phx Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -48,7 +48,6 @@
#include <dev/nor/cfi_0002.h>
-static bool cfi_chip_query(struct cfi * const);
static int cfi_scan_media(device_t self, struct nor_chip *chip);
static void cfi_init(device_t);
static void cfi_select(device_t, bool);
@@ -64,9 +63,7 @@
static void cfi_write_buf_1(device_t, flash_off_t, const uint8_t *, size_t);
static void cfi_write_buf_2(device_t, flash_off_t, const uint16_t *, size_t);
static void cfi_write_buf_4(device_t, flash_off_t, const uint32_t *, size_t);
-static void cfi_jedec_id_1(struct cfi * const );
-static void cfi_jedec_id_2(struct cfi * const );
-static void cfi_jedec_id_4(struct cfi * const );
+static uint8_t cfi_read_qry(struct cfi * const, bus_size_t);
static bool cfi_jedec_id(struct cfi * const);
static bool cfi_emulate(struct cfi * const);
static const struct cfi_jedec_tab * cfi_jedec_search(struct cfi *);
@@ -76,59 +73,6 @@
static void cfi_hexdump(flash_off_t, void * const, u_int, u_int);
#endif
-
-
-/*
- * NOTE these opmode tables are informed by "Table 1. CFI Query Read"
- * in Intel "Common Flash Interface (CFI) and Command Sets"
- * Application Note 646, April 2000
- *
- * Assume the byte order of the flash (and of the signature there)
- * is the same as host byte order. The Intel App. Note describes the
- * little endian variant.
- *
- * XXX down-sized, interleaved & multi-chip opmodes not yet supported
- */
-
-#if BYTE_ORDER == BIG_ENDIAN
-/* BIG ENDIAN host */
-/* 1-byte access */
-static const struct cfi_opmodes cfi_opmodes_1[] = {
- { 0, 0, 0, 0x10, 3, "QRY", "x8 device operating in 8-bit mode" },
-};
-
-/* 2-byte access */
-static const struct cfi_opmodes cfi_opmodes_2[] = {
- { 1, 1, 0, 0x20, 6, "\0Q\0R\0Y",
- "x16 device operating in 16-bit mode" },
-};
-
-/* 4-byte access */
-static const struct cfi_opmodes cfi_opmodes_4[] = {
- { 2, 2, 0, 0x40, 12, "\0\0\0Q\0\0\0R\0\0\0Y",
- "x32 device operating in 32-bit mode" },
-};
-#else
-/* LITTLE ENDIAN host */
-/* 1-byte access */
-static const struct cfi_opmodes cfi_opmodes_1[] = {
- { 0, 0, 0, 0x10, 3, "QRY", "x8 device operating in 8-bit mode" },
-};
-
-/* 2-byte access */
-static const struct cfi_opmodes cfi_opmodes_2[] = {
- { 1, 1, 0, 0x20, 6, "Q\0R\0Y\0",
- "x16 device operating in 16-bit mode" },
-};
-
-/* 4-byte access */
-static const struct cfi_opmodes cfi_opmodes_4[] = {
- { 2, 2, 0, 0x40, 12, "Q\0\0\0R\0\0\0Y\0\0\0",
- "x32 device operating in 32-bit mode" },
-};
-#endif
-
-
#define LOG2_64K 16
#define LOG2_128K 17
#define LOG2_256K 18
@@ -166,7 +110,6 @@
.jt_write_nbyte_time_max = 0,
.jt_erase_blk_time_max = 1,
.jt_erase_chip_time_max = 1,
- .jt_opmode = &cfi_opmodes_1[0],
},
{
.jt_name = "Pm39LV010",
@@ -188,7 +131,6 @@
.jt_write_nbyte_time_max = 0,
.jt_erase_blk_time_max = 1,
.jt_erase_chip_time_max = 1,
- .jt_opmode = &cfi_opmodes_1[0],
},
};
@@ -307,7 +249,7 @@
cfi_unpack_1(data[0x39]); \
} while (0)
-#define CFI_QRY_UNPACK_COMMON(cfi, data, type, found) \
+#define CFI_QRY_UNPACK_COMMON(cfi, data, type) \
do { \
struct cfi_query_data * const qryp = &cfi->cfi_qry_data; \
\
@@ -321,13 +263,8 @@
(cfi_unpack_1(data[qryp->addr_pri + 2]) == 'I')) { \
type *pri_data = &data[qryp->addr_pri]; \
cfi_unpack_pri_0002(qryp, pri_data); \
- found = true; \
break; \
} \
- default: \
- printf("%s: unsupported id_pri=%#x\n", \
- __func__, qryp->id_pri); \
- break; /* unknown command set */ \
} \
} while (0)
@@ -352,103 +289,49 @@
#endif
-/*
- * cfi_chip_query_opmode - determine operational mode based on QRY signature
- */
-static bool
-cfi_chip_query_opmode(struct cfi *cfi, uint8_t *data,
- const struct cfi_opmodes *tab, u_int nentries)
-{
- for (u_int i=0; i < nentries; i++) {
- if (memcmp(&data[tab[i].qsa], tab[i].sig, tab[i].len) == 0) {
- cfi->cfi_opmode = &tab[i];
- return true;
- }
- }
- return false;
-}
-
-static bool
+static void
cfi_chip_query_1(struct cfi * const cfi)
{
uint8_t data[0x80];
bus_space_read_region_1(cfi->cfi_bst, cfi->cfi_bsh, 0, data,
- __arraycount(data));
-
+ __arraycount(data));
CFI_DUMP_QRY(0, data, sizeof(data), 1);
-
- bool found = cfi_chip_query_opmode(cfi, data, cfi_opmodes_1,
- __arraycount(cfi_opmodes_1));
-
- if (found) {
- CFI_QRY_UNPACK_COMMON(cfi, data, uint8_t, found);
- }
-
- return found;
+ CFI_QRY_UNPACK_COMMON(cfi, data, uint8_t);
}
-static bool
+static void
cfi_chip_query_2(struct cfi * const cfi)
{
uint16_t data[0x80];
bus_space_read_region_2(cfi->cfi_bst, cfi->cfi_bsh, 0, data,
- __arraycount(data));
-
+ __arraycount(data));
CFI_DUMP_QRY(0, data, sizeof(data), 2);
-
- bool found = cfi_chip_query_opmode(cfi, (uint8_t *)data,
- cfi_opmodes_2, __arraycount(cfi_opmodes_2));
-
- if (found) {
- CFI_QRY_UNPACK_COMMON(cfi, data, uint16_t, found);
- }
-
- return found;
+ CFI_QRY_UNPACK_COMMON(cfi, data, uint16_t);
}
-static bool
+static void
cfi_chip_query_4(struct cfi * const cfi)
{
uint32_t data[0x80];
bus_space_read_region_4(cfi->cfi_bst, cfi->cfi_bsh, 0, data,
- __arraycount(data));
-
+ __arraycount(data));
CFI_DUMP_QRY(0, data, sizeof(data), 4);
-
- bool found = cfi_chip_query_opmode(cfi, (uint8_t *)data,
- cfi_opmodes_4, __arraycount(cfi_opmodes_4));
-
- if (found) {
- CFI_QRY_UNPACK_COMMON(cfi, data, uint32_t, found);
- }
-
- return found;
+ CFI_QRY_UNPACK_COMMON(cfi, data, uint32_t);
}
-static bool
+static void
cfi_chip_query_8(struct cfi * const cfi)
{
#ifdef NOTYET
uint64_t data[0x80];
bus_space_read_region_8(cfi->cfi_bst, cfi->cfi_bsh, 0, data,
- __arraycount(data));
-
+ __arraycount(data));
CFI_DUMP_QRY(0, data, sizeof(data), 8);
-
- bool found = cfi_chip_query_opmode(cfi, (uint8_t *)data,
- cfi_opmodes_8, __arraycount(cfi_opmodes_8));
-
- if (found) {
- CFI_QRY_UNPACK_COMMON(cfi, data, uint64_t, found);
- }
-
- return found;
-#else
- return false;
+ CFI_QRY_UNPACK_COMMON(cfi, data, uint64_t);
#endif
}
@@ -460,43 +343,57 @@
static bool
cfi_chip_query(struct cfi * const cfi)
{
- bool found = false;
const bus_size_t cfi_query_offset[] = {
- CFI_QUERY_MODE_ADDRESS,
- CFI_QUERY_MODE_ALT_ADDRESS
+ CFI_QUERY_MODE_ADDR,
+ CFI_QUERY_MODE_ALT_ADDR
};
KASSERT(cfi != NULL);
KASSERT(cfi->cfi_bst != NULL);
- for (int j=0; !found && j < __arraycount(cfi_query_offset); j++) {
+ for (int j=0; j < __arraycount(cfi_query_offset); j++) {
cfi_reset_default(cfi);
cfi_cmd(cfi, cfi_query_offset[j], CFI_QUERY_DATA);
- switch(cfi->cfi_portwidth) {
- case 0:
- found = cfi_chip_query_1(cfi);
- break;
- case 1:
- found = cfi_chip_query_2(cfi);
- break;
- case 2:
- found = cfi_chip_query_4(cfi);
- break;
- case 3:
- found = cfi_chip_query_8(cfi);
- break;
- default:
- panic("%s: bad portwidth %d\n",
- __func__, cfi->cfi_portwidth);
+ if (cfi_read_qry(cfi, 0x10) == 'Q' &&
+ cfi_read_qry(cfi, 0x11) == 'R' &&
+ cfi_read_qry(cfi, 0x12) == 'Y') {
+ switch(cfi->cfi_portwidth) {
+ case 0:
+ cfi_chip_query_1(cfi);
+ break;
+ case 1:
+ cfi_chip_query_2(cfi);
+ break;
+ case 2:
Home |
Main Index |
Thread Index |
Old Index