Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * TI DA850/OMAP-L138 EVM board
0004  *
0005  * Copyright (C) 2009 Texas Instruments Incorporated - https://www.ti.com/
0006  *
0007  * Derived from: arch/arm/mach-davinci/board-da830-evm.c
0008  * Original Copyrights follow:
0009  *
0010  * 2007, 2009 (c) MontaVista Software, Inc.
0011  */
0012 #include <linux/console.h>
0013 #include <linux/delay.h>
0014 #include <linux/gpio.h>
0015 #include <linux/gpio_keys.h>
0016 #include <linux/gpio/machine.h>
0017 #include <linux/init.h>
0018 #include <linux/kernel.h>
0019 #include <linux/leds.h>
0020 #include <linux/i2c.h>
0021 #include <linux/platform_data/pca953x.h>
0022 #include <linux/input.h>
0023 #include <linux/input/tps6507x-ts.h>
0024 #include <linux/mfd/tps6507x.h>
0025 #include <linux/mtd/mtd.h>
0026 #include <linux/mtd/rawnand.h>
0027 #include <linux/mtd/partitions.h>
0028 #include <linux/nvmem-provider.h>
0029 #include <linux/mtd/physmap.h>
0030 #include <linux/platform_device.h>
0031 #include <linux/platform_data/gpio-davinci.h>
0032 #include <linux/platform_data/mtd-davinci.h>
0033 #include <linux/platform_data/mtd-davinci-aemif.h>
0034 #include <linux/platform_data/ti-aemif.h>
0035 #include <linux/platform_data/spi-davinci.h>
0036 #include <linux/platform_data/uio_pruss.h>
0037 #include <linux/property.h>
0038 #include <linux/regulator/machine.h>
0039 #include <linux/regulator/tps6507x.h>
0040 #include <linux/regulator/fixed.h>
0041 #include <linux/spi/spi.h>
0042 #include <linux/spi/flash.h>
0043 
0044 #include "common.h"
0045 #include "da8xx.h"
0046 #include "mux.h"
0047 #include "irqs.h"
0048 #include "sram.h"
0049 
0050 #include <asm/mach-types.h>
0051 #include <asm/mach/arch.h>
0052 #include <asm/system_info.h>
0053 
0054 #include <media/i2c/tvp514x.h>
0055 #include <media/i2c/adv7343.h>
0056 
0057 #define DA850_EVM_PHY_ID        "davinci_mdio-0:00"
0058 #define DA850_LCD_PWR_PIN       GPIO_TO_PIN(2, 8)
0059 #define DA850_LCD_BL_PIN        GPIO_TO_PIN(2, 15)
0060 
0061 #define DA850_MII_MDIO_CLKEN_PIN    GPIO_TO_PIN(2, 6)
0062 
0063 static struct mtd_partition da850evm_spiflash_part[] = {
0064     [0] = {
0065         .name = "UBL",
0066         .offset = 0,
0067         .size = SZ_64K,
0068         .mask_flags = MTD_WRITEABLE,
0069     },
0070     [1] = {
0071         .name = "U-Boot",
0072         .offset = MTDPART_OFS_APPEND,
0073         .size = SZ_512K,
0074         .mask_flags = MTD_WRITEABLE,
0075     },
0076     [2] = {
0077         .name = "U-Boot-Env",
0078         .offset = MTDPART_OFS_APPEND,
0079         .size = SZ_64K,
0080         .mask_flags = MTD_WRITEABLE,
0081     },
0082     [3] = {
0083         .name = "Kernel",
0084         .offset = MTDPART_OFS_APPEND,
0085         .size = SZ_2M + SZ_512K,
0086         .mask_flags = 0,
0087     },
0088     [4] = {
0089         .name = "Filesystem",
0090         .offset = MTDPART_OFS_APPEND,
0091         .size = SZ_4M,
0092         .mask_flags = 0,
0093     },
0094     [5] = {
0095         .name = "MAC-Address",
0096         .offset = SZ_8M - SZ_64K,
0097         .size = SZ_64K,
0098         .mask_flags = MTD_WRITEABLE,
0099     },
0100 };
0101 
0102 static struct nvmem_cell_info da850evm_nvmem_cells[] = {
0103     {
0104         .name       = "macaddr",
0105         .offset     = 0x0,
0106         .bytes      = ETH_ALEN,
0107     }
0108 };
0109 
0110 static struct nvmem_cell_table da850evm_nvmem_cell_table = {
0111     /*
0112      * The nvmem name differs from the partition name because of the
0113      * internal works of the nvmem framework.
0114      */
0115     .nvmem_name = "MAC-Address0",
0116     .cells      = da850evm_nvmem_cells,
0117     .ncells     = ARRAY_SIZE(da850evm_nvmem_cells),
0118 };
0119 
0120 static struct nvmem_cell_lookup da850evm_nvmem_cell_lookup = {
0121     .nvmem_name = "MAC-Address0",
0122     .cell_name  = "macaddr",
0123     .dev_id     = "davinci_emac.1",
0124     .con_id     = "mac-address",
0125 };
0126 
0127 static struct flash_platform_data da850evm_spiflash_data = {
0128     .name       = "m25p80",
0129     .parts      = da850evm_spiflash_part,
0130     .nr_parts   = ARRAY_SIZE(da850evm_spiflash_part),
0131     .type       = "m25p64",
0132 };
0133 
0134 static struct davinci_spi_config da850evm_spiflash_cfg = {
0135     .io_type    = SPI_IO_TYPE_DMA,
0136     .c2tdelay   = 8,
0137     .t2cdelay   = 8,
0138 };
0139 
0140 static struct spi_board_info da850evm_spi_info[] = {
0141     {
0142         .modalias       = "m25p80",
0143         .platform_data      = &da850evm_spiflash_data,
0144         .controller_data    = &da850evm_spiflash_cfg,
0145         .mode           = SPI_MODE_0,
0146         .max_speed_hz       = 30000000,
0147         .bus_num        = 1,
0148         .chip_select        = 0,
0149     },
0150 };
0151 
0152 static struct mtd_partition da850_evm_norflash_partition[] = {
0153     {
0154         .name           = "bootloaders + env",
0155         .offset         = 0,
0156         .size           = SZ_512K,
0157         .mask_flags     = MTD_WRITEABLE,
0158     },
0159     {
0160         .name           = "kernel",
0161         .offset         = MTDPART_OFS_APPEND,
0162         .size           = SZ_2M,
0163         .mask_flags     = 0,
0164     },
0165     {
0166         .name           = "filesystem",
0167         .offset         = MTDPART_OFS_APPEND,
0168         .size           = MTDPART_SIZ_FULL,
0169         .mask_flags     = 0,
0170     },
0171 };
0172 
0173 static struct physmap_flash_data da850_evm_norflash_data = {
0174     .width      = 2,
0175     .parts      = da850_evm_norflash_partition,
0176     .nr_parts   = ARRAY_SIZE(da850_evm_norflash_partition),
0177 };
0178 
0179 static struct resource da850_evm_norflash_resource[] = {
0180     {
0181         .start  = DA8XX_AEMIF_CS2_BASE,
0182         .end    = DA8XX_AEMIF_CS2_BASE + SZ_32M - 1,
0183         .flags  = IORESOURCE_MEM,
0184     },
0185 };
0186 
0187 /* DA850/OMAP-L138 EVM includes a 512 MByte large-page NAND flash
0188  * (128K blocks). It may be used instead of the (default) SPI flash
0189  * to boot, using TI's tools to install the secondary boot loader
0190  * (UBL) and U-Boot.
0191  */
0192 static struct mtd_partition da850_evm_nandflash_partition[] = {
0193     {
0194         .name       = "u-boot env",
0195         .offset     = 0,
0196         .size       = SZ_128K,
0197         .mask_flags = MTD_WRITEABLE,
0198      },
0199     {
0200         .name       = "UBL",
0201         .offset     = MTDPART_OFS_APPEND,
0202         .size       = SZ_128K,
0203         .mask_flags = MTD_WRITEABLE,
0204     },
0205     {
0206         .name       = "u-boot",
0207         .offset     = MTDPART_OFS_APPEND,
0208         .size       = 4 * SZ_128K,
0209         .mask_flags = MTD_WRITEABLE,
0210     },
0211     {
0212         .name       = "kernel",
0213         .offset     = 0x200000,
0214         .size       = SZ_2M,
0215         .mask_flags = 0,
0216     },
0217     {
0218         .name       = "filesystem",
0219         .offset     = MTDPART_OFS_APPEND,
0220         .size       = MTDPART_SIZ_FULL,
0221         .mask_flags = 0,
0222     },
0223 };
0224 
0225 static struct davinci_aemif_timing da850_evm_nandflash_timing = {
0226     .wsetup     = 24,
0227     .wstrobe    = 21,
0228     .whold      = 14,
0229     .rsetup     = 19,
0230     .rstrobe    = 50,
0231     .rhold      = 0,
0232     .ta     = 20,
0233 };
0234 
0235 static struct davinci_nand_pdata da850_evm_nandflash_data = {
0236     .core_chipsel   = 1,
0237     .parts      = da850_evm_nandflash_partition,
0238     .nr_parts   = ARRAY_SIZE(da850_evm_nandflash_partition),
0239     .engine_type    = NAND_ECC_ENGINE_TYPE_ON_HOST,
0240     .ecc_bits   = 4,
0241     .bbt_options    = NAND_BBT_USE_FLASH,
0242     .timing     = &da850_evm_nandflash_timing,
0243 };
0244 
0245 static struct resource da850_evm_nandflash_resource[] = {
0246     {
0247         .start  = DA8XX_AEMIF_CS3_BASE,
0248         .end    = DA8XX_AEMIF_CS3_BASE + SZ_512K + 2 * SZ_1K - 1,
0249         .flags  = IORESOURCE_MEM,
0250     },
0251     {
0252         .start  = DA8XX_AEMIF_CTL_BASE,
0253         .end    = DA8XX_AEMIF_CTL_BASE + SZ_32K - 1,
0254         .flags  = IORESOURCE_MEM,
0255     },
0256 };
0257 
0258 static struct resource da850_evm_aemif_resource[] = {
0259     {
0260         .start  = DA8XX_AEMIF_CTL_BASE,
0261         .end    = DA8XX_AEMIF_CTL_BASE + SZ_32K,
0262         .flags  = IORESOURCE_MEM,
0263     }
0264 };
0265 
0266 static struct aemif_abus_data da850_evm_aemif_abus_data[] = {
0267     {
0268         .cs = 3,
0269     }
0270 };
0271 
0272 static struct platform_device da850_evm_aemif_devices[] = {
0273     {
0274         .name       = "davinci_nand",
0275         .id     = 1,
0276         .dev        = {
0277             .platform_data  = &da850_evm_nandflash_data,
0278         },
0279         .num_resources  = ARRAY_SIZE(da850_evm_nandflash_resource),
0280         .resource   = da850_evm_nandflash_resource,
0281     },
0282     {
0283         .name       = "physmap-flash",
0284         .id     = 0,
0285         .dev        = {
0286             .platform_data  = &da850_evm_norflash_data,
0287         },
0288         .num_resources  = 1,
0289         .resource   = da850_evm_norflash_resource,
0290     }
0291 };
0292 
0293 static struct aemif_platform_data da850_evm_aemif_pdata = {
0294     .cs_offset = 2,
0295     .abus_data = da850_evm_aemif_abus_data,
0296     .num_abus_data = ARRAY_SIZE(da850_evm_aemif_abus_data),
0297     .sub_devices = da850_evm_aemif_devices,
0298     .num_sub_devices = ARRAY_SIZE(da850_evm_aemif_devices),
0299 };
0300 
0301 static struct platform_device da850_evm_aemif_device = {
0302     .name       = "ti-aemif",
0303     .id     = -1,
0304     .dev = {
0305         .platform_data  = &da850_evm_aemif_pdata,
0306     },
0307     .resource   = da850_evm_aemif_resource,
0308     .num_resources  = ARRAY_SIZE(da850_evm_aemif_resource),
0309 };
0310 
0311 static const short da850_evm_nand_pins[] = {
0312     DA850_EMA_D_0, DA850_EMA_D_1, DA850_EMA_D_2, DA850_EMA_D_3,
0313     DA850_EMA_D_4, DA850_EMA_D_5, DA850_EMA_D_6, DA850_EMA_D_7,
0314     DA850_EMA_A_1, DA850_EMA_A_2, DA850_NEMA_CS_3, DA850_NEMA_CS_4,
0315     DA850_NEMA_WE, DA850_NEMA_OE,
0316     -1
0317 };
0318 
0319 static const short da850_evm_nor_pins[] = {
0320     DA850_EMA_BA_1, DA850_EMA_CLK, DA850_EMA_WAIT_1, DA850_NEMA_CS_2,
0321     DA850_NEMA_WE, DA850_NEMA_OE, DA850_EMA_D_0, DA850_EMA_D_1,
0322     DA850_EMA_D_2, DA850_EMA_D_3, DA850_EMA_D_4, DA850_EMA_D_5,
0323     DA850_EMA_D_6, DA850_EMA_D_7, DA850_EMA_D_8, DA850_EMA_D_9,
0324     DA850_EMA_D_10, DA850_EMA_D_11, DA850_EMA_D_12, DA850_EMA_D_13,
0325     DA850_EMA_D_14, DA850_EMA_D_15, DA850_EMA_A_0, DA850_EMA_A_1,
0326     DA850_EMA_A_2, DA850_EMA_A_3, DA850_EMA_A_4, DA850_EMA_A_5,
0327     DA850_EMA_A_6, DA850_EMA_A_7, DA850_EMA_A_8, DA850_EMA_A_9,
0328     DA850_EMA_A_10, DA850_EMA_A_11, DA850_EMA_A_12, DA850_EMA_A_13,
0329     DA850_EMA_A_14, DA850_EMA_A_15, DA850_EMA_A_16, DA850_EMA_A_17,
0330     DA850_EMA_A_18, DA850_EMA_A_19, DA850_EMA_A_20, DA850_EMA_A_21,
0331     DA850_EMA_A_22, DA850_EMA_A_23,
0332     -1
0333 };
0334 
0335 #define HAS_MMC     IS_ENABLED(CONFIG_MMC_DAVINCI)
0336 
0337 static inline void da850_evm_setup_nor_nand(void)
0338 {
0339     int ret = 0;
0340 
0341     if (!HAS_MMC) {
0342         ret = davinci_cfg_reg_list(da850_evm_nand_pins);
0343         if (ret)
0344             pr_warn("%s: NAND mux setup failed: %d\n",
0345                 __func__, ret);
0346 
0347         ret = davinci_cfg_reg_list(da850_evm_nor_pins);
0348         if (ret)
0349             pr_warn("%s: NOR mux setup failed: %d\n",
0350                 __func__, ret);
0351 
0352         ret = platform_device_register(&da850_evm_aemif_device);
0353         if (ret)
0354             pr_warn("%s: registering aemif failed: %d\n",
0355                 __func__, ret);
0356     }
0357 }
0358 
0359 #ifdef CONFIG_DA850_UI_RMII
0360 static inline void da850_evm_setup_emac_rmii(int rmii_sel)
0361 {
0362     struct davinci_soc_info *soc_info = &davinci_soc_info;
0363 
0364     soc_info->emac_pdata->rmii_en = 1;
0365     gpio_set_value_cansleep(rmii_sel, 0);
0366 }
0367 #else
0368 static inline void da850_evm_setup_emac_rmii(int rmii_sel) { }
0369 #endif
0370 
0371 
0372 #define DA850_KEYS_DEBOUNCE_MS  10
0373 /*
0374  * At 200ms polling interval it is possible to miss an
0375  * event by tapping very lightly on the push button but most
0376  * pushes do result in an event; longer intervals require the
0377  * user to hold the button whereas shorter intervals require
0378  * more CPU time for polling.
0379  */
0380 #define DA850_GPIO_KEYS_POLL_MS 200
0381 
0382 enum da850_evm_ui_exp_pins {
0383     DA850_EVM_UI_EXP_SEL_C = 5,
0384     DA850_EVM_UI_EXP_SEL_B,
0385     DA850_EVM_UI_EXP_SEL_A,
0386     DA850_EVM_UI_EXP_PB8,
0387     DA850_EVM_UI_EXP_PB7,
0388     DA850_EVM_UI_EXP_PB6,
0389     DA850_EVM_UI_EXP_PB5,
0390     DA850_EVM_UI_EXP_PB4,
0391     DA850_EVM_UI_EXP_PB3,
0392     DA850_EVM_UI_EXP_PB2,
0393     DA850_EVM_UI_EXP_PB1,
0394 };
0395 
0396 static const char * const da850_evm_ui_exp[] = {
0397     [DA850_EVM_UI_EXP_SEL_C]        = "sel_c",
0398     [DA850_EVM_UI_EXP_SEL_B]        = "sel_b",
0399     [DA850_EVM_UI_EXP_SEL_A]        = "sel_a",
0400     [DA850_EVM_UI_EXP_PB8]          = "pb8",
0401     [DA850_EVM_UI_EXP_PB7]          = "pb7",
0402     [DA850_EVM_UI_EXP_PB6]          = "pb6",
0403     [DA850_EVM_UI_EXP_PB5]          = "pb5",
0404     [DA850_EVM_UI_EXP_PB4]          = "pb4",
0405     [DA850_EVM_UI_EXP_PB3]          = "pb3",
0406     [DA850_EVM_UI_EXP_PB2]          = "pb2",
0407     [DA850_EVM_UI_EXP_PB1]          = "pb1",
0408 };
0409 
0410 #define DA850_N_UI_PB       8
0411 
0412 static struct gpio_keys_button da850_evm_ui_keys[] = {
0413     [0 ... DA850_N_UI_PB - 1] = {
0414         .type           = EV_KEY,
0415         .active_low     = 1,
0416         .wakeup         = 0,
0417         .debounce_interval  = DA850_KEYS_DEBOUNCE_MS,
0418         .code           = -1, /* assigned at runtime */
0419         .gpio           = -1, /* assigned at runtime */
0420         .desc           = NULL, /* assigned at runtime */
0421     },
0422 };
0423 
0424 static struct gpio_keys_platform_data da850_evm_ui_keys_pdata = {
0425     .buttons = da850_evm_ui_keys,
0426     .nbuttons = ARRAY_SIZE(da850_evm_ui_keys),
0427     .poll_interval = DA850_GPIO_KEYS_POLL_MS,
0428 };
0429 
0430 static struct platform_device da850_evm_ui_keys_device = {
0431     .name = "gpio-keys-polled",
0432     .id = 0,
0433     .dev = {
0434         .platform_data = &da850_evm_ui_keys_pdata
0435     },
0436 };
0437 
0438 static void da850_evm_ui_keys_init(unsigned gpio)
0439 {
0440     int i;
0441     struct gpio_keys_button *button;
0442 
0443     for (i = 0; i < DA850_N_UI_PB; i++) {
0444         button = &da850_evm_ui_keys[i];
0445         button->code = KEY_F8 - i;
0446         button->desc = da850_evm_ui_exp[DA850_EVM_UI_EXP_PB8 + i];
0447         button->gpio = gpio + DA850_EVM_UI_EXP_PB8 + i;
0448     }
0449 }
0450 
0451 #ifdef CONFIG_DA850_UI_SD_VIDEO_PORT
0452 static inline void da850_evm_setup_video_port(int video_sel)
0453 {
0454     gpio_set_value_cansleep(video_sel, 0);
0455 }
0456 #else
0457 static inline void da850_evm_setup_video_port(int video_sel) { }
0458 #endif
0459 
0460 static int da850_evm_ui_expander_setup(struct i2c_client *client, unsigned gpio,
0461                         unsigned ngpio, void *c)
0462 {
0463     int sel_a, sel_b, sel_c, ret;
0464 
0465     sel_a = gpio + DA850_EVM_UI_EXP_SEL_A;
0466     sel_b = gpio + DA850_EVM_UI_EXP_SEL_B;
0467     sel_c = gpio + DA850_EVM_UI_EXP_SEL_C;
0468 
0469     ret = gpio_request(sel_a, da850_evm_ui_exp[DA850_EVM_UI_EXP_SEL_A]);
0470     if (ret) {
0471         pr_warn("Cannot open UI expander pin %d\n", sel_a);
0472         goto exp_setup_sela_fail;
0473     }
0474 
0475     ret = gpio_request(sel_b, da850_evm_ui_exp[DA850_EVM_UI_EXP_SEL_B]);
0476     if (ret) {
0477         pr_warn("Cannot open UI expander pin %d\n", sel_b);
0478         goto exp_setup_selb_fail;
0479     }
0480 
0481     ret = gpio_request(sel_c, da850_evm_ui_exp[DA850_EVM_UI_EXP_SEL_C]);
0482     if (ret) {
0483         pr_warn("Cannot open UI expander pin %d\n", sel_c);
0484         goto exp_setup_selc_fail;
0485     }
0486 
0487     /* deselect all functionalities */
0488     gpio_direction_output(sel_a, 1);
0489     gpio_direction_output(sel_b, 1);
0490     gpio_direction_output(sel_c, 1);
0491 
0492     da850_evm_ui_keys_init(gpio);
0493     ret = platform_device_register(&da850_evm_ui_keys_device);
0494     if (ret) {
0495         pr_warn("Could not register UI GPIO expander push-buttons");
0496         goto exp_setup_keys_fail;
0497     }
0498 
0499     pr_info("DA850/OMAP-L138 EVM UI card detected\n");
0500 
0501     da850_evm_setup_nor_nand();
0502 
0503     da850_evm_setup_emac_rmii(sel_a);
0504 
0505     da850_evm_setup_video_port(sel_c);
0506 
0507     return 0;
0508 
0509 exp_setup_keys_fail:
0510     gpio_free(sel_c);
0511 exp_setup_selc_fail:
0512     gpio_free(sel_b);
0513 exp_setup_selb_fail:
0514     gpio_free(sel_a);
0515 exp_setup_sela_fail:
0516     return ret;
0517 }
0518 
0519 static int da850_evm_ui_expander_teardown(struct i2c_client *client,
0520                     unsigned gpio, unsigned ngpio, void *c)
0521 {
0522     platform_device_unregister(&da850_evm_ui_keys_device);
0523 
0524     /* deselect all functionalities */
0525     gpio_set_value_cansleep(gpio + DA850_EVM_UI_EXP_SEL_C, 1);
0526     gpio_set_value_cansleep(gpio + DA850_EVM_UI_EXP_SEL_B, 1);
0527     gpio_set_value_cansleep(gpio + DA850_EVM_UI_EXP_SEL_A, 1);
0528 
0529     gpio_free(gpio + DA850_EVM_UI_EXP_SEL_C);
0530     gpio_free(gpio + DA850_EVM_UI_EXP_SEL_B);
0531     gpio_free(gpio + DA850_EVM_UI_EXP_SEL_A);
0532 
0533     return 0;
0534 }
0535 
0536 /* assign the baseboard expander's GPIOs after the UI board's */
0537 #define DA850_UI_EXPANDER_N_GPIOS ARRAY_SIZE(da850_evm_ui_exp)
0538 #define DA850_BB_EXPANDER_GPIO_BASE (DAVINCI_N_GPIO + DA850_UI_EXPANDER_N_GPIOS)
0539 
0540 enum da850_evm_bb_exp_pins {
0541     DA850_EVM_BB_EXP_DEEP_SLEEP_EN = 0,
0542     DA850_EVM_BB_EXP_SW_RST,
0543     DA850_EVM_BB_EXP_TP_23,
0544     DA850_EVM_BB_EXP_TP_22,
0545     DA850_EVM_BB_EXP_TP_21,
0546     DA850_EVM_BB_EXP_USER_PB1,
0547     DA850_EVM_BB_EXP_USER_LED2,
0548     DA850_EVM_BB_EXP_USER_LED1,
0549     DA850_EVM_BB_EXP_USER_SW1,
0550     DA850_EVM_BB_EXP_USER_SW2,
0551     DA850_EVM_BB_EXP_USER_SW3,
0552     DA850_EVM_BB_EXP_USER_SW4,
0553     DA850_EVM_BB_EXP_USER_SW5,
0554     DA850_EVM_BB_EXP_USER_SW6,
0555     DA850_EVM_BB_EXP_USER_SW7,
0556     DA850_EVM_BB_EXP_USER_SW8
0557 };
0558 
0559 static const char * const da850_evm_bb_exp[] = {
0560     [DA850_EVM_BB_EXP_DEEP_SLEEP_EN]    = "deep_sleep_en",
0561     [DA850_EVM_BB_EXP_SW_RST]       = "sw_rst",
0562     [DA850_EVM_BB_EXP_TP_23]        = "tp_23",
0563     [DA850_EVM_BB_EXP_TP_22]        = "tp_22",
0564     [DA850_EVM_BB_EXP_TP_21]        = "tp_21",
0565     [DA850_EVM_BB_EXP_USER_PB1]     = "user_pb1",
0566     [DA850_EVM_BB_EXP_USER_LED2]        = "user_led2",
0567     [DA850_EVM_BB_EXP_USER_LED1]        = "user_led1",
0568     [DA850_EVM_BB_EXP_USER_SW1]     = "user_sw1",
0569     [DA850_EVM_BB_EXP_USER_SW2]     = "user_sw2",
0570     [DA850_EVM_BB_EXP_USER_SW3]     = "user_sw3",
0571     [DA850_EVM_BB_EXP_USER_SW4]     = "user_sw4",
0572     [DA850_EVM_BB_EXP_USER_SW5]     = "user_sw5",
0573     [DA850_EVM_BB_EXP_USER_SW6]     = "user_sw6",
0574     [DA850_EVM_BB_EXP_USER_SW7]     = "user_sw7",
0575     [DA850_EVM_BB_EXP_USER_SW8]     = "user_sw8",
0576 };
0577 
0578 #define DA850_N_BB_USER_SW  8
0579 
0580 static struct gpio_keys_button da850_evm_bb_keys[] = {
0581     [0] = {
0582         .type           = EV_KEY,
0583         .active_low     = 1,
0584         .wakeup         = 0,
0585         .debounce_interval  = DA850_KEYS_DEBOUNCE_MS,
0586         .code           = KEY_PROG1,
0587         .desc           = NULL, /* assigned at runtime */
0588         .gpio           = -1, /* assigned at runtime */
0589     },
0590     [1 ... DA850_N_BB_USER_SW] = {
0591         .type           = EV_SW,
0592         .active_low     = 1,
0593         .wakeup         = 0,
0594         .debounce_interval  = DA850_KEYS_DEBOUNCE_MS,
0595         .code           = -1, /* assigned at runtime */
0596         .desc           = NULL, /* assigned at runtime */
0597         .gpio           = -1, /* assigned at runtime */
0598     },
0599 };
0600 
0601 static struct gpio_keys_platform_data da850_evm_bb_keys_pdata = {
0602     .buttons = da850_evm_bb_keys,
0603     .nbuttons = ARRAY_SIZE(da850_evm_bb_keys),
0604     .poll_interval = DA850_GPIO_KEYS_POLL_MS,
0605 };
0606 
0607 static struct platform_device da850_evm_bb_keys_device = {
0608     .name = "gpio-keys-polled",
0609     .id = 1,
0610     .dev = {
0611         .platform_data = &da850_evm_bb_keys_pdata
0612     },
0613 };
0614 
0615 static void da850_evm_bb_keys_init(unsigned gpio)
0616 {
0617     int i;
0618     struct gpio_keys_button *button;
0619 
0620     button = &da850_evm_bb_keys[0];
0621     button->desc = da850_evm_bb_exp[DA850_EVM_BB_EXP_USER_PB1];
0622     button->gpio = gpio + DA850_EVM_BB_EXP_USER_PB1;
0623 
0624     for (i = 0; i < DA850_N_BB_USER_SW; i++) {
0625         button = &da850_evm_bb_keys[i + 1];
0626         button->code = SW_LID + i;
0627         button->desc = da850_evm_bb_exp[DA850_EVM_BB_EXP_USER_SW1 + i];
0628         button->gpio = gpio + DA850_EVM_BB_EXP_USER_SW1 + i;
0629     }
0630 }
0631 
0632 static struct gpio_led da850_evm_bb_leds[] = {
0633     {
0634         .name = "user_led2",
0635     },
0636     {
0637         .name = "user_led1",
0638     },
0639 };
0640 
0641 static struct gpio_led_platform_data da850_evm_bb_leds_pdata = {
0642     .leds = da850_evm_bb_leds,
0643     .num_leds = ARRAY_SIZE(da850_evm_bb_leds),
0644 };
0645 
0646 static struct gpiod_lookup_table da850_evm_bb_leds_gpio_table = {
0647     .dev_id = "leds-gpio",
0648     .table = {
0649         GPIO_LOOKUP_IDX("i2c-bb-expander",
0650                 DA850_EVM_BB_EXP_USER_LED2, NULL,
0651                 0, GPIO_ACTIVE_LOW),
0652         GPIO_LOOKUP_IDX("i2c-bb-expander",
0653                 DA850_EVM_BB_EXP_USER_LED2 + 1, NULL,
0654                 1, GPIO_ACTIVE_LOW),
0655 
0656         { },
0657     },
0658 };
0659 
0660 static struct platform_device da850_evm_bb_leds_device = {
0661     .name       = "leds-gpio",
0662     .id     = -1,
0663     .dev = {
0664         .platform_data = &da850_evm_bb_leds_pdata
0665     }
0666 };
0667 
0668 static int da850_evm_bb_expander_setup(struct i2c_client *client,
0669                         unsigned gpio, unsigned ngpio,
0670                         void *c)
0671 {
0672     int ret;
0673 
0674     /*
0675      * Register the switches and pushbutton on the baseboard as a gpio-keys
0676      * device.
0677      */
0678     da850_evm_bb_keys_init(gpio);
0679     ret = platform_device_register(&da850_evm_bb_keys_device);
0680     if (ret) {
0681         pr_warn("Could not register baseboard GPIO expander keys");
0682         goto io_exp_setup_sw_fail;
0683     }
0684 
0685     gpiod_add_lookup_table(&da850_evm_bb_leds_gpio_table);
0686     ret = platform_device_register(&da850_evm_bb_leds_device);
0687     if (ret) {
0688         pr_warn("Could not register baseboard GPIO expander LEDs");
0689         goto io_exp_setup_leds_fail;
0690     }
0691 
0692     return 0;
0693 
0694 io_exp_setup_leds_fail:
0695     platform_device_unregister(&da850_evm_bb_keys_device);
0696 io_exp_setup_sw_fail:
0697     return ret;
0698 }
0699 
0700 static int da850_evm_bb_expander_teardown(struct i2c_client *client,
0701                     unsigned gpio, unsigned ngpio, void *c)
0702 {
0703     platform_device_unregister(&da850_evm_bb_leds_device);
0704     platform_device_unregister(&da850_evm_bb_keys_device);
0705 
0706     return 0;
0707 }
0708 
0709 static struct pca953x_platform_data da850_evm_ui_expander_info = {
0710     .gpio_base  = DAVINCI_N_GPIO,
0711     .setup      = da850_evm_ui_expander_setup,
0712     .teardown   = da850_evm_ui_expander_teardown,
0713     .names      = da850_evm_ui_exp,
0714 };
0715 
0716 static struct pca953x_platform_data da850_evm_bb_expander_info = {
0717     .gpio_base  = DA850_BB_EXPANDER_GPIO_BASE,
0718     .setup      = da850_evm_bb_expander_setup,
0719     .teardown   = da850_evm_bb_expander_teardown,
0720     .names      = da850_evm_bb_exp,
0721 };
0722 
0723 static struct i2c_board_info __initdata da850_evm_i2c_devices[] = {
0724     {
0725         I2C_BOARD_INFO("tlv320aic3x", 0x18),
0726     },
0727     {
0728         I2C_BOARD_INFO("tca6416", 0x20),
0729         .dev_name = "ui-expander",
0730         .platform_data = &da850_evm_ui_expander_info,
0731     },
0732     {
0733         I2C_BOARD_INFO("tca6416", 0x21),
0734         .dev_name = "bb-expander",
0735         .platform_data = &da850_evm_bb_expander_info,
0736     },
0737 };
0738 
0739 static struct davinci_i2c_platform_data da850_evm_i2c_0_pdata = {
0740     .bus_freq   = 100,  /* kHz */
0741     .bus_delay  = 0,    /* usec */
0742 };
0743 
0744 /* davinci da850 evm audio machine driver */
0745 static u8 da850_iis_serializer_direction[] = {
0746     INACTIVE_MODE,  INACTIVE_MODE,  INACTIVE_MODE,  INACTIVE_MODE,
0747     INACTIVE_MODE,  INACTIVE_MODE,  INACTIVE_MODE,  INACTIVE_MODE,
0748     INACTIVE_MODE,  INACTIVE_MODE,  INACTIVE_MODE,  TX_MODE,
0749     RX_MODE,    INACTIVE_MODE,  INACTIVE_MODE,  INACTIVE_MODE,
0750 };
0751 
0752 static struct snd_platform_data da850_evm_snd_data = {
0753     .tx_dma_offset      = 0x2000,
0754     .rx_dma_offset      = 0x2000,
0755     .op_mode        = DAVINCI_MCASP_IIS_MODE,
0756     .num_serializer     = ARRAY_SIZE(da850_iis_serializer_direction),
0757     .tdm_slots      = 2,
0758     .serial_dir     = da850_iis_serializer_direction,
0759     .asp_chan_q     = EVENTQ_0,
0760     .ram_chan_q     = EVENTQ_1,
0761     .version        = MCASP_VERSION_2,
0762     .txnumevt       = 1,
0763     .rxnumevt       = 1,
0764     .sram_size_playback = SZ_8K,
0765     .sram_size_capture  = SZ_8K,
0766 };
0767 
0768 static const short da850_evm_mcasp_pins[] __initconst = {
0769     DA850_AHCLKX, DA850_ACLKX, DA850_AFSX,
0770     DA850_AHCLKR, DA850_ACLKR, DA850_AFSR, DA850_AMUTE,
0771     DA850_AXR_11, DA850_AXR_12,
0772     -1
0773 };
0774 
0775 #define DA850_MMCSD_CD_PIN      GPIO_TO_PIN(4, 0)
0776 #define DA850_MMCSD_WP_PIN      GPIO_TO_PIN(4, 1)
0777 
0778 static struct gpiod_lookup_table mmc_gpios_table = {
0779     .dev_id = "da830-mmc.0",
0780     .table = {
0781         /* gpio chip 2 contains gpio range 64-95 */
0782         GPIO_LOOKUP("davinci_gpio", DA850_MMCSD_CD_PIN, "cd",
0783                 GPIO_ACTIVE_LOW),
0784         GPIO_LOOKUP("davinci_gpio", DA850_MMCSD_WP_PIN, "wp",
0785                 GPIO_ACTIVE_HIGH),
0786         { }
0787     },
0788 };
0789 
0790 static struct davinci_mmc_config da850_mmc_config = {
0791     .wires      = 4,
0792     .max_freq   = 50000000,
0793     .caps       = MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED,
0794 };
0795 
0796 static const short da850_evm_mmcsd0_pins[] __initconst = {
0797     DA850_MMCSD0_DAT_0, DA850_MMCSD0_DAT_1, DA850_MMCSD0_DAT_2,
0798     DA850_MMCSD0_DAT_3, DA850_MMCSD0_CLK, DA850_MMCSD0_CMD,
0799     DA850_GPIO4_0, DA850_GPIO4_1,
0800     -1
0801 };
0802 
0803 static struct property_entry da850_lcd_backlight_props[] = {
0804     PROPERTY_ENTRY_BOOL("default-on"),
0805     { }
0806 };
0807 
0808 static struct gpiod_lookup_table da850_lcd_backlight_gpio_table = {
0809     .dev_id     = "gpio-backlight",
0810     .table = {
0811         GPIO_LOOKUP("davinci_gpio", DA850_LCD_BL_PIN, NULL, 0),
0812         { }
0813     },
0814 };
0815 
0816 static const struct platform_device_info da850_lcd_backlight_info = {
0817     .name       = "gpio-backlight",
0818     .id     = PLATFORM_DEVID_NONE,
0819     .properties = da850_lcd_backlight_props,
0820 };
0821 
0822 static struct regulator_consumer_supply da850_lcd_supplies[] = {
0823     REGULATOR_SUPPLY("lcd", NULL),
0824 };
0825 
0826 static struct regulator_init_data da850_lcd_supply_data = {
0827     .consumer_supplies  = da850_lcd_supplies,
0828     .num_consumer_supplies  = ARRAY_SIZE(da850_lcd_supplies),
0829     .constraints    = {
0830         .valid_ops_mask = REGULATOR_CHANGE_STATUS,
0831     },
0832 };
0833 
0834 static struct fixed_voltage_config da850_lcd_supply = {
0835     .supply_name        = "lcd",
0836     .microvolts     = 33000000,
0837     .init_data      = &da850_lcd_supply_data,
0838 };
0839 
0840 static struct platform_device da850_lcd_supply_device = {
0841     .name           = "reg-fixed-voltage",
0842     .id         = 1, /* Dummy fixed regulator is 0 */
0843     .dev            = {
0844         .platform_data = &da850_lcd_supply,
0845     },
0846 };
0847 
0848 static struct gpiod_lookup_table da850_lcd_supply_gpio_table = {
0849     .dev_id         = "reg-fixed-voltage.1",
0850     .table = {
0851         GPIO_LOOKUP("davinci_gpio", DA850_LCD_PWR_PIN, NULL, 0),
0852         { }
0853     },
0854 };
0855 
0856 static struct gpiod_lookup_table *da850_lcd_gpio_lookups[] = {
0857     &da850_lcd_backlight_gpio_table,
0858     &da850_lcd_supply_gpio_table,
0859 };
0860 
0861 static int da850_lcd_hw_init(void)
0862 {
0863     struct platform_device *backlight;
0864     int status;
0865 
0866     gpiod_add_lookup_tables(da850_lcd_gpio_lookups,
0867                 ARRAY_SIZE(da850_lcd_gpio_lookups));
0868 
0869     backlight = platform_device_register_full(&da850_lcd_backlight_info);
0870     if (IS_ERR(backlight))
0871         return PTR_ERR(backlight);
0872 
0873     status = platform_device_register(&da850_lcd_supply_device);
0874     if (status)
0875         return status;
0876 
0877     return 0;
0878 }
0879 
0880 /* Fixed regulator support */
0881 static struct regulator_consumer_supply fixed_supplies[] = {
0882     /* Baseboard 3.3V: 5V -> TPS73701DCQ -> 3.3V */
0883     REGULATOR_SUPPLY("AVDD", "1-0018"),
0884     REGULATOR_SUPPLY("DRVDD", "1-0018"),
0885 
0886     /* Baseboard 1.8V: 5V -> TPS73701DCQ -> 1.8V */
0887     REGULATOR_SUPPLY("DVDD", "1-0018"),
0888 
0889     /* UI card 3.3V: 5V -> TPS73701DCQ -> 3.3V */
0890     REGULATOR_SUPPLY("vcc", "1-0020"),
0891 };
0892 
0893 /* TPS65070 voltage regulator support */
0894 
0895 /* 3.3V */
0896 static struct regulator_consumer_supply tps65070_dcdc1_consumers[] = {
0897     {
0898         .supply = "usb0_vdda33",
0899     },
0900     {
0901         .supply = "usb1_vdda33",
0902     },
0903 };
0904 
0905 /* 3.3V or 1.8V */
0906 static struct regulator_consumer_supply tps65070_dcdc2_consumers[] = {
0907     {
0908         .supply = "dvdd3318_a",
0909     },
0910     {
0911         .supply = "dvdd3318_b",
0912     },
0913     {
0914         .supply = "dvdd3318_c",
0915     },
0916     REGULATOR_SUPPLY("IOVDD", "1-0018"),
0917 };
0918 
0919 /* 1.2V */
0920 static struct regulator_consumer_supply tps65070_dcdc3_consumers[] = {
0921     {
0922         .supply = "cvdd",
0923     },
0924 };
0925 
0926 /* 1.8V LDO */
0927 static struct regulator_consumer_supply tps65070_ldo1_consumers[] = {
0928     {
0929         .supply = "sata_vddr",
0930     },
0931     {
0932         .supply = "usb0_vdda18",
0933     },
0934     {
0935         .supply = "usb1_vdda18",
0936     },
0937     {
0938         .supply = "ddr_dvdd18",
0939     },
0940 };
0941 
0942 /* 1.2V LDO */
0943 static struct regulator_consumer_supply tps65070_ldo2_consumers[] = {
0944     {
0945         .supply = "sata_vdd",
0946     },
0947     {
0948         .supply = "pll0_vdda",
0949     },
0950     {
0951         .supply = "pll1_vdda",
0952     },
0953     {
0954         .supply = "usbs_cvdd",
0955     },
0956     {
0957         .supply = "vddarnwa1",
0958     },
0959 };
0960 
0961 /* We take advantage of the fact that both defdcdc{2,3} are tied high */
0962 static struct tps6507x_reg_platform_data tps6507x_platform_data = {
0963     .defdcdc_default = true,
0964 };
0965 
0966 static struct regulator_init_data tps65070_regulator_data[] = {
0967     /* dcdc1 */
0968     {
0969         .constraints = {
0970             .min_uV = 3150000,
0971             .max_uV = 3450000,
0972             .valid_ops_mask = (REGULATOR_CHANGE_VOLTAGE |
0973                 REGULATOR_CHANGE_STATUS),
0974             .boot_on = 1,
0975         },
0976         .num_consumer_supplies = ARRAY_SIZE(tps65070_dcdc1_consumers),
0977         .consumer_supplies = tps65070_dcdc1_consumers,
0978     },
0979 
0980     /* dcdc2 */
0981     {
0982         .constraints = {
0983             .min_uV = 1710000,
0984             .max_uV = 3450000,
0985             .valid_ops_mask = (REGULATOR_CHANGE_VOLTAGE |
0986                 REGULATOR_CHANGE_STATUS),
0987             .boot_on = 1,
0988             .always_on = 1,
0989         },
0990         .num_consumer_supplies = ARRAY_SIZE(tps65070_dcdc2_consumers),
0991         .consumer_supplies = tps65070_dcdc2_consumers,
0992         .driver_data = &tps6507x_platform_data,
0993     },
0994 
0995     /* dcdc3 */
0996     {
0997         .constraints = {
0998             .min_uV = 950000,
0999             .max_uV = 1350000,
1000             .valid_ops_mask = (REGULATOR_CHANGE_VOLTAGE |
1001                 REGULATOR_CHANGE_STATUS),
1002             .boot_on = 1,
1003         },
1004         .num_consumer_supplies = ARRAY_SIZE(tps65070_dcdc3_consumers),
1005         .consumer_supplies = tps65070_dcdc3_consumers,
1006         .driver_data = &tps6507x_platform_data,
1007     },
1008 
1009     /* ldo1 */
1010     {
1011         .constraints = {
1012             .min_uV = 1710000,
1013             .max_uV = 1890000,
1014             .valid_ops_mask = (REGULATOR_CHANGE_VOLTAGE |
1015                 REGULATOR_CHANGE_STATUS),
1016             .boot_on = 1,
1017         },
1018         .num_consumer_supplies = ARRAY_SIZE(tps65070_ldo1_consumers),
1019         .consumer_supplies = tps65070_ldo1_consumers,
1020     },
1021 
1022     /* ldo2 */
1023     {
1024         .constraints = {
1025             .min_uV = 1140000,
1026             .max_uV = 1320000,
1027             .valid_ops_mask = (REGULATOR_CHANGE_VOLTAGE |
1028                 REGULATOR_CHANGE_STATUS),
1029             .boot_on = 1,
1030         },
1031         .num_consumer_supplies = ARRAY_SIZE(tps65070_ldo2_consumers),
1032         .consumer_supplies = tps65070_ldo2_consumers,
1033     },
1034 };
1035 
1036 static struct touchscreen_init_data tps6507x_touchscreen_data = {
1037     .poll_period =  30, /* ms between touch samples */
1038     .min_pressure = 0x30,   /* minimum pressure to trigger touch */
1039     .vendor = 0,        /* /sys/class/input/input?/id/vendor */
1040     .product = 65070,   /* /sys/class/input/input?/id/product */
1041     .version = 0x100,   /* /sys/class/input/input?/id/version */
1042 };
1043 
1044 static struct tps6507x_board tps_board = {
1045     .tps6507x_pmic_init_data = &tps65070_regulator_data[0],
1046     .tps6507x_ts_init_data = &tps6507x_touchscreen_data,
1047 };
1048 
1049 static struct i2c_board_info __initdata da850_evm_tps65070_info[] = {
1050     {
1051         I2C_BOARD_INFO("tps6507x", 0x48),
1052         .platform_data = &tps_board,
1053     },
1054 };
1055 
1056 static int __init pmic_tps65070_init(void)
1057 {
1058     return i2c_register_board_info(1, da850_evm_tps65070_info,
1059                     ARRAY_SIZE(da850_evm_tps65070_info));
1060 }
1061 
1062 static const short da850_evm_lcdc_pins[] = {
1063     DA850_GPIO2_8, DA850_GPIO2_15,
1064     -1
1065 };
1066 
1067 static const short da850_evm_mii_pins[] = {
1068     DA850_MII_TXEN, DA850_MII_TXCLK, DA850_MII_COL, DA850_MII_TXD_3,
1069     DA850_MII_TXD_2, DA850_MII_TXD_1, DA850_MII_TXD_0, DA850_MII_RXER,
1070     DA850_MII_CRS, DA850_MII_RXCLK, DA850_MII_RXDV, DA850_MII_RXD_3,
1071     DA850_MII_RXD_2, DA850_MII_RXD_1, DA850_MII_RXD_0, DA850_MDIO_CLK,
1072     DA850_MDIO_D,
1073     -1
1074 };
1075 
1076 static const short da850_evm_rmii_pins[] = {
1077     DA850_RMII_TXD_0, DA850_RMII_TXD_1, DA850_RMII_TXEN,
1078     DA850_RMII_CRS_DV, DA850_RMII_RXD_0, DA850_RMII_RXD_1,
1079     DA850_RMII_RXER, DA850_RMII_MHZ_50_CLK, DA850_MDIO_CLK,
1080     DA850_MDIO_D,
1081     -1
1082 };
1083 
1084 static struct gpiod_hog da850_evm_emac_gpio_hogs[] = {
1085     {
1086         .chip_label = "davinci_gpio",
1087         .chip_hwnum = DA850_MII_MDIO_CLKEN_PIN,
1088         .line_name  = "mdio_clk_en",
1089         .lflags     = 0,
1090         /* dflags set in da850_evm_config_emac() */
1091     },
1092     { }
1093 };
1094 
1095 static int __init da850_evm_config_emac(void)
1096 {
1097     void __iomem *cfg_chip3_base;
1098     int ret;
1099     u32 val;
1100     struct davinci_soc_info *soc_info = &davinci_soc_info;
1101     u8 rmii_en;
1102 
1103     if (!machine_is_davinci_da850_evm())
1104         return 0;
1105 
1106     rmii_en = soc_info->emac_pdata->rmii_en;
1107 
1108     cfg_chip3_base = DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP3_REG);
1109 
1110     val = __raw_readl(cfg_chip3_base);
1111 
1112     if (rmii_en) {
1113         val |= BIT(8);
1114         ret = davinci_cfg_reg_list(da850_evm_rmii_pins);
1115         pr_info("EMAC: RMII PHY configured, MII PHY will not be"
1116                             " functional\n");
1117     } else {
1118         val &= ~BIT(8);
1119         ret = davinci_cfg_reg_list(da850_evm_mii_pins);
1120         pr_info("EMAC: MII PHY configured, RMII PHY will not be"
1121                             " functional\n");
1122     }
1123 
1124     if (ret)
1125         pr_warn("%s: CPGMAC/RMII mux setup failed: %d\n",
1126             __func__, ret);
1127 
1128     /* configure the CFGCHIP3 register for RMII or MII */
1129     __raw_writel(val, cfg_chip3_base);
1130 
1131     ret = davinci_cfg_reg(DA850_GPIO2_6);
1132     if (ret)
1133         pr_warn("%s:GPIO(2,6) mux setup failed\n", __func__);
1134 
1135     da850_evm_emac_gpio_hogs[0].dflags = rmii_en ? GPIOD_OUT_HIGH
1136                              : GPIOD_OUT_LOW;
1137     gpiod_add_hogs(da850_evm_emac_gpio_hogs);
1138 
1139     soc_info->emac_pdata->phy_id = DA850_EVM_PHY_ID;
1140 
1141     ret = da8xx_register_emac();
1142     if (ret)
1143         pr_warn("%s: EMAC registration failed: %d\n", __func__, ret);
1144 
1145     return 0;
1146 }
1147 device_initcall(da850_evm_config_emac);
1148 
1149 /*
1150  * The following EDMA channels/slots are not being used by drivers (for
1151  * example: Timer, GPIO, UART events etc) on da850/omap-l138 EVM, hence
1152  * they are being reserved for codecs on the DSP side.
1153  */
1154 static const s16 da850_dma0_rsv_chans[][2] = {
1155     /* (offset, number) */
1156     { 8,  6},
1157     {24,  4},
1158     {30,  2},
1159     {-1, -1}
1160 };
1161 
1162 static const s16 da850_dma0_rsv_slots[][2] = {
1163     /* (offset, number) */
1164     { 8,  6},
1165     {24,  4},
1166     {30, 50},
1167     {-1, -1}
1168 };
1169 
1170 static const s16 da850_dma1_rsv_chans[][2] = {
1171     /* (offset, number) */
1172     { 0, 28},
1173     {30,  2},
1174     {-1, -1}
1175 };
1176 
1177 static const s16 da850_dma1_rsv_slots[][2] = {
1178     /* (offset, number) */
1179     { 0, 28},
1180     {30, 90},
1181     {-1, -1}
1182 };
1183 
1184 static struct edma_rsv_info da850_edma_cc0_rsv = {
1185     .rsv_chans  = da850_dma0_rsv_chans,
1186     .rsv_slots  = da850_dma0_rsv_slots,
1187 };
1188 
1189 static struct edma_rsv_info da850_edma_cc1_rsv = {
1190     .rsv_chans  = da850_dma1_rsv_chans,
1191     .rsv_slots  = da850_dma1_rsv_slots,
1192 };
1193 
1194 static struct edma_rsv_info *da850_edma_rsv[2] = {
1195     &da850_edma_cc0_rsv,
1196     &da850_edma_cc1_rsv,
1197 };
1198 
1199 #ifdef CONFIG_CPU_FREQ
1200 static __init int da850_evm_init_cpufreq(void)
1201 {
1202     switch (system_rev & 0xF) {
1203     case 3:
1204         da850_max_speed = 456000;
1205         break;
1206     case 2:
1207         da850_max_speed = 408000;
1208         break;
1209     case 1:
1210         da850_max_speed = 372000;
1211         break;
1212     }
1213 
1214     return da850_register_cpufreq("pll0_sysclk3");
1215 }
1216 #else
1217 static __init int da850_evm_init_cpufreq(void) { return 0; }
1218 #endif
1219 
1220 #if defined(CONFIG_DA850_UI_SD_VIDEO_PORT)
1221 
1222 #define TVP5147_CH0     "tvp514x-0"
1223 #define TVP5147_CH1     "tvp514x-1"
1224 
1225 /* VPIF capture configuration */
1226 static struct tvp514x_platform_data tvp5146_pdata = {
1227         .clk_polarity = 0,
1228         .hs_polarity  = 1,
1229         .vs_polarity  = 1,
1230 };
1231 
1232 #define TVP514X_STD_ALL (V4L2_STD_NTSC | V4L2_STD_PAL)
1233 
1234 static struct vpif_input da850_ch0_inputs[] = {
1235     {
1236         .input = {
1237             .index = 0,
1238             .name  = "Composite",
1239             .type  = V4L2_INPUT_TYPE_CAMERA,
1240             .capabilities = V4L2_IN_CAP_STD,
1241             .std   = TVP514X_STD_ALL,
1242         },
1243         .input_route = INPUT_CVBS_VI2B,
1244         .output_route = OUTPUT_10BIT_422_EMBEDDED_SYNC,
1245         .subdev_name = TVP5147_CH0,
1246     },
1247 };
1248 
1249 static struct vpif_input da850_ch1_inputs[] = {
1250     {
1251         .input = {
1252             .index = 0,
1253             .name  = "S-Video",
1254             .type  = V4L2_INPUT_TYPE_CAMERA,
1255             .capabilities = V4L2_IN_CAP_STD,
1256             .std   = TVP514X_STD_ALL,
1257         },
1258         .input_route = INPUT_SVIDEO_VI2C_VI1C,
1259         .output_route = OUTPUT_10BIT_422_EMBEDDED_SYNC,
1260         .subdev_name = TVP5147_CH1,
1261     },
1262 };
1263 
1264 static struct vpif_subdev_info da850_vpif_capture_sdev_info[] = {
1265     {
1266         .name = TVP5147_CH0,
1267         .board_info = {
1268             I2C_BOARD_INFO("tvp5146", 0x5d),
1269             .platform_data = &tvp5146_pdata,
1270         },
1271     },
1272     {
1273         .name = TVP5147_CH1,
1274         .board_info = {
1275             I2C_BOARD_INFO("tvp5146", 0x5c),
1276             .platform_data = &tvp5146_pdata,
1277         },
1278     },
1279 };
1280 
1281 static struct vpif_capture_config da850_vpif_capture_config = {
1282     .subdev_info = da850_vpif_capture_sdev_info,
1283     .subdev_count = ARRAY_SIZE(da850_vpif_capture_sdev_info),
1284     .i2c_adapter_id = 1,
1285     .chan_config[0] = {
1286         .inputs = da850_ch0_inputs,
1287         .input_count = ARRAY_SIZE(da850_ch0_inputs),
1288         .vpif_if = {
1289             .if_type = VPIF_IF_BT656,
1290             .hd_pol  = 1,
1291             .vd_pol  = 1,
1292             .fid_pol = 0,
1293         },
1294     },
1295     .chan_config[1] = {
1296         .inputs = da850_ch1_inputs,
1297         .input_count = ARRAY_SIZE(da850_ch1_inputs),
1298         .vpif_if = {
1299             .if_type = VPIF_IF_BT656,
1300             .hd_pol  = 1,
1301             .vd_pol  = 1,
1302             .fid_pol = 0,
1303         },
1304     },
1305     .card_name = "DA850/OMAP-L138 Video Capture",
1306 };
1307 
1308 /* VPIF display configuration */
1309 
1310 static struct adv7343_platform_data adv7343_pdata = {
1311     .mode_config = {
1312         .dac = { 1, 1, 1 },
1313     },
1314     .sd_config = {
1315         .sd_dac_out = { 1 },
1316     },
1317 };
1318 
1319 static struct vpif_subdev_info da850_vpif_subdev[] = {
1320     {
1321         .name = "adv7343",
1322         .board_info = {
1323             I2C_BOARD_INFO("adv7343", 0x2a),
1324             .platform_data = &adv7343_pdata,
1325         },
1326     },
1327 };
1328 
1329 static const struct vpif_output da850_ch0_outputs[] = {
1330     {
1331         .output = {
1332             .index = 0,
1333             .name = "Composite",
1334             .type = V4L2_OUTPUT_TYPE_ANALOG,
1335             .capabilities = V4L2_OUT_CAP_STD,
1336             .std = V4L2_STD_ALL,
1337         },
1338         .subdev_name = "adv7343",
1339         .output_route = ADV7343_COMPOSITE_ID,
1340     },
1341     {
1342         .output = {
1343             .index = 1,
1344             .name = "S-Video",
1345             .type = V4L2_OUTPUT_TYPE_ANALOG,
1346             .capabilities = V4L2_OUT_CAP_STD,
1347             .std = V4L2_STD_ALL,
1348         },
1349         .subdev_name = "adv7343",
1350         .output_route = ADV7343_SVIDEO_ID,
1351     },
1352 };
1353 
1354 static struct vpif_display_config da850_vpif_display_config = {
1355     .subdevinfo   = da850_vpif_subdev,
1356     .subdev_count = ARRAY_SIZE(da850_vpif_subdev),
1357     .chan_config[0] = {
1358         .outputs = da850_ch0_outputs,
1359         .output_count = ARRAY_SIZE(da850_ch0_outputs),
1360     },
1361     .card_name    = "DA850/OMAP-L138 Video Display",
1362     .i2c_adapter_id = 1,
1363 };
1364 
1365 static __init void da850_vpif_init(void)
1366 {
1367     int ret;
1368 
1369     ret = da850_register_vpif();
1370     if (ret)
1371         pr_warn("da850_evm_init: VPIF setup failed: %d\n", ret);
1372 
1373     ret = davinci_cfg_reg_list(da850_vpif_capture_pins);
1374     if (ret)
1375         pr_warn("da850_evm_init: VPIF capture mux setup failed: %d\n",
1376             ret);
1377 
1378     ret = da850_register_vpif_capture(&da850_vpif_capture_config);
1379     if (ret)
1380         pr_warn("da850_evm_init: VPIF capture setup failed: %d\n", ret);
1381 
1382     ret = davinci_cfg_reg_list(da850_vpif_display_pins);
1383     if (ret)
1384         pr_warn("da850_evm_init: VPIF display mux setup failed: %d\n",
1385             ret);
1386 
1387     ret = da850_register_vpif_display(&da850_vpif_display_config);
1388     if (ret)
1389         pr_warn("da850_evm_init: VPIF display setup failed: %d\n", ret);
1390 }
1391 
1392 #else
1393 static __init void da850_vpif_init(void) {}
1394 #endif
1395 
1396 #define DA850EVM_SATA_REFCLKPN_RATE (100 * 1000 * 1000)
1397 
1398 static __init void da850_evm_init(void)
1399 {
1400     int ret;
1401 
1402     da850_register_clocks();
1403 
1404     ret = da850_register_gpio();
1405     if (ret)
1406         pr_warn("%s: GPIO init failed: %d\n", __func__, ret);
1407 
1408     regulator_register_fixed(0, fixed_supplies, ARRAY_SIZE(fixed_supplies));
1409 
1410     ret = pmic_tps65070_init();
1411     if (ret)
1412         pr_warn("%s: TPS65070 PMIC init failed: %d\n", __func__, ret);
1413 
1414     ret = da850_register_edma(da850_edma_rsv);
1415     if (ret)
1416         pr_warn("%s: EDMA registration failed: %d\n", __func__, ret);
1417 
1418     ret = davinci_cfg_reg_list(da850_i2c0_pins);
1419     if (ret)
1420         pr_warn("%s: I2C0 mux setup failed: %d\n", __func__, ret);
1421 
1422     ret = da8xx_register_i2c(0, &da850_evm_i2c_0_pdata);
1423     if (ret)
1424         pr_warn("%s: I2C0 registration failed: %d\n", __func__, ret);
1425 
1426 
1427     ret = da8xx_register_watchdog();
1428     if (ret)
1429         pr_warn("%s: watchdog registration failed: %d\n",
1430             __func__, ret);
1431 
1432     if (HAS_MMC) {
1433         ret = davinci_cfg_reg_list(da850_evm_mmcsd0_pins);
1434         if (ret)
1435             pr_warn("%s: MMCSD0 mux setup failed: %d\n",
1436                 __func__, ret);
1437 
1438         gpiod_add_lookup_table(&mmc_gpios_table);
1439 
1440         ret = da8xx_register_mmcsd0(&da850_mmc_config);
1441         if (ret)
1442             pr_warn("%s: MMCSD0 registration failed: %d\n",
1443                 __func__, ret);
1444     }
1445 
1446     davinci_serial_init(da8xx_serial_device);
1447 
1448     nvmem_add_cell_table(&da850evm_nvmem_cell_table);
1449     nvmem_add_cell_lookups(&da850evm_nvmem_cell_lookup, 1);
1450 
1451     i2c_register_board_info(1, da850_evm_i2c_devices,
1452             ARRAY_SIZE(da850_evm_i2c_devices));
1453 
1454     /*
1455      * shut down uart 0 and 1; they are not used on the board and
1456      * accessing them causes endless "too much work in irq53" messages
1457      * with arago fs
1458      */
1459     __raw_writel(0, IO_ADDRESS(DA8XX_UART1_BASE) + 0x30);
1460     __raw_writel(0, IO_ADDRESS(DA8XX_UART0_BASE) + 0x30);
1461 
1462     ret = davinci_cfg_reg_list(da850_evm_mcasp_pins);
1463     if (ret)
1464         pr_warn("%s: McASP mux setup failed: %d\n", __func__, ret);
1465 
1466     da850_evm_snd_data.sram_pool = sram_get_gen_pool();
1467     da8xx_register_mcasp(0, &da850_evm_snd_data);
1468 
1469     ret = davinci_cfg_reg_list(da850_lcdcntl_pins);
1470     if (ret)
1471         pr_warn("%s: LCDC mux setup failed: %d\n", __func__, ret);
1472 
1473     ret = da8xx_register_uio_pruss();
1474     if (ret)
1475         pr_warn("da850_evm_init: pruss initialization failed: %d\n",
1476                 ret);
1477 
1478     /* Handle board specific muxing for LCD here */
1479     ret = davinci_cfg_reg_list(da850_evm_lcdc_pins);
1480     if (ret)
1481         pr_warn("%s: EVM specific LCD mux setup failed: %d\n",
1482             __func__, ret);
1483 
1484     ret = da850_lcd_hw_init();
1485     if (ret)
1486         pr_warn("%s: LCD initialization failed: %d\n", __func__, ret);
1487 
1488     ret = da8xx_register_lcdc(&sharp_lk043t1dg01_pdata);
1489     if (ret)
1490         pr_warn("%s: LCDC registration failed: %d\n", __func__, ret);
1491 
1492     ret = da8xx_register_rtc();
1493     if (ret)
1494         pr_warn("%s: RTC setup failed: %d\n", __func__, ret);
1495 
1496     ret = da850_evm_init_cpufreq();
1497     if (ret)
1498         pr_warn("%s: cpufreq registration failed: %d\n", __func__, ret);
1499 
1500     ret = da8xx_register_cpuidle();
1501     if (ret)
1502         pr_warn("%s: cpuidle registration failed: %d\n", __func__, ret);
1503 
1504     davinci_pm_init();
1505     da850_vpif_init();
1506 
1507     ret = spi_register_board_info(da850evm_spi_info,
1508                       ARRAY_SIZE(da850evm_spi_info));
1509     if (ret)
1510         pr_warn("%s: spi info registration failed: %d\n", __func__,
1511             ret);
1512 
1513     ret = da8xx_register_spi_bus(1, ARRAY_SIZE(da850evm_spi_info));
1514     if (ret)
1515         pr_warn("%s: SPI 1 registration failed: %d\n", __func__, ret);
1516 
1517     ret = da850_register_sata(DA850EVM_SATA_REFCLKPN_RATE);
1518     if (ret)
1519         pr_warn("%s: SATA registration failed: %d\n", __func__, ret);
1520 
1521     ret = da8xx_register_rproc();
1522     if (ret)
1523         pr_warn("%s: dsp/rproc registration failed: %d\n",
1524             __func__, ret);
1525 
1526     regulator_has_full_constraints();
1527 }
1528 
1529 #ifdef CONFIG_SERIAL_8250_CONSOLE
1530 static int __init da850_evm_console_init(void)
1531 {
1532     if (!machine_is_davinci_da850_evm())
1533         return 0;
1534 
1535     return add_preferred_console("ttyS", 2, "115200");
1536 }
1537 console_initcall(da850_evm_console_init);
1538 #endif
1539 
1540 static void __init da850_evm_map_io(void)
1541 {
1542     da850_init();
1543 }
1544 
1545 MACHINE_START(DAVINCI_DA850_EVM, "DaVinci DA850/OMAP-L138/AM18x EVM")
1546     .atag_offset    = 0x100,
1547     .map_io     = da850_evm_map_io,
1548     .init_irq   = da850_init_irq,
1549     .init_time  = da850_init_time,
1550     .init_machine   = da850_evm_init,
1551     .init_late  = davinci_init_late,
1552     .dma_zone_size  = SZ_128M,
1553     .reserve    = da8xx_rproc_reserve_cma,
1554 MACHINE_END