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
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>
30 #include <cpu/sh7724.h>
31 #include <mach/kfr2r09.h>
33 static struct mtd_partition kfr2r09_nor_flash_partitions
[] =
38 .size
= (4 * 1024 * 1024),
39 .mask_flags
= MTD_WRITEABLE
, /* Read-only */
43 .offset
= MTDPART_OFS_APPEND
,
44 .size
= MTDPART_SIZ_FULL
,
48 static struct physmap_flash_data kfr2r09_nor_flash_data
= {
50 .parts
= kfr2r09_nor_flash_partitions
,
51 .nr_parts
= ARRAY_SIZE(kfr2r09_nor_flash_partitions
),
54 static struct resource kfr2r09_nor_flash_resources
[] = {
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
),
68 .platform_data
= &kfr2r09_nor_flash_data
,
72 static struct resource kfr2r09_nand_flash_resources
[] = {
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 */
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
,
101 static struct resource kfr2r09_sh_keysc_resources
[] = {
106 .flags
= IORESOURCE_MEM
,
110 .flags
= IORESOURCE_IRQ
,
114 static struct platform_device kfr2r09_sh_keysc_device
= {
116 .id
= 0, /* "keysc0" clock */
117 .num_resources
= ARRAY_SIZE(kfr2r09_sh_keysc_resources
),
118 .resource
= kfr2r09_sh_keysc_resources
,
120 .platform_data
= &kfr2r09_sh_keysc_info
,
123 .hwblk_id
= HWBLK_KEYSC
,
127 static struct sh_mobile_lcdc_info kfr2r09_sh_lcdc_info
= {
128 .clock_source
= LCDC_CLK_BUS
,
130 .chan
= LCDC_CHAN_MAINLCD
,
132 .interface_type
= SYS18
,
134 .flags
= LCDC_FLAGS_DWPOL
,
136 .name
= "TX07D34VM0AAA",
145 .sync
= FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
152 .setup_sys
= kfr2r09_lcd_setup
,
153 .start_transfer
= kfr2r09_lcd_start
,
154 .display_on
= kfr2r09_lcd_on
,
155 .display_off
= kfr2r09_lcd_off
,
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
[] = {
169 .start
= 0xfe940000, /* P4-only space */
171 .flags
= IORESOURCE_MEM
,
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
,
184 .platform_data
= &kfr2r09_sh_lcdc_info
,
187 .hwblk_id
= HWBLK_LCDC
,
191 static struct r8a66597_platdata kfr2r09_usb0_gadget_data
= {
195 static struct resource kfr2r09_usb0_gadget_resources
[] = {
199 .flags
= IORESOURCE_MEM
,
204 .flags
= IORESOURCE_IRQ
| IRQF_TRIGGER_LOW
,
208 static struct platform_device kfr2r09_usb0_gadget_device
= {
209 .name
= "r8a66597_udc",
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
[] = {
229 .flags
= IORESOURCE_MEM
,
234 .flags
= IORESOURCE_IRQ
,
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
,
247 .platform_data
= &sh_mobile_ceu_info
,
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
)
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
);
282 * use 1.8 V for VccQ_VIO
283 * use 2.85V for VccQ_SR
285 ctrl_outw((ctrl_inw(DRVCRB
) & ~0x0003) | 0x0001, DRVCRB
);
288 ret
= gpio_request(GPIO_PTB4
, NULL
);
291 ret
= gpio_request(GPIO_PTB7
, NULL
);
295 ret
= gpio_direction_output(GPIO_PTB4
, 1);
297 ret
= gpio_direction_output(GPIO_PTB7
, 1);
302 ret
= clk_enable(camera_clk
); /* start VIO_CKO */
311 clk_disable(camera_clk
);
313 gpio_set_value(GPIO_PTB7
, 0);
315 gpio_set_value(GPIO_PTB4
, 0);
316 gpio_free(GPIO_PTB7
);
318 gpio_free(GPIO_PTB4
);
325 static struct rj54n1_pdata rj54n1_priv
= {
326 .mclk_freq
= CEU_MCLK_FREQ
,
330 static struct soc_camera_link rj54n1_link
= {
331 .power
= camera_power
,
332 .board_info
= &kfr2r09_i2c_camera
,
334 .module_name
= "rj54n1cb0c",
335 .priv
= &rj54n1_priv
,
338 static struct platform_device kfr2r09_camera
= {
339 .name
= "soc-camera-pdrv",
342 .platform_data
= &rj54n1_link
,
346 static struct resource kfr2r09_sh_sdhi0_resources
[] = {
351 .flags
= IORESOURCE_MEM
,
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
,
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
,
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
385 static int kfr2r09_usb0_gadget_i2c_setup(void)
387 struct i2c_adapter
*a
;
389 unsigned char buf
[2];
392 a
= i2c_get_adapter(0);
396 /* set bit 1 (the second bit) of chip at 0x09, register 0x13 */
402 ret
= i2c_transfer(a
, &msg
, 1);
410 msg
.flags
= I2C_M_RD
;
411 ret
= i2c_transfer(a
, &msg
, 1);
415 buf
[1] = buf
[0] | (1 << 1);
421 ret
= i2c_transfer(a
, &msg
, 1);
428 static int kfr2r09_serial_i2c_setup(void)
430 struct i2c_adapter
*a
;
432 unsigned char buf
[2];
435 a
= i2c_get_adapter(0);
439 /* set bit 6 (the 7th bit) of chip at 0x09, register 0x13 */
445 ret
= i2c_transfer(a
, &msg
, 1);
453 msg
.flags
= I2C_M_RD
;
454 ret
= i2c_transfer(a
, &msg
, 1);
458 buf
[1] = buf
[0] | (1 << 6);
464 ret
= i2c_transfer(a
, &msg
, 1);
471 static int kfr2r09_usb0_gadget_i2c_setup(void)
476 static int kfr2r09_serial_i2c_setup(void)
482 static int kfr2r09_usb0_gadget_setup(void)
486 gpio_request(GPIO_PTN4
, NULL
); /* USB_DET */
487 gpio_direction_input(GPIO_PTN4
);
488 plugged_in
= gpio_get_value(GPIO_PTN4
);
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);
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
|
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
);
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
;
629 static struct sh_machine_vector mv_kfr2r09 __initmv
= {
630 .mv_name
= "kfr2r09",
631 .mv_mode_pins
= kfr2r09_mode_pins
,