1 /***************************************************************************
2 * Copyright (C) 2007, 2008 by Ben Dooks *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17 ***************************************************************************/
20 * S3C24XX Series OpenOCD NAND Flash controller support.
22 * Many thanks to Simtec Electronics for sponsoring this work.
31 S3C24XX_DEVICE_COMMAND()
35 struct s3c24xx_nand_controller *s3c24xx_info;
36 s3c24xx_info = malloc(sizeof(struct s3c24xx_nand_controller));
37 if (s3c24xx_info == NULL) {
38 LOG_ERROR("no memory for nand controller");
42 nand->controller_priv = s3c24xx_info;
48 int s3c24xx_reset(struct nand_device *nand)
50 struct s3c24xx_nand_controller *s3c24xx_info = nand->controller_priv;
51 struct target *target = nand->target;
53 if (target->state != TARGET_HALTED) {
54 LOG_ERROR("target must be halted to use S3C24XX NAND flash controller");
55 return ERROR_NAND_OPERATION_FAILED;
58 target_write_u32(target, s3c24xx_info->cmd, 0xff);
63 int s3c24xx_command(struct nand_device *nand, uint8_t command)
65 struct s3c24xx_nand_controller *s3c24xx_info = nand->controller_priv;
66 struct target *target = nand->target;
68 if (target->state != TARGET_HALTED) {
69 LOG_ERROR("target must be halted to use S3C24XX NAND flash controller");
70 return ERROR_NAND_OPERATION_FAILED;
73 target_write_u16(target, s3c24xx_info->cmd, command);
77 int s3c24xx_address(struct nand_device *nand, uint8_t address)
79 struct s3c24xx_nand_controller *s3c24xx_info = nand->controller_priv;
80 struct target *target = nand->target;
82 if (target->state != TARGET_HALTED) {
83 LOG_ERROR("target must be halted to use S3C24XX NAND flash controller");
84 return ERROR_NAND_OPERATION_FAILED;
87 target_write_u16(target, s3c24xx_info->addr, address);
91 int s3c24xx_write_data(struct nand_device *nand, uint16_t data)
93 struct s3c24xx_nand_controller *s3c24xx_info = nand->controller_priv;
94 struct target *target = nand->target;
96 if (target->state != TARGET_HALTED) {
97 LOG_ERROR("target must be halted to use S3C24XX NAND flash controller");
98 return ERROR_NAND_OPERATION_FAILED;
101 target_write_u8(target, s3c24xx_info->data, data);
105 int s3c24xx_read_data(struct nand_device *nand, void *data)
107 struct s3c24xx_nand_controller *s3c24xx_info = nand->controller_priv;
108 struct target *target = nand->target;
110 if (target->state != TARGET_HALTED) {
111 LOG_ERROR("target must be halted to use S3C24XX NAND flash controller");
112 return ERROR_NAND_OPERATION_FAILED;
115 target_read_u8(target, s3c24xx_info->data, data);