blob: 80fbc847b40909c4f874a89197067c9cdf2488b3 [file] [log] [blame]
Stefan Roese9182d2f2009-01-21 17:24:39 +01001/*
2 * (C) Copyright 2008 Stefan Roese <sr@denx.de>, DENX Software Engineering
3 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Stefan Roese9182d2f2009-01-21 17:24:39 +01005 */
6
7#include <common.h>
8#include <asm/io.h>
9#include "vct.h"
10
11static u32 ebi_read(u32 addr)
12{
13 addr &= ~0xFC000000;
14
15 reg_write(EBI_CPU_IO_ACCS(EBI_BASE), EXT_DEVICE_CHANNEL_2 | addr);
16 ebi_wait();
17
18 return reg_read(EBI_IO_ACCS_DATA(EBI_BASE));
19}
20
21static int ebi_write_u16(u32 addr, u32 data, int fetchIO)
22{
23 u32 val = (data << 16);
24
25 addr &= ~0xFC000000;
26
27 ebi_wait();
28
29 reg_write(EBI_IO_ACCS_DATA(EBI_BASE), val);
30 reg_write(EBI_CPU_IO_ACCS(EBI_BASE),
31 EXT_DEVICE_CHANNEL_2 | EBI_CPU_WRITE | addr);
32 ebi_wait();
33
34 if (fetchIO) {
35 u32 counter = 0;
36 while (!(reg_read(EBI_SIG_LEVEL(EBI_BASE)) & EXT_CPU_IORDY_SL)) {
37 if (counter++ > 0xFFFFFF)
38 return 1;
39 }
40 }
41
42 return 0;
43}
44
45static u16 ebi_read_u16(u32 addr)
46{
47 return ((ebi_read(addr) >> 16) & 0xFFFF);
48}
49
50static u8 ebi_read_u8(u32 addr)
51{
52 u32 val = ebi_read(addr) >> 16;
53
54 if (addr & 0x1)
55 return val & 0xff;
56 else
57 return (val >> 8) & 0xff;
58}
59
60/*
61 * EBI initialization for NOR FLASH access
62 */
63int ebi_init_nor_flash(void)
64{
65 reg_write(EBI_DEV1_CONFIG1(EBI_BASE), 0x83000);
66
67 reg_write(EBI_DEV2_CONFIG1(EBI_BASE), 0x400002);
68 reg_write(EBI_DEV2_CONFIG2(EBI_BASE), 0x50);
69
70 reg_write(EBI_DEV2_TIM1_RD1(EBI_BASE), 0x409113);
71 reg_write(EBI_DEV2_TIM1_RD2(EBI_BASE), 0xFF01000);
72 reg_write(EBI_DEV2_TIM1_WR1(EBI_BASE), 0x04003113);
73 reg_write(EBI_DEV2_TIM1_WR2(EBI_BASE), 0x3FC12011);
74 reg_write(EBI_DEV2_TIM_EXT(EBI_BASE), 0xFFF00000);
75
76 return 0;
77}
78
79/*
80 * Accessor functions replacing the "weak" functions in
81 * drivers/mtd/cfi_flash.c
82 */
83void flash_write8(u8 value, void *addr)
84{
85 ebi_write_u16((u32)addr, value, 0);
86}
87
88void flash_write16(u16 value, void *addr)
89{
90 ebi_write_u16((u32)addr, value, 0);
91}
92
93u8 flash_read8(void *addr)
94{
95 return ebi_read_u8((u32)addr);
96}
97
98u16 flash_read16(void *addr)
99{
100 return ebi_read_u16((u32)addr);
101}
102
103u32 flash_read32(void *addr)
104{
105 return ((u32)ebi_read_u16((u32)addr) << 16) |
106 ebi_read_u16((u32)addr + 2);
107}
108
109void *board_flash_read_memcpy(void *dest, const void *src, size_t count)
110{
111 u16 *tmp = (u16 *)dest, *s = (u16 *)src;
112 int i;
113
114 for (i = 0; i < count; i += 2)
115 *tmp++ = flash_read16(s++);
116
117 return dest;
118}