1 /* arch/arm/mach-goldfish/board-goldfish.c
2 **
3 ** Copyright (C) 2007 Google, Inc.
4 **
5 ** This software is licensed under the terms of the GNU General Public
6 ** License version 2, as published by the Free Software Foundation, and
7 ** may be copied, distributed, and modified under those terms.
8 **
9 ** This program is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ** GNU General Public License for more details.
13 **
14 */
15
16 #include <linux/kernel.h>
17 #include <linux/dma-mapping.h>
18 #include <linux/init.h>
19 #include <linux/interrupt.h>
20 #include <linux/irq.h>
21 #include <linux/platform_device.h>
22 #include <linux/delay.h>
23 #include <linux/mtd/mtd.h>
24 #include <linux/mtd/nand.h>
25 #include <linux/mtd/partitions.h>
26 #include <linux/input.h>
27 #include <linux/memblock.h>
28
29 #include <mach/hardware.h>
30 #include <asm/io.h>
31 #include <asm/mach-types.h>
32 #include <asm/mach/arch.h>
33 #include <asm/mach/flash.h>
34 #include <asm/mach/map.h>
35 #include <asm/mach/time.h>
36
37 #include "pdev_bus.h"
38
39 int GOLDFISH_READY = 0;
40
41 static struct resource goldfish_pdev_bus_resources[] = {
42 {
43 .start = GOLDFISH_PDEV_BUS_BASE,
44 .end = GOLDFISH_PDEV_BUS_BASE + GOLDFISH_PDEV_BUS_END - 1,
45 .flags = IORESOURCE_IO,
46 },
47 {
48 .start = IRQ_PDEV_BUS,
49 .end = IRQ_PDEV_BUS,
50 .flags = IORESOURCE_IRQ,
51 }
52 };
53
54
55 struct platform_device goldfish_pdev_bus_device = {
56 .name = "goldfish_pdev_bus",
57 .id = -1,
58 .num_resources = ARRAY_SIZE(goldfish_pdev_bus_resources),
59 .resource = goldfish_pdev_bus_resources
60 };
61
62 #ifdef CONFIG_FB_GOLDFISH
63 static struct resource goldfish_fb_resources[] = {
64 {
65 .start = 0, /* to be filled in by goldfish_reserve() */
66 .end = 0,
67 .flags = IORESOURCE_MEM,
68 }
69 };
70
71 static struct pdev_extra_resources goldfish_fb_extra_resources = {
72 .name = "goldfish_fb",
73 .num_resources = ARRAY_SIZE(goldfish_fb_resources),
74 .resource = goldfish_fb_resources,
75 };
76 #endif
77
goldfish_init(void)78 static void __init goldfish_init(void)
79 {
80 platform_device_register(&goldfish_pdev_bus_device);
81 }
82
goldfish_mask_irq(struct irq_data * d)83 void goldfish_mask_irq(struct irq_data *d)
84 {
85 writel(d->irq, IO_ADDRESS(GOLDFISH_INTERRUPT_BASE) + GOLDFISH_INTERRUPT_DISABLE);
86 }
87
goldfish_unmask_irq(struct irq_data * d)88 void goldfish_unmask_irq(struct irq_data *d)
89 {
90 writel(d->irq, IO_ADDRESS(GOLDFISH_INTERRUPT_BASE) + GOLDFISH_INTERRUPT_ENABLE);
91 }
92
93 static struct irq_chip goldfish_irq_chip = {
94 .name = "goldfish",
95 .irq_mask = goldfish_mask_irq,
96 .irq_mask_ack = goldfish_mask_irq,
97 .irq_unmask = goldfish_unmask_irq,
98 };
99
goldfish_init_irq(void)100 void goldfish_init_irq(void)
101 {
102 unsigned int i;
103 uint32_t int_base = IO_ADDRESS(GOLDFISH_INTERRUPT_BASE);
104
105 /*
106 * Disable all interrupt sources
107 */
108 writel(1, int_base + GOLDFISH_INTERRUPT_DISABLE_ALL);
109
110 for (i = 0; i < NR_IRQS; i++) {
111 irq_set_chip(i, &goldfish_irq_chip);
112 irq_set_handler(i, handle_level_irq);
113 set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
114 }
115 }
116
117 static struct map_desc goldfish_io_desc[] __initdata = {
118 {
119 .virtual = IO_BASE,
120 .pfn = __phys_to_pfn(IO_START),
121 .length = IO_SIZE,
122 .type = MT_DEVICE
123 },
124 };
125
goldfish_reserve(void)126 static void __init goldfish_reserve(void)
127 {
128 #ifdef CONFIG_FB_GOLDFISH
129 struct resource *fbmem = &goldfish_fb_resources[0];
130 const size_t fbmem_size = SZ_16M;
131
132 fbmem->start = memblock_alloc(fbmem_size, PAGE_SIZE);
133 fbmem->end = fbmem->start + fbmem_size - 1;
134 goldfish_pdev_bus_add_extra_resources(&goldfish_fb_extra_resources);
135 #endif
136 }
137
goldfish_map_io(void)138 static void __init goldfish_map_io(void)
139 {
140 iotable_init(goldfish_io_desc, ARRAY_SIZE(goldfish_io_desc));
141 GOLDFISH_READY = 1;
142 }
143
144 extern void __init goldfish_timer_init(void);
145
146 MACHINE_START(GOLDFISH, "Goldfish")
147 .reserve = goldfish_reserve,
148 .map_io = goldfish_map_io,
149 .init_irq = goldfish_init_irq,
150 .init_machine = goldfish_init,
151 .init_time = goldfish_timer_init,
152 MACHINE_END
153