OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [arm/] [xscale/] [ixdp425/] [current/] [src/] [ixdp425_misc.c] - Blame information for rev 868

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      ixdp425_misc.c
4
//
5
//      HAL misc board support code for Intel XScale IXDP425
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, 2003 Free Software Foundation, 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      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
//==========================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):    msalter
43
// Contributors: msalter
44
// Date:         2002-12-11
45
// Purpose:      HAL board support
46
// Description:  Implementations of HAL board interfaces
47
//
48
//####DESCRIPTIONEND####
49
//
50
//========================================================================*/
51
 
52
#include <pkgconf/hal.h>
53
#include <pkgconf/system.h>
54
#include CYGBLD_HAL_PLATFORM_H
55
 
56
#include <cyg/infra/cyg_type.h>         // base types
57
#include <cyg/infra/cyg_trac.h>         // tracing macros
58
#include <cyg/infra/cyg_ass.h>          // assertion macros
59
 
60
#include <cyg/hal/hal_io.h>             // IO macros
61
#include <cyg/hal/hal_arch.h>           // Register state info
62
#include <cyg/hal/hal_diag.h>
63
#include <cyg/hal/hal_intr.h>           // Interrupt names
64
#include <cyg/hal/hal_cache.h>
65
#include <cyg/hal/hal_ixp425.h>         // Hardware definitions
66
#include <cyg/hal/ixdp425.h>            // Platform specifics
67
 
68
#include <cyg/infra/diag.h>             // diag_printf
69
 
70
//
71
// Platform specific initialization
72
//
73
void
74
plf_hardware_init(void)
75
{
76
    // GPIO(15) used for ENET clock
77
    HAL_GPIO_OUTPUT_ENABLE(15);
78
    *IXP425_GPCLKR |= GPCLKR_CLK1_ENABLE;
79
    *IXP425_GPCLKR |= GPCLKR_CLK1_PCLK2;
80
 
81
    HAL_GPIO_OUTPUT_SET(GPIO_EEPROM_SCL);
82
    HAL_GPIO_OUTPUT_ENABLE(GPIO_EEPROM_SCL);
83
 
84
    HAL_GPIO_OUTPUT_SET(GPIO_EEPROM_SDA);
85
    HAL_GPIO_OUTPUT_ENABLE(GPIO_EEPROM_SDA);
86
 
87
    // ENET-0 IRQ line
88
    HAL_GPIO_OUTPUT_DISABLE(GPIO_ENET0_INT_N);
89
    HAL_INTERRUPT_CONFIGURE(CYGNUM_HAL_INTERRUPT_ETH0, 1, 0);
90
 
91
    // ENET-1 IRQ line
92
    HAL_GPIO_OUTPUT_DISABLE(GPIO_ENET1_INT_N);
93
    HAL_INTERRUPT_CONFIGURE(CYGNUM_HAL_INTERRUPT_ETH1, 1, 0);
94
 
95
    // HSS IRQ lines
96
    HAL_GPIO_OUTPUT_DISABLE(GPIO_HSS0_INT_N);
97
    HAL_INTERRUPT_CONFIGURE(CYGNUM_HAL_INTERRUPT_HSS0, 1, 0);
98
    HAL_GPIO_OUTPUT_DISABLE(GPIO_HSS1_INT_N);
99
    HAL_INTERRUPT_CONFIGURE(CYGNUM_HAL_INTERRUPT_HSS1, 1, 0);
100
 
101
    // DSL IRQ line
102
    HAL_GPIO_OUTPUT_DISABLE(GPIO_DSL_INT_N);
103
    HAL_INTERRUPT_CONFIGURE(CYGNUM_HAL_INTERRUPT_DSL, 1, 0);
104
 
105
    *IXP425_EXP_CS4 = (EXP_ADDR_T(3) | EXP_SETUP_T(3) | EXP_STROBE_T(15) | EXP_HOLD_T(3) | \
106
                       EXP_RECOVERY_T(15) | EXP_SZ_512 | EXP_WR_EN | EXP_CS_EN);
107
    *IXP425_EXP_CS5 = (EXP_ADDR_T(3) | EXP_SETUP_T(3) | EXP_STROBE_T(15) | EXP_HOLD_T(3) | \
108
                       EXP_RECOVERY_T(15) | EXP_SZ_512 | EXP_WR_EN | EXP_CS_EN);
109
 
110
#ifdef CYGPKG_IO_PCI
111
    extern void hal_plf_pci_init(void);
112
    hal_plf_pci_init();
113
#endif
114
}
115
 
116
// --------------------------------------------------------------------------------------
117
// EEPROM Support 
118
//
119
#ifdef CYGPKG_DEVS_ETH_INTEL_NPE
120
 
121
#define CLK_LO()      HAL_GPIO_OUTPUT_CLEAR(GPIO_EEPROM_SCL)
122
#define CLK_HI()      HAL_GPIO_OUTPUT_SET(GPIO_EEPROM_SCL)
123
 
124
#define DATA_LO()     HAL_GPIO_OUTPUT_CLEAR(GPIO_EEPROM_SDA)
125
#define DATA_HI()     HAL_GPIO_OUTPUT_SET(GPIO_EEPROM_SDA)
126
 
127
 
128
// returns non-zero if ACK bit seen
129
static int
130
eeprom_start(cyg_uint8 b)
131
{
132
    int i;
133
 
134
    CLK_HI();
135
    hal_delay_us(5);
136
    DATA_LO();
137
    hal_delay_us(5);
138
    CLK_LO();
139
 
140
    for (i = 7; i >= 0; i--) {
141
        if (b & (1 << i))
142
            DATA_HI();
143
        else
144
            DATA_LO();
145
        hal_delay_us(5);
146
        CLK_HI();
147
        hal_delay_us(5);
148
        CLK_LO();
149
    }
150
    hal_delay_us(5);
151
    HAL_GPIO_OUTPUT_DISABLE(GPIO_EEPROM_SDA);
152
    CLK_HI();
153
    hal_delay_us(5);
154
    i = (*IXP425_GPINR & (1 << GPIO_EEPROM_SDA)) ? 0 : 1;
155
    CLK_LO();
156
    hal_delay_us(5);
157
    HAL_GPIO_OUTPUT_ENABLE(GPIO_EEPROM_SDA);
158
 
159
    return i;
160
}
161
 
162
 
163
static void
164
eeprom_stop(void)
165
{
166
    int i;
167
 
168
    hal_delay_us(5);
169
    DATA_LO();
170
    hal_delay_us(5);
171
    CLK_HI();
172
    hal_delay_us(5);
173
    DATA_HI();
174
    hal_delay_us(5);
175
    CLK_LO();
176
    hal_delay_us(5);
177
    CLK_HI();
178
    hal_delay_us(5);
179
}
180
 
181
 
182
static int
183
eeprom_putb(cyg_uint8 b)
184
{
185
    int i;
186
 
187
    for (i = 7; i >= 0; i--) {
188
        if (b & (1 << i))
189
            DATA_HI();
190
        else
191
            DATA_LO();
192
        CLK_HI();
193
        hal_delay_us(5);
194
        CLK_LO();
195
        hal_delay_us(5);
196
    }
197
    HAL_GPIO_OUTPUT_DISABLE(GPIO_EEPROM_SDA);
198
    CLK_HI();
199
    hal_delay_us(5);
200
    i = (*IXP425_GPINR & (1 << GPIO_EEPROM_SDA)) ? 0 : 1;
201
    CLK_LO();
202
    hal_delay_us(5);
203
 
204
    DATA_HI();
205
    HAL_GPIO_OUTPUT_ENABLE(GPIO_EEPROM_SDA);
206
 
207
    return i;
208
}
209
 
210
 
211
static cyg_uint8
212
eeprom_getb(int more)
213
{
214
    int i;
215
    cyg_uint8 b = 0;
216
 
217
    HAL_GPIO_OUTPUT_DISABLE(GPIO_EEPROM_SDA);
218
    hal_delay_us(5);
219
 
220
    for (i = 7; i >= 0; i--) {
221
        b <<= 1;
222
        if (*IXP425_GPINR & (1 << GPIO_EEPROM_SDA))
223
            b |= 1;
224
        CLK_HI();
225
        hal_delay_us(5);
226
        CLK_LO();
227
        hal_delay_us(5);
228
    }
229
    HAL_GPIO_OUTPUT_ENABLE(GPIO_EEPROM_SDA);
230
    if (more)
231
        DATA_LO();
232
    else
233
        DATA_HI();
234
    hal_delay_us(5);
235
    CLK_HI();
236
    hal_delay_us(5);
237
    CLK_LO();
238
    hal_delay_us(5);
239
 
240
    return b;
241
}
242
 
243
 
244
static int
245
eeprom_read(int addr, cyg_uint8 *buf, int nbytes)
246
{
247
    cyg_uint8 start_byte;
248
    int i;
249
 
250
    start_byte = 0xA0;  // write
251
 
252
    if (addr & (1 << 8))
253
        start_byte |= 2;
254
 
255
 
256
    for (i = 0; i < 10; i++)
257
        if (eeprom_start(start_byte))
258
            break;
259
 
260
    if (i == 10) {
261
        diag_printf("eeprom_read: Can't get write start ACK\n");
262
        return 0;
263
    }
264
 
265
    if (!eeprom_putb(addr & 0xff)) {
266
        diag_printf("eeprom_read: Can't get address ACK\n");
267
        return 0;
268
    }
269
 
270
    start_byte |= 1; // READ command
271
    if (!eeprom_start(start_byte)) {
272
        diag_printf("eeprom_read: Can't get read start ACK\n");
273
        return 0;
274
    }
275
 
276
    for (i = 0; i < (nbytes - 1); i++)
277
        *buf++ = eeprom_getb(1);
278
 
279
    *buf++ = eeprom_getb(0);
280
    hal_delay_us(5);
281
    eeprom_stop();
282
 
283
    return nbytes;
284
}
285
 
286
static void
287
eeprom_write(int addr, cyg_uint8 val)
288
{
289
    cyg_uint8 start_byte;
290
    int i;
291
 
292
    start_byte = 0xA0;  // write
293
 
294
    if (addr & (1 << 8))
295
        start_byte |= 2;
296
 
297
    for (i = 0; i < 10; i++)
298
        if (eeprom_start(start_byte))
299
            break;
300
 
301
    if (i == 10) {
302
        diag_printf("eeprom_write: Can't get start ACK\n");
303
        return;
304
    }
305
 
306
    if (!eeprom_putb(addr & 0xff)) {
307
        diag_printf("eeprom_write: Can't get address ACK\n");
308
        return;
309
    }
310
 
311
    if (!eeprom_putb(val)) {
312
        diag_printf("eeprom_write: no data ACK\n");
313
        return;
314
    }
315
    eeprom_stop();
316
}
317
 
318
 
319
#define MAC_EEPROM_OFFSET(p)  (0x100 + ((p) * 6))
320
 
321
int
322
cyghal_get_npe_esa(int port, cyg_uint8 *buf)
323
{
324
    if (port != 0 && port != 1)
325
        return 0;
326
 
327
    if (eeprom_read(MAC_EEPROM_OFFSET(port), buf, 6) != 6)
328
        return 0;
329
 
330
    // don't use broadcast address
331
    if (buf[0] == 0xff && buf[1] == 0xff && buf[2] == 0xff &&
332
        buf[3] == 0xff && buf[4] == 0xff && buf[5] == 0xff)
333
        return 0;
334
 
335
    return 1;
336
}
337
 
338
 
339
#ifdef CYGPKG_REDBOOT
340
#include <redboot.h>
341
 
342
static void
343
do_set_npe_mac(int argc, char *argv[])
344
{
345
    bool portnum_set;
346
    int  portnum, i;
347
    char *addr = 0;
348
    struct option_info opts[1];
349
    cyg_uint8  mac[6];
350
 
351
    init_opts(&opts[0], 'p', true, OPTION_ARG_TYPE_NUM,
352
              (void **)&portnum, (bool *)&portnum_set, "port number");
353
    if (!scan_opts(argc, argv, 1, opts, 1, (void *)&addr,
354
                   OPTION_ARG_TYPE_STR, "MAC address")) {
355
        return;
356
    }
357
 
358
    if ((!portnum_set && addr) ||
359
        (portnum_set && portnum != 0 && portnum != 1)) {
360
        diag_printf("Must specify port with \"-p <0|1>\"\n");
361
        return;
362
    }
363
 
364
    if (!portnum_set) {
365
        for (i = 0; i < 2; i++) {
366
            cyghal_get_npe_esa(i, mac);
367
            diag_printf("NPE eth%d mac: %02x:%02x:%02x:%02x:%02x:%02x\n",
368
                        i, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
369
        }
370
        return;
371
    }
372
 
373
    if (!addr) {
374
        cyghal_get_npe_esa(portnum, mac);
375
        diag_printf("NPE eth%d mac: %02x:%02x:%02x:%02x:%02x:%02x\n",
376
                    portnum, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
377
        return;
378
    }
379
 
380
    // parse MAC address from user.
381
    // acceptable formats are "nn:nn:nn:nn:nn:nn" and "nnnnnnnnnnnn"
382
    for (i = 0; i < 6; i++) {
383
        if (!_is_hex(addr[0]) || !_is_hex(addr[1]))
384
            break;
385
        mac[i] = (_from_hex(addr[0]) * 16) + _from_hex(addr[1]);
386
        addr += 2;
387
        if (*addr == ':')
388
            addr++;
389
    }
390
 
391
    if (i != 6 || *addr != '\0') {
392
        diag_printf("Malformed MAC address.\n");
393
        return;
394
    }
395
 
396
    for (i = 0; i < 6; i++) {
397
        eeprom_write(MAC_EEPROM_OFFSET(portnum) + i, mac[i]);
398
        hal_delay_us(100000);
399
    }
400
}
401
 
402
RedBoot_cmd("set_npe_mac",
403
            "Set/Read MAC address for NPE ethernet ports",
404
            "[-p <portnum>] [xx:xx:xx:xx:xx:xx]",
405
            do_set_npe_mac);
406
 
407
#endif // CYGPKG_REDBOOT
408
 
409
#endif // CYGPKG_DEVS_ETH_INTEL_NPE
410
 
411
// ------------------------------------------------------------------------
412
// EOF ixdp425_misc.c

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.