]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/devs/eth/powerpc/ec555/v2_0/include/devs_eth_powerpc_ec555.inl
Initial revision
[karo-tx-redboot.git] / packages / devs / eth / powerpc / ec555 / v2_0 / include / devs_eth_powerpc_ec555.inl
1 //==========================================================================
2 //
3 //      devs_eth_powerpc_ec555.inl
4 //
5 //      ec555 ethernet I/O definitions.
6 //
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12 //
13 // eCos is free software; you can redistribute it and/or modify it under
14 // the terms of the GNU General Public License as published by the Free
15 // Software Foundation; either version 2 or (at your option) any later version.
16 //
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20 // for more details.
21 //
22 // You should have received a copy of the GNU General Public License along
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25 //
26 // As a special exception, if other files instantiate templates or use macros
27 // or inline functions from this file, or you compile this file and link it
28 // with other works to produce a work based on this file, this file does not
29 // by itself cause the resulting work to be covered by the GNU General Public
30 // License. However the source code for this file must still be made available
31 // in accordance with section (3) of the GNU General Public License.
32 //
33 // This exception does not invalidate any other reasons why a work based on
34 // this file might be covered by the GNU General Public License.
35 //
36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37 // at http://sources.redhat.com/ecos/ecos-license/
38 // -------------------------------------------
39 //####ECOSGPLCOPYRIGHTEND####
40 //==========================================================================
41 //#####DESCRIPTIONBEGIN####
42 //
43 // Author(s):   Bob Koninckx
44 // Contributors:Bob Koninckx
45 // Date:        2002-11-20
46 // Purpose:     ec555 ethernet defintions
47 //
48 //####DESCRIPTIONEND####
49 //==========================================================================
50
51 #include <cyg/hal/hal_intr.h> 
52 #include <cyg/hal/hal_if.h>
53
54 #ifdef CYGPKG_REDBOOT
55 # include <pkgconf/redboot.h>
56 # ifdef CYGSEM_REDBOOT_FLASH_CONFIG
57 #  include <redboot.h>
58 #  include <flash_config.h>
59 # endif
60 #endif
61
62 #ifdef __WANT_CONFIG
63 # define CS8900A_step 2
64 #endif
65
66 #ifdef __WANT_DEVS
67
68 #ifdef CYGPKG_DEVS_ETH_POWERPC_EC555_ETH0
69
70 #ifndef CYGSEM_DEVS_ETH_POWERPC_EC555_ETH0_SET_ESA
71 # if defined(CYGPKG_REDBOOT) && defined(CYGSEM_REDBOOT_FLASH_CONFIG)
72 RedBoot_config_option("Set " CYGDAT_DEVS_ETH_POWERPC_EC555_ETH0_NAME " network hardware address [MAC]",
73                       eth0_esa,
74                       ALWAYS_ENABLED, true,
75                       CONFIG_BOOL, false
76     );
77 RedBoot_config_option(CYGDAT_DEVS_ETH_POWERPC_EC555_ETH0_NAME " network hardware address [MAC]",
78                       eth0_esa_data,
79                       "eth0_esa", true,
80                       CONFIG_ESA, 0
81     );
82 # endif // CYGPKG_REDBOOT && CYGSEM_REDBOOT_FLASH_CONFIG
83
84 # ifdef CYGSEM_HAL_VIRTUAL_VECTOR_SUPPORT
85 // Note that this section *is* active in an application, outside RedBoot,
86 // where the above section is not included.
87
88 #  include <cyg/hal/hal_if.h>
89
90 #  ifndef CONFIG_ESA
91 #   define CONFIG_ESA (6)
92 #  endif
93 #  ifndef CONFIG_BOOL
94 #   define CONFIG_BOOL (1)
95 #  endif
96
97 cyg_bool
98 _ec555_provide_eth0_esa(struct cs8900a_priv_data* cpd)
99 {
100     cyg_bool set_esa;
101     int ok;
102     ok = CYGACC_CALL_IF_FLASH_CFG_OP( CYGNUM_CALL_IF_FLASH_CFG_GET,
103                                       "eth0_esa", &set_esa, CONFIG_BOOL);
104     if (ok && set_esa) {
105         ok = CYGACC_CALL_IF_FLASH_CFG_OP( CYGNUM_CALL_IF_FLASH_CFG_GET,
106                                           "eth0_esa_data", cpd->esa, CONFIG_ESA);
107     }
108     return ok && set_esa;
109 }
110
111 # endif // CYGSEM_HAL_VIRTUAL_VECTOR_SUPPORT
112 #endif // ! CYGSEM_DEVS_ETH_POWERPC_EC555_ETH0_SET_ESA
113
114 // ------------------------------------------------------------------------
115 // EEPROM access functions
116 // These are byte swapped
117 #ifdef CYGIMP_DEVS_ETH_CL_CS8900A_DATABUS_BYTE_SWAPPED
118 #define PP_ECR          0x4000    // EEPROM Command Register
119 #define PP_EE_READ_CMD  0x0002
120 #define PP_EE_WRITE_CMD 0x0001
121 #define PP_EE_DATA              0x4200
122 #else
123 #define PP_ECR          0x0040    // EEPROM Command Register
124 #define PP_EE_READ_CMD  0x0200
125 #define PP_EE_WRITE_CMD 0x0100
126 #define PP_EE_DATA      0x0042
127 #endif
128
129 #define PP_EE_ADDR_W0   0x001C    // Notice that the EEPROM is not programmed when you got the
130 #define PP_EE_ADDR_W1   0x001D    // Module from Wuerz. Make sure to program the address to these
131 #define PP_EE_ADDR_W2   0x001E    // locations before using the adapter. This is fairly easy using GDB
132
133 // The example below programs the MAC address 0050 c4ff fc07 to the eeprom, supposed that the module
134 // is mapped to adresses 0x0400 0000, and supposed that the data bus is _not_ byte swapped
135 //
136 // set *(unsigned short *)0x0400030a = 0x0040        Make the eeprom writable / erasable
137 // set *(unsigned short *)0x0400030c = 0x0030        
138 //
139 // set *(unsigned short *)0x0400030a = 0x0040        erase the old esa
140 // set *(unsigned short *)0x0400030c = 0x031c       
141 // set *(unsigned short *)0x0400030c = 0x031d       
142 // set *(unsigned short *)0x0400030c = 0x031e       
143 // 
144 // set *(unsigned short *)0x0400030a = 0x0042        program the new esa
145 // set *(unsigned short *)0x0400030c = 0x5000
146 // set *(unsigned short *)0x0400030a = 0x0040
147 // set *(unsigned short *)0x0400030c = 0x011c
148 // set *(unsigned short *)0x0400030a = 0x0042
149 // set *(unsigned short *)0x0400030c = 0xffc4
150 // set *(unsigned short *)0x0400030a = 0x0040
151 // set *(unsigned short *)0x0400030c = 0x011d
152 // set *(unsigned short *)0x0400030a = 0x0042
153 // set *(unsigned short *)0x0400030c = 0x07fc
154 // set *(unsigned short *)0x0400030a = 0x0040
155 // set *(unsigned short *)0x0400030c = 0x011e
156 //
157 // set *(unsigned short *)0x0400030a = 0x0040        Write protect the eeprom
158 // set *(unsigned short *)0x0400030c = 0x0030         
159
160 static __inline__ cyg_uint16 
161 read_eeprom(cyg_addrword_t base, cyg_uint16 offset)
162 {
163     while (get_reg(base, PP_SelfStat) & PP_SelfStat_SIBSY)
164         ;
165
166 #ifdef CYGIMP_DEVS_ETH_CL_CS8900A_DATABUS_BYTE_SWAPPED
167     put_reg(base, PP_ECR, (CYG_SWAP16(offset) | PP_EE_READ_CMD));
168 #else
169     put_reg(base, PP_ECR, (offset | PP_EE_READ_CMD));
170 #endif
171
172     while (get_reg(base, PP_SelfStat) & PP_SelfStat_SIBSY)
173         ;
174
175     return get_reg(base, PP_EE_DATA);
176 }
177
178 static __inline__ void 
179 copy_eeprom(cyg_addrword_t base)
180 {
181     volatile cyg_uint16 esa_word;
182     cyg_uint16 i;
183     for (i = 0;  i < 6;  i += 2)
184     {    // Offset in the eeprom is WORD oriented, in the packetpage BYTE oriented
185          esa_word = read_eeprom(base, PP_EE_ADDR_W0 + (i/2));
186 #ifdef CYGIMP_DEVS_ETH_CL_CS8900A_DATABUS_BYTE_SWAPPED
187          put_reg(base, (PP_IA + CYG_SWAP16(i)), esa_word);
188 #else
189          put_reg(base, (PP_IA + i), esa_word);
190 #endif
191     }
192 }
193
194 // Not so nice, but reading these will never conflict on the ec555
195 // They certainly differ in A18
196 #define FIRSTRAM 0x01000000
197 #define LASTRAM  0x010ffffe
198
199 static __inline__ void 
200 post_reset(cyg_addrword_t base)
201 {
202    cyg_uint16 tmp;
203
204         // The following must toggle Address line 18, connected to SBHE on the CS8900a
205         HAL_READ_UINT16( LASTRAM,  tmp);
206         HAL_READ_UINT16( FIRSTRAM, tmp);
207         HAL_READ_UINT16( LASTRAM,  tmp);
208         HAL_READ_UINT16( FIRSTRAM, tmp);
209 }
210
211 #undef  CYGHWR_CL_CS8900A_PLF_POST_RESET
212 #define CYGHWR_CL_CS8900A_PLF_POST_RESET(base) post_reset(base)
213
214 #undef  CYGHWR_CL_CS8900A_PLF_RESET
215 #define CYGHWR_CL_CS8900A_PLF_RESET(base) copy_eeprom(base)
216  
217 static cs8900a_priv_data_t cs8900a_eth0_priv_data = { 
218     base : (cyg_addrword_t) (CYGNUM_DEVS_ETH_POWERPC_EC555_ETH0_BASE + 0x300),
219     interrupt:((CYGNUM_DEVS_ETH_POWERPC_EC555_ETH0_IRQ*2)+1), 
220 #ifdef CYGSEM_DEVS_ETH_POWERPC_EC555_ETH0_SET_ESA
221     esa : CYGDAT_DEVS_ETH_POWERPC_EC555_ETH0_ESA,
222     hardwired_esa : true,
223 #else
224     hardwired_esa : false,
225 # ifdef CYGSEM_HAL_VIRTUAL_VECTOR_SUPPORT
226     provide_esa : &_ec555_provide_eth0_esa,
227 # else
228     provide_esa : NULL,
229 # endif
230 #endif
231
232 };
233
234
235 ETH_DRV_SC(cs8900a_sc,
236            &cs8900a_eth0_priv_data, // Driver specific data
237            CYGDAT_DEVS_ETH_POWERPC_EC555_ETH0_NAME,
238            cs8900a_start,
239            cs8900a_stop,
240            cs8900a_control,
241            cs8900a_can_send,
242            cs8900a_send,
243            cs8900a_recv,
244            cs8900a_deliver,     // "pseudoDSR" called from fast net thread
245            cs8900a_poll,        // poll function, encapsulates ISR and DSR
246            cs8900a_int_vector);
247
248 NETDEVTAB_ENTRY(cs8900a_netdev, 
249                 "cs8900a_" CYGDAT_DEVS_ETH_POWERPC_EC555_ETH0_NAME,
250                 cs8900a_init, 
251                 &cs8900a_sc);
252
253 #endif // CYGPKG_DEVS_ETH_POWERPC_EC555_ETH0
254
255 #endif // __WANT_DEVS
256
257 // EOF devs_eth_powerpc_ec555.inl