* Dominic.Rath@gmx.de *
* *
* partially based on *
- * drivers/mtd/nand_ids.c *
+ * drivers/mtd/nand_ids.c *
* *
* Copyright (C) 2002 Thomas Gleixner (tglx@linutronix.de) *
* *
#include <stdlib.h>
#include <string.h>
+#include <inttypes.h>
#include <errno.h>
/* NAND flash controller
*/
extern nand_flash_controller_t lpc3180_nand_controller;
-/* extern nand_flash_controller_t s3c2410_nand_controller; */
+extern nand_flash_controller_t s3c2410_nand_controller;
+extern nand_flash_controller_t s3c2412_nand_controller;
+extern nand_flash_controller_t s3c2440_nand_controller;
+extern nand_flash_controller_t s3c2443_nand_controller;
+
/* extern nand_flash_controller_t boundary_scan_nand_controller; */
nand_flash_controller_t *nand_flash_controllers[] =
{
&lpc3180_nand_controller,
-/* &s3c2410_nand_controller, */
+ &s3c2410_nand_controller,
+ &s3c2412_nand_controller,
+ &s3c2440_nand_controller,
+ &s3c2443_nand_controller,
/* &boundary_scan_nand_controller, */
NULL
};
int nand_register_commands(struct command_context_s *cmd_ctx)
{
- nand_cmd = register_command(cmd_ctx, NULL, "nand", NULL, COMMAND_ANY, NULL);
+ nand_cmd = register_command(cmd_ctx, NULL, "nand", NULL, COMMAND_ANY, "NAND specific commands");
register_command(cmd_ctx, nand_cmd, "device", handle_nand_device_command, COMMAND_CONFIG, NULL);
int nand_probe(struct nand_device_s *device)
{
u8 manufacturer_id, device_id;
+ u8 id_buff[5];
int retval;
int i;
device->bus_width = 16;
else
device->bus_width = 8;
+
+ /* Do we need extended device probe information? */
+ if (device->device->page_size == 0 ||
+ device->device->erase_size == 0)
+ {
+ if (device->bus_width == 8)
+ {
+ device->controller->read_data(device, id_buff+3);
+ device->controller->read_data(device, id_buff+4);
+ device->controller->read_data(device, id_buff+5);
+ }
+ else
+ {
+ u16 data_buf;
+
+ device->controller->read_data(device, &data_buf);
+ id_buff[3] = data_buf;
+
+ device->controller->read_data(device, &data_buf);
+ id_buff[4] = data_buf;
+
+ device->controller->read_data(device, &data_buf);
+ id_buff[5] = data_buf >> 8;
+ }
+ }
/* page size */
if (device->device->page_size == 0)
{
- /* TODO: support reading extended chip id to determine page size */
- return ERROR_NAND_OPERATION_FAILED;
+ device->page_size = 1 << (10 + (id_buff[4] & 3));
}
else if (device->device->page_size == 256)
{
/* erase size */
if (device->device->erase_size == 0)
{
- /* TODO: support reading extended chip id to determine erase size */
+ switch ((id_buff[4] >> 4) & 3) {
+ case 0:
+ device->erase_size = 64 << 10;
+ break;
+ case 1:
+ device->erase_size = 128 << 10;
+ break;
+ case 2:
+ device->erase_size = 256 << 10;
+ break;
+ case 3:
+ device->erase_size =512 << 10;
+ break;
+ }
}
else
{
if (!device->device)
return ERROR_NAND_DEVICE_NOT_PROBED;
- if (device->use_raw)
+ if (device->use_raw || device->controller->write_page == NULL)
return nand_write_page_raw(device, page, data, data_size, oob, oob_size);
else
return device->controller->write_page(device, page, data, data_size, oob, oob_size);
if (!device->device)
return ERROR_NAND_DEVICE_NOT_PROBED;
- if (device->use_raw)
+ if (device->use_raw || device->controller->read_page == NULL)
return nand_read_page_raw(device, page, data, data_size, oob, oob_size);
else
return device->controller->read_page(device, page, data, data_size, oob, oob_size);
if (data)
{
- for (i = 0; i < data_size;)
+ if (device->controller->read_block_data != NULL)
+ (device->controller->read_block_data)(device, data, data_size);
+ else
{
- if (device->device->options & NAND_BUSWIDTH_16)
+ for (i = 0; i < data_size;)
{
- device->controller->read_data(device, data);
- data += 2;
- i += 2;
- }
- else
- {
- device->controller->read_data(device, data);
- data += 1;
- i += 1;
+ if (device->device->options & NAND_BUSWIDTH_16)
+ {
+ device->controller->read_data(device, data);
+ data += 2;
+ i += 2;
+ }
+ else
+ {
+ device->controller->read_data(device, data);
+ data += 1;
+ i += 1;
+ }
}
}
}
if (oob)
{
- for (i = 0; i < oob_size;)
+ if (device->controller->read_block_data != NULL)
+ (device->controller->read_block_data)(device, oob, oob_size);
+ else
{
- if (device->device->options & NAND_BUSWIDTH_16)
- {
- device->controller->read_data(device, oob);
- oob += 2;
- i += 2;
- }
- else
+ for (i = 0; i < oob_size;)
{
- device->controller->read_data(device, oob);
- oob += 1;
- i += 1;
+ if (device->device->options & NAND_BUSWIDTH_16)
+ {
+ device->controller->read_data(device, oob);
+ oob += 2;
+ i += 2;
+ }
+ else
+ {
+ device->controller->read_data(device, oob);
+ oob += 1;
+ i += 1;
+ }
}
}
}
if (data)
{
- for (i = 0; i < data_size;)
+ if (device->controller->write_block_data != NULL)
+ (device->controller->write_block_data)(device, data, data_size);
+ else
{
- if (device->device->options & NAND_BUSWIDTH_16)
+ for (i = 0; i < data_size;)
{
- u16 data_buf = le_to_h_u16(data);
- device->controller->write_data(device, data_buf);
- data += 2;
- i += 2;
- }
- else
- {
- device->controller->write_data(device, *data);
- data += 1;
- i += 1;
+ if (device->device->options & NAND_BUSWIDTH_16)
+ {
+ u16 data_buf = le_to_h_u16(data);
+ device->controller->write_data(device, data_buf);
+ data += 2;
+ i += 2;
+ }
+ else
+ {
+ device->controller->write_data(device, *data);
+ data += 1;
+ i += 1;
+ }
}
}
}
if (oob)
{
- for (i = 0; i < oob_size;)
+ if (device->controller->write_block_data != NULL)
+ (device->controller->write_block_data)(device, oob, oob_size);
+ else
{
- if (device->device->options & NAND_BUSWIDTH_16)
+ for (i = 0; i < oob_size;)
{
- u16 oob_buf = le_to_h_u16(data);
- device->controller->write_data(device, oob_buf);
- oob += 2;
- i += 2;
- }
- else
- {
- device->controller->write_data(device, *oob);
- oob += 1;
- i += 1;
+ if (device->device->options & NAND_BUSWIDTH_16)
+ {
+ u16 oob_buf = le_to_h_u16(data);
+ device->controller->write_data(device, oob_buf);
+ oob += 2;
+ i += 2;
+ }
+ else
+ {
+ device->controller->write_data(device, *oob);
+ oob += 1;
+ i += 1;
+ }
}
}
}
fileio_close(&fileio);
duration_stop_measure(&duration, &duration_text);
- command_print(cmd_ctx, "dumped %lli byte in %s", fileio.size, duration_text);
+ command_print(cmd_ctx, "dumped %"PRIi64" byte in %s", fileio.size, duration_text);
free(duration_text);
}
else