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 <media/rj54n1cb0c.h>
26 #include <media/soc_camera.h>
27 #include <media/sh_mobile_ceu.h>
28 #include <video/sh_mobile_lcdc.h>
29 #include <asm/suspend.h>
30 #include <asm/clock.h>
31 #include <asm/machvec.h>
33 #include <cpu/sh7724.h>
34 #include <mach/kfr2r09.h>
36 static struct mtd_partition kfr2r09_nor_flash_partitions
[] =
41 .size
= (4 * 1024 * 1024),
42 .mask_flags
= MTD_WRITEABLE
, /* Read-only */
46 .offset
= MTDPART_OFS_APPEND
,
47 .size
= MTDPART_SIZ_FULL
,
51 static struct physmap_flash_data kfr2r09_nor_flash_data
= {
53 .parts
= kfr2r09_nor_flash_partitions
,
54 .nr_parts
= ARRAY_SIZE(kfr2r09_nor_flash_partitions
),
57 static struct resource kfr2r09_nor_flash_resources
[] = {
62 .flags
= IORESOURCE_MEM
,
66 static struct platform_device kfr2r09_nor_flash_device
= {
67 .name
= "physmap-flash",
68 .resource
= kfr2r09_nor_flash_resources
,
69 .num_resources
= ARRAY_SIZE(kfr2r09_nor_flash_resources
),
71 .platform_data
= &kfr2r09_nor_flash_data
,
75 static struct resource kfr2r09_nand_flash_resources
[] = {
80 .flags
= IORESOURCE_MEM
,
84 static struct platform_device kfr2r09_nand_flash_device
= {
85 .name
= "onenand-flash",
86 .resource
= kfr2r09_nand_flash_resources
,
87 .num_resources
= ARRAY_SIZE(kfr2r09_nand_flash_resources
),
90 static struct sh_keysc_info kfr2r09_sh_keysc_info
= {
91 .mode
= SH_KEYSC_MODE_1
, /* KEYOUT0->4, KEYIN0->4 */
95 KEY_PHONE
, KEY_CLEAR
, KEY_MAIL
, KEY_WWW
, KEY_ENTER
,
96 KEY_1
, KEY_2
, KEY_3
, 0, KEY_UP
,
97 KEY_4
, KEY_5
, KEY_6
, 0, KEY_LEFT
,
98 KEY_7
, KEY_8
, KEY_9
, KEY_PROG1
, KEY_RIGHT
,
99 KEY_S
, KEY_0
, KEY_P
, KEY_PROG2
, KEY_DOWN
,
104 static struct resource kfr2r09_sh_keysc_resources
[] = {
109 .flags
= IORESOURCE_MEM
,
113 .flags
= IORESOURCE_IRQ
,
117 static struct platform_device kfr2r09_sh_keysc_device
= {
119 .id
= 0, /* "keysc0" clock */
120 .num_resources
= ARRAY_SIZE(kfr2r09_sh_keysc_resources
),
121 .resource
= kfr2r09_sh_keysc_resources
,
123 .platform_data
= &kfr2r09_sh_keysc_info
,
126 .hwblk_id
= HWBLK_KEYSC
,
130 const static struct fb_videomode kfr2r09_lcdc_modes
[] = {
132 .name
= "TX07D34VM0AAA",
141 .sync
= FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
145 static struct sh_mobile_lcdc_info kfr2r09_sh_lcdc_info
= {
146 .clock_source
= LCDC_CLK_BUS
,
148 .chan
= LCDC_CHAN_MAINLCD
,
150 .interface_type
= SYS18
,
152 .flags
= LCDC_FLAGS_DWPOL
,
153 .lcd_cfg
= kfr2r09_lcdc_modes
,
154 .num_cfg
= ARRAY_SIZE(kfr2r09_lcdc_modes
),
160 .setup_sys
= kfr2r09_lcd_setup
,
161 .start_transfer
= kfr2r09_lcd_start
,
162 .display_on
= kfr2r09_lcd_on
,
163 .display_off
= kfr2r09_lcd_off
,
166 .ldmt2r
= 0x07010904,
167 .ldmt3r
= 0x14012914,
168 /* set 1s delay to encourage fsync() */
169 .deferred_io_msec
= 1000,
174 static struct resource kfr2r09_sh_lcdc_resources
[] = {
177 .start
= 0xfe940000, /* P4-only space */
179 .flags
= IORESOURCE_MEM
,
183 .flags
= IORESOURCE_IRQ
,
187 static struct platform_device kfr2r09_sh_lcdc_device
= {
188 .name
= "sh_mobile_lcdc_fb",
189 .num_resources
= ARRAY_SIZE(kfr2r09_sh_lcdc_resources
),
190 .resource
= kfr2r09_sh_lcdc_resources
,
192 .platform_data
= &kfr2r09_sh_lcdc_info
,
195 .hwblk_id
= HWBLK_LCDC
,
199 static struct r8a66597_platdata kfr2r09_usb0_gadget_data
= {
203 static struct resource kfr2r09_usb0_gadget_resources
[] = {
207 .flags
= IORESOURCE_MEM
,
212 .flags
= IORESOURCE_IRQ
| IRQF_TRIGGER_LOW
,
216 static struct platform_device kfr2r09_usb0_gadget_device
= {
217 .name
= "r8a66597_udc",
220 .dma_mask
= NULL
, /* not use dma */
221 .coherent_dma_mask
= 0xffffffff,
222 .platform_data
= &kfr2r09_usb0_gadget_data
,
224 .num_resources
= ARRAY_SIZE(kfr2r09_usb0_gadget_resources
),
225 .resource
= kfr2r09_usb0_gadget_resources
,
228 static struct sh_mobile_ceu_info sh_mobile_ceu_info
= {
229 .flags
= SH_CEU_FLAG_USE_8BIT_BUS
,
232 static struct resource kfr2r09_ceu_resources
[] = {
237 .flags
= IORESOURCE_MEM
,
242 .flags
= IORESOURCE_IRQ
,
245 /* place holder for contiguous memory */
249 static struct platform_device kfr2r09_ceu_device
= {
250 .name
= "sh_mobile_ceu",
251 .id
= 0, /* "ceu0" clock */
252 .num_resources
= ARRAY_SIZE(kfr2r09_ceu_resources
),
253 .resource
= kfr2r09_ceu_resources
,
255 .platform_data
= &sh_mobile_ceu_info
,
258 .hwblk_id
= HWBLK_CEU0
,
262 static struct i2c_board_info kfr2r09_i2c_camera
= {
263 I2C_BOARD_INFO("rj54n1cb0c", 0x50),
266 static struct clk
*camera_clk
;
268 /* set VIO_CKO clock to 25MHz */
269 #define CEU_MCLK_FREQ 25000000
271 #define DRVCRB 0xA405018C
272 static int camera_power(struct device
*dev
, int mode
)
279 camera_clk
= clk_get(NULL
, "video_clk");
280 if (IS_ERR(camera_clk
))
281 return PTR_ERR(camera_clk
);
283 rate
= clk_round_rate(camera_clk
, CEU_MCLK_FREQ
);
284 ret
= clk_set_rate(camera_clk
, rate
);
290 * use 1.8 V for VccQ_VIO
291 * use 2.85V for VccQ_SR
293 __raw_writew((__raw_readw(DRVCRB
) & ~0x0003) | 0x0001, DRVCRB
);
296 ret
= gpio_request(GPIO_PTB4
, NULL
);
299 ret
= gpio_request(GPIO_PTB7
, NULL
);
303 ret
= gpio_direction_output(GPIO_PTB4
, 1);
305 ret
= gpio_direction_output(GPIO_PTB7
, 1);
310 ret
= clk_enable(camera_clk
); /* start VIO_CKO */
319 clk_disable(camera_clk
);
321 gpio_set_value(GPIO_PTB7
, 0);
323 gpio_set_value(GPIO_PTB4
, 0);
324 gpio_free(GPIO_PTB7
);
326 gpio_free(GPIO_PTB4
);
333 static struct rj54n1_pdata rj54n1_priv
= {
334 .mclk_freq
= CEU_MCLK_FREQ
,
338 static struct soc_camera_link rj54n1_link
= {
339 .power
= camera_power
,
340 .board_info
= &kfr2r09_i2c_camera
,
342 .priv
= &rj54n1_priv
,
345 static struct platform_device kfr2r09_camera
= {
346 .name
= "soc-camera-pdrv",
349 .platform_data
= &rj54n1_link
,
353 static struct resource kfr2r09_sh_sdhi0_resources
[] = {
358 .flags
= IORESOURCE_MEM
,
362 .flags
= IORESOURCE_IRQ
,
366 static struct sh_mobile_sdhi_info sh7724_sdhi0_data
= {
367 .dma_slave_tx
= SHDMA_SLAVE_SDHI0_TX
,
368 .dma_slave_rx
= SHDMA_SLAVE_SDHI0_RX
,
369 .tmio_flags
= TMIO_MMC_WRPROTECT_DISABLE
,
370 .tmio_caps
= MMC_CAP_SDIO_IRQ
,
373 static struct platform_device kfr2r09_sh_sdhi0_device
= {
374 .name
= "sh_mobile_sdhi",
375 .num_resources
= ARRAY_SIZE(kfr2r09_sh_sdhi0_resources
),
376 .resource
= kfr2r09_sh_sdhi0_resources
,
378 .platform_data
= &sh7724_sdhi0_data
,
381 .hwblk_id
= HWBLK_SDHI0
,
385 static struct platform_device
*kfr2r09_devices
[] __initdata
= {
386 &kfr2r09_nor_flash_device
,
387 &kfr2r09_nand_flash_device
,
388 &kfr2r09_sh_keysc_device
,
389 &kfr2r09_sh_lcdc_device
,
392 &kfr2r09_sh_sdhi0_device
,
395 #define BSC_CS0BCR 0xfec10004
396 #define BSC_CS0WCR 0xfec10024
397 #define BSC_CS4BCR 0xfec10010
398 #define BSC_CS4WCR 0xfec10030
399 #define PORT_MSELCRB 0xa4050182
402 static int kfr2r09_usb0_gadget_i2c_setup(void)
404 struct i2c_adapter
*a
;
406 unsigned char buf
[2];
409 a
= i2c_get_adapter(0);
413 /* set bit 1 (the second bit) of chip at 0x09, register 0x13 */
419 ret
= i2c_transfer(a
, &msg
, 1);
427 msg
.flags
= I2C_M_RD
;
428 ret
= i2c_transfer(a
, &msg
, 1);
432 buf
[1] = buf
[0] | (1 << 1);
438 ret
= i2c_transfer(a
, &msg
, 1);
445 static int kfr2r09_serial_i2c_setup(void)
447 struct i2c_adapter
*a
;
449 unsigned char buf
[2];
452 a
= i2c_get_adapter(0);
456 /* set bit 6 (the 7th bit) of chip at 0x09, register 0x13 */
462 ret
= i2c_transfer(a
, &msg
, 1);
470 msg
.flags
= I2C_M_RD
;
471 ret
= i2c_transfer(a
, &msg
, 1);
475 buf
[1] = buf
[0] | (1 << 6);
481 ret
= i2c_transfer(a
, &msg
, 1);
488 static int kfr2r09_usb0_gadget_i2c_setup(void)
493 static int kfr2r09_serial_i2c_setup(void)
499 static int kfr2r09_usb0_gadget_setup(void)
503 gpio_request(GPIO_PTN4
, NULL
); /* USB_DET */
504 gpio_direction_input(GPIO_PTN4
);
505 plugged_in
= gpio_get_value(GPIO_PTN4
);
507 return -ENODEV
; /* no cable plugged in */
509 if (kfr2r09_usb0_gadget_i2c_setup() != 0)
510 return -ENODEV
; /* unable to configure using i2c */
512 __raw_writew((__raw_readw(PORT_MSELCRB
) & ~0xc000) | 0x8000, PORT_MSELCRB
);
513 gpio_request(GPIO_FN_PDSTATUS
, NULL
); /* R-standby disables USB clock */
514 gpio_request(GPIO_PTV6
, NULL
); /* USBCLK_ON */
515 gpio_direction_output(GPIO_PTV6
, 1); /* USBCLK_ON = H */
516 msleep(20); /* wait 20ms to let the clock settle */
517 clk_enable(clk_get(NULL
, "usb0"));
518 __raw_writew(0x0600, 0xa40501d4);
523 extern char kfr2r09_sdram_enter_start
;
524 extern char kfr2r09_sdram_enter_end
;
525 extern char kfr2r09_sdram_leave_start
;
526 extern char kfr2r09_sdram_leave_end
;
528 static int __init
kfr2r09_devices_setup(void)
530 /* register board specific self-refresh code */
531 sh_mobile_register_self_refresh(SUSP_SH_STANDBY
| SUSP_SH_SF
|
533 &kfr2r09_sdram_enter_start
,
534 &kfr2r09_sdram_enter_end
,
535 &kfr2r09_sdram_leave_start
,
536 &kfr2r09_sdram_leave_end
);
538 /* enable SCIF1 serial port for YC401 console support */
539 gpio_request(GPIO_FN_SCIF1_RXD
, NULL
);
540 gpio_request(GPIO_FN_SCIF1_TXD
, NULL
);
541 kfr2r09_serial_i2c_setup(); /* ECONTMSK(bit6=L10ONEN) set 1 */
542 gpio_request(GPIO_PTG3
, NULL
); /* HPON_ON */
543 gpio_direction_output(GPIO_PTG3
, 1); /* HPON_ON = H */
545 /* setup NOR flash at CS0 */
546 __raw_writel(0x36db0400, BSC_CS0BCR
);
547 __raw_writel(0x00000500, BSC_CS0WCR
);
549 /* setup NAND flash at CS4 */
550 __raw_writel(0x36db0400, BSC_CS4BCR
);
551 __raw_writel(0x00000500, BSC_CS4WCR
);
553 /* setup KEYSC pins */
554 gpio_request(GPIO_FN_KEYOUT0
, NULL
);
555 gpio_request(GPIO_FN_KEYOUT1
, NULL
);
556 gpio_request(GPIO_FN_KEYOUT2
, NULL
);
557 gpio_request(GPIO_FN_KEYOUT3
, NULL
);
558 gpio_request(GPIO_FN_KEYOUT4_IN6
, NULL
);
559 gpio_request(GPIO_FN_KEYIN0
, NULL
);
560 gpio_request(GPIO_FN_KEYIN1
, NULL
);
561 gpio_request(GPIO_FN_KEYIN2
, NULL
);
562 gpio_request(GPIO_FN_KEYIN3
, NULL
);
563 gpio_request(GPIO_FN_KEYIN4
, NULL
);
564 gpio_request(GPIO_FN_KEYOUT5_IN5
, NULL
);
566 /* setup LCDC pins for SYS panel */
567 gpio_request(GPIO_FN_LCDD17
, NULL
);
568 gpio_request(GPIO_FN_LCDD16
, NULL
);
569 gpio_request(GPIO_FN_LCDD15
, NULL
);
570 gpio_request(GPIO_FN_LCDD14
, NULL
);
571 gpio_request(GPIO_FN_LCDD13
, NULL
);
572 gpio_request(GPIO_FN_LCDD12
, NULL
);
573 gpio_request(GPIO_FN_LCDD11
, NULL
);
574 gpio_request(GPIO_FN_LCDD10
, NULL
);
575 gpio_request(GPIO_FN_LCDD9
, NULL
);
576 gpio_request(GPIO_FN_LCDD8
, NULL
);
577 gpio_request(GPIO_FN_LCDD7
, NULL
);
578 gpio_request(GPIO_FN_LCDD6
, NULL
);
579 gpio_request(GPIO_FN_LCDD5
, NULL
);
580 gpio_request(GPIO_FN_LCDD4
, NULL
);
581 gpio_request(GPIO_FN_LCDD3
, NULL
);
582 gpio_request(GPIO_FN_LCDD2
, NULL
);
583 gpio_request(GPIO_FN_LCDD1
, NULL
);
584 gpio_request(GPIO_FN_LCDD0
, NULL
);
585 gpio_request(GPIO_FN_LCDRS
, NULL
); /* LCD_RS */
586 gpio_request(GPIO_FN_LCDCS
, NULL
); /* LCD_CS/ */
587 gpio_request(GPIO_FN_LCDRD
, NULL
); /* LCD_RD/ */
588 gpio_request(GPIO_FN_LCDWR
, NULL
); /* LCD_WR/ */
589 gpio_request(GPIO_FN_LCDVSYN
, NULL
); /* LCD_VSYNC */
590 gpio_request(GPIO_PTE4
, NULL
); /* LCD_RST/ */
591 gpio_direction_output(GPIO_PTE4
, 1);
592 gpio_request(GPIO_PTF4
, NULL
); /* PROTECT/ */
593 gpio_direction_output(GPIO_PTF4
, 1);
594 gpio_request(GPIO_PTU0
, NULL
); /* LEDSTDBY/ */
595 gpio_direction_output(GPIO_PTU0
, 1);
597 /* setup USB function */
598 if (kfr2r09_usb0_gadget_setup() == 0)
599 platform_device_register(&kfr2r09_usb0_gadget_device
);
602 gpio_request(GPIO_FN_VIO_CKO
, NULL
);
603 gpio_request(GPIO_FN_VIO0_CLK
, NULL
);
604 gpio_request(GPIO_FN_VIO0_VD
, NULL
);
605 gpio_request(GPIO_FN_VIO0_HD
, NULL
);
606 gpio_request(GPIO_FN_VIO0_FLD
, NULL
);
607 gpio_request(GPIO_FN_VIO0_D7
, NULL
);
608 gpio_request(GPIO_FN_VIO0_D6
, NULL
);
609 gpio_request(GPIO_FN_VIO0_D5
, NULL
);
610 gpio_request(GPIO_FN_VIO0_D4
, NULL
);
611 gpio_request(GPIO_FN_VIO0_D3
, NULL
);
612 gpio_request(GPIO_FN_VIO0_D2
, NULL
);
613 gpio_request(GPIO_FN_VIO0_D1
, NULL
);
614 gpio_request(GPIO_FN_VIO0_D0
, NULL
);
616 platform_resource_setup_memory(&kfr2r09_ceu_device
, "ceu", 4 << 20);
618 /* SDHI0 connected to yc304 */
619 gpio_request(GPIO_FN_SDHI0CD
, NULL
);
620 gpio_request(GPIO_FN_SDHI0D3
, NULL
);
621 gpio_request(GPIO_FN_SDHI0D2
, NULL
);
622 gpio_request(GPIO_FN_SDHI0D1
, NULL
);
623 gpio_request(GPIO_FN_SDHI0D0
, NULL
);
624 gpio_request(GPIO_FN_SDHI0CMD
, NULL
);
625 gpio_request(GPIO_FN_SDHI0CLK
, NULL
);
627 return platform_add_devices(kfr2r09_devices
,
628 ARRAY_SIZE(kfr2r09_devices
));
630 device_initcall(kfr2r09_devices_setup
);
632 /* Return the board specific boot mode pin configuration */
633 static int kfr2r09_mode_pins(void)
635 /* MD0=1, MD1=1, MD2=0: Clock Mode 3
636 * MD3=0: 16-bit Area0 Bus Width
637 * MD5=1: Little Endian
638 * MD8=1: Test Mode Disabled
640 return MODE_PIN0
| MODE_PIN1
| MODE_PIN5
| MODE_PIN8
;
646 static struct sh_machine_vector mv_kfr2r09 __initmv
= {
647 .mv_name
= "kfr2r09",
648 .mv_mode_pins
= kfr2r09_mode_pins
,