Merge tag 'v3.3.7' into 3.3/master
[zen-stable.git] / arch / sh / boards / mach-kfr2r09 / setup.c
blob5b382e1afaea6afe7a5de762c08a136b1363adfd
1 /*
2 * KFR2R09 board support code
4 * Copyright (C) 2009 Magnus Damm
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10 #include <linux/init.h>
11 #include <linux/platform_device.h>
12 #include <linux/interrupt.h>
13 #include <linux/mmc/host.h>
14 #include <linux/mmc/sh_mobile_sdhi.h>
15 #include <linux/mfd/tmio.h>
16 #include <linux/mtd/physmap.h>
17 #include <linux/mtd/onenand.h>
18 #include <linux/delay.h>
19 #include <linux/clk.h>
20 #include <linux/gpio.h>
21 #include <linux/input.h>
22 #include <linux/input/sh_keysc.h>
23 #include <linux/i2c.h>
24 #include <linux/usb/r8a66597.h>
25 #include <linux/videodev2.h>
26 #include <media/rj54n1cb0c.h>
27 #include <media/soc_camera.h>
28 #include <media/sh_mobile_ceu.h>
29 #include <video/sh_mobile_lcdc.h>
30 #include <asm/suspend.h>
31 #include <asm/clock.h>
32 #include <asm/machvec.h>
33 #include <asm/io.h>
34 #include <cpu/sh7724.h>
35 #include <mach/kfr2r09.h>
37 static struct mtd_partition kfr2r09_nor_flash_partitions[] =
40 .name = "boot",
41 .offset = 0,
42 .size = (4 * 1024 * 1024),
43 .mask_flags = MTD_WRITEABLE, /* Read-only */
46 .name = "other",
47 .offset = MTDPART_OFS_APPEND,
48 .size = MTDPART_SIZ_FULL,
52 static struct physmap_flash_data kfr2r09_nor_flash_data = {
53 .width = 2,
54 .parts = kfr2r09_nor_flash_partitions,
55 .nr_parts = ARRAY_SIZE(kfr2r09_nor_flash_partitions),
58 static struct resource kfr2r09_nor_flash_resources[] = {
59 [0] = {
60 .name = "NOR Flash",
61 .start = 0x00000000,
62 .end = 0x03ffffff,
63 .flags = IORESOURCE_MEM,
67 static struct platform_device kfr2r09_nor_flash_device = {
68 .name = "physmap-flash",
69 .resource = kfr2r09_nor_flash_resources,
70 .num_resources = ARRAY_SIZE(kfr2r09_nor_flash_resources),
71 .dev = {
72 .platform_data = &kfr2r09_nor_flash_data,
76 static struct resource kfr2r09_nand_flash_resources[] = {
77 [0] = {
78 .name = "NAND Flash",
79 .start = 0x10000000,
80 .end = 0x1001ffff,
81 .flags = IORESOURCE_MEM,
85 static struct platform_device kfr2r09_nand_flash_device = {
86 .name = "onenand-flash",
87 .resource = kfr2r09_nand_flash_resources,
88 .num_resources = ARRAY_SIZE(kfr2r09_nand_flash_resources),
91 static struct sh_keysc_info kfr2r09_sh_keysc_info = {
92 .mode = SH_KEYSC_MODE_1, /* KEYOUT0->4, KEYIN0->4 */
93 .scan_timing = 3,
94 .delay = 10,
95 .keycodes = {
96 KEY_PHONE, KEY_CLEAR, KEY_MAIL, KEY_WWW, KEY_ENTER,
97 KEY_1, KEY_2, KEY_3, 0, KEY_UP,
98 KEY_4, KEY_5, KEY_6, 0, KEY_LEFT,
99 KEY_7, KEY_8, KEY_9, KEY_PROG1, KEY_RIGHT,
100 KEY_S, KEY_0, KEY_P, KEY_PROG2, KEY_DOWN,
101 0, 0, 0, 0, 0
105 static struct resource kfr2r09_sh_keysc_resources[] = {
106 [0] = {
107 .name = "KEYSC",
108 .start = 0x044b0000,
109 .end = 0x044b000f,
110 .flags = IORESOURCE_MEM,
112 [1] = {
113 .start = 79,
114 .flags = IORESOURCE_IRQ,
118 static struct platform_device kfr2r09_sh_keysc_device = {
119 .name = "sh_keysc",
120 .id = 0, /* "keysc0" clock */
121 .num_resources = ARRAY_SIZE(kfr2r09_sh_keysc_resources),
122 .resource = kfr2r09_sh_keysc_resources,
123 .dev = {
124 .platform_data = &kfr2r09_sh_keysc_info,
128 static const struct fb_videomode kfr2r09_lcdc_modes[] = {
130 .name = "TX07D34VM0AAA",
131 .xres = 240,
132 .yres = 400,
133 .left_margin = 0,
134 .right_margin = 16,
135 .hsync_len = 8,
136 .upper_margin = 0,
137 .lower_margin = 1,
138 .vsync_len = 1,
139 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
143 static struct sh_mobile_lcdc_info kfr2r09_sh_lcdc_info = {
144 .clock_source = LCDC_CLK_BUS,
145 .ch[0] = {
146 .chan = LCDC_CHAN_MAINLCD,
147 .fourcc = V4L2_PIX_FMT_RGB565,
148 .interface_type = SYS18,
149 .clock_divider = 6,
150 .flags = LCDC_FLAGS_DWPOL,
151 .lcd_cfg = kfr2r09_lcdc_modes,
152 .num_cfg = ARRAY_SIZE(kfr2r09_lcdc_modes),
153 .lcd_size_cfg = {
154 .width = 35,
155 .height = 58,
157 .board_cfg = {
158 .setup_sys = kfr2r09_lcd_setup,
159 .start_transfer = kfr2r09_lcd_start,
160 .display_on = kfr2r09_lcd_on,
161 .display_off = kfr2r09_lcd_off,
163 .sys_bus_cfg = {
164 .ldmt2r = 0x07010904,
165 .ldmt3r = 0x14012914,
166 /* set 1s delay to encourage fsync() */
167 .deferred_io_msec = 1000,
172 static struct resource kfr2r09_sh_lcdc_resources[] = {
173 [0] = {
174 .name = "LCDC",
175 .start = 0xfe940000, /* P4-only space */
176 .end = 0xfe942fff,
177 .flags = IORESOURCE_MEM,
179 [1] = {
180 .start = 106,
181 .flags = IORESOURCE_IRQ,
185 static struct platform_device kfr2r09_sh_lcdc_device = {
186 .name = "sh_mobile_lcdc_fb",
187 .num_resources = ARRAY_SIZE(kfr2r09_sh_lcdc_resources),
188 .resource = kfr2r09_sh_lcdc_resources,
189 .dev = {
190 .platform_data = &kfr2r09_sh_lcdc_info,
194 static struct r8a66597_platdata kfr2r09_usb0_gadget_data = {
195 .on_chip = 1,
198 static struct resource kfr2r09_usb0_gadget_resources[] = {
199 [0] = {
200 .start = 0x04d80000,
201 .end = 0x04d80123,
202 .flags = IORESOURCE_MEM,
204 [1] = {
205 .start = 65,
206 .end = 65,
207 .flags = IORESOURCE_IRQ | IRQF_TRIGGER_LOW,
211 static struct platform_device kfr2r09_usb0_gadget_device = {
212 .name = "r8a66597_udc",
213 .id = 0,
214 .dev = {
215 .dma_mask = NULL, /* not use dma */
216 .coherent_dma_mask = 0xffffffff,
217 .platform_data = &kfr2r09_usb0_gadget_data,
219 .num_resources = ARRAY_SIZE(kfr2r09_usb0_gadget_resources),
220 .resource = kfr2r09_usb0_gadget_resources,
223 static struct sh_mobile_ceu_info sh_mobile_ceu_info = {
224 .flags = SH_CEU_FLAG_USE_8BIT_BUS,
227 static struct resource kfr2r09_ceu_resources[] = {
228 [0] = {
229 .name = "CEU",
230 .start = 0xfe910000,
231 .end = 0xfe91009f,
232 .flags = IORESOURCE_MEM,
234 [1] = {
235 .start = 52,
236 .end = 52,
237 .flags = IORESOURCE_IRQ,
239 [2] = {
240 /* place holder for contiguous memory */
244 static struct platform_device kfr2r09_ceu_device = {
245 .name = "sh_mobile_ceu",
246 .id = 0, /* "ceu0" clock */
247 .num_resources = ARRAY_SIZE(kfr2r09_ceu_resources),
248 .resource = kfr2r09_ceu_resources,
249 .dev = {
250 .platform_data = &sh_mobile_ceu_info,
254 static struct i2c_board_info kfr2r09_i2c_camera = {
255 I2C_BOARD_INFO("rj54n1cb0c", 0x50),
258 static struct clk *camera_clk;
260 /* set VIO_CKO clock to 25MHz */
261 #define CEU_MCLK_FREQ 25000000
263 #define DRVCRB 0xA405018C
264 static int camera_power(struct device *dev, int mode)
266 int ret;
268 if (mode) {
269 long rate;
271 camera_clk = clk_get(NULL, "video_clk");
272 if (IS_ERR(camera_clk))
273 return PTR_ERR(camera_clk);
275 rate = clk_round_rate(camera_clk, CEU_MCLK_FREQ);
276 ret = clk_set_rate(camera_clk, rate);
277 if (ret < 0)
278 goto eclkrate;
280 /* set DRVCRB
282 * use 1.8 V for VccQ_VIO
283 * use 2.85V for VccQ_SR
285 __raw_writew((__raw_readw(DRVCRB) & ~0x0003) | 0x0001, DRVCRB);
287 /* reset clear */
288 ret = gpio_request(GPIO_PTB4, NULL);
289 if (ret < 0)
290 goto eptb4;
291 ret = gpio_request(GPIO_PTB7, NULL);
292 if (ret < 0)
293 goto eptb7;
295 ret = gpio_direction_output(GPIO_PTB4, 1);
296 if (!ret)
297 ret = gpio_direction_output(GPIO_PTB7, 1);
298 if (ret < 0)
299 goto egpioout;
300 msleep(1);
302 ret = clk_enable(camera_clk); /* start VIO_CKO */
303 if (ret < 0)
304 goto eclkon;
306 return 0;
309 ret = 0;
311 clk_disable(camera_clk);
312 eclkon:
313 gpio_set_value(GPIO_PTB7, 0);
314 egpioout:
315 gpio_set_value(GPIO_PTB4, 0);
316 gpio_free(GPIO_PTB7);
317 eptb7:
318 gpio_free(GPIO_PTB4);
319 eptb4:
320 eclkrate:
321 clk_put(camera_clk);
322 return ret;
325 static struct rj54n1_pdata rj54n1_priv = {
326 .mclk_freq = CEU_MCLK_FREQ,
327 .ioctl_high = false,
330 static struct soc_camera_link rj54n1_link = {
331 .power = camera_power,
332 .board_info = &kfr2r09_i2c_camera,
333 .i2c_adapter_id = 1,
334 .priv = &rj54n1_priv,
337 static struct platform_device kfr2r09_camera = {
338 .name = "soc-camera-pdrv",
339 .id = 0,
340 .dev = {
341 .platform_data = &rj54n1_link,
345 static struct resource kfr2r09_sh_sdhi0_resources[] = {
346 [0] = {
347 .name = "SDHI0",
348 .start = 0x04ce0000,
349 .end = 0x04ce00ff,
350 .flags = IORESOURCE_MEM,
352 [1] = {
353 .start = 100,
354 .flags = IORESOURCE_IRQ,
358 static struct sh_mobile_sdhi_info sh7724_sdhi0_data = {
359 .dma_slave_tx = SHDMA_SLAVE_SDHI0_TX,
360 .dma_slave_rx = SHDMA_SLAVE_SDHI0_RX,
361 .tmio_flags = TMIO_MMC_WRPROTECT_DISABLE,
362 .tmio_caps = MMC_CAP_SDIO_IRQ,
365 static struct platform_device kfr2r09_sh_sdhi0_device = {
366 .name = "sh_mobile_sdhi",
367 .num_resources = ARRAY_SIZE(kfr2r09_sh_sdhi0_resources),
368 .resource = kfr2r09_sh_sdhi0_resources,
369 .dev = {
370 .platform_data = &sh7724_sdhi0_data,
374 static struct platform_device *kfr2r09_devices[] __initdata = {
375 &kfr2r09_nor_flash_device,
376 &kfr2r09_nand_flash_device,
377 &kfr2r09_sh_keysc_device,
378 &kfr2r09_sh_lcdc_device,
379 &kfr2r09_ceu_device,
380 &kfr2r09_camera,
381 &kfr2r09_sh_sdhi0_device,
384 #define BSC_CS0BCR 0xfec10004
385 #define BSC_CS0WCR 0xfec10024
386 #define BSC_CS4BCR 0xfec10010
387 #define BSC_CS4WCR 0xfec10030
388 #define PORT_MSELCRB 0xa4050182
390 #ifdef CONFIG_I2C
391 static int kfr2r09_usb0_gadget_i2c_setup(void)
393 struct i2c_adapter *a;
394 struct i2c_msg msg;
395 unsigned char buf[2];
396 int ret;
398 a = i2c_get_adapter(0);
399 if (!a)
400 return -ENODEV;
402 /* set bit 1 (the second bit) of chip at 0x09, register 0x13 */
403 buf[0] = 0x13;
404 msg.addr = 0x09;
405 msg.buf = buf;
406 msg.len = 1;
407 msg.flags = 0;
408 ret = i2c_transfer(a, &msg, 1);
409 if (ret != 1)
410 return -ENODEV;
412 buf[0] = 0;
413 msg.addr = 0x09;
414 msg.buf = buf;
415 msg.len = 1;
416 msg.flags = I2C_M_RD;
417 ret = i2c_transfer(a, &msg, 1);
418 if (ret != 1)
419 return -ENODEV;
421 buf[1] = buf[0] | (1 << 1);
422 buf[0] = 0x13;
423 msg.addr = 0x09;
424 msg.buf = buf;
425 msg.len = 2;
426 msg.flags = 0;
427 ret = i2c_transfer(a, &msg, 1);
428 if (ret != 1)
429 return -ENODEV;
431 return 0;
434 static int kfr2r09_serial_i2c_setup(void)
436 struct i2c_adapter *a;
437 struct i2c_msg msg;
438 unsigned char buf[2];
439 int ret;
441 a = i2c_get_adapter(0);
442 if (!a)
443 return -ENODEV;
445 /* set bit 6 (the 7th bit) of chip at 0x09, register 0x13 */
446 buf[0] = 0x13;
447 msg.addr = 0x09;
448 msg.buf = buf;
449 msg.len = 1;
450 msg.flags = 0;
451 ret = i2c_transfer(a, &msg, 1);
452 if (ret != 1)
453 return -ENODEV;
455 buf[0] = 0;
456 msg.addr = 0x09;
457 msg.buf = buf;
458 msg.len = 1;
459 msg.flags = I2C_M_RD;
460 ret = i2c_transfer(a, &msg, 1);
461 if (ret != 1)
462 return -ENODEV;
464 buf[1] = buf[0] | (1 << 6);
465 buf[0] = 0x13;
466 msg.addr = 0x09;
467 msg.buf = buf;
468 msg.len = 2;
469 msg.flags = 0;
470 ret = i2c_transfer(a, &msg, 1);
471 if (ret != 1)
472 return -ENODEV;
474 return 0;
476 #else
477 static int kfr2r09_usb0_gadget_i2c_setup(void)
479 return -ENODEV;
482 static int kfr2r09_serial_i2c_setup(void)
484 return -ENODEV;
486 #endif
488 static int kfr2r09_usb0_gadget_setup(void)
490 int plugged_in;
492 gpio_request(GPIO_PTN4, NULL); /* USB_DET */
493 gpio_direction_input(GPIO_PTN4);
494 plugged_in = gpio_get_value(GPIO_PTN4);
495 if (!plugged_in)
496 return -ENODEV; /* no cable plugged in */
498 if (kfr2r09_usb0_gadget_i2c_setup() != 0)
499 return -ENODEV; /* unable to configure using i2c */
501 __raw_writew((__raw_readw(PORT_MSELCRB) & ~0xc000) | 0x8000, PORT_MSELCRB);
502 gpio_request(GPIO_FN_PDSTATUS, NULL); /* R-standby disables USB clock */
503 gpio_request(GPIO_PTV6, NULL); /* USBCLK_ON */
504 gpio_direction_output(GPIO_PTV6, 1); /* USBCLK_ON = H */
505 msleep(20); /* wait 20ms to let the clock settle */
506 clk_enable(clk_get(NULL, "usb0"));
507 __raw_writew(0x0600, 0xa40501d4);
509 return 0;
512 extern char kfr2r09_sdram_enter_start;
513 extern char kfr2r09_sdram_enter_end;
514 extern char kfr2r09_sdram_leave_start;
515 extern char kfr2r09_sdram_leave_end;
517 static int __init kfr2r09_devices_setup(void)
519 /* register board specific self-refresh code */
520 sh_mobile_register_self_refresh(SUSP_SH_STANDBY | SUSP_SH_SF |
521 SUSP_SH_RSTANDBY,
522 &kfr2r09_sdram_enter_start,
523 &kfr2r09_sdram_enter_end,
524 &kfr2r09_sdram_leave_start,
525 &kfr2r09_sdram_leave_end);
527 /* enable SCIF1 serial port for YC401 console support */
528 gpio_request(GPIO_FN_SCIF1_RXD, NULL);
529 gpio_request(GPIO_FN_SCIF1_TXD, NULL);
530 kfr2r09_serial_i2c_setup(); /* ECONTMSK(bit6=L10ONEN) set 1 */
531 gpio_request(GPIO_PTG3, NULL); /* HPON_ON */
532 gpio_direction_output(GPIO_PTG3, 1); /* HPON_ON = H */
534 /* setup NOR flash at CS0 */
535 __raw_writel(0x36db0400, BSC_CS0BCR);
536 __raw_writel(0x00000500, BSC_CS0WCR);
538 /* setup NAND flash at CS4 */
539 __raw_writel(0x36db0400, BSC_CS4BCR);
540 __raw_writel(0x00000500, BSC_CS4WCR);
542 /* setup KEYSC pins */
543 gpio_request(GPIO_FN_KEYOUT0, NULL);
544 gpio_request(GPIO_FN_KEYOUT1, NULL);
545 gpio_request(GPIO_FN_KEYOUT2, NULL);
546 gpio_request(GPIO_FN_KEYOUT3, NULL);
547 gpio_request(GPIO_FN_KEYOUT4_IN6, NULL);
548 gpio_request(GPIO_FN_KEYIN0, NULL);
549 gpio_request(GPIO_FN_KEYIN1, NULL);
550 gpio_request(GPIO_FN_KEYIN2, NULL);
551 gpio_request(GPIO_FN_KEYIN3, NULL);
552 gpio_request(GPIO_FN_KEYIN4, NULL);
553 gpio_request(GPIO_FN_KEYOUT5_IN5, NULL);
555 /* setup LCDC pins for SYS panel */
556 gpio_request(GPIO_FN_LCDD17, NULL);
557 gpio_request(GPIO_FN_LCDD16, NULL);
558 gpio_request(GPIO_FN_LCDD15, NULL);
559 gpio_request(GPIO_FN_LCDD14, NULL);
560 gpio_request(GPIO_FN_LCDD13, NULL);
561 gpio_request(GPIO_FN_LCDD12, NULL);
562 gpio_request(GPIO_FN_LCDD11, NULL);
563 gpio_request(GPIO_FN_LCDD10, NULL);
564 gpio_request(GPIO_FN_LCDD9, NULL);
565 gpio_request(GPIO_FN_LCDD8, NULL);
566 gpio_request(GPIO_FN_LCDD7, NULL);
567 gpio_request(GPIO_FN_LCDD6, NULL);
568 gpio_request(GPIO_FN_LCDD5, NULL);
569 gpio_request(GPIO_FN_LCDD4, NULL);
570 gpio_request(GPIO_FN_LCDD3, NULL);
571 gpio_request(GPIO_FN_LCDD2, NULL);
572 gpio_request(GPIO_FN_LCDD1, NULL);
573 gpio_request(GPIO_FN_LCDD0, NULL);
574 gpio_request(GPIO_FN_LCDRS, NULL); /* LCD_RS */
575 gpio_request(GPIO_FN_LCDCS, NULL); /* LCD_CS/ */
576 gpio_request(GPIO_FN_LCDRD, NULL); /* LCD_RD/ */
577 gpio_request(GPIO_FN_LCDWR, NULL); /* LCD_WR/ */
578 gpio_request(GPIO_FN_LCDVSYN, NULL); /* LCD_VSYNC */
579 gpio_request(GPIO_PTE4, NULL); /* LCD_RST/ */
580 gpio_direction_output(GPIO_PTE4, 1);
581 gpio_request(GPIO_PTF4, NULL); /* PROTECT/ */
582 gpio_direction_output(GPIO_PTF4, 1);
583 gpio_request(GPIO_PTU0, NULL); /* LEDSTDBY/ */
584 gpio_direction_output(GPIO_PTU0, 1);
586 /* setup USB function */
587 if (kfr2r09_usb0_gadget_setup() == 0)
588 platform_device_register(&kfr2r09_usb0_gadget_device);
590 /* CEU */
591 gpio_request(GPIO_FN_VIO_CKO, NULL);
592 gpio_request(GPIO_FN_VIO0_CLK, NULL);
593 gpio_request(GPIO_FN_VIO0_VD, NULL);
594 gpio_request(GPIO_FN_VIO0_HD, NULL);
595 gpio_request(GPIO_FN_VIO0_FLD, NULL);
596 gpio_request(GPIO_FN_VIO0_D7, NULL);
597 gpio_request(GPIO_FN_VIO0_D6, NULL);
598 gpio_request(GPIO_FN_VIO0_D5, NULL);
599 gpio_request(GPIO_FN_VIO0_D4, NULL);
600 gpio_request(GPIO_FN_VIO0_D3, NULL);
601 gpio_request(GPIO_FN_VIO0_D2, NULL);
602 gpio_request(GPIO_FN_VIO0_D1, NULL);
603 gpio_request(GPIO_FN_VIO0_D0, NULL);
605 platform_resource_setup_memory(&kfr2r09_ceu_device, "ceu", 4 << 20);
607 /* SDHI0 connected to yc304 */
608 gpio_request(GPIO_FN_SDHI0CD, NULL);
609 gpio_request(GPIO_FN_SDHI0D3, NULL);
610 gpio_request(GPIO_FN_SDHI0D2, NULL);
611 gpio_request(GPIO_FN_SDHI0D1, NULL);
612 gpio_request(GPIO_FN_SDHI0D0, NULL);
613 gpio_request(GPIO_FN_SDHI0CMD, NULL);
614 gpio_request(GPIO_FN_SDHI0CLK, NULL);
616 return platform_add_devices(kfr2r09_devices,
617 ARRAY_SIZE(kfr2r09_devices));
619 device_initcall(kfr2r09_devices_setup);
621 /* Return the board specific boot mode pin configuration */
622 static int kfr2r09_mode_pins(void)
624 /* MD0=1, MD1=1, MD2=0: Clock Mode 3
625 * MD3=0: 16-bit Area0 Bus Width
626 * MD5=1: Little Endian
627 * MD8=1: Test Mode Disabled
629 return MODE_PIN0 | MODE_PIN1 | MODE_PIN5 | MODE_PIN8;
633 * The Machine Vector
635 static struct sh_machine_vector mv_kfr2r09 __initmv = {
636 .mv_name = "kfr2r09",
637 .mv_mode_pins = kfr2r09_mode_pins,