| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) 2009 Renesas Solutions Corp. |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Kuninori Morimoto <morimoto.kuninori@renesas.com> |
|---|
| 5 | | - * |
|---|
| 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 |
|---|
| 8 | | - * for more details. |
|---|
| 9 | 6 | */ |
|---|
| 10 | 7 | #include <asm/clock.h> |
|---|
| 11 | 8 | #include <asm/heartbeat.h> |
|---|
| .. | .. |
|---|
| 39 | 36 | #include <linux/usb/r8a66597.h> |
|---|
| 40 | 37 | #include <linux/usb/renesas_usbhs.h> |
|---|
| 41 | 38 | #include <linux/videodev2.h> |
|---|
| 39 | +#include <linux/dma-map-ops.h> |
|---|
| 42 | 40 | |
|---|
| 43 | 41 | #include <media/drv-intf/renesas-ceu.h> |
|---|
| 44 | 42 | #include <media/i2c/mt9t112.h> |
|---|
| .. | .. |
|---|
| 374 | 372 | }, |
|---|
| 375 | 373 | }; |
|---|
| 376 | 374 | |
|---|
| 377 | | -static struct gpio_backlight_platform_data gpio_backlight_data = { |
|---|
| 378 | | - .fbdev = &lcdc_device.dev, |
|---|
| 379 | | - .gpio = GPIO_PTR1, |
|---|
| 380 | | - .def_value = 1, |
|---|
| 381 | | - .name = "backlight", |
|---|
| 382 | | -}; |
|---|
| 383 | | - |
|---|
| 384 | | -static struct platform_device gpio_backlight_device = { |
|---|
| 385 | | - .name = "gpio-backlight", |
|---|
| 386 | | - .dev = { |
|---|
| 387 | | - .platform_data = &gpio_backlight_data, |
|---|
| 375 | +static struct gpiod_lookup_table gpio_backlight_lookup = { |
|---|
| 376 | + .dev_id = "gpio-backlight.0", |
|---|
| 377 | + .table = { |
|---|
| 378 | + GPIO_LOOKUP("sh7724_pfc", GPIO_PTR1, NULL, GPIO_ACTIVE_HIGH), |
|---|
| 379 | + { } |
|---|
| 388 | 380 | }, |
|---|
| 389 | 381 | }; |
|---|
| 382 | + |
|---|
| 383 | +static struct property_entry gpio_backlight_props[] = { |
|---|
| 384 | + PROPERTY_ENTRY_BOOL("default-on"), |
|---|
| 385 | + { } |
|---|
| 386 | +}; |
|---|
| 387 | + |
|---|
| 388 | +static struct gpio_backlight_platform_data gpio_backlight_data = { |
|---|
| 389 | + .fbdev = &lcdc_device.dev, |
|---|
| 390 | +}; |
|---|
| 391 | + |
|---|
| 392 | +static const struct platform_device_info gpio_backlight_device_info = { |
|---|
| 393 | + .name = "gpio-backlight", |
|---|
| 394 | + .data = &gpio_backlight_data, |
|---|
| 395 | + .size_data = sizeof(gpio_backlight_data), |
|---|
| 396 | + .properties = gpio_backlight_props, |
|---|
| 397 | +}; |
|---|
| 398 | + |
|---|
| 399 | +static struct platform_device *gpio_backlight_device; |
|---|
| 390 | 400 | |
|---|
| 391 | 401 | /* CEU0 */ |
|---|
| 392 | 402 | static struct ceu_platform_data ceu0_pdata = { |
|---|
| .. | .. |
|---|
| 633 | 643 | static struct fixed_voltage_config cn12_power_info = { |
|---|
| 634 | 644 | .supply_name = "CN12 SD/MMC Vdd", |
|---|
| 635 | 645 | .microvolts = 3300000, |
|---|
| 636 | | - .gpio = GPIO_PTB7, |
|---|
| 637 | | - .enable_high = 1, |
|---|
| 638 | 646 | .init_data = &cn12_power_init_data, |
|---|
| 639 | 647 | }; |
|---|
| 640 | 648 | |
|---|
| .. | .. |
|---|
| 643 | 651 | .id = 0, |
|---|
| 644 | 652 | .dev = { |
|---|
| 645 | 653 | .platform_data = &cn12_power_info, |
|---|
| 654 | + }, |
|---|
| 655 | +}; |
|---|
| 656 | + |
|---|
| 657 | +static struct gpiod_lookup_table cn12_power_gpiod_table = { |
|---|
| 658 | + .dev_id = "reg-fixed-voltage.0", |
|---|
| 659 | + .table = { |
|---|
| 660 | + /* Offset 7 on port B */ |
|---|
| 661 | + GPIO_LOOKUP("sh7724_pfc", GPIO_PTB7, |
|---|
| 662 | + NULL, GPIO_ACTIVE_HIGH), |
|---|
| 663 | + { }, |
|---|
| 646 | 664 | }, |
|---|
| 647 | 665 | }; |
|---|
| 648 | 666 | |
|---|
| .. | .. |
|---|
| 665 | 683 | static struct fixed_voltage_config sdhi0_power_info = { |
|---|
| 666 | 684 | .supply_name = "CN11 SD/MMC Vdd", |
|---|
| 667 | 685 | .microvolts = 3300000, |
|---|
| 668 | | - .gpio = GPIO_PTB6, |
|---|
| 669 | | - .enable_high = 1, |
|---|
| 670 | 686 | .init_data = &sdhi0_power_init_data, |
|---|
| 671 | 687 | }; |
|---|
| 672 | 688 | |
|---|
| .. | .. |
|---|
| 678 | 694 | }, |
|---|
| 679 | 695 | }; |
|---|
| 680 | 696 | |
|---|
| 697 | +static struct gpiod_lookup_table sdhi0_power_gpiod_table = { |
|---|
| 698 | + .dev_id = "reg-fixed-voltage.1", |
|---|
| 699 | + .table = { |
|---|
| 700 | + /* Offset 6 on port B */ |
|---|
| 701 | + GPIO_LOOKUP("sh7724_pfc", GPIO_PTB6, |
|---|
| 702 | + NULL, GPIO_ACTIVE_HIGH), |
|---|
| 703 | + { }, |
|---|
| 704 | + }, |
|---|
| 705 | +}; |
|---|
| 706 | + |
|---|
| 707 | +static struct gpiod_lookup_table sdhi0_gpio_table = { |
|---|
| 708 | + .dev_id = "sh_mobile_sdhi.0", |
|---|
| 709 | + .table = { |
|---|
| 710 | + /* Card detect */ |
|---|
| 711 | + GPIO_LOOKUP("sh7724_pfc", GPIO_PTY7, "cd", GPIO_ACTIVE_LOW), |
|---|
| 712 | + { }, |
|---|
| 713 | + }, |
|---|
| 714 | +}; |
|---|
| 715 | + |
|---|
| 681 | 716 | static struct tmio_mmc_data sdhi0_info = { |
|---|
| 682 | 717 | .chan_priv_tx = (void *)SHDMA_SLAVE_SDHI0_TX, |
|---|
| 683 | 718 | .chan_priv_rx = (void *)SHDMA_SLAVE_SDHI0_RX, |
|---|
| 684 | 719 | .capabilities = MMC_CAP_SDIO_IRQ | MMC_CAP_POWER_OFF_CARD | |
|---|
| 685 | 720 | MMC_CAP_NEEDS_POLL, |
|---|
| 686 | | - .flags = TMIO_MMC_USE_GPIO_CD, |
|---|
| 687 | | - .cd_gpio = GPIO_PTY7, |
|---|
| 688 | 721 | }; |
|---|
| 689 | 722 | |
|---|
| 690 | 723 | static struct resource sdhi0_resources[] = { |
|---|
| .. | .. |
|---|
| 717 | 750 | .chan_priv_rx = (void *)SHDMA_SLAVE_SDHI1_RX, |
|---|
| 718 | 751 | .capabilities = MMC_CAP_SDIO_IRQ | MMC_CAP_POWER_OFF_CARD | |
|---|
| 719 | 752 | MMC_CAP_NEEDS_POLL, |
|---|
| 720 | | - .flags = TMIO_MMC_USE_GPIO_CD, |
|---|
| 721 | | - .cd_gpio = GPIO_PTW7, |
|---|
| 753 | +}; |
|---|
| 754 | + |
|---|
| 755 | +static struct gpiod_lookup_table sdhi1_gpio_table = { |
|---|
| 756 | + .dev_id = "sh_mobile_sdhi.1", |
|---|
| 757 | + .table = { |
|---|
| 758 | + /* Card detect */ |
|---|
| 759 | + GPIO_LOOKUP("sh7724_pfc", GPIO_PTW7, "cd", GPIO_ACTIVE_LOW), |
|---|
| 760 | + { }, |
|---|
| 761 | + }, |
|---|
| 722 | 762 | }; |
|---|
| 723 | 763 | |
|---|
| 724 | 764 | static struct resource sdhi1_resources[] = { |
|---|
| .. | .. |
|---|
| 758 | 798 | .caps2 = MMC_CAP2_RO_ACTIVE_HIGH, |
|---|
| 759 | 799 | .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34, /* 3.3V only */ |
|---|
| 760 | 800 | .setpower = mmc_spi_setpower, |
|---|
| 761 | | - .flags = MMC_SPI_USE_CD_GPIO | MMC_SPI_USE_RO_GPIO, |
|---|
| 762 | | - .cd_gpio = GPIO_PTY7, |
|---|
| 763 | | - .ro_gpio = GPIO_PTY6, |
|---|
| 801 | +}; |
|---|
| 802 | + |
|---|
| 803 | +static struct gpiod_lookup_table mmc_spi_gpio_table = { |
|---|
| 804 | + .dev_id = "mmc_spi.0", /* device "mmc_spi" @ CS0 */ |
|---|
| 805 | + .table = { |
|---|
| 806 | + /* Card detect */ |
|---|
| 807 | + GPIO_LOOKUP_IDX("sh7724_pfc", GPIO_PTY7, NULL, 0, |
|---|
| 808 | + GPIO_ACTIVE_LOW), |
|---|
| 809 | + /* Write protect */ |
|---|
| 810 | + GPIO_LOOKUP_IDX("sh7724_pfc", GPIO_PTY6, NULL, 1, |
|---|
| 811 | + GPIO_ACTIVE_HIGH), |
|---|
| 812 | + { }, |
|---|
| 813 | + }, |
|---|
| 764 | 814 | }; |
|---|
| 765 | 815 | |
|---|
| 766 | 816 | static struct spi_board_info spi_bus[] = { |
|---|
| .. | .. |
|---|
| 769 | 819 | .platform_data = &mmc_spi_info, |
|---|
| 770 | 820 | .max_speed_hz = 5000000, |
|---|
| 771 | 821 | .mode = SPI_MODE_0, |
|---|
| 772 | | - .controller_data = (void *) GPIO_PTM4, |
|---|
| 773 | 822 | }, |
|---|
| 774 | 823 | }; |
|---|
| 775 | 824 | |
|---|
| .. | .. |
|---|
| 799 | 848 | }, |
|---|
| 800 | 849 | .num_resources = ARRAY_SIZE(msiof0_resources), |
|---|
| 801 | 850 | .resource = msiof0_resources, |
|---|
| 851 | +}; |
|---|
| 852 | + |
|---|
| 853 | +static struct gpiod_lookup_table msiof_gpio_table = { |
|---|
| 854 | + .dev_id = "spi_sh_msiof.0", |
|---|
| 855 | + .table = { |
|---|
| 856 | + GPIO_LOOKUP("sh7724_pfc", GPIO_PTM4, "cs", GPIO_ACTIVE_HIGH), |
|---|
| 857 | + { }, |
|---|
| 858 | + }, |
|---|
| 802 | 859 | }; |
|---|
| 803 | 860 | |
|---|
| 804 | 861 | #endif |
|---|
| .. | .. |
|---|
| 962 | 1019 | &usb1_common_device, |
|---|
| 963 | 1020 | &usbhs_device, |
|---|
| 964 | 1021 | &lcdc_device, |
|---|
| 965 | | - &gpio_backlight_device, |
|---|
| 966 | 1022 | &keysc_device, |
|---|
| 967 | 1023 | &cn12_power, |
|---|
| 968 | 1024 | #if defined(CONFIG_MMC_SDHI) || defined(CONFIG_MMC_SDHI_MODULE) |
|---|
| .. | .. |
|---|
| 1259 | 1315 | gpio_request(GPIO_FN_MSIOF0_TXD, NULL); |
|---|
| 1260 | 1316 | gpio_request(GPIO_FN_MSIOF0_RXD, NULL); |
|---|
| 1261 | 1317 | gpio_request(GPIO_FN_MSIOF0_TSCK, NULL); |
|---|
| 1262 | | - gpio_request(GPIO_PTM4, NULL); /* software CS control of TSYNC pin */ |
|---|
| 1263 | | - gpio_direction_output(GPIO_PTM4, 1); /* active low CS */ |
|---|
| 1264 | 1318 | gpio_request(GPIO_PTB6, NULL); /* 3.3V power control */ |
|---|
| 1265 | 1319 | gpio_direction_output(GPIO_PTB6, 0); /* disable power by default */ |
|---|
| 1266 | 1320 | |
|---|
| 1321 | + gpiod_add_lookup_table(&mmc_spi_gpio_table); |
|---|
| 1322 | + gpiod_add_lookup_table(&msiof_gpio_table); |
|---|
| 1267 | 1323 | spi_register_board_info(spi_bus, ARRAY_SIZE(spi_bus)); |
|---|
| 1268 | 1324 | #endif |
|---|
| 1269 | 1325 | |
|---|
| .. | .. |
|---|
| 1396 | 1452 | |
|---|
| 1397 | 1453 | /* Initialize CEU platform devices separately to map memory first */ |
|---|
| 1398 | 1454 | device_initialize(&ecovec_ceu_devices[0]->dev); |
|---|
| 1399 | | - arch_setup_pdev_archdata(ecovec_ceu_devices[0]); |
|---|
| 1400 | 1455 | dma_declare_coherent_memory(&ecovec_ceu_devices[0]->dev, |
|---|
| 1401 | 1456 | ceu0_dma_membase, ceu0_dma_membase, |
|---|
| 1402 | 1457 | ceu0_dma_membase + |
|---|
| 1403 | | - CEU_BUFFER_MEMORY_SIZE - 1, |
|---|
| 1404 | | - DMA_MEMORY_EXCLUSIVE); |
|---|
| 1458 | + CEU_BUFFER_MEMORY_SIZE - 1); |
|---|
| 1405 | 1459 | platform_device_add(ecovec_ceu_devices[0]); |
|---|
| 1406 | 1460 | |
|---|
| 1407 | 1461 | device_initialize(&ecovec_ceu_devices[1]->dev); |
|---|
| 1408 | | - arch_setup_pdev_archdata(ecovec_ceu_devices[1]); |
|---|
| 1409 | 1462 | dma_declare_coherent_memory(&ecovec_ceu_devices[1]->dev, |
|---|
| 1410 | 1463 | ceu1_dma_membase, ceu1_dma_membase, |
|---|
| 1411 | 1464 | ceu1_dma_membase + |
|---|
| 1412 | | - CEU_BUFFER_MEMORY_SIZE - 1, |
|---|
| 1413 | | - DMA_MEMORY_EXCLUSIVE); |
|---|
| 1465 | + CEU_BUFFER_MEMORY_SIZE - 1); |
|---|
| 1414 | 1466 | platform_device_add(ecovec_ceu_devices[1]); |
|---|
| 1467 | + |
|---|
| 1468 | + gpiod_add_lookup_table(&cn12_power_gpiod_table); |
|---|
| 1469 | +#if defined(CONFIG_MMC_SDHI) || defined(CONFIG_MMC_SDHI_MODULE) |
|---|
| 1470 | + gpiod_add_lookup_table(&sdhi0_power_gpiod_table); |
|---|
| 1471 | + gpiod_add_lookup_table(&sdhi0_gpio_table); |
|---|
| 1472 | +#if !defined(CONFIG_MMC_SH_MMCIF) && !defined(CONFIG_MMC_SH_MMCIF_MODULE) |
|---|
| 1473 | + gpiod_add_lookup_table(&sdhi1_gpio_table); |
|---|
| 1474 | +#endif |
|---|
| 1475 | +#endif |
|---|
| 1476 | + |
|---|
| 1477 | + gpiod_add_lookup_table(&gpio_backlight_lookup); |
|---|
| 1478 | + gpio_backlight_device = platform_device_register_full( |
|---|
| 1479 | + &gpio_backlight_device_info); |
|---|
| 1480 | + if (IS_ERR(gpio_backlight_device)) |
|---|
| 1481 | + return PTR_ERR(gpio_backlight_device); |
|---|
| 1415 | 1482 | |
|---|
| 1416 | 1483 | return platform_add_devices(ecovec_devices, |
|---|
| 1417 | 1484 | ARRAY_SIZE(ecovec_devices)); |
|---|
| .. | .. |
|---|
| 1431 | 1498 | phys_addr_t phys; |
|---|
| 1432 | 1499 | phys_addr_t size = CEU_BUFFER_MEMORY_SIZE; |
|---|
| 1433 | 1500 | |
|---|
| 1434 | | - phys = memblock_alloc_base(size, PAGE_SIZE, MEMBLOCK_ALLOC_ANYWHERE); |
|---|
| 1501 | + phys = memblock_phys_alloc(size, PAGE_SIZE); |
|---|
| 1502 | + if (!phys) |
|---|
| 1503 | + panic("Failed to allocate CEU0 memory\n"); |
|---|
| 1504 | + |
|---|
| 1435 | 1505 | memblock_free(phys, size); |
|---|
| 1436 | 1506 | memblock_remove(phys, size); |
|---|
| 1437 | 1507 | ceu0_dma_membase = phys; |
|---|
| 1438 | 1508 | |
|---|
| 1439 | | - phys = memblock_alloc_base(size, PAGE_SIZE, MEMBLOCK_ALLOC_ANYWHERE); |
|---|
| 1509 | + phys = memblock_phys_alloc(size, PAGE_SIZE); |
|---|
| 1510 | + if (!phys) |
|---|
| 1511 | + panic("Failed to allocate CEU1 memory\n"); |
|---|
| 1512 | + |
|---|
| 1440 | 1513 | memblock_free(phys, size); |
|---|
| 1441 | 1514 | memblock_remove(phys, size); |
|---|
| 1442 | 1515 | ceu1_dma_membase = phys; |
|---|