pdata-quirks.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  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_warn("RX-51: Not enabling ARM errata 430973 workaround\n");
  205. pr_warn("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. static void __init omap3_tao3530_legacy_init(void)
  212. {
  213. hsmmc2_internal_input_clk();
  214. }
  215. #endif /* CONFIG_ARCH_OMAP3 */
  216. #ifdef CONFIG_ARCH_OMAP4
  217. static void __init omap4_sdp_legacy_init(void)
  218. {
  219. legacy_init_wl12xx(WL12XX_REFCLOCK_26,
  220. WL12XX_TCXOCLOCK_26, 53);
  221. }
  222. static void __init omap4_panda_legacy_init(void)
  223. {
  224. legacy_init_wl12xx(WL12XX_REFCLOCK_38, 0, 53);
  225. }
  226. static void __init var_som_om44_legacy_init(void)
  227. {
  228. legacy_init_wl12xx(WL12XX_REFCLOCK_38, 0, 41);
  229. }
  230. #endif
  231. #if defined(CONFIG_ARCH_OMAP4) || defined(CONFIG_SOC_OMAP5)
  232. static struct iommu_platform_data omap4_iommu_pdata = {
  233. .reset_name = "mmu_cache",
  234. .assert_reset = omap_device_assert_hardreset,
  235. .deassert_reset = omap_device_deassert_hardreset,
  236. };
  237. #endif
  238. #ifdef CONFIG_SOC_AM33XX
  239. static void __init am335x_evmsk_legacy_init(void)
  240. {
  241. legacy_init_wl12xx(WL12XX_REFCLOCK_38, 0, 31);
  242. }
  243. #endif
  244. #ifdef CONFIG_SOC_OMAP5
  245. static void __init omap5_uevm_legacy_init(void)
  246. {
  247. }
  248. #endif
  249. static struct pcs_pdata pcs_pdata;
  250. void omap_pcs_legacy_init(int irq, void (*rearm)(void))
  251. {
  252. pcs_pdata.irq = irq;
  253. pcs_pdata.rearm = rearm;
  254. }
  255. /*
  256. * GPIOs for TWL are initialized by the I2C bus and need custom
  257. * handing until DSS has device tree bindings.
  258. */
  259. void omap_auxdata_legacy_init(struct device *dev)
  260. {
  261. if (dev->platform_data)
  262. return;
  263. if (strcmp("twl4030-gpio", dev_name(dev)))
  264. return;
  265. dev->platform_data = &twl_gpio_auxdata;
  266. }
  267. /*
  268. * Few boards still need auxdata populated before we populate
  269. * the dev entries in of_platform_populate().
  270. */
  271. static struct pdata_init auxdata_quirks[] __initdata = {
  272. #ifdef CONFIG_SOC_OMAP2420
  273. { "nokia,n800", omap2420_n8x0_legacy_init, },
  274. { "nokia,n810", omap2420_n8x0_legacy_init, },
  275. { "nokia,n810-wimax", omap2420_n8x0_legacy_init, },
  276. #endif
  277. #ifdef CONFIG_ARCH_OMAP3
  278. { "compulab,omap3-sbc-t3730", omap3_sbc_t3730_twl_init, },
  279. #endif
  280. { /* sentinel */ },
  281. };
  282. struct of_dev_auxdata omap_auxdata_lookup[] __initdata = {
  283. #ifdef CONFIG_MACH_NOKIA_N8X0
  284. OF_DEV_AUXDATA("ti,omap2420-mmc", 0x4809c000, "mmci-omap.0", NULL),
  285. OF_DEV_AUXDATA("menelaus", 0x72, "1-0072", &n8x0_menelaus_platform_data),
  286. OF_DEV_AUXDATA("tlv320aic3x", 0x18, "2-0018", &n810_aic33_data),
  287. #endif
  288. #ifdef CONFIG_ARCH_OMAP3
  289. OF_DEV_AUXDATA("ti,omap3-padconf", 0x48002030, "48002030.pinmux", &pcs_pdata),
  290. OF_DEV_AUXDATA("ti,omap3-padconf", 0x480025a0, "480025a0.pinmux", &pcs_pdata),
  291. OF_DEV_AUXDATA("ti,omap3-padconf", 0x48002a00, "48002a00.pinmux", &pcs_pdata),
  292. OF_DEV_AUXDATA("ti,omap2-iommu", 0x5d000000, "5d000000.mmu",
  293. &omap3_iommu_pdata),
  294. /* Only on am3517 */
  295. OF_DEV_AUXDATA("ti,davinci_mdio", 0x5c030000, "davinci_mdio.0", NULL),
  296. OF_DEV_AUXDATA("ti,am3517-emac", 0x5c000000, "davinci_emac.0",
  297. &am35xx_emac_pdata),
  298. #endif
  299. #ifdef CONFIG_ARCH_OMAP4
  300. OF_DEV_AUXDATA("ti,omap4-padconf", 0x4a100040, "4a100040.pinmux", &pcs_pdata),
  301. OF_DEV_AUXDATA("ti,omap4-padconf", 0x4a31e040, "4a31e040.pinmux", &pcs_pdata),
  302. #endif
  303. #ifdef CONFIG_SOC_OMAP5
  304. OF_DEV_AUXDATA("ti,omap5-padconf", 0x4a002840, "4a002840.pinmux", &pcs_pdata),
  305. OF_DEV_AUXDATA("ti,omap5-padconf", 0x4ae0c840, "4ae0c840.pinmux", &pcs_pdata),
  306. #endif
  307. #ifdef CONFIG_SOC_DRA7XX
  308. OF_DEV_AUXDATA("ti,dra7-padconf", 0x4a003400, "4a003400.pinmux", &pcs_pdata),
  309. #endif
  310. #ifdef CONFIG_SOC_AM43XX
  311. OF_DEV_AUXDATA("ti,am437-padconf", 0x44e10800, "44e10800.pinmux", &pcs_pdata),
  312. #endif
  313. #if defined(CONFIG_ARCH_OMAP4) || defined(CONFIG_SOC_OMAP5)
  314. OF_DEV_AUXDATA("ti,omap4-iommu", 0x4a066000, "4a066000.mmu",
  315. &omap4_iommu_pdata),
  316. OF_DEV_AUXDATA("ti,omap4-iommu", 0x55082000, "55082000.mmu",
  317. &omap4_iommu_pdata),
  318. #endif
  319. { /* sentinel */ },
  320. };
  321. /*
  322. * Few boards still need to initialize some legacy devices with
  323. * platform data until the drivers support device tree.
  324. */
  325. static struct pdata_init pdata_quirks[] __initdata = {
  326. #ifdef CONFIG_ARCH_OMAP3
  327. { "compulab,omap3-sbc-t3517", omap3_sbc_t3517_legacy_init, },
  328. { "compulab,omap3-sbc-t3530", omap3_sbc_t3530_legacy_init, },
  329. { "compulab,omap3-sbc-t3730", omap3_sbc_t3730_legacy_init, },
  330. { "nokia,omap3-n900", nokia_n900_legacy_init, },
  331. { "nokia,omap3-n9", hsmmc2_internal_input_clk, },
  332. { "nokia,omap3-n950", hsmmc2_internal_input_clk, },
  333. { "isee,omap3-igep0020", omap3_igep0020_legacy_init, },
  334. { "ti,omap3-evm-37xx", omap3_evm_legacy_init, },
  335. { "ti,omap3-zoom3", omap3_zoom_legacy_init, },
  336. { "ti,am3517-evm", am3517_evm_legacy_init, },
  337. { "technexion,omap3-tao3530", omap3_tao3530_legacy_init, },
  338. #endif
  339. #ifdef CONFIG_ARCH_OMAP4
  340. { "ti,omap4-sdp", omap4_sdp_legacy_init, },
  341. { "ti,omap4-panda", omap4_panda_legacy_init, },
  342. { "variscite,var-dvk-om44", var_som_om44_legacy_init, },
  343. { "variscite,var-stk-om44", var_som_om44_legacy_init, },
  344. #endif
  345. #ifdef CONFIG_SOC_AM33XX
  346. { "ti,am335x-evmsk", am335x_evmsk_legacy_init, },
  347. #endif
  348. #ifdef CONFIG_SOC_OMAP5
  349. { "ti,omap5-uevm", omap5_uevm_legacy_init, },
  350. #endif
  351. { /* sentinel */ },
  352. };
  353. static void pdata_quirks_check(struct pdata_init *quirks)
  354. {
  355. while (quirks->compatible) {
  356. if (of_machine_is_compatible(quirks->compatible)) {
  357. if (quirks->fn)
  358. quirks->fn();
  359. break;
  360. }
  361. quirks++;
  362. }
  363. }
  364. void __init pdata_quirks_init(const struct of_device_id *omap_dt_match_table)
  365. {
  366. omap_sdrc_init(NULL, NULL);
  367. pdata_quirks_check(auxdata_quirks);
  368. of_platform_populate(NULL, omap_dt_match_table,
  369. omap_auxdata_lookup, NULL);
  370. pdata_quirks_check(pdata_quirks);
  371. }