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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [powerpc/] [mbx/] [v2_0/] [src/] [hal_aux.c] - Blame information for rev 307

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

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

powered by: WebSVN 2.1.0

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