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/i2c.h>
20 #include <linux/usb/r8a66597.h>
21 #include <media/soc_camera.h>
22 #include <media/sh_mobile_ceu.h>
23 #include <video/sh_mobile_lcdc.h>
24 #include <asm/clock.h>
25 #include <asm/machvec.h>
27 #include <asm/sh_keysc.h>
28 #include <cpu/sh7724.h>
29 #include <mach/kfr2r09.h>
31 static struct mtd_partition kfr2r09_nor_flash_partitions
[] =
36 .size
= (4 * 1024 * 1024),
37 .mask_flags
= MTD_WRITEABLE
, /* Read-only */
41 .offset
= MTDPART_OFS_APPEND
,
42 .size
= MTDPART_SIZ_FULL
,
46 static struct physmap_flash_data kfr2r09_nor_flash_data
= {
48 .parts
= kfr2r09_nor_flash_partitions
,
49 .nr_parts
= ARRAY_SIZE(kfr2r09_nor_flash_partitions
),
52 static struct resource kfr2r09_nor_flash_resources
[] = {
57 .flags
= IORESOURCE_MEM
,
61 static struct platform_device kfr2r09_nor_flash_device
= {
62 .name
= "physmap-flash",
63 .resource
= kfr2r09_nor_flash_resources
,
64 .num_resources
= ARRAY_SIZE(kfr2r09_nor_flash_resources
),
66 .platform_data
= &kfr2r09_nor_flash_data
,
70 static struct resource kfr2r09_nand_flash_resources
[] = {
75 .flags
= IORESOURCE_MEM
,
79 static struct platform_device kfr2r09_nand_flash_device
= {
80 .name
= "onenand-flash",
81 .resource
= kfr2r09_nand_flash_resources
,
82 .num_resources
= ARRAY_SIZE(kfr2r09_nand_flash_resources
),
85 static struct sh_keysc_info kfr2r09_sh_keysc_info
= {
86 .mode
= SH_KEYSC_MODE_1
, /* KEYOUT0->4, KEYIN0->4 */
90 KEY_PHONE
, KEY_CLEAR
, KEY_MAIL
, KEY_WWW
, KEY_ENTER
,
91 KEY_1
, KEY_2
, KEY_3
, 0, KEY_UP
,
92 KEY_4
, KEY_5
, KEY_6
, 0, KEY_LEFT
,
93 KEY_7
, KEY_8
, KEY_9
, KEY_PROG1
, KEY_RIGHT
,
94 KEY_S
, KEY_0
, KEY_P
, KEY_PROG2
, KEY_DOWN
,
99 static struct resource kfr2r09_sh_keysc_resources
[] = {
104 .flags
= IORESOURCE_MEM
,
108 .flags
= IORESOURCE_IRQ
,
112 static struct platform_device kfr2r09_sh_keysc_device
= {
114 .id
= 0, /* "keysc0" clock */
115 .num_resources
= ARRAY_SIZE(kfr2r09_sh_keysc_resources
),
116 .resource
= kfr2r09_sh_keysc_resources
,
118 .platform_data
= &kfr2r09_sh_keysc_info
,
121 .hwblk_id
= HWBLK_KEYSC
,
125 static struct sh_mobile_lcdc_info kfr2r09_sh_lcdc_info
= {
126 .clock_source
= LCDC_CLK_BUS
,
128 .chan
= LCDC_CHAN_MAINLCD
,
130 .interface_type
= SYS18
,
132 .flags
= LCDC_FLAGS_DWPOL
,
134 .name
= "TX07D34VM0AAA",
143 .sync
= FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
150 .setup_sys
= kfr2r09_lcd_setup
,
151 .display_on
= kfr2r09_lcd_on
,
152 .display_off
= kfr2r09_lcd_off
,
155 .ldmt2r
= 0x07010904,
156 .ldmt3r
= 0x14012914,
157 /* set 1s delay to encourage fsync() */
158 .deferred_io_msec
= 1000,
163 static struct resource kfr2r09_sh_lcdc_resources
[] = {
166 .start
= 0xfe940000, /* P4-only space */
168 .flags
= IORESOURCE_MEM
,
172 .flags
= IORESOURCE_IRQ
,
176 static struct platform_device kfr2r09_sh_lcdc_device
= {
177 .name
= "sh_mobile_lcdc_fb",
178 .num_resources
= ARRAY_SIZE(kfr2r09_sh_lcdc_resources
),
179 .resource
= kfr2r09_sh_lcdc_resources
,
181 .platform_data
= &kfr2r09_sh_lcdc_info
,
184 .hwblk_id
= HWBLK_LCDC
,
188 static struct r8a66597_platdata kfr2r09_usb0_gadget_data
= {
192 static struct resource kfr2r09_usb0_gadget_resources
[] = {
196 .flags
= IORESOURCE_MEM
,
201 .flags
= IORESOURCE_IRQ
| IRQF_TRIGGER_LOW
,
205 static struct platform_device kfr2r09_usb0_gadget_device
= {
206 .name
= "r8a66597_udc",
209 .dma_mask
= NULL
, /* not use dma */
210 .coherent_dma_mask
= 0xffffffff,
211 .platform_data
= &kfr2r09_usb0_gadget_data
,
213 .num_resources
= ARRAY_SIZE(kfr2r09_usb0_gadget_resources
),
214 .resource
= kfr2r09_usb0_gadget_resources
,
217 static struct sh_mobile_ceu_info sh_mobile_ceu_info
= {
218 .flags
= SH_CEU_FLAG_USE_8BIT_BUS
,
221 static struct resource kfr2r09_ceu_resources
[] = {
226 .flags
= IORESOURCE_MEM
,
231 .flags
= IORESOURCE_IRQ
,
234 /* place holder for contiguous memory */
238 static struct platform_device kfr2r09_ceu_device
= {
239 .name
= "sh_mobile_ceu",
240 .id
= 0, /* "ceu0" clock */
241 .num_resources
= ARRAY_SIZE(kfr2r09_ceu_resources
),
242 .resource
= kfr2r09_ceu_resources
,
244 .platform_data
= &sh_mobile_ceu_info
,
247 .hwblk_id
= HWBLK_CEU0
,
251 static struct i2c_board_info kfr2r09_i2c_camera
= {
252 I2C_BOARD_INFO("rj54n1cb0c", 0x50),
255 static struct clk
*camera_clk
;
257 #define DRVCRB 0xA405018C
258 static int camera_power(struct device
*dev
, int mode
)
265 camera_clk
= clk_get(NULL
, "video_clk");
266 if (IS_ERR(camera_clk
))
267 return PTR_ERR(camera_clk
);
269 /* set VIO_CKO clock to 25MHz */
270 rate
= clk_round_rate(camera_clk
, 25000000);
271 ret
= clk_set_rate(camera_clk
, rate
);
277 * use 1.8 V for VccQ_VIO
278 * use 2.85V for VccQ_SR
280 ctrl_outw((ctrl_inw(DRVCRB
) & ~0x0003) | 0x0001, DRVCRB
);
283 ret
= gpio_request(GPIO_PTB4
, NULL
);
286 ret
= gpio_request(GPIO_PTB7
, NULL
);
290 ret
= gpio_direction_output(GPIO_PTB4
, 1);
292 ret
= gpio_direction_output(GPIO_PTB7
, 1);
297 ret
= clk_enable(camera_clk
); /* start VIO_CKO */
306 clk_disable(camera_clk
);
308 gpio_set_value(GPIO_PTB7
, 0);
310 gpio_set_value(GPIO_PTB4
, 0);
311 gpio_free(GPIO_PTB7
);
313 gpio_free(GPIO_PTB4
);
320 static struct soc_camera_link rj54n1_link
= {
321 .power
= camera_power
,
322 .board_info
= &kfr2r09_i2c_camera
,
324 .module_name
= "rj54n1cb0c",
327 static struct platform_device kfr2r09_camera
= {
328 .name
= "soc-camera-pdrv",
331 .platform_data
= &rj54n1_link
,
335 static struct platform_device
*kfr2r09_devices
[] __initdata
= {
336 &kfr2r09_nor_flash_device
,
337 &kfr2r09_nand_flash_device
,
338 &kfr2r09_sh_keysc_device
,
339 &kfr2r09_sh_lcdc_device
,
344 #define BSC_CS0BCR 0xfec10004
345 #define BSC_CS0WCR 0xfec10024
346 #define BSC_CS4BCR 0xfec10010
347 #define BSC_CS4WCR 0xfec10030
348 #define PORT_MSELCRB 0xa4050182
351 static int kfr2r09_usb0_gadget_i2c_setup(void)
353 struct i2c_adapter
*a
;
355 unsigned char buf
[2];
358 a
= i2c_get_adapter(0);
362 /* set bit 1 (the second bit) of chip at 0x09, register 0x13 */
368 ret
= i2c_transfer(a
, &msg
, 1);
376 msg
.flags
= I2C_M_RD
;
377 ret
= i2c_transfer(a
, &msg
, 1);
381 buf
[1] = buf
[0] | (1 << 1);
387 ret
= i2c_transfer(a
, &msg
, 1);
394 static int kfr2r09_usb0_gadget_i2c_setup(void)
400 static int kfr2r09_usb0_gadget_setup(void)
404 gpio_request(GPIO_PTN4
, NULL
); /* USB_DET */
405 gpio_direction_input(GPIO_PTN4
);
406 plugged_in
= gpio_get_value(GPIO_PTN4
);
408 return -ENODEV
; /* no cable plugged in */
410 if (kfr2r09_usb0_gadget_i2c_setup() != 0)
411 return -ENODEV
; /* unable to configure using i2c */
413 ctrl_outw((ctrl_inw(PORT_MSELCRB
) & ~0xc000) | 0x8000, PORT_MSELCRB
);
414 gpio_request(GPIO_FN_PDSTATUS
, NULL
); /* R-standby disables USB clock */
415 gpio_request(GPIO_PTV6
, NULL
); /* USBCLK_ON */
416 gpio_direction_output(GPIO_PTV6
, 1); /* USBCLK_ON = H */
417 msleep(20); /* wait 20ms to let the clock settle */
418 clk_enable(clk_get(NULL
, "usb0"));
419 ctrl_outw(0x0600, 0xa40501d4);
424 static int __init
kfr2r09_devices_setup(void)
426 /* enable SCIF1 serial port for YC401 console support */
427 gpio_request(GPIO_FN_SCIF1_RXD
, NULL
);
428 gpio_request(GPIO_FN_SCIF1_TXD
, NULL
);
430 /* setup NOR flash at CS0 */
431 ctrl_outl(0x36db0400, BSC_CS0BCR
);
432 ctrl_outl(0x00000500, BSC_CS0WCR
);
434 /* setup NAND flash at CS4 */
435 ctrl_outl(0x36db0400, BSC_CS4BCR
);
436 ctrl_outl(0x00000500, BSC_CS4WCR
);
438 /* setup KEYSC pins */
439 gpio_request(GPIO_FN_KEYOUT0
, NULL
);
440 gpio_request(GPIO_FN_KEYOUT1
, NULL
);
441 gpio_request(GPIO_FN_KEYOUT2
, NULL
);
442 gpio_request(GPIO_FN_KEYOUT3
, NULL
);
443 gpio_request(GPIO_FN_KEYOUT4_IN6
, NULL
);
444 gpio_request(GPIO_FN_KEYIN0
, NULL
);
445 gpio_request(GPIO_FN_KEYIN1
, NULL
);
446 gpio_request(GPIO_FN_KEYIN2
, NULL
);
447 gpio_request(GPIO_FN_KEYIN3
, NULL
);
448 gpio_request(GPIO_FN_KEYIN4
, NULL
);
449 gpio_request(GPIO_FN_KEYOUT5_IN5
, NULL
);
451 /* setup LCDC pins for SYS panel */
452 gpio_request(GPIO_FN_LCDD17
, NULL
);
453 gpio_request(GPIO_FN_LCDD16
, NULL
);
454 gpio_request(GPIO_FN_LCDD15
, NULL
);
455 gpio_request(GPIO_FN_LCDD14
, NULL
);
456 gpio_request(GPIO_FN_LCDD13
, NULL
);
457 gpio_request(GPIO_FN_LCDD12
, NULL
);
458 gpio_request(GPIO_FN_LCDD11
, NULL
);
459 gpio_request(GPIO_FN_LCDD10
, NULL
);
460 gpio_request(GPIO_FN_LCDD9
, NULL
);
461 gpio_request(GPIO_FN_LCDD8
, NULL
);
462 gpio_request(GPIO_FN_LCDD7
, NULL
);
463 gpio_request(GPIO_FN_LCDD6
, NULL
);
464 gpio_request(GPIO_FN_LCDD5
, NULL
);
465 gpio_request(GPIO_FN_LCDD4
, NULL
);
466 gpio_request(GPIO_FN_LCDD3
, NULL
);
467 gpio_request(GPIO_FN_LCDD2
, NULL
);
468 gpio_request(GPIO_FN_LCDD1
, NULL
);
469 gpio_request(GPIO_FN_LCDD0
, NULL
);
470 gpio_request(GPIO_FN_LCDRS
, NULL
); /* LCD_RS */
471 gpio_request(GPIO_FN_LCDCS
, NULL
); /* LCD_CS/ */
472 gpio_request(GPIO_FN_LCDRD
, NULL
); /* LCD_RD/ */
473 gpio_request(GPIO_FN_LCDWR
, NULL
); /* LCD_WR/ */
474 gpio_request(GPIO_FN_LCDVSYN
, NULL
); /* LCD_VSYNC */
475 gpio_request(GPIO_PTE4
, NULL
); /* LCD_RST/ */
476 gpio_direction_output(GPIO_PTE4
, 1);
477 gpio_request(GPIO_PTF4
, NULL
); /* PROTECT/ */
478 gpio_direction_output(GPIO_PTF4
, 1);
479 gpio_request(GPIO_PTU0
, NULL
); /* LEDSTDBY/ */
480 gpio_direction_output(GPIO_PTU0
, 1);
482 /* setup USB function */
483 if (kfr2r09_usb0_gadget_setup() == 0)
484 platform_device_register(&kfr2r09_usb0_gadget_device
);
487 gpio_request(GPIO_FN_VIO_CKO
, NULL
);
488 gpio_request(GPIO_FN_VIO0_CLK
, NULL
);
489 gpio_request(GPIO_FN_VIO0_VD
, NULL
);
490 gpio_request(GPIO_FN_VIO0_HD
, NULL
);
491 gpio_request(GPIO_FN_VIO0_FLD
, NULL
);
492 gpio_request(GPIO_FN_VIO0_D7
, NULL
);
493 gpio_request(GPIO_FN_VIO0_D6
, NULL
);
494 gpio_request(GPIO_FN_VIO0_D5
, NULL
);
495 gpio_request(GPIO_FN_VIO0_D4
, NULL
);
496 gpio_request(GPIO_FN_VIO0_D3
, NULL
);
497 gpio_request(GPIO_FN_VIO0_D2
, NULL
);
498 gpio_request(GPIO_FN_VIO0_D1
, NULL
);
499 gpio_request(GPIO_FN_VIO0_D0
, NULL
);
501 platform_resource_setup_memory(&kfr2r09_ceu_device
, "ceu", 4 << 20);
503 return platform_add_devices(kfr2r09_devices
,
504 ARRAY_SIZE(kfr2r09_devices
));
506 device_initcall(kfr2r09_devices_setup
);
508 /* Return the board specific boot mode pin configuration */
509 static int kfr2r09_mode_pins(void)
511 /* MD0=1, MD1=1, MD2=0: Clock Mode 3
512 * MD3=0: 16-bit Area0 Bus Width
513 * MD5=1: Little Endian
514 * MD8=1: Test Mode Disabled
516 return MODE_PIN0
| MODE_PIN1
| MODE_PIN5
| MODE_PIN8
;
522 static struct sh_machine_vector mv_kfr2r09 __initmv
= {
523 .mv_name
= "kfr2r09",
524 .mv_mode_pins
= kfr2r09_mode_pins
,