blob: 20891418a1f87820711acf2b1e11afe112a909d8 [file] [log] [blame]
Jean-Christophe PLAGNIOL-VILLARDd87c24f2008-04-24 07:57:17 +02001/*
2 * (c) 2007 Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (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, MA 02111-1307 USA
17 */
18#include <common.h>
19#include "ax88796.h"
20
21/*
22 * Set 1 bit data
23 */
24static void ax88796_bitset(u32 bit)
25{
26 /* DATA1 */
27 if( bit )
28 EEDI_HIGH;
29 else
30 EEDI_LOW;
31
32 EECLK_LOW;
33 udelay(1000);
34 EECLK_HIGH;
35 udelay(1000);
36 EEDI_LOW;
37}
38
39/*
40 * Get 1 bit data
41 */
42static u8 ax88796_bitget(void)
43{
44 u8 bit;
45
46 EECLK_LOW;
47 udelay(1000);
48 /* DATA */
49 bit = EEDO;
50 EECLK_HIGH;
51 udelay(1000);
52
53 return bit;
54}
55
56/*
57 * Send COMMAND to EEPROM
58 */
59static void ax88796_eep_cmd(u8 cmd)
60{
61 ax88796_bitset(BIT_DUMMY);
62 switch(cmd){
63 case MAC_EEP_READ:
64 ax88796_bitset(1);
65 ax88796_bitset(1);
66 ax88796_bitset(0);
67 break;
68
69 case MAC_EEP_WRITE:
70 ax88796_bitset(1);
71 ax88796_bitset(0);
72 ax88796_bitset(1);
73 break;
74
75 case MAC_EEP_ERACE:
76 ax88796_bitset(1);
77 ax88796_bitset(1);
78 ax88796_bitset(1);
79 break;
80
81 case MAC_EEP_EWEN:
82 ax88796_bitset(1);
83 ax88796_bitset(0);
84 ax88796_bitset(0);
85 break;
86
87 case MAC_EEP_EWDS:
88 ax88796_bitset(1);
89 ax88796_bitset(0);
90 ax88796_bitset(0);
91 break;
92 default:
93 break;
94 }
95}
96
97static void ax88796_eep_setaddr(u16 addr)
98{
99 int i ;
100
101 for( i = 7 ; i >= 0 ; i-- )
102 ax88796_bitset(addr & (1 << i));
103}
104
105/*
106 * Get data from EEPROM
107 */
108static u16 ax88796_eep_getdata(void)
109{
110 ushort data = 0;
111 int i;
112
113 ax88796_bitget(); /* DUMMY */
114 for( i = 0 ; i < 16 ; i++ ){
115 data <<= 1;
116 data |= ax88796_bitget();
117 }
118 return data;
119}
120
121static void ax88796_mac_read(u8 *buff)
122{
123 int i ;
124 u16 data;
125 u16 addr = 0;
126
127 for( i = 0 ; i < 3; i++ )
128 {
129 EECS_HIGH;
130 EEDI_LOW;
131 udelay(1000);
132 /* READ COMMAND */
133 ax88796_eep_cmd(MAC_EEP_READ);
134 /* ADDRESS */
135 ax88796_eep_setaddr(addr++);
136 /* GET DATA */
137 data = ax88796_eep_getdata();
138 *buff++ = (uchar)(data & 0xff);
139 *buff++ = (uchar)((data >> 8) & 0xff);
140 EECLK_LOW;
141 EEDI_LOW;
142 EECS_LOW;
143 }
144}
145
Nobuhiro Iwamatsuf909daa2008-09-30 15:02:53 +0900146int get_prom(u8* mac_addr, u8* base_addr)
Jean-Christophe PLAGNIOL-VILLARDd87c24f2008-04-24 07:57:17 +0200147{
148 u8 prom[32];
149 int i;
150
151 ax88796_mac_read(prom);
152 for (i = 0; i < 6; i++){
153 mac_addr[i] = prom[i];
154 }
155 return 1;
156}