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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [powerpc/] [moab/] [current/] [src/] [hal_aux.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//=============================================================================
2
//
3
//      hal_aux.c
4
//
5
//      HAL auxiliary objects and code; per platform
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, 2004 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):   hmt
43
// Contributors:hmt, gthomas
44
// Date:        1999-06-08
45
// Purpose:     HAL aux objects: startup tables.
46
// Description: Tables for per-platform initialization
47
//
48
//####DESCRIPTIONEND####
49
//
50
//=============================================================================
51
 
52
#include <pkgconf/hal.h>
53
 
54
#include <cyg/infra/cyg_type.h>
55
#include <cyg/hal/hal_mem.h>            // HAL memory definitions
56
#define CYGARC_HAL_COMMON_EXPORT_CPU_MACROS
57
#include <cyg/hal/ppc_regs.h>           // Platform registers
58
#include <cyg/hal/hal_if.h>             // hal_if_init
59
#include <cyg/hal/hal_intr.h>           // interrupt definitions
60
#include <cyg/infra/cyg_ass.h>          // assertion macros
61
#include <cyg/hal/hal_io.h>             // I/O macros
62
#include <cyg/infra/diag.h>
63
#include CYGHWR_MEMORY_LAYOUT_H
64
#include <cyg/io/pci_hw.h>
65
#include <cyg/io/pci.h>
66
 
67
#ifdef CYGPKG_REDBOOT
68
#include <redboot.h>
69
#endif
70
 
71
// The memory map is weakly defined, allowing the application to redefine
72
// it if necessary. The regions defined below are the minimum requirements.
73
CYGARC_MEMDESC_TABLE CYGBLD_ATTRIB_WEAK = {
74
    // Mapping for the TAMS MOAB development boards
75
    CYGARC_MEMDESC_NOCACHE( 0xFFE00000, 0x00200000 ), // Boot ROM
76
    CYGARC_MEMDESC_NOCACHE( 0xEF000000, 0x01000000 ), // CPU registers
77
    CYGARC_MEMDESC_NOCACHE( 0xEE000000, 0x01000000 ), // PCI CFG 
78
    CYGARC_MEMDESC_NOCACHE( 0xE8000000, 0x01000000 ), // PCI I/O
79
    CYGARC_MEMDESC_NOCACHE( 0xA0000000, 0x10000000 ), // PCI Memory
80
    CYGARC_MEMDESC_NOCACHE( _MOAB_NAND, 0x00100000 ), // Main [NAND] FLASH
81
    CYGARC_MEMDESC_NOCACHE( _MOAB_OCM,  0x01000000 ), // OCM
82
    CYGARC_MEMDESC_NOCACHE_PA( 0x80000000, 0x00000000, CYGMEM_REGION_ram_SIZE ), // Uncached version of RAM
83
    CYGARC_MEMDESC_CACHE(   CYGMEM_REGION_ram, CYGMEM_REGION_ram_SIZE ), // Main memory
84
    CYGARC_MEMDESC_TABLE_END
85
};
86
 
87
//--------------------------------------------------------------------------
88
// Platform init code.
89
 
90
// Board/CPU serial number
91
cyg_uint32 _moab_serial_no[2];
92
unsigned char _moab_eth0_ESA[] = { 0x00, 0x20, 0xCF, 0x02, 0x11, 0x11}; // Default ESA
93
unsigned char _moab_eth1_ESA[] = { 0x00, 0x20, 0xCF, 0x03, 0x11, 0x11}; // Default ESA
94
 
95
void
96
hal_platform_init(void)
97
{
98
    unsigned long munged_serial_no;
99
    cyg_pci_device USB_info;
100
    cyg_pci_device_id USB_dev = CYG_PCI_NULL_DEVID;
101
 
102
    CYGARC_MFDCR(DCR_CPC0_ECID0, _moab_serial_no[0]);
103
    CYGARC_MFDCR(DCR_CPC0_ECID1, _moab_serial_no[1]);
104
    // Set default ethernet ESA - using 16 bits of munged serial number
105
    munged_serial_no = ((_moab_serial_no[0] & 0x0000000F) << 12) | (_moab_serial_no[1] & 0x00000FFF);
106
    _moab_eth0_ESA[4] = ((munged_serial_no & 0x0000FF00) >> 8);
107
    _moab_eth0_ESA[5] = ((munged_serial_no & 0x000000FF) >> 0);
108
    _moab_eth1_ESA[4] = ((munged_serial_no & 0x0000FF00) >> 8);
109
    _moab_eth1_ESA[5] = ((munged_serial_no & 0x000000FF) >> 0);
110
#ifdef CYGPKG_REDBOOT
111
    diag_printf("CPU serial number: %08x/%08x\n", _moab_serial_no[0], _moab_serial_no[1]);
112
#endif
113
    // Configure USB controller (if present)
114
    while (cyg_pci_find_next(USB_dev, &USB_dev)) {
115
        cyg_uint8 bus = CYG_PCI_DEV_GET_BUS(USB_dev);
116
        cyg_uint8 devfn = CYG_PCI_DEV_GET_DEVFN(USB_dev);
117
        cyg_uint16 v, d;
118
        cyg_uint32 ext_reg;
119
 
120
        cyg_pcihw_read_config_uint16(bus, devfn, CYG_PCI_CFG_VENDOR, &v);
121
        cyg_pcihw_read_config_uint16(bus, devfn, CYG_PCI_CFG_DEVICE, &d);
122
        if ((v == 0x1033) && ((d == 0x0035) || (d == 0x00E0))) {
123
            // NEC USB controller
124
            cyg_pcihw_read_config_uint32(bus, devfn, 0xE4, &ext_reg);
125
            ext_reg |= (1<<5);  // 48MHz clock
126
            cyg_pcihw_write_config_uint32(bus, devfn, 0xE4, ext_reg);
127
        }
128
    }
129
}
130
 
131
#ifdef CYGSEM_REDBOOT_PLF_STARTUP
132
void
133
cyg_plf_redboot_startup(void)
134
{
135
    cyg_uint32 gpio_ir;
136
 
137
    HAL_READ_UINT32(GPIO_IR, gpio_ir);
138
    if ((gpio_ir & 0x00080000) != 0) {
139
        // Load RedBoot from NAND FLASH and execute it
140
        script = "fi lo RedBoot;go\n";
141
        script_timeout = 1;
142
    } else {
143
        script = (char *)0;
144
    }
145
}
146
#endif
147
 
148
#ifdef CYGSEM_REDBOOT_PLF_ESA_VALIDATE
149
//
150
// Verify that the given ESA is valid for this platform
151
//
152
bool
153
cyg_plf_redboot_esa_validate(unsigned char *val)
154
{
155
    return ((val[0] == 0x00) && (val[1] == 0x20) && (val[2] == 0xCF));
156
}
157
#endif
158
 
159
//
160
// Initialize serial ports - called during hal_if_init()
161
// Note: actual serial port support code is supported by the PPC405 variant layer
162
//       Having this call here allows for additional platform specific additions
163
//
164
externC void cyg_hal_var_serial_init(void);
165
void
166
cyg_hal_plf_comms_init(void)
167
{
168
    static int initialized = 0;
169
 
170
    if (initialized)
171
        return;
172
    initialized = 1;
173
 
174
    cyg_hal_var_serial_init();
175
}
176
 
177
//----------------------------------------------------------------------------
178
// Reset.
179
void
180
_moab_reset(void)
181
{
182
    CYGARC_MTSPR(SPR_DBCR0, 0x30000000);  // Asserts system reset
183
    while (1) ;
184
}
185
 
186
#ifdef CYGPKG_REDBOOT
187
//----------------------------------------------------------------------------
188
// Memory map [segment] support for RedBoot
189
void
190
cyg_plf_memory_segment(int seg, unsigned char **start, unsigned char **end)
191
{
192
    if (seg == 1) {
193
        *start = (unsigned char *)_MOAB_OCM;
194
        *end = (unsigned char *)_MOAB_OCM + 0x1000;
195
    } else {
196
        diag_printf("** Invalid memory segment #%d - ignored\n", seg);
197
        *start = NO_MEMORY;
198
        *end = NO_MEMORY;
199
    }
200
}
201
#endif
202
 
203
//--------------------------------------------------------------------------
204
// EEPROM support - 1024 bytes, treated as a single read/write block
205
void
206
read_eeprom(unsigned char *buf, int len)
207
{
208
    int i, page, page_addr, size;
209
    cyg_uint8 addr[2];
210
 
211
    if (len > CYGNUM_HAL_EEPROM_SIZE) {
212
        diag_printf("%s - Illegal length: %d\n", __FUNCTION__, len);
213
        return;
214
    }
215
#if CYGNUM_HAL_EEPROM_SIZE == 1024
216
    // Read from start of EEPROM
217
    for (i = 0;  i < len;  i += 4) {
218
        page = 0xA9 + ((i >> 8) << 1);
219
        if ((i % 256) == 0) {
220
            addr[0] = 0x00;
221
            if (!hal_ppc405_i2c_put_bytes(page, addr, 1)) {
222
                diag_printf("%s - Can't select page %x\n", __FUNCTION__, page);
223
                return;
224
            }
225
        }
226
        if (!hal_ppc405_i2c_get_bytes(page, &buf[i], 4)) {
227
            diag_printf("%s - Can't read byte %d\n", __FUNCTION__, i);
228
            return;
229
        }
230
    }
231
#else
232
    // Read from start of EEPROM
233
    page = 0xAF;  page_addr = 0;
234
    for (i = 0;  i < len;  i += size) {
235
        addr[0] = page_addr >> 8;  addr[1] = (page_addr & 0xFF);
236
        size = (len - i);
237
        if (size > 32) size = 32;
238
        if (!hal_ppc405_i2c_put_bytes(page, addr, 2)) {
239
            diag_printf("%s - Can't select address %x\n", __FUNCTION__, page);
240
            return;
241
        }
242
        if (!hal_ppc405_i2c_get_bytes(page, &buf[i], size)) {
243
            diag_printf("%s - Can't read bytes\n", __FUNCTION__);
244
            return;
245
        }
246
        page_addr += size;
247
    }
248
#endif
249
#if 0
250
    diag_printf("EEPROM data - read\n");
251
    diag_dump_buf(buf, len);
252
#endif
253
}
254
 
255
void
256
write_eeprom(unsigned char *buf, int len)
257
{
258
    int i, j, page, page_addr, size;
259
    cyg_uint8 addr[32+2];
260
#if CYGNUM_HAL_EEPROM_SIZE == 1024
261
    int left;
262
#endif
263
 
264
#if 0
265
    diag_printf("EEPROM data - write\n");
266
    diag_dump_buf(buf, len < 256 ? len : 256);
267
#endif
268
    if (len > CYGNUM_HAL_EEPROM_SIZE) {
269
        diag_printf("%s - Illegal length: %d\n", __FUNCTION__, len);
270
        return;
271
    }
272
#if CYGNUM_HAL_EEPROM_SIZE == 1024
273
    // Write from start of EEPROM
274
    for (left = len, i = 0;  i < len;  i += size, left -= size) {
275
        addr[0] = i;
276
        size = sizeof(addr)-1;
277
        if (size > left) size = left;
278
        for (j = 0;  j < size;  j++) {
279
            addr[j+1] = buf[i+j];
280
        }
281
        page = 0xA8 + ((i >> 8) << 1);
282
        if (!hal_ppc405_i2c_put_bytes(page, addr, size+1)) {
283
            diag_printf("%s - Can't write byte - page: %x, addr: %d\n", __FUNCTION__, page, i);
284
            return;
285
        }
286
        // Give device time to recover
287
        CYGACC_CALL_IF_DELAY_US(10000);   // 10ms
288
    }
289
#else
290
    // Write from start of EEPROM
291
    page_addr = 0;  page = 0xAE;
292
    for (i = 0;  i < len;  i += size) {
293
        addr[0] = page_addr >> 8;  addr[1] = page_addr & 0xFF;
294
        size = (len - i);
295
        if (size > 32) size = 32;
296
        for (j = 0;  j < size;  j++) {
297
            addr[j+2] = buf[i+j];
298
        }
299
        if (!hal_ppc405_i2c_put_bytes(page, addr, size+2)) {
300
            diag_printf("%s - Can't write byte - page: %x, addr: %d\n", __FUNCTION__, page, i);
301
            return;
302
        }
303
        // Give device time to recover
304
        CYGACC_CALL_IF_DELAY_US(50000);   // 10ms
305
        page_addr += size;
306
    }
307
#endif
308
}
309
 
310
// Interrupt support
311
 
312
void
313
hal_platform_IRQ_init(void)
314
{
315
}
316
 
317
// EOF hal_aux.c

powered by: WebSVN 2.1.0

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