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/gpio.h>
18 #include <linux/gpio/machine.h>
19 #include <linux/i2c.h>
20 #include <linux/init.h>
21 #include <linux/input.h>
22 #include <linux/input/sh_keysc.h>
23 #include <linux/interrupt.h>
24 #include <linux/memblock.h>
25 #include <linux/mmc/host.h>
26 #include <linux/mtd/physmap.h>
27 #include <linux/platform_data/lv5207lp.h>
28 #include <linux/platform_data/tmio.h>
29 #include <linux/platform_device.h>
30 #include <linux/regulator/fixed.h>
31 #include <linux/regulator/machine.h>
32 #include <linux/sh_intc.h>
33 #include <linux/usb/r8a66597.h>
34 #include <linux/videodev2.h>
35 #include <linux/dma-map-ops.h>
37 #include <mach/kfr2r09.h>
39 #include <media/drv-intf/renesas-ceu.h>
40 #include <media/i2c/rj54n1cb0c.h>
42 #include <video/sh_mobile_lcdc.h>
44 #define CEU_BUFFER_MEMORY_SIZE (4 << 20)
45 static phys_addr_t ceu_dma_membase
;
47 /* set VIO_CKO clock to 25MHz */
48 #define CEU_MCLK_FREQ 25000000
49 #define DRVCRB 0xA405018C
51 static struct mtd_partition kfr2r09_nor_flash_partitions
[] =
56 .size
= (4 * 1024 * 1024),
57 .mask_flags
= MTD_WRITEABLE
, /* Read-only */
61 .offset
= MTDPART_OFS_APPEND
,
62 .size
= MTDPART_SIZ_FULL
,
66 static struct physmap_flash_data kfr2r09_nor_flash_data
= {
68 .parts
= kfr2r09_nor_flash_partitions
,
69 .nr_parts
= ARRAY_SIZE(kfr2r09_nor_flash_partitions
),
72 static struct resource kfr2r09_nor_flash_resources
[] = {
77 .flags
= IORESOURCE_MEM
,
81 static struct platform_device kfr2r09_nor_flash_device
= {
82 .name
= "physmap-flash",
83 .resource
= kfr2r09_nor_flash_resources
,
84 .num_resources
= ARRAY_SIZE(kfr2r09_nor_flash_resources
),
86 .platform_data
= &kfr2r09_nor_flash_data
,
90 static struct resource kfr2r09_nand_flash_resources
[] = {
95 .flags
= IORESOURCE_MEM
,
99 static struct platform_device kfr2r09_nand_flash_device
= {
100 .name
= "onenand-flash",
101 .resource
= kfr2r09_nand_flash_resources
,
102 .num_resources
= ARRAY_SIZE(kfr2r09_nand_flash_resources
),
105 static struct sh_keysc_info kfr2r09_sh_keysc_info
= {
106 .mode
= SH_KEYSC_MODE_1
, /* KEYOUT0->4, KEYIN0->4 */
110 KEY_PHONE
, KEY_CLEAR
, KEY_MAIL
, KEY_WWW
, KEY_ENTER
,
111 KEY_1
, KEY_2
, KEY_3
, 0, KEY_UP
,
112 KEY_4
, KEY_5
, KEY_6
, 0, KEY_LEFT
,
113 KEY_7
, KEY_8
, KEY_9
, KEY_PROG1
, KEY_RIGHT
,
114 KEY_S
, KEY_0
, KEY_P
, KEY_PROG2
, KEY_DOWN
,
119 static struct resource kfr2r09_sh_keysc_resources
[] = {
124 .flags
= IORESOURCE_MEM
,
127 .start
= evt2irq(0xbe0),
128 .flags
= IORESOURCE_IRQ
,
132 static struct platform_device kfr2r09_sh_keysc_device
= {
134 .id
= 0, /* "keysc0" clock */
135 .num_resources
= ARRAY_SIZE(kfr2r09_sh_keysc_resources
),
136 .resource
= kfr2r09_sh_keysc_resources
,
138 .platform_data
= &kfr2r09_sh_keysc_info
,
142 static const struct fb_videomode kfr2r09_lcdc_modes
[] = {
144 .name
= "TX07D34VM0AAA",
153 .sync
= FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
157 static struct sh_mobile_lcdc_info kfr2r09_sh_lcdc_info
= {
158 .clock_source
= LCDC_CLK_BUS
,
160 .chan
= LCDC_CHAN_MAINLCD
,
161 .fourcc
= V4L2_PIX_FMT_RGB565
,
162 .interface_type
= SYS18
,
164 .flags
= LCDC_FLAGS_DWPOL
,
165 .lcd_modes
= kfr2r09_lcdc_modes
,
166 .num_modes
= ARRAY_SIZE(kfr2r09_lcdc_modes
),
170 .setup_sys
= kfr2r09_lcd_setup
,
171 .start_transfer
= kfr2r09_lcd_start
,
174 .ldmt2r
= 0x07010904,
175 .ldmt3r
= 0x14012914,
176 /* set 1s delay to encourage fsync() */
177 .deferred_io_msec
= 1000,
182 static struct resource kfr2r09_sh_lcdc_resources
[] = {
185 .start
= 0xfe940000, /* P4-only space */
187 .flags
= IORESOURCE_MEM
,
190 .start
= evt2irq(0xf40),
191 .flags
= IORESOURCE_IRQ
,
195 static struct platform_device kfr2r09_sh_lcdc_device
= {
196 .name
= "sh_mobile_lcdc_fb",
197 .num_resources
= ARRAY_SIZE(kfr2r09_sh_lcdc_resources
),
198 .resource
= kfr2r09_sh_lcdc_resources
,
200 .platform_data
= &kfr2r09_sh_lcdc_info
,
204 static struct lv5207lp_platform_data kfr2r09_backlight_data
= {
205 .dev
= &kfr2r09_sh_lcdc_device
.dev
,
210 static struct i2c_board_info kfr2r09_backlight_board_info
= {
211 I2C_BOARD_INFO("lv5207lp", 0x75),
212 .platform_data
= &kfr2r09_backlight_data
,
215 static struct r8a66597_platdata kfr2r09_usb0_gadget_data
= {
219 static struct resource kfr2r09_usb0_gadget_resources
[] = {
223 .flags
= IORESOURCE_MEM
,
226 .start
= evt2irq(0xa20),
227 .end
= evt2irq(0xa20),
228 .flags
= IORESOURCE_IRQ
| IRQF_TRIGGER_LOW
,
232 static struct platform_device kfr2r09_usb0_gadget_device
= {
233 .name
= "r8a66597_udc",
236 .dma_mask
= NULL
, /* not use dma */
237 .coherent_dma_mask
= 0xffffffff,
238 .platform_data
= &kfr2r09_usb0_gadget_data
,
240 .num_resources
= ARRAY_SIZE(kfr2r09_usb0_gadget_resources
),
241 .resource
= kfr2r09_usb0_gadget_resources
,
244 static struct ceu_platform_data ceu_pdata
= {
247 { /* [0] = rj54n1cb0c */
257 static struct resource kfr2r09_ceu_resources
[] = {
262 .flags
= IORESOURCE_MEM
,
265 .start
= evt2irq(0x880),
266 .end
= evt2irq(0x880),
267 .flags
= IORESOURCE_IRQ
,
271 static struct platform_device kfr2r09_ceu_device
= {
272 .name
= "renesas-ceu",
273 .id
= 0, /* "ceu0" clock */
274 .num_resources
= ARRAY_SIZE(kfr2r09_ceu_resources
),
275 .resource
= kfr2r09_ceu_resources
,
277 .platform_data
= &ceu_pdata
,
281 static struct rj54n1_pdata rj54n1_priv
= {
282 .mclk_freq
= CEU_MCLK_FREQ
,
286 static struct i2c_board_info kfr2r09_i2c_camera
= {
287 I2C_BOARD_INFO("rj54n1cb0c", 0x50),
288 .platform_data
= &rj54n1_priv
,
291 static struct gpiod_lookup_table rj54n1_gpios
= {
294 GPIO_LOOKUP("sh7724_pfc", GPIO_PTB4
, "poweron",
296 GPIO_LOOKUP("sh7724_pfc", GPIO_PTB7
, "enable",
301 /* Fixed 3.3V regulator to be used by SDHI0 */
302 static struct regulator_consumer_supply fixed3v3_power_consumers
[] =
304 REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.0"),
305 REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.0"),
308 static struct resource kfr2r09_sh_sdhi0_resources
[] = {
313 .flags
= IORESOURCE_MEM
,
316 .start
= evt2irq(0xe80),
317 .flags
= IORESOURCE_IRQ
,
321 static struct tmio_mmc_data sh7724_sdhi0_data
= {
322 .chan_priv_tx
= (void *)SHDMA_SLAVE_SDHI0_TX
,
323 .chan_priv_rx
= (void *)SHDMA_SLAVE_SDHI0_RX
,
324 .capabilities
= MMC_CAP_SDIO_IRQ
,
325 .capabilities2
= MMC_CAP2_NO_WRITE_PROTECT
,
328 static struct platform_device kfr2r09_sh_sdhi0_device
= {
329 .name
= "sh_mobile_sdhi",
330 .num_resources
= ARRAY_SIZE(kfr2r09_sh_sdhi0_resources
),
331 .resource
= kfr2r09_sh_sdhi0_resources
,
333 .platform_data
= &sh7724_sdhi0_data
,
337 static struct platform_device
*kfr2r09_devices
[] __initdata
= {
338 &kfr2r09_nor_flash_device
,
339 &kfr2r09_nand_flash_device
,
340 &kfr2r09_sh_keysc_device
,
341 &kfr2r09_sh_lcdc_device
,
342 &kfr2r09_sh_sdhi0_device
,
345 #define BSC_CS0BCR 0xfec10004
346 #define BSC_CS0WCR 0xfec10024
347 #define BSC_CS4BCR 0xfec10010
348 #define BSC_CS4WCR 0xfec10030
349 #define PORT_MSELCRB 0xa4050182
352 static int kfr2r09_usb0_gadget_i2c_setup(void)
354 struct i2c_adapter
*a
;
356 unsigned char buf
[2];
359 a
= i2c_get_adapter(0);
363 /* set bit 1 (the second bit) of chip at 0x09, register 0x13 */
369 ret
= i2c_transfer(a
, &msg
, 1);
377 msg
.flags
= I2C_M_RD
;
378 ret
= i2c_transfer(a
, &msg
, 1);
382 buf
[1] = buf
[0] | (1 << 1);
388 ret
= i2c_transfer(a
, &msg
, 1);
395 static int kfr2r09_serial_i2c_setup(void)
397 struct i2c_adapter
*a
;
399 unsigned char buf
[2];
402 a
= i2c_get_adapter(0);
406 /* set bit 6 (the 7th bit) of chip at 0x09, register 0x13 */
412 ret
= i2c_transfer(a
, &msg
, 1);
420 msg
.flags
= I2C_M_RD
;
421 ret
= i2c_transfer(a
, &msg
, 1);
425 buf
[1] = buf
[0] | (1 << 6);
431 ret
= i2c_transfer(a
, &msg
, 1);
438 static int kfr2r09_usb0_gadget_i2c_setup(void)
443 static int kfr2r09_serial_i2c_setup(void)
449 static int kfr2r09_usb0_gadget_setup(void)
453 gpio_request(GPIO_PTN4
, NULL
); /* USB_DET */
454 gpio_direction_input(GPIO_PTN4
);
455 plugged_in
= gpio_get_value(GPIO_PTN4
);
457 return -ENODEV
; /* no cable plugged in */
459 if (kfr2r09_usb0_gadget_i2c_setup() != 0)
460 return -ENODEV
; /* unable to configure using i2c */
462 __raw_writew((__raw_readw(PORT_MSELCRB
) & ~0xc000) | 0x8000, PORT_MSELCRB
);
463 gpio_request(GPIO_FN_PDSTATUS
, NULL
); /* R-standby disables USB clock */
464 gpio_request(GPIO_PTV6
, NULL
); /* USBCLK_ON */
465 gpio_direction_output(GPIO_PTV6
, 1); /* USBCLK_ON = H */
466 msleep(20); /* wait 20ms to let the clock settle */
467 clk_enable(clk_get(NULL
, "usb0"));
468 __raw_writew(0x0600, 0xa40501d4);
473 extern char kfr2r09_sdram_enter_start
;
474 extern char kfr2r09_sdram_enter_end
;
475 extern char kfr2r09_sdram_leave_start
;
476 extern char kfr2r09_sdram_leave_end
;
478 static int __init
kfr2r09_devices_setup(void)
480 struct clk
*camera_clk
;
482 /* register board specific self-refresh code */
483 sh_mobile_register_self_refresh(SUSP_SH_STANDBY
| SUSP_SH_SF
|
485 &kfr2r09_sdram_enter_start
,
486 &kfr2r09_sdram_enter_end
,
487 &kfr2r09_sdram_leave_start
,
488 &kfr2r09_sdram_leave_end
);
490 regulator_register_always_on(0, "fixed-3.3V", fixed3v3_power_consumers
,
491 ARRAY_SIZE(fixed3v3_power_consumers
), 3300000);
493 /* enable SCIF1 serial port for YC401 console support */
494 gpio_request(GPIO_FN_SCIF1_RXD
, NULL
);
495 gpio_request(GPIO_FN_SCIF1_TXD
, NULL
);
496 kfr2r09_serial_i2c_setup(); /* ECONTMSK(bit6=L10ONEN) set 1 */
497 gpio_request(GPIO_PTG3
, NULL
); /* HPON_ON */
498 gpio_direction_output(GPIO_PTG3
, 1); /* HPON_ON = H */
500 /* setup NOR flash at CS0 */
501 __raw_writel(0x36db0400, BSC_CS0BCR
);
502 __raw_writel(0x00000500, BSC_CS0WCR
);
504 /* setup NAND flash at CS4 */
505 __raw_writel(0x36db0400, BSC_CS4BCR
);
506 __raw_writel(0x00000500, BSC_CS4WCR
);
508 /* setup KEYSC pins */
509 gpio_request(GPIO_FN_KEYOUT0
, NULL
);
510 gpio_request(GPIO_FN_KEYOUT1
, NULL
);
511 gpio_request(GPIO_FN_KEYOUT2
, NULL
);
512 gpio_request(GPIO_FN_KEYOUT3
, NULL
);
513 gpio_request(GPIO_FN_KEYOUT4_IN6
, NULL
);
514 gpio_request(GPIO_FN_KEYIN0
, NULL
);
515 gpio_request(GPIO_FN_KEYIN1
, NULL
);
516 gpio_request(GPIO_FN_KEYIN2
, NULL
);
517 gpio_request(GPIO_FN_KEYIN3
, NULL
);
518 gpio_request(GPIO_FN_KEYIN4
, NULL
);
519 gpio_request(GPIO_FN_KEYOUT5_IN5
, NULL
);
521 /* setup LCDC pins for SYS panel */
522 gpio_request(GPIO_FN_LCDD17
, NULL
);
523 gpio_request(GPIO_FN_LCDD16
, NULL
);
524 gpio_request(GPIO_FN_LCDD15
, NULL
);
525 gpio_request(GPIO_FN_LCDD14
, NULL
);
526 gpio_request(GPIO_FN_LCDD13
, NULL
);
527 gpio_request(GPIO_FN_LCDD12
, NULL
);
528 gpio_request(GPIO_FN_LCDD11
, NULL
);
529 gpio_request(GPIO_FN_LCDD10
, NULL
);
530 gpio_request(GPIO_FN_LCDD9
, NULL
);
531 gpio_request(GPIO_FN_LCDD8
, NULL
);
532 gpio_request(GPIO_FN_LCDD7
, NULL
);
533 gpio_request(GPIO_FN_LCDD6
, NULL
);
534 gpio_request(GPIO_FN_LCDD5
, NULL
);
535 gpio_request(GPIO_FN_LCDD4
, NULL
);
536 gpio_request(GPIO_FN_LCDD3
, NULL
);
537 gpio_request(GPIO_FN_LCDD2
, NULL
);
538 gpio_request(GPIO_FN_LCDD1
, NULL
);
539 gpio_request(GPIO_FN_LCDD0
, NULL
);
540 gpio_request(GPIO_FN_LCDRS
, NULL
); /* LCD_RS */
541 gpio_request(GPIO_FN_LCDCS
, NULL
); /* LCD_CS/ */
542 gpio_request(GPIO_FN_LCDRD
, NULL
); /* LCD_RD/ */
543 gpio_request(GPIO_FN_LCDWR
, NULL
); /* LCD_WR/ */
544 gpio_request(GPIO_FN_LCDVSYN
, NULL
); /* LCD_VSYNC */
545 gpio_request(GPIO_PTE4
, NULL
); /* LCD_RST/ */
546 gpio_direction_output(GPIO_PTE4
, 1);
547 gpio_request(GPIO_PTF4
, NULL
); /* PROTECT/ */
548 gpio_direction_output(GPIO_PTF4
, 1);
549 gpio_request(GPIO_PTU0
, NULL
); /* LEDSTDBY/ */
550 gpio_direction_output(GPIO_PTU0
, 1);
552 /* setup USB function */
553 if (kfr2r09_usb0_gadget_setup() == 0)
554 platform_device_register(&kfr2r09_usb0_gadget_device
);
557 gpio_request(GPIO_FN_VIO_CKO
, NULL
);
558 gpio_request(GPIO_FN_VIO0_CLK
, NULL
);
559 gpio_request(GPIO_FN_VIO0_VD
, NULL
);
560 gpio_request(GPIO_FN_VIO0_HD
, NULL
);
561 gpio_request(GPIO_FN_VIO0_FLD
, NULL
);
562 gpio_request(GPIO_FN_VIO0_D7
, NULL
);
563 gpio_request(GPIO_FN_VIO0_D6
, NULL
);
564 gpio_request(GPIO_FN_VIO0_D5
, NULL
);
565 gpio_request(GPIO_FN_VIO0_D4
, NULL
);
566 gpio_request(GPIO_FN_VIO0_D3
, NULL
);
567 gpio_request(GPIO_FN_VIO0_D2
, NULL
);
568 gpio_request(GPIO_FN_VIO0_D1
, NULL
);
569 gpio_request(GPIO_FN_VIO0_D0
, NULL
);
571 /* SDHI0 connected to yc304 */
572 gpio_request(GPIO_FN_SDHI0CD
, NULL
);
573 gpio_request(GPIO_FN_SDHI0D3
, NULL
);
574 gpio_request(GPIO_FN_SDHI0D2
, NULL
);
575 gpio_request(GPIO_FN_SDHI0D1
, NULL
);
576 gpio_request(GPIO_FN_SDHI0D0
, NULL
);
577 gpio_request(GPIO_FN_SDHI0CMD
, NULL
);
578 gpio_request(GPIO_FN_SDHI0CLK
, NULL
);
580 i2c_register_board_info(0, &kfr2r09_backlight_board_info
, 1);
582 /* Set camera clock frequency and register and alias for rj54n1. */
583 camera_clk
= clk_get(NULL
, "video_clk");
584 if (!IS_ERR(camera_clk
)) {
585 clk_set_rate(camera_clk
,
586 clk_round_rate(camera_clk
, CEU_MCLK_FREQ
));
589 clk_add_alias(NULL
, "1-0050", "video_clk", NULL
);
593 * use 1.8 V for VccQ_VIO
594 * use 2.85V for VccQ_SR
596 __raw_writew((__raw_readw(DRVCRB
) & ~0x0003) | 0x0001, DRVCRB
);
598 gpiod_add_lookup_table(&rj54n1_gpios
);
600 i2c_register_board_info(1, &kfr2r09_i2c_camera
, 1);
602 /* Initialize CEU platform device separately to map memory first */
603 device_initialize(&kfr2r09_ceu_device
.dev
);
604 dma_declare_coherent_memory(&kfr2r09_ceu_device
.dev
,
605 ceu_dma_membase
, ceu_dma_membase
,
606 CEU_BUFFER_MEMORY_SIZE
);
608 platform_device_add(&kfr2r09_ceu_device
);
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
;
626 /* Reserve a portion of memory for CEU buffers */
627 static void __init
kfr2r09_mv_mem_reserve(void)
630 phys_addr_t size
= CEU_BUFFER_MEMORY_SIZE
;
632 phys
= memblock_phys_alloc(size
, PAGE_SIZE
);
634 panic("Failed to allocate CEU memory\n");
636 memblock_phys_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
,