acpiphp: Execute ACPI _REG method for hotadded devices
[linux/fpc-iii.git] / arch / sh / boards / mach-kfr2r09 / setup.c
blob5d7b5d92475e46227b5b4c0e932a78f37ad0697f
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/mtd/physmap.h>
14 #include <linux/mtd/onenand.h>
15 #include <linux/delay.h>
16 #include <linux/clk.h>
17 #include <linux/gpio.h>
18 #include <linux/input.h>
19 #include <linux/input/sh_keysc.h>
20 #include <linux/i2c.h>
21 #include <linux/usb/r8a66597.h>
22 #include <media/rj54n1cb0c.h>
23 #include <media/soc_camera.h>
24 #include <media/sh_mobile_ceu.h>
25 #include <video/sh_mobile_lcdc.h>
26 #include <asm/suspend.h>
27 #include <asm/clock.h>
28 #include <asm/machvec.h>
29 #include <asm/io.h>
30 #include <cpu/sh7724.h>
31 #include <mach/kfr2r09.h>
33 static struct mtd_partition kfr2r09_nor_flash_partitions[] =
36 .name = "boot",
37 .offset = 0,
38 .size = (4 * 1024 * 1024),
39 .mask_flags = MTD_WRITEABLE, /* Read-only */
42 .name = "other",
43 .offset = MTDPART_OFS_APPEND,
44 .size = MTDPART_SIZ_FULL,
48 static struct physmap_flash_data kfr2r09_nor_flash_data = {
49 .width = 2,
50 .parts = kfr2r09_nor_flash_partitions,
51 .nr_parts = ARRAY_SIZE(kfr2r09_nor_flash_partitions),
54 static struct resource kfr2r09_nor_flash_resources[] = {
55 [0] = {
56 .name = "NOR Flash",
57 .start = 0x00000000,
58 .end = 0x03ffffff,
59 .flags = IORESOURCE_MEM,
63 static struct platform_device kfr2r09_nor_flash_device = {
64 .name = "physmap-flash",
65 .resource = kfr2r09_nor_flash_resources,
66 .num_resources = ARRAY_SIZE(kfr2r09_nor_flash_resources),
67 .dev = {
68 .platform_data = &kfr2r09_nor_flash_data,
72 static struct resource kfr2r09_nand_flash_resources[] = {
73 [0] = {
74 .name = "NAND Flash",
75 .start = 0x10000000,
76 .end = 0x1001ffff,
77 .flags = IORESOURCE_MEM,
81 static struct platform_device kfr2r09_nand_flash_device = {
82 .name = "onenand-flash",
83 .resource = kfr2r09_nand_flash_resources,
84 .num_resources = ARRAY_SIZE(kfr2r09_nand_flash_resources),
87 static struct sh_keysc_info kfr2r09_sh_keysc_info = {
88 .mode = SH_KEYSC_MODE_1, /* KEYOUT0->4, KEYIN0->4 */
89 .scan_timing = 3,
90 .delay = 10,
91 .keycodes = {
92 KEY_PHONE, KEY_CLEAR, KEY_MAIL, KEY_WWW, KEY_ENTER,
93 KEY_1, KEY_2, KEY_3, 0, KEY_UP,
94 KEY_4, KEY_5, KEY_6, 0, KEY_LEFT,
95 KEY_7, KEY_8, KEY_9, KEY_PROG1, KEY_RIGHT,
96 KEY_S, KEY_0, KEY_P, KEY_PROG2, KEY_DOWN,
97 0, 0, 0, 0, 0
101 static struct resource kfr2r09_sh_keysc_resources[] = {
102 [0] = {
103 .name = "KEYSC",
104 .start = 0x044b0000,
105 .end = 0x044b000f,
106 .flags = IORESOURCE_MEM,
108 [1] = {
109 .start = 79,
110 .flags = IORESOURCE_IRQ,
114 static struct platform_device kfr2r09_sh_keysc_device = {
115 .name = "sh_keysc",
116 .id = 0, /* "keysc0" clock */
117 .num_resources = ARRAY_SIZE(kfr2r09_sh_keysc_resources),
118 .resource = kfr2r09_sh_keysc_resources,
119 .dev = {
120 .platform_data = &kfr2r09_sh_keysc_info,
122 .archdata = {
123 .hwblk_id = HWBLK_KEYSC,
127 static struct sh_mobile_lcdc_info kfr2r09_sh_lcdc_info = {
128 .clock_source = LCDC_CLK_BUS,
129 .ch[0] = {
130 .chan = LCDC_CHAN_MAINLCD,
131 .bpp = 16,
132 .interface_type = SYS18,
133 .clock_divider = 6,
134 .flags = LCDC_FLAGS_DWPOL,
135 .lcd_cfg = {
136 .name = "TX07D34VM0AAA",
137 .xres = 240,
138 .yres = 400,
139 .left_margin = 0,
140 .right_margin = 16,
141 .hsync_len = 8,
142 .upper_margin = 0,
143 .lower_margin = 1,
144 .vsync_len = 1,
145 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
147 .lcd_size_cfg = {
148 .width = 35,
149 .height = 58,
151 .board_cfg = {
152 .setup_sys = kfr2r09_lcd_setup,
153 .start_transfer = kfr2r09_lcd_start,
154 .display_on = kfr2r09_lcd_on,
155 .display_off = kfr2r09_lcd_off,
157 .sys_bus_cfg = {
158 .ldmt2r = 0x07010904,
159 .ldmt3r = 0x14012914,
160 /* set 1s delay to encourage fsync() */
161 .deferred_io_msec = 1000,
166 static struct resource kfr2r09_sh_lcdc_resources[] = {
167 [0] = {
168 .name = "LCDC",
169 .start = 0xfe940000, /* P4-only space */
170 .end = 0xfe942fff,
171 .flags = IORESOURCE_MEM,
173 [1] = {
174 .start = 106,
175 .flags = IORESOURCE_IRQ,
179 static struct platform_device kfr2r09_sh_lcdc_device = {
180 .name = "sh_mobile_lcdc_fb",
181 .num_resources = ARRAY_SIZE(kfr2r09_sh_lcdc_resources),
182 .resource = kfr2r09_sh_lcdc_resources,
183 .dev = {
184 .platform_data = &kfr2r09_sh_lcdc_info,
186 .archdata = {
187 .hwblk_id = HWBLK_LCDC,
191 static struct r8a66597_platdata kfr2r09_usb0_gadget_data = {
192 .on_chip = 1,
195 static struct resource kfr2r09_usb0_gadget_resources[] = {
196 [0] = {
197 .start = 0x04d80000,
198 .end = 0x04d80123,
199 .flags = IORESOURCE_MEM,
201 [1] = {
202 .start = 65,
203 .end = 65,
204 .flags = IORESOURCE_IRQ | IRQF_TRIGGER_LOW,
208 static struct platform_device kfr2r09_usb0_gadget_device = {
209 .name = "r8a66597_udc",
210 .id = 0,
211 .dev = {
212 .dma_mask = NULL, /* not use dma */
213 .coherent_dma_mask = 0xffffffff,
214 .platform_data = &kfr2r09_usb0_gadget_data,
216 .num_resources = ARRAY_SIZE(kfr2r09_usb0_gadget_resources),
217 .resource = kfr2r09_usb0_gadget_resources,
220 static struct sh_mobile_ceu_info sh_mobile_ceu_info = {
221 .flags = SH_CEU_FLAG_USE_8BIT_BUS,
224 static struct resource kfr2r09_ceu_resources[] = {
225 [0] = {
226 .name = "CEU",
227 .start = 0xfe910000,
228 .end = 0xfe91009f,
229 .flags = IORESOURCE_MEM,
231 [1] = {
232 .start = 52,
233 .end = 52,
234 .flags = IORESOURCE_IRQ,
236 [2] = {
237 /* place holder for contiguous memory */
241 static struct platform_device kfr2r09_ceu_device = {
242 .name = "sh_mobile_ceu",
243 .id = 0, /* "ceu0" clock */
244 .num_resources = ARRAY_SIZE(kfr2r09_ceu_resources),
245 .resource = kfr2r09_ceu_resources,
246 .dev = {
247 .platform_data = &sh_mobile_ceu_info,
249 .archdata = {
250 .hwblk_id = HWBLK_CEU0,
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 ctrl_outw((ctrl_inw(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 .module_name = "rj54n1cb0c",
335 .priv = &rj54n1_priv,
338 static struct platform_device kfr2r09_camera = {
339 .name = "soc-camera-pdrv",
340 .id = 0,
341 .dev = {
342 .platform_data = &rj54n1_link,
346 static struct resource kfr2r09_sh_sdhi0_resources[] = {
347 [0] = {
348 .name = "SDHI0",
349 .start = 0x04ce0000,
350 .end = 0x04ce01ff,
351 .flags = IORESOURCE_MEM,
353 [1] = {
354 .start = 101,
355 .flags = IORESOURCE_IRQ,
359 static struct platform_device kfr2r09_sh_sdhi0_device = {
360 .name = "sh_mobile_sdhi",
361 .num_resources = ARRAY_SIZE(kfr2r09_sh_sdhi0_resources),
362 .resource = kfr2r09_sh_sdhi0_resources,
363 .archdata = {
364 .hwblk_id = HWBLK_SDHI0,
368 static struct platform_device *kfr2r09_devices[] __initdata = {
369 &kfr2r09_nor_flash_device,
370 &kfr2r09_nand_flash_device,
371 &kfr2r09_sh_keysc_device,
372 &kfr2r09_sh_lcdc_device,
373 &kfr2r09_ceu_device,
374 &kfr2r09_camera,
375 &kfr2r09_sh_sdhi0_device,
378 #define BSC_CS0BCR 0xfec10004
379 #define BSC_CS0WCR 0xfec10024
380 #define BSC_CS4BCR 0xfec10010
381 #define BSC_CS4WCR 0xfec10030
382 #define PORT_MSELCRB 0xa4050182
384 #ifdef CONFIG_I2C
385 static int kfr2r09_usb0_gadget_i2c_setup(void)
387 struct i2c_adapter *a;
388 struct i2c_msg msg;
389 unsigned char buf[2];
390 int ret;
392 a = i2c_get_adapter(0);
393 if (!a)
394 return -ENODEV;
396 /* set bit 1 (the second bit) of chip at 0x09, register 0x13 */
397 buf[0] = 0x13;
398 msg.addr = 0x09;
399 msg.buf = buf;
400 msg.len = 1;
401 msg.flags = 0;
402 ret = i2c_transfer(a, &msg, 1);
403 if (ret != 1)
404 return -ENODEV;
406 buf[0] = 0;
407 msg.addr = 0x09;
408 msg.buf = buf;
409 msg.len = 1;
410 msg.flags = I2C_M_RD;
411 ret = i2c_transfer(a, &msg, 1);
412 if (ret != 1)
413 return -ENODEV;
415 buf[1] = buf[0] | (1 << 1);
416 buf[0] = 0x13;
417 msg.addr = 0x09;
418 msg.buf = buf;
419 msg.len = 2;
420 msg.flags = 0;
421 ret = i2c_transfer(a, &msg, 1);
422 if (ret != 1)
423 return -ENODEV;
425 return 0;
428 static int kfr2r09_serial_i2c_setup(void)
430 struct i2c_adapter *a;
431 struct i2c_msg msg;
432 unsigned char buf[2];
433 int ret;
435 a = i2c_get_adapter(0);
436 if (!a)
437 return -ENODEV;
439 /* set bit 6 (the 7th bit) of chip at 0x09, register 0x13 */
440 buf[0] = 0x13;
441 msg.addr = 0x09;
442 msg.buf = buf;
443 msg.len = 1;
444 msg.flags = 0;
445 ret = i2c_transfer(a, &msg, 1);
446 if (ret != 1)
447 return -ENODEV;
449 buf[0] = 0;
450 msg.addr = 0x09;
451 msg.buf = buf;
452 msg.len = 1;
453 msg.flags = I2C_M_RD;
454 ret = i2c_transfer(a, &msg, 1);
455 if (ret != 1)
456 return -ENODEV;
458 buf[1] = buf[0] | (1 << 6);
459 buf[0] = 0x13;
460 msg.addr = 0x09;
461 msg.buf = buf;
462 msg.len = 2;
463 msg.flags = 0;
464 ret = i2c_transfer(a, &msg, 1);
465 if (ret != 1)
466 return -ENODEV;
468 return 0;
470 #else
471 static int kfr2r09_usb0_gadget_i2c_setup(void)
473 return -ENODEV;
476 static int kfr2r09_serial_i2c_setup(void)
478 return -ENODEV;
480 #endif
482 static int kfr2r09_usb0_gadget_setup(void)
484 int plugged_in;
486 gpio_request(GPIO_PTN4, NULL); /* USB_DET */
487 gpio_direction_input(GPIO_PTN4);
488 plugged_in = gpio_get_value(GPIO_PTN4);
489 if (!plugged_in)
490 return -ENODEV; /* no cable plugged in */
492 if (kfr2r09_usb0_gadget_i2c_setup() != 0)
493 return -ENODEV; /* unable to configure using i2c */
495 ctrl_outw((ctrl_inw(PORT_MSELCRB) & ~0xc000) | 0x8000, PORT_MSELCRB);
496 gpio_request(GPIO_FN_PDSTATUS, NULL); /* R-standby disables USB clock */
497 gpio_request(GPIO_PTV6, NULL); /* USBCLK_ON */
498 gpio_direction_output(GPIO_PTV6, 1); /* USBCLK_ON = H */
499 msleep(20); /* wait 20ms to let the clock settle */
500 clk_enable(clk_get(NULL, "usb0"));
501 ctrl_outw(0x0600, 0xa40501d4);
503 return 0;
506 extern char kfr2r09_sdram_enter_start;
507 extern char kfr2r09_sdram_enter_end;
508 extern char kfr2r09_sdram_leave_start;
509 extern char kfr2r09_sdram_leave_end;
511 static int __init kfr2r09_devices_setup(void)
513 /* register board specific self-refresh code */
514 sh_mobile_register_self_refresh(SUSP_SH_STANDBY | SUSP_SH_SF |
515 SUSP_SH_RSTANDBY,
516 &kfr2r09_sdram_enter_start,
517 &kfr2r09_sdram_enter_end,
518 &kfr2r09_sdram_leave_start,
519 &kfr2r09_sdram_leave_end);
521 /* enable SCIF1 serial port for YC401 console support */
522 gpio_request(GPIO_FN_SCIF1_RXD, NULL);
523 gpio_request(GPIO_FN_SCIF1_TXD, NULL);
524 kfr2r09_serial_i2c_setup(); /* ECONTMSK(bit6=L10ONEN) set 1 */
525 gpio_request(GPIO_PTG3, NULL); /* HPON_ON */
526 gpio_direction_output(GPIO_PTG3, 1); /* HPON_ON = H */
528 /* setup NOR flash at CS0 */
529 ctrl_outl(0x36db0400, BSC_CS0BCR);
530 ctrl_outl(0x00000500, BSC_CS0WCR);
532 /* setup NAND flash at CS4 */
533 ctrl_outl(0x36db0400, BSC_CS4BCR);
534 ctrl_outl(0x00000500, BSC_CS4WCR);
536 /* setup KEYSC pins */
537 gpio_request(GPIO_FN_KEYOUT0, NULL);
538 gpio_request(GPIO_FN_KEYOUT1, NULL);
539 gpio_request(GPIO_FN_KEYOUT2, NULL);
540 gpio_request(GPIO_FN_KEYOUT3, NULL);
541 gpio_request(GPIO_FN_KEYOUT4_IN6, NULL);
542 gpio_request(GPIO_FN_KEYIN0, NULL);
543 gpio_request(GPIO_FN_KEYIN1, NULL);
544 gpio_request(GPIO_FN_KEYIN2, NULL);
545 gpio_request(GPIO_FN_KEYIN3, NULL);
546 gpio_request(GPIO_FN_KEYIN4, NULL);
547 gpio_request(GPIO_FN_KEYOUT5_IN5, NULL);
549 /* setup LCDC pins for SYS panel */
550 gpio_request(GPIO_FN_LCDD17, NULL);
551 gpio_request(GPIO_FN_LCDD16, NULL);
552 gpio_request(GPIO_FN_LCDD15, NULL);
553 gpio_request(GPIO_FN_LCDD14, NULL);
554 gpio_request(GPIO_FN_LCDD13, NULL);
555 gpio_request(GPIO_FN_LCDD12, NULL);
556 gpio_request(GPIO_FN_LCDD11, NULL);
557 gpio_request(GPIO_FN_LCDD10, NULL);
558 gpio_request(GPIO_FN_LCDD9, NULL);
559 gpio_request(GPIO_FN_LCDD8, NULL);
560 gpio_request(GPIO_FN_LCDD7, NULL);
561 gpio_request(GPIO_FN_LCDD6, NULL);
562 gpio_request(GPIO_FN_LCDD5, NULL);
563 gpio_request(GPIO_FN_LCDD4, NULL);
564 gpio_request(GPIO_FN_LCDD3, NULL);
565 gpio_request(GPIO_FN_LCDD2, NULL);
566 gpio_request(GPIO_FN_LCDD1, NULL);
567 gpio_request(GPIO_FN_LCDD0, NULL);
568 gpio_request(GPIO_FN_LCDRS, NULL); /* LCD_RS */
569 gpio_request(GPIO_FN_LCDCS, NULL); /* LCD_CS/ */
570 gpio_request(GPIO_FN_LCDRD, NULL); /* LCD_RD/ */
571 gpio_request(GPIO_FN_LCDWR, NULL); /* LCD_WR/ */
572 gpio_request(GPIO_FN_LCDVSYN, NULL); /* LCD_VSYNC */
573 gpio_request(GPIO_PTE4, NULL); /* LCD_RST/ */
574 gpio_direction_output(GPIO_PTE4, 1);
575 gpio_request(GPIO_PTF4, NULL); /* PROTECT/ */
576 gpio_direction_output(GPIO_PTF4, 1);
577 gpio_request(GPIO_PTU0, NULL); /* LEDSTDBY/ */
578 gpio_direction_output(GPIO_PTU0, 1);
580 /* setup USB function */
581 if (kfr2r09_usb0_gadget_setup() == 0)
582 platform_device_register(&kfr2r09_usb0_gadget_device);
584 /* CEU */
585 gpio_request(GPIO_FN_VIO_CKO, NULL);
586 gpio_request(GPIO_FN_VIO0_CLK, NULL);
587 gpio_request(GPIO_FN_VIO0_VD, NULL);
588 gpio_request(GPIO_FN_VIO0_HD, NULL);
589 gpio_request(GPIO_FN_VIO0_FLD, NULL);
590 gpio_request(GPIO_FN_VIO0_D7, NULL);
591 gpio_request(GPIO_FN_VIO0_D6, NULL);
592 gpio_request(GPIO_FN_VIO0_D5, NULL);
593 gpio_request(GPIO_FN_VIO0_D4, NULL);
594 gpio_request(GPIO_FN_VIO0_D3, NULL);
595 gpio_request(GPIO_FN_VIO0_D2, NULL);
596 gpio_request(GPIO_FN_VIO0_D1, NULL);
597 gpio_request(GPIO_FN_VIO0_D0, NULL);
599 platform_resource_setup_memory(&kfr2r09_ceu_device, "ceu", 4 << 20);
601 /* SDHI0 connected to yc304 */
602 gpio_request(GPIO_FN_SDHI0CD, NULL);
603 gpio_request(GPIO_FN_SDHI0D3, NULL);
604 gpio_request(GPIO_FN_SDHI0D2, NULL);
605 gpio_request(GPIO_FN_SDHI0D1, NULL);
606 gpio_request(GPIO_FN_SDHI0D0, NULL);
607 gpio_request(GPIO_FN_SDHI0CMD, NULL);
608 gpio_request(GPIO_FN_SDHI0CLK, NULL);
610 return platform_add_devices(kfr2r09_devices,
611 ARRAY_SIZE(kfr2r09_devices));
613 device_initcall(kfr2r09_devices_setup);
615 /* Return the board specific boot mode pin configuration */
616 static int kfr2r09_mode_pins(void)
618 /* MD0=1, MD1=1, MD2=0: Clock Mode 3
619 * MD3=0: 16-bit Area0 Bus Width
620 * MD5=1: Little Endian
621 * MD8=1: Test Mode Disabled
623 return MODE_PIN0 | MODE_PIN1 | MODE_PIN5 | MODE_PIN8;
627 * The Machine Vector
629 static struct sh_machine_vector mv_kfr2r09 __initmv = {
630 .mv_name = "kfr2r09",
631 .mv_mode_pins = kfr2r09_mode_pins,