1 // SPDX-License-Identifier: GPL-2.0
3 * KFR2R09 board support code
5 * Copyright (C) 2009 Magnus Damm
10 #include <asm/machvec.h>
11 #include <asm/suspend.h>
13 #include <cpu/sh7724.h>
15 #include <linux/clkdev.h>
16 #include <linux/delay.h>
17 #include <linux/dma-mapping.h>
18 #include <linux/gpio.h>
19 #include <linux/gpio/machine.h>
20 #include <linux/i2c.h>
21 #include <linux/init.h>
22 #include <linux/input.h>
23 #include <linux/input/sh_keysc.h>
24 #include <linux/interrupt.h>
25 #include <linux/memblock.h>
26 #include <linux/mfd/tmio.h>
27 #include <linux/mmc/host.h>
28 #include <linux/mtd/onenand.h>
29 #include <linux/mtd/physmap.h>
30 #include <linux/platform_data/lv5207lp.h>
31 #include <linux/platform_device.h>
32 #include <linux/regulator/fixed.h>
33 #include <linux/regulator/machine.h>
34 #include <linux/sh_intc.h>
35 #include <linux/usb/r8a66597.h>
36 #include <linux/videodev2.h>
38 #include <mach/kfr2r09.h>
40 #include <media/drv-intf/renesas-ceu.h>
41 #include <media/i2c/rj54n1cb0c.h>
43 #include <video/sh_mobile_lcdc.h>
45 #define CEU_BUFFER_MEMORY_SIZE (4 << 20)
46 static phys_addr_t ceu_dma_membase;
48 /* set VIO_CKO clock to 25MHz */
49 #define CEU_MCLK_FREQ 25000000
50 #define DRVCRB 0xA405018C
52 static struct mtd_partition kfr2r09_nor_flash_partitions[] =
57 .size = (4 * 1024 * 1024),
58 .mask_flags = MTD_WRITEABLE, /* Read-only */
62 .offset = MTDPART_OFS_APPEND,
63 .size = MTDPART_SIZ_FULL,
67 static struct physmap_flash_data kfr2r09_nor_flash_data = {
69 .parts = kfr2r09_nor_flash_partitions,
70 .nr_parts = ARRAY_SIZE(kfr2r09_nor_flash_partitions),
73 static struct resource kfr2r09_nor_flash_resources[] = {
78 .flags = IORESOURCE_MEM,
82 static struct platform_device kfr2r09_nor_flash_device = {
83 .name = "physmap-flash",
84 .resource = kfr2r09_nor_flash_resources,
85 .num_resources = ARRAY_SIZE(kfr2r09_nor_flash_resources),
87 .platform_data = &kfr2r09_nor_flash_data,
91 static struct resource kfr2r09_nand_flash_resources[] = {
96 .flags = IORESOURCE_MEM,
100 static struct platform_device kfr2r09_nand_flash_device = {
101 .name = "onenand-flash",
102 .resource = kfr2r09_nand_flash_resources,
103 .num_resources = ARRAY_SIZE(kfr2r09_nand_flash_resources),
106 static struct sh_keysc_info kfr2r09_sh_keysc_info = {
107 .mode = SH_KEYSC_MODE_1, /* KEYOUT0->4, KEYIN0->4 */
111 KEY_PHONE, KEY_CLEAR, KEY_MAIL, KEY_WWW, KEY_ENTER,
112 KEY_1, KEY_2, KEY_3, 0, KEY_UP,
113 KEY_4, KEY_5, KEY_6, 0, KEY_LEFT,
114 KEY_7, KEY_8, KEY_9, KEY_PROG1, KEY_RIGHT,
115 KEY_S, KEY_0, KEY_P, KEY_PROG2, KEY_DOWN,
120 static struct resource kfr2r09_sh_keysc_resources[] = {
125 .flags = IORESOURCE_MEM,
128 .start = evt2irq(0xbe0),
129 .flags = IORESOURCE_IRQ,
133 static struct platform_device kfr2r09_sh_keysc_device = {
135 .id = 0, /* "keysc0" clock */
136 .num_resources = ARRAY_SIZE(kfr2r09_sh_keysc_resources),
137 .resource = kfr2r09_sh_keysc_resources,
139 .platform_data = &kfr2r09_sh_keysc_info,
143 static const struct fb_videomode kfr2r09_lcdc_modes[] = {
145 .name = "TX07D34VM0AAA",
154 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
158 static struct sh_mobile_lcdc_info kfr2r09_sh_lcdc_info = {
159 .clock_source = LCDC_CLK_BUS,
161 .chan = LCDC_CHAN_MAINLCD,
162 .fourcc = V4L2_PIX_FMT_RGB565,
163 .interface_type = SYS18,
165 .flags = LCDC_FLAGS_DWPOL,
166 .lcd_modes = kfr2r09_lcdc_modes,
167 .num_modes = ARRAY_SIZE(kfr2r09_lcdc_modes),
171 .setup_sys = kfr2r09_lcd_setup,
172 .start_transfer = kfr2r09_lcd_start,
175 .ldmt2r = 0x07010904,
176 .ldmt3r = 0x14012914,
177 /* set 1s delay to encourage fsync() */
178 .deferred_io_msec = 1000,
183 static struct resource kfr2r09_sh_lcdc_resources[] = {
186 .start = 0xfe940000, /* P4-only space */
188 .flags = IORESOURCE_MEM,
191 .start = evt2irq(0xf40),
192 .flags = IORESOURCE_IRQ,
196 static struct platform_device kfr2r09_sh_lcdc_device = {
197 .name = "sh_mobile_lcdc_fb",
198 .num_resources = ARRAY_SIZE(kfr2r09_sh_lcdc_resources),
199 .resource = kfr2r09_sh_lcdc_resources,
201 .platform_data = &kfr2r09_sh_lcdc_info,
205 static struct lv5207lp_platform_data kfr2r09_backlight_data = {
206 .fbdev = &kfr2r09_sh_lcdc_device.dev,
211 static struct i2c_board_info kfr2r09_backlight_board_info = {
212 I2C_BOARD_INFO("lv5207lp", 0x75),
213 .platform_data = &kfr2r09_backlight_data,
216 static struct r8a66597_platdata kfr2r09_usb0_gadget_data = {
220 static struct resource kfr2r09_usb0_gadget_resources[] = {
224 .flags = IORESOURCE_MEM,
227 .start = evt2irq(0xa20),
228 .end = evt2irq(0xa20),
229 .flags = IORESOURCE_IRQ | IRQF_TRIGGER_LOW,
233 static struct platform_device kfr2r09_usb0_gadget_device = {
234 .name = "r8a66597_udc",
237 .dma_mask = NULL, /* not use dma */
238 .coherent_dma_mask = 0xffffffff,
239 .platform_data = &kfr2r09_usb0_gadget_data,
241 .num_resources = ARRAY_SIZE(kfr2r09_usb0_gadget_resources),
242 .resource = kfr2r09_usb0_gadget_resources,
245 static struct ceu_platform_data ceu_pdata = {
248 { /* [0] = rj54n1cb0c */
258 static struct resource kfr2r09_ceu_resources[] = {
263 .flags = IORESOURCE_MEM,
266 .start = evt2irq(0x880),
267 .end = evt2irq(0x880),
268 .flags = IORESOURCE_IRQ,
272 static struct platform_device kfr2r09_ceu_device = {
273 .name = "renesas-ceu",
274 .id = 0, /* "ceu0" clock */
275 .num_resources = ARRAY_SIZE(kfr2r09_ceu_resources),
276 .resource = kfr2r09_ceu_resources,
278 .platform_data = &ceu_pdata,
282 static struct rj54n1_pdata rj54n1_priv = {
283 .mclk_freq = CEU_MCLK_FREQ,
287 static struct i2c_board_info kfr2r09_i2c_camera = {
288 I2C_BOARD_INFO("rj54n1cb0c", 0x50),
289 .platform_data = &rj54n1_priv,
292 static struct gpiod_lookup_table rj54n1_gpios = {
295 GPIO_LOOKUP("sh7724_pfc", GPIO_PTB4, "poweron",
297 GPIO_LOOKUP("sh7724_pfc", GPIO_PTB7, "enable",
302 /* Fixed 3.3V regulator to be used by SDHI0 */
303 static struct regulator_consumer_supply fixed3v3_power_consumers[] =
305 REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.0"),
306 REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.0"),
309 static struct resource kfr2r09_sh_sdhi0_resources[] = {
314 .flags = IORESOURCE_MEM,
317 .start = evt2irq(0xe80),
318 .flags = IORESOURCE_IRQ,
322 static struct tmio_mmc_data sh7724_sdhi0_data = {
323 .chan_priv_tx = (void *)SHDMA_SLAVE_SDHI0_TX,
324 .chan_priv_rx = (void *)SHDMA_SLAVE_SDHI0_RX,
325 .capabilities = MMC_CAP_SDIO_IRQ,
326 .capabilities2 = MMC_CAP2_NO_WRITE_PROTECT,
329 static struct platform_device kfr2r09_sh_sdhi0_device = {
330 .name = "sh_mobile_sdhi",
331 .num_resources = ARRAY_SIZE(kfr2r09_sh_sdhi0_resources),
332 .resource = kfr2r09_sh_sdhi0_resources,
334 .platform_data = &sh7724_sdhi0_data,
338 static struct platform_device *kfr2r09_devices[] __initdata = {
339 &kfr2r09_nor_flash_device,
340 &kfr2r09_nand_flash_device,
341 &kfr2r09_sh_keysc_device,
342 &kfr2r09_sh_lcdc_device,
343 &kfr2r09_sh_sdhi0_device,
346 #define BSC_CS0BCR 0xfec10004
347 #define BSC_CS0WCR 0xfec10024
348 #define BSC_CS4BCR 0xfec10010
349 #define BSC_CS4WCR 0xfec10030
350 #define PORT_MSELCRB 0xa4050182
353 static int kfr2r09_usb0_gadget_i2c_setup(void)
355 struct i2c_adapter *a;
357 unsigned char buf[2];
360 a = i2c_get_adapter(0);
364 /* set bit 1 (the second bit) of chip at 0x09, register 0x13 */
370 ret = i2c_transfer(a, &msg, 1);
378 msg.flags = I2C_M_RD;
379 ret = i2c_transfer(a, &msg, 1);
383 buf[1] = buf[0] | (1 << 1);
389 ret = i2c_transfer(a, &msg, 1);
396 static int kfr2r09_serial_i2c_setup(void)
398 struct i2c_adapter *a;
400 unsigned char buf[2];
403 a = i2c_get_adapter(0);
407 /* set bit 6 (the 7th bit) of chip at 0x09, register 0x13 */
413 ret = i2c_transfer(a, &msg, 1);
421 msg.flags = I2C_M_RD;
422 ret = i2c_transfer(a, &msg, 1);
426 buf[1] = buf[0] | (1 << 6);
432 ret = i2c_transfer(a, &msg, 1);
439 static int kfr2r09_usb0_gadget_i2c_setup(void)
444 static int kfr2r09_serial_i2c_setup(void)
450 static int kfr2r09_usb0_gadget_setup(void)
454 gpio_request(GPIO_PTN4, NULL); /* USB_DET */
455 gpio_direction_input(GPIO_PTN4);
456 plugged_in = gpio_get_value(GPIO_PTN4);
458 return -ENODEV; /* no cable plugged in */
460 if (kfr2r09_usb0_gadget_i2c_setup() != 0)
461 return -ENODEV; /* unable to configure using i2c */
463 __raw_writew((__raw_readw(PORT_MSELCRB) & ~0xc000) | 0x8000, PORT_MSELCRB);
464 gpio_request(GPIO_FN_PDSTATUS, NULL); /* R-standby disables USB clock */
465 gpio_request(GPIO_PTV6, NULL); /* USBCLK_ON */
466 gpio_direction_output(GPIO_PTV6, 1); /* USBCLK_ON = H */
467 msleep(20); /* wait 20ms to let the clock settle */
468 clk_enable(clk_get(NULL, "usb0"));
469 __raw_writew(0x0600, 0xa40501d4);
474 extern char kfr2r09_sdram_enter_start;
475 extern char kfr2r09_sdram_enter_end;
476 extern char kfr2r09_sdram_leave_start;
477 extern char kfr2r09_sdram_leave_end;
479 static int __init kfr2r09_devices_setup(void)
481 static struct clk *camera_clk;
483 /* register board specific self-refresh code */
484 sh_mobile_register_self_refresh(SUSP_SH_STANDBY | SUSP_SH_SF |
486 &kfr2r09_sdram_enter_start,
487 &kfr2r09_sdram_enter_end,
488 &kfr2r09_sdram_leave_start,
489 &kfr2r09_sdram_leave_end);
491 regulator_register_always_on(0, "fixed-3.3V", fixed3v3_power_consumers,
492 ARRAY_SIZE(fixed3v3_power_consumers), 3300000);
494 /* enable SCIF1 serial port for YC401 console support */
495 gpio_request(GPIO_FN_SCIF1_RXD, NULL);
496 gpio_request(GPIO_FN_SCIF1_TXD, NULL);
497 kfr2r09_serial_i2c_setup(); /* ECONTMSK(bit6=L10ONEN) set 1 */
498 gpio_request(GPIO_PTG3, NULL); /* HPON_ON */
499 gpio_direction_output(GPIO_PTG3, 1); /* HPON_ON = H */
501 /* setup NOR flash at CS0 */
502 __raw_writel(0x36db0400, BSC_CS0BCR);
503 __raw_writel(0x00000500, BSC_CS0WCR);
505 /* setup NAND flash at CS4 */
506 __raw_writel(0x36db0400, BSC_CS4BCR);
507 __raw_writel(0x00000500, BSC_CS4WCR);
509 /* setup KEYSC pins */
510 gpio_request(GPIO_FN_KEYOUT0, NULL);
511 gpio_request(GPIO_FN_KEYOUT1, NULL);
512 gpio_request(GPIO_FN_KEYOUT2, NULL);
513 gpio_request(GPIO_FN_KEYOUT3, NULL);
514 gpio_request(GPIO_FN_KEYOUT4_IN6, NULL);
515 gpio_request(GPIO_FN_KEYIN0, NULL);
516 gpio_request(GPIO_FN_KEYIN1, NULL);
517 gpio_request(GPIO_FN_KEYIN2, NULL);
518 gpio_request(GPIO_FN_KEYIN3, NULL);
519 gpio_request(GPIO_FN_KEYIN4, NULL);
520 gpio_request(GPIO_FN_KEYOUT5_IN5, NULL);
522 /* setup LCDC pins for SYS panel */
523 gpio_request(GPIO_FN_LCDD17, NULL);
524 gpio_request(GPIO_FN_LCDD16, NULL);
525 gpio_request(GPIO_FN_LCDD15, NULL);
526 gpio_request(GPIO_FN_LCDD14, NULL);
527 gpio_request(GPIO_FN_LCDD13, NULL);
528 gpio_request(GPIO_FN_LCDD12, NULL);
529 gpio_request(GPIO_FN_LCDD11, NULL);
530 gpio_request(GPIO_FN_LCDD10, NULL);
531 gpio_request(GPIO_FN_LCDD9, NULL);
532 gpio_request(GPIO_FN_LCDD8, NULL);
533 gpio_request(GPIO_FN_LCDD7, NULL);
534 gpio_request(GPIO_FN_LCDD6, NULL);
535 gpio_request(GPIO_FN_LCDD5, NULL);
536 gpio_request(GPIO_FN_LCDD4, NULL);
537 gpio_request(GPIO_FN_LCDD3, NULL);
538 gpio_request(GPIO_FN_LCDD2, NULL);
539 gpio_request(GPIO_FN_LCDD1, NULL);
540 gpio_request(GPIO_FN_LCDD0, NULL);
541 gpio_request(GPIO_FN_LCDRS, NULL); /* LCD_RS */
542 gpio_request(GPIO_FN_LCDCS, NULL); /* LCD_CS/ */
543 gpio_request(GPIO_FN_LCDRD, NULL); /* LCD_RD/ */
544 gpio_request(GPIO_FN_LCDWR, NULL); /* LCD_WR/ */
545 gpio_request(GPIO_FN_LCDVSYN, NULL); /* LCD_VSYNC */
546 gpio_request(GPIO_PTE4, NULL); /* LCD_RST/ */
547 gpio_direction_output(GPIO_PTE4, 1);
548 gpio_request(GPIO_PTF4, NULL); /* PROTECT/ */
549 gpio_direction_output(GPIO_PTF4, 1);
550 gpio_request(GPIO_PTU0, NULL); /* LEDSTDBY/ */
551 gpio_direction_output(GPIO_PTU0, 1);
553 /* setup USB function */
554 if (kfr2r09_usb0_gadget_setup() == 0)
555 platform_device_register(&kfr2r09_usb0_gadget_device);
558 gpio_request(GPIO_FN_VIO_CKO, NULL);
559 gpio_request(GPIO_FN_VIO0_CLK, NULL);
560 gpio_request(GPIO_FN_VIO0_VD, NULL);
561 gpio_request(GPIO_FN_VIO0_HD, NULL);
562 gpio_request(GPIO_FN_VIO0_FLD, NULL);
563 gpio_request(GPIO_FN_VIO0_D7, NULL);
564 gpio_request(GPIO_FN_VIO0_D6, NULL);
565 gpio_request(GPIO_FN_VIO0_D5, NULL);
566 gpio_request(GPIO_FN_VIO0_D4, NULL);
567 gpio_request(GPIO_FN_VIO0_D3, NULL);
568 gpio_request(GPIO_FN_VIO0_D2, NULL);
569 gpio_request(GPIO_FN_VIO0_D1, NULL);
570 gpio_request(GPIO_FN_VIO0_D0, NULL);
572 /* SDHI0 connected to yc304 */
573 gpio_request(GPIO_FN_SDHI0CD, NULL);
574 gpio_request(GPIO_FN_SDHI0D3, NULL);
575 gpio_request(GPIO_FN_SDHI0D2, NULL);
576 gpio_request(GPIO_FN_SDHI0D1, NULL);
577 gpio_request(GPIO_FN_SDHI0D0, NULL);
578 gpio_request(GPIO_FN_SDHI0CMD, NULL);
579 gpio_request(GPIO_FN_SDHI0CLK, NULL);
581 i2c_register_board_info(0, &kfr2r09_backlight_board_info, 1);
583 /* Set camera clock frequency and register and alias for rj54n1. */
584 camera_clk = clk_get(NULL, "video_clk");
585 if (!IS_ERR(camera_clk)) {
586 clk_set_rate(camera_clk,
587 clk_round_rate(camera_clk, CEU_MCLK_FREQ));
590 clk_add_alias(NULL, "1-0050", "video_clk", NULL);
594 * use 1.8 V for VccQ_VIO
595 * use 2.85V for VccQ_SR
597 __raw_writew((__raw_readw(DRVCRB) & ~0x0003) | 0x0001, DRVCRB);
599 gpiod_add_lookup_table(&rj54n1_gpios);
601 i2c_register_board_info(1, &kfr2r09_i2c_camera, 1);
603 /* Initialize CEU platform device separately to map memory first */
604 device_initialize(&kfr2r09_ceu_device.dev);
605 arch_setup_pdev_archdata(&kfr2r09_ceu_device);
606 dma_declare_coherent_memory(&kfr2r09_ceu_device.dev,
607 ceu_dma_membase, ceu_dma_membase,
608 ceu_dma_membase + CEU_BUFFER_MEMORY_SIZE - 1,
609 DMA_MEMORY_EXCLUSIVE);
611 platform_device_add(&kfr2r09_ceu_device);
613 return platform_add_devices(kfr2r09_devices,
614 ARRAY_SIZE(kfr2r09_devices));
616 device_initcall(kfr2r09_devices_setup);
618 /* Return the board specific boot mode pin configuration */
619 static int kfr2r09_mode_pins(void)
621 /* MD0=1, MD1=1, MD2=0: Clock Mode 3
622 * MD3=0: 16-bit Area0 Bus Width
623 * MD5=1: Little Endian
624 * MD8=1: Test Mode Disabled
626 return MODE_PIN0 | MODE_PIN1 | MODE_PIN5 | MODE_PIN8;
629 /* Reserve a portion of memory for CEU buffers */
630 static void __init kfr2r09_mv_mem_reserve(void)
633 phys_addr_t size = CEU_BUFFER_MEMORY_SIZE;
635 phys = memblock_alloc_base(size, PAGE_SIZE, MEMBLOCK_ALLOC_ANYWHERE);
636 memblock_free(phys, size);
637 memblock_remove(phys, size);
639 ceu_dma_membase = phys;
645 static struct sh_machine_vector mv_kfr2r09 __initmv = {
646 .mv_name = "kfr2r09",
647 .mv_mode_pins = kfr2r09_mode_pins,
648 .mv_mem_reserve = kfr2r09_mv_mem_reserve,