]> git.sur5r.net Git - openocd/blob - src/flash/s3c2412_nand.c
1ddcff04eab2bb9d1c74f69baf6700e33f0f1b1c
[openocd] / src / flash / s3c2412_nand.c
1 /* src/flash/s3c2412_nand.c
2  *
3  * S3C2412 OpenOCD NAND Flash controller support.
4  *
5  * Copyright 2007,2008 Ben Dooks <ben@fluff.org>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * Many thanks to Simtec Electronics for sponsoring this work.
13  */
14
15 #ifdef HAVE_CONFIG_H
16 #include "config.h"
17 #endif
18
19 #include "replacements.h"
20 #include "log.h"
21
22 #include <stdlib.h>
23 #include <string.h>
24
25 #include "nand.h"
26 #include "s3c24xx_nand.h"
27 #include "target.h"
28
29 int s3c2412_nand_device_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct nand_device_s *device);
30 int s3c2412_init(struct nand_device_s *device);
31
32 nand_flash_controller_t s3c2412_nand_controller =
33 {
34         .name                   = "s3c2412",
35         .nand_device_command    = s3c2412_nand_device_command,
36         .register_commands      = s3c24xx_register_commands,
37         .init                   = s3c2412_init,
38         .reset                  = s3c24xx_reset,
39         .command                = s3c24xx_command,
40         .address                = s3c24xx_address,
41         .write_data             = s3c24xx_write_data,
42         .read_data              = s3c24xx_read_data,
43         .write_page             = s3c24xx_write_page,
44         .read_page              = s3c24xx_read_page,
45         .write_block_data       = s3c2440_write_block_data,
46         .read_block_data        = s3c2440_read_block_data,
47         .controller_ready       = s3c24xx_controller_ready,
48         .nand_ready             = s3c2440_nand_ready,
49 };
50
51 int s3c2412_nand_device_command(struct command_context_s *cmd_ctx, char *cmd,
52                                 char **args, int argc,
53                                 struct nand_device_s *device)
54 {
55         s3c24xx_nand_controller_t *info;
56
57         info = s3c24xx_nand_device_command(cmd_ctx, cmd, args, argc, device);
58         if (info == NULL) {
59                 return ERROR_NAND_DEVICE_INVALID;
60         }
61
62         /* fill in the address fields for the core device */
63         info->cmd = S3C2440_NFCMD;
64         info->addr = S3C2440_NFADDR;
65         info->data = S3C2440_NFDATA;
66         info->nfstat = S3C2412_NFSTAT;
67         
68         return ERROR_OK;
69 }
70
71 int s3c2412_init(struct nand_device_s *device)
72 {
73         s3c24xx_nand_controller_t *s3c24xx_info = device->controller_priv;
74         target_t *target = s3c24xx_info->target;
75
76         target_write_u32(target, S3C2410_NFCONF,
77                          S3C2440_NFCONF_TACLS(3) |
78                          S3C2440_NFCONF_TWRPH0(7) |
79                          S3C2440_NFCONF_TWRPH1(7));
80
81         target_write_u32(target, S3C2440_NFCONT,
82                          S3C2412_NFCONT_INIT_MAIN_ECC |
83                          S3C2440_NFCONT_ENABLE);
84
85         return ERROR_OK;
86 }