Skip to content

Commit 638d983

Browse files
Nicolas PitreThomas Gleixner
authored andcommitted
{MTD] add support for Intel's "Sibley" flash
This updates the Primary Vendor-Specific Extended Query parsing to version 1.4 in order to get the information about the Configurable Programming Mode regions implemented in the Sibley flash, as well as selecting the appropriate write command code. This flash does not behave like traditional NOR flash when writing data. While mtdblock should just work, further changes are needed for JFFS2 use. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1 parent 4843653 commit 638d983

5 files changed

Lines changed: 92 additions & 29 deletions

File tree

‎drivers/mtd/chips/cfi_cmdset_0001.c‎

Lines changed: 65 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* (C) 2000 Red Hat. GPL'd
66
*
7-
* $Id: cfi_cmdset_0001.c,v 1.181 2005/08/06 04:16:48 nico Exp $
7+
* $Id: cfi_cmdset_0001.c,v 1.182 2005/08/06 04:40:41 nico Exp $
88
*
99
*
1010
* 10/10/2000 Nicolas Pitre <nico@cam.org>
@@ -105,6 +105,7 @@ static struct mtd_chip_driver cfi_intelext_chipdrv = {
105105
static void cfi_tell_features(struct cfi_pri_intelext *extp)
106106
{
107107
int i;
108+
printk(" Extended Query version %c.%c\n", extp->MajorVersion, extp->MinorVersion);
108109
printk(" Feature/Command Support: %4.4X\n", extp->FeatureSupport);
109110
printk(" - Chip Erase: %s\n", extp->FeatureSupport&1?"supported":"unsupported");
110111
printk(" - Suspend Erase: %s\n", extp->FeatureSupport&2?"supported":"unsupported");
@@ -116,7 +117,8 @@ static void cfi_tell_features(struct cfi_pri_intelext *extp)
116117
printk(" - Page-mode read: %s\n", extp->FeatureSupport&128?"supported":"unsupported");
117118
printk(" - Synchronous read: %s\n", extp->FeatureSupport&256?"supported":"unsupported");
118119
printk(" - Simultaneous operations: %s\n", extp->FeatureSupport&512?"supported":"unsupported");
119-
for (i=10; i<32; i++) {
120+
printk(" - Extended Flash Array: %s\n", extp->FeatureSupport&1024?"supported":"unsupported");
121+
for (i=11; i<32; i++) {
120122
if (extp->FeatureSupport & (1<<i))
121123
printk(" - Unknown Bit %X: supported\n", i);
122124
}
@@ -130,12 +132,18 @@ static void cfi_tell_features(struct cfi_pri_intelext *extp)
130132

131133
printk(" Block Status Register Mask: %4.4X\n", extp->BlkStatusRegMask);
132134
printk(" - Lock Bit Active: %s\n", extp->BlkStatusRegMask&1?"yes":"no");
133-
printk(" - Valid Bit Active: %s\n", extp->BlkStatusRegMask&2?"yes":"no");
134-
for (i=2; i<16; i++) {
135+
printk(" - Lock-Down Bit Active: %s\n", extp->BlkStatusRegMask&2?"yes":"no");
136+
for (i=2; i<3; i++) {
135137
if (extp->BlkStatusRegMask & (1<<i))
136138
printk(" - Unknown Bit %X Active: yes\n",i);
137139
}
138-
140+
printk(" - EFA Lock Bit: %s\n", extp->BlkStatusRegMask&16?"yes":"no");
141+
printk(" - EFA Lock-Down Bit: %s\n", extp->BlkStatusRegMask&32?"yes":"no");
142+
for (i=6; i<16; i++) {
143+
if (extp->BlkStatusRegMask & (1<<i))
144+
printk(" - Unknown Bit %X Active: yes\n",i);
145+
}
146+
139147
printk(" Vcc Logic Supply Optimum Program/Erase Voltage: %d.%d V\n",
140148
extp->VccOptimal >> 4, extp->VccOptimal & 0xf);
141149
if (extp->VppOptimal)
@@ -253,7 +261,7 @@ read_pri_intelext(struct map_info *map, __u16 adr)
253261
return NULL;
254262

255263
if (extp->MajorVersion != '1' ||
256-
(extp->MinorVersion < '0' || extp->MinorVersion > '3')) {
264+
(extp->MinorVersion < '0' || extp->MinorVersion > '4')) {
257265
printk(KERN_ERR " Unknown Intel/Sharp Extended Query "
258266
"version %c.%c.\n", extp->MajorVersion,
259267
extp->MinorVersion);
@@ -266,7 +274,7 @@ read_pri_intelext(struct map_info *map, __u16 adr)
266274
extp->BlkStatusRegMask = le16_to_cpu(extp->BlkStatusRegMask);
267275
extp->ProtRegAddr = le16_to_cpu(extp->ProtRegAddr);
268276

269-
if (extp->MajorVersion == '1' && extp->MinorVersion == '3') {
277+
if (extp->MajorVersion == '1' && extp->MinorVersion >= '3') {
270278
unsigned int extra_size = 0;
271279
int nb_parts, i;
272280

@@ -275,14 +283,18 @@ read_pri_intelext(struct map_info *map, __u16 adr)
275283
sizeof(struct cfi_intelext_otpinfo);
276284

277285
/* Burst Read info */
278-
extra_size += 6;
286+
extra_size += (extp->MinorVersion < '4') ? 6 : 5;
279287

280288
/* Number of hardware-partitions */
281289
extra_size += 1;
282290
if (extp_size < sizeof(*extp) + extra_size)
283291
goto need_more;
284292
nb_parts = extp->extra[extra_size - 1];
285293

294+
/* skip the sizeof(partregion) field in CFI 1.4 */
295+
if (extp->MinorVersion >= '4')
296+
extra_size += 2;
297+
286298
for (i = 0; i < nb_parts; i++) {
287299
struct cfi_intelext_regioninfo *rinfo;
288300
rinfo = (struct cfi_intelext_regioninfo *)&extp->extra[extra_size];
@@ -294,6 +306,9 @@ read_pri_intelext(struct map_info *map, __u16 adr)
294306
* sizeof(struct cfi_intelext_blockinfo);
295307
}
296308

309+
if (extp->MinorVersion >= '4')
310+
extra_size += sizeof(struct cfi_intelext_programming_regioninfo);
311+
297312
if (extp_size < sizeof(*extp) + extra_size) {
298313
need_more:
299314
extp_size = sizeof(*extp) + extra_size;
@@ -490,7 +505,7 @@ static int cfi_intelext_partition_fixup(struct mtd_info *mtd,
490505
* arrangement at this point. This can be rearranged in the future
491506
* if someone feels motivated enough. --nico
492507
*/
493-
if (extp && extp->MajorVersion == '1' && extp->MinorVersion == '3'
508+
if (extp && extp->MajorVersion == '1' && extp->MinorVersion >= '3'
494509
&& extp->FeatureSupport & (1 << 9)) {
495510
struct cfi_private *newcfi;
496511
struct flchip *chip;
@@ -502,12 +517,16 @@ static int cfi_intelext_partition_fixup(struct mtd_info *mtd,
502517
sizeof(struct cfi_intelext_otpinfo);
503518

504519
/* Burst Read info */
505-
offs += 6;
520+
offs += (extp->MinorVersion < '4') ? 6 : 5;
506521

507522
/* Number of partition regions */
508523
numregions = extp->extra[offs];
509524
offs += 1;
510525

526+
/* skip the sizeof(partregion) field in CFI 1.4 */
527+
if (extp->MinorVersion >= '4')
528+
offs += 2;
529+
511530
/* Number of hardware partitions */
512531
numparts = 0;
513532
for (i = 0; i < numregions; i++) {
@@ -519,6 +538,20 @@ static int cfi_intelext_partition_fixup(struct mtd_info *mtd,
519538
sizeof(struct cfi_intelext_blockinfo);
520539
}
521540

541+
/* Programming Region info */
542+
if (extp->MinorVersion >= '4') {
543+
struct cfi_intelext_programming_regioninfo *prinfo;
544+
prinfo = (struct cfi_intelext_programming_regioninfo *)&extp->extra[offs];
545+
MTD_PROGREGION_SIZE(mtd) = cfi->interleave << prinfo->ProgRegShift;
546+
MTD_PROGREGION_CTRLMODE_VALID(mtd) = cfi->interleave * prinfo->ControlValid;
547+
MTD_PROGREGION_CTRLMODE_INVALID(mtd) = cfi->interleave * prinfo->ControlInvalid;
548+
mtd->flags |= MTD_PROGRAM_REGIONS;
549+
printk(KERN_DEBUG "%s: program region size/ctrl_valid/ctrl_inval = %d/%d/%d\n",
550+
map->name, MTD_PROGREGION_SIZE(mtd),
551+
MTD_PROGREGION_CTRLMODE_VALID(mtd),
552+
MTD_PROGREGION_CTRLMODE_INVALID(mtd));
553+
}
554+
522555
/*
523556
* All functions below currently rely on all chips having
524557
* the same geometry so we'll just assume that all hardware
@@ -1222,12 +1255,17 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
12221255

12231256
adr += chip->start;
12241257

1225-
/* Let's determine this according to the interleave only once */
1258+
/* Let's determine those according to the interleave only once */
12261259
status_OK = CMD(0x80);
12271260
switch (mode) {
1228-
case FL_WRITING: write_cmd = CMD(0x40); break;
1229-
case FL_OTP_WRITE: write_cmd = CMD(0xc0); break;
1230-
default: return -EINVAL;
1261+
case FL_WRITING:
1262+
write_cmd = (cfi->cfiq->P_ID != 0x0200) ? CMD(0x40) : CMD(0x41);
1263+
break;
1264+
case FL_OTP_WRITE:
1265+
write_cmd = CMD(0xc0);
1266+
break;
1267+
default:
1268+
return -EINVAL;
12311269
}
12321270

12331271
spin_lock(chip->mutex);
@@ -1410,16 +1448,17 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
14101448
unsigned long adr, const u_char *buf, int len)
14111449
{
14121450
struct cfi_private *cfi = map->fldrv_priv;
1413-
map_word status, status_OK;
1451+
map_word status, status_OK, write_cmd;
14141452
unsigned long cmd_adr, timeo;
14151453
int wbufsize, z, ret=0, bytes, words;
14161454

14171455
wbufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize;
14181456
adr += chip->start;
14191457
cmd_adr = adr & ~(wbufsize-1);
1420-
1458+
14211459
/* Let's determine this according to the interleave only once */
14221460
status_OK = CMD(0x80);
1461+
write_cmd = (cfi->cfiq->P_ID != 0x0200) ? CMD(0xe8) : CMD(0xe9);
14231462

14241463
spin_lock(chip->mutex);
14251464
ret = get_chip(map, chip, cmd_adr, FL_WRITING);
@@ -1451,7 +1490,7 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
14511490

14521491
z = 0;
14531492
for (;;) {
1454-
map_write(map, CMD(0xe8), cmd_adr);
1493+
map_write(map, write_cmd, cmd_adr);
14551494

14561495
status = map_read(map, cmd_adr);
14571496
if (map_word_andequal(map, status, status_OK, status_OK))
@@ -2380,20 +2419,23 @@ static void cfi_intelext_destroy(struct mtd_info *mtd)
23802419
kfree(mtd->eraseregions);
23812420
}
23822421

2383-
static char im_name_1[]="cfi_cmdset_0001";
2384-
static char im_name_3[]="cfi_cmdset_0003";
2422+
static char im_name_0001[] = "cfi_cmdset_0001";
2423+
static char im_name_0003[] = "cfi_cmdset_0003";
2424+
static char im_name_0200[] = "cfi_cmdset_0200";
23852425

23862426
static int __init cfi_intelext_init(void)
23872427
{
2388-
inter_module_register(im_name_1, THIS_MODULE, &cfi_cmdset_0001);
2389-
inter_module_register(im_name_3, THIS_MODULE, &cfi_cmdset_0001);
2428+
inter_module_register(im_name_0001, THIS_MODULE, &cfi_cmdset_0001);
2429+
inter_module_register(im_name_0003, THIS_MODULE, &cfi_cmdset_0001);
2430+
inter_module_register(im_name_0200, THIS_MODULE, &cfi_cmdset_0001);
23902431
return 0;
23912432
}
23922433

23932434
static void __exit cfi_intelext_exit(void)
23942435
{
2395-
inter_module_unregister(im_name_1);
2396-
inter_module_unregister(im_name_3);
2436+
inter_module_unregister(im_name_0001);
2437+
inter_module_unregister(im_name_0003);
2438+
inter_module_unregister(im_name_0200);
23972439
}
23982440

23992441
module_init(cfi_intelext_init);

‎drivers/mtd/chips/gen_probe.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Routines common to all CFI-type probes.
33
* (C) 2001-2003 Red Hat, Inc.
44
* GPL'd
5-
* $Id: gen_probe.c,v 1.22 2005/01/24 23:49:50 rmk Exp $
5+
* $Id: gen_probe.c,v 1.23 2005/08/06 04:40:41 nico Exp $
66
*/
77

88
#include <linux/kernel.h>
@@ -235,6 +235,7 @@ static struct mtd_info *check_cmd_set(struct map_info *map, int primary)
235235
#ifdef CONFIG_MTD_CFI_INTELEXT
236236
case 0x0001:
237237
case 0x0003:
238+
case 0x0200:
238239
return cfi_cmdset_0001(map, primary);
239240
#endif
240241
#ifdef CONFIG_MTD_CFI_AMDSTD

‎include/linux/mtd/cfi.h‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
/* Common Flash Interface structures
33
* See http://support.intel.com/design/flash/technote/index.htm
4-
* $Id: cfi.h,v 1.54 2005/06/06 23:04:36 tpoynor Exp $
4+
* $Id: cfi.h,v 1.55 2005/08/06 04:40:42 nico Exp $
55
*/
66

77
#ifndef __MTD_CFI_H__
@@ -173,6 +173,15 @@ struct cfi_intelext_regioninfo {
173173
struct cfi_intelext_blockinfo BlockTypes[1];
174174
} __attribute__((packed));
175175

176+
struct cfi_intelext_programming_regioninfo {
177+
uint8_t ProgRegShift;
178+
uint8_t Reserved1;
179+
uint8_t ControlValid;
180+
uint8_t Reserved2;
181+
uint8_t ControlInvalid;
182+
uint8_t Reserved3;
183+
} __attribute__((packed));
184+
176185
/* Vendor-Specific PRI for AMD/Fujitsu Extended Command Set (0x0002) */
177186

178187
struct cfi_pri_amdstd {
@@ -316,7 +325,7 @@ static inline map_word cfi_build_cmd(u_long cmd, struct map_info *map, struct cf
316325
#define CMD(x) cfi_build_cmd((x), map, cfi)
317326

318327

319-
static inline unsigned char cfi_merge_status(map_word val, struct map_info *map,
328+
static inline unsigned long cfi_merge_status(map_word val, struct map_info *map,
320329
struct cfi_private *cfi)
321330
{
322331
int wordwidth, words_per_bus, chip_mode, chips_per_word;

‎include/linux/mtd/mtd.h‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $Id: mtd.h,v 1.59 2005/04/11 10:19:02 gleixner Exp $
2+
* $Id: mtd.h,v 1.60 2005/08/06 04:40:42 nico Exp $
33
*
44
* Copyright (C) 1999-2003 David Woodhouse <dwmw2@infradead.org> et al.
55
*
@@ -72,7 +72,17 @@ struct mtd_info {
7272
u_int32_t oobsize; // Amount of OOB data per block (e.g. 16)
7373
u_int32_t ecctype;
7474
u_int32_t eccsize;
75-
75+
76+
/*
77+
* Reuse some of the above unused fields in the case of NOR flash
78+
* with configurable programming regions to avoid modifying the
79+
* user visible structure layout/size. Only valid when the
80+
* MTD_PROGRAM_REGIONS flag is set.
81+
* (Maybe we should have an union for those?)
82+
*/
83+
#define MTD_PROGREGION_SIZE(mtd) (mtd)->oobblock
84+
#define MTD_PROGREGION_CTRLMODE_VALID(mtd) (mtd)->oobsize
85+
#define MTD_PROGREGION_CTRLMODE_INVALID(mtd) (mtd)->ecctype
7686

7787
// Kernel-only stuff starts here.
7888
char *name;

‎include/mtd/mtd-abi.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $Id: mtd-abi.h,v 1.11 2005/05/19 16:08:58 gleixner Exp $
2+
* $Id: mtd-abi.h,v 1.12 2005/08/06 04:40:43 nico Exp $
33
*
44
* Portions of MTD ABI definition which are shared by kernel and user space
55
*/
@@ -42,6 +42,7 @@ struct mtd_oob_buf {
4242
#define MTD_OOB 64 // Out-of-band data (NAND flash)
4343
#define MTD_ECC 128 // Device capable of automatic ECC
4444
#define MTD_NO_VIRTBLOCKS 256 // Virtual blocks not allowed
45+
#define MTD_PROGRAM_REGIONS 512 // Configurable Programming Regions
4546

4647
// Some common devices / combinations of capabilities
4748
#define MTD_CAP_ROM 0

0 commit comments

Comments
 (0)