pdata-quirks.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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/ti_wilink_st.h>
  17. #include <linux/wl12xx.h>
  18. #include <linux/platform_data/pinctrl-single.h>
  19. #include <linux/platform_data/iommu-omap.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. }
  111. static void __init omap3_sbc_t3530_legacy_init(void)
  112. {
  113. omap3_sbc_t3x_usb_hub_init(167, "sb-t35 usb hub");
  114. }
  115. struct ti_st_plat_data wilink_pdata = {
  116. .nshutdown_gpio = 137,
  117. .dev_name = "/dev/ttyO1",
  118. .flow_cntrl = 1,
  119. .baud_rate = 300000,
  120. };
  121. static struct platform_device wl18xx_device = {
  122. .name = "kim",
  123. .id = -1,
  124. .dev = {
  125. .platform_data = &wilink_pdata,
  126. }
  127. };
  128. static struct platform_device btwilink_device = {
  129. .name = "btwilink",
  130. .id = -1,
  131. };
  132. static void __init omap3_igep0020_rev_f_legacy_init(void)
  133. {
  134. legacy_init_wl12xx(0, 0, 177);
  135. platform_device_register(&wl18xx_device);
  136. platform_device_register(&btwilink_device);
  137. }
  138. static void __init omap3_igep0030_rev_g_legacy_init(void)
  139. {
  140. legacy_init_wl12xx(0, 0, 136);
  141. platform_device_register(&wl18xx_device);
  142. platform_device_register(&btwilink_device);
  143. }
  144. static void __init omap3_evm_legacy_init(void)
  145. {
  146. hsmmc2_internal_input_clk();
  147. legacy_init_wl12xx(WL12XX_REFCLOCK_38, 0, 149);
  148. }
  149. static void __init omap3_zoom_legacy_init(void)
  150. {
  151. legacy_init_wl12xx(WL12XX_REFCLOCK_26, 0, 162);
  152. }
  153. static void am35xx_enable_emac_int(void)
  154. {
  155. u32 v;
  156. v = omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR);
  157. v |= (AM35XX_CPGMAC_C0_RX_PULSE_CLR | AM35XX_CPGMAC_C0_TX_PULSE_CLR |
  158. AM35XX_CPGMAC_C0_MISC_PULSE_CLR | AM35XX_CPGMAC_C0_RX_THRESH_CLR);
  159. omap_ctrl_writel(v, AM35XX_CONTROL_LVL_INTR_CLEAR);
  160. omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR); /* OCP barrier */
  161. }
  162. static void am35xx_disable_emac_int(void)
  163. {
  164. u32 v;
  165. v = omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR);
  166. v |= (AM35XX_CPGMAC_C0_RX_PULSE_CLR | AM35XX_CPGMAC_C0_TX_PULSE_CLR);
  167. omap_ctrl_writel(v, AM35XX_CONTROL_LVL_INTR_CLEAR);
  168. omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR); /* OCP barrier */
  169. }
  170. static struct emac_platform_data am35xx_emac_pdata = {
  171. .interrupt_enable = am35xx_enable_emac_int,
  172. .interrupt_disable = am35xx_disable_emac_int,
  173. };
  174. static void __init am35xx_emac_reset(void)
  175. {
  176. u32 v;
  177. v = omap_ctrl_readl(AM35XX_CONTROL_IP_SW_RESET);
  178. v &= ~AM35XX_CPGMACSS_SW_RST;
  179. omap_ctrl_writel(v, AM35XX_CONTROL_IP_SW_RESET);
  180. omap_ctrl_readl(AM35XX_CONTROL_IP_SW_RESET); /* OCP barrier */
  181. }
  182. static struct gpio cm_t3517_wlan_gpios[] __initdata = {
  183. { 56, GPIOF_OUT_INIT_HIGH, "wlan pwr" },
  184. { 4, GPIOF_OUT_INIT_HIGH, "xcvr noe" },
  185. };
  186. static void __init omap3_sbc_t3517_wifi_init(void)
  187. {
  188. int err = gpio_request_array(cm_t3517_wlan_gpios,
  189. ARRAY_SIZE(cm_t3517_wlan_gpios));
  190. if (err) {
  191. pr_err("SBC-T3517: wl12xx gpios request failed: %d\n", err);
  192. return;
  193. }
  194. gpio_export(cm_t3517_wlan_gpios[0].gpio, 0);
  195. gpio_export(cm_t3517_wlan_gpios[1].gpio, 0);
  196. msleep(100);
  197. gpio_set_value(cm_t3517_wlan_gpios[1].gpio, 0);
  198. }
  199. static void __init omap3_sbc_t3517_legacy_init(void)
  200. {
  201. omap3_sbc_t3x_usb_hub_init(152, "cm-t3517 usb hub");
  202. omap3_sbc_t3x_usb_hub_init(98, "sb-t35 usb hub");
  203. am35xx_emac_reset();
  204. hsmmc2_internal_input_clk();
  205. omap3_sbc_t3517_wifi_init();
  206. legacy_init_wl12xx(WL12XX_REFCLOCK_38, 0, 145);
  207. }
  208. static void __init am3517_evm_legacy_init(void)
  209. {
  210. am35xx_emac_reset();
  211. }
  212. static struct platform_device omap3_rom_rng_device = {
  213. .name = "omap3-rom-rng",
  214. .id = -1,
  215. .dev = {
  216. .platform_data = rx51_secure_rng_call,
  217. },
  218. };
  219. static void __init nokia_n900_legacy_init(void)
  220. {
  221. hsmmc2_internal_input_clk();
  222. if (omap_type() == OMAP2_DEVICE_TYPE_SEC) {
  223. if (IS_ENABLED(CONFIG_ARM_ERRATA_430973)) {
  224. pr_info("RX-51: Enabling ARM errata 430973 workaround\n");
  225. /* set IBE to 1 */
  226. rx51_secure_update_aux_cr(BIT(6), 0);
  227. } else {
  228. pr_warn("RX-51: Not enabling ARM errata 430973 workaround\n");
  229. pr_warn("Thumb binaries may crash randomly without this workaround\n");
  230. }
  231. pr_info("RX-51: Registring OMAP3 HWRNG device\n");
  232. platform_device_register(&omap3_rom_rng_device);
  233. }
  234. }
  235. static void __init omap3_tao3530_legacy_init(void)
  236. {
  237. hsmmc2_internal_input_clk();
  238. }
  239. #endif /* CONFIG_ARCH_OMAP3 */
  240. #ifdef CONFIG_ARCH_OMAP4
  241. static void __init omap4_sdp_legacy_init(void)
  242. {
  243. legacy_init_wl12xx(WL12XX_REFCLOCK_26,
  244. WL12XX_TCXOCLOCK_26, 53);
  245. }
  246. static void __init omap4_panda_legacy_init(void)
  247. {
  248. legacy_init_wl12xx(WL12XX_REFCLOCK_38, 0, 53);
  249. }
  250. static void __init var_som_om44_legacy_init(void)
  251. {
  252. legacy_init_wl12xx(WL12XX_REFCLOCK_38, 0, 41);
  253. }
  254. #endif
  255. #if defined(CONFIG_ARCH_OMAP4) || defined(CONFIG_SOC_OMAP5)
  256. static struct iommu_platform_data omap4_iommu_pdata = {
  257. .reset_name = "mmu_cache",
  258. .assert_reset = omap_device_assert_hardreset,
  259. .deassert_reset = omap_device_deassert_hardreset,
  260. };
  261. #endif
  262. #ifdef CONFIG_SOC_AM33XX
  263. static void __init am335x_evmsk_legacy_init(void)
  264. {
  265. legacy_init_wl12xx(WL12XX_REFCLOCK_38, 0, 31);
  266. }
  267. #endif
  268. #ifdef CONFIG_SOC_OMAP5
  269. static void __init omap5_uevm_legacy_init(void)
  270. {
  271. }
  272. #endif
  273. static struct pcs_pdata pcs_pdata;
  274. void omap_pcs_legacy_init(int irq, void (*rearm)(void))
  275. {
  276. pcs_pdata.irq = irq;
  277. pcs_pdata.rearm = rearm;
  278. }
  279. /*
  280. * GPIOs for TWL are initialized by the I2C bus and need custom
  281. * handing until DSS has device tree bindings.
  282. */
  283. void omap_auxdata_legacy_init(struct device *dev)
  284. {
  285. if (dev->platform_data)
  286. return;
  287. if (strcmp("twl4030-gpio", dev_name(dev)))
  288. return;
  289. dev->platform_data = &twl_gpio_auxdata;
  290. }
  291. /*
  292. * Few boards still need auxdata populated before we populate
  293. * the dev entries in of_platform_populate().
  294. */
  295. static struct pdata_init auxdata_quirks[] __initdata = {
  296. #ifdef CONFIG_SOC_OMAP2420
  297. { "nokia,n800", omap2420_n8x0_legacy_init, },
  298. { "nokia,n810", omap2420_n8x0_legacy_init, },
  299. { "nokia,n810-wimax", omap2420_n8x0_legacy_init, },
  300. #endif
  301. #ifdef CONFIG_ARCH_OMAP3
  302. { "compulab,omap3-sbc-t3730", omap3_sbc_t3730_twl_init, },
  303. #endif
  304. { /* sentinel */ },
  305. };
  306. struct of_dev_auxdata omap_auxdata_lookup[] __initdata = {
  307. #ifdef CONFIG_MACH_NOKIA_N8X0
  308. OF_DEV_AUXDATA("ti,omap2420-mmc", 0x4809c000, "mmci-omap.0", NULL),
  309. OF_DEV_AUXDATA("menelaus", 0x72, "1-0072", &n8x0_menelaus_platform_data),
  310. OF_DEV_AUXDATA("tlv320aic3x", 0x18, "2-0018", &n810_aic33_data),
  311. #endif
  312. #ifdef CONFIG_ARCH_OMAP3
  313. OF_DEV_AUXDATA("ti,omap3-padconf", 0x48002030, "48002030.pinmux", &pcs_pdata),
  314. OF_DEV_AUXDATA("ti,omap3-padconf", 0x480025a0, "480025a0.pinmux", &pcs_pdata),
  315. OF_DEV_AUXDATA("ti,omap3-padconf", 0x48002a00, "48002a00.pinmux", &pcs_pdata),
  316. OF_DEV_AUXDATA("ti,omap2-iommu", 0x5d000000, "5d000000.mmu",
  317. &omap3_iommu_pdata),
  318. /* Only on am3517 */
  319. OF_DEV_AUXDATA("ti,davinci_mdio", 0x5c030000, "davinci_mdio.0", NULL),
  320. OF_DEV_AUXDATA("ti,am3517-emac", 0x5c000000, "davinci_emac.0",
  321. &am35xx_emac_pdata),
  322. #endif
  323. #ifdef CONFIG_ARCH_OMAP4
  324. OF_DEV_AUXDATA("ti,omap4-padconf", 0x4a100040, "4a100040.pinmux", &pcs_pdata),
  325. OF_DEV_AUXDATA("ti,omap4-padconf", 0x4a31e040, "4a31e040.pinmux", &pcs_pdata),
  326. #endif
  327. #ifdef CONFIG_SOC_OMAP5
  328. OF_DEV_AUXDATA("ti,omap5-padconf", 0x4a002840, "4a002840.pinmux", &pcs_pdata),
  329. OF_DEV_AUXDATA("ti,omap5-padconf", 0x4ae0c840, "4ae0c840.pinmux", &pcs_pdata),
  330. #endif
  331. #ifdef CONFIG_SOC_DRA7XX
  332. OF_DEV_AUXDATA("ti,dra7-padconf", 0x4a003400, "4a003400.pinmux", &pcs_pdata),
  333. #endif
  334. #ifdef CONFIG_SOC_AM43XX
  335. OF_DEV_AUXDATA("ti,am437-padconf", 0x44e10800, "44e10800.pinmux", &pcs_pdata),
  336. #endif
  337. #if defined(CONFIG_ARCH_OMAP4) || defined(CONFIG_SOC_OMAP5)
  338. OF_DEV_AUXDATA("ti,omap4-iommu", 0x4a066000, "4a066000.mmu",
  339. &omap4_iommu_pdata),
  340. OF_DEV_AUXDATA("ti,omap4-iommu", 0x55082000, "55082000.mmu",
  341. &omap4_iommu_pdata),
  342. #endif
  343. { /* sentinel */ },
  344. };
  345. /*
  346. * Few boards still need to initialize some legacy devices with
  347. * platform data until the drivers support device tree.
  348. */
  349. static struct pdata_init pdata_quirks[] __initdata = {
  350. #ifdef CONFIG_ARCH_OMAP3
  351. { "compulab,omap3-sbc-t3517", omap3_sbc_t3517_legacy_init, },
  352. { "compulab,omap3-sbc-t3530", omap3_sbc_t3530_legacy_init, },
  353. { "compulab,omap3-sbc-t3730", omap3_sbc_t3730_legacy_init, },
  354. { "nokia,omap3-n900", nokia_n900_legacy_init, },
  355. { "nokia,omap3-n9", hsmmc2_internal_input_clk, },
  356. { "nokia,omap3-n950", hsmmc2_internal_input_clk, },
  357. { "isee,omap3-igep0020-rev-f", omap3_igep0020_rev_f_legacy_init, },
  358. { "isee,omap3-igep0030-rev-g", omap3_igep0030_rev_g_legacy_init, },
  359. { "ti,omap3-evm-37xx", omap3_evm_legacy_init, },
  360. { "ti,omap3-zoom3", omap3_zoom_legacy_init, },
  361. { "ti,am3517-evm", am3517_evm_legacy_init, },
  362. { "technexion,omap3-tao3530", omap3_tao3530_legacy_init, },
  363. #endif
  364. #ifdef CONFIG_ARCH_OMAP4
  365. { "ti,omap4-sdp", omap4_sdp_legacy_init, },
  366. { "ti,omap4-panda", omap4_panda_legacy_init, },
  367. { "variscite,var-dvk-om44", var_som_om44_legacy_init, },
  368. { "variscite,var-stk-om44", var_som_om44_legacy_init, },
  369. #endif
  370. #ifdef CONFIG_SOC_AM33XX
  371. { "ti,am335x-evmsk", am335x_evmsk_legacy_init, },
  372. #endif
  373. #ifdef CONFIG_SOC_OMAP5
  374. { "ti,omap5-uevm", omap5_uevm_legacy_init, },
  375. #endif
  376. { /* sentinel */ },
  377. };
  378. static void pdata_quirks_check(struct pdata_init *quirks)
  379. {
  380. while (quirks->compatible) {
  381. if (of_machine_is_compatible(quirks->compatible)) {
  382. if (quirks->fn)
  383. quirks->fn();
  384. break;
  385. }
  386. quirks++;
  387. }
  388. }
  389. void __init pdata_quirks_init(const struct of_device_id *omap_dt_match_table)
  390. {
  391. omap_sdrc_init(NULL, NULL);
  392. pdata_quirks_check(auxdata_quirks);
  393. of_platform_populate(NULL, omap_dt_match_table,
  394. omap_auxdata_lookup, NULL);
  395. pdata_quirks_check(pdata_quirks);
  396. }