]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/hal/arm/xscale/ixdp425/v2_0/src/ixdp425_pci.c
Initial revision
[karo-tx-redboot.git] / packages / hal / arm / xscale / ixdp425 / v2_0 / src / ixdp425_pci.c
1 //==========================================================================
2 //
3 //      ixdp425_pci.c
4 //
5 //      HAL PCI 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, 2004 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):    msalter
44 // Contributors: msalter
45 // Date:         2002-12-11
46 // Purpose:      HAL PCI board support
47 // Description:  Implementations of HAL board interfaces
48 //
49 //####DESCRIPTIONEND####
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_if.h>             // calling interface API
62 #include <cyg/hal/hal_arch.h>           // Register state info
63 #include <cyg/hal/hal_diag.h>
64 #include <cyg/hal/hal_intr.h>           // Interrupt names
65 #include <cyg/hal/hal_cache.h>
66
67 #ifdef CYGPKG_IO_PCI
68 #include <cyg/io/pci_hw.h>
69 #include <cyg/io/pci.h>
70
71 #define IXP425_PCI_MAX_DEV      4
72 #define IXP425_PCI_IRQ_LINES    4
73
74 // PCI pin mappings
75 #define PCI_CLK_GPIO     14  // CLK0
76 #define PCI_RESET_GPIO   13
77 #define PCI_INTA_GPIO    11
78 #define PCI_INTB_GPIO    10
79 #define PCI_INTC_GPIO    9
80 #define PCI_INTD_GPIO    8
81
82 #define INTA    CYGNUM_HAL_INTERRUPT_GPIO11
83 #define INTB    CYGNUM_HAL_INTERRUPT_GPIO10
84 #define INTC    CYGNUM_HAL_INTERRUPT_GPIO9
85 #define INTD    CYGNUM_HAL_INTERRUPT_GPIO8
86
87 static const int pci_irq_table[IXP425_PCI_MAX_DEV][IXP425_PCI_IRQ_LINES] = {
88     {INTA, INTB, INTC, INTD},
89     {INTB, INTC, INTD, INTA},
90     {INTC, INTD, INTA, INTB},
91     {INTD, INTA, INTB, INTC}
92 };
93     
94 void
95 cyg_hal_plf_pci_translate_interrupt(cyg_uint32 bus, cyg_uint32 devfn,
96                                     CYG_ADDRWORD *vec, cyg_bool *valid)
97 {
98     cyg_uint8 pin;
99     cyg_uint32 slot = 3 - (CYG_PCI_DEV_GET_DEV(devfn) - 18);
100     
101     HAL_PCI_CFG_READ_UINT8(bus, devfn, CYG_PCI_CFG_INT_PIN, pin);
102     *vec = -1;
103     *valid = false;
104
105     if (slot < IXP425_PCI_MAX_DEV && pin <= IXP425_PCI_IRQ_LINES) {
106         *vec = pci_irq_table[slot][pin-1];
107         *valid = true;
108     }
109 }
110
111
112 #define HAL_PCI_CLOCK_ENABLE() \
113     *IXP425_GPCLKR |= GPCLKR_CLK0_ENABLE;  // GPIO(0) used for PCI clock
114
115 #define HAL_PCI_CLOCK_DISABLE() \
116     *IXP425_GPCLKR &= ~GPCLKR_CLK0_ENABLE;  // GPIO(0) used for PCI clock
117
118 #define HAL_PCI_CLOCK_CONFIG() \
119     *IXP425_GPCLKR |= GPCLKR_CLK0_PCLK2;
120
121 #define HAL_PCI_RESET_ASSERT() \
122     HAL_GPIO_OUTPUT_CLEAR(PCI_RESET_GPIO);
123
124 #define HAL_PCI_RESET_DEASSERT() \
125     HAL_GPIO_OUTPUT_SET(PCI_RESET_GPIO);
126
127 void
128 hal_plf_pci_init(void)
129 {
130 #if defined(CYG_HAL_STARTUP_ROM) || defined(CYG_HAL_STARTUP_ROMRAM)
131     HAL_PCI_RESET_ASSERT();
132     HAL_PCI_CLOCK_DISABLE();
133
134     // Set GPIO line direction
135     HAL_GPIO_OUTPUT_ENABLE(PCI_CLK_GPIO);
136     HAL_GPIO_OUTPUT_ENABLE(PCI_RESET_GPIO);
137     HAL_GPIO_OUTPUT_DISABLE(PCI_INTA_GPIO);
138     HAL_GPIO_OUTPUT_DISABLE(PCI_INTB_GPIO);
139     HAL_GPIO_OUTPUT_DISABLE(PCI_INTC_GPIO);
140     HAL_GPIO_OUTPUT_DISABLE(PCI_INTD_GPIO);
141
142     // configure PCI interrupt lines for active low irq
143     HAL_INTERRUPT_CONFIGURE(INTA, 1, 0);
144     HAL_INTERRUPT_CONFIGURE(INTB, 1, 0);
145     HAL_INTERRUPT_CONFIGURE(INTC, 1, 0);
146     HAL_INTERRUPT_CONFIGURE(INTD, 1, 0);
147
148     // wait 1ms to satisfy "minimum reset assertion time" of the PCI spec.
149     HAL_DELAY_US(1000);
150     HAL_PCI_CLOCK_CONFIG();
151     HAL_PCI_CLOCK_ENABLE();
152
153     // wait 100us to satisfy "minimum reset assertion time from clock stable" 
154     // requirement of the PCI spec.
155     HAL_DELAY_US(100);
156     HAL_PCI_RESET_DEASSERT();
157 #endif
158 }
159
160 #endif // CYGPKG_IO_PCI