1 | /** |
---|
2 | * @file |
---|
3 | * @ingroup leon2_rasta |
---|
4 | * @brief GR-RASTA-IO PCI board driver |
---|
5 | */ |
---|
6 | |
---|
7 | /* |
---|
8 | * GR-RASTA-IO PCI board driver |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.rtems.org/license/LICENSE. |
---|
13 | */ |
---|
14 | |
---|
15 | #include <rtems/bspIo.h> |
---|
16 | #include <pci.h> |
---|
17 | #include <rasta.h> |
---|
18 | #include <ambapp.h> |
---|
19 | #include <grlib.h> |
---|
20 | #include <grcan_rasta.h> |
---|
21 | #include <grspw_rasta.h> |
---|
22 | #include <b1553brm_rasta.h> |
---|
23 | #include <apbuart_rasta.h> |
---|
24 | |
---|
25 | #include <string.h> |
---|
26 | |
---|
27 | /* If RASTA_SRAM is defined SRAM will be used, else SDRAM */ |
---|
28 | /*#define RASTA_SRAM 1*/ |
---|
29 | |
---|
30 | #define RASTA_IRQ 5 |
---|
31 | |
---|
32 | /* Offset from 0x80000000 (dual bus version) */ |
---|
33 | #define AHB1_IOAREA_BASE_ADDR 0x80100000 |
---|
34 | #define APB2_OFFSET 0x200000 |
---|
35 | #define IRQ_OFFSET 0x200500 |
---|
36 | #define GRHCAN_OFFSET 0x201000 |
---|
37 | #define BRM_OFFSET 0x100000 |
---|
38 | #define SPW_OFFSET 0xa00 |
---|
39 | #define UART_OFFSET 0x200200 |
---|
40 | #define GPIO0_OFF 0x200600 |
---|
41 | #define GPIO1_OFF 0x200700 |
---|
42 | |
---|
43 | /* #define DEBUG 1 */ |
---|
44 | |
---|
45 | #ifdef DEBUG |
---|
46 | #define DBG(x...) printk(x) |
---|
47 | #else |
---|
48 | #define DBG(x...) |
---|
49 | #endif |
---|
50 | |
---|
51 | static int bus, dev, fun; |
---|
52 | |
---|
53 | struct irqmp_regs *irq = NULL; |
---|
54 | LEON_Register_Map *regs = (LEON_Register_Map *)0x80000000; |
---|
55 | |
---|
56 | struct gpio_reg *gpio0, *gpio1; |
---|
57 | |
---|
58 | /* static rtems_isr pci_interrupt_handler (rtems_vector_number v) { */ |
---|
59 | |
---|
60 | /* volatile unsigned int *pci_int = (volatile unsigned int *) 0x80000168;*/ |
---|
61 | /* volatile unsigned int *pci_mem = (volatile unsigned int *) 0xb0400000;*/ |
---|
62 | |
---|
63 | /* if (*pci_int & 0x20) { */ |
---|
64 | |
---|
65 | /* *pci_int = 0x20; */ |
---|
66 | |
---|
67 | /* *pci_mem = 0; */ |
---|
68 | |
---|
69 | /* printk("pci died\n"); */ |
---|
70 | |
---|
71 | /* } */ |
---|
72 | |
---|
73 | /* } */ |
---|
74 | |
---|
75 | void *uart0_int_arg, *uart1_int_arg; |
---|
76 | void *spw0_int_arg, *spw1_int_arg, *spw2_int_arg; |
---|
77 | void *grcan_int_arg; |
---|
78 | void *brm_int_arg; |
---|
79 | |
---|
80 | void (*uart0_int_handler)(int irq, void *arg) = NULL; |
---|
81 | void (*uart1_int_handler)(int irq, void *arg) = NULL; |
---|
82 | void (*spw0_int_handler)(int irq, void *arg) = NULL; |
---|
83 | void (*spw1_int_handler)(int irq, void *arg) = NULL; |
---|
84 | void (*spw2_int_handler)(int irq, void *arg) = NULL; |
---|
85 | void (*grcan_int_handler)(int irq, void *arg) = NULL; |
---|
86 | void (*brm_int_handler)(int irq, void *arg) = NULL; |
---|
87 | |
---|
88 | static rtems_isr rasta_interrupt_handler (rtems_vector_number v) |
---|
89 | { |
---|
90 | unsigned int status; |
---|
91 | |
---|
92 | status = irq->ipend; |
---|
93 | |
---|
94 | if ( (status & GRCAN_IRQ) && grcan_int_handler ) { |
---|
95 | grcan_int_handler(GRCAN_IRQNO,grcan_int_arg); |
---|
96 | } |
---|
97 | |
---|
98 | if (status & SPW_IRQ) { |
---|
99 | if ( (status & SPW0_IRQ) && spw0_int_handler ){ |
---|
100 | spw0_int_handler(SPW0_IRQNO,spw0_int_arg); |
---|
101 | } |
---|
102 | |
---|
103 | if ( (status & SPW1_IRQ) && spw1_int_handler ){ |
---|
104 | spw1_int_handler(SPW1_IRQNO,spw1_int_arg); |
---|
105 | } |
---|
106 | |
---|
107 | if ( (status & SPW2_IRQ) && spw2_int_handler ){ |
---|
108 | spw2_int_handler(SPW2_IRQNO,spw2_int_arg); |
---|
109 | } |
---|
110 | } |
---|
111 | if ((status & BRM_IRQ) && brm_int_handler ){ |
---|
112 | brm_int_handler(BRM_IRQNO,brm_int_arg); |
---|
113 | } |
---|
114 | if ( (status & UART0_IRQ) && uart0_int_handler ) { |
---|
115 | uart0_int_handler(UART0_IRQNO,uart0_int_arg); |
---|
116 | } |
---|
117 | if ( (status & UART1_IRQ) && uart1_int_handler) { |
---|
118 | uart1_int_handler(UART1_IRQNO,uart1_int_arg); |
---|
119 | } |
---|
120 | |
---|
121 | DBG("RASTA-IRQ: 0x%x\n",status); |
---|
122 | irq->iclear = status; |
---|
123 | |
---|
124 | } |
---|
125 | |
---|
126 | void rasta_interrrupt_register(void *handler, int irqno, void *arg) |
---|
127 | { |
---|
128 | DBG("RASTA: Registering irq %d\n",irqno); |
---|
129 | if ( irqno == UART0_IRQNO ){ |
---|
130 | DBG("RASTA: Registering uart0 handler: 0x%x, arg: 0x%x\n",handler,arg); |
---|
131 | uart0_int_handler = handler; |
---|
132 | uart0_int_arg = arg; |
---|
133 | |
---|
134 | /* unmask interrupt source */ |
---|
135 | irq->iclear = UART0_IRQ; |
---|
136 | irq->mask[0] |= UART0_IRQ; |
---|
137 | } |
---|
138 | |
---|
139 | if ( irqno == UART1_IRQNO ){ |
---|
140 | DBG("RASTA: Registering uart1 handler: 0x%x, arg: 0x%x\n",handler,arg); |
---|
141 | uart1_int_handler = handler; |
---|
142 | uart1_int_arg = arg; |
---|
143 | |
---|
144 | /* unmask interrupt source */ |
---|
145 | irq->iclear = UART1_IRQ; |
---|
146 | irq->mask[0] |= UART1_IRQ; |
---|
147 | } |
---|
148 | |
---|
149 | if ( irqno == SPW0_IRQNO ){ |
---|
150 | DBG("RASTA: Registering spw0 handler: 0x%x, arg: 0x%x\n",handler,arg); |
---|
151 | spw0_int_handler = handler; |
---|
152 | spw0_int_arg = arg; |
---|
153 | |
---|
154 | /* unmask interrupt source */ |
---|
155 | irq->iclear = SPW0_IRQ; |
---|
156 | irq->mask[0] |= SPW0_IRQ; |
---|
157 | } |
---|
158 | |
---|
159 | if ( irqno == SPW1_IRQNO ){ |
---|
160 | DBG("RASTA: Registering spw1 handler: 0x%x, arg: 0x%x\n",handler,arg); |
---|
161 | spw1_int_handler = handler; |
---|
162 | spw1_int_arg = arg; |
---|
163 | |
---|
164 | /* unmask interrupt source */ |
---|
165 | irq->iclear = SPW1_IRQ; |
---|
166 | irq->mask[0] |= SPW1_IRQ; |
---|
167 | } |
---|
168 | |
---|
169 | if ( irqno == SPW2_IRQNO ){ |
---|
170 | DBG("RASTA: Registering spw2 handler: 0x%x, arg: 0x%x\n",handler,arg); |
---|
171 | spw2_int_handler = handler; |
---|
172 | spw2_int_arg = arg; |
---|
173 | |
---|
174 | /* unmask interrupt source */ |
---|
175 | irq->iclear = SPW2_IRQ; |
---|
176 | irq->mask[0] |= SPW2_IRQ; |
---|
177 | } |
---|
178 | |
---|
179 | if ( irqno == GRCAN_IRQNO ){ |
---|
180 | DBG("RASTA: Registering GRCAN handler: 0x%x, arg: 0x%x\n",handler,arg); |
---|
181 | grcan_int_handler = handler; |
---|
182 | grcan_int_arg = arg; |
---|
183 | |
---|
184 | /* unmask interrupt source */ |
---|
185 | irq->iclear = GRCAN_IRQ; |
---|
186 | irq->mask[0] |= GRCAN_IRQ; |
---|
187 | } |
---|
188 | |
---|
189 | if ( irqno == BRM_IRQNO ){ |
---|
190 | DBG("RASTA: Registering BRM handler: 0x%x, arg: 0x%x\n",handler,arg); |
---|
191 | brm_int_handler = handler; |
---|
192 | brm_int_arg = arg; |
---|
193 | |
---|
194 | /* unmask interrupt source */ |
---|
195 | irq->iclear = BRM_IRQ; |
---|
196 | irq->mask[0] |= BRM_IRQ; |
---|
197 | } |
---|
198 | } |
---|
199 | |
---|
200 | |
---|
201 | int rasta_get_gpio(struct ambapp_bus *abus, int index, struct gpio_reg **regs, |
---|
202 | int *irq) |
---|
203 | { |
---|
204 | struct ambapp_apb_info dev; |
---|
205 | int cores; |
---|
206 | |
---|
207 | if ( !abus ) |
---|
208 | return -1; |
---|
209 | |
---|
210 | /* Scan PnP info for GPIO port number 'index' */ |
---|
211 | cores = ambapp_find_apbslv_next(abus, VENDOR_GAISLER, GAISLER_GPIO, &dev, |
---|
212 | index); |
---|
213 | if ( cores < 1 ) |
---|
214 | return -1; |
---|
215 | |
---|
216 | if ( regs ) |
---|
217 | *regs = (struct gpio_reg *)dev.start; |
---|
218 | |
---|
219 | if ( irq ) |
---|
220 | *irq = dev.irq; |
---|
221 | |
---|
222 | return 0; |
---|
223 | } |
---|
224 | |
---|
225 | /* AMBA Plug&Play information */ |
---|
226 | static struct ambapp_bus abus; |
---|
227 | static struct ambapp_mmap amba_maps[3]; |
---|
228 | |
---|
229 | int rasta_register(void) |
---|
230 | { |
---|
231 | unsigned int bar0, bar1, data; |
---|
232 | |
---|
233 | unsigned int *page0 = NULL; |
---|
234 | unsigned int *apb_base = NULL; |
---|
235 | int found=0; |
---|
236 | |
---|
237 | |
---|
238 | DBG("Searching for RASTA board ..."); |
---|
239 | |
---|
240 | /* Search PCI vendor/device id. */ |
---|
241 | if (BSP_pciFindDevice(0x1AC8, 0x0010, 0, &bus, &dev, &fun) == 0) { |
---|
242 | found = 1; |
---|
243 | } |
---|
244 | |
---|
245 | /* Search old PCI vendor/device id. */ |
---|
246 | if ( (!found) && |
---|
247 | (BSP_pciFindDevice(0x16E3, 0x0210, 0, &bus, &dev, &fun) == 0) ) { |
---|
248 | found = 1; |
---|
249 | } |
---|
250 | |
---|
251 | /* Did we find a RASTA board? */ |
---|
252 | if ( !found ) |
---|
253 | return -1; |
---|
254 | |
---|
255 | DBG(" found it (dev/fun: %d/%d).\n", dev, fun); |
---|
256 | |
---|
257 | pci_read_config_dword(bus, dev, fun, 0x10, &bar0); |
---|
258 | pci_read_config_dword(bus, dev, fun, 0x14, &bar1); |
---|
259 | |
---|
260 | page0 = (unsigned int *)(bar0 + 0x400000); |
---|
261 | *page0 = 0x80000000; /* Point PAGE0 to start of APB */ |
---|
262 | |
---|
263 | apb_base = (unsigned int *)(bar0+APB2_OFFSET); |
---|
264 | |
---|
265 | /* apb_base[0] = 0x000002ff; |
---|
266 | apb_base[1] = 0x8a205260; |
---|
267 | apb_base[2] = 0x00184000; */ |
---|
268 | |
---|
269 | /* Configure memory controller */ |
---|
270 | #ifdef RASTA_SRAM |
---|
271 | apb_base[0] = 0x000002ff; |
---|
272 | apb_base[1] = 0x00001260; |
---|
273 | apb_base[2] = 0x000e8000; |
---|
274 | #else |
---|
275 | apb_base[0] = 0x000002ff; |
---|
276 | apb_base[1] = 0x82206000; |
---|
277 | apb_base[2] = 0x000e8000; |
---|
278 | #endif |
---|
279 | /* Set up rasta irq controller */ |
---|
280 | irq = (struct irqmp_regs *) (bar0+IRQ_OFFSET); |
---|
281 | irq->iclear = 0xffff; |
---|
282 | irq->ilevel = 0; |
---|
283 | irq->mask[0] = 0xffff & |
---|
284 | ~(UART0_IRQ|UART1_IRQ|SPW0_IRQ|SPW1_IRQ|SPW2_IRQ|GRCAN_IRQ|BRM_IRQ); |
---|
285 | |
---|
286 | /* Configure AT697 ioport bit 7 to input pci irq */ |
---|
287 | regs->PIO_Direction &= ~(1<<7); |
---|
288 | regs->PIO_Interrupt |= (0x87<<8); /* level sensitive */ |
---|
289 | |
---|
290 | apb_base[0x100] |= 0x40000000; /* Set GRPCI mmap 0x4 */ |
---|
291 | apb_base[0x104] = 0x40000000; /* 0xA0000000; Point PAGE1 to RAM */ |
---|
292 | |
---|
293 | |
---|
294 | /* set parity error response */ |
---|
295 | pci_read_config_dword(bus, dev, fun, 0x4, &data); |
---|
296 | pci_write_config_dword(bus, dev, fun, 0x4, data|0x40); |
---|
297 | |
---|
298 | |
---|
299 | pci_master_enable(bus, dev, fun); |
---|
300 | |
---|
301 | /* install PCI interrupt vector */ |
---|
302 | /* set_vector(pci_interrupt_handler,14+0x10, 1); */ |
---|
303 | |
---|
304 | |
---|
305 | /* install interrupt vector */ |
---|
306 | set_vector(rasta_interrupt_handler, RASTA_IRQ+0x10, 1); |
---|
307 | |
---|
308 | /* Scan AMBA Plug&Play */ |
---|
309 | |
---|
310 | /* AMBA MAP bar0 (in CPU) ==> 0x80000000(remote amba address) */ |
---|
311 | amba_maps[0].size = 0x10000000; |
---|
312 | amba_maps[0].local_adr = bar0; |
---|
313 | amba_maps[0].remote_adr = 0x80000000; |
---|
314 | |
---|
315 | /* AMBA MAP bar1 (in CPU) ==> 0x40000000(remote amba address) */ |
---|
316 | amba_maps[1].size = 0x10000000; |
---|
317 | amba_maps[1].local_adr = bar1; |
---|
318 | amba_maps[1].remote_adr = 0x40000000; |
---|
319 | |
---|
320 | /* Mark end of table */ |
---|
321 | amba_maps[2].size=0; |
---|
322 | amba_maps[2].local_adr = 0; |
---|
323 | amba_maps[2].remote_adr = 0; |
---|
324 | |
---|
325 | memset(&abus,0,sizeof(abus)); |
---|
326 | |
---|
327 | /* Start AMBA PnP scan at first AHB bus */ |
---|
328 | ambapp_scan(&abus, bar0 + (AHB1_IOAREA_BASE_ADDR & ~0xf0000000), NULL, |
---|
329 | &amba_maps[0]); |
---|
330 | |
---|
331 | printk("Registering RASTA GRCAN driver\n\r"); |
---|
332 | |
---|
333 | /*grhcan_register(bar0 + GRHCAN_OFFSET, bar1);*/ |
---|
334 | grcan_rasta_int_reg=rasta_interrrupt_register; |
---|
335 | if ( grcan_rasta_ram_register(&abus,bar1+0x20000) ){ |
---|
336 | printk("Failed to register RASTA GRCAN driver\n\r"); |
---|
337 | return -1; |
---|
338 | } |
---|
339 | |
---|
340 | printk("Registering RASTA BRM driver\n\r"); |
---|
341 | |
---|
342 | /*brm_register(bar0 + BRM_OFFSET, bar1);*/ |
---|
343 | /* register the BRM RASTA driver, use 128k on RASTA SRAM... */ |
---|
344 | b1553brm_rasta_int_reg=rasta_interrrupt_register; |
---|
345 | if ( b1553brm_rasta_register(&abus,2,0,3,bar1,0x40000000) ){ |
---|
346 | printk("Failed to register BRM RASTA driver\n"); |
---|
347 | return -1; |
---|
348 | } |
---|
349 | |
---|
350 | /* provide the spacewire driver with AMBA Plug&Play |
---|
351 | * info so that it can find the GRSPW cores. |
---|
352 | */ |
---|
353 | grspw_rasta_int_reg=rasta_interrrupt_register; |
---|
354 | if ( grspw_rasta_register(&abus,bar1) ){ |
---|
355 | printk("Failed to register RASTA GRSPW driver\n\r"); |
---|
356 | return -1; |
---|
357 | } |
---|
358 | |
---|
359 | /* provide the spacewire driver with AMBA Plug&Play |
---|
360 | * info so that it can find the GRSPW cores. |
---|
361 | */ |
---|
362 | apbuart_rasta_int_reg=rasta_interrrupt_register; |
---|
363 | if ( apbuart_rasta_register(&abus) ){ |
---|
364 | printk("Failed to register RASTA APBUART driver\n\r"); |
---|
365 | return -1; |
---|
366 | } |
---|
367 | |
---|
368 | /* Find GPIO0 address */ |
---|
369 | if ( rasta_get_gpio(&abus,0,&gpio0,NULL) ){ |
---|
370 | printk("Failed to get address for RASTA GPIO0\n\r"); |
---|
371 | return -1; |
---|
372 | } |
---|
373 | |
---|
374 | /* Find GPIO1 address */ |
---|
375 | if ( rasta_get_gpio(&abus,1,&gpio1,NULL) ){ |
---|
376 | printk("Failed to get address for RASTA GPIO1\n\r"); |
---|
377 | return -1; |
---|
378 | } |
---|
379 | |
---|
380 | /* Successfully registered the RASTA board */ |
---|
381 | return 0; |
---|
382 | } |
---|