1 // SPDX-License-Identifier: GPL-2.0
4 * (Compatible with Algo System ., LTD. - AP-320A)
6 * Copyright (C) 2008 Renesas Solutions Corp.
7 * Author : Yusuke Goda <goda.yuske@renesas.com>
10 #include <asm/clock.h>
12 #include <asm/suspend.h>
14 #include <cpu/sh7723.h>
16 #include <linux/clkdev.h>
17 #include <linux/delay.h>
18 #include <linux/device.h>
19 #include <linux/gpio.h>
20 #include <linux/gpio/machine.h>
21 #include <linux/i2c.h>
22 #include <linux/init.h>
23 #include <linux/interrupt.h>
24 #include <linux/memblock.h>
25 #include <linux/mfd/tmio.h>
26 #include <linux/mmc/host.h>
27 #include <linux/mtd/physmap.h>
28 #include <linux/mtd/sh_flctl.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/smsc911x.h>
34 #include <linux/videodev2.h>
36 #include <media/drv-intf/renesas-ceu.h>
37 #include <media/i2c/ov772x.h>
39 #include <video/sh_mobile_lcdc.h>
41 #define CEU_BUFFER_MEMORY_SIZE (4 << 20)
42 static phys_addr_t ceu_dma_membase
;
44 /* Dummy supplies, where voltage doesn't matter */
45 static struct regulator_consumer_supply dummy_supplies
[] = {
46 REGULATOR_SUPPLY("vddvario", "smsc911x"),
47 REGULATOR_SUPPLY("vdd33a", "smsc911x"),
50 static struct smsc911x_platform_config smsc911x_config
= {
51 .phy_interface
= PHY_INTERFACE_MODE_MII
,
52 .irq_polarity
= SMSC911X_IRQ_POLARITY_ACTIVE_LOW
,
53 .irq_type
= SMSC911X_IRQ_TYPE_OPEN_DRAIN
,
54 .flags
= SMSC911X_USE_32BIT
,
57 static struct resource smsc9118_resources
[] = {
61 .flags
= IORESOURCE_MEM
,
64 .start
= evt2irq(0x660),
65 .end
= evt2irq(0x660),
66 .flags
= IORESOURCE_IRQ
,
70 static struct platform_device smsc9118_device
= {
73 .num_resources
= ARRAY_SIZE(smsc9118_resources
),
74 .resource
= smsc9118_resources
,
76 .platform_data
= &smsc911x_config
,
81 * AP320 and AP325RXA has CPLD data in NOR Flash(0xA80000-0xABFFFF).
82 * If this area erased, this board can not boot.
84 static struct mtd_partition ap325rxa_nor_flash_partitions
[] = {
88 .size
= (1 * 1024 * 1024),
89 .mask_flags
= MTD_WRITEABLE
, /* Read-only */
92 .offset
= MTDPART_OFS_APPEND
,
93 .size
= (2 * 1024 * 1024),
96 .offset
= MTDPART_OFS_APPEND
,
97 .size
= ((7 * 1024 * 1024) + (512 * 1024)),
100 .offset
= MTDPART_OFS_APPEND
,
101 .mask_flags
= MTD_WRITEABLE
, /* Read-only */
102 .size
= (1024 * 128 * 2),
104 .name
= "free-area1",
105 .offset
= MTDPART_OFS_APPEND
,
106 .size
= MTDPART_SIZ_FULL
,
110 static struct physmap_flash_data ap325rxa_nor_flash_data
= {
112 .parts
= ap325rxa_nor_flash_partitions
,
113 .nr_parts
= ARRAY_SIZE(ap325rxa_nor_flash_partitions
),
116 static struct resource ap325rxa_nor_flash_resources
[] = {
121 .flags
= IORESOURCE_MEM
,
125 static struct platform_device ap325rxa_nor_flash_device
= {
126 .name
= "physmap-flash",
127 .resource
= ap325rxa_nor_flash_resources
,
128 .num_resources
= ARRAY_SIZE(ap325rxa_nor_flash_resources
),
130 .platform_data
= &ap325rxa_nor_flash_data
,
134 static struct mtd_partition nand_partition_info
[] = {
138 .size
= MTDPART_SIZ_FULL
,
142 static struct resource nand_flash_resources
[] = {
146 .flags
= IORESOURCE_MEM
,
150 static struct sh_flctl_platform_data nand_flash_data
= {
151 .parts
= nand_partition_info
,
152 .nr_parts
= ARRAY_SIZE(nand_partition_info
),
153 .flcmncr_val
= FCKSEL_E
| TYPESEL_SET
| NANWF_E
,
157 static struct platform_device nand_flash_device
= {
159 .resource
= nand_flash_resources
,
160 .num_resources
= ARRAY_SIZE(nand_flash_resources
),
162 .platform_data
= &nand_flash_data
,
166 #define FPGA_LCDREG 0xB4100180
167 #define FPGA_BKLREG 0xB4100212
168 #define FPGA_LCDREG_VAL 0x0018
169 #define PORT_MSELCRB 0xA4050182
170 #define PORT_HIZCRC 0xA405015C
171 #define PORT_DRVCRA 0xA405018A
172 #define PORT_DRVCRB 0xA405018C
174 static int ap320_wvga_set_brightness(int brightness
)
177 gpio_set_value(GPIO_PTS3
, 0);
178 __raw_writew(0x100, FPGA_BKLREG
);
180 __raw_writew(0, FPGA_BKLREG
);
181 gpio_set_value(GPIO_PTS3
, 1);
187 static void ap320_wvga_power_on(void)
191 /* ASD AP-320/325 LCD ON */
192 __raw_writew(FPGA_LCDREG_VAL
, FPGA_LCDREG
);
195 static void ap320_wvga_power_off(void)
197 /* ASD AP-320/325 LCD OFF */
198 __raw_writew(0, FPGA_LCDREG
);
201 static const struct fb_videomode ap325rxa_lcdc_modes
[] = {
212 .sync
= 0, /* hsync and vsync are active low */
216 static struct sh_mobile_lcdc_info lcdc_info
= {
217 .clock_source
= LCDC_CLK_EXTERNAL
,
219 .chan
= LCDC_CHAN_MAINLCD
,
220 .fourcc
= V4L2_PIX_FMT_RGB565
,
221 .interface_type
= RGB18
,
223 .lcd_modes
= ap325rxa_lcdc_modes
,
224 .num_modes
= ARRAY_SIZE(ap325rxa_lcdc_modes
),
226 .width
= 152, /* 7.0 inch */
228 .display_on
= ap320_wvga_power_on
,
229 .display_off
= ap320_wvga_power_off
,
232 .name
= "sh_mobile_lcdc_bl",
234 .set_brightness
= ap320_wvga_set_brightness
,
239 static struct resource lcdc_resources
[] = {
242 .start
= 0xfe940000, /* P4-only space */
244 .flags
= IORESOURCE_MEM
,
247 .start
= evt2irq(0x580),
248 .flags
= IORESOURCE_IRQ
,
252 static struct platform_device lcdc_device
= {
253 .name
= "sh_mobile_lcdc_fb",
254 .num_resources
= ARRAY_SIZE(lcdc_resources
),
255 .resource
= lcdc_resources
,
257 .platform_data
= &lcdc_info
,
261 /* Powerdown/reset gpios for CEU image sensors */
262 static struct gpiod_lookup_table ov7725_gpios
= {
265 GPIO_LOOKUP("sh7723_pfc", GPIO_PTZ5
, "reset", GPIO_ACTIVE_LOW
),
269 static struct ceu_platform_data ceu0_pdata
= {
282 static struct resource ceu_resources
[] = {
287 .flags
= IORESOURCE_MEM
,
290 .start
= evt2irq(0x880),
291 .flags
= IORESOURCE_IRQ
,
295 static struct platform_device ap325rxa_ceu_device
= {
296 .name
= "renesas-ceu",
297 .id
= 0, /* "ceu.0" clock */
298 .num_resources
= ARRAY_SIZE(ceu_resources
),
299 .resource
= ceu_resources
,
301 .platform_data
= &ceu0_pdata
,
305 /* Fixed 3.3V regulators to be used by SDHI0, SDHI1 */
306 static struct regulator_consumer_supply fixed3v3_power_consumers
[] =
308 REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.0"),
309 REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.0"),
310 REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.1"),
311 REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.1"),
314 static struct resource sdhi0_cn3_resources
[] = {
319 .flags
= IORESOURCE_MEM
,
322 .start
= evt2irq(0xe80),
323 .flags
= IORESOURCE_IRQ
,
327 static struct tmio_mmc_data sdhi0_cn3_data
= {
328 .capabilities
= MMC_CAP_SDIO_IRQ
,
331 static struct platform_device sdhi0_cn3_device
= {
332 .name
= "sh_mobile_sdhi",
333 .id
= 0, /* "sdhi0" clock */
334 .num_resources
= ARRAY_SIZE(sdhi0_cn3_resources
),
335 .resource
= sdhi0_cn3_resources
,
337 .platform_data
= &sdhi0_cn3_data
,
341 static struct resource sdhi1_cn7_resources
[] = {
346 .flags
= IORESOURCE_MEM
,
349 .start
= evt2irq(0x4e0),
350 .flags
= IORESOURCE_IRQ
,
354 static struct tmio_mmc_data sdhi1_cn7_data
= {
355 .capabilities
= MMC_CAP_SDIO_IRQ
,
358 static struct platform_device sdhi1_cn7_device
= {
359 .name
= "sh_mobile_sdhi",
360 .id
= 1, /* "sdhi1" clock */
361 .num_resources
= ARRAY_SIZE(sdhi1_cn7_resources
),
362 .resource
= sdhi1_cn7_resources
,
364 .platform_data
= &sdhi1_cn7_data
,
368 static struct ov772x_camera_info ov7725_info
= {
369 .flags
= OV772X_FLAG_VFLIP
| OV772X_FLAG_HFLIP
,
370 .edgectrl
= OV772X_AUTO_EDGECTRL(0xf, 0),
373 static struct i2c_board_info ap325rxa_i2c_devices
[] __initdata
= {
375 I2C_BOARD_INFO("pcf8563", 0x51),
378 I2C_BOARD_INFO("ov772x", 0x21),
379 .platform_data
= &ov7725_info
,
383 static struct platform_device
*ap325rxa_devices
[] __initdata
= {
385 &ap325rxa_nor_flash_device
,
392 extern char ap325rxa_sdram_enter_start
;
393 extern char ap325rxa_sdram_enter_end
;
394 extern char ap325rxa_sdram_leave_start
;
395 extern char ap325rxa_sdram_leave_end
;
397 static int __init
ap325rxa_devices_setup(void)
399 /* register board specific self-refresh code */
400 sh_mobile_register_self_refresh(SUSP_SH_STANDBY
| SUSP_SH_SF
,
401 &ap325rxa_sdram_enter_start
,
402 &ap325rxa_sdram_enter_end
,
403 &ap325rxa_sdram_leave_start
,
404 &ap325rxa_sdram_leave_end
);
406 regulator_register_always_on(0, "fixed-3.3V", fixed3v3_power_consumers
,
407 ARRAY_SIZE(fixed3v3_power_consumers
), 3300000);
408 regulator_register_fixed(1, dummy_supplies
, ARRAY_SIZE(dummy_supplies
));
410 /* LD3 and LD4 LEDs */
411 gpio_request(GPIO_PTX5
, NULL
); /* RUN */
412 gpio_direction_output(GPIO_PTX5
, 1);
413 gpio_export(GPIO_PTX5
, 0);
415 gpio_request(GPIO_PTX4
, NULL
); /* INDICATOR */
416 gpio_direction_output(GPIO_PTX4
, 0);
417 gpio_export(GPIO_PTX4
, 0);
420 gpio_request(GPIO_PTF7
, NULL
); /* MODE */
421 gpio_direction_input(GPIO_PTF7
);
422 gpio_export(GPIO_PTF7
, 0);
425 gpio_request(GPIO_FN_LCDD15
, NULL
);
426 gpio_request(GPIO_FN_LCDD14
, NULL
);
427 gpio_request(GPIO_FN_LCDD13
, NULL
);
428 gpio_request(GPIO_FN_LCDD12
, NULL
);
429 gpio_request(GPIO_FN_LCDD11
, NULL
);
430 gpio_request(GPIO_FN_LCDD10
, NULL
);
431 gpio_request(GPIO_FN_LCDD9
, NULL
);
432 gpio_request(GPIO_FN_LCDD8
, NULL
);
433 gpio_request(GPIO_FN_LCDD7
, NULL
);
434 gpio_request(GPIO_FN_LCDD6
, NULL
);
435 gpio_request(GPIO_FN_LCDD5
, NULL
);
436 gpio_request(GPIO_FN_LCDD4
, NULL
);
437 gpio_request(GPIO_FN_LCDD3
, NULL
);
438 gpio_request(GPIO_FN_LCDD2
, NULL
);
439 gpio_request(GPIO_FN_LCDD1
, NULL
);
440 gpio_request(GPIO_FN_LCDD0
, NULL
);
441 gpio_request(GPIO_FN_LCDLCLK_PTR
, NULL
);
442 gpio_request(GPIO_FN_LCDDCK
, NULL
);
443 gpio_request(GPIO_FN_LCDVEPWC
, NULL
);
444 gpio_request(GPIO_FN_LCDVCPWC
, NULL
);
445 gpio_request(GPIO_FN_LCDVSYN
, NULL
);
446 gpio_request(GPIO_FN_LCDHSYN
, NULL
);
447 gpio_request(GPIO_FN_LCDDISP
, NULL
);
448 gpio_request(GPIO_FN_LCDDON
, NULL
);
451 gpio_request(GPIO_PTS3
, NULL
);
452 gpio_direction_output(GPIO_PTS3
, 1);
455 gpio_request(GPIO_FN_VIO_CLK2
, NULL
);
456 gpio_request(GPIO_FN_VIO_VD2
, NULL
);
457 gpio_request(GPIO_FN_VIO_HD2
, NULL
);
458 gpio_request(GPIO_FN_VIO_FLD
, NULL
);
459 gpio_request(GPIO_FN_VIO_CKO
, NULL
);
460 gpio_request(GPIO_FN_VIO_D15
, NULL
);
461 gpio_request(GPIO_FN_VIO_D14
, NULL
);
462 gpio_request(GPIO_FN_VIO_D13
, NULL
);
463 gpio_request(GPIO_FN_VIO_D12
, NULL
);
464 gpio_request(GPIO_FN_VIO_D11
, NULL
);
465 gpio_request(GPIO_FN_VIO_D10
, NULL
);
466 gpio_request(GPIO_FN_VIO_D9
, NULL
);
467 gpio_request(GPIO_FN_VIO_D8
, NULL
);
469 gpio_request(GPIO_PTZ7
, NULL
);
470 gpio_direction_output(GPIO_PTZ7
, 0); /* OE_CAM */
471 gpio_request(GPIO_PTZ6
, NULL
);
472 gpio_direction_output(GPIO_PTZ6
, 0); /* STBY_CAM */
473 gpio_request(GPIO_PTZ5
, NULL
);
474 gpio_direction_output(GPIO_PTZ5
, 0); /* RST_CAM */
475 gpio_request(GPIO_PTZ4
, NULL
);
476 gpio_direction_output(GPIO_PTZ4
, 0); /* SADDR */
478 __raw_writew(__raw_readw(PORT_MSELCRB
) & ~0x0001, PORT_MSELCRB
);
481 gpio_request(GPIO_FN_FCE
, NULL
);
482 gpio_request(GPIO_FN_NAF7
, NULL
);
483 gpio_request(GPIO_FN_NAF6
, NULL
);
484 gpio_request(GPIO_FN_NAF5
, NULL
);
485 gpio_request(GPIO_FN_NAF4
, NULL
);
486 gpio_request(GPIO_FN_NAF3
, NULL
);
487 gpio_request(GPIO_FN_NAF2
, NULL
);
488 gpio_request(GPIO_FN_NAF1
, NULL
);
489 gpio_request(GPIO_FN_NAF0
, NULL
);
490 gpio_request(GPIO_FN_FCDE
, NULL
);
491 gpio_request(GPIO_FN_FOE
, NULL
);
492 gpio_request(GPIO_FN_FSC
, NULL
);
493 gpio_request(GPIO_FN_FWE
, NULL
);
494 gpio_request(GPIO_FN_FRB
, NULL
);
496 __raw_writew(0, PORT_HIZCRC
);
497 __raw_writew(0xFFFF, PORT_DRVCRA
);
498 __raw_writew(0xFFFF, PORT_DRVCRB
);
500 /* SDHI0 - CN3 - SD CARD */
501 gpio_request(GPIO_FN_SDHI0CD_PTD
, NULL
);
502 gpio_request(GPIO_FN_SDHI0WP_PTD
, NULL
);
503 gpio_request(GPIO_FN_SDHI0D3_PTD
, NULL
);
504 gpio_request(GPIO_FN_SDHI0D2_PTD
, NULL
);
505 gpio_request(GPIO_FN_SDHI0D1_PTD
, NULL
);
506 gpio_request(GPIO_FN_SDHI0D0_PTD
, NULL
);
507 gpio_request(GPIO_FN_SDHI0CMD_PTD
, NULL
);
508 gpio_request(GPIO_FN_SDHI0CLK_PTD
, NULL
);
510 /* SDHI1 - CN7 - MICRO SD CARD */
511 gpio_request(GPIO_FN_SDHI1CD
, NULL
);
512 gpio_request(GPIO_FN_SDHI1D3
, NULL
);
513 gpio_request(GPIO_FN_SDHI1D2
, NULL
);
514 gpio_request(GPIO_FN_SDHI1D1
, NULL
);
515 gpio_request(GPIO_FN_SDHI1D0
, NULL
);
516 gpio_request(GPIO_FN_SDHI1CMD
, NULL
);
517 gpio_request(GPIO_FN_SDHI1CLK
, NULL
);
519 /* Add a clock alias for ov7725 xclk source. */
520 clk_add_alias(NULL
, "0-0021", "video_clk", NULL
);
522 /* Register RSTB gpio for ov7725 camera sensor. */
523 gpiod_add_lookup_table(&ov7725_gpios
);
525 i2c_register_board_info(0, ap325rxa_i2c_devices
,
526 ARRAY_SIZE(ap325rxa_i2c_devices
));
528 /* Initialize CEU platform device separately to map memory first */
529 device_initialize(&ap325rxa_ceu_device
.dev
);
530 arch_setup_pdev_archdata(&ap325rxa_ceu_device
);
531 dma_declare_coherent_memory(&ap325rxa_ceu_device
.dev
,
532 ceu_dma_membase
, ceu_dma_membase
,
533 ceu_dma_membase
+ CEU_BUFFER_MEMORY_SIZE
- 1,
534 DMA_MEMORY_EXCLUSIVE
);
536 platform_device_add(&ap325rxa_ceu_device
);
538 return platform_add_devices(ap325rxa_devices
,
539 ARRAY_SIZE(ap325rxa_devices
));
541 arch_initcall(ap325rxa_devices_setup
);
543 /* Return the board specific boot mode pin configuration */
544 static int ap325rxa_mode_pins(void)
546 /* MD0=0, MD1=0, MD2=0: Clock Mode 0
547 * MD3=0: 16-bit Area0 Bus Width
548 * MD5=1: Little Endian
549 * TSTMD=1, MD8=1: Test Mode Disabled
551 return MODE_PIN5
| MODE_PIN8
;
554 /* Reserve a portion of memory for CEU buffers */
555 static void __init
ap325rxa_mv_mem_reserve(void)
558 phys_addr_t size
= CEU_BUFFER_MEMORY_SIZE
;
560 phys
= memblock_alloc_base(size
, PAGE_SIZE
, MEMBLOCK_ALLOC_ANYWHERE
);
561 memblock_free(phys
, size
);
562 memblock_remove(phys
, size
);
564 ceu_dma_membase
= phys
;
567 static struct sh_machine_vector mv_ap325rxa __initmv
= {
568 .mv_name
= "AP-325RXA",
569 .mv_mode_pins
= ap325rxa_mode_pins
,
570 .mv_mem_reserve
= ap325rxa_mv_mem_reserve
,