pdata-quirks.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. /*
  2. * Legacy platform_data quirks
  3. *
  4. * Copyright (C) 2013 Texas Instruments
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/clk.h>
  11. #include <linux/davinci_emac.h>
  12. #include <linux/gpio.h>
  13. #include <linux/init.h>
  14. #include <linux/kernel.h>
  15. #include <linux/of_platform.h>
  16. #include <linux/wl12xx.h>
  17. #include <linux/platform_data/pinctrl-single.h>
  18. #include "am35xx.h"
  19. #include "common.h"
  20. #include "common-board-devices.h"
  21. #include "dss-common.h"
  22. #include "control.h"
  23. #include "omap-secure.h"
  24. #include "soc.h"
  25. struct pdata_init {
  26. const char *compatible;
  27. void (*fn)(void);
  28. };
  29. struct of_dev_auxdata omap_auxdata_lookup[];
  30. static struct twl4030_gpio_platform_data twl_gpio_auxdata;
  31. /*
  32. * Create alias for USB host PHY clock.
  33. * Remove this when clock phandle can be provided via DT
  34. */
  35. static void __init __used legacy_init_ehci_clk(char *clkname)
  36. {
  37. int ret;
  38. ret = clk_add_alias("main_clk", NULL, clkname, NULL);
  39. if (ret)
  40. pr_err("%s:Failed to add main_clk alias to %s :%d\n",
  41. __func__, clkname, ret);
  42. }
  43. #if IS_ENABLED(CONFIG_WL12XX)
  44. static struct wl12xx_platform_data wl12xx __initdata;
  45. static void __init __used legacy_init_wl12xx(unsigned ref_clock,
  46. unsigned tcxo_clock,
  47. int gpio)
  48. {
  49. int res;
  50. wl12xx.board_ref_clock = ref_clock;
  51. wl12xx.board_tcxo_clock = tcxo_clock;
  52. wl12xx.irq = gpio_to_irq(gpio);
  53. res = wl12xx_set_platform_data(&wl12xx);
  54. if (res) {
  55. pr_err("error setting wl12xx data: %d\n", res);
  56. return;
  57. }
  58. }
  59. #else
  60. static inline void legacy_init_wl12xx(unsigned ref_clock,
  61. unsigned tcxo_clock,
  62. int gpio)
  63. {
  64. }
  65. #endif
  66. #ifdef CONFIG_MACH_NOKIA_N8X0
  67. static void __init omap2420_n8x0_legacy_init(void)
  68. {
  69. omap_auxdata_lookup[0].platform_data = n8x0_legacy_init();
  70. }
  71. #else
  72. #define omap2420_n8x0_legacy_init NULL
  73. #endif
  74. #ifdef CONFIG_ARCH_OMAP3
  75. static void __init hsmmc2_internal_input_clk(void)
  76. {
  77. u32 reg;
  78. reg = omap_ctrl_readl(OMAP343X_CONTROL_DEVCONF1);
  79. reg |= OMAP2_MMCSDIO2ADPCLKISEL;
  80. omap_ctrl_writel(reg, OMAP343X_CONTROL_DEVCONF1);
  81. }
  82. static int omap3_sbc_t3730_twl_callback(struct device *dev,
  83. unsigned gpio,
  84. unsigned ngpio)
  85. {
  86. int res;
  87. res = gpio_request_one(gpio + 2, GPIOF_OUT_INIT_HIGH,
  88. "wlan rst");
  89. if (res)
  90. return res;
  91. gpio_export(gpio, 0);
  92. return 0;
  93. }
  94. static void __init omap3_sbc_t3730_twl_init(void)
  95. {
  96. twl_gpio_auxdata.setup = omap3_sbc_t3730_twl_callback;
  97. }
  98. static void __init omap3_sbc_t3730_legacy_init(void)
  99. {
  100. legacy_init_wl12xx(WL12XX_REFCLOCK_38, 0, 136);
  101. omap_ads7846_init(1, 57, 0, NULL);
  102. }
  103. static void __init omap3_igep0020_legacy_init(void)
  104. {
  105. omap3_igep2_display_init_of();
  106. }
  107. static void __init omap3_evm_legacy_init(void)
  108. {
  109. legacy_init_wl12xx(WL12XX_REFCLOCK_38, 0, 149);
  110. }
  111. static void __init omap3_zoom_legacy_init(void)
  112. {
  113. legacy_init_wl12xx(WL12XX_REFCLOCK_26, 0, 162);
  114. }
  115. static void am35xx_enable_emac_int(void)
  116. {
  117. u32 v;
  118. v = omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR);
  119. v |= (AM35XX_CPGMAC_C0_RX_PULSE_CLR | AM35XX_CPGMAC_C0_TX_PULSE_CLR |
  120. AM35XX_CPGMAC_C0_MISC_PULSE_CLR | AM35XX_CPGMAC_C0_RX_THRESH_CLR);
  121. omap_ctrl_writel(v, AM35XX_CONTROL_LVL_INTR_CLEAR);
  122. omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR); /* OCP barrier */
  123. }
  124. static void am35xx_disable_emac_int(void)
  125. {
  126. u32 v;
  127. v = omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR);
  128. v |= (AM35XX_CPGMAC_C0_RX_PULSE_CLR | AM35XX_CPGMAC_C0_TX_PULSE_CLR);
  129. omap_ctrl_writel(v, AM35XX_CONTROL_LVL_INTR_CLEAR);
  130. omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR); /* OCP barrier */
  131. }
  132. static struct emac_platform_data am35xx_emac_pdata = {
  133. .interrupt_enable = am35xx_enable_emac_int,
  134. .interrupt_disable = am35xx_disable_emac_int,
  135. };
  136. static void __init am3517_evm_legacy_init(void)
  137. {
  138. u32 v;
  139. v = omap_ctrl_readl(AM35XX_CONTROL_IP_SW_RESET);
  140. v &= ~AM35XX_CPGMACSS_SW_RST;
  141. omap_ctrl_writel(v, AM35XX_CONTROL_IP_SW_RESET);
  142. omap_ctrl_readl(AM35XX_CONTROL_IP_SW_RESET); /* OCP barrier */
  143. }
  144. static void __init nokia_n900_legacy_init(void)
  145. {
  146. hsmmc2_internal_input_clk();
  147. if (omap_type() == OMAP2_DEVICE_TYPE_SEC) {
  148. if (IS_ENABLED(CONFIG_ARM_ERRATA_430973)) {
  149. pr_info("RX-51: Enabling ARM errata 430973 workaround\n");
  150. /* set IBE to 1 */
  151. rx51_secure_update_aux_cr(BIT(6), 0);
  152. } else {
  153. pr_warning("RX-51: Not enabling ARM errata 430973 workaround\n");
  154. pr_warning("Thumb binaries may crash randomly without this workaround\n");
  155. }
  156. }
  157. }
  158. #endif /* CONFIG_ARCH_OMAP3 */
  159. #ifdef CONFIG_ARCH_OMAP4
  160. static void __init omap4_sdp_legacy_init(void)
  161. {
  162. omap_4430sdp_display_init_of();
  163. legacy_init_wl12xx(WL12XX_REFCLOCK_26,
  164. WL12XX_TCXOCLOCK_26, 53);
  165. }
  166. static void __init omap4_panda_legacy_init(void)
  167. {
  168. omap4_panda_display_init_of();
  169. legacy_init_ehci_clk("auxclk3_ck");
  170. legacy_init_wl12xx(WL12XX_REFCLOCK_38, 0, 53);
  171. }
  172. #endif
  173. #ifdef CONFIG_SOC_OMAP5
  174. static void __init omap5_uevm_legacy_init(void)
  175. {
  176. legacy_init_ehci_clk("auxclk1_ck");
  177. }
  178. #endif
  179. static struct pcs_pdata pcs_pdata;
  180. void omap_pcs_legacy_init(int irq, void (*rearm)(void))
  181. {
  182. pcs_pdata.irq = irq;
  183. pcs_pdata.rearm = rearm;
  184. }
  185. /*
  186. * GPIOs for TWL are initialized by the I2C bus and need custom
  187. * handing until DSS has device tree bindings.
  188. */
  189. void omap_auxdata_legacy_init(struct device *dev)
  190. {
  191. if (dev->platform_data)
  192. return;
  193. if (strcmp("twl4030-gpio", dev_name(dev)))
  194. return;
  195. dev->platform_data = &twl_gpio_auxdata;
  196. }
  197. /*
  198. * Few boards still need auxdata populated before we populate
  199. * the dev entries in of_platform_populate().
  200. */
  201. static struct pdata_init auxdata_quirks[] __initdata = {
  202. #ifdef CONFIG_SOC_OMAP2420
  203. { "nokia,n800", omap2420_n8x0_legacy_init, },
  204. { "nokia,n810", omap2420_n8x0_legacy_init, },
  205. { "nokia,n810-wimax", omap2420_n8x0_legacy_init, },
  206. #endif
  207. #ifdef CONFIG_ARCH_OMAP3
  208. { "compulab,omap3-sbc-t3730", omap3_sbc_t3730_twl_init, },
  209. #endif
  210. { /* sentinel */ },
  211. };
  212. struct of_dev_auxdata omap_auxdata_lookup[] __initdata = {
  213. #ifdef CONFIG_MACH_NOKIA_N8X0
  214. OF_DEV_AUXDATA("ti,omap2420-mmc", 0x4809c000, "mmci-omap.0", NULL),
  215. #endif
  216. #ifdef CONFIG_ARCH_OMAP3
  217. OF_DEV_AUXDATA("ti,omap3-padconf", 0x48002030, "48002030.pinmux", &pcs_pdata),
  218. OF_DEV_AUXDATA("ti,omap3-padconf", 0x480025a0, "480025a0.pinmux", &pcs_pdata),
  219. OF_DEV_AUXDATA("ti,omap3-padconf", 0x48002a00, "48002a00.pinmux", &pcs_pdata),
  220. /* Only on am3517 */
  221. OF_DEV_AUXDATA("ti,davinci_mdio", 0x5c030000, "davinci_mdio.0", NULL),
  222. OF_DEV_AUXDATA("ti,am3517-emac", 0x5c000000, "davinci_emac.0",
  223. &am35xx_emac_pdata),
  224. #endif
  225. #ifdef CONFIG_ARCH_OMAP4
  226. OF_DEV_AUXDATA("ti,omap4-padconf", 0x4a100040, "4a100040.pinmux", &pcs_pdata),
  227. OF_DEV_AUXDATA("ti,omap4-padconf", 0x4a31e040, "4a31e040.pinmux", &pcs_pdata),
  228. #endif
  229. { /* sentinel */ },
  230. };
  231. /*
  232. * Few boards still need to initialize some legacy devices with
  233. * platform data until the drivers support device tree.
  234. */
  235. static struct pdata_init pdata_quirks[] __initdata = {
  236. #ifdef CONFIG_ARCH_OMAP3
  237. { "compulab,omap3-sbc-t3730", omap3_sbc_t3730_legacy_init, },
  238. { "nokia,omap3-n900", nokia_n900_legacy_init, },
  239. { "nokia,omap3-n9", hsmmc2_internal_input_clk, },
  240. { "nokia,omap3-n950", hsmmc2_internal_input_clk, },
  241. { "isee,omap3-igep0020", omap3_igep0020_legacy_init, },
  242. { "ti,omap3-evm-37xx", omap3_evm_legacy_init, },
  243. { "ti,omap3-zoom3", omap3_zoom_legacy_init, },
  244. { "ti,am3517-evm", am3517_evm_legacy_init, },
  245. #endif
  246. #ifdef CONFIG_ARCH_OMAP4
  247. { "ti,omap4-sdp", omap4_sdp_legacy_init, },
  248. { "ti,omap4-panda", omap4_panda_legacy_init, },
  249. #endif
  250. #ifdef CONFIG_SOC_OMAP5
  251. { "ti,omap5-uevm", omap5_uevm_legacy_init, },
  252. #endif
  253. { /* sentinel */ },
  254. };
  255. static void pdata_quirks_check(struct pdata_init *quirks)
  256. {
  257. while (quirks->compatible) {
  258. if (of_machine_is_compatible(quirks->compatible)) {
  259. if (quirks->fn)
  260. quirks->fn();
  261. break;
  262. }
  263. quirks++;
  264. }
  265. }
  266. void __init pdata_quirks_init(struct of_device_id *omap_dt_match_table)
  267. {
  268. omap_sdrc_init(NULL, NULL);
  269. pdata_quirks_check(auxdata_quirks);
  270. of_platform_populate(NULL, omap_dt_match_table,
  271. omap_auxdata_lookup, NULL);
  272. pdata_quirks_check(pdata_quirks);
  273. }