blob: fe749e354626cdcacd7164f1687d8409fd962b5b [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>
Kuninori Morimoto6bf28052011-11-10 18:47:26 -080029#include <linux/smsc911x.h>
Kuninori Morimotod55c9a92011-11-10 18:46:45 -080030#include <mach/common.h>
31#include <asm/mach-types.h>
32#include <asm/mach/arch.h>
33#include <asm/mach/map.h>
34#include <asm/mach/time.h>
35#include <asm/hardware/cache-l2x0.h>
36#include <mach/r8a7740.h>
Kuninori Morimoto665ccfa2011-11-10 18:47:16 -080037#include <video/sh_mobile_lcdc.h>
Kuninori Morimotod55c9a92011-11-10 18:46:45 -080038
39/*
40 * CS Address device note
41 *----------------------------------------------------------------
42 * 0 0x0000_0000 NOR Flash (64MB) SW12 : bit3 = OFF
43 * 2 0x0800_0000 ExtNOR (64MB) SW12 : bit3 = OFF
44 * 4 -
45 * 5A -
46 * 5B 0x1600_0000 SRAM (8MB)
47 * 6 0x1800_0000 FPGA (64K)
48 * 0x1801_0000 Ether (4KB)
49 * 0x1801_1000 USB (4KB)
50 */
51
52/*
53 * SW12
54 *
55 * bit1 bit2 bit3
56 *----------------------------------------------------------------------------
57 * ON NOR WriteProtect NAND WriteProtect CS0 ExtNOR / CS2 NOR
58 * OFF NOR Not WriteProtect NAND Not WriteProtect CS0 NOR / CS2 ExtNOR
59 */
60
61/*
Kuninori Morimotob6b37e22011-11-10 18:46:56 -080062 * SCIFA5 (CN42)
63 *
64 * S38.3 = ON
65 * S39.6 = ON
66 * S43.1 = ON
67 */
68
69/*
Kuninori Morimoto665ccfa2011-11-10 18:47:16 -080070 * LCDC0 (CN3/CN4/CN7)
71 *
72 * S38.1 = OFF
73 * S38.2 = OFF
74 */
75
76/*
Kuninori Morimotod55c9a92011-11-10 18:46:45 -080077 * FPGA
78 */
Kuninori Morimoto6bf28052011-11-10 18:47:26 -080079#define IRQSR0 0x0020
80#define IRQSR1 0x0022
81#define IRQMR0 0x0030
82#define IRQMR1 0x0032
Kuninori Morimotob6b37e22011-11-10 18:46:56 -080083#define BUSSWMR1 0x0070
84#define BUSSWMR2 0x0072
85#define BUSSWMR3 0x0074
86#define BUSSWMR4 0x0076
87
Kuninori Morimoto665ccfa2011-11-10 18:47:16 -080088#define LCDCR 0x10B4
Kuninori Morimoto6bf28052011-11-10 18:47:26 -080089#define DEVRSTCR1 0x10D0
90#define DEVRSTCR2 0x10D2
Kuninori Morimotod55c9a92011-11-10 18:46:45 -080091#define A1MDSR 0x10E0
92#define BVERR 0x1100
Kuninori Morimoto6bf28052011-11-10 18:47:26 -080093
94/* FPGA IRQ */
95#define FPGA_IRQ_BASE (512)
96#define FPGA_IRQ0 (FPGA_IRQ_BASE)
97#define FPGA_IRQ1 (FPGA_IRQ_BASE + 16)
Kuninori Morimotod55c9a92011-11-10 18:46:45 -080098static u16 bonito_fpga_read(u32 offset)
99{
100 return __raw_readw(0xf0003000 + offset);
101}
102
103static void bonito_fpga_write(u32 offset, u16 val)
104{
105 __raw_writew(val, 0xf0003000 + offset);
106}
107
Kuninori Morimoto6bf28052011-11-10 18:47:26 -0800108static void bonito_fpga_irq_disable(struct irq_data *data)
109{
110 unsigned int irq = data->irq;
111 u32 addr = (irq < 1016) ? IRQMR0 : IRQMR1;
112 int shift = irq % 16;
113
114 bonito_fpga_write(addr, bonito_fpga_read(addr) | (1 << shift));
115}
116
117static void bonito_fpga_irq_enable(struct irq_data *data)
118{
119 unsigned int irq = data->irq;
120 u32 addr = (irq < 1016) ? IRQMR0 : IRQMR1;
121 int shift = irq % 16;
122
123 bonito_fpga_write(addr, bonito_fpga_read(addr) & ~(1 << shift));
124}
125
126static struct irq_chip bonito_fpga_irq_chip __read_mostly = {
127 .name = "bonito FPGA",
128 .irq_mask = bonito_fpga_irq_disable,
129 .irq_unmask = bonito_fpga_irq_enable,
130};
131
132static void bonito_fpga_irq_demux(unsigned int irq, struct irq_desc *desc)
133{
134 u32 val = bonito_fpga_read(IRQSR1) << 16 |
135 bonito_fpga_read(IRQSR0);
136 u32 mask = bonito_fpga_read(IRQMR1) << 16 |
137 bonito_fpga_read(IRQMR0);
138
139 int i;
140
141 val &= ~mask;
142
143 for (i = 0; i < 32; i++) {
144 if (!(val & (1 << i)))
145 continue;
146
147 generic_handle_irq(FPGA_IRQ_BASE + i);
148 }
149}
150
151static void bonito_fpga_init(void)
152{
153 int i;
154
155 bonito_fpga_write(IRQMR0, 0xffff); /* mask all */
156 bonito_fpga_write(IRQMR1, 0xffff); /* mask all */
157
158 /* Device reset */
159 bonito_fpga_write(DEVRSTCR1,
160 (1 << 2)); /* Eth */
161
162 /* FPGA irq require special handling */
163 for (i = FPGA_IRQ_BASE; i < FPGA_IRQ_BASE + 32; i++) {
164 irq_set_chip_and_handler_name(i, &bonito_fpga_irq_chip,
165 handle_level_irq, "level");
166 set_irq_flags(i, IRQF_VALID); /* yuck */
167 }
168
169 irq_set_chained_handler(evt2irq(0x0340), bonito_fpga_irq_demux);
170 irq_set_irq_type(evt2irq(0x0340), IRQ_TYPE_LEVEL_LOW);
171}
172
Kuninori Morimotod55c9a92011-11-10 18:46:45 -0800173/*
Kuninori Morimotoe609b7c2011-11-10 18:47:07 -0800174* PMIC settings
175*
176* FIXME
177*
178* bonito board needs some settings by pmic which use i2c access.
179* pmic settings use device_initcall() here for use it.
180*/
181static __u8 *pmic_settings = NULL;
182static __u8 pmic_do_2A[] = {
183 0x1C, 0x09,
184 0x1A, 0x80,
185 0xff, 0xff,
186};
187
188static int __init pmic_init(void)
189{
190 struct i2c_adapter *a = i2c_get_adapter(0);
191 struct i2c_msg msg;
192 __u8 buf[2];
193 int i, ret;
194
195 if (!pmic_settings)
196 return 0;
197 if (!a)
198 return 0;
199
200 msg.addr = 0x46;
201 msg.buf = buf;
202 msg.len = 2;
203 msg.flags = 0;
204
205 for (i = 0; ; i += 2) {
206 buf[0] = pmic_settings[i + 0];
207 buf[1] = pmic_settings[i + 1];
208
209 if ((0xff == buf[0]) && (0xff == buf[1]))
210 break;
211
212 ret = i2c_transfer(a, &msg, 1);
213 if (ret < 0) {
214 pr_err("i2c transfer fail\n");
215 break;
216 }
217 }
218
219 return 0;
220}
221device_initcall(pmic_init);
222
223/*
Kuninori Morimoto665ccfa2011-11-10 18:47:16 -0800224 * LCDC0
225 */
226static const struct fb_videomode lcdc0_mode = {
227 .name = "WVGA Panel",
228 .xres = 800,
229 .yres = 480,
230 .left_margin = 88,
231 .right_margin = 40,
232 .hsync_len = 128,
233 .upper_margin = 20,
234 .lower_margin = 5,
235 .vsync_len = 5,
236 .sync = 0,
237};
238
239static struct sh_mobile_lcdc_info lcdc0_info = {
240 .clock_source = LCDC_CLK_BUS,
241 .ch[0] = {
242 .chan = LCDC_CHAN_MAINLCD,
243 .bpp = 16,
244 .interface_type = RGB24,
245 .clock_divider = 5,
246 .flags = 0,
247 .lcd_cfg = &lcdc0_mode,
248 .num_cfg = 1,
249 .lcd_size_cfg = {
250 .width = 152,
251 .height = 91,
252 },
253 },
254};
255
256static struct resource lcdc0_resources[] = {
257 [0] = {
258 .name = "LCDC0",
259 .start = 0xfe940000,
260 .end = 0xfe943fff,
261 .flags = IORESOURCE_MEM,
262 },
263 [1] = {
264 .start = intcs_evt2irq(0x0580),
265 .flags = IORESOURCE_IRQ,
266 },
267};
268
269static struct platform_device lcdc0_device = {
270 .name = "sh_mobile_lcdc_fb",
271 .id = 0,
272 .resource = lcdc0_resources,
273 .num_resources = ARRAY_SIZE(lcdc0_resources),
274 .dev = {
275 .platform_data = &lcdc0_info,
276 .coherent_dma_mask = ~0,
277 },
278};
279
280/*
Kuninori Morimotob6b37e22011-11-10 18:46:56 -0800281 * core board devices
Kuninori Morimotod55c9a92011-11-10 18:46:45 -0800282 */
Kuninori Morimotob6b37e22011-11-10 18:46:56 -0800283static struct platform_device *bonito_core_devices[] __initdata = {
284};
285
286/*
287 * base board devices
288 */
289static struct platform_device *bonito_base_devices[] __initdata = {
Kuninori Morimoto665ccfa2011-11-10 18:47:16 -0800290 &lcdc0_device,
Kuninori Morimotod55c9a92011-11-10 18:46:45 -0800291};
292
293/*
294 * map I/O
295 */
296static struct map_desc bonito_io_desc[] __initdata = {
297 /*
298 * for CPGA/INTC/PFC
299 * 0xe6000000-0xefffffff -> 0xe6000000-0xefffffff
300 */
301 {
302 .virtual = 0xe6000000,
303 .pfn = __phys_to_pfn(0xe6000000),
304 .length = 160 << 20,
305 .type = MT_DEVICE_NONSHARED
306 },
307#ifdef CONFIG_CACHE_L2X0
308 /*
309 * for l2x0_init()
310 * 0xf0100000-0xf0101000 -> 0xf0002000-0xf0003000
311 */
312 {
313 .virtual = 0xf0002000,
314 .pfn = __phys_to_pfn(0xf0100000),
315 .length = PAGE_SIZE,
316 .type = MT_DEVICE_NONSHARED
317 },
318#endif
319 /*
320 * for FPGA (0x1800000-0x19ffffff)
321 * 0x18000000-0x18002000 -> 0xf0003000-0xf0005000
322 */
323 {
324 .virtual = 0xf0003000,
325 .pfn = __phys_to_pfn(0x18000000),
326 .length = PAGE_SIZE * 2,
327 .type = MT_DEVICE_NONSHARED
328 }
329};
330
331static void __init bonito_map_io(void)
332{
333 iotable_init(bonito_io_desc, ARRAY_SIZE(bonito_io_desc));
334
335 /* setup early devices and console here as well */
336 r8a7740_add_early_devices();
337 shmobile_setup_console();
338}
339
340/*
341 * board init
342 */
Kuninori Morimotob6b37e22011-11-10 18:46:56 -0800343#define BIT_ON(sw, bit) (sw & (1 << bit))
344#define BIT_OFF(sw, bit) (!(sw & (1 << bit)))
345
Kuninori Morimoto665ccfa2011-11-10 18:47:16 -0800346#define VCCQ1CR 0xE6058140
347#define VCCQ1LCDCR 0xE6058186
348
Kuninori Morimotod55c9a92011-11-10 18:46:45 -0800349static void __init bonito_init(void)
350{
351 u16 val;
352
353 r8a7740_pinmux_init();
Kuninori Morimoto6bf28052011-11-10 18:47:26 -0800354 bonito_fpga_init();
Kuninori Morimotod55c9a92011-11-10 18:46:45 -0800355
Kuninori Morimotoe609b7c2011-11-10 18:47:07 -0800356 pmic_settings = pmic_do_2A;
357
Kuninori Morimotob6b37e22011-11-10 18:46:56 -0800358 /*
359 * core board settings
360 */
Kuninori Morimotod55c9a92011-11-10 18:46:45 -0800361
362#ifdef CONFIG_CACHE_L2X0
363 /* Early BRESP enable, Shared attribute override enable, 32K*8way */
364 l2x0_init(__io(0xf0002000), 0x40440000, 0x82000fff);
365#endif
366
367 r8a7740_add_standard_devices();
Kuninori Morimotob6b37e22011-11-10 18:46:56 -0800368
369 platform_add_devices(bonito_core_devices,
370 ARRAY_SIZE(bonito_core_devices));
371
372 /*
373 * base board settings
374 */
375 gpio_request(GPIO_PORT176, NULL);
376 gpio_direction_input(GPIO_PORT176);
377 if (!gpio_get_value(GPIO_PORT176)) {
378 u16 bsw2;
379 u16 bsw3;
380 u16 bsw4;
381
382 /*
383 * FPGA
384 */
385 gpio_request(GPIO_FN_CS5B, NULL);
386 gpio_request(GPIO_FN_CS6A, NULL);
387 gpio_request(GPIO_FN_CS5A_PORT105, NULL);
388 gpio_request(GPIO_FN_IRQ10, NULL);
389
390 val = bonito_fpga_read(BVERR);
391 pr_info("bonito version: cpu %02x, base %02x\n",
392 ((val >> 8) & 0xFF),
393 ((val >> 0) & 0xFF));
394
395 bsw2 = bonito_fpga_read(BUSSWMR2);
396 bsw3 = bonito_fpga_read(BUSSWMR3);
397 bsw4 = bonito_fpga_read(BUSSWMR4);
398
399 /*
400 * SCIFA5 (CN42)
401 */
402 if (BIT_OFF(bsw2, 1) && /* S38.3 = ON */
403 BIT_OFF(bsw3, 9) && /* S39.6 = ON */
404 BIT_OFF(bsw4, 4)) { /* S43.1 = ON */
405 gpio_request(GPIO_FN_SCIFA5_TXD_PORT91, NULL);
406 gpio_request(GPIO_FN_SCIFA5_RXD_PORT92, NULL);
407 }
408
Kuninori Morimoto665ccfa2011-11-10 18:47:16 -0800409 /*
410 * LCDC0 (CN3)
411 */
412 if (BIT_ON(bsw2, 3) && /* S38.1 = OFF */
413 BIT_ON(bsw2, 2)) { /* S38.2 = OFF */
414 gpio_request(GPIO_FN_LCDC0_SELECT, NULL);
415 gpio_request(GPIO_FN_LCD0_D0, NULL);
416 gpio_request(GPIO_FN_LCD0_D1, NULL);
417 gpio_request(GPIO_FN_LCD0_D2, NULL);
418 gpio_request(GPIO_FN_LCD0_D3, NULL);
419 gpio_request(GPIO_FN_LCD0_D4, NULL);
420 gpio_request(GPIO_FN_LCD0_D5, NULL);
421 gpio_request(GPIO_FN_LCD0_D6, NULL);
422 gpio_request(GPIO_FN_LCD0_D7, NULL);
423 gpio_request(GPIO_FN_LCD0_D8, NULL);
424 gpio_request(GPIO_FN_LCD0_D9, NULL);
425 gpio_request(GPIO_FN_LCD0_D10, NULL);
426 gpio_request(GPIO_FN_LCD0_D11, NULL);
427 gpio_request(GPIO_FN_LCD0_D12, NULL);
428 gpio_request(GPIO_FN_LCD0_D13, NULL);
429 gpio_request(GPIO_FN_LCD0_D14, NULL);
430 gpio_request(GPIO_FN_LCD0_D15, NULL);
431 gpio_request(GPIO_FN_LCD0_D16, NULL);
432 gpio_request(GPIO_FN_LCD0_D17, NULL);
433 gpio_request(GPIO_FN_LCD0_D18_PORT163, NULL);
434 gpio_request(GPIO_FN_LCD0_D19_PORT162, NULL);
435 gpio_request(GPIO_FN_LCD0_D20_PORT161, NULL);
436 gpio_request(GPIO_FN_LCD0_D21_PORT158, NULL);
437 gpio_request(GPIO_FN_LCD0_D22_PORT160, NULL);
438 gpio_request(GPIO_FN_LCD0_D23_PORT159, NULL);
439 gpio_request(GPIO_FN_LCD0_DCK, NULL);
440 gpio_request(GPIO_FN_LCD0_VSYN, NULL);
441 gpio_request(GPIO_FN_LCD0_HSYN, NULL);
442 gpio_request(GPIO_FN_LCD0_DISP, NULL);
443 gpio_request(GPIO_FN_LCD0_LCLK_PORT165, NULL);
444
445 gpio_request(GPIO_PORT61, NULL); /* LCDDON */
446 gpio_direction_output(GPIO_PORT61, 1);
447
448 /* backlight on */
449 bonito_fpga_write(LCDCR, 1);
450
451 /* drivability Max */
452 __raw_writew(0x00FF , VCCQ1LCDCR);
453 __raw_writew(0xFFFF , VCCQ1CR);
454 }
455
Kuninori Morimotob6b37e22011-11-10 18:46:56 -0800456 platform_add_devices(bonito_base_devices,
457 ARRAY_SIZE(bonito_base_devices));
458 }
Kuninori Morimotod55c9a92011-11-10 18:46:45 -0800459}
460
461static void __init bonito_timer_init(void)
462{
463 u16 val;
464 u8 md_ck = 0;
465
466 /* read MD_CK value */
467 val = bonito_fpga_read(A1MDSR);
468 if (val & (1 << 10))
469 md_ck |= MD_CK2;
470 if (val & (1 << 9))
471 md_ck |= MD_CK1;
472 if (val & (1 << 8))
473 md_ck |= MD_CK0;
474
475 r8a7740_clock_init(md_ck);
476 shmobile_timer.init();
477}
478
479struct sys_timer bonito_timer = {
480 .init = bonito_timer_init,
481};
482
483MACHINE_START(BONITO, "bonito")
484 .map_io = bonito_map_io,
485 .init_irq = r8a7740_init_irq,
486 .handle_irq = shmobile_handle_irq_intc,
487 .init_machine = bonito_init,
488 .timer = &bonito_timer,
489MACHINE_END