1 //==========================================================================
3 // devs_eth_powerpc_ec555.inl
5 // ec555 ethernet I/O definitions.
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.
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.
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
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.
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.
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.
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####
43 // Author(s): Bob Koninckx
44 // Contributors:Bob Koninckx
46 // Purpose: ec555 ethernet defintions
48 //####DESCRIPTIONEND####
49 //==========================================================================
51 #include <cyg/hal/hal_intr.h>
52 #include <cyg/hal/hal_if.h>
55 # include <pkgconf/redboot.h>
56 # ifdef CYGSEM_REDBOOT_FLASH_CONFIG
58 # include <flash_config.h>
63 # define CS8900A_step 2
68 #ifdef CYGPKG_DEVS_ETH_POWERPC_EC555_ETH0
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]",
77 RedBoot_config_option(CYGDAT_DEVS_ETH_POWERPC_EC555_ETH0_NAME " network hardware address [MAC]",
82 # endif // CYGPKG_REDBOOT && CYGSEM_REDBOOT_FLASH_CONFIG
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.
88 # include <cyg/hal/hal_if.h>
91 # define CONFIG_ESA (6)
94 # define CONFIG_BOOL (1)
98 _ec555_provide_eth0_esa(struct cs8900a_priv_data* cpd)
102 ok = CYGACC_CALL_IF_FLASH_CFG_OP( CYGNUM_CALL_IF_FLASH_CFG_GET,
103 "eth0_esa", &set_esa, CONFIG_BOOL);
105 ok = CYGACC_CALL_IF_FLASH_CFG_OP( CYGNUM_CALL_IF_FLASH_CFG_GET,
106 "eth0_esa_data", cpd->esa, CONFIG_ESA);
108 return ok && set_esa;
111 # endif // CYGSEM_HAL_VIRTUAL_VECTOR_SUPPORT
112 #endif // ! CYGSEM_DEVS_ETH_POWERPC_EC555_ETH0_SET_ESA
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
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
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
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
136 // set *(unsigned short *)0x0400030a = 0x0040 Make the eeprom writable / erasable
137 // set *(unsigned short *)0x0400030c = 0x0030
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
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
157 // set *(unsigned short *)0x0400030a = 0x0040 Write protect the eeprom
158 // set *(unsigned short *)0x0400030c = 0x0030
160 static __inline__ cyg_uint16
161 read_eeprom(cyg_addrword_t base, cyg_uint16 offset)
163 while (get_reg(base, PP_SelfStat) & PP_SelfStat_SIBSY)
166 #ifdef CYGIMP_DEVS_ETH_CL_CS8900A_DATABUS_BYTE_SWAPPED
167 put_reg(base, PP_ECR, (CYG_SWAP16(offset) | PP_EE_READ_CMD));
169 put_reg(base, PP_ECR, (offset | PP_EE_READ_CMD));
172 while (get_reg(base, PP_SelfStat) & PP_SelfStat_SIBSY)
175 return get_reg(base, PP_EE_DATA);
178 static __inline__ void
179 copy_eeprom(cyg_addrword_t base)
181 volatile cyg_uint16 esa_word;
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);
189 put_reg(base, (PP_IA + i), esa_word);
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
199 static __inline__ void
200 post_reset(cyg_addrword_t base)
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);
211 #undef CYGHWR_CL_CS8900A_PLF_POST_RESET
212 #define CYGHWR_CL_CS8900A_PLF_POST_RESET(base) post_reset(base)
214 #undef CYGHWR_CL_CS8900A_PLF_RESET
215 #define CYGHWR_CL_CS8900A_PLF_RESET(base) copy_eeprom(base)
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,
224 hardwired_esa : false,
225 # ifdef CYGSEM_HAL_VIRTUAL_VECTOR_SUPPORT
226 provide_esa : &_ec555_provide_eth0_esa,
235 ETH_DRV_SC(cs8900a_sc,
236 &cs8900a_eth0_priv_data, // Driver specific data
237 CYGDAT_DEVS_ETH_POWERPC_EC555_ETH0_NAME,
244 cs8900a_deliver, // "pseudoDSR" called from fast net thread
245 cs8900a_poll, // poll function, encapsulates ISR and DSR
248 NETDEVTAB_ENTRY(cs8900a_netdev,
249 "cs8900a_" CYGDAT_DEVS_ETH_POWERPC_EC555_ETH0_NAME,
253 #endif // CYGPKG_DEVS_ETH_POWERPC_EC555_ETH0
255 #endif // __WANT_DEVS
257 // EOF devs_eth_powerpc_ec555.inl