9
0
Fork 0

nor flash: integrate into mtd

CFI Flash is currently handled outside the mtd layer which makes it
a special case. Integrate it into mtd so that we get rid of this
special status.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Sascha Hauer 2012-04-19 20:22:00 +02:00
parent 1bd90ff5a1
commit 2749fbac48
23 changed files with 35 additions and 71 deletions

View File

@ -30,4 +30,5 @@ CONFIG_CMD_TFTP=y
CONFIG_FS_TFTP=y
CONFIG_DRIVER_NET_EP93XX=y
# CONFIG_SPI is not set
CONFIG_MTD=y
CONFIG_DRIVER_CFI=y

View File

@ -46,6 +46,7 @@ CONFIG_DRIVER_NET_FEC_IMX=y
CONFIG_I2C=y
CONFIG_I2C_IMX=y
CONFIG_I2C_LP3972=y
CONFIG_MTD=y
CONFIG_DRIVER_CFI=y
# CONFIG_DRIVER_CFI_AMD is not set
# CONFIG_DRIVER_CFI_BANK_WIDTH_1 is not set

View File

@ -55,6 +55,7 @@ CONFIG_NET_PING=y
CONFIG_NET_RESOLV=y
CONFIG_DRIVER_NET_FEC_IMX=y
CONFIG_DRIVER_SPI_IMX=y
CONFIG_MTD=y
CONFIG_DRIVER_CFI=y
CONFIG_CFI_BUFFER_WRITE=y
CONFIG_MCI=y

View File

@ -34,5 +34,6 @@ CONFIG_FS_TFTP=y
CONFIG_DRIVER_NET_MACB=y
# CONFIG_SPI is not set
CONFIG_I2C=y
CONFIG_MTD=y
CONFIG_DRIVER_CFI=y
CONFIG_CFI_BUFFER_WRITE=y

View File

@ -35,6 +35,7 @@ CONFIG_CMD_TFTP=y
CONFIG_FS_TFTP=y
CONFIG_DRIVER_NET_CS8900=y
# CONFIG_SPI is not set
CONFIG_MTD=y
CONFIG_DRIVER_CFI=y
# CONFIG_DRIVER_CFI_INTEL is not set
CONFIG_CFI_BUFFER_WRITE=y

View File

@ -33,6 +33,7 @@ CONFIG_NET_PING=y
CONFIG_CMD_TFTP=y
CONFIG_FS_TFTP=y
CONFIG_DRIVER_SPI_IMX=y
CONFIG_MTD=y
CONFIG_DRIVER_CFI=y
# CONFIG_DRIVER_CFI_INTEL is not set
CONFIG_CFI_BUFFER_WRITE=y

View File

@ -26,5 +26,6 @@ CONFIG_NET_PING=y
CONFIG_CMD_TFTP=y
CONFIG_FS_TFTP=y
CONFIG_DRIVER_NET_NETX=y
CONFIG_MTD=y
CONFIG_DRIVER_CFI=y
CONFIG_CFI_BUFFER_WRITE=y

View File

@ -54,6 +54,7 @@ CONFIG_FS_TFTP=y
CONFIG_DRIVER_SERIAL_PXA=y
CONFIG_DRIVER_NET_SMC91111=y
# CONFIG_SPI is not set
CONFIG_MTD=y
CONFIG_DRIVER_CFI=y
CONFIG_VIDEO=y
CONFIG_DRIVER_VIDEO_PXA=y

View File

@ -33,6 +33,7 @@ CONFIG_CMD_TFTP=y
CONFIG_FS_TFTP=y
CONFIG_DRIVER_NET_MACB=y
# CONFIG_SPI is not set
CONFIG_MTD=y
CONFIG_DRIVER_CFI=y
CONFIG_CFI_BUFFER_WRITE=y
CONFIG_W1=y

View File

@ -52,6 +52,7 @@ CONFIG_FS_TFTP=y
CONFIG_NET_NETCONSOLE=y
CONFIG_NET_RESOLV=y
CONFIG_DRIVER_NET_DM9K=y
CONFIG_MTD=y
CONFIG_DRIVER_CFI=y
# CONFIG_DRIVER_CFI_BANK_WIDTH_4 is not set
CONFIG_CFI_BUFFER_WRITE=y

View File

@ -25,5 +25,6 @@ CONFIG_NET_PING=y
CONFIG_CMD_TFTP=y
CONFIG_FS_TFTP=y
CONFIG_DRIVER_NET_SMC911X=y
CONFIG_MTD=y
CONFIG_DRIVER_CFI=y
CONFIG_CFI_BUFFER_WRITE=y

View File

@ -27,6 +27,7 @@ CONFIG_CMD_PARTITION=y
CONFIG_NET=y
CONFIG_NET_PING=y
CONFIG_DRIVER_NET_TSE=y
CONFIG_MTD=y
CONFIG_DRIVER_CFI=y
CONFIG_FS_TFTP=y
CONFIG_ZLIB=y

View File

@ -36,6 +36,7 @@ CONFIG_FS_TFTP=y
CONFIG_ARCH_MPC5XXX=y
CONFIG_MACH_PHYCORE_MPC5200B_TINY=y
CONFIG_DRIVER_NET_MPC5200=y
CONFIG_MTD=y
CONFIG_DRIVER_CFI=y
CONFIG_CFI_BUFFER_WRITE=y
CONFIG_ZLIB=y

View File

@ -4,7 +4,6 @@ source "drivers/serial/Kconfig"
source "drivers/net/Kconfig"
source "drivers/spi/Kconfig"
source "drivers/i2c/Kconfig"
source "drivers/nor/Kconfig"
source "drivers/mtd/Kconfig"
source "drivers/ata/Kconfig"
source "drivers/usb/Kconfig"

View File

@ -3,7 +3,6 @@ obj-$(CONFIG_ARM_AMBA) += amba/
obj-y += net/
obj-y += serial/
obj-y += mtd/
obj-y += nor/
obj-y += usb/
obj-$(CONFIG_DISK) += ata/
obj-$(CONFIG_SPI) += spi/

View File

@ -21,6 +21,7 @@ config MTD_RAW_DEVICE
prompt "mtdraw device to read/write both data+oob"
source "drivers/mtd/devices/Kconfig"
source "drivers/mtd/nor/Kconfig"
source "drivers/mtd/nand/Kconfig"
source "drivers/mtd/ubi/Kconfig"

View File

@ -1,4 +1,5 @@
obj-$(CONFIG_NAND) += nand/
obj-$(CONFIG_DRIVER_CFI) += nor/
obj-$(CONFIG_UBI) += ubi/
obj-y += devices/
obj-$(CONFIG_PARTITION_NEED_MTD) += partition.o

View File

@ -1,7 +1,5 @@
menu "flash drivers"
menuconfig DRIVER_CFI
bool "CFI"
bool "CFI NOR flash support"
help
If you have NOR Flash devices connected to your system and wish
to use them say yes here.
@ -55,5 +53,3 @@ config CFI_BUFFER_WRITE
depends on DRIVER_CFI || DRIVER_CFI
endif
endmenu

View File

@ -454,10 +454,8 @@ flash_sect_t find_sector (struct flash_info *info, ulong addr)
return sector;
}
static int __cfi_erase(struct cdev *cdev, size_t count, loff_t offset,
int verbose)
static int cfi_erase(struct flash_info *finfo, size_t count, loff_t offset)
{
struct flash_info *finfo = (struct flash_info *)cdev->priv;
unsigned long start, end;
int i, ret = 0;
@ -467,9 +465,6 @@ static int __cfi_erase(struct cdev *cdev, size_t count, loff_t offset,
end = find_sector(finfo, (unsigned long)finfo->base + offset +
count - 1);
if (verbose)
init_progression_bar(end - start);
for (i = start; i <= end; i++) {
ret = finfo->cfi_cmd_set->flash_erase_one(finfo, i);
if (ret)
@ -479,21 +474,11 @@ static int __cfi_erase(struct cdev *cdev, size_t count, loff_t offset,
ret = -EINTR;
goto out;
}
if (verbose)
show_progress(i - start);
}
out:
if (verbose)
putchar('\n');
return ret;
}
static int cfi_erase(struct cdev *cdev, size_t count, loff_t offset)
{
return __cfi_erase(cdev, count, offset, 1);
}
/*
* Copy memory to flash, returns:
* 0 - OK
@ -626,18 +611,13 @@ static int flash_real_protect (struct flash_info *info, long sector, int prot)
return retcode;
}
static int cfi_protect(struct cdev *cdev, size_t count, loff_t offset, int prot)
static int cfi_mtd_protect(struct flash_info *finfo, loff_t offset, size_t len, int prot)
{
struct flash_info *finfo = (struct flash_info *)cdev->priv;
unsigned long start, end;
int i, ret = 0;
const char *action = (prot? "protect" : "unprotect");
printf("%s: %s 0x%p (size %zu)\n", __func__,
action, finfo->base + offset, count);
start = find_sector(finfo, (unsigned long)finfo->base + offset);
end = find_sector(finfo, (unsigned long)finfo->base + offset + count - 1);
end = find_sector(finfo, (unsigned long)finfo->base + offset + len - 1);
for (i = start; i <= end; i++) {
ret = flash_real_protect (finfo, i, prot);
@ -645,20 +625,21 @@ static int cfi_protect(struct cdev *cdev, size_t count, loff_t offset, int prot)
goto out;
}
out:
putchar('\n');
return ret;
}
static ssize_t cfi_write(struct cdev *cdev, const void *buf, size_t count, loff_t offset, ulong flags)
static int cfi_mtd_lock(struct mtd_info *mtd, loff_t offset, size_t len)
{
struct flash_info *finfo = (struct flash_info *)cdev->priv;
int ret;
struct flash_info *finfo = container_of(mtd, struct flash_info, mtd);
debug("cfi_write: buf=0x%p addr=0x%p count=0x%08zx\n",
buf, finfo->base + offset, count);
return cfi_mtd_protect(finfo, offset, len, 1);
}
ret = write_buff(finfo, buf, (unsigned long)finfo->base + offset, count);
return ret == 0 ? count : -1;
static int cfi_mtd_unlock(struct mtd_info *mtd, loff_t offset, size_t len)
{
struct flash_info *finfo = container_of(mtd, struct flash_info, mtd);
return cfi_mtd_protect(finfo, offset, len, 0);
}
static void cfi_info (struct device_d* dev)
@ -908,15 +889,6 @@ int flash_isset(struct flash_info *info, flash_sect_t sect,
return retval;
}
struct file_operations cfi_ops = {
.read = mem_read,
.write = cfi_write,
.lseek = dev_lseek_default,
.erase = cfi_erase,
.protect = cfi_protect,
.memmap = generic_memmap_ro,
};
static int cfi_mtd_read(struct mtd_info *mtd, loff_t from, size_t len,
size_t *retlen, u_char *buf)
{
@ -943,10 +915,9 @@ static int cfi_mtd_write(struct mtd_info *mtd, loff_t to, size_t len,
static int cfi_mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
{
struct flash_info *info = container_of(mtd, struct flash_info, mtd);
struct cdev *cdev = &info->cdev;
int ret;
ret = __cfi_erase(cdev, instr->len, instr->addr, 0);
ret = cfi_erase(info, instr->len, instr->addr);
if (ret) {
instr->state = MTD_ERASE_FAILED;
@ -966,21 +937,23 @@ static void cfi_init_mtd(struct flash_info *info)
mtd->read = cfi_mtd_read;
mtd->write = cfi_mtd_write;
mtd->erase = cfi_mtd_erase;
mtd->lock = cfi_mtd_lock;
mtd->unlock = cfi_mtd_unlock;
mtd->size = info->size;
mtd->name = info->cdev.name;
mtd->erasesize = info->eraseregions[1].erasesize; /* FIXME */
mtd->writesize = 1;
mtd->subpage_sft = 0;
mtd->eraseregions = info->eraseregions;
mtd->numeraseregions = info->numeraseregions;
mtd->flags = MTD_CAP_NORFLASH;
info->cdev.mtd = mtd;
mtd->type = MTD_NORFLASH;
add_mtd_device(mtd, "nor");
}
static int cfi_probe (struct device_d *dev)
{
struct flash_info *info = xzalloc(sizeof(*info));
int cfinum;
dev->priv = (void *)info;
@ -999,24 +972,7 @@ static int cfi_probe (struct device_d *dev)
dev_info(dev, "found cfi flash at %p, size %ld\n",
info->base, info->size);
if (dev->id < 0)
cfinum = cdev_find_free_index("nor");
else
cfinum = dev->id;
info->cdev.name = asprintf("nor%d", cfinum);
info->cdev.size = info->size;
info->cdev.dev = dev;
info->cdev.ops = &cfi_ops;
info->cdev.priv = info;
if (IS_ENABLED(CONFIG_PARTITION_NEED_MTD))
cfi_init_mtd(info);
devfs_create(&info->cdev);
if (dev->device_node)
of_parse_partitions(info->cdev.name, dev->device_node);
cfi_init_mtd(info);
return 0;
}

View File

@ -74,7 +74,6 @@ struct flash_info {
ulong addr_unlock1; /* unlock address 1 for AMD flash roms */
ulong addr_unlock2; /* unlock address 2 for AMD flash roms */
struct cfi_cmd_set *cfi_cmd_set;
struct cdev cdev;
struct mtd_info mtd;
int numeraseregions;
struct mtd_erase_region_info *eraseregions;