1 // SPDX-License-Identifier: GPL-2.0
3 * Renesas System Solutions Asia Pte. Ltd - Migo-R
5 * Copyright (C) 2008 Magnus Damm
7 #include <linux/clkdev.h>
8 #include <linux/init.h>
9 #include <linux/platform_device.h>
10 #include <linux/interrupt.h>
11 #include <linux/input.h>
12 #include <linux/input/sh_keysc.h>
13 #include <linux/memblock.h>
14 #include <linux/mmc/host.h>
15 #include <linux/mtd/physmap.h>
16 #include <linux/mfd/tmio.h>
17 #include <linux/mtd/rawnand.h>
18 #include <linux/i2c.h>
19 #include <linux/regulator/fixed.h>
20 #include <linux/regulator/machine.h>
21 #include <linux/smc91x.h>
22 #include <linux/delay.h>
23 #include <linux/clk.h>
24 #include <linux/gpio.h>
25 #include <linux/gpio/machine.h>
26 #include <linux/videodev2.h>
27 #include <linux/sh_intc.h>
28 #include <video/sh_mobile_lcdc.h>
29 #include <media/drv-intf/renesas-ceu.h>
30 #include <media/i2c/ov772x.h>
31 #include <media/soc_camera.h>
32 #include <media/i2c/tw9910.h>
33 #include <asm/clock.h>
34 #include <asm/machvec.h>
36 #include <asm/suspend.h>
37 #include <mach/migor.h>
38 #include <cpu/sh7722.h>
40 /* Address IRQ Size Bus Description
41 * 0x00000000 64MB 16 NOR Flash (SP29PL256N)
42 * 0x0c000000 64MB 64 SDRAM (2xK4M563233G)
43 * 0x10000000 IRQ0 16 Ethernet (SMC91C111)
44 * 0x14000000 IRQ4 16 USB 2.0 Host Controller (M66596)
45 * 0x18000000 8GB 8 NAND Flash (K9K8G08U0A)
48 #define CEU_BUFFER_MEMORY_SIZE (4 << 20)
49 static phys_addr_t ceu_dma_membase
;
51 static struct smc91x_platdata smc91x_info
= {
52 .flags
= SMC91X_USE_16BIT
| SMC91X_NOWAIT
,
55 static struct resource smc91x_eth_resources
[] = {
60 .flags
= IORESOURCE_MEM
,
63 .start
= evt2irq(0x600), /* IRQ0 */
64 .flags
= IORESOURCE_IRQ
| IORESOURCE_IRQ_HIGHLEVEL
,
68 static struct platform_device smc91x_eth_device
= {
70 .num_resources
= ARRAY_SIZE(smc91x_eth_resources
),
71 .resource
= smc91x_eth_resources
,
73 .platform_data
= &smc91x_info
,
77 static struct sh_keysc_info sh_keysc_info
= {
78 .mode
= SH_KEYSC_MODE_2
, /* KEYOUT0->4, KEYIN1->5 */
82 0, KEY_UP
, KEY_DOWN
, KEY_LEFT
, KEY_RIGHT
, KEY_ENTER
,
83 0, KEY_F
, KEY_C
, KEY_D
, KEY_H
, KEY_1
,
84 0, KEY_2
, KEY_3
, KEY_4
, KEY_5
, KEY_6
,
85 0, KEY_7
, KEY_8
, KEY_9
, KEY_S
, KEY_0
,
86 0, KEY_P
, KEY_STOP
, KEY_REWIND
, KEY_PLAY
, KEY_FASTFORWARD
,
90 static struct resource sh_keysc_resources
[] = {
94 .flags
= IORESOURCE_MEM
,
97 .start
= evt2irq(0xbe0),
98 .flags
= IORESOURCE_IRQ
,
102 static struct platform_device sh_keysc_device
= {
104 .id
= 0, /* "keysc0" clock */
105 .num_resources
= ARRAY_SIZE(sh_keysc_resources
),
106 .resource
= sh_keysc_resources
,
108 .platform_data
= &sh_keysc_info
,
112 static struct mtd_partition migor_nor_flash_partitions
[] =
117 .size
= (1 * 1024 * 1024),
118 .mask_flags
= MTD_WRITEABLE
, /* Read-only */
122 .offset
= MTDPART_OFS_APPEND
,
123 .size
= (15 * 1024 * 1024),
127 .offset
= MTDPART_OFS_APPEND
,
128 .size
= MTDPART_SIZ_FULL
,
132 static struct physmap_flash_data migor_nor_flash_data
= {
134 .parts
= migor_nor_flash_partitions
,
135 .nr_parts
= ARRAY_SIZE(migor_nor_flash_partitions
),
138 static struct resource migor_nor_flash_resources
[] = {
143 .flags
= IORESOURCE_MEM
,
147 static struct platform_device migor_nor_flash_device
= {
148 .name
= "physmap-flash",
149 .resource
= migor_nor_flash_resources
,
150 .num_resources
= ARRAY_SIZE(migor_nor_flash_resources
),
152 .platform_data
= &migor_nor_flash_data
,
156 static struct mtd_partition migor_nand_flash_partitions
[] = {
160 .size
= 512 * 1024 * 1024,
164 .offset
= MTDPART_OFS_APPEND
,
165 .size
= 512 * 1024 * 1024,
169 static void migor_nand_flash_cmd_ctl(struct mtd_info
*mtd
, int cmd
,
172 struct nand_chip
*chip
= mtd_to_nand(mtd
);
174 if (cmd
== NAND_CMD_NONE
)
178 writeb(cmd
, chip
->IO_ADDR_W
+ 0x00400000);
179 else if (ctrl
& NAND_ALE
)
180 writeb(cmd
, chip
->IO_ADDR_W
+ 0x00800000);
182 writeb(cmd
, chip
->IO_ADDR_W
);
185 static int migor_nand_flash_ready(struct mtd_info
*mtd
)
187 return gpio_get_value(GPIO_PTA1
); /* NAND_RBn */
190 static struct platform_nand_data migor_nand_flash_data
= {
193 .partitions
= migor_nand_flash_partitions
,
194 .nr_partitions
= ARRAY_SIZE(migor_nand_flash_partitions
),
198 .dev_ready
= migor_nand_flash_ready
,
199 .cmd_ctrl
= migor_nand_flash_cmd_ctl
,
203 static struct resource migor_nand_flash_resources
[] = {
205 .name
= "NAND Flash",
208 .flags
= IORESOURCE_MEM
,
212 static struct platform_device migor_nand_flash_device
= {
214 .resource
= migor_nand_flash_resources
,
215 .num_resources
= ARRAY_SIZE(migor_nand_flash_resources
),
217 .platform_data
= &migor_nand_flash_data
,
221 static const struct fb_videomode migor_lcd_modes
[] = {
223 #if defined(CONFIG_SH_MIGOR_RTA_WVGA)
231 #elif defined(CONFIG_SH_MIGOR_QVGA)
238 .sync
= FB_SYNC_HOR_HIGH_ACT
,
246 static struct sh_mobile_lcdc_info sh_mobile_lcdc_info
= {
247 #if defined(CONFIG_SH_MIGOR_RTA_WVGA)
248 .clock_source
= LCDC_CLK_BUS
,
250 .chan
= LCDC_CHAN_MAINLCD
,
251 .fourcc
= V4L2_PIX_FMT_RGB565
,
252 .interface_type
= RGB16
,
254 .lcd_modes
= migor_lcd_modes
,
255 .num_modes
= ARRAY_SIZE(migor_lcd_modes
),
256 .panel_cfg
= { /* 7.0 inch */
261 #elif defined(CONFIG_SH_MIGOR_QVGA)
262 .clock_source
= LCDC_CLK_PERIPHERAL
,
264 .chan
= LCDC_CHAN_MAINLCD
,
265 .fourcc
= V4L2_PIX_FMT_RGB565
,
266 .interface_type
= SYS16A
,
268 .lcd_modes
= migor_lcd_modes
,
269 .num_modes
= ARRAY_SIZE(migor_lcd_modes
),
271 .width
= 49, /* 2.4 inch */
273 .setup_sys
= migor_lcd_qvga_setup
,
276 .ldmt2r
= 0x06000a09,
277 .ldmt3r
= 0x180e3418,
278 /* set 1s delay to encourage fsync() */
279 .deferred_io_msec
= 1000,
285 static struct resource migor_lcdc_resources
[] = {
288 .start
= 0xfe940000, /* P4-only space */
290 .flags
= IORESOURCE_MEM
,
293 .start
= evt2irq(0x580),
294 .flags
= IORESOURCE_IRQ
,
298 static struct platform_device migor_lcdc_device
= {
299 .name
= "sh_mobile_lcdc_fb",
300 .num_resources
= ARRAY_SIZE(migor_lcdc_resources
),
301 .resource
= migor_lcdc_resources
,
303 .platform_data
= &sh_mobile_lcdc_info
,
307 static struct ceu_platform_data ceu_pdata
= {
327 static struct resource migor_ceu_resources
[] = {
332 .flags
= IORESOURCE_MEM
,
335 .start
= evt2irq(0x880),
336 .flags
= IORESOURCE_IRQ
,
340 static struct platform_device migor_ceu_device
= {
341 .name
= "renesas-ceu",
343 .num_resources
= ARRAY_SIZE(migor_ceu_resources
),
344 .resource
= migor_ceu_resources
,
346 .platform_data
= &ceu_pdata
,
350 /* Powerdown/reset gpios for CEU image sensors */
351 static struct gpiod_lookup_table ov7725_gpios
= {
354 GPIO_LOOKUP("sh7722_pfc", GPIO_PTT0
, "pwdn", GPIO_ACTIVE_HIGH
),
355 GPIO_LOOKUP("sh7722_pfc", GPIO_PTT3
, "rstb", GPIO_ACTIVE_LOW
),
359 static struct gpiod_lookup_table tw9910_gpios
= {
362 GPIO_LOOKUP("sh7722_pfc", GPIO_PTT2
, "pdn", GPIO_ACTIVE_LOW
),
363 GPIO_LOOKUP("sh7722_pfc", GPIO_PTT3
, "rstb", GPIO_ACTIVE_LOW
),
367 /* Fixed 3.3V regulator to be used by SDHI0 */
368 static struct regulator_consumer_supply fixed3v3_power_consumers
[] =
370 REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.0"),
371 REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.0"),
374 static struct resource sdhi_cn9_resources
[] = {
379 .flags
= IORESOURCE_MEM
,
382 .start
= evt2irq(0xe80),
383 .flags
= IORESOURCE_IRQ
,
387 static struct tmio_mmc_data sh7724_sdhi_data
= {
388 .chan_priv_tx
= (void *)SHDMA_SLAVE_SDHI0_TX
,
389 .chan_priv_rx
= (void *)SHDMA_SLAVE_SDHI0_RX
,
390 .capabilities
= MMC_CAP_SDIO_IRQ
,
393 static struct platform_device sdhi_cn9_device
= {
394 .name
= "sh_mobile_sdhi",
395 .num_resources
= ARRAY_SIZE(sdhi_cn9_resources
),
396 .resource
= sdhi_cn9_resources
,
398 .platform_data
= &sh7724_sdhi_data
,
402 static struct ov772x_camera_info ov7725_info
= {
406 static struct tw9910_video_info tw9910_info
= {
408 .mpout
= TW9910_MPO_FIELD
,
411 static struct i2c_board_info migor_i2c_devices
[] = {
413 I2C_BOARD_INFO("rs5c372b", 0x32),
416 I2C_BOARD_INFO("migor_ts", 0x51),
417 .irq
= evt2irq(0x6c0), /* IRQ6 */
420 I2C_BOARD_INFO("wm8978", 0x1a),
423 I2C_BOARD_INFO("ov772x", 0x21),
424 .platform_data
= &ov7725_info
,
427 I2C_BOARD_INFO("tw9910", 0x45),
428 .platform_data
= &tw9910_info
,
432 static struct platform_device
*migor_devices
[] __initdata
= {
436 &migor_nor_flash_device
,
437 &migor_nand_flash_device
,
441 extern char migor_sdram_enter_start
;
442 extern char migor_sdram_enter_end
;
443 extern char migor_sdram_leave_start
;
444 extern char migor_sdram_leave_end
;
446 static int __init
migor_devices_setup(void)
448 struct clk
*video_clk
;
450 /* register board specific self-refresh code */
451 sh_mobile_register_self_refresh(SUSP_SH_STANDBY
| SUSP_SH_SF
,
452 &migor_sdram_enter_start
,
453 &migor_sdram_enter_end
,
454 &migor_sdram_leave_start
,
455 &migor_sdram_leave_end
);
457 regulator_register_always_on(0, "fixed-3.3V", fixed3v3_power_consumers
,
458 ARRAY_SIZE(fixed3v3_power_consumers
), 3300000);
460 /* Let D11 LED show STATUS0 */
461 gpio_request(GPIO_FN_STATUS0
, NULL
);
463 /* Lit D12 LED show PDSTATUS */
464 gpio_request(GPIO_FN_PDSTATUS
, NULL
);
466 /* SMC91C111 - Enable IRQ0, Setup CS4 for 16-bit fast access */
467 gpio_request(GPIO_FN_IRQ0
, NULL
);
468 __raw_writel(0x00003400, BSC_CS4BCR
);
469 __raw_writel(0x00110080, BSC_CS4WCR
);
472 gpio_request(GPIO_FN_KEYOUT0
, NULL
);
473 gpio_request(GPIO_FN_KEYOUT1
, NULL
);
474 gpio_request(GPIO_FN_KEYOUT2
, NULL
);
475 gpio_request(GPIO_FN_KEYOUT3
, NULL
);
476 gpio_request(GPIO_FN_KEYOUT4_IN6
, NULL
);
477 gpio_request(GPIO_FN_KEYIN1
, NULL
);
478 gpio_request(GPIO_FN_KEYIN2
, NULL
);
479 gpio_request(GPIO_FN_KEYIN3
, NULL
);
480 gpio_request(GPIO_FN_KEYIN4
, NULL
);
481 gpio_request(GPIO_FN_KEYOUT5_IN5
, NULL
);
484 gpio_request(GPIO_FN_CS6A_CE2B
, NULL
);
485 __raw_writel((__raw_readl(BSC_CS6ABCR
) & ~0x0600) | 0x0200, BSC_CS6ABCR
);
486 gpio_request(GPIO_PTA1
, NULL
);
487 gpio_direction_input(GPIO_PTA1
);
490 gpio_request(GPIO_FN_SDHICD
, NULL
);
491 gpio_request(GPIO_FN_SDHIWP
, NULL
);
492 gpio_request(GPIO_FN_SDHID3
, NULL
);
493 gpio_request(GPIO_FN_SDHID2
, NULL
);
494 gpio_request(GPIO_FN_SDHID1
, NULL
);
495 gpio_request(GPIO_FN_SDHID0
, NULL
);
496 gpio_request(GPIO_FN_SDHICMD
, NULL
);
497 gpio_request(GPIO_FN_SDHICLK
, NULL
);
500 gpio_request(GPIO_FN_IRQ6
, NULL
);
503 #ifdef CONFIG_SH_MIGOR_QVGA /* LCDC - QVGA - Enable SYS Interface signals */
504 gpio_request(GPIO_FN_LCDD17
, NULL
);
505 gpio_request(GPIO_FN_LCDD16
, NULL
);
506 gpio_request(GPIO_FN_LCDD15
, NULL
);
507 gpio_request(GPIO_FN_LCDD14
, NULL
);
508 gpio_request(GPIO_FN_LCDD13
, NULL
);
509 gpio_request(GPIO_FN_LCDD12
, NULL
);
510 gpio_request(GPIO_FN_LCDD11
, NULL
);
511 gpio_request(GPIO_FN_LCDD10
, NULL
);
512 gpio_request(GPIO_FN_LCDD8
, NULL
);
513 gpio_request(GPIO_FN_LCDD7
, NULL
);
514 gpio_request(GPIO_FN_LCDD6
, NULL
);
515 gpio_request(GPIO_FN_LCDD5
, NULL
);
516 gpio_request(GPIO_FN_LCDD4
, NULL
);
517 gpio_request(GPIO_FN_LCDD3
, NULL
);
518 gpio_request(GPIO_FN_LCDD2
, NULL
);
519 gpio_request(GPIO_FN_LCDD1
, NULL
);
520 gpio_request(GPIO_FN_LCDRS
, NULL
);
521 gpio_request(GPIO_FN_LCDCS
, NULL
);
522 gpio_request(GPIO_FN_LCDRD
, NULL
);
523 gpio_request(GPIO_FN_LCDWR
, NULL
);
524 gpio_request(GPIO_PTH2
, NULL
); /* LCD_DON */
525 gpio_direction_output(GPIO_PTH2
, 1);
527 #ifdef CONFIG_SH_MIGOR_RTA_WVGA /* LCDC - WVGA - Enable RGB Interface signals */
528 gpio_request(GPIO_FN_LCDD15
, NULL
);
529 gpio_request(GPIO_FN_LCDD14
, NULL
);
530 gpio_request(GPIO_FN_LCDD13
, NULL
);
531 gpio_request(GPIO_FN_LCDD12
, NULL
);
532 gpio_request(GPIO_FN_LCDD11
, NULL
);
533 gpio_request(GPIO_FN_LCDD10
, NULL
);
534 gpio_request(GPIO_FN_LCDD9
, NULL
);
535 gpio_request(GPIO_FN_LCDD8
, NULL
);
536 gpio_request(GPIO_FN_LCDD7
, NULL
);
537 gpio_request(GPIO_FN_LCDD6
, NULL
);
538 gpio_request(GPIO_FN_LCDD5
, NULL
);
539 gpio_request(GPIO_FN_LCDD4
, NULL
);
540 gpio_request(GPIO_FN_LCDD3
, NULL
);
541 gpio_request(GPIO_FN_LCDD2
, NULL
);
542 gpio_request(GPIO_FN_LCDD1
, NULL
);
543 gpio_request(GPIO_FN_LCDD0
, NULL
);
544 gpio_request(GPIO_FN_LCDLCLK
, NULL
);
545 gpio_request(GPIO_FN_LCDDCK
, NULL
);
546 gpio_request(GPIO_FN_LCDVEPWC
, NULL
);
547 gpio_request(GPIO_FN_LCDVCPWC
, NULL
);
548 gpio_request(GPIO_FN_LCDVSYN
, NULL
);
549 gpio_request(GPIO_FN_LCDHSYN
, NULL
);
550 gpio_request(GPIO_FN_LCDDISP
, NULL
);
551 gpio_request(GPIO_FN_LCDDON
, NULL
);
555 gpio_request(GPIO_FN_VIO_CLK2
, NULL
);
556 gpio_request(GPIO_FN_VIO_VD2
, NULL
);
557 gpio_request(GPIO_FN_VIO_HD2
, NULL
);
558 gpio_request(GPIO_FN_VIO_FLD
, NULL
);
559 gpio_request(GPIO_FN_VIO_CKO
, NULL
);
560 gpio_request(GPIO_FN_VIO_D15
, NULL
);
561 gpio_request(GPIO_FN_VIO_D14
, NULL
);
562 gpio_request(GPIO_FN_VIO_D13
, NULL
);
563 gpio_request(GPIO_FN_VIO_D12
, NULL
);
564 gpio_request(GPIO_FN_VIO_D11
, NULL
);
565 gpio_request(GPIO_FN_VIO_D10
, NULL
);
566 gpio_request(GPIO_FN_VIO_D9
, NULL
);
567 gpio_request(GPIO_FN_VIO_D8
, NULL
);
569 __raw_writew(__raw_readw(PORT_MSELCRB
) | 0x2000, PORT_MSELCRB
); /* D15->D8 */
572 gpio_request(GPIO_FN_SIUBOLR
, NULL
);
573 gpio_request(GPIO_FN_SIUBOBT
, NULL
);
574 gpio_request(GPIO_FN_SIUBISLD
, NULL
);
575 gpio_request(GPIO_FN_SIUBOSLD
, NULL
);
576 gpio_request(GPIO_FN_SIUMCKB
, NULL
);
579 * The original driver sets SIUB OLR/OBT, ILR/IBT, and SIUA OLR/OBT to
580 * output. Need only SIUB, set to output for master mode (table 34.2)
582 __raw_writew(__raw_readw(PORT_MSELCRA
) | 1, PORT_MSELCRA
);
585 * Use 10 MHz VIO_CKO instead of 24 MHz to work around signal quality
586 * issues on Panel Board V2.1.
588 video_clk
= clk_get(NULL
, "video_clk");
589 if (!IS_ERR(video_clk
)) {
590 clk_set_rate(video_clk
, clk_round_rate(video_clk
, 10000000));
594 /* Add a clock alias for ov7725 xclk source. */
595 clk_add_alias("xclk", "0-0021", "video_clk", NULL
);
597 /* Register GPIOs for video sources. */
598 gpiod_add_lookup_table(&ov7725_gpios
);
599 gpiod_add_lookup_table(&tw9910_gpios
);
601 i2c_register_board_info(0, migor_i2c_devices
,
602 ARRAY_SIZE(migor_i2c_devices
));
604 /* Initialize CEU platform device separately to map memory first */
605 device_initialize(&migor_ceu_device
.dev
);
606 arch_setup_pdev_archdata(&migor_ceu_device
);
607 dma_declare_coherent_memory(&migor_ceu_device
.dev
,
608 ceu_dma_membase
, ceu_dma_membase
,
609 ceu_dma_membase
+ CEU_BUFFER_MEMORY_SIZE
- 1,
610 DMA_MEMORY_EXCLUSIVE
);
612 platform_device_add(&migor_ceu_device
);
614 return platform_add_devices(migor_devices
, ARRAY_SIZE(migor_devices
));
616 arch_initcall(migor_devices_setup
);
618 /* Return the board specific boot mode pin configuration */
619 static int migor_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 * TSTMD=1, MD8=0: Test Mode Disabled
626 return MODE_PIN0
| MODE_PIN1
| MODE_PIN5
;
629 /* Reserve a portion of memory for CEU buffers */
630 static void __init
migor_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_migor __initmv
= {
647 .mv_mode_pins
= migor_mode_pins
,
648 .mv_mem_reserve
= migor_mv_mem_reserve
,