pdata-quirks.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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 <linux/platform_data/iommu-omap.h>
  19. #include "am35xx.h"
  20. #include "common.h"
  21. #include "common-board-devices.h"
  22. #include "dss-common.h"
  23. #include "control.h"
  24. #include "omap_device.h"
  25. #include "omap-secure.h"
  26. #include "soc.h"
  27. struct pdata_init {
  28. const char *compatible;
  29. void (*fn)(void);
  30. };
  31. struct of_dev_auxdata omap_auxdata_lookup[];
  32. static struct twl4030_gpio_platform_data twl_gpio_auxdata;
  33. #if IS_ENABLED(CONFIG_WL12XX)
  34. static struct wl12xx_platform_data wl12xx __initdata;
  35. static void __init __used legacy_init_wl12xx(unsigned ref_clock,
  36. unsigned tcxo_clock,
  37. int gpio)
  38. {
  39. int res;
  40. wl12xx.board_ref_clock = ref_clock;
  41. wl12xx.board_tcxo_clock = tcxo_clock;
  42. wl12xx.irq = gpio_to_irq(gpio);
  43. res = wl12xx_set_platform_data(&wl12xx);
  44. if (res) {
  45. pr_err("error setting wl12xx data: %d\n", res);
  46. return;
  47. }
  48. }
  49. #else
  50. static inline void legacy_init_wl12xx(unsigned ref_clock,
  51. unsigned tcxo_clock,
  52. int gpio)
  53. {
  54. }
  55. #endif
  56. #ifdef CONFIG_MACH_NOKIA_N8X0
  57. static void __init omap2420_n8x0_legacy_init(void)
  58. {
  59. omap_auxdata_lookup[0].platform_data = n8x0_legacy_init();
  60. }
  61. #else
  62. #define omap2420_n8x0_legacy_init NULL
  63. #endif
  64. #ifdef CONFIG_ARCH_OMAP3
  65. static void __init hsmmc2_internal_input_clk(void)
  66. {
  67. u32 reg;
  68. reg = omap_ctrl_readl(OMAP343X_CONTROL_DEVCONF1);
  69. reg |= OMAP2_MMCSDIO2ADPCLKISEL;
  70. omap_ctrl_writel(reg, OMAP343X_CONTROL_DEVCONF1);
  71. }
  72. static struct iommu_platform_data omap3_iommu_pdata = {
  73. .reset_name = "mmu",
  74. .assert_reset = omap_device_assert_hardreset,
  75. .deassert_reset = omap_device_deassert_hardreset,
  76. };
  77. static int omap3_sbc_t3730_twl_callback(struct device *dev,
  78. unsigned gpio,
  79. unsigned ngpio)
  80. {
  81. int res;
  82. res = gpio_request_one(gpio + 2, GPIOF_OUT_INIT_HIGH,
  83. "wlan pwr");
  84. if (res)
  85. return res;
  86. gpio_export(gpio, 0);
  87. return 0;
  88. }
  89. static void __init omap3_sbc_t3x_usb_hub_init(int gpio, char *hub_name)
  90. {
  91. int err = gpio_request_one(gpio, GPIOF_OUT_INIT_LOW, hub_name);
  92. if (err) {
  93. pr_err("SBC-T3x: %s reset gpio request failed: %d\n",
  94. hub_name, err);
  95. return;
  96. }
  97. gpio_export(gpio, 0);
  98. udelay(10);
  99. gpio_set_value(gpio, 1);
  100. msleep(1);
  101. }
  102. static void __init omap3_sbc_t3730_twl_init(void)
  103. {
  104. twl_gpio_auxdata.setup = omap3_sbc_t3730_twl_callback;
  105. }
  106. static void __init omap3_sbc_t3730_legacy_init(void)
  107. {
  108. omap3_sbc_t3x_usb_hub_init(167, "sb-t35 usb hub");
  109. legacy_init_wl12xx(WL12XX_REFCLOCK_38, 0, 136);
  110. omap_ads7846_init(1, 57, 0, NULL);
  111. }
  112. static void __init omap3_sbc_t3530_legacy_init(void)
  113. {
  114. omap3_sbc_t3x_usb_hub_init(167, "sb-t35 usb hub");
  115. omap_ads7846_init(1, 57, 0, NULL);
  116. }
  117. static void __init omap3_igep0020_legacy_init(void)
  118. {
  119. }
  120. static void __init omap3_evm_legacy_init(void)
  121. {
  122. legacy_init_wl12xx(WL12XX_REFCLOCK_38, 0, 149);
  123. }
  124. static void __init omap3_zoom_legacy_init(void)
  125. {
  126. legacy_init_wl12xx(WL12XX_REFCLOCK_26, 0, 162);
  127. }
  128. static void am35xx_enable_emac_int(void)
  129. {
  130. u32 v;
  131. v = omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR);
  132. v |= (AM35XX_CPGMAC_C0_RX_PULSE_CLR | AM35XX_CPGMAC_C0_TX_PULSE_CLR |
  133. AM35XX_CPGMAC_C0_MISC_PULSE_CLR | AM35XX_CPGMAC_C0_RX_THRESH_CLR);
  134. omap_ctrl_writel(v, AM35XX_CONTROL_LVL_INTR_CLEAR);
  135. omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR); /* OCP barrier */
  136. }
  137. static void am35xx_disable_emac_int(void)
  138. {
  139. u32 v;
  140. v = omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR);
  141. v |= (AM35XX_CPGMAC_C0_RX_PULSE_CLR | AM35XX_CPGMAC_C0_TX_PULSE_CLR);
  142. omap_ctrl_writel(v, AM35XX_CONTROL_LVL_INTR_CLEAR);
  143. omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR); /* OCP barrier */
  144. }
  145. static struct emac_platform_data am35xx_emac_pdata = {
  146. .interrupt_enable = am35xx_enable_emac_int,
  147. .interrupt_disable = am35xx_disable_emac_int,
  148. };
  149. static void __init am35xx_emac_reset(void)
  150. {
  151. u32 v;
  152. v = omap_ctrl_readl(AM35XX_CONTROL_IP_SW_RESET);
  153. v &= ~AM35XX_CPGMACSS_SW_RST;
  154. omap_ctrl_writel(v, AM35XX_CONTROL_IP_SW_RESET);
  155. omap_ctrl_readl(AM35XX_CONTROL_IP_SW_RESET); /* OCP barrier */
  156. }
  157. static struct gpio cm_t3517_wlan_gpios[] __initdata = {
  158. { 56, GPIOF_OUT_INIT_HIGH, "wlan pwr" },
  159. { 4, GPIOF_OUT_INIT_HIGH, "xcvr noe" },
  160. };
  161. static void __init omap3_sbc_t3517_wifi_init(void)
  162. {
  163. int err = gpio_request_array(cm_t3517_wlan_gpios,
  164. ARRAY_SIZE(cm_t3517_wlan_gpios));
  165. if (err) {
  166. pr_err("SBC-T3517: wl12xx gpios request failed: %d\n", err);
  167. return;
  168. }
  169. gpio_export(cm_t3517_wlan_gpios[0].gpio, 0);
  170. gpio_export(cm_t3517_wlan_gpios[1].gpio, 0);
  171. msleep(100);
  172. gpio_set_value(cm_t3517_wlan_gpios[1].gpio, 0);
  173. }
  174. static void __init omap3_sbc_t3517_legacy_init(void)
  175. {
  176. omap3_sbc_t3x_usb_hub_init(152, "cm-t3517 usb hub");
  177. omap3_sbc_t3x_usb_hub_init(98, "sb-t35 usb hub");
  178. am35xx_emac_reset();
  179. hsmmc2_internal_input_clk();
  180. omap3_sbc_t3517_wifi_init();
  181. legacy_init_wl12xx(WL12XX_REFCLOCK_38, 0, 145);
  182. omap_ads7846_init(1, 57, 0, NULL);
  183. }
  184. static void __init am3517_evm_legacy_init(void)
  185. {
  186. am35xx_emac_reset();
  187. }
  188. static struct platform_device omap3_rom_rng_device = {
  189. .name = "omap3-rom-rng",
  190. .id = -1,
  191. .dev = {
  192. .platform_data = rx51_secure_rng_call,
  193. },
  194. };
  195. static void __init nokia_n900_legacy_init(void)
  196. {
  197. hsmmc2_internal_input_clk();
  198. if (omap_type() == OMAP2_DEVICE_TYPE_SEC) {
  199. if (IS_ENABLED(CONFIG_ARM_ERRATA_430973)) {
  200. pr_info("RX-51: Enabling ARM errata 430973 workaround\n");
  201. /* set IBE to 1 */
  202. rx51_secure_update_aux_cr(BIT(6), 0);
  203. } else {
  204. pr_warning("RX-51: Not enabling ARM errata 430973 workaround\n");
  205. pr_warning("Thumb binaries may crash randomly without this workaround\n");
  206. }
  207. pr_info("RX-51: Registring OMAP3 HWRNG device\n");
  208. platform_device_register(&omap3_rom_rng_device);
  209. }
  210. }
  211. #endif /* CONFIG_ARCH_OMAP3 */
  212. #ifdef CONFIG_ARCH_OMAP4
  213. static void __init omap4_sdp_legacy_init(void)
  214. {
  215. legacy_init_wl12xx(WL12XX_REFCLOCK_26,
  216. WL12XX_TCXOCLOCK_26, 53);
  217. }
  218. static void __init omap4_panda_legacy_init(void)
  219. {
  220. legacy_init_wl12xx(WL12XX_REFCLOCK_38, 0, 53);
  221. }
  222. #endif
  223. #if defined(CONFIG_ARCH_OMAP4) || defined(CONFIG_SOC_OMAP5)
  224. static struct iommu_platform_data omap4_iommu_pdata = {
  225. .reset_name = "mmu_cache",
  226. .assert_reset = omap_device_assert_hardreset,
  227. .deassert_reset = omap_device_deassert_hardreset,
  228. };
  229. #endif
  230. #ifdef CONFIG_SOC_AM33XX
  231. static void __init am335x_evmsk_legacy_init(void)
  232. {
  233. legacy_init_wl12xx(WL12XX_REFCLOCK_38, 0, 31);
  234. }
  235. #endif
  236. #ifdef CONFIG_SOC_OMAP5
  237. static void __init omap5_uevm_legacy_init(void)
  238. {
  239. }
  240. #endif
  241. static struct pcs_pdata pcs_pdata;
  242. void omap_pcs_legacy_init(int irq, void (*rearm)(void))
  243. {
  244. pcs_pdata.irq = irq;
  245. pcs_pdata.rearm = rearm;
  246. }
  247. /*
  248. * GPIOs for TWL are initialized by the I2C bus and need custom
  249. * handing until DSS has device tree bindings.
  250. */
  251. void omap_auxdata_legacy_init(struct device *dev)
  252. {
  253. if (dev->platform_data)
  254. return;
  255. if (strcmp("twl4030-gpio", dev_name(dev)))
  256. return;
  257. dev->platform_data = &twl_gpio_auxdata;
  258. }
  259. /*
  260. * Few boards still need auxdata populated before we populate
  261. * the dev entries in of_platform_populate().
  262. */
  263. static struct pdata_init auxdata_quirks[] __initdata = {
  264. #ifdef CONFIG_SOC_OMAP2420
  265. { "nokia,n800", omap2420_n8x0_legacy_init, },
  266. { "nokia,n810", omap2420_n8x0_legacy_init, },
  267. { "nokia,n810-wimax", omap2420_n8x0_legacy_init, },
  268. #endif
  269. #ifdef CONFIG_ARCH_OMAP3
  270. { "compulab,omap3-sbc-t3730", omap3_sbc_t3730_twl_init, },
  271. #endif
  272. { /* sentinel */ },
  273. };
  274. struct of_dev_auxdata omap_auxdata_lookup[] __initdata = {
  275. #ifdef CONFIG_MACH_NOKIA_N8X0
  276. OF_DEV_AUXDATA("ti,omap2420-mmc", 0x4809c000, "mmci-omap.0", NULL),
  277. #endif
  278. #ifdef CONFIG_ARCH_OMAP3
  279. OF_DEV_AUXDATA("ti,omap3-padconf", 0x48002030, "48002030.pinmux", &pcs_pdata),
  280. OF_DEV_AUXDATA("ti,omap3-padconf", 0x480025a0, "480025a0.pinmux", &pcs_pdata),
  281. OF_DEV_AUXDATA("ti,omap3-padconf", 0x48002a00, "48002a00.pinmux", &pcs_pdata),
  282. OF_DEV_AUXDATA("ti,omap2-iommu", 0x5d000000, "5d000000.mmu",
  283. &omap3_iommu_pdata),
  284. /* Only on am3517 */
  285. OF_DEV_AUXDATA("ti,davinci_mdio", 0x5c030000, "davinci_mdio.0", NULL),
  286. OF_DEV_AUXDATA("ti,am3517-emac", 0x5c000000, "davinci_emac.0",
  287. &am35xx_emac_pdata),
  288. #endif
  289. #ifdef CONFIG_ARCH_OMAP4
  290. OF_DEV_AUXDATA("ti,omap4-padconf", 0x4a100040, "4a100040.pinmux", &pcs_pdata),
  291. OF_DEV_AUXDATA("ti,omap4-padconf", 0x4a31e040, "4a31e040.pinmux", &pcs_pdata),
  292. #endif
  293. #if defined(CONFIG_ARCH_OMAP4) || defined(CONFIG_SOC_OMAP5)
  294. OF_DEV_AUXDATA("ti,omap4-iommu", 0x4a066000, "4a066000.mmu",
  295. &omap4_iommu_pdata),
  296. OF_DEV_AUXDATA("ti,omap4-iommu", 0x55082000, "55082000.mmu",
  297. &omap4_iommu_pdata),
  298. #endif
  299. { /* sentinel */ },
  300. };
  301. /*
  302. * Few boards still need to initialize some legacy devices with
  303. * platform data until the drivers support device tree.
  304. */
  305. static struct pdata_init pdata_quirks[] __initdata = {
  306. #ifdef CONFIG_ARCH_OMAP3
  307. { "compulab,omap3-sbc-t3517", omap3_sbc_t3517_legacy_init, },
  308. { "compulab,omap3-sbc-t3530", omap3_sbc_t3530_legacy_init, },
  309. { "compulab,omap3-sbc-t3730", omap3_sbc_t3730_legacy_init, },
  310. { "nokia,omap3-n900", nokia_n900_legacy_init, },
  311. { "nokia,omap3-n9", hsmmc2_internal_input_clk, },
  312. { "nokia,omap3-n950", hsmmc2_internal_input_clk, },
  313. { "isee,omap3-igep0020", omap3_igep0020_legacy_init, },
  314. { "ti,omap3-evm-37xx", omap3_evm_legacy_init, },
  315. { "ti,omap3-zoom3", omap3_zoom_legacy_init, },
  316. { "ti,am3517-evm", am3517_evm_legacy_init, },
  317. #endif
  318. #ifdef CONFIG_ARCH_OMAP4
  319. { "ti,omap4-sdp", omap4_sdp_legacy_init, },
  320. { "ti,omap4-panda", omap4_panda_legacy_init, },
  321. #endif
  322. #ifdef CONFIG_SOC_AM33XX
  323. { "ti,am335x-evmsk", am335x_evmsk_legacy_init, },
  324. #endif
  325. #ifdef CONFIG_SOC_OMAP5
  326. { "ti,omap5-uevm", omap5_uevm_legacy_init, },
  327. #endif
  328. { /* sentinel */ },
  329. };
  330. static void pdata_quirks_check(struct pdata_init *quirks)
  331. {
  332. while (quirks->compatible) {
  333. if (of_machine_is_compatible(quirks->compatible)) {
  334. if (quirks->fn)
  335. quirks->fn();
  336. break;
  337. }
  338. quirks++;
  339. }
  340. }
  341. void __init pdata_quirks_init(struct of_device_id *omap_dt_match_table)
  342. {
  343. omap_sdrc_init(NULL, NULL);
  344. pdata_quirks_check(auxdata_quirks);
  345. of_platform_populate(NULL, omap_dt_match_table,
  346. omap_auxdata_lookup, NULL);
  347. pdata_quirks_check(pdata_quirks);
  348. }