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/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>
34 #include <cpu/sh7724.h>
35 #include <mach/kfr2r09.h>
37 static struct mtd_partition kfr2r09_nor_flash_partitions
[] =
42 .size
= (4 * 1024 * 1024),
43 .mask_flags
= MTD_WRITEABLE
, /* Read-only */
47 .offset
= MTDPART_OFS_APPEND
,
48 .size
= MTDPART_SIZ_FULL
,
52 static struct physmap_flash_data kfr2r09_nor_flash_data
= {
54 .parts
= kfr2r09_nor_flash_partitions
,
55 .nr_parts
= ARRAY_SIZE(kfr2r09_nor_flash_partitions
),
58 static struct resource kfr2r09_nor_flash_resources
[] = {
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
),
72 .platform_data
= &kfr2r09_nor_flash_data
,
76 static struct resource kfr2r09_nand_flash_resources
[] = {
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 */
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
,
105 static struct resource kfr2r09_sh_keysc_resources
[] = {
110 .flags
= IORESOURCE_MEM
,
114 .flags
= IORESOURCE_IRQ
,
118 static struct platform_device kfr2r09_sh_keysc_device
= {
120 .id
= 0, /* "keysc0" clock */
121 .num_resources
= ARRAY_SIZE(kfr2r09_sh_keysc_resources
),
122 .resource
= kfr2r09_sh_keysc_resources
,
124 .platform_data
= &kfr2r09_sh_keysc_info
,
128 static const struct fb_videomode kfr2r09_lcdc_modes
[] = {
130 .name
= "TX07D34VM0AAA",
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
,
146 .chan
= LCDC_CHAN_MAINLCD
,
147 .fourcc
= V4L2_PIX_FMT_RGB565
,
148 .interface_type
= SYS18
,
150 .flags
= LCDC_FLAGS_DWPOL
,
151 .lcd_cfg
= kfr2r09_lcdc_modes
,
152 .num_cfg
= ARRAY_SIZE(kfr2r09_lcdc_modes
),
158 .setup_sys
= kfr2r09_lcd_setup
,
159 .start_transfer
= kfr2r09_lcd_start
,
160 .display_on
= kfr2r09_lcd_on
,
161 .display_off
= kfr2r09_lcd_off
,
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
[] = {
175 .start
= 0xfe940000, /* P4-only space */
177 .flags
= IORESOURCE_MEM
,
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
,
190 .platform_data
= &kfr2r09_sh_lcdc_info
,
194 static struct r8a66597_platdata kfr2r09_usb0_gadget_data
= {
198 static struct resource kfr2r09_usb0_gadget_resources
[] = {
202 .flags
= IORESOURCE_MEM
,
207 .flags
= IORESOURCE_IRQ
| IRQF_TRIGGER_LOW
,
211 static struct platform_device kfr2r09_usb0_gadget_device
= {
212 .name
= "r8a66597_udc",
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
[] = {
232 .flags
= IORESOURCE_MEM
,
237 .flags
= IORESOURCE_IRQ
,
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
,
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
)
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 __raw_writew((__raw_readw(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 .priv
= &rj54n1_priv
,
337 static struct platform_device kfr2r09_camera
= {
338 .name
= "soc-camera-pdrv",
341 .platform_data
= &rj54n1_link
,
345 static struct resource kfr2r09_sh_sdhi0_resources
[] = {
350 .flags
= IORESOURCE_MEM
,
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
,
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
,
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
391 static int kfr2r09_usb0_gadget_i2c_setup(void)
393 struct i2c_adapter
*a
;
395 unsigned char buf
[2];
398 a
= i2c_get_adapter(0);
402 /* set bit 1 (the second bit) of chip at 0x09, register 0x13 */
408 ret
= i2c_transfer(a
, &msg
, 1);
416 msg
.flags
= I2C_M_RD
;
417 ret
= i2c_transfer(a
, &msg
, 1);
421 buf
[1] = buf
[0] | (1 << 1);
427 ret
= i2c_transfer(a
, &msg
, 1);
434 static int kfr2r09_serial_i2c_setup(void)
436 struct i2c_adapter
*a
;
438 unsigned char buf
[2];
441 a
= i2c_get_adapter(0);
445 /* set bit 6 (the 7th bit) of chip at 0x09, register 0x13 */
451 ret
= i2c_transfer(a
, &msg
, 1);
459 msg
.flags
= I2C_M_RD
;
460 ret
= i2c_transfer(a
, &msg
, 1);
464 buf
[1] = buf
[0] | (1 << 6);
470 ret
= i2c_transfer(a
, &msg
, 1);
477 static int kfr2r09_usb0_gadget_i2c_setup(void)
482 static int kfr2r09_serial_i2c_setup(void)
488 static int kfr2r09_usb0_gadget_setup(void)
492 gpio_request(GPIO_PTN4
, NULL
); /* USB_DET */
493 gpio_direction_input(GPIO_PTN4
);
494 plugged_in
= gpio_get_value(GPIO_PTN4
);
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);
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
|
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
);
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
;
635 static struct sh_machine_vector mv_kfr2r09 __initmv
= {
636 .mv_name
= "kfr2r09",
637 .mv_mode_pins
= kfr2r09_mode_pins
,