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

Subversion Repositories openrisc_me

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

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
// Copyright (C) 2002, 2003 Gary Thomas
13
//
14
// eCos is free software; you can redistribute it and/or modify it under
15
// the terms of the GNU General Public License as published by the Free
16
// Software Foundation; either version 2 or (at your option) any later version.
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
19
// 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 along
24
// with eCos; if not, write to the Free Software Foundation, Inc.,
25
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26
//
27
// As a special exception, if other files instantiate templates or use macros
28
// or inline functions from this file, or you compile this file and link it
29
// with other works to produce a work based on this file, this file does not
30
// by itself cause the resulting work to be covered by the GNU General Public
31
// License. However the source code for this file must still be made available
32
// in accordance with section (3) of the GNU General Public License.
33
//
34
// This exception does not invalidate any other reasons why a work based on
35
// this file might be covered by the GNU General Public License.
36
//
37
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
38
// at http://sources.redhat.com/ecos/ecos-license/
39
// -------------------------------------------
40
//####ECOSGPLCOPYRIGHTEND####
41
//=============================================================================
42
//#####DESCRIPTIONBEGIN####
43
//
44
// Author(s):   hmt
45
// Contributors:hmt, gthomas
46
// Date:        1999-06-08
47
// Purpose:     HAL aux objects: startup tables.
48
// Description: Tables for per-platform initialization
49
//
50
//####DESCRIPTIONEND####
51
//
52
//=============================================================================
53
 
54
#include <pkgconf/hal.h>
55
#include <pkgconf/io_pci.h>
56
 
57
#include <cyg/infra/cyg_type.h>
58
#include <cyg/infra/diag.h>
59
#include <cyg/hal/hal_mem.h>            // HAL memory definitions
60
#include <cyg/hal/ppc_regs.h>           // Platform registers
61
#include <cyg/hal/hal_if.h>             // hal_if_init
62
#include <cyg/hal/hal_intr.h>           // interrupt definitions
63
#include <cyg/hal/hal_cache.h>
64
#include <cyg/infra/cyg_ass.h>          // assertion macros
65
#include <cyg/io/pci.h>
66
#include <cyg/hal/hal_io.h>             // I/O macros
67
#include CYGHWR_MEMORY_LAYOUT_H
68
 
69
// Functions defined in this module
70
void _csb281_fs6377_init(int mode);
71
static void _csb281_i2c_init(void);
72
 
73
// The memory map is weakly defined, allowing the application to redefine
74
// it if necessary. The regions defined below are the minimum requirements.
75
CYGARC_MEMDESC_TABLE CYGBLD_ATTRIB_WEAK = {
76
    // Mapping for the Cogent CSB281 development boards
77
    CYGARC_MEMDESC_NOCACHE( 0x70000000, 0x10000000 ), // FLASH region, LCD, PS/2
78
    CYGARC_MEMDESC_NOCACHE( 0xf0000000, 0x10000000 ), // PCI space, LEDS, control
79
    CYGARC_MEMDESC_CACHE(   CYGMEM_REGION_ram, CYGMEM_REGION_ram_SIZE ), // Main memory
80
// Main memory, mapped non-cacheable for PCI use
81
    CYGARC_MEMDESC_NOCACHE_PA(CYGMEM_SECTION_pci_window,
82
                              CYGARC_PHYSICAL_ADDRESS(CYGMEM_SECTION_pci_window),
83
                              CYGMEM_SECTION_pci_window_SIZE),
84
 
85
    CYGARC_MEMDESC_TABLE_END
86
};
87
 
88
//--------------------------------------------------------------------------
89
// Platform init code.
90
void
91
hal_platform_init(void)
92
{
93
    cyg_uint32 bcsr, gcr, frr, eicr, iack;
94
    int vec;
95
 
96
    // Initialize I/O interfaces
97
    hal_if_init();
98
    // Reset interrupt controller/state
99
    HAL_READ_UINT32LE(_CSB281_EPIC_GCR, gcr);
100
    HAL_READ_UINT32LE(_CSB281_EPIC_FRR, frr);
101
    HAL_WRITE_UINT32LE(_CSB281_EPIC_GCR, gcr | _CSB281_EPIC_GCR_R);
102
    do {
103
        HAL_READ_UINT32LE(_CSB281_EPIC_GCR, gcr);
104
    } while ((gcr & _CSB281_EPIC_GCR_R) != 0);
105
    HAL_WRITE_UINT32LE(_CSB281_EPIC_GCR, gcr | _CSB281_EPIC_GCR_M);
106
    HAL_READ_UINT32LE(_CSB281_EPIC_EICR, eicr);  // Force direct interrupts
107
    eicr &= ~_CSB281_EPIC_EICR_SIE;
108
    HAL_WRITE_UINT32LE(_CSB281_EPIC_EICR, eicr);
109
    for (vec = CYGNUM_HAL_INTERRUPT_IRQ0; vec <= CYGNUM_HAL_ISR_MAX; vec++) {
110
        HAL_INTERRUPT_CONFIGURE(vec, 0, 0);  // Default to low-edge
111
        HAL_INTERRUPT_SET_LEVEL(vec, 0x0F);  // Priority
112
    }
113
    vec = (frr & 0x0FFF0000) >> 16;  // Number of interrupt sources
114
    while (vec-- > 0) {
115
        HAL_READ_UINT32LE(_CSB281_EPIC_IACK, iack);
116
        HAL_WRITE_UINT32LE(_CSB281_EPIC_EOI, 0);
117
    }
118
    HAL_WRITE_UINT32LE(_CSB281_EPIC_PCTPR, 1); // Enables interrupts
119
#ifndef CYGSEM_HAL_USE_ROM_MONITOR
120
    // Reset peripherals
121
    HAL_READ_UINT32(_CSB281_BCSR, bcsr);
122
    HAL_WRITE_UINT32(_CSB281_BCSR, _zero_bit(bcsr, _CSB281_BCSR_PRESET));
123
    HAL_WRITE_UINT32(_CSB281_BCSR, _one_bit(bcsr, _CSB281_BCSR_PRESET));
124
    _csb281_i2c_init();
125
    _csb281_fs6377_init(0);
126
#endif
127
#ifdef CYGSEM_CSB281_LCD_COMM
128
    lcd_comm_init();
129
#endif
130
    _csb281_pci_init();
131
}
132
 
133
//--------------------------------------------------------------------------
134
// Interrupt support
135
 
136
CYG_ADDRWORD _pvrs[] = {
137
    _CSB281_EPIC_IVPR0,     // CYGNUM_HAL_INTERRUPT_IRQ0   0x02
138
    _CSB281_EPIC_IVPR1,     // CYGNUM_HAL_INTERRUPT_IRQ1   0x03
139
    _CSB281_EPIC_IVPR2,     // CYGNUM_HAL_INTERRUPT_IRQ2   0x04
140
    _CSB281_EPIC_IVPR3,     // CYGNUM_HAL_INTERRUPT_IRQ3   0x05
141
    _CSB281_EPIC_IVPR4,     // CYGNUM_HAL_INTERRUPT_IRQ4   0x06
142
    _CSB281_EPIC_UART0VPR,  // CYGNUM_HAL_INTERRUPT_UART0  0x07
143
    _CSB281_EPIC_UART1VPR,  // CYGNUM_HAL_INTERRUPT_UART1  0x08
144
    _CSB281_EPIC_GTVPR0,    // CYGNUM_HAL_INTERRUPT_TIMER0 0x09
145
    _CSB281_EPIC_GTVPR1,    // CYGNUM_HAL_INTERRUPT_TIMER1 0x0A
146
    _CSB281_EPIC_GTVPR2,    // CYGNUM_HAL_INTERRUPT_TIMER2 0x0B
147
    _CSB281_EPIC_GTVPR3,    // CYGNUM_HAL_INTERRUPT_TIMER3 0x0C
148
    _CSB281_EPIC_I2CVPR,    // CYGNUM_HAL_INTERRUPT_I2C    0x0D
149
    _CSB281_EPIC_DMA0VPR,   // CYGNUM_HAL_INTERRUPT_DMA0   0x0E
150
    _CSB281_EPIC_DMA1VPR,   // CYGNUM_HAL_INTERRUPT_DMA1   0x0F
151
    _CSB281_EPIC_MSGVPR,    // CYGNUM_HAL_INTERRUPT_MSG    0x10
152
};
153
 
154
void
155
hal_interrupt_mask(int vector)
156
{
157
    cyg_uint32 pvr;
158
 
159
    CYG_ASSERT( vector <= CYGNUM_HAL_ISR_MAX, "Invalid vector");
160
    CYG_ASSERT( vector >= CYGNUM_HAL_ISR_MIN, "Invalid vector");
161
    if (vector < CYGNUM_HAL_INTERRUPT_IRQ0) {
162
        // Can't do much with non-external interrupts
163
        return;
164
    }
165
    HAL_READ_UINT32LE(_pvrs[vector-CYGNUM_HAL_INTERRUPT_IRQ0], pvr);
166
    pvr |= _CSB281_EPIC_PVR_M;
167
    HAL_WRITE_UINT32LE(_pvrs[vector-CYGNUM_HAL_INTERRUPT_IRQ0], pvr);
168
//    diag_printf("%s(%d)\n", __FUNCTION__, vector);
169
}
170
 
171
void
172
hal_interrupt_unmask(int vector)
173
{
174
    cyg_uint32 pvr;
175
 
176
    CYG_ASSERT( vector <= CYGNUM_HAL_ISR_MAX, "Invalid vector");
177
    CYG_ASSERT( vector >= CYGNUM_HAL_ISR_MIN, "Invalid vector");
178
    if (vector < CYGNUM_HAL_INTERRUPT_IRQ0) {
179
        // Can't do much with non-external interrupts
180
        return;
181
    }
182
    HAL_READ_UINT32LE(_pvrs[vector-CYGNUM_HAL_INTERRUPT_IRQ0], pvr);
183
    pvr &= ~_CSB281_EPIC_PVR_M;
184
    HAL_WRITE_UINT32LE(_pvrs[vector-CYGNUM_HAL_INTERRUPT_IRQ0], pvr);
185
//    diag_printf("%s(%d)\n", __FUNCTION__, vector);
186
}
187
 
188
void
189
hal_interrupt_acknowledge(int vector)
190
{
191
}
192
 
193
void
194
hal_interrupt_configure(int vector, int level, int up)
195
{
196
    cyg_uint32 pvr;
197
 
198
    CYG_ASSERT( vector <= CYGNUM_HAL_ISR_MAX, "Invalid vector");
199
    CYG_ASSERT( vector >= CYGNUM_HAL_ISR_MIN, "Invalid vector");
200
    if (vector < CYGNUM_HAL_INTERRUPT_IRQ0) {
201
        // Can't do much with non-external interrupts
202
        return;
203
    }
204
//    diag_printf("%s(%d, %d, %d)\n", __FUNCTION__, vector, level, up);
205
    HAL_READ_UINT32LE(_pvrs[vector-CYGNUM_HAL_INTERRUPT_IRQ0], pvr);
206
    pvr &= _CSB281_EPIC_PVR_M;  // Preserve mask
207
    pvr |= vector;
208
    if (level) {
209
        pvr |= _CSB281_EPIC_PVR_S;
210
    } else {
211
        pvr &= ~_CSB281_EPIC_PVR_S;
212
    }
213
    if (up) {
214
        pvr |= _CSB281_EPIC_PVR_P;
215
    } else {
216
        pvr &= ~_CSB281_EPIC_PVR_P;
217
    }
218
    HAL_WRITE_UINT32LE(_pvrs[vector-CYGNUM_HAL_INTERRUPT_IRQ0], pvr);
219
}
220
 
221
void
222
hal_interrupt_set_level(int vector, int level)
223
{
224
    cyg_uint32 pvr;
225
 
226
    CYG_ASSERT( vector <= CYGNUM_HAL_ISR_MAX, "Invalid vector");
227
    CYG_ASSERT( vector >= CYGNUM_HAL_ISR_MIN, "Invalid vector");
228
    if (vector < CYGNUM_HAL_INTERRUPT_IRQ0) {
229
        // Can't do much with non-external interrupts
230
        return;
231
    }
232
    HAL_READ_UINT32LE(_pvrs[vector-CYGNUM_HAL_INTERRUPT_IRQ0], pvr);
233
    pvr &= ~(_CSB281_EPIC_PVR_PRIO_MASK<<_CSB281_EPIC_PVR_PRIO_SHIFT);
234
    pvr |= (level<<_CSB281_EPIC_PVR_PRIO_SHIFT);
235
    HAL_WRITE_UINT32LE(_pvrs[vector-CYGNUM_HAL_INTERRUPT_IRQ0], pvr);
236
}
237
 
238
 
239
//--------------------------------------------------------------------------
240
// PCI support
241
 
242
externC void
243
_csb281_pci_init(void)
244
{
245
    static int _init = 0;
246
    cyg_uint8 next_bus;
247
    cyg_uint32 cmd_state;
248
 
249
    if (_init) return;
250
    _init = 1;
251
 
252
    // Initialize PCI support
253
    cyg_pci_init();
254
 
255
    // Setup for bus mastering
256
    HAL_PCI_CFG_READ_UINT32(0, CYG_PCI_DEV_MAKE_DEVFN(0,0),
257
                            CYG_PCI_CFG_COMMAND, cmd_state);
258
    if ((cmd_state & CYG_PCI_CFG_COMMAND_MEMORY) == 0) {
259
        // Force PCI-side window to 0
260
        HAL_PCI_CFG_WRITE_UINT32(0, CYG_PCI_DEV_MAKE_DEVFN(0,0),
261
                                 CYG_PCI_CFG_BAR_0, 0x01);
262
        // Enable bus mastering from host
263
        HAL_PCI_CFG_WRITE_UINT32(0, CYG_PCI_DEV_MAKE_DEVFN(0,0),
264
                                 CYG_PCI_CFG_COMMAND,
265
                                 CYG_PCI_CFG_COMMAND_MEMORY |
266
                                 CYG_PCI_CFG_COMMAND_MASTER |
267
                                 CYG_PCI_CFG_COMMAND_PARITY |
268
                                 CYG_PCI_CFG_COMMAND_SERR);
269
 
270
        // Setup latency timer field
271
        HAL_PCI_CFG_WRITE_UINT8(0, CYG_PCI_DEV_MAKE_DEVFN(0,0),
272
                                CYG_PCI_CFG_LATENCY_TIMER, 32);
273
 
274
        // Configure PCI bus.
275
        next_bus = 1;
276
        cyg_pci_configure_bus(0, &next_bus);
277
    }
278
 
279
    // Configure interrupts (high level)?
280
    HAL_INTERRUPT_CONFIGURE(CYGNUM_HAL_INTERRUPT_PCI0, 1, 1);
281
    HAL_INTERRUPT_CONFIGURE(CYGNUM_HAL_INTERRUPT_PCI1, 1, 1);
282
    HAL_INTERRUPT_CONFIGURE(CYGNUM_HAL_INTERRUPT_LAN, 1, 1);
283
}
284
 
285
externC void
286
_csb281_pci_translate_interrupt(int bus, int devfn, int *vec, int *valid)
287
{
288
    cyg_uint8 dev = CYG_PCI_DEV_GET_DEV(devfn);
289
 
290
    // Purely slot based
291
    if (dev >= CYG_PCI_MIN_DEV) {
292
        CYG_ADDRWORD __translation[] = {
293
            CYGNUM_HAL_INTERRUPT_PCI0,
294
            CYGNUM_HAL_INTERRUPT_PCI1,
295
            CYGNUM_HAL_INTERRUPT_LAN
296
        };
297
        *vec = __translation[dev-CYG_PCI_MIN_DEV];
298
        *valid = true;
299
    } else {
300
        *valid = false;
301
    }
302
#if 0
303
    diag_printf("Int - dev: %d, vector: %d [%s]\n",
304
                dev, *vec, *valid ? "OK" : "BAD");
305
#endif
306
}
307
 
308
// PCI configuration space access
309
#define _EXT_ENABLE                     0x80000000
310
 
311
//
312
// Prepare for a config cycle on the PCI bus
313
//
314
static __inline__ cyg_uint32
315
_cfg_sel(int bus, int devfn, int offset)
316
{
317
    cyg_uint32 cfg_addr, addr;
318
    cyg_uint32 bcsr;
319
 
320
    HAL_READ_UINT32(_CSB281_BCSR, bcsr);
321
    bcsr = (bcsr & ~0x07) | (1<<(CYG_PCI_DEV_GET_DEV(devfn)-CYG_PCI_MIN_DEV));
322
    HAL_WRITE_UINT32(_CSB281_BCSR, bcsr);
323
    cfg_addr = _EXT_ENABLE |
324
        (bus << 16) |
325
        (CYG_PCI_DEV_GET_DEV(devfn) << 11) |
326
        (CYG_PCI_DEV_GET_FN(devfn) << 8) |
327
        ((offset & 0xFF) << 0);
328
    HAL_WRITE_UINT32LE(_CSB281_PCI_CONFIG_ADDR, cfg_addr);
329
    addr = _CSB281_PCI_CONFIG_DATA + (offset & 0x03);
330
    return addr;
331
}
332
 
333
externC cyg_uint8
334
_csb281_pci_cfg_read_uint8(int bus, int devfn, int offset)
335
{
336
    cyg_uint32 addr;
337
    cyg_uint8 cfg_val = (cyg_uint8)0xFF;
338
 
339
#ifdef CYGPKG_IO_PCI_DEBUG
340
    diag_printf("%s(bus=%x, devfn=%x, offset=%x) = ", __FUNCTION__, bus, devfn, offset);
341
#endif // CYGPKG_IO_PCI_DEBUG
342
    addr = _cfg_sel(bus, devfn, offset);
343
    HAL_READ_UINT8LE(addr, cfg_val);
344
#if 0
345
    HAL_READ_UINT16(_CSB281_PCI_STAT_CMD, status);
346
    if (status & _CSB281_PCI_STAT_ERROR_MASK) {
347
        // Cycle failed - clean up and get out
348
        cfg_val = (cyg_uint8)0xFF;
349
        HAL_WRITE_UINT16(_CSB281_PCI_STAT_CMD, status & _CSB281_PCI_STAT_ERROR_MASK);
350
    }
351
#endif
352
#ifdef CYGPKG_IO_PCI_DEBUG
353
    diag_printf("%x\n", cfg_val);
354
#endif // CYGPKG_IO_PCI_DEBUG
355
    HAL_WRITE_UINT32(_CSB281_PCI_CONFIG_ADDR, 0);
356
    return cfg_val;
357
}
358
 
359
externC cyg_uint16
360
_csb281_pci_cfg_read_uint16(int bus, int devfn, int offset)
361
{
362
    cyg_uint32 addr;
363
    cyg_uint16 cfg_val = (cyg_uint16)0xFFFF;
364
 
365
#ifdef CYGPKG_IO_PCI_DEBUG
366
    diag_printf("%s(bus=%x, devfn=%x, offset=%x) = ", __FUNCTION__, bus, devfn, offset);
367
#endif // CYGPKG_IO_PCI_DEBUG
368
    addr = _cfg_sel(bus, devfn, offset);
369
    HAL_READ_UINT16LE(addr, cfg_val);
370
#if 0
371
    HAL_READ_UINT16LE(_CSB281_PCI_STAT_CMD, status);
372
    if (status & _CSB281_PCI_STAT_ERROR_MASK) {
373
        // Cycle failed - clean up and get out
374
        cfg_val = (cyg_uint16)0xFFFF;
375
        HAL_WRITE_UINT16(_CSB281_PCI_STAT_CMD, status & _CSB281_PCI_STAT_ERROR_MASK);
376
    }
377
#endif
378
#ifdef CYGPKG_IO_PCI_DEBUG
379
    diag_printf("%x\n", cfg_val);
380
#endif // CYGPKG_IO_PCI_DEBUG
381
    HAL_WRITE_UINT32(_CSB281_PCI_CONFIG_ADDR, 0);
382
    return cfg_val;
383
}
384
 
385
externC cyg_uint32
386
_csb281_pci_cfg_read_uint32(int bus, int devfn, int offset)
387
{
388
    cyg_uint32 addr;
389
    cyg_uint32 cfg_val = (cyg_uint32)0xFFFFFFFF;
390
 
391
#ifdef CYGPKG_IO_PCI_DEBUG
392
    diag_printf("%s(bus=%x, devfn=%x, offset=%x) = ", __FUNCTION__, bus, devfn, offset);
393
#endif // CYGPKG_IO_PCI_DEBUG
394
    addr = _cfg_sel(bus, devfn, offset);
395
    HAL_READ_UINT32LE(addr, cfg_val);
396
#if 0
397
    HAL_READ_UINT16(_CSB281_PCI_STAT_CMD, status);
398
    if (status & _CSB281_PCI_STAT_ERROR_MASK) {
399
        // Cycle failed - clean up and get out
400
        cfg_val = (cyg_uint32)0xFFFFFFFF;
401
        HAL_WRITE_UINT16(_CSB281_PCI_STAT_CMD, status & _CSB281_PCI_STAT_ERROR_MASK);
402
    }
403
#endif
404
#ifdef CYGPKG_IO_PCI_DEBUG
405
    diag_printf("%x\n", cfg_val);
406
#endif // CYGPKG_IO_PCI_DEBUG
407
    HAL_WRITE_UINT32(_CSB281_PCI_CONFIG_ADDR, 0);
408
    return cfg_val;
409
}
410
 
411
externC void
412
_csb281_pci_cfg_write_uint8(int bus, int devfn, int offset, cyg_uint8 cfg_val)
413
{
414
    cyg_uint32 addr;
415
 
416
#ifdef CYGPKG_IO_PCI_DEBUG
417
    diag_printf("%s(bus=%x, devfn=%x, offset=%x, val=%x)\n", __FUNCTION__, bus, devfn, offset, cfg_val);
418
#endif // CYGPKG_IO_PCI_DEBUG
419
    addr = _cfg_sel(bus, devfn, offset);
420
    HAL_WRITE_UINT8LE(addr, cfg_val);
421
#if 0
422
    HAL_READ_UINT16(_CSB281_PCI_STAT_CMD, status);
423
    if (status & _CSB281_PCI_STAT_ERROR_MASK) {
424
        // Cycle failed - clean up and get out
425
        HAL_WRITE_UINT16(_CSB281_PCI_STAT_CMD, status & _CSB281_PCI_STAT_ERROR_MASK);
426
    }
427
#endif
428
    HAL_WRITE_UINT32(_CSB281_PCI_CONFIG_ADDR, 0);
429
}
430
 
431
externC void
432
_csb281_pci_cfg_write_uint16(int bus, int devfn, int offset, cyg_uint16 cfg_val)
433
{
434
    cyg_uint32 addr;
435
 
436
#ifdef CYGPKG_IO_PCI_DEBUG
437
    diag_printf("%s(bus=%x, devfn=%x, offset=%x, val=%x)\n", __FUNCTION__, bus, devfn, offset, cfg_val);
438
#endif // CYGPKG_IO_PCI_DEBUG
439
    addr = _cfg_sel(bus, devfn, offset);
440
    HAL_WRITE_UINT16LE(addr, cfg_val);
441
#if 0
442
    HAL_READ_UINT16(_CSB281_PCI_STAT_CMD, status);
443
    if (status & _CSB281_PCI_STAT_ERROR_MASK) {
444
        // Cycle failed - clean up and get out
445
        HAL_WRITE_UINT16(_CSB281_PCI_STAT_CMD, status & _CSB281_PCI_STAT_ERROR_MASK);
446
    }
447
#endif
448
    HAL_WRITE_UINT32(_CSB281_PCI_CONFIG_ADDR, 0);
449
}
450
 
451
externC void
452
_csb281_pci_cfg_write_uint32(int bus, int devfn, int offset, cyg_uint32 cfg_val)
453
{
454
    cyg_uint32 addr;
455
 
456
#ifdef CYGPKG_IO_PCI_DEBUG
457
    diag_printf("%s(bus=%x, devfn=%x, offset=%x, val=%x)\n", __FUNCTION__, bus, devfn, offset, cfg_val);
458
#endif // CYGPKG_IO_PCI_DEBUG
459
    addr = _cfg_sel(bus, devfn, offset);
460
    HAL_WRITE_UINT32LE(addr, cfg_val);
461
#if 0
462
    HAL_READ_UINT16(_CSB281_PCI_STAT_CMD, status);
463
    if (status & _CSB281_PCI_STAT_ERROR_MASK) {
464
        // Cycle failed - clean up and get out
465
        HAL_WRITE_UINT16(_CSB281_PCI_STAT_CMD, status & _CSB281_PCI_STAT_ERROR_MASK);
466
    }
467
#endif
468
    HAL_WRITE_UINT32(_CSB281_PCI_CONFIG_ADDR, 0);
469
}
470
 
471
//--------------------------------------------------------------------------
472
// I2C support
473
static void
474
_csb281_i2c_init(void)
475
{
476
    HAL_WRITE_UINT32(_CSB281_2WCSR, _CSB281_2WCSR_SET_ALL);   // SDA=1, SCL=1
477
}
478
 
479
static void
480
_csb281_i2c_delay(void)
481
{
482
    int ctr;
483
 
484
    for (ctr = 0;  ctr < 100*10;  ctr++);
485
}
486
 
487
// Issue start sequence which is SDA(1->0) with SCL(1)
488
static void
489
_csb281_i2c_start(void)
490
{
491
    HAL_WRITE_UINT32(_CSB281_2WCSR, _CSB281_2WCSR_SET_SDA);   // SDA=1, SCL=?
492
    _csb281_i2c_delay();
493
    HAL_WRITE_UINT32(_CSB281_2WCSR, _CSB281_2WCSR_SET_SCL);   // SDA=1, SCL=1
494
    _csb281_i2c_delay();
495
    HAL_WRITE_UINT32(_CSB281_2WCSR, _CSB281_2WCSR_CLR_SDA);   // SDA=0, SCL=1
496
    _csb281_i2c_delay();
497
    HAL_WRITE_UINT32(_CSB281_2WCSR, _CSB281_2WCSR_CLR_SCL);   // SDA=0, SCL=0
498
    _csb281_i2c_delay();
499
    HAL_WRITE_UINT32(_CSB281_2WCSR, _CSB281_2WCSR_SET_SDA);   // SDA=1, SCL=1
500
    _csb281_i2c_delay();
501
}
502
 
503
// Issue stop sequence which is SDA(0->1) with SCL(1)
504
static void
505
_csb281_i2c_stop(void)
506
{
507
    HAL_WRITE_UINT32(_CSB281_2WCSR, _CSB281_2WCSR_CLR_SDA);   // SDA=0, SCL=?
508
    _csb281_i2c_delay();
509
    HAL_WRITE_UINT32(_CSB281_2WCSR, _CSB281_2WCSR_SET_SCL);   // SDA=1, SCL=1
510
    _csb281_i2c_delay();
511
    HAL_WRITE_UINT32(_CSB281_2WCSR, _CSB281_2WCSR_SET_SDA);   // SDA=1, SCL=1
512
    _csb281_i2c_delay();
513
    HAL_WRITE_UINT32(_CSB281_2WCSR, _CSB281_2WCSR_CLR_SCL);   // SDA=0, SCL=0
514
    _csb281_i2c_delay();
515
}
516
 
517
// Send an 8-bit value, MSB first, SCL(1->0) clocks the data
518
static int
519
_csb281_i2c_put(unsigned char val)
520
{
521
    int bit, csr;
522
 
523
    for (bit = 7;  bit >= 0;  bit--) {
524
        if ((val & (1 << bit))) {
525
            HAL_WRITE_UINT32(_CSB281_2WCSR, _CSB281_2WCSR_SET_SDA);   // SDA=1, SCL=?
526
        } else {
527
            HAL_WRITE_UINT32(_CSB281_2WCSR, _CSB281_2WCSR_CLR_SDA);   // SDA=0, SCL=?
528
        }
529
        _csb281_i2c_delay();
530
        HAL_WRITE_UINT32(_CSB281_2WCSR, _CSB281_2WCSR_SET_SCL);   // SDA=?, SCL=1
531
        _csb281_i2c_delay();
532
        HAL_WRITE_UINT32(_CSB281_2WCSR, _CSB281_2WCSR_CLR_SCL);   // SDA=?, SCL=0
533
    }
534
    // Now wait for ACK
535
    HAL_WRITE_UINT32(_CSB281_2WCSR, _CSB281_2WCSR_SET_SDA);   // SDA=1, SCL=0
536
    _csb281_i2c_delay();
537
    HAL_WRITE_UINT32(_CSB281_2WCSR, _CSB281_2WCSR_SET_SCL);   // SDA=1, SCL=1
538
    _csb281_i2c_delay();
539
    HAL_READ_UINT32(_CSB281_2WCSR, csr);  // Read current state
540
    if ((csr & _CSB281_2WCSR_GET_SDA)) {
541
        // No ACK!
542
        return -1;
543
    }
544
    HAL_WRITE_UINT32(_CSB281_2WCSR, _CSB281_2WCSR_CLR_SCL);   // SDA=?, SCL=0
545
    _csb281_i2c_delay();
546
    return 0;
547
}
548
 
549
static unsigned char
550
_csb281_i2c_get(void)
551
{
552
    unsigned char val = 0;
553
    int bit, csr;
554
 
555
    for (bit = 7;  bit >= 0;  bit--) {
556
        HAL_WRITE_UINT32(_CSB281_2WCSR, _CSB281_2WCSR_SET_SCL);   // SDA=?, SCL=1
557
        _csb281_i2c_delay();
558
        HAL_READ_UINT32(_CSB281_2WCSR, csr);  // Read current state
559
        if ((csr & _CSB281_2WCSR_GET_SDA)) {
560
            val |= (1 << bit);
561
        }
562
        HAL_WRITE_UINT32(_CSB281_2WCSR, _CSB281_2WCSR_CLR_SCL);   // SDA=?, SCL=0
563
        _csb281_i2c_delay();
564
    }
565
    // Need extra transition (for ACK time slot)
566
    HAL_WRITE_UINT32(_CSB281_2WCSR, _CSB281_2WCSR_SET_SCL);   // SDA=?, SCL=0
567
    _csb281_i2c_delay();
568
    HAL_WRITE_UINT32(_CSB281_2WCSR, _CSB281_2WCSR_CLR_SCL);   // SDA=?, SCL=0
569
    _csb281_i2c_delay();
570
    return val;
571
}
572
 
573
int
574
_csb281_i2c_write_reg(int addr, int reg, unsigned char val)
575
{
576
    _csb281_i2c_start();
577
    if (_csb281_i2c_put(addr << 1) < 0) {
578
        return -1;
579
    }
580
    if (_csb281_i2c_put(reg) < 0) {
581
        return -1;
582
    }
583
    if (_csb281_i2c_put(val) < 0) {
584
        return -1;
585
    }
586
    _csb281_i2c_stop();
587
    return 0;
588
}
589
 
590
int
591
_csb281_i2c_read_reg(int addr, int reg)
592
{
593
    unsigned char val;
594
    _csb281_i2c_start();
595
    if (_csb281_i2c_put(addr << 1) < 0) {
596
        return -1;
597
    }
598
    if (_csb281_i2c_put(reg) < 0) {
599
        return -1;
600
    }
601
    _csb281_i2c_start();
602
    if (_csb281_i2c_put((addr << 1) | 0x01) < 0) {
603
        return -1;
604
    }
605
    val = _csb281_i2c_get();
606
    _csb281_i2c_stop();
607
    return val;
608
}
609
 
610
//--------------------------------------------------------------------------
611
// FS6377 Clock generator support
612
 
613
static unsigned char _fs6377_init_data[] = {
614
    0x28, 0xEF, 0x53, 0x03, 0x4B, 0x80, 0x32, 0x80,
615
    0x94, 0x32, 0x80, 0xD4, 0x56, 0xF6, 0xF6, 0xE0
616
};
617
 
618
// Setup for CRT mode 640x480 @75Hz
619
static unsigned char _fs6377_init_data_CRT[] = {
620
    0x10, 0x3b, 0x49, 0x03, 0x4B, 0x80, 0x32, 0x80,
621
    0x94, 0x32, 0x80, 0xD4, 0x66, 0xF6, 0xF6, 0xE0
622
};
623
 
624
void
625
_csb281_fs6377_init(int mode)
626
{
627
    int reg;
628
    unsigned char *data;
629
 
630
    if (mode) {
631
        data = _fs6377_init_data_CRT;
632
    } else {
633
        data = _fs6377_init_data;
634
    }
635
    for (reg = 0;  reg < 16;  reg++) {
636
        if (_csb281_i2c_write_reg(_CSB281_FS6377_DEV, reg, *data++) < 0) {
637
            diag_printf("** Can't write FS6377 register %d\n", reg);
638
            return;
639
        }
640
    }
641
}
642
 
643
//--------------------------------------------------------------------------
644
// Blink the value 'val' into the LEDs
645
//   LED0 - clock
646
//   LED1 - value
647
 
648
static void
649
_set_leds(int led0, int led1)
650
{
651
    cyg_uint32 bcsr;
652
 
653
    HAL_READ_UINT32(_CSB281_BCSR, bcsr);
654
    bcsr = _one_bit(bcsr, (_CSB281_BCSR_LED0 | _CSB281_BCSR_LED1));
655
    if (led0) bcsr = _zero_bit(bcsr, _CSB281_BCSR_LED0);
656
    if (led1) bcsr = _zero_bit(bcsr, _CSB281_BCSR_LED1);
657
    HAL_WRITE_UINT32(_CSB281_BCSR, bcsr);
658
}
659
 
660
static void
661
_led_delay(int len)
662
{
663
    int ctr, limit;
664
    int cache_state;
665
 
666
    HAL_ICACHE_IS_ENABLED(cache_state);
667
    limit = cache_state ? 0x100000 : 0x40000;
668
    while (len--) {
669
        for (ctr = 0;  ctr < limit;  ctr++);
670
    }
671
}
672
 
673
void
674
_csb281_led(int val)
675
{
676
    int bit, ctr;
677
 
678
    for (ctr = 0;  ctr < 8;  ctr++) {
679
        _set_leds(0,0);
680
        _led_delay(1);
681
        _set_leds(0,1);
682
        _led_delay(1);
683
    }
684
    _set_leds(0,0);
685
    _led_delay(16);
686
    for (bit = 7;  bit >= 0;  bit--) {
687
        _set_leds(1, val & (1<<bit));
688
        _led_delay(8);
689
        _set_leds(0, 0);
690
        _led_delay(8);
691
    }
692
}
693
 
694
// EOF hal_aux.c

powered by: WebSVN 2.1.0

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