blob: d78008bbdf701b0a80bb6b78766818e5f35ec120 [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>
Kuninori Morimotoe609b7c2011-11-10 18:47:07 -080023#include <linux/i2c.h>
Kuninori Morimotod55c9a92011-11-10 18:46:45 -080024#include <linux/init.h>
25#include <linux/interrupt.h>
26#include <linux/irq.h>
27#include <linux/platform_device.h>
28#include <linux/gpio.h>
29#include <mach/common.h>
30#include <asm/mach-types.h>
31#include <asm/mach/arch.h>
32#include <asm/mach/map.h>
33#include <asm/mach/time.h>
34#include <asm/hardware/cache-l2x0.h>
35#include <mach/r8a7740.h>
36
37/*
38 * CS Address device note
39 *----------------------------------------------------------------
40 * 0 0x0000_0000 NOR Flash (64MB) SW12 : bit3 = OFF
41 * 2 0x0800_0000 ExtNOR (64MB) SW12 : bit3 = OFF
42 * 4 -
43 * 5A -
44 * 5B 0x1600_0000 SRAM (8MB)
45 * 6 0x1800_0000 FPGA (64K)
46 * 0x1801_0000 Ether (4KB)
47 * 0x1801_1000 USB (4KB)
48 */
49
50/*
51 * SW12
52 *
53 * bit1 bit2 bit3
54 *----------------------------------------------------------------------------
55 * ON NOR WriteProtect NAND WriteProtect CS0 ExtNOR / CS2 NOR
56 * OFF NOR Not WriteProtect NAND Not WriteProtect CS0 NOR / CS2 ExtNOR
57 */
58
59/*
Kuninori Morimotob6b37e22011-11-10 18:46:56 -080060 * SCIFA5 (CN42)
61 *
62 * S38.3 = ON
63 * S39.6 = ON
64 * S43.1 = ON
65 */
66
67/*
Kuninori Morimotod55c9a92011-11-10 18:46:45 -080068 * FPGA
69 */
Kuninori Morimotob6b37e22011-11-10 18:46:56 -080070#define BUSSWMR1 0x0070
71#define BUSSWMR2 0x0072
72#define BUSSWMR3 0x0074
73#define BUSSWMR4 0x0076
74
Kuninori Morimotod55c9a92011-11-10 18:46:45 -080075#define A1MDSR 0x10E0
76#define BVERR 0x1100
77static u16 bonito_fpga_read(u32 offset)
78{
79 return __raw_readw(0xf0003000 + offset);
80}
81
82static void bonito_fpga_write(u32 offset, u16 val)
83{
84 __raw_writew(val, 0xf0003000 + offset);
85}
86
87/*
Kuninori Morimotoe609b7c2011-11-10 18:47:07 -080088* PMIC settings
89*
90* FIXME
91*
92* bonito board needs some settings by pmic which use i2c access.
93* pmic settings use device_initcall() here for use it.
94*/
95static __u8 *pmic_settings = NULL;
96static __u8 pmic_do_2A[] = {
97 0x1C, 0x09,
98 0x1A, 0x80,
99 0xff, 0xff,
100};
101
102static int __init pmic_init(void)
103{
104 struct i2c_adapter *a = i2c_get_adapter(0);
105 struct i2c_msg msg;
106 __u8 buf[2];
107 int i, ret;
108
109 if (!pmic_settings)
110 return 0;
111 if (!a)
112 return 0;
113
114 msg.addr = 0x46;
115 msg.buf = buf;
116 msg.len = 2;
117 msg.flags = 0;
118
119 for (i = 0; ; i += 2) {
120 buf[0] = pmic_settings[i + 0];
121 buf[1] = pmic_settings[i + 1];
122
123 if ((0xff == buf[0]) && (0xff == buf[1]))
124 break;
125
126 ret = i2c_transfer(a, &msg, 1);
127 if (ret < 0) {
128 pr_err("i2c transfer fail\n");
129 break;
130 }
131 }
132
133 return 0;
134}
135device_initcall(pmic_init);
136
137/*
Kuninori Morimotob6b37e22011-11-10 18:46:56 -0800138 * core board devices
Kuninori Morimotod55c9a92011-11-10 18:46:45 -0800139 */
Kuninori Morimotob6b37e22011-11-10 18:46:56 -0800140static struct platform_device *bonito_core_devices[] __initdata = {
141};
142
143/*
144 * base board devices
145 */
146static struct platform_device *bonito_base_devices[] __initdata = {
Kuninori Morimotod55c9a92011-11-10 18:46:45 -0800147};
148
149/*
150 * map I/O
151 */
152static struct map_desc bonito_io_desc[] __initdata = {
153 /*
154 * for CPGA/INTC/PFC
155 * 0xe6000000-0xefffffff -> 0xe6000000-0xefffffff
156 */
157 {
158 .virtual = 0xe6000000,
159 .pfn = __phys_to_pfn(0xe6000000),
160 .length = 160 << 20,
161 .type = MT_DEVICE_NONSHARED
162 },
163#ifdef CONFIG_CACHE_L2X0
164 /*
165 * for l2x0_init()
166 * 0xf0100000-0xf0101000 -> 0xf0002000-0xf0003000
167 */
168 {
169 .virtual = 0xf0002000,
170 .pfn = __phys_to_pfn(0xf0100000),
171 .length = PAGE_SIZE,
172 .type = MT_DEVICE_NONSHARED
173 },
174#endif
175 /*
176 * for FPGA (0x1800000-0x19ffffff)
177 * 0x18000000-0x18002000 -> 0xf0003000-0xf0005000
178 */
179 {
180 .virtual = 0xf0003000,
181 .pfn = __phys_to_pfn(0x18000000),
182 .length = PAGE_SIZE * 2,
183 .type = MT_DEVICE_NONSHARED
184 }
185};
186
187static void __init bonito_map_io(void)
188{
189 iotable_init(bonito_io_desc, ARRAY_SIZE(bonito_io_desc));
190
191 /* setup early devices and console here as well */
192 r8a7740_add_early_devices();
193 shmobile_setup_console();
194}
195
196/*
197 * board init
198 */
Kuninori Morimotob6b37e22011-11-10 18:46:56 -0800199#define BIT_ON(sw, bit) (sw & (1 << bit))
200#define BIT_OFF(sw, bit) (!(sw & (1 << bit)))
201
Kuninori Morimotod55c9a92011-11-10 18:46:45 -0800202static void __init bonito_init(void)
203{
204 u16 val;
205
206 r8a7740_pinmux_init();
207
Kuninori Morimotoe609b7c2011-11-10 18:47:07 -0800208 pmic_settings = pmic_do_2A;
209
Kuninori Morimotob6b37e22011-11-10 18:46:56 -0800210 /*
211 * core board settings
212 */
Kuninori Morimotod55c9a92011-11-10 18:46:45 -0800213
214#ifdef CONFIG_CACHE_L2X0
215 /* Early BRESP enable, Shared attribute override enable, 32K*8way */
216 l2x0_init(__io(0xf0002000), 0x40440000, 0x82000fff);
217#endif
218
219 r8a7740_add_standard_devices();
Kuninori Morimotob6b37e22011-11-10 18:46:56 -0800220
221 platform_add_devices(bonito_core_devices,
222 ARRAY_SIZE(bonito_core_devices));
223
224 /*
225 * base board settings
226 */
227 gpio_request(GPIO_PORT176, NULL);
228 gpio_direction_input(GPIO_PORT176);
229 if (!gpio_get_value(GPIO_PORT176)) {
230 u16 bsw2;
231 u16 bsw3;
232 u16 bsw4;
233
234 /*
235 * FPGA
236 */
237 gpio_request(GPIO_FN_CS5B, NULL);
238 gpio_request(GPIO_FN_CS6A, NULL);
239 gpio_request(GPIO_FN_CS5A_PORT105, NULL);
240 gpio_request(GPIO_FN_IRQ10, NULL);
241
242 val = bonito_fpga_read(BVERR);
243 pr_info("bonito version: cpu %02x, base %02x\n",
244 ((val >> 8) & 0xFF),
245 ((val >> 0) & 0xFF));
246
247 bsw2 = bonito_fpga_read(BUSSWMR2);
248 bsw3 = bonito_fpga_read(BUSSWMR3);
249 bsw4 = bonito_fpga_read(BUSSWMR4);
250
251 /*
252 * SCIFA5 (CN42)
253 */
254 if (BIT_OFF(bsw2, 1) && /* S38.3 = ON */
255 BIT_OFF(bsw3, 9) && /* S39.6 = ON */
256 BIT_OFF(bsw4, 4)) { /* S43.1 = ON */
257 gpio_request(GPIO_FN_SCIFA5_TXD_PORT91, NULL);
258 gpio_request(GPIO_FN_SCIFA5_RXD_PORT92, NULL);
259 }
260
261 platform_add_devices(bonito_base_devices,
262 ARRAY_SIZE(bonito_base_devices));
263 }
Kuninori Morimotod55c9a92011-11-10 18:46:45 -0800264}
265
266static void __init bonito_timer_init(void)
267{
268 u16 val;
269 u8 md_ck = 0;
270
271 /* read MD_CK value */
272 val = bonito_fpga_read(A1MDSR);
273 if (val & (1 << 10))
274 md_ck |= MD_CK2;
275 if (val & (1 << 9))
276 md_ck |= MD_CK1;
277 if (val & (1 << 8))
278 md_ck |= MD_CK0;
279
280 r8a7740_clock_init(md_ck);
281 shmobile_timer.init();
282}
283
284struct sys_timer bonito_timer = {
285 .init = bonito_timer_init,
286};
287
288MACHINE_START(BONITO, "bonito")
289 .map_io = bonito_map_io,
290 .init_irq = r8a7740_init_irq,
291 .handle_irq = shmobile_handle_irq_intc,
292 .init_machine = bonito_init,
293 .timer = &bonito_timer,
294MACHINE_END