pdata-quirks.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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 void __init nokia_n900_legacy_init(void)
  189. {
  190. hsmmc2_internal_input_clk();
  191. if (omap_type() == OMAP2_DEVICE_TYPE_SEC) {
  192. if (IS_ENABLED(CONFIG_ARM_ERRATA_430973)) {
  193. pr_info("RX-51: Enabling ARM errata 430973 workaround\n");
  194. /* set IBE to 1 */
  195. rx51_secure_update_aux_cr(BIT(6), 0);
  196. } else {
  197. pr_warning("RX-51: Not enabling ARM errata 430973 workaround\n");
  198. pr_warning("Thumb binaries may crash randomly without this workaround\n");
  199. }
  200. }
  201. }
  202. #endif /* CONFIG_ARCH_OMAP3 */
  203. #ifdef CONFIG_ARCH_OMAP4
  204. static void __init omap4_sdp_legacy_init(void)
  205. {
  206. legacy_init_wl12xx(WL12XX_REFCLOCK_26,
  207. WL12XX_TCXOCLOCK_26, 53);
  208. }
  209. static void __init omap4_panda_legacy_init(void)
  210. {
  211. legacy_init_wl12xx(WL12XX_REFCLOCK_38, 0, 53);
  212. }
  213. #endif
  214. #if defined(CONFIG_ARCH_OMAP4) || defined(CONFIG_SOC_OMAP5)
  215. static struct iommu_platform_data omap4_iommu_pdata = {
  216. .reset_name = "mmu_cache",
  217. .assert_reset = omap_device_assert_hardreset,
  218. .deassert_reset = omap_device_deassert_hardreset,
  219. };
  220. #endif
  221. #ifdef CONFIG_SOC_AM33XX
  222. static void __init am335x_evmsk_legacy_init(void)
  223. {
  224. legacy_init_wl12xx(WL12XX_REFCLOCK_38, 0, 31);
  225. }
  226. #endif
  227. #ifdef CONFIG_SOC_OMAP5
  228. static void __init omap5_uevm_legacy_init(void)
  229. {
  230. }
  231. #endif
  232. static struct pcs_pdata pcs_pdata;
  233. void omap_pcs_legacy_init(int irq, void (*rearm)(void))
  234. {
  235. pcs_pdata.irq = irq;
  236. pcs_pdata.rearm = rearm;
  237. }
  238. /*
  239. * GPIOs for TWL are initialized by the I2C bus and need custom
  240. * handing until DSS has device tree bindings.
  241. */
  242. void omap_auxdata_legacy_init(struct device *dev)
  243. {
  244. if (dev->platform_data)
  245. return;
  246. if (strcmp("twl4030-gpio", dev_name(dev)))
  247. return;
  248. dev->platform_data = &twl_gpio_auxdata;
  249. }
  250. /*
  251. * Few boards still need auxdata populated before we populate
  252. * the dev entries in of_platform_populate().
  253. */
  254. static struct pdata_init auxdata_quirks[] __initdata = {
  255. #ifdef CONFIG_SOC_OMAP2420
  256. { "nokia,n800", omap2420_n8x0_legacy_init, },
  257. { "nokia,n810", omap2420_n8x0_legacy_init, },
  258. { "nokia,n810-wimax", omap2420_n8x0_legacy_init, },
  259. #endif
  260. #ifdef CONFIG_ARCH_OMAP3
  261. { "compulab,omap3-sbc-t3730", omap3_sbc_t3730_twl_init, },
  262. #endif
  263. { /* sentinel */ },
  264. };
  265. struct of_dev_auxdata omap_auxdata_lookup[] __initdata = {
  266. #ifdef CONFIG_MACH_NOKIA_N8X0
  267. OF_DEV_AUXDATA("ti,omap2420-mmc", 0x4809c000, "mmci-omap.0", NULL),
  268. #endif
  269. #ifdef CONFIG_ARCH_OMAP3
  270. OF_DEV_AUXDATA("ti,omap3-padconf", 0x48002030, "48002030.pinmux", &pcs_pdata),
  271. OF_DEV_AUXDATA("ti,omap3-padconf", 0x480025a0, "480025a0.pinmux", &pcs_pdata),
  272. OF_DEV_AUXDATA("ti,omap3-padconf", 0x48002a00, "48002a00.pinmux", &pcs_pdata),
  273. OF_DEV_AUXDATA("ti,omap2-iommu", 0x5d000000, "5d000000.mmu",
  274. &omap3_iommu_pdata),
  275. /* Only on am3517 */
  276. OF_DEV_AUXDATA("ti,davinci_mdio", 0x5c030000, "davinci_mdio.0", NULL),
  277. OF_DEV_AUXDATA("ti,am3517-emac", 0x5c000000, "davinci_emac.0",
  278. &am35xx_emac_pdata),
  279. #endif
  280. #ifdef CONFIG_ARCH_OMAP4
  281. OF_DEV_AUXDATA("ti,omap4-padconf", 0x4a100040, "4a100040.pinmux", &pcs_pdata),
  282. OF_DEV_AUXDATA("ti,omap4-padconf", 0x4a31e040, "4a31e040.pinmux", &pcs_pdata),
  283. #endif
  284. #if defined(CONFIG_ARCH_OMAP4) || defined(CONFIG_SOC_OMAP5)
  285. OF_DEV_AUXDATA("ti,omap4-iommu", 0x4a066000, "4a066000.mmu",
  286. &omap4_iommu_pdata),
  287. OF_DEV_AUXDATA("ti,omap4-iommu", 0x55082000, "55082000.mmu",
  288. &omap4_iommu_pdata),
  289. #endif
  290. { /* sentinel */ },
  291. };
  292. /*
  293. * Few boards still need to initialize some legacy devices with
  294. * platform data until the drivers support device tree.
  295. */
  296. static struct pdata_init pdata_quirks[] __initdata = {
  297. #ifdef CONFIG_ARCH_OMAP3
  298. { "compulab,omap3-sbc-t3517", omap3_sbc_t3517_legacy_init, },
  299. { "compulab,omap3-sbc-t3530", omap3_sbc_t3530_legacy_init, },
  300. { "compulab,omap3-sbc-t3730", omap3_sbc_t3730_legacy_init, },
  301. { "nokia,omap3-n900", nokia_n900_legacy_init, },
  302. { "nokia,omap3-n9", hsmmc2_internal_input_clk, },
  303. { "nokia,omap3-n950", hsmmc2_internal_input_clk, },
  304. { "isee,omap3-igep0020", omap3_igep0020_legacy_init, },
  305. { "ti,omap3-evm-37xx", omap3_evm_legacy_init, },
  306. { "ti,omap3-zoom3", omap3_zoom_legacy_init, },
  307. { "ti,am3517-evm", am3517_evm_legacy_init, },
  308. #endif
  309. #ifdef CONFIG_ARCH_OMAP4
  310. { "ti,omap4-sdp", omap4_sdp_legacy_init, },
  311. { "ti,omap4-panda", omap4_panda_legacy_init, },
  312. #endif
  313. #ifdef CONFIG_SOC_AM33XX
  314. { "ti,am335x-evmsk", am335x_evmsk_legacy_init, },
  315. #endif
  316. #ifdef CONFIG_SOC_OMAP5
  317. { "ti,omap5-uevm", omap5_uevm_legacy_init, },
  318. #endif
  319. { /* sentinel */ },
  320. };
  321. static void pdata_quirks_check(struct pdata_init *quirks)
  322. {
  323. while (quirks->compatible) {
  324. if (of_machine_is_compatible(quirks->compatible)) {
  325. if (quirks->fn)
  326. quirks->fn();
  327. break;
  328. }
  329. quirks++;
  330. }
  331. }
  332. void __init pdata_quirks_init(struct of_device_id *omap_dt_match_table)
  333. {
  334. omap_sdrc_init(NULL, NULL);
  335. pdata_quirks_check(auxdata_quirks);
  336. of_platform_populate(NULL, omap_dt_match_table,
  337. omap_auxdata_lookup, NULL);
  338. pdata_quirks_check(pdata_quirks);
  339. }