18 #include <linux/kernel.h>
19 #include <linux/slab.h>
20 #include <linux/module.h>
29 #ifndef CONFIG_ONENAND_SIM_MANUFACTURER
30 #define CONFIG_ONENAND_SIM_MANUFACTURER 0xec
33 #ifndef CONFIG_ONENAND_SIM_DEVICE_ID
34 #define CONFIG_ONENAND_SIM_DEVICE_ID 0x04
37 #define CONFIG_FLEXONENAND ((CONFIG_ONENAND_SIM_DEVICE_ID >> 9) & 1)
39 #ifndef CONFIG_ONENAND_SIM_VERSION_ID
40 #define CONFIG_ONENAND_SIM_VERSION_ID 0x1e
43 #ifndef CONFIG_ONENAND_SIM_TECHNOLOGY_ID
44 #define CONFIG_ONENAND_SIM_TECHNOLOGY_ID CONFIG_FLEXONENAND
48 #ifndef CONFIG_FLEXONENAND_SIM_DIE0_BOUNDARY
49 #define CONFIG_FLEXONENAND_SIM_DIE0_BOUNDARY 0x01
52 #ifndef CONFIG_FLEXONENAND_SIM_DIE1_BOUNDARY
53 #define CONFIG_FLEXONENAND_SIM_DIE1_BOUNDARY 0x01
60 static int boundary[] = {
70 #define ONENAND_CORE(flash) (flash->data)
71 #define ONENAND_CORE_SPARE(flash, this, offset) \
72 ((flash->data) + (this->chipsize) + (offset >> 5))
74 #define ONENAND_MAIN_AREA(this, offset) \
75 (this->base + ONENAND_DATARAM + offset)
77 #define ONENAND_SPARE_AREA(this, offset) \
78 (this->base + ONENAND_SPARERAM + offset)
80 #define ONENAND_GET_WP_STATUS(this) \
81 (readw(this->base + ONENAND_REG_WP_STATUS))
83 #define ONENAND_SET_WP_STATUS(v, this) \
84 (writew(v, this->base + ONENAND_REG_WP_STATUS))
87 #define MAX_ONENAND_PAGESIZE (4096 + 128)
88 static unsigned char *ffchars;
90 #if CONFIG_FLEXONENAND
91 #define PARTITION_NAME "Flex-OneNAND simulator partition"
93 #define PARTITION_NAME "OneNAND simulator partition"
116 #define DPRINTK(format, args...) \
118 printk(KERN_DEBUG "%s[%d]: " format "\n", __func__, \
132 int block_lock_scheme;
141 if (block_lock_scheme)
148 if (block_lock_scheme)
155 if (block_lock_scheme)
177 writew(manuf_id, this->base);
195 static void onenand_update_interrupt(
struct onenand_chip *
this,
int cmd)
235 static int onenand_check_overwrite(
void *
dest,
void *
src,
size_t count)
237 unsigned int *
s = (
unsigned int *) src;
238 unsigned int *
d = (
unsigned int *) dest;
242 for (i = 0; i <
count; i++)
243 if ((*s++ ^ *d++) != 0)
260 static void onenand_data_handle(
struct onenand_chip *
this,
int cmd,
261 int dataram,
unsigned int offset)
265 int main_offset, spare_offset,
die = 0;
269 static int pi_operation;
319 int off = i * this->subpagesize;
320 if (!
memcmp(src + off, ffchars, this->subpagesize))
322 if (
memcmp(dest + off, ffchars, this->subpagesize) &&
323 onenand_check_overwrite(dest + off, src + off, this->subpagesize))
325 memcpy(dest + off, src + off, this->subpagesize);
337 onenand_check_overwrite(dest, src, mtd->
oobsize))
370 static void onenand_command_handle(
struct onenand_chip *
this,
int cmd)
372 unsigned long offset = 0;
381 onenand_lock_handle(
this, cmd);
393 block += this->chipsize >> (this->erase_shift + 1);
411 offset +=
page << this->page_shift;
413 onenand_data_handle(
this, cmd, dataram, offset);
415 onenand_update_interrupt(
this, cmd);
431 onenand_bootram_handle(
this, value);
436 onenand_command_handle(
this, value);
460 size = ((16 << 20) << density);
478 buffer_size = 0x0400;
480 buffer_size = 0x0800;
498 static int __init onenand_sim_init(
void)
517 info->
onenand.write_word = onenand_writew;
526 info->
parts = os_partitions;
531 info->
mtd.name =
"OneNAND simulator";
536 flash_exit(&info->
flash);
548 static void __exit onenand_sim_exit(
void)