]> git.ipfire.org Git - people/ms/u-boot.git/blob - onenand_ipl/onenand_read.c
Merge branch 'master' of git://www.denx.de/git/u-boot-sh
[people/ms/u-boot.git] / onenand_ipl / onenand_read.c
1 /*
2 * (C) Copyright 2005-2008 Samsung Electronis
3 * Kyungmin Park <kyungmin.park@samsung.com>
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24 #include <common.h>
25
26 #include <asm/io.h>
27 #include <asm/string.h>
28
29 #include "onenand_ipl.h"
30
31 #define onenand_block_address(block) (block)
32 #define onenand_sector_address(page) (page << 2)
33 #define onenand_buffer_address() ((1 << 3) << 8)
34 #define onenand_bufferram_address(block) (0)
35
36 /* read a page with ECC */
37 static inline int onenand_read_page(ulong block, ulong page, u_char *buf)
38 {
39 unsigned long *base;
40
41 #ifndef __HAVE_ARCH_MEMCPY32
42 unsigned int offset, value;
43 unsigned long *p;
44 #endif
45
46 onenand_writew(onenand_block_address(block),
47 THIS_ONENAND(ONENAND_REG_START_ADDRESS1));
48
49 onenand_writew(onenand_sector_address(page),
50 THIS_ONENAND(ONENAND_REG_START_ADDRESS8));
51
52 onenand_writew(onenand_buffer_address(),
53 THIS_ONENAND(ONENAND_REG_START_BUFFER));
54
55 onenand_writew(onenand_bufferram_address(block),
56 THIS_ONENAND(ONENAND_REG_START_ADDRESS2));
57
58 onenand_writew(ONENAND_INT_CLEAR, THIS_ONENAND(ONENAND_REG_INTERRUPT));
59
60 onenand_writew(ONENAND_CMD_READ, THIS_ONENAND(ONENAND_REG_COMMAND));
61
62 #ifndef __HAVE_ARCH_MEMCPY32
63 p = (unsigned long *) buf;
64 #endif
65 base = (unsigned long *) (CFG_ONENAND_BASE + ONENAND_DATARAM);
66
67 while (!(READ_INTERRUPT() & ONENAND_INT_READ))
68 continue;
69
70 #ifdef __HAVE_ARCH_MEMCPY32
71 /* 32 bytes boundary memory copy */
72 memcpy32(buf, base, ONENAND_PAGE_SIZE);
73 #else
74 for (offset = 0; offset < (ONENAND_PAGE_SIZE >> 2); offset++) {
75 value = *(base + offset);
76 *p++ = value;
77 }
78 #endif
79
80 return 0;
81 }
82
83 #define ONENAND_START_PAGE 1
84 #define ONENAND_PAGES_PER_BLOCK 64
85
86 /**
87 * onenand_read_block - Read a block data to buf
88 * @return 0 on success
89 */
90 int onenand_read_block(unsigned char *buf, ulong block)
91 {
92 int page, offset = 0;
93
94 /* NOTE: you must read page from page 1 of block 0 */
95 /* read the block page by page*/
96 for (page = ONENAND_START_PAGE;
97 page < ONENAND_PAGES_PER_BLOCK; page++) {
98
99 onenand_read_page(block, page, buf + offset);
100
101 offset += ONENAND_PAGE_SIZE;
102 }
103
104 return 0;
105 }