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

Subversion Repositories openrisc

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

Go to most recent revision | 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 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
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
#include <cyg/hal/hal_mem.h>            // HAL memory definitions
54
#include <pkgconf/hal_powerpc_quicc.h>
55
#include <cyg/infra/cyg_type.h>
56
#include <cyg/hal/quicc/ppc8xx.h>
57
#include <cyg/hal/hal_if.h>             // hal_if_init
58
 
59
// The memory map is weakly defined, allowing the application to redefine
60
// it if necessary. The regions defined below are the minimum requirements.
61
CYGARC_MEMDESC_TABLE CYGBLD_ATTRIB_WEAK = {
62
    // Mapping for the Motorola MBX860 development board
63
    CYGARC_MEMDESC_CACHE(   0xfe000000, 0x00400000 ), // ROM region
64
    CYGARC_MEMDESC_NOCACHE( 0xfa000000, 0x00400000 ), // Control/Status+LEDs
65
    CYGARC_MEMDESC_CACHE(   0x00000000, 0x00800000 ), // Main memory
66
 
67
    CYGARC_MEMDESC_TABLE_END
68
};
69
 
70
#ifdef _DOWNLOAD_UCODE_UPDATE // Not currently used
71
//
72
// The MPC8xx CPM (Control Processor) has some problems (overlapping structures) which
73
// can be fixed by downloading new ucode.  This code came from:
74
//   http://www.mot.com/SPS/ADC/pps/subpgs/etoolbox/8XX/i2c_spi.html
75
//
76
 
77
static unsigned char i2c_ucode_low[] = {
78
    0x7F, 0xFF, 0xEF, 0xD9, 0x3F, 0xFD, 0x00, 0x00,
79
    0x7F, 0xFB, 0x49, 0xF7, 0x7F, 0xF9, 0x00, 0x00,
80
    0x5F, 0xEF, 0xAD, 0xF7, 0x5F, 0x89, 0xAD, 0xF7,
81
    0x5F, 0xEF, 0xAF, 0xF7, 0x5F, 0x89, 0xAF, 0xF7,
82
    0x3A, 0x9C, 0xFB, 0xC8, 0xE7, 0xC0, 0xED, 0xF0,
83
    0x77, 0xC1, 0xE1, 0xBB, 0xF4, 0xDC, 0x7F, 0x1D,
84
    0xAB, 0xAD, 0x93, 0x2F, 0x4E, 0x08, 0xFD, 0xCF,
85
    0x6E, 0x0F, 0xAF, 0xF8, 0x7C, 0xCF, 0x76, 0xCF,
86
    0xFD, 0x1F, 0xF9, 0xCF, 0xAB, 0xF8, 0x8D, 0xC6,
87
    0xAB, 0x56, 0x79, 0xF7, 0xB0, 0x93, 0x73, 0x83,
88
    0xDF, 0xCE, 0x79, 0xF7, 0xB0, 0x91, 0xE6, 0xBB,
89
    0xE5, 0xBB, 0xE7, 0x4F, 0xB3, 0xFA, 0x6F, 0x0F,
90
    0x6F, 0xFB, 0x76, 0xCE, 0xEE, 0x0D, 0xF9, 0xCF,
91
    0x2B, 0xFB, 0xEF, 0xEF, 0xCF, 0xEE, 0xF9, 0xCF,
92
    0x76, 0xCE, 0xAD, 0x24, 0x90, 0xB2, 0xDF, 0x9A,
93
    0x7F, 0xDD, 0xD0, 0xBF, 0x4B, 0xF8, 0x47, 0xFD,
94
    0x7C, 0xCF, 0x76, 0xCE, 0xCF, 0xEF, 0x7E, 0x1F,
95
    0x7F, 0x1D, 0x7D, 0xFD, 0xF0, 0xB6, 0xEF, 0x71,
96
    0x7F, 0xC1, 0x77, 0xC1, 0xFB, 0xC8, 0x60, 0x79,
97
    0xE7, 0x22, 0xFB, 0xC8, 0x5F, 0xFF, 0xDF, 0xFF,
98
    0x5F, 0xB2, 0xFF, 0xFB, 0xFB, 0xC8, 0xF3, 0xC8,
99
    0x94, 0xA6, 0x7F, 0x01, 0x7F, 0x1D, 0x5F, 0x39,
100
    0xAF, 0xE8, 0x5F, 0x5E, 0xFF, 0xDF, 0xDF, 0x96,
101
    0xCB, 0x9F, 0xAF, 0x7D, 0x5F, 0xC1, 0xAF, 0xED,
102
    0x8C, 0x1C, 0x5F, 0xC1, 0xAF, 0xDD, 0x5F, 0xC3,
103
    0xDF, 0x9A, 0x7E, 0xFD, 0xB0, 0xB2, 0x5F, 0xB2,
104
    0xFF, 0xFE, 0xAB, 0xAD, 0x5F, 0xB2, 0xFF, 0xFE,
105
    0x5F, 0xCE, 0x60, 0x0B, 0xE6, 0xBB, 0x60, 0x0B,
106
    0x5F, 0xCE, 0xDF, 0xC6, 0x27, 0xFB, 0xEF, 0xDF,
107
    0x5F, 0xC8, 0xCF, 0xDE, 0x3A, 0x9C, 0xE7, 0xC0,
108
    0xED, 0xF0, 0xF3, 0xC8, 0x7F, 0x01, 0x54, 0xCD,
109
    0x7F, 0x1D, 0x2D, 0x3D, 0x36, 0x3A, 0x75, 0x70,
110
    0x7E, 0x0A, 0xF1, 0xCE, 0x37, 0xEF, 0x2E, 0x68,
111
    0x7F, 0xEE, 0x10, 0xEC, 0xAD, 0xF8, 0xEF, 0xDE,
112
    0xCF, 0xEA, 0xE5, 0x2F, 0x7D, 0x0F, 0xE1, 0x2B,
113
    0xF1, 0xCE, 0x5F, 0x65, 0x7E, 0x0A, 0x4D, 0xF8,
114
    0xCF, 0xEA, 0x5F, 0x72, 0x7D, 0x0B, 0xEF, 0xEE,
115
    0xCF, 0xEA, 0x5F, 0x74, 0xE5, 0x22, 0xEF, 0xDE,
116
    0x5F, 0x74, 0xCF, 0xDA, 0x0B, 0x62, 0x73, 0x85,
117
    0xDF, 0x62, 0x7E, 0x0A, 0x30, 0xD8, 0x14, 0x5B,
118
    0xBF, 0xFF, 0xF3, 0xC8, 0x5F, 0xFF, 0xDF, 0xFF,
119
    0xA7, 0xF8, 0x5F, 0x5E, 0xBF, 0xFE, 0x7F, 0x7D,
120
    0x10, 0xD3, 0x14, 0x50, 0x5F, 0x36, 0xBF, 0xFF,
121
    0xAF, 0x78, 0x5F, 0x5E, 0xBF, 0xFD, 0xA7, 0xF8,
122
    0x5F, 0x36, 0xBF, 0xFE, 0x77, 0xFD, 0x30, 0xC0,
123
    0x4E, 0x08, 0xFD, 0xCF, 0xE5, 0xFF, 0x6E, 0x0F,
124
    0xAF, 0xF8, 0x7E, 0x1F, 0x7E, 0x0F, 0xFD, 0x1F,
125
    0xF1, 0xCF, 0x5F, 0x1B, 0xAB, 0xF8, 0x0D, 0x5E,
126
    0x5F, 0x5E, 0xFF, 0xEF, 0x79, 0xF7, 0x30, 0xA2,
127
    0xAF, 0xDD, 0x5F, 0x34, 0x47, 0xF8, 0x5F, 0x34,
128
    0xAF, 0xED, 0x7F, 0xDD, 0x50, 0xB2, 0x49, 0x78,
129
    0x47, 0xFD, 0x7F, 0x1D, 0x7D, 0xFD, 0x70, 0xAD,
130
    0xEF, 0x71, 0x7E, 0xC1, 0x6B, 0xA4, 0x7F, 0x01,
131
    0x2D, 0x26, 0x7E, 0xFD, 0x30, 0xDE, 0x5F, 0x5E,
132
    0xFF, 0xFD, 0x5F, 0x5E, 0xFF, 0xEF, 0x5F, 0x5E,
133
    0xFF, 0xDF, 0x0C, 0xA0, 0xAF, 0xED, 0x0A, 0x9E,
134
    0xAF, 0xDD, 0x0C, 0x3A, 0x5F, 0x3A, 0xAF, 0xBD,
135
    0x7F, 0xBD, 0xB0, 0x82, 0x5F, 0x82, 0x47, 0xF8,
136
};
137
static unsigned char i2c_ucode_high[] = {
138
    0x3E, 0x30, 0x34, 0x30, 0x34, 0x34, 0x37, 0x37,
139
    0xAB, 0xF7, 0xBF, 0x9B, 0x99, 0x4B, 0x4F, 0xBD,
140
    0xBD, 0x59, 0x94, 0x93, 0x34, 0x9F, 0xFF, 0x37,
141
    0xFB, 0x9B, 0x17, 0x7D, 0xD9, 0x93, 0x69, 0x56,
142
    0xBB, 0xFD, 0xD6, 0x97, 0xBD, 0xD2, 0xFD, 0x11,
143
    0x31, 0xDB, 0x9B, 0xB3, 0x63, 0x13, 0x96, 0x37,
144
    0x93, 0x73, 0x36, 0x93, 0x19, 0x31, 0x37, 0xF7,
145
    0x33, 0x17, 0x37, 0xAF, 0x7B, 0xB9, 0xB9, 0x99,
146
    0xBB, 0x19, 0x79, 0x57, 0x7F, 0xDF, 0xD3, 0xD5,
147
    0x73, 0xB7, 0x73, 0xF7, 0x37, 0x93, 0x3B, 0x99,
148
    0x1D, 0x11, 0x53, 0x16, 0x99, 0x31, 0x53, 0x15,
149
    0x31, 0x69, 0x4B, 0xF4, 0xFB, 0xDB, 0xD3, 0x59,
150
    0x31, 0x49, 0x73, 0x53, 0x76, 0x95, 0x6D, 0x69,
151
    0x7B, 0x9D, 0x96, 0x93, 0x13, 0x13, 0x19, 0x79,
152
    0x79, 0x37, 0x69, 0x35,
153
};
154
#endif
155
 
156
#define QUICC_I2C_MOD_EN          0x01  // Enable I2C controller
157
#define QUICC_I2C_MOD_PDIV_CLK32  0x00  // I2C BRG - /32
158
#define QUICC_I2C_MOD_PDIV_CLK16  0x02  //           /16
159
#define QUICC_I2C_MOD_PDIV_CLK8   0x04  //           /8
160
#define QUICC_I2C_MOD_PDIV_CLK4   0x06  //           /4
161
#define QUICC_I2C_MOD_FLT         0x08  // 1 = input clock is filtered
162
#define QUICC_I2C_MOD_GCD         0x10  // 1 = deny general call address
163
#define QUICC_I2C_MOD_REVD        0x20  // 1 = reverse TxD and RxD order
164
 
165
#define QUICC_I2C_CMD_MASTER      0x01  // 1 = master, 0 = slave
166
#define QUICC_I2C_CMD_START       0x80  // 1 = start transmit
167
 
168
#define QUICC_I2C_FCR_BE          0x10  // Big Endian operation
169
 
170
#define MBX_CONFIG_EEPROM         0xA5  // I2C address of configuration ROM
171
 
172
static unsigned char _MBX_eeprom_data[0x100];
173
#define VPD_EOD 0xFF
174
 
175
static void
176
_mbx_init_i2c(void)
177
{
178
    volatile EPPC *eppc = eppc_base();
179
    unsigned char *sp, *ep;
180
    int i, len, RxBD, TxBD;
181
    struct i2c_pram *i2c;
182
    volatile struct cp_bufdesc *rxbd, *txbd;
183
    unsigned char i2c_address[521];
184
    static int i2c_init = 0;
185
 
186
    if (i2c_init) return;
187
    i2c_init = 1;
188
    eppc->cp_rccr = 0;  // Disables any current ucode running
189
#ifdef _DOWNLOAD_UCODE_UPDATE // Not currently used
190
    // Patch the ucode
191
    sp = i2c_ucode_low;
192
    ep = (unsigned char *)eppc->udata_ucode;
193
    for (i = 0;  i < sizeof(i2c_ucode_low);  i++) {
194
        *ep++ = *sp++;
195
    }
196
    sp = i2c_ucode_high;
197
    ep = (unsigned char *)eppc->udata_ext;
198
    for (i = 0;  i < sizeof(i2c_ucode_high);  i++) {
199
        *ep++ = *sp++;
200
    }
201
    eppc->cp_rctr1 = 0x802A;
202
    eppc->cp_rctr2 = 0x8028;
203
    eppc->cp_rctr3 = 0x802E;
204
    eppc->cp_rctr4 = 0x802C;
205
    diag_printf("RCCR: %x, RTCRx: %x/%x/%x/%x\n",
206
                eppc->cp_rccr, eppc->cp_rctr1, eppc->cp_rctr2, eppc->cp_rctr3, eppc->cp_rctr4);
207
    diag_dump_buf(eppc->udata_ucode, 256);
208
    diag_dump_buf(&eppc->pram[0].scc.pothers.i2c_idma, 0x40);
209
    eppc->cp_rccr = 0x01;  // Enable ucode
210
    diag_printf("RCCR: %x, RTCRx: %x/%x/%x/%x\n",
211
                eppc->cp_rccr, eppc->cp_rctr1, eppc->cp_rctr2, eppc->cp_rctr3, eppc->cp_rctr4);
212
    diag_dump_buf(eppc->udata_ucode, 256);
213
    diag_dump_buf(&eppc->pram[0].scc.pothers.i2c_idma, 0x40);
214
    diag_printf("RPBASE = %x/%x\n", eppc->pram[0].scc.pothers.i2c_idma.i2c.rpbase, &eppc->pram[0].scc.pothers.i2c_idma.i2c.rpbase);
215
    eppc->pram[0].scc.pothers.i2c_idma.i2c.rpbase = (unsigned long)&eppc->i2c_spare_pram - (unsigned long)eppc;
216
    diag_printf("RPBASE = %x/%x\n", eppc->pram[0].scc.pothers.i2c_idma.i2c.rpbase, &eppc->pram[0].scc.pothers.i2c_idma.i2c.rpbase);
217
    eppc->i2c_i2mod = 0;  // Disable I2C controller
218
    i2c = (struct i2c_pram *)&eppc->i2c_spare_pram;
219
#else
220
    eppc->i2c_i2mod = 0;  // Disable I2C controller
221
    i2c = (struct i2c_pram *)&eppc->pram[0].scc.pothers.i2c_idma.i2c;
222
#endif // _DOWNLOAD_UCODE_UPDATE
223
    sp = (unsigned char *)i2c;
224
    for (i = 0;  i < sizeof(*i2c);  i++) {
225
        *sp++ = 0;
226
    }
227
    RxBD = 0x2E08;  // CAUTION
228
    TxBD = 0x2E00;
229
    i2c->rbase = RxBD;
230
    i2c->tbase = TxBD;
231
    i2c->rfcr = QUICC_I2C_FCR_BE;
232
    i2c->tfcr = QUICC_I2C_FCR_BE;
233
    i2c->mrblr = sizeof(i2c_address);
234
    rxbd = (volatile struct cp_bufdesc *)((char *)eppc + RxBD);
235
    rxbd->ctrl = QUICC_BD_CTL_Ready | QUICC_BD_CTL_Wrap | QUICC_BD_CTL_Last;
236
    rxbd->length = 257;
237
    rxbd->buffer = i2c_address;
238
    txbd = (volatile struct cp_bufdesc *)((char *)eppc + TxBD);
239
    txbd->length = 1+520;
240
    i2c_address[0] = MBX_CONFIG_EEPROM;
241
    txbd->buffer = i2c_address;
242
    txbd->ctrl = QUICC_BD_CTL_Ready | QUICC_BD_CTL_Wrap | QUICC_BD_CTL_Last;
243
    eppc->i2c_i2add = 0x00;
244
    eppc->i2c_i2brg = 0x50;
245
    eppc->i2c_i2mod = QUICC_I2C_MOD_EN;  // Enable I2C interface
246
    // Initialize the CPM (set up buffer pointers, etc).
247
    // This needs to be done *after* the interface is enabled.
248
    eppc->cp_cr = QUICC_CPM_I2C | QUICC_CPM_CR_INIT_RX | QUICC_CPM_CR_BUSY;
249
    while (eppc->cp_cr & QUICC_CPM_CR_BUSY) ;
250
    eppc->cp_cr = QUICC_CPM_I2C | QUICC_CPM_CR_INIT_TX | QUICC_CPM_CR_BUSY;
251
    while (eppc->cp_cr & QUICC_CPM_CR_BUSY) ;
252
    eppc->i2c_i2com = QUICC_I2C_CMD_MASTER | QUICC_I2C_CMD_START;
253
    i = 0;
254
    while (txbd->ctrl & QUICC_BD_CTL_Ready) {
255
        if (++i > 50000) break;
256
    }
257
    // Rebuild the actual VPD
258
    for (i = 0;  i < sizeof(_MBX_eeprom_data);  i++) {
259
        _MBX_eeprom_data[i] = VPD_EOD;  // Undefined
260
    }
261
    sp = (unsigned char *)&i2c_address[1];
262
    ep = (unsigned char *)&i2c_address[sizeof(i2c_address)];
263
    while (sp != ep) {
264
        if ((sp[0] == 'M') && (sp[1] == 'O') && (sp[2] == 'T')) {
265
            // Found the "eye catcher" string
266
            sp += 8;
267
            len = (sp[0] << 8) | sp[1];
268
            sp += 2;
269
            for (i = 0;  i < len;  i++) {
270
                _MBX_eeprom_data[i] = *sp++;
271
                if (sp == ep) sp = (unsigned char *)&i2c_address[1];
272
            }
273
            break;
274
        }
275
        sp++;
276
    }
277
    eppc->i2c_i2mod = 0;  // Disable I2C interface
278
}
279
 
280
//
281
// Fetch a value from the VPD and return it's length.
282
// Returns a length of zero if not found
283
//
284
int
285
_mbx_fetch_VPD(int code, unsigned char *buf, int size)
286
{
287
    unsigned char *vp, *ep;
288
    int i, len;
289
 
290
    _mbx_init_i2c();  // Fetch the data if not already
291
    vp = &_MBX_eeprom_data[0];
292
    ep = &_MBX_eeprom_data[sizeof(_MBX_eeprom_data)];
293
    while (vp < ep) {
294
        if (*vp == (unsigned char)code) {
295
            // Found the desired item
296
            len = (int)vp[1];
297
            if (len > size) len = size;
298
            vp += 2;
299
            for (i = 0;  i < len;  i++) {
300
                *buf++ = *vp++;
301
            }
302
            return len;
303
        }
304
        len = (int)vp[1];
305
        vp += 2 + len;  // Skip to next item
306
        if (*vp == VPD_EOD) break;
307
    }
308
    return 0;
309
}
310
 
311
//--------------------------------------------------------------------------
312
// Platform init code.
313
void
314
hal_platform_init(void)
315
{
316
    hal_if_init();
317
}
318
 
319
// EOF hal_aux.c

powered by: WebSVN 2.1.0

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