cfi.c revision 1.2 1 /* $NetBSD: cfi.c,v 1.2 2011/07/17 00:52:42 dyoung Exp $ */
2
3 #include "opt_nor.h"
4 #include "opt_flash.h"
5
6 #include <sys/cdefs.h>
7 __KERNEL_RCSID(0, "$NetBSD: cfi.c,v 1.2 2011/07/17 00:52:42 dyoung Exp $");
8
9 #include <sys/param.h>
10 #include <sys/systm.h>
11 #include <sys/cdefs.h>
12 #include <sys/device.h>
13 #include <sys/endian.h>
14
15 #include <sys/bus.h>
16
17 #include <dev/nor/nor.h>
18 #include <dev/nor/cfi.h>
19 #include <dev/nor/cfi_0002.h>
20
21
22 static bool cfi_chip_query(struct cfi * const);
23 static int cfi_scan_media(device_t self, struct nor_chip *chip);
24 static void cfi_init(device_t);
25 static void cfi_select(device_t, bool);
26 static void cfi_read_1(device_t, flash_off_t, uint8_t *);
27 static void cfi_read_2(device_t, flash_off_t, uint16_t *);
28 static void cfi_read_4(device_t, flash_off_t, uint32_t *);
29 static void cfi_read_buf_1(device_t, flash_off_t, uint8_t *, size_t);
30 static void cfi_read_buf_2(device_t, flash_off_t, uint16_t *, size_t);
31 static void cfi_read_buf_4(device_t, flash_off_t, uint32_t *, size_t);
32 static void cfi_write_1(device_t, flash_off_t, uint8_t);
33 static void cfi_write_2(device_t, flash_off_t, uint16_t);
34 static void cfi_write_4(device_t, flash_off_t, uint32_t);
35 static void cfi_write_buf_1(device_t, flash_off_t, const uint8_t *, size_t);
36 static void cfi_write_buf_2(device_t, flash_off_t, const uint16_t *, size_t);
37 static void cfi_write_buf_4(device_t, flash_off_t, const uint32_t *, size_t);
38 static bool cfi_jedec_id(struct cfi * const);
39
40
41 /*
42 * NOTE these opmode tables are informed by "Table 1. CFI Query Read"
43 * in Intel "Common Flash Interface (CFI) and Command Sets"
44 * Application Note 646, April 2000
45 *
46 * The byte ordering of the signature string here varies from that table
47 * because of discrepancy in observed behavior, for the case:
48 * - x16 device operating in 16-bit mode
49 * Similar discrepancy is expected (but not verified) for the case:
50 * - x32 device operating in 32-bit mode
51 * so the ordering is changed here for that case also.
52 *
53 * XXX down-sized, interleaved & multi-chip opmodes not yet supported
54 */
55
56 /* 1-byte access */
57 static const struct cfi_opmodes cfi_opmodes_1[] = {
58 { 0, 0, 0, 0x10, 3, "QRY", "x8 device operating in 8-bit mode" },
59 };
60
61 /* 2-byte access */
62 static const struct cfi_opmodes cfi_opmodes_2[] = {
63 { 1, 1, 0, 0x20, 6, "\0Q\0R\0Y",
64 "x16 device operating in 16-bit mode" },
65 };
66
67 /* 4-byte access */
68 static const struct cfi_opmodes cfi_opmodes_4[] = {
69 { 2, 2, 0, 0x40, 12, "\0\0\0Q\0\0\0R\0\0\0Y",
70 "x32 device operating in 32-bit mode" },
71 };
72
73
74 const struct nor_interface nor_interface_cfi = {
75 .scan_media = cfi_scan_media,
76 .init = cfi_init,
77 .select = cfi_select,
78 .read_1 = cfi_read_1,
79 .read_2 = cfi_read_2,
80 .read_4 = cfi_read_4,
81 .read_buf_1 = cfi_read_buf_1,
82 .read_buf_2 = cfi_read_buf_2,
83 .read_buf_4 = cfi_read_buf_4,
84 .write_1 = cfi_write_1,
85 .write_2 = cfi_write_2,
86 .write_4 = cfi_write_4,
87 .write_buf_1 = cfi_write_buf_1,
88 .write_buf_2 = cfi_write_buf_2,
89 .write_buf_4 = cfi_write_buf_4,
90 .read_page = NULL, /* cmdset */
91 .program_page = NULL, /* cmdset */
92 .busy = NULL,
93 .private = NULL,
94 .access_width = -1,
95 .part_info = NULL,
96 .part_num = -1,
97 };
98
99
100 /* only data[7..0] are used regardless of chip width */
101 #define cfi_unpack_1(n) ((n) & 0xff)
102
103 /* construct (arbitrarily big endian) uint16_t */
104 #define cfi_unpack_2(b0, b1) \
105 ((cfi_unpack_1(b1) << 8) | cfi_unpack_1(b0))
106
107 /* construct (arbitrarily) big endian uint32_t */
108 #define cfi_unpack_4(b0, b1, b2, b3) \
109 ((cfi_unpack_1(b3) << 24) | \
110 (cfi_unpack_1(b2) << 16) | \
111 (cfi_unpack_1(b1) << 8) | \
112 (cfi_unpack_1(b0)))
113
114 #define cfi_unpack_qry(qryp, data) \
115 do { \
116 (qryp)->qry[0] = cfi_unpack_1(data[0x10]); \
117 (qryp)->qry[1] = cfi_unpack_1(data[0x11]); \
118 (qryp)->qry[2] = cfi_unpack_1(data[0x12]); \
119 (qryp)->id_pri = be16toh(cfi_unpack_2(data[0x13], data[0x14])); \
120 (qryp)->addr_pri = \
121 be16toh(cfi_unpack_2(data[0x15], data[0x16])); \
122 (qryp)->id_alt = be16toh(cfi_unpack_2(data[0x17], data[0x18])); \
123 (qryp)->addr_alt = \
124 be16toh(cfi_unpack_2(data[0x19], data[0x1a])); \
125 (qryp)->vcc_min = cfi_unpack_1(data[0x1b]); \
126 (qryp)->vcc_max = cfi_unpack_1(data[0x1c]); \
127 (qryp)->vpp_min = cfi_unpack_1(data[0x1d]); \
128 (qryp)->vpp_max = cfi_unpack_1(data[0x1e]); \
129 (qryp)->write_word_time_typ = cfi_unpack_1(data[0x1f]); \
130 (qryp)->write_nbyte_time_typ = cfi_unpack_1(data[0x20]); \
131 (qryp)->erase_blk_time_typ = cfi_unpack_1(data[0x21]); \
132 (qryp)->erase_chiptime_typ = cfi_unpack_1(data[0x22]); \
133 (qryp)->write_word_time_max = cfi_unpack_1(data[0x23]); \
134 (qryp)->write_nbyte_time_max = cfi_unpack_1(data[0x24]); \
135 (qryp)->erase_blk_time_max = cfi_unpack_1(data[0x25]); \
136 (qryp)->erase_chiptime_max = cfi_unpack_1(data[0x26]); \
137 (qryp)->device_size = cfi_unpack_1(data[0x27]); \
138 (qryp)->interface_code_desc = \
139 be16toh(cfi_unpack_2(data[0x28], data[0x29])); \
140 (qryp)->write_nbyte_size_max = \
141 be16toh(cfi_unpack_2(data[0x2a], data[0x2b])); \
142 (qryp)->erase_blk_regions = cfi_unpack_1(data[0x2c]); \
143 u_int _i = 0x2d; \
144 const u_int _n = (qryp)->erase_blk_regions; \
145 KASSERT(_n <= 4); \
146 for (u_int _r = 0; _r < _n; _r++, _i+=4) { \
147 (qryp)->erase_blk_info[_r].y = \
148 be32toh(cfi_unpack_2(data[_i+0], data[_i+1])); \
149 (qryp)->erase_blk_info[_r].z = \
150 be32toh(cfi_unpack_2(data[_i+2], data[_i+3])); \
151 } \
152 } while (0)
153
154 #define cfi_unpack_pri_0002(qryp, data) \
155 do { \
156 (qryp)->pri.cmd_0002.pri[0] = cfi_unpack_1(data[0x00]); \
157 (qryp)->pri.cmd_0002.pri[1] = cfi_unpack_1(data[0x01]); \
158 (qryp)->pri.cmd_0002.pri[2] = cfi_unpack_1(data[0x02]); \
159 (qryp)->pri.cmd_0002.version_maj = cfi_unpack_1(data[0x03]); \
160 (qryp)->pri.cmd_0002.version_min = cfi_unpack_1(data[0x04]); \
161 (qryp)->pri.cmd_0002.asupt = cfi_unpack_1(data[0x05]); \
162 (qryp)->pri.cmd_0002.erase_susp = cfi_unpack_1(data[0x06]); \
163 (qryp)->pri.cmd_0002.sector_prot = cfi_unpack_1(data[0x07]); \
164 (qryp)->pri.cmd_0002.tmp_sector_unprot = \
165 cfi_unpack_1(data[0x08]); \
166 (qryp)->pri.cmd_0002.sector_prot_scheme = \
167 cfi_unpack_1(data[0x09]); \
168 (qryp)->pri.cmd_0002.simul_op = cfi_unpack_1(data[0x0a]); \
169 (qryp)->pri.cmd_0002.burst_mode_type = cfi_unpack_1(data[0x0b]);\
170 (qryp)->pri.cmd_0002.page_mode_type = cfi_unpack_1(data[0x0c]); \
171 (qryp)->pri.cmd_0002.acc_min = cfi_unpack_1(data[0x0d]); \
172 (qryp)->pri.cmd_0002.acc_max = cfi_unpack_1(data[0x0e]); \
173 (qryp)->pri.cmd_0002.wp_prot = cfi_unpack_1(data[0x0f]); \
174 /* XXX 1.3 stops here */ \
175 (qryp)->pri.cmd_0002.prog_susp = cfi_unpack_1(data[0x10]); \
176 (qryp)->pri.cmd_0002.unlock_bypass = cfi_unpack_1(data[0x11]); \
177 (qryp)->pri.cmd_0002.sss_size = cfi_unpack_1(data[0x12]); \
178 (qryp)->pri.cmd_0002.soft_feat = cfi_unpack_1(data[0x13]); \
179 (qryp)->pri.cmd_0002.page_size = cfi_unpack_1(data[0x14]); \
180 (qryp)->pri.cmd_0002.erase_susp_time_max = \
181 cfi_unpack_1(data[0x15]); \
182 (qryp)->pri.cmd_0002.prog_susp_time_max = \
183 cfi_unpack_1(data[0x16]); \
184 (qryp)->pri.cmd_0002.embhwrst_time_max = \
185 cfi_unpack_1(data[0x38]); \
186 (qryp)->pri.cmd_0002.hwrst_time_max = \
187 cfi_unpack_1(data[0x39]); \
188 } while (0)
189
190 #define CFI_QRY_UNPACK_COMMON(cfi, data, type, found) \
191 do { \
192 struct cfi_query_data * const qryp = &cfi->cfi_qry_data; \
193 \
194 memset(qryp, 0, sizeof(*qryp)); \
195 cfi_unpack_qry(qryp, data); \
196 \
197 switch (qryp->id_pri) { \
198 case 0x0002: \
199 if ((cfi_unpack_1(data[qryp->addr_pri + 0]) == 'P') && \
200 (cfi_unpack_1(data[qryp->addr_pri + 1]) == 'R') && \
201 (cfi_unpack_1(data[qryp->addr_pri + 2]) == 'I')) { \
202 type *pri_data = &data[qryp->addr_pri]; \
203 cfi_unpack_pri_0002(qryp, pri_data); \
204 found = true; \
205 break; \
206 } \
207 default: \
208 printf("%s: unsupported id_pri=%#x\n", \
209 __func__, qryp->id_pri); \
210 break; /* unknown command set */ \
211 } \
212 } while (0)
213
214 /*
215 * cfi_chip_query_opmode - determine operational mode based on QRY signature
216 */
217 static bool
218 cfi_chip_query_opmode(struct cfi *cfi, uint8_t *data,
219 const struct cfi_opmodes *tab, u_int nentries)
220 {
221 for (u_int i=0; i < nentries; i++) {
222 if (memcmp(&data[tab[i].qsa], tab[i].sig, tab[i].len) == 0) {
223 cfi->cfi_opmode = &tab[i];
224 return true;
225 }
226 }
227 return false;
228 }
229
230 static bool
231 cfi_chip_query_1(struct cfi * const cfi)
232 {
233 uint8_t data[0x80];
234
235 bus_space_read_region_1(cfi->cfi_bst, cfi->cfi_bsh, 0, data,
236 __arraycount(data));
237
238 bool found = cfi_chip_query_opmode(cfi, data, cfi_opmodes_1,
239 __arraycount(cfi_opmodes_1));
240
241 if (found) {
242 CFI_QRY_UNPACK_COMMON(cfi, data, uint8_t, found);
243 }
244
245 return found;
246 }
247
248 static bool
249 cfi_chip_query_2(struct cfi * const cfi)
250 {
251 uint16_t data[0x80];
252
253 bus_space_read_region_2(cfi->cfi_bst, cfi->cfi_bsh, 0, data,
254 __arraycount(data));
255
256 bool found = cfi_chip_query_opmode(cfi, (uint8_t *)data,
257 cfi_opmodes_2, __arraycount(cfi_opmodes_2));
258
259 if (found) {
260 CFI_QRY_UNPACK_COMMON(cfi, data, uint16_t, found);
261 }
262
263 return found;
264 }
265
266 static bool
267 cfi_chip_query_4(struct cfi * const cfi)
268 {
269 uint32_t data[0x80];
270
271 bus_space_read_region_4(cfi->cfi_bst, cfi->cfi_bsh, 0, data,
272 __arraycount(data));
273
274 bool found = cfi_chip_query_opmode(cfi, (uint8_t *)data,
275 cfi_opmodes_4, __arraycount(cfi_opmodes_4));
276
277 if (found) {
278 CFI_QRY_UNPACK_COMMON(cfi, data, uint32_t, found);
279 }
280
281 return found;
282 }
283
284 static bool
285 cfi_chip_query_8(struct cfi * const cfi)
286 {
287 #ifdef NOTYET
288 uint64_t data[0x80];
289
290 bus_space_read_region_8(cfi->cfi_bst, cfi->cfi_bsh, 0, data,
291 __arraycount(data));
292
293 bool found = cfi_chip_query_opmode(cfi, (uint8_t *)data,
294 cfi_opmodes_8, __arraycount(cfi_opmodes_8));
295
296 if (found) {
297 CFI_QRY_UNPACK_COMMON(cfi, data, uint64_t, found);
298 }
299
300 return found;
301 #else
302 return false;
303 #endif
304 }
305
306 /*
307 * cfi_chip_query - detect a CFI chip
308 *
309 * fill in the struct cfi as we discover what's there
310 */
311 static bool
312 cfi_chip_query(struct cfi * const cfi)
313 {
314 bool found = false;
315 const bus_size_t cfi_query_offset[] = {
316 CFI_QUERY_MODE_ADDRESS,
317 CFI_QUERY_MODE_ALT_ADDRESS
318 };
319
320 KASSERT(cfi != NULL);
321 KASSERT(cfi->cfi_bst != NULL);
322
323 for (int j=0; !found && j < __arraycount(cfi_query_offset); j++) {
324
325 cfi_reset_default(cfi);
326 cfi_cmd(cfi, cfi_query_offset[j], CFI_QUERY_DATA);
327
328 switch(cfi->cfi_portwidth) {
329 case 0:
330 found = cfi_chip_query_1(cfi);
331 break;
332 case 1:
333 found = cfi_chip_query_2(cfi);
334 break;
335 case 2:
336 found = cfi_chip_query_4(cfi);
337 break;
338 case 3:
339 found = cfi_chip_query_8(cfi);
340 break;
341 default:
342 panic("%s: bad portwidth %d\n",
343 __func__, cfi->cfi_portwidth);
344 }
345 }
346
347 return found;
348 }
349
350 /*
351 * cfi_probe - search for a CFI NOR trying various port & chip widths
352 *
353 * NOTE:
354 * striped NOR chips design not supported yet,
355 * so force portwidth=chipwidth for now
356 * eventually permute portwidth seperately
357 */
358 bool
359 cfi_probe(struct cfi * const cfi)
360 {
361 bool found;
362
363 KASSERT(cfi != NULL);
364
365 for (u_int cw = 0; cw < 3; cw++) {
366 cfi->cfi_portwidth = /* XXX */
367 cfi->cfi_chipwidth = cw;
368 found = cfi_chip_query(cfi);
369 if (found)
370 goto out;
371 }
372 out:
373 cfi_reset_default(cfi); /* exit QRY mode */
374 return found;
375 }
376
377 bool
378 cfi_identify(struct cfi * const cfi)
379 {
380 const bus_space_tag_t bst = cfi->cfi_bst;
381 const bus_space_handle_t bsh = cfi->cfi_bsh;
382 bool found = true;
383
384 KASSERT(cfi != NULL);
385 KASSERT(bst != NULL);
386
387 memset(cfi, 0, sizeof(struct cfi)); /* XXX clean slate */
388 cfi->cfi_bst = bst; /* restore bus space */
389 cfi->cfi_bsh = bsh; /* " " " */
390
391 /* gather CFI PRQ and PRI data */
392 if (! cfi_probe(cfi)) {
393 aprint_debug("%s: cfi_probe failed\n", __func__);
394 found = false;
395 goto out;
396 }
397
398 /* gather ID data if possible */
399 if (! cfi_jedec_id(cfi)) {
400 aprint_debug("%s: cfi_jedec_id failed\n", __func__);
401 goto out;
402 }
403
404 out:
405 cfi_reset_default(cfi); /* exit QRY mode */
406
407 return found;
408 }
409
410 static int
411 cfi_scan_media(device_t self, struct nor_chip *chip)
412 {
413 struct nor_softc *sc = device_private(self);
414 KASSERT(sc != NULL);
415 KASSERT(sc->sc_nor_if != NULL);
416 struct cfi * const cfi = (struct cfi * const)sc->sc_nor_if->private;
417 KASSERT(cfi != NULL);
418
419 sc->sc_nor_if->access_width = cfi->cfi_portwidth;
420
421 chip->nc_manf_id = cfi->cfi_id_data.id_mid;
422 chip->nc_dev_id = cfi->cfi_id_data.id_did[0]; /* XXX 3 words */
423 chip->nc_size = 1 << cfi->cfi_qry_data.device_size;
424
425 /* size of line for Read Buf command */
426 chip->nc_line_size = 1 << cfi->cfi_qry_data.pri.cmd_0002.page_size;
427
428 /*
429 * size of erase block
430 * XXX depends on erase region
431 */
432 chip->nc_num_luns = 1;
433 chip->nc_lun_blocks = cfi->cfi_qry_data.erase_blk_info[0].y + 1;
434 chip->nc_block_size = cfi->cfi_qry_data.erase_blk_info[0].z * 256;
435
436 switch (cfi->cfi_qry_data.id_pri) {
437 case 0x0002:
438 cfi_0002_init(sc, cfi, chip);
439 break;
440 default:
441 return -1;
442 }
443
444 return 0;
445 }
446
447 void
448 cfi_init(device_t self)
449 {
450 /* nothing */
451 }
452
453 static void
454 cfi_select(device_t self, bool select)
455 {
456 /* nothing */
457 }
458
459 static void
460 cfi_read_1(device_t self, flash_off_t offset, uint8_t *datap)
461 {
462 }
463
464 static void
465 cfi_read_2(device_t self, flash_off_t offset, uint16_t *datap)
466 {
467 }
468
469 static void
470 cfi_read_4(device_t self, flash_off_t offset, uint32_t *datap)
471 {
472 }
473
474 static void
475 cfi_read_buf_1(device_t self, flash_off_t offset, uint8_t *datap, size_t size)
476 {
477 }
478
479 static void
480 cfi_read_buf_2(device_t self, flash_off_t offset, uint16_t *datap, size_t size)
481 {
482 }
483
484 static void
485 cfi_read_buf_4(device_t self, flash_off_t offset, uint32_t *datap, size_t size)
486 {
487 }
488
489 static void
490 cfi_write_1(device_t self, flash_off_t offset, uint8_t data)
491 {
492 }
493
494 static void
495 cfi_write_2(device_t self, flash_off_t offset, uint16_t data)
496 {
497 }
498
499 static void
500 cfi_write_4(device_t self, flash_off_t offset, uint32_t data)
501 {
502 }
503
504 static void
505 cfi_write_buf_1(device_t self, flash_off_t offset, const uint8_t *datap,
506 size_t size)
507 {
508 }
509
510 static void
511 cfi_write_buf_2(device_t self, flash_off_t offset, const uint16_t *datap,
512 size_t size)
513 {
514 }
515
516 static void
517 cfi_write_buf_4(device_t self, flash_off_t offset, const uint32_t *datap,
518 size_t size)
519 {
520 }
521
522 void
523 cfi_cmd(struct cfi * const cfi, bus_size_t off, uint32_t val)
524 {
525 const bus_space_tag_t bst = cfi->cfi_bst;
526 bus_space_handle_t bsh = cfi->cfi_bsh;
527
528 off <<= cfi->cfi_portwidth;
529
530 DPRINTF(("%s: %p %x %x %x\n", __func__, bst, bsh, off, val));
531
532 switch(cfi->cfi_portwidth) {
533 case 0:
534 bus_space_write_1(bst, bsh, off, (uint8_t)val);
535 break;
536 case 1:
537 bus_space_write_2(bst, bsh, off, val);
538 break;
539 case 2:
540 bus_space_write_4(bst, bsh, off, (uint32_t)val);
541 break;
542 #ifdef NOTYET
543 case 3:
544 bus_space_write_4(bst, bsh, off, (uint64_t)val);
545 break;
546 #endif
547 default:
548 panic("%s: bad portwidth %d bytes\n",
549 __func__, 1 << cfi->cfi_portwidth);
550 }
551 }
552
553 /*
554 * cfi_reset_default - when we don't know which command will work, use both
555 */
556 void
557 cfi_reset_default(struct cfi * const cfi)
558 {
559 cfi_cmd(cfi, CFI_ADDRESS_ANY, CFI_RESET_DATA);
560 cfi_cmd(cfi, CFI_ADDRESS_ANY, CFI_ALT_RESET_DATA);
561 }
562
563 /*
564 * cfi_reset_std - use standard reset command
565 */
566 void
567 cfi_reset_std(struct cfi * const cfi)
568 {
569 cfi_cmd(cfi, CFI_ADDRESS_ANY, CFI_RESET_DATA);
570 }
571
572 /*
573 * cfi_reset_alt - use "alternate" reset command
574 */
575 void
576 cfi_reset_alt(struct cfi * const cfi)
577 {
578 cfi_cmd(cfi, CFI_ADDRESS_ANY, CFI_ALT_RESET_DATA);
579 }
580
581 static void
582 cfi_jedec_id_2(struct cfi * const cfi)
583 {
584 struct cfi_jedec_id_data *idp = &cfi->cfi_id_data;
585 uint16_t data[0x10];
586
587 bus_space_read_region_2(cfi->cfi_bst, cfi->cfi_bsh, 0, data,
588 __arraycount(data));
589
590 idp->id_mid = data[0];
591 idp->id_did[0] = data[1];
592 idp->id_did[1] = data[0xe];
593 idp->id_did[2] = data[0xf];
594 idp->id_prot_state = data[2];
595 idp->id_indicators = data[3];
596
597 /* software bits, upper and lower
598 * - undefined on S29GL-P
599 * - defined on S29GL-S
600 */
601 idp->id_swb_lo = data[0xc];
602 idp->id_swb_hi = data[0xd];
603 }
604
605 /*
606 * cfi_jedec_id - get JEDEC ID info
607 *
608 * this should be ignored altogether for CFI chips?
609 * JEDEC ID is superceded by CFI info except CFI is not
610 * a true superset of the JEDEC, so some info provided
611 * by JEDEC is not available via CFI QRY.
612 * But the JEDEC info is unreliable:
613 * - different chips not distinguishaable by IDs
614 * - some fields undefined (read as 0xff) on some chips
615 */
616 static bool
617 cfi_jedec_id(struct cfi * const cfi)
618 {
619 DPRINTF(("%s\n", __func__));
620
621 cfi_cmd(cfi, 0x555, 0xaa);
622 cfi_cmd(cfi, 0x2aa, 0x55);
623 cfi_cmd(cfi, 0x555, 0x90);
624
625 switch(cfi->cfi_portwidth) {
626 case 1:
627 cfi_jedec_id_2(cfi);
628 break;
629 #ifdef NOTYET
630 case 0:
631 cfi_jedec_id_1(cfi);
632 break;
633 case 2:
634 cfi_jedec_id_4(cfi);
635 break;
636 case 3:
637 cfi_jedec_id_8(cfi);
638 break;
639 #endif
640 default:
641 panic("%s: bad portwidth %d bytes\n",
642 __func__, 1 << cfi->cfi_portwidth);
643 }
644
645 return true;
646 }
647
648 void
649 cfi_print(device_t self, struct cfi * const cfi)
650 {
651 char pbuf[sizeof("XXXX MB")];
652 struct cfi_query_data * const qryp = &cfi->cfi_qry_data;
653
654 format_bytes(pbuf, sizeof(pbuf), 1 << qryp->device_size);
655 aprint_normal_dev(self, "CFI NOR flash %s %s\n", pbuf,
656 cfi_interface_desc_str(qryp->interface_code_desc));
657 #ifdef NOR_VERBOSE
658 aprint_normal_dev(self, "manufacturer id %#x, device id %#x %#x %#x\n",
659 cfi->cfi_id_data.id_mid,
660 cfi->cfi_id_data.id_did[0],
661 cfi->cfi_id_data.id_did[1],
662 cfi->cfi_id_data.id_did[2]);
663 aprint_normal_dev(self, "%s\n", cfi->cfi_opmode->str);
664 aprint_normal_dev(self, "sw bits lo=%#x hi=%#x\n",
665 cfi->cfi_id_data.id_swb_lo,
666 cfi->cfi_id_data.id_swb_hi);
667 aprint_normal_dev(self, "max multibyte write size %d\n",
668 1 << qryp->write_nbyte_size_max);
669 aprint_normal_dev(self, "%d Erase Block Region(s)\n",
670 qryp->erase_blk_regions);
671 for (u_int r=0; r < qryp->erase_blk_regions; r++) {
672 size_t sz = qryp->erase_blk_info[r].z * 256;
673 format_bytes(pbuf, sizeof(pbuf), sz);
674 aprint_normal(" %d: %d blocks, size %s\n", r,
675 qryp->erase_blk_info[r].y + 1, pbuf);
676 }
677 #endif
678
679 switch (cfi->cfi_qry_data.id_pri) {
680 case 0x0002:
681 cfi_0002_print(self, cfi);
682 break;
683 }
684 }
685