e1b67a075b7eb0ba6e61df7cc78f22dbe0b7f696
[platform/kernel/u-boot.git] / board / micronas / vct / ebi_smc911x.c
1 /*
2  * (C) Copyright 2008 Stefan Roese <sr@denx.de>, DENX Software Engineering
3  *
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.
8  *
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.
13  *
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,
17  * MA 02111-1307 USA
18  */
19
20 #include <common.h>
21 #include <asm/io.h>
22 #include "vct.h"
23
24 /*
25  * EBI initialization for SMC911x access
26  */
27 int ebi_init_smc911x(void)
28 {
29         reg_write(EBI_DEV1_CONFIG1(EBI_BASE), 0x00003020);
30         reg_write(EBI_DEV1_CONFIG2(EBI_BASE), 0x0000004F);
31
32         reg_write(EBI_DEV1_TIM1_RD1(EBI_BASE), 0x00501100);
33         reg_write(EBI_DEV1_TIM1_RD2(EBI_BASE), 0x0FF02111);
34
35         reg_write(EBI_DEV1_TIM_EXT(EBI_BASE), 0xFFF00000);
36         reg_write(EBI_DEV1_EXT_ACC(EBI_BASE), 0x0FFFFFFF);
37
38         reg_write(EBI_DEV1_TIM1_WR1(EBI_BASE), 0x05001100);
39         reg_write(EBI_DEV1_TIM1_WR2(EBI_BASE), 0x3FC21110);
40
41         return 0;
42 }
43
44 /*
45  * Accessor functions replacing the "weak" functions in
46  * drivers/net/smc911x.c
47  */
48 u32 smc911x_reg_read(u32 addr)
49 {
50         volatile u32 data;
51
52         reg_write(EBI_DEV1_CONFIG2(EBI_BASE), 0x0000004F);
53         ebi_wait();
54         reg_write(EBI_CPU_IO_ACCS(EBI_BASE), (EXT_DEVICE_CHANNEL_1 | addr));
55         ebi_wait();
56         data = reg_read(EBI_IO_ACCS_DATA(EBI_BASE));
57
58         return (data);
59 }
60
61 void smc911x_reg_write(u32 addr, u32 data)
62 {
63         reg_write(EBI_DEV1_CONFIG2(EBI_BASE), 0x0000004F);
64         ebi_wait();
65         reg_write(EBI_IO_ACCS_DATA(EBI_BASE), data);
66         reg_write(EBI_CPU_IO_ACCS(EBI_BASE),
67                   EXT_DEVICE_CHANNEL_1 | EBI_CPU_WRITE | addr);
68         ebi_wait();
69 }
70
71 void pkt_data_push(u32 addr, u32 data)
72 {
73         reg_write(EBI_DEV1_CONFIG2(EBI_BASE), 0x0000004A);
74         ebi_wait();
75         reg_write(EBI_IO_ACCS_DATA(EBI_BASE), data);
76         reg_write(EBI_CPU_IO_ACCS(EBI_BASE),
77                   EXT_DEVICE_CHANNEL_1 | EBI_CPU_WRITE | addr);
78         ebi_wait();
79
80         return;
81 }
82
83 u32 pkt_data_pull(u32 addr)
84 {
85         volatile u32 data;
86
87         reg_write(EBI_DEV1_CONFIG2(EBI_BASE), 0x0000004A);
88         ebi_wait();
89         reg_write(EBI_CPU_IO_ACCS(EBI_BASE), (EXT_DEVICE_CHANNEL_1 | addr));
90         ebi_wait();
91         data = reg_read(EBI_IO_ACCS_DATA(EBI_BASE));
92
93         return data;
94 }