Remove FSF address from GPL notices
[fw/openocd] / src / flash / nand / s3c24xx.c
1 /***************************************************************************
2  *   Copyright (C) 2007, 2008 by Ben Dooks                                 *
3  *   ben@fluff.org                                                         *
4  *                                                                         *
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.                                   *
9  *                                                                         *
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.                          *
14  *                                                                         *
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  ***************************************************************************/
18
19 /*
20  * S3C24XX Series OpenOCD NAND Flash controller support.
21  *
22  * Many thanks to Simtec Electronics for sponsoring this work.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 #endif
28
29 #include "s3c24xx.h"
30
31 S3C24XX_DEVICE_COMMAND()
32 {
33         *info = NULL;
34
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");
39                 return -ENOMEM;
40         }
41
42         nand->controller_priv = s3c24xx_info;
43         *info = s3c24xx_info;
44
45         return ERROR_OK;
46 }
47
48 int s3c24xx_reset(struct nand_device *nand)
49 {
50         struct s3c24xx_nand_controller *s3c24xx_info = nand->controller_priv;
51         struct target *target = nand->target;
52
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;
56         }
57
58         target_write_u32(target, s3c24xx_info->cmd, 0xff);
59
60         return ERROR_OK;
61 }
62
63 int s3c24xx_command(struct nand_device *nand, uint8_t command)
64 {
65         struct s3c24xx_nand_controller *s3c24xx_info = nand->controller_priv;
66         struct target *target = nand->target;
67
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;
71         }
72
73         target_write_u16(target, s3c24xx_info->cmd, command);
74         return ERROR_OK;
75 }
76
77 int s3c24xx_address(struct nand_device *nand, uint8_t address)
78 {
79         struct s3c24xx_nand_controller *s3c24xx_info = nand->controller_priv;
80         struct target *target = nand->target;
81
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;
85         }
86
87         target_write_u16(target, s3c24xx_info->addr, address);
88         return ERROR_OK;
89 }
90
91 int s3c24xx_write_data(struct nand_device *nand, uint16_t data)
92 {
93         struct s3c24xx_nand_controller *s3c24xx_info = nand->controller_priv;
94         struct target *target = nand->target;
95
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;
99         }
100
101         target_write_u8(target, s3c24xx_info->data, data);
102         return ERROR_OK;
103 }
104
105 int s3c24xx_read_data(struct nand_device *nand, void *data)
106 {
107         struct s3c24xx_nand_controller *s3c24xx_info = nand->controller_priv;
108         struct target *target = nand->target;
109
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;
113         }
114
115         target_read_u8(target, s3c24xx_info->data, data);
116         return ERROR_OK;
117 }