2 * (C) Copyright 2008 Stefan Roese <sr@denx.de>, DENX Software Engineering
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of
7 * the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 static u32 ebi_read(u32 addr)
28 reg_write(EBI_CPU_IO_ACCS(EBI_BASE), EXT_DEVICE_CHANNEL_2 | addr);
31 return reg_read(EBI_IO_ACCS_DATA(EBI_BASE));
34 static int ebi_write_u16(u32 addr, u32 data, int fetchIO)
36 u32 val = (data << 16);
42 reg_write(EBI_IO_ACCS_DATA(EBI_BASE), val);
43 reg_write(EBI_CPU_IO_ACCS(EBI_BASE),
44 EXT_DEVICE_CHANNEL_2 | EBI_CPU_WRITE | addr);
49 while (!(reg_read(EBI_SIG_LEVEL(EBI_BASE)) & EXT_CPU_IORDY_SL)) {
50 if (counter++ > 0xFFFFFF)
58 static u16 ebi_read_u16(u32 addr)
60 return ((ebi_read(addr) >> 16) & 0xFFFF);
63 static u8 ebi_read_u8(u32 addr)
65 u32 val = ebi_read(addr) >> 16;
70 return (val >> 8) & 0xff;
74 * EBI initialization for NOR FLASH access
76 int ebi_init_nor_flash(void)
78 reg_write(EBI_DEV1_CONFIG1(EBI_BASE), 0x83000);
80 reg_write(EBI_DEV2_CONFIG1(EBI_BASE), 0x400002);
81 reg_write(EBI_DEV2_CONFIG2(EBI_BASE), 0x50);
83 reg_write(EBI_DEV2_TIM1_RD1(EBI_BASE), 0x409113);
84 reg_write(EBI_DEV2_TIM1_RD2(EBI_BASE), 0xFF01000);
85 reg_write(EBI_DEV2_TIM1_WR1(EBI_BASE), 0x04003113);
86 reg_write(EBI_DEV2_TIM1_WR2(EBI_BASE), 0x3FC12011);
87 reg_write(EBI_DEV2_TIM_EXT(EBI_BASE), 0xFFF00000);
93 * Accessor functions replacing the "weak" functions in
94 * drivers/mtd/cfi_flash.c
96 void flash_write8(u8 value, void *addr)
98 ebi_write_u16((u32)addr, value, 0);
101 void flash_write16(u16 value, void *addr)
103 ebi_write_u16((u32)addr, value, 0);
106 u8 flash_read8(void *addr)
108 return ebi_read_u8((u32)addr);
111 u16 flash_read16(void *addr)
113 return ebi_read_u16((u32)addr);
116 u32 flash_read32(void *addr)
118 return ((u32)ebi_read_u16((u32)addr) << 16) |
119 ebi_read_u16((u32)addr + 2);
122 void *board_flash_read_memcpy(void *dest, const void *src, size_t count)
124 u16 *tmp = (u16 *)dest, *s = (u16 *)src;
127 for (i = 0; i < count; i += 2)
128 *tmp++ = flash_read16(s++);