blob: efaa5feb39b8b67fa457751e329991886f488e65 [file] [log] [blame]
Kuninori Morimotod55c9a92011-11-10 18:46:45 -08001/*
2 * bonito board support
3 *
4 * Copyright (C) 2011 Renesas Solutions Corp.
5 * Copyright (C) 2011 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 */
21
22#include <linux/kernel.h>
23#include <linux/init.h>
24#include <linux/interrupt.h>
25#include <linux/irq.h>
26#include <linux/platform_device.h>
27#include <linux/gpio.h>
28#include <mach/common.h>
29#include <asm/mach-types.h>
30#include <asm/mach/arch.h>
31#include <asm/mach/map.h>
32#include <asm/mach/time.h>
33#include <asm/hardware/cache-l2x0.h>
34#include <mach/r8a7740.h>
35
36/*
37 * CS Address device note
38 *----------------------------------------------------------------
39 * 0 0x0000_0000 NOR Flash (64MB) SW12 : bit3 = OFF
40 * 2 0x0800_0000 ExtNOR (64MB) SW12 : bit3 = OFF
41 * 4 -
42 * 5A -
43 * 5B 0x1600_0000 SRAM (8MB)
44 * 6 0x1800_0000 FPGA (64K)
45 * 0x1801_0000 Ether (4KB)
46 * 0x1801_1000 USB (4KB)
47 */
48
49/*
50 * SW12
51 *
52 * bit1 bit2 bit3
53 *----------------------------------------------------------------------------
54 * ON NOR WriteProtect NAND WriteProtect CS0 ExtNOR / CS2 NOR
55 * OFF NOR Not WriteProtect NAND Not WriteProtect CS0 NOR / CS2 ExtNOR
56 */
57
58/*
Kuninori Morimotob6b37e22011-11-10 18:46:56 -080059 * SCIFA5 (CN42)
60 *
61 * S38.3 = ON
62 * S39.6 = ON
63 * S43.1 = ON
64 */
65
66/*
Kuninori Morimotod55c9a92011-11-10 18:46:45 -080067 * FPGA
68 */
Kuninori Morimotob6b37e22011-11-10 18:46:56 -080069#define BUSSWMR1 0x0070
70#define BUSSWMR2 0x0072
71#define BUSSWMR3 0x0074
72#define BUSSWMR4 0x0076
73
Kuninori Morimotod55c9a92011-11-10 18:46:45 -080074#define A1MDSR 0x10E0
75#define BVERR 0x1100
76static u16 bonito_fpga_read(u32 offset)
77{
78 return __raw_readw(0xf0003000 + offset);
79}
80
81static void bonito_fpga_write(u32 offset, u16 val)
82{
83 __raw_writew(val, 0xf0003000 + offset);
84}
85
86/*
Kuninori Morimotob6b37e22011-11-10 18:46:56 -080087 * core board devices
Kuninori Morimotod55c9a92011-11-10 18:46:45 -080088 */
Kuninori Morimotob6b37e22011-11-10 18:46:56 -080089static struct platform_device *bonito_core_devices[] __initdata = {
90};
91
92/*
93 * base board devices
94 */
95static struct platform_device *bonito_base_devices[] __initdata = {
Kuninori Morimotod55c9a92011-11-10 18:46:45 -080096};
97
98/*
99 * map I/O
100 */
101static struct map_desc bonito_io_desc[] __initdata = {
102 /*
103 * for CPGA/INTC/PFC
104 * 0xe6000000-0xefffffff -> 0xe6000000-0xefffffff
105 */
106 {
107 .virtual = 0xe6000000,
108 .pfn = __phys_to_pfn(0xe6000000),
109 .length = 160 << 20,
110 .type = MT_DEVICE_NONSHARED
111 },
112#ifdef CONFIG_CACHE_L2X0
113 /*
114 * for l2x0_init()
115 * 0xf0100000-0xf0101000 -> 0xf0002000-0xf0003000
116 */
117 {
118 .virtual = 0xf0002000,
119 .pfn = __phys_to_pfn(0xf0100000),
120 .length = PAGE_SIZE,
121 .type = MT_DEVICE_NONSHARED
122 },
123#endif
124 /*
125 * for FPGA (0x1800000-0x19ffffff)
126 * 0x18000000-0x18002000 -> 0xf0003000-0xf0005000
127 */
128 {
129 .virtual = 0xf0003000,
130 .pfn = __phys_to_pfn(0x18000000),
131 .length = PAGE_SIZE * 2,
132 .type = MT_DEVICE_NONSHARED
133 }
134};
135
136static void __init bonito_map_io(void)
137{
138 iotable_init(bonito_io_desc, ARRAY_SIZE(bonito_io_desc));
139
140 /* setup early devices and console here as well */
141 r8a7740_add_early_devices();
142 shmobile_setup_console();
143}
144
145/*
146 * board init
147 */
Kuninori Morimotob6b37e22011-11-10 18:46:56 -0800148#define BIT_ON(sw, bit) (sw & (1 << bit))
149#define BIT_OFF(sw, bit) (!(sw & (1 << bit)))
150
Kuninori Morimotod55c9a92011-11-10 18:46:45 -0800151static void __init bonito_init(void)
152{
153 u16 val;
154
155 r8a7740_pinmux_init();
156
Kuninori Morimotob6b37e22011-11-10 18:46:56 -0800157 /*
158 * core board settings
159 */
Kuninori Morimotod55c9a92011-11-10 18:46:45 -0800160
161#ifdef CONFIG_CACHE_L2X0
162 /* Early BRESP enable, Shared attribute override enable, 32K*8way */
163 l2x0_init(__io(0xf0002000), 0x40440000, 0x82000fff);
164#endif
165
166 r8a7740_add_standard_devices();
Kuninori Morimotob6b37e22011-11-10 18:46:56 -0800167
168 platform_add_devices(bonito_core_devices,
169 ARRAY_SIZE(bonito_core_devices));
170
171 /*
172 * base board settings
173 */
174 gpio_request(GPIO_PORT176, NULL);
175 gpio_direction_input(GPIO_PORT176);
176 if (!gpio_get_value(GPIO_PORT176)) {
177 u16 bsw2;
178 u16 bsw3;
179 u16 bsw4;
180
181 /*
182 * FPGA
183 */
184 gpio_request(GPIO_FN_CS5B, NULL);
185 gpio_request(GPIO_FN_CS6A, NULL);
186 gpio_request(GPIO_FN_CS5A_PORT105, NULL);
187 gpio_request(GPIO_FN_IRQ10, NULL);
188
189 val = bonito_fpga_read(BVERR);
190 pr_info("bonito version: cpu %02x, base %02x\n",
191 ((val >> 8) & 0xFF),
192 ((val >> 0) & 0xFF));
193
194 bsw2 = bonito_fpga_read(BUSSWMR2);
195 bsw3 = bonito_fpga_read(BUSSWMR3);
196 bsw4 = bonito_fpga_read(BUSSWMR4);
197
198 /*
199 * SCIFA5 (CN42)
200 */
201 if (BIT_OFF(bsw2, 1) && /* S38.3 = ON */
202 BIT_OFF(bsw3, 9) && /* S39.6 = ON */
203 BIT_OFF(bsw4, 4)) { /* S43.1 = ON */
204 gpio_request(GPIO_FN_SCIFA5_TXD_PORT91, NULL);
205 gpio_request(GPIO_FN_SCIFA5_RXD_PORT92, NULL);
206 }
207
208 platform_add_devices(bonito_base_devices,
209 ARRAY_SIZE(bonito_base_devices));
210 }
Kuninori Morimotod55c9a92011-11-10 18:46:45 -0800211}
212
213static void __init bonito_timer_init(void)
214{
215 u16 val;
216 u8 md_ck = 0;
217
218 /* read MD_CK value */
219 val = bonito_fpga_read(A1MDSR);
220 if (val & (1 << 10))
221 md_ck |= MD_CK2;
222 if (val & (1 << 9))
223 md_ck |= MD_CK1;
224 if (val & (1 << 8))
225 md_ck |= MD_CK0;
226
227 r8a7740_clock_init(md_ck);
228 shmobile_timer.init();
229}
230
231struct sys_timer bonito_timer = {
232 .init = bonito_timer_init,
233};
234
235MACHINE_START(BONITO, "bonito")
236 .map_io = bonito_map_io,
237 .init_irq = r8a7740_init_irq,
238 .handle_irq = shmobile_handle_irq_intc,
239 .init_machine = bonito_init,
240 .timer = &bonito_timer,
241MACHINE_END