blob: 0f65177f9e5fafabcd897ee610915d1e4409d49a [file] [log] [blame]
Uwe Kleine-König9918cda2007-02-16 15:36:55 +01001/*
2 * arch/arm/mach-ns9xxx/board-a9m9750dev.c
3 *
4 * Copyright (C) 2006,2007 by Digi International Inc.
5 * All rights reserved.
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation.
10 */
11#include <linux/platform_device.h>
12#include <linux/serial_8250.h>
13#include <linux/irq.h>
14
15#include <asm/mach/map.h>
Uwe Kleine-Königc54ecb22007-09-30 20:36:14 +010016#include <asm/gpio.h>
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010017
18#include <asm/arch-ns9xxx/board.h>
19#include <asm/arch-ns9xxx/regs-sys.h>
20#include <asm/arch-ns9xxx/regs-mem.h>
21#include <asm/arch-ns9xxx/regs-bbu.h>
22#include <asm/arch-ns9xxx/regs-board-a9m9750dev.h>
23
24#include "board-a9m9750dev.h"
25
26static struct map_desc board_a9m9750dev_io_desc[] __initdata = {
27 { /* FPGA on CS0 */
28 .virtual = io_p2v(NS9XXX_CSxSTAT_PHYS(0)),
29 .pfn = __phys_to_pfn(NS9XXX_CSxSTAT_PHYS(0)),
30 .length = NS9XXX_CS0STAT_LENGTH,
31 .type = MT_DEVICE,
32 },
33};
34
35void __init board_a9m9750dev_map_io(void)
36{
37 iotable_init(board_a9m9750dev_io_desc,
38 ARRAY_SIZE(board_a9m9750dev_io_desc));
39}
40
41static void a9m9750dev_fpga_ack_irq(unsigned int irq)
42{
43 /* nothing */
44}
45
46static void a9m9750dev_fpga_mask_irq(unsigned int irq)
47{
Uwe Kleine-König361c7ad2007-09-30 20:36:33 +010048 u8 ier;
49
50 ier = __raw_readb(FPGA_IER);
51
52 ier &= ~(1 << (irq - FPGA_IRQ(0)));
53
54 __raw_writeb(ier, FPGA_IER);
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010055}
56
57static void a9m9750dev_fpga_maskack_irq(unsigned int irq)
58{
59 a9m9750dev_fpga_mask_irq(irq);
60 a9m9750dev_fpga_ack_irq(irq);
61}
62
63static void a9m9750dev_fpga_unmask_irq(unsigned int irq)
64{
Uwe Kleine-König361c7ad2007-09-30 20:36:33 +010065 u8 ier;
66
67 ier = __raw_readb(FPGA_IER);
68
69 ier |= 1 << (irq - FPGA_IRQ(0));
70
71 __raw_writeb(ier, FPGA_IER);
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010072}
73
74static struct irq_chip a9m9750dev_fpga_chip = {
75 .ack = a9m9750dev_fpga_ack_irq,
76 .mask = a9m9750dev_fpga_mask_irq,
77 .mask_ack = a9m9750dev_fpga_maskack_irq,
78 .unmask = a9m9750dev_fpga_unmask_irq,
79};
80
81static void a9m9750dev_fpga_demux_handler(unsigned int irq,
82 struct irq_desc *desc)
83{
Uwe Kleine-König361c7ad2007-09-30 20:36:33 +010084 u8 stat = __raw_readb(FPGA_ISR);
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010085
Uwe Kleine-Königba7d8502007-09-30 20:34:41 +010086 desc->chip->mask_ack(irq);
87
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010088 while (stat != 0) {
89 int irqno = fls(stat) - 1;
Uwe Kleine-Königba7d8502007-09-30 20:34:41 +010090 struct irq_desc *fpgadesc;
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010091
92 stat &= ~(1 << irqno);
93
Uwe Kleine-Königba7d8502007-09-30 20:34:41 +010094 fpgadesc = irq_desc + FPGA_IRQ(irqno);
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010095
Uwe Kleine-Königba7d8502007-09-30 20:34:41 +010096 desc_handle_irq(FPGA_IRQ(irqno), fpgadesc);
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010097 }
Uwe Kleine-Königba7d8502007-09-30 20:34:41 +010098
99 desc->chip->unmask(irq);
Uwe Kleine-König9918cda2007-02-16 15:36:55 +0100100}
101
102void __init board_a9m9750dev_init_irq(void)
103{
Uwe Kleine-König361c7ad2007-09-30 20:36:33 +0100104 u32 eic;
Uwe Kleine-König9918cda2007-02-16 15:36:55 +0100105 int i;
106
Uwe Kleine-Königc54ecb22007-09-30 20:36:14 +0100107 if (gpio_request(11, "board a9m9750dev extirq2") == 0)
108 ns9xxx_gpio_configure(11, 0, 1);
109 else
110 printk(KERN_ERR "%s: cannot get gpio 11 for IRQ_EXT2\n",
111 __func__);
Uwe Kleine-König9918cda2007-02-16 15:36:55 +0100112
113 for (i = FPGA_IRQ(0); i <= FPGA_IRQ(7); ++i) {
114 set_irq_chip(i, &a9m9750dev_fpga_chip);
115 set_irq_handler(i, handle_level_irq);
116 set_irq_flags(i, IRQF_VALID);
117 }
118
119 /* IRQ_EXT2: level sensitive + active low */
Uwe Kleine-König361c7ad2007-09-30 20:36:33 +0100120 eic = __raw_readl(SYS_EIC(2));
121 REGSET(eic, SYS_EIC, PLTY, AL);
122 REGSET(eic, SYS_EIC, LVEDG, LEVEL);
123 __raw_writel(eic, SYS_EIC(2));
Uwe Kleine-König9918cda2007-02-16 15:36:55 +0100124
125 set_irq_chained_handler(IRQ_EXT2,
126 a9m9750dev_fpga_demux_handler);
127}
128
129static struct plat_serial8250_port board_a9m9750dev_serial8250_port[] = {
130 {
131 .iobase = FPGA_UARTA_BASE,
132 .membase = (unsigned char*)FPGA_UARTA_BASE,
133 .mapbase = FPGA_UARTA_BASE,
134 .irq = IRQ_FPGA_UARTA,
135 .iotype = UPIO_MEM,
136 .uartclk = 18432000,
137 .regshift = 0,
138 .flags = UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ,
139 }, {
140 .iobase = FPGA_UARTB_BASE,
141 .membase = (unsigned char*)FPGA_UARTB_BASE,
142 .mapbase = FPGA_UARTB_BASE,
143 .irq = IRQ_FPGA_UARTB,
144 .iotype = UPIO_MEM,
145 .uartclk = 18432000,
146 .regshift = 0,
147 .flags = UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ,
148 }, {
149 .iobase = FPGA_UARTC_BASE,
150 .membase = (unsigned char*)FPGA_UARTC_BASE,
151 .mapbase = FPGA_UARTC_BASE,
152 .irq = IRQ_FPGA_UARTC,
153 .iotype = UPIO_MEM,
154 .uartclk = 18432000,
155 .regshift = 0,
156 .flags = UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ,
157 }, {
158 .iobase = FPGA_UARTD_BASE,
159 .membase = (unsigned char*)FPGA_UARTD_BASE,
160 .mapbase = FPGA_UARTD_BASE,
161 .irq = IRQ_FPGA_UARTD,
162 .iotype = UPIO_MEM,
163 .uartclk = 18432000,
164 .regshift = 0,
165 .flags = UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ,
166 }, {
167 /* end marker */
168 },
169};
170
171static struct platform_device board_a9m9750dev_serial_device = {
172 .name = "serial8250",
173 .dev = {
174 .platform_data = board_a9m9750dev_serial8250_port,
175 },
176};
177
178static struct platform_device *board_a9m9750dev_devices[] __initdata = {
179 &board_a9m9750dev_serial_device,
180};
181
182void __init board_a9m9750dev_init_machine(void)
183{
184 u32 reg;
185
186 /* setup static CS0: memory base ... */
Uwe Kleine-König361c7ad2007-09-30 20:36:33 +0100187 reg = __raw_readl(SYS_SMCSSMB(0));
188 REGSETIM(reg, SYS_SMCSSMB, CSxB, NS9XXX_CSxSTAT_PHYS(0) >> 12);
189 __raw_writel(reg, SYS_SMCSSMB(0));
Uwe Kleine-König9918cda2007-02-16 15:36:55 +0100190
191 /* ... and mask */
Uwe Kleine-König361c7ad2007-09-30 20:36:33 +0100192 reg = __raw_readl(SYS_SMCSSMM(0));
Uwe Kleine-König9918cda2007-02-16 15:36:55 +0100193 REGSETIM(reg, SYS_SMCSSMM, CSxM, 0xfffff);
194 REGSET(reg, SYS_SMCSSMM, CSEx, EN);
Uwe Kleine-König361c7ad2007-09-30 20:36:33 +0100195 __raw_writel(reg, SYS_SMCSSMM(0));
Uwe Kleine-König9918cda2007-02-16 15:36:55 +0100196
197 /* setup static CS0: memory configuration */
Uwe Kleine-König361c7ad2007-09-30 20:36:33 +0100198 reg = __raw_readl(MEM_SMC(0));
Uwe Kleine-Königf4ae6412007-07-17 22:35:52 +0100199 REGSET(reg, MEM_SMC, PSMC, OFF);
Uwe Kleine-König9918cda2007-02-16 15:36:55 +0100200 REGSET(reg, MEM_SMC, BSMC, OFF);
201 REGSET(reg, MEM_SMC, EW, OFF);
202 REGSET(reg, MEM_SMC, PB, 1);
203 REGSET(reg, MEM_SMC, PC, AL);
204 REGSET(reg, MEM_SMC, PM, DIS);
205 REGSET(reg, MEM_SMC, MW, 8);
Uwe Kleine-König361c7ad2007-09-30 20:36:33 +0100206 __raw_writel(reg, MEM_SMC(0));
Uwe Kleine-König9918cda2007-02-16 15:36:55 +0100207
208 /* setup static CS0: timing */
Uwe Kleine-König361c7ad2007-09-30 20:36:33 +0100209 __raw_writel(0x2, MEM_SMWED(0));
210 __raw_writel(0x2, MEM_SMOED(0));
211 __raw_writel(0x6, MEM_SMRD(0));
212 __raw_writel(0x6, MEM_SMWD(0));
Uwe Kleine-König9918cda2007-02-16 15:36:55 +0100213
214 platform_add_devices(board_a9m9750dev_devices,
215 ARRAY_SIZE(board_a9m9750dev_devices));
216}