16a08e1e6STony Lindgren /* 26a08e1e6STony Lindgren * Legacy platform_data quirks 36a08e1e6STony Lindgren * 46a08e1e6STony Lindgren * Copyright (C) 2013 Texas Instruments 56a08e1e6STony Lindgren * 66a08e1e6STony Lindgren * This program is free software; you can redistribute it and/or modify 76a08e1e6STony Lindgren * it under the terms of the GNU General Public License version 2 as 86a08e1e6STony Lindgren * published by the Free Software Foundation. 96a08e1e6STony Lindgren */ 106a08e1e6STony Lindgren #include <linux/clk.h> 115f0a2c69STony Lindgren #include <linux/gpio.h> 126a08e1e6STony Lindgren #include <linux/init.h> 136a08e1e6STony Lindgren #include <linux/kernel.h> 148651bd8cSTony Lindgren #include <linux/of_platform.h> 155f0a2c69STony Lindgren #include <linux/wl12xx.h> 166a08e1e6STony Lindgren 1730a69ef7STony Lindgren #include <linux/platform_data/pinctrl-single.h> 1830a69ef7STony Lindgren 196a08e1e6STony Lindgren #include "common.h" 206a08e1e6STony Lindgren #include "common-board-devices.h" 216a08e1e6STony Lindgren #include "dss-common.h" 22faf4bd47SAaro Koskinen #include "control.h" 236a08e1e6STony Lindgren 246a08e1e6STony Lindgren struct pdata_init { 256a08e1e6STony Lindgren const char *compatible; 266a08e1e6STony Lindgren void (*fn)(void); 276a08e1e6STony Lindgren }; 286a08e1e6STony Lindgren 29*fa590c92STony Lindgren struct of_dev_auxdata omap_auxdata_lookup[]; 30*fa590c92STony Lindgren 313e7a3185STony Lindgren /* 323e7a3185STony Lindgren * Create alias for USB host PHY clock. 333e7a3185STony Lindgren * Remove this when clock phandle can be provided via DT 343e7a3185STony Lindgren */ 353e7a3185STony Lindgren static void __init __used legacy_init_ehci_clk(char *clkname) 363e7a3185STony Lindgren { 373e7a3185STony Lindgren int ret; 383e7a3185STony Lindgren 393e7a3185STony Lindgren ret = clk_add_alias("main_clk", NULL, clkname, NULL); 403e7a3185STony Lindgren if (ret) 413e7a3185STony Lindgren pr_err("%s:Failed to add main_clk alias to %s :%d\n", 423e7a3185STony Lindgren __func__, clkname, ret); 433e7a3185STony Lindgren } 443e7a3185STony Lindgren 455f0a2c69STony Lindgren #if IS_ENABLED(CONFIG_WL12XX) 465f0a2c69STony Lindgren 475f0a2c69STony Lindgren static struct wl12xx_platform_data wl12xx __initdata; 485f0a2c69STony Lindgren 495f0a2c69STony Lindgren static void __init __used legacy_init_wl12xx(unsigned ref_clock, 505f0a2c69STony Lindgren unsigned tcxo_clock, 515f0a2c69STony Lindgren int gpio) 525f0a2c69STony Lindgren { 535f0a2c69STony Lindgren int res; 545f0a2c69STony Lindgren 555f0a2c69STony Lindgren wl12xx.board_ref_clock = ref_clock; 565f0a2c69STony Lindgren wl12xx.board_tcxo_clock = tcxo_clock; 575f0a2c69STony Lindgren wl12xx.irq = gpio_to_irq(gpio); 585f0a2c69STony Lindgren 595f0a2c69STony Lindgren res = wl12xx_set_platform_data(&wl12xx); 605f0a2c69STony Lindgren if (res) { 615f0a2c69STony Lindgren pr_err("error setting wl12xx data: %d\n", res); 625f0a2c69STony Lindgren return; 635f0a2c69STony Lindgren } 645f0a2c69STony Lindgren } 655f0a2c69STony Lindgren #else 665f0a2c69STony Lindgren static inline void legacy_init_wl12xx(unsigned ref_clock, 675f0a2c69STony Lindgren unsigned tcxo_clock, 685f0a2c69STony Lindgren int gpio) 695f0a2c69STony Lindgren { 705f0a2c69STony Lindgren } 715f0a2c69STony Lindgren #endif 725f0a2c69STony Lindgren 73*fa590c92STony Lindgren #ifdef CONFIG_MACH_NOKIA_N8X0 74*fa590c92STony Lindgren static void __init omap2420_n8x0_legacy_init(void) 75*fa590c92STony Lindgren { 76*fa590c92STony Lindgren omap_auxdata_lookup[0].platform_data = n8x0_legacy_init(); 77*fa590c92STony Lindgren } 78*fa590c92STony Lindgren #else 79*fa590c92STony Lindgren #define omap2420_n8x0_legacy_init NULL 80*fa590c92STony Lindgren #endif 81*fa590c92STony Lindgren 82faf4bd47SAaro Koskinen #ifdef CONFIG_ARCH_OMAP3 83faf4bd47SAaro Koskinen static void __init hsmmc2_internal_input_clk(void) 84faf4bd47SAaro Koskinen { 85faf4bd47SAaro Koskinen u32 reg; 86faf4bd47SAaro Koskinen 87faf4bd47SAaro Koskinen reg = omap_ctrl_readl(OMAP343X_CONTROL_DEVCONF1); 88faf4bd47SAaro Koskinen reg |= OMAP2_MMCSDIO2ADPCLKISEL; 89faf4bd47SAaro Koskinen omap_ctrl_writel(reg, OMAP343X_CONTROL_DEVCONF1); 90faf4bd47SAaro Koskinen } 9115c9887eSJavier Martinez Canillas 9215c9887eSJavier Martinez Canillas static void __init omap3_igep0020_legacy_init(void) 9315c9887eSJavier Martinez Canillas { 9415c9887eSJavier Martinez Canillas omap3_igep2_display_init_of(); 9515c9887eSJavier Martinez Canillas } 9679b39f79STony Lindgren 9779b39f79STony Lindgren static void __init omap3_evm_legacy_init(void) 9879b39f79STony Lindgren { 9979b39f79STony Lindgren legacy_init_wl12xx(WL12XX_REFCLOCK_38, 0, 149); 10079b39f79STony Lindgren } 10179b39f79STony Lindgren 10279b39f79STony Lindgren static void __init omap3_zoom_legacy_init(void) 10379b39f79STony Lindgren { 10479b39f79STony Lindgren legacy_init_wl12xx(WL12XX_REFCLOCK_26, 0, 162); 10579b39f79STony Lindgren } 106faf4bd47SAaro Koskinen #endif /* CONFIG_ARCH_OMAP3 */ 107faf4bd47SAaro Koskinen 1083e7a3185STony Lindgren #ifdef CONFIG_ARCH_OMAP4 1093e7a3185STony Lindgren static void __init omap4_sdp_legacy_init(void) 1103e7a3185STony Lindgren { 1113e7a3185STony Lindgren omap_4430sdp_display_init_of(); 1125f0a2c69STony Lindgren legacy_init_wl12xx(WL12XX_REFCLOCK_26, 1135f0a2c69STony Lindgren WL12XX_TCXOCLOCK_26, 53); 1143e7a3185STony Lindgren } 1153e7a3185STony Lindgren 1163e7a3185STony Lindgren static void __init omap4_panda_legacy_init(void) 1173e7a3185STony Lindgren { 1183e7a3185STony Lindgren omap4_panda_display_init_of(); 1193e7a3185STony Lindgren legacy_init_ehci_clk("auxclk3_ck"); 1205f0a2c69STony Lindgren legacy_init_wl12xx(WL12XX_REFCLOCK_38, 0, 53); 1213e7a3185STony Lindgren } 1223e7a3185STony Lindgren #endif 1233e7a3185STony Lindgren 1243e7a3185STony Lindgren #ifdef CONFIG_SOC_OMAP5 1253e7a3185STony Lindgren static void __init omap5_uevm_legacy_init(void) 1263e7a3185STony Lindgren { 1273e7a3185STony Lindgren legacy_init_ehci_clk("auxclk1_ck"); 1283e7a3185STony Lindgren } 1293e7a3185STony Lindgren #endif 1303e7a3185STony Lindgren 13130a69ef7STony Lindgren static struct pcs_pdata pcs_pdata; 13230a69ef7STony Lindgren 13330a69ef7STony Lindgren void omap_pcs_legacy_init(int irq, void (*rearm)(void)) 13430a69ef7STony Lindgren { 13530a69ef7STony Lindgren pcs_pdata.irq = irq; 13630a69ef7STony Lindgren pcs_pdata.rearm = rearm; 13730a69ef7STony Lindgren } 13830a69ef7STony Lindgren 139036582f7STony Lindgren /* 140036582f7STony Lindgren * Few boards still need auxdata populated before we populate 141036582f7STony Lindgren * the dev entries in of_platform_populate(). 142036582f7STony Lindgren */ 143036582f7STony Lindgren static struct pdata_init auxdata_quirks[] __initdata = { 144*fa590c92STony Lindgren #ifdef CONFIG_SOC_OMAP2420 145*fa590c92STony Lindgren { "nokia,n800", omap2420_n8x0_legacy_init, }, 146*fa590c92STony Lindgren { "nokia,n810", omap2420_n8x0_legacy_init, }, 147*fa590c92STony Lindgren { "nokia,n810-wimax", omap2420_n8x0_legacy_init, }, 148*fa590c92STony Lindgren #endif 149036582f7STony Lindgren { /* sentinel */ }, 150036582f7STony Lindgren }; 151036582f7STony Lindgren 1528651bd8cSTony Lindgren struct of_dev_auxdata omap_auxdata_lookup[] __initdata = { 153036582f7STony Lindgren #ifdef CONFIG_MACH_NOKIA_N8X0 154036582f7STony Lindgren OF_DEV_AUXDATA("ti,omap2420-mmc", 0x4809c000, "mmci-omap.0", NULL), 155036582f7STony Lindgren #endif 15630a69ef7STony Lindgren #ifdef CONFIG_ARCH_OMAP3 15730a69ef7STony Lindgren OF_DEV_AUXDATA("ti,omap3-padconf", 0x48002030, "48002030.pinmux", &pcs_pdata), 15830a69ef7STony Lindgren OF_DEV_AUXDATA("ti,omap3-padconf", 0x48002a00, "48002a00.pinmux", &pcs_pdata), 15930a69ef7STony Lindgren #endif 16030a69ef7STony Lindgren #ifdef CONFIG_ARCH_OMAP4 16130a69ef7STony Lindgren OF_DEV_AUXDATA("ti,omap4-padconf", 0x4a100040, "4a100040.pinmux", &pcs_pdata), 16230a69ef7STony Lindgren OF_DEV_AUXDATA("ti,omap4-padconf", 0x4a31e040, "4a31e040.pinmux", &pcs_pdata), 16330a69ef7STony Lindgren #endif 1648651bd8cSTony Lindgren { /* sentinel */ }, 1658651bd8cSTony Lindgren }; 1668651bd8cSTony Lindgren 167036582f7STony Lindgren /* 168036582f7STony Lindgren * Few boards still need to initialize some legacy devices with 169036582f7STony Lindgren * platform data until the drivers support device tree. 170036582f7STony Lindgren */ 1716a08e1e6STony Lindgren static struct pdata_init pdata_quirks[] __initdata = { 172faf4bd47SAaro Koskinen #ifdef CONFIG_ARCH_OMAP3 173edd5eb4eSTony Lindgren { "nokia,omap3-n900", hsmmc2_internal_input_clk, }, 174faf4bd47SAaro Koskinen { "nokia,omap3-n9", hsmmc2_internal_input_clk, }, 175faf4bd47SAaro Koskinen { "nokia,omap3-n950", hsmmc2_internal_input_clk, }, 17615c9887eSJavier Martinez Canillas { "isee,omap3-igep0020", omap3_igep0020_legacy_init, }, 17779b39f79STony Lindgren { "ti,omap3-evm-37xx", omap3_evm_legacy_init, }, 17879b39f79STony Lindgren { "ti,omap3-zoom3", omap3_zoom_legacy_init, }, 179faf4bd47SAaro Koskinen #endif 1803e7a3185STony Lindgren #ifdef CONFIG_ARCH_OMAP4 1813e7a3185STony Lindgren { "ti,omap4-sdp", omap4_sdp_legacy_init, }, 1823e7a3185STony Lindgren { "ti,omap4-panda", omap4_panda_legacy_init, }, 1833e7a3185STony Lindgren #endif 1843e7a3185STony Lindgren #ifdef CONFIG_SOC_OMAP5 1853e7a3185STony Lindgren { "ti,omap5-uevm", omap5_uevm_legacy_init, }, 1863e7a3185STony Lindgren #endif 1876a08e1e6STony Lindgren { /* sentinel */ }, 1886a08e1e6STony Lindgren }; 1896a08e1e6STony Lindgren 190036582f7STony Lindgren static void pdata_quirks_check(struct pdata_init *quirks) 1916a08e1e6STony Lindgren { 1926a08e1e6STony Lindgren while (quirks->compatible) { 1936a08e1e6STony Lindgren if (of_machine_is_compatible(quirks->compatible)) { 1946a08e1e6STony Lindgren if (quirks->fn) 1956a08e1e6STony Lindgren quirks->fn(); 1966a08e1e6STony Lindgren break; 1976a08e1e6STony Lindgren } 1986a08e1e6STony Lindgren quirks++; 1996a08e1e6STony Lindgren } 2006a08e1e6STony Lindgren } 201036582f7STony Lindgren 202036582f7STony Lindgren void __init pdata_quirks_init(struct of_device_id *omap_dt_match_table) 203036582f7STony Lindgren { 204036582f7STony Lindgren omap_sdrc_init(NULL, NULL); 205036582f7STony Lindgren pdata_quirks_check(auxdata_quirks); 206036582f7STony Lindgren of_platform_populate(NULL, omap_dt_match_table, 207036582f7STony Lindgren omap_auxdata_lookup, NULL); 208036582f7STony Lindgren pdata_quirks_check(pdata_quirks); 209036582f7STony Lindgren } 210