* Problems with Intel TE28F320 B3 @ 2001-09-04 13:09 Norbert Leon 2001-09-04 13:39 ` David Woodhouse 0 siblings, 1 reply; 6+ messages in thread From: Norbert Leon @ 2001-09-04 13:09 UTC (permalink / raw) To: linux-mtd Hi all I'm working on an intel te28f320 b3ba110 (complete reference) and i can't get my system to recognize it ... Here is my kernel configuration : CONFIG_MTD=y CONFIG_MTD_DEBUG=y CONFIG_MTD_DEBUG_VERBOSE=3 CONFIG_MTD_SLRAM=y CONFIG_MTD_RAM=y CONFIG_MTD_ROM=y CONFIG_MTD_CFI=y CONFIG_MTD_CFI_GEOMETRY=y CONFIG_MTD_CFI_B1=y CONFIG_MTD_CFI_B2=y CONFIG_MTD_CFI_B4=y CONFIG_MTD_CFI_I1=y CONFIG_MTD_CFI_I2=y CONFIG_MTD_CFI_I4=y CONFIG_MTD_CFI_INTELEXT=y CONFIG_MTD_PHYSMAP=y CONFIG_MTD_PHYSMAP_START=0x8000000 CONFIG_MTD_PHYSMAP_LEN=0x4000000 CONFIG_MTD_PHYSMAP_BUSWIDTH=2 and here are the kernel messages at the boot : mtd: Giving out device 0 to Raw memory Registered physmem device from 98304Kb to 131072Kb Mapped from 0xc2808000 to 0xc4808000 physmap flash device: 4000000 at 8000000 Physically mapped flash: Found no CFI device at location zero finally, when i type cat /proc/mtd, here is what i get : / # cat /proc/mtd dev: size erasesize name mtd0: 02000000 00010000 "Raw memory" it's all weird because the kernel seems to find the flash, however there is this message "Found no CFI ..." I've tried to put a jffs filesystem on /dev/mtd but it doesn't work ... i also tried the various utilities provided along with jffs (erase, ftl_check ...) and it didn't work as well can some of you help me ? did some of you already succeed in mounting a filessytem on such an intel flash card ?? Thanks in advance ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Problems with Intel TE28F320 B3 2001-09-04 13:09 Problems with Intel TE28F320 B3 Norbert Leon @ 2001-09-04 13:39 ` David Woodhouse 2001-09-04 14:25 ` Daniel Belz 0 siblings, 1 reply; 6+ messages in thread From: David Woodhouse @ 2001-09-04 13:39 UTC (permalink / raw) To: Norbert Leon; +Cc: linux-mtd norbert@safetech.com said: > I'm working on an intel te28f320 b3ba110 (complete reference) and i > can't get my system to recognize it ... Some of the 28F320 chips are CFI-compliant and some aren't. The other letters and numbers you quoted didn't seem to help me work out which you have. Turn off CONFIG_MTD_RAM, CONFIG_MTD_ROM and CONFIG_MTD_SLRAM. You don't need them. -- dwmw2 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Problems with Intel TE28F320 B3 2001-09-04 13:39 ` David Woodhouse @ 2001-09-04 14:25 ` Daniel Belz 2001-09-04 14:23 ` Norbert Leon 0 siblings, 1 reply; 6+ messages in thread From: Daniel Belz @ 2001-09-04 14:25 UTC (permalink / raw) To: David Woodhouse; +Cc: Norbert Leon, linux-mtd David Woodhouse wrote: > norbert@safetech.com said: > > I'm working on an intel te28f320 b3ba110 (complete reference) and i > > can't get my system to recognize it ... > > Some of the 28F320 chips are CFI-compliant and some aren't. The other > letters and numbers you quoted didn't seem to help me work out which you > have. > > Turn off CONFIG_MTD_RAM, CONFIG_MTD_ROM and CONFIG_MTD_SLRAM. You don't > need them. > > -- > dwmw2 > > ______________________________________________________ > Linux MTD discussion mailing list > http://lists.infradead.org/mailman/listinfo/linux-mtd/ the flash intel TE28F320B3BA110 (same of the BSE-IPengine) isn't CFI compliant. Is a JEDEC Flash. You have to modify the MTD source code to detect the flash. If you are interested, i have this code, and if you need, i send to you. Else, see the cfi_cmdset002.c, cfi_probe.c, cfi_jedec.c (/drivers/mtd/chips) and physmap.c (/drivers/mtd/maps). My code give a solution to implementing JFFS file system and Partitioning Support. Daniel Belz belz@inf.pucrs.br ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Problems with Intel TE28F320 B3 2001-09-04 14:25 ` Daniel Belz @ 2001-09-04 14:23 ` Norbert Leon 2001-09-04 15:22 ` Daniel Belz 0 siblings, 1 reply; 6+ messages in thread From: Norbert Leon @ 2001-09-04 14:23 UTC (permalink / raw) To: Daniel Belz; +Cc: David Woodhouse, linux-mtd well thank you i am for sure interested in your code and it would be nice from you to send it to me. thanks in advance On Tue, 4 Sep 2001, Daniel Belz wrote: > David Woodhouse wrote: > > > norbert@safetech.com said: > > > I'm working on an intel te28f320 b3ba110 (complete reference) and i > > > can't get my system to recognize it ... > > > > Some of the 28F320 chips are CFI-compliant and some aren't. The other > > letters and numbers you quoted didn't seem to help me work out which you > > have. > > > > Turn off CONFIG_MTD_RAM, CONFIG_MTD_ROM and CONFIG_MTD_SLRAM. You don't > > need them. > > > > -- > > dwmw2 > > > > ______________________________________________________ > > Linux MTD discussion mailing list > > http://lists.infradead.org/mailman/listinfo/linux-mtd/ > > the flash intel TE28F320B3BA110 (same of the BSE-IPengine) isn't CFI > compliant. Is a JEDEC Flash. > You have to modify the MTD source code to detect the flash. > If you are interested, i have this code, and if you need, i send to you. > Else, see the cfi_cmdset002.c, cfi_probe.c, cfi_jedec.c > (/drivers/mtd/chips) and physmap.c (/drivers/mtd/maps). > My code give a solution to implementing JFFS file system and Partitioning > Support. > > > Daniel Belz > belz@inf.pucrs.br > > ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Problems with Intel TE28F320 B3 2001-09-04 14:23 ` Norbert Leon @ 2001-09-04 15:22 ` Daniel Belz 0 siblings, 0 replies; 6+ messages in thread From: Daniel Belz @ 2001-09-04 15:22 UTC (permalink / raw) To: Norbert Leon, linux-mtd [-- Attachment #1: Type: text/plain, Size: 2091 bytes --] Norbert Leon wrote: > well thank you > i am for sure interested in your code and it would be nice from you to > send it to me. > > thanks in advance > > On Tue, 4 Sep 2001, Daniel Belz wrote: > > > David Woodhouse wrote: > > > > > norbert@safetech.com said: > > > > I'm working on an intel te28f320 b3ba110 (complete reference) and i > > > > can't get my system to recognize it ... > > > > > > Some of the 28F320 chips are CFI-compliant and some aren't. The other > > > letters and numbers you quoted didn't seem to help me work out which you > > > have. > > > > > > Turn off CONFIG_MTD_RAM, CONFIG_MTD_ROM and CONFIG_MTD_SLRAM. You don't > > > need them. > > > > > > -- > > > dwmw2 > > > > > > ______________________________________________________ > > > Linux MTD discussion mailing list > > > http://lists.infradead.org/mailman/listinfo/linux-mtd/ > > > > the flash intel TE28F320B3BA110 (same of the BSE-IPengine) isn't CFI > > compliant. Is a JEDEC Flash. > > You have to modify the MTD source code to detect the flash. > > If you are interested, i have this code, and if you need, i send to you. > > Else, see the cfi_cmdset002.c, cfi_probe.c, cfi_jedec.c > > (/drivers/mtd/chips) and physmap.c (/drivers/mtd/maps). > > My code give a solution to implementing JFFS file system and Partitioning > > Support. > > > > > > Daniel Belz > > belz@inf.pucrs.br > > > > > > ______________________________________________________ > Linux MTD discussion mailing list > http://lists.infradead.org/mailman/listinfo/linux-mtd/ i'm using the hhl20 journeyman from montavista (www.mvsita.com). (Kernel 2.4.2) with a recent (last month) MTD snapshot! the modified code is under (//by belz) tags or (//belz //endbelz) tags. also see the flash datasheet and the .config file attached for more information about configuration. atually, i'm do making a documentation about the modifications (where, what, why, what work and what not, ...). when done, a send all to MTD. this provide a full support to bse-ipengine (www.brightstareng.com), including flash partitioning. Daniel Belz belz@inf.pucrs.br [-- Attachment #2: cfi_cmdset_0002.c --] [-- Type: text/plain, Size: 24655 bytes --] /* * Common Flash Interface support: * AMD & Fujitsu Standard Vendor Command Set (ID 0x0002) * * Copyright (C) 2000 Crossnet Co. <info@crossnet.co.jp> * * 2_by_8 routines added by Simon Munton * * This code is GPL * * $Id: cfi_cmdset_0002.c,v 1.49 2001/07/14 00:59:16 thockin Exp $ * */ #include <linux/module.h> #include <linux/types.h> #include <linux/kernel.h> #include <linux/sched.h> #include <asm/io.h> #include <asm/byteorder.h> #include <linux/errno.h> #include <linux/slab.h> #include <linux/delay.h> #include <linux/interrupt.h> #include <linux/mtd/map.h> #include <linux/mtd/cfi.h> #define AMD_BOOTLOC_BUG static int cfi_amdstd_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *); static int cfi_amdstd_write(struct mtd_info *, loff_t, size_t, size_t *, const u_char *); static int cfi_amdstd_erase_onesize(struct mtd_info *, struct erase_info *); static int cfi_amdstd_erase_varsize(struct mtd_info *, struct erase_info *); static void cfi_amdstd_sync (struct mtd_info *); static int cfi_amdstd_suspend (struct mtd_info *); static void cfi_amdstd_resume (struct mtd_info *); static void cfi_amdstd_destroy(struct mtd_info *); void cfi_cmdset_0002(struct map_info *, int, unsigned long); static struct mtd_info *cfi_amdstd_setup (struct map_info *); static struct mtd_chip_driver cfi_amdstd_chipdrv = { probe: cfi_amdstd_setup, destroy: cfi_amdstd_destroy, name: "cfi_cmdset_0002", module: THIS_MODULE }; void cfi_cmdset_0002(struct map_info *map, int primary, unsigned long base) { struct cfi_private *cfi = map->fldrv_priv; unsigned char bootloc; int ofs_factor = cfi->interleave * cfi->device_type; int i; __u8 major, minor; // struct cfi_pri_intelext *extp; if (cfi->cfi_mode==0){ __u16 adr = primary?cfi->cfiq->P_ADR:cfi->cfiq->A_ADR; cfi_send_gen_cmd(0x98, 0x55, 0, map, cfi, cfi->device_type, NULL); major = cfi_read_query(map, (adr+3)*ofs_factor); minor = cfi_read_query(map, (adr+4)*ofs_factor); printk(" Amd/Fujitsu Extended Query Table v%c.%c at 0x%4.4X\n", major, minor, adr); cfi_send_gen_cmd(0xf0, 0x55, 0, map, cfi, cfi->device_type, NULL); cfi_send_gen_cmd(0xaa, 0x555, base, map, cfi, cfi->device_type, NULL); cfi_send_gen_cmd(0x55, 0x2aa, base, map, cfi, cfi->device_type, NULL); cfi_send_gen_cmd(0x90, 0x555, base, map, cfi, cfi->device_type, NULL); cfi->mfr = cfi_read_query(map, base); cfi->id = cfi_read_query(map, base + ofs_factor); /* Wheee. Bring me the head of someone at AMD. */ #ifdef AMD_BOOTLOC_BUG if (((major << 8) | minor) < 0x3131) { /* CFI version 1.0 => don't trust bootloc */ if (cfi->id & 0x80) { printk(KERN_WARNING "%s: JEDEC Device ID is 0x%02X. Assuming broken CFI table.\n", map->name, cfi->id); bootloc = 3; /* top boot */ } else { bootloc = 2; /* bottom boot */ } } else #endif { cfi_send_gen_cmd(0x98, 0x55, 0, map, cfi, cfi->device_type, NULL); bootloc = cfi_read_query(map, (adr+15)*ofs_factor); } if (bootloc == 3 && cfi->cfiq->NumEraseRegions > 1) { printk(KERN_WARNING "%s: Swapping erase regions for broken CFI table.\n", map->name); for (i=0; i<cfi->cfiq->NumEraseRegions / 2; i++) { int j = (cfi->cfiq->NumEraseRegions-1)-i; __u32 swap; swap = cfi->cfiq->EraseRegionInfo[i]; cfi->cfiq->EraseRegionInfo[i] = cfi->cfiq->EraseRegionInfo[j]; cfi->cfiq->EraseRegionInfo[j] = swap; } } } //JEDEC so pega daqui em diante -- belz /* If there was an old setup function, decrease its use count */ if (map->fldrv) if(map->fldrv->module) __MOD_DEC_USE_COUNT(map->fldrv->module); if (cfi->cmdset_priv) kfree(cfi->cmdset_priv); for (i=0; i< cfi->numchips; i++) { cfi->chips[i].word_write_time = 1<<cfi->cfiq->WordWriteTimeoutTyp; cfi->chips[i].buffer_write_time = 1<<cfi->cfiq->BufWriteTimeoutTyp; cfi->chips[i].erase_time = 1<<cfi->cfiq->BlockEraseTimeoutTyp; } map->fldrv = &cfi_amdstd_chipdrv; MOD_INC_USE_COUNT; cfi_send_gen_cmd(0xf0, 0x55, 0, map, cfi, cfi->device_type, NULL); return; } static struct mtd_info *cfi_amdstd_setup(struct map_info *map) { struct cfi_private *cfi = map->fldrv_priv; struct mtd_info *mtd; unsigned long devsize = (1<<cfi->cfiq->DevSize) * cfi->interleave; mtd = kmalloc(sizeof(*mtd), GFP_KERNEL); printk("number of %s chips: %d\n", (cfi->cfi_mode)?"JEDEC":"CFI",cfi->numchips); if (!mtd) { printk("Failed to allocate memory for MTD device\n"); kfree(cfi->cmdset_priv); return NULL; } memset(mtd, 0, sizeof(*mtd)); mtd->priv = map; mtd->type = MTD_NORFLASH; /* Also select the correct geometry setup too */ mtd->size = devsize * cfi->numchips; if (cfi->cfiq->NumEraseRegions == 1) { /* No need to muck about with multiple erase sizes */ mtd->erasesize = ((cfi->cfiq->EraseRegionInfo[0] >> 8) & ~0xff) * cfi->interleave; } else { unsigned long offset = 0; int i,j; mtd->numeraseregions = cfi->cfiq->NumEraseRegions * cfi->numchips; mtd->eraseregions = kmalloc(sizeof(struct mtd_erase_region_info) * mtd->numeraseregions, GFP_KERNEL); if (!mtd->eraseregions) { printk("Failed to allocate memory for MTD erase region info\n"); kfree(cfi->cmdset_priv); return NULL; } for (i=0; i<cfi->cfiq->NumEraseRegions; i++) { unsigned long ernum, ersize; ersize = ((cfi->cfiq->EraseRegionInfo[i] >> 8) & ~0xff) * cfi->interleave; ernum = (cfi->cfiq->EraseRegionInfo[i] & 0xffff) + 1; if (mtd->erasesize < ersize) { mtd->erasesize = ersize; } for (j=0; j<cfi->numchips; j++) { mtd->eraseregions[(j*cfi->cfiq->NumEraseRegions)+i].offset = (j*devsize)+offset; mtd->eraseregions[(j*cfi->cfiq->NumEraseRegions)+i].erasesize = ersize; mtd->eraseregions[(j*cfi->cfiq->NumEraseRegions)+i].numblocks = ernum; } offset += (ersize * ernum); } if (offset != devsize) { /* Argh */ printk("Sum of regions (%lx) != total size of set of interleaved chips (%lx)\n", offset, devsize); kfree(mtd->eraseregions); kfree(cfi->cmdset_priv); return NULL; } // debug for (i=0; i<mtd->numeraseregions;i++){ printk("%d: offset=0x%x,size=0x%x,blocks=%d\n", i,mtd->eraseregions[i].offset, mtd->eraseregions[i].erasesize, mtd->eraseregions[i].numblocks); } } switch (CFIDEV_BUSWIDTH) { case 1: case 2: case 4: //#if 1 if (mtd->numeraseregions > 1) mtd->erase = cfi_amdstd_erase_varsize; else //#endif mtd->erase = cfi_amdstd_erase_onesize; mtd->read = cfi_amdstd_read; mtd->write = cfi_amdstd_write; break; default: printk("Unsupported buswidth\n"); kfree(mtd); kfree(cfi->cmdset_priv); return NULL; break; } mtd->sync = cfi_amdstd_sync; mtd->suspend = cfi_amdstd_suspend; mtd->resume = cfi_amdstd_resume; mtd->flags = MTD_CAP_NORFLASH; map->fldrv = &cfi_amdstd_chipdrv; mtd->name = map->name; MOD_INC_USE_COUNT; return mtd; } static inline int do_read_onechip(struct map_info *map, struct flchip *chip, loff_t adr, size_t len, u_char *buf) { DECLARE_WAITQUEUE(wait, current); unsigned long timeo = jiffies + HZ; struct cfi_private *cfi = map->fldrv_priv; retry: cfi_spin_lock(chip->mutex); if (chip->state != FL_READY){ printk("Waiting for chip to read, status = %d\n", chip->state); set_current_state(TASK_UNINTERRUPTIBLE); add_wait_queue(&chip->wq, &wait); cfi_spin_unlock(chip->mutex); schedule(); remove_wait_queue(&chip->wq, &wait); #if 0 if(signal_pending(current)) return -EINTR; #endif timeo = jiffies + HZ; goto retry; } adr += chip->start; chip->state = FL_READY; cfi_write(map, CMD(0xFF), adr); //belz map->copy_from(map, buf, adr, len); wake_up(&chip->wq); cfi_spin_unlock(chip->mutex); return 0; } static int cfi_amdstd_read (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf) { struct map_info *map = mtd->priv; struct cfi_private *cfi = map->fldrv_priv; unsigned long ofs; int chipnum; int ret = 0; /* ofs: offset within the first chip that the first read should start */ chipnum = (from >> cfi->chipshift); ofs = from - (chipnum << cfi->chipshift); *retlen = 0; while (len) { unsigned long thislen; if (chipnum >= cfi->numchips) break; if ((len + ofs -1) >> cfi->chipshift) thislen = (1<<cfi->chipshift) - ofs; else thislen = len; ret = do_read_onechip(map, &cfi->chips[chipnum], ofs, thislen, buf); if (ret) break; *retlen += thislen; len -= thislen; buf += thislen; ofs = 0; chipnum++; } return ret; } static int do_write_oneword(struct map_info *map, struct flchip *chip, unsigned long adr, __u32 datum, int fast) { unsigned long timeo = jiffies + HZ; //unsigned int Last[4]; //com belz //unsigned long Count = 0; //com belz struct cfi_private *cfi = map->fldrv_priv; DECLARE_WAITQUEUE(wait, current); int ret = 0; __u32 status, status_OK; //belz status_OK = CMD(0x80); retry: cfi_spin_lock(chip->mutex); if (chip->state != FL_READY){ printk("Waiting for chip to write, status = %d\n", chip->state); set_current_state(TASK_UNINTERRUPTIBLE); add_wait_queue(&chip->wq, &wait); cfi_spin_unlock(chip->mutex); schedule(); remove_wait_queue(&chip->wq, &wait); printk("Wake up to write:\n"); #if 0 if(signal_pending(current)) return -EINTR; #endif timeo = jiffies + HZ; goto retry; } chip->state = FL_WRITING; adr += chip->start; ENABLE_VPP(map); if (fast) { // Unlock bypass cfi_send_gen_cmd(0xA0, 0, chip->start, map, cfi, cfi->device_type, NULL); } else { cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi, CFI_DEVICETYPE_X8, NULL); cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chip->start, map, cfi, CFI_DEVICETYPE_X8, NULL); cfi_send_gen_cmd(0xA0, cfi->addr_unlock1, chip->start, map, cfi, CFI_DEVICETYPE_X8, NULL); } //cfi_write(map, CMD(0x50), adr); //belz cfi_write(map, CMD(0x40), adr); //belz cfi_write(map, datum, adr); cfi_spin_unlock(chip->mutex); cfi_udelay(chip->word_write_time); cfi_spin_lock(chip->mutex); //belz inicio while ( ( (status = cfi_read(map,adr)) & status_OK ) != status_OK ) { static int z=0; /* OK Still waiting */ if (time_after(jiffies, timeo)) { chip->state = FL_READY; cfi_spin_unlock(chip->mutex); printk("waiting for writing to complete timed out."); DISABLE_VPP(map); return -EIO; } /* Latency issues. Drop the lock, wait a while and retry */ cfi_spin_unlock(chip->mutex); z++; if ( 0 && !(z % 100 )) printk("chip not ready yet after write. looping\n"); cfi_udelay(1); cfi_spin_lock(chip->mutex); continue; } //belz fim /* Last[0] = cfi_read(map, adr); printk("Last[0] is %x\n", Last[0]); Last[1] = cfi_read(map, adr); printk("Last[1] is %x\n", Last[1]); Last[2] = cfi_read(map, adr); printk("Last[2] is %x\n", Last[2]); for (Count = 3; Last[(Count - 1) % 4] != Last[(Count - 2) % 4] && Count < 10000; Count++){ cfi_spin_unlock(chip->mutex); cfi_udelay(10); cfi_spin_lock(chip->mutex); Last[Count % 4] = cfi_read(map, adr); // printk("Last[%d%%4] is %x\n", Count, Last[Count%4]); } if (Last[(Count - 1) % 4] != datum){ printk("Last[%ld] is %x, datum is %x\n",(Count - 1) % 4,Last[(Count - 1) % 4],datum); cfi_send_gen_cmd(0xF0, 0, chip->start, map, cfi, cfi->device_type, NULL); DISABLE_VPP(map); ret = -EIO; } */ DISABLE_VPP(map); chip->state = FL_READY; wake_up(&chip->wq); cfi_spin_unlock(chip->mutex); return ret; } static int cfi_amdstd_write (struct mtd_info *mtd, loff_t to , size_t len, size_t *retlen, const u_char *buf) { struct map_info *map = mtd->priv; struct cfi_private *cfi = map->fldrv_priv; int ret = 0; int chipnum; unsigned long ofs, chipstart; *retlen = 0; if (!len) return 0; chipnum = to >> cfi->chipshift; ofs = to - (chipnum << cfi->chipshift); chipstart = cfi->chips[chipnum].start; /* If it's not bus-aligned, do the first byte write */ if (ofs & (CFIDEV_BUSWIDTH-1)) { unsigned long bus_ofs = ofs & ~(CFIDEV_BUSWIDTH-1); int i = ofs - bus_ofs; int n = 0; u_char tmp_buf[4]; __u32 datum; map->copy_from(map, tmp_buf, bus_ofs + cfi->chips[chipnum].start, CFIDEV_BUSWIDTH); while (len && i < CFIDEV_BUSWIDTH) tmp_buf[i++] = buf[n++], len--; if (cfi_buswidth_is_2()) { datum = *(__u16*)tmp_buf; } else if (cfi_buswidth_is_4()) { datum = *(__u32*)tmp_buf; } else { return -EINVAL; /* should never happen, but be safe */ } ret = do_write_oneword(map, &cfi->chips[chipnum], bus_ofs, datum, 0); if (ret) return ret; ofs += n; buf += n; (*retlen) += n; if (ofs >> cfi->chipshift) { chipnum ++; ofs = 0; if (chipnum == cfi->numchips) return 0; } } /* Go into unlock bypass mode */ cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chipstart, map, cfi, CFI_DEVICETYPE_X8, NULL); cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chipstart, map, cfi, CFI_DEVICETYPE_X8, NULL); cfi_send_gen_cmd(0x20, cfi->addr_unlock1, chipstart, map, cfi, CFI_DEVICETYPE_X8, NULL); //cfi_write(map, CMD(0x40), 0); //belz /* We are now aligned, write as much as possible */ while(len >= CFIDEV_BUSWIDTH) { __u32 datum; if (cfi_buswidth_is_1()) { datum = *(__u8*)buf; } else if (cfi_buswidth_is_2()) { datum = *(__u16*)buf; } else if (cfi_buswidth_is_4()) { datum = *(__u32*)buf; } else { return -EINVAL; } ret = do_write_oneword(map, &cfi->chips[chipnum], ofs, datum, cfi->fast_prog); if (ret) { if (cfi->fast_prog){ /* Get out of unlock bypass mode */ cfi_send_gen_cmd(0x90, 0, chipstart, map, cfi, cfi->device_type, NULL); cfi_send_gen_cmd(0x00, 0, chipstart, map, cfi, cfi->device_type, NULL); } return ret; } ofs += CFIDEV_BUSWIDTH; buf += CFIDEV_BUSWIDTH; (*retlen) += CFIDEV_BUSWIDTH; len -= CFIDEV_BUSWIDTH; if (ofs >> cfi->chipshift) { if (cfi->fast_prog){ /* Get out of unlock bypass mode */ cfi_send_gen_cmd(0x90, 0, chipstart, map, cfi, cfi->device_type, NULL); cfi_send_gen_cmd(0x00, 0, chipstart, map, cfi, cfi->device_type, NULL); } chipnum ++; ofs = 0; if (chipnum == cfi->numchips) return 0; chipstart = cfi->chips[chipnum].start; if (cfi->fast_prog){ /* Go into unlock bypass mode for next set of chips */ cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chipstart, map, cfi, CFI_DEVICETYPE_X8, NULL); cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chipstart, map, cfi, CFI_DEVICETYPE_X8, NULL); cfi_send_gen_cmd(0x20, cfi->addr_unlock1, chipstart, map, cfi, CFI_DEVICETYPE_X8, NULL); } } } if (cfi->fast_prog){ /* Get out of unlock bypass mode */ cfi_send_gen_cmd(0x90, 0, chipstart, map, cfi, cfi->device_type, NULL); cfi_send_gen_cmd(0x00, 0, chipstart, map, cfi, cfi->device_type, NULL); } if (len & (CFIDEV_BUSWIDTH-1)) { int i = 0, n = 0; u_char tmp_buf[4]; __u32 datum; map->copy_from(map, tmp_buf, ofs + cfi->chips[chipnum].start, CFIDEV_BUSWIDTH); while (len--) tmp_buf[i++] = buf[n++]; if (cfi_buswidth_is_2()) { datum = *(__u16*)tmp_buf; } else if (cfi_buswidth_is_4()) { datum = *(__u32*)tmp_buf; } else { return -EINVAL; /* should never happen, but be safe */ } ret = do_write_oneword(map, &cfi->chips[chipnum], ofs, datum, 0); if (ret) return ret; (*retlen) += n; } return 0; } static inline int do_erase_oneblock(struct map_info *map, struct flchip *chip, unsigned long adr) { unsigned int status; unsigned long timeo = jiffies + HZ; struct cfi_private *cfi = map->fldrv_priv; unsigned int rdy_mask; DECLARE_WAITQUEUE(wait, current); retry: cfi_spin_lock(chip->mutex); if (chip->state != FL_READY){ set_current_state(TASK_UNINTERRUPTIBLE); add_wait_queue(&chip->wq, &wait); cfi_spin_unlock(chip->mutex); schedule(); remove_wait_queue(&chip->wq, &wait); #if 0 if(signal_pending(current)) return -EINTR; #endif timeo = jiffies + HZ; goto retry; } chip->state = FL_ERASING; adr += chip->start; ENABLE_VPP(map); cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi, CFI_DEVICETYPE_X8, NULL); cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chip->start, map, cfi, CFI_DEVICETYPE_X8, NULL); cfi_send_gen_cmd(0x80, cfi->addr_unlock1, chip->start, map, cfi, CFI_DEVICETYPE_X8, NULL); cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi, CFI_DEVICETYPE_X8, NULL); cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chip->start, map, cfi, CFI_DEVICETYPE_X8, NULL); //cfi_write(map, CMD(0x20), adr); timeo = jiffies + (HZ*20); cfi_spin_unlock(chip->mutex); schedule_timeout(HZ); cfi_spin_lock(chip->mutex); rdy_mask = CMD(0x80); cfi_write(map, CMD(0x50), adr);//<----foi inserido e com cfi_write(map, CMD(0x20), adr);//<----foi inserido cfi_write(map, CMD(0xD0), adr);//<----foi inserido /* FIXME. Use a timer to check this, and return immediately. */ /* Once the state machine's known to be working I'll do that */ while ( ( (status = cfi_read(map,adr)) & rdy_mask ) != rdy_mask ) { static int z=0; if (chip->state != FL_ERASING) { /* Someone's suspended the erase. Sleep */ set_current_state(TASK_UNINTERRUPTIBLE); add_wait_queue(&chip->wq, &wait); cfi_spin_unlock(chip->mutex); printk("erase suspended. Sleeping\n"); schedule(); remove_wait_queue(&chip->wq, &wait); #if 0 if (signal_pending(current)) return -EINTR; #endif timeo = jiffies + (HZ*2); /* FIXME */ cfi_spin_lock(chip->mutex); continue; } /* OK Still waiting */ if (time_after(jiffies, timeo)) { chip->state = FL_READY; cfi_spin_unlock(chip->mutex); printk("--->(status:%X, cfi_read:%X) waiting for erase to complete timed out.",chip->state,cfi_read(map, adr)); DISABLE_VPP(map); return -EIO; } /* Latency issues. Drop the lock, wait a while and retry */ cfi_spin_unlock(chip->mutex); z++; if ( 0 && !(z % 100 )) printk("chip not ready yet after erase. looping\n"); cfi_udelay(1); cfi_spin_lock(chip->mutex); continue; } /* Done and happy. */ DISABLE_VPP(map); chip->state = FL_READY; wake_up(&chip->wq); cfi_spin_unlock(chip->mutex); return 0; } static int cfi_amdstd_erase_varsize(struct mtd_info *mtd, struct erase_info *instr) { struct map_info *map = mtd->priv; struct cfi_private *cfi = map->fldrv_priv; unsigned long adr, len; int chipnum, ret = 0; int i, first; struct mtd_erase_region_info *regions = mtd->eraseregions; if (instr->addr > mtd->size) return -EINVAL; if ((instr->len + instr->addr) > mtd->size) return -EINVAL; /* Check that both start and end of the requested erase are * aligned with the erasesize at the appropriate addresses. */ i = 0; /* Skip all erase regions which are ended before the start of the requested erase. Actually, to save on the calculations, we skip to the first erase region which starts after the start of the requested erase, and then go back one. */ while (i < mtd->numeraseregions && instr->addr >= regions[i].offset) i++; i--; /* OK, now i is pointing at the erase region in which this erase request starts. Check the start of the requested erase range is aligned with the erase size which is in effect here. */ if (instr->addr & (regions[i].erasesize-1)) return -EINVAL; /* Remember the erase region we start on */ first = i; /* Next, check that the end of the requested erase is aligned * with the erase region at that address. */ while (i<mtd->numeraseregions && (instr->addr + instr->len) >= regions[i].offset) i++; /* As before, drop back one to point at the region in which the address actually falls */ i--; if ((instr->addr + instr->len) & (regions[i].erasesize-1)) return -EINVAL; chipnum = instr->addr >> cfi->chipshift; adr = instr->addr - (chipnum << cfi->chipshift); len = instr->len; i=first; while(len) { ret = do_erase_oneblock(map, &cfi->chips[chipnum], adr); if (ret) return ret; adr += regions[i].erasesize; len -= regions[i].erasesize; if (adr % (1<< cfi->chipshift) == ((regions[i].offset + (regions[i].erasesize * regions[i].numblocks)) %( 1<< cfi->chipshift))) i++; if (adr >> cfi->chipshift) { adr = 0; chipnum++; if (chipnum >= cfi->numchips) break; } } instr->state = MTD_ERASE_DONE; if (instr->callback) instr->callback(instr); return 0; } static int cfi_amdstd_erase_onesize(struct mtd_info *mtd, struct erase_info *instr) { struct map_info *map = mtd->priv; struct cfi_private *cfi = map->fldrv_priv; unsigned long adr, len; int chipnum, ret = 0; if (instr->addr & (mtd->erasesize - 1)) return -EINVAL; if (instr->len & (mtd->erasesize -1)) return -EINVAL; if ((instr->len + instr->addr) > mtd->size) return -EINVAL; chipnum = instr->addr >> cfi->chipshift; adr = instr->addr - (chipnum << cfi->chipshift); len = instr->len; while(len) { ret = do_erase_oneblock(map, &cfi->chips[chipnum], adr); if (ret) return ret; adr += mtd->erasesize; len -= mtd->erasesize; if (adr >> cfi->chipshift) { adr = 0; chipnum++; if (chipnum >= cfi->numchips) break; } } instr->state = MTD_ERASE_DONE; if (instr->callback) instr->callback(instr); return 0; } static void cfi_amdstd_sync (struct mtd_info *mtd) { struct map_info *map = mtd->priv; struct cfi_private *cfi = map->fldrv_priv; int i; struct flchip *chip; int ret = 0; DECLARE_WAITQUEUE(wait, current); for (i=0; !ret && i<cfi->numchips; i++) { chip = &cfi->chips[i]; retry: cfi_spin_lock(chip->mutex); switch(chip->state) { case FL_READY: case FL_STATUS: case FL_CFI_QUERY: case FL_JEDEC_QUERY: chip->oldstate = chip->state; chip->state = FL_SYNCING; /* No need to wake_up() on this state change - * as the whole point is that nobody can do anything * with the chip now anyway. */ case FL_SYNCING: cfi_spin_unlock(chip->mutex); break; default: /* Not an idle state */ add_wait_queue(&chip->wq, &wait); cfi_spin_unlock(chip->mutex); schedule(); remove_wait_queue(&chip->wq, &wait); goto retry; } } /* Unlock the chips again */ for (i--; i >=0; i--) { chip = &cfi->chips[i]; cfi_spin_lock(chip->mutex); if (chip->state == FL_SYNCING) { chip->state = chip->oldstate; wake_up(&chip->wq); } cfi_spin_unlock(chip->mutex); } } static int cfi_amdstd_suspend(struct mtd_info *mtd) { struct map_info *map = mtd->priv; struct cfi_private *cfi = map->fldrv_priv; int i; struct flchip *chip; int ret = 0; //printk("suspend\n"); for (i=0; !ret && i<cfi->numchips; i++) { chip = &cfi->chips[i]; cfi_spin_lock(chip->mutex); switch(chip->state) { case FL_READY: case FL_STATUS: case FL_CFI_QUERY: case FL_JEDEC_QUERY: chip->oldstate = chip->state; chip->state = FL_PM_SUSPENDED; /* No need to wake_up() on this state change - * as the whole point is that nobody can do anything * with the chip now anyway. */ case FL_PM_SUSPENDED: break; default: ret = -EAGAIN; break; } cfi_spin_unlock(chip->mutex); } /* Unlock the chips again */ if (ret) { for (i--; i >=0; i--) { chip = &cfi->chips[i]; cfi_spin_lock(chip->mutex); if (chip->state == FL_PM_SUSPENDED) { chip->state = chip->oldstate; wake_up(&chip->wq); } cfi_spin_unlock(chip->mutex); } } return ret; } static void cfi_amdstd_resume(struct mtd_info *mtd) { struct map_info *map = mtd->priv; struct cfi_private *cfi = map->fldrv_priv; int i; struct flchip *chip; //printk("resume\n"); for (i=0; i<cfi->numchips; i++) { chip = &cfi->chips[i]; cfi_spin_lock(chip->mutex); if (chip->state == FL_PM_SUSPENDED) { chip->state = FL_READY; cfi_write(map, CMD(0xF0), chip->start); wake_up(&chip->wq); } else printk("Argh. Chip not in PM_SUSPENDED state upon resume()\n"); cfi_spin_unlock(chip->mutex); } } static void cfi_amdstd_destroy(struct mtd_info *mtd) { struct map_info *map = mtd->priv; struct cfi_private *cfi = map->fldrv_priv; kfree(cfi->cmdset_priv); kfree(cfi); } #if LINUX_VERSION_CODE < 0x20212 && defined(MODULE) #define cfi_amdstd_init init_module #define cfi_amdstd_exit cleanup_module #endif static char im_name[]="cfi_cmdset_0002"; mod_init_t cfi_amdstd_init(void) { inter_module_register(im_name, THIS_MODULE, &cfi_cmdset_0002); return 0; } mod_exit_t cfi_amdstd_exit(void) { inter_module_unregister(im_name); } module_init(cfi_amdstd_init); module_exit(cfi_amdstd_exit); [-- Attachment #3: cfi_jedec.c --] [-- Type: text/plain, Size: 7068 bytes --] /* $Id: cfi_jedec.c,v 1.6 2001/07/14 00:59:17 thockin Exp $ */ #include <linux/config.h> #include <linux/module.h> #include <linux/types.h> #include <linux/kernel.h> #include <asm/io.h> #include <asm/byteorder.h> #include <linux/errno.h> #include <linux/slab.h> #include <linux/interrupt.h> #include <linux/mtd/map.h> #include <linux/mtd/cfi.h> /* Manufacturers */ #define MANUFACTURER_AMD 0x0001 #define MANUFACTURER_FUJITSU 0x0004 #define MANUFACTURER_ATMEL 0x001f #define MANUFACTURER_ST 0x0020 #define MANUFACTURER_SST 0x00BF #define MANUFACTURER_TOSHIBA 0x0098 #define MANUFACTURER_INTEL 0x0089 //by belz /*INTEL*/ //by belz #define TE28F320B3 0x8897 /* AMD */ #define AM29F800BB 0x2258 #define AM29F800BT 0x22D6 #define AM29LV800BB 0x225B #define AM29LV800BT 0x22DA #define AM29LV160DT 0x22C4 #define AM29LV160DB 0x2249 /* Atmel */ #define AT49BV16X4 0x00c0 #define AT49BV16X4T 0x00c2 /* Fujitsu */ #define MBM29LV160TE 0x22C4 #define MBM29LV160BE 0x2249 /* ST - www.st.com */ #define M29W800T 0x00D7 #define M29W160DT 0x22C4 #define M29W160DB 0x2249 /* SST */ #define SST39LF800 0x2781 #define SST39LF160 0x2782 /* Toshiba */ #define TC58FVT160 0x00C2 #define TC58FVB160 0x0043 struct amd_flash_info { const __u16 mfr_id; const __u16 dev_id; const char *name; const int DevSize; const int InterfaceDesc; const int NumEraseRegions; const ulong regions[4]; }; #define ERASEINFO(size,blocks) (size<<8)|(blocks-1) #define SIZE_1MiB 20 #define SIZE_2MiB 21 #define SIZE_4MiB 22 static const struct amd_flash_info jedec_table[] = { { //by belz mfr_id: MANUFACTURER_INTEL, dev_id: TE28F320B3, name: "INTEL TE28F320B3", DevSize: SIZE_4MiB, NumEraseRegions: 1, regions: {//ERASEINFO(0x02000,8), ERASEINFO(0x10000,64) } }, { mfr_id: MANUFACTURER_AMD, dev_id: AM29LV160DT, name: "AMD AM29LV160DT", DevSize: SIZE_2MiB, NumEraseRegions: 4, regions: {ERASEINFO(0x10000,31), ERASEINFO(0x08000,1), ERASEINFO(0x02000,2), ERASEINFO(0x04000,1) } }, { mfr_id: MANUFACTURER_AMD, dev_id: AM29LV160DB, name: "AMD AM29LV160DB", DevSize: SIZE_2MiB, NumEraseRegions: 4, regions: {ERASEINFO(0x04000,1), ERASEINFO(0x02000,2), ERASEINFO(0x08000,1), ERASEINFO(0x10000,31) } }, { mfr_id: MANUFACTURER_TOSHIBA, dev_id: TC58FVT160, name: "Toshiba TC58FVT160", DevSize: SIZE_2MiB, NumEraseRegions: 4, regions: {ERASEINFO(0x10000,31), ERASEINFO(0x08000,1), ERASEINFO(0x02000,2), ERASEINFO(0x04000,1) } }, { mfr_id: MANUFACTURER_FUJITSU, dev_id: MBM29LV160TE, name: "Fujitsu MBM29LV160TE", DevSize: SIZE_2MiB, NumEraseRegions: 4, regions: {ERASEINFO(0x10000,31), ERASEINFO(0x08000,1), ERASEINFO(0x02000,2), ERASEINFO(0x04000,1) } }, { mfr_id: MANUFACTURER_TOSHIBA, dev_id: TC58FVB160, name: "Toshiba TC58FVB160", DevSize: SIZE_2MiB, NumEraseRegions: 4, regions: {ERASEINFO(0x04000,1), ERASEINFO(0x02000,2), ERASEINFO(0x08000,1), ERASEINFO(0x10000,31) } }, { mfr_id: MANUFACTURER_FUJITSU, dev_id: MBM29LV160BE, name: "Fujitsu MBM29LV160BE", DevSize: SIZE_2MiB, NumEraseRegions: 4, regions: {ERASEINFO(0x04000,1), ERASEINFO(0x02000,2), ERASEINFO(0x08000,1), ERASEINFO(0x10000,31) } }, { mfr_id: MANUFACTURER_AMD, dev_id: AM29LV800BB, name: "AMD AM29LV800BB", DevSize: SIZE_1MiB, NumEraseRegions: 4, regions: {ERASEINFO(0x04000,1), ERASEINFO(0x02000,2), ERASEINFO(0x08000,1), ERASEINFO(0x10000,15), } }, { mfr_id: MANUFACTURER_AMD, dev_id: AM29F800BB, name: "AMD AM29F800BB", DevSize: SIZE_1MiB, NumEraseRegions: 4, regions: {ERASEINFO(0x04000,1), ERASEINFO(0x02000,2), ERASEINFO(0x08000,1), ERASEINFO(0x10000,15), } }, { mfr_id: MANUFACTURER_AMD, dev_id: AM29LV800BT, name: "AMD AM29LV800BT", DevSize: SIZE_1MiB, NumEraseRegions: 4, regions: {ERASEINFO(0x10000,15), ERASEINFO(0x08000,1), ERASEINFO(0x02000,2), ERASEINFO(0x04000,1) } }, { mfr_id: MANUFACTURER_AMD, dev_id: AM29F800BT, name: "AMD AM29F800BT", DevSize: SIZE_1MiB, NumEraseRegions: 4, regions: {ERASEINFO(0x10000,15), ERASEINFO(0x08000,1), ERASEINFO(0x02000,2), ERASEINFO(0x04000,1) } }, { mfr_id: MANUFACTURER_AMD, dev_id: AM29LV800BB, name: "AMD AM29LV800BB", DevSize: SIZE_1MiB, NumEraseRegions: 4, regions: {ERASEINFO(0x10000,15), ERASEINFO(0x08000,1), ERASEINFO(0x02000,2), ERASEINFO(0x04000,1) } }, { mfr_id: MANUFACTURER_ST, dev_id: M29W800T, name: "ST M29W800T", DevSize: SIZE_1MiB, NumEraseRegions: 4, regions: {ERASEINFO(0x10000,15), ERASEINFO(0x08000,1), ERASEINFO(0x02000,2), ERASEINFO(0x04000,1) } }, { mfr_id: MANUFACTURER_ST, dev_id: M29W160DT, name: "ST M29W160DT", DevSize: SIZE_2MiB, NumEraseRegions: 4, regions: {ERASEINFO(0x10000,31), ERASEINFO(0x08000,1), ERASEINFO(0x02000,2), ERASEINFO(0x04000,1) } }, { mfr_id: MANUFACTURER_ST, dev_id: M29W160DB, name: "ST M29W160DB", DevSize: SIZE_2MiB, NumEraseRegions: 4, regions: {ERASEINFO(0x04000,1), ERASEINFO(0x02000,2), ERASEINFO(0x08000,1), ERASEINFO(0x10000,31) } }, { mfr_id: MANUFACTURER_ATMEL, dev_id: AT49BV16X4, name: "Atmel AT49BV16X4", DevSize: SIZE_2MiB, NumEraseRegions: 3, regions: {ERASEINFO(0x02000,8), ERASEINFO(0x08000,2), ERASEINFO(0x10000,30) } }, { mfr_id: MANUFACTURER_ATMEL, dev_id: AT49BV16X4T, name: "Atmel AT49BV16X4T", DevSize: SIZE_2MiB, NumEraseRegions: 3, regions: {ERASEINFO(0x10000,30), ERASEINFO(0x08000,2), ERASEINFO(0x02000,8) } }, { 0 } }; int cfi_jedec_lookup(int index, int mfr_id, int dev_id) { if (index>=0){ if (jedec_table[index].mfr_id == mfr_id && jedec_table[index].dev_id == dev_id) return index; } else{ for (index=0; jedec_table[index].mfr_id; index++){ if (jedec_table[index].mfr_id == mfr_id && jedec_table[index].dev_id == dev_id) return index; } } return -1; } int cfi_jedec_setup(struct cfi_private *p_cfi, int index) { int i,num_erase_regions; printk("Found: %s\n",jedec_table[index].name); num_erase_regions = jedec_table[index].NumEraseRegions; p_cfi->cfiq = kmalloc(sizeof(struct cfi_ident) + num_erase_regions * 4, GFP_KERNEL); if (!p_cfi->cfiq) { //xx printk(KERN_WARNING "%s: kmalloc failed for CFI ident structure\n", map->name); return -1; } memset(p_cfi->cfiq,0,sizeof(struct cfi_ident)); p_cfi->cfiq->P_ID = P_ID_AMD_STD; //if (jedec_table[index].mfr_id==MANUFACTURER_INTEL) p_cfi->cfiq->P_ID = P_ID_INTEL_STD; //by belz p_cfi->cfiq->NumEraseRegions = jedec_table[index].NumEraseRegions; p_cfi->cfiq->DevSize = jedec_table[index].DevSize; for (i=0; i<num_erase_regions; i++){ p_cfi->cfiq->EraseRegionInfo[i] = jedec_table[index].regions[i]; } return 0; /* ok */ } [-- Attachment #4: cfi_probe.c --] [-- Type: text/plain, Size: 19521 bytes --] /* Common Flash Interface probe code. (C) 2000 Red Hat. GPL'd. $Id: cfi_probe.c,v 1.61 2001/07/14 00:59:17 thockin Exp $ */ #include <linux/config.h> #include <linux/module.h> #include <linux/types.h> #include <linux/kernel.h> #include <asm/io.h> #include <asm/byteorder.h> #include <linux/errno.h> #include <linux/slab.h> #include <linux/interrupt.h> #include <linux/mtd/map.h> #include <linux/mtd/cfi.h> //#define DEBUG_CFI #ifdef DEBUG_CFI static void print_cfi_ident(struct cfi_ident *); #endif int cfi_jedec_setup(struct cfi_private *p_cfi, int index); int cfi_jedec_lookup(int index, int mfr_id, int dev_id); static void check_cmd_set(struct map_info *, int, unsigned long); static struct cfi_private *cfi_cfi_probe(struct map_info *); struct mtd_info *cfi_probe(struct map_info *map); static struct mtd_chip_driver cfi_chipdrv = { probe: cfi_probe, name: "cfi_probe", module: THIS_MODULE }; struct mtd_info *cfi_probe(struct map_info *map) { struct mtd_info *mtd = NULL; struct cfi_private *cfi; /* First probe the map to see if we have CFI stuff there. */ cfi = cfi_cfi_probe(map); if (!cfi) return NULL; map->fldrv_priv = cfi; /* OK we liked it. Now find a driver for the command set it talks */ check_cmd_set(map, 1, cfi->chips[0].start); /* First the primary cmdset */ if (!map->fldrv) check_cmd_set(map, 0, cfi->chips[0].start); /* Then the secondary */ /* check_cmd_set() will have used inter_module_get to increase the use count of the module which provides the command set driver. If we're quitting, we have to decrease it again. */ if(map->fldrv) { mtd = map->fldrv->probe(map); /* Undo the use count we held onto from inter_module_get */ #ifdef MODULE if(map->fldrv->module) __MOD_DEC_USE_COUNT(map->fldrv->module); #endif if (mtd) return mtd; } printk(KERN_WARNING"cfi_probe: No supported Vendor Command Set found\n"); kfree(cfi->cfiq); kfree(cfi); map->fldrv_priv = NULL; return NULL; } static __u32 cfi_send_cmd(u_char cmd, __u32 base, struct map_info *map, struct cfi_private *cfi) { return cfi_send_gen_cmd(cmd, 0x55, base, map, cfi, cfi->device_type, NULL); } /* check for QRY, or search for jedec id. in: interleave,type,mode ret: table index, <0 for error */ static int cfi_check_qry_or_id(struct map_info *map, __u32 base, int index, struct cfi_private *cfi) { __u32 manufacturer_id, device_id; int osf = cfi->interleave * cfi->device_type; // scale factor //printk("cfi_check_qry_or_id: base=0x%08lx interl=%d type=%d index=%d\n",base,cfi->interleave,cfi->device_type,index); switch(cfi->cfi_mode){ case 0: if (cfi_read(map,base+osf*0x10)==cfi_build_cmd('Q',map,cfi) && //<------------ estas tres linhas devem ser inseridas cfi_read(map,base+osf*0x11)==cfi_build_cmd('R',map,cfi) && cfi_read(map,base+osf*0x12)==cfi_build_cmd('Y',map,cfi)) return 0; // ok ! break; case 1: manufacturer_id = cfi_read(map,base+0*osf); device_id = cfi_read(map,base+1*osf); //printk("--> cfi_check_qry_or_id: man=0x%lx,id=0x%lx\n",manufacturer_id, device_id); return cfi_jedec_lookup(index,manufacturer_id,device_id); } return -1; // nothing found } static void cfi_qry_mode(struct map_info *map, __u32 base, struct cfi_private *cfi) { switch(cfi->cfi_mode){ case 0: /* Query */ cfi_send_cmd(0x98, base, map, cfi); break; case 1: /* Autoselect */ cfi_send_gen_cmd(0xaa, cfi->addr_unlock1, base, map, cfi, CFI_DEVICETYPE_X8, NULL); cfi_send_gen_cmd(0x55, cfi->addr_unlock2, base, map, cfi, CFI_DEVICETYPE_X8, NULL); cfi_send_gen_cmd(0x90, cfi->addr_unlock1, base, map, cfi, CFI_DEVICETYPE_X8, NULL); break; } } static int cfi_probe_chip_1(struct map_info *map, __u32 base, struct flchip *chips, struct cfi_private *cfi) { int index; __u32 tmp,ofs; ofs = cfi_send_gen_cmd(0xF0, 0, base, map, cfi, cfi->device_type, &tmp); cfi_qry_mode(map,base,cfi); index=cfi_check_qry_or_id(map,base,-1,cfi); if (index<0) return -1; if (chips){ int i; for (i=0; i<cfi->numchips; i++){ /* This chip should be in read mode if it's one we've already touched. */ if (cfi_check_qry_or_id(map,chips[i].start,index,cfi) >= 0){ cfi_send_gen_cmd(0xF0, 0, chips[i].start, map, cfi, cfi->device_type, NULL); if (cfi_check_qry_or_id(map,chips[i].start,index,cfi) >= 0){ /* Yes it's got QRY for data. Most unfortunate. Stick the old one in read mode too. */ cfi_send_gen_cmd(0xF0, 0, base, map, cfi, cfi->device_type, NULL); if (cfi_check_qry_or_id(map,base,index,cfi) >= 0){ /* OK, so has the new one. Assume it's an alias */ printk(KERN_DEBUG "%s: Found an alias at 0x%x for the chip at 0x%lx\n", map->name, base, chips[i].start); return -1; } } else { /* * FIXME: Is this supposed to work? * The third argument is already * multiplied as this within the * function definition. (Nicolas Pitre) */ cfi_send_gen_cmd(0xF0, 0, base+0xaa*cfi->interleave * cfi->device_type, map, cfi, cfi->device_type, NULL); cfi_send_gen_cmd(0xF0, 0, chips[i].start+0xaa*cfi->interleave * cfi->device_type, map, cfi, cfi->device_type, NULL); return -1; } } } /* for i */ /* OK, if we got to here, then none of the previous chips appear to be aliases for the current one. */ if (cfi->numchips == MAX_CFI_CHIPS) { printk(KERN_WARNING"%s: Too many flash chips detected. Increase MAX_CFI_CHIPS from %d.\n", map->name, MAX_CFI_CHIPS); /* Doesn't matter about resetting it to Read Mode - we're not going to talk to it anyway */ return -1; } chips[cfi->numchips].start = base; chips[cfi->numchips].state = FL_READY; chips[cfi->numchips].mutex = &chips[cfi->numchips]._spinlock; cfi->numchips++; /* Put it back into Read Mode */ cfi_send_gen_cmd(0xF0, 0, base, map, cfi, cfi->device_type, NULL); } printk(KERN_INFO "%s: Found %d x%d devices at 0x%x in %d-bit mode\n", map->name, cfi->interleave, cfi->device_type*8, base, map->buswidth*8); return index; } /* put dev into qry mode, and try cfi and jedec modes for the given type/interleave */ static int cfi_probe_chip(struct map_info *map, __u32 base, struct flchip *chips, struct cfi_private *cfi) { int index; cfi->cfi_mode=0; /* cfi mode */ switch (cfi->device_type) { case CFI_DEVICETYPE_X8: cfi->addr_unlock1 = 0x555; cfi->addr_unlock2 = 0x2aa; break; case CFI_DEVICETYPE_X16: cfi->addr_unlock1 = 0xaaa; if (map->buswidth == cfi->interleave) { /* X16 chip(s) in X8 mode */ cfi->addr_unlock2 = 0x555; } else { cfi->addr_unlock2 = 0x554; } break; case CFI_DEVICETYPE_X32: cfi->addr_unlock1 = 0x1555; cfi->addr_unlock2 = 0xaaa; break; default: return 0; } index = cfi_probe_chip_1(map,base,chips,cfi); if (index>=0) return index; cfi->cfi_mode=1; /* jedec mode */ index = cfi_probe_chip_1(map,base,chips,cfi); if (index>=0) return index; cfi->addr_unlock1 = 0x5555; cfi->addr_unlock2 = 0x2aaa; index = cfi_probe_chip_1(map,base,chips,cfi); return index; } /* * Since probeing for CFI chips requires writing to the device problems may * occur if the flash is not present and RAM is accessed instead. For now we * assume that the flash is present so we don't check for RAM or replace * possibly overwritten data. */ static int cfi_probe_new_chip(struct map_info *map, unsigned long base, struct flchip *chips, struct cfi_private *cfi) { int index; switch (map->buswidth) { #ifdef CFIDEV_BUSWIDTH_1 case CFIDEV_BUSWIDTH_1: cfi->interleave = CFIDEV_INTERLEAVE_1; cfi->device_type = CFI_DEVICETYPE_X8; index = cfi_probe_chip(map,base,chips,cfi); if (index>=0) return index; cfi->device_type = CFI_DEVICETYPE_X16; index = cfi_probe_chip(map,base,chips,cfi); if (index>=0) return index; break; #endif #ifdef CFIDEV_BUSWIDTH_2 case CFIDEV_BUSWIDTH_2: #ifdef CFIDEV_INTERLEAVE_1 cfi->interleave = CFIDEV_INTERLEAVE_1; cfi->device_type = CFI_DEVICETYPE_X16; index = cfi_probe_chip(map,base,chips,cfi); if (index>=0) return index; #endif #ifdef CFIDEV_INTERLEAVE_2 cfi->interleave = CFIDEV_INTERLEAVE_2; cfi->device_type = CFI_DEVICETYPE_X8; index = cfi_probe_chip(map,base,chips,cfi); if (index>=0) return index; cfi->device_type = CFI_DEVICETYPE_X16; index = cfi_probe_chip(map,base,chips,cfi); if (index>=0) return index; #endif break; #endif #ifdef CFIDEV_BUSWIDTH_4 case CFIDEV_BUSWIDTH_4: #ifdef CFIDEV_INTERLEAVE_4 cfi->interleave = CFIDEV_INTERLEAVE_4; cfi->device_type = CFI_DEVICETYPE_X16; index = cfi_probe_chip(map,base,chips,cfi); if (index>=0) return index; cfi->device_type = CFI_DEVICETYPE_X32; index = cfi_probe_chip(map,base,chips,cfi); if (index>=0) return index; cfi->device_type = CFI_DEVICETYPE_X8; index = cfi_probe_chip(map,base,chips,cfi); if (index>=0) return index; #endif #ifdef CFIDEV_INTERLEAVE_2 cfi->interleave = CFIDEV_INTERLEAVE_2; cfi->device_type = CFI_DEVICETYPE_X16; index = cfi_probe_chip(map,base,chips,cfi); if (index>=0) return index; #endif #ifdef CFIDEV_INTERLEAVE_1 cfi->interleave = CFIDEV_INTERLEAVE_1; cfi->device_type = CFI_DEVICETYPE_X32; index = cfi_probe_chip(map,base,chips,cfi); if (index>=0) return index; #endif break; #endif default: printk(KERN_WARNING "cfi_probe called with unsupported buswidth %d\n", map->buswidth); return -1; } // switch return -1; } static struct cfi_private *cfi_cfi_probe(struct map_info *map) { unsigned long base=0; struct cfi_private cfi; struct cfi_private *retcfi; struct flchip chip[MAX_CFI_CHIPS]; int i,index; char num_erase_regions; int ofs_factor; memset(&cfi, 0, sizeof(cfi)); /* The first invocation (with chips == NULL) leaves the device in Query Mode */ index = cfi_probe_new_chip(map, 0, NULL, &cfi); if (index<0) { printk(KERN_WARNING"%s: Found no CFI device at location zero\n", map->name); /* Doesn't appear to be CFI-compliant at all */ return NULL; } /* Read the Basic Query Structure from the device */ ofs_factor = cfi.interleave*cfi.device_type; /* First, work out the amount of space to allocate */ if (cfi.cfi_mode==0){ num_erase_regions = cfi_read_query(map, base + (0x10 + 28)*ofs_factor); //#ifdef DEBUG_CFI printk("Number of erase regions: %d\n", num_erase_regions); //#endif cfi.cfiq = kmalloc(sizeof(struct cfi_ident) + num_erase_regions * 4, GFP_KERNEL); if (!cfi.cfiq) { printk(KERN_WARNING "%s: kmalloc failed for CFI ident structure\n", map->name); return NULL; } memset(cfi.cfiq,0,sizeof(struct cfi_ident)); cfi.fast_prog=1; /* CFI supports fast programming */ /* CFI flash */ for (i=0; i<(sizeof(struct cfi_ident) + num_erase_regions * 4); i++) { ((unsigned char *)cfi.cfiq)[i] = cfi_read_query(map,base + (0x10 + i)*ofs_factor); } /* Do any necessary byteswapping */ cfi.cfiq->P_ID = le16_to_cpu(cfi.cfiq->P_ID); cfi.cfiq->P_ADR = le16_to_cpu(cfi.cfiq->P_ADR); cfi.cfiq->A_ID = le16_to_cpu(cfi.cfiq->A_ID); cfi.cfiq->A_ADR = le16_to_cpu(cfi.cfiq->A_ADR); cfi.cfiq->InterfaceDesc = le16_to_cpu(cfi.cfiq->InterfaceDesc); cfi.cfiq->MaxBufWriteSize = le16_to_cpu(cfi.cfiq->MaxBufWriteSize); for (i=0; i<cfi.cfiq->NumEraseRegions; i++) { cfi.cfiq->EraseRegionInfo[i] = le32_to_cpu(cfi.cfiq->EraseRegionInfo[i]); //#ifdef DEBUG_CFI printk(" Erase Region #%d: BlockSize 0x%4.4X bytes, %d blocks\n", i, (cfi.cfiq->EraseRegionInfo[i] >> 8) & ~0xff, (cfi.cfiq->EraseRegionInfo[i] & 0xffff) + 1); //#endif } } else{ /* JEDEC flash */ if (cfi_jedec_setup(&cfi,index)<0){ printk(KERN_WARNING "cfi_jedec_setup failed\n"); return NULL; } } if (cfi.cfiq->NumEraseRegions == 0) { printk(KERN_WARNING "Number of erase regions is zero\n"); kfree(cfi.cfiq); return NULL; } #ifdef DEBUG_CFI /* Dump the information therein */ print_cfi_ident(cfi.cfiq); #endif cfi_send_cmd(0xFF, base, map, &cfi); /* OK. We've worked out what it is and we're happy with it. Now see if there are others */ chip[0].start = 0; chip[0].state = FL_READY; chip[0].mutex = &chip[0]._spinlock; cfi.chipshift = cfi.cfiq->DevSize; cfi.numchips = 1; if (!cfi.chipshift) { printk(KERN_ERR"cfi.chipsize is zero. This is bad. cfi.cfiq->DevSize is %d\n", cfi.cfiq->DevSize); kfree(cfi.cfiq); return NULL; } switch (cfi.interleave) { case 2: cfi.chipshift += 1; break; case 4: cfi.chipshift += 2; break; } for (base = (1<<cfi.chipshift); base < map->size; base += (1<<cfi.chipshift)) cfi_probe_chip_1(map, base, &chip[0], &cfi); retcfi = kmalloc(sizeof(struct cfi_private) + cfi.numchips * sizeof(struct flchip), GFP_KERNEL); if (!retcfi) { printk(KERN_WARNING "%s: kmalloc failed for CFI private structure\n", map->name); kfree(cfi.cfiq); return NULL; } memcpy(retcfi, &cfi, sizeof(cfi)); memcpy(&retcfi->chips[0], chip, sizeof(struct flchip) * cfi.numchips); for (i=0; i< retcfi->numchips; i++) { init_waitqueue_head(&retcfi->chips[i].wq); spin_lock_init(&retcfi->chips[i]._spinlock); retcfi->chips[i].mutex = &retcfi->chips[i]._spinlock; } return retcfi; } #ifdef DEBUG_CFI static char *vendorname(__u16 vendor) { switch (vendor) { case P_ID_NONE: return "None"; case P_ID_INTEL_EXT: return "Intel/Sharp Extended"; case P_ID_AMD_STD: return "AMD/Fujitsu Standard"; case P_ID_INTEL_STD: return "Intel/Sharp Standard"; case P_ID_AMD_EXT: return "AMD/Fujitsu Extended"; case P_ID_MITSUBISHI_STD: return "Mitsubishi Standard"; case P_ID_MITSUBISHI_EXT: return "Mitsubishi Extended"; case P_ID_RESERVED: return "Not Allowed / Reserved for Future Use"; default: return "Unknown"; } } static void print_cfi_ident(struct cfi_ident *cfip) { #if 0 if (cfip->qry[0] != 'Q' || cfip->qry[1] != 'R' || cfip->qry[2] != 'Y') { printk("Invalid CFI ident structure.\n"); return; } #endif printk("Primary Vendor Command Set: %4.4X (%s)\n", cfip->P_ID, vendorname(cfip->P_ID)); if (cfip->P_ADR) printk("Primary Algorithm Table at %4.4X\n", cfip->P_ADR); else printk("No Primary Algorithm Table\n"); printk("Alternative Vendor Command Set: %4.4X (%s)\n", cfip->A_ID, vendorname(cfip->A_ID)); if (cfip->A_ADR) printk("Alternate Algorithm Table at %4.4X\n", cfip->A_ADR); else printk("No Alternate Algorithm Table\n"); printk("Vcc Minimum: %x.%x V\n", cfip->VccMin >> 4, cfip->VccMin & 0xf); printk("Vcc Maximum: %x.%x V\n", cfip->VccMax >> 4, cfip->VccMax & 0xf); if (cfip->VppMin) { printk("Vpp Minimum: %x.%x V\n", cfip->VppMin >> 4, cfip->VppMin & 0xf); printk("Vpp Maximum: %x.%x V\n", cfip->VppMax >> 4, cfip->VppMax & 0xf); } else printk("No Vpp line\n"); printk("Typical byte/word write timeout: %d µs\n", 1<<cfip->WordWriteTimeoutTyp); printk("Maximum byte/word write timeout: %d µs\n", (1<<cfip->WordWriteTimeoutMax) * (1<<cfip->WordWriteTimeoutTyp)); if (cfip->BufWriteTimeoutTyp || cfip->BufWriteTimeoutMax) { printk("Typical full buffer write timeout: %d µs\n", 1<<cfip->BufWriteTimeoutTyp); printk("Maximum full buffer write timeout: %d µs\n", (1<<cfip->BufWriteTimeoutMax) * (1<<cfip->BufWriteTimeoutTyp)); } else printk("Full buffer write not supported\n"); printk("Typical block erase timeout: %d µs\n", 1<<cfip->BlockEraseTimeoutTyp); printk("Maximum block erase timeout: %d µs\n", (1<<cfip->BlockEraseTimeoutMax) * (1<<cfip->BlockEraseTimeoutTyp)); if (cfip->ChipEraseTimeoutTyp || cfip->ChipEraseTimeoutMax) { printk("Typical chip erase timeout: %d µs\n", 1<<cfip->ChipEraseTimeoutTyp); printk("Maximum chip erase timeout: %d µs\n", (1<<cfip->ChipEraseTimeoutMax) * (1<<cfip->ChipEraseTimeoutTyp)); } else printk("Chip erase not supported\n"); printk("Device size: 0x%X bytes (%d MiB)\n", 1 << cfip->DevSize, 1<< (cfip->DevSize - 20)); printk("Flash Device Interface description: 0x%4.4X\n", cfip->InterfaceDesc); switch(cfip->InterfaceDesc) { case 0: printk(" - x8-only asynchronous interface\n"); break; case 1: printk(" - x16-only asynchronous interface\n"); break; case 2: printk(" - supports x8 and x16 via BYTE# with asynchronous interface\n"); break; case 3: printk(" - x32-only asynchronous interface\n"); break; case 65535: printk(" - Not Allowed / Reserved\n"); break; default: printk(" - Unknown\n"); break; } printk("Max. bytes in buffer write: 0x%x\n", 1<< cfip->MaxBufWriteSize); printk("Number of Erase Block Regions: %d\n", cfip->NumEraseRegions); } #endif /* DEBUG_CFI */ typedef void cfi_cmdset_fn_t(struct map_info *, int, unsigned long); extern cfi_cmdset_fn_t cfi_cmdset_0001; extern cfi_cmdset_fn_t cfi_cmdset_0002; static void cfi_cmdset_unknown(struct map_info *map, int primary, unsigned long base) { __u16 adr; struct cfi_private *cfi = map->fldrv_priv; __u16 type = primary?cfi->cfiq->P_ID:cfi->cfiq->A_ID; #ifdef HAVE_INTER_MODULE char probename[32]; cfi_cmdset_fn_t *probe_function; sprintf(probename, "cfi_cmdset_%4.4X", type); probe_function = inter_module_get_request(probename, probename); if (probe_function) { (*probe_function)(map, primary, base); return; } #endif printk(KERN_NOTICE "Support for command set %04X not present\n", type); /* This was a command set we don't know about. Print only the basic info */ adr = primary?cfi->cfiq->P_ADR:cfi->cfiq->A_ADR; if (!adr) { printk(" No Extended Query Table\n"); } else { int ofs_factor = cfi->interleave * cfi->device_type; if (cfi_read_query(map,base + adr*ofs_factor) != (primary?'P':'A') || cfi_read_query(map,base + (adr+1)*ofs_factor) != (primary?'R':'L') || cfi_read_query(map,base + (adr+2)*ofs_factor) != (primary?'I':'T')) { printk ("Invalid Extended Query Table at %4.4X: %2.2X %2.2X %2.2X\n", adr, cfi_read_query(map,base + adr*ofs_factor), cfi_read_query(map,base + (adr+1)*ofs_factor), cfi_read_query(map,base + (adr+2)*ofs_factor)); } else { printk(" Extended Query Table version %c.%c\n", cfi_read_query(map,base + (adr+3)*ofs_factor), cfi_read_query(map,base + (adr+4)*ofs_factor)); } } cfi_send_cmd(0xff, base, map, cfi); } static void check_cmd_set(struct map_info *map, int primary, unsigned long base) { struct cfi_private *cfi = map->fldrv_priv; __u16 type = primary?cfi->cfiq->P_ID:cfi->cfiq->A_ID; if (type == P_ID_NONE || type == P_ID_RESERVED) return; /* Put it in query mode */ cfi_qry_mode(map,base,cfi); switch(type){ /* Urgh. Ifdefs. The version with weak symbols was * _much_ nicer. Shame it didn't seem to work on * anything but x86, really. * But we can't rely in inter_module_get() because * that'd mean we depend on link order. */ #ifdef CONFIG_MTD_CFI_INTELEXT case 0x0001: case 0x0003: return cfi_cmdset_0001(map, primary, base); #endif #ifdef CONFIG_MTD_CFI_AMDSTD case 0x0002: return cfi_cmdset_0002(map, primary, base); #endif } return cfi_cmdset_unknown(map, primary, base); } #if LINUX_VERSION_CODE < 0x20212 && defined(MODULE) #define cfi_probe_init init_module #define cfi_probe_exit cleanup_module #endif mod_init_t cfi_probe_init(void) { register_mtd_chip_driver(&cfi_chipdrv); return 0; } mod_exit_t cfi_probe_exit(void) { unregister_mtd_chip_driver(&cfi_chipdrv); } module_init(cfi_probe_init); module_exit(cfi_probe_exit); [-- Attachment #5: physmap.c --] [-- Type: text/plain, Size: 3717 bytes --] /* * $Id: physmap.c,v 1.14 2001/07/14 00:59:17 thockin Exp $ * * Normal mappings of chips in physical memory */ #include <linux/module.h> #include <linux/types.h> #include <linux/kernel.h> #include <asm/io.h> #include <linux/mtd/mtd.h> #include <linux/mtd/map.h> #include <linux/config.h> #include <linux/mtd/partitions.h> /*belz*/ #define WINDOW_ADDR CONFIG_MTD_PHYSMAP_START #define WINDOW_SIZE CONFIG_MTD_PHYSMAP_LEN #define BUSWIDTH CONFIG_MTD_PHYSMAP_BUSWIDTH struct mtd_part_def //belz { int nums; unsigned char *type; struct mtd_partition* mtd_part; }; static struct mtd_info *mymtd; static struct mtd_part_def part_banks; //belz __u8 physmap_read8(struct map_info *map, unsigned long ofs) { return __raw_readb(map->map_priv_1 + ofs); } __u16 physmap_read16(struct map_info *map, unsigned long ofs) { return __raw_readw(map->map_priv_1 + ofs); } __u32 physmap_read32(struct map_info *map, unsigned long ofs) { return __raw_readl(map->map_priv_1 + ofs); } void physmap_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len) { memcpy_fromio(to, map->map_priv_1 + from, len); } void physmap_write8(struct map_info *map, __u8 d, unsigned long adr) { __raw_writeb(d, map->map_priv_1 + adr); mb(); } void physmap_write16(struct map_info *map, __u16 d, unsigned long adr) { __raw_writew(d, map->map_priv_1 + adr); mb(); } void physmap_write32(struct map_info *map, __u32 d, unsigned long adr) { __raw_writel(d, map->map_priv_1 + adr); mb(); } void physmap_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len) { memcpy_toio(map->map_priv_1 + to, from, len); } struct map_info physmap_map = { name: "Physically mapped flash", size: WINDOW_SIZE, buswidth: BUSWIDTH, read8: physmap_read8, read16: physmap_read16, read32: physmap_read32, copy_from: physmap_copy_from, write8: physmap_write8, write16: physmap_write16, write32: physmap_write32, copy_to: physmap_copy_to }; //belz #ifdef CONFIG_MTD_PARTITIONS static struct mtd_partition physmap_partitions[] = { { name: "boot ro", offset: 0x00000000, size: 0x00010000, //64k mask_flags: MTD_WRITEABLE, //force ro (read-only) }, { name: "zimage ro", offset: 0x00010000, size: 0x002e0000, //3mb mask_flags: MTD_WRITEABLE, //force ro (read-only) }, { name: "jffs", offset: 0x00300000, size: 0x00070000, // 1/2 mb }, { name: "jffs backup", offset: 0x00370000, size: 0x00070000, // 1/2 mb } }; #endif //endbelz #if LINUX_VERSION_CODE < 0x20212 && defined(MODULE) #define init_physmap init_module #define cleanup_physmap cleanup_module #endif int __init init_physmap(void) { printk(KERN_NOTICE "physmap flash device: %x at %x\n", WINDOW_SIZE, WINDOW_ADDR); physmap_map.map_priv_1 = (unsigned long)ioremap(WINDOW_ADDR, WINDOW_SIZE); if (!physmap_map.map_priv_1) { printk("Failed to ioremap\n"); return -EIO; } mymtd = do_map_probe("cfi_probe", &physmap_map); if (mymtd) { mymtd->module = THIS_MODULE; //belz #ifdef CONFIG_MTD_PARTITIONS part_banks.mtd_part = physmap_partitions; part_banks.type = "Boot, Images and File System"; part_banks.nums = 4; printk("Physmap Flash: Using %s partition definition\n", part_banks.type); add_mtd_partitions(mymtd, part_banks.mtd_part, part_banks.nums); #else add_mtd_device(mymtd); #endif //endblez return 0; } iounmap((void *)physmap_map.map_priv_1); return -ENXIO; } static void __exit cleanup_physmap(void) { if (mymtd) { del_mtd_device(mymtd); map_destroy(mymtd); } if (physmap_map.map_priv_1) { iounmap((void *)physmap_map.map_priv_1); physmap_map.map_priv_1 = 0; } } module_init(init_physmap); module_exit(cleanup_physmap); [-- Attachment #6: .config --] [-- Type: text/plain, Size: 10083 bytes --] # # Automatically generated by make menuconfig: don't edit # # CONFIG_UID16 is not set # # Code maturity level options # CONFIG_EXPERIMENTAL=y # # Loadable module support # CONFIG_MODULES=y # CONFIG_MODVERSIONS is not set CONFIG_KMOD=y # # Platform support # CONFIG_PPC=y # CONFIG_6xx is not set # CONFIG_4xx is not set # CONFIG_POWER3 is not set # CONFIG_POWER4 is not set CONFIG_8xx=y CONFIG_SERIAL_CONSOLE=y # CONFIG_RPXLITE is not set # CONFIG_RPXCLASSIC is not set CONFIG_BSEIP=y # CONFIG_TQM823L is not set # CONFIG_TQM850L is not set # CONFIG_TQM855L is not set # CONFIG_TQM860L is not set # CONFIG_FPS850L is not set # CONFIG_TQM860 is not set # CONFIG_SPD823TS is not set # CONFIG_IVMS8 is not set # CONFIG_SM850 is not set # CONFIG_MBX is not set # CONFIG_FADS is not set # CONFIG_WINCEPT is not set CONFIG_NOT_COHERENT_CACHE=y # CONFIG_WORKSTATION_PPC is not set # CONFIG_SMP is not set # CONFIG_OPENFIRMWARE is not set # CONFIG_MATH_EMULATION is not set # CONFIG_RTSCHED is not set # # General setup # # CONFIG_HIGHMEM is not set # CONFIG_MOL is not set # CONFIG_ISA is not set # CONFIG_EISA is not set # CONFIG_SBUS is not set # CONFIG_MCA is not set # CONFIG_PCI_QSPAN is not set # CONFIG_PCI is not set CONFIG_NET=y CONFIG_SYSCTL=y CONFIG_SYSVIPC=y # CONFIG_BSD_PROCESS_ACCT is not set CONFIG_KCORE_ELF=y CONFIG_BINFMT_ELF=y CONFIG_KERNEL_ELF=y CONFIG_BINFMT_MISC=y # CONFIG_HOTPLUG is not set # CONFIG_PCMCIA is not set # # Parallel port support # # CONFIG_PARPORT is not set # CONFIG_PPC_RTC is not set CONFIG_CMDLINE_BOOL=y CONFIG_CMDLINE="console=ttyS0,9600 console=tty0 root=/dev/ram" # # Memory Technology Devices (MTD) # CONFIG_MTD=y # CONFIG_MTD_DEBUG is not set CONFIG_MTD_PARTITIONS=y CONFIG_MTD_REDBOOT_PARTS=y # CONFIG_MTD_BOOTLDR_PARTS is not set # CONFIG_MTD_AFS_PARTS is not set CONFIG_MTD_CHAR=y CONFIG_MTD_BLOCK=y # CONFIG_FTL is not set # CONFIG_NFTL is not set # # RAM/ROM/Flash chip drivers # CONFIG_MTD_CFI=y # CONFIG_MTD_CFI_ADV_OPTIONS is not set # CONFIG_MTD_CFI_INTELEXT is not set CONFIG_MTD_CFI_AMDSTD=y # CONFIG_MTD_AMDSTD is not set # CONFIG_MTD_SHARP is not set # CONFIG_MTD_RAM is not set # CONFIG_MTD_ROM is not set # CONFIG_MTD_ABSENT is not set CONFIG_MTD_JEDEC=y # # Mapping drivers for chip access # CONFIG_MTD_PHYSMAP=y CONFIG_MTD_PHYSMAP_START=fe000000 CONFIG_MTD_PHYSMAP_LEN=0400000 CONFIG_MTD_PHYSMAP_BUSWIDTH=2 # CONFIG_MTD_SUN_UFLASH is not set # CONFIG_MTD_NORA is not set # CONFIG_MTD_PNC2000 is not set # CONFIG_MTD_RPXLITE is not set # CONFIG_MTD_TQM8XXL is not set # CONFIG_MTD_SC520CDP is not set # CONFIG_MTD_NETSC520 is not set # CONFIG_MTD_SBC_GXX is not set # CONFIG_MTD_ELAN_104NC is not set # CONFIG_MTD_DBOX2 is not set # CONFIG_MTD_CSTM_MIPS_IXX is not set # CONFIG_MTD_CFI_FLAGADM is not set # CONFIG_MTD_SOLUTIONENGINE is not set # CONFIG_MTD_MIXMEM is not set # CONFIG_MTD_OCTAGON is not set # CONFIG_MTD_VMAX is not set # CONFIG_MTD_OCELOT is not set # CONFIG_MTD_L440GX is not set # # Self-contained MTD device drivers # # CONFIG_MTD_PMC551 is not set # CONFIG_MTD_SLRAM is not set # CONFIG_MTD_LART is not set # CONFIG_MTD_MTDRAM is not set # CONFIG_MTD_BLKMTD is not set # CONFIG_MTD_DOC1000 is not set # CONFIG_MTD_DOC2000 is not set # CONFIG_MTD_DOC2001 is not set # CONFIG_MTD_DOCPROBE is not set # # NAND Flash Device Drivers # # CONFIG_MTD_NAND is not set # # Plug and Play configuration # # CONFIG_PNP is not set # CONFIG_ISAPNP is not set # # Block devices # # CONFIG_BLK_DEV_FD is not set # CONFIG_BLK_DEV_XD is not set # CONFIG_PARIDE is not set # CONFIG_BLK_CPQ_DA is not set # CONFIG_BLK_CPQ_CISS_DA is not set # CONFIG_BLK_DEV_DAC960 is not set CONFIG_BLK_DEV_LOOP=y # CONFIG_BLK_DEV_NBD is not set CONFIG_BLK_DEV_RAM=y CONFIG_BLK_DEV_RAM_SIZE=8192 CONFIG_BLK_DEV_INITRD=y # # Multi-device support (RAID and LVM) # # CONFIG_MD is not set # CONFIG_BLK_DEV_MD is not set # CONFIG_MD_LINEAR is not set # CONFIG_MD_RAID0 is not set # CONFIG_MD_RAID1 is not set # CONFIG_MD_RAID5 is not set # CONFIG_BLK_DEV_LVM is not set # # Networking options # CONFIG_PACKET=y # CONFIG_PACKET_MMAP is not set CONFIG_NETLINK=y CONFIG_RTNETLINK=y # CONFIG_NETLINK_DEV is not set # CONFIG_NETFILTER is not set # CONFIG_FILTER is not set CONFIG_UNIX=y CONFIG_INET=y CONFIG_IP_MULTICAST=y CONFIG_IP_ADVANCED_ROUTER=y CONFIG_RTNETLINK=y CONFIG_NETLINK=y # CONFIG_IP_MULTIPLE_TABLES is not set # CONFIG_IP_ROUTE_MULTIPATH is not set # CONFIG_IP_ROUTE_TOS is not set # CONFIG_IP_ROUTE_VERBOSE is not set # CONFIG_IP_ROUTE_LARGE_TABLES is not set # CONFIG_IP_PNP is not set # CONFIG_NET_IPIP is not set # CONFIG_NET_IPGRE is not set # CONFIG_IP_MROUTE is not set # CONFIG_ARPD is not set # CONFIG_INET_ECN is not set CONFIG_SYN_COOKIES=y # CONFIG_IPV6 is not set # CONFIG_KHTTPD is not set # CONFIG_ATM is not set # CONFIG_IPX is not set # CONFIG_ATALK is not set # CONFIG_DECNET is not set # CONFIG_BRIDGE is not set # CONFIG_X25 is not set # CONFIG_LAPB is not set # CONFIG_LLC is not set # CONFIG_NET_DIVERT is not set # CONFIG_ECONET is not set # CONFIG_WAN_ROUTER is not set # CONFIG_NET_FASTROUTE is not set # CONFIG_NET_HW_FLOWCONTROL is not set # # QoS and/or fair queueing # # CONFIG_NET_SCHED is not set # # ATA/IDE/MFM/RLL support # # CONFIG_IDE is not set # CONFIG_BLK_DEV_IDE_MODES is not set # CONFIG_BLK_DEV_HD is not set # # SCSI support # # CONFIG_SCSI is not set # # Network device support # CONFIG_NETDEVICES=y # # ARCnet devices # # CONFIG_ARCNET is not set # CONFIG_DUMMY is not set # CONFIG_BONDING is not set # CONFIG_EQUALIZER is not set # CONFIG_TUN is not set # CONFIG_ETHERTAP is not set # CONFIG_NET_SB1000 is not set # # Ethernet (10 or 100Mbit) # CONFIG_NET_ETHERNET=y CONFIG_SCC_ENET=y # CONFIG_SCC1_ENET is not set CONFIG_SCC2_ENET=y # CONFIG_SCC3_ENET is not set # CONFIG_FEC_ENET is not set # CONFIG_ENET_BIG_BUFFERS is not set # CONFIG_NET_VENDOR_3COM is not set # CONFIG_LANCE is not set # CONFIG_NET_VENDOR_SMC is not set # CONFIG_NET_VENDOR_RACAL is not set # CONFIG_AT1700 is not set # CONFIG_DEPCA is not set # CONFIG_NET_ISA is not set # CONFIG_NET_PCI is not set # CONFIG_NET_POCKET is not set # # Ethernet (1000 Mbit) # # CONFIG_ACENIC is not set # CONFIG_HAMACHI is not set # CONFIG_YELLOWFIN is not set # CONFIG_SK98LIN is not set # CONFIG_FDDI is not set # CONFIG_HIPPI is not set # CONFIG_PPP is not set # CONFIG_SLIP is not set # # Wireless LAN (non-hamradio) # # CONFIG_NET_RADIO is not set # # Token Ring devices # # CONFIG_TR is not set # CONFIG_NET_FC is not set # CONFIG_RCPCI is not set # CONFIG_SHAPER is not set # # Wan interfaces # # CONFIG_WAN is not set # # Amateur Radio support # # CONFIG_HAMRADIO is not set # # IrDA (infrared) support # # CONFIG_IRDA is not set # # ISDN subsystem # # CONFIG_ISDN is not set # # Old CD-ROM drivers (not SCSI, not IDE) # # CONFIG_CD_NO_IDESCSI is not set # # Console drivers # # # Frame-buffer support # # CONFIG_FB is not set # # Input core support # # CONFIG_INPUT is not set # # Macintosh device drivers # # CONFIG_MACINTOSH_DRIVERS is not set # # Character devices # CONFIG_VT=y # CONFIG_VT_CONSOLE is not set # CONFIG_SERIAL is not set # CONFIG_SERIAL_EXTENDED is not set # CONFIG_SERIAL_NONSTANDARD is not set CONFIG_UNIX98_PTYS=y CONFIG_UNIX98_PTY_COUNT=128 # # I2C support # # CONFIG_I2C is not set # # Hardware monitors support # # CONFIG_MONITORS is not set # # Mice # # CONFIG_BUSMOUSE is not set # CONFIG_MOUSE is not set # # Joysticks # # CONFIG_JOYSTICK is not set # CONFIG_QIC02_TAPE is not set # # Watchdog Cards # # CONFIG_WATCHDOG is not set # CONFIG_INTEL_RNG is not set # CONFIG_NVRAM is not set # CONFIG_RTC is not set # CONFIG_DTLK is not set # CONFIG_R3964 is not set # CONFIG_APPLICOM is not set # # Ftape, the floppy tape device driver # # CONFIG_FTAPE is not set # CONFIG_AGP is not set # CONFIG_DRM is not set # # Multimedia devices # # CONFIG_VIDEO_DEV is not set # # File systems # # CONFIG_QUOTA is not set # CONFIG_MULTI_THREADED_CORE_FILES is not set # CONFIG_AUTOFS_FS is not set # CONFIG_AUTOFS4_FS is not set # CONFIG_REISERFS_FS is not set # CONFIG_REISERFS_CHECK is not set # CONFIG_ADFS_FS is not set # CONFIG_ADFS_FS_RW is not set # CONFIG_AFFS_FS is not set # CONFIG_HFS_FS is not set # CONFIG_BFS_FS is not set # CONFIG_FAT_FS is not set # CONFIG_MSDOS_FS is not set # CONFIG_UMSDOS_FS is not set # CONFIG_VFAT_FS is not set # CONFIG_EFS_FS is not set CONFIG_JFFS_FS=y CONFIG_JFFS_FS_VERBOSE=0 # CONFIG_JFFS2_FS is not set # CONFIG_CRAMFS is not set # CONFIG_RAMFS is not set # CONFIG_ISO9660_FS is not set # CONFIG_JOLIET is not set # CONFIG_MINIX_FS is not set # CONFIG_NTFS_FS is not set # CONFIG_NTFS_RW is not set # CONFIG_HPFS_FS is not set CONFIG_PROC_FS=y CONFIG_DEVFS_FS=y CONFIG_DEVFS_MOUNT=y CONFIG_DEVFS_DEBUG=y CONFIG_DEVPTS_FS=y # CONFIG_QNX4FS_FS is not set # CONFIG_QNX4FS_RW is not set # CONFIG_ROMFS_FS is not set CONFIG_EXT2_FS=y # CONFIG_SYSV_FS is not set # CONFIG_SYSV_FS_WRITE is not set # CONFIG_UDF_FS is not set # CONFIG_UDF_RW is not set # CONFIG_UFS_FS is not set # CONFIG_UFS_FS_WRITE is not set # # Network File Systems # # CONFIG_CODA_FS is not set CONFIG_NFS_FS=y # CONFIG_NFS_V3 is not set # CONFIG_ROOT_NFS is not set # CONFIG_NFSD is not set # CONFIG_NFSD_V3 is not set CONFIG_SUNRPC=y CONFIG_LOCKD=y # CONFIG_SMB_FS is not set # CONFIG_NCP_FS is not set # CONFIG_NCPFS_PACKET_SIGNING is not set # CONFIG_NCPFS_IOCTL_LOCKING is not set # CONFIG_NCPFS_STRONG is not set # CONFIG_NCPFS_NFS_NS is not set # CONFIG_NCPFS_OS2_NS is not set # CONFIG_NCPFS_SMALLDOS is not set # CONFIG_NCPFS_NLS is not set # CONFIG_NCPFS_EXTRAS is not set # # Partition Types # # CONFIG_PARTITION_ADVANCED is not set CONFIG_MSDOS_PARTITION=y # CONFIG_SMB_NLS is not set # CONFIG_NLS is not set # # Sound # # CONFIG_SOUND is not set # # MPC8xx CPM Options # # CONFIG_SMC2_UART is not set # CONFIG_USE_SCC_IO is not set # CONFIG_8xx_COPYBACK is not set # CONFIG_8xx_CPU6 is not set # # USB support # # CONFIG_USB is not set # # Kernel hacking # # CONFIG_MAGIC_SYSRQ is not set # CONFIG_KGDB is not set # CONFIG_XMON is not set ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Problems with Intel TE28F320 B3
@ 2001-09-04 14:02 Kremer, Alex
0 siblings, 0 replies; 6+ messages in thread
From: Kremer, Alex @ 2001-09-04 14:02 UTC (permalink / raw)
To: linux-mtd
[-- Attachment #1: Type: text/plain, Size: 2200 bytes --]
I ran into the same problem a while ago and posted a patch.
The patch is to cvs from Aug, 19. Note that it modifies
the maps/dc21285.c code and Config.in, so I'm sending separately
intel_bb.c file which adds support for 28F*B Fast Boot Block Series.
Here is a short explanation of what I found:
As opposed to Intel's 28F*J Strata Flash series the
old Fast Boot Block (28F*B) series is not CFI compliant.
I couldn't coerce it to work as a jedec, neither.
The Lart (devices/lart.c) uses a chip from this series, but the data bus has
a totally crazy mapping.
I wrote a module for this series somewhat based on the chips/amd_flash.c
code.
Since I have it mapped via dc21285 I modified maps/dc21285.c to probe using
my module ("intel_bb_probe") instead of using cfi_probe.
(I also had to modify the write16, since the code there uses, IMO, a wrong
addr. mask).
BTW: For some reason for Intel's 28F* chips the most important is the letter
that follows the size code, so the 28F128J means that it belongs to
a Strata Flash line
which is CFI comliant, while 28F128B belongs to the Fast Boot Block
Flash line, which is
really a pre-CFI, and the CFI code wont work.
The modification to maps/dc21285.c should probably try to first probe cfi,
fallback to intel_bb
and at the end try rom mapping, so at least kernel can mount root. Does
anyone have a better suggestion.
Kreso
| -----Original Message-----
| From: David Woodhouse [mailto:dwmw2@infradead.org]
| Sent: Tue, September 04, 2001 4:40 PM
| To: Norbert Leon
| Cc: linux-mtd@lists.infradead.org
| Subject: Re: Problems with Intel TE28F320 B3
|
|
|
| norbert@safetech.com said:
| > I'm working on an intel te28f320 b3ba110 (complete reference) and i
| > can't get my system to recognize it ...
|
| Some of the 28F320 chips are CFI-compliant and some aren't. The other
| letters and numbers you quoted didn't seem to help me work
| out which you
| have.
|
| Turn off CONFIG_MTD_RAM, CONFIG_MTD_ROM and CONFIG_MTD_SLRAM.
| You don't
| need them.
|
| --
| dwmw2
|
|
|
| ______________________________________________________
| Linux MTD discussion mailing list
| http://lists.infradead.org/mailman/listinfo/linux-mtd/
|
[-- Attachment #2: mtd-cvs-2001-08-19-intel_bb.patch --]
[-- Type: application/octet-stream, Size: 35342 bytes --]
diff -urN mtd-cvs-2001-08-19/drivers/mtd/chips/Config.in mtd/drivers/mtd/chips/Config.in
--- mtd-cvs-2001-08-19/drivers/mtd/chips/Config.in Sun Aug 19 08:28:51 2001
+++ mtd/drivers/mtd/chips/Config.in Sun Aug 19 18:47:32 2001
@@ -32,6 +32,7 @@
dep_tristate ' CFI support for Intel/Sharp Basic/Extended Commands' CONFIG_MTD_CFI_INTELEXT $CONFIG_MTD_CFI
dep_tristate ' CFI support for AMD/Fujitsu Standard Commands' CONFIG_MTD_CFI_AMDSTD $CONFIG_MTD_CFI
dep_tristate ' AMD compatible flash chip support (non-CFI)' CONFIG_MTD_AMDSTD $CONFIG_MTD
+dep_tristate ' Intel Fast Boot Block chip support (non-CFI)' CONFIG_MTD_INTELBB $CONFIG_MTD
dep_tristate ' pre-CFI Sharp chip support' CONFIG_MTD_SHARP $CONFIG_MTD
dep_tristate ' Support for RAM chips in bus mapping' CONFIG_MTD_RAM $CONFIG_MTD
dep_tristate ' Support for ROM chips in bus mapping' CONFIG_MTD_ROM $CONFIG_MTD
diff -urN mtd-cvs-2001-08-19/drivers/mtd/chips/Makefile mtd/drivers/mtd/chips/Makefile
--- mtd-cvs-2001-08-19/drivers/mtd/chips/Makefile Sun Aug 19 08:28:51 2001
+++ mtd/drivers/mtd/chips/Makefile Sun Aug 19 18:47:06 2001
@@ -15,6 +15,7 @@
# the CFI command set drivers are linked before cfi_probe.o
obj-$(CONFIG_MTD) += chipreg.o
+obj-$(CONFIG_MTD_INTELBB) += intel_bb.o
obj-$(CONFIG_MTD_AMDSTD) += amd_flash.o
obj-$(CONFIG_MTD_CFI) += cfi_probe.o cfi_jedec.o
obj-$(CONFIG_MTD_CFI_AMDSTD) += cfi_cmdset_0002.o
diff -urN mtd-cvs-2001-08-19/drivers/mtd/chips/intel_bb.c mtd/drivers/mtd/chips/intel_bb.c
--- mtd-cvs-2001-08-19/drivers/mtd/chips/intel_bb.c Thu Jan 1 02:00:00 1970
+++ mtd/drivers/mtd/chips/intel_bb.c Sun Aug 19 18:42:47 2001
@@ -0,0 +1,1201 @@
+/*
+ * MTD map driver for the old Intel Advanced BootBlock TE28F*B3 pre-CFI series
+ *
+ * Author: Alex Kremer <alex.kremer@intel.com>
+ *
+ * Code based on Jonas Holmberg's AMD code
+ *
+ * $Id$
+ *
+ * Copyright (c) 2001 Intel Co.
+ *
+ * This file is under GPL.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/errno.h>
+#include <linux/slab.h>
+#include <linux/delay.h>
+#include <linux/interrupt.h>
+#include <linux/mtd/map.h>
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/flashchip.h>
+
+/* There's no limit. It exists only to avoid realloc. */
+#define MAX_BB_CHIPS 4
+
+/* flash addressing type */
+#define DEVICE_ADDRTYPE_x8 (8 / 8)
+#define DEVICE_ADDRTYPE_x16 (16 / 8)
+#define DEVICE_ADDRTYPE_x32 (32 / 8)
+
+/* Addresses */
+#define ADDR_DEVICE_MFR 0x0000
+#define ADDR_DEVICE_ID 0x0001
+
+#define ADDR_DEVICE_GEN_CMD 0x0000 /* for general commands,
+ any addr would do,
+ for erase, erase-confirm
+ use any addr within the block */
+
+
+/* Commands */
+#define CMD_READ_ARRAY 0xFF /* to any address */
+#define CMD_PROGRAM_SETUP 0x40 /* followed by addr/data */
+#define CMD_ERASE_SETUP 0x20 /* to the address within the block */
+#define CMD_RESUME 0xD0
+#define CMD_ERASE_CONFIRM 0xD0 /* to the address within the block */
+#define CMD_SUSPEND 0xB0 /* suspends both program and erase ops */
+#define CMD_READ_STATUS 0x70 /* automatically after program or erase */
+#define CMD_CLEAR_STATUS 0x50
+#define CMD_READ_ID 0x90
+
+/* status register bits */
+#define SR_READY (1<<7) /* write state machine status: 1-ready 0-busy */
+#define SR_ERASE_SUSPENDED (1<<6) /* erase was suspended, can resume */
+#define SR_ERASE_FAILED (1<<5) /* erase op failed */
+#define SR_PROGRAM_FAILED (1<<4) /* program has failed */
+#define SR_VPP (1<<3) /* Vpp state */
+#define SR_PROGRAM_SUSPENDED (1<<2) /* program was suspended, can resume */
+#define SR_BLOCK_LOCKED (1<<1) /* program/erase on locked block attempted */
+#define SR_RESERVED (1<<0) /* bah! */
+
+
+
+
+/* all the in the advanced boot block series */
+#define MFR_INTEL 0x0089
+
+#define TE28F004B3_TOP 0x00D4
+#define TE28F004B3_BOTTOM 0x00D5
+
+#define TE28F400B3_TOP 0x8894
+#define TE28F400B3_BOTTOM 0x8895
+
+#define TE28F008B3_TOP 0x00D2
+#define TE28F008B3_BOTTOM 0x00D3
+
+#define TE28F016B3_TOP 0x00D0
+#define TE28F016B3_BOTTOM 0x00D1
+
+#define TE28F160B3_TOP 0x8890
+#define TE28F160B3_BOTTOM 0x8891
+
+#define TE28F320B3_TOP 0x8896
+#define TE28F320B3_BOTTOM 0x8897
+
+#define TE28F640B3_TOP 0x8898
+#define TE28F640B3_BOTTOM 0x8899
+
+
+struct bb_flash_chip_info {
+ const __u16 mfr_id;
+ const __u16 dev_id;
+ const int device_addrtype;
+ const char *name;
+ const u_long size; /* in bytes */
+
+#define MAX_ERASEREGIONS 4
+ const int numeraseregions;
+ const struct mtd_erase_region_info regions[MAX_ERASEREGIONS];
+};
+
+
+
+struct bb_flash_private {
+
+ int interleave;
+ unsigned long chipshift;
+ int device_addrtype;
+
+ int numchips;
+ struct flchip chips[0];
+};
+
+
+static int bb_flash_read(struct mtd_info *, loff_t, size_t, size_t *,
+ u_char *);
+static int bb_flash_write(struct mtd_info *, loff_t, size_t, size_t *,
+ const u_char *);
+static int bb_flash_erase(struct mtd_info *, struct erase_info *);
+static void bb_flash_sync(struct mtd_info *);
+static int bb_flash_suspend(struct mtd_info *);
+static void bb_flash_resume(struct mtd_info *);
+static void bb_flash_destroy(struct mtd_info *);
+static struct mtd_info *bb_flash_probe(struct map_info *map);
+
+
+static struct mtd_chip_driver bb_flash_chipdrv = {
+ probe: bb_flash_probe,
+ destroy: bb_flash_destroy,
+ name: "intel_bb_flash",
+ module: THIS_MODULE
+};
+
+static const char im_name[] = "bb_flash";
+
+static inline void dump_bits(__u32 w, int bn) {
+ int i;
+ for (i=0; i<bn; i++)
+ printk(" %02d=%d ", i, ((w>>i)&1));
+ printk("\n");
+}
+
+
+static inline __u32 wide_read(struct map_info *map, __u32 addr)
+{
+ if (map->buswidth == 1) {
+ return map->read8(map, addr);
+ } else if (map->buswidth == 2) {
+ return map->read16(map, addr);
+ } else if (map->buswidth == 4) {
+ return map->read32(map, addr);
+ }
+
+ return 0;
+}
+
+static inline void wide_write(struct map_info *map, __u32 val, __u32 addr)
+{
+ if (map->buswidth == 1) {
+ map->write8(map, val, addr);
+ } else if (map->buswidth == 2) {
+ map->write16(map, val, addr);
+ } else if (map->buswidth == 4) {
+ map->write32(map, val, addr);
+ }
+}
+
+static inline __u32 make_cmd(struct map_info *map, __u32 cmd)
+{
+ const struct bb_flash_private *private = map->fldrv_priv;
+ if ((private->interleave == 2) &&
+ (private->device_addrtype == DEVICE_ADDRTYPE_x16)) {
+ cmd |= (cmd << 16);
+ }
+
+ return cmd;
+}
+
+#if 0
+static inline void send_unlock(struct map_info *map, unsigned long base)
+{
+ wide_write(map, (CMD_UNLOCK_DATA_1 << 16) | CMD_UNLOCK_DATA_1,
+ base + (map->buswidth * ADDR_UNLOCK_1));
+ wide_write(map, (CMD_UNLOCK_DATA_2 << 16) | CMD_UNLOCK_DATA_2,
+ base + (map->buswidth * ADDR_UNLOCK_2));
+}
+#endif
+
+static inline void send_cmd(struct map_info *map, unsigned long base, __u32 cmd)
+{
+ //send_unlock(map, base);
+ wide_write(map, make_cmd(map, cmd), base);
+}
+
+static inline void send_cmd_to_addr(struct map_info *map, unsigned long base,
+ __u32 cmd, unsigned long addr)
+{
+ //send_unlock(map, base);
+ wide_write(map, make_cmd(map, cmd), base + addr);
+}
+
+static inline int check_SR(struct map_info *map, unsigned long base, __u32 bits)
+{
+ return (wide_read(map, base) & bits);
+}
+
+static inline int flash_is_busy(struct map_info *map, unsigned long base,
+ int interleave)
+{
+ return !check_SR(map, base, SR_READY);
+}
+
+
+/*
+ * Reads JEDEC manufacturer ID and device ID and returns the index of the first
+ * matching table = table entry (-1 if not found or alias for already found chip).
+ */
+static int probe_new_chip(struct mtd_info *mtd, __u32 base,
+ struct flchip *chips,
+ struct bb_flash_private *private,
+ struct bb_flash_chip_info *table)
+{
+ __u32 mfr_id;
+ __u32 dev_id;
+ struct map_info *map = mtd->priv;
+ struct bb_flash_private temp;
+ int i;
+
+ printk("probing a new chip at 0x%ux\n", base);
+
+ temp.interleave = 2;
+ map->fldrv_priv = &temp;
+
+ /* Enter autoselect mode. */
+ send_cmd(map, base, CMD_CLEAR_STATUS);
+ send_cmd(map, base, CMD_READ_ID);
+
+ printk("after command\n");
+
+ mfr_id = wide_read(map, base + (map->buswidth * ADDR_DEVICE_MFR));
+ dev_id = wide_read(map, base + (map->buswidth * ADDR_DEVICE_ID));
+
+ if ((map->buswidth == 4) && ((mfr_id >> 16) == (mfr_id & 0xffff)) &&
+ ((dev_id >> 16) == (dev_id & 0xffff))) {
+ mfr_id &= 0xffff;
+ dev_id &= 0xffff;
+ } else {
+ temp.interleave = 1;
+ }
+
+ printk("after determining interleave\n");
+
+
+ for (i = 0; table[i].name; i++) {
+ printk("testing chips: is it [%d] %s?\n", i, table[i].name);
+ if ((mfr_id == table[i].mfr_id) &&
+ (dev_id == table[i].dev_id)) {
+ if (private->numchips) {
+#if 0
+ int j;
+
+ /* Is this an alias for an already found chip?
+ * In that case that chip should be in
+ * autoselect mode now.
+ */
+
+ for (j = 0; j < private->numchips; j++) {
+ __u32 mfr_id_other;
+ __u32 dev_id_other;
+
+ mfr_id_other =
+ wide_read(map, private->chips[j].start +
+ (map->buswidth *
+ ADDR_DEVICE_MFR
+ ));
+ dev_id_other =
+ wide_read(map, private->chips[j].start +
+ (map->buswidth *
+ ADDR_DEVICE_ID));
+ if (temp.interleave == 2) {
+ mfr_id_other &= 0xffff;
+ dev_id_other &= 0xffff;
+ }
+ if ((mfr_id_other == mfr_id) &&
+ (dev_id_other == dev_id)) {
+
+ /* Exit autoselect mode. */
+ send_cmd(map, base,
+ CMD_READ_ARRAY);
+
+ return -1;
+ }
+ }
+#endif
+
+ if (private->numchips == MAX_BB_CHIPS) {
+ printk(KERN_WARNING
+ "%s: Too many flash chips "
+ "detected. Increase "
+ "MAX_BB_CHIPS from %d.\n",
+ map->name, MAX_BB_CHIPS);
+
+ return -1;
+ }
+
+ chips[private->numchips].start = base;
+ chips[private->numchips].state = FL_READY;
+ chips[private->numchips].mutex = &chips[private->numchips]._spinlock;
+ private->numchips++;
+ }
+
+ printk("%s: Found %d x %ldMiB %s at 0x%x -- %d chips found so far\n",
+ map->name,
+ temp.interleave, (table[i].size)/(1024*1024),
+ table[i].name, base,
+ private->numchips);
+
+ mtd->size += table[i].size * temp.interleave;
+ mtd->numeraseregions += table[i].numeraseregions;
+
+ printk("that's it\n");
+
+ break;
+ }
+ }
+
+ printk("finished scanning for chip type\n");
+
+ /* Exit autoselect mode. */
+ send_cmd(map, base, CMD_READ_ARRAY);
+
+ if (!(table[i].name)) {
+ printk(KERN_DEBUG "%s: unknown flash device at 0x%x, "
+ "mfr id 0x%x, dev id 0x%x\n", map->name,
+ base, mfr_id, dev_id);
+ map->fldrv_priv = NULL;
+
+ return -1;
+ }
+
+ printk("ok my job is finished\n");
+
+ private->device_addrtype = table[i].device_addrtype;
+ private->interleave = temp.interleave;
+
+ return i;
+}
+
+
+
+static struct mtd_info *bb_flash_probe(struct map_info *map)
+{
+ /* Keep this table on the stack so that it gets deallocated after the
+ * probe is done.
+ */
+
+
+ struct bb_flash_chip_info table[] = {
+ /* need to fill in the others */
+
+
+#define expandID(id) mfr_id: MFR_INTEL, dev_id: id, name: "Intel " #id
+#define expandADDRTYPE(t) device_addrtype: DEVICE_ADDRTYPE_ ## t
+
+
+ { expandID(TE28F320B3_TOP),
+ expandADDRTYPE(x16),
+ size: 0x0400000, /* 4MB in bytes */
+ numeraseregions: 2,
+ regions: {
+ [0] = { offset: 0x000000, erasesize: 0x10000, numblocks: 63 },
+ [1] = { offset: 0x1F8000, erasesize: 0x02000, numblocks: 8 },
+ }
+ },
+
+ { expandID(TE28F320B3_BOTTOM),
+ expandADDRTYPE(x16),
+ size: 0x0400000, /* 4MB in bytes */
+ numeraseregions: 2,
+ regions: {
+ [0] = { offset: 0x000000, erasesize: 0x02000, numblocks: 8 },
+ [1] = { offset: 0x008000, erasesize: 0x10000, numblocks: 63 },
+ }
+ },
+
+ { 0 },
+ };
+
+ struct mtd_info *mtd;
+
+ struct bb_flash_private temp;
+ struct bb_flash_private *private;
+
+ u_long size;
+ unsigned long base;
+ int i, table_pos[MAX_BB_CHIPS];
+ struct flchip chips[MAX_BB_CHIPS];
+ int reg_idx;
+ int offset;
+
+ printk("Probing flash\n");
+
+ mtd = (struct mtd_info*)kmalloc(sizeof(*mtd), GFP_KERNEL);
+ if (!mtd) {
+ printk(KERN_WARNING
+ "%s: kmalloc failed for info structure\n", map->name);
+ return NULL;
+ }
+ memset(mtd, 0, sizeof(*mtd));
+ mtd->priv = map;
+
+ memset(&temp, 0, sizeof(temp));
+ printk("%s: Probing for BB compatible flash...\n", map->name);
+
+ if ((table_pos[0] = probe_new_chip(mtd, 0, NULL, &temp, table))
+ == -1) {
+ printk(KERN_WARNING
+ "%s: Found no BB compatible device at location zero\n",
+ map->name);
+ kfree(mtd);
+
+ return NULL;
+ }
+
+ printk("one chip found at base 0\n");
+
+ chips[0].start = 0;
+ chips[0].state = FL_READY;
+ chips[0].mutex = &chips[0]._spinlock;
+ temp.numchips = 1;
+
+
+ for (size = mtd->size; size > 1; size >>= 1) {
+ temp.chipshift++;
+ }
+ switch (temp.interleave) {
+ case 2:
+ temp.chipshift += 1;
+ break;
+ case 4:
+ temp.chipshift += 2;
+ break;
+ }
+
+
+ printk("before scanning the rest of the ROM space for chips\n");
+ /* Find out if there are any more chips in the map. */
+ for (base = (1 << temp.chipshift);
+ base < map->size;
+ base += (1 << temp.chipshift)) {
+ int numchips = temp.numchips;
+ printk("scanning at %lux, numchip so far is %d\n", base, numchips);
+ table_pos[numchips] = probe_new_chip(mtd, base, chips, &temp, table);
+ }
+
+
+ printk("finished scanning\n");
+ mtd->eraseregions = kmalloc(sizeof(struct mtd_erase_region_info) *
+ mtd->numeraseregions, GFP_KERNEL);
+ if (!mtd->eraseregions) {
+ printk(KERN_WARNING "%s: Failed to allocate "
+ "memory for MTD erase region info\n", map->name);
+ kfree(mtd);
+ map->fldrv_priv = NULL;
+ return 0;
+ }
+
+ printk("updating erase regions for chips mtd->numeraseregions = %d\n", mtd->numeraseregions);
+
+ reg_idx = 0;
+ offset = 0;
+ for (i = 0; i < temp.numchips; i++) {
+ int dev_size;
+ int j;
+
+ printk("dealing with chip number %d, offset = %d\n", i, offset);
+
+ dev_size = 0;
+ for (j = 0; j < table[table_pos[i]].numeraseregions; j++) {
+ printk("reg_idx = %d, dealing with eraseregion %d of chip %d\n", reg_idx, j, i);
+
+ mtd->eraseregions[reg_idx].offset = offset +
+ (table[table_pos[i]].regions[j].offset *
+ temp.interleave);
+ mtd->eraseregions[reg_idx].erasesize =
+ table[table_pos[i]].regions[j].erasesize *
+ temp.interleave;
+ mtd->eraseregions[reg_idx].numblocks =
+ table[table_pos[i]].regions[j].numblocks;
+ if (mtd->erasesize <
+ mtd->eraseregions[reg_idx].erasesize) {
+ mtd->erasesize =
+ mtd->eraseregions[reg_idx].erasesize;
+ }
+ dev_size += mtd->eraseregions[reg_idx].erasesize *
+ mtd->eraseregions[reg_idx].numblocks;
+ reg_idx++;
+ }
+ offset += dev_size;
+ }
+
+ printk("finished with eraseregion bits\n");
+
+ mtd->type = MTD_NORFLASH;
+ mtd->flags = MTD_CAP_NORFLASH;
+ mtd->name = map->name;
+ mtd->erase = bb_flash_erase;
+ mtd->read = bb_flash_read;
+ mtd->write = bb_flash_write;
+ mtd->sync = bb_flash_sync;
+ mtd->suspend = bb_flash_suspend;
+ mtd->resume = bb_flash_resume;
+
+ private = kmalloc(sizeof(*private) + (sizeof(struct flchip) * temp.numchips), GFP_KERNEL);
+ if (!private) {
+ printk(KERN_WARNING
+ "%s: kmalloc failed for private structure\n", map->name);
+ kfree(mtd->eraseregions);
+ kfree(mtd);
+ map->fldrv_priv = NULL;
+ return NULL;
+ }
+ memcpy(private, &temp, sizeof(temp));
+ memcpy(private->chips, chips, sizeof(struct flchip) * private->numchips);
+
+ for (i = 0; i < private->numchips; i++) {
+ init_waitqueue_head(&private->chips[i].wq);
+ spin_lock_init(&private->chips[i]._spinlock);
+ }
+
+ map->fldrv_priv = private;
+
+ map->fldrv = &bb_flash_chipdrv;
+
+ MOD_INC_USE_COUNT;
+
+ printk("FLASH: found %d chips, interleave = %d,"
+ "chipshift = %lu, device_addrtype = %u\n, erasesize=%d",
+ private->numchips, private->interleave,
+ private->chipshift, private->device_addrtype*8, mtd->erasesize);
+
+
+ return mtd;
+}
+
+
+
+static inline int read_one_chip(struct map_info *map, struct flchip *chip,
+ loff_t adr, size_t len, u_char *buf)
+{
+ DECLARE_WAITQUEUE(wait, current);
+ unsigned long timeo = jiffies + HZ;
+
+ send_cmd(map, chip->start, CMD_READ_ARRAY);
+
+ retry:
+ spin_lock_bh(chip->mutex);
+
+ if (chip->state != FL_READY){
+ printk(KERN_INFO "%s: waiting for chip to read, state = %d\n",
+ map->name, chip->state);
+ set_current_state(TASK_UNINTERRUPTIBLE);
+ add_wait_queue(&chip->wq, &wait);
+
+ spin_unlock_bh(chip->mutex);
+
+ schedule();
+ remove_wait_queue(&chip->wq, &wait);
+
+ if(signal_pending(current)) {
+ return -EINTR;
+ }
+
+ timeo = jiffies + HZ;
+
+ goto retry;
+ }
+
+ adr += chip->start;
+
+ chip->state = FL_READY;
+
+ map->copy_from(map, buf, adr, len);
+
+ wake_up(&chip->wq);
+ spin_unlock_bh(chip->mutex);
+
+ return 0;
+}
+
+
+
+static int bb_flash_read(struct mtd_info *mtd, loff_t from, size_t len,
+ size_t *retlen, u_char *buf)
+{
+ struct map_info *map = mtd->priv;
+ struct bb_flash_private *private = map->fldrv_priv;
+ unsigned long ofs;
+ int chipnum;
+ int ret = 0;
+
+ if ((from + len) > mtd->size) {
+ printk(KERN_WARNING "%s: read request past end of device "
+ "(0x%lx)\n", map->name, (unsigned long)from + len);
+
+ return -EINVAL;
+ }
+
+ /* Offset within the first chip that the first read should start. */
+ chipnum = (from >> private->chipshift);
+ ofs = from - (chipnum << private->chipshift);
+
+ *retlen = 0;
+
+ while (len) {
+ unsigned long this_len;
+
+ if (chipnum >= private->numchips) {
+ break;
+ }
+
+ if ((len + ofs - 1) >> private->chipshift) {
+ this_len = (1 << private->chipshift) - ofs;
+ } else {
+ this_len = len;
+ }
+
+ ret = read_one_chip(map, &private->chips[chipnum], ofs,
+ this_len, buf);
+ if (ret) {
+ break;
+ }
+
+ *retlen += this_len;
+ len -= this_len;
+ buf += this_len;
+
+ ofs = 0;
+ chipnum++;
+ }
+
+ return ret;
+}
+
+
+
+static int write_one_word(struct map_info *map, struct flchip *chip,
+ unsigned long adr, __u32 datum)
+{
+ unsigned long timeo = jiffies + HZ;
+ struct bb_flash_private *private = map->fldrv_priv;
+ DECLARE_WAITQUEUE(wait, current);
+ int ret = 0;
+ int times_left;
+
+#if 0
+ if (((adr + chip->start ) % 1024) < 4)
+ printk("attempt to write 0x%x at 0x%lx\n", datum, adr + chip->start);
+ return 0;
+#endif
+
+ retry:
+ spin_lock_bh(chip->mutex);
+
+ if (chip->state != FL_READY){
+ printk("%s: waiting for chip to write, state = %d\n",
+ map->name, chip->state);
+ set_current_state(TASK_UNINTERRUPTIBLE);
+ add_wait_queue(&chip->wq, &wait);
+
+ spin_unlock_bh(chip->mutex);
+
+ schedule();
+ remove_wait_queue(&chip->wq, &wait);
+ printk(KERN_INFO "%s: woke up to write\n", map->name);
+ if(signal_pending(current))
+ return -EINTR;
+
+ timeo = jiffies + HZ;
+
+ goto retry;
+ }
+
+ chip->state = FL_WRITING;
+
+ adr += chip->start;
+ ENABLE_VPP(map);
+ send_cmd(map, chip->start, CMD_PROGRAM_SETUP);
+ wide_write(map, datum, adr);
+
+ times_left = 500000;
+ while (times_left-- && flash_is_busy(map, chip->start,
+ private->interleave)) {
+ if (current->need_resched) {
+ spin_unlock_bh(chip->mutex);
+ schedule();
+ spin_lock_bh(chip->mutex);
+ }
+ }
+
+ DISABLE_VPP(map);
+
+ if (!times_left) {
+ printk(KERN_WARNING "%s: write to 0x%lx timed out!\n",
+ map->name, adr);
+ ret = -EIO;
+ } else {
+#if 0
+ __u32 verify;
+
+ send_cmd(map, chip->start, CMD_READ_ARRAY);
+ if ((verify = wide_read(map, adr)) != datum) {
+ printk(KERN_WARNING "%s: write to 0x%lx failed. "
+ "datum = %x, verify = %x\n",
+ map->name, adr, datum, verify);
+ ret = -EIO;
+ } else {
+ printk("wrote %d at 0x%lx: success\n", datum, adr);
+ }
+#endif
+ }
+
+
+ chip->state = FL_READY;
+ wake_up(&chip->wq);
+ spin_unlock_bh(chip->mutex);
+
+ return ret;
+}
+
+
+
+static int bb_flash_write(struct mtd_info *mtd, loff_t to , size_t len,
+ size_t *retlen, const u_char *buf)
+{
+ struct map_info *map = mtd->priv;
+ struct bb_flash_private *private = map->fldrv_priv;
+ int ret = 0;
+ int chipnum;
+ unsigned long ofs;
+ unsigned long chipstart;
+
+ *retlen = 0;
+ if (!len) {
+ return 0;
+ }
+
+ chipnum = to >> private->chipshift;
+ ofs = to - (chipnum << private->chipshift);
+ chipstart = private->chips[chipnum].start;
+
+ /* If it's not bus-aligned, do the first byte write. */
+ if (ofs & (map->buswidth - 1)) {
+ unsigned long bus_ofs = ofs & ~(map->buswidth - 1);
+ int i = ofs - bus_ofs;
+ int n = 0;
+ u_char tmp_buf[4];
+ __u32 datum;
+
+ map->copy_from(map, tmp_buf,
+ bus_ofs + private->chips[chipnum].start,
+ map->buswidth);
+ while (len && i < map->buswidth)
+ tmp_buf[i++] = buf[n++], len--;
+
+ if (map->buswidth == 2) {
+ datum = *(__u16*)tmp_buf;
+ } else if (map->buswidth == 4) {
+ datum = *(__u32*)tmp_buf;
+ } else {
+ return -EINVAL; /* should never happen, but be safe */
+ }
+
+ ret = write_one_word(map, &private->chips[chipnum], bus_ofs,
+ datum);
+ if (ret) {
+ return ret;
+ }
+
+ ofs += n;
+ buf += n;
+ (*retlen) += n;
+
+ if (ofs >> private->chipshift) {
+ chipnum++;
+ ofs = 0;
+ if (chipnum == private->numchips) {
+ return 0;
+ }
+ }
+ }
+
+ /* We are now aligned, write as much as possible. */
+ while(len >= map->buswidth) {
+ __u32 datum;
+
+ if (map->buswidth == 1) {
+ datum = *(__u8*)buf;
+ } else if (map->buswidth == 2) {
+ datum = *(__u16*)buf;
+ } else if (map->buswidth == 4) {
+ datum = *(__u32*)buf;
+ } else {
+ return -EINVAL;
+ }
+
+ ret = write_one_word(map, &private->chips[chipnum], ofs, datum);
+
+ if (ret) {
+ return ret;
+ }
+
+ ofs += map->buswidth;
+ buf += map->buswidth;
+ (*retlen) += map->buswidth;
+ len -= map->buswidth;
+
+ if (ofs >> private->chipshift) {
+ chipnum++;
+ ofs = 0;
+ if (chipnum == private->numchips) {
+ return 0;
+ }
+ chipstart = private->chips[chipnum].start;
+ }
+ }
+
+ if (len & (map->buswidth - 1)) {
+ int i = 0, n = 0;
+ u_char tmp_buf[2];
+ __u32 datum;
+
+ map->copy_from(map, tmp_buf,
+ ofs + private->chips[chipnum].start,
+ map->buswidth);
+ while (len--) {
+ tmp_buf[i++] = buf[n++];
+ }
+
+ if (map->buswidth == 2) {
+ datum = *(__u16*)tmp_buf;
+ } else if (map->buswidth == 4) {
+ datum = *(__u32*)tmp_buf;
+ } else {
+ return -EINVAL; /* should never happen, but be safe */
+ }
+
+ ret = write_one_word(map, &private->chips[chipnum], ofs, datum);
+
+ if (ret) {
+ return ret;
+ }
+
+ (*retlen) += n;
+ }
+
+ return 0;
+}
+
+
+
+static inline int erase_one_block(struct map_info *map, struct flchip *chip,
+ unsigned long adr, u_long size)
+{
+ unsigned long timeo = jiffies + HZ;
+ struct bb_flash_private *private = map->fldrv_priv;
+ DECLARE_WAITQUEUE(wait, current);
+
+ //printk("attempt to erase block at 0x%lx (size = %ld)\n", adr + chip->start, size);
+ //return 0;
+
+ retry:
+ spin_lock_bh(chip->mutex);
+
+ if (chip->state != FL_READY){
+ set_current_state(TASK_UNINTERRUPTIBLE);
+ add_wait_queue(&chip->wq, &wait);
+
+ spin_unlock_bh(chip->mutex);
+
+ schedule();
+ remove_wait_queue(&chip->wq, &wait);
+
+ if (signal_pending(current)) {
+ return -EINTR;
+ }
+
+ timeo = jiffies + HZ;
+
+ goto retry;
+ }
+
+ chip->state = FL_ERASING;
+
+ adr += chip->start;
+ ENABLE_VPP(map);
+ send_cmd(map, chip->start, CMD_ERASE_SETUP);
+ send_cmd_to_addr(map, chip->start, CMD_ERASE_CONFIRM, adr);
+
+ timeo = jiffies + (HZ * 5);
+
+ spin_unlock_bh(chip->mutex);
+ schedule_timeout(HZ);
+ spin_lock_bh(chip->mutex);
+
+ while (flash_is_busy(map, chip->start, private->interleave)) {
+
+ if (chip->state != FL_ERASING) {
+ /* Someone's suspended the erase. Sleep */
+ set_current_state(TASK_UNINTERRUPTIBLE);
+ add_wait_queue(&chip->wq, &wait);
+
+ spin_unlock_bh(chip->mutex);
+ printk(KERN_INFO "%s: erase suspended. Sleeping\n",
+ map->name);
+ schedule();
+ remove_wait_queue(&chip->wq, &wait);
+
+ if (signal_pending(current)) {
+ return -EINTR;
+ }
+
+ timeo = jiffies + (HZ*2); /* FIXME */
+ spin_lock_bh(chip->mutex);
+ continue;
+ }
+
+ /* OK Still waiting */
+ if (time_after(jiffies, timeo)) {
+ chip->state = FL_READY;
+ spin_unlock_bh(chip->mutex);
+ printk(KERN_WARNING "%s: waiting for erase to complete "
+ "timed out.\n", map->name);
+ DISABLE_VPP(map);
+
+ return -EIO;
+ }
+
+ /* Latency issues. Drop the lock, wait a while and retry */
+ spin_unlock_bh(chip->mutex);
+
+ if (current->need_resched)
+ schedule();
+ else
+ udelay(1);
+
+ spin_lock_bh(chip->mutex);
+ }
+
+ DISABLE_VPP(map);
+
+ send_cmd(map, chip->start, CMD_READ_ARRAY);
+
+ /* Verify every single word */
+ {
+ int address;
+ int error = 0;
+ __u16 verify;
+
+ for (address = adr; address < (adr + size); address++) {
+ if ((verify = map->read16(map, address)) != 0xFFFF) {
+ error = 1;
+ break;
+ }
+ }
+ if (error) {
+ chip->state = FL_READY;
+ spin_unlock_bh(chip->mutex);
+ printk(KERN_WARNING
+ "%s: verify error at 0x%x, size %ld.\n",
+ map->name, address, size);
+ DISABLE_VPP(map);
+
+ return -EIO;
+ } else {
+ //printk("erased block at 0x%lx\n", adr);
+ }
+ }
+
+ chip->state = FL_READY;
+ wake_up(&chip->wq);
+ spin_unlock_bh(chip->mutex);
+
+ return 0;
+}
+
+
+
+static int bb_flash_erase(struct mtd_info *mtd, struct erase_info *instr)
+{
+ struct map_info *map = mtd->priv;
+ struct bb_flash_private *private = map->fldrv_priv;
+ unsigned long adr, len;
+ int chipnum;
+ int ret = 0;
+ int i;
+ int first;
+ struct mtd_erase_region_info *regions = mtd->eraseregions;
+
+ if (instr->addr > mtd->size) {
+ return -EINVAL;
+ }
+
+ if ((instr->len + instr->addr) > mtd->size) {
+ return -EINVAL;
+ }
+
+ /* Check that both start and end of the requested erase are
+ * aligned with the erasesize at the appropriate addresses.
+ */
+
+ i = 0;
+
+ /* Skip all erase regions which are ended before the start of
+ the requested erase. Actually, to save on the calculations,
+ we skip to the first erase region which starts after the
+ start of the requested erase, and then go back one.
+ */
+
+ while ((i < mtd->numeraseregions) &&
+ (instr->addr >= regions[i].offset)) {
+ i++;
+ }
+ i--;
+
+ /* OK, now i is pointing at the erase region in which this
+ * erase request starts. Check the start of the requested
+ * erase range is aligned with the erase size which is in
+ * effect here.
+ */
+
+ if (instr->addr & (regions[i].erasesize-1)) {
+ return -EINVAL;
+ }
+
+ /* Remember the erase region we start on. */
+
+ first = i;
+
+ /* Next, check that the end of the requested erase is aligned
+ * with the erase region at that address.
+ */
+
+ while ((i < mtd->numeraseregions) &&
+ ((instr->addr + instr->len) >= regions[i].offset)) {
+ i++;
+ }
+
+ /* As before, drop back one to point at the region in which
+ * the address actually falls.
+ */
+
+ i--;
+
+ if ((instr->addr + instr->len) & (regions[i].erasesize-1)) {
+ return -EINVAL;
+ }
+
+ chipnum = instr->addr >> private->chipshift;
+ adr = instr->addr - (chipnum << private->chipshift);
+ len = instr->len;
+
+ i = first;
+
+ while (len) {
+ ret = erase_one_block(map, &private->chips[chipnum], adr,
+ regions[i].erasesize);
+
+ if (ret) {
+ return ret;
+ }
+
+ adr += regions[i].erasesize;
+ len -= regions[i].erasesize;
+
+ if ((adr % (1 << private->chipshift)) ==
+ ((regions[i].offset + (regions[i].erasesize *
+ regions[i].numblocks))
+ % (1 << private->chipshift))) {
+ i++;
+ }
+
+ if (adr >> private->chipshift) {
+ adr = 0;
+ chipnum++;
+ if (chipnum >= private->numchips) {
+ break;
+ }
+ }
+ }
+
+ instr->state = MTD_ERASE_DONE;
+ if (instr->callback) {
+ instr->callback(instr);
+ }
+
+ return 0;
+}
+
+
+
+static void bb_flash_sync(struct mtd_info *mtd)
+{
+ struct map_info *map = mtd->priv;
+ struct bb_flash_private *private = map->fldrv_priv;
+ int i;
+ struct flchip *chip;
+ int ret = 0;
+ DECLARE_WAITQUEUE(wait, current);
+
+ for (i = 0; !ret && (i < private->numchips); i++) {
+ chip = &private->chips[i];
+
+ retry:
+ spin_lock_bh(chip->mutex);
+
+ switch(chip->state) {
+ case FL_READY:
+ case FL_STATUS:
+ case FL_CFI_QUERY:
+ case FL_JEDEC_QUERY:
+ chip->oldstate = chip->state;
+ chip->state = FL_SYNCING;
+ /* No need to wake_up() on this state change -
+ * as the whole point is that nobody can do anything
+ * with the chip now anyway.
+ */
+ case FL_SYNCING:
+ spin_unlock_bh(chip->mutex);
+ break;
+
+ default:
+ /* Not an idle state */
+ add_wait_queue(&chip->wq, &wait);
+
+ spin_unlock_bh(chip->mutex);
+
+ schedule();
+
+ remove_wait_queue(&chip->wq, &wait);
+
+ goto retry;
+ }
+ }
+
+ /* Unlock the chips again */
+ for (i--; i >= 0; i--) {
+ chip = &private->chips[i];
+
+ spin_lock_bh(chip->mutex);
+
+ if (chip->state == FL_SYNCING) {
+ chip->state = chip->oldstate;
+ wake_up(&chip->wq);
+ }
+ spin_unlock_bh(chip->mutex);
+ }
+}
+
+
+
+static int bb_flash_suspend(struct mtd_info *mtd)
+{
+ printk("bb_flash_suspend(): not implemented!\n");
+ return -EINVAL;
+}
+
+
+
+static void bb_flash_resume(struct mtd_info *mtd)
+{
+ printk("bb_flash_resume(): not implemented!\n");
+}
+
+
+
+static void bb_flash_destroy(struct mtd_info *mtd)
+{
+ struct map_info *map = mtd->priv;
+ struct bb_flash_private *private = map->fldrv_priv;
+ kfree(private);
+}
+
+int __init bb_flash_init(void)
+{
+ register_mtd_chip_driver(&bb_flash_chipdrv);
+ return 0;
+}
+
+void __exit bb_flash_exit(void)
+{
+ unregister_mtd_chip_driver(&bb_flash_chipdrv);
+}
+
+module_init(bb_flash_init);
+module_exit(bb_flash_exit);
diff -urN mtd-cvs-2001-08-19/drivers/mtd/maps/Config.in mtd/drivers/mtd/maps/Config.in
--- mtd-cvs-2001-08-19/drivers/mtd/maps/Config.in Sun Aug 19 08:28:51 2001
+++ mtd/drivers/mtd/maps/Config.in Sun Aug 19 18:55:23 2001
@@ -41,7 +41,7 @@
dep_tristate ' CFI Flash device mapped on ARM Integrator/P720T' CONFIG_MTD_ARM_INTEGRATOR $CONFIG_MTD_CFI $CONFIG_ARM
dep_tristate ' Cirrus CDB89712 evaluation board mappings' CONFIG_MTD_CDB89712 $CONFIG_MTD_CFI $CONFIG_ARCH_CDB89712
dep_tristate ' CFI Flash device mapped on StrongARM SA11x0' CONFIG_MTD_SA1100 $CONFIG_MTD_CFI $CONFIG_ARCH_SA1100 $CONFIG_MTD_PARTITIONS
- dep_tristate ' CFI Flash device mapped on DC21285 Footbridge' CONFIG_MTD_DC21285 $CONFIG_MTD_CFI $CONFIG_ARCH_FOOTBRIDGE $CONFIG_MTD_PARTITIONS
+ dep_tristate ' CFI Flash device mapped on DC21285 Footbridge' CONFIG_MTD_DC21285 $CONFIG_MTD_INTELBB $CONFIG_ARCH_FOOTBRIDGE $CONFIG_MTD_PARTITIONS
dep_tristate ' CFI Flash device mapped on the XScale IQ80310 board' CONFIG_MTD_IQ80310 $CONFIG_MTD_CFI $CONFIG_XSCALE_IQ80310
fi
endmenu
diff -urN mtd-cvs-2001-08-19/drivers/mtd/maps/dc21285.c mtd/drivers/mtd/maps/dc21285.c
--- mtd-cvs-2001-08-19/drivers/mtd/maps/dc21285.c Sat Jul 14 03:59:17 2001
+++ mtd/drivers/mtd/maps/dc21285.c Sun Aug 19 18:41:12 2001
@@ -52,7 +52,10 @@
void dc21285_write16(struct map_info *map, __u16 d, unsigned long adr)
{
*CSR_ROMWRITEREG = adr;
- adr &= ~1;
+ /*Original:
+ adr &= ~1;
+ */
+ adr &= ~3;
*(__u16*)(map->map_priv_1 + adr) = d;
}
@@ -137,7 +140,7 @@
return -EIO;
}
- mymtd = do_map_probe("cfi_probe", &dc21285_map);
+ mymtd = do_map_probe("intel_bb_flash", &dc21285_map);
if (mymtd) {
int nrparts;
[-- Attachment #3: intel_bb.c --]
[-- Type: application/octet-stream, Size: 30729 bytes --]
/*
* MTD map driver for the old Intel Advanced BootBlock TE28F*B3 pre-CFI series
*
* Author: Alex Kremer <alex.kremer@intel.com>
*
* Code based on Jonas Holmberg's AMD code
*
* $Id$
*
* Copyright (c) 2001 Intel Co.
*
* This file is under GPL.
*
*/
#include <linux/module.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/errno.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/mtd/map.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/flashchip.h>
/* There's no limit. It exists only to avoid realloc. */
#define MAX_BB_CHIPS 4
/* flash addressing type */
#define DEVICE_ADDRTYPE_x8 (8 / 8)
#define DEVICE_ADDRTYPE_x16 (16 / 8)
#define DEVICE_ADDRTYPE_x32 (32 / 8)
/* Addresses */
#define ADDR_DEVICE_MFR 0x0000
#define ADDR_DEVICE_ID 0x0001
#define ADDR_DEVICE_GEN_CMD 0x0000 /* for general commands,
any addr would do,
for erase, erase-confirm
use any addr within the block */
/* Commands */
#define CMD_READ_ARRAY 0xFF /* to any address */
#define CMD_PROGRAM_SETUP 0x40 /* followed by addr/data */
#define CMD_ERASE_SETUP 0x20 /* to the address within the block */
#define CMD_RESUME 0xD0
#define CMD_ERASE_CONFIRM 0xD0 /* to the address within the block */
#define CMD_SUSPEND 0xB0 /* suspends both program and erase ops */
#define CMD_READ_STATUS 0x70 /* automatically after program or erase */
#define CMD_CLEAR_STATUS 0x50
#define CMD_READ_ID 0x90
/* status register bits */
#define SR_READY (1<<7) /* write state machine status: 1-ready 0-busy */
#define SR_ERASE_SUSPENDED (1<<6) /* erase was suspended, can resume */
#define SR_ERASE_FAILED (1<<5) /* erase op failed */
#define SR_PROGRAM_FAILED (1<<4) /* program has failed */
#define SR_VPP (1<<3) /* Vpp state */
#define SR_PROGRAM_SUSPENDED (1<<2) /* program was suspended, can resume */
#define SR_BLOCK_LOCKED (1<<1) /* program/erase on locked block attempted */
#define SR_RESERVED (1<<0) /* bah! */
/* all the in the advanced boot block series */
#define MFR_INTEL 0x0089
#define TE28F004B3_TOP 0x00D4
#define TE28F004B3_BOTTOM 0x00D5
#define TE28F400B3_TOP 0x8894
#define TE28F400B3_BOTTOM 0x8895
#define TE28F008B3_TOP 0x00D2
#define TE28F008B3_BOTTOM 0x00D3
#define TE28F016B3_TOP 0x00D0
#define TE28F016B3_BOTTOM 0x00D1
#define TE28F160B3_TOP 0x8890
#define TE28F160B3_BOTTOM 0x8891
#define TE28F320B3_TOP 0x8896
#define TE28F320B3_BOTTOM 0x8897
#define TE28F640B3_TOP 0x8898
#define TE28F640B3_BOTTOM 0x8899
struct bb_flash_chip_info {
const __u16 mfr_id;
const __u16 dev_id;
const int device_addrtype;
const char *name;
const u_long size; /* in bytes */
#define MAX_ERASEREGIONS 4
const int numeraseregions;
const struct mtd_erase_region_info regions[MAX_ERASEREGIONS];
};
struct bb_flash_private {
int interleave;
unsigned long chipshift;
int device_addrtype;
int numchips;
struct flchip chips[0];
};
static int bb_flash_read(struct mtd_info *, loff_t, size_t, size_t *,
u_char *);
static int bb_flash_write(struct mtd_info *, loff_t, size_t, size_t *,
const u_char *);
static int bb_flash_erase(struct mtd_info *, struct erase_info *);
static void bb_flash_sync(struct mtd_info *);
static int bb_flash_suspend(struct mtd_info *);
static void bb_flash_resume(struct mtd_info *);
static void bb_flash_destroy(struct mtd_info *);
static struct mtd_info *bb_flash_probe(struct map_info *map);
static struct mtd_chip_driver bb_flash_chipdrv = {
probe: bb_flash_probe,
destroy: bb_flash_destroy,
name: "intel_bb_flash",
module: THIS_MODULE
};
static const char im_name[] = "bb_flash";
static inline void dump_bits(__u32 w, int bn) {
int i;
for (i=0; i<bn; i++)
printk(" %02d=%d ", i, ((w>>i)&1));
printk("\n");
}
static inline __u32 wide_read(struct map_info *map, __u32 addr)
{
if (map->buswidth == 1) {
return map->read8(map, addr);
} else if (map->buswidth == 2) {
return map->read16(map, addr);
} else if (map->buswidth == 4) {
return map->read32(map, addr);
}
return 0;
}
static inline void wide_write(struct map_info *map, __u32 val, __u32 addr)
{
if (map->buswidth == 1) {
map->write8(map, val, addr);
} else if (map->buswidth == 2) {
map->write16(map, val, addr);
} else if (map->buswidth == 4) {
map->write32(map, val, addr);
}
}
static inline __u32 make_cmd(struct map_info *map, __u32 cmd)
{
const struct bb_flash_private *private = map->fldrv_priv;
if ((private->interleave == 2) &&
(private->device_addrtype == DEVICE_ADDRTYPE_x16)) {
cmd |= (cmd << 16);
}
return cmd;
}
#if 0
static inline void send_unlock(struct map_info *map, unsigned long base)
{
wide_write(map, (CMD_UNLOCK_DATA_1 << 16) | CMD_UNLOCK_DATA_1,
base + (map->buswidth * ADDR_UNLOCK_1));
wide_write(map, (CMD_UNLOCK_DATA_2 << 16) | CMD_UNLOCK_DATA_2,
base + (map->buswidth * ADDR_UNLOCK_2));
}
#endif
static inline void send_cmd(struct map_info *map, unsigned long base, __u32 cmd)
{
//send_unlock(map, base);
wide_write(map, make_cmd(map, cmd), base);
}
static inline void send_cmd_to_addr(struct map_info *map, unsigned long base,
__u32 cmd, unsigned long addr)
{
//send_unlock(map, base);
wide_write(map, make_cmd(map, cmd), base + addr);
}
static inline int check_SR(struct map_info *map, unsigned long base, __u32 bits)
{
return (wide_read(map, base) & bits);
}
static inline int flash_is_busy(struct map_info *map, unsigned long base,
int interleave)
{
return !check_SR(map, base, SR_READY);
}
/*
* Reads JEDEC manufacturer ID and device ID and returns the index of the first
* matching table = table entry (-1 if not found or alias for already found chip).
*/
static int probe_new_chip(struct mtd_info *mtd, __u32 base,
struct flchip *chips,
struct bb_flash_private *private,
struct bb_flash_chip_info *table)
{
__u32 mfr_id;
__u32 dev_id;
struct map_info *map = mtd->priv;
struct bb_flash_private temp;
int i;
printk("probing a new chip at 0x%ux\n", base);
temp.interleave = 2;
map->fldrv_priv = &temp;
/* Enter autoselect mode. */
send_cmd(map, base, CMD_CLEAR_STATUS);
send_cmd(map, base, CMD_READ_ID);
printk("after command\n");
mfr_id = wide_read(map, base + (map->buswidth * ADDR_DEVICE_MFR));
dev_id = wide_read(map, base + (map->buswidth * ADDR_DEVICE_ID));
if ((map->buswidth == 4) && ((mfr_id >> 16) == (mfr_id & 0xffff)) &&
((dev_id >> 16) == (dev_id & 0xffff))) {
mfr_id &= 0xffff;
dev_id &= 0xffff;
} else {
temp.interleave = 1;
}
printk("after determining interleave\n");
for (i = 0; table[i].name; i++) {
printk("testing chips: is it [%d] %s?\n", i, table[i].name);
if ((mfr_id == table[i].mfr_id) &&
(dev_id == table[i].dev_id)) {
if (private->numchips) {
#if 0
int j;
/* Is this an alias for an already found chip?
* In that case that chip should be in
* autoselect mode now.
*/
for (j = 0; j < private->numchips; j++) {
__u32 mfr_id_other;
__u32 dev_id_other;
mfr_id_other =
wide_read(map, private->chips[j].start +
(map->buswidth *
ADDR_DEVICE_MFR
));
dev_id_other =
wide_read(map, private->chips[j].start +
(map->buswidth *
ADDR_DEVICE_ID));
if (temp.interleave == 2) {
mfr_id_other &= 0xffff;
dev_id_other &= 0xffff;
}
if ((mfr_id_other == mfr_id) &&
(dev_id_other == dev_id)) {
/* Exit autoselect mode. */
send_cmd(map, base,
CMD_READ_ARRAY);
return -1;
}
}
#endif
if (private->numchips == MAX_BB_CHIPS) {
printk(KERN_WARNING
"%s: Too many flash chips "
"detected. Increase "
"MAX_BB_CHIPS from %d.\n",
map->name, MAX_BB_CHIPS);
return -1;
}
chips[private->numchips].start = base;
chips[private->numchips].state = FL_READY;
chips[private->numchips].mutex = &chips[private->numchips]._spinlock;
private->numchips++;
}
printk("%s: Found %d x %ldMiB %s at 0x%x -- %d chips found so far\n",
map->name,
temp.interleave, (table[i].size)/(1024*1024),
table[i].name, base,
private->numchips);
mtd->size += table[i].size * temp.interleave;
mtd->numeraseregions += table[i].numeraseregions;
printk("that's it\n");
break;
}
}
printk("finished scanning for chip type\n");
/* Exit autoselect mode. */
send_cmd(map, base, CMD_READ_ARRAY);
if (!(table[i].name)) {
printk(KERN_DEBUG "%s: unknown flash device at 0x%x, "
"mfr id 0x%x, dev id 0x%x\n", map->name,
base, mfr_id, dev_id);
map->fldrv_priv = NULL;
return -1;
}
printk("ok my job is finished\n");
private->device_addrtype = table[i].device_addrtype;
private->interleave = temp.interleave;
return i;
}
static struct mtd_info *bb_flash_probe(struct map_info *map)
{
/* Keep this table on the stack so that it gets deallocated after the
* probe is done.
*/
struct bb_flash_chip_info table[] = {
/* need to fill in the others */
#define expandID(id) mfr_id: MFR_INTEL, dev_id: id, name: "Intel " #id
#define expandADDRTYPE(t) device_addrtype: DEVICE_ADDRTYPE_ ## t
{ expandID(TE28F320B3_TOP),
expandADDRTYPE(x16),
size: 0x0400000, /* 4MB in bytes */
numeraseregions: 2,
regions: {
[0] = { offset: 0x000000, erasesize: 0x10000, numblocks: 63 },
[1] = { offset: 0x1F8000, erasesize: 0x02000, numblocks: 8 },
}
},
{ expandID(TE28F320B3_BOTTOM),
expandADDRTYPE(x16),
size: 0x0400000, /* 4MB in bytes */
numeraseregions: 2,
regions: {
[0] = { offset: 0x000000, erasesize: 0x02000, numblocks: 8 },
[1] = { offset: 0x008000, erasesize: 0x10000, numblocks: 63 },
}
},
{ 0 },
};
struct mtd_info *mtd;
struct bb_flash_private temp;
struct bb_flash_private *private;
u_long size;
unsigned long base;
int i, table_pos[MAX_BB_CHIPS];
struct flchip chips[MAX_BB_CHIPS];
int reg_idx;
int offset;
printk("Probing flash\n");
mtd = (struct mtd_info*)kmalloc(sizeof(*mtd), GFP_KERNEL);
if (!mtd) {
printk(KERN_WARNING
"%s: kmalloc failed for info structure\n", map->name);
return NULL;
}
memset(mtd, 0, sizeof(*mtd));
mtd->priv = map;
memset(&temp, 0, sizeof(temp));
printk("%s: Probing for BB compatible flash...\n", map->name);
if ((table_pos[0] = probe_new_chip(mtd, 0, NULL, &temp, table))
== -1) {
printk(KERN_WARNING
"%s: Found no BB compatible device at location zero\n",
map->name);
kfree(mtd);
return NULL;
}
printk("one chip found at base 0\n");
chips[0].start = 0;
chips[0].state = FL_READY;
chips[0].mutex = &chips[0]._spinlock;
temp.numchips = 1;
for (size = mtd->size; size > 1; size >>= 1) {
temp.chipshift++;
}
switch (temp.interleave) {
case 2:
temp.chipshift += 1;
break;
case 4:
temp.chipshift += 2;
break;
}
printk("before scanning the rest of the ROM space for chips\n");
/* Find out if there are any more chips in the map. */
for (base = (1 << temp.chipshift);
base < map->size;
base += (1 << temp.chipshift)) {
int numchips = temp.numchips;
printk("scanning at %lux, numchip so far is %d\n", base, numchips);
table_pos[numchips] = probe_new_chip(mtd, base, chips, &temp, table);
}
printk("finished scanning\n");
mtd->eraseregions = kmalloc(sizeof(struct mtd_erase_region_info) *
mtd->numeraseregions, GFP_KERNEL);
if (!mtd->eraseregions) {
printk(KERN_WARNING "%s: Failed to allocate "
"memory for MTD erase region info\n", map->name);
kfree(mtd);
map->fldrv_priv = NULL;
return 0;
}
printk("updating erase regions for chips mtd->numeraseregions = %d\n", mtd->numeraseregions);
reg_idx = 0;
offset = 0;
for (i = 0; i < temp.numchips; i++) {
int dev_size;
int j;
printk("dealing with chip number %d, offset = %d\n", i, offset);
dev_size = 0;
for (j = 0; j < table[table_pos[i]].numeraseregions; j++) {
printk("reg_idx = %d, dealing with eraseregion %d of chip %d\n", reg_idx, j, i);
mtd->eraseregions[reg_idx].offset = offset +
(table[table_pos[i]].regions[j].offset *
temp.interleave);
mtd->eraseregions[reg_idx].erasesize =
table[table_pos[i]].regions[j].erasesize *
temp.interleave;
mtd->eraseregions[reg_idx].numblocks =
table[table_pos[i]].regions[j].numblocks;
if (mtd->erasesize <
mtd->eraseregions[reg_idx].erasesize) {
mtd->erasesize =
mtd->eraseregions[reg_idx].erasesize;
}
dev_size += mtd->eraseregions[reg_idx].erasesize *
mtd->eraseregions[reg_idx].numblocks;
reg_idx++;
}
offset += dev_size;
}
printk("finished with eraseregion bits\n");
mtd->type = MTD_NORFLASH;
mtd->flags = MTD_CAP_NORFLASH;
mtd->name = map->name;
mtd->erase = bb_flash_erase;
mtd->read = bb_flash_read;
mtd->write = bb_flash_write;
mtd->sync = bb_flash_sync;
mtd->suspend = bb_flash_suspend;
mtd->resume = bb_flash_resume;
private = kmalloc(sizeof(*private) + (sizeof(struct flchip) * temp.numchips), GFP_KERNEL);
if (!private) {
printk(KERN_WARNING
"%s: kmalloc failed for private structure\n", map->name);
kfree(mtd->eraseregions);
kfree(mtd);
map->fldrv_priv = NULL;
return NULL;
}
memcpy(private, &temp, sizeof(temp));
memcpy(private->chips, chips, sizeof(struct flchip) * private->numchips);
for (i = 0; i < private->numchips; i++) {
init_waitqueue_head(&private->chips[i].wq);
spin_lock_init(&private->chips[i]._spinlock);
}
map->fldrv_priv = private;
map->fldrv = &bb_flash_chipdrv;
MOD_INC_USE_COUNT;
printk("FLASH: found %d chips, interleave = %d,"
"chipshift = %lu, device_addrtype = %u\n, erasesize=%d",
private->numchips, private->interleave,
private->chipshift, private->device_addrtype*8, mtd->erasesize);
return mtd;
}
static inline int read_one_chip(struct map_info *map, struct flchip *chip,
loff_t adr, size_t len, u_char *buf)
{
DECLARE_WAITQUEUE(wait, current);
unsigned long timeo = jiffies + HZ;
send_cmd(map, chip->start, CMD_READ_ARRAY);
retry:
spin_lock_bh(chip->mutex);
if (chip->state != FL_READY){
printk(KERN_INFO "%s: waiting for chip to read, state = %d\n",
map->name, chip->state);
set_current_state(TASK_UNINTERRUPTIBLE);
add_wait_queue(&chip->wq, &wait);
spin_unlock_bh(chip->mutex);
schedule();
remove_wait_queue(&chip->wq, &wait);
if(signal_pending(current)) {
return -EINTR;
}
timeo = jiffies + HZ;
goto retry;
}
adr += chip->start;
chip->state = FL_READY;
map->copy_from(map, buf, adr, len);
wake_up(&chip->wq);
spin_unlock_bh(chip->mutex);
return 0;
}
static int bb_flash_read(struct mtd_info *mtd, loff_t from, size_t len,
size_t *retlen, u_char *buf)
{
struct map_info *map = mtd->priv;
struct bb_flash_private *private = map->fldrv_priv;
unsigned long ofs;
int chipnum;
int ret = 0;
if ((from + len) > mtd->size) {
printk(KERN_WARNING "%s: read request past end of device "
"(0x%lx)\n", map->name, (unsigned long)from + len);
return -EINVAL;
}
/* Offset within the first chip that the first read should start. */
chipnum = (from >> private->chipshift);
ofs = from - (chipnum << private->chipshift);
*retlen = 0;
while (len) {
unsigned long this_len;
if (chipnum >= private->numchips) {
break;
}
if ((len + ofs - 1) >> private->chipshift) {
this_len = (1 << private->chipshift) - ofs;
} else {
this_len = len;
}
ret = read_one_chip(map, &private->chips[chipnum], ofs,
this_len, buf);
if (ret) {
break;
}
*retlen += this_len;
len -= this_len;
buf += this_len;
ofs = 0;
chipnum++;
}
return ret;
}
static int write_one_word(struct map_info *map, struct flchip *chip,
unsigned long adr, __u32 datum)
{
unsigned long timeo = jiffies + HZ;
struct bb_flash_private *private = map->fldrv_priv;
DECLARE_WAITQUEUE(wait, current);
int ret = 0;
int times_left;
#if 0
if (((adr + chip->start ) % 1024) < 4)
printk("attempt to write 0x%x at 0x%lx\n", datum, adr + chip->start);
return 0;
#endif
retry:
spin_lock_bh(chip->mutex);
if (chip->state != FL_READY){
printk("%s: waiting for chip to write, state = %d\n",
map->name, chip->state);
set_current_state(TASK_UNINTERRUPTIBLE);
add_wait_queue(&chip->wq, &wait);
spin_unlock_bh(chip->mutex);
schedule();
remove_wait_queue(&chip->wq, &wait);
printk(KERN_INFO "%s: woke up to write\n", map->name);
if(signal_pending(current))
return -EINTR;
timeo = jiffies + HZ;
goto retry;
}
chip->state = FL_WRITING;
adr += chip->start;
ENABLE_VPP(map);
send_cmd(map, chip->start, CMD_PROGRAM_SETUP);
wide_write(map, datum, adr);
times_left = 500000;
while (times_left-- && flash_is_busy(map, chip->start,
private->interleave)) {
if (current->need_resched) {
spin_unlock_bh(chip->mutex);
schedule();
spin_lock_bh(chip->mutex);
}
}
DISABLE_VPP(map);
if (!times_left) {
printk(KERN_WARNING "%s: write to 0x%lx timed out!\n",
map->name, adr);
ret = -EIO;
} else {
#if 0
__u32 verify;
send_cmd(map, chip->start, CMD_READ_ARRAY);
if ((verify = wide_read(map, adr)) != datum) {
printk(KERN_WARNING "%s: write to 0x%lx failed. "
"datum = %x, verify = %x\n",
map->name, adr, datum, verify);
ret = -EIO;
} else {
printk("wrote %d at 0x%lx: success\n", datum, adr);
}
#endif
}
chip->state = FL_READY;
wake_up(&chip->wq);
spin_unlock_bh(chip->mutex);
return ret;
}
static int bb_flash_write(struct mtd_info *mtd, loff_t to , size_t len,
size_t *retlen, const u_char *buf)
{
struct map_info *map = mtd->priv;
struct bb_flash_private *private = map->fldrv_priv;
int ret = 0;
int chipnum;
unsigned long ofs;
unsigned long chipstart;
*retlen = 0;
if (!len) {
return 0;
}
chipnum = to >> private->chipshift;
ofs = to - (chipnum << private->chipshift);
chipstart = private->chips[chipnum].start;
/* If it's not bus-aligned, do the first byte write. */
if (ofs & (map->buswidth - 1)) {
unsigned long bus_ofs = ofs & ~(map->buswidth - 1);
int i = ofs - bus_ofs;
int n = 0;
u_char tmp_buf[4];
__u32 datum;
map->copy_from(map, tmp_buf,
bus_ofs + private->chips[chipnum].start,
map->buswidth);
while (len && i < map->buswidth)
tmp_buf[i++] = buf[n++], len--;
if (map->buswidth == 2) {
datum = *(__u16*)tmp_buf;
} else if (map->buswidth == 4) {
datum = *(__u32*)tmp_buf;
} else {
return -EINVAL; /* should never happen, but be safe */
}
ret = write_one_word(map, &private->chips[chipnum], bus_ofs,
datum);
if (ret) {
return ret;
}
ofs += n;
buf += n;
(*retlen) += n;
if (ofs >> private->chipshift) {
chipnum++;
ofs = 0;
if (chipnum == private->numchips) {
return 0;
}
}
}
/* We are now aligned, write as much as possible. */
while(len >= map->buswidth) {
__u32 datum;
if (map->buswidth == 1) {
datum = *(__u8*)buf;
} else if (map->buswidth == 2) {
datum = *(__u16*)buf;
} else if (map->buswidth == 4) {
datum = *(__u32*)buf;
} else {
return -EINVAL;
}
ret = write_one_word(map, &private->chips[chipnum], ofs, datum);
if (ret) {
return ret;
}
ofs += map->buswidth;
buf += map->buswidth;
(*retlen) += map->buswidth;
len -= map->buswidth;
if (ofs >> private->chipshift) {
chipnum++;
ofs = 0;
if (chipnum == private->numchips) {
return 0;
}
chipstart = private->chips[chipnum].start;
}
}
if (len & (map->buswidth - 1)) {
int i = 0, n = 0;
u_char tmp_buf[2];
__u32 datum;
map->copy_from(map, tmp_buf,
ofs + private->chips[chipnum].start,
map->buswidth);
while (len--) {
tmp_buf[i++] = buf[n++];
}
if (map->buswidth == 2) {
datum = *(__u16*)tmp_buf;
} else if (map->buswidth == 4) {
datum = *(__u32*)tmp_buf;
} else {
return -EINVAL; /* should never happen, but be safe */
}
ret = write_one_word(map, &private->chips[chipnum], ofs, datum);
if (ret) {
return ret;
}
(*retlen) += n;
}
return 0;
}
static inline int erase_one_block(struct map_info *map, struct flchip *chip,
unsigned long adr, u_long size)
{
unsigned long timeo = jiffies + HZ;
struct bb_flash_private *private = map->fldrv_priv;
DECLARE_WAITQUEUE(wait, current);
//printk("attempt to erase block at 0x%lx (size = %ld)\n", adr + chip->start, size);
//return 0;
retry:
spin_lock_bh(chip->mutex);
if (chip->state != FL_READY){
set_current_state(TASK_UNINTERRUPTIBLE);
add_wait_queue(&chip->wq, &wait);
spin_unlock_bh(chip->mutex);
schedule();
remove_wait_queue(&chip->wq, &wait);
if (signal_pending(current)) {
return -EINTR;
}
timeo = jiffies + HZ;
goto retry;
}
chip->state = FL_ERASING;
adr += chip->start;
ENABLE_VPP(map);
send_cmd(map, chip->start, CMD_ERASE_SETUP);
send_cmd_to_addr(map, chip->start, CMD_ERASE_CONFIRM, adr);
timeo = jiffies + (HZ * 5);
spin_unlock_bh(chip->mutex);
schedule_timeout(HZ);
spin_lock_bh(chip->mutex);
while (flash_is_busy(map, chip->start, private->interleave)) {
if (chip->state != FL_ERASING) {
/* Someone's suspended the erase. Sleep */
set_current_state(TASK_UNINTERRUPTIBLE);
add_wait_queue(&chip->wq, &wait);
spin_unlock_bh(chip->mutex);
printk(KERN_INFO "%s: erase suspended. Sleeping\n",
map->name);
schedule();
remove_wait_queue(&chip->wq, &wait);
if (signal_pending(current)) {
return -EINTR;
}
timeo = jiffies + (HZ*2); /* FIXME */
spin_lock_bh(chip->mutex);
continue;
}
/* OK Still waiting */
if (time_after(jiffies, timeo)) {
chip->state = FL_READY;
spin_unlock_bh(chip->mutex);
printk(KERN_WARNING "%s: waiting for erase to complete "
"timed out.\n", map->name);
DISABLE_VPP(map);
return -EIO;
}
/* Latency issues. Drop the lock, wait a while and retry */
spin_unlock_bh(chip->mutex);
if (current->need_resched)
schedule();
else
udelay(1);
spin_lock_bh(chip->mutex);
}
DISABLE_VPP(map);
send_cmd(map, chip->start, CMD_READ_ARRAY);
/* Verify every single word */
{
int address;
int error = 0;
__u16 verify;
for (address = adr; address < (adr + size); address++) {
if ((verify = map->read16(map, address)) != 0xFFFF) {
error = 1;
break;
}
}
if (error) {
chip->state = FL_READY;
spin_unlock_bh(chip->mutex);
printk(KERN_WARNING
"%s: verify error at 0x%x, size %ld.\n",
map->name, address, size);
DISABLE_VPP(map);
return -EIO;
} else {
//printk("erased block at 0x%lx\n", adr);
}
}
chip->state = FL_READY;
wake_up(&chip->wq);
spin_unlock_bh(chip->mutex);
return 0;
}
static int bb_flash_erase(struct mtd_info *mtd, struct erase_info *instr)
{
struct map_info *map = mtd->priv;
struct bb_flash_private *private = map->fldrv_priv;
unsigned long adr, len;
int chipnum;
int ret = 0;
int i;
int first;
struct mtd_erase_region_info *regions = mtd->eraseregions;
if (instr->addr > mtd->size) {
return -EINVAL;
}
if ((instr->len + instr->addr) > mtd->size) {
return -EINVAL;
}
/* Check that both start and end of the requested erase are
* aligned with the erasesize at the appropriate addresses.
*/
i = 0;
/* Skip all erase regions which are ended before the start of
the requested erase. Actually, to save on the calculations,
we skip to the first erase region which starts after the
start of the requested erase, and then go back one.
*/
while ((i < mtd->numeraseregions) &&
(instr->addr >= regions[i].offset)) {
i++;
}
i--;
/* OK, now i is pointing at the erase region in which this
* erase request starts. Check the start of the requested
* erase range is aligned with the erase size which is in
* effect here.
*/
if (instr->addr & (regions[i].erasesize-1)) {
return -EINVAL;
}
/* Remember the erase region we start on. */
first = i;
/* Next, check that the end of the requested erase is aligned
* with the erase region at that address.
*/
while ((i < mtd->numeraseregions) &&
((instr->addr + instr->len) >= regions[i].offset)) {
i++;
}
/* As before, drop back one to point at the region in which
* the address actually falls.
*/
i--;
if ((instr->addr + instr->len) & (regions[i].erasesize-1)) {
return -EINVAL;
}
chipnum = instr->addr >> private->chipshift;
adr = instr->addr - (chipnum << private->chipshift);
len = instr->len;
i = first;
while (len) {
ret = erase_one_block(map, &private->chips[chipnum], adr,
regions[i].erasesize);
if (ret) {
return ret;
}
adr += regions[i].erasesize;
len -= regions[i].erasesize;
if ((adr % (1 << private->chipshift)) ==
((regions[i].offset + (regions[i].erasesize *
regions[i].numblocks))
% (1 << private->chipshift))) {
i++;
}
if (adr >> private->chipshift) {
adr = 0;
chipnum++;
if (chipnum >= private->numchips) {
break;
}
}
}
instr->state = MTD_ERASE_DONE;
if (instr->callback) {
instr->callback(instr);
}
return 0;
}
static void bb_flash_sync(struct mtd_info *mtd)
{
struct map_info *map = mtd->priv;
struct bb_flash_private *private = map->fldrv_priv;
int i;
struct flchip *chip;
int ret = 0;
DECLARE_WAITQUEUE(wait, current);
for (i = 0; !ret && (i < private->numchips); i++) {
chip = &private->chips[i];
retry:
spin_lock_bh(chip->mutex);
switch(chip->state) {
case FL_READY:
case FL_STATUS:
case FL_CFI_QUERY:
case FL_JEDEC_QUERY:
chip->oldstate = chip->state;
chip->state = FL_SYNCING;
/* No need to wake_up() on this state change -
* as the whole point is that nobody can do anything
* with the chip now anyway.
*/
case FL_SYNCING:
spin_unlock_bh(chip->mutex);
break;
default:
/* Not an idle state */
add_wait_queue(&chip->wq, &wait);
spin_unlock_bh(chip->mutex);
schedule();
remove_wait_queue(&chip->wq, &wait);
goto retry;
}
}
/* Unlock the chips again */
for (i--; i >= 0; i--) {
chip = &private->chips[i];
spin_lock_bh(chip->mutex);
if (chip->state == FL_SYNCING) {
chip->state = chip->oldstate;
wake_up(&chip->wq);
}
spin_unlock_bh(chip->mutex);
}
}
static int bb_flash_suspend(struct mtd_info *mtd)
{
printk("bb_flash_suspend(): not implemented!\n");
return -EINVAL;
}
static void bb_flash_resume(struct mtd_info *mtd)
{
printk("bb_flash_resume(): not implemented!\n");
}
static void bb_flash_destroy(struct mtd_info *mtd)
{
struct map_info *map = mtd->priv;
struct bb_flash_private *private = map->fldrv_priv;
kfree(private);
}
int __init bb_flash_init(void)
{
register_mtd_chip_driver(&bb_flash_chipdrv);
return 0;
}
void __exit bb_flash_exit(void)
{
unregister_mtd_chip_driver(&bb_flash_chipdrv);
}
module_init(bb_flash_init);
module_exit(bb_flash_exit);
^ permalink raw reply [flat|nested] 6+ messages in threadend of thread, other threads:[~2001-09-04 15:05 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2001-09-04 13:09 Problems with Intel TE28F320 B3 Norbert Leon 2001-09-04 13:39 ` David Woodhouse 2001-09-04 14:25 ` Daniel Belz 2001-09-04 14:23 ` Norbert Leon 2001-09-04 15:22 ` Daniel Belz -- strict thread matches above, loose matches on Subject: below -- 2001-09-04 14:02 Kremer, Alex
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox