2008-02-29 12:37:45 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2007, 2008 by Ben Dooks *
|
|
|
|
* ben@fluff.org *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the *
|
|
|
|
* Free Software Foundation, Inc., *
|
2013-06-02 19:32:36 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
|
2008-02-29 12:37:45 +00:00
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
/*
|
2008-02-19 19:52:09 +00:00
|
|
|
* S3C2410 OpenOCD NAND Flash controller support.
|
|
|
|
*
|
|
|
|
* Many thanks to Simtec Electronics for sponsoring this work.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2009-12-02 06:37:11 +00:00
|
|
|
#include "s3c24xx.h"
|
2009-05-11 04:30:41 +00:00
|
|
|
|
2009-11-10 08:53:40 +00:00
|
|
|
NAND_DEVICE_COMMAND_HANDLER(s3c2410_nand_device_command)
|
2008-02-19 19:52:09 +00:00
|
|
|
{
|
2009-11-13 15:38:52 +00:00
|
|
|
struct s3c24xx_nand_controller *info;
|
2009-11-10 13:32:51 +00:00
|
|
|
CALL_S3C24XX_DEVICE_COMMAND(nand, &info);
|
2008-02-19 19:52:09 +00:00
|
|
|
|
|
|
|
/* fill in the address fields for the core device */
|
|
|
|
info->cmd = S3C2410_NFCMD;
|
|
|
|
info->addr = S3C2410_NFADDR;
|
|
|
|
info->data = S3C2410_NFDATA;
|
|
|
|
info->nfstat = S3C2410_NFSTAT;
|
2009-05-18 04:37:33 +00:00
|
|
|
|
2008-02-19 19:52:09 +00:00
|
|
|
return ERROR_OK;
|
|
|
|
}
|
|
|
|
|
2009-11-13 19:32:17 +00:00
|
|
|
static int s3c2410_init(struct nand_device *nand)
|
2008-02-19 19:52:09 +00:00
|
|
|
{
|
2010-12-31 11:46:09 +00:00
|
|
|
struct target *target = nand->target;
|
2008-02-19 19:52:09 +00:00
|
|
|
|
2009-05-18 04:37:33 +00:00
|
|
|
target_write_u32(target, S3C2410_NFCONF,
|
2008-02-19 19:52:09 +00:00
|
|
|
S3C2410_NFCONF_EN | S3C2410_NFCONF_TACLS(3) |
|
|
|
|
S3C2410_NFCONF_TWRPH0(5) | S3C2410_NFCONF_TWRPH1(3));
|
|
|
|
|
|
|
|
return ERROR_OK;
|
|
|
|
}
|
|
|
|
|
2009-11-13 19:32:17 +00:00
|
|
|
static int s3c2410_write_data(struct nand_device *nand, uint16_t data)
|
2008-02-19 19:52:09 +00:00
|
|
|
{
|
2010-12-31 11:46:09 +00:00
|
|
|
struct target *target = nand->target;
|
2008-02-19 19:52:09 +00:00
|
|
|
|
|
|
|
if (target->state != TARGET_HALTED) {
|
2008-03-25 15:45:17 +00:00
|
|
|
LOG_ERROR("target must be halted to use S3C24XX NAND flash controller");
|
2008-02-19 19:52:09 +00:00
|
|
|
return ERROR_NAND_OPERATION_FAILED;
|
|
|
|
}
|
2009-05-18 04:37:33 +00:00
|
|
|
|
2008-02-19 19:52:09 +00:00
|
|
|
target_write_u32(target, S3C2410_NFDATA, data);
|
|
|
|
return ERROR_OK;
|
|
|
|
}
|
|
|
|
|
2009-11-13 19:32:17 +00:00
|
|
|
static int s3c2410_read_data(struct nand_device *nand, void *data)
|
2008-02-19 19:52:09 +00:00
|
|
|
{
|
2010-12-31 11:46:09 +00:00
|
|
|
struct target *target = nand->target;
|
2009-05-18 04:37:33 +00:00
|
|
|
|
2008-02-19 19:52:09 +00:00
|
|
|
if (target->state != TARGET_HALTED) {
|
2008-03-25 15:45:17 +00:00
|
|
|
LOG_ERROR("target must be halted to use S3C24XX NAND flash controller");
|
2008-02-19 19:52:09 +00:00
|
|
|
return ERROR_NAND_OPERATION_FAILED;
|
|
|
|
}
|
|
|
|
|
2009-05-18 04:37:33 +00:00
|
|
|
target_read_u8(target, S3C2410_NFDATA, data);
|
2008-02-19 19:52:09 +00:00
|
|
|
return ERROR_OK;
|
|
|
|
}
|
|
|
|
|
2009-11-13 19:32:17 +00:00
|
|
|
static int s3c2410_nand_ready(struct nand_device *nand, int timeout)
|
2008-02-19 19:52:09 +00:00
|
|
|
{
|
2010-12-31 11:46:09 +00:00
|
|
|
struct target *target = nand->target;
|
2009-06-18 07:06:25 +00:00
|
|
|
uint8_t status;
|
2008-02-19 19:52:09 +00:00
|
|
|
|
|
|
|
if (target->state != TARGET_HALTED) {
|
2008-03-25 15:45:17 +00:00
|
|
|
LOG_ERROR("target must be halted to use S3C24XX NAND flash controller");
|
2008-02-19 19:52:09 +00:00
|
|
|
return ERROR_NAND_OPERATION_FAILED;
|
|
|
|
}
|
2009-05-18 04:37:33 +00:00
|
|
|
|
2008-02-19 19:52:09 +00:00
|
|
|
do {
|
|
|
|
target_read_u8(target, S3C2410_NFSTAT, &status);
|
2009-05-18 04:37:33 +00:00
|
|
|
|
2008-02-19 19:52:09 +00:00
|
|
|
if (status & S3C2410_NFSTAT_BUSY)
|
|
|
|
return 1;
|
|
|
|
|
2009-05-18 04:37:33 +00:00
|
|
|
alive_sleep(1);
|
2008-02-19 19:52:09 +00:00
|
|
|
} while (timeout-- > 0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2009-11-09 17:20:33 +00:00
|
|
|
|
2009-11-13 15:38:30 +00:00
|
|
|
struct nand_flash_controller s3c2410_nand_controller = {
|
2012-01-31 11:07:53 +00:00
|
|
|
.name = "s3c2410",
|
|
|
|
.nand_device_command = &s3c2410_nand_device_command,
|
|
|
|
.init = &s3c2410_init,
|
|
|
|
.reset = &s3c24xx_reset,
|
|
|
|
.command = &s3c24xx_command,
|
|
|
|
.address = &s3c24xx_address,
|
|
|
|
.write_data = &s3c2410_write_data,
|
|
|
|
.read_data = &s3c2410_read_data,
|
|
|
|
.write_page = s3c24xx_write_page,
|
|
|
|
.read_page = s3c24xx_read_page,
|
|
|
|
.nand_ready = &s3c2410_nand_ready,
|
|
|
|
};
|